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  id = numberingScheme.getUnitID(tmp);
127 
128  CaloHitID current_id(id,time,myTrack.id());
129  std::map<CaloHitID,float>::iterator cellitr;
130  cellitr = hitMap.find(current_id);
131  if(cellitr==hitMap.end()) {
132  hitMap.insert(std::pair<CaloHitID,float>(current_id,1.0));
133  } else {
134  cellitr->second += 1.0;
135  }
136  } // end of isItinFidVolume check
137  } // end loop over hits
138 
139 }
140 
142 
143  HcalDetId hid(id);
144  if (hid.subdet() == HcalForward) {
145  int eta = hid.ieta();
146  int phi = hid.iphi();
147  if (hcalConstants->maxHFDepth(eta,phi) > 2) {
148  if (hid.depth() <= 2) {
149  int dep = (G4UniformRand() > 0.5) ? (2+hid.depth()) : hid.depth();
150  id = HcalDetId(HcalForward,eta,phi,dep).rawId();
151  }
152  }
153  }
154 }
#define LogDebug(id)
T getParameter(std::string const &) const
const RawParticle & vfcalEntrance() const
The particle at VFCAL entrance.
Definition: FSimTrack.h:144
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
const edm::ParameterSet fast
void recoHFShowerLibrary(const FSimTrack &myTrack)
virtual uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id)
Definition: weight.py:1
void modifyDepth(uint32_t &id)
static int PMTNumber(const G4ThreeVector &pe_effect)
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
int depth() const
get the tower depth
Definition: HcalDetId.cc:108
HcalNumberingScheme numberingScheme
double Y() const
y of vertex
Definition: RawParticle.h:275
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
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
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
FastHFShowerLibrary(edm::ParameterSet const &p)
const T & get() const
Definition: EventSetup.h:59
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