CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalBarrelRecHitsMaker.cc
Go to the documentation of this file.
6 
27 
28 #include "CLHEP/GenericFunctions/Erf.hh"
29 //#include <algorithm>
30 
32 {
33  edm::ParameterSet RecHitsParameters=p.getParameter<edm::ParameterSet>("ECALBarrel");
34  inputCol_=RecHitsParameters.getParameter<edm::InputTag>("MixedSimHits");
35  noise_ = RecHitsParameters.getParameter<double>("Noise");
36  threshold_ = RecHitsParameters.getParameter<double>("Threshold");
37  refactor_ = RecHitsParameters.getParameter<double> ("Refactor");
38  refactor_mean_ = RecHitsParameters.getParameter<double> ("Refactor_mean");
39  noiseADC_ = RecHitsParameters.getParameter<double>("NoiseADC");
40  highNoiseParameters_ = RecHitsParameters.getParameter<std::vector<double> > ("HighNoiseParameters");
41  SRThreshold_ = RecHitsParameters.getParameter<double> ("SRThreshold");
42  SREtaSize_ = RecHitsParameters.getUntrackedParameter<int> ("SREtaSize",1);
43  SRPhiSize_ = RecHitsParameters.getUntrackedParameter<int> ("SRPhiSize",1);
46  crystalsinTT_.resize(2448);
47  TTTEnergy_.resize(2448,0.);
48  TTHighInterest_.resize(2448,0);
49  treatedTTs_.resize(2448,false);
50  theTTDetIds_.resize(2448);
51  neighboringTTs_.resize(2448);
52  sinTheta_.resize(86,0.);
53  doCustomHighNoise_=false;
54  // Initialize the Gaussian tail generator
55  // Two options : noise is set by the user (to a positive value). In this case, this value is taken
56  // or the user chose to use the noise from DB. In this case, the noise is flat in pT and not in energy
57  // but the threshold is in energy and not in pT.
58  doCustomHighNoise_=highNoiseParameters_.size()>=3;
59  Genfun::Erf myErf;
60  if( noise_>0. ) {
61  EBHotFraction_ = 0.5-0.5*myErf(threshold_/noise_/sqrt(2.));
62  myGaussianTailGenerator_ = new GaussianTail(noise_, threshold_);
63  edm::LogInfo("CaloRecHitsProducer") <<"Uniform noise simulation selected in the barrel";
64  } else if (noise_==-1 && doCustomHighNoise_)
65  {
66  if(highNoiseParameters_.size()==4)
67  EBHotFraction_ = 0.5-0.5*myErf(highNoiseParameters_[3]/highNoiseParameters_[2]/sqrt(2.));
68  if(highNoiseParameters_.size()==3)
69  EBHotFraction_ = highNoiseParameters_[2] ;
70  edm::LogInfo("CaloRecHitsProducer")<< " The gaussian model for high noise fluctuation cells after ZS is selected (best model), hot fraction " << EBHotFraction_ << std::endl;
71  }
72 
73  noisified_ = (noise_==0.);
74  edm::ParameterSet CalibParameters = RecHitsParameters.getParameter<edm::ParameterSet>("ContFact");
75  double c1=CalibParameters.getParameter<double>("EBs25notContainment");
76  calibfactor_=1./c1;
77 
78 
79 }
80 
82 {;
83 }
84 
85 
87 {
88  // std::cout << " clean " << std::endl;
89  unsigned size=theFiredCells_.size();
90  for(unsigned ic=0;ic<size;++ic)
91  {
93  applyZSCells_[theFiredCells_[ic]] = true;
94  }
95  theFiredCells_.clear();
96  // If the noise is set to 0. No need to simulate it.
97  noisified_ = (noise_==0.);
98  // std::cout << " Finished to clean " << std::endl;
99 
100  size=theFiredTTs_.size();
101  // std::cout << " Number of barrel TT " << size << std::endl;
102  for(unsigned itt=0;itt<size;++itt)
103  {
104  // std::cout << " TT " << theFiredTTs_[itt] << " " << TTTEnergy_[theFiredTTs_[itt]] << std::endl;
105  TTTEnergy_[theFiredTTs_[itt]]=0.;
106  treatedTTs_[theFiredTTs_[itt]]=false;
107  }
108  theFiredTTs_.clear();
109 
110  size=theTTofHighInterest_.size();
111  for(unsigned itt=0;itt<size;++itt)
113  theTTofHighInterest_.clear();
114 
115 // std::cout << " Check cleaning " << std::endl;
116 // for(unsigned ic=0;ic<TTTEnergy_.size();++ic)
117 // if(TTTEnergy_[ic]!=0.) std::cout << " TT " << ic << " not cleaned " << std::endl;
118 // for(unsigned ic=0;ic<TTHighInterest_.size();++ic)
119 // if(TTHighInterest_[ic]!=0) std::cout << " TTHighInterest " << ic << TTHighInterest_[ic] << " not cleaned " << std::endl;
120 // for(unsigned ic=0;ic<treatedTTs_.size();++ic)
121 // if(treatedTTs_[ic]) std::cout << " treatedTT " << ic << treatedTTs_[ic] << " not cleaned " << std::endl;
122 
123 }
124 
127 {
128 
129  clean();
130  loadPCaloHits(iEvent, random);
131 
132  unsigned nhit=theFiredCells_.size();
133  // std::cout << " loadEcalBarrelRecHits " << nhit << std::endl;
134  unsigned gain, adc;
135  ecalDigis.reserve(nhit);
136  ecalHits.reserve(nhit);
137  for(unsigned ihit=0;ihit<nhit;++ihit)
138  {
139  unsigned icell = theFiredCells_[ihit];
140 
141  EBDetId myDetId(barrelRawId_[icell]);
142  EcalTrigTowerDetId towid= eTTmap_->towerOf(myDetId);
143  int TThashedindex=towid.hashedIndex();
144 
145  if(doDigis_)
146  {
147  ecalDigis.push_back( myDetId );
148  EBDataFrame myDataFrame( ecalDigis.back() );
149  // myDataFrame.setSize(1); // now useless - by construction fixed at 1 frame - FIXME
150  // The real work is in the following line
151  geVtoGainAdc(theCalorimeterHits_[icell],gain,adc);
152  myDataFrame.setSample(0,EcalMGPASample(adc,gain));
153 
154  // std::cout << "myDataFrame" << myDataFrame.sample(0).raw() << std::endl;
155  //ecalDigis.push_back(myDataFrame);
156  }
157 
158  // If the energy+noise is below the threshold, a hit is nevertheless created, otherwise, there is a risk that a "noisy" hit
159  // is afterwards put in this cell which would not be correct.
160  float energy=theCalorimeterHits_[icell];
161  // std::cout << myDetId << " Energy " << theCalorimeterHits_[icell] << " " << TTTEnergy_[TThashedindex] << " " << isHighInterest(TThashedindex) << std::endl;
162  if ( SRThreshold_ && energy < threshold_ && !isHighInterest(TThashedindex) && applyZSCells_[icell])
163  {
164  // std::cout << " Killed " << std::endl;
165  theCalorimeterHits_[icell]=0.;
166  energy=0.;
167  }
168  // else
169  // std::cout << " SR " << TTTEnergy_[TThashedindex] << " Cell energy " << energy << " 1" << std::endl;
170 // if( TTTEnergy_[TThashedindex] < SRThreshold_ && energy > threshold_)
171 // std::cout << " SR " << TTTEnergy_[TThashedindex] << " Cell energy " << energy << std::endl;
172  if (energy > sat_)
173  {
174  theCalorimeterHits_[icell]=sat_;
175  energy=sat_;
176  }
177 // std::cout << " Threshold ok " << std::endl;
178 // std::cout << " Raw Id " << barrelRawId_[icell] << std::endl;
179 // std::cout << " Adding " << icell << " " << barrelRawId_[icell] << " " << energy << std::endl;
180  if(energy!=0.)
181  ecalHits.push_back(EcalRecHit(myDetId,energy,0.));
182  // std::cout << " Hit stored " << std::endl;
183  }
184  // std::cout << " Done " << std::endl;
185 
186 }
187 
189 {
190 
192  iEvent.getByLabel(inputCol_,cf);
193  std::auto_ptr<MixCollection<PCaloHit> > colcalo(new MixCollection<PCaloHit>(cf.product(),std::pair<int,int>(0,0) ));
194 
195 
196  theFiredCells_.reserve(colcalo->size());
197 
199  MixCollection<PCaloHit>::iterator cficaloend=colcalo->end();
200 
201  for (cficalo=colcalo->begin(); cficalo!=cficaloend;cficalo++)
202  {
203  unsigned hashedindex = EBDetId(cficalo->id()).hashedIndex();
204  // the famous 1/0.97 calibration factor is applied here !
205  // the miscalibration is applied here:
207  // Check if the hit already exists
208  if(theCalorimeterHits_[hashedindex]==0.)
209  {
210  theFiredCells_.push_back(hashedindex);
211  float noise=(noise_==-1.) ? noisesigma_[hashedindex] : noise_ ;
212  if (!noisified_ ) theCalorimeterHits_[hashedindex] += random->gaussShoot(0.,noise*calib);
213  }
214 
215 
216  // cficalo->energy can be 0 (a 7x7 grid is always built) if there is no noise simulated, in this case the cells should
217  // not be added several times.
218  float energy=(cficalo->energy()==0.) ? 0.000001 : cficalo->energy() ;
219  energy*=calib;
220  theCalorimeterHits_[hashedindex]+=energy;
221 
222  // Now deal with the TTs.
223  EBDetId myDetId(EBDetId(cficalo->id()));
224  EcalTrigTowerDetId towid= eTTmap_->towerOf(myDetId);
225 // std::cout << " Added " << energy << " in " << EBDetId(cficalo->id()) << std::endl;
226  int TThashedindex=towid.hashedIndex();
227  if(TTTEnergy_[TThashedindex]==0.)
228  {
229  theFiredTTs_.push_back(TThashedindex);
230 // std::cout << " Creating " ;
231  }
232  // std::cout << " Updating " << TThashedindex << " " << energy << " " << sinTheta_[myDetId.ietaAbs()] <<std::endl;
233  TTTEnergy_[TThashedindex]+=energy*sinTheta_[myDetId.ietaAbs()];
234  // std::cout << " TT " << TThashedindex << " updated, now contains " << TTTEnergy_[TThashedindex] << std::endl;
235  }
236  noisifyTriggerTowers(random);
237  noisified_ = true;
238 }
239 
241 {
242  if(noise_==0.) return;
243 // std::cout << " List of TT before" << std::endl;
244 // for(unsigned itt=0;itt<theFiredTTs_.size();++itt)
245 // std::cout << " TT " << theFiredTTs_[itt] << " " << TTTEnergy_[theFiredTTs_[itt]] << std::endl;
246 
247  // std::cout << " Starting to noisify the trigger towers " << std::endl;
248  unsigned nTT=theFiredTTs_.size();
249  for(unsigned itt=0;itt<nTT;++itt)
250  {
251  // std::cout << "Treating " << theFiredTTs_[itt] << " " << theTTDetIds_[theFiredTTs_[itt]].ieta() << " " << theTTDetIds_[theFiredTTs_[itt]].iphi() << " " << TTTEnergy_[theFiredTTs_[itt]] << std::endl;
252  // shoot noise in the trigger tower
253  noisifyTriggerTower(theFiredTTs_[itt], random);
254  // get the neighboring TTs
255  const std::vector<int>& neighbors=neighboringTTs_[theFiredTTs_[itt]];
256  unsigned nneighbors=neighbors.size();
257  // inject noise in those towers only if they have not been looked at yet
258  // std::cout << " Now looking at the neighbours " << std::endl;
259  for(unsigned in=0;in<nneighbors;++in)
260  {
261  // std::cout << " TT " << neighbors[in] << " " << theTTDetIds_[neighbors[in]] << " has been treated " << treatedTTs_[neighbors[in]] << std::endl;
262  if(!treatedTTs_[neighbors[in]])
263  {
264  noisifyTriggerTower(neighbors[in], random);
265  if(TTTEnergy_[neighbors[in]]==0.)
266  theFiredTTs_.push_back(neighbors[in]);
267  // std::cout << " Added " << neighbors[in] << " in theFiredTTs_ " << std::endl;;
268  }
269  }
270  }
271 // std::cout << " List of TT after" << std::endl;
272 // for(unsigned itt=0;itt<theFiredTTs_.size();++itt)
273 // {
274 // std::cout << " TT " << theFiredTTs_[itt] << " " << TTTEnergy_[theFiredTTs_[itt]] << std::endl;
275 // const std::vector<int> & xtals=crystalsinTT_[theFiredTTs_[itt]];
276 // for(unsigned ic=0;ic<xtals.size();++ic)
277 // std::cout << EBDetId::unhashIndex(xtals[ic]) << " " << theCalorimeterHits_[xtals[ic]] << std::endl;
278 // }
279 
280  randomNoisifier(random);
281 }
282 
284 {
285  // check if the TT has already been treated or not
286  if(treatedTTs_[tthi]) return false;
287  // get the crystals in the TT (this info might need to be cached)
288  // const std::vector<DetId> & xtals=eTTmap_->constituentsOf(theTTDetIds_[tthi]);
289  const std::vector<int> & xtals(crystalsinTT_[tthi]);
290  unsigned nxtals=xtals.size();
291  unsigned counter =0 ;
292  float energy=0.;
293  for(unsigned ic=0;ic<nxtals;++ic)
294  {
295  unsigned hashedindex=xtals[ic];
296  // check if the crystal has been already hit
297 // std::cout << " Checking " << EBDetId(barrelRawId_[xtals[ic]]) << " " << theCalorimeterHits_[hashedindex] << std::endl;
298  if(theCalorimeterHits_[hashedindex]==0)
299  {
301  float noise = (noise_==-1.) ? noisesigma_[hashedindex]:noise_;
302  float energy = calib*random->gaussShoot(0.,noise);
303  theCalorimeterHits_[hashedindex]=energy;
304  // std::cout << " Updating with noise " << tthi << " " << energy << " " << sinTheta_[EBDetId(barrelRawId_[hashedindex]).ietaAbs()] << std::endl;
305  if(TTTEnergy_[tthi]==0.)
306  theFiredTTs_.push_back(tthi);
307  TTTEnergy_[tthi]+=energy*sinTheta_[EBDetId(barrelRawId_[hashedindex]).ietaAbs()];
308 
309  theFiredCells_.push_back(hashedindex);
310  ++counter;
311  }
312  else
313  energy+=theCalorimeterHits_[hashedindex];
314  }
315 // std::cout << " Energy " << energy << " Added noise in " << counter << " cells" << std::endl;
316  treatedTTs_[tthi]=true;
317  return true;
318 }
319 
320 
321 // injects high noise fluctuations cells. It is assumed that these cells cannot
322 // make of the tower a high interest one
324 {
325  // first number of cells where some noise will be injected
327  unsigned ncells= random->poissonShoot(mean);
328 
329  // if hot fraction is high (for example, no ZS, inject everywhere)
330  bool fullInjection=(noise_==-1. && !doCustomHighNoise_);
331 
332  if(fullInjection)
334  // for debugging
335  // std::vector<int> listofNewTowers;
336 
337  unsigned icell=0;
338  while(icell < ncells)
339  {
340  unsigned cellindex= (!fullInjection) ?
341  (unsigned)(floor(random->flatShoot()*EBDetId::kSizeForDenseIndexing)): icell ;
342 
343  if(theCalorimeterHits_[cellindex]==0.)
344  {
345  float energy=0.;
346  if(noise_>0.)
347  energy=myGaussianTailGenerator_->shoot(random);
348  if(noise_==-1.)
349  {
350  // in this case the generated noise might be below the threshold but it
351  // does not matter, the threshold will be applied anyway
352  // energy/=sinTheta_[(cellindex<EEDetId::kEEhalf)?cellindex : cellindex-EEDetId::kEEhalf];
353  float noisemean = (doCustomHighNoise_)? highNoiseParameters_[0]*(*ICMC_)[cellindex]*adcToGeV_: 0.;
354  float noisesigma = (doCustomHighNoise_)? highNoiseParameters_[1]*(*ICMC_)[cellindex]*adcToGeV_ : noisesigma_[cellindex];
355  energy=random->gaussShoot(noisemean,noisesigma);
356 
357  // in the case of high noise fluctuation, the ZS should not be applied later
358  if(doCustomHighNoise_) applyZSCells_[cellindex]=false;
359  }
361  energy *= calib;
362  theCalorimeterHits_[cellindex]=energy;
363  theFiredCells_.push_back(cellindex);
364  EBDetId myDetId(EBDetId::unhashIndex(cellindex));
365  // now get the TT
366  int TThashedindex=(eTTmap_->towerOf(myDetId)).hashedIndex();
367  // std::cout << " myDetIds " << myDetId << " "TTHI " << TThashedindex<< std::endl;
368  if(TTTEnergy_[TThashedindex]==0.)
369  {
370  theFiredTTs_.push_back(TThashedindex);
371  TTTEnergy_[TThashedindex]+=energy*sinTheta_[myDetId.ietaAbs()];
372  // listofNewTowers.push_back(TThashedindex);
373  }
374 // else
375 // {
376 // std::vector<int>::const_iterator itcheck=std::find(listofNewTowers.begin(),listofNewTowers.end(),
377 // TThashedindex);
378 // if(itcheck==listofNewTowers.end())
379 // {
380 // std::cout << " EcalBarrelRecHitsMaker : this tower has already been treated " << TTTEnergy_[TThashedindex] << std::endl;
381 // const std::vector<int> & xtals=crystalsinTT_[TThashedindex];
382 // for(unsigned ic=0;ic<xtals.size();++ic)
383 // std::cout << EBDetId::unhashIndex(xtals[ic]) << " " << theCalorimeterHits_[xtals[ic]] << std::endl;
384 // }
385 // }
386  if(noise_>0.)
387  ++icell;
388  }
389  if(noise_==-1.)
390  ++icell;
391  }
392  // std::cout << " Injected random noise in " << ncells << " cells " << std::endl;
393 }
394 
395 void EcalBarrelRecHitsMaker::init(const edm::EventSetup &es,bool doDigis,bool doMiscalib)
396 {
397  // std::cout << " Initializing EcalBarrelRecHitsMaker " << std::endl;
398  doDigis_=doDigis;
399  doMisCalib_=doMiscalib;
400 
402  es.get<EcalADCToGeVConstantRcd>().get(agc);
403 
404  adcToGeV_= agc->getEBValue();// 0.035 ;
405  minAdc_ = 200;
406  maxAdc_ = 4085;
407 
408  geVToAdc1_ = 1./adcToGeV_;
409  geVToAdc2_ = geVToAdc1_/2.;
410  geVToAdc3_ = geVToAdc1_/12.;
411 
412  t1_ = ((int)maxAdc_-(int)minAdc_)*adcToGeV_;
413  t2_ = 2.* t1_ ;
414 
415  // Saturation value. Not needed in the digitization
416  sat_ = 12.*t1_*calibfactor_;
417 
421  es.get<CaloGeometryRecord>().get(pG);
422 
423 // edm::ESHandle<CaloTopology> theCaloTopology;
424 // es.get<CaloTopologyRecord>().get(theCaloTopology);
425 
427  es.get<IdealGeometryRecord>().get(hetm);
428  eTTmap_ = &(*hetm);
429 
430  const EcalBarrelGeometry * myEcalBarrelGeometry = dynamic_cast<const EcalBarrelGeometry*>(pG->getSubdetectorGeometry(DetId::Ecal,EcalBarrel));
431  // std::cout << " Got the geometry " << myEcalBarrelGeometry << std::endl;
432  const std::vector<DetId>& vec(myEcalBarrelGeometry->getValidDetIds(DetId::Ecal,EcalBarrel));
433  unsigned size=vec.size();
434  for(unsigned ic=0; ic<size; ++ic)
435  {
436  EBDetId myDetId(vec[ic]);
437  int crystalHashedIndex=myDetId.hashedIndex();
438  barrelRawId_[crystalHashedIndex]=vec[ic].rawId();
439  // save the Trigger tower DetIds
440  EcalTrigTowerDetId towid= eTTmap_->towerOf(EBDetId(vec[ic]));
441  int TThashedindex=towid.hashedIndex();
442  theTTDetIds_[TThashedindex]=towid;
443  crystalsinTT_[TThashedindex].push_back(crystalHashedIndex);
444  int ietaAbs=myDetId.ietaAbs();
445  if(sinTheta_[ietaAbs]==0.)
446  {
447  sinTheta_[ietaAbs]=std::sin(myEcalBarrelGeometry->getGeometry(myDetId)->getPosition().theta());
448  // std::cout << " Ieta abs " << ietaAbs << " " << sinTheta_[ietaAbs] << std::endl;
449  }
450  }
451 
452 
453  unsigned nTTs=theTTDetIds_.size();
454 
455 // EBDetId myDetId(-58,203);
457 // EcalTrigTowerDetId towid= eTTmap_->towerOf(myDetId);
460 // const std::vector<int> & xtals(crystalsinTT_[towid.hashedIndex()]);
461 // unsigned Size=xtals.size();
462 // for(unsigned i=0;i<Size;++i)
463 // {
464 // std::cout << EBDetId(barrelRawId_[xtals[i]]) << std::endl;
465 // }
466 
467  // now loop on each TT and save its neighbors.
468  for(unsigned iTT=0;iTT<nTTs;++iTT)
469  {
470  int ietaPivot=theTTDetIds_[iTT].ieta();
471  int iphiPivot=theTTDetIds_[iTT].iphi();
472  int TThashedIndex=theTTDetIds_[iTT].hashedIndex();
473  // std::cout << " TT Pivot " << TThashedIndex << " " << ietaPivot << " " << iphiPivot << " iz " << theTTDetIds_[iTT].zside() << std::endl;
474  int ietamin=std::max(ietaPivot-SREtaSize_,-17);
475  if(ietamin==0) ietamin=-1;
476  int ietamax=std::min(ietaPivot+SREtaSize_,17);
477  if(ietamax==0) ietamax=1;
478  int iphimin=iphiPivot-SRPhiSize_;
479  int iphimax=iphiPivot+SRPhiSize_;
480  for(int ieta=ietamin;ieta<=ietamax;)
481  {
482  int iz=(ieta>0)? 1 : -1;
483  for(int iphi=iphimin;iphi<=iphimax;)
484  {
485  int riphi=iphi;
486  if(riphi<1) riphi+=72;
487  else if(riphi>72) riphi-=72;
488  EcalTrigTowerDetId neighborTTDetId(iz,EcalBarrel,abs(ieta),riphi);
489  // std::cout << " Voisin " << ieta << " " << riphi << " " <<neighborTTDetId.hashedIndex()<< " " << neighborTTDetId.ieta() << " " << neighborTTDetId.iphi() << std::endl;
490  if(ieta!=ietaPivot||riphi!=iphiPivot)
491  {
492  neighboringTTs_[TThashedIndex].push_back(neighborTTDetId.hashedIndex());
493  }
494  ++iphi;
495 
496  }
497  ++ieta;
498  if(ieta==0) ieta=1;
499  }
500  }
501 
502  // std::cout << " Made the array " << std::endl;
503 
504  // Stores the miscalibration constants
505  if(doMisCalib_ || noise_==-1.)
506  {
507  double rms=0.;
508  double mean=0.;
509  unsigned ncells=0;
510 
511  if(noise_==-1.)
513 
514  // Intercalib MC constants IC_MC_i
516  es.get<EcalIntercalibConstantsMCRcd>().get(pJcal);
517  const EcalIntercalibConstantsMC* jcal = pJcal.product();
518  const std::vector<float>& ICMC = jcal->barrelItems();
519 
520  // should be saved, used by the zero suppression
521  ICMC_ = &ICMC;
522 
523  // Intercalib constants IC_i
524  // IC = IC_MC * (1+delta)
525  // where delta is the miscalib
527  es.get<EcalIntercalibConstantsRcd>().get(pIcal);
528  const EcalIntercalibConstants* ical = pIcal.product();
529  const std::vector<float> & IC = ical->barrelItems();
530 
531  float meanIC=0.;
532  unsigned nic = IC.size();
533  for ( unsigned ic=0; ic <nic ; ++ic ) {
534  // the miscalibration factor is
535  float factor = IC[ic]/ICMC[ic];
536  meanIC+=(IC[ic]-1.);
537  // Apply Refactor & refactor_mean
538  theCalibConstants_[ic] = refactor_mean_+(factor-1.)*refactor_;
539 
540  rms+=(factor-1.)*(factor-1.);
541  mean+=(factor-1.);
542  ++ncells;
543  if(noise_==-1.)
544  {
545  // the calibfactor will be applied later on
547  }
548 
549  }
550 
551  mean/=(float)ncells;
552  rms/=(float)ncells;
553 
554  rms=sqrt(rms-mean*mean);
555  meanIC = 1.+ meanIC/ncells;
556  // The following should be on LogInfo
557  // float NoiseSigma = 1.26 * meanIC * adcToGeV_ ;
558  // std::cout << " Found " << ncells <<
559  edm::LogInfo("CaloRecHitsProducer") << "Found " << ncells << " cells in the barrel calibration map. RMS is " << rms << std::endl;
560  // std::cout << "Found " << ncells << " cells in the barrel calibration map. RMS is " << rms << std::endl;
561  }
562 }
563 
564 void EcalBarrelRecHitsMaker::geVtoGainAdc(float e,unsigned & gain, unsigned &adc) const
565 {
566  if(e<t1_)
567  {
568  gain = 1; // x1
569  // std::cout << " E " << e << std::endl;
570  adc = minAdc_ + (unsigned)(e*geVToAdc1_);
571  // std::cout << " e*geVtoAdc1_ " << e*geVToAdc1_ << " " <<(unsigned)(e*geVToAdc1_) << std::endl;
572  }
573  else if (e<t2_)
574  {
575  gain = 2;
576  adc = minAdc_ + (unsigned)(e*geVToAdc2_);
577  }
578  else
579  {
580  gain = 3;
581  adc = std::min(minAdc_+(unsigned)(e*geVToAdc3_),maxAdc_);
582  }
583 }
584 
586 {
587 
588  if(TTHighInterest_[tthi]!=0) return (TTHighInterest_[tthi]>0);
589 
590  TTHighInterest_[tthi]=(TTTEnergy_[tthi] > SRThreshold_) ? 1:-1;
591  // if high interest, can leave ; otherwise look at the neighbours)
592  if( TTHighInterest_[tthi]==1)
593  {
594  theTTofHighInterest_.push_back(tthi);
595  return true;
596  }
597 
598  // now look if a neighboring TT is of high interest
599  const std::vector<int> & tts(neighboringTTs_[tthi]);
600  // a tower is of high interest if it or one of its neighbour is above the SR threshold
601  unsigned size=tts.size();
602  bool result=false;
603  for(unsigned itt=0;itt<size&&!result;++itt)
604  {
605  if(TTTEnergy_[tts[itt]] > SRThreshold_) result=true;
606  }
607  TTHighInterest_[tthi]=(result)? 1:-1;
608  theTTofHighInterest_.push_back(tthi);
609  return result;
610 }
int adc(sample_type sample)
get the ADC sample (12 bits)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int hashedIndex() const
get a compact index for arrays
Definition: EBDetId.h:86
void randomNoisifier(RandomEngineAndDistribution const *)
const GaussianTail * myGaussianTailGenerator_
double flatShoot(double xmin=0.0, double xmax=1.0) const
const std::vector< float > * ICMC_
std::vector< int > theFiredCells_
const Items & barrelItems() const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
int hashedIndex() const
get a compact index for arrays [TODO: NEEDS WORK]
void push_back(T const &t)
TRandom random
Definition: MVATrainer.cc:138
std::vector< float > sinTheta_
EcalTrigTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
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)
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
std::vector< float > theCalorimeterHits_
double shoot(RandomEngineAndDistribution const *) const
Definition: GaussianTail.cc:18
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
std::vector< float > noisesigma_
#define nTT
Definition: TMEGeom.h:6
void geVtoGainAdc(float e, unsigned &gain, unsigned &adc) const
int hashedIndex(int ieta, int iphi)
Definition: EcalPyUtils.cc:42
void noisifyTriggerTowers(RandomEngineAndDistribution const *)
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
int iEvent
Definition: GenABIO.cc:230
T sqrt(T t)
Definition: SSEVec.h:48
EcalBarrelRecHitsMaker(edm::ParameterSet const &p)
tuple result
Definition: query.py:137
std::vector< uint32_t > barrelRawId_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< double > highNoiseParameters_
std::vector< unsigned > theFiredTTs_
T min(T a, T b)
Definition: MathUtil.h:58
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
void reserve(size_t isize)
void loadPCaloHits(const edm::Event &iEvent, RandomEngineAndDistribution const *)
const EcalTrigTowerConstituentsMap * eTTmap_
T const * product() const
Definition: Handle.h:81
std::vector< float > TTTEnergy_
const T & get() const
Definition: EventSetup.h:55
bool noisifyTriggerTower(unsigned tthi, RandomEngineAndDistribution const *)
T const * product() const
Definition: ESHandle.h:86
void push_back(id_type iid, data_type const *idata)
std::vector< std::vector< int > > crystalsinTT_
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
std::vector< std::vector< int > > neighboringTTs_
static std::atomic< unsigned int > counter
std::vector< float > theCalibConstants_
std::vector< int > theTTofHighInterest_
double gaussShoot(double mean=0.0, double sigma=1.0) const
unsigned int poissonShoot(double mean) const
void reserve(size_type n)
std::vector< int > applyZSCells_
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
void loadEcalBarrelRecHits(edm::Event &iEvent, EBRecHitCollection &ecalHits, EBDigiCollection &ecaldigis, RandomEngineAndDistribution const *)
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:49
tuple size
Write out results.
void init(const edm::EventSetup &es, bool dodigis, bool doMiscalib)
std::vector< EcalTrigTowerDetId > theTTDetIds_
std::vector< bool > treatedTTs_
std::vector< int > TTHighInterest_