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 
24 
25 #include "G4VPhysicalVolume.hh"
26 #include "G4Track.hh"
27 #include "G4VGFlashSensitiveDetector.hh"
28 
29 #include <vector>
30 #include <map>
31 #include <memory>
32 
33 class G4Step;
34 class G4HCofThisEvent;
35 class CaloSlaveSD;
36 class G4GFlashSpot;
37 class SimTrackManager;
38 
40  public G4VGFlashSensitiveDetector,
41  public Observer<const BeginOfRun*>,
42  public Observer<const BeginOfEvent*>,
43  public Observer<const BeginOfTrack*>,
44  public Observer<const EndOfTrack*>,
45  public Observer<const EndOfEvent*> {
46 public:
47  CaloSD(const std::string& aSDname,
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:863
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:883
CaloSD::setToGlobal
G4ThreeVector setToGlobal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:389
MessageLogger.h
SensitiveCaloDetector.h
CaloSD::currentHit
CaloG4Hit * currentHit
Definition: CaloSD.h:143
CaloSD::ProcessHits
G4bool ProcessHits(G4Step *step, G4TouchableHistory *) override
Definition: CaloSD.cc:159
CaloSD::kmaxProton
double kmaxProton
Definition: CaloSD.h:146
CaloSD::saveHit
bool saveHit(CaloG4Hit *)
Definition: CaloSD.cc:895
step
step
Definition: StallMonitor.cc:94
CaloSD::ignoreRejection
void ignoreRejection()
Definition: CaloSD.h:105
CaloG4HitCollection.h
CaloSD::cleanIndex
int cleanIndex
Definition: CaloSD.h:173
CaloSD::initRun
virtual void initRun()
Definition: CaloSD.cc:815
CaloSD::update
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: CaloSD.cc:705
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:683
CaloSD::edepositEM
float edepositEM
Definition: CaloSD.h:137
CaloSD::hitExists
bool hitExists(const G4Step *)
Definition: CaloSD.cc:393
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:839
CaloSD::getResponseWt
double getResponseWt(const G4Track *)
Definition: CaloSD.cc:874
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:385
CaloSD::~CaloSD
~CaloSD() override
Definition: CaloSD.cc:157
CaloSD::primIDSaved
int primIDSaved
Definition: CaloSD.h:175
CaloSD::PrintAll
void PrintAll() override
Definition: CaloSD.cc:367
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:798
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:809
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:350
edm::ParameterSet
Definition: ParameterSet.h:47
CaloSD::hitMap
std::map< CaloHitID, CaloG4Hit * > hitMap
Definition: CaloSD.h:184
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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:306
CaloSD::slave
std::unique_ptr< CaloSlaveSD > slave
Definition: CaloSD.h:160
CaloSD::CaloSD
CaloSD(const std::string &aSDname, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *, float timeSlice=1., bool ignoreTkID=false)
Definition: CaloSD.cc:34
CaloSD::printDetectorLevels
void printDetectorLevels(const G4VTouchable *) const
Definition: CaloSD.cc:1102
CaloSD::resetForNewPrimary
void resetForNewPrimary(const G4Step *)
Definition: CaloSD.cc:670
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:861
CaloSD::hcID
int hcID
Definition: CaloSD.h:171
CaloSD::eminHitD
double eminHitD
Definition: CaloSD.h:179
CaloSD::DrawAll
void DrawAll() override
Definition: CaloSD.cc:365
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
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:821
heppy_batch.val
val
Definition: heppy_batch.py:351
CaloSD::clear
void clear() override
Definition: CaloSD.cc:363
CaloSD::Detector
Definition: CaloSD.h:151
CaloSD::getNumberOfHits
int getNumberOfHits()
Definition: CaloSD.cc:443
CaloSD::cleanHitCollection
void cleanHitCollection()
Definition: CaloSD.cc:986
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
ParameterSetfwd.h
CaloSD::hitBookkeepingFineCalo
void hitBookkeepingFineCalo(const G4Step *step, const G4Track *currentTrack, CaloG4Hit *hit)
Definition: CaloSD.cc:459
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:310
CaloSD::Initialize
void Initialize(G4HCofThisEvent *HCE) override
Definition: CaloSD.cc:332
CaloSD::checkHit
bool checkHit()
Definition: CaloSD.cc:414
CaloSD::forceSave
bool forceSave
Definition: CaloSD.h:148
CaloSD::fillHits
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: CaloSD.cc:374
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:817
CaloSD::printableDecayChain
static std::string printableDecayChain(const std::vector< unsigned int > &decayChain)
Definition: CaloSD.cc:445
CaloSD::updateHit
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:659
CaloSD::suppressHeavy
bool suppressHeavy
Definition: CaloSD.h:145
CaloSD::EnergyCorrected
virtual double EnergyCorrected(const G4Step &step, const G4Track *)
Definition: CaloSD.cc:308
CaloG4Hit.h
CaloSD::isItFineCalo
bool isItFineCalo(const G4VTouchable *touch)
Definition: CaloSD.cc:312
CaloSD
Definition: CaloSD.h:39
CaloMeanResponse.h
hit
Definition: SiStripHitEffFromCalibTree.cc:88
CaloSD::endEvent
virtual void endEvent()
Definition: CaloSD.cc:819
CaloSD::createNewHit
CaloG4Hit * createNewHit(const G4Step *, const G4Track *)
Definition: CaloSD.cc:566
CaloSD::previousID
CaloHitID previousID
Definition: CaloSD.h:139
TrackWithHistory.h