CMS 3D CMS Logo

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