StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StPidAmpMaker.cxx
1 //
3 // $Id: StPidAmpMaker.cxx,v 1.12 2003/09/02 17:58:46 perev Exp $
4 //
5 // Authors: Aihong Tang
6 //
8 //
9 // Description: produce hist. for PIDFitter, which builds PID tables.
10 //
12 
13 #include <Stiostream.h>
14 #include <stdlib.h>
15 #include <math.h>
16 #include "StMaker.h"
17 #include "StPidAmpMaker.h"
18 #include "StFlowMaker/StFlowMaker.h"
19 #include "StFlowMaker/StFlowEvent.h"
20 #include "StFlowMaker/StFlowConstants.h"
21 #include "StFlowMaker/StFlowSelection.h"
22 #include "StFlowMaker/StFlowCutTrack.h"
23 #include "StEnumerations.h"
24 #include "PhysicalConstants.h"
25 #include "SystemOfUnits.h"
26 #include "TVector2.h"
27 #include "TFile.h"
28 #include "TString.h"
29 #include "TH1.h"
30 #include "TH2.h"
31 #include "TH3.h"
32 #include "TF1.h"
33 #include "StMessMgr.h"
34 #include "TMath.h"
35 #define PR(x) cout << "##### PidAmp " << (#x) << " = " << (x) << endl;
36 
37 ClassImp(StPidAmpMaker)
38 
39 //-----------------------------------------------------------------------
40 
41 StPidAmpMaker::StPidAmpMaker(const Char_t* name):
42  StMaker(name),
43  mSingleMultiplicityBin(1),
44  MakerName(name) {
45 
46 }
47 
48 //-----------------------------------------------------------------------
49 
50 StPidAmpMaker::~StPidAmpMaker() {
51 }
52 
53 //-----------------------------------------------------------------------
54 
56  // Make histograms
57 
58 
59  // Get a pointer to StFlowEvent
60  StFlowMaker* pFlowMaker = NULL;
61  pFlowMaker = (StFlowMaker*)GetMaker("Flow");
62  if (pFlowMaker) pFlowEvent = pFlowMaker->FlowEventPointer();
63  if (pFlowEvent && pFlowSelect->Select(pFlowEvent)) { // event selected
64 
65  if (pFlowEvent) FillParticleHistograms(); // fill particle histograms
66 
67  if (Debug()) StMaker::PrintInfo();
68 
69  }
70 
71  return kStOK;
72 }
73 
74 //-----------------------------------------------------------------------
75 
76 Int_t StPidAmpMaker::Init() {
77  // Book histograms
78 
79 
80  TH1F dummyHisto("dummy","dummy",mNDedxBins,mDedxStart,mDedxEnd);
81 
82  pidHisto
83  =new TH1F*[mSingleMultiplicityBin*mNDcaBins*mNChargeBins*mNPBins*mNEtaBins*mNNHitsBins];
84 
85  for(int m=0;m<mSingleMultiplicityBin;m++) //
86  for(int d=0; d<mNDcaBins;d++) //0_3_inf
87  for(int e=0; e<mNChargeBins;e++) //0_minus 1_plus
88  for(int i=0; i<mNPBins;i++) //0-99
89  for(int j=0; j<mNEtaBins;j++) //0-9
90  for(int k=0; k<mNNHitsBins; k++){ //0-5
91  char *theName = new char[80];
92 
93  if (i<10){
94  sprintf(theName,"%d%d%d0%d%d%d",theMultBin,d,e,i,j,k);
95  }else {
96  sprintf(theName,"%d%d%d%d%d%d",theMultBin,d,e,i,j,k);
97  }
98 
99  pidHisto[GetPositionInArray(m,d,e,i,j,k)]=
100  new TH1F(dummyHisto);
101  pidHisto[GetPositionInArray(m,d,e,i,j,k)]->SetName(theName);
102  pidHisto[GetPositionInArray(m,d,e,i,j,k)]->SetTitle(theName);
103 
104  cout<<"booking histo, mult. # "<<theMultBin<<", dca # "<<d<<", charge # "<<e<<", p # "<<i<<", eta # "<<j<<", ndedx # "<<k<<endl;
105  }
106 
107 
108  gMessMgr->SetLimit("##### StPidAmp", 2);
109  gMessMgr->Info("##### StPidAmp: $Id: StPidAmpMaker.cxx,v 1.12 2003/09/02 17:58:46 perev Exp $");
110 
111  return StMaker::Init();
112 }
113 
114 
115 
116 
117 //-----------------------------------------------------------------------
118 
119 void StPidAmpMaker::FillParticleHistograms() {
120  // Fill histograms from the particles
121 
122  int multBin=0; //single multbin here.
123 
124  // Initialize Iterator
125  StFlowTrackCollection* pFlowTracks = pFlowEvent->TrackCollection();
126  StFlowTrackIterator itr;
127 
128  for (itr = pFlowTracks->begin(); itr != pFlowTracks->end(); itr++) {
129  StFlowTrack* pFlowTrack = *itr;
130 
131  float eta = pFlowTrack->Eta();
132  int charge = pFlowTrack->Charge();
133 //VPunused float dca = pFlowTrack->Dca();
134 //VPunused float dcaGlobal = pFlowTrack->DcaGlobal();
135  int fitPts = pFlowTrack->FitPts();
136  float mtm = pFlowTrack->P();
137  float dedx = pFlowTrack->Dedx();
138  float NDedxUsed = (fitPts-1.39589)/1.41276; //linear relation between mFitPts and NDedxUsed.
139 
140  int dcaBin=0;
141  int chargeBin=0;
142  int pBin=0;
143  int etaBin=0;
144  int nhitsBin=0;
145 
146  dcaBin=0; //for p00he dst, they only produced primary tracks, so I let dcaBin=0.
147 
148  chargeBin= (charge>0) ? 1 : 0;
149 
150  pBin=int(mtm/((mPEnd-mPStart)/mNPBins));
151  if (pBin>(mNPBins-1)) continue;
152 
153  etaBin=int(fabs(eta)/((mEtaEnd-mEtaStart)/mNEtaBins));
154  if (etaBin>(mNEtaBins-1)) continue;
155 
156  nhitsBin=
157  int(float(NDedxUsed)/(float(mNNHitsEnd-mNNHitsStart)/mNNHitsBins));
158  nhitsBin=(nhitsBin>(mNNHitsBins-1)) ? (mNNHitsBins-1) : nhitsBin;
159  nhitsBin=(nhitsBin<0) ? 0 : nhitsBin;
160 
161  if (dedx>mDedxStart && dedx<mDedxEnd)
162  pidHisto[GetPositionInArray(multBin,dcaBin,chargeBin,pBin,etaBin,nhitsBin)]->Fill(dedx);//multBin shoud be 0 if produce histo for mult bin seperatly.
163 
164  }
165 
166 
167 }
168 
169 
170 //---------------------------------------------------------------------------
171 Int_t StPidAmpMaker::GetPositionInArray(Int_t theMultBin, Int_t theDcaBin, Int_t theChargeBin, Int_t thePBin, Int_t theEtaBin, Int_t theNHitsBin){
172 
173  int totalEntry
174  = mSingleMultiplicityBin*mNDcaBins*mNChargeBins*mNPBins*mNEtaBins*mNNHitsBins;
175 
176  int positionPointer=0;
177 
178  totalEntry=totalEntry/mSingleMultiplicityBin;
179  positionPointer=positionPointer+totalEntry*theMultBin;
180 
181  totalEntry=totalEntry/mNDcaBins;
182  positionPointer=positionPointer+totalEntry*theDcaBin;
183 
184  totalEntry=totalEntry/mNChargeBins;
185  positionPointer=positionPointer+totalEntry*theChargeBin;
186 
187  totalEntry=totalEntry/mNPBins;
188  positionPointer=positionPointer+totalEntry*thePBin;
189 
190  totalEntry=totalEntry/mNEtaBins;
191  positionPointer=positionPointer+totalEntry*theEtaBin;
192 
193  totalEntry=totalEntry/mNNHitsBins;
194  positionPointer=positionPointer+totalEntry*theNHitsBin;
195 
196  return positionPointer;
197 }
198 
199 
200 
201 
202 //-----------------------------------------------------------------------
203 
205 
206  //write out histograms
207  for(int m=0;m<mSingleMultiplicityBin;m++) //
208  for(int d=0; d<mNDcaBins;d++) //0_3_inf
209  for(int e=0; e<mNChargeBins;e++) { //0_minus 1_plus
210 
211  char *theHistoFileName = new char[200];
212  sprintf(theHistoFileName,"./PidHisto_%d%d%d.root",theMultBin,d,e);
213 
214  TFile histoFile(theHistoFileName,"RECREATE");
215  cout<<" writting histogram file "<<theHistoFileName<<endl;
216 
217  histoFile.cd();
218 
219  //a name for PIDFitter to identify
221  // 1 -> the second multiplicity bin
222  // N -> no primary tracks
223  // + -> positive charge tracks
224 
225  char* multName=new char[80];
226  sprintf(multName,"%d",theMultBin);
227 
228  TString tempString;
229  tempString.Append(multName);
230 
231  if (d==0) tempString.Append("P"); // dca<3
232  else tempString.Append("N"); //dca>3
233 
234  if (e==0) tempString.Append("-"); //negative particle
235  else tempString.Append("+"); //positive particle
236 
237 
238  TNamed fileNameTag(tempString,tempString);
239 
240  fileNameTag.Write();
241 
242 
243  TH1F* tempHisto=0;
244 
245  for (int i =0; i<mNPBins; i++)
246  for (int j=0; j<mNEtaBins;j++)
247  for (int k=0; k<mNNHitsBins;k++) {
248 
249 
250  char *theName = new char[80];
251  if (i<10)
252  sprintf(theName,"h0%d%d%d",i,j,k);
253  else sprintf(theName,"h%d%d%d",i,j,k);
254 
255  histoFile.cd();
256  tempHisto=new TH1F(*(pidHisto[GetPositionInArray(m,d,e,i,j,k)]));
257  tempHisto->SetName(theName);
258  tempHisto->SetTitle(theName);
259  tempHisto->Write();
260  delete tempHisto;
261 
262  }
263 
264  histoFile.Write();
265 
266  histoFile.Close();
267 
268  }
269 
270 
271  // Print the selection object details
272  // pFlowSelect->PrintList();
273 
274  delete pFlowSelect;
275 
276  cout << endl;
277  gMessMgr->Summary(3);
278  cout << endl;
279 
280  return StMaker::Finish();
281 }
282 
284 //
285 // $Log: StPidAmpMaker.cxx,v $
286 // Revision 1.12 2003/09/02 17:58:46 perev
287 // gcc 3.2 updates + WarnOff
288 //
289 // Revision 1.11 2003/04/30 20:37:56 perev
290 // Warnings cleanup. Modified lines marked VP
291 //
292 // Revision 1.10 2002/02/25 19:30:07 jeromel
293 // ... SetFormat() again
294 //
295 // Revision 1.9 2002/02/14 21:25:56 aihong
296 // re-install the new version
297 //
298 //
Definition: Stypes.h:40
virtual Int_t Finish()
Definition: StMaker.cxx:776