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 edm::EventSetup& es,
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*, const G4Track*);
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, step->GetTrack());
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;
166 
167  std::map<CaloHitID, CaloG4Hit*> hitMap;
168  std::map<int, TrackWithHistory*> tkMap;
169  std::vector<std::unique_ptr<CaloG4Hit>> reusehit;
170 };
171 
172 #endif // SimG4CMS_CaloSD_h
CaloSD::tkMap
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:168
CaloSD::filterHit
virtual bool filterHit(CaloG4Hit *, double)
Definition: CaloSD.cc:616
CaloSD::edepositHAD
float edepositHAD
Definition: CaloSD.h:129
SimTrackManager
Definition: SimTrackManager.h:35
CaloSD::tmaxHit
double tmaxHit
Definition: CaloSD.h:133
Observer
Definition: Observer.h:23
CaloSD::storeHit
void storeHit(CaloG4Hit *)
Definition: CaloSD.cc:636
CaloSD::setToGlobal
G4ThreeVector setToGlobal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:295
MessageLogger.h
SensitiveCaloDetector.h
CaloSD::currentHit
CaloG4Hit * currentHit
Definition: CaloSD.h:135
CaloSD::ProcessHits
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition: CaloSD.cc:107
CaloSD::kmaxProton
double kmaxProton
Definition: CaloSD.h:138
CaloSD::saveHit
bool saveHit(CaloG4Hit *)
Definition: CaloSD.cc:648
step
step
Definition: StallMonitor.cc:94
CaloG4HitCollection.h
CaloSD::useFineCaloID_
bool useFineCaloID_
Definition: CaloSD.h:165
CaloSD::cleanIndex
int cleanIndex
Definition: CaloSD.h:157
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CaloSD::initRun
virtual void initRun()
Definition: CaloSD.cc:567
CaloSD::update
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: CaloSD.cc:457
CaloSD::nCheckedHits
int nCheckedHits
Definition: CaloSD.h:160
CaloSD::getAttenuation
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:435
CaloSD::edepositEM
float edepositEM
Definition: CaloSD.h:129
CaloSD::hitExists
bool hitExists(const G4Step *)
Definition: CaloSD.cc:299
EndOfTrack.h
CaloSlaveSD
Definition: CaloSlaveSD.h:16
EndOfEvent.h
CaloSD::kmaxIon
double kmaxIon
Definition: CaloSD.h:138
EndOfTrack
Definition: EndOfTrack.h:6
Observer.h
BeginOfTrack.h
CaloSD::setTrackID
virtual int setTrackID(const G4Step *)
Definition: CaloSD.cc:592
CaloSD::getResponseWt
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:627
SensitiveCaloDetector
Definition: SensitiveCaloDetector.h:10
CaloSD::setDetUnitId
uint32_t setDetUnitId(const G4Step *step) override=0
BeginOfRun.h
CaloSD::useMap
bool useMap
Definition: CaloSD.h:152
CaloSD::isParameterized
bool isParameterized
Definition: CaloSD.h:151
CaloSD::setToLocal
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:291
CaloSD::~CaloSD
~CaloSD() override
Definition: CaloSD.cc:105
CaloSD::primIDSaved
int primIDSaved
Definition: CaloSD.h:159
CaloSD::PrintAll
void PrintAll() override
Definition: CaloSD.cc:277
BeginOfTrack
Definition: BeginOfTrack.h:6
CaloSD::entrancePoint
G4ThreeVector entrancePoint
Definition: CaloSD.h:125
SensitiveDetectorCatalog
Definition: SensitiveDetectorCatalog.h:10
CaloSD::processHit
void processHit(const G4Step *step)
Definition: CaloSD.h:103
CaloSD::posGlobal
G4ThreeVector posGlobal
Definition: CaloSD.h:127
CaloSD::clearHits
void clearHits() override
Definition: CaloSD.cc:550
CaloSD::meanResponse
std::unique_ptr< CaloMeanResponse > meanResponse
Definition: CaloSD.h:146
CaloSD::currentID
CaloHitID currentID
Definition: CaloSD.h:131
CaloSD::energyCut
double energyCut
Definition: CaloSD.h:133
CaloSD::reset
void reset() override
Definition: CaloSD.cc:561
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CaloSD::eminHit
double eminHit
Definition: CaloSD.h:133
CaloSD::EndOfEvent
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: CaloSD.cc:263
edm::ParameterSet
Definition: ParameterSet.h:36
CaloSD::hitMap
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:167
CaloSD::theHC
CaloG4HitCollection * theHC
Definition: CaloSD.h:148
CaloSD::ignoreTrackID
bool ignoreTrackID
Definition: CaloSD.h:150
CaloSD::totalHits
int totalHits
Definition: CaloSD.h:158
CaloSD::incidentEnergy
float incidentEnergy
Definition: CaloSD.h:128
CaloSD::kmaxNeutron
double kmaxNeutron
Definition: CaloSD.h:138
BeginOfEvent.h
CaloSD::timeSlice
float timeSlice
Definition: CaloSD.h:162
CaloSD::getEnergyDeposit
virtual double getEnergyDeposit(const G4Step *step)
Definition: CaloSD.cc:241
CaloSD::slave
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:145
CaloSD::CaloSD
CaloSD(const std::string &aSDname, const edm::EventSetup &es, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *, float timeSlice=1., bool ignoreTkID=false)
Definition: CaloSD.cc:27
CaloSD::resetForNewPrimary
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:422
CaloSD::setNumberCheckedHits
void setNumberCheckedHits(int val)
Definition: CaloSD.h:112
BeginOfEvent
Definition: BeginOfEvent.h:6
BeginOfRun
Definition: BeginOfRun.h:6
CaloSD::getDepth
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:614
CaloSD::hcID
int hcID
Definition: CaloSD.h:155
CaloSD::eminHitD
double eminHitD
Definition: CaloSD.h:163
edm::EventSetup
Definition: EventSetup.h:57
CaloSD::DrawAll
void DrawAll() override
Definition: CaloSD.cc:275
CaloSD::reusehit
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
Definition: CaloSD.h:169
CaloG4Hit
Definition: CaloG4Hit.h:32
CaloSD::corrTOFBeam
bool corrTOFBeam
Definition: CaloSD.h:153
CaloSD::m_trackManager
const SimTrackManager * m_trackManager
Definition: CaloSD.h:143
CaloSD::getTrackID
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:573
heppy_batch.val
val
Definition: heppy_batch.py:351
CaloSD::clear
void clear() override
Definition: CaloSD.cc:273
CaloSD::getNumberOfHits
int getNumberOfHits()
Definition: CaloSD.cc:343
CaloSD::cleanHitCollection
void cleanHitCollection()
Definition: CaloSD.cc:707
CaloSD::setParameterized
void setParameterized(bool val)
Definition: CaloSD.h:100
CaloSD::primAncestor
int primAncestor
Definition: CaloSD.h:156
CaloHitID
Definition: CaloHitID.h:11
CaloSD::entranceLocal
G4ThreeVector entranceLocal
Definition: CaloSD.h:126
edm::PCaloHitContainer
std::vector< PCaloHit > PCaloHitContainer
Definition: PCaloHitContainer.h:8
CaloG4HitCollection
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
Definition: CaloG4HitCollection.h:11
CaloSD::correctT
double correctT
Definition: CaloSD.h:164
CaloSD::getFromLibrary
virtual bool getFromLibrary(const G4Step *step)
Definition: CaloSD.cc:243
CaloSD::Initialize
void Initialize(G4HCofThisEvent *HCE) override
Definition: CaloSD.cc:245
CaloSD::checkHit
bool checkHit()
Definition: CaloSD.cc:314
CaloSD::forceSave
bool forceSave
Definition: CaloSD.h:140
CaloSD::fillHits
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: CaloSD.cc:284
CaloSD::setUseMap
void setUseMap(bool val)
Definition: CaloSD.h:101
CaloSD::initEvent
virtual void initEvent(const BeginOfEvent *)
Definition: CaloSD.cc:569
CaloSD::updateHit
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:411
CaloSD::suppressHeavy
bool suppressHeavy
Definition: CaloSD.h:137
CaloG4Hit.h
CaloSD
Definition: CaloSD.h:38
CaloMeanResponse.h
CaloSD::endEvent
virtual void endEvent()
Definition: CaloSD.cc:571
CaloSD::createNewHit
CaloG4Hit * createNewHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:345
CaloSD::previousID
CaloHitID previousID
Definition: CaloSD.h:131
TrackWithHistory.h