StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StMyEventMaker.cxx
1 #include <TROOT.h>
2 #include <TTree.h>
3 #include <TH2F.h>
4 #include <TVector3.h>
5 #include <TFile.h>
6 #include <assert.h>
7 
8 #include <StEvent.h>
9 #include <StEventTypes.h>
10 
11 #include <StMuDSTMaker/COMMON/StMuTrack.h>
12 #include <StMuDSTMaker/COMMON/StMuDst.h>
13 #include <StMuDSTMaker/COMMON/StMuEvent.h>
14 #include <StMuDSTMaker/COMMON/StMuTriggerIdCollection.h>
15 #include <StMuDSTMaker/COMMON/StMuPrimaryVertex.h>
16 
17 #include <StEmcUtil/geometry/StEmcGeom.h>
18 #include <StEmcUtil/projection/StEmcPosition.h>
19 #include <StEmcUtil/database/StBemcTables.h>
20 #include <StEmcUtil/others/emcDetectorName.h>
21 #include <StEmcRawMaker/defines.h>
22 #include <StEvent/StEnumerations.h>
23 #include <St_db_Maker/St_db_Maker.h>
24 #include <StEmcADCtoEMaker/StEmcADCtoEMaker.h>
25 #include <StDetectorDbMaker/StDetectorDbTriggerID.h>
26 
27 //MyEvent
28 #include <StEmcPool/StPhotonCommon/MyEvent.h>
29 #include <StEmcPool/StPhotonCommon/MyPoint.h>
30 #include <StEmcPool/StPhotonCommon/MyMcTrack.h>
31 
32 #include "StMyEventMaker.h"
33 
34 ClassImp(StMyEventMaker)
35 
36  StMyEventMaker::StMyEventMaker(const char *name,const char *outputFile,
37  const char *type,const char *coll,Bool_t debug):StMaker(name)
38 {
39  mFileName=outputFile;
40 
41  if(strcmp(type,"real")!=0){
42  cout<<"not running on real data??"<<endl;
43  assert(0);
44  }
45 
46  mDAU=kFALSE;
47  mPP04=kFALSE;
48  mPP05=kFALSE;
49  mAUAU200=kFALSE;
50  if(strcmp(coll,"dAu")==0){
51  mDAU=kTRUE;
52  mTrig[0]=2001;
53  mTrig[1]=2003;
54  mTrig[2]=2201;
55  mTrig[3]=2202;
56  }
57  if(strcmp(coll,"pp04")==0){
58  mPP04=kTRUE;
59  mTrig[0]=45010;
60  mTrig[1]=10;
61  mTrig[2]=45201;
62  mTrig[3]=45202;
63  }
64  if(strcmp(coll,"pp05")==0){
65  mPP05=kTRUE;
66  mTrig[0]=96011;
67  mTrig[1]=-10000;
68  mTrig[2]=96201;
69  mTrig[3]=96211;
70  }
71  if(strcmp(coll,"auau200")==0){
72  mAUAU200=kTRUE;
73  mTrig[0]=15003;//minbias r<5023099
74  mTrig[1]=15007;//minbias r>5023099
75  mTrig[2]=15203;//bemc-ht-13
76  mTrig[3]=-10000;
77  }
78 
79  mDebug=debug;
80 
81  mBemcTables=new StBemcTables();
82  mEvent=new MyEvent();
83 }
84 
85 StMyEventMaker::~StMyEventMaker()
86 {
87  //destructor, leave this!!
88 }
89 
90 Int_t StMyEventMaker::Init()
91 {
92 
93  h_EvSum=new TH1F("h_EvSum","see code for details",22,-1.5,20.5);
94 
95  mEventTree=new TTree("mEventTree","tree with my event structure");
96  mEventTree->Branch("branch","MyEvent",&mEvent);
97 
98  mN=0;
99  mRunId=0;
100  mRunPrev=0;
101  mEventId=0;
102  mTrigger=0;
103  mDate=0;
104  mTime=0;
105  mPs_mb=0;
106  mPs_mb2=0;
107  mPs_ht1=0;
108  mPs_ht2=0;
109 
110  return StMaker::Init();
111 }
112 
114 {
115  mN++;
116  if(mDebug) cout<<endl<<"#### processing event "<<mN<<endl<<endl;
117  h_EvSum->Fill(1);
118 
119  StEmcGeom *bemcGeom=StEmcGeom::getEmcGeom("bemc");
120 
121  StMuDst* mu=(StMuDst*)GetInputDS("MuDst");
122  if(!mu){
123  if(mDebug) cout << "********* no StMuDst*"<<endl;
124  return kStOK;
125  }
126 
127  if(mDebug) cout<<"number of primverts: "<<mu->numberOfPrimaryVertices()<<endl;
128 
129  StMuEvent *muEvent=(StMuEvent*)mu->event();
130  if(!muEvent){
131  if(mDebug) cout << "********* no StMuEvent*"<<endl;
132  return kStOK;
133  }
134 
135  mRunPrev=mRunId;
136  mRunId=muEvent->runId();
137  mEventId=muEvent->eventId();
138  if(mDebug) cout<<"starting run: "<<mRunId<<" and event: "<<mEventId<<endl;
139 
140  if(mAdcMaker->isCorrupted()){
141  if(mDebug) cout<<"event corrupted!"<<endl;
142  h_EvSum->Fill(-1);
143  return kStOK;
144  }
145 
146  if(mRunId!=mRunPrev){
147  StDetectorDbTriggerID& DetDbTrigId = *(StDetectorDbTriggerID::instance());
148  for(UInt_t i=0;i<DetDbTrigId.getL0NumRows();i++){
149  if(mDebug) cout<<"prescales: "<<DetDbTrigId.getPsL0(i)<<endl<<endl;
150  if(DetDbTrigId.getL0OfflineTrgId(i)==mTrig[0])
151  mPs_mb=DetDbTrigId.getPsL0(i);
152  if(DetDbTrigId.getL0OfflineTrgId(i)==mTrig[1])
153  mPs_mb2=DetDbTrigId.getPsL0(i);
154  if(DetDbTrigId.getL0OfflineTrgId(i)==mTrig[2])
155  mPs_ht1=DetDbTrigId.getPsL0(i);
156  if(DetDbTrigId.getL0OfflineTrgId(i)==mTrig[3])
157  mPs_ht2=DetDbTrigId.getPsL0(i);
158  }
159 
160  mBemcTables->loadTables((StMaker*)this);
161  }
162 
163  mDate=(Int_t)mDbMaker->GetDateTime().GetDate();
164  mTime=(Int_t)mDbMaker->GetDateTime().GetTime();
165 
166  //get trigger info
167  Float_t mips=-1.;
168  Float_t zdcEast=0.;
169  Float_t zdcWest=0.;
170  Float_t zdcVertex=0.;
171  Float_t bbcEast=0.;
172  Float_t bbcWest=0.;
173  StCtbTriggerDetector &CTB=muEvent->ctbTriggerDetector();
174  mips=CTB.mips(0);
175  StZdcTriggerDetector &ZDC=muEvent->zdcTriggerDetector();
176  zdcEast=ZDC.adcSum(east);
177  zdcWest=ZDC.adcSum(west);
178  zdcVertex=ZDC.vertexZ();
179  StBbcTriggerDetector &BBC=muEvent->bbcTriggerDetector();
180  bbcEast=BBC.adcSumEastLarge();
181  bbcWest=BBC.adcSumWestLarge();
182 
183  // get BBC vertex
184  int west=BBC.tdcEarliestWest();
185  int east=BBC.tdcEarliestEast();
186  int diff=west-east;
187  float BBCVertexZ = 10.77 + 2.82*diff; // z is now in cm
188 
189  //from Sasha:
190  // BBCVertexZ = a + b*diff , with a = 10.77 and b = 2.82
191  // used to be BBCVertexZ = 2.0*diff ....
192 
193  //----- CREATE MyEvent -----
194  mEvent=new MyEvent(mRunId,mEventId,mDate,mTime);
195  if(!mEvent){
196  if(mDebug) cout<<"couldn't create MyEvent*"<<endl;
197  return kStErr;
198  }
199 
200  //get current vertex from mudst?
201  StThreeVectorF vPos;
202  StMuPrimaryVertex *muVert=mu->primaryVertex();
203  if(muVert){
204  vPos=muVert->position();
205  }
206  else if(mAUAU200){
207  vPos.setX(muEvent->primaryVertexPosition().x());
208  vPos.setY(muEvent->primaryVertexPosition().y());
209  vPos.setZ(muEvent->primaryVertexPosition().z());
210  }
211  else{
212  vPos.setX(0);
213  vPos.setY(0);
214  vPos.setZ(0);
215  }
216 
217  //a priori reject for AuAu:
218  if(mAUAU200){
219  if(fabs(vPos.z())>30.){
220  if(mDebug) cout<<"vertex out of range"<<endl;
221  return kStOK;
222  }
223  }
224 
225  //get trig per event
226  mTrigger=0;
227  if(muEvent->triggerIdCollection().nominal().isTrigger(mTrig[0])||
228  muEvent->triggerIdCollection().nominal().isTrigger(mTrig[1])) mTrigger+=1;
229  if(muEvent->triggerIdCollection().nominal().isTrigger(mTrig[2])) mTrigger+=2;
230  if(muEvent->triggerIdCollection().nominal().isTrigger(mTrig[3])) mTrigger+=4;
231  if(muEvent->triggerIdCollection().nominal().isTrigger(2002)) mTrigger+=8;
232 
233  if(mTrigger==0){
234  if(mDebug) cout<<"nothing more useless than an event with no trigger!"<<endl;
235  return kStOK;
236  }
237 
239  if(!emcCol){
240  if(mDebug) cout<<"no StEmcCollection"<<endl;
241  h_EvSum->Fill(8);
242  return kStOK;
243  }
244  StEmcDetector *emcDet=(StEmcDetector*)emcCol->detector(kBarrelEmcTowerId);
245  if(!emcDet)
246  {
247  if(mDebug) cout<<"no emcDet!!"<<endl;
248  h_EvSum->Fill(9);
249  return kStOK;
250  }
251  //get status of trigger tower
252  Int_t hiTowId=-1;
253  Int_t hiTowAdc=-1;
254  Int_t hiTowStatus=-1;
255  Float_t hiTowEnergy=0.;
256  if(mTrigger>1){
257  for(UInt_t m=1;m<=emcDet->numberOfModules();m++){
258  StEmcModule *emcMod=emcDet->module(m);
259  if(!emcMod){
260  if(mDebug) cout<<"no emcMod for module "<<m<<endl;
261  continue;
262  }
263  StSPtrVecEmcRawHit& modHits=emcMod->hits();
264  for(UInt_t h=0;h<modHits.size();h++){
265  Int_t adc=modHits[h]->adc();
266  Float_t nrg=modHits[h]->energy();
267  if(adc>hiTowAdc && nrg>0.){
268  hiTowAdc=adc;
269  hiTowEnergy=nrg;
270  bemcGeom->getId(m,modHits[h]->eta(),modHits[h]->sub(),hiTowId);
271  }
272  }
273  }
274  //get status
275  if(hiTowId>0) mBemcTables->getStatus(BTOW,hiTowId,hiTowStatus);
276  }
277 
278  Int_t nPrimTracks=0;
279  Int_t nGlobalTracks=0;
280  Int_t nGoodPrimaries=0;
281  Int_t nGoodPrimBarrel=0;
282  Int_t nGoodGlobals=0;
283  Float_t TpcPt=0.;
284  Float_t TpcPtBarrelWest=0.;
285  //using current vertex -> best??
286  StMuTrack *ptrack;
287  if(!mAUAU200){
288  nPrimTracks=mu->primaryTracks()->GetEntries();
289  for(Int_t i=0;i<nPrimTracks;i++){
290  ptrack=(StMuTrack*)mu->primaryTracks()->UncheckedAt(i);
291  if(ptrack->bad()) continue;
292  if(ptrack->dca().mag()<3. && ptrack->nHitsFit()>15){
293  nGoodPrimaries++;
294  TpcPt+=ptrack->momentum().mag();
295  if(fabs(ptrack->eta() - 0.5)<0.5){
296  nGoodPrimBarrel++;
297  TpcPtBarrelWest+=ptrack->momentum().mag();
298  }
299  }
300  }
301  StMuTrack *gtrack;
302  nGlobalTracks=mu->globalTracks()->GetEntries();
303  for(Int_t i=0;i<nGlobalTracks;i++){
304  gtrack=(StMuTrack*)mu->globalTracks()->UncheckedAt(i);
305  if(gtrack->bad()) continue;
306  if(gtrack->dca().mag()<3. && gtrack->nHitsFit()>15)
307  nGoodGlobals++;
308  }
309  }
310  //refmult
311  Int_t ftpcRefMultTracks=muEvent->refMultFtpcEast();
312  if(mAUAU200) ftpcRefMultTracks=muEvent->refMult();
313  if(mDebug) cout<<"event has refMult: "<<ftpcRefMultTracks<<endl;
314 
315 
316  //start reco tree here:
317  Float_t EnergyNeutral=0.;
318 
319  StEmcPoint *pt=0;
320  StSPtrVecEmcPoint& barrelPoints=emcCol->barrelPoints();
321  for(UInt_t i=0;i<barrelPoints.size();i++){
322 
323  pt=(StEmcPoint*)barrelPoints[i];
324  Float_t dist=9999.;
325  if(!calcDistanceTrackToPoint(pt,mu,dist)){
326  cout<<"wrong bfield or no event pointer (shouldn't see this)"<<endl;
327  }
328  MyPoint *mypt=new MyPoint();
329 
330  if(pt->position().pseudoRapidity()>0.0)//only WEST
331  EnergyNeutral+=pt->energy();
332 
333  StPtrVecEmcCluster& etaClus=pt->cluster(kBarrelSmdEtaStripId);
334  StPtrVecEmcCluster& phiClus=pt->cluster(kBarrelSmdPhiStripId);
335  Int_t nEtaHits=0;
336  Int_t nPhiHits=0;
337  Float_t etaEnergy=0.;
338  Float_t phiEnergy=0.;
339  Float_t etaWidth=0.;
340  Float_t phiWidth=0.;
341  if(etaClus.size()>0){
342  StEmcCluster *clE=(StEmcCluster*)etaClus[0];
343  StPtrVecEmcRawHit& hE=clE->hit();
344  nEtaHits=hE.size();
345  etaEnergy=clE->energy();
346  etaWidth=clE->sigmaEta();
347  }
348  if(phiClus.size()>0){
349  StEmcCluster *clP=(StEmcCluster*)phiClus[0];
350  StPtrVecEmcRawHit& hP=clP->hit();
351  nPhiHits=hP.size();
352  phiEnergy=clP->energy();
353  phiWidth=clP->sigmaPhi();
354  }
355 
356  if( mAUAU200 && (nEtaHits<1||nPhiHits<1) ){
357  delete mypt;
358  continue;
359  }
360 
361  mypt->setEnergy(pt->energy());
362  mypt->setQuality((Int_t)pt->quality());
363  mypt->setPosition(pt->position().x(),pt->position().y(),pt->position().z());
364  mypt->setDistanceToTrack(dist);
365  mypt->setHitsEta(nEtaHits);
366  mypt->setWidthEta(etaWidth);
367  mypt->setEnergyEta(etaEnergy);
368  mypt->setHitsPhi(nPhiHits);
369  mypt->setWidthPhi(phiWidth);
370  mypt->setEnergyPhi(phiEnergy);
371 
372  mEvent->addPoint(mypt);
373 
374  delete mypt;
375  }
376 
377  //fill MyEvent
378  mEvent->setPrescale(0,mPs_mb);
379  mEvent->setPrescale(1,mPs_mb2);
380  mEvent->setPrescale(2,mPs_ht1);
381  mEvent->setPrescale(3,mPs_ht2);
382  mEvent->setHighTowerAdc(hiTowAdc);
383  mEvent->setHighTowerId(hiTowId);
384  mEvent->setHighTowerStatus(hiTowStatus);
385  mEvent->setHighTowerEnergy(hiTowEnergy);
386  mEvent->setVertex(vPos.x(),vPos.y(),vPos.z());
387  mEvent->setTrigger(mTrigger);
388  mEvent->setGoodPrimaries(nGoodPrimaries);
389  mEvent->setGoodPrimBarrel(nGoodPrimBarrel);
390  mEvent->setGoodGlobals(nGoodGlobals);
391  mEvent->setRefMult(ftpcRefMultTracks);
392  mEvent->setEnergyInBarrel(EnergyNeutral);
393  mEvent->setMomentumInTpc(TpcPt);
394  mEvent->setMomentumInTpcWest(TpcPtBarrelWest);
395  mEvent->setCtbSum(mips);
396  mEvent->setBbcSumEast(bbcEast);
397  mEvent->setBbcSumWest(bbcWest);
398  mEvent->setZdcSumEast(zdcEast);
399  mEvent->setZdcSumWest(zdcWest);
400  mEvent->setZdcVertexZ(zdcVertex);
401  mEvent->setBbcVertexZ(BBCVertexZ);
402 
403  mEventTree->Fill();
404 
405  return kStOK;
406 }
407 
409 {
410  saveHistograms();
411  return kStOK;
412 }
413 
414 void StMyEventMaker::saveHistograms()
415 {
416  if(mDebug) cout<<"************ saving histograms ****************"<<endl;
417  TFile *hfile=(TFile*)gROOT->FindObject(mFileName);
418  if(hfile) hfile->Close();
419  hfile=new TFile(mFileName,"RECREATE");
420 
421  h_EvSum->Write();
422  mEventTree->Write();
423 
424  hfile->Close();
425 }
426 
427 Bool_t StMyEventMaker::calcDistanceTrackToPoint(StEmcPoint *point,StMuDst *currMuDst,Float_t &distanceToTrack)
428 {
429  StMuEvent *muEv=(StMuEvent*)currMuDst->event();
430  if(!muEv) return kFALSE;
431  Double_t bFld=muEv->magneticField()/10.;
432  if(mDebug) cout<<"summary()->magneticField()="<<bFld<<"(Tesla)"<<endl;
433 
434  if(fabs(bFld)<0.01){
435  if(mDebug) cout<<"wrong/no BField!"<<endl;
436  return kFALSE;
437  }
438 
439  StEmcPosition* emcPosition = new StEmcPosition();
440  StThreeVectorD pos,mom;
441  distanceToTrack=999.;
442  StMuTrack *track;
443 
444  Int_t ntracks=currMuDst->primaryTracks()->GetEntries();
445  for(Int_t i=0;i<ntracks;i++){
446  track=(StMuTrack*)currMuDst->primaryTracks()->UncheckedAt(i);
447  if(track->bad()) continue;
448  //if(track->momentum().mag()<.5) continue;//E=sqrt(p^2+m^2) -> p=sqrt(E^2-m^2) protons???
449  StPhysicalHelixD helix = track->outerHelix();
450  Bool_t projOK=emcPosition->projTrack(&pos,&mom,&helix,bFld,230.705,1);
451  if(!projOK) continue;
452  Float_t d=(pos - point->position()).mag();//in cm
453 
454  if(d<distanceToTrack&&d>0.) distanceToTrack=d;
455  }
456 
457 
458  delete emcPosition;
459  return kTRUE;
460 }
461 
462 
463 
464 
465 
466 
static StMuPrimaryVertex * primaryVertex()
return pointer to current primary vertex
Definition: StMuDst.h:322
static TObjArray * globalTracks()
returns pointer to the global tracks list
Definition: StMuDst.h:303
StThreeVectorF primaryVertexPosition(int vtx_id=-1) const
The StMuDst is supposed to be structured in &#39;physical events&#39;. Therefore there is only 1 primary vert...
Definition: StMuEvent.cxx:221
Bool_t isCorrupted()
Returns if BTOW is corrupted or not.
virtual Int_t Make()
Definition: MyPoint.h:7
virtual Int_t Finish()
UShort_t nHitsFit() const
Return total number of hits used in fit.
Definition: StMuTrack.h:239
Accessor to the database for trigger id information.
void loadTables(StMaker *anyMaker)
load tables.
Double_t eta() const
Returns pseudo rapidity at point of dca to primary vertex.
Definition: StMuTrack.h:257
static TObjArray * primaryTracks()
returns pointer to a list of tracks belonging to the selected primary vertex
Definition: StMuDst.h:301
unsigned short refMult(int vtx_id=-1)
Reference multiplicity of charged particles as defined in StEventUtilities/StuRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:195
static StMuEvent * event()
returns pointer to current StMuEvent (class holding the event wise information, e.g. event number, run number)
Definition: StMuDst.h:320
const StThreeVectorF & momentum() const
Returns 3-momentum at dca to primary vertex.
Definition: StMuTrack.h:260
Definition: Stypes.h:40
StThreeVectorF dca(Int_t vtx_id=-1) const
Returns 3D distance of closest approach to primary vertex.
Definition: StMuTrack.cxx:359
static StEmcCollection * emcCollection()
returns pointer to current StEmcCollection
Definition: StMuDst.h:405
void getStatus(Int_t det, Int_t softId, Int_t &status, const char *option="") const
Return status.
Bool_t projTrack(StThreeVectorD *atFinal, StThreeVectorD *momentumAtFinal, const StTrack *const track, Double_t magField, Double_t radius=225.405, Int_t option=1) const
Track projection utility.
StPhysicalHelixD outerHelix() const
Returns outer helix (last measured point)
Definition: StMuTrack.cxx:412
Definition: Stypes.h:44
unsigned short refMultFtpcEast(int vtx_id=-1)
Reference multiplicity of particles in the east FTPC as defined in StEventUtilities/StuFtpcRefMult.hh for vertex vtx_id (-1 is default index from StMuDst)
Definition: StMuEvent.cxx:197