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  bool isItFineCalo(const G4VTouchable* touch);
71 
72 protected:
73  virtual double getEnergyDeposit(const G4Step* step);
74  virtual double EnergyCorrected(const G4Step& step, const G4Track*);
75  virtual bool getFromLibrary(const G4Step* step);
76 
77  G4ThreeVector setToLocal(const G4ThreeVector&, const G4VTouchable*) const;
78  G4ThreeVector setToGlobal(const G4ThreeVector&, const G4VTouchable*) const;
79 
80  bool hitExists(const G4Step*);
81  bool checkHit();
82  CaloG4Hit* createNewHit(const G4Step*, const G4Track*);
83  void updateHit(CaloG4Hit*);
84  void resetForNewPrimary(const G4Step*);
85  double getAttenuation(const G4Step* aStep, double birk1, double birk2, double birk3) const;
86 
87  static std::string printableDecayChain(const std::vector<unsigned int>& decayChain);
88  void hitBookkeepingFineCalo(const G4Step* step, const G4Track* currentTrack, CaloG4Hit* hit);
89 
90  void update(const BeginOfRun*) override;
91  void update(const BeginOfEvent*) override;
92  void update(const BeginOfTrack* trk) override;
93  void update(const EndOfTrack* trk) override;
94  void update(const ::EndOfEvent*) override;
95  virtual void initRun();
96  virtual void initEvent(const BeginOfEvent*);
97  virtual void endEvent();
98  virtual bool filterHit(CaloG4Hit*, double);
99 
100  virtual int getTrackID(const G4Track*);
101  virtual int setTrackID(const G4Step*);
102  virtual uint16_t getDepth(const G4Step*);
103  double getResponseWt(const G4Track*);
104  int getNumberOfHits();
105  void ignoreRejection() { ignoreReject = true; }
106 
107  inline void setParameterized(bool val) { isParameterized = val; }
108  inline void setUseMap(bool val) { useMap = val; }
109 
110  inline void processHit(const G4Step* step) {
111  // check if it is in the same unit and timeslice as the previous one
112  if (currentID == previousID) {
114  } else if (!checkHit()) {
115  currentHit = createNewHit(step, step->GetTrack());
116  }
117  }
118 
119  inline void setNumberCheckedHits(int val) { nCheckedHits = val; }
120  void printDetectorLevels(const G4VTouchable*) const;
121 
122 private:
123  void storeHit(CaloG4Hit*);
124  bool saveHit(CaloG4Hit*);
125  void cleanHitCollection();
126 
127 protected:
128  // Data relative to primary particle (the one which triggers a shower)
129  // These data are common to all Hits of a given shower.
130  // One shower is made of several hits which differ by the
131  // unit ID (crystal/fibre/scintillator) and the Time slice ID.
132 
133  G4ThreeVector entrancePoint;
134  G4ThreeVector entranceLocal;
135  G4ThreeVector posGlobal;
138 
140 
142 
144 
147 
148  bool forceSave;
149 
150 private:
151  struct Detector {
152  Detector() {}
154  G4LogicalVolume* lv;
155  int level;
156  };
157 
159 
160  std::unique_ptr<CaloSlaveSD> slave;
161  std::unique_ptr<CaloMeanResponse> meanResponse;
162 
164 
168  bool useMap; // use map for comparison of ID
170 
171  int hcID;
175  int primIDSaved; // ID of the last saved primary
176  int nCheckedHits; // number of last hits to compare ID
177 
178  float timeSlice;
179  double eminHitD;
180  double correctT;
182  double eMinFine_;
183 
184  std::map<CaloHitID, CaloG4Hit*> hitMap;
185  std::map<int, TrackWithHistory*> tkMap;
186  std::vector<std::unique_ptr<CaloG4Hit>> reusehit;
187  std::vector<Detector> fineDetectors_;
188 };
189 
190 #endif // SimG4CMS_CaloSD_h
CaloSD::tkMap
std::map< int, TrackWithHistory * > tkMap
Definition: CaloSD.h:185
CaloSD::filterHit
virtual bool filterHit(CaloG4Hit *, double)
Definition: CaloSD.cc:865
CaloSD::edepositHAD
float edepositHAD
Definition: CaloSD.h:137
SimTrackManager
Definition: SimTrackManager.h:35
CaloSD::tmaxHit
double tmaxHit
Definition: CaloSD.h:141
Observer
Definition: Observer.h:23
CaloSD::storeHit
void storeHit(CaloG4Hit *)
Definition: CaloSD.cc:885
CaloSD::setToGlobal
G4ThreeVector setToGlobal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:391
MessageLogger.h
SensitiveCaloDetector.h
CaloSD::currentHit
CaloG4Hit * currentHit
Definition: CaloSD.h:143
CaloSD::ProcessHits
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition: CaloSD.cc:161
CaloSD::kmaxProton
double kmaxProton
Definition: CaloSD.h:146
CaloSD::saveHit
bool saveHit(CaloG4Hit *)
Definition: CaloSD.cc:897
step
step
Definition: StallMonitor.cc:94
CaloSD::ignoreRejection
void ignoreRejection()
Definition: CaloSD.h:105
CaloG4HitCollection.h
CaloSD::cleanIndex
int cleanIndex
Definition: CaloSD.h:173
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
CaloSD::initRun
virtual void initRun()
Definition: CaloSD.cc:817
CaloSD::update
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: CaloSD.cc:707
CaloSD::nCheckedHits
int nCheckedHits
Definition: CaloSD.h:176
CaloSD::getAttenuation
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:685
CaloSD::edepositEM
float edepositEM
Definition: CaloSD.h:137
CaloSD::hitExists
bool hitExists(const G4Step *)
Definition: CaloSD.cc:395
EndOfTrack.h
CaloSlaveSD
Definition: CaloSlaveSD.h:15
EndOfEvent.h
CaloSD::Detector::name
std::string name
Definition: CaloSD.h:153
CaloSD::kmaxIon
double kmaxIon
Definition: CaloSD.h:146
EndOfTrack
Definition: EndOfTrack.h:6
Observer.h
BeginOfTrack.h
CaloSD::setTrackID
virtual int setTrackID(const G4Step *)
Definition: CaloSD.cc:841
CaloSD::getResponseWt
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:876
SensitiveCaloDetector
Definition: SensitiveCaloDetector.h:10
CaloSD::Detector::lv
G4LogicalVolume * lv
Definition: CaloSD.h:154
CaloSD::setDetUnitId
uint32_t setDetUnitId(const G4Step *step) override=0
BeginOfRun.h
CaloSD::useMap
bool useMap
Definition: CaloSD.h:168
CaloSD::isParameterized
bool isParameterized
Definition: CaloSD.h:166
CaloSD::setToLocal
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:387
CaloSD::~CaloSD
~CaloSD() override
Definition: CaloSD.cc:159
CaloSD::primIDSaved
int primIDSaved
Definition: CaloSD.h:175
CaloSD::PrintAll
void PrintAll() override
Definition: CaloSD.cc:369
BeginOfTrack
Definition: BeginOfTrack.h:6
CaloSD::entrancePoint
G4ThreeVector entrancePoint
Definition: CaloSD.h:133
SensitiveDetectorCatalog
Definition: SensitiveDetectorCatalog.h:10
CaloSD::processHit
void processHit(const G4Step *step)
Definition: CaloSD.h:110
CaloSD::posGlobal
G4ThreeVector posGlobal
Definition: CaloSD.h:135
CaloSD::clearHits
void clearHits() override
Definition: CaloSD.cc:800
CaloSD::meanResponse
std::unique_ptr< CaloMeanResponse > meanResponse
Definition: CaloSD.h:161
CaloSD::currentID
CaloHitID currentID
Definition: CaloSD.h:139
CaloSD::energyCut
double energyCut
Definition: CaloSD.h:141
CaloSD::reset
void reset() override
Definition: CaloSD.cc:811
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CaloSD::Detector::level
int level
Definition: CaloSD.h:155
CaloSD::eminHit
double eminHit
Definition: CaloSD.h:141
CaloSD::EndOfEvent
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: CaloSD.cc:352
edm::ParameterSet
Definition: ParameterSet.h:47
CaloSD::hitMap
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:184
CaloSD::theHC
CaloG4HitCollection * theHC
Definition: CaloSD.h:163
CaloSD::ignoreTrackID
bool ignoreTrackID
Definition: CaloSD.h:165
CaloSD::totalHits
int totalHits
Definition: CaloSD.h:174
CaloSD::incidentEnergy
float incidentEnergy
Definition: CaloSD.h:136
CaloSD::kmaxNeutron
double kmaxNeutron
Definition: CaloSD.h:146
CaloSD::eMinFine_
double eMinFine_
Definition: CaloSD.h:182
BeginOfEvent.h
CaloSD::timeSlice
float timeSlice
Definition: CaloSD.h:178
CaloSD::getEnergyDeposit
virtual double getEnergyDeposit(const G4Step *step)
Definition: CaloSD.cc:308
CaloSD::slave
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:160
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:35
CaloSD::printDetectorLevels
void printDetectorLevels(const G4VTouchable *) const
Definition: CaloSD.cc:1104
CaloSD::resetForNewPrimary
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:672
CaloSD::setNumberCheckedHits
void setNumberCheckedHits(int val)
Definition: CaloSD.h:119
BeginOfEvent
Definition: BeginOfEvent.h:6
CaloSD::Detector::Detector
Detector()
Definition: CaloSD.h:152
BeginOfRun
Definition: BeginOfRun.h:6
CaloSD::getDepth
virtual uint16_t getDepth(const G4Step *)
Definition: CaloSD.cc:863
CaloSD::hcID
int hcID
Definition: CaloSD.h:171
CaloSD::eminHitD
double eminHitD
Definition: CaloSD.h:179
edm::EventSetup
Definition: EventSetup.h:58
CaloSD::DrawAll
void DrawAll() override
Definition: CaloSD.cc:367
CaloSD::reusehit
std::vector< std::unique_ptr< CaloG4Hit > > reusehit
Definition: CaloSD.h:186
CaloG4Hit
Definition: CaloG4Hit.h:32
CaloSD::corrTOFBeam
bool corrTOFBeam
Definition: CaloSD.h:169
CaloSD::doFineCalo_
bool doFineCalo_
Definition: CaloSD.h:181
CaloSD::m_trackManager
const SimTrackManager * m_trackManager
Definition: CaloSD.h:158
CaloSD::getTrackID
virtual int getTrackID(const G4Track *)
Definition: CaloSD.cc:823
heppy_batch.val
val
Definition: heppy_batch.py:351
CaloSD::clear
void clear() override
Definition: CaloSD.cc:365
CaloSD::Detector
Definition: CaloSD.h:151
CaloSD::getNumberOfHits
int getNumberOfHits()
Definition: CaloSD.cc:445
CaloSD::cleanHitCollection
void cleanHitCollection()
Definition: CaloSD.cc:988
CaloSD::setParameterized
void setParameterized(bool val)
Definition: CaloSD.h:107
CaloSD::primAncestor
int primAncestor
Definition: CaloSD.h:172
CaloHitID
Definition: CaloHitID.h:11
CaloSD::fineDetectors_
std::vector< Detector > fineDetectors_
Definition: CaloSD.h:187
CaloSD::entranceLocal
G4ThreeVector entranceLocal
Definition: CaloSD.h:134
edm::PCaloHitContainer
std::vector< PCaloHit > PCaloHitContainer
Definition: PCaloHitContainer.h:8
CaloSD::hitBookkeepingFineCalo
void hitBookkeepingFineCalo(const G4Step *step, const G4Track *currentTrack, CaloG4Hit *hit)
Definition: CaloSD.cc:461
CaloG4HitCollection
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
Definition: CaloG4HitCollection.h:11
CaloSD::correctT
double correctT
Definition: CaloSD.h:180
CaloSD::getFromLibrary
virtual bool getFromLibrary(const G4Step *step)
Definition: CaloSD.cc:312
CaloSD::Initialize
void Initialize(G4HCofThisEvent *HCE) override
Definition: CaloSD.cc:334
CaloSD::checkHit
bool checkHit()
Definition: CaloSD.cc:416
CaloSD::forceSave
bool forceSave
Definition: CaloSD.h:148
CaloSD::fillHits
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: CaloSD.cc:376
CaloSD::ignoreReject
bool ignoreReject
Definition: CaloSD.h:167
CaloSD::setUseMap
void setUseMap(bool val)
Definition: CaloSD.h:108
CaloSD::initEvent
virtual void initEvent(const BeginOfEvent *)
Definition: CaloSD.cc:819
CaloSD::printableDecayChain
static std::string printableDecayChain(const std::vector< unsigned int > &decayChain)
Definition: CaloSD.cc:447
CaloSD::updateHit
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:661
CaloSD::suppressHeavy
bool suppressHeavy
Definition: CaloSD.h:145
CaloSD::EnergyCorrected
virtual double EnergyCorrected(const G4Step &step, const G4Track *)
Definition: CaloSD.cc:310
CaloG4Hit.h
CaloSD::isItFineCalo
bool isItFineCalo(const G4VTouchable *touch)
Definition: CaloSD.cc:314
CaloSD
Definition: CaloSD.h:38
CaloMeanResponse.h
hit
Definition: SiStripHitEffFromCalibTree.cc:88
CaloSD::endEvent
virtual void endEvent()
Definition: CaloSD.cc:821
CaloSD::createNewHit
CaloG4Hit * createNewHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:568
CaloSD::previousID
CaloHitID previousID
Definition: CaloSD.h:139
TrackWithHistory.h