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