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