CMS 3D CMS Logo

CalorimetryManager.cc
Go to the documentation of this file.
1 //updated by Reza Goldouzian
2 //Framework headers
5 
6 // Fast Simulation headers
18 //#include "FastSimulation/Utilities/interface/Histos.h"
28 // New headers for Muon Mip Simulation
31 // Muon Brem
33 
34 //Gflash Hadronic Model
42 
43 //FastHFShowerLibrary
45 
46 // STL headers
47 #include <vector>
48 #include <iostream>
49 
50 //CMSSW headers
53 //#include "DataFormats/EcalDetId/interface/EcalDetId.h"
55 
58 
59 //ROOT headers
60 #include "TROOT.h"
61 #include "TH1.h"
62 
63 using namespace edm;
64 
67 
68 std::vector<std::pair<int,float> > CalorimetryManager::myZero_ = std::vector<std::pair<int,float> >
69  (1,std::pair<int,float>(0,0.));
70 
72  myCalorimeter_(nullptr),
73  initialized_(false)
74 {;}
75 
77  const edm::ParameterSet& fastCalo,
78  const edm::ParameterSet& fastMuECAL,
79  const edm::ParameterSet& fastMuHCAL,
80  const edm::ParameterSet& parGflash)
81  :
82  mySimEvent(aSimEvent),
85 {
86 
89 
90  //Gflash
91  theProfile = new GflashHadronShowerProfile(parGflash);
92  thePiKProfile = new GflashPiKShowerProfile(parGflash);
95 
96  // FastHFShowerLibrary
98 
99  readParameters(fastCalo);
100 
101  myCalorimeter_ =
102  new CaloGeometryHelper(fastCalo);
103  myHDResponse_ =
104  new HCALResponse(fastCalo.getParameter<edm::ParameterSet>("HCALResponse"));
105  myHSParameters_ =
106  new HSParameters(fastCalo.getParameter<edm::ParameterSet>("HSParameters"));
107 
108  // Material Effects for Muons in ECAL (only EnergyLoss implemented so far)
109  if ( fastMuECAL.getParameter<bool>("PairProduction") ||
110  fastMuECAL.getParameter<bool>("Bremsstrahlung") ||
111  fastMuECAL.getParameter<bool>("MuonBremsstrahlung") ||
112  fastMuECAL.getParameter<bool>("EnergyLoss") ||
113  fastMuECAL.getParameter<bool>("MultipleScattering") )
114  theMuonEcalEffects = new MaterialEffects(fastMuECAL);
115 
116  // Material Effects for Muons in HCAL (only EnergyLoss implemented so far)
117  if ( fastMuHCAL.getParameter<bool>("PairProduction") ||
118  fastMuHCAL.getParameter<bool>("Bremsstrahlung") ||
119  fastMuHCAL.getParameter<bool>("MuonBremsstrahlung") ||
120  fastMuHCAL.getParameter<bool>("EnergyLoss") ||
121  fastMuHCAL.getParameter<bool>("MultipleScattering") )
122  theMuonHcalEffects = new MaterialEffects(fastMuHCAL);
123 
124  if( fastCalo.exists("ECALResponseScaling") ) {
125  ecalCorrection = std::unique_ptr<KKCorrectionFactors>( new KKCorrectionFactors( fastCalo.getParameter<edm::ParameterSet>("ECALResponseScaling") ) );
126  }
127 
128 }
129 
131 {
132  EBMapping_.clear();
133  EEMapping_.clear();
134  HMapping_.clear();
135  ESMapping_.clear();
136  muonSimTracks.clear();
137  savedMuonSimTracks.clear();
138 }
139 
141 {
142  if(myCalorimeter_) delete myCalorimeter_;
143  if(myHDResponse_) delete myHDResponse_;
144 
147 
148  if ( theProfile ) delete theProfile;
149 
151 }
152 
154 {
155  if(!evtsToDebug_.empty())
156  {
157  std::vector<unsigned int>::const_iterator itcheck=find(evtsToDebug_.begin(),evtsToDebug_.end(),mySimEvent->id().event());
158  debug_=(itcheck!=evtsToDebug_.end());
159  if(debug_)
160  mySimEvent->print();
161  }
162 
163  initialize(random);
164 
165  LogInfo("FastCalorimetry") << "Reconstructing " << (int) mySimEvent->nTracks() << " tracks." << std::endl;
166  for( int fsimi=0; fsimi < (int) mySimEvent->nTracks() ; ++fsimi) {
167 
168  FSimTrack& myTrack = mySimEvent->track(fsimi);
169 
170  reconstructTrack(myTrack, random);
171  } // particle loop
172 
173 } // reconstruct
174 
176 
177  // Clear the content of the calorimeters
178  if(!initialized_)
179  {
180  theHFShowerLibrary->SetRandom(random);
181 
182  // Check if the preshower is really available
184  {
185  edm::LogWarning("CalorimetryManager") << " WARNING: The preshower simulation has been turned on; but no preshower geometry is available " << std::endl;
186  edm::LogWarning("CalorimetryManager") << " Disabling the preshower simulation " << std::endl;
187  simulatePreshower_ = false;
188  }
189 
190  initialized_=true;
191  }
192  clean();
193 }
194 
196  int pid = abs(myTrack.type());
197 
198  if (debug_) {
199  LogInfo("FastCalorimetry") << " ===> pid = " << pid << std::endl;
200  }
201 
202  // Check that the particle hasn't decayed
203  if(myTrack.noEndVertex()) {
204  // Simulate energy smearing for photon and electrons
205  float charge_ = (float)(myTrack.charge());
206  if ( pid == 11 || pid == 22 ) {
207 
208  if ( myTrack.onEcal() )
209  EMShowerSimulation(myTrack, random);
210  else if ( myTrack.onVFcal() ) {
211  if(useShowerLibrary) {
213  myHDResponse_->correctHF(myTrack.hcalEntrance().e(),abs(myTrack.type()));
215  }
216  else reconstructHCAL(myTrack, random);
217  }
218  } // electron or photon
219  else if (pid == 13 || pid == 1000024 || (pid > 1000100 && pid < 1999999 && fabs(charge_) > 0.001))
220  {
221  MuonMipSimulation(myTrack, random);
222  }
223  // Simulate energy smearing for hadrons (i.e., everything
224  // but muons... and SUSY particles that deserve a special
225  // treatment.
226  else if ( pid < 1000000 ) {
227  if ( myTrack.onHcal() || myTrack.onVFcal() ) {
228  if(optionHDSim_ == 0 ) reconstructHCAL(myTrack, random);
229  else HDShowerSimulation(myTrack, random);
230  }
231  } // pid < 1000000
232  } // myTrack.noEndVertex()
233 }
234 
235 // Simulation of electromagnetic showers in PS, ECAL, HCAL
238  std::vector<const RawParticle*> thePart;
239  double X0depth;
240 
241  if (debug_) {
242  LogInfo("FastCalorimetry") << " EMShowerSimulation " <<myTrack << std::endl;
243  }
244 
245  // The Particle at ECAL entrance
246  myPart = myTrack.ecalEntrance();
247 
248  // protection against infinite loop.
249  if ( myTrack.type() == 22 && myPart.e()<0.055) return;
250 
251 
252  // Barrel or Endcap ?
253  int onEcal = myTrack.onEcal();
254  int onHcal = myTrack.onHcal();
255  int onLayer1 = myTrack.onLayer1();
256  int onLayer2 = myTrack.onLayer2();
257 
258  // The entrance in ECAL
259  XYZPoint ecalentrance = myPart.vertex().Vect();
260 
261  // The preshower
262  PreshowerHitMaker * myPreshower = nullptr;
263  if(simulatePreshower_ && (onLayer1 || onLayer2))
264  {
265  XYZPoint layer1entrance,layer2entrance;
266  XYZVector dir1,dir2;
267  if(onLayer1)
268  {
269  layer1entrance = XYZPoint(myTrack.layer1Entrance().vertex().Vect());
270  dir1 = XYZVector(myTrack.layer1Entrance().Vect().Unit());
271  }
272  if(onLayer2)
273  {
274  layer2entrance = XYZPoint(myTrack.layer2Entrance().vertex().Vect());
275  dir2 = XYZVector(myTrack.layer2Entrance().Vect().Unit());
276  }
277  myPreshower = new PreshowerHitMaker(myCalorimeter_,
278  layer1entrance,
279  dir1,
280  layer2entrance,
281  dir2,
283  random);
284  myPreshower->setMipEnergy(mipValues_[0],mipValues_[1]);
285  }
286 
287  // The ECAL Properties
289  showerparam(myCalorimeter_->ecalProperties(onEcal),
290  myCalorimeter_->hcalProperties(onHcal),
291  myCalorimeter_->layer1Properties(onLayer1),
292  myCalorimeter_->layer2Properties(onLayer2),
295  RCFactor_,
296  RTFactor_);
297 
298  // Photons : create an e+e- pair
299  if ( myTrack.type() == 22 ) {
300 
301  // Depth for the first e+e- pair creation (in X0)
302  X0depth = -log(random->flatShoot()) * (9./7.);
303 
304  // Initialization
305  double eMass = 0.000510998902;
306  double xe=0;
307  double xm=eMass/myPart.e();
308  double weight = 0.;
309 
310  // Generate electron energy between emass and eGamma-emass
311  do {
312  xe = random->flatShoot()*(1.-2.*xm) + xm;
313  weight = 1. - 4./3.*xe*(1.-xe);
314  } while ( weight < random->flatShoot() );
315 
316  // Protection agains infinite loop in Famos Shower
317  if ( myPart.e()*xe < 0.055 || myPart.e()*(1.-xe) < 0.055 ) {
318 
319  if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
320 
321  } else {
322 
323  myElec = (myPart) * xe;
324  myPosi = (myPart) * (1.-xe);
327  thePart.push_back(&myElec);
328  thePart.push_back(&myPosi);
329  }
330  // Electrons
331  } else {
332 
333  X0depth = 0.;
334  if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
335 
336  }
337 
338  // After the different protections, this shouldn't happen.
339  if(thePart.empty())
340  {
341  if(myPreshower==nullptr) return;
342  delete myPreshower;
343  return;
344  }
345 
346  // find the most energetic particle
347  double maxEnergy=-1.;
348  for(unsigned ip=0;ip < thePart.size();++ip)
349  if(thePart[ip]->e() > maxEnergy) maxEnergy = thePart[ip]->e();
350 
351  // Initialize the Grid in ECAL
352  int size = gridSize_;
353  if(maxEnergy>100) size=11;
354 
355  EMShower theShower(random,aGammaGenerator,&showerparam,&thePart,nullptr,nullptr,bFixedLength_);
356 
357  double maxShower = theShower.getMaximumOfShower();
358  if (maxShower > 20.) maxShower = 2.; // simple pivot-searching protection
359 
360  double depth((X0depth + maxShower) *
362  XYZPoint meanShower = ecalentrance + myPart.Vect().Unit()*depth;
363 
364 
365  // The closest crystal
366  DetId pivot(myCalorimeter_->getClosestCell(meanShower, true, onEcal==1));
367 
368  if(pivot.subdetId() == 0) { // further protection against avbsence of pivot
369  edm::LogWarning("CalorimetryManager") << "Pivot for egamma e = " << myTrack.hcalEntrance().e() << " is not found at depth " << depth << " and meanShower coordinates = " << meanShower << std::endl;
370  if(myPreshower) delete myPreshower;
371  return;
372  }
373 
374  EcalHitMaker myGrid(myCalorimeter_,ecalentrance,pivot,onEcal,size,0,random);
375  // ^^^^
376  // for EM showers
379 
380  //maximumdepth dependence of the radiusfactorbehindpreshower
381  //First tuning: Shilpi Jain (Mar-Apr 2010); changed after tuning - Feb-July - Shilpi Jain
382  /* **************
383  myGrid.setRadiusFactor(radiusFactor_);
384  if(onLayer1 || onLayer2)
385  {
386  float b = radiusPreshowerCorrections_[0];
387  float a = radiusFactor_*( 1.+radiusPreshowerCorrections_[1]*radiusPreshowerCorrections_[0] );
388  float maxdepth = X0depth+theShower.getMaximumOfShower();
389  float newRadiusFactor = radiusFactor_;
390  if(myPart.e()<=250.)
391  {
392  newRadiusFactor = a/(1.+b*maxdepth);
393  }
394  myGrid.setRadiusFactor(newRadiusFactor);
395  }
396  else // otherwise use the normal radius factor
397  {
398  myGrid.setRadiusFactor(radiusFactor_);
399  }
400  ************** */
401  if(myTrack.onEcal() == 2) // if on EE
402  {
403  if( (onLayer1 || onLayer2) && myPart.e()<=250.)
404  {
405  double maxdepth = X0depth+theShower.getMaximumOfShower();
406  double newRadiusFactor = radiusFactorEE_ * aTerm/(1.+bTerm*maxdepth);
407  myGrid.setRadiusFactor(newRadiusFactor);
408  }
409  else // otherwise use the normal radius factor
410  {
412  }
413  }//if(myTrack.onEcal() == 2)
414  else // else if on EB
415  {
417  }
418  //(end of) changed after tuning - Feb-July - Shilpi Jain
419 
421 
422  // The shower simulation
423  myGrid.setTrackParameters(myPart.Vect().Unit(),X0depth,myTrack);
424 
425  if(myPreshower) theShower.setPreshower(myPreshower);
426 
427  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)0);
428 
429  theShower.setGrid(&myGrid);
430  theShower.setHcal(&myHcalHitMaker);
431  theShower.compute();
432 
433  // calculate the total simulated energy for this particle
434  float simE = 0;
435  for( const auto& mapIterator : myGrid.getHits() ) {
436  simE += mapIterator.second;
437  }
438 
439  auto scale = ecalCorrection ? ecalCorrection->getScale( myTrack.ecalEntrance().e(),
440  std::abs( myTrack.ecalEntrance().eta() ), simE ) : 1.;
441 
442  // Save the hits !
443  updateECAL( myGrid.getHits(), onEcal,myTrack.id(), scale );
444 
445  // Now fill the HCAL hits
446  updateHCAL(myHcalHitMaker.getHits(),myTrack.id());
447 
448  // delete the preshower
449  if(myPreshower!=nullptr) {
450  updatePreshower(myPreshower->getHits(),myTrack.id());
451  delete myPreshower;
452  }
453 
454 }
455 
458 {
459  int hit;
460  int pid = abs(myTrack.type());
461  if (debug_) {
462  LogInfo("FastCalorimetry") << " reconstructHCAL " << myTrack << std::endl;
463  }
464 
465  XYZTLorentzVector trackPosition;
466  if (myTrack.onHcal()) {
467  trackPosition=myTrack.hcalEntrance().vertex();
468  hit = myTrack.onHcal()-1;
469  } else {
470  trackPosition=myTrack.vfcalEntrance().vertex();
471  hit = 2;
472  }
473 
474  double pathEta = trackPosition.eta();
475  double pathPhi = trackPosition.phi();
476 
477  double EGen = myTrack.hcalEntrance().e();
478  double emeas = 0.;
479 
480  float charge_ = (float)myTrack.charge();
481  if (pid == 13 || pid == 1000024 || (pid > 1000100 && pid < 1999999 && fabs(charge_) > 0.001)) {
482  emeas = myHDResponse_->responseHCAL(0, EGen, pathEta, 2, random); // 2=muon
483  if(debug_)
484  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - MUON !!!" << std::endl;
485  }
486  else if( pid == 22 || pid == 11) {
487  emeas = myHDResponse_->responseHCAL(0, EGen, pathEta, 0, random); // last par. = 0 = e/gamma
488  if(debug_)
489  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
490  }
491  else {
492  emeas = myHDResponse_->getHCALEnergyResponse(EGen, hit, random);
493  }
494 
495  if(debug_)
496  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - on-calo "
497  << " eta = " << pathEta
498  << " phi = " << pathPhi
499  << " Egen = " << EGen
500  << " Emeas = " << emeas << std::endl;
501 
502  if(emeas > 0.) {
503  DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
504  double tof = (((HcalGeometry*)(myCalorimeter_->getHcalGeometry()))->getPosition(cell).mag())/29.98;//speed of light
505  CaloHitID current_id(cell.rawId(),tof,myTrack.id());
506  std::map<CaloHitID,float> hitMap;
507  hitMap[current_id] = emeas;
508  updateHCAL(hitMap,myTrack.id());
509  }
510 }
511 
513  // const edm::ParameterSet& fastCalo){
514 
515  theHFShowerLibrary->SetRandom(random);
516 
517  // TimeMe t(" FASTEnergyReconstructor::HDShower");
518  const XYZTLorentzVector& moment = myTrack.momentum();
519 
520  if(debug_)
521  LogInfo("FastCalorimetry")
522  << "CalorimetryManager::HDShowerSimulation - track param."
523  << std::endl
524  << " eta = " << moment.eta() << std::endl
525  << " phi = " << moment.phi() << std::endl
526  << " et = " << moment.Et() << std::endl
527  << " e = " << myTrack.hcalEntrance().e() << std::endl;
528 
529  if (debug_) {
530  LogInfo("FastCalorimetry") << " HDShowerSimulation " << myTrack << std::endl;
531  }
532 
533 
534  int hit;
535 
536  XYZTLorentzVector trackPosition;
537  if ( myTrack.onEcal() ) {
538  trackPosition=myTrack.ecalEntrance().vertex();
539  hit = myTrack.onEcal()-1; //
540  myPart = myTrack.ecalEntrance();
541  } else if ( myTrack.onVFcal()) {
542  trackPosition=myTrack.vfcalEntrance().vertex();
543  hit = 2;
544  myPart = myTrack.vfcalEntrance();
545  }
546  else
547  {
548  LogInfo("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
549  return;
550  }
551 
552  // int onHCAL = hit + 1; - specially for myCalorimeter->hcalProperties(onHCAL)
553  // (below) to get VFcal properties ...
554  int onHCAL = hit + 1;
555  int onECAL = myTrack.onEcal();
556 
557  double pathEta = trackPosition.eta();
558  double pathPhi = trackPosition.phi();
559 
560  double eint = moment.e();
561  double eGen = myTrack.hcalEntrance().e();
562 
563  double emeas = 0.;
564  double pmip= myHDResponse_->getMIPfraction(eGen, pathEta);
565 
566 
567  //===========================================================================
568  if(eGen > 0.) {
569 
570  // ECAL and HCAL properties to get
572  theHDShowerparam(myCalorimeter_->ecalProperties(onECAL),
575 
576  //Making ECAL Grid (and segments calculation)
577  XYZPoint caloentrance;
578  XYZVector direction;
579  if(myTrack.onEcal())
580  {
581  caloentrance = myTrack.ecalEntrance().vertex().Vect();
582  direction = myTrack.ecalEntrance().Vect().Unit();
583  }
584  else if(myTrack.onHcal())
585  {
586  caloentrance = myTrack.hcalEntrance().vertex().Vect();
587  direction = myTrack.hcalEntrance().Vect().Unit();
588  }
589  else
590  {
591  caloentrance = myTrack.vfcalEntrance().vertex().Vect();
592  direction = myTrack.vfcalEntrance().Vect().Unit();
593  }
594 
595  if(debug_)
596  LogInfo("FastCalorimetry")
597  << "CalorimetryManager::HDShowerSimulation - on-calo 1 "
598  << std::endl
599  << " onEcal = " << myTrack.onEcal() << std::endl
600  << " onHcal = " << myTrack.onHcal() << std::endl
601  << " onVFcal = " << myTrack.onVFcal() << std::endl
602  << " position = " << caloentrance << std::endl;
603 
604 
605  DetId pivot;
606  if(myTrack.onEcal())
607  {
608  pivot=myCalorimeter_->getClosestCell(caloentrance,
609  true, myTrack.onEcal()==1);
610  }
611  else if(myTrack.onHcal())
612  {
613  pivot=myCalorimeter_->getClosestCell(caloentrance,
614  false, false);
615  }
616 
617  EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
618  pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,1,
619  random);
620  // 1=HAD shower
621 
622  myGrid.setTrackParameters(direction,0,myTrack);
623  // Build the FAMOS HCAL
624  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)1);
625 
626  // Shower simulation
627  bool status = false;
628  int mip = 2;
629  // Use HFShower for HF
630  if ( !myTrack.onEcal() && !myTrack.onHcal() ) {
631  // Warning : We give here the particle energy with the response
632  // but without the resolution/gaussian smearing
633  // For HF, the resolution is due to the PE statistic
634 
635  if(useShowerLibrary) {
637  status = true;
638  } else {
639  HFShower theShower(random,
640  &theHDShowerparam,
641  &myGrid,
642  &myHcalHitMaker,
643  onECAL,
644  eGen);
645  // eGen);
646  // e); // PV Warning : temporarly set the energy to the generated E
647 
648  status = theShower.compute();
649  }
650  } else {
651  if(hdSimMethod_ == 0) {
652  HDShower theShower(random,
653  &theHDShowerparam,
654  &myGrid,
655  &myHcalHitMaker,
656  onECAL,
657  eGen,
658  pmip);
659  status = theShower.compute();
660  mip = theShower.getmip();
661  }
662  else if (hdSimMethod_ == 1) {
663  HDRShower theShower(random,
664  &theHDShowerparam,
665  &myGrid,
666  &myHcalHitMaker,
667  onECAL,
668  eGen);
669  status = theShower.computeShower();
670  mip = 2;
671  }
672  else if (hdSimMethod_ == 2 ) {
673  //dynamically loading a corresponding profile by the particle type
674  int particleType = myTrack.type();
676  if(particleType == -2212) theProfile = theAntiProtonProfile;
677  else if(particleType == 2212) theProfile = theProtonProfile;
678 
679  //input variables for GflashHadronShowerProfile
680  int showerType = 99 + myTrack.onEcal();
681  double globalTime = 150.0; // a temporary reference hit time in nanosecond
682  float charge = (float)(myTrack.charge());
683  Gflash3Vector gfpos(trackPosition.X(),trackPosition.Y(),trackPosition.Z());
684  Gflash3Vector gfmom(moment.X(),moment.Y(),moment.Z());
685 
686  theProfile->initialize(showerType,eGen,globalTime,charge,gfpos,gfmom);
689 
690  //make hits
691  std::vector<GflashHit>& gflashHitList = theProfile->getGflashHitList();
692  std::vector<GflashHit>::const_iterator spotIter = gflashHitList.begin();
693  std::vector<GflashHit>::const_iterator spotIterEnd = gflashHitList.end();
694 
696 
697  for( ; spotIter != spotIterEnd; spotIter++){
698 
699  double pathLength = theProfile->getGflashShowino()->getPathLengthAtShower()
700  + (30*100/eGen)*(spotIter->getTime() - globalTime);
701 
702  double currentDepth = std::max(0.0,pathLength - theProfile->getGflashShowino()->getPathLengthOnEcal());
703 
704  //find the the showino position at the currentDepth
705  GflashTrajectoryPoint trajectoryPoint;
706  theProfile->getGflashShowino()->getHelix()->getGflashTrajectoryPoint(trajectoryPoint,pathLength);
707  Gflash3Vector positionAtCurrentDepth = trajectoryPoint.getPosition();
708  //find radial distrance
709  Gflash3Vector lateralDisplacement = positionAtCurrentDepth - spotIter->getPosition()/CLHEP::cm;
710  double rShower = lateralDisplacement.r();
711  double azimuthalAngle = lateralDisplacement.phi();
712 
713  whichCalor = Gflash::getCalorimeterNumber(positionAtCurrentDepth);
714 
715  if(whichCalor==Gflash::kESPM || whichCalor==Gflash::kENCA) {
716  bool statusPad = myGrid.getPads(currentDepth,true);
717  if(!statusPad) continue;
718  myGrid.setSpotEnergy(1.2*spotIter->getEnergy()/CLHEP::GeV);
719  myGrid.addHit(rShower/Gflash::intLength[Gflash::kESPM],azimuthalAngle,0);
720  }
721  else if(whichCalor==Gflash::kHB || whichCalor==Gflash::kHE) {
722  bool setHDdepth = myHcalHitMaker.setDepth(currentDepth,true);
723  if(!setHDdepth) continue;
724  myHcalHitMaker.setSpotEnergy(1.4*spotIter->getEnergy()/CLHEP::GeV);
725  myHcalHitMaker.addHit(rShower/Gflash::intLength[Gflash::kHB],azimuthalAngle,0);
726  }
727  }
728  status = true;
729  }
730  else {
731  edm::LogInfo("FastSimulationCalorimetry") << " SimMethod " << hdSimMethod_ <<" is NOT available ";
732  }
733  }
734 
735 
736  if(status) {
737 
738  // Here to switch between simple formulae and parameterized response
739  if(optionHDSim_ == 1) {
740  emeas = myHDResponse_->getHCALEnergyResponse(eGen, hit, random);
741  }
742  else { // optionHDsim == 2
743  emeas = myHDResponse_->responseHCAL(mip, eGen, pathEta, 1, random); // 1=hadron
744  }
745 
746  double correction = emeas / eGen;
747 
748  // RespCorrP factors (ECAL and HCAL separately) calculation
749  respCorr(eint);
750 
751  if(debug_)
752  LogInfo("FastCalorimetry")
753  << "CalorimetryManager::HDShowerSimulation - on-calo 2" << std::endl
754  << " eta = " << pathEta << std::endl
755  << " phi = " << pathPhi << std::endl
756  << " Egen = " << eGen << std::endl
757  << " Emeas = " << emeas << std::endl
758  << " corr = " << correction << std::endl
759  << " mip = " << mip << std::endl;
760 
761  if(myTrack.onEcal() > 0) {
762  // Save ECAL hits
763  updateECAL(myGrid.getHits(),onECAL,myTrack.id(),correction*ecorr);
764  }
765 
766  // Save HCAL hits
767  if(myTrack.onVFcal() && useShowerLibrary) {
768  myHDResponse_->correctHF(eGen,abs(myTrack.type()));
770  }
771  else
772  updateHCAL(myHcalHitMaker.getHits(),myTrack.id(),correction*hcorr);
773 
774  }
775  else { // shower simulation failed
776  if(myTrack.onHcal() || myTrack.onVFcal())
777  {
778  DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
779  double tof = (((HcalGeometry*)(myCalorimeter_->getHcalGeometry()))->getPosition(cell).mag())/29.98;//speed of light
780  CaloHitID current_id(cell.rawId(),tof,myTrack.id());
781  std::map<CaloHitID,float> hitMap;
782  hitMap[current_id] = emeas;
783  updateHCAL(hitMap,myTrack.id());
784  if(debug_)
785  LogInfo("FastCalorimetry") << " HCAL simple cell "
786  << cell.rawId() << " added E = "
787  << emeas << std::endl;
788  }
789  }
790 
791  } // e > 0. ...
792 
793  if(debug_)
794  LogInfo("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::HDShowerSimulation finished "
795  << std::endl;
796 }
797 
798 
800 {
801  // TimeMe t(" FASTEnergyReconstructor::HDShower");
802  XYZTLorentzVector moment = myTrack.momentum();
803 
804  // Backward compatibility behaviour
805  if(!theMuonHcalEffects)
806  {
807  savedMuonSimTracks.push_back(myTrack);
808 
809  if(myTrack.onHcal() || myTrack.onVFcal() )
810  reconstructHCAL(myTrack, random);
811 
812  return;
813  }
814 
815 
816  if(debug_)
817  LogInfo("FastCalorimetry") << "CalorimetryManager::MuonMipSimulation - track param."
818  << std::endl
819  << " eta = " << moment.eta() << std::endl
820  << " phi = " << moment.phi() << std::endl
821  << " et = " << moment.Et() << std::endl;
822 
823  XYZTLorentzVector trackPosition;
824  if ( myTrack.onEcal() ) {
825  trackPosition=myTrack.ecalEntrance().vertex();
826  myPart = myTrack.ecalEntrance();
827  } else if ( myTrack.onVFcal()) {
828  trackPosition=myTrack.vfcalEntrance().vertex();
829  myPart = myTrack.vfcalEntrance();
830  }
831  else
832  {
833  LogInfo("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
834  return;
835  }
836 
837  // int onHCAL = hit + 1; - specially for myCalorimeter->hcalProperties(onHCAL)
838  // (below) to get VFcal properties ...
839  // not needed ?
840  // int onHCAL = hit + 1;
841  int onECAL = myTrack.onEcal();
842 
843  //===========================================================================
844 
845  // ECAL and HCAL properties to get
846 
847  //Making ECAL Grid (and segments calculation)
848  XYZPoint caloentrance;
849  XYZVector direction;
850  if(myTrack.onEcal())
851  {
852  caloentrance = myTrack.ecalEntrance().vertex().Vect();
853  direction = myTrack.ecalEntrance().Vect().Unit();
854  }
855  else if(myTrack.onHcal())
856  {
857  caloentrance = myTrack.hcalEntrance().vertex().Vect();
858  direction = myTrack.hcalEntrance().Vect().Unit();
859  }
860  else
861  {
862  caloentrance = myTrack.vfcalEntrance().vertex().Vect();
863  direction = myTrack.vfcalEntrance().Vect().Unit();
864  }
865 
866  DetId pivot;
867  if(myTrack.onEcal())
868  {
869  pivot=myCalorimeter_->getClosestCell(caloentrance,
870  true, myTrack.onEcal()==1);
871  }
872  else if(myTrack.onHcal())
873  {
874  pivot=myCalorimeter_->getClosestCell(caloentrance,
875  false, false);
876  }
877 
878  EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
879  pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,0,
880  random);
881  // 0 =EM shower -> Unit = X0
882 
883  myGrid.setTrackParameters(direction,0,myTrack);
884 
885  // Now get the path in the Preshower, ECAL and HCAL along a straight line extrapolation
886  // but only those in the ECAL are used
887 
888  const std::vector<CaloSegment>& segments=myGrid.getSegments();
889  unsigned nsegments=segments.size();
890 
891  int ifirstHcal=-1;
892  int ilastEcal=-1;
893 
894  EnergyLossSimulator* energyLossECAL = (theMuonEcalEffects) ?
896  // // Muon brem in ECAL
897  // MuonBremsstrahlungSimulator* muonBremECAL = 0;
898  // if (theMuonEcalEffects) muonBremECAL = theMuonEcalEffects->muonBremsstrahlungSimulator();
899 
900  for(unsigned iseg=0;iseg<nsegments&&ifirstHcal<0;++iseg)
901  {
902 
903  // in the ECAL, there are two types of segments: PbWO4 and GAP
904  float segmentSizeinX0=segments[iseg].X0length();
905 
906  // Martijn - insert your computations here
907  float energy=0.0;
908  if (segmentSizeinX0>0.001 && segments[iseg].material()==CaloSegment::PbWO4 ) {
909  // The energy loss simulator
910  float charge = (float)(myTrack.charge());
911  ParticlePropagator theMuon(moment,trackPosition,charge,nullptr);
912  theMuon.setID(-(int)charge*13);
913  if ( energyLossECAL ) {
914  energyLossECAL->updateState(theMuon, segmentSizeinX0, random);
915  energy = energyLossECAL->deltaMom().E();
916  moment -= energyLossECAL->deltaMom();
917  }
918  }
919  // that's all for ECAL, Florian
920  // Save the hit only if it is a crystal
921  if(segments[iseg].material()==CaloSegment::PbWO4)
922  {
923  myGrid.getPads(segments[iseg].sX0Entrance()+segmentSizeinX0*0.5);
924  myGrid.setSpotEnergy(energy);
925  myGrid.addHit(0.,0.);
926  ilastEcal=iseg;
927  }
928  // Check for end of loop:
929  if(segments[iseg].material()==CaloSegment::HCAL)
930  {
931  ifirstHcal=iseg;
932  }
933  }
934 
935 
936  // Build the FAMOS HCAL
937  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)2);
938  // float mipenergy=0.1;
939  // Create the helix with the stepping helix propagator
940  // to add a hit, just do
941  // myHcalHitMaker.setSpotEnergy(mipenergy);
942  // math::XYZVector hcalEntrance;
943  // if(ifirstHcal>=0) hcalEntrance=segments[ifirstHcal].entrance();
944  // myHcalHitMaker.addHit(hcalEntrance);
948  int ilastHcal=-1;
949  float mipenergy=0.0;
950 
951  EnergyLossSimulator* energyLossHCAL = (theMuonHcalEffects) ?
953  // // Muon Brem effect
954  // MuonBremsstrahlungSimulator* muonBremHCAL = 0;
955  // if (theMuonHcalEffects) muonBremHCAL = theMuonHcalEffects->muonBremsstrahlungSimulator();
956 
957  if(ifirstHcal>0 && energyLossHCAL){
958  for(unsigned iseg=ifirstHcal;iseg<nsegments;++iseg)
959  {
960  float segmentSizeinX0=segments[iseg].X0length();
961  if(segments[iseg].material()==CaloSegment::HCAL) {
962  ilastHcal=iseg;
963  if (segmentSizeinX0>0.001) {
964  // The energy loss simulator
965  float charge = (float)(myTrack.charge());
966  ParticlePropagator theMuon(moment,trackPosition,charge,nullptr);
967  theMuon.setID(-(int)charge*13);
968  energyLossHCAL->updateState(theMuon, segmentSizeinX0, random);
969  mipenergy = energyLossHCAL->deltaMom().E();
970  moment -= energyLossHCAL->deltaMom();
971  myHcalHitMaker.setSpotEnergy(mipenergy);
972  myHcalHitMaker.addHit(segments[iseg].entrance());
973  }
974  }
975  }
976  }
977 
978  // Copy the muon SimTrack (Only for Energy loss)
979  FSimTrack muonTrack(myTrack);
980  if(energyLossHCAL && ilastHcal>=0) {
981  math::XYZVector hcalExit=segments[ilastHcal].exit();
982  muonTrack.setTkPosition(hcalExit);
983  muonTrack.setTkMomentum(moment);
984  } else if(energyLossECAL && ilastEcal>=0) {
985  math::XYZVector ecalExit=segments[ilastEcal].exit();
986  muonTrack.setTkPosition(ecalExit);
987  muonTrack.setTkMomentum(moment);
988  } // else just leave tracker surface position and momentum...
989 
990  muonSimTracks.push_back(muonTrack);
991 
992  // no need to change below this line
993  std::map<CaloHitID,float>::const_iterator mapitr;
994  std::map<CaloHitID,float>::const_iterator endmapitr;
995  if(myTrack.onEcal() > 0) {
996  // Save ECAL hits
997  updateECAL(myGrid.getHits(),onECAL,myTrack.id());
998  }
999 
1000  // Save HCAL hits
1001  updateHCAL(myHcalHitMaker.getHits(),myTrack.id());
1002 
1003  if(debug_)
1004  LogInfo("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::MipShowerSimulation finished "
1005  << std::endl;
1006 }
1007 
1008 
1010 
1011  edm::ParameterSet ECALparameters = fastCalo.getParameter<edm::ParameterSet>("ECAL");
1012 
1013  evtsToDebug_ = fastCalo.getUntrackedParameter<std::vector<unsigned int> >("EvtsToDebug",std::vector<unsigned>());
1014  debug_ = fastCalo.getUntrackedParameter<bool>("Debug");
1015 
1016  bFixedLength_ = ECALparameters.getParameter<bool>("bFixedLength");
1017 
1018  gridSize_ = ECALparameters.getParameter<int>("GridSize");
1019  spotFraction_ = ECALparameters.getParameter<double>("SpotFraction");
1020  pulledPadSurvivalProbability_ = ECALparameters.getParameter<double>("FrontLeakageProbability");
1021  crackPadSurvivalProbability_ = ECALparameters.getParameter<double>("GapLossProbability");
1022  theCoreIntervals_ = ECALparameters.getParameter<std::vector<double> >("CoreIntervals");
1023  theTailIntervals_ = ECALparameters.getParameter<std::vector<double> >("TailIntervals");
1024 
1025  RCFactor_ = ECALparameters.getParameter<double>("RCFactor");
1026  RTFactor_ = ECALparameters.getParameter<double>("RTFactor");
1027  //changed after tuning - Feb-July - Shilpi Jain
1028  // radiusFactor_ = ECALparameters.getParameter<double>("RadiusFactor");
1029  radiusFactorEE_ = ECALparameters.getParameter<double>("RadiusFactorEE");
1030  radiusFactorEB_ = ECALparameters.getParameter<double>("RadiusFactorEB");
1031  //(end of) changed after tuning - Feb-July - Shilpi Jain
1032  radiusPreshowerCorrections_ = ECALparameters.getParameter<std::vector<double> >("RadiusPreshowerCorrections");
1033  aTerm = 1.+radiusPreshowerCorrections_[1]*radiusPreshowerCorrections_[0];
1034  bTerm = radiusPreshowerCorrections_[0];
1035  mipValues_ = ECALparameters.getParameter<std::vector<double> >("MipsinGeV");
1036  simulatePreshower_ = ECALparameters.getParameter<bool>("SimulatePreshower");
1037 
1038  if(gridSize_ <1) gridSize_= 7;
1039  if(pulledPadSurvivalProbability_ <0. || pulledPadSurvivalProbability_>1 ) pulledPadSurvivalProbability_= 1.;
1040  if(crackPadSurvivalProbability_ <0. || crackPadSurvivalProbability_>1 ) crackPadSurvivalProbability_= 0.9;
1041 
1042  LogInfo("FastCalorimetry") << " Fast ECAL simulation parameters " << std::endl;
1043  LogInfo("FastCalorimetry") << " =============================== " << std::endl;
1044  if(simulatePreshower_)
1045  LogInfo("FastCalorimetry") << " The preshower is present " << std::endl;
1046  else
1047  LogInfo("FastCalorimetry") << " The preshower is NOT present " << std::endl;
1048  LogInfo("FastCalorimetry") << " Grid Size : " << gridSize_ << std::endl;
1049  if(spotFraction_>0.)
1050  LogInfo("FastCalorimetry") << " Spot Fraction : " << spotFraction_ << std::endl;
1051  else
1052  {
1053  LogInfo("FastCalorimetry") << " Core of the shower " << std::endl;
1054  for(unsigned ir=0; ir < theCoreIntervals_.size()/2;++ir)
1055  {
1056  LogInfo("FastCalorimetry") << " r < " << theCoreIntervals_[ir*2] << " R_M : " << theCoreIntervals_[ir*2+1] << " ";
1057  }
1058  LogInfo("FastCalorimetry") << std::endl;
1059 
1060  LogInfo("FastCalorimetry") << " Tail of the shower " << std::endl;
1061  for(unsigned ir=0; ir < theTailIntervals_.size()/2;++ir)
1062  {
1063  LogInfo("FastCalorimetry") << " r < " << theTailIntervals_[ir*2] << " R_M : " << theTailIntervals_[ir*2+1] << " ";
1064  }
1065  //changed after tuning - Feb-July - Shilpi Jain
1066  LogInfo("FastCalorimetry") << "Radius correction factors: EB & EE " << radiusFactorEB_ << " : "<< radiusFactorEE_ << std::endl;
1067  //(end of) changed after tuning - Feb-July - Shilpi Jain
1068  LogInfo("FastCalorimetry") << std::endl;
1069  if(mipValues_.size()>2) {
1070  LogInfo("FastCalorimetry") << "Improper number of parameters for the preshower ; using 95keV" << std::endl;
1071  mipValues_.clear();
1072  mipValues_.resize(2,0.000095);
1073  }
1074  }
1075 
1076  LogInfo("FastCalorimetry") << " FrontLeakageProbability : " << pulledPadSurvivalProbability_ << std::endl;
1077  LogInfo("FastCalorimetry") << " GapLossProbability : " << crackPadSurvivalProbability_ << std::endl;
1078 
1079 
1080  // RespCorrP: p (momentum), ECAL and HCAL corrections = f(p)
1081  edm::ParameterSet CalorimeterParam = fastCalo.getParameter<edm::ParameterSet>("CalorimeterProperties");
1082 
1083  rsp = CalorimeterParam.getParameter<std::vector<double> >("RespCorrP");
1084  LogInfo("FastCalorimetry") << " RespCorrP (rsp) size " << rsp.size() << std::endl;
1085 
1086  if( rsp.size()%3 !=0 ) {
1087  LogInfo("FastCalorimetry")
1088  << " RespCorrP size is wrong -> no corrections applied !!!"
1089  << std::endl;
1090 
1091  p_knots.push_back(14000.);
1092  k_e.push_back (1.);
1093  k_h.push_back (1.);
1094  }
1095  else {
1096  for(unsigned i = 0; i < rsp.size(); i += 3) {
1097  LogInfo("FastCalorimetry") << "i = " << i/3 << " p = " << rsp [i]
1098  << " k_e(p) = " << rsp[i+1]
1099  << " k_e(p) = " << rsp[i+2] << std::endl;
1100 
1101  p_knots.push_back(rsp[i]);
1102  k_e.push_back (rsp[i+1]);
1103  k_h.push_back (rsp[i+2]);
1104  }
1105  }
1106 
1107 
1108  //FR
1109  edm::ParameterSet HCALparameters = fastCalo.getParameter<edm::ParameterSet>("HCAL");
1110  optionHDSim_ = HCALparameters.getParameter<int>("SimOption");
1111  hdGridSize_ = HCALparameters.getParameter<int>("GridSize");
1112  hdSimMethod_ = HCALparameters.getParameter<int>("SimMethod");
1113  //RF
1114 
1115  EcalDigitizer_ = ECALparameters.getUntrackedParameter<bool>("Digitizer",false);
1116  HcalDigitizer_ = HCALparameters.getUntrackedParameter<bool>("Digitizer",false);
1117  samplingHBHE_ = HCALparameters.getParameter< std::vector<double> >("samplingHBHE");
1118  samplingHF_ = HCALparameters.getParameter< std::vector<double> >("samplingHF");
1119  samplingHO_ = HCALparameters.getParameter< std::vector<double> >("samplingHO");
1120  ietaShiftHB_ = HCALparameters.getParameter< int >("ietaShiftHB");
1121  ietaShiftHE_ = HCALparameters.getParameter< int >("ietaShiftHE");
1122  ietaShiftHF_ = HCALparameters.getParameter< int >("ietaShiftHF");
1123  ietaShiftHO_ = HCALparameters.getParameter< int >("ietaShiftHO");
1124  timeShiftHB_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHB");
1125  timeShiftHE_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHE");
1126  timeShiftHF_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHF");
1127  timeShiftHO_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHO");
1128 
1129  // FastHFShowerLibrary
1130  edm::ParameterSet m_HS = fastCalo.getParameter<edm::ParameterSet>("HFShowerLibrary");
1131  useShowerLibrary = m_HS.getUntrackedParameter<bool>("useShowerLibrary",false);
1132  useCorrectionSL = m_HS.getUntrackedParameter<bool>("useCorrectionSL",false);
1133 }
1134 
1136 
1137  int sizeP = p_knots.size();
1138 
1139  if(sizeP <= 1) {
1140  ecorr = 1.;
1141  hcorr = 1.;
1142  }
1143  else {
1144  int ip = -1;
1145  for (int i = 0; i < sizeP; i++) {
1146  if (p < p_knots[i]) { ip = i; break;}
1147  }
1148  if (ip == 0) {
1149  ecorr = k_e[0];
1150  hcorr = k_h[0];
1151  }
1152  else {
1153  if(ip == -1) {
1154  ecorr = k_e[sizeP-1];
1155  hcorr = k_h[sizeP-1];
1156  }
1157  else {
1158  double x1 = p_knots[ip-1];
1159  double x2 = p_knots[ip];
1160  double y1 = k_e[ip-1];
1161  double y2 = k_e[ip];
1162 
1163  ecorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
1164 
1165  y1 = k_h[ip-1];
1166  y2 = k_h[ip];
1167  hcorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
1168 
1169  }
1170  }
1171  }
1172 
1173  if(debug_)
1174  LogInfo("FastCalorimetry") << " p, ecorr, hcorr = " << p << " "
1175  << ecorr << " " << hcorr << std::endl;
1176 
1177 }
1178 
1179 void CalorimetryManager::updateECAL(const std::map<CaloHitID,float>& hitMap, int onEcal, int trackID, float corr)
1180 {
1181  std::map<CaloHitID,float>::const_iterator mapitr;
1182  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1183  if(onEcal==1) {
1184  EBMapping_.reserve(EBMapping_.size()+hitMap.size());
1185  endmapitr=hitMap.end();
1186  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1187  //correct energy
1188  float energy = mapitr->second;
1189  energy *= corr;
1190 
1191  //make finalized CaloHitID
1192  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1193 
1194  EBMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1195  }
1196  }
1197  else if(onEcal==2) {
1198  EEMapping_.reserve(EEMapping_.size()+hitMap.size());
1199  endmapitr=hitMap.end();
1200  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1201  //correct energy
1202  float energy = mapitr->second;
1203  energy *= corr;
1204 
1205  //make finalized CaloHitID
1206  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1207 
1208  EEMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1209  }
1210  }
1211 
1212 }
1213 
1214 void CalorimetryManager::updateHCAL(const std::map<CaloHitID,float>& hitMap, int trackID, float corr)
1215 {
1216  std::vector<double> hfcorrEm = myHDResponse_->getCorrHFem();
1217  std::vector<double> hfcorrHad = myHDResponse_->getCorrHFhad();
1218  std::map<CaloHitID,float>::const_iterator mapitr;
1219  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1220  HMapping_.reserve(HMapping_.size()+hitMap.size());
1221  for(mapitr=hitMap.begin(); mapitr!=endmapitr; ++mapitr) {
1222  //correct energy
1223  float energy = mapitr->second;
1224  energy *= corr;
1225 
1226  float time = mapitr->first.timeSlice();
1227  //put energy into uncalibrated state for digitizer && correct timing
1228  if(HcalDigitizer_){
1229  HcalDetId hdetid = HcalDetId(mapitr->first.unitID());
1230  if (hdetid.subdetId()== HcalBarrel){
1231  energy /= samplingHBHE_[hdetid.ietaAbs()-1]; //re-convert to GeV
1232  time = timeShiftHB_[hdetid.ietaAbs()-ietaShiftHB_];
1233  }
1234  else if (hdetid.subdetId()== HcalEndcap){
1235  energy /= samplingHBHE_[hdetid.ietaAbs()-1]; //re-convert to GeV
1236  time = timeShiftHE_[hdetid.ietaAbs()-ietaShiftHE_];
1237  }
1238  else if (hdetid.subdetId()== HcalForward){
1239  if(useShowerLibrary) {
1240  if(useCorrectionSL) {
1241  if(hdetid.depth()== 1 or hdetid.depth()==3) energy *= hfcorrEm[hdetid.ietaAbs()-ietaShiftHF_];
1242  if(hdetid.depth()== 2 or hdetid.depth()==4) energy *= hfcorrHad[hdetid.ietaAbs()-ietaShiftHF_];
1243  }
1244  } else {
1245  if(hdetid.depth()== 1 or hdetid.depth()==3) energy *= samplingHF_[0];
1246  if(hdetid.depth()== 2 or hdetid.depth()==4) energy *= samplingHF_[1];
1247  time = timeShiftHF_[hdetid.ietaAbs()-ietaShiftHF_];
1248  }
1249  }
1250  else if (hdetid.subdetId()== HcalOuter){
1251  energy /= samplingHO_[hdetid.ietaAbs()-1];
1252  time = timeShiftHO_[hdetid.ietaAbs()-ietaShiftHO_];
1253  }
1254  }
1255 
1256  //make finalized CaloHitID
1257  CaloHitID current_id(mapitr->first.unitID(),time,trackID);
1258  HMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1259  }
1260 }
1261 
1262 void CalorimetryManager::updatePreshower(const std::map<CaloHitID,float>& hitMap, int trackID, float corr)
1263 {
1264  std::map<CaloHitID,float>::const_iterator mapitr;
1265  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1266  ESMapping_.reserve(ESMapping_.size()+hitMap.size());
1267  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1268  //correct energy
1269  float energy = mapitr->second;
1270  energy *= corr;
1271 
1272  //make finalized CaloHitID
1273  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1274 
1275  ESMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1276  }
1277 }
1278 
1280 {
1281  c.reserve(c.size()+EBMapping_.size());
1282  for(unsigned i=0; i<EBMapping_.size(); i++) {
1283  c.push_back(PCaloHit(EBDetId::unhashIndex(EBMapping_[i].first.unitID()),EBMapping_[i].second,EBMapping_[i].first.timeSlice(),EBMapping_[i].first.trackID()));
1284  }
1285 }
1286 
1288 {
1289  c.reserve(c.size()+EEMapping_.size());
1290  for(unsigned i=0; i<EEMapping_.size(); i++) {
1291  c.push_back(PCaloHit(EEDetId::unhashIndex(EEMapping_[i].first.unitID()),EEMapping_[i].second,EEMapping_[i].first.timeSlice(),EEMapping_[i].first.trackID()));
1292  }
1293 }
1294 
1296 {
1297  c.reserve(c.size()+HMapping_.size());
1298  for(unsigned i=0; i<HMapping_.size(); i++) {
1299  c.push_back(PCaloHit(DetId(HMapping_[i].first.unitID()),HMapping_[i].second,HMapping_[i].first.timeSlice(),HMapping_[i].first.trackID()));
1300  }
1301 }
1302 
1303 
1305 {
1306  c.reserve(c.size()+ESMapping_.size());
1307  for(unsigned i=0; i<ESMapping_.size(); i++) {
1308  c.push_back(PCaloHit(ESMapping_[i].first.unitID(),ESMapping_[i].second,ESMapping_[i].first.timeSlice(),ESMapping_[i].first.trackID()));
1309  }
1310 }
1311 
1312 // The main danger in this method is to screw up to relationships between particles
1313 // So, the muon FSimTracks created by FSimEvent.cc are simply to be updated
1315 {
1316  unsigned size=muons.size();
1317  for(unsigned i=0; i<size;++i)
1318  {
1319  int id = muons[i].trackId();
1320  if (!(abs(muons[i].type()) == 13 || abs(muons[i].type()) == 1000024 ||
1321  (abs(muons[i].type()) > 1000100 && abs(muons[i].type()) < 1999999)))
1322  continue;
1323  // identify the corresponding muon in the local collection
1324 
1325  std::vector<FSimTrack>::const_iterator itcheck=find_if(muonSimTracks.begin(),muonSimTracks.end(),FSimTrackEqual(id));
1326  if(itcheck!=muonSimTracks.end())
1327  {
1328  muons[i].setTkPosition(itcheck->trackerSurfacePosition());
1329  muons[i].setTkMomentum(itcheck->trackerSurfaceMomentum());
1330  }
1331  }
1332 
1333 }
1334 
1335 
1337 {
1338  c.reserve(int(0.2*muonSimTracks.size()+0.2*savedMuonSimTracks.size()+0.5));
1339  for(const auto & track : muonSimTracks){
1340  if(track.momentum().perp2() > 1.0 && fabs(track.momentum().eta()) < 3.0 && track.isGlobal()) c.push_back(track);
1341  }
1342  for(const auto & track : savedMuonSimTracks){
1343  if(track.momentum().perp2() > 1.0 && fabs(track.momentum().eta()) < 3.0 && track.isGlobal()) c.push_back(track);
1344  }
1345  c.shrink_to_fit();
1346 }
1347 
size
Write out results.
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
std::vector< double > rsp
std::vector< double > k_h
bool noEndVertex() const
no end vertex
RawParticle myElec
A few pointers to save time.
std::vector< std::pair< CaloHitID, float > > ESMapping_
float charge() const
charge
Definition: FSimTrack.h:51
void reconstructHCAL(const FSimTrack &myTrack, RandomEngineAndDistribution const *)
std::vector< PCaloHit > PCaloHitContainer
const double GeV
Definition: MathUtil.h:16
const ECALProperties * ecalProperties(int onEcal) const
ECAL properties.
Definition: Calorimeter.cc:76
double responseHCAL(int _mip, double energy, double eta, int partype, RandomEngineAndDistribution const *)
const RawParticle & vfcalEntrance() const
The particle at VFCAL entrance.
Definition: FSimTrack.h:144
void updateHCAL(const std::map< CaloHitID, float > &hitMap, int trackID=0, float corr=1.0)
int onLayer2() const
Definition: FSimTrack.h:101
GflashPiKShowerProfile * thePiKProfile
double flatShoot(double xmin=0.0, double xmax=1.0) const
std::vector< double > timeShiftHO_
void updatePreshower(const std::map< CaloHitID, float > &hitMap, int trackID=0, float corr=1.0)
GflashTrajectory * getHelix()
Definition: GflashShowino.h:30
MaterialEffects * theMuonEcalEffects
MaterialEffects * theMuonHcalEffects
void recoHFShowerLibrary(const FSimTrack &myTrack)
const XYZTLorentzVector & momentum() const
Temporary (until move of SimTrack to Mathcore) - No! Actually very useful.
Definition: FSimTrack.h:204
void setCrackPadSurvivalProbability(double val)
Definition: EcalHitMaker.h:134
double getHCALEnergyResponse(double e, int hit, RandomEngineAndDistribution const *)
GflashHadronShowerProfile * theProfile
const RawParticle & layer1Entrance() const
The particle at Preshower Layer 1.
Definition: FSimTrack.h:132
bool compute()
Compute the shower longitudinal and lateral development.
Definition: HDShower.cc:447
bool exists(std::string const &parameterName) const
checks if a parameter exists
void correctHF(double e, int type)
void reconstructTrack(FSimTrack &myTrack, RandomEngineAndDistribution const *)
void setPreshower(PreshowerHitMaker *const myPresh)
set the preshower address
Definition: EMShower.cc:704
void loadFromPreshower(edm::PCaloHitContainer &c) const
Definition: weight.py:1
void updateState(ParticlePropagator &myTrack, double radlen, RandomEngineAndDistribution const *)
Compute the material effect (calls the sub class)
void updateECAL(const std::map< CaloHitID, float > &hitMap, int onEcal, int trackID=0, float corr=1.0)
const std::map< CaloHitID, float > & getHits() override
const CaloSubdetectorGeometry * getHcalGeometry() const
Definition: Calorimeter.h:57
void MuonMipSimulation(const FSimTrack &myTrack, RandomEngineAndDistribution const *)
void readParameters(const edm::ParameterSet &fastCalo)
TRandom random
Definition: MVATrainer.cc:138
const PreshowerLayer1Properties * layer1Properties(int onLayer1) const
Preshower Layer1 properties.
Definition: Calorimeter.cc:103
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
#define nullptr
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
static double constexpr eMass
Electron mass[GeV].
Definition: Constants.h:17
std::vector< double > timeShiftHF_
std::vector< double > p_knots
void compute()
Compute the shower longitudinal and lateral development.
Definition: EMShower.cc:273
std::vector< std::pair< CaloHitID, float > > EBMapping_
int onEcal() const
Definition: FSimTrack.h:106
std::vector< FSimTrack > muonSimTracks
double radLenIncm() const override
Radiation length in cm.
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
void HDShowerSimulation(const FSimTrack &myTrack, RandomEngineAndDistribution const *)
Hadronic Shower Simulation.
const LandauFluctuationGenerator * aLandauGenerator
std::vector< double > samplingHF_
bool compute()
Compute the shower longitudinal and lateral development.
Definition: HFShower.cc:475
void setRadiusFactor(double r)
Definition: EcalHitMaker.h:130
bool addHit(double r, double phi, unsigned layer=0) override
add the hit in the HCAL in local coordinates
Definition: HcalHitMaker.cc:28
int depth() const
get the tower depth
Definition: HcalDetId.cc:129
void reconstruct(RandomEngineAndDistribution const *)
CalorimeterNumber getCalorimeterNumber(const Gflash3Vector &position)
GflashAntiProtonShowerProfile * theAntiProtonProfile
math::XYZVector XYZVector
int getmip()
Definition: HDShower.h:42
GflashProtonShowerProfile * theProtonProfile
const PreshowerLayer2Properties * layer2Properties(int onLayer2) const
Preshower Layer2 properties.
Definition: Calorimeter.cc:111
double getPathLengthAtShower()
Definition: GflashShowino.h:26
const std::map< CaloHitID, float > & getHits() override
not been done.
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< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void setTrackParameters(const XYZNormal &normal, double X0depthoffset, const FSimTrack &theTrack)
void loadFromEcalEndcap(edm::PCaloHitContainer &c) const
void setID(const int id)
Definition: RawParticle.cc:102
const XYZTLorentzVector & deltaMom() const
Returns the actual energy lost.
std::vector< double > radiusPreshowerCorrections_
const HCALProperties * hcalProperties(int onHcal) const
HCAL properties.
Definition: Calorimeter.cc:87
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double getMIPfraction(double energy, double eta)
vec1 & getCorrHFhad()
Definition: HCALResponse.h:49
const RawParticle & ecalEntrance() const
The particle at ECAL entrance.
Definition: FSimTrack.h:138
int onVFcal() const
Definition: FSimTrack.h:116
void setSpotEnergy(double e) override
Set the spot energy.
Definition: HcalHitMaker.h:28
std::vector< double > theTailIntervals_
std::vector< double > samplingHBHE_
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
void loadMuonSimTracks(edm::SimTrackContainer &m) const
unsigned int nTracks() const
Number of tracks.
Definition: FSimEvent.cc:36
JetCorrectorParameters corr
Definition: classes.h:5
HCALResponse * myHDResponse_
vec1 & getCorrHFem()
Definition: HCALResponse.h:48
CaloGeometryHelper * myCalorimeter_
std::vector< double > timeShiftHB_
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.cc:119
void initialize(RandomEngineAndDistribution const *random)
const double intLength[kNumberCalorimeter]
std::vector< double > theCoreIntervals_
void getGflashTrajectoryPoint(GflashTrajectoryPoint &point, double s) const
edm::EventID id() const
Method to return the EventId.
Definition: FSimEvent.cc:27
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:285
Definition: DetId.h:18
void loadFromHcal(edm::PCaloHitContainer &c) const
GammaFunctionGenerator * aGammaGenerator
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
CLHEP::Hep3Vector Gflash3Vector
Definition: Gflash3Vector.h:6
std::vector< double > mipValues_
static std::vector< std::pair< int, float > > myZero_
std::vector< FSimTrack > savedMuonSimTracks
bool null() const
is this a null id ?
Definition: DetId.h:45
std::vector< std::pair< CaloHitID, float > > EEMapping_
void setTkPosition(const math::XYZVectorD &pos)
Definition: SimTrack.h:40
double getPathLengthOnEcal()
Definition: GflashShowino.h:25
void SetRandom(const RandomEngineAndDistribution *)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
math::XYZVector XYZPoint
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:25
HLT enums.
void harvestMuonSimTracks(edm::SimTrackContainer &m) const
std::vector< unsigned int > evtsToDebug_
int id() const
the index in FBaseSimEvent and other vectors
Definition: FSimTrack.h:91
bool preshowerPresent() const
const std::map< CaloHitID, float > & getHitsMap()
void setPulledPadSurvivalProbability(double val)
Definition: EcalHitMaker.h:132
const RawParticle & layer2Entrance() const
The particle at Preshower Layer 2.
Definition: FSimTrack.h:135
int onLayer1() const
Definition: FSimTrack.h:96
std::vector< double > k_e
std::vector< GflashHit > & getGflashHitList()
int onHcal() const
Definition: FSimTrack.h:111
const std::map< CaloHitID, float > & getHits() override
Definition: HcalHitMaker.h:37
void setTkMomentum(const math::XYZTLorentzVectorD &mom)
Definition: SimTrack.h:42
double eta() const
Definition: RawParticle.h:267
const RawParticle & hcalEntrance() const
The particle at HCAL entrance.
Definition: FSimTrack.h:141
std::vector< std::pair< CaloHitID, float > > HMapping_
std::vector< double > samplingHO_
void setPreshowerPresent(bool ps)
Definition: EcalHitMaker.h:137
FastHFShowerLibrary * theHFShowerLibrary
DetId getClosestCell(const XYZPoint &point, bool ecal, bool central) const
EnergyLossSimulator * energyLossSimulator() const
Return the Energy Loss engine.
std::unique_ptr< KKCorrectionFactors > ecalCorrection
HSParameters * myHSParameters_
std::vector< SimTrack > SimTrackContainer
void setVertex(const XYZTLorentzVector &vtx)
set the vertex
Definition: RawParticle.h:288
bool setDepth(double, bool inCm=false)
set the depth in X0 or Lambda0 units depending on showerType
void initialize(int showerType, double energy, double globalTime, double charge, Gflash3Vector &position, Gflash3Vector &momentum)
bool computeShower()
Definition: HDRShower.cc:47
math::XYZTLorentzVector XYZTLorentzVector
Definition: RawParticle.h:15
void print() const
print the FBaseSimEvent in an intelligible way
void setHcal(HcalHitMaker *const myHcal)
set the HCAL address
Definition: EMShower.cc:714
void setGrid(EcalHitMaker *const myGrid)
set the grid address
Definition: EMShower.h:61
void EMShowerSimulation(const FSimTrack &myTrack, RandomEngineAndDistribution const *)
std::vector< double > timeShiftHE_
FSimTrack & track(int id) const
Return track with given Id.
double getMaximumOfShower() const
get the depth of the centre of gravity of the shower(s)
Definition: EMShower.h:58
void loadFromEcalBarrel(edm::PCaloHitContainer &c) const