CMS 3D CMS Logo

FastHFShowerLibrary.cc
Go to the documentation of this file.
1 // File: FastHFShowerLibrary.cc
3 // Description: Shower library for Very forward hadron calorimeter
5 
22 
23 #include "Randomize.hh"
24 #include "CLHEP/Units/GlobalSystemOfUnits.h"
25 #include "CLHEP/Units/GlobalPhysicalConstants.h"
26 
27 // Geant4 headers
28 #include "G4ParticleDefinition.hh"
29 #include "G4DynamicParticle.hh"
30 #include "G4DecayPhysics.hh"
31 #include "G4ParticleTable.hh"
32 #include "G4ParticleTypes.hh"
33 
34 // STL headers
35 #include <vector>
36 #include <iostream>
37 #include <mutex>
38 
39 //#define DebugLog
40 
41 static std::once_flag initializeOnce;
42 
44  : fast(p) {
45  edm::ParameterSet m_HS = p.getParameter<edm::ParameterSet>("HFShowerLibrary");
46  applyFidCut = m_HS.getParameter<bool>("ApplyFiducialCut");
47 }
48 
50 
51  edm::LogInfo("FastCalorimetry") << "initHFShowerLibrary::initialization";
52 
54  iSetup.get<IdealGeometryRecord>().get(cpv);
55 
57  iSetup.get<HcalSimNumberingRecord>().get(hdc);
58  hcalConstants = (HcalDDDSimConstants*)(&(*hdc));
59 
60  std::string name = "HcalHits";
62  hfshower.reset(new HFShowerLibrary(name,*cpv,fast));
63 
64  //only one thread can be allowed to setup the G4 physics table.
65  std::call_once(initializeOnce,[]() {
66  // Geant4 particles
67  G4DecayPhysics decays;
68  decays.ConstructParticle();
69  G4ParticleTable* partTable = G4ParticleTable::GetParticleTable();
70  partTable->SetReadiness();
71  });
72  G4ParticleTable* partTable = G4ParticleTable::GetParticleTable();
73  hfshower->initRun(partTable, hcalConstants); // init particle code
74 }
75 
77 {
78  // define Geant4 engine per thread
79  G4Random::setTheEngine(&(rnd->theEngine()));
80  LogDebug("FastHFShowerLibrary::recoHFShowerLibrary")
81  << "Begin of event " << G4UniformRand() << " "
82  << rnd->theEngine().name() << " " << rnd->theEngine();
83 }
84 
86 
87 #ifdef DebugLog
88  edm::LogInfo("FastCalorimetry") << "FastHFShowerLibrary: recoHFShowerLibrary ";
89 #endif
90 
91  if(!myTrack.onVFcal()) {
92 #ifdef DebugLog
93  edm::LogInfo("FastCalorimetry") << "FastHFShowerLibrary: we should not be here ";
94 #endif
95  }
96 
97  hitMap.clear();
98  double eGen = 1000.*myTrack.vfcalEntrance().e(); // energy in [MeV]
99  double delZv = (myTrack.vfcalEntrance().vertex().Z()>0.0) ? 50.0 : -50.0;
100  G4ThreeVector vertex( 10.*myTrack.vfcalEntrance().vertex().X(),
101  10.*myTrack.vfcalEntrance().vertex().Y(),
102  10.*myTrack.vfcalEntrance().vertex().Z()+delZv); // in [mm]
103 
104  G4ThreeVector direction(myTrack.vfcalEntrance().Vect().X(),
105  myTrack.vfcalEntrance().Vect().Y(),
106  myTrack.vfcalEntrance().Vect().Z());
107 
108  bool ok;
109  double weight = 1.0; // rad. damage
110  int parCode = myTrack.type();
111  double tSlice = 0.1*vertex.mag()/29.98;
112 
113  std::vector<HFShowerLibrary::Hit> hits =
114  hfshower->fillHits(vertex,direction,parCode,eGen,ok,weight,tSlice,false);
115 
116  for (unsigned int i=0; i<hits.size(); ++i) {
117  G4ThreeVector pos = hits[i].position;
118  int depth = hits[i].depth;
119  double time = hits[i].time;
120  if (!applyFidCut || (HFFibreFiducial::PMTNumber(pos)>0) ) {
121 // if (!applyFidCut || (applyFidCut && HFFibreFiducial::PMTNumber(pos)>0)) {
122  int det = 5;
123  int lay = 1;
124  uint32_t id = 0;
125  HcalNumberingFromDDD::HcalID tmp = numberingFromDDD->unitID(det, pos, depth, lay);
126  modifyDepth(tmp);
127  id = numberingScheme.getUnitID(tmp);
128 
129  CaloHitID current_id(id,time,myTrack.id());
130  std::map<CaloHitID,float>::iterator cellitr;
131  cellitr = hitMap.find(current_id);
132  if(cellitr==hitMap.end()) {
133  hitMap.insert(std::pair<CaloHitID,float>(current_id,1.0));
134  } else {
135  cellitr->second += 1.0;
136  }
137  } // end of isItinFidVolume check
138  } // end loop over hits
139 
140 }
141 
143  if (id.subdet == HcalForward) {
144  int ieta = (id.zside == 0) ? -id.etaR : id.etaR;
145  if (hcalConstants->maxHFDepth(ieta,id.phis) > 2) {
146  if (id.depth <= 2) {
147  if (G4UniformRand() > 0.5) id.depth += 2;
148  }
149  }
150  }
151 }
#define LogDebug(id)
T getParameter(std::string const &) const
const RawParticle & vfcalEntrance() const
The particle at VFCAL entrance.
Definition: FSimTrack.h:144
const edm::ParameterSet fast
void recoHFShowerLibrary(const FSimTrack &myTrack)
virtual uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id)
Definition: weight.py:1
static int PMTNumber(const G4ThreeVector &pe_effect)
HcalNumberingScheme numberingScheme
double Y() const
y of vertex
Definition: RawParticle.h:275
double Z() const
z of vertex
Definition: RawParticle.h:276
static std::once_flag initializeOnce
int onVFcal() const
Definition: FSimTrack.h:116
CLHEP::HepRandomEngine & theEngine() const
std::unique_ptr< HcalNumberingFromDDD > numberingFromDDD
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:285
FastHFShowerLibrary(edm::ParameterSet const &p)
void modifyDepth(HcalNumberingFromDDD::HcalID &id)
const T & get() const
Definition: EventSetup.h:55
double X() const
x of vertex
Definition: RawParticle.h:274
void SetRandom(const RandomEngineAndDistribution *)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
std::unique_ptr< HFShowerLibrary > hfshower
int id() const
the index in FBaseSimEvent and other vectors
Definition: FSimTrack.h:91
void const initHFShowerLibrary(const edm::EventSetup &)
std::map< CaloHitID, float > hitMap
int maxHFDepth(const int &ieta, const int &iphi) const
HcalDDDSimConstants * hcalConstants