CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HCalSD.cc
Go to the documentation of this file.
1 // File: HCalSD.cc
3 // Description: Sensitive Detector class for calorimeters
5 
16 
24 
25 #include "G4LogicalVolumeStore.hh"
26 #include "G4LogicalVolume.hh"
27 #include "G4Step.hh"
28 #include "G4Track.hh"
29 #include "G4ParticleTable.hh"
30 #include "G4VProcess.hh"
31 
32 #include "G4SystemOfUnits.hh"
33 #include "G4PhysicalConstants.hh"
34 
35 #include <iostream>
36 #include <fstream>
37 #include <iomanip>
38 
39 //#define DebugLog
40 //#define plotDebug
41 
42 HCalSD::HCalSD(G4String name, const DDCompactView & cpv,
43  const SensitiveDetectorCatalog & clg,
44  edm::ParameterSet const & p, const SimTrackManager* manager) :
45  CaloSD(name, cpv, clg, p, manager,
46  (float)(p.getParameter<edm::ParameterSet>("HCalSD").getParameter<double>("TimeSliceUnit")),
47  p.getParameter<edm::ParameterSet>("HCalSD").getParameter<bool>("IgnoreTrackID")),
48  hcalConstants(0), numberingFromDDD(0), numberingScheme(0), showerLibrary(0),
49  hfshower(0), showerParam(0), showerPMT(0), showerBundle(0), m_HEDarkening(0),
50  m_HFDarkening(0) {
51 
52  //static SimpleConfigurable<bool> on1(false, "HCalSD:UseBirkLaw");
53  //static SimpleConfigurable<double> bk1(0.013, "HCalSD:BirkC1");
54  //static SimpleConfigurable<double> bk2(0.0568,"HCalSD:BirkC2");
55  //static SimpleConfigurable<double> bk3(1.75, "HCalSD:BirkC3");
56  // Values from NIM 80 (1970) 239-244: as implemented in Geant3
57  //static SimpleConfigurable<bool> on2(true,"HCalSD:UseShowerLibrary");
59  useBirk = m_HC.getParameter<bool>("UseBirkLaw");
60  birk1 = m_HC.getParameter<double>("BirkC1")*(g/(MeV*cm2));
61  birk2 = m_HC.getParameter<double>("BirkC2");
62  birk3 = m_HC.getParameter<double>("BirkC3");
63  useShowerLibrary = m_HC.getParameter<bool>("UseShowerLibrary");
64  useParam = m_HC.getParameter<bool>("UseParametrize");
65  testNumber = m_HC.getParameter<bool>("TestNumberingScheme");
66  usePMTHit = m_HC.getParameter<bool>("UsePMTHits");
67  betaThr = m_HC.getParameter<double>("BetaThreshold");
68  eminHitHB = m_HC.getParameter<double>("EminHitHB")*MeV;
69  eminHitHE = m_HC.getParameter<double>("EminHitHE")*MeV;
70  eminHitHO = m_HC.getParameter<double>("EminHitHO")*MeV;
71  eminHitHF = m_HC.getParameter<double>("EminHitHF")*MeV;
72  useFibreBundle = m_HC.getParameter<bool>("UseFibreBundleHits");
73  deliveredLumi = m_HC.getParameter<double>("DelivLuminosity");
74  bool ageingFlagHE= m_HC.getParameter<bool>("HEDarkening");
75  bool ageingFlagHF= m_HC.getParameter<bool>("HFDarkening");
76  useHF = m_HC.getUntrackedParameter<bool>("UseHF",true);
77  bool forTBH2 = m_HC.getUntrackedParameter<bool>("ForTBH2",false);
78  useLayerWt = m_HC.getUntrackedParameter<bool>("UseLayerWt",false);
79  std::string file = m_HC.getUntrackedParameter<std::string>("WtFile","None");
80  edm::ParameterSet m_HF = p.getParameter<edm::ParameterSet>("HFShower");
81  applyFidCut = m_HF.getParameter<bool>("ApplyFiducialCut");
82 
83 #ifdef DebugLog
84  LogDebug("HcalSim") << "***************************************************"
85  << "\n"
86  << "* *"
87  << "\n"
88  << "* Constructing a HCalSD with name " << name << "\n"
89  << "* *"
90  << "\n"
91  << "***************************************************";
92 #endif
93  edm::LogInfo("HcalSim") << "HCalSD:: Use of HF code is set to " << useHF
94  << "\nUse of shower parametrization set to "
95  << useParam << "\nUse of shower library is set to "
96  << useShowerLibrary << "\nUse PMT Hit is set to "
97  << usePMTHit << " with beta Threshold "<< betaThr
98  << "\nUSe of FibreBundle Hit set to "<<useFibreBundle
99  << "\n Use of Birks law is set to "
100  << useBirk << " with three constants kB = "
101  << birk1 << ", C1 = " << birk2 << ", C2 = " << birk3;
102  edm::LogInfo("HcalSim") << "HCalSD:: Suppression Flag " << suppressHeavy
103  << " protons below " << kmaxProton << " MeV,"
104  << " neutrons below " << kmaxNeutron << " MeV and"
105  << " ions below " << kmaxIon << " MeV\n"
106  << " Threshold for storing hits in HB: "
107  << eminHitHB << " HE: " << eminHitHE << " HO: "
108  << eminHitHO << " HF: " << eminHitHF << "\n"
109  << "Delivered luminosity for Darkening "
110  << deliveredLumi << " Flag (HE) " << ageingFlagHE
111  << " Flag (HF) " << ageingFlagHF << "\n"
112  << "Application of Fiducial Cut " << applyFidCut;
113 
114  HcalNumberingScheme* scheme;
115  if (testNumber || forTBH2)
116  scheme = dynamic_cast<HcalNumberingScheme*>(new HcalTestNumberingScheme(forTBH2));
117  else
118  scheme = new HcalNumberingScheme();
119  setNumberingScheme(scheme);
120 
121  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
122  std::vector<G4LogicalVolume *>::const_iterator lvcite;
123  G4LogicalVolume* lv;
124  std::string attribute, value;
125  if (useHF) {
126  if (useParam) {
127  showerParam = new HFShowerParam(name, cpv, p);
128  } else {
129  if (useShowerLibrary) showerLibrary = new HFShowerLibrary(name, cpv, p);
130  hfshower = new HFShower(name, cpv, p, 0);
131  }
132 
133  // HF volume names
134  attribute = "Volume";
135  value = "HF";
136  DDSpecificsFilter filter0;
137  DDValue ddv0(attribute, value, 0);
138  filter0.setCriteria(ddv0, DDCompOp::equals);
139  DDFilteredView fv0(cpv);
140  fv0.addFilter(filter0);
141  hfNames = getNames(fv0);
142  fv0.firstChild();
143  DDsvalues_type sv0(fv0.mergedSpecifics());
144  std::vector<double> temp = getDDDArray("Levels",sv0);
145  edm::LogInfo("HcalSim") << "HCalSD: Names to be tested for " << attribute
146  << " = " << value << " has " << hfNames.size()
147  << " elements";
148  for (unsigned int i=0; i < hfNames.size(); ++i) {
149  G4String namv = hfNames[i];
150  lv = 0;
151  for(lvcite=lvs->begin(); lvcite!=lvs->end(); lvcite++)
152  if((*lvcite)->GetName()==namv) {
153  lv = (*lvcite);
154  break;
155  }
156  hfLV.push_back(lv);
157  int level = static_cast<int>(temp[i]);
158  hfLevels.push_back(level);
159  edm::LogInfo("HcalSim") << "HCalSD: HF[" << i << "] = " << hfNames[i]
160  << " LV " << hfLV[i] << " at level "
161  << hfLevels[i];
162  }
163 
164  // HF Fibre volume names
165  value = "HFFibre";
166  DDSpecificsFilter filter1;
167  DDValue ddv1(attribute,value,0);
168  filter1.setCriteria(ddv1, DDCompOp::equals);
169  DDFilteredView fv1(cpv);
170  fv1.addFilter(filter1);
171  fibreNames = getNames(fv1);
172  edm::LogInfo("HcalSim") << "HCalSD: Names to be tested for " << attribute
173  << " = " << value << ":";
174  for (unsigned int i=0; i<fibreNames.size(); ++i) {
175  G4String namv = fibreNames[i];
176  lv = 0;
177  for (lvcite = lvs->begin(); lvcite != lvs->end(); ++lvcite) {
178  if ((*lvcite)->GetName() == namv) {
179  lv = (*lvcite);
180  break;
181  }
182  }
183  fibreLV.push_back(lv);
184  edm::LogInfo("HcalSim") << "HCalSD: (" << i << ") " << fibreNames[i]
185  << " LV " << fibreLV[i];
186  }
187 
188  // HF PMT volume names
189  value = "HFPMT";
190  DDSpecificsFilter filter3;
191  DDValue ddv3(attribute,value,0);
192  filter3.setCriteria(ddv3,DDCompOp::equals);
193  DDFilteredView fv3(cpv);
194  fv3.addFilter(filter3);
195  std::vector<G4String> pmtNames = getNames(fv3);
196  edm::LogInfo("HcalSim") << "HCalSD: Names to be tested for " << attribute
197  << " = " << value << " have " << pmtNames.size()
198  << " entries";
199  for (unsigned int i=0; i<pmtNames.size(); ++i) {
200  G4String namv = pmtNames[i];
201  lv = 0;
202  for (lvcite = lvs->begin(); lvcite != lvs->end(); ++lvcite)
203  if ((*lvcite)->GetName() == namv) {
204  lv = (*lvcite);
205  break;
206  }
207  pmtLV.push_back(lv);
208  edm::LogInfo("HcalSim") << "HCalSD: (" << i << ") " << pmtNames[i]
209  << " LV " << pmtLV[i];
210  }
211  if (pmtNames.size() > 0) showerPMT = new HFShowerPMT (name, cpv, p);
212 
213  // HF Fibre bundles
214  value = "HFFibreBundleStraight";
215  DDSpecificsFilter filter4;
216  DDValue ddv4(attribute,value,0);
217  filter4.setCriteria(ddv4,DDCompOp::equals);
218  DDFilteredView fv4(cpv);
219  fv4.addFilter(filter4);
220  std::vector<G4String> fibreNames = getNames(fv4);
221  edm::LogInfo("HcalSim") << "HCalSD: Names to be tested for " << attribute
222  << " = " << value << " have " << fibreNames.size()
223  << " entries";
224  for (unsigned int i=0; i<fibreNames.size(); ++i) {
225  G4String namv = fibreNames[i];
226  lv = 0;
227  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
228  if ((*lvcite)->GetName() == namv) {
229  lv = (*lvcite);
230  break;
231  }
232  fibre1LV.push_back(lv);
233  edm::LogInfo("HcalSim") << "HCalSD: (" << i << ") " << fibreNames[i]
234  << " LV " << fibre1LV[i];
235  }
236 
237  // Geometry parameters for HF
238  value = "HFFibreBundleConical";
239  DDSpecificsFilter filter5;
240  DDValue ddv5(attribute,value,0);
241  filter5.setCriteria(ddv5,DDCompOp::equals);
242  DDFilteredView fv5(cpv);
243  fv5.addFilter(filter5);
244  fibreNames = getNames(fv5);
245  edm::LogInfo("HcalSim") << "HCalSD: Names to be tested for " << attribute
246  << " = " << value << " have " << fibreNames.size()
247  << " entries";
248  for (unsigned int i=0; i<fibreNames.size(); ++i) {
249  G4String namv = fibreNames[i];
250  lv = 0;
251  for (lvcite = lvs->begin(); lvcite != lvs->end(); ++lvcite)
252  if ((*lvcite)->GetName() == namv) {
253  lv = (*lvcite);
254  break;
255  }
256  fibre2LV.push_back(lv);
257  edm::LogInfo("HcalSim") << "HCalSD: (" << i << ") " << fibreNames[i]
258  << " LV " << fibre2LV[i];
259  }
260  if (fibre1LV.size() > 0 || fibre2LV.size() > 0)
261  showerBundle = new HFShowerFibreBundle (name, cpv, p);
262  }
263 
264  //Material list for HB/HE/HO sensitive detectors
265  const G4MaterialTable * matTab = G4Material::GetMaterialTable();
266  std::vector<G4Material*>::const_iterator matite;
267  attribute = "OnlyForHcalSimNumbering";
268  value = "any";
269  DDSpecificsFilter filter2;
270  DDValue ddv2(attribute,value,0);
271  filter2.setCriteria(ddv2, DDCompOp::not_equals,
272  DDLogOp::AND, true, true);
273  DDFilteredView fv2(cpv);
274  fv2.addFilter(filter2);
275  bool dodet = fv2.firstChild();
277 
278  while (dodet) {
279  const DDLogicalPart & log = fv2.logicalPart();
280  G4String namx = log.name().name();
281  if (!isItHF(namx) && !isItFibre(namx)) {
282  bool notIn = true;
283  for (unsigned int i=0; i<matNames.size(); ++i) {
284  if (!strcmp(matNames[i].c_str(),log.material().name().name().c_str())){
285  notIn = false;
286  break;
287  }
288  }
289  if (notIn) {
290  namx = log.material().name().name();
291  matNames.push_back(namx);
292  G4Material* mat = nullptr;
293  for (matite = matTab->begin(); matite != matTab->end(); ++matite) {
294  if ((*matite)->GetName() == namx) {
295  mat = (*matite);
296  break;
297  }
298  }
299  materials.push_back(mat);
300  }
301  }
302  dodet = fv2.next();
303  }
304 
305  edm::LogInfo("HcalSim") << "HCalSD: Material names for " << attribute
306  << " = " << name << ":";
307  for (unsigned int i=0; i<matNames.size(); ++i)
308  edm::LogInfo("HcalSim") << "HCalSD: (" << i << ") " << matNames[i]
309  << " pointer " << materials[i];
310 
311  mumPDG = mupPDG = 0;
312  maxDepthHF = 2;
313 
314  if (useLayerWt) readWeightFromFile(file);
315 
316  for (int i=0; i<9; ++i) hit_[i] = time_[i]= dist_[i] = 0;
317  hzvem = hzvhad = 0;
318 
319  if (ageingFlagHE) m_HEDarkening = new HEDarkening();
320  if (ageingFlagHF) m_HFDarkening = new HFDarkening();
321 #ifdef plotDebug
323 
324  if ( tfile.isAvailable() ) {
325  static const char * const labels[] = {"HB", "HE", "HO", "HF Absorber", "HF PMT",
326  "HF Absorber Long", "HF Absorber Short",
327  "HF PMT Long", "HF PMT Short"};
328  TFileDirectory hcDir = tfile->mkdir("ProfileFromHCalSD");
329  char name[20], title[60];
330  for (int i=0; i<9; ++i) {
331  sprintf (title, "Hit energy in %s", labels[i]);
332  sprintf (name, "HCalSDHit%d", i);
333  hit_[i] = hcDir.make<TH1F>(name, title, 2000, 0., 2000.);
334  sprintf (title, "Energy (MeV)");
335  hit_[i]->GetXaxis()->SetTitle(title);
336  hit_[i]->GetYaxis()->SetTitle("Hits");
337  sprintf (title, "Time of the hit in %s", labels[i]);
338  sprintf (name, "HCalSDTime%d", i);
339  time_[i] = hcDir.make<TH1F>(name, title, 2000, 0., 2000.);
340  sprintf (title, "Time (ns)");
341  time_[i]->GetXaxis()->SetTitle(title);
342  time_[i]->GetYaxis()->SetTitle("Hits");
343  sprintf (title, "Longitudinal profile in %s", labels[i]);
344  sprintf (name, "HCalSDDist%d", i);
345  dist_[i] = hcDir.make<TH1F>(name, title, 2000, 0., 2000.);
346  sprintf (title, "Distance (mm)");
347  dist_[i]->GetXaxis()->SetTitle(title);
348  dist_[i]->GetYaxis()->SetTitle("Hits");
349  }
350  if (useHF && (!useParam)) {
351  hzvem = hcDir.make<TH1F>("hzvem", "Longitudinal Profile (EM Part)",330,0.0,1650.0);
352  hzvem->GetXaxis()->SetTitle("Longitudinal Profile (EM Part)");
353  hzvhad = hcDir.make<TH1F>("hzvhad","Longitudinal Profile (Had Part)",330,0.0,1650.0);
354  hzvhad->GetXaxis()->SetTitle("Longitudinal Profile (Hadronic Part)");
355  }
356  }
357 #endif
358 }
359 
361 
363  if (numberingScheme) delete numberingScheme;
364  if (showerLibrary) delete showerLibrary;
365  if (hfshower) delete hfshower;
366  if (showerParam) delete showerParam;
367  if (showerPMT) delete showerPMT;
368  if (showerBundle) delete showerBundle;
369  if (m_HEDarkening) delete m_HEDarkening;
370  if (m_HFDarkening) delete m_HFDarkening;
371 }
372 
373 bool HCalSD::ProcessHits(G4Step * aStep, G4TouchableHistory * ) {
374 
375  NaNTrap( aStep ) ;
376 
377  if (aStep == NULL) {
378  return true;
379  } else {
380  G4LogicalVolume* lv =
381  aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
382  G4String nameVolume = lv->GetName();
383  if (isItHF(aStep)) {
384  G4int parCode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
385  double weight(1.0);
386  if (m_HFDarkening != 0) {
387  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
388  double r = hitPoint.perp()/CLHEP::cm;
389  double z = std::abs(hitPoint.z())/CLHEP::cm;
390  float dose_acquired = 0.;
391  if (z>=1100 && z <= 1300) {
392  int hfZLayer = (int)((z - 1100)/20);
393  if (hfZLayer > 9) hfZLayer = 9;
394  float normalized_lumi = m_HFDarkening->int_lumi(deliveredLumi);
395  for (int i = hfZLayer; i <= 9; ++i) {
396  dose_acquired = m_HFDarkening->dose(i,r);
397  weight *= m_HFDarkening->degradation(normalized_lumi*dose_acquired);
398  }
399  }
400 #ifdef DebugLog
401  LogDebug("HcalSim") << "HCalSD: HFLumiDarkening at r = " << r
402  << ", z = " << z << " Dose " << dose_acquired
403  << " weight " << weight;
404 #endif
405  }
406  if (useParam) {
407 #ifdef DebugLog
408  LogDebug("HcalSim") << "HCalSD: " << getNumberOfHits()
409  << " hits from parametrization in " << nameVolume
410  << " for Track " << aStep->GetTrack()->GetTrackID()
411  <<" (" << aStep->GetTrack()->GetDefinition()->GetParticleName()
412  <<")";
413 #endif
414  getFromParam(aStep, weight);
415 #ifdef DebugLog
416  LogDebug("HcalSim") << "HCalSD: " << getNumberOfHits()
417  << " hits afterParamS*";
418 #endif
419  } else {
420  bool notaMuon = true;
421  if (parCode == mupPDG || parCode == mumPDG ) notaMuon = false;
422  if (useShowerLibrary && notaMuon) {
423 #ifdef DebugLog
424  LogDebug("HcalSim") << "HCalSD: Starts shower library from "
425  << nameVolume << " for Track "
426  << aStep->GetTrack()->GetTrackID() << " ("
427  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
428 #endif
429  getFromLibrary(aStep, weight);
430  } else if (isItFibre(lv)) {
431 #ifdef DebugLog
432  LogDebug("HcalSim") << "HCalSD: Hit at Fibre in " << nameVolume
433  << " for Track "
434  << aStep->GetTrack()->GetTrackID() <<" ("
435  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
436 #endif
437  hitForFibre(aStep, weight);
438  }
439  }
440  } else if (isItPMT(lv)) {
441 #ifdef DebugLog
442  LogDebug("HcalSim") << "HCalSD: Hit from PMT parametrization from "
443  << nameVolume << " for Track "
444  << aStep->GetTrack()->GetTrackID() << " ("
445  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
446 #endif
447  if (usePMTHit && showerPMT) getHitPMT(aStep);
448  } else if (isItStraightBundle(lv) || isItConicalBundle(lv)) {
449 #ifdef DebugLog
450  LogDebug("HcalSim") << "HCalSD: Hit from FibreBundle from "
451  << nameVolume << " for Track "
452  << aStep->GetTrack()->GetTrackID() << " ("
453  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
454 #endif
457  } else {
458 #ifdef DebugLog
459  LogDebug("HcalSim") << "HCalSD: Hit from standard path from "
460  << nameVolume << " for Track "
461  << aStep->GetTrack()->GetTrackID() << " ("
462  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
463 #endif
464  if (getStepInfo(aStep)) {
465 #ifdef plotDebug
466  if (edepositEM+edepositHAD > 0)
467  plotProfile(aStep, aStep->GetPreStepPoint()->GetPosition(),
468  edepositEM+edepositHAD,aStep->GetPostStepPoint()->GetGlobalTime(),0);
469 #endif
470  if (hitExists() == false && edepositEM+edepositHAD>0.) currentHit = createNewHit();
471  }
472  }
473  return true;
474  }
475 }
476 
477 double HCalSD::getEnergyDeposit(G4Step* aStep) {
478  double destep = aStep->GetTotalEnergyDeposit();
479  double weight = 1;
480  G4Track* theTrack = aStep->GetTrack();
481 
482  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
483  int depth = (touch->GetReplicaNumber(0))%10;
484  int det = ((touch->GetReplicaNumber(1))/1000)-3;
485  if (depth==0 && (det==0 || det==1)) weight = layer0wt[det];
486  if (useLayerWt) {
487  int lay = (touch->GetReplicaNumber(0)/10)%100 + 1;
488  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
489  weight = layerWeight(det+3, hitPoint, depth, lay);
490  }
491 
492  if (m_HEDarkening !=0 && det == 1) {
493  int lay = (touch->GetReplicaNumber(0)/10)%100 + 1;
494  int ieta;
495  uint32_t detid = setDetUnitId(aStep);
496  if(testNumber) {
497  int det, z, depth, eta, phi, lay;
498  HcalTestNumbering::unpackHcalIndex(detid,det,z,depth,eta,phi,lay);
499  ieta = eta;
500  }
501  else ieta = HcalDetId(detid).ietaAbs();
502 #ifdef DebugLog
503  edm::LogInfo("HcalSim") << "HCalSD:HE_Darkening >>> ieta: "<< ieta //<< " vs. ietaAbs(): " << HcalDetId(detid).ietaAbs()
504  << " lay: " << lay-2;
505 #endif
506  float dweight = m_HEDarkening->degradation(deliveredLumi,ieta,lay-2);//NB:diff. layer count
507  weight *= dweight;
508 #ifdef DebugLog
509  edm::LogInfo("HcalSim") << "HCalSD: >>> Lumi: " << deliveredLumi
510  << " coefficient = " << dweight;
511 #endif
512  }
513 
514  if (suppressHeavy) {
515  TrackInformation * trkInfo = (TrackInformation *)(theTrack->GetUserInformation());
516  if (trkInfo) {
517  int pdg = theTrack->GetDefinition()->GetPDGEncoding();
518  if (!(trkInfo->isPrimary())) { // Only secondary particles
519  double ke = theTrack->GetKineticEnergy()/MeV;
520  if ( pdg/1000000000 == 1 && (pdg/10000)%100 > 0 &&
521  (pdg/10)%100 > 0 && ke <kmaxIon ) weight = 0;
522  if ((pdg == 2212) && (ke < kmaxProton)) weight = 0;
523  if ((pdg == 2112) && (ke < kmaxNeutron)) weight = 0;
524 #ifdef DebugLog
525  if (weight == 0)
526  edm::LogInfo("HcalSim") << "HCalSD:Ignore Track "
527  << theTrack->GetTrackID() << " Type "
528  << theTrack->GetDefinition()->GetParticleName()
529  << " Kinetic Energy " << ke << " MeV";
530 #endif
531  }
532  }
533  }
534 #ifdef DebugLog
535  double weight0 = weight;
536 #endif
537  if (useBirk) {
538  G4Material* mat = aStep->GetPreStepPoint()->GetMaterial();
539  if (isItScintillator(mat)) weight *= getAttenuation(aStep, birk1, birk2, birk3);
540  }
541  double wt1 = getResponseWt(theTrack);
542  double wt2 = theTrack->GetWeight();
543  /*
544  if (wt2 != 1.0) {
545  edm::LogInfo("HcalSim") << "HCalSD: Detector " << det+3 << " Depth "
546  << depth << " weight= " << weight << " wt1= "
547  << wt1 << " wt2= " << wt2;
548  const G4VProcess* pr = theTrack->GetCreatorProcess();
549  if (pr) {
550  edm::LogInfo("HcalSim") << theTrack->GetDefinition()->GetParticleName()
551  << " " << theTrack->GetKineticEnergy()
552  << " Id=" << theTrack->GetTrackID()
553  << " IdP=" << theTrack->GetParentID()
554  << " from " << pr->GetProcessName();
555  } else {
556  edm::LogInfo("HcalSim") << theTrack->GetDefinition()->GetParticleName()
557  << " " << theTrack->GetKineticEnergy()
558  << " Id=" << theTrack->GetTrackID()
559  << " IdP=" << theTrack->GetParentID();
560  }
561  }
562  */
563 #ifdef DebugLog
564  edm::LogInfo("HcalSim") << "HCalSD: Detector " << det+3 << " Depth " << depth
565  << " weight " << weight0 << " " << weight << " " << wt1
566  << " " << wt2;
567 #endif
568  double edep = weight*wt1*destep;
569  if(wt2 > 0.0) { edep *= wt2; }
570  return edep;
571 }
572 
573 uint32_t HCalSD::setDetUnitId(G4Step * aStep) {
574 
575  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
576  const G4VTouchable* touch = preStepPoint->GetTouchable();
577  G4ThreeVector hitPoint = preStepPoint->GetPosition();
578 
579  int depth = (touch->GetReplicaNumber(0))%10 + 1;
580  int lay = (touch->GetReplicaNumber(0)/10)%100 + 1;
581  int det = (touch->GetReplicaNumber(1))/1000;
582 
583  return setDetUnitId (det, hitPoint, depth, lay);
584 }
585 
587  if (scheme != 0) {
588  edm::LogInfo("HcalSim") << "HCalSD: updates numbering scheme for " << GetName();
589  if (numberingScheme) delete numberingScheme;
590  numberingScheme = scheme;
591  }
592 }
593 
595 
596  const edm::EventSetup* es = (*job)();
598  es->get<HcalSimNumberingRecord>().get(hdc);
599  if (hdc.isValid()) {
600  hcalConstants = (HcalDDDSimConstants*)(&(*hdc));
601  } else {
602  edm::LogError("HcalSim") << "HCalSD : Cannot find HcalDDDSimConstant";
603  throw cms::Exception("Unknown", "HCalSD") << "Cannot find HcalDDDSimConstant" << "\n";
604  }
605 
607 
609  edm::LogInfo("HcalSim") << "Maximum depth for HF " << maxDepthHF;
610 
611  //Special Geometry parameters
613  edm::LogInfo("HcalSim") << "HCalSD: " << gpar.size()<< " gpar (cm)";
614  for (unsigned int ig=0; ig<gpar.size(); ig++)
615  edm::LogInfo("HcalSim") << "HCalSD: gpar[" << ig << "] = "
616  << gpar[ig]/cm << " cm";
617 
618  //Layer0 Weight
620  edm::LogInfo("HcalSim") << "HCalSD: " << layer0wt.size() << " Layer0Wt";
621  for (unsigned int it=0; it<layer0wt.size(); ++it)
622  edm::LogInfo("HcalSim") << "HCalSD: [" << it << "] " << layer0wt[it];
623 
624 }
625 
627  G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
628  G4String particleName;
629  mumPDG = theParticleTable->FindParticle(particleName="mu-")->GetPDGEncoding();
630  mupPDG = theParticleTable->FindParticle(particleName="mu+")->GetPDGEncoding();
631 #ifdef DebugLog
632  LogDebug("HcalSim") << "HCalSD: Particle code for mu- = " << mumPDG
633  << " for mu+ = " << mupPDG;
634 #endif
635  if (showerLibrary) showerLibrary->initRun(theParticleTable,hcalConstants);
636  if (showerParam) showerParam->initRun(theParticleTable,hcalConstants);
637  if (hfshower) hfshower->initRun(theParticleTable,hcalConstants);
638  if (showerPMT) showerPMT->initRun(theParticleTable,hcalConstants);
639  if (showerBundle) showerBundle->initRun(theParticleTable,hcalConstants);
640 }
641 
642 bool HCalSD::filterHit(CaloG4Hit* aHit, double time) {
643  double threshold=0;
644  DetId theId(aHit->getUnitID());
645  switch (theId.subdetId()) {
646  case HcalBarrel:
647  threshold = eminHitHB; break;
648  case HcalEndcap:
649  threshold = eminHitHE; break;
650  case HcalOuter:
651  threshold = eminHitHO; break;
652  case HcalForward:
653  threshold = eminHitHF; break;
654  default:
655  break;
656  }
657  return ((time <= tmaxHit) && (aHit->getEnergyDeposit() > threshold));
658 }
659 
660 
661 uint32_t HCalSD::setDetUnitId (int det, const G4ThreeVector& pos, int depth, int lay=1) {
662  uint32_t id = 0;
663  if (numberingFromDDD) {
664  //get the ID's as eta, phi, depth, ... indices
665  HcalNumberingFromDDD::HcalID tmp = numberingFromDDD->unitID(det, pos, depth, lay);
666  modifyDepth(tmp);
667  //get the ID
668  if (numberingScheme) id = numberingScheme->getUnitID(tmp);
669  }
670  return id;
671 }
672 
673 std::vector<double> HCalSD::getDDDArray(const std::string & str,
674  const DDsvalues_type & sv) {
675 #ifdef DebugLog
676  LogDebug("HcalSim") << "HCalSD:getDDDArray called for " << str;
677 #endif
678  DDValue value(str);
679  if (DDfetch(&sv,value)) {
680 #ifdef DebugLog
681  LogDebug("HcalSim") << value;
682 #endif
683  const std::vector<double> & fvec = value.doubles();
684  int nval = fvec.size();
685  if (nval < 1) {
686  edm::LogError("HcalSim") << "HCalSD : # of " << str << " bins " << nval
687  << " < 2 ==> illegal";
688  throw cms::Exception("Unknown", "HCalSD") << "nval < 2 for array " << str << "\n";
689  }
690 
691  return fvec;
692  } else {
693  edm::LogError("HcalSim") << "HCalSD : cannot get array " << str;
694  throw cms::Exception("Unknown", "HCalSD") << "cannot get array " << str << "\n";
695  }
696 }
697 
698 std::vector<G4String> HCalSD::getNames(DDFilteredView& fv) {
699 
700  std::vector<G4String> tmp;
701  bool dodet = fv.firstChild();
702  while (dodet) {
703  const DDLogicalPart & log = fv.logicalPart();
704  bool ok = true;
705 
706  for (unsigned int i=0; i<tmp.size(); ++i) {
707  if (!strcmp(tmp[i].c_str(), log.name().name().c_str())) {
708  ok = false;
709  break;
710  }
711  }
712  if (ok) tmp.push_back(log.name().name());
713  dodet = fv.next();
714  }
715  return tmp;
716 }
717 
718 bool HCalSD::isItHF(G4Step * aStep) {
719  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
720  int levels = (touch->GetHistoryDepth()) + 1;
721  for (unsigned int it=0; it < hfNames.size(); ++it) {
722  if (levels >= hfLevels[it]) {
723  G4LogicalVolume* lv = touch->GetVolume(levels-hfLevels[it])->GetLogicalVolume();
724  if (lv == hfLV[it]) return true;
725  }
726  }
727  return false;
728 }
729 
730 bool HCalSD::isItHF (G4String name) {
731  std::vector<G4String>::const_iterator it = hfNames.begin();
732  for (; it != hfNames.end(); ++it) if (name == *it) return true;
733  return false;
734 }
735 
736 bool HCalSD::isItFibre (G4LogicalVolume* lv) {
737  std::vector<G4LogicalVolume*>::const_iterator ite = fibreLV.begin();
738  for (; ite != fibreLV.end(); ++ite) if (lv == *ite) return true;
739  return false;
740 }
741 
742 bool HCalSD::isItFibre (G4String name) {
743  std::vector<G4String>::const_iterator it = fibreNames.begin();
744  for (; it != fibreNames.end(); ++it) if (name == *it) return true;
745  return false;
746 }
747 
748 bool HCalSD::isItPMT (G4LogicalVolume* lv) {
749  std::vector<G4LogicalVolume*>::const_iterator ite = pmtLV.begin();
750  for (; ite != pmtLV.end(); ++ite) if (lv == *ite) return true;
751  return false;
752 }
753 
754 bool HCalSD::isItStraightBundle (G4LogicalVolume* lv) {
755  std::vector<G4LogicalVolume*>::const_iterator ite = fibre1LV.begin();
756  for (; ite != fibre1LV.end(); ++ite) if (lv == *ite) return true;
757  return false;
758 }
759 
760 bool HCalSD::isItConicalBundle (G4LogicalVolume* lv) {
761  std::vector<G4LogicalVolume*>::const_iterator ite = fibre2LV.begin();
762  for (; ite != fibre2LV.end(); ++ite) if (lv == *ite) return true;
763  return false;
764 }
765 
766 bool HCalSD::isItScintillator (G4Material* mat) {
767  std::vector<G4Material*>::const_iterator ite = materials.begin();
768  for (; ite != materials.end(); ++ite) if (mat == *ite) return true;
769  return false;
770 }
771 
772 bool HCalSD::isItinFidVolume (G4ThreeVector& hitPoint) {
773  bool flag = true;
774  if (applyFidCut) {
775  int npmt = HFFibreFiducial:: PMTNumber(hitPoint);
776 #ifdef DebugLog
777  edm::LogInfo("HcalSim") << "HCalSD::isItinFidVolume:#PMT= " << npmt
778  << " for hit point " << hitPoint;
779 #endif
780  if (npmt <= 0) flag = false;
781  }
782 #ifdef DebugLog
783  edm::LogInfo("HcalSim") << "HCalSD::isItinFidVolume: point " << hitPoint
784  << " return flag " << flag;
785 #endif
786  return flag;
787 }
788 
789 void HCalSD::getFromLibrary (G4Step* aStep, double weight) {
790  preStepPoint = aStep->GetPreStepPoint();
791  theTrack = aStep->GetTrack();
792  int det = 5;
793  bool ok;
794 
795  std::vector<HFShowerLibrary::Hit> hits = showerLibrary->getHits(aStep, ok, weight, false);
796 
797  double etrack = preStepPoint->GetKineticEnergy();
798  int primaryID = setTrackID(aStep);
799 
800  // Reset entry point for new primary
801  posGlobal = preStepPoint->GetPosition();
802  resetForNewPrimary(posGlobal, etrack);
803 
804  G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding();
805  if (particleCode==emPDG || particleCode==epPDG || particleCode==gammaPDG) {
806  edepositEM = 1.*GeV;
807  edepositHAD = 0.;
808  } else {
809  edepositEM = 0.;
810  edepositHAD = 1.*GeV;
811  }
812 #ifdef DebugLog
813  edm::LogInfo("HcalSim") << "HCalSD::getFromLibrary " <<hits.size()
814  << " hits for " << GetName() << " of " << primaryID
815  << " with " << theTrack->GetDefinition()->GetParticleName()
816  << " of " << preStepPoint->GetKineticEnergy()/GeV << " GeV";
817 #endif
818  for (unsigned int i=0; i<hits.size(); ++i) {
819  G4ThreeVector hitPoint = hits[i].position;
820  if (isItinFidVolume (hitPoint)) {
821  int depth = hits[i].depth;
822  double time = hits[i].time;
823  unsigned int unitID = setDetUnitId(det, hitPoint, depth);
824  currentID.setID(unitID, time, primaryID, 0);
825 #ifdef plotDebug
826  plotProfile(aStep, hitPoint, 1.0*GeV, time, depth);
827  bool emType = false;
828  if (particleCode==emPDG || particleCode==epPDG || particleCode==gammaPDG)
829  emType = true;
830  plotHF(hitPoint,emType);
831 #endif
832 
833  // check if it is in the same unit and timeslice as the previous one
834  if (currentID == previousID) {
836  } else {
837  if (!checkHit()) currentHit = createNewHit();
838  }
839  }
840  }
841 
842  //Now kill the current track
843  if (ok) {
844  theTrack->SetTrackStatus(fStopAndKill);
845  G4TrackVector tv = *(aStep->GetSecondary());
846  for (unsigned int kk=0; kk<tv.size(); ++kk)
847  if (tv[kk]->GetVolume() == preStepPoint->GetPhysicalVolume())
848  tv[kk]->SetTrackStatus(fStopAndKill);
849  }
850 }
851 
852 void HCalSD::hitForFibre (G4Step* aStep, double weight) { // if not ParamShower
853 
854  preStepPoint = aStep->GetPreStepPoint();
855  theTrack = aStep->GetTrack();
856  int primaryID = setTrackID(aStep);
857 
858  int det = 5;
859  std::vector<HFShower::Hit> hits = hfshower->getHits(aStep, weight);
860 
861  G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding();
862  if (particleCode==emPDG || particleCode==epPDG || particleCode==gammaPDG) {
863  edepositEM = 1.*GeV;
864  edepositHAD = 0.;
865  } else {
866  edepositEM = 0.;
867  edepositHAD = 1.*GeV;
868  }
869 
870 #ifdef DebugLog
871  edm::LogInfo("HcalSim") << "HCalSD::hitForFibre " << hits.size()
872  << " hits for " << GetName() << " of " << primaryID
873  << " with " << theTrack->GetDefinition()->GetParticleName()
874  << " of " << preStepPoint->GetKineticEnergy()/GeV
875  << " GeV in detector type " << det;
876 #endif
877  if (hits.size() > 0) {
878  for (unsigned int i=0; i<hits.size(); ++i) {
879  G4ThreeVector hitPoint = hits[i].position;
880  if (isItinFidVolume (hitPoint)) {
881  int depth = hits[i].depth;
882  double time = hits[i].time;
883  unsigned int unitID = setDetUnitId(det, hitPoint, depth);
884  currentID.setID(unitID, time, primaryID, 0);
885 #ifdef plotDebug
886  plotProfile(aStep, hitPoint, edepositEM, time, depth);
887  bool emType = false;
888  if (particleCode==emPDG || particleCode==epPDG || particleCode==gammaPDG)
889  emType = true;
890  plotHF(hitPoint,emType);
891 #endif
892  // check if it is in the same unit and timeslice as the previous one
893  if (currentID == previousID) {
895  } else {
896  posGlobal = preStepPoint->GetPosition();
897  if (!checkHit()) currentHit = createNewHit();
898  }
899  }
900  }
901  }
902 }
903 
904 void HCalSD::getFromParam (G4Step* aStep, double weight) {
905  std::vector<HFShowerParam::Hit> hits = showerParam->getHits(aStep, weight);
906  int nHit = static_cast<int>(hits.size());
907 
908  if (nHit > 0) {
909  preStepPoint = aStep->GetPreStepPoint();
910  int primaryID = setTrackID(aStep);
911 
912  int det = 5;
913 #ifdef DebugLog
914  edm::LogInfo("HcalSim") << "HCalSD::getFromParam " << nHit << " hits for "
915  << GetName() << " of " << primaryID << " with "
916  << aStep->GetTrack()->GetDefinition()->GetParticleName()
917  << " of " << preStepPoint->GetKineticEnergy()/GeV
918  << " GeV in detector type " << det;
919 #endif
920  for (int i = 0; i<nHit; ++i) {
921  G4ThreeVector hitPoint = hits[i].position;
922  int depth = hits[i].depth;
923  double time = hits[i].time;
924  unsigned int unitID = setDetUnitId(det, hitPoint, depth);
925  currentID.setID(unitID, time, primaryID, 0);
926  edepositEM = hits[i].edep*GeV;
927  edepositHAD = 0.;
928 #ifdef plotDebug
929  plotProfile(aStep, hitPoint, edepositEM, time, depth);
930 #endif
931 
932  // check if it is in the same unit and timeslice as the previous one
933  if (currentID == previousID) {
935  } else {
936  posGlobal = preStepPoint->GetPosition();
937  if (!checkHit()) currentHit = createNewHit();
938  }
939  }
940  }
941 }
942 
943 void HCalSD::getHitPMT (G4Step * aStep) {
944 
945  preStepPoint = aStep->GetPreStepPoint();
946  theTrack = aStep->GetTrack();
947  double edep = showerPMT->getHits(aStep);
948 
949  if (edep >= 0) {
950  double etrack = preStepPoint->GetKineticEnergy();
951  int primaryID = 0;
952  if (etrack >= energyCut) {
953  primaryID = theTrack->GetTrackID();
954  } else {
955  primaryID = theTrack->GetParentID();
956  if (primaryID == 0) primaryID = theTrack->GetTrackID();
957  }
958  // Reset entry point for new primary
959  posGlobal = preStepPoint->GetPosition();
960  resetForNewPrimary(posGlobal, etrack);
961 
962  //
963  int det = static_cast<int>(HcalForward);
964  G4ThreeVector hitPoint = preStepPoint->GetPosition();
965  double rr = (hitPoint.x()*hitPoint.x() + hitPoint.y()*hitPoint.y());
966  double phi = (rr == 0. ? 0. :atan2(hitPoint.y(),hitPoint.x()));
967  double etaR = showerPMT->getRadius();
968  int depth = 1;
969  if (etaR < 0) {
970  depth = 2;
971  etaR =-etaR;
972  }
973  if (hitPoint.z() < 0) etaR =-etaR;
974 #ifdef DebugLog
975  edm::LogInfo("HcalSim") << "HCalSD::Hit for Detector " << det << " etaR "
976  << etaR << " phi " << phi/deg << " depth " <<depth;
977 #endif
978  double time = (aStep->GetPostStepPoint()->GetGlobalTime());
979  uint32_t unitID = 0;
980  if (numberingFromDDD) {
982  depth,1);
983  modifyDepth(tmp);
984  if (numberingScheme) unitID = numberingScheme->getUnitID(tmp);
985  }
986  currentID.setID(unitID, time, primaryID, 1);
987 
988  edepositHAD = aStep->GetTotalEnergyDeposit();
989  edepositEM =-edepositHAD + (edep*GeV);
990 #ifdef plotDebug
991  plotProfile(aStep, hitPoint, edep*GeV, time, depth);
992 #endif
993 #ifdef DebugLog
994  double beta = preStepPoint->GetBeta();
995  LogDebug("HcalSim") << "HCalSD::getHitPMT 1 hit for " << GetName()
996  << " of " << primaryID << " with "
997  << theTrack->GetDefinition()->GetParticleName()
998  << " of " << preStepPoint->GetKineticEnergy()/GeV
999  << " GeV with velocity " << beta << " UnitID "
1000  << std::hex << unitID << std::dec;
1001 #endif
1002  // check if it is in the same unit and timeslice as the previous one
1003  if (currentID == previousID) {
1005  } else {
1006  if (!checkHit()) currentHit = createNewHit();
1007  }
1008  }
1009 }
1010 
1011 void HCalSD::getHitFibreBundle (G4Step* aStep, bool type) {
1012  preStepPoint = aStep->GetPreStepPoint();
1013  theTrack = aStep->GetTrack();
1014  double edep = showerBundle->getHits(aStep, type);
1015 
1016  if (edep >= 0) {
1017  double etrack = preStepPoint->GetKineticEnergy();
1018  int primaryID = 0;
1019  if (etrack >= energyCut) {
1020  primaryID = theTrack->GetTrackID();
1021  } else {
1022  primaryID = theTrack->GetParentID();
1023  if (primaryID == 0) primaryID = theTrack->GetTrackID();
1024  }
1025  // Reset entry point for new primary
1026  posGlobal = preStepPoint->GetPosition();
1027  resetForNewPrimary(posGlobal, etrack);
1028 
1029  //
1030  int det = static_cast<int>(HcalForward);
1031  G4ThreeVector hitPoint = preStepPoint->GetPosition();
1032  double rr = (hitPoint.x()*hitPoint.x() + hitPoint.y()*hitPoint.y());
1033  double phi = (rr == 0. ? 0. :atan2(hitPoint.y(),hitPoint.x()));
1034  double etaR = showerBundle->getRadius();
1035  int depth = 1;
1036  if (etaR < 0) {
1037  depth = 2;
1038  etaR =-etaR;
1039  }
1040  if (hitPoint.z() < 0) etaR =-etaR;
1041 #ifdef DebugLog
1042  LogDebug("HcalSim") << "HCalSD::Hit for Detector " << det << " etaR "
1043  << etaR << " phi " << phi/deg << " depth " <<depth;
1044 #endif
1045  double time = (aStep->GetPostStepPoint()->GetGlobalTime());
1046  uint32_t unitID = 0;
1047  if (numberingFromDDD) {
1048  HcalNumberingFromDDD::HcalID tmp = numberingFromDDD->unitID(det,etaR,phi,depth,1);
1049  modifyDepth(tmp);
1050  if (numberingScheme) unitID = numberingScheme->getUnitID(tmp);
1051  }
1052  if (type) currentID.setID(unitID, time, primaryID, 3);
1053  else currentID.setID(unitID, time, primaryID, 2);
1054 
1055  edepositHAD = aStep->GetTotalEnergyDeposit();
1056  edepositEM =-edepositHAD + (edep*GeV);
1057 #ifdef plotDebug
1058  plotProfile(aStep, hitPoint, edep*GeV, time, depth);
1059 #endif
1060 #ifdef DebugLog
1061  double beta = preStepPoint->GetBeta();
1062  LogDebug("HcalSim") << "HCalSD::getHitFibreBundle 1 hit for " << GetName()
1063  << " of " << primaryID << " with "
1064  << theTrack->GetDefinition()->GetParticleName()
1065  << " of " << preStepPoint->GetKineticEnergy()/GeV
1066  << " GeV with velocity " << beta << " UnitID "
1067  << std::hex << unitID << std::dec;
1068 #endif
1069  // check if it is in the same unit and timeslice as the previous one
1071  else if (!checkHit()) currentHit = createNewHit();
1072  } // non-zero energy deposit
1073 }
1074 
1075 int HCalSD::setTrackID (G4Step* aStep) {
1076  theTrack = aStep->GetTrack();
1077 
1078  double etrack = preStepPoint->GetKineticEnergy();
1079  TrackInformation * trkInfo = (TrackInformation *)(theTrack->GetUserInformation());
1080  int primaryID = trkInfo->getIDonCaloSurface();
1081  if (primaryID == 0) {
1082 #ifdef DebugLog
1083  edm::LogInfo("HcalSim") << "HCalSD: Problem with primaryID **** set by "
1084  << "force to TkID **** " <<theTrack->GetTrackID();
1085 #endif
1086  primaryID = theTrack->GetTrackID();
1087  }
1088 
1089  if (primaryID != previousID.trackID())
1090  resetForNewPrimary(preStepPoint->GetPosition(), etrack);
1091 
1092  return primaryID;
1093 }
1094 
1096 
1097  std::ifstream infile;
1098  int entry=0;
1099  infile.open(fName.c_str(), std::ios::in);
1100  if (infile) {
1101  int det, zside, etaR, phi, lay;
1102  double wt;
1103  while (infile >> det >> zside >> etaR >> phi >> lay >> wt) {
1104  uint32_t id = HcalTestNumbering::packHcalIndex(det,zside,1,etaR,phi,lay);
1105  layerWeights.insert(std::pair<uint32_t,double>(id,wt));
1106  ++entry;
1107 #ifdef DebugLog
1108  edm::LogInfo("HcalSim") << "HCalSD::readWeightFromFile:Entry " << entry
1109  << " ID " << std::hex << id << std::dec << " ("
1110  << det << "/" << zside << "/1/" << etaR << "/"
1111  << phi << "/" << lay << ") Weight " << wt;
1112 #endif
1113  }
1114  infile.close();
1115  }
1116  edm::LogInfo("HcalSim") << "HCalSD::readWeightFromFile: reads " << entry
1117  << " weights from " << fName;
1118  if (entry <= 0) useLayerWt = false;
1119 }
1120 
1121 double HCalSD::layerWeight(int det, const G4ThreeVector& pos, int depth, int lay) {
1122 
1123  double wt = 1.;
1124  if (numberingFromDDD) {
1125  //get the ID's as eta, phi, depth, ... indices
1127  depth, lay);
1128  modifyDepth(tmp);
1129  uint32_t id = HcalTestNumbering::packHcalIndex(tmp.subdet, tmp.zside, 1,
1130  tmp.etaR, tmp.phis,tmp.lay);
1131  std::map<uint32_t,double>::const_iterator ite = layerWeights.find(id);
1132  if (ite != layerWeights.end()) wt = ite->second;
1133 #ifdef DebugLog
1134  edm::LogInfo("HcalSim") << "HCalSD::layerWeight: ID " << std::hex << id
1135  << std::dec << " (" << tmp.subdet << "/"
1136  << tmp.zside << "/1/" << tmp.etaR << "/"
1137  << tmp.phis << "/" << tmp.lay << ") Weight " <<wt;
1138 #endif
1139  }
1140  return wt;
1141 }
1142 
1143 void HCalSD::plotProfile(G4Step* aStep,const G4ThreeVector& global, double edep,
1144  double time, int id) {
1145 
1146  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
1147  static G4String modName[8] = {"HEModule", "HVQF" , "HBModule", "MBAT",
1148  "MBBT" , "MBBTC", "MBBT_R1P", "MBBT_R1M"};
1149  G4ThreeVector local;
1150  bool found=false;
1151  double depth=-2000;
1152  int idx = 4;
1153  for (int n=0; n<touch->GetHistoryDepth(); ++n) {
1154  G4String name = touch->GetVolume(n)->GetName();
1155 #ifdef DebugLog
1156  LogDebug("HcalSim") << "plotProfile Depth " << n << " Name " << name;
1157 #endif
1158  for (unsigned int ii=0; ii<8; ++ii) {
1159  if (name == modName[ii]) {
1160  found = true;
1161  int dn = touch->GetHistoryDepth() - n;
1162  local = touch->GetHistory()->GetTransform(dn).TransformPoint(global);
1163  if (ii == 0) {depth = local.z() - 4006.5; idx = 1;}
1164  else if (ii == 1) {depth = local.z() + 825.0; idx = 3;}
1165  else if (ii == 2) {depth = local.x() - 1775.; idx = 0;}
1166  else {depth = local.y() + 15.; idx = 2;}
1167  break;
1168  }
1169  }
1170  if (found) break;
1171  }
1172  if (!found) depth = std::abs(global.z()) - 11500;
1173 #ifdef DebugLog
1174  LogDebug("HcalSim") << "plotProfile Found " << found << " Global " << global
1175  << " Local " << local << " depth " << depth << " ID "
1176  << id << " EDEP " << edep << " Time " << time;
1177 #endif
1178  if (hit_[idx] != 0) hit_[idx]->Fill(edep);
1179  if (time_[idx] != 0) time_[idx]->Fill(time,edep);
1180  if (dist_[idx] != 0) dist_[idx]->Fill(depth,edep);
1181  int jd = 2*idx + id - 7;
1182  if (jd >= 0 && jd < 4) {
1183  jd += 5;
1184  if (hit_[jd] != 0) hit_[jd]->Fill(edep);
1185  if (time_[jd] != 0) time_[jd]->Fill(time,edep);
1186  if (dist_[jd] != 0) dist_[jd]->Fill(depth,edep);
1187  }
1188 }
1189 
1190 void HCalSD::plotHF(G4ThreeVector& hitPoint, bool emType) {
1191  double zv = std::abs(hitPoint.z()) - gpar[4];
1192  if (emType) {
1193  if (hzvem != 0) hzvem->Fill(zv);
1194  } else {
1195  if (hzvhad != 0) hzvhad->Fill(zv);
1196  }
1197 }
1198 
1200  if (id.subdet == 4 && maxDepthHF > 2) {
1201  if (id.depth <= 2)
1202  if (G4UniformRand() > 0.5) id.depth += 2;
1203  }
1204 }
#define LogDebug(id)
float edepositEM
Definition: CaloSD.h:121
const double beta
double energyCut
Definition: CaloSD.h:123
HCalSD(G4String, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: HCalSD.cc:42
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
std::vector< double > layer0wt
Definition: HCalSD.h:97
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
bool useParam
Definition: HCalSD.h:93
double eminHitHE
Definition: HCalSD.h:94
HFShowerParam * showerParam
Definition: HCalSD.h:86
TH1F * time_[9]
Definition: HCalSD.h:103
G4int emPDG
Definition: CaloSD.h:136
double getRadius()
Definition: HFShowerPMT.cc:137
float int_lumi(float intlumi)
Definition: HFDarkening.cc:147
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:139
const double GeV
Definition: MathUtil.h:16
double kmaxNeutron
Definition: CaloSD.h:134
void updateHit(CaloG4Hit *)
Definition: CaloSD.cc:440
void hitForFibre(G4Step *step, double weight)
Definition: HCalSD.cc:852
const N & name() const
Definition: DDBase.h:78
void getFromParam(G4Step *step, double weight)
Definition: HCalSD.cc:904
int getIDonCaloSurface() const
bool useLayerWt
Definition: HCalSD.h:91
Definition: CaloSD.h:42
void addFilter(const DDFilter &, DDLogOp op=DDLogOp::AND)
virtual void update(const BeginOfJob *)
This routine will be called when the appropriate signal arrives.
Definition: HCalSD.cc:594
bool isItStraightBundle(G4LogicalVolume *)
Definition: HCalSD.cc:754
virtual bool ProcessHits(G4Step *, G4TouchableHistory *)
Definition: HCalSD.cc:373
std::vector< double > gpar
Definition: HCalSD.h:97
bool useFibreBundle
Definition: HCalSD.h:91
bool isItinFidVolume(G4ThreeVector &)
Definition: HCalSD.cc:772
double betaThr
Definition: HCalSD.h:92
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
Definition: HFShower.cc:454
double deliveredLumi
Definition: HCalSD.h:95
std::vector< Hit > getHits(G4Step *aStep, bool &ok, double weight, bool onlyLong=false)
virtual uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id)
HFShowerFibreBundle * showerBundle
Definition: HCalSD.h:88
std::vector< G4LogicalVolume * > fibre1LV
Definition: HCalSD.h:101
std::vector< G4LogicalVolume * > fibreLV
Definition: HCalSD.h:101
double eminHitHB
Definition: HCalSD.h:94
bool useShowerLibrary
Definition: HCalSD.h:93
std::vector< double > getDDDArray(const std::string &, const DDsvalues_type &)
Definition: HCalSD.cc:673
int getMaxDepth(const int type) const
double getHits(G4Step *aStep, bool type)
#define NULL
Definition: scimark2.h:8
virtual uint32_t setDetUnitId(G4Step *step)
Definition: HCalSD.cc:573
double birk2
Definition: HCalSD.h:92
int setTrackID(G4Step *step)
Definition: HCalSD.cc:1075
void getFromLibrary(G4Step *step, double weight)
Definition: HCalSD.cc:789
bool usePMTHit
Definition: HCalSD.h:91
#define DebugLog
G4ThreeVector posGlobal
Definition: CaloSD.h:113
int zside(DetId const &)
void modifyDepth(HcalNumberingFromDDD::HcalID &id)
Definition: HCalSD.cc:1199
int ii
Definition: cuy.py:588
void setNumberingScheme(HcalNumberingScheme *)
Definition: HCalSD.cc:586
type of data representation of DDCompactView
Definition: DDCompactView.h:77
double birk1
Definition: HCalSD.h:92
double kmaxProton
Definition: CaloSD.h:134
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:80
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
static int PMTNumber(const G4ThreeVector &pe_effect)
bool isItHF(G4Step *)
Definition: HCalSD.cc:718
G4bool checkHit()
Definition: CaloSD.cc:331
static TrackerG4SimHitNumberingScheme & numberingScheme(const DDCompactView &cpv, const GeometricDet &det)
TH1F * hzvhad
Definition: HCalSD.h:103
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
Definition: HFShowerPMT.cc:80
double eminHitHF
Definition: HCalSD.h:94
const double MeV
bool isItConicalBundle(G4LogicalVolume *)
Definition: HCalSD.cc:760
static uint32_t packHcalIndex(int det, int z, int depth, int eta, int phi, int lay)
TH1F * hit_[9]
Definition: HCalSD.h:103
const std::vector< double > & getLayer0Wt() const
void resetForNewPrimary(const G4ThreeVector &, double)
Definition: CaloSD.cc:454
virtual void initRun()
Definition: HCalSD.cc:626
bool testNumber
Definition: HCalSD.h:91
std::vector< G4LogicalVolume * > pmtLV
Definition: HCalSD.h:101
std::vector< G4LogicalVolume * > hfLV
Definition: HCalSD.h:101
double kmaxIon
Definition: CaloSD.h:134
bool suppressHeavy
Definition: CaloSD.h:132
bool isItScintillator(G4Material *)
Definition: HCalSD.cc:766
bool next()
set current node to the next node in the filtered tree
HFShower * hfshower
Definition: HCalSD.h:85
bool useBirk
Definition: HCalSD.h:91
float edepositHAD
Definition: CaloSD.h:121
double birk3
Definition: HCalSD.h:92
int trackID() const
Definition: CaloHitID.h:25
virtual double getEnergyDeposit(G4Step *)
Definition: HCalSD.cc:477
G4int epPDG
Definition: CaloSD.h:136
void plotHF(G4ThreeVector &pos, bool emType)
Definition: HCalSD.cc:1190
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:19
float degradation(float mrad)
Definition: HFDarkening.cc:143
G4int gammaPDG
Definition: CaloSD.h:136
bool isAvailable() const
Definition: Service.h:46
bool applyFidCut
Definition: HCalSD.h:93
std::vector< Hit > getHits(G4Step *aStep, double weight)
Definition: HFShower.cc:47
TH1F * dist_[9]
Definition: HCalSD.h:103
virtual ~HCalSD()
Definition: HCalSD.cc:360
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
HcalNumberingScheme * numberingScheme
Definition: HCalSD.h:83
void getHitPMT(G4Step *step)
Definition: HCalSD.cc:943
T * make(const Args &...args) const
make new ROOT object
int getNumberOfHits()
Definition: CaloSD.cc:361
HFDarkening * m_HFDarkening
Definition: HCalSD.h:90
CaloHitID previousID
Definition: CaloSD.h:117
double getAttenuation(G4Step *aStep, double birk1, double birk2, double birk3)
Definition: CaloSD.cc:465
CaloG4Hit * currentHit
Definition: CaloSD.h:128
std::vector< int > hfLevels
Definition: HCalSD.h:98
virtual std::vector< std::string > getNames()
void plotProfile(G4Step *step, const G4ThreeVector &pos, double edep, double time, int id)
Definition: HCalSD.cc:1143
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
HEDarkening * m_HEDarkening
Definition: HCalSD.h:89
void NaNTrap(G4Step *step)
G4Track * theTrack
Definition: CaloSD.h:118
virtual G4bool getStepInfo(G4Step *aStep)
Definition: CaloSD.cc:250
bool isItPMT(G4LogicalVolume *)
Definition: HCalSD.cc:748
G4int mupPDG
Definition: HCalSD.h:96
double eminHitHO
Definition: HCalSD.h:94
double tmaxHit
Definition: CaloSD.h:123
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:49
G4int maxDepthHF
Definition: HCalSD.h:96
void setID(uint32_t unitID, double timeSlice, int trackID, uint16_t depth=0)
Definition: CaloHitID.cc:44
TH1F * hzvem
Definition: HCalSD.h:103
G4StepPoint * preStepPoint
Definition: CaloSD.h:120
const std::vector< double > & getGparHF() const
Definition: DetId.h:18
static const G4LogicalVolume * GetVolume(const std::string &name)
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
Definition: TFileService.h:69
CaloHitID currentID
Definition: CaloSD.h:117
std::vector< Hit > getHits(G4Step *aStep, double weight)
void readWeightFromFile(std::string)
Definition: HCalSD.cc:1095
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
void getHitFibreBundle(G4Step *step, bool type)
Definition: HCalSD.cc:1011
const T & get() const
Definition: EventSetup.h:56
int ke
bool isPrimary() const
DDsvalues_type mergedSpecifics() const
double getHits(G4Step *aStep)
Definition: HFShowerPMT.cc:91
HcalNumberingFromDDD * numberingFromDDD
Definition: HCalSD.h:82
double layerWeight(int, const G4ThreeVector &, int, int)
Definition: HCalSD.cc:1121
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
float dose(int layer, float radius)
Definition: HFDarkening.cc:92
double getResponseWt(G4Track *)
Definition: CaloSD.cc:607
std::vector< G4String > fibreNames
Definition: HCalSD.h:99
list infile
Definition: EdgesToViz.py:90
G4bool hitExists()
Definition: CaloSD.cc:310
bool firstChild()
set the current node to the first child ...
std::vector< G4Material * > materials
Definition: HCalSD.h:100
virtual bool filterHit(CaloG4Hit *, double)
Definition: HCalSD.cc:642
std::vector< G4String > hfNames
Definition: HCalSD.h:99
G4int mumPDG
Definition: HCalSD.h:96
std::map< uint32_t, double > layerWeights
Definition: HCalSD.h:102
tuple level
Definition: testEve_cfg.py:34
HFShowerPMT * showerPMT
Definition: HCalSD.h:87
uint32_t getUnitID() const
Definition: CaloG4Hit.h:69
HcalID unitID(int det, const CLHEP::Hep3Vector &pos, int depth, int lay=-1) const
float degradation(float intlumi, int ieta, int lay)
Definition: HEDarkening.cc:52
HFShowerLibrary * showerLibrary
Definition: HCalSD.h:84
void initRun(G4ParticleTable *, HcalDDDSimConstants *)
std::vector< G4LogicalVolume * > fibre2LV
Definition: HCalSD.h:101
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
void setCriteria(const DDValue &nameVal, DDCompOp, DDLogOp l=DDLogOp::AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:245
CaloG4Hit * createNewHit()
Definition: CaloSD.cc:363
std::vector< G4String > matNames
Definition: HCalSD.h:99
bool isItFibre(G4LogicalVolume *)
Definition: HCalSD.cc:736
double getEnergyDeposit() const
Definition: CaloG4Hit.h:81
bool useHF
Definition: HCalSD.h:93
tuple log
Definition: cmsBatch.py:341
HcalDDDSimConstants * hcalConstants
Definition: HCalSD.h:81
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:32