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 = hdc.product();
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;
126  numberingFromDDD->unitID(det, math::XYZVectorD(pos.x(),pos.y(),
127  pos.z()), depth, lay);
128  modifyDepth(tmp);
129  id = numberingScheme.getUnitID(tmp);
130 
131  CaloHitID current_id(id,time,myTrack.id());
132  std::map<CaloHitID,float>::iterator cellitr;
133  cellitr = hitMap.find(current_id);
134  if(cellitr==hitMap.end()) {
135  hitMap.insert(std::pair<CaloHitID,float>(current_id,1.0));
136  } else {
137  cellitr->second += 1.0;
138  }
139  } // end of isItinFidVolume check
140  } // end loop over hits
141 
142 }
143 
145  if (id.subdet == HcalForward) {
146  int ieta = (id.zside == 0) ? -id.etaR : id.etaR;
147  if (hcalConstants->maxHFDepth(ieta,id.phis) > 2) {
148  if (id.depth <= 2) {
149  if (G4UniformRand() > 0.5) id.depth += 2;
150  }
151  }
152  }
153 }
#define LogDebug(id)
T getParameter(std::string const &) const
XYZVector Vect() const
the momentum threevector
Definition: RawParticle.h:342
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
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
HcalNumberingScheme numberingScheme
double e() const
energy of the momentum
Definition: RawParticle.h:324
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:339
int PMTNumber(const G4ThreeVector &pe_effect)
FastHFShowerLibrary(edm::ParameterSet const &p)
void modifyDepth(HcalNumberingFromDDD::HcalID &id)
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:22
std::unique_ptr< HFShowerLibrary > hfshower
int id() const
the index in FBaseSimEvent and other vectors
Definition: FSimTrack.h:91
T get() const
Definition: EventSetup.h:71
const HcalDDDSimConstants * hcalConstants
void const initHFShowerLibrary(const edm::EventSetup &)
std::map< CaloHitID, float > hitMap
int maxHFDepth(const int &ieta, const int &iphi) const
T const * product() const
Definition: ESHandle.h:86