CMS 3D CMS Logo

CaloSD.h
Go to the documentation of this file.
1 #ifndef SimG4CMS_CaloSD_h
2 #define SimG4CMS_CaloSD_h
3 // File: CaloSD.h
5 // Description: Stores hits of calorimetric type in appropriate container
6 // Use in your sensitive detector builder:
7 // CaloSD* caloSD = new CaloSD(SDname, new CaloNumberingScheme());
9 
21 
24 
25 #include "G4VPhysicalVolume.hh"
26 #include "G4Track.hh"
27 #include "G4VGFlashSensitiveDetector.hh"
28 
29 #include <vector>
30 #include <map>
31 #include <unordered_map>
32 #include <memory>
33 
34 class G4Step;
35 class G4HCofThisEvent;
36 class CaloSlaveSD;
37 class G4GFlashSpot;
38 class SimTrackManager;
39 
41  public G4VGFlashSensitiveDetector,
42  public Observer<const BeginOfRun*>,
43  public Observer<const BeginOfEvent*>,
44  public Observer<const BeginOfTrack*>,
45  public Observer<const EndOfTrack*>,
46  public Observer<const EndOfEvent*> {
47 public:
48  CaloSD(const std::string& aSDname,
49  const SensitiveDetectorCatalog& clg,
50  edm::ParameterSet const& p,
51  const SimTrackManager*,
52  float timeSlice = 1.,
53  bool ignoreTkID = false,
54  const std::string& newcolname = "");
55  ~CaloSD() override;
56 
57  void newCollection(const std::string& name, edm::ParameterSet const& p);
58  G4bool ProcessHits(G4Step* step, G4TouchableHistory*) override;
59  bool ProcessHits(G4GFlashSpot* aSpot, G4TouchableHistory*) override;
60 
61  uint32_t setDetUnitId(const G4Step* step) override = 0;
62 
63  void Initialize(G4HCofThisEvent* HCE) override;
64  void EndOfEvent(G4HCofThisEvent* eventHC) override;
65  void clear() override;
66  void DrawAll() override;
67  void PrintAll() override;
68 
69  void clearHits() override;
70  void fillHits(edm::PCaloHitContainer&, const std::string&) override;
71  void reset() override;
72 
73  bool isItFineCalo(const G4VTouchable* touch);
74 
75 protected:
76  virtual double getEnergyDeposit(const G4Step* step);
77  virtual double EnergyCorrected(const G4Step& step, const G4Track*);
78  virtual bool getFromLibrary(const G4Step* step);
79 
80  G4ThreeVector setToLocal(const G4ThreeVector&, const G4VTouchable*) const;
81  G4ThreeVector setToGlobal(const G4ThreeVector&, const G4VTouchable*) const;
82 
83  bool hitExists(const G4Step*, int k);
84  bool checkHit(int k = 0);
85  CaloG4Hit* createNewHit(const G4Step*, const G4Track*, int k);
86  void updateHit(CaloG4Hit*, int k);
87  void resetForNewPrimary(const G4Step*);
88  double getAttenuation(const G4Step* aStep, double birk1, double birk2, double birk3) const;
89 
90  static std::string printableDecayChain(const std::vector<unsigned int>& decayChain);
93  unsigned int findBoundaryCrossingParent(const G4Track* track, bool markParentAsSaveable = true);
94 
95  void update(const BeginOfRun*) override;
96  void update(const BeginOfEvent*) override;
97  void update(const BeginOfTrack* trk) override;
98  void update(const EndOfTrack* trk) override;
99  void update(const ::EndOfEvent*) override;
100  virtual void initRun();
101  virtual void initEvent(const BeginOfEvent*);
102  virtual void endEvent();
103  virtual bool filterHit(CaloG4Hit*, double);
104 
105  virtual int getTrackID(const G4Track*);
106  virtual int setTrackID(const G4Step*);
107  virtual uint16_t getDepth(const G4Step*);
108  virtual void processSecondHit(const G4Step*, const G4Track*);
109 
110  double getResponseWt(const G4Track*, int k = 0);
111  int getNumberOfHits(int k = 0);
112  void ignoreRejection() { ignoreReject = true; }
113 
114  inline void setParameterized(bool val) { isParameterized = val; }
115  inline void setUseMap(bool val) { useMap = val; }
116 
117  inline void processHit(const G4Step* step) {
118  // check if it is in the same unit and timeslice as the previous one
119  if (currentID[0] == previousID[0]) {
120  updateHit(currentHit[0], 0);
121  } else if (!checkHit()) {
122  currentHit[0] = createNewHit(step, step->GetTrack(), 0);
123  }
124  }
125 
126  inline void setNumberCheckedHits(int val, int k = 0) { nCheckedHits[k] = val; }
127  void printDetectorLevels(const G4VTouchable*) const;
128 
129 private:
130  void storeHit(CaloG4Hit*, int k = 0);
131  bool saveHit(CaloG4Hit*, int k = 0);
132  void cleanHitCollection();
133 
134 protected:
135  // Data relative to primary particle (the one which triggers a shower)
136  // These data are common to all Hits of a given shower.
137  // One shower is made of several hits which differ by the
138  // unit ID (crystal/fibre/scintillator) and the Time slice ID.
139 
140  G4ThreeVector entrancePoint;
141  G4ThreeVector entranceLocal;
142  G4ThreeVector posGlobal;
145 
147 
149  std::vector<std::string> hcn_;
150  std::vector<int> useResMap_;
151 
153 
156 
157  bool forceSave;
158  int nHC_;
160 
161 private:
162  struct Detector {
163  Detector() {}
165  G4LogicalVolume* lv;
166  int level;
167  };
168 
170 
171  std::unique_ptr<CaloSlaveSD> slave[2];
172  std::unique_ptr<CaloMeanResponse> meanResponse[2];
173 
175 
179  bool useMap; // use map for comparison of ID
181 
182  int hcID[2];
184  int cleanIndex[2];
185  int totalHits[2];
186  int primIDSaved[2]; // ID of the last saved primary
187  int nCheckedHits[2]; // number of last hits to compare ID
188 
189  float timeSlice;
190  double eminHitD;
191  double correctT;
193  double eMinFine_;
194 
195  std::map<CaloHitID, CaloG4Hit*> hitMap[2];
196  std::map<int, TrackWithHistory*> tkMap;
197  std::unordered_map<unsigned int, unsigned int> boundaryCrossingParentMap_;
198  std::vector<std::unique_ptr<CaloG4Hit>> reusehit[2];
199  std::vector<Detector> fineDetectors_;
201 };
202 
203 #endif // SimG4CMS_CaloSD_h
CaloG4Hit * currentHit[2]
Definition: CaloSD.h:152
float edepositEM
Definition: CaloSD.h:144
virtual void processSecondHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:916
int getNumberOfHits(int k=0)
Definition: CaloSD.cc:522
double energyCut
Definition: CaloSD.h:148
bool ignoreReject
Definition: CaloSD.h:178
G4LogicalVolume * lv
Definition: CaloSD.h:165
virtual bool getFromLibrary(const G4Step *step)
Definition: CaloSD.cc:367
std::vector< PCaloHit > PCaloHitContainer
double kmaxNeutron
Definition: CaloSD.h:155
bool doFineCaloThisStep_
Definition: CaloSD.h:200
std::map< CaloHitID, CaloG4Hit * > hitMap[2]
Definition: CaloSD.h:195
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:914
virtual double getEnergyDeposit(const G4Step *step)
Definition: CaloSD.cc:363
virtual double EnergyCorrected(const G4Step &step, const G4Track *)
Definition: CaloSD.cc:365
unsigned int findBoundaryCrossingParent(const G4Track *track, bool markParentAsSaveable=true)
Definition: CaloSD.cc:553
double eMinFine_
Definition: CaloSD.h:193
bool corrTOFBeam
Definition: CaloSD.h:180
Definition: CaloSD.h:40
void setNumberCheckedHits(int val, int k=0)
Definition: CaloSD.h:126
void DrawAll() override
Definition: CaloSD.cc:431
uint32_t ID
Definition: Definitions.h:24
void clear() override
Definition: CaloSD.cc:429
uint32_t setDetUnitId(const G4Step *step) override=0
bool useMap
Definition: CaloSD.h:179
void newCollection(const std::string &name, edm::ParameterSet const &p)
Definition: CaloSD.cc:177
double eminHitD
Definition: CaloSD.h:190
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:455
int nCheckedHits[2]
Definition: CaloSD.h:187
G4ThreeVector posGlobal
Definition: CaloSD.h:142
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:874
CaloG4HitCollection * theHC[2]
Definition: CaloSD.h:174
void Initialize(G4HCofThisEvent *HCE) override
Definition: CaloSD.cc:389
int primAncestor
Definition: CaloSD.h:183
int cleanIndex[2]
Definition: CaloSD.h:184
std::vector< int > useResMap_
Definition: CaloSD.h:150
void reset() override
Definition: CaloSD.cc:862
void processHit(const G4Step *step)
Definition: CaloSD.h:117
double kmaxProton
Definition: CaloSD.h:155
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: CaloSD.cc:442
void setUseMap(bool val)
Definition: CaloSD.h:115
std::vector< Detector > fineDetectors_
Definition: CaloSD.h:199
double eminHit
Definition: CaloSD.h:148
bool saveHit(CaloG4Hit *, int k=0)
Definition: CaloSD.cc:950
bool checkHit(int k=0)
Definition: CaloSD.cc:489
void ignoreRejection()
Definition: CaloSD.h:112
virtual void initEvent(const BeginOfEvent *)
Definition: CaloSD.cc:870
std::unordered_map< unsigned int, unsigned int > boundaryCrossingParentMap_
Definition: CaloSD.h:197
void cleanHitCollection()
Definition: CaloSD.cc:1041
int primIDSaved[2]
Definition: CaloSD.h:186
bool forceSave
Definition: CaloSD.h:157
int nHC_
Definition: CaloSD.h:158
bool isItFineCalo(const G4VTouchable *touch)
Definition: CaloSD.cc:369
float timeSlice
Definition: CaloSD.h:189
double getResponseWt(const G4Track *, int k=0)
Definition: CaloSD.cc:929
void updateHit(CaloG4Hit *, int k)
Definition: CaloSD.cc:704
CaloG4Hit * createNewHit(const G4Step *, const G4Track *, int k)
Definition: CaloSD.cc:625
static std::string printableDecayChain(const std::vector< unsigned int > &decayChain)
Definition: CaloSD.cc:528
double kmaxIon
Definition: CaloSD.h:155
bool suppressHeavy
Definition: CaloSD.h:154
float edepositHAD
Definition: CaloSD.h:144
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:715
bool doFineCalo_
Definition: CaloSD.h:192
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition: CaloSD.cc:195
std::vector< std::string > hcn_
Definition: CaloSD.h:149
~CaloSD() override
Definition: CaloSD.cc:175
std::vector< std::unique_ptr< CaloG4Hit > > reusehit[2]
Definition: CaloSD.h:198
G4ThreeVector setToGlobal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:459
int totalHits[2]
Definition: CaloSD.h:185
virtual bool filterHit(CaloG4Hit *, double)
Definition: CaloSD.cc:918
CaloHitID previousID[2]
Definition: CaloSD.h:146
double tmaxHit
Definition: CaloSD.h:148
CaloSD(const std::string &aSDname, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *, float timeSlice=1., bool ignoreTkID=false, const std::string &newcolname="")
Definition: CaloSD.cc:34
virtual void initRun()
Definition: CaloSD.cc:868
double correctT
Definition: CaloSD.h:191
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:728
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: CaloSD.cc:413
void storeHit(CaloG4Hit *, int k=0)
Definition: CaloSD.cc:938
bool hitExists(const G4Step *, int k)
Definition: CaloSD.cc:463
virtual void endEvent()
Definition: CaloSD.cc:872
std::string name
Definition: CaloSD.h:164
void printDetectorLevels(const G4VTouchable *) const
Definition: CaloSD.cc:1159
float incidentEnergy
Definition: CaloSD.h:143
virtual int setTrackID(const G4Step *)
Definition: CaloSD.cc:892
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
bool isParameterized
Definition: CaloSD.h:177
std::string detName_
Definition: CaloSD.h:159
CaloHitID currentID[2]
Definition: CaloSD.h:146
std::string collName_[2]
Definition: CaloSD.h:159
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:196
std::unique_ptr< CaloMeanResponse > meanResponse[2]
Definition: CaloSD.h:172
step
Definition: StallMonitor.cc:83
const SimTrackManager * m_trackManager
Definition: CaloSD.h:169
std::string shortreprID(const CaloHitID &ID)
Definition: CaloSD.cc:539
void clearHits() override
Definition: CaloSD.cc:849
int hcID[2]
Definition: CaloSD.h:182
std::unique_ptr< CaloSlaveSD > slave[2]
Definition: CaloSD.h:171
void PrintAll() override
Definition: CaloSD.cc:433
G4ThreeVector entrancePoint
Definition: CaloSD.h:140
G4ThreeVector entranceLocal
Definition: CaloSD.h:141
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: CaloSD.cc:750
bool ignoreTrackID
Definition: CaloSD.h:176
void setParameterized(bool val)
Definition: CaloSD.h:114