StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StEmcAssociationMaker.cxx
1 /********************************************************************************
2  *
3  * Author: Marcia Maria de Moura
4  *
5  * See README file for description
6  *
7  ********************************************************************************/
8 
9 #include "StEmcAssociationMaker.h"
10 
11 #include <Stiostream.h>
12 #include <math.h>
13 
14 #include "StEmcUtil/geometry/StEmcGeom.h"
15 #include "StMcEvent/StMcCalorimeterHit.hh"
16 #include "StMcEventTypes.hh"
17 #include "StMcEvent.hh"
18 #include "StEventTypes.h"
19 #include <StMessMgr.h>
20 
21 ClassImp(StEmcAssociation)
23 ClassImp(StEmcPointAssociation)
24 ClassImp(StEmcAssociationMaker)
25 //------------------------------------------------------------------------------
27 { mTrack = t; }
28 StEmcAssociation::~StEmcAssociation()
29 { }
30 //------------------------------------------------------------------------------
31 StEmcClusterAssociation::StEmcClusterAssociation(StMcTrack* t, StEmcCluster* c, float ft,float fe):StEmcAssociation(t)
32 { mCluster=c; mFTrack = ft; mFEmc = fe;}
33 StEmcClusterAssociation::~StEmcClusterAssociation()
34 { }
35 //------------------------------------------------------------------------------
36 StEmcPointAssociation::StEmcPointAssociation(StMcTrack* t, StEmcPoint* p, int at):StEmcAssociation(t)
37 { mPoint=p; mAssocType = at; }
38 StEmcPointAssociation::~StEmcPointAssociation()
39 { }
40 //------------------------------------------------------------------------------
41 StEmcAssociationMaker::StEmcAssociationMaker(const char* name):StMaker(name)
42 {
43  for(Int_t i=0;i<NDETECTORS;i++)
44  {
45  mTrackCluster[i] = NULL;
46  mClusterTrack[i] = NULL;
47  }
48  mTrackPoint = NULL;
49  mPointTrack = NULL;
50 
51  mPrint = kTRUE;
52 }
53 //------------------------------------------------------------------------------
54 StEmcAssociationMaker::~StEmcAssociationMaker()
55 {
56 }
57 void StEmcAssociationMaker::Clear(const char* a)
58 {
59  if(mPrint) cout <<"Cleaning old stuff from EMC association\n";
60  for(Int_t i=0;i<NDETECTORS;i++)
61  {
62  if(mPrint) cout <<"Cleaning for detector "<<i<<endl;
63  if(mTrackCluster[i])
64  {
65  for(multiEmcTrackClusterIter j=mTrackCluster[i]->begin(); j!=mTrackCluster[i]->end(); j++)
66  {
67  SafeDelete((*j).second);
68  }
69  mTrackCluster[i]->clear();
70  SafeDelete(mTrackCluster[i]);
71  mTrackCluster[i]=NULL;
72  }
73  if(mClusterTrack[i])
74  {
75  mClusterTrack[i]->clear();
76  SafeDelete(mClusterTrack[i]);
77  mClusterTrack[i]=NULL;
78  }
79  }
80  if (mPrint) cout <<"Cleaning points Association\n";
81  if(mTrackPoint)
82  {
83  for(multiEmcTrackPointIter j=mTrackPoint->begin(); j!=mTrackPoint->end(); j++)
84  {
85  SafeDelete((*j).second);
86  }
87  mTrackPoint->clear();
88  SafeDelete(mTrackPoint);
89  mTrackPoint=NULL;
90  }
91  if(mPointTrack)
92  {
93  mPointTrack->clear();
94  SafeDelete(mPointTrack);
95  mPointTrack=NULL;
96  }
97  return;
98 }
99 //------------------------------------------------------------------------------
100 Int_t StEmcAssociationMaker::Init()
101 {
102  return StMaker::Init();
103 }
104 //------------------------------------------------------------------------------
106 {
107  if(mPrint) gMessMgr->Info() << "StEmcAssociationMaker::Make()" << endm;
108 
109  // Getting McEvent object
110  StMcEvent* mcEvent= (StMcEvent*) GetDataSet("StMcEvent");
111  if (!mcEvent) return kStWarn;
112  StSPtrVecMcTrack& tracks=mcEvent->tracks();
113  if(tracks.size()==0) return kStWarn;
114 
115  // Getting Event object
116  StEvent* event=(StEvent*) GetDataSet("StEvent");
117  if (!event) return kStWarn;
118 
119  StEmcCollection* emcCollection=event->emcCollection();
120  if(!emcCollection) return kStWarn;
121 
122  // Starting doing cluster association for each detector
123  for (Int_t detnum=0; detnum<NDETECTORS; detnum++) // For detnum<4, only barrel EMC
124  {
125  if(mPrint) cout <<"Doing association for detector "<<detnum<<endl;
126  StDetectorId detId=static_cast<StDetectorId>(detnum+kBarrelEmcTowerId);
127  StEmcDetector* detector=emcCollection->detector(detId);
128  StEmcClusterCollection* clusterColl=NULL;
129  if (detector) clusterColl=detector->cluster();
130  if (clusterColl)
131  {
132  StSPtrVecEmcCluster& clusters=clusterColl->clusters();
133 
134  // Allocate cluster matching maps
135  if(mPrint) cout<<"Track size = "<<tracks.size()<<" cluster size = "<<clusters.size()<<endl;
136  if(!mTrackCluster[detnum]) mTrackCluster[detnum]=new multiEmcTrackCluster;
137  if(!mClusterTrack[detnum]) mClusterTrack[detnum]=new multiEmcClusterTrack;
138 
139  for (UInt_t i=0; i<tracks.size(); i++)
140  {
141  StPtrVecMcCalorimeterHit hits;
142  switch (detnum)
143  {
144  case 0: { hits=tracks[i]->bemcHits(); break; }
145  case 1: { hits=tracks[i]->bprsHits(); break; }
146  case 2: { hits=tracks[i]->bsmdeHits(); break; }
147  case 3: { hits=tracks[i]->bsmdpHits(); break; }
148  default: { gMessMgr->Warning()<<"Detector does not exist"<<endm; break; }
149  }
150 
151  if (hits.size()!=0){
152  // Calculating track energy by summing over hits energies
153  Float_t energy=0;
154  for (UInt_t i2=0; i2<hits.size(); i2++)
155  {
156  Float_t hitEnergy=dEToEnergy(hits[i2],detnum);
157  energy+=hitEnergy;
158  }
159 
160  for (UInt_t j=0; j<clusters.size(); j++){
161  StPtrVecEmcRawHit& clHits=clusters[j]->hit();
162  Float_t trackEnergyFraction=0;
163  Float_t clusterEnergyFraction=0;
164  Int_t assoc=0;
165  for (UInt_t k=0; k<hits.size(); k++){
166  UInt_t module=hits[k]->module();
167  UInt_t eta=hits[k]->eta();
168  Int_t sub=hits[k]->sub();
169 
170  for (UInt_t l=0; l<clHits.size(); l++){
171  UInt_t clModule=clHits[l]->module();
172  UInt_t clEta=clHits[l]->eta();
173  Int_t clSub=abs(clHits[l]->sub());
174  //Doing comparision between hit track and hit cluster
175  if (module==clModule && eta==clEta && sub==clSub){
176  assoc=1;
177  Float_t hitEnergy=dEToEnergy(hits[k],detnum);
178  trackEnergyFraction+=hitEnergy/energy;
179  Float_t clEnergy=clusters[j]->energy();
180  clusterEnergyFraction+=hitEnergy/clEnergy;
181  }
182  }
183  }
184  if (assoc) {
185  StEmcClusterAssociation *c=new StEmcClusterAssociation(tracks[i],clusters[j],trackEnergyFraction,clusterEnergyFraction);
186  mTrackCluster[detnum]->insert(multiEmcTrackClusterValue(tracks[i],c));
187 
188  mClusterTrack[detnum]->insert(multiEmcClusterTrackValue(clusters[j],c));
189  }
190  }
191  }
192  }
193  }
194  }
195  // Finishing doing cluster association
196 
197  // Starting doing point association
198  if(mPrint) cout <<"Doing point association\n";
199  StSPtrVecEmcPoint& barrelPoints=emcCollection->barrelPoints();
200  if(barrelPoints.size()!=0)
201  {
202  // Allocate point matching maps
203  if(!mTrackPoint) mTrackPoint = new multiEmcTrackPoint;
204  if(!mPointTrack) mPointTrack = new multiEmcPointTrack;
205 
206  for (UInt_t i=0; i<tracks.size(); i++)
207  {
208  StPtrVecMcCalorimeterHit hits;
209 
210  for (UInt_t j=0; j<barrelPoints.size(); j++)
211  {
212  Int_t assoc=0;
213  for(Int_t detnum=0;detnum<NDETECTORS;detnum++)
214  {
215  switch (detnum)
216  {
217  case 0: { hits=tracks[i]->bemcHits(); break; }
218  case 1: { hits=tracks[i]->bprsHits(); break; }
219  case 2: { hits=tracks[i]->bsmdeHits(); break; }
220  case 3: { hits=tracks[i]->bsmdpHits(); break; }
221  default: { gMessMgr->Warning()<<"Detector does not exist"<<endm; break; }
222  }
223  StDetectorId detId=static_cast<StDetectorId>(detnum+kBarrelEmcTowerId);
224  StPtrVecEmcCluster& cluster=barrelPoints[j]->cluster(detId);
225  for (UInt_t k=0; k<hits.size(); k++) if(hits[k])
226  {
227  UInt_t module=hits[k]->module();
228  UInt_t eta=hits[k]->eta();
229  Int_t sub=hits[k]->sub();
230 
231  for (UInt_t j2=0; j2<cluster.size(); j2++) if(cluster[j2])
232  {
233  StPtrVecEmcRawHit& clHit=cluster[j2]->hit();
234  for (UInt_t l=0; l<clHit.size(); l++) if(clHit[l])
235  {
236  UInt_t clModule=clHit[l]->module();
237  UInt_t clEta=clHit[l]->eta();
238  Int_t clSub=abs(clHit[l]->sub());
239 
240  //Doing comparision between hit track and hit cluster from a point
241  if (module==clModule && eta==clEta && sub==clSub) { assoc+=(1<<(detnum)); goto nextDetector;}
242  }
243  }
244  }
245  nextDetector: continue;
246  }
247  if (assoc) {
248  StEmcPointAssociation *p= new StEmcPointAssociation(tracks[i],barrelPoints[j],assoc);
249  mTrackPoint->insert(multiEmcTrackPointValue(tracks[i],p));
250  mPointTrack->insert(multiEmcPointTrackValue(barrelPoints[j],p));
251  }
252  }
253  }
254  }
255  // Finishing doing point association
256  return kStOK;
257 }
258 //------------------------------------------------------------------------------
260 {
261  // Finishing the maker
262  gMessMgr->Info() << "StEmcAssociationMaker::Finish()" << endm;
263  return kStOK;
264 }
265 //------------------------------------------------------------------------------
266 Float_t StEmcAssociationMaker::dEToEnergy(StMcCalorimeterHit* hit, Int_t detnum)
267 {
268  // Get hit deposited energy and convert to energy for each EMC detector.
269 
270  Float_t P0[]={14.69,559.7,0.1185e6,0.1260e6};
271  Float_t P1[]={-0.1022,-109.9,-0.3292e5,-0.1395e5};
272  Float_t P2[]={0.7484,-97.81,0.3113e5,0.1971e5};
273 
274  UInt_t m=hit->module();
275  UInt_t e=hit->eta();
276  Float_t dE=hit->dE();
277  Float_t hitEnergy = 0;
278 
279  StEmcGeom* emcGeom=StEmcGeom::instance(detnum+1);
280  Float_t Eta;
281  emcGeom->getEta(m,e,Eta);
282  Float_t x=fabs(Eta);
283  Float_t sf=P0[detnum]+P1[detnum]*x+P2[detnum]*x*x;
284  hitEnergy=dE*sf;
285  if (hitEnergy<=0) hitEnergy=0;
286  return hitEnergy;
287 }
288 //---------------------------------------------------------------------
289 multiEmcTrackCluster* StEmcAssociationMaker::getTrackClusterMap(const char* detname)
290 {
291  Int_t det = getDetNum(detname);
292  if(det>0) return mTrackCluster[det-1];
293  return NULL;
294 }
295 //---------------------------------------------------------------------
296 multiEmcClusterTrack* StEmcAssociationMaker::getClusterTrackMap(const char* detname)
297 {
298  Int_t det = getDetNum(detname);
299  if(det>0) return mClusterTrack[det-1];
300  return NULL;
301 }
302 //---------------------------------------------------------------------
303 Int_t StEmcAssociationMaker::getDetNum(const char* detname)
304 {
305  const TString det[] = {"bemc","bprs","bsmde","bsmdp"};
306  Int_t detnum = 0;
307  for (Int_t i=0; i<NDETECTORS; i++)
308  if (!strcmp(detname,det[i])) detnum = i+1;
309  return detnum;
310 }
311 //---------------------------------------------------------------------
312 void StEmcAssociationMaker::printMaps()
313 {
314  const TString det[] = {"bemc","bprs","bsmde","bsmdp"};
315  for(int i=0;i<NDETECTORS;i++)
316  {
317  cout <<"-----------------------------------------------------------\n";
318  cout <<"ASSOCIATION FOR DETECTOR "<<det[i].Data()<<endl;
319  multiEmcTrackCluster* map = getTrackClusterMap(i+1);
320  if(map)
321  {
322  cout <<"Track->Cluster Association Map\n";
323  for(multiEmcTrackClusterIter j=map->begin(); j!=map->end(); j++)
324  {
325  StMcTrack* track = (StMcTrack*)(*j).first;
326  StEmcClusterAssociation* value = (StEmcClusterAssociation*)(*j).second;
327  if(track && value)
328  {
329  StEmcCluster *c = (StEmcCluster*) value->getCluster();
330 
331  if(c)
332  {
333  cout <<" McTrack = "<<track<<" GeantId = "<<track->geantId()<<" pt = "<<track->pt()<<" TReta = "<<track->pseudoRapidity()
334  <<" Cl = "<<c<<" E = "<<c->energy()<<" eta = "<<c->eta()<<" phi = "<<c->phi()
335  <<" FrTr = "<<value->getFractionTrack()<<" FrCl = "<<value->getFractionCluster()<<endl;
336  }
337  }
338  }
339  }
340  cout <<endl;
341  multiEmcClusterTrack* map1 = getClusterTrackMap(i+1);
342  if(map1)
343  {
344  cout <<"Cluster->Track Association Map\n";
345  for(multiEmcClusterTrackIter j=map1->begin(); j!=map1->end(); j++)
346  {
347  StEmcCluster *c = (StEmcCluster*)(*j).first;
348  StEmcClusterAssociation* value = (StEmcClusterAssociation*)(*j).second;
349  if(c && value)
350  {
351  StMcTrack* track = (StMcTrack*)value->getTrack();
352  if(track)
353  {
354  cout <<" Cl = "<<c<<" E = "<<c->energy()<<" eta = "<<c->eta()<<" phi = "<<c->phi()
355  <<" McTrack = "<<track<<" GeantId = "<<track->geantId()<<" pt = "<<track->pt()<<" TReta = "<<track->pseudoRapidity()
356  <<" FrTr = "<<value->getFractionTrack()<<" FrCl = "<<value->getFractionCluster()<<endl;
357  }
358  }
359  }
360  }
361  }
362  multiEmcTrackPoint *mapPoint = getTrackPointMap();
363  if(mapPoint)
364  {
365  cout <<"Track->Point Association Map\n";
366  for(multiEmcTrackPointIter j = mapPoint->begin(); j!=mapPoint->end(); j++)
367  {
368  StMcTrack *track = (StMcTrack*)(*j).first;
369  StEmcPointAssociation *value = (StEmcPointAssociation*)(*j).second;
370  if(value)
371  {
372  StEmcPoint *point = (StEmcPoint*)value->getPoint();
373  if(track && point)
374  {
375  cout <<" McTrack = "<<track<<" GeantId = "<<track->geantId()<<" pt = "<<track->pt()<<" TReta = "<<track->pseudoRapidity()
376  <<" Point = "<<point<<" E = "<<point->energy()
377  <<" Assoc. = "<<value->getAssociation();
378  for(int i=1;i<=4;i++) cout <<" det "<<i<<" A = "<< value->getAssociation(i);
379  cout <<endl;
380  }
381  }
382  }
383  }
384  multiEmcPointTrack *mapPoint1 = getPointTrackMap();
385  if(mapPoint1)
386  {
387  cout <<"Point->Track Association Map\n";
388  for(multiEmcPointTrackIter j = mapPoint1->begin(); j!=mapPoint1->end(); j++)
389  {
390  StEmcPoint *point = (StEmcPoint*)(*j).first;
391  StEmcPointAssociation *value = (StEmcPointAssociation*)(*j).second;
392  if(value)
393  {
394  StMcTrack *track = (StMcTrack*)value->getTrack();
395  if(track && point)
396  {
397  cout <<" McTrack = "<<track<<" GeantId = "<<track->geantId()<<" pt = "<<track->pt()<<" TReta = "<<track->pseudoRapidity()
398  <<" Point = "<<point<<" E = "<<point->energy()
399  <<" Assoc. = "<<value->getAssociation();
400  for(int i=1;i<=4;i++) cout <<" det "<<i<<" A = "<< value->getAssociation(i);
401  cout <<endl;
402  }
403  }
404  }
405  }
406 }
407 void StEmcAssociationMaker::printTracks()
408 {
409  StMcEvent* mcEvent=(StMcEvent*) GetDataSet("StMcEvent");
410  if (!mcEvent) return;
411  StSPtrVecMcTrack& tracks=mcEvent->tracks();
412  if(tracks.size()==0) return;
413 
414  StMcVertex *v = mcEvent->primaryVertex();
415  if(v)
416  {
417  cout<<"Primary Vertex (x,y,z) = "<<v->position().x()<<" "<<v->position().y()<<" "<<v->position().z()<<" "<<endl;
418  }
419  for(UInt_t i = 0; i<tracks.size();i++)
420  {
421  cout <<"Track " <<tracks[i]<<" Geant Id = "<<tracks[i]->geantId()<<" pT = "<< tracks[i]->pt()
422  <<" eta = "<<tracks[i]->pseudoRapidity()
423  <<" phi = "<<tracks[i]->momentum().phi()<<endl;
424  cout <<" Parent = "<<tracks[i]->parent()<<endl;
425  v = tracks[i]->startVertex();
426  if(v) cout <<" Start vertex (x,y,z) = "<<v->position().x()<<" "<<v->position().y()<<" "<<v->position().z()<<" "<<endl;
427  v = tracks[i]->stopVertex();
428  if(v) cout <<" Stop vertex (x,y,z) = "<<v->position().x()<<" "<<v->position().y()<<" "<<v->position().z()<<" "<<endl;
429  }
430 }
multiEmcTrackCluster * getTrackClusterMap(Int_t i)
returns multimap for association betwwen MC tracks and clusters
Int_t getDetNum(const char *)
returns detector number for each EMC sub detector
Monte Carlo Track class All information on a simulated track is stored in this class: kinematics...
Definition: StMcTrack.hh:144
multiEmcPointTrack * getPointTrackMap()
returns multimap for association betwwen points and MC tracks
Definition: Stypes.h:42
Definition: Stypes.h:40
multiEmcClusterTrack * getClusterTrackMap(Int_t i)
returns multimap for association betwwen clusters and MC tracks
multiEmcTrackPoint * getTrackPointMap()
returns multimap for association betwwen MC tracks and points
Event data structure to hold all information from a Monte Carlo simulation. This class is the interfa...
Definition: StMcEvent.hh:169