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 
24 
25 #include "Randomize.hh"
26 #include "CLHEP/Units/GlobalSystemOfUnits.h"
27 #include "CLHEP/Units/GlobalPhysicalConstants.h"
28 
29 // Geant4 headers
30 #include "G4ParticleDefinition.hh"
31 #include "G4DynamicParticle.hh"
32 #include "G4DecayPhysics.hh"
33 #include "G4ParticleTable.hh"
34 #include "G4ParticleTypes.hh"
35 
36 // STL headers
37 #include <vector>
38 #include <iostream>
39 #include <mutex>
40 
41 //#define DebugLog
42 
43 static std::once_flag initializeOnce;
44 
46  edm::ParameterSet m_HS = p.getParameter<edm::ParameterSet>("HFShowerLibrary");
47  applyFidCut = m_HS.getParameter<bool>("ApplyFiducialCut");
48 }
49 
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 
61  iSetup.get<HcalSimNumberingRecord>().get(hdsc);
62  const HcalDDDSimulationConstants* hsps = hdsc.product();
63 
64  std::string name = "HcalHits";
66  hfshower.reset(new HFShowerLibrary(name, hcalConstants, hsps->hcalsimpar(), fast));
67 
68  //only one thread can be allowed to setup the G4 physics table.
69  std::call_once(initializeOnce, []() {
70  // Geant4 particles
71  G4DecayPhysics decays;
72  decays.ConstructParticle();
73  G4ParticleTable* partTable = G4ParticleTable::GetParticleTable();
74  partTable->SetReadiness();
75  });
76  //G4ParticleTable* partTable = G4ParticleTable::GetParticleTable();
77  //hfshower->initRun(partTable, hcalConstants); // init particle code
78 }
79 
81  // define Geant4 engine per thread
82  G4Random::setTheEngine(&(rnd->theEngine()));
83  LogDebug("FastHFShowerLibrary::recoHFShowerLibrary")
84  << "Begin of event " << G4UniformRand() << " " << rnd->theEngine().name() << " " << rnd->theEngine();
85 }
86 
88 #ifdef DebugLog
89  edm::LogInfo("FastCalorimetry") << "FastHFShowerLibrary: recoHFShowerLibrary ";
90 #endif
91 
92  if (!myTrack.onVFcal()) {
93 #ifdef DebugLog
94  edm::LogInfo("FastCalorimetry") << "FastHFShowerLibrary: we should not be here ";
95 #endif
96  }
97 
98  hitMap.clear();
99  double eGen = 1000. * myTrack.vfcalEntrance().e(); // energy in [MeV]
100  double delZv = (myTrack.vfcalEntrance().vertex().Z() > 0.0) ? 50.0 : -50.0;
101  G4ThreeVector vertex(10. * myTrack.vfcalEntrance().vertex().X(),
102  10. * myTrack.vfcalEntrance().vertex().Y(),
103  10. * myTrack.vfcalEntrance().vertex().Z() + delZv); // in [mm]
104 
105  G4ThreeVector direction(
106  myTrack.vfcalEntrance().Vect().X(), myTrack.vfcalEntrance().Vect().Y(), 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(), pos.z()), depth, lay);
127  modifyDepth(tmp);
128  id = numberingScheme.getUnitID(tmp);
129 
130  CaloHitID current_id(id, time, myTrack.id());
131  std::map<CaloHitID, float>::iterator cellitr;
132  cellitr = hitMap.find(current_id);
133  if (cellitr == hitMap.end()) {
134  hitMap.insert(std::pair<CaloHitID, float>(current_id, 1.0));
135  } else {
136  cellitr->second += 1.0;
137  }
138  } // end of isItinFidVolume check
139  } // end loop over hits
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)
148  id.depth += 2;
149  }
150  }
151  }
152 }
#define LogDebug(id)
std::map< CaloHitID, float > hitMap
T getParameter(std::string const &) const
XYZVector Vect() const
the momentum threevector
Definition: RawParticle.h:323
const RawParticle & vfcalEntrance() const
The particle at VFCAL entrance.
Definition: FSimTrack.h:149
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:305
static std::once_flag initializeOnce
int onVFcal() const
Definition: FSimTrack.h:121
CLHEP::HepRandomEngine & theEngine() const
std::unique_ptr< HcalNumberingFromDDD > numberingFromDDD
const HcalSimulationParameters * hcalsimpar() const
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:320
int PMTNumber(const G4ThreeVector &pe_effect)
FastHFShowerLibrary(edm::ParameterSet const &p)
void modifyDepth(HcalNumberingFromDDD::HcalID &id)
void SetRandom(const RandomEngineAndDistribution *)
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:96
T get() const
Definition: EventSetup.h:73
const HcalDDDSimConstants * hcalConstants
void const initHFShowerLibrary(const edm::EventSetup &)
tmp
align.sh
Definition: createJobs.py:716
int maxHFDepth(const int &ieta, const int &iphi) const
T const * product() const
Definition: ESHandle.h:86