CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalRecHitsMaker.cc
Go to the documentation of this file.
3 
15 #include "CLHEP/GenericFunctions/Erf.hh"
26 
27 #include "TFile.h"
28 #include "TGraph.h"
29 #include "TROOT.h"
30 #include <fstream>
31 
32 class RandomEngine;
33 
34 bool HcalRecHitsMaker::initialized_ = false;
35 std::vector<float> HcalRecHitsMaker::peds_;
36 std::vector<int> HcalRecHitsMaker::fctoadc_;
37 std::vector<float> HcalRecHitsMaker::sat_;
38 std::vector<float> HcalRecHitsMaker::gains_;
39 std::vector<float> HcalRecHitsMaker::noisesigma_;
40 std::vector<float> HcalRecHitsMaker::TPGFactor_;
41 std::vector<float> HcalRecHitsMaker::miscalib_;
42 std::vector<HcalDetId> HcalRecHitsMaker::theDetIds_;
43 std::vector<int> HcalRecHitsMaker::hbhi_;
44 std::vector<int> HcalRecHitsMaker::hehi_;
45 std::vector<int> HcalRecHitsMaker::hohi_;
46 std::vector<int> HcalRecHitsMaker::hfhi_;
47 unsigned HcalRecHitsMaker::maxIndex_ = 0 ;
48 
50  const RandomEngine * myrandom)
51  :
52  det_(det),
53  doDigis_(false),
54  noiseFromDb_(false),
55  random_(myrandom)
56  //,myHcalSimParameterMap_(0)
57 {
58  edm::ParameterSet RecHitsParameters=p.getParameter<edm::ParameterSet>("HCAL");
59  noise_ = RecHitsParameters.getParameter<std::vector<double> >("Noise");
60  corrfac_ = RecHitsParameters.getParameter<std::vector<double> >("NoiseCorrectionFactor");
61  threshold_ = RecHitsParameters.getParameter<std::vector<double> >("Threshold");
62  doSaturation_ = RecHitsParameters.getParameter<bool>("EnableSaturation");
63 
64  refactor_ = RecHitsParameters.getParameter<double> ("Refactor");
65  refactor_mean_ = RecHitsParameters.getParameter<double> ("Refactor_mean");
66  hcalfileinpath_= RecHitsParameters.getParameter<std::string> ("fileNameHcal");
67  inputCol_=RecHitsParameters.getParameter<edm::InputTag>("MixedSimHits");
69 
70  if(det_==4)
71  {
72  hbhi_.reserve(2600);
73  hehi_.reserve(2600);
74  }
75  else if (det_==5)
76  hohi_.reserve(2200);
77  else if (det_==6)
78  hfhi_.reserve(1800);
79 
80  if(threshold_.size()!=noise_.size())
81  {
82  edm::LogWarning("CaloRecHitsProducer") << " WARNING : HCAL Noise simulation, the number of parameters should be the same for the noise and the thresholds. Disabling the noise simulation " << std::endl;
83  noise_.clear();
84  noise_.push_back(0.);
85  }
86  else
87  nnoise_=noise_.size();
88 
89  // edm::ParameterSet hcalparam = p2.getParameter<edm::ParameterSet>("hcalSimParam");
90  // myHcalSimParameterMap_ = new HcalSimParameterMap(hcalparam);
91 
92  // Computes the fraction of HCAL above the threshold
93  Genfun::Erf myErf;
94  hcalHotFraction_.resize(nnoise_,0.);
96  if(noise_.size()>0)
97  {
98  for(unsigned inoise=0;inoise<nnoise_;++inoise)
99  {
100  if(noise_[inoise]==0) {
101  hcalHotFraction_[inoise]=0.;
102  continue;
103  } else if(noise_[inoise]==-1) {
104  noiseFromDb_=true;
105  continue;
106  } else {
107  hcalHotFraction_.push_back(0.5-0.5*myErf(threshold_[inoise]/noise_[inoise]/sqrt(2.)));
108  myGaussianTailGenerators_[inoise]=new GaussianTail(random_,noise_[inoise],threshold_[inoise]);
109  }
110  }
111  }
112 }
113 
115 {
116  clean();
117  if(myGaussianTailGenerators_.size())
118  {
119  for(unsigned igt=0; igt<myGaussianTailGenerators_.size();++igt)
120  delete myGaussianTailGenerators_[igt];
121  }
123  theDetIds_.clear();
124  hbhi_.clear();
125  hehi_.clear();
126  hohi_.clear();
127  hfhi_.clear();
128 
129 }
130 
131 void HcalRecHitsMaker::init(const edm::EventSetup &es,bool doDigis,bool doMiscalib)
132 {
133  doDigis_=doDigis;
134  doMiscalib_=doMiscalib;
135 // needed for the noise simulation
136  edm::ESHandle<HcalDbService> conditions;
137  es.get<HcalDbRecord>().get(conditions);
138  const HcalDbService * theDbService=conditions.product();
139 
140  // get the correction factors
142  es.get<HcalRespCorrsRcd>().get(rchandle);
143  myRespCorr= rchandle.product();
144 
145 
146  if(!initialized_)
147  {
148  theDetIds_.resize(9201);
149  unsigned ncells=createVectorsOfCells(es);
150  edm::LogInfo("CaloRecHitsProducer") << "Total number of cells in HCAL " << ncells << std::endl;
151  hcalRecHits_.resize(maxIndex_+1,0.);
152  edm::LogInfo("CaloRecHitsProducer") << "Largest HCAL hashedindex" << maxIndex_ << std::endl;
153 
154  peds_.resize(9201);
155  gains_.resize(9201);
156  if(doSaturation_)
157  sat_.resize(9201);
158  if(noiseFromDb_)
159  noisesigma_.resize(9201);
160 
161 
162  miscalib_.resize(maxIndex_+1,1.);
163  // Read from file ( a la HcalRecHitsRecalib.cc)
164  // here read them from xml (particular to HCAL)
165  CaloMiscalibMapHcal mapHcal;
166  mapHcal.prefillMap();
167 
168 
169  edm::FileInPath hcalfiletmp("CalibCalorimetry/CaloMiscalibTools/data/"+hcalfileinpath_);
170  std::string hcalfile=hcalfiletmp.fullPath();
171  if(doMiscalib_ && !hcalfile.empty())
172  {
173  MiscalibReaderFromXMLHcal hcalreader_(mapHcal);
174 
175  hcalreader_.parseXMLMiscalibFile(hcalfile);
176  // mapHcal.print();
177  std::map<uint32_t,float>::const_iterator it=mapHcal.get().begin();
178  std::map<uint32_t,float>::const_iterator itend=mapHcal.get().end();
179  for(;it!=itend;++it)
180  {
181  HcalDetId myDetId(it->first);
182  float icalconst=it->second;
184  }
185  }
186 
187 
188  // Open the histogram for the fC to ADC conversion
189  gROOT->cd();
190  edm::FileInPath myDataFile("FastSimulation/CaloRecHitsProducer/data/adcvsfc.root");
191  TFile * myFile = new TFile(myDataFile.fullPath().c_str(),"READ");
192  TGraph * myGraf = (TGraph*)myFile->Get("adcvsfc");
193  unsigned size=myGraf->GetN();
194  fctoadc_.resize(10000);
195  unsigned p_index=0;
196  fctoadc_[0]=0;
197  int prev_nadc=0;
198  int nadc=0;
199  for(unsigned ibin=0;ibin<size;++ibin)
200  {
201  double x,y;
202  myGraf->GetPoint(ibin,x,y);
203  int index=(int)floor(x);
204  if(index<0||index>=10000) continue;
205  prev_nadc=nadc;
206  nadc=(int)y;
207  // Now fills the vector
208  for(unsigned ivec=p_index;ivec<(unsigned)index;++ivec)
209  {
210  fctoadc_[ivec] = prev_nadc;
211  }
212  p_index = index;
213  }
214  myFile->Close();
215  gROOT->cd();
216  edm::FileInPath myTPGFilePath("CalibCalorimetry/HcalTPGAlgos/data/RecHit-TPG-calib.dat");
217  TPGFactor_.resize(87,1.2);
218  std::ifstream myTPGFile(myTPGFilePath.fullPath().c_str(),ifstream::in);
219  if(myTPGFile)
220  {
221  float gain;
222  myTPGFile >> gain;
223  for(unsigned i=0;i<86;++i)
224  {
225  myTPGFile >> TPGFactor_[i] ;
226  // std::cout << TPGFactor_[i] << std::endl;
227  }
228  }
229  else
230  {
231  std::cout << " Unable to open CalibCalorimetry/HcalTPGAlgos/data/RecHit-TPG-calib.dat" << std::endl;
232  std::cout << " Using a constant 1.2 factor " << std::endl;
233  }
234  //HB
235  for(unsigned ic=0;ic<nhbcells_;++ic)
236  {
237  float gain = theDbService->getGain(theDetIds_[hbhi_[ic]])->getValue(0);
238  float mgain=0.;
239  for(unsigned ig=0;ig<4;++ig)
240  mgain+=theDbService->getGain(theDetIds_[hbhi_[ic]])->getValue(ig);
241  if(noiseFromDb_)
242  noisesigma_[hbhi_[ic]]=noiseInfCfromDB(theDbService,theDetIds_[hbhi_[ic]])*mgain*0.25;
243  // std::cout << " NOISEHB " << theDetIds_[hbhi_[ic]].ieta() << " " << noisesigma_[hbhi_[ic]] << " "<< std::endl;
244  // 10000 (ADC scale) / 4. (to compute the mean) / 0.92 ADC/fC
245  // *1.25 (only ~80% in 1ts Digi, while saturation applied to 4ts RecHit)
246  int ieta=theDetIds_[hbhi_[ic]].ieta();
247  float tpgfactor=TPGFactor_[(ieta>0)?ieta+43:-ieta];
248  mgain*=2500./0.92*tpgfactor ;// 10000 (ADC scale) / 4. (to compute the mean)
249  sat_[hbhi_[ic]]=(doSaturation_)?mgain:99999.;
250 
251  peds_[hbhi_[ic]]=theDbService->getPedestal(theDetIds_[hbhi_[ic]])->getValue(0);
252 
253  gain*=tpgfactor;
254  gains_[hbhi_[ic]]=gain;
255  }
256  //HE
257 
258  for(unsigned ic=0;ic<nhecells_;++ic)
259  {
260  float gain= theDbService->getGain(theDetIds_[hehi_[ic]])->getValue(0);
261  int ieta=theDetIds_[hehi_[ic]].ieta();
262  float mgain=0.;
263  for(unsigned ig=0;ig<4;++ig)
264  mgain+=theDbService->getGain(theDetIds_[hehi_[ic]])->getValue(ig);
265  if(noiseFromDb_)
266  noisesigma_[hehi_[ic]]=noiseInfCfromDB(theDbService,theDetIds_[hehi_[ic]])*mgain*0.25;
267 
268  // std::cout << " NOISEHE " << theDetIds_[hehi_[ic]].ieta() << " " << noisesigma_[hehi_[ic]] << " "<< std::endl;
269  float tpgfactor=TPGFactor_[(ieta>0)?ieta+44:-ieta+1];
270  mgain*=2500./0.92*tpgfactor;
271  sat_[hehi_[ic]]=(doSaturation_)?mgain:99999.;
272 
273  gain*=tpgfactor;
274  peds_[hehi_[ic]]=theDbService->getPedestal(theDetIds_[hehi_[ic]])->getValue(0);
275  gains_[hehi_[ic]]=gain;
276  }
277  //HO
278 
279  for(unsigned ic=0;ic<nhocells_;++ic)
280  {
281  float ped=theDbService->getPedestal(theDetIds_[hohi_[ic]])->getValue(0);
282  float gain=theDbService->getGain(theDetIds_[hohi_[ic]])->getValue(0);
283  float mgain=0.;
284  for(unsigned ig=0;ig<4;++ig)
285  mgain+=theDbService->getGain(theDetIds_[hohi_[ic]])->getValue(ig);
286  if(noiseFromDb_)
287  noisesigma_[hohi_[ic]]=noiseInfCfromDB(theDbService,theDetIds_[hohi_[ic]])*mgain*0.25;
288  // std::cout << " NOISEHO " << theDetIds_[hohi_[ic]].ieta() << " " << noisesigma_[hohi_[ic]] << " "<< std::endl;
289  int ieta=HcalDetId(hohi_[ic]).ieta();
290  float tpgfactor=TPGFactor_[(ieta>0)?ieta+43:-ieta];
291  mgain*=2500./0.92*tpgfactor;
292  sat_[hohi_[ic]]=(doSaturation_)?mgain:99999.;
293 
294  gain*=tpgfactor;
295  peds_[hohi_[ic]]=ped;
296  gains_[hohi_[ic]]=gain;
297  }
298  //HF
299 
300  for(unsigned ic=0;ic<nhfcells_;++ic)
301  {
302  float ped=theDbService->getPedestal(theDetIds_[hfhi_[ic]])->getValue(0);
303  float gain=theDbService->getGain(theDetIds_[hfhi_[ic]])->getValue(0);
304  float mgain=0.;
305  for(unsigned ig=0;ig<4;++ig)
306  mgain+=theDbService->getGain(theDetIds_[hfhi_[ic]])->getValue(ig);
307  // additional 1/2 factor for the HF (Salavat)
308  if(noiseFromDb_)
309  {
310  // computation from when the noise was taken
311  noisesigma_[hfhi_[ic]]=noiseInfCfromDB(theDbService,theDetIds_[hfhi_[ic]])*mgain*0.25;
312  }
313  // std::cout << " NOISEHF " << theDetIds_[hfhi_[ic]].ieta() << " " << noisesigma_[hfhi_[ic]] << " "<< std::endl;
314 
315  mgain*=2500./0.36;
316  sat_[hfhi_[ic]]=(doSaturation_)?mgain:99999.;
317  int ieta=theDetIds_[hfhi_[ic]].ieta();
318  gain*=TPGFactor_[(ieta>0)?ieta+45:-ieta+2];
319  peds_[hfhi_[ic]]=ped;
320  gains_[hfhi_[ic]]=gain;
321  }
322  initialized_=true;
323  }
324 
325  // clear the vector we don't need. It is a bit stupid
326  hcalRecHits_.resize(maxIndex_+1,0.);
327 
328 }
329 
330 
331 // Get the PCaloHits from the event. They have to be stored in a map, because when
332 // the pile-up is added thanks to the Mixing Module, the same cell can be present several times
334 {
335  clean();
336 
338  iEvent.getByLabel(inputCol_,cf);
339  std::auto_ptr<MixCollection<PCaloHit> > colcalo(new MixCollection<PCaloHit>(cf.product(),std::pair<int,int>(0,0) ));
340 
341  MixCollection<PCaloHit>::iterator it=colcalo->begin();;
342  MixCollection<PCaloHit>::iterator itend=colcalo->end();
343  unsigned counter=0;
344  for(;it!=itend;++it)
345  {
346  HcalDetId detid(it->id());
347  int hashedindex=detid.hashed_index();
348 
349  // apply ToF correction
350  int time_slice=0; // temporary
351  double fTOF=1.;
352  if (detid.subdet()==HcalForward) fTOF = (time_slice==0) ? 1. : 0.;
353  else fTOF = fractionOOT(time_slice);
354 
355  switch(detid.subdet())
356  {
357  case HcalBarrel:
358  {
359  if(det_==4)
360  Fill(hashedindex,fTOF*(it->energy()),firedCells_,noise_[0],corrfac_[0]);
361  }
362  break;
363  case HcalEndcap:
364  {
365  if(det_==4)
366  Fill(hashedindex,fTOF*(it->energy()),firedCells_,noise_[1],corrfac_[1]);
367  }
368  break;
369  case HcalOuter:
370  {
371  if(det_==5)
372  Fill(hashedindex,fTOF*(it->energy()),firedCells_,noise_[0],corrfac_[0]);
373  }
374  break;
375  case HcalForward:
376  {
377  if(det_==6 && time_slice==0) // skip the HF hit if out-of-time
378  Fill(hashedindex,it->energy(),firedCells_,noise_[0],corrfac_[0]);
379  }
380  break;
381  default:
382  edm::LogWarning("CaloRecHitsProducer") << "RecHit not registered\n";
383  ;
384  }
385  ++counter;
386  }
387 }
388 
389 // Fills the collections.
391 {
392  loadPCaloHits(iEvent);
393  noisify();
394  hbheHits.reserve(firedCells_.size());
395  if(doDigis_)
396  {
397  hbheDigis.reserve(firedCells_.size());
398  }
399  static HcalQIESample zeroSample(0,0,0,0);
400  unsigned nhits=firedCells_.size();
401  // HB and HE
402 
403  for(unsigned ihit=0;ihit<nhits;++ihit)
404  {
405  unsigned cellhashedindex=firedCells_[ihit];
406  const HcalDetId& detid = theDetIds_[cellhashedindex];
407  unsigned subdet=(detid.subdet()==HcalBarrel) ? 0: 1;
408 
409  float energy=hcalRecHits_[cellhashedindex];
410  // Check if it is above the threshold
411  if(energy<threshold_[subdet]) continue;
412  // apply RespCorr only to the RecHit
413  energy *= myRespCorr->getValues(theDetIds_[cellhashedindex])->getValue();
414  // poor man saturation
415  if(energy>sat_[cellhashedindex])
416  {
417  // std::cout << " Saturation " << energy << " " << sat_[cellhashedindex] << " HB " << std::endl;
418  energy=sat_[cellhashedindex];
419  }
420 
421 
422  hbheHits.push_back(HBHERecHit(detid,energy,0.));
423  if(doDigis_)
424  {
425  HBHEDataFrame myDataFrame(detid);
426  myDataFrame.setSize(2);
427  double nfc=hcalRecHits_[cellhashedindex]/gains_[cellhashedindex]+peds_[cellhashedindex];
428  int nadc=fCtoAdc(nfc);
429  HcalQIESample qie(nadc, 0, 0, 0) ;
430  myDataFrame.setSample(0,qie);
431  myDataFrame.setSample(1,zeroSample);
432  hbheDigis.push_back(myDataFrame);
433  }
434  }
435 }
436 
437 
438 // Fills the collections.
440 {
441  loadPCaloHits(iEvent);
442  noisify();
443  hoHits.reserve(firedCells_.size());
444  if(doDigis_)
445  {
446  hoDigis.reserve(firedCells_.size());
447  }
448  static HcalQIESample zeroSample(0,0,0,0);
449 
450  // HO
451  unsigned nhits=firedCells_.size();
452  for(unsigned ihit=0;ihit<nhits;++ihit)
453  {
454 
455  unsigned cellhashedindex=firedCells_[ihit];
456  // Check if it is above the threshold
457  if(hcalRecHits_[cellhashedindex]<threshold_[0]) continue;
458 
459  const HcalDetId& detid=theDetIds_[cellhashedindex];
460  int ieta = detid.ieta();
461 
462  // Force only Ring#0 to remain
463  if(ieta > 4 || ieta < -4 ) continue;
464 
465  float energy=hcalRecHits_[cellhashedindex];
466  // apply RespCorr
467  energy *= myRespCorr->getValues(theDetIds_[cellhashedindex])->getValue();
468 
469  // poor man saturation
470  if(energy>sat_[cellhashedindex]) energy=sat_[cellhashedindex];
471 
472  hoHits.push_back(HORecHit(detid,energy,0));
473  }
474 }
475 
476 // Fills the collections.
478 {
479  loadPCaloHits(iEvent);
480  noisify();
481  hfHits.reserve(firedCells_.size());
482  if(doDigis_)
483  {
484  hfDigis.reserve(firedCells_.size());
485  }
486  static HcalQIESample zeroSample(0,0,0,0);
487 
488  unsigned nhits=firedCells_.size();
489  for(unsigned ihit=0;ihit<nhits;++ihit)
490  {
491  unsigned cellhashedindex=firedCells_[ihit];
492  // Check if it is above the threshold
493  if(hcalRecHits_[cellhashedindex]<threshold_[0]) continue;
494 
495  float energy=hcalRecHits_[cellhashedindex];
496 
497  // apply RespCorr
498  energy *= myRespCorr->getValues(theDetIds_[cellhashedindex])->getValue();
499 
500  // poor man saturation
501  if(energy>sat_[cellhashedindex]) energy=sat_[cellhashedindex];
502 
503  const HcalDetId & detid=theDetIds_[cellhashedindex];
504  hfHits.push_back(HFRecHit(detid,energy,0.));
505  if(doDigis_)
506  {
507  HFDataFrame myDataFrame(detid);
508  myDataFrame.setSize(1);
509 
510  double nfc= hcalRecHits_[cellhashedindex]/gains_[cellhashedindex]+peds_[cellhashedindex];
511  int nadc=fCtoAdc(nfc/2.6);
512  HcalQIESample qie(nadc, 0, 0, 0) ;
513  myDataFrame.setSample(0,qie);
514  hfDigis.push_back(myDataFrame);
515  }
516  }
517 }
518 
519 
520 // For a fast injection of the noise: the list of cell ids is stored
522 {
524  es.get<CaloGeometryRecord>().get(pG);
529 
531 }
532 
533 // list of the cellids for a given subdetector
534 unsigned HcalRecHitsMaker::createVectorOfSubdetectorCells(const CaloGeometry& cg,int subdetn,std::vector<int>& cellsvec )
535 {
536 
538  const std::vector<DetId>& ids=geom->getValidDetIds(DetId::Hcal,subdetn);
539 
540  for (std::vector<DetId>::const_iterator i=ids.begin(); i!=ids.end(); i++)
541  {
542  HcalDetId myDetId(*i);
543  // std::cout << myDetId << myHcalSimParameterMap_->simParameters(myDetId).simHitToPhotoelectrons() << std::endl;;
544  // std::cout << " hi " << hi << " " theDetIds_.size() << std::endl;
545  unsigned hi=myDetId.hashed_index();
546  theDetIds_[hi]=myDetId;
547  // std::cout << myDetId << " " << hi << std::endl;
548  cellsvec.push_back(hi);
549 
550  if(hi>maxIndex_)
551  maxIndex_=hi;
552  }
553  return cellsvec.size();
554 }
555 
556 // Takes a hit (from a PSimHit) and fills a map
557 void HcalRecHitsMaker::Fill(int id, float energy, std::vector<int>& theHits,float noise,float correctionfactor)
558 {
559  if(doMiscalib_)
560  energy*=miscalib_[id];
561 
562  if(noiseFromDb_)
563  noise=noisesigma_[id]*correctionfactor;
564 
565  // Check if the RecHit exists
566  if(hcalRecHits_[id]>0.)
568  else
569  {
570  // the noise is injected only the first time
571  hcalRecHits_[id]=energy + random_->gaussShoot(0.,noise);
572  theHits.push_back(id);
573  }
574 }
575 
577 {
578  unsigned total=0;
579  switch(det_)
580  {
581  case 4:
582  {
583  // do the HB
584  if(noise_[0] != 0.) {
586  }
587  // do the HE
588  if(noise_[1] != 0.) {
590  }
591  }
592  break;
593  case 5:
594  {
595  // do the HO
596  if(noise_[0] != 0.) {
598  }
599  }
600  break;
601  case 6:
602  {
603  // do the HF
604  if(noise_[0] != 0.) {
606  }
607  }
608  break;
609  default:
610  break;
611  }
612  edm::LogInfo("CaloRecHitsProducer") << "CaloRecHitsProducer : added noise in "<< total << " HCAL cells " << std::endl;
613 }
614 
615 unsigned HcalRecHitsMaker::noisifySubdet(std::vector<float>& theMap, std::vector<int>& theHits, const std::vector<int>& thecells, unsigned ncells, double hcalHotFraction,const GaussianTail *myGT,double sigma,double threshold,double correctionfactor)
616 {
617  // If the fraction of "hot " is small, use an optimized method to inject noise only in noisy cells. The 30% has not been tuned
618  if(!noiseFromDb_ && hcalHotFraction==0.) return 0;
619  if(hcalHotFraction<0.3 && !noiseFromDb_)
620  {
621  double mean = (double)(ncells-theHits.size())*hcalHotFraction;
622  unsigned nhcal = random_->poissonShoot(mean);
623 
624  unsigned ncell=0;
625  unsigned cellindex=0;
626  uint32_t cellhashedindex=0;
627 
628  while(ncell < nhcal)
629  {
630  cellindex = (unsigned)(random_->flatShoot()*ncells);
631  cellhashedindex = thecells[cellindex];
632 
633  if(hcalRecHits_[cellhashedindex]==0.) // new cell
634  {
635  hcalRecHits_[cellhashedindex]=myGT->shoot();
636  theHits.push_back(cellhashedindex);
637  ++ncell;
638  }
639  }
640  return ncell;
641  }
642  else // otherwise, inject noise everywhere
643  {
644  uint32_t cellhashedindex=0;
645  unsigned nhcal=thecells.size();
646 
647 
648  for(unsigned ncell=0;ncell<nhcal;++ncell)
649  {
650  cellhashedindex = thecells[ncell];
651  if(hcalRecHits_[cellhashedindex]==0.) // new cell
652  {
653 
654  sigma=noisesigma_[cellhashedindex]*correctionfactor;
655 
656  double noise =random_->gaussShoot(0.,sigma);
657  if(noise>threshold)
658  {
659  hcalRecHits_[cellhashedindex]=noise;
660  theHits.push_back(cellhashedindex);
661  }
662  }
663  }
664  return nhcal;
665  }
666  return 0;
667 }
668 
670 {
672 }
673 
674 void HcalRecHitsMaker::cleanSubDet(std::vector<float>& hits,std::vector<int>& cells)
675 {
676  unsigned size=cells.size();
677  // Reset the energies
678  for(unsigned ic=0;ic<size;++ic)
679  {
680  hits[cells[ic]] = 0.;
681  }
682  // Clear the list of fired cells
683  cells.clear();
684 }
685 
686 // fC to ADC conversion
687 int HcalRecHitsMaker::fCtoAdc(double fc) const
688 {
689  if(fc<0.) return 0;
690  if(fc>9985.) return 127;
691  return fctoadc_[(unsigned)floor(fc)];
692 }
693 
694 double HcalRecHitsMaker::noiseInfCfromDB(const HcalDbService * conditions,const HcalDetId & detId)
695 {
696  // method from Salavat
697  // fetch pedestal widths (noise sigmas for all 4 CapID)
698  const HcalPedestalWidth* pedWidth =
699  conditions-> getPedestalWidth(detId);
700  double ssqq_1 = pedWidth->getSigma(0,0);
701  double ssqq_2 = pedWidth->getSigma(1,1);
702  double ssqq_3 = pedWidth->getSigma(2,2);
703  double ssqq_4 = pedWidth->getSigma(3,3);
704 
705  // correction factors (hb,he,ho,hf)
706  // static float corrfac[4]={1.39,1.32,1.17,3.76};
707  // static float corrfac[4]={0.93,0.88,1.17,2.51}; // divided HB, HE, HF by 1.5 (to take into account the halving of the number of time slices), HO did not change
708 
709  int sub = detId.subdet();
710 
711  // HO: only Ring#0 matters
712  int ieta = detId.ieta();
713  if (sub == 3 && abs (ieta) > 4) return 0.;
714 
715  // effective RecHits (for this particular detId) noise calculation :
716 
717  double sig_sq_mean = 0.25 * ( ssqq_1 + ssqq_2 + ssqq_3 + ssqq_4);
718 
719  // f - external parameter (currently set to 0.5 in the FullSim) !!!
720  double f=0.5;
721 
722  double term = sqrt (1. + sqrt(1. - 2.*f*f));
723  double alpha = sqrt (0.5) * term;
724  double beta = sqrt (0.5) * f / term;
725 
726  // double RMS1 = sqrt(sig_sq_mean) * sqrt (2.*beta*beta + alpha*alpha) ;
727  double RMS4 = sqrt(sig_sq_mean) * sqrt (2.*beta*beta + 2.*(alpha-beta)*(alpha-beta) + 2.*(alpha-2.*beta)*(alpha-2.*beta)) ;
728 
729  double noise_rms_fC;
730 
731  // if(sub == 4) noise_rms_fC = RMS1;
732  // else noise_rms_fC = RMS4;
733  noise_rms_fC = RMS4;
734 
735 
736  // to convert from above fC to GeV - multiply by gain (GeV/fC)
737  // const HcalGain* gain = conditions->getGain(detId);
738  // double noise_rms_GeV = noise_rms_fC * gain->getValue(0); // Noise RMS (GeV) for detId channel
739  return noise_rms_fC;
740 }
741 
742 // fraction of energy collected as a function of ToF (for out-of-time particles; use case is out-of-time pileup)
743 double HcalRecHitsMaker::fractionOOT(int time_slice)// in units of 25 ns; 0 means in-time
744 {
745  double SF = 100./88.; // to normalize to in-time signal (88% is in the reco window)
746  if (time_slice==-4) {
747  return 0.02*SF;
748  } else if (time_slice==-3) {
749  return 0.06*SF;
750  } else if (time_slice==-2) {
751  return 0.19*SF;
752  } else if (time_slice==-1) {
753  return 0.24*SF;
754  } else if (time_slice==0) {
755  return 1.;
756  } else if (time_slice==1) {
757  return 0.70*SF;
758  } else {
759  return 0.;
760  }
761 
762 }
const double beta
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
const std::map< uint32_t, float > & get()
int i
Definition: DBlmapReader.cc:9
static std::vector< float > peds_
float alpha
Definition: AMPTWrapper.h:95
HcalRecHitsMaker(edm::ParameterSet const &p, int, const RandomEngine *random)
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:32
static std::vector< float > sat_
std::vector< GaussianTail * > myGaussianTailGenerators_
void Fill(int id, float energy, std::vector< int > &myHits, float noise, float correctionfactor)
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
int fCtoAdc(double fc) const
std::vector< double > hcalHotFraction_
unsigned createVectorOfSubdetectorCells(const CaloGeometry &, int subdetn, std::vector< int > &)
double noiseInfCfromDB(const HcalDbService *conditions, const HcalDetId &detId)
edm::InputTag inputCol_
std::vector< double > noise_
bool parseXMLMiscalibFile(std::string configFile)
std::vector< float > hcalRecHits_
static std::vector< float > TPGFactor_
void push_back(T const &t)
#define abs(x)
Definition: mlp_lapack.h:159
const RandomEngine * random_
static std::vector< int > hfhi_
float getValue(int fCapId) const
get value for capId = 0..3
Definition: HcalGain.h:20
unsigned createVectorsOfCells(const edm::EventSetup &es)
void setSize(int size)
std::vector< double > corrfac_
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)
static std::vector< float > noisesigma_
double fractionOOT(int time_slice)
int iEvent
Definition: GenABIO.cc:243
std::vector< double > threshold_
static std::vector< int > hohi_
static std::vector< int > fctoadc_
void setSample(int i, const HcalQIESample &sam)
Definition: HBHEDataFrame.h:50
T sqrt(T t)
Definition: SSEVec.h:46
unsigned int poissonShoot(double mean) const
Definition: RandomEngine.h:44
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
void loadPCaloHits(const edm::Event &iEvent)
static bool initialized_
float getValue(int fCapId) const
get value for capId = 0..3
Definition: HcalPedestal.h:19
double f[11][100]
std::string hcalfileinpath_
static std::vector< HcalDetId > theDetIds_
void setSample(int i, const HcalQIESample &sam)
Definition: HFDataFrame.h:50
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
const HcalGain * getGain(const HcalGenericDetId &fId) const
T const * product() const
Definition: Handle.h:74
double flatShoot(double xmin=0.0, double xmax=1.0) const
Definition: RandomEngine.h:30
static unsigned maxIndex_
void setSize(int size)
Definition: HFDataFrame.cc:17
const HcalRespCorrs * myRespCorr
unsigned noisifySubdet(std::vector< float > &theMap, std::vector< int > &theHits, const std::vector< int > &thecells, unsigned ncells, double hcalHotFraction_, const GaussianTail *, double sigma, double threshold, double correctionfactor)
double shoot() const
Definition: GaussianTail.cc:20
static std::vector< float > gains_
float getValue() const
Definition: HcalRespCorr.h:18
void loadHcalRecHits(edm::Event &iEvent, HBHERecHitCollection &hbheHits, HBHEDigiCollection &hbheDigis)
void reserve(size_type n)
void cleanSubDet(std::vector< float > &hits, std::vector< int > &cells)
std::vector< int > firedCells_
static std::vector< int > hbhi_
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:171
x
Definition: VDTMath.h:216
static std::vector< float > miscalib_
const Item * getValues(DetId fId) const
const HcalPedestal * getPedestal(const HcalGenericDetId &fId) const
static std::vector< int > hehi_
void init(const edm::EventSetup &es, bool dodigis, bool domiscalib)
tuple size
Write out results.
int hashed_index() const
Definition: HcalDetId.cc:119