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 
313  if (useLayerWt) readWeightFromFile(file);
314 
315  for (int i=0; i<9; ++i) hit_[i] = time_[i]= dist_[i] = 0;
316  hzvem = hzvhad = 0;
317 
318  if (ageingFlagHE) m_HEDarkening = new HEDarkening();
319  if (ageingFlagHF) m_HFDarkening = new HFDarkening();
320 #ifdef plotDebug
322 
323  if ( tfile.isAvailable() ) {
324  static const char * const labels[] = {"HB", "HE", "HO", "HF Absorber", "HF PMT",
325  "HF Absorber Long", "HF Absorber Short",
326  "HF PMT Long", "HF PMT Short"};
327  TFileDirectory hcDir = tfile->mkdir("ProfileFromHCalSD");
328  char name[20], title[60];
329  for (int i=0; i<9; ++i) {
330  sprintf (title, "Hit energy in %s", labels[i]);
331  sprintf (name, "HCalSDHit%d", i);
332  hit_[i] = hcDir.make<TH1F>(name, title, 2000, 0., 2000.);
333  sprintf (title, "Energy (MeV)");
334  hit_[i]->GetXaxis()->SetTitle(title);
335  hit_[i]->GetYaxis()->SetTitle("Hits");
336  sprintf (title, "Time of the hit in %s", labels[i]);
337  sprintf (name, "HCalSDTime%d", i);
338  time_[i] = hcDir.make<TH1F>(name, title, 2000, 0., 2000.);
339  sprintf (title, "Time (ns)");
340  time_[i]->GetXaxis()->SetTitle(title);
341  time_[i]->GetYaxis()->SetTitle("Hits");
342  sprintf (title, "Longitudinal profile in %s", labels[i]);
343  sprintf (name, "HCalSDDist%d", i);
344  dist_[i] = hcDir.make<TH1F>(name, title, 2000, 0., 2000.);
345  sprintf (title, "Distance (mm)");
346  dist_[i]->GetXaxis()->SetTitle(title);
347  dist_[i]->GetYaxis()->SetTitle("Hits");
348  }
349  if (useHF && (!useParam)) {
350  hzvem = hcDir.make<TH1F>("hzvem", "Longitudinal Profile (EM Part)",330,0.0,1650.0);
351  hzvem->GetXaxis()->SetTitle("Longitudinal Profile (EM Part)");
352  hzvhad = hcDir.make<TH1F>("hzvhad","Longitudinal Profile (Had Part)",330,0.0,1650.0);
353  hzvhad->GetXaxis()->SetTitle("Longitudinal Profile (Hadronic Part)");
354  }
355  }
356 #endif
357 }
358 
360 
362  if (numberingScheme) delete numberingScheme;
363  if (showerLibrary) delete showerLibrary;
364  if (hfshower) delete hfshower;
365  if (showerParam) delete showerParam;
366  if (showerPMT) delete showerPMT;
367  if (showerBundle) delete showerBundle;
368  if (m_HEDarkening) delete m_HEDarkening;
369  if (m_HFDarkening) delete m_HFDarkening;
370 }
371 
372 bool HCalSD::ProcessHits(G4Step * aStep, G4TouchableHistory * ) {
373 
374  NaNTrap( aStep ) ;
375 
376  if (aStep == NULL) {
377  return true;
378  } else {
379  G4LogicalVolume* lv =
380  aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume();
381  G4String nameVolume = lv->GetName();
382  if (isItHF(aStep)) {
383  G4int parCode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
384  double weight(1.0);
385  if (m_HFDarkening != 0) {
386  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
387  double r = hitPoint.perp()/CLHEP::cm;
388  double z = std::abs(hitPoint.z())/CLHEP::cm;
389  float dose_acquired = 0.;
390  if (z>=1100 && z <= 1300) {
391  int hfZLayer = (int)((z - 1100)/20);
392  if (hfZLayer > 9) hfZLayer = 9;
393  float normalized_lumi = m_HFDarkening->int_lumi(deliveredLumi);
394  for (int i = hfZLayer; i <= 9; ++i) {
395  dose_acquired = m_HFDarkening->dose(i,r);
396  weight *= m_HFDarkening->degradation(normalized_lumi*dose_acquired);
397  }
398  }
399 #ifdef DebugLog
400  LogDebug("HcalSim") << "HCalSD: HFLumiDarkening at r = " << r
401  << ", z = " << z << " Dose " << dose_acquired
402  << " weight " << weight;
403 #endif
404  }
405  if (useParam) {
406 #ifdef DebugLog
407  LogDebug("HcalSim") << "HCalSD: " << getNumberOfHits()
408  << " hits from parametrization in " << nameVolume
409  << " for Track " << aStep->GetTrack()->GetTrackID()
410  <<" (" << aStep->GetTrack()->GetDefinition()->GetParticleName()
411  <<")";
412 #endif
413  getFromParam(aStep, weight);
414 #ifdef DebugLog
415  LogDebug("HcalSim") << "HCalSD: " << getNumberOfHits()
416  << " hits afterParamS*";
417 #endif
418  } else {
419  bool notaMuon = true;
420  if (parCode == mupPDG || parCode == mumPDG ) notaMuon = false;
421  if (useShowerLibrary && notaMuon) {
422 #ifdef DebugLog
423  LogDebug("HcalSim") << "HCalSD: Starts shower library from "
424  << nameVolume << " for Track "
425  << aStep->GetTrack()->GetTrackID() << " ("
426  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
427 #endif
428  getFromLibrary(aStep, weight);
429  } else if (isItFibre(lv)) {
430 #ifdef DebugLog
431  LogDebug("HcalSim") << "HCalSD: Hit at Fibre in " << nameVolume
432  << " for Track "
433  << aStep->GetTrack()->GetTrackID() <<" ("
434  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
435 #endif
436  hitForFibre(aStep, weight);
437  }
438  }
439  } else if (isItPMT(lv)) {
440 #ifdef DebugLog
441  LogDebug("HcalSim") << "HCalSD: Hit from PMT parametrization from "
442  << nameVolume << " for Track "
443  << aStep->GetTrack()->GetTrackID() << " ("
444  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
445 #endif
446  if (usePMTHit && showerPMT) getHitPMT(aStep);
447  } else if (isItStraightBundle(lv) || isItConicalBundle(lv)) {
448 #ifdef DebugLog
449  LogDebug("HcalSim") << "HCalSD: Hit from FibreBundle from "
450  << nameVolume << " for Track "
451  << aStep->GetTrack()->GetTrackID() << " ("
452  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
453 #endif
456  } else {
457 #ifdef DebugLog
458  LogDebug("HcalSim") << "HCalSD: Hit from standard path from "
459  << nameVolume << " for Track "
460  << aStep->GetTrack()->GetTrackID() << " ("
461  << aStep->GetTrack()->GetDefinition()->GetParticleName() << ")";
462 #endif
463  if (getStepInfo(aStep)) {
464 #ifdef plotDebug
465  if (edepositEM+edepositHAD > 0)
466  plotProfile(aStep, aStep->GetPreStepPoint()->GetPosition(),
467  edepositEM+edepositHAD,aStep->GetPostStepPoint()->GetGlobalTime(),0);
468 #endif
469  if (hitExists() == false && edepositEM+edepositHAD>0.) currentHit = createNewHit();
470  }
471  }
472  return true;
473  }
474 }
475 
476 double HCalSD::getEnergyDeposit(G4Step* aStep) {
477  double destep = aStep->GetTotalEnergyDeposit();
478  double weight = 1;
479  G4Track* theTrack = aStep->GetTrack();
480 
481  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
482  int depth = (touch->GetReplicaNumber(0))%10;
483  int det = ((touch->GetReplicaNumber(1))/1000)-3;
484  if (depth==0 && (det==0 || det==1)) weight = layer0wt[det];
485  if (useLayerWt) {
486  int lay = (touch->GetReplicaNumber(0)/10)%100 + 1;
487  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
488  weight = layerWeight(det+3, hitPoint, depth, lay);
489  }
490 
491  if (m_HEDarkening !=0 && det == 1) {
492  int lay = (touch->GetReplicaNumber(0)/10)%100 + 1;
493  int ieta;
494  uint32_t detid = setDetUnitId(aStep);
495  if(testNumber) {
496  int det, z, depth, eta, phi, lay;
497  HcalTestNumbering::unpackHcalIndex(detid,det,z,depth,eta,phi,lay);
498  ieta = eta;
499  }
500  else ieta = HcalDetId(detid).ietaAbs();
501 #ifdef DebugLog
502  edm::LogInfo("HcalSim") << "HCalSD:HE_Darkening >>> ieta: "<< ieta //<< " vs. ietaAbs(): " << HcalDetId(detid).ietaAbs()
503  << " lay: " << lay-2;
504 #endif
505  float dweight = m_HEDarkening->degradation(deliveredLumi,ieta,lay-2);//NB:diff. layer count
506  weight *= dweight;
507 #ifdef DebugLog
508  edm::LogInfo("HcalSim") << "HCalSD: >>> Lumi: " << deliveredLumi
509  << " coefficient = " << dweight;
510 #endif
511  }
512 
513  if (suppressHeavy) {
514  TrackInformation * trkInfo = (TrackInformation *)(theTrack->GetUserInformation());
515  if (trkInfo) {
516  int pdg = theTrack->GetDefinition()->GetPDGEncoding();
517  if (!(trkInfo->isPrimary())) { // Only secondary particles
518  double ke = theTrack->GetKineticEnergy()/MeV;
519  if ( pdg/1000000000 == 1 && (pdg/10000)%100 > 0 &&
520  (pdg/10)%100 > 0 && ke <kmaxIon ) weight = 0;
521  if ((pdg == 2212) && (ke < kmaxProton)) weight = 0;
522  if ((pdg == 2112) && (ke < kmaxNeutron)) weight = 0;
523 #ifdef DebugLog
524  if (weight == 0)
525  edm::LogInfo("HcalSim") << "HCalSD:Ignore Track "
526  << theTrack->GetTrackID() << " Type "
527  << theTrack->GetDefinition()->GetParticleName()
528  << " Kinetic Energy " << ke << " MeV";
529 #endif
530  }
531  }
532  }
533 #ifdef DebugLog
534  double weight0 = weight;
535 #endif
536  if (useBirk) {
537  G4Material* mat = aStep->GetPreStepPoint()->GetMaterial();
538  if (isItScintillator(mat)) weight *= getAttenuation(aStep, birk1, birk2, birk3);
539  }
540  double wt1 = getResponseWt(theTrack);
541  double wt2 = theTrack->GetWeight();
542  /*
543  if (wt2 != 1.0) {
544  edm::LogInfo("HcalSim") << "HCalSD: Detector " << det+3 << " Depth "
545  << depth << " weight= " << weight << " wt1= "
546  << wt1 << " wt2= " << wt2;
547  const G4VProcess* pr = theTrack->GetCreatorProcess();
548  if (pr) {
549  edm::LogInfo("HcalSim") << theTrack->GetDefinition()->GetParticleName()
550  << " " << theTrack->GetKineticEnergy()
551  << " Id=" << theTrack->GetTrackID()
552  << " IdP=" << theTrack->GetParentID()
553  << " from " << pr->GetProcessName();
554  } else {
555  edm::LogInfo("HcalSim") << theTrack->GetDefinition()->GetParticleName()
556  << " " << theTrack->GetKineticEnergy()
557  << " Id=" << theTrack->GetTrackID()
558  << " IdP=" << theTrack->GetParentID();
559  }
560  }
561  */
562 #ifdef DebugLog
563  edm::LogInfo("HcalSim") << "HCalSD: Detector " << det+3 << " Depth " << depth
564  << " weight " << weight0 << " " << weight << " " << wt1
565  << " " << wt2;
566 #endif
567  double edep = weight*wt1*destep;
568  if(wt2 > 0.0) { edep *= wt2; }
569  return edep;
570 }
571 
572 uint32_t HCalSD::setDetUnitId(G4Step * aStep) {
573 
574  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
575  const G4VTouchable* touch = preStepPoint->GetTouchable();
576  G4ThreeVector hitPoint = preStepPoint->GetPosition();
577 
578  int depth = (touch->GetReplicaNumber(0))%10 + 1;
579  int lay = (touch->GetReplicaNumber(0)/10)%100 + 1;
580  int det = (touch->GetReplicaNumber(1))/1000;
581 
582  return setDetUnitId (det, hitPoint, depth, lay);
583 }
584 
586  if (scheme != 0) {
587  edm::LogInfo("HcalSim") << "HCalSD: updates numbering scheme for " << GetName();
588  if (numberingScheme) delete numberingScheme;
589  numberingScheme = scheme;
590  }
591 }
592 
593 void HCalSD::update(const BeginOfJob * job) {
594 
595  const edm::EventSetup* es = (*job)();
597  es->get<HcalSimNumberingRecord>().get(hdc);
598  if (hdc.isValid()) {
599  hcalConstants = (HcalDDDSimConstants*)(&(*hdc));
600  } else {
601  edm::LogError("HcalSim") << "HCalSD : Cannot find HcalDDDSimConstant";
602  throw cms::Exception("Unknown", "HCalSD") << "Cannot find HcalDDDSimConstant" << "\n";
603  }
604 
606 
607  edm::LogInfo("HcalSim") << "Maximum depth for HF " << hcalConstants->getMaxDepth(2);
608 
609  //Special Geometry parameters
611  edm::LogInfo("HcalSim") << "HCalSD: " << gpar.size()<< " gpar (cm)";
612  for (unsigned int ig=0; ig<gpar.size(); ig++)
613  edm::LogInfo("HcalSim") << "HCalSD: gpar[" << ig << "] = "
614  << gpar[ig]/cm << " cm";
615 
616  //Layer0 Weight
618  edm::LogInfo("HcalSim") << "HCalSD: " << layer0wt.size() << " Layer0Wt";
619  for (unsigned int it=0; it<layer0wt.size(); ++it)
620  edm::LogInfo("HcalSim") << "HCalSD: [" << it << "] " << layer0wt[it];
621 
622 }
623 
625  G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
626  G4String particleName;
627  mumPDG = theParticleTable->FindParticle(particleName="mu-")->GetPDGEncoding();
628  mupPDG = theParticleTable->FindParticle(particleName="mu+")->GetPDGEncoding();
629 #ifdef DebugLog
630  LogDebug("HcalSim") << "HCalSD: Particle code for mu- = " << mumPDG
631  << " for mu+ = " << mupPDG;
632 #endif
633  if (showerLibrary) showerLibrary->initRun(theParticleTable,hcalConstants);
634  if (showerParam) showerParam->initRun(theParticleTable,hcalConstants);
635  if (hfshower) hfshower->initRun(theParticleTable,hcalConstants);
636  if (showerPMT) showerPMT->initRun(theParticleTable,hcalConstants);
637  if (showerBundle) showerBundle->initRun(theParticleTable,hcalConstants);
638 }
639 
640 bool HCalSD::filterHit(CaloG4Hit* aHit, double time) {
641  double threshold=0;
642  DetId theId(aHit->getUnitID());
643  switch (theId.subdetId()) {
644  case HcalBarrel:
645  threshold = eminHitHB; break;
646  case HcalEndcap:
647  threshold = eminHitHE; break;
648  case HcalOuter:
649  threshold = eminHitHO; break;
650  case HcalForward:
651  threshold = eminHitHF; break;
652  default:
653  break;
654  }
655  return ((time <= tmaxHit) && (aHit->getEnergyDeposit() > threshold));
656 }
657 
658 
659 uint32_t HCalSD::setDetUnitId (int det, const G4ThreeVector& pos, int depth, int lay=1) {
660  uint32_t id = 0;
661  if (numberingFromDDD) {
662  //get the ID's as eta, phi, depth, ... indices
663  HcalNumberingFromDDD::HcalID tmp = numberingFromDDD->unitID(det, pos, depth, lay);
664  modifyDepth(tmp);
665  //get the ID
666  if (numberingScheme) id = numberingScheme->getUnitID(tmp);
667  }
668  return id;
669 }
670 
671 std::vector<double> HCalSD::getDDDArray(const std::string & str,
672  const DDsvalues_type & sv) {
673 #ifdef DebugLog
674  LogDebug("HcalSim") << "HCalSD:getDDDArray called for " << str;
675 #endif
676  DDValue value(str);
677  if (DDfetch(&sv,value)) {
678 #ifdef DebugLog
679  LogDebug("HcalSim") << value;
680 #endif
681  const std::vector<double> & fvec = value.doubles();
682  int nval = fvec.size();
683  if (nval < 1) {
684  edm::LogError("HcalSim") << "HCalSD : # of " << str << " bins " << nval
685  << " < 2 ==> illegal";
686  throw cms::Exception("Unknown", "HCalSD") << "nval < 2 for array " << str << "\n";
687  }
688 
689  return fvec;
690  } else {
691  edm::LogError("HcalSim") << "HCalSD : cannot get array " << str;
692  throw cms::Exception("Unknown", "HCalSD") << "cannot get array " << str << "\n";
693  }
694 }
695 
696 std::vector<G4String> HCalSD::getNames(DDFilteredView& fv) {
697 
698  std::vector<G4String> tmp;
699  bool dodet = fv.firstChild();
700  while (dodet) {
701  const DDLogicalPart & log = fv.logicalPart();
702  bool ok = true;
703 
704  for (unsigned int i=0; i<tmp.size(); ++i) {
705  if (!strcmp(tmp[i].c_str(), log.name().name().c_str())) {
706  ok = false;
707  break;
708  }
709  }
710  if (ok) tmp.push_back(log.name().name());
711  dodet = fv.next();
712  }
713  return tmp;
714 }
715 
716 bool HCalSD::isItHF(G4Step * aStep) {
717  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
718  int levels = (touch->GetHistoryDepth()) + 1;
719  for (unsigned int it=0; it < hfNames.size(); ++it) {
720  if (levels >= hfLevels[it]) {
721  G4LogicalVolume* lv = touch->GetVolume(levels-hfLevels[it])->GetLogicalVolume();
722  if (lv == hfLV[it]) return true;
723  }
724  }
725  return false;
726 }
727 
728 bool HCalSD::isItHF (G4String name) {
729  std::vector<G4String>::const_iterator it = hfNames.begin();
730  for (; it != hfNames.end(); ++it) if (name == *it) return true;
731  return false;
732 }
733 
734 bool HCalSD::isItFibre (G4LogicalVolume* lv) {
735  std::vector<G4LogicalVolume*>::const_iterator ite = fibreLV.begin();
736  for (; ite != fibreLV.end(); ++ite) if (lv == *ite) return true;
737  return false;
738 }
739 
740 bool HCalSD::isItFibre (G4String name) {
741  std::vector<G4String>::const_iterator it = fibreNames.begin();
742  for (; it != fibreNames.end(); ++it) if (name == *it) return true;
743  return false;
744 }
745 
746 bool HCalSD::isItPMT (G4LogicalVolume* lv) {
747  std::vector<G4LogicalVolume*>::const_iterator ite = pmtLV.begin();
748  for (; ite != pmtLV.end(); ++ite) if (lv == *ite) return true;
749  return false;
750 }
751 
752 bool HCalSD::isItStraightBundle (G4LogicalVolume* lv) {
753  std::vector<G4LogicalVolume*>::const_iterator ite = fibre1LV.begin();
754  for (; ite != fibre1LV.end(); ++ite) if (lv == *ite) return true;
755  return false;
756 }
757 
758 bool HCalSD::isItConicalBundle (G4LogicalVolume* lv) {
759  std::vector<G4LogicalVolume*>::const_iterator ite = fibre2LV.begin();
760  for (; ite != fibre2LV.end(); ++ite) if (lv == *ite) return true;
761  return false;
762 }
763 
764 bool HCalSD::isItScintillator (G4Material* mat) {
765  std::vector<G4Material*>::const_iterator ite = materials.begin();
766  for (; ite != materials.end(); ++ite) if (mat == *ite) return true;
767  return false;
768 }
769 
770 bool HCalSD::isItinFidVolume (G4ThreeVector& hitPoint) {
771  bool flag = true;
772  if (applyFidCut) {
773  int npmt = HFFibreFiducial:: PMTNumber(hitPoint);
774 #ifdef DebugLog
775  edm::LogInfo("HcalSim") << "HCalSD::isItinFidVolume:#PMT= " << npmt
776  << " for hit point " << hitPoint;
777 #endif
778  if (npmt <= 0) flag = false;
779  }
780 #ifdef DebugLog
781  edm::LogInfo("HcalSim") << "HCalSD::isItinFidVolume: point " << hitPoint
782  << " return flag " << flag;
783 #endif
784  return flag;
785 }
786 
787 void HCalSD::getFromLibrary (G4Step* aStep, double weight) {
788  preStepPoint = aStep->GetPreStepPoint();
789  theTrack = aStep->GetTrack();
790  int det = 5;
791  bool ok;
792 
793  std::vector<HFShowerLibrary::Hit> hits = showerLibrary->getHits(aStep, ok, weight, false);
794 
795  double etrack = preStepPoint->GetKineticEnergy();
796  int primaryID = setTrackID(aStep);
797 
798  // Reset entry point for new primary
799  posGlobal = preStepPoint->GetPosition();
800  resetForNewPrimary(posGlobal, etrack);
801 
802  G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding();
803  if (particleCode==emPDG || particleCode==epPDG || particleCode==gammaPDG) {
804  edepositEM = 1.*GeV;
805  edepositHAD = 0.;
806  } else {
807  edepositEM = 0.;
808  edepositHAD = 1.*GeV;
809  }
810 #ifdef DebugLog
811  edm::LogInfo("HcalSim") << "HCalSD::getFromLibrary " <<hits.size()
812  << " hits for " << GetName() << " of " << primaryID
813  << " with " << theTrack->GetDefinition()->GetParticleName()
814  << " of " << preStepPoint->GetKineticEnergy()/GeV << " GeV";
815 #endif
816  for (unsigned int i=0; i<hits.size(); ++i) {
817  G4ThreeVector hitPoint = hits[i].position;
818  if (isItinFidVolume (hitPoint)) {
819  int depth = hits[i].depth;
820  double time = hits[i].time;
821  unsigned int unitID = setDetUnitId(det, hitPoint, depth);
822  currentID.setID(unitID, time, primaryID, 0);
823 #ifdef plotDebug
824  plotProfile(aStep, hitPoint, 1.0*GeV, time, depth);
825  bool emType = false;
826  if (particleCode==emPDG || particleCode==epPDG || particleCode==gammaPDG)
827  emType = true;
828  plotHF(hitPoint,emType);
829 #endif
830 
831  // check if it is in the same unit and timeslice as the previous one
832  if (currentID == previousID) {
834  } else {
835  if (!checkHit()) currentHit = createNewHit();
836  }
837  }
838  }
839 
840  //Now kill the current track
841  if (ok) {
842  theTrack->SetTrackStatus(fStopAndKill);
843  G4TrackVector tv = *(aStep->GetSecondary());
844  for (unsigned int kk=0; kk<tv.size(); ++kk)
845  if (tv[kk]->GetVolume() == preStepPoint->GetPhysicalVolume())
846  tv[kk]->SetTrackStatus(fStopAndKill);
847  }
848 }
849 
850 void HCalSD::hitForFibre (G4Step* aStep, double weight) { // if not ParamShower
851 
852  preStepPoint = aStep->GetPreStepPoint();
853  theTrack = aStep->GetTrack();
854  int primaryID = setTrackID(aStep);
855 
856  int det = 5;
857  std::vector<HFShower::Hit> hits = hfshower->getHits(aStep, weight);
858 
859  G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding();
860  if (particleCode==emPDG || particleCode==epPDG || particleCode==gammaPDG) {
861  edepositEM = 1.*GeV;
862  edepositHAD = 0.;
863  } else {
864  edepositEM = 0.;
865  edepositHAD = 1.*GeV;
866  }
867 
868 #ifdef DebugLog
869  edm::LogInfo("HcalSim") << "HCalSD::hitForFibre " << hits.size()
870  << " hits for " << GetName() << " of " << primaryID
871  << " with " << theTrack->GetDefinition()->GetParticleName()
872  << " of " << preStepPoint->GetKineticEnergy()/GeV
873  << " GeV in detector type " << det;
874 #endif
875  if (hits.size() > 0) {
876  for (unsigned int i=0; i<hits.size(); ++i) {
877  G4ThreeVector hitPoint = hits[i].position;
878  if (isItinFidVolume (hitPoint)) {
879  int depth = hits[i].depth;
880  double time = hits[i].time;
881  unsigned int unitID = setDetUnitId(det, hitPoint, depth);
882  currentID.setID(unitID, time, primaryID, 0);
883 #ifdef plotDebug
884  plotProfile(aStep, hitPoint, edepositEM, time, depth);
885  bool emType = false;
886  if (particleCode==emPDG || particleCode==epPDG || particleCode==gammaPDG)
887  emType = true;
888  plotHF(hitPoint,emType);
889 #endif
890  // check if it is in the same unit and timeslice as the previous one
891  if (currentID == previousID) {
893  } else {
894  posGlobal = preStepPoint->GetPosition();
895  if (!checkHit()) currentHit = createNewHit();
896  }
897  }
898  }
899  }
900 }
901 
902 void HCalSD::getFromParam (G4Step* aStep, double weight) {
903  std::vector<HFShowerParam::Hit> hits = showerParam->getHits(aStep, weight);
904  int nHit = static_cast<int>(hits.size());
905 
906  if (nHit > 0) {
907  preStepPoint = aStep->GetPreStepPoint();
908  int primaryID = setTrackID(aStep);
909 
910  int det = 5;
911 #ifdef DebugLog
912  edm::LogInfo("HcalSim") << "HCalSD::getFromParam " << nHit << " hits for "
913  << GetName() << " of " << primaryID << " with "
914  << aStep->GetTrack()->GetDefinition()->GetParticleName()
915  << " of " << preStepPoint->GetKineticEnergy()/GeV
916  << " GeV in detector type " << det;
917 #endif
918  for (int i = 0; i<nHit; ++i) {
919  G4ThreeVector hitPoint = hits[i].position;
920  int depth = hits[i].depth;
921  double time = hits[i].time;
922  unsigned int unitID = setDetUnitId(det, hitPoint, depth);
923  currentID.setID(unitID, time, primaryID, 0);
924  edepositEM = hits[i].edep*GeV;
925  edepositHAD = 0.;
926 #ifdef plotDebug
927  plotProfile(aStep, hitPoint, edepositEM, time, depth);
928 #endif
929 
930  // check if it is in the same unit and timeslice as the previous one
931  if (currentID == previousID) {
933  } else {
934  posGlobal = preStepPoint->GetPosition();
935  if (!checkHit()) currentHit = createNewHit();
936  }
937  }
938  }
939 }
940 
941 void HCalSD::getHitPMT (G4Step * aStep) {
942 
943  preStepPoint = aStep->GetPreStepPoint();
944  theTrack = aStep->GetTrack();
945  double edep = showerPMT->getHits(aStep);
946 
947  if (edep >= 0) {
948  double etrack = preStepPoint->GetKineticEnergy();
949  int primaryID = 0;
950  if (etrack >= energyCut) {
951  primaryID = theTrack->GetTrackID();
952  } else {
953  primaryID = theTrack->GetParentID();
954  if (primaryID == 0) primaryID = theTrack->GetTrackID();
955  }
956  // Reset entry point for new primary
957  posGlobal = preStepPoint->GetPosition();
958  resetForNewPrimary(posGlobal, etrack);
959 
960  //
961  int det = static_cast<int>(HcalForward);
962  G4ThreeVector hitPoint = preStepPoint->GetPosition();
963  double rr = (hitPoint.x()*hitPoint.x() + hitPoint.y()*hitPoint.y());
964  double phi = (rr == 0. ? 0. :atan2(hitPoint.y(),hitPoint.x()));
965  double etaR = showerPMT->getRadius();
966  int depth = 1;
967  if (etaR < 0) {
968  depth = 2;
969  etaR =-etaR;
970  }
971  if (hitPoint.z() < 0) etaR =-etaR;
972 #ifdef DebugLog
973  edm::LogInfo("HcalSim") << "HCalSD::Hit for Detector " << det << " etaR "
974  << etaR << " phi " << phi/deg << " depth " <<depth;
975 #endif
976  double time = (aStep->GetPostStepPoint()->GetGlobalTime());
977  uint32_t unitID = 0;
978  if (numberingFromDDD) {
980  depth,1);
981  modifyDepth(tmp);
982  if (numberingScheme) unitID = numberingScheme->getUnitID(tmp);
983  }
984  currentID.setID(unitID, time, primaryID, 1);
985 
986  edepositHAD = aStep->GetTotalEnergyDeposit();
987  edepositEM =-edepositHAD + (edep*GeV);
988 #ifdef plotDebug
989  plotProfile(aStep, hitPoint, edep*GeV, time, depth);
990 #endif
991 #ifdef DebugLog
992  double beta = preStepPoint->GetBeta();
993  LogDebug("HcalSim") << "HCalSD::getHitPMT 1 hit for " << GetName()
994  << " of " << primaryID << " with "
995  << theTrack->GetDefinition()->GetParticleName()
996  << " of " << preStepPoint->GetKineticEnergy()/GeV
997  << " GeV with velocity " << beta << " UnitID "
998  << std::hex << unitID << std::dec;
999 #endif
1000  // check if it is in the same unit and timeslice as the previous one
1001  if (currentID == previousID) {
1003  } else {
1004  if (!checkHit()) currentHit = createNewHit();
1005  }
1006  }
1007 }
1008 
1009 void HCalSD::getHitFibreBundle (G4Step* aStep, bool type) {
1010  preStepPoint = aStep->GetPreStepPoint();
1011  theTrack = aStep->GetTrack();
1012  double edep = showerBundle->getHits(aStep, type);
1013 
1014  if (edep >= 0) {
1015  double etrack = preStepPoint->GetKineticEnergy();
1016  int primaryID = 0;
1017  if (etrack >= energyCut) {
1018  primaryID = theTrack->GetTrackID();
1019  } else {
1020  primaryID = theTrack->GetParentID();
1021  if (primaryID == 0) primaryID = theTrack->GetTrackID();
1022  }
1023  // Reset entry point for new primary
1024  posGlobal = preStepPoint->GetPosition();
1025  resetForNewPrimary(posGlobal, etrack);
1026 
1027  //
1028  int det = static_cast<int>(HcalForward);
1029  G4ThreeVector hitPoint = preStepPoint->GetPosition();
1030  double rr = (hitPoint.x()*hitPoint.x() + hitPoint.y()*hitPoint.y());
1031  double phi = (rr == 0. ? 0. :atan2(hitPoint.y(),hitPoint.x()));
1032  double etaR = showerBundle->getRadius();
1033  int depth = 1;
1034  if (etaR < 0) {
1035  depth = 2;
1036  etaR =-etaR;
1037  }
1038  if (hitPoint.z() < 0) etaR =-etaR;
1039 #ifdef DebugLog
1040  LogDebug("HcalSim") << "HCalSD::Hit for Detector " << det << " etaR "
1041  << etaR << " phi " << phi/deg << " depth " <<depth;
1042 #endif
1043  double time = (aStep->GetPostStepPoint()->GetGlobalTime());
1044  uint32_t unitID = 0;
1045  if (numberingFromDDD) {
1046  HcalNumberingFromDDD::HcalID tmp = numberingFromDDD->unitID(det,etaR,phi,depth,1);
1047  modifyDepth(tmp);
1048  if (numberingScheme) unitID = numberingScheme->getUnitID(tmp);
1049  }
1050  if (type) currentID.setID(unitID, time, primaryID, 3);
1051  else currentID.setID(unitID, time, primaryID, 2);
1052 
1053  edepositHAD = aStep->GetTotalEnergyDeposit();
1054  edepositEM =-edepositHAD + (edep*GeV);
1055 #ifdef plotDebug
1056  plotProfile(aStep, hitPoint, edep*GeV, time, depth);
1057 #endif
1058 #ifdef DebugLog
1059  double beta = preStepPoint->GetBeta();
1060  LogDebug("HcalSim") << "HCalSD::getHitFibreBundle 1 hit for " << GetName()
1061  << " of " << primaryID << " with "
1062  << theTrack->GetDefinition()->GetParticleName()
1063  << " of " << preStepPoint->GetKineticEnergy()/GeV
1064  << " GeV with velocity " << beta << " UnitID "
1065  << std::hex << unitID << std::dec;
1066 #endif
1067  // check if it is in the same unit and timeslice as the previous one
1069  else if (!checkHit()) currentHit = createNewHit();
1070  } // non-zero energy deposit
1071 }
1072 
1073 int HCalSD::setTrackID (G4Step* aStep) {
1074  theTrack = aStep->GetTrack();
1075 
1076  double etrack = preStepPoint->GetKineticEnergy();
1077  TrackInformation * trkInfo = (TrackInformation *)(theTrack->GetUserInformation());
1078  int primaryID = trkInfo->getIDonCaloSurface();
1079  if (primaryID == 0) {
1080 #ifdef DebugLog
1081  edm::LogInfo("HcalSim") << "HCalSD: Problem with primaryID **** set by "
1082  << "force to TkID **** " <<theTrack->GetTrackID();
1083 #endif
1084  primaryID = theTrack->GetTrackID();
1085  }
1086 
1087  if (primaryID != previousID.trackID())
1088  resetForNewPrimary(preStepPoint->GetPosition(), etrack);
1089 
1090  return primaryID;
1091 }
1092 
1094 
1095  std::ifstream infile;
1096  int entry=0;
1097  infile.open(fName.c_str(), std::ios::in);
1098  if (infile) {
1099  int det, zside, etaR, phi, lay;
1100  double wt;
1101  while (infile >> det >> zside >> etaR >> phi >> lay >> wt) {
1102  uint32_t id = HcalTestNumbering::packHcalIndex(det,zside,1,etaR,phi,lay);
1103  layerWeights.insert(std::pair<uint32_t,double>(id,wt));
1104  ++entry;
1105 #ifdef DebugLog
1106  edm::LogInfo("HcalSim") << "HCalSD::readWeightFromFile:Entry " << entry
1107  << " ID " << std::hex << id << std::dec << " ("
1108  << det << "/" << zside << "/1/" << etaR << "/"
1109  << phi << "/" << lay << ") Weight " << wt;
1110 #endif
1111  }
1112  infile.close();
1113  }
1114  edm::LogInfo("HcalSim") << "HCalSD::readWeightFromFile: reads " << entry
1115  << " weights from " << fName;
1116  if (entry <= 0) useLayerWt = false;
1117 }
1118 
1119 double HCalSD::layerWeight(int det, const G4ThreeVector& pos, int depth, int lay) {
1120 
1121  double wt = 1.;
1122  if (numberingFromDDD) {
1123  //get the ID's as eta, phi, depth, ... indices
1125  depth, lay);
1126  modifyDepth(tmp);
1127  uint32_t id = HcalTestNumbering::packHcalIndex(tmp.subdet, tmp.zside, 1,
1128  tmp.etaR, tmp.phis,tmp.lay);
1129  std::map<uint32_t,double>::const_iterator ite = layerWeights.find(id);
1130  if (ite != layerWeights.end()) wt = ite->second;
1131 #ifdef DebugLog
1132  edm::LogInfo("HcalSim") << "HCalSD::layerWeight: ID " << std::hex << id
1133  << std::dec << " (" << tmp.subdet << "/"
1134  << tmp.zside << "/1/" << tmp.etaR << "/"
1135  << tmp.phis << "/" << tmp.lay << ") Weight " <<wt;
1136 #endif
1137  }
1138  return wt;
1139 }
1140 
1141 void HCalSD::plotProfile(G4Step* aStep,const G4ThreeVector& global, double edep,
1142  double time, int id) {
1143 
1144  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
1145  static G4String modName[8] = {"HEModule", "HVQF" , "HBModule", "MBAT",
1146  "MBBT" , "MBBTC", "MBBT_R1P", "MBBT_R1M"};
1147  G4ThreeVector local;
1148  bool found=false;
1149  double depth=-2000;
1150  int idx = 4;
1151  for (int n=0; n<touch->GetHistoryDepth(); ++n) {
1152  G4String name = touch->GetVolume(n)->GetName();
1153 #ifdef DebugLog
1154  LogDebug("HcalSim") << "plotProfile Depth " << n << " Name " << name;
1155 #endif
1156  for (unsigned int ii=0; ii<8; ++ii) {
1157  if (name == modName[ii]) {
1158  found = true;
1159  int dn = touch->GetHistoryDepth() - n;
1160  local = touch->GetHistory()->GetTransform(dn).TransformPoint(global);
1161  if (ii == 0) {depth = local.z() - 4006.5; idx = 1;}
1162  else if (ii == 1) {depth = local.z() + 825.0; idx = 3;}
1163  else if (ii == 2) {depth = local.x() - 1775.; idx = 0;}
1164  else {depth = local.y() + 15.; idx = 2;}
1165  break;
1166  }
1167  }
1168  if (found) break;
1169  }
1170  if (!found) depth = std::abs(global.z()) - 11500;
1171 #ifdef DebugLog
1172  LogDebug("HcalSim") << "plotProfile Found " << found << " Global " << global
1173  << " Local " << local << " depth " << depth << " ID "
1174  << id << " EDEP " << edep << " Time " << time;
1175 #endif
1176  if (hit_[idx] != 0) hit_[idx]->Fill(edep);
1177  if (time_[idx] != 0) time_[idx]->Fill(time,edep);
1178  if (dist_[idx] != 0) dist_[idx]->Fill(depth,edep);
1179  int jd = 2*idx + id - 7;
1180  if (jd >= 0 && jd < 4) {
1181  jd += 5;
1182  if (hit_[jd] != 0) hit_[jd]->Fill(edep);
1183  if (time_[jd] != 0) time_[jd]->Fill(time,edep);
1184  if (dist_[jd] != 0) dist_[jd]->Fill(depth,edep);
1185  }
1186 }
1187 
1188 void HCalSD::plotHF(G4ThreeVector& hitPoint, bool emType) {
1189  double zv = std::abs(hitPoint.z()) - gpar[4];
1190  if (emType) {
1191  if (hzvem != 0) hzvem->Fill(zv);
1192  } else {
1193  if (hzvhad != 0) hzvhad->Fill(zv);
1194  }
1195 }
1196 
1198  if (id.subdet == 4) {
1199  int ieta = (id.zside == 0) ? -id.etaR : id.etaR;
1200  if (hcalConstants->maxHFDepth(ieta,id.phis) > 2) {
1201  if (id.depth <= 2) {
1202  if (G4UniformRand() > 0.5) id.depth += 2;
1203  }
1204  }
1205  }
1206 }
#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:850
const N & name() const
Definition: DDBase.h:78
void getFromParam(G4Step *step, double weight)
Definition: HCalSD.cc:902
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:593
bool isItStraightBundle(G4LogicalVolume *)
Definition: HCalSD.cc:752
virtual bool ProcessHits(G4Step *, G4TouchableHistory *)
Definition: HCalSD.cc:372
std::vector< double > gpar
Definition: HCalSD.h:97
bool useFibreBundle
Definition: HCalSD.h:91
bool isItinFidVolume(G4ThreeVector &)
Definition: HCalSD.cc:770
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:671
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:572
double birk2
Definition: HCalSD.h:92
int setTrackID(G4Step *step)
Definition: HCalSD.cc:1073
void getFromLibrary(G4Step *step, double weight)
Definition: HCalSD.cc:787
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:1197
int ii
Definition: cuy.py:588
void setNumberingScheme(HcalNumberingScheme *)
Definition: HCalSD.cc:585
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:716
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:758
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:624
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:764
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:476
G4int epPDG
Definition: CaloSD.h:136
void plotHF(G4ThreeVector &pos, bool emType)
Definition: HCalSD.cc:1188
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:359
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:941
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:1141
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:746
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.cc:119
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:1093
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:1009
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:1119
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
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:640
list entry
Definition: mps_splice.py:62
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
int weight
Definition: histoStyle.py:50
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:734
double getEnergyDeposit() const
Definition: CaloG4Hit.h:81
bool useHF
Definition: HCalSD.h:93
int maxHFDepth(int ieta, int iphi) const
HcalDDDSimConstants * hcalConstants
Definition: HCalSD.h:81
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:32