StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StGammaCandidate.cxx
1 // //
3 // Note that, when calculating the isolation sums, //
4 // the candidate momentum, tower eta and track eta //
5 // have been corrected for vertex so that the //
6 // dR comparisons are in fact consistent //
7 // //
9 
10 #include "StEEmcUtil/EEmcGeom/EEmcGeomSimple.h"
11 #include "StEEmcUtil/StEEmcSmd/EEmcSmdGeom.h"
12 #include "StGammaEEmcLeakage.h"
13 
14 #include "StGammaCandidate.h"
15 
16 #include "TVector3.h"
17 
18 ClassImp(StGammaCandidate);
19 
21 // Constructor //
23 StGammaCandidate::StGammaCandidate()
24 {
25 
26  SetId(0);
27  SetTowerId(0);
28  SetTowerClusterId(0);
29  SetSmduClusterId(0);
30  SetSmdvClusterId(0);
31  SetDetectorId(0);
32 
33  SetMomentum( TVector3(0.,0.,0.) );
34  SetPosition( TVector3(0.,0.,0.) );
35  SetEnergy(0.);
36  SetSeedEnergy(0.);
37  SetPre1Energy(0.);
38  SetPre2Energy(0.);
39  SetPostEnergy(0.);
40  SetSmduEnergy(0.);
41  SetSmdvEnergy(0.);
42 
43 }
44 
46 // Destructor //
48 StGammaCandidate::~StGammaCandidate()
49 {}
50 
52 // Return the total track pT and tower eT //
53 // within a cone of the given radius around //
54 // the candidate //
56 
57 Float_t StGammaCandidate::sumPt(Float_t radius, Float_t threshold, thresholdCut cut)
58 {
59  Float_t sumTracks = sumTrackPt(radius, threshold, cut);
60  Float_t sumTowers = sumTowerPt(radius, threshold, cut);
61  return sumTracks + sumTowers;
62 }
63 
65 // Return the total track pT within a cone //
66 // of the given radius around the candidate, //
67 // subject to a threshold requirement (in GeV) //
69 
70 Float_t StGammaCandidate::sumTrackPt(Float_t radius, Float_t threshold, thresholdCut cut)
71 {
72 
73  Float_t sum = 0.0;
74  Float_t myEta = mMomentum.Eta();
75  Float_t myPhi = mMomentum.Phi();
76 
77  for(Int_t i = 0; i < numberOfTracks(); i++)
78  {
79 
80  StGammaTrack *t = track(i);
81 
82  Float_t dEta = myEta - t->eta();
83  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi());
84  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
85 
86  if(cut == kMagnitude) if(r <= radius && t->momentum.Mag() > threshold) sum += t->pt();
87  if(cut == kTransverse) if(r <= radius && t->pt() > threshold) sum += t->pt();
88 
89  }
90 
91  return sum;
92 
93 }
94 
96 // Return the total tower Et within a cone //
97 // of the given radius around the candidate //
98 // subject to a threshold requirement (in GeV) //
100 
101 Float_t StGammaCandidate::sumTowerPt(Float_t radius, Float_t threshold, thresholdCut cut)
102 {
103 
104  Float_t sum = 0.0;
105  Float_t myEta = mMomentum.Eta();
106  Float_t myPhi = mMomentum.Phi();
107 
108  for(Int_t i = 0; i < numberOfTowers(); i++)
109  {
110 
111  StGammaTower *t = tower(i);
112  if(t->fail) continue;
113 
114  Float_t dEta = myEta - t->eta;
115  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi);
116  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
117 
118  if(cut == kMagnitude) if(r <= radius && t->energy > threshold) sum += t->pt();
119  if(cut == kTransverse) if(r <= radius && t->pt() > threshold) sum += t->pt();
120 
121  }
122 
123  return sum;
124 
125 }
126 
128 // Return the total preshower Et within a cone //
129 // of the given radius around the candidate //
130 // subject to a threshold requirement (in GeV) //
132 
133 Float_t StGammaCandidate::sumPreshower1(Float_t radius, Float_t threshold)
134 {
135 
136  Float_t sum = 0.;
137  Float_t myEta = mMomentum.Eta();
138  Float_t myPhi = mMomentum.Phi();
139 
140  for(Int_t i = 0; i < numberOfPreshower1(); i++)
141  {
142 
143  StGammaTower *t = preshower1(i);
144  if(t->fail) continue;
145 
146  Float_t dEta = myEta - t->eta;
147  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi);
148  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
149 
150  if(r <= radius && t->energy > threshold) sum += t->pt();
151 
152  }
153 
154  return sum;
155 
156 }
157 
159 // Return the total preshower Et within a cone //
160 // of the given radius around the candidate //
161 // subject to a threshold requirement (in GeV) //
163 
164 Float_t StGammaCandidate::sumPreshower2(Float_t radius, Float_t threshold)
165 {
166 
167  Float_t sum = 0.0;
168  Float_t myEta = mMomentum.Eta();
169  Float_t myPhi = mMomentum.Phi();
170 
171  for(Int_t i = 0; i < numberOfPreshower2(); i++)
172  {
173 
174  StGammaTower *t = preshower2(i);
175  if(t->fail) continue;
176 
177  Float_t dEta = myEta - t->eta;
178  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi);
179  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
180 
181  if(r <= radius && t->energy > threshold) sum += t->pt();
182 
183  }
184 
185  return sum;
186 
187 }
188 
190 // Return the total postshower Et within a cone //
191 // of the given radius around the candidate //
192 // subject to a threshold requirement (in GeV) //
194 
195 Float_t StGammaCandidate::sumPostshower(Float_t radius, Float_t threshold)
196 {
197 
198  Float_t sum = 0.0;
199  Float_t myEta = mMomentum.Eta();
200  Float_t myPhi = mMomentum.Phi();
201 
202  for(Int_t i = 0; i < numberOfPostshower(); i++)
203  {
204 
205  StGammaTower *t = postshower(i);
206  if (t->fail) continue;
207 
208  Float_t dEta = myEta - t->eta;
209  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi);
210  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
211 
212  if (r <= radius && t->energy > threshold) sum += t->pt();
213 
214  }
215 
216  return sum;
217 
218 }
219 
221 // Return the number of tracks within a cone //
222 // of the given radius around the candidate //
223 // subject to a threshold requirement (in GeV) //
225 
226 Int_t StGammaCandidate::numberOfTracks(Float_t radius, Float_t threshold, thresholdCut cut)
227 {
228 
229  Int_t count = 0;
230  Float_t myEta = mMomentum.Eta();
231  Float_t myPhi = mMomentum.Phi();
232 
233  for (Int_t i = 0; i < numberOfTracks(); i++)
234  {
235 
236  StGammaTrack *t = track(i);
237 
238  Float_t dEta = myEta - t->eta();
239  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi());
240  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
241 
242  if(cut == kMagnitude) if(r <= radius && t->momentum.Mag() > threshold) ++count;
243  if(cut == kTransverse) if(r <= radius && t->pt() > threshold) ++count;
244 
245  }
246 
247  return count;
248 
249 }
250 
252 // Return the number of towers within a cone //
253 // of the given radius around the candidate //
254 // subject to a threshold requirement (in GeV) //
256 
257 Int_t StGammaCandidate::numberOfTowers(Float_t radius, Float_t threshold, thresholdCut cut)
258 {
259 
260  Int_t count = 0;
261  Float_t myEta = mMomentum.Eta();
262  Float_t myPhi = mMomentum.Phi();
263 
264  for(Int_t i = 0; i < numberOfTowers(); i++)
265  {
266 
267  StGammaTower *t = tower(i);
268  if(t->fail) continue;
269 
270  Float_t dEta = myEta - t->eta;
271  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi);
272  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
273 
274  if(cut == kMagnitude) if(r <= radius && t->energy > threshold) ++count;
275  if(cut == kTransverse) if(r <= radius && t->pt() > threshold) ++count;
276 
277  }
278 
279  return count;
280 
281 }
282 
284 // Return the number of preshowers within a cone//
285 // of the given radius around the candidate //
286 // subject to a threshold requirement (in GeV) //
288 
289 Int_t StGammaCandidate::numberOfPreshower1(Float_t radius, Float_t threshold)
290 {
291 
292  Int_t count = 0;
293  Float_t myEta = mMomentum.Eta();
294  Float_t myPhi = mMomentum.Phi();
295 
296  for(Int_t i = 0; i < numberOfPreshower1(); i++)
297  {
298 
299  StGammaTower *t = preshower1(i);
300 
301  Float_t dEta = myEta - t->eta;
302  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi);
303  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
304 
305  if(r <= radius && t->energy > threshold) ++count;
306 
307  }
308 
309  return count;
310 
311 }
312 
314 // Return the number of preshowers within a cone//
315 // of the given radius around the candidate //
316 // subject to a threshold requirement (in GeV) //
318 
319 Int_t StGammaCandidate::numberOfPreshower2(Float_t radius, Float_t threshold)
320 {
321 
322  Int_t count = 0;
323  Float_t myEta = mMomentum.Eta();
324  Float_t myPhi = mMomentum.Phi();
325 
326  for(Int_t i = 0; i < numberOfPreshower2(); i++)
327  {
328 
329  StGammaTower *t = preshower2(i);
330 
331  Float_t dEta = myEta - t->eta;
332  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi);
333  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
334 
335  if(r <= radius && t->energy > threshold) ++count;
336 
337  }
338 
339  return count;
340 
341 }
342 
344 // Return the number of postshowers within a //
345 // cone of the given radius around the candidate//
346 // subject to a threshold requirement (in GeV) //
348 
349 Int_t StGammaCandidate::numberOfPostshower(Float_t radius, Float_t threshold)
350 {
351 
352  Int_t count = 0;
353  Float_t myEta = mMomentum.Eta();
354  Float_t myPhi = mMomentum.Phi();
355 
356  for(Int_t i = 0; i < numberOfPostshower(); i++)
357  {
358 
359  StGammaTower *t = postshower(i);
360 
361  Float_t dEta = myEta - t->eta;
362  Float_t dPhi = TVector2::Phi_mpi_pi(myPhi - t->phi);
363  Float_t r = TMath::Sqrt(dEta * dEta + dPhi * dPhi);
364 
365  if(r <= radius && t->energy > threshold) ++count;
366  }
367 
368  return count;
369 
370 }
371 
373 // Return cluster preshower 1 energy //
374 // subject to a threshold requirement (in GeV) //
376 
377 Float_t StGammaCandidate::pre1Energy(Float_t threshold)
378 {
379 
380  mPre1Energy = 0;
381 
382  for(Int_t i = 0; i < numberOfMyPreshower1(); i++)
383  {
384 
385  StGammaTower *t = mypreshower1(i);
386  if(t->fail) continue;
387 
388  if(t->energy > threshold) mPre1Energy += t->energy;
389 
390  }
391 
392  return mPre1Energy;
393 
394 }
395 
397 // Return cluster preshower 2 energy //
398 // subject to a threshold requirement (in GeV) //
400 
401 Float_t StGammaCandidate::pre2Energy(Float_t threshold)
402 {
403 
404  mPre2Energy = 0;
405 
406  for(Int_t i = 0; i < numberOfMyPreshower2(); i++)
407  {
408 
409  StGammaTower *t = mypreshower2(i);
410  if(t->fail) continue;
411 
412  if(t->energy > threshold) mPre2Energy += t->energy;
413 
414  }
415 
416  return mPre2Energy;
417 
418 }
419 
421 // Return cluster postshower energy //
422 // subject to a threshold requirement (in GeV) //
424 
425 Float_t StGammaCandidate::postEnergy(Float_t threshold)
426 {
427 
428  mPostEnergy = 0;
429 
430  for(Int_t i = 0; i < numberOfMyPostshower(); i++)
431  {
432 
433  StGammaTower *t = mypostshower(i);
434  if(t->fail) continue;
435 
436  if(t->energy > threshold) mPostEnergy += t->energy;
437 
438  }
439 
440  return mPostEnergy;
441 
442 }
443 
445 // Return cluster Smd(U/Eta) energy //
446 // subject to a threshold requirement (in GeV) //
448 
449 Float_t StGammaCandidate::smduEnergy(Float_t threshold)
450 {
451 
452  mSmduEnergy = 0;
453 
454  for(Int_t i = 0; i < numberOfSmdu(); i++)
455  {
456 
457  StGammaStrip *t = smdu(i);
458  if(t->fail) continue;
459 
460  if(t->energy > threshold) mSmduEnergy += t->energy;
461 
462  }
463 
464  return mSmduEnergy;
465 
466 }
467 
469 // Return cluster Smd(V/Phi) energy //
470 // subject to a threshold requirement (in GeV) //
472 
473 Float_t StGammaCandidate::smdvEnergy(Float_t threshold)
474 {
475 
476  mSmdvEnergy = 0;
477 
478  for(Int_t i = 0; i < numberOfSmdv(); i++)
479  {
480 
481  StGammaStrip *t = smdv(i);
482  if(t->fail) continue;
483 
484  if(t->energy > threshold) mSmdvEnergy += t->energy;
485 
486  }
487 
488  return mSmdvEnergy;
489 
490 }
491 
493 // Auxiliary struct and function for //
494 // sorting towers by distance //
496 struct Tower
497 {
498  StGammaTower *tower;
499  Float_t dR;
500 };
501 
502 Bool_t SortDistance(const Tower& t1, const Tower& t2)
503 {
504  return (t1.dR < t2.dR);
505 }
506 
508 // Recluster, computing cluster positon, //
509 // momentum, and energy after exluding towers //
510 // below a given threshold (in GeV) //
512 
513 void StGammaCandidate::recluster(TVector3 vertex, Float_t threshold, thresholdCut cut)
514 {
515 
516  mEnergy = 0.0;
517  mPosition.SetPtEtaPhi(0, 0, 0);
518 
519  for(Int_t i = 0; i < numberOfMyTowers(); ++i)
520  {
521 
522  StGammaTower *t = mytower(i);
523 
524  if(t->fail)continue;
525 
526  if(cut == kMagnitude) if(t->energy < threshold) continue;
527  if(cut == kTransverse) if(t->pt() < threshold) continue;
528 
529  TVector3 tower;
530  tower.SetPtEtaPhi(t->pt(), t->eta, t->phi);
531 
532  mPosition += tower * t->energy;
533  mEnergy += t->energy;
534 
535  }
536 
537  mPosition *= 1.0 / mEnergy;
538 
539  mMomentum = mPosition - vertex;
540  mMomentum.SetMag(mEnergy);
541 
542  return;
543 
544 }
545 
547 // Return momentum using the seed tower only //
549 TVector3 StGammaCandidate::momentum1x1()
550 {
551  return mMomentum.Unit() * mSeedEnergy;
552 }
553 
555 // Return momentum using the seed tower //
556 // with leakage correction (EEMC only) //
558 TVector3 StGammaCandidate::momentum1x1c()
559 {
560 
561  // Perform light leakage correction w/in the EEmc
562  if(detectorId() == kEEmc)
563  {
564 
565  static StGammaEEmcLeakage *shape = StGammaEEmcLeakage::instance();
566  static EEmcGeomSimple &geom = EEmcGeomSimple::Instance();
567 
568  Int_t sec,sub,eta;
569  if(!geom.getTower( position(), sec, sub, eta )) return TVector3(0.0, 0.0, -999.0);
570 
571  TVector3 tower = geom.getTowerCenter( (UInt_t)sec, (UInt_t)sub, (UInt_t)eta );
572 
573  Float_t frac = shape->expectation( position() );
574  TVector3 p=momentum1x1();
575  p *= 1.0 / frac;
576 
577  return p;
578 
579  }
580  else
581  {
582  // to be implemented
583  }
584 
585  return momentum1x1();
586 
587 }
588 
590 // Return momentum using the seed tower //
591 // with leakage correction plus the most //
592 // energetic neighboring tower(EEMC only) //
594 TVector3 StGammaCandidate::momentum2x1()
595 {
596 
597  Float_t eta = mMomentum.Eta();
598  Float_t phi = mMomentum.Phi();
599 
600  // Create Tower structs for each cluster tower
601  std::vector<Tower> listOfTowers;
602  for(Int_t i = 0; i < numberOfMyTowers(); i++)
603  {
604 
605  StGammaTower *t = mytower(i);
606  Float_t deta = eta - t->eta;
607  Float_t dphi = TVector2::Phi_mpi_pi(phi - t->phi);
608  Float_t dR = TMath::Sqrt(deta * deta + dphi * dphi);
609  Tower T = { t, dR };
610  listOfTowers.push_back(T);
611 
612  }
613 
614  // Sort Tower structs by energy
615  std::sort(listOfTowers.begin(), listOfTowers.end(), SortDistance);
616  std::vector<Tower>::iterator iter;
617 
618  Float_t energy_sum = 0.0;
619  Int_t count = 0;
620 
621  // Sum the energy from the two highest towers
622  for(iter=listOfTowers.begin(); iter != listOfTowers.end(); iter++)
623  {
624  if(count < 2) energy_sum += (*iter).tower->energy;
625  count++;
626  }
627 
628  TVector3 p = mMomentum;
629  p.SetMag(energy_sum);
630 
631  return p;
632 
633 }
634 
TVector3 getTowerCenter(const UInt_t sec, const UInt_t sub, const UInt_t etabin) const
Float_t mPostEnergy
Energy deposited in epre2 (possibly tof?)
Float_t mSeedEnergy
Energy of the gamma candidate.
static EEmcGeomSimple & Instance()
returns a reference to a static instance of EEmcGeomSimple
Float_t mPre1Energy
Energy of the seed tower.
TVector3 mPosition
Momentum of the gamma candidate.
Float_t mSmduEnergy
Energy deposited in epost.
Float_t mSmdvEnergy
Energy deposited in esmdu (or bsmd eta)
Float_t mEnergy
Position of the gamma at z (r) = SMD.
Float_t pt() const
Referencing candidates.
Definition: StGammaTrack.h:62
EEMC simple geometry.
Float_t phi() const
eta at vertex
Definition: StGammaTrack.h:65
TVector3 mMomentum
0=EEMC 1=BEMC
bool getTower(const TVector3 &r, int &sec, int &sub, int &etabin, Float_t &dphi, Float_t &deta) const
Float_t mPre2Energy
Energy deposited in epre1 (or bprs)
Float_t eta() const
pz at vertex
Definition: StGammaTrack.h:64
Float_t expectation(const TVector3 &gamma)