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