PandaRoot
PndEmcCluster.h
Go to the documentation of this file.
1 //----------------------------------------------------------------------
2 // Software developed for the BaBar Detector at the SLAC B-Factory.
3 // Adapted for the PANDA experiment at GSI
4 //
5 // Author List:
6 // Xiaorong Shi Lawrence Livermore National Lab
7 // Steve Playfer University of Edinburgh
8 // Stephen Gowdy University of Edinburgh
9 //
10 // M Tiemens University of Groningen (added cluster radius)
11 //-----------------------------------------------------------------------
12 //#pragma once
13 #ifndef PNDEMCCLUSTER_H
14 #define PNDEMCCLUSTER_H
15 
16 #include "TObject.h"
17 #include "FairTimeStamp.h"
18 #include "TMatrixD.h"
19 #include "TVector3.h"
20 #include "TLorentzVector.h"
21 #include "TClonesArray.h"
22 #include <vector>
23 #include <map>
24 
25 class PndEmcDigi;
27 
29  Short_t score;
30 
31  void SetValShift(Bool_t val, Int_t shift)
32  {
33  if (shift < 4)
34  score |= val << shift;
35  }
36 
37  Bool_t GetValShift(Int_t shift) { return score >> shift & 0x1; }
38 };
39 
40 class PndEmcCluster : public FairTimeStamp {
41 
42  public:
43  // Constructors
44  PndEmcCluster();
45  virtual void Print(const Option_t *opt = "") const;
46  // Destructor
47  virtual ~PndEmcCluster();
48 
49  Double_t fSingleCrystalRadius = 1.84; // cm = single crystal radius = sqrt(2)*1.3 = 1.8385, 1.3 = 0.5*crystal size
50 
51  // List of Digi indexes
52  const std::vector<Int_t> &DigiList() const { return fDigiList; };
53  std::vector<Int_t> &DigiList() { return fDigiList; };
54  const std::map<Int_t, Int_t> &LocalMaxMap() const { return fLocalMaxMap; };
55  const std::map<Int_t, Int_t> &MemberDigiMap() const { return fMemberDigiMap; };
56 
57  // Digi with largest energy in cluster
58  virtual const PndEmcDigi *Maxima(const TClonesArray *digiArray) const;
59  virtual PndEmcDigi *Maxima(const TClonesArray *digiArray);
60 
61  // index of digi with largest energy in cluster
62  int MaximaAsIndex(const TClonesArray *digiArray);
63 
64  // Total Energy of Cluster
65  // virtual Double_t energy() const; // old function, renamed to make compatible with the rest of PandaRoot
66  Double_t GetEnergy() const;
67  // Theta centroid of cluster
68  Double_t theta() const;
69  // Phi centroid of cluster
70  Double_t phi() const;
71  // Theta centroid of cluster in index units
72  TVector3 position() const;
73  // Where is cluster?
74  TVector3 where() const;
75  // x co-ordinate of clus
76  Double_t x() const;
77  // y co-ordinate of clus
78  Double_t y() const;
79  // z co-ordinate of clus
80  Double_t z() const;
81  // Cluster moments
82  // Zernike moment (2,0)
83  Double_t Z20() const { return fZ20; }
84  // Zernike moment (5,3)
85  Double_t Z53() const { return fZ53; }
86  // Lateral energy deposition within the cluster
87  Double_t LatMom() const { return fLatMom; }
88  // Radius of cluster
89  Double_t GetRadius() const;
90  Double_t GetXRadius() const
91  {
92  if (fRadiusValid)
93  return fXRadius;
94  }
95  Double_t GetYRadius() const
96  {
97  if (fRadiusValid)
98  return fYRadius;
99  }
100 
101  // Get Module in which cluster is located
102  Short_t GetModule() const; // {return fModule;}
103 
104  bool IsEnergyValid() const { return fEnergyValid; };
105  bool IsPositionValid() const { return fWhereValid; };
106 
107  Int_t NumberOfDigis() const;
108  Int_t NBumps() const;
109 
110  bool isInCluster(PndEmcDigi *theDigi, const TClonesArray *digiArray);
111 
112  // Distance from centre of cluster to a point
113  virtual Double_t DistanceToCentre(const TVector3 &aPoint) const;
114  virtual Double_t DistanceToCentre(const PndEmcDigi *aDigi) const;
115  // Returns the difference between the two phi angles, defined as the
116  // first minus the second, but deals with the overlap at 2 pi.
117  static Double_t FindPhiDiff(Double_t, Double_t);
118 
119  // Modifiers
120  virtual void addDigi(const TClonesArray *digiArray, Int_t iDigi);
121  virtual void removeDigi(const TClonesArray *digiArray, Int_t iDigi);
122  virtual std::vector<Int_t>::iterator removeDigi(const TClonesArray *digiArray, std::vector<Int_t>::iterator it);
123  void addCluster(PndEmcCluster *cluster, const TClonesArray *digiArray);
124  virtual void addLocalMax(const TClonesArray *digiArray, Int_t iDigi);
125  virtual void addLocalMax(const PndEmcDigi *digi);
126  virtual void SetNBumps(unsigned nbumps);
127  void SetEnergy(Double_t en)
128  {
129  fEnergy = en;
130  fEnergyValid = true;
131  }
132  void SetPosition(TVector3 pos)
133  {
134  fWhere = pos;
135  fWhereValid = true;
136  }
137  void SetZ20(Double_t z20) { fZ20 = z20; }
138  void SetZ53(Double_t z53) { fZ53 = z53; }
139  void SetLatMom(Double_t latMom) { fLatMom = latMom; }
140  void SetTrackEntering(const FairMultiLinkedData &tracks) { fTrackEntering = tracks; }
141  void SetTrackExiting(const FairMultiLinkedData &tracks) { fTrackExiting = tracks; }
142  void SetRadius(Double_t clusradius, Int_t n = 1)
143  {
144  if (n == 0)
145  n = 1;
146  fRadius = clusradius + n * fSingleCrystalRadius;
147  fRadiusValid = true;
148  } // Add single crystal radius to precluster radius, because distance to crystal centre is taken and not its size. If this correction is not implemented, preclusters consisting
149  // of a single crystal will get a radius of 0 and will never be merged to another cluster. Added multiplier n to allow the use of the diameter, or manually increase the radius
150  // of a cluster
151  void SetXRadius(Double_t xrad, Int_t n = 1)
152  {
153  fXRadius = xrad + n * fSingleCrystalRadius;
154  fRadiusValid = true;
155  }
156  void SetYRadius(Double_t yrad, Int_t n = 1)
157  {
158  fYRadius = yrad + n * fSingleCrystalRadius;
159  fRadiusValid = true;
160  }
161  void SetModule(Short_t mod) { fModule = mod; }
162 
163  void AddTracksEnteringExiting(const FairMultiLinkedData &tracksEntering, const FairMultiLinkedData &tracksExiting);
164 
165  Double_t GetEnergyCorrected() const;
166 
167  const std::vector<Int_t> &GetMcList() const;
168  Int_t GetMcRadius() { return fMcList.size(); }
169  Int_t GetMcIndex(Int_t i = 0) { return fMcList[i]; }
170  FairMultiLinkedData GetTrackEntering() const { return fTrackEntering; }
171  FairMultiLinkedData GetTrackExiting() const { return fTrackExiting; }
172 
173  TLorentzVector GetLorentzVector(); // returns the lorentz vector of this cluster, assuming it starts in the IP
174 
175  void OverwriteDigiList(Int_t, Int_t); // Update indices of digis in fDigiArray (EXAMPLE USE: call after putting member digis in a new array e.g. using FairLinks) //
176 
177  private:
178  friend class PndEmcMakeCluster;
179 
180  protected:
181  void FillScoreBoard(FairMultiLinkedData tracks, std::map<FairLink, LinkScoreBoard> &scoreBoard, Int_t shift);
182 
183  std::vector<Int_t> fDigiList;
184  mutable std::vector<Int_t> fMcList;
185  mutable std::map<Int_t, Int_t> fMcMap; //<track, count>
186  std::map<Int_t, Int_t> fMemberDigiMap; // Map <detId,digiIndex>
187  std::map<Int_t, Int_t> fLocalMaxMap; // Map<detId, digiIndex> for the maxima
188 
191  Double_t fEnergy;
192  Double_t fRadius;
194  TVector3 fWhere;
195  unsigned fNbumps;
196  Double_t fZ20; // Zernike moment (2,0)
197  Double_t fZ53; // Zernike moment (5,3)
198  Double_t fLatMom; // Lateral energy deposition within the cluster
199  Short_t fModule;
200 
201  FairMultiLinkedData fTrackEntering;
202  FairMultiLinkedData fTrackExiting;
203 
204  Double_t fXRadius;
205  Double_t fYRadius;
206 
207  TLorentzVector fLorentzVector;
208 
209  void invalidateCache(bool);
210 
211  ClassDef(PndEmcCluster, 5)
212 };
213 
214 #endif // EMCCLUSTER_HH
Double_t GetYRadius() const
Definition: PndEmcCluster.h:95
void SetEnergy(Double_t en)
Double_t fXRadius
Double_t fEnergy
void SetRadius(Double_t clusradius, Int_t n=1)
Int_t GetMcRadius()
std::map< Int_t, Int_t > fLocalMaxMap
Double_t Z53() const
Definition: PndEmcCluster.h:85
Double_t LatMom() const
Definition: PndEmcCluster.h:87
std::map< Int_t, Int_t > fMcMap
void SetYRadius(Double_t yrad, Int_t n=1)
TVector3 fWhere
Double_t fLatMom
Double_t GetXRadius() const
Definition: PndEmcCluster.h:90
void SetTrackExiting(const FairMultiLinkedData &tracks)
stores crystal index coordinates (x,y) or (theta,phi)
Double_t Z20() const
Definition: PndEmcCluster.h:83
bool IsPositionValid() const
Int_t GetMcIndex(Int_t i=0)
unsigned int i
Definition: P4_F32vec4.h:21
const std::map< Int_t, Int_t > & MemberDigiMap() const
Definition: PndEmcCluster.h:55
Double_t fRadius
void SetXRadius(Double_t xrad, Int_t n=1)
void SetModule(Short_t mod)
FairMultiLinkedData fTrackExiting
std::vector< Int_t > fMcList
FairMultiLinkedData fTrackEntering
bool IsEnergyValid() const
const std::vector< Int_t > & DigiList() const
Definition: PndEmcCluster.h:52
std::map< Int_t, Int_t > fMemberDigiMap
FairMultiLinkedData GetTrackExiting() const
Task to cluster PndEmcDigis.
void SetZ20(Double_t z20)
void SetZ53(Double_t z53)
TLorentzVector fLorentzVector
Bool_t GetValShift(Int_t shift)
Definition: PndEmcCluster.h:37
void SetPosition(TVector3 pos)
std::vector< Int_t > fDigiList
void SetValShift(Bool_t val, Int_t shift)
Definition: PndEmcCluster.h:31
void SetTrackEntering(const FairMultiLinkedData &tracks)
FairMultiLinkedData GetTrackEntering() const
const std::map< Int_t, Int_t > & LocalMaxMap() const
Definition: PndEmcCluster.h:54
void SetLatMom(Double_t latMom)
Double_t fYRadius
std::vector< Int_t > & DigiList()
Definition: PndEmcCluster.h:53
unsigned fNbumps