FairRoot/PandaRoot
PndEmcDigi.cxx
Go to the documentation of this file.
1 //
3 //--------------------------------------------------------------------------
4 // File and Version Information:
5 // $Id:$
6 //
7 // Description:
8 // EMC Digi.
9 //
10 // Software developed for the BaBar Detector at the SLAC B-Factory.
11 // Adapted for the PANDA experiment at GSI
12 //
13 // Author List:
14 // Xiaorong Shi Lawrence Livermore National Lab
15 // Stephen J. Gowdy University of Edinburgh
16 // Dima Melnichuk - adaption for PANDA
17 //
18 // Copyright Information:
19 // Copyright (C) 1996 Lawrence Livermore National Lab
20 //
22 
23 #include "PndEmcDigi.h"
24 #include "PndEmcSharedDigi.h"
25 #include "PndEmcMapper.h"
26 #include "PndEmcStructure.h"
27 #include "PndEmcXtal.h"
28 #include "PndEmcDataTypes.h"
29 #include "PndDetectorList.h"
30 #include <iostream>
31 
32 #include "TClass.h"
33 #include "TVector3.h"
34 #include "TBuffer.h"
35 #include "Riostream.h"
36 
37 using namespace std;
38 TClonesArray* PndEmcDigi::fDigiArrayTBD = NULL;//new TClonesArray("PndEmcDigi");
39 // ----- Default constructor -----------------------------------
40 PndEmcDigi::PndEmcDigi():FairTimeStamp(0), fEvtNo(-1),fEnergy(0),fTrackId(-1),fDetectorId(-1),fHitIndex(-1),fWhere(0,0,0), fThetaInd(0), fPhiInd(0),fTheta(0), fPhi(0)
41 {
42 }
43 // -----------------------------------------------------------------
44 
45 
46 // ----- Destructor --------------------------------------------
48 // -----------------------------------------------------------------
49 
50 PndEmcDigi::PndEmcDigi(Int_t trackid, Int_t id, Float_t energy, Float_t time, Int_t hitIndex):FairTimeStamp(time),fEnergy(energy),fTrackId(trackid),fDetectorId(id),fHitIndex(hitIndex),fWhere(0,0,0), fThetaInd(0), fPhiInd(0),fTheta(0), fPhi(0)
51 {
53  PndEmcTwoCoordIndex* tci=emcMap->GetTCI(id);
54  fThetaInd=tci->XCoord();
55  fPhiInd=tci->YCoord();
56 
58  PndEmcXtal* xtal = tciXtalMap.find(tci)->second;
59  fWhere = algPointer()(xtal);
60  fTheta = fWhere.Theta();
61  fPhi = fWhere.Phi();
62  SetLink(FairLink(-1, FairRootManager::Instance()->GetEntryNr(), "EmcHit", hitIndex));
63 }
64 
65 //
66 // From another Digi
67 //
68 
70 : FairTimeStamp(other), fEvtNo(other.fEvtNo),
71  fEnergy( other.fEnergy ),
72  fTrackId(other.fTrackId),
73  fDetectorId( other.fDetectorId),
74  fHitIndex( other.fHitIndex), fWhere(0,0,0),
75  fThetaInd(0), fPhiInd(0),fTheta(0),fPhi(0)
76 {
79  fThetaInd=tci->XCoord();
80  fPhiInd=tci->YCoord();
81 
83  PndEmcXtal* xtal = tciXtalMap.find(tci)->second;
84  fWhere = algPointer()(xtal);
85  fTheta = fWhere.Theta();
86  fPhi = fWhere.Phi();
87 }
88 
90 {
91  if (fDigiArrayTBD==NULL)
92  fDigiArrayTBD = new TClonesArray("PndEmcDigi");
93 }
94 
96 {
97 // PndEmcMapper assumed to instantiate first time with correct parameter before
99  PndEmcTwoCoordIndex* tci=emcMap->GetTCI(id);
100  fThetaInd=tci->XCoord();
101  fPhiInd=tci->YCoord();
102  fDetectorId=id;
103 
104  fThetaInd=tci->XCoord();
105  fPhiInd=tci->YCoord();
106 
108  PndEmcXtal* xtal = tciXtalMap.find(tci)->second;
109  fWhere = algPointer()(xtal);
110  fTheta = fWhere.Theta();
111  fPhi = fWhere.Phi();
112 
113 }
114 
115 
116 //in case of a timebased simulation framework, a crystal might be counted twice in a cluster.
117 //In order to use subsequent eventbased algorithms, use AbsorbEnergy to merge these.
119  if(otherDigi.equal(this)) {
120  fEnergy += otherDigi.GetEnergy();
121  } else {
122  std::cerr << "-E- in PndEmcDigi::AbsorbEnergy Mismatch in DetectorId. Cannot absorb energy." << std::endl;
123  }
124 }
125 
126 
127 TVector3
129 {
130  return xtal->frontCentre();
131 }
132 
133 TVector3
135 {
136  //cout << "depth" << endl;
137 
138  TVector3 pos = xtal->frontCentre();
139  TVector3 norm = xtal->axisVector();
140  int module=xtal->myIndex()->Index()/100000000;
141 
142  if (module==5) //shahslyk
144  else
145  norm*=fPositionDepthPWO;
146 
147  pos += norm;
148 
149  return pos;
150 }
151 
152 void
154  double positionDepthPWO,
155  double positionDepthShashlyk,
156  double rescaleFactor)
157 {
158 
159  TVector3 (*algorithm)( const PndEmcXtal* ) = 0;
160 
161  switch ( alg )
162  {
163  case surface:
164  algorithm = PndEmcDigi::surfacePosition;
165  fRescaleFactor = rescaleFactor;
166  fPositionDepthPWO = positionDepthPWO;
167  fPositionDepthShashlyk = positionDepthShashlyk;
168  break;
169 
170  case depth:
171  algorithm = PndEmcDigi::depthPosition;
172  fRescaleFactor = rescaleFactor;
173  fPositionDepthPWO = positionDepthPWO;
174  fPositionDepthShashlyk = positionDepthShashlyk;
175  break;
176 
177  default:
178  cout << "PndEmcDigi::selectDigiPositionMethod. "
179  << "Attempted to select unknown digi position method."
180  << endl;
181  }
182 
183  // Now actually set the pointer
184  algPointer() = algorithm;
185 }
186 
187 //Set the default digi position method
188 
189 TVector3 ( *&PndEmcDigi::algPointer() ) ( const PndEmcXtal* )
190 {
191  static TVector3 (*pointer) ( const PndEmcXtal* ) = PndEmcDigi::depthPosition;
192 
193  return pointer;
194 }
195 
196 double PndEmcDigi::fRescaleFactor = 1.0;
197 double PndEmcDigi::fPositionDepthPWO = 6.2;
199 
200 
201 bool PndEmcDigi::isNeighbour( const PndEmcDigi* theDigi ) const
202 {
203  PndEmcMapper::Instance(); //: unused variable?PndEmcMapper *emcMap= //[R.K.03/2017] unused variable
204  PndEmcTwoCoordIndex* tci=this->GetTCI();
205 
206  if ((theDigi->GetTCI()==0)||(tci==0)){
207  std::cout<<"TwoCoordIndex of digi is not defined"<<std::endl;
208  abort();
209  }
210 
211  if (tci->IsNeighbour(theDigi->GetTCI())) return true;
212 
213  return false;
214 }
215 
217 {
219  PndEmcTwoCoordIndex* tci=emcMap->GetTCI(fDetectorId);
220  return tci;
221 };
222 
223 Short_t PndEmcDigi::GetXPad() const {
224  // Return the X pad value for clusterization
225 
226  // Barrel EMC
227  if (GetModule()==1 || GetModule()==2)
228  return (GetCrystal()+(GetCopy()-1)*10);
229 
230  // BwEndCap and forward EMC
231  if ((GetModule()==4) || (GetModule()==5))
232  {
233  if (GetCopy()==1) { return -GetRow()+1;}
234  if (GetCopy()==2) { return -GetRow()+1; }
235  if (GetCopy()==3) { return GetRow();}
236  if (GetCopy()==4) { return GetRow();}
237  }
238 
239  // FwEndCap
240  if (GetModule()==3)
241  return -(GetCrystal()-36);//the minus sign before the paranthesis
242  //is introduced since the geometry of
243  //FwEndCap gets rotated by 180 deg
244  //around the y-axis in PndEmc.cxx;
245 
246  //this rotation was done in turn due to the way the geometry was
247  //defined in the geometry file of the forward end cap
248 
249  /*
250  if (GetModule()==3 && GetCrystal()==999 && GetRow()==999)
251  return GetCrystal();
252  */
253 
254  // Test EMC
255  if (GetModule()==6)
256  return GetRow();
257 
258  return -1000; // failure
259 }
260 
261 Short_t PndEmcDigi::GetYPad() const {
262  // Return the Y pad value for clusterization
263 
264  // Barrel EMC
265  if (GetModule()==1)
266  return (GetRow()+29);
267 
268  if (GetModule()==2)
269  return (-GetRow()+30);
270 
271  // BwEndCap and forward EMC
272  if ((GetModule()==4) || (GetModule()==5))
273  {
274  if (GetCopy()==1) { return GetCrystal(); }
275  if (GetCopy()==2) { return -GetCrystal() + 1; }
276  if (GetCopy()==3) { return -GetCrystal() + 1; }
277  if (GetCopy()==4) { return GetCrystal(); }
278  }
279 
280  // FwEndCap
281  if (GetModule()==3)
282  return (GetRow()- 37);
283 
284  /*
285  if (GetModule()==3 && GetCrystal()==999 && GetRow()==999)
286  return GetRow();
287  */
288 
289  // Test EMC
290  if (GetModule()==6)
291  return GetCrystal();
292 
293  return -1000; // failure
294 }
295 
297 {
298  return fEnergy;
299 }
300 
301 
302 bool
303 PndEmcDigi::operator==( const PndEmcDigi& otherDigi ) const
304 {
305  bool isEqual = false;
306 
307  // 2 EmcDigis are equal is their relative energy difference whithin the folloowing tolerance
308  Double_t energy_tolerance=1e-5;
309 
310  if ( this->GetThetaInt() == otherDigi.GetThetaInt() &&
311  this->GetPhiInt() == otherDigi.GetPhiInt() &&
312  ((this->GetEnergy() - otherDigi.GetEnergy())/this->GetEnergy()<energy_tolerance )) isEqual =true;
313 
314  return isEqual;
315 }
316 
317 bool PndEmcDigi::operator!=(const PndEmcDigi& otherDigi) const
318 {
319  return ! ( *this == otherDigi );
320 }
321 
322 bool PndEmcDigi::operator<( const PndEmcDigi & otherDigi) const
323 {
324  if (fEnergy < otherDigi.fEnergy)
325  return true;
326  else if (fEnergy == otherDigi.fEnergy && fTheta< otherDigi.fTheta)
327  return true;
328  else if (fEnergy == otherDigi.fEnergy && fTheta == otherDigi.fTheta && fPhi < otherDigi.fPhi)
329  return true;
330 
331  return false;
332 }
333 
334 
335 
336 // ----- Public method Print -----------------------------------
337 void PndEmcDigi::Print(const Option_t* ) const {
338  cout << "EMC digi: cellid=" << GetDetectorId() << ", Energy=" << fEnergy<<", Time="<<GetTimeStamp()<<", Evt="<<fEvtNo;
339  if (fTrackId>0) cout << ", TrackID= " << fTrackId;
340  //cout<<endl;
341 // cout << ", x=" << GetX() << ", y=" << GetY() << endl << flush;
342 }
343 
344 
347 {
348  return 0;
349 }
350 
351 const PndEmcSharedDigi*
353 {
354  return 0;
355 }
356 
TVector3 pos
static void selectDigiPositionMethod(PositionMethod, double positionDepthPWO=0., double positionDepthShahslyk=0., double rescaleFactor=1.)
Definition: PndEmcDigi.cxx:153
static TClonesArray * fDigiArrayTBD
Definition: PndEmcDigi.h:52
const PndEmcTwoCoordIndex * myIndex() const
Definition: PndEmcXtal.cxx:133
virtual Double_t GetEnergy() const
Definition: PndEmcDigi.cxx:296
represents the reconstructed hit of one emc crystal
Definition: PndEmcDigi.h:40
virtual PndEmcSharedDigi * dynamic_cast_PndEmcSharedDigi()
Definition: PndEmcDigi.cxx:346
virtual bool operator<(const PndEmcDigi &otherDigi) const
Definition: PndEmcDigi.cxx:322
Int_t GetThetaInt() const
Definition: PndEmcDigi.h:99
Int_t GetDetectorId() const
Definition: PndEmcDigi.h:97
static double fPositionDepthPWO
Definition: PndEmcDigi.h:157
static double fRescaleFactor
Definition: PndEmcDigi.h:156
Int_t fTrackId
Definition: PndEmcDigi.h:125
const TVector3 & frontCentre() const
Definition: PndEmcXtal.cxx:145
Short_t GetCrystal() const
Definition: PndEmcDigi.h:105
represents coordinates of one crystal
Definition: PndEmcXtal.h:36
stores crystal index coordinates (x,y) or (theta,phi)
PndEmcTwoCoordIndex * GetTCI(Int_t DetectorId)
Emc geometry mapper.
Definition: PndEmcMapper.h:22
static TVector3 depthPosition(const PndEmcXtal *xtal)
Definition: PndEmcDigi.cxx:134
Double_t fEnergy
Definition: PndEmcDigi.h:124
static void InitDigiArrayTBD()
Definition: PndEmcDigi.cxx:89
Short_t GetCopy() const
Definition: PndEmcDigi.h:106
TVector3 fWhere
Definition: PndEmcDigi.h:128
Short_t GetModule() const
Definition: PndEmcDigi.h:103
const TVector3 & axisVector() const
Definition: PndEmcXtal.cxx:157
Double_t
PndEmcMapper * emcMap
used to share PndEmcDigis between bumps
Double_t fTheta
Definition: PndEmcDigi.h:131
const PndEmcTciXtalMap & GetTciXtalMap() const
virtual bool equal(FairTimeStamp *data)
Definition: PndEmcDigi.h:69
Int_t fPhiInd
Definition: PndEmcDigi.h:130
Double_t const fPhi
bool IsNeighbour(PndEmcTwoCoordIndex *_tci)
void SetDetectorId(Int_t id)
Definition: PndEmcDigi.cxx:95
static double fPositionDepthShashlyk
Definition: PndEmcDigi.h:158
Int_t fEvtNo
Definition: PndEmcDigi.h:118
Short_t GetYPad() const
Definition: PndEmcDigi.cxx:261
std::map< PndEmcTwoCoordIndex *, PndEmcXtal * > PndEmcTciXtalMap
virtual bool operator==(const PndEmcDigi &otherDigi) const
Definition: PndEmcDigi.cxx:303
Short_t GetRow() const
Definition: PndEmcDigi.h:104
Int_t fDetectorId
Definition: PndEmcDigi.h:126
ClassImp(PndAnaContFact)
static TVector3 surfacePosition(const PndEmcXtal *xtal)
Definition: PndEmcDigi.cxx:128
virtual bool operator!=(const PndEmcDigi &otherDigi) const
Definition: PndEmcDigi.cxx:317
static TVector3(*&)(const PndEmcXtal *) algPointer()
Definition: PndEmcDigi.h:154
virtual void Print(const Option_t *opt="") const
Definition: PndEmcDigi.cxx:337
Short_t GetXPad() const
Definition: PndEmcDigi.cxx:223
Int_t fThetaInd
Definition: PndEmcDigi.h:129
bool isNeighbour(const PndEmcDigi *theDigi) const
Definition: PndEmcDigi.cxx:201
static PndEmcStructure * Instance()
Double_t fPhi
Definition: PndEmcDigi.h:132
static PndEmcMapper * Instance()
virtual ~PndEmcDigi()
Definition: PndEmcDigi.cxx:47
virtual void AbsorbEnergy(PndEmcDigi &otherDigi)
Definition: PndEmcDigi.cxx:118
PndEmcTwoCoordIndex * GetTCI() const
Definition: PndEmcDigi.cxx:216
Double_t energy
Definition: plot_dirc.C:15
Int_t GetPhiInt() const
Definition: PndEmcDigi.h:100