StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTrack2FastDetectorMatcher.cxx
1 /************************************************************
2  *
3  * $Id: StTrack2FastDetectorMatcher.cxx,v 2.15 2018/04/10 11:32:10 smirnovd Exp $
4  *
5  * Author: Jan Balewski
6  ************************************************************
7  *
8  * Description: does not fear any pileup
9  *
10  ************************************************************/
11 
12 #include <StMessMgr.h>
13 #include "St_db_Maker/St_db_Maker.h"
14 #include "StTrack2FastDetectorMatcher.h"
15 #include "StEvent.h"
16 #include "StEEmcUtil/database/StEEmcDb.h"
17 #include "StEEmcUtil/database/EEmcDbItem.h"
18 #include "StEEmcUtil/database/cstructs/eemcConstDB.hh"
19 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
20 #include "StEmcCollection.h"
21 #include "StBTofCollection.h" // dongx
22 #include "StBTofUtil/StBTofGeometry.h"
23 #include "TGeoManager.h"
24 #include "TMath.h"
25 
26 //________________________________________________________________________________
27 StTrack2FastDetectorMatcher::StTrack2FastDetectorMatcher() : mTotEve(0), mMinZBtof(-3.0), mMaxZBtof(3.0), mMinAdcBemc(5), mMinAdcEemc(5),
28  isMC(kFALSE),
29  btofList(0),
30  ctbList(0),
31  bemcList(0), eemcList(0), btofGeom(0),
32  eeDb(0), geomE(0) {
33 
34  LOG_INFO << "StTrack2FastDetectorMatcher::StTrack2FastDetectorMatcher is in use" << endm;
35 }
36 //________________________________________________________________________________
37 void
38 StTrack2FastDetectorMatcher::Clear(const Char_t *opt){
39  LOG_DEBUG << "StTrack2FastDetectorMatcher::Clear nEve="<<mTotEve<< endm;
40  if (btofList) btofList->clear(); // dongx
41  if (ctbList) ctbList->clear();
42  if (bemcList) bemcList->clear();
43  if (eemcList) eemcList->clear();
44  eveID=-1;
45 }
46 //________________________________________________________________________________
47 StTrack2FastDetectorMatcher::~StTrack2FastDetectorMatcher() {
48  //x delete mStiTrack2FastDetector;
49  //x delete mVertexData;
50  SafeDelete(geomE);
51  SafeDelete(btofGeom); // dongx
52  SafeDelete(btofList);
53  SafeDelete(ctbList);
54  SafeDelete(bemcList);
55  SafeDelete(eemcList)
56 }
57 //________________________________________________________________________________
58 void StTrack2FastDetectorMatcher::fillArrays(StEvent* event) {
59  static Bool_t InitRun = kTRUE;
60  if (InitRun) {
61  isMC = (! event->triggerData() );
62  St_db_Maker* mydb = (St_db_Maker*) StMaker::GetChain()->GetMaker("db");
63  Int_t dateY=mydb->GetDateTime().GetYear();
64  // access EEMC-DB
65  eeDb = (StEEmcDb*)StMaker::GetChain()->GetDataSet("StEEmcDb");
66  if (eeDb) {
67  geomE= new EEmcGeomSimple();
68  // choose which 'stat' bits are fatal for mip detection
69  UInt_t killStatEEmc=EEMCSTAT_ONLPED | EEMCSTAT_STKBT| EEMCSTAT_HOTHT | EEMCSTAT_HOTJP | EEMCSTAT_JUMPED ;
70  eemcList =new StEemcHitList(eeDb, killStatEEmc,geomE); eemcList->initRun();
71  }
72  if (dateY > 2008) {
73  TObjectSet *btofGeom_dataset = (TObjectSet *) mydb->GetDataSet("btofGeometry");
74  btofGeom = btofGeom_dataset ? (StBTofGeometry *) btofGeom_dataset->GetObject() : nullptr;
75  // If StBTofGeometry object is not found in the list of maker's objects create a new one
76  if (! btofGeom) {
77  // Build StBTofGeometry from TGeo geometry if available
78  TVolume *starHall = gGeoManager ? nullptr : (TVolume *)mydb->GetDataSet("HALL");
79  LOG_INFO << " BTofGeometry initialization ... " << endm;
80  btofGeom = new StBTofGeometry("btofGeometry","btofGeometry");
81  if (isMC) btofGeom->SetMCOn();
82  else btofGeom->SetMCOff();
83  btofGeom->Init(mydb, starHall, gGeoManager);
84  mydb->AddConst(new TObjectSet("btofGeometry",btofGeom));
85  }
86 
87  btofList = new StBtofHitList();
88  btofList->initRun();
89 
90  } else {
91  ctbList = new StCtbHitList; ctbList->initRun();
92  }
93  if(isMC) {
94  LOG_INFO << "StTrack2FastDetectorMatcher M-C, Db_date="<<mydb->GetDateTime().AsString()<<endm;
95  // simu prior to 2008
96  mMinAdcBemc =7; //ideal BTOW gain 60 GeV ET @ 3500 ADC
97  // in late 2008 Matt uploaded ideal (aka sim) gians matching endcap
98  if(dateY>=2008) mMinAdcBemc =8; //ideal BTOW gain 60 GeV ET @ 4076 ADC
99  }
100  if(dateY<2006) mMinAdcBemc = 15; // BTOW used calibration of maxt Et @ ~27Gev
101  else mMinAdcBemc = 8; // BTOW used calibration of maxt Et @ ~60Gev
102  bemcList = new StBemcHitList; bemcList->initRun();
103  LOG_INFO
104  <<"\n Min/Max Z position for BTOF hit = "<<mMinZBtof<<" "<<mMaxZBtof // dongx
105  <<"\n MinAdcBemc for MIP ="<<mMinAdcBemc
106  <<"\n MinAdcEemc for MIP ="<<mMinAdcEemc
107  <<"\n bool isMC ="<<isMC
108  <<"\n bool useCtb ="<< (ctbList != 0)
109  <<"\n bool useBemc ="<< (bemcList != 0)
110  <<"\n bool useEemc ="<< (eemcList != 0)
111  <<"\n bool useBtof ="<< (btofList != 0)
112  <<endm;
113  InitRun = kFALSE;
114  }
115  StEvent *mEvent = (StEvent *) StMaker::GetChain()->GetInputDS("StEvent");
116  assert(mEvent);
117 
118  mTotEve++;
119  eveID=event->id();
120  LOG_INFO << "StTrack2FastDetectorMatcher::fillArrays START nEve="<<mTotEve<<" eveID="<<eveID<< endm;
121  // get BTOF info - dongx
122  if (btofList) {
123  StBTofCollection *btofColl = (StBTofCollection*)mEvent->btofCollection();
124  if (btofColl) btofList->build(btofColl);
125  }
126  // get CTB info, does not work for embeding
127  if (ctbList) {
128  StTriggerData *trgD=event->triggerData();
129  if (trgD) {
130  ctbList->buildFromData(trgD); // use real data
131  } else {
132  if(StMaker::GetChain()->GetDataSet("geant/g2t_ctb_hit")) {
133  St_DataSet *gds=StMaker::GetChain()->GetDataSet("geant");
134  ctbList->buildFromMC(gds); // use M-C
135  }
136  }
137  }
138  StEmcCollection* emcC =(StEmcCollection*)mEvent->emcCollection();
139  if (emcC) {
140  if (bemcList) {
141  StEmcDetector* btow = emcC->detector( kBarrelEmcTowerId);
142  if(btow) bemcList->build(btow, mMinAdcBemc);
143  }
144  if (eemcList) {
145  StEmcDetector* etow = emcC->detector(kEndcapEmcTowerId);
146  if (etow) eemcList->build(etow, mMinAdcEemc);
147  }
148  }
149 }
150 //________________________________________________________________________________
151 void
152 StTrack2FastDetectorMatcher::matchTrack2BTOF(const StPhysicalHelixD *hlx,StiTrack2FastDetector *t){
153  IntVec idVec;
154  DoubleVec pathVec;
155  PointVec crossVec;
156 
157  IntVec iBinVec;
158  if(btofGeom->HelixCrossCellIds(*hlx,idVec,pathVec,crossVec)) {
159  for(size_t i=0;i<idVec.size();i++) {
160  Int_t tray, module, cell;
161  btofGeom->DecodeCellId(idVec[i], cell, module, tray);
162 
163  Double_t local[3], global[3];
164  for(Int_t j=0;j<3;j++) local[j] = 0;
165  global[0] = crossVec[i].x();
166  global[1] = crossVec[i].y();
167  global[2] = crossVec[i].z();
168  StBTofGeomSensor *sensor = btofGeom->GetGeomSensor(module,tray);
169  if(!sensor) {
170  LOG_WARN << "no sensitive module in this projection??? - weird" << endm;
171  continue;
172  }
173  sensor->Master2Local(&global[0],&local[0]);
174  if(local[2]<mMinZBtof||local[2]>mMaxZBtof) continue;
175  Int_t iBin = btofList->addBtofTrack(tray, module, cell);
176  if (iBin < 0) continue;
177  iBinVec.push_back(iBin);
178  btofList->addBtofTrack(tray, module, cell);
179  }
180  }
181  if (! iBinVec.size()) return;
182  Bool_t btofMatch=btofList->isMatched(iBinVec);
183  Bool_t btofVeto =btofList->isVetoed(iBinVec);
184  Float_t btofW =btofList->getWeight(iBinVec);
185  LOG_DEBUG << " ** BTOF ** match/veto/weight = " << btofMatch << " " << btofVeto << " " << btofW << endm;
186  t->updateAnyMatch(btofMatch,btofVeto,t->mBtof);
187  t->weight*=btofW;
188  t->btofBin= iBinVec.size();
189 }
190 //________________________________________________________________________________
191 void
192 StTrack2FastDetectorMatcher::matchTrack2CTB(const StPhysicalHelixD *hlx,StiTrack2FastDetector *t){
193  const Double_t Rctb=213.6; // (cm) radius of the CTB
194  StThreeVectorD posCTB;
195  Float_t path=-1;
196  //alternative helix extrapolation:
197  pairD d2;
198  d2 = hlx->pathLength(Rctb);
199  path=d2.second;
200  if(d2.first>=0 || d2.second<=0) {
201  LOG_DEBUG <<Form("WARN MatchTrk , unexpected solution for track crossing CTB\n")<<
202  Form(" d2.firts=%f, second=%f, try first", d2.first, d2.second)<<endm;
203  path=d2.first;
204  }
205  posCTB = hlx->at(path);
206  // printf(" punch Cylinder x,y,z=%.1f, %.1f, %.1f path.second=%.1f\n",posCTB.x(),posCTB.y(),posCTB.z(),path);
207 
208 
209  Float_t phi=TMath::ATan2(posCTB.y(),posCTB.x());
210  if(phi < ctbList->MinPhi()) phi+=2*TMath::Pi();// now phi is [0,2Pi] as for CTB slats
211  Float_t eta=posCTB.pseudoRapidity();
212  //1 cout<<"#e @ctbNode xyz="<<posCTB<<" eta="<<eta<<" phi/deg="<<phi/3.1416*180<<" path/cm="<<path<<endl;
213 
214  Int_t iBin=ctbList->addTrack(eta,phi);
215  if (iBin < 0) return;
216  Bool_t ctbMatch=ctbList->isMatched(iBin);
217  Bool_t ctbVeto =ctbList->isVetoed(iBin);
218  Float_t ctbW =ctbList->getWeight(iBin);
219 
220  t->updateAnyMatch(ctbMatch,ctbVeto,t->mCtb);
221  t->weight*=ctbW;
222  t->ctbBin=iBin;
223 }
224 //________________________________________________________________________________
225 void
226 StTrack2FastDetectorMatcher::matchTrack2BEMC(const StPhysicalHelixD *hlx,StiTrack2FastDetector *t, Float_t Rxy){
227  StThreeVectorD posCyl;
228  Float_t path=-1;
229  pairD d2;
230  d2 = hlx->pathLength(Rxy);
231  path=d2.second;
232  if(d2.first>=0 || d2.second<=0) {
233 #if 0
234  printf("WARN MatchTrk , unexpected solution for track crossing Cyl\n");
235  printf(" d2.firts=%f, second=%f, try first\n",
236  d2.first, d2.second);
237 #endif
238  path=d2.first;
239  }
240  posCyl = hlx->at(path);
241  // printf(" punch Cylinder x,y,z=%.1f, %.1f, %.1f path.second=%.1f\n",posCyl.x(),posCyl.y(),posCyl.z(),path);
242 
243 
244  Float_t phi=TMath::ATan2(posCyl.y(),posCyl.x());
245  if(phi < bemcList->MinPhi()) phi+=2*TMath::Pi();// now phi is [0,2Pi] as for Cyl slats
246  Float_t eta=posCyl.pseudoRapidity();
247 
248  // cout<<"#e @bemcNode xyz="<<posCyl<<" etaDet="<<eta<<" phi/deg="<<phi/3.1416*180<<" path/cm="<<path<<endl;
249 
250  Int_t iBin=bemcList->addTrack(eta,phi);
251  if (iBin < 0) return;
252  Bool_t bemcMatch=bemcList->isMatched(iBin);
253  Bool_t bemcVeto =bemcList->isVetoed(iBin);
254  Float_t bemcW =bemcList->getWeight(iBin);
255 
256  t->updateAnyMatch(bemcMatch,bemcVeto,t->mBemc);
257  t->weight*=bemcW;
258  t->bemcBin=iBin;
259 
260 }
261 //________________________________________________________________________________
262 void
263 StTrack2FastDetectorMatcher::matchTrack2EEMC(const StPhysicalHelixD *hlx,StiTrack2FastDetector *t,Float_t z){
264 
265  const Float_t maxPath=200 ;// tmp, cut too long extrapolation
266 
267  StThreeVectorD rSmd=StThreeVectorD(0,0,z);
269  // path length at intersection with plane
270  // Double_t pathLength(const StThreeVectorD& r,
271  // const StThreeVectorD& n) const;
272 
273  Double_t path = hlx->pathLength(rSmd,n);
274  //cout<<" EEMC match: path="<<path<<endl;
275  if(path>maxPath) return; // too long extrapolation
276 
277  StThreeVectorD r = hlx->at(path);
278  Float_t periodL=hlx-> period();
279 
280  if(periodL<2*path) {
281  printf(" Warn, long path fac=%.1f ",path/periodL);
282  printf(" punchEEMC1 x,y,z=%.1f, %.1f, %.1f path=%.1f period=%.1f\n",r.x(),r.y(),r.z(),path,periodL);
283  }
284 
285  Float_t phi=TMath::ATan2(r.y(),r.x());
286  if(phi < eemcList->MinPhi()) phi+=2*TMath::Pi();// now phi is [0,2Pi] as for Cyl slats
287  Float_t eta=r.pseudoRapidity();
288 
289  Int_t iBin=eemcList->addTrack(eta,phi);
290  if (iBin < 0) return;
291  Bool_t eemcMatch=eemcList->isMatched(iBin);
292  Bool_t eemcVeto =eemcList->isVetoed(iBin);
293  Float_t eemcW =eemcList->getWeight(iBin);
294 
295  t->updateAnyMatch(eemcMatch,eemcVeto,t->mEemc);
296  t->weight*=eemcW;
297  t->eemcBin=iBin;
298 
299 }
300 //________________________________________________________________________________
301 void StTrack2FastDetectorMatcher::matchTrack2FastDetectors(const StPhysicalHelixD *hlx,StiTrack2FastDetector *t) {
302  if (btofList && btofList->NoHits()) matchTrack2BTOF(hlx,t); // matching track to btofGeometry
303  if (ctbList && ctbList->NoHits() ) matchTrack2CTB(hlx,t);
304  if (bemcList && bemcList->NoHits()) matchTrack2BEMC(hlx,t,242); // middle of tower in Rxy
305  if (eemcList && eemcList->NoHits()) matchTrack2EEMC(hlx,t,288); // middle of tower in Z
306 }
307 /**************************************************************************
308  * $Log: StTrack2FastDetectorMatcher.cxx,v $
309  * Revision 2.15 2018/04/10 11:32:10 smirnovd
310  * Minor corrections across multiple files
311  *
312  * - Remove ClassImp macro
313  * - Change white space
314  * - Correct windows newlines to unix
315  * - Remove unused debugging
316  * - Correct StTpcRTSHitMaker header guard
317  * - Remove unused preprocessor directives in StiCA
318  * - Minor changes in status and debug print out
319  * - Remove using std namespace from StiKalmanTrackFinder
320  * - Remove includes for unused headers
321  *
322  * Revision 2.14 2018/02/28 19:40:48 genevb
323  * Fix some informational output
324  *
325  * Revision 2.13 2018/02/26 23:29:50 smirnovd
326  * StTrack2FastDetectorMatcher: Build StBTOfGeometry from TGeo geometry when available
327  *
328  * Revision 2.12 2018/02/26 23:29:42 smirnovd
329  * StTrack2FastDetectorMatcher: Don't change debug level for StBTofGeometry (in a weird way)
330  *
331  * Revision 2.11 2018/02/26 23:29:33 smirnovd
332  * StTrack2FastDetectorMatcher: Remove unnecessary test for just created BTof geometry
333  *
334  * Revision 2.10 2018/01/30 13:23:42 smirnovd
335  * Revert previous changes mistakenly committed to trunk instead of a branch
336  *
337  * Revision 2.9 2018/01/29 19:49:04 smirnovd
338  * StTrack2FastDetectorMatcher: Build StBTOfGeometry from TGeo geometry when available
339  *
340  * Revision 2.8 2018/01/29 19:48:54 smirnovd
341  * StTrack2FastDetectorMatcher: Don't change debug level for StBTofGeometry (in a weird way)
342  *
343  * Revision 2.7 2018/01/29 19:48:40 smirnovd
344  * StTrack2FastDetectorMatcher: Remove unnecessary test for just created BTof geometry
345  *
346  * Revision 2.6 2018/01/03 21:24:14 smirnovd
347  * Don't use common name from std:: as local variable
348  *
349  * Revision 2.5 2013/03/22 23:29:15 genevb
350  * Initialize mTotEve to zero
351  *
352  * Revision 2.4 2013/01/18 15:03:37 fisyak
353  * Fix TrackData data name clash with StiPPVertexFinder
354  *
355  * Revision 2.3 2013/01/17 15:57:26 fisyak
356  * Add handles for debugging
357  *
358  * Revision 2.2 2012/11/06 20:54:09 fisyak
359  * Fix a bug with misplacement of TObjectSet
360  *
361  * Revision 2.1 2012/05/07 14:56:14 fisyak
362  * Add StKFVertexMaker
363  *
364  **************************************************************************/
Bool_t HelixCrossCellIds(const StHelixD &helix, IntVec &idVec, DoubleVec &pathVec, PointVec &crossVec) const
pair< double, double > pathLength(double r) const
path length at given r (cylindrical r)
Definition: StHelix.cc:351
EEMC simple geometry.
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:56