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 // STL headers
43 #include <vector>
44 #include <iostream>
45 
46 //DQM
50 
51 //CMSSW headers
54 //#include "DataFormats/EcalDetId/interface/EcalDetId.h"
55 
57 
58 //ROOT headers
59 #include "TROOT.h"
60 #include "TH1.h"
61 
62 using namespace edm;
63 
66 
67 std::vector<std::pair<int,float> > CalorimetryManager::myZero_ = std::vector<std::pair<int,float> >
68 (1,std::pair<int,float>(0,0.));
69 
71  myCalorimeter_(0),
72  // myHistos(0),
73  initialized_(false)
74 {;}
75 
77  const edm::ParameterSet& fastCalo,
78  const edm::ParameterSet& fastMuECAL,
79  const edm::ParameterSet& fastMuHCAL,
80  const edm::ParameterSet& parGflash)
81  :
82  mySimEvent(aSimEvent),
83  initialized_(false),
84  theMuonEcalEffects(0), theMuonHcalEffects (0), bFixedLength_(false)
85 {
86 
89 
90  //Gflash
91  theProfile = new GflashHadronShowerProfile(parGflash);
92  thePiKProfile = new GflashPiKShowerProfile(parGflash);
95 
96  readParameters(fastCalo);
97 
98  // myHistos = 0;
99 
101 
102  if (useDQM_){
103  TH1::SetDefaultSumw2(true); //turn on histo errors
104 
105  //ECAL histos
106  dbe->setCurrentFolder("EMShower");
107  // please keep the binning with fixed width and coherent between ShapeRhoZ and Tr/Lo shapes. Also check if you
108  // change the binning that the weight changes in the filling in EMShower.cc
109  dbe->book1D("TransverseShape","Transverse Shape; #rho / Moliere radius; 1/E dE/d#rho",70, 0., 7.);
110  dbe->book1D("LongitudinalShape","Longitudinal Shape; z / X0; 1/E dE/dz",40, 0.01, 40.01);
111  dbe->book1D("LongitudinalShapeLayers","Longitudinal Shape in number of layers; z / Layers; 1/E dE/dz", 26, 0.01, 26.01);
112  dbe->book2D("ShapeRhoZ","2D Shape; #rho / Moliere radius; z / X0", 70, 0., 7., 26, 0.01, 26.01);
113  dbe->book1D("NumberOfParticles","Number Of Particles entering the Shower; #Particles; #Events", 6, -0.5, 5.5);
114  dbe->book1D("ParticlesEnergy","Log Particles Energy; log10(E / GeV); #Particles", 30, 0, 3);
115 
116  //HCAL histos
117  dbe->setCurrentFolder("HDShower");
118 
119  dbe->book1D("TransverseShapeECAL","ECAL Transverse Shape; #rho / #lambda_{int}; 1/E dE/d#rho",70, 0., 7.);
120  dbe->book1D("LongitudinalShapeECAL","ECAL Longitudinal Shape; z / #lambda_{int}; 1/E dE/dz",20, 0., 2.);
121  dbe->book1D("TransverseShapeHCAL","HCAL Transverse Shape; #rho / #lambda_{int}; 1/E dE/d#rho",70, 0., 7.);
122  dbe->book1D("LongitudinalShapeHCAL","HCAL Longitudinal Shape; z / #lambda_{int}; 1/E dE/dz",120, 0., 12.);
123  dbe->book1D("ParticlesEnergy","Log Particles Energy; log10(E / GeV); #Particles", 30, 0, 3);
124 
125  }
126 
127 // myHistos = Histos::instance();
128 // myHistos->book("h10",140,-3.5,3.5,100,-0.5,99.5);
129 // myHistos->book("h20",150,0,150.,100,-0.5,99.5);
130 // myHistos->book("h100",140,-3.5,3.5,100,0,0.1);
131 // myHistos->book("h110",140,-3.5,3.5,100,0,10.);
132 // myHistos->book("h120",200,-5.,5.,100,0,0.5);
133 
134 // myHistos->book("h200",300,0,3.,100,0.,35.);
135 // myHistos->book("h210",720,-M_PI,M_PI,100,0,35.);
136 // myHistos->book("h212",720,-M_PI,M_PI,100,0,35.);
137 
138 // myHistos->bookByNumber("h30",0,7,300,-3.,3.,100,0.,35.);
139 // myHistos->book("h310",75,-3.,3.,"");
140 // myHistos->book("h400",100,-10.,10.,100,0.,35.);
141 // myHistos->book("h410",720,-M_PI,M_PI);
142 
143  myCalorimeter_ =
144  new CaloGeometryHelper(fastCalo);
145  myHDResponse_ =
146  new HCALResponse(fastCalo.getParameter<edm::ParameterSet>("HCALResponse"));
147  myHSParameters_ =
148  new HSParameters(fastCalo.getParameter<edm::ParameterSet>("HSParameters"));
149 
150  // Material Effects for Muons in ECAL (only EnergyLoss implemented so far)
151 
152  if ( fastMuECAL.getParameter<bool>("PairProduction") ||
153  fastMuECAL.getParameter<bool>("Bremsstrahlung") ||
154  fastMuECAL.getParameter<bool>("MuonBremsstrahlung") ||
155  fastMuECAL.getParameter<bool>("EnergyLoss") ||
156  fastMuECAL.getParameter<bool>("MultipleScattering") )
157  theMuonEcalEffects = new MaterialEffects(fastMuECAL);
158 
159  // Material Effects for Muons in HCAL (only EnergyLoss implemented so far)
160 
161  if ( fastMuHCAL.getParameter<bool>("PairProduction") ||
162  fastMuHCAL.getParameter<bool>("Bremsstrahlung") ||
163  fastMuHCAL.getParameter<bool>("MuonBremsstrahlung") ||
164  fastMuHCAL.getParameter<bool>("EnergyLoss") ||
165  fastMuHCAL.getParameter<bool>("MultipleScattering") )
166  theMuonHcalEffects = new MaterialEffects(fastMuHCAL);
167 
168 
169 }
170 
172 {
173  EBMapping_.clear();
174  EEMapping_.clear();
175  HMapping_.clear();
176  ESMapping_.clear();
177  muonSimTracks.clear();
178 }
179 
181 {
182  if(myCalorimeter_) delete myCalorimeter_;
183  if(myHDResponse_) delete myHDResponse_;
184 
187 
188  if ( theProfile ) delete theProfile;
189 }
190 
192 {
193 
194  if(evtsToDebug_.size())
195  {
196  std::vector<unsigned int>::const_iterator itcheck=find(evtsToDebug_.begin(),evtsToDebug_.end(),mySimEvent->id().event());
197  debug_=(itcheck!=evtsToDebug_.end());
198  if(debug_)
199  mySimEvent->print();
200  }
201  // Clear the content of the calorimeters
202  if(!initialized_)
203  {
204 
205  // Check if the preshower is really available
207  {
208  std::cout << " WARNING " << std::endl;
209  std::cout << " The preshower simulation has been turned on; but no preshower geometry is available " << std::endl;
210  std::cout << " Disabling the preshower simulation " << std::endl;
211  simulatePreshower_ = false;
212  }
213 
214  initialized_=true;
215  }
216  clean();
217 
218  LogInfo("FastCalorimetry") << "Reconstructing " << (int) mySimEvent->nTracks() << " tracks." << std::endl;
219  for( int fsimi=0; fsimi < (int) mySimEvent->nTracks() ; ++fsimi) {
220 
221  FSimTrack& myTrack = mySimEvent->track(fsimi);
222 
223  int pid = abs(myTrack.type());
224 
225  if (debug_) {
226  LogInfo("FastCalorimetry") << " ===> pid = " << pid << std::endl;
227  }
228 
229 
230  // Check that the particle hasn't decayed
231  if(myTrack.noEndVertex()) {
232  // Simulate energy smearing for photon and electrons
233  if ( pid == 11 || pid == 22 ) {
234 
235  if ( myTrack.onEcal() )
236  EMShowerSimulation(myTrack, random);
237  else if ( myTrack.onVFcal() )
238  reconstructHCAL(myTrack, random);
239 
240  } // electron or photon
241  else if (pid==13)
242  {
243  MuonMipSimulation(myTrack, random);
244  }
245  // Simulate energy smearing for hadrons (i.e., everything
246  // but muons... and SUSY particles that deserve a special
247  // treatment.
248  else if ( pid < 1000000 ) {
249  if ( myTrack.onHcal() || myTrack.onVFcal() ) {
250  if(optionHDSim_ == 0 ) reconstructHCAL(myTrack, random);
251  else HDShowerSimulation(myTrack, random);
252  }
253  } // pid < 1000000
254  } // myTrack.noEndVertex()
255  } // particle loop
256  // LogInfo("FastCalorimetry") << " Number of hits (barrel)" << EBMapping_.size() << std::endl;
257  // LogInfo("FastCalorimetry") << " Number of hits (Hcal)" << HMapping_.size() << std::endl;
258  // std::cout << " Nombre de hit (endcap)" << EEMapping_.size() << std::endl;
259 
260 } // reconstruct
261 
262 // Simulation of electromagnetic showers in PS, ECAL, HCAL
265  std::vector<const RawParticle*> thePart;
266  double X0depth;
267 
268  if (debug_) {
269  LogInfo("FastCalorimetry") << " EMShowerSimulation " <<myTrack << std::endl;
270  }
271 
272  // std::cout << " Simulating " << myTrack << std::endl;
273 
274  // The Particle at ECAL entrance
275  // std::cout << " Before ecalEntrance " << std::endl;
276  myPart = myTrack.ecalEntrance();
277 
278  // protection against infinite loop.
279  if ( myTrack.type() == 22 && myPart.e()<0.055) return;
280 
281 
282  // Barrel or Endcap ?
283  int onEcal = myTrack.onEcal();
284  int onHcal = myTrack.onHcal();
285  int onLayer1 = myTrack.onLayer1();
286  int onLayer2 = myTrack.onLayer2();
287 
288  // The entrance in ECAL
289  XYZPoint ecalentrance = myPart.vertex().Vect();
290 
291  // std::cout << " Ecal entrance " << ecalentrance << std::endl;
292 
293  // The preshower
294  PreshowerHitMaker * myPreshower = NULL ;
295  if(simulatePreshower_ && (onLayer1 || onLayer2))
296  {
297  XYZPoint layer1entrance,layer2entrance;
298  XYZVector dir1,dir2;
299  if(onLayer1)
300  {
301  layer1entrance = XYZPoint(myTrack.layer1Entrance().vertex().Vect());
302  dir1 = XYZVector(myTrack.layer1Entrance().Vect().Unit());
303  }
304  if(onLayer2)
305  {
306  layer2entrance = XYZPoint(myTrack.layer2Entrance().vertex().Vect());
307  dir2 = XYZVector(myTrack.layer2Entrance().Vect().Unit());
308  }
309  // std::cout << " Layer1entrance " << layer1entrance << std::endl;
310  // std::cout << " Layer2entrance " << layer2entrance << std::endl;
311  myPreshower = new PreshowerHitMaker(myCalorimeter_,
312  layer1entrance,
313  dir1,
314  layer2entrance,
315  dir2,
317  random);
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 
499 {
500  int hit;
501  int pid = abs(myTrack.type());
502  if (debug_) {
503  LogInfo("FastCalorimetry") << " reconstructHCAL " << myTrack << std::endl;
504  }
505 
506  // FSimTrack myTrack = mySimEvent.track(fsimi);
507 
508  // int pid=abs(myTrack.type());
509  // std::cout << "reconstructHCAL " << std::endl;
510 
511  XYZTLorentzVector trackPosition;
512  if (myTrack.onHcal()) {
513  trackPosition=myTrack.hcalEntrance().vertex();
514  hit = myTrack.onHcal()-1;
515  } else {
516  trackPosition=myTrack.vfcalEntrance().vertex();
517  hit = 2;
518  }
519 
520  double pathEta = trackPosition.eta();
521  double pathPhi = trackPosition.phi();
522  // double pathTheta = trackPosition.theta();
523 
524  double EGen = myTrack.hcalEntrance().e();
525  double emeas = 0.;
526  //double emeas = -0.0001;
527 
528  if(pid == 13) {
529  // std::cout << " We should not be here " << std::endl;
530  emeas = myHDResponse_->responseHCAL(0, EGen, pathEta, 2, random); // 2=muon
531  if(debug_)
532  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - MUON !!!" << std::endl;
533  }
534  else if( pid == 22 || pid == 11) {
535  emeas = myHDResponse_->responseHCAL(0, EGen, pathEta, 0, random); // last par. = 0 = e/gamma
536  // cout << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
537  if(debug_)
538  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
539  }
540  else {
541  emeas = myHDResponse_->getHCALEnergyResponse(EGen, hit, random);
542  }
543 
544  if(debug_)
545  LogInfo("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - on-calo "
546  << " eta = " << pathEta
547  << " phi = " << pathPhi
548  << " Egen = " << EGen
549  << " Emeas = " << emeas << std::endl;
550 
551  if(emeas > 0.) {
552  DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
553  double tof = (myCalorimeter_->getHcalGeometry()->getGeometry(cell)->getPosition().mag())/29.98;//speed of light
554  CaloHitID current_id(cell.rawId(),tof,myTrack.id());
555  std::map<CaloHitID,float> hitMap;
556  hitMap[current_id] = emeas;
557  updateHCAL(hitMap,myTrack.id());
558  }
559 }
560 
562  // const edm::ParameterSet& fastCalo){
563 
564  // TimeMe t(" FASTEnergyReconstructor::HDShower");
565  XYZTLorentzVector moment = myTrack.momentum();
566 
567  if(debug_)
568  LogInfo("FastCalorimetry")
569  << "CalorimetryManager::HDShowerSimulation - track param."
570  << std::endl
571  << " eta = " << moment.eta() << std::endl
572  << " phi = " << moment.phi() << std::endl
573  << " et = " << moment.Et() << std::endl
574  << " e = " << myTrack.hcalEntrance().e() << std::endl;
575 
576  if (debug_) {
577  LogInfo("FastCalorimetry") << " HDShowerSimulation " << myTrack << std::endl;
578  }
579 
580 
581  int hit;
582  // int pid = abs(myTrack.type());
583 
584  XYZTLorentzVector trackPosition;
585  if ( myTrack.onEcal() ) {
586  trackPosition=myTrack.ecalEntrance().vertex();
587  hit = myTrack.onEcal()-1; //
588  myPart = myTrack.ecalEntrance();
589  } else if ( myTrack.onVFcal()) {
590  trackPosition=myTrack.vfcalEntrance().vertex();
591  hit = 2;
592  myPart = myTrack.vfcalEntrance();
593  }
594  else
595  {
596  LogInfo("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
597  return;
598  }
599 
600  // int onHCAL = hit + 1; - specially for myCalorimeter->hcalProperties(onHCAL)
601  // (below) to get VFcal properties ...
602  int onHCAL = hit + 1;
603  int onECAL = myTrack.onEcal();
604 
605  double pathEta = trackPosition.eta();
606  double pathPhi = trackPosition.phi();
607  // double pathTheta = trackPosition.theta();
608 
609  double eint = moment.e();
610  double eGen = myTrack.hcalEntrance().e();
611 
612  double emeas = 0.;
613  double pmip= myHDResponse_->getMIPfraction(eGen, pathEta);
614 // std::cout << " CalorimetryManager onHcal " << pmip << std::endl;
615 
616 
617  //double emeas = -0.000001;
618 
619  //===========================================================================
620  if(eGen > 0.) {
621 
622  // ECAL and HCAL properties to get
624  theHDShowerparam(myCalorimeter_->ecalProperties(onECAL),
627 
628  //Making ECAL Grid (and segments calculation)
629  XYZPoint caloentrance;
630  XYZVector direction;
631  if(myTrack.onEcal())
632  {
633  caloentrance = myTrack.ecalEntrance().vertex().Vect();
634  direction = myTrack.ecalEntrance().Vect().Unit();
635  }
636  else if(myTrack.onHcal())
637  {
638  caloentrance = myTrack.hcalEntrance().vertex().Vect();
639  direction = myTrack.hcalEntrance().Vect().Unit();
640  }
641  else
642  {
643  caloentrance = myTrack.vfcalEntrance().vertex().Vect();
644  direction = myTrack.vfcalEntrance().Vect().Unit();
645  }
646 
647  if(debug_)
648  LogInfo("FastCalorimetry")
649  << "CalorimetryManager::HDShowerSimulation - on-calo 1 "
650  << std::endl
651  << " onEcal = " << myTrack.onEcal() << std::endl
652  << " onHcal = " << myTrack.onHcal() << std::endl
653  << " onVFcal = " << myTrack.onVFcal() << std::endl
654  << " position = " << caloentrance << std::endl;
655 
656 
657  DetId pivot;
658  if(myTrack.onEcal())
659  {
660  pivot=myCalorimeter_->getClosestCell(caloentrance,
661  true, myTrack.onEcal()==1);
662  }
663  else if(myTrack.onHcal())
664  {
665  // std::cout << " CalorimetryManager onHcal " << myTrack.onHcal() << " caloentrance" << caloentrance << std::endl;
666  pivot=myCalorimeter_->getClosestCell(caloentrance,
667  false, false);
668  }
669 
670  EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
671  pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,1,
672  random);
673  // 1=HAD shower
674 
675  myGrid.setTrackParameters(direction,0,myTrack);
676  // Build the FAMOS HCAL
677  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)1);
678 
679  // Shower simulation
680  bool status = false;
681  int mip = 2;
682  // Use HFShower for HF
683  if ( !myTrack.onEcal() && !myTrack.onHcal() ) {
684  // std::cout << "CalorimetryManager::HDShowerSimulation(): track entrance = "
685  // << myTrack.vfcalEntrance().vertex().X() << " "
686  // << myTrack.vfcalEntrance().vertex().Y() << " "
687  // << myTrack.vfcalEntrance().vertex().Z() << " "
688  // << " , Energy (Gen/Scale) = " << eGen << " " << e << std::endl;
689 
690  // Warning : We give here the particle energy with the response
691  // but without the resolution/gaussian smearing
692  // For HF, the resolution is due to the PE statistic
693 
694  HFShower theShower(random,
695  &theHDShowerparam,
696  &myGrid,
697  &myHcalHitMaker,
698  onECAL,
699  eGen);
700  // eGen);
701  // e); // PV Warning : temporarly set the energy to the generated E
702 
703  status = theShower.compute();
704  } else {
705  if(hdSimMethod_ == 0) {
706  HDShower theShower(random,
707  &theHDShowerparam,
708  &myGrid,
709  &myHcalHitMaker,
710  onECAL,
711  eGen,
712  pmip,
713  dbe);
714  status = theShower.compute();
715  mip = theShower.getmip();
716  }
717  else if (hdSimMethod_ == 1) {
718  HDRShower theShower(random,
719  &theHDShowerparam,
720  &myGrid,
721  &myHcalHitMaker,
722  onECAL,
723  eGen);
724  status = theShower.computeShower();
725  mip = 2;
726  }
727  else if (hdSimMethod_ == 2 ) {
728  // std::cout << "Using GflashHadronShowerProfile hdSimMethod_ == 2" << std::endl;
729 
730  //dynamically loading a corresponding profile by the particle type
731  int particleType = myTrack.type();
733  if(particleType == -2212) theProfile = theAntiProtonProfile;
734  else if(particleType == 2212) theProfile = theProtonProfile;
735 
736  //input variables for GflashHadronShowerProfile
737  int showerType = 99 + myTrack.onEcal();
738  double globalTime = 150.0; // a temporary reference hit time in nanosecond
739  float charge = (float)(myTrack.charge());
740  Gflash3Vector gfpos(trackPosition.X(),trackPosition.Y(),trackPosition.Z());
741  Gflash3Vector gfmom(moment.X(),moment.Y(),moment.Z());
742 
743  theProfile->initialize(showerType,eGen,globalTime,charge,gfpos,gfmom);
746 
747  //make hits
748  std::vector<GflashHit>& gflashHitList = theProfile->getGflashHitList();
749  std::vector<GflashHit>::const_iterator spotIter = gflashHitList.begin();
750  std::vector<GflashHit>::const_iterator spotIterEnd = gflashHitList.end();
751 
753 
754  for( ; spotIter != spotIterEnd; spotIter++){
755 
756  double pathLength = theProfile->getGflashShowino()->getPathLengthAtShower()
757  + (30*100/eGen)*(spotIter->getTime() - globalTime);
758 
759  double currentDepth = std::max(0.0,pathLength - theProfile->getGflashShowino()->getPathLengthOnEcal());
760 
761  //find the the showino position at the currentDepth
762  GflashTrajectoryPoint trajectoryPoint;
763  theProfile->getGflashShowino()->getHelix()->getGflashTrajectoryPoint(trajectoryPoint,pathLength);
764  Gflash3Vector positionAtCurrentDepth = trajectoryPoint.getPosition();
765  //find radial distrance
766  Gflash3Vector lateralDisplacement = positionAtCurrentDepth - spotIter->getPosition()/CLHEP::cm;
767  double rShower = lateralDisplacement.r();
768  double azimuthalAngle = lateralDisplacement.phi();
769 
770  whichCalor = Gflash::getCalorimeterNumber(positionAtCurrentDepth);
771 
772  if(whichCalor==Gflash::kESPM || whichCalor==Gflash::kENCA) {
773  bool statusPad = myGrid.getPads(currentDepth,true);
774  if(!statusPad) continue;
775  myGrid.setSpotEnergy(1.2*spotIter->getEnergy()/CLHEP::GeV);
776  myGrid.addHit(rShower/Gflash::intLength[Gflash::kESPM],azimuthalAngle,0);
777  }
778  else if(whichCalor==Gflash::kHB || whichCalor==Gflash::kHE) {
779  bool setHDdepth = myHcalHitMaker.setDepth(currentDepth,true);
780  if(!setHDdepth) continue;
781  myHcalHitMaker.setSpotEnergy(1.4*spotIter->getEnergy()/CLHEP::GeV);
782  myHcalHitMaker.addHit(rShower/Gflash::intLength[Gflash::kHB],azimuthalAngle,0);
783  }
784  }
785  status = true;
786  }
787  else {
788  edm::LogInfo("FastSimulationCalorimetry") << " SimMethod " << hdSimMethod_ <<" is NOT available ";
789  }
790  }
791 
792 
793  if(status) {
794 
795  // Here to switch between simple formulae and parameterized response
796  if(optionHDSim_ == 1) {
797  emeas = myHDResponse_->getHCALEnergyResponse(eGen, hit, random);
798  }
799  else { // optionHDsim == 2
800  emeas = myHDResponse_->responseHCAL(mip, eGen, pathEta, 1, random); // 1=hadron
801  }
802 
803  double correction = emeas / eGen;
804 
805  // RespCorrP factors (ECAL and HCAL separately) calculation
806  respCorr(eint);
807 
808  if(debug_)
809  LogInfo("FastCalorimetry")
810  << "CalorimetryManager::HDShowerSimulation - on-calo 2" << std::endl
811  << " eta = " << pathEta << std::endl
812  << " phi = " << pathPhi << std::endl
813  << " Egen = " << eGen << std::endl
814  << " Emeas = " << emeas << std::endl
815  << " corr = " << correction << std::endl
816  << " mip = " << mip << std::endl;
817 
818  if(myTrack.onEcal() > 0) {
819  // Save ECAL hits
820  updateECAL(myGrid.getHits(),onECAL,myTrack.id(),correction*ecorr);
821  }
822 
823  // Save HCAL hits
824  updateHCAL(myHcalHitMaker.getHits(),myTrack.id(),correction*hcorr);
825 
826  }
827  else { // shower simulation failed
828 // std::cout << " Shower simulation failed " << trackPosition.Vect() << std::endl;
829 // std::cout << " The FSimTrack " << myTrack << std::endl;
830 // std::cout << " HF entrance on VFcal" << myTrack.onVFcal() << std::endl;
831 // std::cout << " trackPosition.eta() " << trackPosition.eta() << std::endl;
832  if(myTrack.onHcal() || myTrack.onVFcal())
833  {
834  DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
835  double tof = (myCalorimeter_->getHcalGeometry()->getGeometry(cell)->getPosition().mag())/29.98;//speed of light
836  CaloHitID current_id(cell.rawId(),tof,myTrack.id());
837  std::map<CaloHitID,float> hitMap;
838  hitMap[current_id] = emeas;
839  updateHCAL(hitMap,myTrack.id());
840  if(debug_)
841  LogInfo("FastCalorimetry") << " HCAL simple cell "
842  << cell.rawId() << " added E = "
843  << emeas << std::endl;
844  }
845  }
846 
847  } // e > 0. ...
848 
849  if(debug_)
850  LogInfo("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::HDShowerSimulation finished "
851  << std::endl;
852 }
853 
854 
856 {
857  // TimeMe t(" FASTEnergyReconstructor::HDShower");
858  XYZTLorentzVector moment = myTrack.momentum();
859 
860  // Backward compatibility behaviour
861  if(!theMuonHcalEffects)
862  {
863  if(myTrack.onHcal() || myTrack.onVFcal() )
864  reconstructHCAL(myTrack, random);
865 
866  return;
867  }
868 
869  if(debug_)
870  LogInfo("FastCalorimetry") << "CalorimetryManager::MuonMipSimulation - track param."
871  << std::endl
872  << " eta = " << moment.eta() << std::endl
873  << " phi = " << moment.phi() << std::endl
874  << " et = " << moment.Et() << std::endl;
875 
876  // int hit;
877  // int pid = abs(myTrack.type());
878 
879  XYZTLorentzVector trackPosition;
880  if ( myTrack.onEcal() ) {
881  trackPosition=myTrack.ecalEntrance().vertex();
882  // hit = myTrack.onEcal()-1; //
883  myPart = myTrack.ecalEntrance();
884  } else if ( myTrack.onVFcal()) {
885  trackPosition=myTrack.vfcalEntrance().vertex();
886  // hit = 2;
887  myPart = myTrack.vfcalEntrance();
888  }
889  else
890  {
891  LogInfo("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
892  return;
893  }
894 
895  // int onHCAL = hit + 1; - specially for myCalorimeter->hcalProperties(onHCAL)
896  // (below) to get VFcal properties ...
897  // not needed ?
898  // int onHCAL = hit + 1;
899  int onECAL = myTrack.onEcal();
900 
901  // double pathEta = trackPosition.eta();
902  // double pathPhi = trackPosition.phi();
903  // double pathTheta = trackPosition.theta();
904 
905  //===========================================================================
906 
907  // ECAL and HCAL properties to get
908 
909  //Making ECAL Grid (and segments calculation)
910  XYZPoint caloentrance;
911  XYZVector direction;
912  if(myTrack.onEcal())
913  {
914  caloentrance = myTrack.ecalEntrance().vertex().Vect();
915  direction = myTrack.ecalEntrance().Vect().Unit();
916  }
917  else if(myTrack.onHcal())
918  {
919  caloentrance = myTrack.hcalEntrance().vertex().Vect();
920  direction = myTrack.hcalEntrance().Vect().Unit();
921  }
922  else
923  {
924  caloentrance = myTrack.vfcalEntrance().vertex().Vect();
925  direction = myTrack.vfcalEntrance().Vect().Unit();
926  }
927 
928  DetId pivot;
929  if(myTrack.onEcal())
930  {
931  pivot=myCalorimeter_->getClosestCell(caloentrance,
932  true, myTrack.onEcal()==1);
933  }
934  else if(myTrack.onHcal())
935  {
936  // std::cout << " CalorimetryManager onHcal " << myTrack.onHcal() << " caloentrance" << caloentrance << std::endl;
937  pivot=myCalorimeter_->getClosestCell(caloentrance,
938  false, false);
939  }
940 
941  EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
942  pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,0,
943  random);
944  // 0 =EM shower -> Unit = X0
945 
946  myGrid.setTrackParameters(direction,0,myTrack);
947 
948  // Now get the path in the Preshower, ECAL and HCAL along a straight line extrapolation
949  // but only those in the ECAL are used
950 
951  const std::vector<CaloSegment>& segments=myGrid.getSegments();
952  unsigned nsegments=segments.size();
953 
954  int ifirstHcal=-1;
955  int ilastEcal=-1;
956 
957  EnergyLossSimulator* energyLossECAL = 0;
959  // // Muon brem in ECAL
960  // MuonBremsstrahlungSimulator* muonBremECAL = 0;
961  // if (theMuonEcalEffects) muonBremECAL = theMuonEcalEffects->muonBremsstrahlungSimulator();
962 
963  for(unsigned iseg=0;iseg<nsegments&&ifirstHcal<0;++iseg)
964  {
965 
966  // in the ECAL, there are two types of segments: PbWO4 and GAP
967  float segmentSizeinX0=segments[iseg].X0length();
968 
969  // Martijn - insert your computations here
970  float energy=0.0;
971  if (segmentSizeinX0>0.001 && segments[iseg].material()==CaloSegment::PbWO4 ) {
972  // The energy loss simulator
973  float charge = (float)(myTrack.charge());
974  ParticlePropagator theMuon(moment,trackPosition,charge,0);
975  theMuon.setID(-(int)charge*13);
976  if ( energyLossECAL ) {
977  energyLossECAL->updateState(theMuon, segmentSizeinX0, random);
978  energy = energyLossECAL->deltaMom().E();
979  moment -= energyLossECAL->deltaMom();
980  }
981  }
982  // that's all for ECAL, Florian
983  // Save the hit only if it is a crystal
984  if(segments[iseg].material()==CaloSegment::PbWO4)
985  {
986  myGrid.getPads(segments[iseg].sX0Entrance()+segmentSizeinX0*0.5);
987  myGrid.setSpotEnergy(energy);
988  myGrid.addHit(0.,0.);
989  ilastEcal=iseg;
990  }
991  // Check for end of loop:
992  if(segments[iseg].material()==CaloSegment::HCAL)
993  {
994  ifirstHcal=iseg;
995  }
996  }
997 
998 
999  // Build the FAMOS HCAL
1000  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)2);
1001  // float mipenergy=0.1;
1002  // Create the helix with the stepping helix propagator
1003  // to add a hit, just do
1004  // myHcalHitMaker.setSpotEnergy(mipenergy);
1005  // math::XYZVector hcalEntrance;
1006  // if(ifirstHcal>=0) hcalEntrance=segments[ifirstHcal].entrance();
1007  // myHcalHitMaker.addHit(hcalEntrance);
1011  int ilastHcal=-1;
1012  float mipenergy=0.0;
1013 
1014  EnergyLossSimulator* energyLossHCAL = 0;
1016  // // Muon Brem effect
1017  // MuonBremsstrahlungSimulator* muonBremHCAL = 0;
1018  // if (theMuonHcalEffects) muonBremHCAL = theMuonHcalEffects->muonBremsstrahlungSimulator();
1019 
1020  if(ifirstHcal>0 && energyLossHCAL){
1021  for(unsigned iseg=ifirstHcal;iseg<nsegments;++iseg)
1022  {
1023  float segmentSizeinX0=segments[iseg].X0length();
1024  if(segments[iseg].material()==CaloSegment::HCAL) {
1025  ilastHcal=iseg;
1026  if (segmentSizeinX0>0.001) {
1027  // The energy loss simulator
1028  float charge = (float)(myTrack.charge());
1029  ParticlePropagator theMuon(moment,trackPosition,charge,0);
1030  theMuon.setID(-(int)charge*13);
1031  energyLossHCAL->updateState(theMuon, segmentSizeinX0, random);
1032  mipenergy = energyLossHCAL->deltaMom().E();
1033  moment -= energyLossHCAL->deltaMom();
1034  myHcalHitMaker.setSpotEnergy(mipenergy);
1035  myHcalHitMaker.addHit(segments[iseg].entrance());
1036  }
1037  }
1038  }
1039  }
1040 
1045  //
1046 
1047 
1048 
1049  // Copy the muon SimTrack (Only for Energy loss)
1050  FSimTrack muonTrack(myTrack);
1051  if(energyLossHCAL && ilastHcal>=0) {
1052  math::XYZVector hcalExit=segments[ilastHcal].exit();
1053  muonTrack.setTkPosition(hcalExit);
1054  muonTrack.setTkMomentum(moment);
1055  } else if(energyLossECAL && ilastEcal>=0) {
1056  math::XYZVector ecalExit=segments[ilastEcal].exit();
1057  muonTrack.setTkPosition(ecalExit);
1058  muonTrack.setTkMomentum(moment);
1059  } // else just leave tracker surface position and momentum...
1060 
1061  muonSimTracks.push_back(muonTrack);
1062 
1063 
1064  // no need to change below this line
1065  std::map<CaloHitID,float>::const_iterator mapitr;
1066  std::map<CaloHitID,float>::const_iterator endmapitr;
1067  if(myTrack.onEcal() > 0) {
1068  // Save ECAL hits
1069  updateECAL(myGrid.getHits(),onECAL,myTrack.id());
1070  }
1071 
1072  // Save HCAL hits
1073  updateHCAL(myHcalHitMaker.getHits(),myTrack.id());
1074 
1075  if(debug_)
1076  LogInfo("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::MipShowerSimulation finished "
1077  << std::endl;
1078 }
1079 
1080 
1082 
1083  edm::ParameterSet ECALparameters = fastCalo.getParameter<edm::ParameterSet>("ECAL");
1084 
1085  evtsToDebug_ = fastCalo.getUntrackedParameter<std::vector<unsigned int> >("EvtsToDebug",std::vector<unsigned>());
1086  debug_ = fastCalo.getUntrackedParameter<bool>("Debug");
1087  useDQM_ = fastCalo.getUntrackedParameter<bool>("useDQM");
1088 
1089  bFixedLength_ = ECALparameters.getParameter<bool>("bFixedLength");
1090  // std::cout << "bFixedLength_ = " << bFixedLength_ << std::endl;
1091 
1092  gridSize_ = ECALparameters.getParameter<int>("GridSize");
1093  spotFraction_ = ECALparameters.getParameter<double>("SpotFraction");
1094  pulledPadSurvivalProbability_ = ECALparameters.getParameter<double>("FrontLeakageProbability");
1095  crackPadSurvivalProbability_ = ECALparameters.getParameter<double>("GapLossProbability");
1096  theCoreIntervals_ = ECALparameters.getParameter<std::vector<double> >("CoreIntervals");
1097  theTailIntervals_ = ECALparameters.getParameter<std::vector<double> >("TailIntervals");
1098 
1099  RCFactor_ = ECALparameters.getParameter<double>("RCFactor");
1100  RTFactor_ = ECALparameters.getParameter<double>("RTFactor");
1101  //changed after tuning - Feb-July - Shilpi Jain
1102  // radiusFactor_ = ECALparameters.getParameter<double>("RadiusFactor");
1103  radiusFactorEE_ = ECALparameters.getParameter<double>("RadiusFactorEE");
1104  radiusFactorEB_ = ECALparameters.getParameter<double>("RadiusFactorEB");
1105  //(end of) changed after tuning - Feb-July - Shilpi Jain
1106  radiusPreshowerCorrections_ = ECALparameters.getParameter<std::vector<double> >("RadiusPreshowerCorrections");
1107  aTerm = 1.+radiusPreshowerCorrections_[1]*radiusPreshowerCorrections_[0];
1108  bTerm = radiusPreshowerCorrections_[0];
1109  mipValues_ = ECALparameters.getParameter<std::vector<double> >("MipsinGeV");
1110  simulatePreshower_ = ECALparameters.getParameter<bool>("SimulatePreshower");
1111 
1112  if(gridSize_ <1) gridSize_= 7;
1113  if(pulledPadSurvivalProbability_ <0. || pulledPadSurvivalProbability_>1 ) pulledPadSurvivalProbability_= 1.;
1114  if(crackPadSurvivalProbability_ <0. || crackPadSurvivalProbability_>1 ) crackPadSurvivalProbability_= 0.9;
1115 
1116  LogInfo("FastCalorimetry") << " Fast ECAL simulation parameters " << std::endl;
1117  LogInfo("FastCalorimetry") << " =============================== " << std::endl;
1118  if(simulatePreshower_)
1119  LogInfo("FastCalorimetry") << " The preshower is present " << std::endl;
1120  else
1121  LogInfo("FastCalorimetry") << " The preshower is NOT present " << std::endl;
1122  LogInfo("FastCalorimetry") << " Grid Size : " << gridSize_ << std::endl;
1123  if(spotFraction_>0.)
1124  LogInfo("FastCalorimetry") << " Spot Fraction : " << spotFraction_ << std::endl;
1125  else
1126  {
1127  LogInfo("FastCalorimetry") << " Core of the shower " << std::endl;
1128  for(unsigned ir=0; ir < theCoreIntervals_.size()/2;++ir)
1129  {
1130  LogInfo("FastCalorimetry") << " r < " << theCoreIntervals_[ir*2] << " R_M : " << theCoreIntervals_[ir*2+1] << " ";
1131  }
1132  LogInfo("FastCalorimetry") << std::endl;
1133 
1134  LogInfo("FastCalorimetry") << " Tail of the shower " << std::endl;
1135  for(unsigned ir=0; ir < theTailIntervals_.size()/2;++ir)
1136  {
1137  LogInfo("FastCalorimetry") << " r < " << theTailIntervals_[ir*2] << " R_M : " << theTailIntervals_[ir*2+1] << " ";
1138  }
1139  //changed after tuning - Feb-July - Shilpi Jain
1140  // LogInfo("FastCalorimetry") << "Radius correction factor " << radiusFactor_ << std::endl;
1141  LogInfo("FastCalorimetry") << "Radius correction factors: EB & EE " << radiusFactorEB_ << " : "<< radiusFactorEE_ << std::endl;
1142  //(end of) changed after tuning - Feb-July - Shilpi Jain
1143  LogInfo("FastCalorimetry") << std::endl;
1144  if(mipValues_.size()>2) {
1145  LogInfo("FastCalorimetry") << "Improper number of parameters for the preshower ; using 95keV" << std::endl;
1146  mipValues_.clear();
1147  mipValues_.resize(2,0.000095);
1148  }
1149  }
1150 
1151  LogInfo("FastCalorimetry") << " FrontLeakageProbability : " << pulledPadSurvivalProbability_ << std::endl;
1152  LogInfo("FastCalorimetry") << " GapLossProbability : " << crackPadSurvivalProbability_ << std::endl;
1153 
1154 
1155  // RespCorrP: p (momentum), ECAL and HCAL corrections = f(p)
1156  edm::ParameterSet CalorimeterParam = fastCalo.getParameter<edm::ParameterSet>("CalorimeterProperties");
1157 
1158  rsp = CalorimeterParam.getParameter<std::vector<double> >("RespCorrP");
1159  LogInfo("FastCalorimetry") << " RespCorrP (rsp) size " << rsp.size() << std::endl;
1160 
1161  if( rsp.size()%3 !=0 ) {
1162  LogInfo("FastCalorimetry")
1163  << " RespCorrP size is wrong -> no corrections applied !!!"
1164  << std::endl;
1165 
1166  p_knots.push_back(14000.);
1167  k_e.push_back (1.);
1168  k_h.push_back (1.);
1169  }
1170  else {
1171  for(unsigned i = 0; i < rsp.size(); i += 3) {
1172  LogInfo("FastCalorimetry") << "i = " << i/3 << " p = " << rsp [i]
1173  << " k_e(p) = " << rsp[i+1]
1174  << " k_e(p) = " << rsp[i+2] << std::endl;
1175 
1176  p_knots.push_back(rsp[i]);
1177  k_e.push_back (rsp[i+1]);
1178  k_h.push_back (rsp[i+2]);
1179  }
1180  }
1181 
1182 
1183  //FR
1184  edm::ParameterSet HCALparameters = fastCalo.getParameter<edm::ParameterSet>("HCAL");
1185  optionHDSim_ = HCALparameters.getParameter<int>("SimOption");
1186  hdGridSize_ = HCALparameters.getParameter<int>("GridSize");
1187  hdSimMethod_ = HCALparameters.getParameter<int>("SimMethod");
1188  //RF
1189 
1190  EcalDigitizer_ = ECALparameters.getUntrackedParameter<bool>("Digitizer",false);
1191  HcalDigitizer_ = HCALparameters.getUntrackedParameter<bool>("Digitizer",false);
1192  samplingHBHE_ = HCALparameters.getParameter< std::vector<double> >("samplingHBHE");
1193  samplingHF_ = HCALparameters.getParameter< std::vector<double> >("samplingHF");
1194  samplingHO_ = HCALparameters.getParameter< std::vector<double> >("samplingHO");
1195  ietaShiftHB_ = HCALparameters.getParameter< int >("ietaShiftHB");
1196  ietaShiftHE_ = HCALparameters.getParameter< int >("ietaShiftHE");
1197  ietaShiftHF_ = HCALparameters.getParameter< int >("ietaShiftHF");
1198  ietaShiftHO_ = HCALparameters.getParameter< int >("ietaShiftHO");
1199  timeShiftHB_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHB");
1200  timeShiftHE_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHE");
1201  timeShiftHF_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHF");
1202  timeShiftHO_ = HCALparameters.getParameter< std::vector<double> >("timeShiftHO");
1203 
1204 }
1205 
1207 
1208  int sizeP = p_knots.size();
1209 
1210  if(sizeP <= 1) {
1211  ecorr = 1.;
1212  hcorr = 1.;
1213  }
1214  else {
1215  int ip = -1;
1216  for (int i = 0; i < sizeP; i++) {
1217  if (p < p_knots[i]) { ip = i; break;}
1218  }
1219  if (ip == 0) {
1220  ecorr = k_e[0];
1221  hcorr = k_h[0];
1222  }
1223  else {
1224  if(ip == -1) {
1225  ecorr = k_e[sizeP-1];
1226  hcorr = k_h[sizeP-1];
1227  }
1228  else {
1229  double x1 = p_knots[ip-1];
1230  double x2 = p_knots[ip];
1231  double y1 = k_e[ip-1];
1232  double y2 = k_e[ip];
1233 
1234  if(x1 == x2) {
1235  // std::cout << " equal p_knots values!!! " << std::endl;
1236  }
1237 
1238  ecorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
1239 
1240  y1 = k_h[ip-1];
1241  y2 = k_h[ip];
1242  hcorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
1243 
1244  }
1245  }
1246  }
1247 
1248  if(debug_)
1249  LogInfo("FastCalorimetry") << " p, ecorr, hcorr = " << p << " "
1250  << ecorr << " " << hcorr << std::endl;
1251 
1252 }
1253 
1254 void CalorimetryManager::updateECAL(const std::map<CaloHitID,float>& hitMap, int onEcal, int trackID, float corr)
1255 {
1256  std::map<CaloHitID,float>::const_iterator mapitr;
1257  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1258  if(onEcal==1) {
1259  EBMapping_.reserve(EBMapping_.size()+hitMap.size());
1260  endmapitr=hitMap.end();
1261  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1262  //correct energy
1263  float energy = mapitr->second;
1264  energy *= corr;
1265 
1266  //make finalized CaloHitID
1267  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1268 
1269  EBMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1270  }
1271  }
1272  else if(onEcal==2) {
1273  EEMapping_.reserve(EEMapping_.size()+hitMap.size());
1274  endmapitr=hitMap.end();
1275  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1276  //correct energy
1277  float energy = mapitr->second;
1278  energy *= corr;
1279 
1280  //make finalized CaloHitID
1281  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1282 
1283  EEMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1284  }
1285  }
1286 
1287 }
1288 
1289 void CalorimetryManager::updateHCAL(const std::map<CaloHitID,float>& hitMap, int trackID, float corr)
1290 {
1291  std::map<CaloHitID,float>::const_iterator mapitr;
1292  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1293  HMapping_.reserve(HMapping_.size()+hitMap.size());
1294  for(mapitr=hitMap.begin(); mapitr!=endmapitr; ++mapitr) {
1295  //correct energy
1296  float energy = mapitr->second;
1297  energy *= corr;
1298 
1299  float time = mapitr->first.timeSlice();
1300  //put energy into uncalibrated state for digitizer && correct timing
1301  if(HcalDigitizer_){
1302  HcalDetId hdetid = HcalDetId(mapitr->first.unitID());
1303  if (hdetid.subdetId()== HcalBarrel){
1304  energy /= samplingHBHE_[hdetid.ietaAbs()-1]; //re-convert to GeV
1305  time = timeShiftHB_[hdetid.ietaAbs()-ietaShiftHB_];
1306  }
1307  else if (hdetid.subdetId()== HcalEndcap){
1308  energy /= samplingHBHE_[hdetid.ietaAbs()-1]; //re-convert to GeV
1309  time = timeShiftHE_[hdetid.ietaAbs()-ietaShiftHE_];
1310  }
1311  else if (hdetid.subdetId()== HcalForward){
1312  if(hdetid.depth()== 1) energy *= samplingHF_[0];
1313  if(hdetid.depth()== 2) energy *= samplingHF_[1];
1314  time = timeShiftHF_[hdetid.ietaAbs()-ietaShiftHF_];
1315  }
1316  else if (hdetid.subdetId()== HcalOuter){
1317  energy /= samplingHO_[hdetid.ietaAbs()-1];
1318  time = timeShiftHO_[hdetid.ietaAbs()-ietaShiftHO_];
1319  }
1320  }
1321 
1322  //make finalized CaloHitID
1323  CaloHitID current_id(mapitr->first.unitID(),time,trackID);
1324  HMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1325  }
1326 }
1327 
1328 void CalorimetryManager::updatePreshower(const std::map<CaloHitID,float>& hitMap, int trackID, float corr)
1329 {
1330  std::map<CaloHitID,float>::const_iterator mapitr;
1331  std::map<CaloHitID,float>::const_iterator endmapitr=hitMap.end();
1332  ESMapping_.reserve(ESMapping_.size()+hitMap.size());
1333  for(mapitr=hitMap.begin();mapitr!=endmapitr;++mapitr) {
1334  //correct energy
1335  float energy = mapitr->second;
1336  energy *= corr;
1337 
1338  //make finalized CaloHitID
1339  CaloHitID current_id(mapitr->first.unitID(),mapitr->first.timeSlice(),trackID);
1340 
1341  ESMapping_.push_back(std::pair<CaloHitID,float>(current_id,energy));
1342  }
1343 }
1344 
1346 {
1347  c.reserve(c.size()+EBMapping_.size());
1348  for(unsigned i=0; i<EBMapping_.size(); i++) {
1349  c.push_back(PCaloHit(EBDetId::unhashIndex(EBMapping_[i].first.unitID()),EBMapping_[i].second,EBMapping_[i].first.timeSlice(),EBMapping_[i].first.trackID()));
1350  }
1351 }
1352 
1354 {
1355  c.reserve(c.size()+EEMapping_.size());
1356  for(unsigned i=0; i<EEMapping_.size(); i++) {
1357  c.push_back(PCaloHit(EEDetId::unhashIndex(EEMapping_[i].first.unitID()),EEMapping_[i].second,EEMapping_[i].first.timeSlice(),EEMapping_[i].first.trackID()));
1358  }
1359 }
1360 
1362 {
1363  c.reserve(c.size()+HMapping_.size());
1364  for(unsigned i=0; i<HMapping_.size(); i++) {
1365  c.push_back(PCaloHit(DetId(HMapping_[i].first.unitID()),HMapping_[i].second,HMapping_[i].first.timeSlice(),HMapping_[i].first.trackID()));
1366  }
1367 }
1368 
1369 
1371 {
1372  c.reserve(c.size()+ESMapping_.size());
1373  for(unsigned i=0; i<ESMapping_.size(); i++) {
1374  c.push_back(PCaloHit(ESMapping_[i].first.unitID(),ESMapping_[i].second,ESMapping_[i].first.timeSlice(),ESMapping_[i].first.trackID()));
1375  }
1376 }
1377 
1378 // The main danger in this method is to screw up to relationships between particles
1379 // So, the muon FSimTracks created by FSimEvent.cc are simply to be updated
1381 {
1382  unsigned size=muons.size();
1383  for(unsigned i=0; i<size;++i)
1384  {
1385  int id=muons[i].trackId();
1386  if(abs(muons[i].type())!=13) continue;
1387  // identify the corresponding muon in the local collection
1388 
1389  std::vector<FSimTrack>::const_iterator itcheck=find_if(muonSimTracks.begin(),muonSimTracks.end(),FSimTrackEqual(id));
1390  if(itcheck!=muonSimTracks.end())
1391  {
1392  muons[i].setTkPosition(itcheck->trackerSurfacePosition());
1393  muons[i].setTkMomentum(itcheck->trackerSurfaceMomentum());
1394 // std::cout << " Found the SimTrack " << std::endl;
1395 // std::cout << *itcheck << std::endl;
1396 // std::cout << "SimTrack Id "<< id << " " << muons[i] << " " << std::endl;
1397  }
1398 // else
1399 // {
1400 // std::cout << " Calorimetery Manager : this should really not happen " << std::endl;
1401 // std::cout << " Was looking for " << id << " " << muons[i] << std::endl;
1402 // for(unsigned i=0;i<muonSimTracks.size();++i)
1403 // std::cout << muonSimTracks[i] << std::endl;
1404 // }
1405  }
1406 
1407 }
1408 
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: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
void reconstructHCAL(const FSimTrack &myTrack, RandomEngineAndDistribution const *)
std::vector< PCaloHit > PCaloHitContainer
const double GeV
Definition: MathUtil.h:16
static std::vector< std::string > checklist log
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
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
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
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:469
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 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
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: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:44
GflashProtonShowerProfile * theProtonProfile
const PreshowerLayer2Properties * layer2Properties(int onLayer2) const
Preshower Layer2 properties.
Definition: Calorimeter.cc:110
double getPathLengthAtShower()
Definition: GflashShowino.h:26
void setTrackParameters(const XYZNormal &normal, double X0depthoffset, const FSimTrack &theTrack)
void loadFromEcalEndcap(edm::PCaloHitContainer &c) const
void setID(const int id)
Definition: RawParticle.cc:102
const XYZTLorentzVector & deltaMom() const
Returns the actual energy lost.
std::vector< double > radiusPreshowerCorrections_
const HCALProperties * hcalProperties(int onHcal) const
HCAL properties.
Definition: Calorimeter.cc: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_
bool first
Definition: L1TdeRCT.cc:75
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:47
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:38
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
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
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:1082
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
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:667
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:842
void setGrid(EcalHitMaker *const myGrid)
set the grid address
Definition: EMShower.h:64
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:61
void loadFromEcalBarrel(edm::PCaloHitContainer &c) const