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