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 
23 
24 #include "G4VPhysicalVolume.hh"
25 #include "G4Track.hh"
26 #include "G4VGFlashSensitiveDetector.hh"
27 
28 #include <vector>
29 #include <map>
30 #include <memory>
31 
32 class G4Step;
33 class G4HCofThisEvent;
34 class CaloSlaveSD;
35 class G4GFlashSpot;
36 class SimTrackManager;
37 
39  public G4VGFlashSensitiveDetector,
40  public Observer<const BeginOfRun*>,
41  public Observer<const BeginOfEvent*>,
42  public Observer<const BeginOfTrack*>,
43  public Observer<const EndOfTrack*>,
44  public Observer<const EndOfEvent*> {
45 public:
46  CaloSD(const std::string& aSDname,
47  const DDCompactView& cpv,
48  const SensitiveDetectorCatalog& clg,
49  edm::ParameterSet const& p,
50  const SimTrackManager*,
51  float timeSlice = 1.,
52  bool ignoreTkID = false);
53  ~CaloSD() override;
54 
55  G4bool ProcessHits(G4Step* step, G4TouchableHistory*) override;
56  bool ProcessHits(G4GFlashSpot* aSpot, G4TouchableHistory*) override;
57 
58  uint32_t setDetUnitId(const G4Step* step) override = 0;
59 
60  void Initialize(G4HCofThisEvent* HCE) override;
61  void EndOfEvent(G4HCofThisEvent* eventHC) override;
62  void clear() override;
63  void DrawAll() override;
64  void PrintAll() override;
65 
66  void clearHits() override;
67  void fillHits(edm::PCaloHitContainer&, const std::string&) override;
68  void reset() override;
69 
70 protected:
71  virtual double getEnergyDeposit(const G4Step* step);
72  virtual bool getFromLibrary(const G4Step* step);
73 
74  G4ThreeVector setToLocal(const G4ThreeVector&, const G4VTouchable*) const;
75  G4ThreeVector setToGlobal(const G4ThreeVector&, const G4VTouchable*) const;
76 
77  bool hitExists(const G4Step*);
78  bool checkHit();
79  CaloG4Hit* createNewHit(const G4Step*);
80  void updateHit(CaloG4Hit*);
81  void resetForNewPrimary(const G4Step*);
82  double getAttenuation(const G4Step* aStep, double birk1, double birk2, double birk3) const;
83 
84  void update(const BeginOfRun*) override;
85  void update(const BeginOfEvent*) override;
86  void update(const BeginOfTrack* trk) override;
87  void update(const EndOfTrack* trk) override;
88  void update(const ::EndOfEvent*) override;
89  virtual void initRun();
90  virtual void initEvent(const BeginOfEvent*);
91  virtual void endEvent();
92  virtual bool filterHit(CaloG4Hit*, double);
93 
94  virtual int getTrackID(const G4Track*);
95  virtual int setTrackID(const G4Step*);
96  virtual uint16_t getDepth(const G4Step*);
97  double getResponseWt(const G4Track*);
98  int getNumberOfHits();
99 
100  inline void setParameterized(bool val) { isParameterized = val; }
101  inline void setUseMap(bool val) { useMap = val; }
102 
103  inline void processHit(const G4Step* step) {
104  // check if it is in the same unit and timeslice as the previous one
105  if (currentID == previousID) {
107  } else if (!checkHit()) {
108  currentHit = createNewHit(step);
109  }
110  }
111 
112  inline void setNumberCheckedHits(int val) { nCheckedHits = val; }
113 
114 private:
115  void storeHit(CaloG4Hit*);
116  bool saveHit(CaloG4Hit*);
117  void cleanHitCollection();
118 
119 protected:
120  // Data relative to primary particle (the one which triggers a shower)
121  // These data are common to all Hits of a given shower.
122  // One shower is made of several hits which differ by the
123  // unit ID (crystal/fibre/scintillator) and the Time slice ID.
124 
125  G4ThreeVector entrancePoint;
126  G4ThreeVector entranceLocal;
127  G4ThreeVector posGlobal;
130 
132 
134 
136 
139 
140  bool forceSave;
141 
142 private:
144 
145  std::unique_ptr<CaloSlaveSD> slave;
146  std::unique_ptr<CaloMeanResponse> meanResponse;
147 
149 
152  bool useMap; // use map for comparison of ID
154 
155  int hcID;
159  int primIDSaved; // ID of the last saved primary
160  int nCheckedHits; // number of last hits to compare ID
161 
162  float timeSlice;
163  double eminHitD;
164  double correctT;
165 
166  std::map<CaloHitID, CaloG4Hit*> hitMap;
167  std::map<int, TrackWithHistory*> tkMap;
168  std::vector<std::unique_ptr<CaloG4Hit>> reusehit;
169 };
170 
171 #endif // SimG4CMS_CaloSD_h
float edepositEM
Definition: CaloSD.h:129
double energyCut
Definition: CaloSD.h:133
virtual bool getFromLibrary(const G4Step *step)
Definition: CaloSD.cc:246
std::vector< PCaloHit > PCaloHitContainer
double kmaxNeutron
Definition: CaloSD.h:138
void setNumberCheckedHits(int val)
Definition: CaloSD.h:112
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:414
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:610
virtual double getEnergyDeposit(const G4Step *step)
Definition: CaloSD.cc:244
bool corrTOFBeam
Definition: CaloSD.h:153
Definition: CaloSD.h:38
int totalHits
Definition: CaloSD.h:158
void DrawAll() override
Definition: CaloSD.cc:278
void clear() override
Definition: CaloSD.cc:276
uint32_t setDetUnitId(const G4Step *step) override=0
bool useMap
Definition: CaloSD.h:152
int hcID
Definition: CaloSD.h:155
double eminHitD
Definition: CaloSD.h:163
G4ThreeVector posGlobal
Definition: CaloSD.h:127
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:574
int primIDSaved
Definition: CaloSD.h:159
void Initialize(G4HCofThisEvent *HCE) override
Definition: CaloSD.cc:248
int primAncestor
Definition: CaloSD.h:156
void reset() override
Definition: CaloSD.cc:562
void processHit(const G4Step *step)
Definition: CaloSD.h:103
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
double kmaxProton
Definition: CaloSD.h:138
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: CaloSD.cc:287
void setUseMap(bool val)
Definition: CaloSD.h:101
double eminHit
Definition: CaloSD.h:133
virtual void initEvent(const BeginOfEvent *)
Definition: CaloSD.cc:570
void cleanHitCollection()
Definition: CaloSD.cc:699
bool forceSave
Definition: CaloSD.h:140
float timeSlice
Definition: CaloSD.h:162
bool checkHit()
Definition: CaloSD.cc:317
double kmaxIon
Definition: CaloSD.h:138
bool suppressHeavy
Definition: CaloSD.h:137
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:145
float edepositHAD
Definition: CaloSD.h:129
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:425
CaloG4Hit * createNewHit(const G4Step *)
Definition: CaloSD.cc:347
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition: CaloSD.cc:107
int getNumberOfHits()
Definition: CaloSD.cc:345
G4ThreeVector setToGlobal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:298
CaloSD(const std::string &aSDname, const DDCompactView &cpv, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *, float timeSlice=1., bool ignoreTkID=false)
Definition: CaloSD.cc:27
CaloHitID previousID
Definition: CaloSD.h:131
~CaloSD() override
Definition: CaloSD.cc:105
CaloG4Hit * currentHit
Definition: CaloSD.h:135
void storeHit(CaloG4Hit *)
Definition: CaloSD.cc:632
virtual bool filterHit(CaloG4Hit *, double)
Definition: CaloSD.cc:612
double tmaxHit
Definition: CaloSD.h:133
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:294
bool hitExists(const G4Step *)
Definition: CaloSD.cc:302
std::unique_ptr< CaloMeanResponse > meanResponse
Definition: CaloSD.h:146
CaloHitID currentID
Definition: CaloSD.h:131
virtual void initRun()
Definition: CaloSD.cc:568
double correctT
Definition: CaloSD.h:164
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:166
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: CaloSD.cc:266
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:438
int nCheckedHits
Definition: CaloSD.h:160
virtual void endEvent()
Definition: CaloSD.cc:572
CaloG4HitCollection * theHC
Definition: CaloSD.h:148
float incidentEnergy
Definition: CaloSD.h:128
virtual int setTrackID(const G4Step *)
Definition: CaloSD.cc:592
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
bool isParameterized
Definition: CaloSD.h:151
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:167
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
Definition: CaloSD.h:168
step
Definition: StallMonitor.cc:94
const SimTrackManager * m_trackManager
Definition: CaloSD.h:143
void clearHits() override
Definition: CaloSD.cc:551
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:623
bool saveHit(CaloG4Hit *)
Definition: CaloSD.cc:644
void PrintAll() override
Definition: CaloSD.cc:280
G4ThreeVector entrancePoint
Definition: CaloSD.h:125
G4ThreeVector entranceLocal
Definition: CaloSD.h:126
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: CaloSD.cc:460
int cleanIndex
Definition: CaloSD.h:157
bool ignoreTrackID
Definition: CaloSD.h:150
void setParameterized(bool val)
Definition: CaloSD.h:100