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
20 //#include "FastSimulation/Utilities/interface/Histos.h"
30 // New headers for Muon Mip Simulation
33 //Gflash Hadronic Model
41 // STL headers
42 #include <vector>
43 #include <iostream>
44 
45 //CMSSW headers
48 //#include "DataFormats/EcalDetId/interface/EcalDetId.h"
49 
51 
52 using namespace edm;
53 
56 
57 std::vector<std::pair<int,float> > CalorimetryManager::myZero_ = std::vector<std::pair<int,float> >
58 (1,std::pair<int,float>(0,0.));
59 
61  myCalorimeter_(0),
62  myHistos(0),
63  random(0),initialized_(false)
64 {;}
65 
67  const edm::ParameterSet& fastCalo,
68  const edm::ParameterSet& fastMuECAL,
69  const edm::ParameterSet& fastMuHCAL,
70  const edm::ParameterSet& parGflash,
71  const RandomEngine* engine)
72  :
73  mySimEvent(aSimEvent),
74  random(engine),initialized_(false),
75  theMuonEcalEffects(0), theMuonHcalEffects (0)
76 
77 {
78 
81 
82  //Gflash
83  theProfile = new GflashHadronShowerProfile(parGflash);
84  thePiKProfile = new GflashPiKShowerProfile(parGflash);
87 
88  readParameters(fastCalo);
89 
90 // EBMapping_.resize(62000,myZero_);
91 // EEMapping_.resize(20000,myZero_);
92 // HMapping_.resize(10000,myZero_);
93  EBMapping_.resize(62000);
94  EEMapping_.resize(20000);
95  HMapping_.resize(10000);
96  theDetIds_.resize(10000);
97 
98  unsigned s=(unfoldedMode_)?5:1;
99  for(unsigned ic=0;ic<62000;++ic)
100  {
101  EBMapping_[ic].reserve(s);
102  if(ic<20000)
103  EEMapping_[ic].reserve(s);
104  if(ic<10000)
105  HMapping_[ic].reserve(s);
106  }
107 
108 
109 
110  myHistos = 0;
111 #ifdef FAMOSDEBUG
113  myHistos->book("h10",140,-3.5,3.5,100,-0.5,99.5);
114  myHistos->book("h20",150,0,150.,100,-0.5,99.5);
115  myHistos->book("h100",140,-3.5,3.5,100,0,0.1);
116  myHistos->book("h110",140,-3.5,3.5,100,0,10.);
117  myHistos->book("h120",200,-5.,5.,100,0,0.5);
118 
119  myHistos->book("h200",300,0,3.,100,0.,35.);
120  myHistos->book("h210",720,-M_PI,M_PI,100,0,35.);
121  myHistos->book("h212",720,-M_PI,M_PI,100,0,35.);
122 
123  myHistos->bookByNumber("h30",0,7,300,-3.,3.,100,0.,35.);
124  myHistos->book("h310",75,-3.,3.,"");
125  myHistos->book("h400",100,-10.,10.,100,0.,35.);
126  myHistos->book("h410",720,-M_PI,M_PI);
127 #endif
128  myCalorimeter_ =
129  new CaloGeometryHelper(fastCalo);
130  myHDResponse_ =
131  new HCALResponse(fastCalo.getParameter<edm::ParameterSet>("HCALResponse"),
132  random);
133  myHSParameters_ =
134  new HSParameters(fastCalo.getParameter<edm::ParameterSet>("HSParameters"));
135 
136  // Material Effects for Muons in ECAL (only EnergyLoss implemented so far)
137 
138  if ( fastMuECAL.getParameter<bool>("PairProduction") ||
139  fastMuECAL.getParameter<bool>("Bremsstrahlung") ||
140  fastMuECAL.getParameter<bool>("EnergyLoss") ||
141  fastMuECAL.getParameter<bool>("MultipleScattering") )
142  theMuonEcalEffects = new MaterialEffects(fastMuECAL,random);
143 
144  // Material Effects for Muons in HCAL (only EnergyLoss implemented so far)
145 
146  if ( fastMuHCAL.getParameter<bool>("PairProduction") ||
147  fastMuHCAL.getParameter<bool>("Bremsstrahlung") ||
148  fastMuHCAL.getParameter<bool>("EnergyLoss") ||
149  fastMuHCAL.getParameter<bool>("MultipleScattering") )
150  theMuonHcalEffects = new MaterialEffects(fastMuHCAL,random);
151 
152 }
153 
155 {
156  unsigned size=firedCellsEB_.size();
157  for(unsigned ic=0;ic<size;++ic)
158  {
159  EBMapping_[firedCellsEB_[ic]].clear();
160  }
161  firedCellsEB_.clear();
162 
163  size=firedCellsEE_.size();
164  for(unsigned ic=0;ic<size;++ic)
165  {
166  EEMapping_[firedCellsEE_[ic]].clear();
167  }
168  firedCellsEE_.clear();
169 
170  size=firedCellsHCAL_.size();
171  for(unsigned ic=0;ic<size;++ic)
172  {
173  HMapping_[firedCellsHCAL_[ic]].clear();
174  }
175  firedCellsHCAL_.clear();
176 
177  ESMapping_.clear();
178  muonSimTracks.clear();
179 }
180 
182 {
183 #ifdef FAMOSDEBUG
184  myHistos->put("Famos.root");
185 #endif
186  if(myCalorimeter_) delete myCalorimeter_;
187  if(myHDResponse_) delete myHDResponse_;
188 
191 
192  if ( theProfile ) delete theProfile;
193 }
194 
196 {
197  if(evtsToDebug_.size())
198  {
199  std::vector<unsigned int>::const_iterator itcheck=find(evtsToDebug_.begin(),evtsToDebug_.end(),mySimEvent->id().event());
200  debug_=(itcheck!=evtsToDebug_.end());
201  if(debug_)
202  mySimEvent->print();
203  }
204  // Clear the content of the calorimeters
205  if(!initialized_)
206  {
208  for(int subdetn=1;subdetn<=4;++subdetn)
209  {
210  const std::vector<DetId>& ids(geom->getValidDetIds(DetId::Hcal,subdetn));
211  for (std::vector<DetId>::const_iterator i=ids.begin(); i!=ids.end(); i++)
212  {
213  HcalDetId myDetId(*i);
214  unsigned hi=myDetId.hashed_index();
215  theDetIds_[hi]=myDetId;
216  }
217  }
218 
219  // Check if the preshower is really available
221  {
222  std::cout << " WARNING " << std::endl;
223  std::cout << " The preshower simulation has been turned on; but no preshower geometry is available " << std::endl;
224  std::cout << " Disabling the preshower simulation " << std::endl;
225  simulatePreshower_ = false;
226  }
227 
228  initialized_=true;
229  }
230  clean();
231 
232  LogInfo("FastCalorimetry") << "Reconstructing " << (int) mySimEvent->nTracks() << " tracks." << std::endl;
233  for( int fsimi=0; fsimi < (int) mySimEvent->nTracks() ; ++fsimi) {
234 
235  FSimTrack& myTrack = mySimEvent->track(fsimi);
236 
237  int pid = abs(myTrack.type());
238 
239  if (debug_) {
240  LogDebug("FastCalorimetry") << " ===> pid = " << pid << std::endl;
241  }
242 
243 
244  // Check that the particle hasn't decayed
245  if(myTrack.noEndVertex()) {
246  // Simulate energy smearing for photon and electrons
247  if ( pid == 11 || pid == 22 ) {
248 
249 
250  if ( myTrack.onEcal() )
251  EMShowerSimulation(myTrack);
252  else if ( myTrack.onVFcal() )
253  reconstructHCAL(myTrack);
254 
255  } // electron or photon
256  else if (pid==13)
257  {
258  MuonMipSimulation(myTrack);
259  }
260  // Simulate energy smearing for hadrons (i.e., everything
261  // but muons... and SUSY particles that deserve a special
262  // treatment.
263  else if ( pid < 1000000 ) {
264  if ( myTrack.onHcal() || myTrack.onVFcal() ) {
265  if(optionHDSim_ == 0 ) reconstructHCAL(myTrack);
266  else HDShowerSimulation(myTrack);
267  }
268  } // pid < 1000000
269  } // myTrack.noEndVertex()
270  } // particle loop
271  // LogInfo("FastCalorimetry") << " Number of hits (barrel)" << EBMapping_.size() << std::endl;
272  // LogInfo("FastCalorimetry") << " Number of hits (Hcal)" << HMapping_.size() << std::endl;
273  // std::cout << " Nombre de hit (endcap)" << EEMapping_.size() << std::endl;
274 
275 } // reconstruct
276 
277 // Simulation of electromagnetic showers in PS, ECAL, HCAL
279  std::vector<const RawParticle*> thePart;
280  double X0depth;
281  if (debug_) {
282  LogDebug("FastCalorimetry") << " EMShowerSimulation " <<myTrack << std::endl;
283  }
284 
285  // std::cout << " Simulating " << myTrack << std::endl;
286 
287  // The Particle at ECAL entrance
288  // std::cout << " Before ecalEntrance " << std::endl;
289  myPart = myTrack.ecalEntrance();
290 
291  // protection against infinite loop.
292  if ( myTrack.type() == 22 && myPart.e()<0.055) return;
293 
294 
295  // Barrel or Endcap ?
296  int onEcal = myTrack.onEcal();
297  int onHcal = myTrack.onHcal();
298  int onLayer1 = myTrack.onLayer1();
299  int onLayer2 = myTrack.onLayer2();
300 
301  // The entrance in ECAL
302  XYZPoint ecalentrance = myPart.vertex().Vect();
303 
304  // std::cout << " Ecal entrance " << ecalentrance << std::endl;
305 
306  // The preshower
307  PreshowerHitMaker * myPreshower = NULL ;
308  if(simulatePreshower_ && (onLayer1 || onLayer2))
309  {
310  XYZPoint layer1entrance,layer2entrance;
311  XYZVector dir1,dir2;
312  if(onLayer1)
313  {
314  layer1entrance = XYZPoint(myTrack.layer1Entrance().vertex().Vect());
315  dir1 = XYZVector(myTrack.layer1Entrance().Vect().Unit());
316  }
317  if(onLayer2)
318  {
319  layer2entrance = XYZPoint(myTrack.layer2Entrance().vertex().Vect());
320  dir2 = XYZVector(myTrack.layer2Entrance().Vect().Unit());
321  }
322  // std::cout << " Layer1entrance " << layer1entrance << std::endl;
323  // std::cout << " Layer2entrance " << layer2entrance << std::endl;
324  myPreshower = new PreshowerHitMaker(myCalorimeter_,
325  layer1entrance,
326  dir1,
327  layer2entrance,
328  dir2,
330  myPreshower->setMipEnergy(mipValues_[0],mipValues_[1]);
331  }
332 
333  // The ECAL Properties
335  showerparam(myCalorimeter_->ecalProperties(onEcal),
336  myCalorimeter_->hcalProperties(onHcal),
337  myCalorimeter_->layer1Properties(onLayer1),
338  myCalorimeter_->layer2Properties(onLayer2),
341  RCFactor_,
342  RTFactor_);
343 
344  // Photons : create an e+e- pair
345  if ( myTrack.type() == 22 ) {
346 
347  // Depth for the first e+e- pair creation (in X0)
348  X0depth = -log(random->flatShoot()) * (9./7.);
349 
350  // Initialization
351  double eMass = 0.000510998902;
352  double xe=0;
353  double xm=eMass/myPart.e();
354  double weight = 0.;
355 
356  // Generate electron energy between emass and eGamma-emass
357  do {
358  xe = random->flatShoot()*(1.-2.*xm) + xm;
359  weight = 1. - 4./3.*xe*(1.-xe);
360  } while ( weight < random->flatShoot() );
361 
362  // Protection agains infinite loop in Famos Shower
363  if ( myPart.e()*xe < 0.055 || myPart.e()*(1.-xe) < 0.055 ) {
364 
365  if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
366 
367  } else {
368 
369  myElec = (myPart) * xe;
370  myPosi = (myPart) * (1.-xe);
373  thePart.push_back(&myElec);
374  thePart.push_back(&myPosi);
375  }
376  // Electrons
377  } else {
378 
379  X0depth = 0.;
380  if ( myPart.e() > 0.055 ) thePart.push_back(&myPart);
381 
382  }
383 
384  // After the different protections, this shouldn't happen.
385  if(thePart.size()==0)
386  {
387  if(myPreshower==NULL) return;
388  delete myPreshower;
389  return;
390  }
391 
392  // find the most energetic particle
393  double maxEnergy=-1.;
394  for(unsigned ip=0;ip < thePart.size();++ip)
395  if(thePart[ip]->e() > maxEnergy) maxEnergy = thePart[ip]->e();
396 
397  // Initialize the Grid in ECAL
398  int size = gridSize_;
399  if(maxEnergy>100) size=11;
400 // if ( maxEnergy < threshold5x5 ) size = 5;
401 // if ( maxEnergy < threshold3x3 ) size = 3;
402 
403 
404  EMShower theShower(random,aGammaGenerator,&showerparam,&thePart);
405 
406  double maxShower = theShower.getMaximumOfShower();
407  if (maxShower > 20.) maxShower = 2.; // simple pivot-searching protection
408 
409  double depth((X0depth + maxShower) *
411  XYZPoint meanShower = ecalentrance + myPart.Vect().Unit()*depth;
412 
413  // if(onEcal!=1) return ;
414 
415  // The closest crystal
416  DetId pivot(myCalorimeter_->getClosestCell(meanShower, true, onEcal==1));
417 
418  if(pivot.subdetId() == 0) { // further protection against avbsence of pivot
419  edm::LogWarning("CalorimetryManager") << "Pivot for egamma e = " << myTrack.hcalEntrance().e() << " is not found at depth " << depth << " and meanShower coordinates = " << meanShower << std::endl;
420  return;
421  }
422 
423  EcalHitMaker myGrid(myCalorimeter_,ecalentrance,pivot,onEcal,size,0,random);
424  // ^^^^
425  // for EM showers
429  //maximumdepth dependence of the radiusfactorbehindpreshower
430  // adjusted by Shilpi Jain (Mar-Apr 2010)
431  if(onLayer1 || onLayer2)
432  {
433  float b = radiusPreshowerCorrections_[0];
435  float maxdepth = X0depth+theShower.getMaximumOfShower();
436  float newRadiusFactor = radiusFactor_;
437  if(myPart.e()<=250.)
438  {
439  newRadiusFactor = a/(1.+b*maxdepth);
440  }
441  myGrid.setRadiusFactor(newRadiusFactor);
442  }
443  else // otherwise use the normal radius factor
444  {
446  }
448 
449  // The shower simulation
450  myGrid.setTrackParameters(myPart.Vect().Unit(),X0depth,myTrack);
451 
452 // std::cout << " PS ECAL GAP HCAL X0 " << myGrid.ps1TotalX0()+myGrid.ps2TotalX0() << " " << myGrid.ecalTotalX0();
453 // std::cout << " " << myGrid.ecalHcalGapTotalX0() << " " << myGrid.hcalTotalX0() << std::endl;
454 // std::cout << " PS ECAL GAP HCAL L0 " << myGrid.ps1TotalL0()+myGrid.ps2TotalL0() << " " << myGrid.ecalTotalL0();
455 // std::cout << " " << myGrid.ecalHcalGapTotalL0() << " " << myGrid.hcalTotalL0() << std::endl;
456 // std::cout << "ECAL-HCAL " << myTrack.momentum().eta() << " " << myGrid.ecalHcalGapTotalL0() << std::endl;
457 //
458 // std::cout << " Grid created " << std::endl;
459  if(myPreshower) theShower.setPreshower(myPreshower);
460 
461  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)0);
462 
463  theShower.setGrid(&myGrid);
464  theShower.setHcal(&myHcalHitMaker);
465  // std:: cout << " About to compute " << std::endl;
466  theShower.compute();
467  // std::cout << " Coming back from compute" << std::endl;
468  //myHistos->fill("h502", myPart->eta(),myGrid.totalX0());
469 
470  // Save the hits !
471  std::map<uint32_t,float>::const_iterator mapitr;
472  std::map<uint32_t,float>::const_iterator endmapitr=myGrid.getHits().end();
473  for(mapitr=myGrid.getHits().begin();mapitr!=endmapitr;++mapitr)
474  {
475  if(onEcal==1)
476  {
477  updateMap(EBDetId(mapitr->first).hashedIndex(), mapitr->second,myTrack.id(),EBMapping_,firedCellsEB_);
478  }
479 
480  else if(onEcal==2)
481  updateMap(EEDetId(mapitr->first).hashedIndex(), mapitr->second,myTrack.id(),EEMapping_,firedCellsEE_);
482  // std::cout << " Adding " <<mapitr->first << " " << mapitr->second <<std::endl;
483  }
484 
485  // Now fill the HCAL hits
486  endmapitr=myHcalHitMaker.getHits().end();
487  for(mapitr=myHcalHitMaker.getHits().begin();mapitr!=endmapitr;++mapitr)
488  {
489  updateMap(HcalDetId(mapitr->first).hashed_index(),mapitr->second,myTrack.id(),HMapping_,firedCellsHCAL_);
490  // std::cout << " Adding " <<mapitr->first << " " << mapitr->second <<std::endl;
491  }
492 
493  // delete the preshower
494  if(myPreshower!=0)
495  {
496  endmapitr=myPreshower->getHits().end();
497  for(mapitr=myPreshower->getHits().begin();mapitr!=endmapitr;++mapitr)
498  {
499  updateMap(mapitr->first,mapitr->second,myTrack.id(),ESMapping_);
500  // std::cout << " Adding " <<mapitr->first << " " << mapitr->second <<std::endl;
501  }
502  delete myPreshower;
503  }
504  // std::cout << " Deleting myPreshower " << std::endl;
505 
506 }
507 
508 
509 
510 // Simulation of electromagnetic showers in VFCAL
512  if(debug_) {
513  XYZTLorentzVector moment = track.momentum();
514  std::cout << "FASTEnergyReconstructor::reconstructECAL - " << std::endl
515  << " eta " << moment.eta() << std::endl
516  << " phi " << moment.phi() << std::endl
517  << " et " << moment.Et() << std::endl;
518  }
519 
520  int hit;
521 
522  bool central=track.onEcal()==1;
523 
524  //Reconstruct only electrons and photons.
525 
526  //deal with different conventions
527  // ParticlePropagator 1 <-> Barrel
528  // 2 <-> EC
529  // whereas for Artur(this code):
530  // 0 <-> Barrel
531  // 1 <-> EC
532  // 2 <-> VF
533  XYZTLorentzVector trackPosition;
534  if( track.onEcal() ) {
535  hit=track.onEcal()-1;
536  trackPosition=track.ecalEntrance().vertex();
537  } else {
538  hit=2;
539  trackPosition=track.vfcalEntrance().vertex();
540  }
541 
542  double pathEta = trackPosition.eta();
543  double pathPhi = trackPosition.phi();
544  double EGen = track.ecalEntrance().e();
545 
546 
547  double e=0.;
548  double sigma=0.;
549  // if full simulation and in HF, but without showering anyway...
550  if(hit == 2 && optionHDSim_ == 2 ) {
551  std::pair<double,double> response =
552  myHDResponse_->responseHCAL(0, EGen, pathEta, 0); // last par.= 0 = e/gamma
553  e = response.first;
554  sigma = response.second;
555  }
556 
557  double emeas = 0.;
558 
559  if(sigma>0.)
560  emeas = random->gaussShoot(e,sigma);
561 
562 
563  if(debug_)
564  std::cout << "FASTEnergyReconstructor::reconstructECAL : "
565  << " on-calo eta, phi = " << pathEta << " " << pathPhi << std::endl
566  << " Egen = " << EGen << std::endl
567  << " Eres = " << e << std::endl
568  << " sigma = " << sigma << std::endl
569  << " Emeas = " << emeas << std::endl;
570 
571 
572  if(debug_)
573  std::cout << "FASTEnergyReconstructor::reconstructECAL : "
574  << " Track position - " << trackPosition.Vect()
575  << " bool central - " << central
576  << " hit - " << hit << std::endl;
577 
578  DetId detid;
579  if( hit==2 )
580  detid = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,central);
581  // Check that the detid is HCAL forward
582  HcalDetId hdetid(detid);
583  if(!hdetid.subdetId()!=HcalForward) return;
584 
585  if(debug_)
586  std::cout << "FASTEnergyReconstructor::reconstructECAL : "
587  << " CellID - " << detid.rawId() << std::endl;
588 
589  if( hit != 2 || emeas > 0.)
590  if(!detid.null())
591  {
592  updateMap(hdetid.hashed_index(),emeas,track.id(),HMapping_,firedCellsHCAL_);
593  }
594 
595 }
596 
597 
599 {
600  int hit;
601  int pid = abs(myTrack.type());
602  if (debug_) {
603  LogDebug("FastCalorimetry") << " reconstructHCAL " << myTrack << std::endl;
604  }
605 
606  // FSimTrack myTrack = mySimEvent.track(fsimi);
607 
608  // int pid=abs(myTrack.type());
609  // std::cout << "reconstructHCAL " << std::endl;
610 
611  XYZTLorentzVector trackPosition;
612  if (myTrack.onHcal()) {
613  trackPosition=myTrack.hcalEntrance().vertex();
614  hit = myTrack.onHcal()-1;
615  } else {
616  trackPosition=myTrack.vfcalEntrance().vertex();
617  hit = 2;
618  }
619 
620  double pathEta = trackPosition.eta();
621  double pathPhi = trackPosition.phi();
622  // double pathTheta = trackPosition.theta();
623 
624  double EGen = myTrack.hcalEntrance().e();
625  double e = 0.;
626  double sigma = 0.;
627  double emeas = 0.;
628 
629  if(pid == 13) {
630  // std::cout << " We should not be here " << std::endl;
631  std::pair<double,double> response =
632  myHDResponse_->responseHCAL(0, EGen, pathEta, 2); // 2=muon
633  emeas = response.first;
634  if(debug_)
635  LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - MUON !!!" << std::endl;
636  }
637  else if( pid == 22 || pid == 11)
638  {
639 
640  std::pair<double,double> response =
641  myHDResponse_->responseHCAL(0, EGen, pathEta, 0); // last par. = 0 = e/gamma
642  e = response.first; //
643  sigma = response.second; //
644  emeas = random->gaussShoot(e,sigma); //
645 
646  // cout << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
647  if(debug_)
648  LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - e/gamma !!!" << std::endl;
649  }
650  else {
651  e = myHDResponse_->getHCALEnergyResponse(EGen,hit);
652  sigma = myHDResponse_->getHCALEnergyResolution(EGen, hit);
653 
654  emeas = random->gaussShoot(e,sigma);
655  }
656 
657 
658  if(debug_)
659  LogDebug("FastCalorimetry") << "CalorimetryManager::reconstructHCAL - on-calo "
660  << " eta = " << pathEta
661  << " phi = " << pathPhi
662  << " Egen = " << EGen
663  << " Eres = " << e
664  << " sigma = " << sigma
665  << " Emeas = " << emeas << std::endl;
666 
667  if(emeas > 0.) {
668  DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
669  updateMap(HcalDetId(cell).hashed_index(), emeas, myTrack.id(),HMapping_,firedCellsHCAL_);
670  }
671 }
672 
674 {
675  // TimeMe t(" FASTEnergyReconstructor::HDShower");
676  XYZTLorentzVector moment = myTrack.momentum();
677 
678  if(debug_)
679  LogDebug("FastCalorimetry")
680  << "CalorimetryManager::HDShowerSimulation - track param."
681  << std::endl
682  << " eta = " << moment.eta() << std::endl
683  << " phi = " << moment.phi() << std::endl
684  << " et = " << moment.Et() << std::endl
685  << " e = " << myTrack.hcalEntrance().e() << std::endl;
686 
687  if (debug_) {
688  LogDebug("FastCalorimetry") << " HDShowerSimulation " << myTrack << std::endl;
689  }
690 
691 
692  int hit;
693  // int pid = abs(myTrack.type());
694 
695  XYZTLorentzVector trackPosition;
696  if ( myTrack.onEcal() ) {
697  trackPosition=myTrack.ecalEntrance().vertex();
698  hit = myTrack.onEcal()-1; //
699  myPart = myTrack.ecalEntrance();
700  } else if ( myTrack.onVFcal()) {
701  trackPosition=myTrack.vfcalEntrance().vertex();
702  hit = 2;
703  myPart = myTrack.vfcalEntrance();
704  }
705  else
706  {
707  LogDebug("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
708  return;
709  }
710 
711  // int onHCAL = hit + 1; - specially for myCalorimeter->hcalProperties(onHCAL)
712  // (below) to get VFcal properties ...
713  int onHCAL = hit + 1;
714  int onECAL = myTrack.onEcal();
715 
716  double pathEta = trackPosition.eta();
717  double pathPhi = trackPosition.phi();
718  // double pathTheta = trackPosition.theta();
719 
720  double eint = moment.e();
721  double eGen = myTrack.hcalEntrance().e();
722  double e = 0.;
723  double sigma = 0.;
724 
725  double emeas = 0.;
726 
727  //===========================================================================
728  if(eGen > 0.) {
729 
730  // ECAL and HCAL properties to get
732  theHDShowerparam(myCalorimeter_->ecalProperties(onECAL),
735 
736  //Making ECAL Grid (and segments calculation)
737  XYZPoint caloentrance;
738  XYZVector direction;
739  if(myTrack.onEcal())
740  {
741  caloentrance = myTrack.ecalEntrance().vertex().Vect();
742  direction = myTrack.ecalEntrance().Vect().Unit();
743  }
744  else if(myTrack.onHcal())
745  {
746  caloentrance = myTrack.hcalEntrance().vertex().Vect();
747  direction = myTrack.hcalEntrance().Vect().Unit();
748  }
749  else
750  {
751  caloentrance = myTrack.vfcalEntrance().vertex().Vect();
752  direction = myTrack.vfcalEntrance().Vect().Unit();
753  }
754 
755  if(debug_)
756  LogDebug("FastCalorimetry")
757  << "CalorimetryManager::HDShowerSimulation - on-calo 1 "
758  << std::endl
759  << " onEcal = " << myTrack.onEcal() << std::endl
760  << " onHcal = " << myTrack.onHcal() << std::endl
761  << " onVFcal = " << myTrack.onVFcal() << std::endl
762  << " position = " << caloentrance << std::endl;
763 
764 
765  DetId pivot;
766  if(myTrack.onEcal())
767  {
768  pivot=myCalorimeter_->getClosestCell(caloentrance,
769  true, myTrack.onEcal()==1);
770  }
771  else if(myTrack.onHcal())
772  {
773  // std::cout << " CalorimetryManager onHcal " << myTrack.onHcal() << " caloentrance" << caloentrance << std::endl;
774  pivot=myCalorimeter_->getClosestCell(caloentrance,
775  false, false);
776  }
777 
778  EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
779  pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,1,
780  random);
781  // 1=HAD shower
782 
783  myGrid.setTrackParameters(direction,0,myTrack);
784  // Build the FAMOS HCAL
785  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)1);
786 
787  // Shower simulation
788  bool status = false;
789  int mip = 2;
790  // Use HFShower for HF
791  if ( !myTrack.onEcal() && !myTrack.onHcal() ) {
792  // std::cout << "CalorimetryManager::HDShowerSimulation(): track entrance = "
793  // << myTrack.vfcalEntrance().vertex().X() << " "
794  // << myTrack.vfcalEntrance().vertex().Y() << " "
795  // << myTrack.vfcalEntrance().vertex().Z() << " "
796  // << " , Energy (Gen/Scale) = " << eGen << " " << e << std::endl;
797 
798  // Warning : We give here the particle energy with the response
799  // but without the resolution/gaussian smearing
800  // For HF, the resolution is due to the PE statistic
801 
802  HFShower theShower(random,
803  &theHDShowerparam,
804  &myGrid,
805  &myHcalHitMaker,
806  onECAL,
807  eGen);
808  // eGen);
809  // e); // PV Warning : temporarly set the energy to the generated E
810 
811  status = theShower.compute();
812  } else {
813  if(hdSimMethod_ == 0) {
814  HDShower theShower(random,
815  &theHDShowerparam,
816  &myGrid,
817  &myHcalHitMaker,
818  onECAL,
819  eGen);
820  status = theShower.compute();
821  mip = theShower.getmip();
822  }
823  else if (hdSimMethod_ == 1) {
824  HDRShower theShower(random,
825  &theHDShowerparam,
826  &myGrid,
827  &myHcalHitMaker,
828  onECAL,
829  eGen);
830  status = theShower.computeShower();
831  mip = 2;
832  }
833  else if (hdSimMethod_ == 2 ) {
834  // std::cout << "Using GflashHadronShowerProfile hdSimMethod_ == 2" << std::endl;
835 
836  //dynamically loading a corresponding profile by the particle type
837  int particleType = myTrack.type();
839  if(particleType == -2212) theProfile = theAntiProtonProfile;
840  else if(particleType == 2212) theProfile = theProtonProfile;
841 
842  //input variables for GflashHadronShowerProfile
843  int showerType = 99 + myTrack.onEcal();
844  double globalTime = 150.0; // a temporary reference hit time in nanosecond
845  float charge = (float)(myTrack.charge());
846  Gflash3Vector gfpos(trackPosition.X(),trackPosition.Y(),trackPosition.Z());
847  Gflash3Vector gfmom(moment.X(),moment.Y(),moment.Z());
848 
849  theProfile->initialize(showerType,eGen,globalTime,charge,gfpos,gfmom);
852 
853  //make hits
854  std::vector<GflashHit>& gflashHitList = theProfile->getGflashHitList();
855  std::vector<GflashHit>::const_iterator spotIter = gflashHitList.begin();
856  std::vector<GflashHit>::const_iterator spotIterEnd = gflashHitList.end();
857 
859  bool result;
860 
861  for( ; spotIter != spotIterEnd; spotIter++){
862 
863  double pathLength = theProfile->getGflashShowino()->getPathLengthAtShower()
864  + (30*100/eGen)*(spotIter->getTime() - globalTime);
865 
866  double currentDepth = std::max(0.0,pathLength - theProfile->getGflashShowino()->getPathLengthOnEcal());
867 
868  //find the the showino position at the currentDepth
869  GflashTrajectoryPoint trajectoryPoint;
870  theProfile->getGflashShowino()->getHelix()->getGflashTrajectoryPoint(trajectoryPoint,pathLength);
871  Gflash3Vector positionAtCurrentDepth = trajectoryPoint.getPosition();
872  //find radial distrance
873  Gflash3Vector lateralDisplacement = positionAtCurrentDepth - spotIter->getPosition()/CLHEP::cm;
874  double rShower = lateralDisplacement.r();
875  double azimuthalAngle = lateralDisplacement.phi();
876 
877  whichCalor = Gflash::getCalorimeterNumber(positionAtCurrentDepth);
878 
879  if(whichCalor==Gflash::kESPM || whichCalor==Gflash::kENCA) {
880  bool statusPad = myGrid.getPads(currentDepth,true);
881  if(!statusPad) continue;
882  myGrid.setSpotEnergy(1.2*spotIter->getEnergy()/CLHEP::GeV);
883  result = myGrid.addHit(rShower/Gflash::intLength[Gflash::kESPM],azimuthalAngle,0);
884  }
885  else if(whichCalor==Gflash::kHB || whichCalor==Gflash::kHE) {
886  bool setHDdepth = myHcalHitMaker.setDepth(currentDepth,true);
887  if(!setHDdepth) continue;
888  myHcalHitMaker.setSpotEnergy(1.4*spotIter->getEnergy()/CLHEP::GeV);
889  result = myHcalHitMaker.addHit(rShower/Gflash::intLength[Gflash::kHB],azimuthalAngle,0);
890  }
891  }
892  status = true;
893  }
894  else {
895  edm::LogInfo("FastSimulationCalorimetry") << " SimMethod " << hdSimMethod_ <<" is NOT available ";
896  }
897  }
898 
899 
900  if(status) {
901 
902  // Here to switch between simple formulae and parameterized response
903  if(optionHDSim_ == 1) {
904  e = myHDResponse_->getHCALEnergyResponse (eGen, hit);
905  sigma = myHDResponse_->getHCALEnergyResolution(eGen, hit);
906  }
907  else { // optionHDsim == 2
908  std::pair<double,double> response =
909  myHDResponse_->responseHCAL(mip, eGen, pathEta, 1); // 1=hadron
910  e = response.first;
911  sigma = response.second;
912  }
913 
914  emeas = random->gaussShoot(e,sigma);
915  double correction = emeas / eGen;
916 
917  // RespCorrP factors (ECAL and HCAL separately) calculation
918  respCorr(eint);
919 
920  if(debug_)
921  LogDebug("FastCalorimetry")
922  << "CalorimetryManager::HDShowerSimulation - on-calo 2" << std::endl
923  << " eta = " << pathEta << std::endl
924  << " phi = " << pathPhi << std::endl
925  << " Egen = " << eGen << std::endl
926  << " Eres = " << e << std::endl
927  << " sigma = " << sigma << std::endl
928  << " Emeas = " << emeas << std::endl
929  << " corr = " << correction << std::endl
930  << " mip = " << mip << std::endl;
931 
932 
933  // was map<unsigned,double> but CaloHitMaker uses float
934  std::map<unsigned,float>::const_iterator mapitr;
935  std::map<unsigned,float>::const_iterator endmapitr;
936  if(myTrack.onEcal() > 0) {
937  // Save ECAL hits
938  endmapitr=myGrid.getHits().end();
939  for(mapitr=myGrid.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
940  double energy = mapitr->second;
941  energy *= correction; // RESCALING
942  energy *= ecorr;
943 
944  if(energy > 0.000001) {
945  if(onECAL==1)
946  updateMap(EBDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EBMapping_,firedCellsEB_);
947 
948  else if(onECAL==2)
949  updateMap(EEDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EEMapping_,firedCellsEE_);
950 
951  if(debug_)
952  LogDebug("FastCalorimetry") << " ECAL cell " << mapitr->first << " added, E = "
953  << energy << std::endl;
954  }
955  }
956  }
957 
958  // Save HCAL hits
959  endmapitr=myHcalHitMaker.getHits().end();
960  for(mapitr=myHcalHitMaker.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
961  double energy = mapitr->second;
962  energy *= correction; // RESCALING
963  energy *= hcorr;
964 
965  updateMap(HcalDetId(mapitr->first).hashed_index(),energy,myTrack.id(),HMapping_,firedCellsHCAL_);
966  if(debug_)
967  LogDebug("FastCalorimetry") << " HCAL cell "
968  << mapitr->first << " added E = "
969  << mapitr->second << std::endl;
970  }
971  }
972  else { // shower simulation failed
973 // std::cout << " Shower simulation failed " << trackPosition.Vect() << std::endl;
974 // std::cout << " The FSimTrack " << myTrack << std::endl;
975 // std::cout << " HF entrance on VFcal" << myTrack.onVFcal() << std::endl;
976 // std::cout << " trackPosition.eta() " << trackPosition.eta() << std::endl;
977  if(myTrack.onHcal() || myTrack.onVFcal())
978  {
979  DetId cell = myCalorimeter_->getClosestCell(trackPosition.Vect(),false,false);
980  updateMap(HcalDetId(cell).hashed_index(),emeas,myTrack.id(),HMapping_,firedCellsHCAL_);
981  if(debug_)
982  LogDebug("FastCalorimetry") << " HCAL simple cell "
983  << cell.rawId() << " added E = "
984  << emeas << std::endl;
985  }
986  }
987 
988  } // e > 0. ...
989 
990  if(debug_)
991  LogDebug("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::HDShowerSimulation finished "
992  << std::endl;
993 }
994 
995 
997 {
998  // TimeMe t(" FASTEnergyReconstructor::HDShower");
999  XYZTLorentzVector moment = myTrack.momentum();
1000 
1001  // Backward compatibility behaviour
1002  if(!theMuonHcalEffects)
1003  {
1004  if(myTrack.onHcal() || myTrack.onVFcal() )
1005  reconstructHCAL(myTrack);
1006 
1007  return;
1008  }
1009 
1010  if(debug_)
1011  LogDebug("FastCalorimetry") << "CalorimetryManager::MuonMipSimulation - track param."
1012  << std::endl
1013  << " eta = " << moment.eta() << std::endl
1014  << " phi = " << moment.phi() << std::endl
1015  << " et = " << moment.Et() << std::endl;
1016 
1017  int hit;
1018  // int pid = abs(myTrack.type());
1019 
1020  XYZTLorentzVector trackPosition;
1021  if ( myTrack.onEcal() ) {
1022  trackPosition=myTrack.ecalEntrance().vertex();
1023  hit = myTrack.onEcal()-1; //
1024  myPart = myTrack.ecalEntrance();
1025  } else if ( myTrack.onVFcal()) {
1026  trackPosition=myTrack.vfcalEntrance().vertex();
1027  hit = 2;
1028  myPart = myTrack.vfcalEntrance();
1029  }
1030  else
1031  {
1032  LogDebug("FastCalorimetry") << " The particle is not in the acceptance " << std::endl;
1033  return;
1034  }
1035 
1036  // int onHCAL = hit + 1; - specially for myCalorimeter->hcalProperties(onHCAL)
1037  // (below) to get VFcal properties ...
1038  // not needed ?
1039  // int onHCAL = hit + 1;
1040  int onECAL = myTrack.onEcal();
1041 
1042  // double pathEta = trackPosition.eta();
1043  // double pathPhi = trackPosition.phi();
1044  // double pathTheta = trackPosition.theta();
1045 
1046  //===========================================================================
1047 
1048  // ECAL and HCAL properties to get
1049 
1050  //Making ECAL Grid (and segments calculation)
1051  XYZPoint caloentrance;
1052  XYZVector direction;
1053  if(myTrack.onEcal())
1054  {
1055  caloentrance = myTrack.ecalEntrance().vertex().Vect();
1056  direction = myTrack.ecalEntrance().Vect().Unit();
1057  }
1058  else if(myTrack.onHcal())
1059  {
1060  caloentrance = myTrack.hcalEntrance().vertex().Vect();
1061  direction = myTrack.hcalEntrance().Vect().Unit();
1062  }
1063  else
1064  {
1065  caloentrance = myTrack.vfcalEntrance().vertex().Vect();
1066  direction = myTrack.vfcalEntrance().Vect().Unit();
1067  }
1068 
1069  DetId pivot;
1070  if(myTrack.onEcal())
1071  {
1072  pivot=myCalorimeter_->getClosestCell(caloentrance,
1073  true, myTrack.onEcal()==1);
1074  }
1075  else if(myTrack.onHcal())
1076  {
1077  // std::cout << " CalorimetryManager onHcal " << myTrack.onHcal() << " caloentrance" << caloentrance << std::endl;
1078  pivot=myCalorimeter_->getClosestCell(caloentrance,
1079  false, false);
1080  }
1081 
1082  EcalHitMaker myGrid(myCalorimeter_,caloentrance,pivot,
1083  pivot.null()? 0 : myTrack.onEcal(),hdGridSize_,0,
1084  random);
1085  // 0 =EM shower -> Unit = X0
1086 
1087  myGrid.setTrackParameters(direction,0,myTrack);
1088 
1089  // Now get the path in the Preshower, ECAL and HCAL along a straight line extrapolation
1090  // but only those in the ECAL are used
1091 
1092  const std::vector<CaloSegment>& segments=myGrid.getSegments();
1093  unsigned nsegments=segments.size();
1094 
1095  int ifirstHcal=-1;
1096  int ilastEcal=-1;
1097  EnergyLossSimulator* energyLossECAL = 0;
1099 
1100  for(unsigned iseg=0;iseg<nsegments&&ifirstHcal<0;++iseg)
1101  {
1102 
1103  // in the ECAL, there are two types of segments: PbWO4 and GAP
1104  float segmentSizeinX0=segments[iseg].X0length();
1105 
1106  // Martijn - insert your computations here
1107  float energy=0.0;
1108  if (segmentSizeinX0>0.001 && segments[iseg].material()==CaloSegment::PbWO4 ) {
1109  // The energy loss simulator
1110  float charge = (float)(myTrack.charge());
1111  ParticlePropagator theMuon(moment,trackPosition,charge,0);
1112  theMuon.setID(-(int)charge*13);
1113  if ( energyLossECAL ) {
1114  energyLossECAL->updateState(theMuon, segmentSizeinX0);
1115  energy = energyLossECAL->deltaMom().E();
1116  moment -= energyLossECAL->deltaMom();
1117  }
1118  }
1119  // that's all for ECAL, Florian
1120  // Save the hit only if it is a crystal
1121  if(segments[iseg].material()==CaloSegment::PbWO4)
1122  {
1123  myGrid.getPads(segments[iseg].sX0Entrance()+segmentSizeinX0*0.5);
1124  myGrid.setSpotEnergy(energy);
1125  myGrid.addHit(0.,0.);
1126  ilastEcal=iseg;
1127  }
1128  // Check for end of loop:
1129  if(segments[iseg].material()==CaloSegment::HCAL)
1130  {
1131  ifirstHcal=iseg;
1132  }
1133  }
1134 
1135  // Position of Ecal Exit
1136  math::XYZVector ecalExit;
1137  if(ilastEcal>=0)
1138  math::XYZVector ecalExit=segments[ilastEcal].exit();
1139 
1140  // Position of HCAL entrance
1141  math::XYZVector hcalEntrance;
1142  if(ifirstHcal>=0)
1143  hcalEntrance=segments[ifirstHcal].entrance();
1144 
1145  // dummy HCAL exit, just to test the FSimTrack saving mechanism
1146  math::XYZVector hcalExit;
1147  if(ifirstHcal>=0)
1148  hcalExit=segments[ifirstHcal].exit();
1149 
1150 
1151  // Build the FAMOS HCAL
1152  HcalHitMaker myHcalHitMaker(myGrid,(unsigned)2);
1153  // float mipenergy=0.1;
1154  // Create the helix with the stepping helix propagator
1155  // to add a hit, just do
1156  // myHcalHitMaker.setSpotEnergy(mipenergy);
1157  // myHcalHitMaker.addHit(hcalEntrance);
1161  int ilastHcal=-1;
1162  float mipenergy=0.0;
1163  EnergyLossSimulator* energyLossHCAL = 0;
1165  if(ifirstHcal>0 && energyLossHCAL){
1166  for(unsigned iseg=ifirstHcal;iseg<nsegments;++iseg)
1167  {
1168  float segmentSizeinX0=segments[iseg].X0length();
1169  if (segmentSizeinX0>0.001 && segments[iseg].material()==CaloSegment::HCAL ) {
1170  // The energy loss simulator
1171  float charge = (float)(myTrack.charge());
1172  ParticlePropagator theMuon(moment,trackPosition,charge,0);
1173  theMuon.setID(-(int)charge*13);
1174  energyLossHCAL->updateState(theMuon, segmentSizeinX0);
1175  mipenergy = energyLossHCAL->deltaMom().E();
1176  moment -= energyLossHCAL->deltaMom();
1177  myHcalHitMaker.setSpotEnergy(mipenergy);
1178  myHcalHitMaker.addHit(segments[iseg].entrance());
1179  }
1180  if(segments[iseg].material()==CaloSegment::HCAL)
1181  {
1182  ilastHcal=iseg;
1183  }
1184  }
1185  }
1186  if(ilastHcal>=0) // Update hcalExit position from 'dummy' HCAL entrance to 'staight line' HCAL exit
1187  hcalExit=segments[ilastHcal].exit();
1188 
1193  //
1194 
1195 
1196 
1197  // Copy the muon SimTrack
1198  FSimTrack muonTrack(myTrack);
1199  if(energyLossHCAL) {
1200  muonTrack.setTkPosition(hcalExit);
1201  muonTrack.setTkMomentum(moment);
1202  } else if(energyLossECAL) {
1203  muonTrack.setTkPosition(ecalExit);
1204  muonTrack.setTkMomentum(moment);
1205  } // else just leave tracker surface position and momentum...
1206 
1207  muonSimTracks.push_back(muonTrack);
1208 
1209 
1210  // no need to change below this line
1211  std::map<unsigned,float>::const_iterator mapitr;
1212  std::map<unsigned,float>::const_iterator endmapitr;
1213  if(myTrack.onEcal() > 0) {
1214  // Save ECAL hits
1215  endmapitr=myGrid.getHits().end();
1216  for(mapitr=myGrid.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
1217  double energy = mapitr->second;
1218  if(onECAL==1)
1219  {
1220  updateMap(EBDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EBMapping_,firedCellsEB_);
1221  }
1222  else if(onECAL==2)
1223  {
1224  updateMap(EEDetId(mapitr->first).hashedIndex(),energy,myTrack.id(),EEMapping_,firedCellsEE_);
1225  }
1226 
1227  if(debug_)
1228  LogDebug("FastCalorimetry") << " ECAL cell " << mapitr->first << " added, E = "
1229  << energy << std::endl;
1230  }
1231  }
1232 
1233  // Save HCAL hits
1234  endmapitr=myHcalHitMaker.getHits().end();
1235  for(mapitr=myHcalHitMaker.getHits().begin(); mapitr!=endmapitr; ++mapitr) {
1236  double energy = mapitr->second;
1237  {
1238  updateMap(HcalDetId(mapitr->first).hashed_index(),energy,myTrack.id(),HMapping_,firedCellsHCAL_);
1239  }
1240  if(debug_)
1241  LogDebug("FastCalorimetry") << " HCAL cell "
1242  << mapitr->first << " added E = "
1243  << mapitr->second << std::endl;
1244  }
1245 
1246  if(debug_)
1247  LogDebug("FastCalorimetry") << std::endl << " FASTEnergyReconstructor::MipShowerSimulation finished "
1248  << std::endl;
1249 }
1250 
1251 
1253 
1254  edm::ParameterSet ECALparameters = fastCalo.getParameter<edm::ParameterSet>("ECAL");
1255 
1256  evtsToDebug_ = fastCalo.getUntrackedParameter<std::vector<unsigned int> >("EvtsToDebug",std::vector<unsigned>());
1257  debug_ = fastCalo.getUntrackedParameter<bool>("Debug");
1258 
1259  gridSize_ = ECALparameters.getParameter<int>("GridSize");
1260  spotFraction_ = ECALparameters.getParameter<double>("SpotFraction");
1261  pulledPadSurvivalProbability_ = ECALparameters.getParameter<double>("FrontLeakageProbability");
1262  crackPadSurvivalProbability_ = ECALparameters.getParameter<double>("GapLossProbability");
1263  theCoreIntervals_ = ECALparameters.getParameter<std::vector<double> >("CoreIntervals");
1264  theTailIntervals_ = ECALparameters.getParameter<std::vector<double> >("TailIntervals");
1265 
1266  RCFactor_ = ECALparameters.getParameter<double>("RCFactor");
1267  RTFactor_ = ECALparameters.getParameter<double>("RTFactor");
1268  radiusFactor_ = ECALparameters.getParameter<double>("RadiusFactor");
1269  radiusPreshowerCorrections_ = ECALparameters.getParameter<std::vector<double> >("RadiusPreshowerCorrections");
1270  mipValues_ = ECALparameters.getParameter<std::vector<double> >("MipsinGeV");
1271  simulatePreshower_ = ECALparameters.getParameter<bool>("SimulatePreshower");
1272 
1273  if(gridSize_ <1) gridSize_= 7;
1274  if(pulledPadSurvivalProbability_ <0. || pulledPadSurvivalProbability_>1 ) pulledPadSurvivalProbability_= 1.;
1275  if(crackPadSurvivalProbability_ <0. || crackPadSurvivalProbability_>1 ) crackPadSurvivalProbability_= 0.9;
1276 
1277  LogInfo("FastCalorimetry") << " Fast ECAL simulation parameters " << std::endl;
1278  LogInfo("FastCalorimetry") << " =============================== " << std::endl;
1279  if(simulatePreshower_)
1280  LogInfo("FastCalorimetry") << " The preshower is present " << std::endl;
1281  else
1282  LogInfo("FastCalorimetry") << " The preshower is NOT present " << std::endl;
1283  LogInfo("FastCalorimetry") << " Grid Size : " << gridSize_ << std::endl;
1284  if(spotFraction_>0.)
1285  LogInfo("FastCalorimetry") << " Spot Fraction : " << spotFraction_ << std::endl;
1286  else
1287  {
1288  LogInfo("FastCalorimetry") << " Core of the shower " << std::endl;
1289  for(unsigned ir=0; ir < theCoreIntervals_.size()/2;++ir)
1290  {
1291  LogInfo("FastCalorimetry") << " r < " << theCoreIntervals_[ir*2] << " R_M : " << theCoreIntervals_[ir*2+1] << " ";
1292  }
1293  LogInfo("FastCalorimetry") << std::endl;
1294 
1295  LogInfo("FastCalorimetry") << " Tail of the shower " << std::endl;
1296  for(unsigned ir=0; ir < theTailIntervals_.size()/2;++ir)
1297  {
1298  LogInfo("FastCalorimetry") << " r < " << theTailIntervals_[ir*2] << " R_M : " << theTailIntervals_[ir*2+1] << " ";
1299  }
1300  LogInfo("FastCalotimetry") << "Radius correction factor " << radiusFactor_ << std::endl;
1301  LogInfo("FastCalorimetry") << std::endl;
1302  if(mipValues_.size()>2) {
1303  LogInfo("FastCalorimetry") << "Improper number of parameters for the preshower ; using 95keV" << std::endl;
1304  mipValues_.clear();
1305  mipValues_.resize(2,0.000095);
1306  }
1307  }
1308 
1309  LogInfo("FastCalorimetry") << " FrontLeakageProbability : " << pulledPadSurvivalProbability_ << std::endl;
1310  LogInfo("FastCalorimetry") << " GapLossProbability : " << crackPadSurvivalProbability_ << std::endl;
1311 
1312 
1313  // RespCorrP: p (momentum), ECAL and HCAL corrections = f(p)
1314  edm::ParameterSet CalorimeterParam = fastCalo.getParameter<edm::ParameterSet>("CalorimeterProperties");
1315 
1316  rsp = CalorimeterParam.getParameter<std::vector<double> >("RespCorrP");
1317  LogInfo("FastCalorimetry") << " RespCorrP (rsp) size " << rsp.size() << std::endl;
1318 
1319  if( rsp.size()%3 !=0 ) {
1320  LogInfo("FastCalorimetry")
1321  << " RespCorrP size is wrong -> no corrections applied !!!"
1322  << std::endl;
1323 
1324  p_knots.push_back(14000.);
1325  k_e.push_back (1.);
1326  k_h.push_back (1.);
1327  }
1328  else {
1329  for(unsigned i = 0; i < rsp.size(); i += 3) {
1330  LogInfo("FastCalorimetry") << "i = " << i/3 << " p = " << rsp [i]
1331  << " k_e(p) = " << rsp[i+1]
1332  << " k_e(p) = " << rsp[i+2] << std::endl;
1333 
1334  p_knots.push_back(rsp[i]);
1335  k_e.push_back (rsp[i+1]);
1336  k_h.push_back (rsp[i+2]);
1337  }
1338  }
1339 
1340 
1341  //FR
1342  edm::ParameterSet HCALparameters = fastCalo.getParameter<edm::ParameterSet>("HCAL");
1343  optionHDSim_ = HCALparameters.getParameter<int>("SimOption");
1344  hdGridSize_ = HCALparameters.getParameter<int>("GridSize");
1345  hdSimMethod_ = HCALparameters.getParameter<int>("SimMethod");
1346  //RF
1347 
1348  unfoldedMode_ = fastCalo.getUntrackedParameter<bool>("UnfoldedMode",false);
1349 }
1350 
1351 
1352 void CalorimetryManager::updateMap(uint32_t cellid,float energy,int id,std::map<uint32_t,std::vector<std::pair<int,float> > > & mymap)
1353 {
1354  // std::cout << " updateMap " << std::endl;
1355  std::map<unsigned,std::vector<std::pair<int,float> > >::iterator cellitr;
1356  cellitr = mymap.find(cellid);
1357  if(!unfoldedMode_) id=0;
1358  if( cellitr==mymap.end())
1359  {
1360  std::vector<std::pair<int,float> > myElement;
1361  myElement.push_back(std::pair<int,float> (id,energy));
1362  mymap[cellid]=myElement;
1363  }
1364  else
1365  {
1366  if(!unfoldedMode_)
1367  {
1368  cellitr->second[0].second+=energy;
1369  }
1370  else
1371  cellitr->second.push_back(std::pair<int,float>(id,energy));
1372  }
1373 }
1374 
1375 void CalorimetryManager::updateMap(int hi,float energy,int tid,std::vector<std::vector<std::pair<int,float> > > & mymap, std::vector<int>& firedCells)
1376 {
1377  // Standard case first : one entry per cell
1378  if(!unfoldedMode_)
1379  {
1380  // if new entry, update the list
1381  if(mymap[hi].size()==0)
1382  {
1383  firedCells.push_back(hi);
1384  mymap[hi].push_back(std::pair<int,float>(0,energy));
1385  }
1386  else
1387  mymap[hi][0].second+=energy;
1388  }
1389  else
1390  {
1391  // std::cout << "update map " << mymap[hi].size() << " " << hi << std::setw(8) << std::setprecision(6) << energy ;
1392  // std::cout << " " << mymap[hi][0].second << std::endl;
1393  // the minimal size is always 1 ; in this case, no push_back
1394  if(mymap[hi].size()==0)
1395  {
1396  // if(tid==0) std::cout << " Shit ! " << std::endl;
1397  firedCells.push_back(hi);
1398  }
1399 
1400  mymap[hi].push_back(std::pair<int,float>(tid,energy));
1401  }
1402 
1403 }
1404 
1405 
1407 
1408  int sizeP = p_knots.size();
1409 
1410  if(sizeP <= 1) {
1411  ecorr = 1.;
1412  hcorr = 1.;
1413  }
1414  else {
1415  int ip = -1;
1416  for (int i = 0; i < sizeP; i++) {
1417  if (p < p_knots[i]) { ip = i; break;}
1418  }
1419  if (ip == 0) {
1420  ecorr = k_e[0];
1421  hcorr = k_h[0];
1422  }
1423  else {
1424  if(ip == -1) {
1425  ecorr = k_e[sizeP-1];
1426  hcorr = k_h[sizeP-1];
1427  }
1428  else {
1429  double x1 = p_knots[ip-1];
1430  double x2 = p_knots[ip];
1431  double y1 = k_e[ip-1];
1432  double y2 = k_e[ip];
1433 
1434  if(x1 == x2) {
1435  // std::cout << " equal p_knots values!!! " << std::endl;
1436  }
1437 
1438  ecorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
1439 
1440  y1 = k_h[ip-1];
1441  y2 = k_h[ip];
1442  hcorr = (y1 + (y2 - y1) * (p - x1)/(x2 - x1));
1443 
1444  }
1445  }
1446  }
1447 
1448  if(debug_)
1449  LogDebug("FastCalorimetry") << " p, ecorr, hcorr = " << p << " "
1450  << ecorr << " " << hcorr << std::endl;
1451 
1452 }
1453 
1454 
1456 {
1457  unsigned size=firedCellsEB_.size();
1458  // float sum=0.;
1459  for(unsigned ic=0;ic<size;++ic)
1460  {
1461  int hi=firedCellsEB_[ic];
1462  if(!unfoldedMode_)
1463  {
1464  c.push_back(PCaloHit(EBDetId::unhashIndex(hi),EBMapping_[hi][0].second,0.,0));
1465  // std::cout << "Adding " << hi << " " << EBDetId::unhashIndex(hi) << " " ;
1466  // std::cout << EBMapping_[hi][0].second << " " << EBMapping_[hi][0].first << std::endl;
1467  }
1468  else
1469  {
1470  unsigned npart=EBMapping_[hi].size();
1471  for(unsigned ip=0;ip<npart;++ip)
1472  {
1473  c.push_back(PCaloHit(EBDetId::unhashIndex(hi),EBMapping_[hi][ip].second,0.,
1474  EBMapping_[hi][ip].first));
1475 
1476  }
1477  }
1478 
1479  // sum+=cellit->second;
1480  }
1481 
1482 // for(unsigned ic=0;ic<61200;++ic)
1483 // {
1484 // EBDetId myCell(EBDetId::unhashIndex(ic));
1485 // if(!myCell.null())
1486 // {
1487 // float total=0.;
1488 // for(unsigned id=0;id<EBMapping_[ic].size();++id)
1489 // total+=EBMapping_[ic][id].second;
1490 // if(EBMapping_[ic].size()>0)
1491 // std::cout << "Adding " << ic << " " << myCell << " " << std::setprecision(8) <<total << std::endl;
1492 // }
1493 // }
1494 
1495 
1496  // std::cout << " SUM : " << sum << std::endl;
1497  // std::cout << " Added " <<c.size() << " hits " <<std::endl;
1498 }
1499 
1500 
1502 {
1503  unsigned size=firedCellsEE_.size();
1504  // float sum=0.;
1505  for(unsigned ic=0;ic<size;++ic)
1506  {
1507  int hi=firedCellsEE_[ic];
1508  if(!unfoldedMode_)
1509  c.push_back(PCaloHit(EEDetId::unhashIndex(hi),EEMapping_[hi][0].second,0.,0));
1510  else
1511  {
1512  unsigned npart=EEMapping_[hi].size();
1513  for(unsigned ip=0;ip<npart;++ip)
1514  c.push_back(PCaloHit(EEDetId::unhashIndex(hi),EEMapping_[hi][ip].second,0.,
1515  EEMapping_[hi][ip].first));
1516  }
1517 
1518  // sum+=cellit->second;
1519  }
1520  // std::cout << " SUM : " << sum << std::endl;
1521  // std::cout << " Added " <<c.size() << " hits " <<std::endl;
1522 }
1523 
1525 {
1526  unsigned size=firedCellsHCAL_.size();
1527  // float sum=0.;
1528  for(unsigned ic=0;ic<size;++ic)
1529  {
1530  int hi=firedCellsHCAL_[ic];
1531  if(!unfoldedMode_)
1532  c.push_back(PCaloHit(theDetIds_[hi],HMapping_[hi][0].second,0.,0));
1533  else
1534  {
1535  unsigned npart=HMapping_[hi].size();
1536  for(unsigned ip=0;ip<npart;++ip)
1537  c.push_back(PCaloHit(theDetIds_[hi],HMapping_[hi][ip].second,0.,
1538  HMapping_[hi][ip].first));
1539  }
1540 
1541  // sum+=cellit->second;
1542  }
1543  // std::cout << " SUM : " << sum << std::endl;
1544  // std::cout << " Added " <<c.size() << " hits " <<std::endl;
1545 }
1546 
1548 {
1549  std::map<uint32_t,std::vector<std::pair< int,float> > >::const_iterator cellit;
1550  std::map<uint32_t,std::vector<std::pair <int,float> > >::const_iterator preshEnd=ESMapping_.end();
1551 
1552  for(cellit=ESMapping_.begin();cellit!=preshEnd;++cellit)
1553  {
1554  if(!unfoldedMode_)
1555  c.push_back(PCaloHit(cellit->first,cellit->second[0].second,0.,0));
1556  else
1557  {
1558  unsigned npart=cellit->second.size();
1559  for(unsigned ip=0;ip<npart;++ip)
1560  {
1561  c.push_back(PCaloHit(cellit->first,cellit->second[ip].second,0.,cellit->second[ip].first));
1562  }
1563  }
1564  }
1565 }
1566 
1567 
1568 // The main danger in this method is to screw up to relationships between particles
1569 // So, the muon FSimTracks created by FSimEvent.cc are simply to be updated
1571 {
1572  unsigned size=muons.size();
1573  for(unsigned i=0; i<size;++i)
1574  {
1575  int id=muons[i].trackId();
1576  if(abs(muons[i].type())!=13) continue;
1577  // identify the corresponding muon in the local collection
1578 
1579  std::vector<FSimTrack>::const_iterator itcheck=find_if(muonSimTracks.begin(),muonSimTracks.end(),FSimTrackEqual(id));
1580  if(itcheck!=muonSimTracks.end())
1581  {
1582  muons[i].setTkPosition(itcheck->trackerSurfacePosition());
1583  muons[i].setTkMomentum(itcheck->trackerSurfaceMomentum());
1584 // std::cout << " Found the SimTrack " << std::endl;
1585 // std::cout << *itcheck << std::endl;
1586 // std::cout << "SimTrack Id "<< id << " " << muons[i] << " " << std::endl;
1587  }
1588 // else
1589 // {
1590 // std::cout << " Calorimetery Manager : this should really not happen " << std::endl;
1591 // std::cout << " Was looking for " << id << " " << muons[i] << std::endl;
1592 // for(unsigned i=0;i<muonSimTracks.size();++i)
1593 // std::cout << muonSimTracks[i] << std::endl;
1594 // }
1595  }
1596 
1597 }
1598 
#define LogDebug(id)
void setSpotEnergy(double e)
Set the spot energy.
Definition: HcalHitMaker.h:28
double getHCALEnergyResponse(double e, int hit)
type
Definition: HCALResponse.h:22
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.
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:73
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:129
int onLayer2() const
Definition: FSimTrack.h:96
GflashPiKShowerProfile * thePiKProfile
void bookByNumber(const std::string &name, int n1, int n2, int nx, float xmin, float xmax, int ny=0, float ymin=0., float ymax=0.)
Definition: Histos.cc:200
void updateMap(uint32_t cellid, float energy, int id, std::map< uint32_t, std::vector< std::pair< int, float > > > &mymap)
std::map< uint32_t, std::vector< std::pair< int, float > > > ESMapping_
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:168
void setCrackPadSurvivalProbability(double val)
Definition: EcalHitMaker.h:134
std::vector< std::vector< std::pair< int, float > > > EBMapping_
response responseHCAL(int mip, double energy, double eta, int partype)
GflashHadronShowerProfile * theProfile
const RawParticle & layer1Entrance() const
The particle at Preshower Layer 1.
Definition: FSimTrack.h:117
bool compute()
Compute the shower longitudinal and lateral development.
Definition: HDShower.cc:471
std::pair< double, double > response
Definition: HCALResponse.h:20
#define abs(x)
Definition: mlp_lapack.h:159
void reconstructECAL(const FSimTrack &track)
void setPreshower(PreshowerHitMaker *const myPresh)
set the preshower address
Definition: EMShower.cc:632
void loadFromPreshower(edm::PCaloHitContainer &c) const
#define NULL
Definition: scimark2.h:8
double npart
Definition: HydjetWrapper.h:45
const CaloSubdetectorGeometry * getHcalGeometry() const
Definition: Calorimeter.h:57
void readParameters(const edm::ParameterSet &fastCalo)
TRandom random
Definition: MVATrainer.cc:138
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:115
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< std::vector< std::pair< int, float > > > EEMapping_
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:244
std::vector< int > firedCellsEB_
double gaussShoot(double mean=0.0, double sigma=1.0) const
Definition: RandomEngine.h:37
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
dictionary map
Definition: Association.py:160
std::vector< int > firedCellsHCAL_
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
bool compute()
Compute the shower longitudinal and lateral development.
Definition: HFShower.cc:475
void setRadiusFactor(double r)
Definition: EcalHitMaker.h:130
GflashAntiProtonShowerProfile * theAntiProtonProfile
math::XYZVector XYZVector
int getmip()
Definition: HDShower.h:41
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 book(const std::string &name, int nx, float xmin, float xmax, int ny=0, float ymin=0., float ymax=0.)
Book an histogram (1D or 2D)
Definition: Histos.cc:23
tuple result
Definition: query.py:137
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< DetId > theDetIds_
std::vector< double > radiusPreshowerCorrections_
std::vector< int > firedCellsEE_
const HCALProperties * hcalProperties(int onHcal) const
HCAL properties.
Definition: Calorimeter.cc:84
static Histos * instance()
Definition: Histos.cc:15
const RawParticle & ecalEntrance() const
The particle at ECAL entrance.
Definition: FSimTrack.h:123
int onVFcal() const
Definition: FSimTrack.h:111
const std::map< uint32_t, float > & getHits()
Definition: HcalHitMaker.h:37
std::vector< double > theTailIntervals_
bool first
Definition: L1TdeRCT.cc:79
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
std::vector< std::vector< std::pair< int, float > > > HMapping_
void loadMuonSimTracks(edm::SimTrackContainer &m) const
unsigned int nTracks() const
Number of tracks.
Definition: FSimEvent.cc:48
HCALResponse * myHDResponse_
CaloGeometryHelper * myCalorimeter_
const std::map< unsigned, float > & getHits()
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 put(const std::string &file, std::string name="")
Write one or all histogram(s) in a file.
Definition: Histos.cc:69
void loadFromHcal(edm::PCaloHitContainer &c) const
#define M_PI
Definition: BFit3D.cc:3
void updateState(ParticlePropagator &myTrack, double radlen)
Compute the material effect (calls the sub class)
int hashedIndex() const
Definition: EEDetId.h:177
void EMShowerSimulation(const FSimTrack &myTrack)
Log< T >::type log(const T &t)
Definition: Log.h:22
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_
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.cc:12
bool null() const
is this a null id ?
Definition: DetId.h:47
CalorimeterNumber getCalorimeterNumber(const Gflash3Vector position)
double b
Definition: hdecay.h:120
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
math::XYZVector XYZPoint
int type() const
particle type (HEP PDT convension)
Definition: CoreSimTrack.h:40
double a
Definition: hdecay.h:121
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:120
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:126
void setMipEnergy(double e1, double e2)
tuple cout
Definition: gather_cfg.py:41
void setPreshowerPresent(bool ps)
Definition: EcalHitMaker.h:137
double getHCALEnergyResolution(double e, int hit)
string s
Definition: asciidump.py:422
DetId getClosestCell(const XYZPoint &point, bool ecal, bool central) const
tuple status
Definition: ntuplemaker.py:245
EnergyLossSimulator * energyLossSimulator() const
Return the Energy Loss engine.
const std::map< uint32_t, float > & getHits()
not been done.
bool addHit(double r, double phi, unsigned layer=0)
add the hit in the HCAL in local coordinates
Definition: HcalHitMaker.cc:28
HSParameters * myHSParameters_
std::vector< SimTrack > SimTrackContainer
tuple size
Write out results.
void setVertex(const XYZTLorentzVector &vtx)
set the vertex
Definition: RawParticle.h:287
bool setDepth(double, bool inCm=false)
set the depth in X0 or Lambda0 units depending on showerType
int hashed_index() const
Definition: HcalDetId.cc:119
void initialize(int showerType, double energy, double globalTime, double charge, Gflash3Vector &position, Gflash3Vector &momentum)
bool computeShower()
Definition: HDRShower.cc:46
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:642
void setGrid(EcalHitMaker *const myGrid)
set the grid address
Definition: EMShower.h:60
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:57
void loadFromEcalBarrel(edm::PCaloHitContainer &c) const