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