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  // myHistos(0),
74  initialized_(false)
75 {;}
76 
78  const edm::ParameterSet& fastCalo,
79  const edm::ParameterSet& fastMuECAL,
80  const edm::ParameterSet& fastMuHCAL,
81  const edm::ParameterSet& parGflash)
82  :
83  mySimEvent(aSimEvent),
86 {
87 
90 
91  //Gflash
92  theProfile = new GflashHadronShowerProfile(parGflash);
93  thePiKProfile = new GflashPiKShowerProfile(parGflash);
96 
97  // FastHFShowerLibrary
99 
100  readParameters(fastCalo);
101 
102  // myHistos = 0;
103 
104  // myHistos = Histos::instance();
105  // myHistos->book("h10",140,-3.5,3.5,100,-0.5,99.5);
106  // myHistos->book("h20",150,0,150.,100,-0.5,99.5);
107  // myHistos->book("h100",140,-3.5,3.5,100,0,0.1);
108  // myHistos->book("h110",140,-3.5,3.5,100,0,10.);
109  // myHistos->book("h120",200,-5.,5.,100,0,0.5);
110 
111  // myHistos->book("h200",300,0,3.,100,0.,35.);
112  // myHistos->book("h210",720,-M_PI,M_PI,100,0,35.);
113  // myHistos->book("h212",720,-M_PI,M_PI,100,0,35.);
114 
115  // myHistos->bookByNumber("h30",0,7,300,-3.,3.,100,0.,35.);
116  // myHistos->book("h310",75,-3.,3.,"");
117  // myHistos->book("h400",100,-10.,10.,100,0.,35.);
118  // myHistos->book("h410",720,-M_PI,M_PI);
119 
120  myCalorimeter_ =
121  new CaloGeometryHelper(fastCalo);
122  myHDResponse_ =
123  new HCALResponse(fastCalo.getParameter<edm::ParameterSet>("HCALResponse"));
124  myHSParameters_ =
125  new HSParameters(fastCalo.getParameter<edm::ParameterSet>("HSParameters"));
126 
127  // Material Effects for Muons in ECAL (only EnergyLoss implemented so far)
128 
129  if ( fastMuECAL.getParameter<bool>("PairProduction") ||
130  fastMuECAL.getParameter<bool>("Bremsstrahlung") ||
131  fastMuECAL.getParameter<bool>("MuonBremsstrahlung") ||
132  fastMuECAL.getParameter<bool>("EnergyLoss") ||
133  fastMuECAL.getParameter<bool>("MultipleScattering") )
134  theMuonEcalEffects = new MaterialEffects(fastMuECAL);
135 
136  // Material Effects for Muons in HCAL (only EnergyLoss implemented so far)
137 
138  if ( fastMuHCAL.getParameter<bool>("PairProduction") ||
139  fastMuHCAL.getParameter<bool>("Bremsstrahlung") ||
140  fastMuHCAL.getParameter<bool>("MuonBremsstrahlung") ||
141  fastMuHCAL.getParameter<bool>("EnergyLoss") ||
142  fastMuHCAL.getParameter<bool>("MultipleScattering") )
143  theMuonHcalEffects = new MaterialEffects(fastMuHCAL);
144 
145  if( fastCalo.exists("ECALResponseScaling") ) {
146  ecalCorrection = std::unique_ptr<KKCorrectionFactors>( new KKCorrectionFactors( fastCalo.getParameter<edm::ParameterSet>("ECALResponseScaling") ) );
147  }
148 
149 }
150 
152 {
153  EBMapping_.clear();
154  EEMapping_.clear();
155  HMapping_.clear();
156  ESMapping_.clear();
157  muonSimTracks.clear();
158 }
159 
161 {
162  if(myCalorimeter_) delete myCalorimeter_;
163  if(myHDResponse_) delete myHDResponse_;
164 
167 
168  if ( theProfile ) delete theProfile;
169 
171 }
172 
174 {
175  theHFShowerLibrary->SetRandom(random);
176  if(!evtsToDebug_.empty())
177  {
178  std::vector<unsigned int>::const_iterator itcheck=find(evtsToDebug_.begin(),evtsToDebug_.end(),mySimEvent->id().event());
179  debug_=(itcheck!=evtsToDebug_.end());
180  if(debug_)
181  mySimEvent->print();
182  }
183  // Clear the content of the calorimeters
184  if(!initialized_)
185  {
186 
187  // Check if the preshower is really available
189  {
190  std::cout << " WARNING " << std::endl;
191  std::cout << " The preshower simulation has been turned on; but no preshower geometry is available " << std::endl;
192  std::cout << " Disabling the preshower simulation " << std::endl;
193  simulatePreshower_ = false;
194  }
195 
196  initialized_=true;
197  }
198  clean();
199 
200 
201 
202  LogInfo("FastCalorimetry") << "Reconstructing " << (int) mySimEvent->nTracks() << " tracks." << std::endl;
203  for( int fsimi=0; fsimi < (int) mySimEvent->nTracks() ; ++fsimi) {
204 
205  FSimTrack& myTrack = mySimEvent->track(fsimi);
206 
207  int pid = abs(myTrack.type());
208 
209  if (debug_) {
210  LogInfo("FastCalorimetry") << " ===> pid = " << pid << std::endl;
211  }
212 
213 
214  // Check that the particle hasn't decayed
215  if(myTrack.noEndVertex()) {
216  // Simulate energy smearing for photon and electrons
217  if ( pid == 11 || pid == 22 ) {
218 
219  if ( myTrack.onEcal() )
220  EMShowerSimulation(myTrack, random);
221  else if ( myTrack.onVFcal() ) {
222  if(useShowerLibrary) {
224  myHDResponse_->correctHF(myTrack.hcalEntrance().e(),abs(myTrack.type()));
226  }
227  else reconstructHCAL(myTrack, random);
228  }
229  } // electron or photon
230  else if (pid==13)
231  {
232  MuonMipSimulation(myTrack, random);
233  }
234  // Simulate energy smearing for hadrons (i.e., everything
235  // but muons... and SUSY particles that deserve a special
236  // treatment.
237  else if ( pid < 1000000 ) {
238  if ( myTrack.onHcal() || myTrack.onVFcal() ) {
239  if(optionHDSim_ == 0 ) reconstructHCAL(myTrack, random);
240  else HDShowerSimulation(myTrack, random);
241  }
242  } // pid < 1000000
243  } // myTrack.noEndVertex()
244  } // particle loop
245  // LogInfo("FastCalorimetry") << " Number of hits (barrel)" << EBMapping_.size() << std::endl;
246  // LogInfo("FastCalorimetry") << " Number of hits (Hcal)" << HMapping_.size() << std::endl;
247  // std::cout << " Nombre de hit (endcap)" << EEMapping_.size() << std::endl;
248 
249 } // reconstruct
250 
251 // Simulation of electromagnetic showers in PS, ECAL, HCAL
254  std::vector<const RawParticle*> thePart;
255  double X0depth;
256 
257  if (debug_) {
258  LogInfo("FastCalorimetry") << " EMShowerSimulation " <<myTrack << std::endl;
259  }
260 
261  // std::cout << " Simulating " << myTrack << std::endl;
262 
263  // The Particle at ECAL entrance
264  // std::cout << " Before ecalEntrance " << std::endl;
265  myPart = myTrack.ecalEntrance();
266 
267  // protection against infinite loop.
268  if ( myTrack.type() == 22 && myPart.e()<0.055) return;
269 
270 
271  // Barrel or Endcap ?
272  int onEcal = myTrack.onEcal();
273  int onHcal = myTrack.onHcal();
274  int onLayer1 = myTrack.onLayer1();
275  int onLayer2 = myTrack.onLayer2();
276 
277  // The entrance in ECAL
278  XYZPoint ecalentrance = myPart.vertex().Vect();
279 
280  // std::cout << " Ecal entrance " << ecalentrance << std::endl;
281 
282  // The preshower
283  PreshowerHitMaker * myPreshower = nullptr;
284  if(simulatePreshower_ && (onLayer1 || onLayer2))
285  {
286  XYZPoint layer1entrance,layer2entrance;
287  XYZVector dir1,dir2;
288  if(onLayer1)
289  {
290  layer1entrance = XYZPoint(myTrack.layer1Entrance().vertex().Vect());
291  dir1 = XYZVector(myTrack.layer1Entrance().Vect().Unit());
292  }
293  if(onLayer2)
294  {
295  layer2entrance = XYZPoint(myTrack.layer2Entrance().vertex().Vect());
296  dir2 = XYZVector(myTrack.layer2Entrance().Vect().Unit());
297  }
298  // std::cout << " Layer1entrance " << layer1entrance << std::endl;
299  // std::cout << " Layer2entrance " << layer2entrance << std::endl;
300  myPreshower = new PreshowerHitMaker(myCalorimeter_,
301  layer1entrance,
302  dir1,
303  layer2entrance,
304  dir2,
306  random);
307  myPreshower->setMipEnergy(mipValues_[0],mipValues_[1]);
308  }
309 
310  // The ECAL Properties
312  showerparam(myCalorimeter_->ecalProperties(onEcal),
313  myCalorimeter_->hcalProperties(onHcal),
314  myCalorimeter_->layer1Properties(onLayer1),
315  myCalorimeter_->layer2Properties(onLayer2),
318  RCFactor_,
319  RTFactor_);
320 
321  // Photons : create an e+e- pair
322  if ( myTrack.type() == 22 ) {
323 
324  // Depth for the first e+e- pair creation (in X0)
325  X0depth = -log(random->flatShoot()) * (9./7.);
326 
327  // Initialization
328  double eMass = 0.000510998902;
329  double xe=0;
330  double xm=eMass/myPart.e();
331  double weight = 0.;
332 
333  // Generate electron energy between emass and eGamma-emass
334  do {
335  xe = random->flatShoot()*(1.-2.*xm) + xm;
336  weight = 1. - 4./3.*xe*(1.-xe);
337  } while ( weight < random->flatShoot() );
338 
339  // Protection agains infinite loop in Famos Shower
340  if ( myPart.e()*xe < 0.055 || myPart.e()*(1.-xe) < 0.055 ) {
341 
342  if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
343 
344  } else {
345 
346  myElec = (myPart) * xe;
347  myPosi = (myPart) * (1.-xe);
350  thePart.push_back(&myElec);
351  thePart.push_back(&myPosi);
352  }
353  // Electrons
354  } else {
355 
356  X0depth = 0.;
357  if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
358 
359  }
360 
361  // After the different protections, this shouldn't happen.
362  if(thePart.empty())
363  {
364  if(myPreshower==nullptr) return;
365  delete myPreshower;
366  return;
367  }
368 
369  // find the most energetic particle
370  double maxEnergy=-1.;
371  for(unsigned ip=0;ip < thePart.size();++ip)
372  if(thePart[ip]->e() > maxEnergy) maxEnergy = thePart[ip]->e();
373 
374  // Initialize the Grid in ECAL
375  int size = gridSize_;
376  if(maxEnergy>100) size=11;
377  // if ( maxEnergy < threshold5x5 ) size = 5;
378  // if ( maxEnergy < threshold3x3 ) size = 3;
379 
380 
381  EMShower theShower(random,aGammaGenerator,&showerparam,&thePart,nullptr,nullptr,bFixedLength_);
382 
383 
384  double maxShower = theShower.getMaximumOfShower();
385  if (maxShower > 20.) maxShower = 2.; // simple pivot-searching protection
386 
387  double depth((X0depth + maxShower) *
389  XYZPoint meanShower = ecalentrance + myPart.Vect().Unit()*depth;
390 
391  // if(onEcal!=1) return ;
392 
393  // The closest crystal
394  DetId pivot(myCalorimeter_->getClosestCell(meanShower, true, onEcal==1));
395 
396  if(pivot.subdetId() == 0) { // further protection against avbsence of pivot
397  edm::LogWarning("CalorimetryManager") << "Pivot for egamma e = " << myTrack.hcalEntrance().e() << " is not found at depth " << depth << " and meanShower coordinates = " << meanShower << std::endl;
398  if(myPreshower) delete myPreshower;
399  return;
400  }
401 
402  EcalHitMaker myGrid(myCalorimeter_,ecalentrance,pivot,onEcal,size,0,random);
403  // ^^^^
404  // for EM showers
407 
408  //maximumdepth dependence of the radiusfactorbehindpreshower
409  //First tuning: Shilpi Jain (Mar-Apr 2010); changed after tuning - Feb-July - Shilpi Jain
410  /* **************
411  myGrid.setRadiusFactor(radiusFactor_);
412  if(onLayer1 || onLayer2)
413  {
414  float b = radiusPreshowerCorrections_[0];
415  float a = radiusFactor_*( 1.+radiusPreshowerCorrections_[1]*radiusPreshowerCorrections_[0] );
416  float maxdepth = X0depth+theShower.getMaximumOfShower();
417  float newRadiusFactor = radiusFactor_;
418  if(myPart.e()<=250.)
419  {
420  newRadiusFactor = a/(1.+b*maxdepth);
421  }
422  myGrid.setRadiusFactor(newRadiusFactor);
423  }
424  else // otherwise use the normal radius factor
425  {
426  myGrid.setRadiusFactor(radiusFactor_);
427  }
428  ************** */
429  if(myTrack.onEcal() == 2) // if on EE
430  {
431  if( (onLayer1 || onLayer2) && myPart.e()<=250.)
432  {
433  double maxdepth = X0depth+theShower.getMaximumOfShower();
434  double newRadiusFactor = radiusFactorEE_ * aTerm/(1.+bTerm*maxdepth);
435  myGrid.setRadiusFactor(newRadiusFactor);
436  }
437  else // otherwise use the normal radius factor
438  {
440  }
441  }//if(myTrack.onEcal() == 2)
442  else // else if on EB
443  {
445  }
446  //(end of) changed after tuning - Feb-July - Shilpi Jain
447 
449 
450  // The shower simulation
451  myGrid.setTrackParameters(myPart.Vect().Unit(),X0depth,myTrack);
452 
453  // std::cout << " PS ECAL GAP HCAL X0 " << myGrid.ps1TotalX0()+myGrid.ps2TotalX0() << " " << myGrid.ecalTotalX0();
454  // std::cout << " " << myGrid.ecalHcalGapTotalX0() << " " << myGrid.hcalTotalX0() << std::endl;
455  // std::cout << " PS ECAL GAP HCAL L0 " << myGrid.ps1TotalL0()+myGrid.ps2TotalL0() << " " << myGrid.ecalTotalL0();
456  // std::cout << " " << myGrid.ecalHcalGapTotalL0() << " " << myGrid.hcalTotalL0() << std::endl;
457  // std::cout << "ECAL-HCAL " << myTrack.momentum().eta() << " " << myGrid.ecalHcalGapTotalL0() << std::endl;
458  //
459  // std::cout << " Grid created " << std::endl;
460  if(myPreshower) theShower.setPreshower(myPreshower);
461 
462  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)0);
463 
464  theShower.setGrid(&myGrid);
465  theShower.setHcal(&myHcalHitMaker);
466  theShower.compute();
467  //myHistos->fill("h502", myPart->eta(),myGrid.totalX0());
468 
469  // calculate the total simulated energy for this particle
470  float simE = 0;
471  for( const auto& mapIterator : myGrid.getHits() ) {
472  simE += mapIterator.second;
473  }
474 
475  auto scale = ecalCorrection ? ecalCorrection->getScale( myTrack.ecalEntrance().e(),
476  std::abs( myTrack.ecalEntrance().eta() ), simE ) : 1.;
477 
478  // Save the hits !
479  updateECAL( myGrid.getHits(), onEcal,myTrack.id(), scale );
480 
481  // Now fill the HCAL hits
482  updateHCAL(myHcalHitMaker.getHits(),myTrack.id());
483 
484  // delete the preshower
485  if(myPreshower!=nullptr) {
486  updatePreshower(myPreshower->getHits(),myTrack.id());
487  delete myPreshower;
488  // std::cout << " Deleting myPreshower " << std::endl;
489  }
490 
491 }
492 
495 {
496  int hit;
497  int pid = abs(myTrack.type());
498  if (debug_) {
499  LogInfo("FastCalorimetry") << " reconstructHCAL " << myTrack << std::endl;
500  }
501 
502  // FSimTrack myTrack = mySimEvent.track(fsimi);
503 
504  // int pid=abs(myTrack.type());
505  // std::cout << "reconstructHCAL " << std::endl;
506 
507  XYZTLorentzVector trackPosition;
508  if (myTrack.onHcal()) {
509  trackPosition=myTrack.hcalEntrance().vertex();
510  hit = myTrack.onHcal()-1;
511  } else {
512  trackPosition=myTrack.vfcalEntrance().vertex();
513  hit = 2;
514  }
515 
516  double pathEta = trackPosition.eta();
517  double pathPhi = trackPosition.phi();
518  // double pathTheta = trackPosition.theta();
519 
520  double EGen = myTrack.hcalEntrance().e();
521  double emeas = 0.;
522  //double emeas = -0.0001;
523 
524  if(pid == 13) {
525  // std::cout << " We should not be here " << std::endl;
526  emeas = myHDResponse_->responseHCAL(0, EGen, pathEta, 2, random); // 2=muon
527  if(debug_)
528  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - MUON !!!" << std::endl;
529  }
530  else if( pid == 22 || pid == 11) {
531  emeas = myHDResponse_->responseHCAL(0, EGen, pathEta, 0, random); // last par. = 0 = e/gamma
532  // cout << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
533  if(debug_)
534  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
535  }
536  else {
537  emeas = myHDResponse_->getHCALEnergyResponse(EGen, hit, random);
538  }
539 
540  if(debug_)
541  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - on-calo "
542  << " eta = " << pathEta
543  << " phi = " << pathPhi
544  << " Egen = " << EGen
545  << " Emeas = " << emeas << std::endl;
546 
547  if(emeas > 0.) {
548  DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
549  double tof = (((HcalGeometry*)(myCalorimeter_->getHcalGeometry()))->getPosition(cell).mag())/29.98;//speed of light
550  CaloHitID current_id(cell.rawId(),tof,myTrack.id());
551  std::map<CaloHitID,float> hitMap;
552  hitMap[current_id] = emeas;
553  updateHCAL(hitMap,myTrack.id());
554  }
555 }
556 
558  // const edm::ParameterSet& fastCalo){
559 
560  theHFShowerLibrary->SetRandom(random);
561 
562  // TimeMe t(" FASTEnergyReconstructor::HDShower");
563  const XYZTLorentzVector& moment = myTrack.momentum();
564 
565  if(debug_)
566  LogInfo("FastCalorimetry")
567  << "CalorimetryManager::HDShowerSimulation - track param."
568  << std::endl
569  << " eta = " << moment.eta() << std::endl
570  << " phi = " << moment.phi() << std::endl
571  << " et = " << moment.Et() << std::endl
572  << " e = " << myTrack.hcalEntrance().e() << std::endl;
573 
574  if (debug_) {
575  LogInfo("FastCalorimetry") << " HDShowerSimulation " << myTrack << std::endl;
576  }
577 
578 
579  int hit;
580  // int pid = abs(myTrack.type());
581 
582  XYZTLorentzVector trackPosition;
583  if ( myTrack.onEcal() ) {
584  trackPosition=myTrack.ecalEntrance().vertex();
585  hit = myTrack.onEcal()-1; //
586  myPart = myTrack.ecalEntrance();
587  } else if ( myTrack.onVFcal()) {
588  trackPosition=myTrack.vfcalEntrance().vertex();
589  hit = 2;
590  myPart = myTrack.vfcalEntrance();
591  }
592  else
593  {
594  LogInfo("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
595  return;
596  }
597 
598  // int onHCAL = hit + 1; - specially for myCalorimeter->hcalProperties(onHCAL)
599  // (below) to get VFcal properties ...
600  int onHCAL = hit + 1;
601  int onECAL = myTrack.onEcal();
602 
603  double pathEta = trackPosition.eta();
604  double pathPhi = trackPosition.phi();
605  // double pathTheta = trackPosition.theta();
606 
607  double eint = moment.e();
608  double eGen = myTrack.hcalEntrance().e();
609 
610  double emeas = 0.;
611  double pmip= myHDResponse_->getMIPfraction(eGen, pathEta);
612  // std::cout << " CalorimetryManager onHcal " << pmip << std::endl;
613 
614 
615  //double emeas = -0.000001;
616 
617  //===========================================================================
618  if(eGen > 0.) {
619 
620  // ECAL and HCAL properties to get
622  theHDShowerparam(myCalorimeter_->ecalProperties(onECAL),
625 
626  //Making ECAL Grid (and segments calculation)
627  XYZPoint caloentrance;
628  XYZVector direction;
629  if(myTrack.onEcal())
630  {
631  caloentrance = myTrack.ecalEntrance().vertex().Vect();
632  direction = myTrack.ecalEntrance().Vect().Unit();
633  }
634  else if(myTrack.onHcal())
635  {
636  caloentrance = myTrack.hcalEntrance().vertex().Vect();
637  direction = myTrack.hcalEntrance().Vect().Unit();
638  }
639  else
640  {
641  caloentrance = myTrack.vfcalEntrance().vertex().Vect();
642  direction = myTrack.vfcalEntrance().Vect().Unit();
643  }
644 
645  if(debug_)
646  LogInfo("FastCalorimetry")
647  << "CalorimetryManager::HDShowerSimulation - on-calo 1 "
648  << std::endl
649  << " onEcal = " << myTrack.onEcal() << std::endl
650  << " onHcal = " << myTrack.onHcal() << std::endl
651  << " onVFcal = " << myTrack.onVFcal() << std::endl
652  << " position = " << caloentrance << std::endl;
653 
654 
655  DetId pivot;
656  if(myTrack.onEcal())
657  {
658  pivot=myCalorimeter_->getClosestCell(caloentrance,
659  true, myTrack.onEcal()==1);
660  }
661  else if(myTrack.onHcal())
662  {
663  // std::cout << " CalorimetryManager onHcal " << myTrack.onHcal() << " caloentrance" << caloentrance << std::endl;
664  pivot=myCalorimeter_->getClosestCell(caloentrance,
665  false, false);
666  }
667 
668  EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
669  pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,1,
670  random);
671  // 1=HAD shower
672 
673  myGrid.setTrackParameters(direction,0,myTrack);
674  // Build the FAMOS HCAL
675  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)1);
676 
677  // Shower simulation
678  bool status = false;
679  int mip = 2;
680  // Use HFShower for HF
681  if ( !myTrack.onEcal() && !myTrack.onHcal() ) {
682  // std::cout << "CalorimetryManager::HDShowerSimulation(): track entrance = "
683  // << myTrack.vfcalEntrance().vertex().X() << " "
684  // << myTrack.vfcalEntrance().vertex().Y() << " "
685  // << myTrack.vfcalEntrance().vertex().Z() << " "
686  // << " , Energy (Gen/Scale) = " << eGen << " " << e << std::endl;
687 
688  // Warning : We give here the particle energy with the response
689  // but without the resolution/gaussian smearing
690  // For HF, the resolution is due to the PE statistic
691 
692  if(useShowerLibrary) {
694  status = true;
695  } else {
696  HFShower theShower(random,
697  &theHDShowerparam,
698  &myGrid,
699  &myHcalHitMaker,
700  onECAL,
701  eGen);
702  // eGen);
703  // e); // PV Warning : temporarly set the energy to the generated E
704 
705  status = theShower.compute();
706  }
707  } else {
708  if(hdSimMethod_ == 0) {
709  HDShower theShower(random,
710  &theHDShowerparam,
711  &myGrid,
712  &myHcalHitMaker,
713  onECAL,
714  eGen,
715  pmip);
716  status = theShower.compute();
717  mip = theShower.getmip();
718  }
719  else if (hdSimMethod_ == 1) {
720  HDRShower theShower(random,
721  &theHDShowerparam,
722  &myGrid,
723  &myHcalHitMaker,
724  onECAL,
725  eGen);
726  status = theShower.computeShower();
727  mip = 2;
728  }
729  else if (hdSimMethod_ == 2 ) {
730  // std::cout << "Using GflashHadronShowerProfile hdSimMethod_ == 2" << std::endl;
731 
732  //dynamically loading a corresponding profile by the particle type
733  int particleType = myTrack.type();
735  if(particleType == -2212) theProfile = theAntiProtonProfile;
736  else if(particleType == 2212) theProfile = theProtonProfile;
737 
738  //input variables for GflashHadronShowerProfile
739  int showerType = 99 + myTrack.onEcal();
740  double globalTime = 150.0; // a temporary reference hit time in nanosecond
741  float charge = (float)(myTrack.charge());
742  Gflash3Vector gfpos(trackPosition.X(),trackPosition.Y(),trackPosition.Z());
743  Gflash3Vector gfmom(moment.X(),moment.Y(),moment.Z());
744 
745  theProfile->initialize(showerType,eGen,globalTime,charge,gfpos,gfmom);
748 
749  //make hits
750  std::vector<GflashHit>& gflashHitList = theProfile->getGflashHitList();
751  std::vector<GflashHit>::const_iterator spotIter = gflashHitList.begin();
752  std::vector<GflashHit>::const_iterator spotIterEnd = gflashHitList.end();
753 
755 
756  for( ; spotIter != spotIterEnd; spotIter++){
757 
758  double pathLength = theProfile->getGflashShowino()->getPathLengthAtShower()
759  + (30*100/eGen)*(spotIter->getTime() - globalTime);
760 
761  double currentDepth = std::max(0.0,pathLength - theProfile->getGflashShowino()->getPathLengthOnEcal());
762 
763  //find the the showino position at the currentDepth
764  GflashTrajectoryPoint trajectoryPoint;
765  theProfile->getGflashShowino()->getHelix()->getGflashTrajectoryPoint(trajectoryPoint,pathLength);
766  Gflash3Vector positionAtCurrentDepth = trajectoryPoint.getPosition();
767  //find radial distrance
768  Gflash3Vector lateralDisplacement = positionAtCurrentDepth - spotIter->getPosition()/CLHEP::cm;
769  double rShower = lateralDisplacement.r();
770  double azimuthalAngle = lateralDisplacement.phi();
771 
772  whichCalor = Gflash::getCalorimeterNumber(positionAtCurrentDepth);
773 
774  if(whichCalor==Gflash::kESPM || whichCalor==Gflash::kENCA) {
775  bool statusPad = myGrid.getPads(currentDepth,true);
776  if(!statusPad) continue;
777  myGrid.setSpotEnergy(1.2*spotIter->getEnergy()/CLHEP::GeV);
778  myGrid.addHit(rShower/Gflash::intLength[Gflash::kESPM],azimuthalAngle,0);
779  }
780  else if(whichCalor==Gflash::kHB || whichCalor==Gflash::kHE) {
781  bool setHDdepth = myHcalHitMaker.setDepth(currentDepth,true);
782  if(!setHDdepth) continue;
783  myHcalHitMaker.setSpotEnergy(1.4*spotIter->getEnergy()/CLHEP::GeV);
784  myHcalHitMaker.addHit(rShower/Gflash::intLength[Gflash::kHB],azimuthalAngle,0);
785  }
786  }
787  status = true;
788  }
789  else {
790  edm::LogInfo("FastSimulationCalorimetry") << " SimMethod " << hdSimMethod_ <<" is NOT available ";
791  }
792  }
793 
794 
795  if(status) {
796 
797  // Here to switch between simple formulae and parameterized response
798  if(optionHDSim_ == 1) {
799  emeas = myHDResponse_->getHCALEnergyResponse(eGen, hit, random);
800  }
801  else { // optionHDsim == 2
802  emeas = myHDResponse_->responseHCAL(mip, eGen, pathEta, 1, random); // 1=hadron
803  }
804 
805  double correction = emeas / eGen;
806 
807  // RespCorrP factors (ECAL and HCAL separately) calculation
808  respCorr(eint);
809 
810  if(debug_)
811  LogInfo("FastCalorimetry")
812  << "CalorimetryManager::HDShowerSimulation - on-calo 2" << std::endl
813  << " eta = " << pathEta << std::endl
814  << " phi = " << pathPhi << std::endl
815  << " Egen = " << eGen << std::endl
816  << " Emeas = " << emeas << std::endl
817  << " corr = " << correction << std::endl
818  << " mip = " << mip << std::endl;
819 
820  if(myTrack.onEcal() > 0) {
821  // Save ECAL hits
822  updateECAL(myGrid.getHits(),onECAL,myTrack.id(),correction*ecorr);
823  }
824 
825  // Save HCAL hits
826  if(myTrack.onVFcal() && useShowerLibrary) {
827  myHDResponse_->correctHF(eGen,abs(myTrack.type()));
829  }
830  else
831  updateHCAL(myHcalHitMaker.getHits(),myTrack.id(),correction*hcorr);
832 
833  }
834  else { // shower simulation failed
835  // std::cout << " Shower simulation failed " << trackPosition.Vect() << std::endl;
836  // std::cout << " The FSimTrack " << myTrack << std::endl;
837  // std::cout << " HF entrance on VFcal" << myTrack.onVFcal() << std::endl;
838  // std::cout << " trackPosition.eta() " << trackPosition.eta() << std::endl;
839  if(myTrack.onHcal() || myTrack.onVFcal())
840  {
841  DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
842  double tof = (((HcalGeometry*)(myCalorimeter_->getHcalGeometry()))->getPosition(cell).mag())/29.98;//speed of light
843  CaloHitID current_id(cell.rawId(),tof,myTrack.id());
844  std::map<CaloHitID,float> hitMap;
845  hitMap[current_id] = emeas;
846  updateHCAL(hitMap,myTrack.id());
847  if(debug_)
848  LogInfo("FastCalorimetry") << " HCAL simple cell "
849  << cell.rawId() << " added E = "
850  << emeas << std::endl;
851  }
852  }
853 
854  } // e > 0. ...
855 
856  if(debug_)
857  LogInfo("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::HDShowerSimulation finished "
858  << std::endl;
859 }
860 
861 
863 {
864  // TimeMe t(" FASTEnergyReconstructor::HDShower");
865  XYZTLorentzVector moment = myTrack.momentum();
866 
867  // Backward compatibility behaviour
868  if(!theMuonHcalEffects)
869  {
870  if(myTrack.onHcal() || myTrack.onVFcal() )
871  reconstructHCAL(myTrack, random);
872 
873  return;
874  }
875 
876  if(debug_)
877  LogInfo("FastCalorimetry") << "CalorimetryManager::MuonMipSimulation - track param."
878  << std::endl
879  << " eta = " << moment.eta() << std::endl
880  << " phi = " << moment.phi() << std::endl
881  << " et = " << moment.Et() << std::endl;
882 
883  // int hit;
884  // int pid = abs(myTrack.type());
885 
886  XYZTLorentzVector trackPosition;
887  if ( myTrack.onEcal() ) {
888  trackPosition=myTrack.ecalEntrance().vertex();
889  // hit = myTrack.onEcal()-1; //
890  myPart = myTrack.ecalEntrance();
891  } else if ( myTrack.onVFcal()) {
892  trackPosition=myTrack.vfcalEntrance().vertex();
893  // hit = 2;
894  myPart = myTrack.vfcalEntrance();
895  }
896  else
897  {
898  LogInfo("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
899  return;
900  }
901 
902  // int onHCAL = hit + 1; - specially for myCalorimeter->hcalProperties(onHCAL)
903  // (below) to get VFcal properties ...
904  // not needed ?
905  // int onHCAL = hit + 1;
906  int onECAL = myTrack.onEcal();
907 
908  // double pathEta = trackPosition.eta();
909  // double pathPhi = trackPosition.phi();
910  // double pathTheta = trackPosition.theta();
911 
912  //===========================================================================
913 
914  // ECAL and HCAL properties to get
915 
916  //Making ECAL Grid (and segments calculation)
917  XYZPoint caloentrance;
918  XYZVector direction;
919  if(myTrack.onEcal())
920  {
921  caloentrance = myTrack.ecalEntrance().vertex().Vect();
922  direction = myTrack.ecalEntrance().Vect().Unit();
923  }
924  else if(myTrack.onHcal())
925  {
926  caloentrance = myTrack.hcalEntrance().vertex().Vect();
927  direction = myTrack.hcalEntrance().Vect().Unit();
928  }
929  else
930  {
931  caloentrance = myTrack.vfcalEntrance().vertex().Vect();
932  direction = myTrack.vfcalEntrance().Vect().Unit();
933  }
934 
935  DetId pivot;
936  if(myTrack.onEcal())
937  {
938  pivot=myCalorimeter_->getClosestCell(caloentrance,
939  true, myTrack.onEcal()==1);
940  }
941  else if(myTrack.onHcal())
942  {
943  // std::cout << " CalorimetryManager onHcal " << myTrack.onHcal() << " caloentrance" << caloentrance << std::endl;
944  pivot=myCalorimeter_->getClosestCell(caloentrance,
945  false, false);
946  }
947 
948  EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
949  pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,0,
950  random);
951  // 0 =EM shower -> Unit = X0
952 
953  myGrid.setTrackParameters(direction,0,myTrack);
954 
955  // Now get the path in the Preshower, ECAL and HCAL along a straight line extrapolation
956  // but only those in the ECAL are used
957 
958  const std::vector<CaloSegment>& segments=myGrid.getSegments();
959  unsigned nsegments=segments.size();
960 
961  int ifirstHcal=-1;
962  int ilastEcal=-1;
963 
964  EnergyLossSimulator* energyLossECAL = (theMuonEcalEffects) ?
966  // // Muon brem in ECAL
967  // MuonBremsstrahlungSimulator* muonBremECAL = 0;
968  // if (theMuonEcalEffects) muonBremECAL = theMuonEcalEffects->muonBremsstrahlungSimulator();
969 
970  for(unsigned iseg=0;iseg<nsegments&&ifirstHcal<0;++iseg)
971  {
972 
973  // in the ECAL, there are two types of segments: PbWO4 and GAP
974  float segmentSizeinX0=segments[iseg].X0length();
975 
976  // Martijn - insert your computations here
977  float energy=0.0;
978  if (segmentSizeinX0>0.001 && segments[iseg].material()==CaloSegment::PbWO4 ) {
979  // The energy loss simulator
980  float charge = (float)(myTrack.charge());
981  ParticlePropagator theMuon(moment,trackPosition,charge,nullptr);
982  theMuon.setID(-(int)charge*13);
983  if ( energyLossECAL ) {
984  energyLossECAL->updateState(theMuon, segmentSizeinX0, random);
985  energy = energyLossECAL->deltaMom().E();
986  moment -= energyLossECAL->deltaMom();
987  }
988  }
989  // that's all for ECAL, Florian
990  // Save the hit only if it is a crystal
991  if(segments[iseg].material()==CaloSegment::PbWO4)
992  {
993  myGrid.getPads(segments[iseg].sX0Entrance()+segmentSizeinX0*0.5);
994  myGrid.setSpotEnergy(energy);
995  myGrid.addHit(0.,0.);
996  ilastEcal=iseg;
997  }
998  // Check for end of loop:
999  if(segments[iseg].material()==CaloSegment::HCAL)
1000  {
1001  ifirstHcal=iseg;
1002  }
1003  }
1004 
1005 
1006  // Build the FAMOS HCAL
1007  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)2);
1008  // float mipenergy=0.1;
1009  // Create the helix with the stepping helix propagator
1010  // to add a hit, just do
1011  // myHcalHitMaker.setSpotEnergy(mipenergy);
1012  // math::XYZVector hcalEntrance;
1013  // if(ifirstHcal>=0) hcalEntrance=segments[ifirstHcal].entrance();
1014  // myHcalHitMaker.addHit(hcalEntrance);
1018  int ilastHcal=-1;
1019  float mipenergy=0.0;
1020 
1021  EnergyLossSimulator* energyLossHCAL = (theMuonHcalEffects) ?
1023  // // Muon Brem effect
1024  // MuonBremsstrahlungSimulator* muonBremHCAL = 0;
1025  // if (theMuonHcalEffects) muonBremHCAL = theMuonHcalEffects->muonBremsstrahlungSimulator();
1026 
1027  if(ifirstHcal>0 && energyLossHCAL){
1028  for(unsigned iseg=ifirstHcal;iseg<nsegments;++iseg)
1029  {
1030  float segmentSizeinX0=segments[iseg].X0length();
1031  if(segments[iseg].material()==CaloSegment::HCAL) {
1032  ilastHcal=iseg;
1033  if (segmentSizeinX0>0.001) {
1034  // The energy loss simulator
1035  float charge = (float)(myTrack.charge());
1036  ParticlePropagator theMuon(moment,trackPosition,charge,nullptr);
1037  theMuon.setID(-(int)charge*13);
1038  energyLossHCAL->updateState(theMuon, segmentSizeinX0, random);
1039  mipenergy = energyLossHCAL->deltaMom().E();
1040  moment -= energyLossHCAL->deltaMom();
1041  myHcalHitMaker.setSpotEnergy(mipenergy);
1042  myHcalHitMaker.addHit(segments[iseg].entrance());
1043  }
1044  }
1045  }
1046  }
1047 
1052  //
1053 
1054 
1055 
1056  // Copy the muon SimTrack (Only for Energy loss)
1057  FSimTrack muonTrack(myTrack);
1058  if(energyLossHCAL && ilastHcal>=0) {
1059  math::XYZVector hcalExit=segments[ilastHcal].exit();
1060  muonTrack.setTkPosition(hcalExit);
1061  muonTrack.setTkMomentum(moment);
1062  } else if(energyLossECAL && ilastEcal>=0) {
1063  math::XYZVector ecalExit=segments[ilastEcal].exit();
1064  muonTrack.setTkPosition(ecalExit);
1065  muonTrack.setTkMomentum(moment);
1066  } // else just leave tracker surface position and momentum...
1067 
1068  muonSimTracks.push_back(muonTrack);
1069 
1070 
1071  // no need to change below this line
1072  std::map<CaloHitID,float>::const_iterator mapitr;
1073  std::map<CaloHitID,float>::const_iterator endmapitr;
1074  if(myTrack.onEcal() > 0) {
1075  // Save ECAL hits
1076  updateECAL(myGrid.getHits(),onECAL,myTrack.id());
1077  }
1078 
1079  // Save HCAL hits
1080  updateHCAL(myHcalHitMaker.getHits(),myTrack.id());
1081 
1082  if(debug_)
1083  LogInfo("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::MipShowerSimulation finished "
1084  << std::endl;
1085 }
1086 
1087 
1089 
1090  edm::ParameterSet ECALparameters = fastCalo.getParameter<edm::ParameterSet>("ECAL");
1091 
1092  evtsToDebug_ = fastCalo.getUntrackedParameter<std::vector<unsigned int> >("EvtsToDebug",std::vector<unsigned>());
1093  debug_ = fastCalo.getUntrackedParameter<bool>("Debug");
1094 
1095  bFixedLength_ = ECALparameters.getParameter<bool>("bFixedLength");
1096  // std::cout << "bFixedLength_ = " << bFixedLength_ << std::endl;
1097 
1098  gridSize_ = ECALparameters.getParameter<int>("GridSize");
1099  spotFraction_ = ECALparameters.getParameter<double>("SpotFraction");
1100  pulledPadSurvivalProbability_ = ECALparameters.getParameter<double>("FrontLeakageProbability");
1101  crackPadSurvivalProbability_ = ECALparameters.getParameter<double>("GapLossProbability");
1102  theCoreIntervals_ = ECALparameters.getParameter<std::vector<double> >("CoreIntervals");
1103  theTailIntervals_ = ECALparameters.getParameter<std::vector<double> >("TailIntervals");
1104 
1105  RCFactor_ = ECALparameters.getParameter<double>("RCFactor");
1106  RTFactor_ = ECALparameters.getParameter<double>("RTFactor");
1107  //changed after tuning - Feb-July - Shilpi Jain
1108  // radiusFactor_ = ECALparameters.getParameter<double>("RadiusFactor");
1109  radiusFactorEE_ = ECALparameters.getParameter<double>("RadiusFactorEE");
1110  radiusFactorEB_ = ECALparameters.getParameter<double>("RadiusFactorEB");
1111  //(end of) changed after tuning - Feb-July - Shilpi Jain
1112  radiusPreshowerCorrections_ = ECALparameters.getParameter<std::vector<double> >("RadiusPreshowerCorrections");
1113  aTerm = 1.+radiusPreshowerCorrections_[1]*radiusPreshowerCorrections_[0];
1114  bTerm = radiusPreshowerCorrections_[0];
1115  mipValues_ = ECALparameters.getParameter<std::vector<double> >("MipsinGeV");
1116  simulatePreshower_ = ECALparameters.getParameter<bool>("SimulatePreshower");
1117 
1118  if(gridSize_ <1) gridSize_= 7;
1119  if(pulledPadSurvivalProbability_ <0. || pulledPadSurvivalProbability_>1 ) pulledPadSurvivalProbability_= 1.;
1120  if(crackPadSurvivalProbability_ <0. || crackPadSurvivalProbability_>1 ) crackPadSurvivalProbability_= 0.9;
1121 
1122  LogInfo("FastCalorimetry") << " Fast ECAL simulation parameters " << std::endl;
1123  LogInfo("FastCalorimetry") << " =============================== " << std::endl;
1124  if(simulatePreshower_)
1125  LogInfo("FastCalorimetry") << " The preshower is present " << std::endl;
1126  else
1127  LogInfo("FastCalorimetry") << " The preshower is NOT present " << std::endl;
1128  LogInfo("FastCalorimetry") << " Grid Size : " << gridSize_ << std::endl;
1129  if(spotFraction_>0.)
1130  LogInfo("FastCalorimetry") << " Spot Fraction : " << spotFraction_ << std::endl;
1131  else
1132  {
1133  LogInfo("FastCalorimetry") << " Core of the shower " << std::endl;
1134  for(unsigned ir=0; ir < theCoreIntervals_.size()/2;++ir)
1135  {
1136  LogInfo("FastCalorimetry") << " r < " << theCoreIntervals_[ir*2] << " R_M : " << theCoreIntervals_[ir*2+1] << " ";
1137  }
1138  LogInfo("FastCalorimetry") << std::endl;
1139 
1140  LogInfo("FastCalorimetry") << " Tail of the shower " << std::endl;
1141  for(unsigned ir=0; ir < theTailIntervals_.size()/2;++ir)
1142  {
1143  LogInfo("FastCalorimetry") << " r < " << theTailIntervals_[ir*2] << " R_M : " << theTailIntervals_[ir*2+1] << " ";
1144  }
1145  //changed after tuning - Feb-July - Shilpi Jain
1146  // LogInfo("FastCalorimetry") << "Radius correction factor " << radiusFactor_ << std::endl;
1147  LogInfo("FastCalorimetry") << "Radius correction factors: EB & EE " << radiusFactorEB_ << " : "<< radiusFactorEE_ << std::endl;
1148  //(end of) changed after tuning - Feb-July - Shilpi Jain
1149  LogInfo("FastCalorimetry") << std::endl;
1150  if(mipValues_.size()>2) {
1151  LogInfo("FastCalorimetry") << "Improper number of parameters for the preshower ; using 95keV" << std::endl;
1152  mipValues_.clear();
1153  mipValues_.resize(2,0.000095);
1154  }
1155  }
1156 
1157  LogInfo("FastCalorimetry") << " FrontLeakageProbability : " << pulledPadSurvivalProbability_ << std::endl;
1158  LogInfo("FastCalorimetry") << " GapLossProbability : " << crackPadSurvivalProbability_ << std::endl;
1159 
1160 
1161  // RespCorrP: p (momentum), ECAL and HCAL corrections = f(p)
1162  edm::ParameterSet CalorimeterParam = fastCalo.getParameter<edm::ParameterSet>("CalorimeterProperties");
1163 
1164  rsp = CalorimeterParam.getParameter<std::vector<double> >("RespCorrP");
1165  LogInfo("FastCalorimetry") << " RespCorrP (rsp) size " << rsp.size() << std::endl;
1166 
1167  if( rsp.size()%3 !=0 ) {
1168  LogInfo("FastCalorimetry")
1169  << " RespCorrP size is wrong -> no corrections applied !!!"
1170  << std::endl;
1171 
1172  p_knots.push_back(14000.);
1173  k_e.push_back (1.);
1174  k_h.push_back (1.);
1175  }
1176  else {
1177  for(unsigned i = 0; i < rsp.size(); i += 3) {
1178  LogInfo("FastCalorimetry") << "i = " << i/3 << " p = " << rsp [i]
1179  << " k_e(p) = " << rsp[i+1]
1180  << " k_e(p) = " << rsp[i+2] << std::endl;
1181 
1182  p_knots.push_back(rsp[i]);
1183  k_e.push_back (rsp[i+1]);
1184  k_h.push_back (rsp[i+2]);
1185  }
1186  }
1187 
1188 
1189  //FR
1190  edm::ParameterSet HCALparameters = fastCalo.getParameter<edm::ParameterSet>("HCAL");
1191  optionHDSim_ = HCALparameters.getParameter<int>("SimOption");
1192  hdGridSize_ = HCALparameters.getParameter<int>("GridSize");
1193  hdSimMethod_ = HCALparameters.getParameter<int>("SimMethod");
1194  //RF
1195 
1196  EcalDigitizer_ = ECALparameters.getUntrackedParameter<bool>("Digitizer",false);
1197  HcalDigitizer_ = HCALparameters.getUntrackedParameter<bool>("Digitizer",false);
1198  samplingHBHE_ = HCALparameters.getParameter< std::vector<double> >("samplingHBHE");
1199  samplingHF_ = HCALparameters.getParameter< std::vector<double> >("samplingHF");
1200  samplingHO_ = HCALparameters.getParameter< std::vector<double> >("samplingHO");
1201  ietaShiftHB_ = HCALparameters.getParameter< int >("ietaShiftHB");
1202  ietaShiftHE_ = HCALparameters.getParameter< int >("ietaShiftHE");
1203  ietaShiftHF_ = HCALparameters.getParameter< int >("ietaShiftHF");
1204  ietaShiftHO_ = HCALparameters.getParameter< int >("ietaShiftHO");
1205  timeShiftHB_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHB");
1206  timeShiftHE_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHE");
1207  timeShiftHF_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHF");
1208  timeShiftHO_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHO");
1209 
1210  // FastHFShowerLibrary
1211  edm::ParameterSet m_HS = fastCalo.getParameter<edm::ParameterSet>("HFShowerLibrary");
1212  useShowerLibrary = m_HS.getUntrackedParameter<bool>("useShowerLibrary",false);
1213  useCorrectionSL = m_HS.getUntrackedParameter<bool>("useCorrectionSL",false);
1214 }
1215 
1217 
1218  int sizeP = p_knots.size();
1219 
1220  if(sizeP <= 1) {
1221  ecorr = 1.;
1222  hcorr = 1.;
1223  }
1224  else {
1225  int ip = -1;
1226  for (int i = 0; i < sizeP; i++) {
1227  if (p < p_knots[i]) { ip = i; break;}
1228  }
1229  if (ip == 0) {
1230  ecorr = k_e[0];
1231  hcorr = k_h[0];
1232  }
1233  else {
1234  if(ip == -1) {
1235  ecorr = k_e[sizeP-1];
1236  hcorr = k_h[sizeP-1];
1237  }
1238  else {
1239  double x1 = p_knots[ip-1];
1240  double x2 = p_knots[ip];
1241  double y1 = k_e[ip-1];
1242  double y2 = k_e[ip];
1243 
1244  if(x1 == x2) {
1245  // std::cout << " equal p_knots values!!! " << std::endl;
1246  }
1247 
1248  ecorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
1249 
1250  y1 = k_h[ip-1];
1251  y2 = k_h[ip];
1252  hcorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
1253 
1254  }
1255  }
1256  }
1257 
1258  if(debug_)
1259  LogInfo("FastCalorimetry") << " p, ecorr, hcorr = " << p << " "
1260  << ecorr << " " << hcorr << std::endl;
1261 
1262 }
1263 
1264 void CalorimetryManager::updateECAL(const std::map<CaloHitID,float>& hitMap, int onEcal, int trackID, float corr)
1265 {
1266  std::map<CaloHitID,float>::const_iterator mapitr;
1267  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1268  if(onEcal==1) {
1269  EBMapping_.reserve(EBMapping_.size()+hitMap.size());
1270  endmapitr=hitMap.end();
1271  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1272  //correct energy
1273  float energy = mapitr->second;
1274  energy *= corr;
1275 
1276  //make finalized CaloHitID
1277  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1278 
1279  EBMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1280  }
1281  }
1282  else if(onEcal==2) {
1283  EEMapping_.reserve(EEMapping_.size()+hitMap.size());
1284  endmapitr=hitMap.end();
1285  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1286  //correct energy
1287  float energy = mapitr->second;
1288  energy *= corr;
1289 
1290  //make finalized CaloHitID
1291  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1292 
1293  EEMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1294  }
1295  }
1296 
1297 }
1298 
1299 void CalorimetryManager::updateHCAL(const std::map<CaloHitID,float>& hitMap, int trackID, float corr)
1300 {
1301  std::vector<double> hfcorrEm = myHDResponse_->getCorrHFem();
1302  std::vector<double> hfcorrHad = myHDResponse_->getCorrHFhad();
1303  std::map<CaloHitID,float>::const_iterator mapitr;
1304  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1305  HMapping_.reserve(HMapping_.size()+hitMap.size());
1306  for(mapitr=hitMap.begin(); mapitr!=endmapitr; ++mapitr) {
1307  //correct energy
1308  float energy = mapitr->second;
1309  energy *= corr;
1310 
1311  float time = mapitr->first.timeSlice();
1312  //put energy into uncalibrated state for digitizer && correct timing
1313  if(HcalDigitizer_){
1314  HcalDetId hdetid = HcalDetId(mapitr->first.unitID());
1315  if (hdetid.subdetId()== HcalBarrel){
1316  energy /= samplingHBHE_[hdetid.ietaAbs()-1]; //re-convert to GeV
1317  time = timeShiftHB_[hdetid.ietaAbs()-ietaShiftHB_];
1318  }
1319  else if (hdetid.subdetId()== HcalEndcap){
1320  energy /= samplingHBHE_[hdetid.ietaAbs()-1]; //re-convert to GeV
1321  time = timeShiftHE_[hdetid.ietaAbs()-ietaShiftHE_];
1322  }
1323  else if (hdetid.subdetId()== HcalForward){
1324  if(useShowerLibrary) {
1325  if(useCorrectionSL) {
1326  if(hdetid.depth()== 1) energy *= hfcorrEm[hdetid.ietaAbs()-ietaShiftHF_];
1327  if(hdetid.depth()== 2) energy *= hfcorrHad[hdetid.ietaAbs()-ietaShiftHF_];
1328  }
1329  } else {
1330  if(hdetid.depth()== 1) energy *= samplingHF_[0];
1331  if(hdetid.depth()== 2) energy *= samplingHF_[1];
1332  time = timeShiftHF_[hdetid.ietaAbs()-ietaShiftHF_];
1333  }
1334  }
1335  else if (hdetid.subdetId()== HcalOuter){
1336  energy /= samplingHO_[hdetid.ietaAbs()-1];
1337  time = timeShiftHO_[hdetid.ietaAbs()-ietaShiftHO_];
1338  }
1339  }
1340 
1341  //make finalized CaloHitID
1342  CaloHitID current_id(mapitr->first.unitID(),time,trackID);
1343  HMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1344  }
1345 }
1346 
1347 void CalorimetryManager::updatePreshower(const std::map<CaloHitID,float>& hitMap, int trackID, float corr)
1348 {
1349  std::map<CaloHitID,float>::const_iterator mapitr;
1350  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1351  ESMapping_.reserve(ESMapping_.size()+hitMap.size());
1352  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1353  //correct energy
1354  float energy = mapitr->second;
1355  energy *= corr;
1356 
1357  //make finalized CaloHitID
1358  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1359 
1360  ESMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1361  }
1362 }
1363 
1365 {
1366  c.reserve(c.size()+EBMapping_.size());
1367  for(unsigned i=0; i<EBMapping_.size(); i++) {
1368  c.push_back(PCaloHit(EBDetId::unhashIndex(EBMapping_[i].first.unitID()),EBMapping_[i].second,EBMapping_[i].first.timeSlice(),EBMapping_[i].first.trackID()));
1369  }
1370 }
1371 
1373 {
1374  c.reserve(c.size()+EEMapping_.size());
1375  for(unsigned i=0; i<EEMapping_.size(); i++) {
1376  c.push_back(PCaloHit(EEDetId::unhashIndex(EEMapping_[i].first.unitID()),EEMapping_[i].second,EEMapping_[i].first.timeSlice(),EEMapping_[i].first.trackID()));
1377  }
1378 }
1379 
1381 {
1382  c.reserve(c.size()+HMapping_.size());
1383  for(unsigned i=0; i<HMapping_.size(); i++) {
1384  c.push_back(PCaloHit(DetId(HMapping_[i].first.unitID()),HMapping_[i].second,HMapping_[i].first.timeSlice(),HMapping_[i].first.trackID()));
1385  }
1386 }
1387 
1388 
1390 {
1391  c.reserve(c.size()+ESMapping_.size());
1392  for(unsigned i=0; i<ESMapping_.size(); i++) {
1393  c.push_back(PCaloHit(ESMapping_[i].first.unitID(),ESMapping_[i].second,ESMapping_[i].first.timeSlice(),ESMapping_[i].first.trackID()));
1394  }
1395 }
1396 
1397 // The main danger in this method is to screw up to relationships between particles
1398 // So, the muon FSimTracks created by FSimEvent.cc are simply to be updated
1400 {
1401  unsigned size=muons.size();
1402  for(unsigned i=0; i<size;++i)
1403  {
1404  int id=muons[i].trackId();
1405  if(abs(muons[i].type())!=13) continue;
1406  // identify the corresponding muon in the local collection
1407 
1408  std::vector<FSimTrack>::const_iterator itcheck=find_if(muonSimTracks.begin(),muonSimTracks.end(),FSimTrackEqual(id));
1409  if(itcheck!=muonSimTracks.end())
1410  {
1411  muons[i].setTkPosition(itcheck->trackerSurfacePosition());
1412  muons[i].setTkMomentum(itcheck->trackerSurfaceMomentum());
1413  // std::cout << " Found the SimTrack " << std::endl;
1414  // std::cout << *itcheck << std::endl;
1415  // std::cout << "SimTrack Id "<< id << " " << muons[i] << " " << std::endl;
1416  }
1417  // else
1418  // {
1419  // std::cout << " Calorimetery Manager : this should really not happen " << std::endl;
1420  // std::cout << " Was looking for " << id << " " << muons[i] << std::endl;
1421  // for(unsigned i=0;i<muonSimTracks.size();++i)
1422  // std::cout << muonSimTracks[i] << std::endl;
1423  // }
1424  }
1425 
1426 }
1427 
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:47
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:139
void updateHCAL(const std::map< CaloHitID, float > &hitMap, int trackID=0, float corr=1.0)
int onLayer2() const
Definition: FSimTrack.h:96
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:190
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:127
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 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
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:101
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:108
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.
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:133
int onVFcal() const
Definition: FSimTrack.h:111
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:98
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_
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.
std::vector< unsigned int > evtsToDebug_
int id() const
the index in FBaseSimEvent and other vectors
Definition: FSimTrack.h:86
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:130
int onLayer1() const
Definition: FSimTrack.h:91
std::vector< double > k_e
std::vector< GflashHit > & getGflashHitList()
int onHcal() const
Definition: FSimTrack.h:106
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:136
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