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 bool filterHit(CaloG4Hit*, double);
90 
91  virtual int getTrackID(const G4Track*);
92  virtual int setTrackID(const G4Step*);
93  virtual uint16_t getDepth(const G4Step*);
94  double getResponseWt(const G4Track*);
95  int getNumberOfHits();
96 
97  inline void setParameterized(bool val) { isParameterized = val; }
98  inline void setUseMap(bool val) { useMap = val; }
99 
100  inline void processHit(const G4Step* step) {
101  // check if it is in the same unit and timeslice as the previous one
102  if (currentID == previousID) {
104  } else if (!checkHit()) {
105  currentHit = createNewHit(step);
106  }
107  }
108 
109  inline void setNumberCheckedHits(int val) { nCheckedHits = val; }
110 
111 private:
112 
113  void storeHit(CaloG4Hit*);
114  bool saveHit(CaloG4Hit*);
115  void cleanHitCollection();
116 
117 protected:
118 
119  // Data relative to primary particle (the one which triggers a shower)
120  // These data are common to all Hits of a given shower.
121  // One shower is made of several hits which differ by the
122  // unit ID (crystal/fibre/scintillator) and the Time slice ID.
123 
124  G4ThreeVector entrancePoint;
125  G4ThreeVector entranceLocal;
126  G4ThreeVector posGlobal;
129 
131 
133 
135 
138 
139  bool forceSave;
140 
141 private:
142 
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 
169  std::vector<CaloG4Hit*> reusehit;
170  std::vector<CaloG4Hit*> hitvec;
171  std::vector<unsigned int> selIndex;
172 
173 };
174 
175 #endif // SimG4CMS_CaloSD_h
float edepositEM
Definition: CaloSD.h:128
double energyCut
Definition: CaloSD.h:132
virtual bool getFromLibrary(const G4Step *step)
Definition: CaloSD.cc:259
std::vector< PCaloHit > PCaloHitContainer
double kmaxNeutron
Definition: CaloSD.h:137
void setNumberCheckedHits(int val)
Definition: CaloSD.h:109
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:434
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:633
virtual double getEnergyDeposit(const G4Step *step)
Definition: CaloSD.cc:255
bool corrTOFBeam
Definition: CaloSD.h:153
Definition: CaloSD.h:37
int totalHits
Definition: CaloSD.h:158
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:152
int hcID
Definition: CaloSD.h:155
double eminHitD
Definition: CaloSD.h:163
G4ThreeVector posGlobal
Definition: CaloSD.h:126
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:593
int primIDSaved
Definition: CaloSD.h:159
void Initialize(G4HCofThisEvent *HCE) override
Definition: CaloSD.cc:263
int primAncestor
Definition: CaloSD.h:156
void processHit(const G4Step *step)
Definition: CaloSD.h:100
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:83
double kmaxProton
Definition: CaloSD.h:137
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: CaloSD.cc:302
void setUseMap(bool val)
Definition: CaloSD.h:98
double eminHit
Definition: CaloSD.h:132
std::vector< CaloG4Hit * > reusehit
Definition: CaloSD.h:169
void cleanHitCollection()
Definition: CaloSD.cc:724
bool forceSave
Definition: CaloSD.h:139
float timeSlice
Definition: CaloSD.h:162
bool checkHit()
Definition: CaloSD.cc:330
double kmaxIon
Definition: CaloSD.h:137
bool suppressHeavy
Definition: CaloSD.h:136
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:145
float edepositHAD
Definition: CaloSD.h:128
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:170
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:130
~CaloSD() override
Definition: CaloSD.cc:99
CaloG4Hit * currentHit
Definition: CaloSD.h:134
std::vector< unsigned int > selIndex
Definition: CaloSD.h:171
void storeHit(CaloG4Hit *)
Definition: CaloSD.cc:655
virtual bool filterHit(CaloG4Hit *, double)
Definition: CaloSD.cc:635
double tmaxHit
Definition: CaloSD.h:132
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:146
CaloHitID currentID
Definition: CaloSD.h:130
virtual void initRun()
Definition: CaloSD.cc:591
double correctT
Definition: CaloSD.h:164
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: CaloSD.cc:280
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:166
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:462
int nCheckedHits
Definition: CaloSD.h:160
CaloG4HitCollection * theHC
Definition: CaloSD.h:148
float incidentEnergy
Definition: CaloSD.h:127
virtual int setTrackID(const G4Step *)
Definition: CaloSD.cc:615
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
bool isParameterized
Definition: CaloSD.h:151
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:167
step
const SimTrackManager * m_trackManager
Definition: CaloSD.h:143
void clearHits() override
Definition: CaloSD.cc:577
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:646
bool saveHit(CaloG4Hit *)
Definition: CaloSD.cc:666
void PrintAll() override
Definition: CaloSD.cc:295
G4ThreeVector entrancePoint
Definition: CaloSD.h:124
G4ThreeVector entranceLocal
Definition: CaloSD.h:125
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: CaloSD.cc:484
int cleanIndex
Definition: CaloSD.h:157
bool ignoreTrackID
Definition: CaloSD.h:150
void setParameterized(bool val)
Definition: CaloSD.h:97