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