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