CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  ~CaloSD() override;
55 
56  G4bool ProcessHits(G4Step* step, G4TouchableHistory*) override;
57  bool ProcessHits(G4GFlashSpot* aSpot, G4TouchableHistory*) override;
58 
59  uint32_t setDetUnitId(const G4Step* step) override = 0;
60 
61  void Initialize(G4HCofThisEvent* HCE) override;
62  void EndOfEvent(G4HCofThisEvent* eventHC) override;
63  void clear() override;
64  void DrawAll() override;
65  void PrintAll() override;
66 
67  void clearHits() override;
68  void fillHits(edm::PCaloHitContainer&, const std::string&) override;
69  void reset() override;
70 
71  bool isItFineCalo(const G4VTouchable* touch);
72 
73 protected:
74  virtual double getEnergyDeposit(const G4Step* step);
75  virtual double EnergyCorrected(const G4Step& step, const G4Track*);
76  virtual bool getFromLibrary(const G4Step* step);
77 
78  G4ThreeVector setToLocal(const G4ThreeVector&, const G4VTouchable*) const;
79  G4ThreeVector setToGlobal(const G4ThreeVector&, const G4VTouchable*) const;
80 
81  bool hitExists(const G4Step*);
82  bool checkHit();
83  CaloG4Hit* createNewHit(const G4Step*, const G4Track*);
84  void updateHit(CaloG4Hit*);
85  void resetForNewPrimary(const G4Step*);
86  double getAttenuation(const G4Step* aStep, double birk1, double birk2, double birk3) const;
87 
88  static std::string printableDecayChain(const std::vector<unsigned int>& decayChain);
91  unsigned int findBoundaryCrossingParent(const G4Track* track, bool markParentAsSaveable = true);
92 
93  void update(const BeginOfRun*) override;
94  void update(const BeginOfEvent*) override;
95  void update(const BeginOfTrack* trk) override;
96  void update(const EndOfTrack* trk) override;
97  void update(const ::EndOfEvent*) override;
98  virtual void initRun();
99  virtual void initEvent(const BeginOfEvent*);
100  virtual void endEvent();
101  virtual bool filterHit(CaloG4Hit*, double);
102 
103  virtual int getTrackID(const G4Track*);
104  virtual int setTrackID(const G4Step*);
105  virtual uint16_t getDepth(const G4Step*);
106  double getResponseWt(const G4Track*);
107  int getNumberOfHits();
108  void ignoreRejection() { ignoreReject = true; }
109 
110  inline void setParameterized(bool val) { isParameterized = val; }
111  inline void setUseMap(bool val) { useMap = val; }
112 
113  inline void processHit(const G4Step* step) {
114  // check if it is in the same unit and timeslice as the previous one
115  if (currentID == previousID) {
117  } else if (!checkHit()) {
118  currentHit = createNewHit(step, step->GetTrack());
119  }
120  }
121 
122  inline void setNumberCheckedHits(int val) { nCheckedHits = val; }
123  void printDetectorLevels(const G4VTouchable*) const;
124 
125 private:
126  void storeHit(CaloG4Hit*);
127  bool saveHit(CaloG4Hit*);
128  void cleanHitCollection();
129 
130 protected:
131  // Data relative to primary particle (the one which triggers a shower)
132  // These data are common to all Hits of a given shower.
133  // One shower is made of several hits which differ by the
134  // unit ID (crystal/fibre/scintillator) and the Time slice ID.
135 
136  G4ThreeVector entrancePoint;
137  G4ThreeVector entranceLocal;
138  G4ThreeVector posGlobal;
141 
143 
145 
147 
150 
151  bool forceSave;
152 
153 private:
154  struct Detector {
155  Detector() {}
157  G4LogicalVolume* lv;
158  int level;
159  };
160 
162 
163  std::unique_ptr<CaloSlaveSD> slave;
164  std::unique_ptr<CaloMeanResponse> meanResponse;
165 
167 
171  bool useMap; // use map for comparison of ID
173 
174  int hcID;
178  int primIDSaved; // ID of the last saved primary
179  int nCheckedHits; // number of last hits to compare ID
180 
181  float timeSlice;
182  double eminHitD;
183  double correctT;
185  double eMinFine_;
186 
187  std::map<CaloHitID, CaloG4Hit*> hitMap;
188  std::map<int, TrackWithHistory*> tkMap;
189  std::unordered_map<unsigned int, unsigned int> boundaryCrossingParentMap_;
190  std::vector<std::unique_ptr<CaloG4Hit>> reusehit;
191  std::vector<Detector> fineDetectors_;
193 };
194 
195 #endif // SimG4CMS_CaloSD_h
float edepositEM
Definition: CaloSD.h:140
double energyCut
Definition: CaloSD.h:144
bool ignoreReject
Definition: CaloSD.h:170
G4LogicalVolume * lv
Definition: CaloSD.h:157
virtual bool getFromLibrary(const G4Step *step)
Definition: CaloSD.cc:319
std::vector< PCaloHit > PCaloHitContainer
double kmaxNeutron
Definition: CaloSD.h:149
bool doFineCaloThisStep_
Definition: CaloSD.h:192
void setNumberCheckedHits(int val)
Definition: CaloSD.h:122
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:633
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:836
virtual double getEnergyDeposit(const G4Step *step)
Definition: CaloSD.cc:315
virtual double EnergyCorrected(const G4Step &step, const G4Track *)
Definition: CaloSD.cc:317
unsigned int findBoundaryCrossingParent(const G4Track *track, bool markParentAsSaveable=true)
Definition: CaloSD.cc:483
double eMinFine_
Definition: CaloSD.h:185
bool corrTOFBeam
Definition: CaloSD.h:172
Definition: CaloSD.h:40
int totalHits
Definition: CaloSD.h:177
void DrawAll() override
Definition: CaloSD.cc:374
uint32_t ID
Definition: Definitions.h:24
void clear() override
Definition: CaloSD.cc:372
uint32_t setDetUnitId(const G4Step *step) override=0
bool useMap
Definition: CaloSD.h:171
int hcID
Definition: CaloSD.h:174
double eminHitD
Definition: CaloSD.h:182
G4ThreeVector posGlobal
Definition: CaloSD.h:138
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:796
int primIDSaved
Definition: CaloSD.h:178
void Initialize(G4HCofThisEvent *HCE) override
Definition: CaloSD.cc:341
int primAncestor
Definition: CaloSD.h:175
void reset() override
Definition: CaloSD.cc:784
void processHit(const G4Step *step)
Definition: CaloSD.h:113
double kmaxProton
Definition: CaloSD.h:149
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: CaloSD.cc:383
void setUseMap(bool val)
Definition: CaloSD.h:111
std::vector< Detector > fineDetectors_
Definition: CaloSD.h:191
double eminHit
Definition: CaloSD.h:144
void ignoreRejection()
Definition: CaloSD.h:108
virtual void initEvent(const BeginOfEvent *)
Definition: CaloSD.cc:792
std::unordered_map< unsigned int, unsigned int > boundaryCrossingParentMap_
Definition: CaloSD.h:189
void cleanHitCollection()
Definition: CaloSD.cc:956
bool forceSave
Definition: CaloSD.h:151
bool isItFineCalo(const G4VTouchable *touch)
Definition: CaloSD.cc:321
float timeSlice
Definition: CaloSD.h:181
bool checkHit()
Definition: CaloSD.cc:423
static std::string printableDecayChain(const std::vector< unsigned int > &decayChain)
Definition: CaloSD.cc:458
double kmaxIon
Definition: CaloSD.h:149
bool suppressHeavy
Definition: CaloSD.h:148
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:163
float edepositHAD
Definition: CaloSD.h:140
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:644
bool doFineCalo_
Definition: CaloSD.h:184
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition: CaloSD.cc:160
int getNumberOfHits()
Definition: CaloSD.cc:452
G4ThreeVector setToGlobal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:398
CaloG4Hit * createNewHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:555
CaloHitID previousID
Definition: CaloSD.h:142
~CaloSD() override
Definition: CaloSD.cc:158
CaloG4Hit * currentHit
Definition: CaloSD.h:146
void storeHit(CaloG4Hit *)
Definition: CaloSD.cc:858
virtual bool filterHit(CaloG4Hit *, double)
Definition: CaloSD.cc:838
double tmaxHit
Definition: CaloSD.h:144
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:394
bool hitExists(const G4Step *)
Definition: CaloSD.cc:402
std::unique_ptr< CaloMeanResponse > meanResponse
Definition: CaloSD.h:164
CaloHitID currentID
Definition: CaloSD.h:142
virtual void initRun()
Definition: CaloSD.cc:790
double correctT
Definition: CaloSD.h:183
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:187
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: CaloSD.cc:359
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:657
int nCheckedHits
Definition: CaloSD.h:179
virtual void endEvent()
Definition: CaloSD.cc:794
CaloG4HitCollection * theHC
Definition: CaloSD.h:166
std::string name
Definition: CaloSD.h:156
CaloSD(const std::string &aSDname, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *, float timeSlice=1., bool ignoreTkID=false)
Definition: CaloSD.cc:33
float incidentEnergy
Definition: CaloSD.h:139
virtual int setTrackID(const G4Step *)
Definition: CaloSD.cc:814
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
void printDetectorLevels(const G4VTouchable *) const
Definition: CaloSD.cc:1072
bool isParameterized
Definition: CaloSD.h:169
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:188
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
Definition: CaloSD.h:190
step
Definition: StallMonitor.cc:94
const SimTrackManager * m_trackManager
Definition: CaloSD.h:161
std::string shortreprID(const CaloHitID &ID)
Definition: CaloSD.cc:469
void clearHits() override
Definition: CaloSD.cc:773
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:849
bool saveHit(CaloG4Hit *)
Definition: CaloSD.cc:870
void PrintAll() override
Definition: CaloSD.cc:376
G4ThreeVector entrancePoint
Definition: CaloSD.h:136
G4ThreeVector entranceLocal
Definition: CaloSD.h:137
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: CaloSD.cc:679
int cleanIndex
Definition: CaloSD.h:176
bool ignoreTrackID
Definition: CaloSD.h:168
void setParameterized(bool val)
Definition: CaloSD.h:110