CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalHitReconstructor.cc
Go to the documentation of this file.
1 #include "HcalHitReconstructor.h"
19 #include <iostream>
20 #include <fstream>
21 
22 
23 /* Hcal Hit reconstructor allows for CaloRecHits with status words */
24 
26  reco_(conf.getParameter<bool>("correctForTimeslew"),
27  conf.getParameter<bool>("correctForPhaseContainment"),
28  conf.getParameter<double>("correctionPhaseNS")),
29  det_(DetId::Hcal),
30  inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
31  correctTiming_(conf.getParameter<bool>("correctTiming")),
32  setNoiseFlags_(conf.getParameter<bool>("setNoiseFlags")),
33  setHSCPFlags_(conf.getParameter<bool>("setHSCPFlags")),
34  setSaturationFlags_(conf.getParameter<bool>("setSaturationFlags")),
35  setTimingTrustFlags_(conf.getParameter<bool>("setTimingTrustFlags")),
36  setPulseShapeFlags_(conf.getParameter<bool>("setPulseShapeFlags")),
37  setNegativeFlags_(false),
38  dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
39  firstAuxTS_(conf.getParameter<int>("firstAuxTS")),
40  firstSample_(conf.getParameter<int>("firstSample")),
41  samplesToAdd_(conf.getParameter<int>("samplesToAdd")),
42  tsFromDB_(conf.getParameter<bool>("tsFromDB")),
43  useLeakCorrection_(conf.getParameter<bool>("useLeakCorrection")),
44  dataOOTCorrectionName_(""),
45  dataOOTCorrectionCategory_("Data"),
46  mcOOTCorrectionName_(""),
47  mcOOTCorrectionCategory_("MC"),
48  setPileupCorrection_(0),
49  paramTS(0),
50  puCorrMethod_(conf.existsAs<int>("puCorrMethod") ? conf.getParameter<int>("puCorrMethod") : 0),
51  cntprtCorrMethod_(0),
52  first_(true)
53 
54 {
55  // register for data access
56  tok_hbhe_ = consumes<HBHEDigiCollection>(inputLabel_);
57  tok_ho_ = consumes<HODigiCollection>(inputLabel_);
58  tok_hf_ = consumes<HFDigiCollection>(inputLabel_);
59  tok_calib_ = consumes<HcalCalibDigiCollection>(inputLabel_);
60 
61  std::string subd=conf.getParameter<std::string>("Subdetector");
62  //Set all FlagSetters to 0
63  /* Important to do this! Otherwise, if the setters are turned off,
64  the "if (XSetter_) delete XSetter_;" commands can crash
65  */
66 
67  recoParamsFromDB_ = conf.getParameter<bool>("recoParamsFromDB");
68  // recoParamsFromDB_ = false ; // trun off for now.
69 
70  // std::cout<<" HcalHitReconstructor recoParamsFromDB_ "<<recoParamsFromDB_<<std::endl;
71 
72  if (conf.existsAs<bool>("setNegativeFlags"))
73  setNegativeFlags_ = conf.getParameter<bool>("setNegativeFlags");
74 
75  hbheFlagSetter_ = 0;
80  hfdigibit_ = 0;
81 
82  hfS9S1_ = 0;
83  hfS8S1_ = 0;
84  hfPET_ = 0;
87  digiTimeFromDB_ = false; // only need for HF
88 
90  {
91  const edm::ParameterSet& pssat = conf.getParameter<edm::ParameterSet>("saturationParameters");
92  saturationFlagSetter_ = new HcalADCSaturationFlag(pssat.getParameter<int>("maxADCvalue"));
93  }
94 
95  if (!strcasecmp(subd.c_str(),"HBHE")) {
97 
100 
101  bool timingShapedCutsFlags = conf.getParameter<bool>("setTimingShapedCutsFlags");
102  if (timingShapedCutsFlags)
103  {
104  const edm::ParameterSet& psTshaped = conf.getParameter<edm::ParameterSet>("timingshapedcutsParameters");
105  hbheTimingShapedFlagSetter_ = new HBHETimingShapedFlagSetter(psTshaped.getParameter<std::vector<double> >("tfilterEnvelope"),
106  psTshaped.getParameter<bool>("ignorelowest"),
107  psTshaped.getParameter<bool>("ignorehighest"),
108  psTshaped.getParameter<double>("win_offset"),
109  psTshaped.getParameter<double>("win_gain"));
110  }
111 
112  if (setNoiseFlags_)
113  {
114  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("flagParameters");
115  hbheFlagSetter_=new HBHEStatusBitSetter(psdigi.getParameter<double>("nominalPedestal"),
116  psdigi.getParameter<double>("hitEnergyMinimum"),
117  psdigi.getParameter<int>("hitMultiplicityThreshold"),
118  psdigi.getParameter<std::vector<edm::ParameterSet> >("pulseShapeParameterSets")
119  );
120  } // if (setNoiseFlags_)
121  if (setHSCPFlags_)
122  {
123  const edm::ParameterSet& psHSCP = conf.getParameter<edm::ParameterSet>("hscpParameters");
125  psHSCP.getParameter<double>("r1Max"),
126  psHSCP.getParameter<double>("r2Min"),
127  psHSCP.getParameter<double>("r2Max"),
128  psHSCP.getParameter<double>("fracLeaderMin"),
129  psHSCP.getParameter<double>("fracLeaderMax"),
130  psHSCP.getParameter<double>("slopeMin"),
131  psHSCP.getParameter<double>("slopeMax"),
132  psHSCP.getParameter<double>("outerMin"),
133  psHSCP.getParameter<double>("outerMax"),
134  psHSCP.getParameter<double>("TimingEnergyThreshold"));
135  } // if (setHSCPFlags_)
137  {
138  const edm::ParameterSet &psPulseShape = conf.getParameter<edm::ParameterSet>("pulseShapeParameters");
140  psPulseShape.getParameter<double>("MinimumChargeThreshold"),
141  psPulseShape.getParameter<double>("TS4TS5ChargeThreshold"),
142  psPulseShape.getParameter<unsigned int>("TrianglePeakTS"),
143  psPulseShape.getParameter<std::vector<double> >("LinearThreshold"),
144  psPulseShape.getParameter<std::vector<double> >("LinearCut"),
145  psPulseShape.getParameter<std::vector<double> >("RMS8MaxThreshold"),
146  psPulseShape.getParameter<std::vector<double> >("RMS8MaxCut"),
147  psPulseShape.getParameter<std::vector<double> >("LeftSlopeThreshold"),
148  psPulseShape.getParameter<std::vector<double> >("LeftSlopeCut"),
149  psPulseShape.getParameter<std::vector<double> >("RightSlopeThreshold"),
150  psPulseShape.getParameter<std::vector<double> >("RightSlopeCut"),
151  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallThreshold"),
152  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallCut"),
153  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerThreshold"),
154  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerCut"),
155  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperThreshold"),
156  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperCut"),
157  psPulseShape.getParameter<bool>("UseDualFit"),
158  psPulseShape.getParameter<bool>("TriangleIgnoreSlow"));
159  } // if (setPulseShapeFlags_)
160  if (setNegativeFlags_)
162 
163  produces<HBHERecHitCollection>();
164  } else if (!strcasecmp(subd.c_str(),"HO")) {
168  produces<HORecHitCollection>();
169  } else if (!strcasecmp(subd.c_str(),"HF")) {
173  digiTimeFromDB_=conf.getParameter<bool>("digiTimeFromDB");
174 
175  if (setTimingTrustFlags_) {
176 
177  const edm::ParameterSet& pstrust = conf.getParameter<edm::ParameterSet>("hfTimingTrustParameters");
178  HFTimingTrustFlagSetter_=new HFTimingTrustFlag(pstrust.getParameter<int>("hfTimingTrustLevel1"),
179  pstrust.getParameter<int>("hfTimingTrustLevel2"));
180  }
181 
182  if (setNoiseFlags_)
183  {
184  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("digistat");
185  const edm::ParameterSet& psTimeWin =conf.getParameter<edm::ParameterSet>("HFInWindowStat");
186  hfdigibit_=new HcalHFStatusBitFromDigis(psdigi,psTimeWin);
187 
188  const edm::ParameterSet& psS9S1 = conf.getParameter<edm::ParameterSet>("S9S1stat");
189  hfS9S1_ = new HcalHF_S9S1algorithm(psS9S1.getParameter<std::vector<double> >("short_optimumSlope"),
190  psS9S1.getParameter<std::vector<double> >("shortEnergyParams"),
191  psS9S1.getParameter<std::vector<double> >("shortETParams"),
192  psS9S1.getParameter<std::vector<double> >("long_optimumSlope"),
193  psS9S1.getParameter<std::vector<double> >("longEnergyParams"),
194  psS9S1.getParameter<std::vector<double> >("longETParams"),
195  psS9S1.getParameter<int>("HcalAcceptSeverityLevel"),
196  psS9S1.getParameter<bool>("isS8S1")
197  );
198 
199  const edm::ParameterSet& psS8S1 = conf.getParameter<edm::ParameterSet>("S8S1stat");
200  hfS8S1_ = new HcalHF_S9S1algorithm(psS8S1.getParameter<std::vector<double> >("short_optimumSlope"),
201  psS8S1.getParameter<std::vector<double> >("shortEnergyParams"),
202  psS8S1.getParameter<std::vector<double> >("shortETParams"),
203  psS8S1.getParameter<std::vector<double> >("long_optimumSlope"),
204  psS8S1.getParameter<std::vector<double> >("longEnergyParams"),
205  psS8S1.getParameter<std::vector<double> >("longETParams"),
206  psS8S1.getParameter<int>("HcalAcceptSeverityLevel"),
207  psS8S1.getParameter<bool>("isS8S1")
208  );
209 
210  const edm::ParameterSet& psPET = conf.getParameter<edm::ParameterSet>("PETstat");
211  hfPET_ = new HcalHF_PETalgorithm(psPET.getParameter<std::vector<double> >("short_R"),
212  psPET.getParameter<std::vector<double> >("shortEnergyParams"),
213  psPET.getParameter<std::vector<double> >("shortETParams"),
214  psPET.getParameter<std::vector<double> >("long_R"),
215  psPET.getParameter<std::vector<double> >("longEnergyParams"),
216  psPET.getParameter<std::vector<double> >("longETParams"),
217  psPET.getParameter<int>("HcalAcceptSeverityLevel"),
218  psPET.getParameter<std::vector<double> >("short_R_29"),
219  psPET.getParameter<std::vector<double> >("long_R_29")
220  );
221  }
222  produces<HFRecHitCollection>();
223  } else if (!strcasecmp(subd.c_str(),"ZDC")) {
226  produces<ZDCRecHitCollection>();
227  } else if (!strcasecmp(subd.c_str(),"CALIB")) {
230  produces<HcalCalibRecHitCollection>();
231  } else {
232  edm::LogWarning("Configuration") << "HcalHitReconstructor is not associated with a specific subdetector!" << std::endl;
233  }
234 
235  // If no valid OOT pileup correction name specified,
236  // disable the correction
237  if (conf.existsAs<std::string>("dataOOTCorrectionName"))
238  dataOOTCorrectionName_ = conf.getParameter<std::string>("dataOOTCorrectionName");
239  if (conf.existsAs<std::string>("dataOOTCorrectionCategory"))
240  dataOOTCorrectionCategory_ = conf.getParameter<std::string>("dataOOTCorrectionCategory");
241  if (conf.existsAs<std::string>("mcOOTCorrectionName"))
242  mcOOTCorrectionName_ = conf.getParameter<std::string>("mcOOTCorrectionName");
243  if (conf.existsAs<std::string>("mcOOTCorrectionCategory"))
244  mcOOTCorrectionCategory_ = conf.getParameter<std::string>("mcOOTCorrectionCategory");
245  if (dataOOTCorrectionName_.empty() && mcOOTCorrectionName_.empty())
247 
249  if(puCorrMethod_ == 2) {
251  conf.getParameter<bool> ("applyPedConstraint"),
252  conf.getParameter<bool> ("applyTimeConstraint"),
253  conf.getParameter<bool> ("applyPulseJitter"),
254  conf.getParameter<bool> ("applyUnconstrainedFit"),
255  conf.getParameter<bool> ("applyTimeSlew"),
256  conf.getParameter<double>("ts4Min"),
257  conf.getParameter<double>("ts4Max"),
258  conf.getParameter<double>("pulseJitter"),
259  conf.getParameter<double>("meanTime"),
260  conf.getParameter<double>("timeSigma"),
261  conf.getParameter<double>("meanPed"),
262  conf.getParameter<double>("pedSigma"),
263  conf.getParameter<double>("noise"),
264  conf.getParameter<double>("timeMin"),
265  conf.getParameter<double>("timeMax"),
266  conf.getParameter<double>("ts3chi2"),
267  conf.getParameter<double>("ts4chi2"),
268  conf.getParameter<double>("ts345chi2"),
269  conf.getParameter<double>("chargeMax"), //For the unconstrained Fit
270  conf.getParameter<int> ("fitTimes")
271  );
272  }
273  if(puCorrMethod_ == 3) {
275  conf.getParameter<int> ("pedestalSubtractionType"),
276  conf.getParameter<double> ("pedestalUpperLimit"),
277  conf.getParameter<int> ("timeSlewParsType"),
278  conf.getParameter<std::vector<double> >("timeSlewPars")
279  );
280  }
281 
282 }
283 
286  desc.setAllowAnything();
287  desc.add<int>("pedestalSubtractionType", 1);
288  desc.add<double>("pedestalUpperLimit", 2.7);
289  desc.add<int>("timeSlewParsType",3);
290  desc.add<std::vector<double>>("timeSlewPars", {9.27638, -2.05585, 9.27638, -2.05585, 9.27638, -2.05585});
291  descriptions.add("hltHbhereco",desc);
292 }
293 
295  delete hbheFlagSetter_;
296  delete hbheHSCPFlagSetter_;
300  delete hfdigibit_;
301 
302  delete hfS9S1_;
303  delete hfS8S1_;
304  delete hfPET_;
305  delete saturationFlagSetter_;
307 
308  delete paramTS;
309 }
310 
312 
314  es.get<IdealGeometryRecord>().get(htopo);
315 
316  if ( tsFromDB_== true || recoParamsFromDB_ == true )
317  {
319  es.get<HcalRecoParamsRcd>().get(p);
320  paramTS = new HcalRecoParams(*p.product());
321  paramTS->setTopo(htopo.product());
322 
323 
324 
325 
326  // std::cout<<" skdump in HcalHitReconstructor::beginRun dupm RecoParams "<<std::endl;
327  // std::ofstream skfile("skdumpRecoParamsNewFormat.txt");
328  // HcalDbASCIIIO::dumpObject(skfile, (*paramTS) );
329  }
330 
331  if (digiTimeFromDB_==true)
332  {
334  es.get<HcalFlagHFDigiTimeParamsRcd>().get(p);
335  HFDigiTimeParams.reset( new HcalFlagHFDigiTimeParams( *p ) );
336 
338  es.get<IdealGeometryRecord>().get(htopo);
339  HFDigiTimeParams->setTopo(htopo.product());
340 
341  }
342 
343  reco_.beginRun(es);
344 }
345 
347  if (tsFromDB_==true)
348  {
349  delete paramTS; paramTS=0;
350  }
351  if (digiTimeFromDB_==true)
352  {
353  //DL delete HFDigiTimeParams; HFDigiTimeParams = 0;
354  }
355  reco_.endRun();
356 }
357 
359 {
360 
361  // get conditions
363  eventSetup.get<IdealGeometryRecord>().get(topo);
364 
365  edm::ESHandle<HcalDbService> conditions;
366  eventSetup.get<HcalDbRecord>().get(conditions);
367 
368  // HACK related to HB- corrections
369  if ( first_ ) {
370  const bool isData = e.isRealData();
371  if (isData) reco_.setForData(e.run()); else reco_.setForData(0);
374  first_=false;
375  }
377 
379  eventSetup.get<HcalChannelQualityRcd>().get("withTopo",p);
380  const HcalChannelQuality* myqual = p.product();
381 
383  eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
384  const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
385 
386  // Configure OOT pileup corrections
387  bool isMethod1Set = false;
388  if (!corrName_.empty())
389  {
390  edm::ESHandle<OOTPileupCorrectionColl> pileupCorrections;
391  if (eventSetup.find(edm::eventsetup::EventSetupRecordKey::makeKey<HcalOOTPileupCorrectionRcd>()))
392  eventSetup.get<HcalOOTPileupCorrectionRcd>().get(pileupCorrections);
393  else
394  eventSetup.get<HcalOOTPileupCompatibilityRcd>().get(pileupCorrections);
395 
396  if( setPileupCorrection_ ){
397  const OOTPileupCorrData * testMethod1Ptr = dynamic_cast<OOTPileupCorrData*>((pileupCorrections->get(corrName_, cat_)).get());
398  if( testMethod1Ptr ) isMethod1Set = true;
399  (reco_.*setPileupCorrection_)(pileupCorrections->get(corrName_, cat_));
400  }
401  }
402 
403  // Configure the negative energy filter
406  {
407  eventSetup.get<HBHENegativeEFilterRcd>().get(negEhandle);
409  }
410 
411  // Only for HBHE
412  if( subdet_ == HcalBarrel ) {
413  if( !cntprtCorrMethod_ ) {
415  if( puCorrMethod_ == 2 ) LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 2" << std::endl;
416  else if( puCorrMethod_ == 1 ){
417  if( isMethod1Set ) LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 1" << std::endl;
418  else edm::LogWarning("HcalPUcorrMethod") <<"puCorrMethod_ set to be 1 but method 1 is NOT activated (method 0 used instead)!\n"
419  <<"Please check GlobalTag usage or method 1 separately disabled by dataOOTCorrectionName & mcOOTCorrectionName?" << std::endl;
420  } else if (puCorrMethod_ == 3) {
421  LogTrace("HcalPUcorrMethod") << "Using Hcal Deterministic Fit Method!" << std::endl;
422  } else LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 0" << std::endl;
423  }
424  }
425 
426  // GET THE BEAM CROSSING INFO HERE, WHEN WE UNDERSTAND HOW THINGS WORK.
427  // Then, call "setBXInfo" method of the reco_ object.
428  // Also remember to call SetBXInfo in the negative energy flag setter.
429 
430  if (det_==DetId::Hcal) {
431 
432  // HBHE -------------------------------------------------------------------
435 
436  e.getByToken(tok_hbhe_,digi);
437 
438  // create empty output
439  std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
440  rec->reserve(digi->size());
441  // run the algorithm
444  std::vector<HBHEDataFrame> HBDigis;
445  std::vector<int> RecHitIndex;
446 
447  // Vote on majority TS0 CapId
448  int favorite_capid = 0;
449  if (correctTiming_) {
450  long capid_votes[4] = {0,0,0,0};
451  for (i=digi->begin(); i!=digi->end(); i++) {
452  capid_votes[(*i)[0].capid()]++;
453  }
454  for (int k = 0; k < 4; k++)
455  if (capid_votes[k] > capid_votes[favorite_capid])
456  favorite_capid = k;
457  }
458 
459  for (i=digi->begin(); i!=digi->end(); i++) {
460  HcalDetId cell = i->id();
461  DetId detcell=(DetId)cell;
462 
464  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
465  if(tsFromDB_) {
466  firstSample_ = param_ts->firstSample();
467  samplesToAdd_ = param_ts->samplesToAdd();
468  }
469  if(recoParamsFromDB_) {
470  bool correctForTimeslew=param_ts->correctForTimeslew();
472  float phaseNS=param_ts->correctionPhaseNS();
474  correctTiming_ = param_ts->correctTiming();
475  firstAuxTS_ = param_ts->firstAuxTS();
476  int pileupCleaningID = param_ts->pileupCleaningID();
477 
478  /*
479  int sub = cell.subdet();
480  int depth = cell.depth();
481  int inteta = cell.ieta();
482  int intphi = cell.iphi();
483 
484  std::cout << "HcalHitReconstructor::produce cell:"
485  << " sub, ieta, iphi, depth = "
486  << sub << " " << inteta << " " << intphi
487  << " " << depth << std::endl
488  << " first, toadd = " << firstSample_ << ", "
489  << samplesToAdd_ << std::endl
490  << " correctForTimeslew " << correctForTimeslew
491  << std::endl
492  << " correctForPhaseContainment "
493  << correctForPhaseContainment << std::endl
494  << " phaseNS " << phaseNS << std::endl
495  << " useLeakCorrection " << useLeakCorrection_
496  << std::endl
497  << " correctTiming " << correctTiming_ << std::endl
498  << " firstAuxTS " << firstAuxTS_ << std::endl
499  << " pileupCleaningID " << pileupCleaningID
500  << std::endl;
501  */
502 
503  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
504  }
505  }
506 
507  int first = firstSample_;
508  int toadd = samplesToAdd_;
509 
510  // check on cells to be ignored and dropped: (rof,20.Feb.09)
511  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
512  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
514  if (i->zsMarkAndPass()) continue;
515 
516  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
517  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
518  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
519  HcalCoderDb coder (*channelCoder, *shape);
520 
521  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
522 
523  // Fill first auxiliary word
524  unsigned int auxflag=0;
525  int fTS = firstAuxTS_;
526  if (fTS<0) fTS=0; // silly protection against time slice <0
527  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx) {
528  int adcv = i->sample(xx).adc();
529  auxflag+=((adcv&0x7F)<<(7*(xx-fTS))); // store the time slices in the first 28 bits of aux, a set of 4 7-bit adc values
530  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
531  }
532  auxflag+=((i->sample(fTS).capid())<<28);
533  (rec->back()).setAux(auxflag);
534 
535  // Fill second auxiliary word
536  auxflag=0;
537  int fTS2 = (firstAuxTS_-4 < 0) ? 0 : firstAuxTS_-4;
538  for (int xx = fTS2; xx < fTS2+4 && xx<i->size(); ++xx) {
539  int adcv = i->sample(xx).adc();
540  auxflag+=((adcv&0x7F)<<(7*(xx-fTS2)));
541  }
542  auxflag+=((i->sample(fTS2).capid())<<28);
543  (rec->back()).setAuxHBHE(auxflag);
544 
545  (rec->back()).setFlags(0); // this sets all flag bits to 0
546  // Set presample flag
547  if (fTS>0)
548  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
549 
552  if (setNoiseFlags_)
553  hbheFlagSetter_->SetFlagsFromDigi(&(*topo),rec->back(),*i,coder,calibrations,first,toadd);
555  hbhePulseShapeFlagSetter_->SetPulseShapeFlags(rec->back(), *i, coder, calibrations);
556  if (setNegativeFlags_)
557  hbheNegativeFlagSetter_->setPulseShapeFlags(rec->back(), *i, coder, calibrations);
560  if (correctTiming_)
561  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
562  if (setHSCPFlags_ && i->id().ietaAbs()<16)
563  {
564  double DigiEnergy=0;
565  for(int j=0; j!=i->size(); DigiEnergy += i->sample(j++).nominal_fC());
566  if(DigiEnergy > hbheHSCPFlagSetter_->EnergyThreshold())
567  {
568  HBDigis.push_back(*i);
569  RecHitIndex.push_back(rec->size()-1);
570  }
571 
572  } // if (set HSCPFlags_ && |ieta|<16)
573  } // loop over HBHE digis
574 
575 
577  if (setHSCPFlags_) hbheHSCPFlagSetter_->hbheSetTimeFlagsFromDigi(rec.get(), HBDigis, RecHitIndex);
578  // return result
579  e.put(rec);
580 
581  // HO ------------------------------------------------------------------
582  } else if (subdet_==HcalOuter) {
584  e.getByToken(tok_ho_,digi);
585 
586  // create empty output
587  std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
588  rec->reserve(digi->size());
589  // run the algorithm
591 
592  // Vote on majority TS0 CapId
593  int favorite_capid = 0;
594  if (correctTiming_) {
595  long capid_votes[4] = {0,0,0,0};
596  for (i=digi->begin(); i!=digi->end(); i++) {
597  capid_votes[(*i)[0].capid()]++;
598  }
599  for (int k = 0; k < 4; k++)
600  if (capid_votes[k] > capid_votes[favorite_capid])
601  favorite_capid = k;
602  }
603 
604  for (i=digi->begin(); i!=digi->end(); i++) {
605  HcalDetId cell = i->id();
606  DetId detcell=(DetId)cell;
607  // firstSample & samplesToAdd
609  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
610  if(tsFromDB_) {
611  firstSample_ = param_ts->firstSample();
612  samplesToAdd_ = param_ts->samplesToAdd();
613  }
614  if(recoParamsFromDB_) {
615  bool correctForTimeslew=param_ts->correctForTimeslew();
617  float phaseNS=param_ts->correctionPhaseNS();
619  correctTiming_ = param_ts->correctTiming();
620  firstAuxTS_ = param_ts->firstAuxTS();
621  int pileupCleaningID = param_ts->pileupCleaningID();
622  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
623  }
624  }
625 
626  int first = firstSample_;
627  int toadd = samplesToAdd_;
628 
629  // check on cells to be ignored and dropped: (rof,20.Feb.09)
630  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
631  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
633  if (i->zsMarkAndPass()) continue;
634 
635  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
636  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
637  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
638  HcalCoderDb coder (*channelCoder, *shape);
639 
640  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
641 
642  // Set auxiliary flag
643  int auxflag=0;
644  int fTS = firstAuxTS_;
645  if (fTS<0) fTS=0; //silly protection against negative time slice values
646  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
647  auxflag+=(i->sample(xx).adc())<<(7*(xx-fTS)); // store the time slices in the first 28 bits of aux, a set of 4 7-bit adc values
648  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
649  auxflag+=((i->sample(fTS).capid())<<28);
650  (rec->back()).setAux(auxflag);
651  (rec->back()).setFlags(0);
652  // Fill Presample ADC flag
653  if (fTS>0)
654  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
655 
658  if (correctTiming_)
659  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
660  }
661  // return result
662  e.put(rec);
663 
664  // HF -------------------------------------------------------------------
665  } else if (subdet_==HcalForward) {
667  e.getByToken(tok_hf_,digi);
668 
669 
671  // create empty output
672  std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
673  rec->reserve(digi->size());
674  // run the algorithm
676 
677  // Vote on majority TS0 CapId
678  int favorite_capid = 0;
679  if (correctTiming_) {
680  long capid_votes[4] = {0,0,0,0};
681  for (i=digi->begin(); i!=digi->end(); i++) {
682  capid_votes[(*i)[0].capid()]++;
683  }
684  for (int k = 0; k < 4; k++)
685  if (capid_votes[k] > capid_votes[favorite_capid])
686  favorite_capid = k;
687  }
688 
689  for (i=digi->begin(); i!=digi->end(); i++) {
690  HcalDetId cell = i->id();
691  DetId detcell=(DetId)cell;
692 
694  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
695  if(tsFromDB_) {
696  firstSample_ = param_ts->firstSample();
697  samplesToAdd_ = param_ts->samplesToAdd();
698  }
699  if(recoParamsFromDB_) {
700  bool correctForTimeslew=param_ts->correctForTimeslew();
702  float phaseNS=param_ts->correctionPhaseNS();
704  correctTiming_ = param_ts->correctTiming();
705  firstAuxTS_ = param_ts->firstAuxTS();
706  int pileupCleaningID = param_ts->pileupCleaningID();
707  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
708  }
709  }
710 
711  int first = firstSample_;
712  int toadd = samplesToAdd_;
713 
714  // check on cells to be ignored and dropped: (rof,20.Feb.09)
715  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
716  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
718  if (i->zsMarkAndPass()) continue;
719 
720  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
721  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
722  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
723  HcalCoderDb coder (*channelCoder, *shape);
724 
725  // Set HFDigiTime flag values from digiTimeFromDB_
726  if (digiTimeFromDB_==true && hfdigibit_!=0)
727  {
728  const HcalFlagHFDigiTimeParam* hfDTparam = HFDigiTimeParams->getValues(detcell.rawId());
730  hfDTparam->HFdigiflagSamplesToAdd(),
731  hfDTparam->HFdigiflagExpectedPeak(),
732  hfDTparam->HFdigiflagMinEThreshold(),
733  hfDTparam->HFdigiflagCoefficients()
734  );
735  }
736 
737  //std::cout << "TOADDHF " << toadd << " " << first << " " << std::endl;
738  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
739 
740  // Set auxiliary flag
741  int auxflag=0;
742  int fTS = firstAuxTS_;
743  if (fTS<0) fTS=0; // silly protection against negative time slice values
744  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
745  auxflag+=(i->sample(xx).adc())<<(7*(xx-fTS)); // store the time slices in the first 28 bits of aux, a set of 4 7-bit adc values
746  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
747  auxflag+=((i->sample(fTS).capid())<<28);
748  (rec->back()).setAux(auxflag);
749 
750  // Clear flags
751  (rec->back()).setFlags(0);
752 
753  // Fill Presample ADC flag
754  if (fTS>0)
755  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
756 
757  // This calls the code for setting the HF noise bit determined from digi shape
758  if (setNoiseFlags_)
759  hfdigibit_->hfSetFlagFromDigi(rec->back(),*i,coder,calibrations);
764  if (correctTiming_)
765  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
766  } // for (i=digi->begin(); i!=digi->end(); i++) -- loop on all HF digis
767 
768  // The following flags require the full set of rechits
769  // These need to be set consecutively, so an energy check should be the first
770  // test performed on these hits (to minimize the loop time)
771  if (setNoiseFlags_)
772  {
773  // Step 1: Set PET flag (short fibers of |ieta|==29)
774  // Neighbor/partner channels that are flagged by Pulse Shape algorithm (HFDigiTime)
775  // won't be considered in these calculations
776  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
777  {
778  int depth=i->id().depth();
779  int ieta=i->id().ieta();
780  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
781  if (depth==2 || abs(ieta)==29 )
782  hfPET_->HFSetFlagFromPET(*i,*rec,myqual,mySeverity);
783  }
784 
785  // Step 2: Set S8S1 flag (short fibers or |ieta|==29)
786  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
787  {
788  int depth=i->id().depth();
789  int ieta=i->id().ieta();
790  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
791  if (depth==2 || abs(ieta)==29 )
792  hfS8S1_->HFSetFlagFromS9S1(*i,*rec,myqual,mySeverity);
793  }
794 
795  // Set 3: Set S9S1 flag (long fibers)
796  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
797  {
798  int depth=i->id().depth();
799  int ieta=i->id().ieta();
800  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
801  if (depth==1 && abs(ieta)!=29 )
802  hfS9S1_->HFSetFlagFromS9S1(*i,*rec,myqual, mySeverity);
803  }
804  }
805 
806  // return result
807  e.put(rec);
808  } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
810  e.getByToken(tok_calib_,digi);
811 
812  // create empty output
813  std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
814  rec->reserve(digi->size());
815  // run the algorithm
816  int first = firstSample_;
817  int toadd = samplesToAdd_;
818 
820  for (i=digi->begin(); i!=digi->end(); i++) {
821  HcalCalibDetId cell = i->id();
822  // HcalDetId cellh = i->id();
823  DetId detcell=(DetId)cell;
824  // check on cells to be ignored and dropped: (rof,20.Feb.09)
825  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
826  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
828  if (i->zsMarkAndPass()) continue;
829 
830  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
831  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
832  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
833  HcalCoderDb coder (*channelCoder, *shape);
834 
835  // firstSample & samplesToAdd
836  if(tsFromDB_) {
837  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
838  first = param_ts->firstSample();
839  toadd = param_ts->samplesToAdd();
840  }
841  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
842 
843  /*
844  // Flag setting not available for calibration rechits
845  // Set auxiliary flag
846  int auxflag=0;
847  int fTS = firstAuxTS_;
848  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
849  auxflag+=(i->sample(xx).adc())<<(7*(xx-fTS)); // store the time slices in the first 28 bits of aux, a set of 4 7-bit adc values
850  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
851  auxflag+=((i->sample(fTS).capid())<<28);
852  (rec->back()).setAux(auxflag);
853 
854  (rec->back()).setFlags(0); // Not yet implemented for HcalCalibRecHit
855  */
856  }
857  // return result
858  e.put(rec);
859  }
860  }
861  //DL delete myqual;
862 } // void HcalHitReconstructor::produce(...)
unsigned int firstSample() const
Definition: HcalRecoParam.h:32
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void HFSetFlagFromS9S1(HFRecHit &hf, HFRecHitCollection &rec, const HcalChannelQuality *myqual, const HcalSeverityLevelComputer *mySeverity)
HBHERecHit reconstruct(const HBHEDataFrame &digi, int first, int toadd, const HcalCoder &coder, const HcalCalibrations &calibs) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
edm::EDGetTokenT< HBHEDigiCollection > tok_hbhe_
void configFilter(const HBHENegativeEFilter *f)
void setHFTimingTrustFlag(HFRecHit &rechit, const HFDataFrame &digi)
unsigned int pileupCleaningID() const
Definition: HcalRecoParam.h:44
HcalADCSaturationFlag * saturationFlagSetter_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void setAllowAnything()
allow any parameter label/value pairs
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
uint32_t HFdigiflagSamplesToAdd() const
void beginRun(edm::EventSetup const &es)
bool correctForPhaseContainment() const
Definition: HcalRecoParam.h:29
void hfSetFlagFromDigi(HFRecHit &hf, const HFDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib)
std::vector< HBHEDataFrame >::const_iterator const_iterator
void setHOPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
const Item * getValues(DetId fId, bool throwOnFail=true) const
void resetParamsFromDB(int firstSample, int samplesToAdd, int expectedPeak, double minthreshold, const std::vector< double > &coef)
virtual void endRun(edm::Run const &r, edm::EventSetup const &es) overridefinal
bool isRealData() const
Definition: EventBase.h:64
SetCorrectionFcn setPileupCorrection_
void HFSetFlagFromPET(HFRecHit &hf, HFRecHitCollection &rec, const HcalChannelQuality *myqual, const HcalSeverityLevelComputer *mySeverity)
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
std::string dataOOTCorrectionCategory_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
HBHENegativeFlagSetter * hbheNegativeFlagSetter_
std::unique_ptr< HcalFlagHFDigiTimeParams > HFDigiTimeParams
void get(HolderT &iHolder) const
bool correctForTimeslew() const
Definition: HcalRecoParam.h:38
edm::EDGetTokenT< HcalCalibDigiCollection > tok_calib_
bool correctTiming() const
Definition: HcalRecoParam.h:40
RunNumber_t run() const
Definition: Event.h:87
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HcalHFStatusBitFromDigis * hfdigibit_
int j
Definition: DBlmapReader.cc:9
bool dropChannel(const uint32_t &mystatus) const
uint32_t HFdigiflagExpectedPeak() const
void setMeth3Params(int iPedSubMethod, float iPedSubThreshold, int iTimeSlewParsType, std::vector< double > iTimeSlewPars)
void hbheSetTimeFlagsFromDigi(HBHERecHitCollection *, const std::vector< HBHEDataFrame > &, const std::vector< int > &)
void setSaturationFlag(HBHERecHit &rechit, const HBHEDataFrame &digi)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
unsigned int samplesToAdd() const
Definition: HcalRecoParam.h:33
edm::EDGetTokenT< HODigiCollection > tok_ho_
HcalHitReconstructor(const edm::ParameterSet &ps)
#define LogTrace(id)
float correctionPhaseNS() const
Definition: HcalRecoParam.h:31
tuple conf
Definition: dbtoconf.py:185
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< HFRecHit >::iterator iterator
std::vector< double > HFdigiflagCoefficients() const
HcalHF_PETalgorithm * hfPET_
Definition: DetId.h:18
HcalHF_S9S1algorithm * hfS9S1_
HBHEPulseShapeFlagSetter * hbhePulseShapeFlagSetter_
static const int SubdetectorId
Definition: HcalZDCDetId.h:20
void setRecoParams(bool correctForTimeslew, bool correctForPulse, bool setLeakCorrection, int pileupCleaningID, float phaseNS)
virtual void beginRun(edm::Run const &r, edm::EventSetup const &es) overridefinal
void SetTimingShapedFlags(HBHERecHit &hbhe)
uint32_t HFdigiflagFirstSample() const
void setHBHEPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
const T & get() const
Definition: EventSetup.h:55
void setForData(int runnum)
T const * product() const
Definition: ESHandle.h:86
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HBHEStatusBitSetter * hbheFlagSetter_
HBHETimeProfileStatusBitSetter * hbheHSCPFlagSetter_
HBHETimingShapedFlagSetter * hbheTimingShapedFlagSetter_
void setPulseShapeFlags(HBHERecHit &hbhe, const HBHEDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib)
void setpuCorrMethod(int method)
HcalHF_S9S1algorithm * hfS8S1_
void SetFlagsFromRecHits(const HcalTopology *topo, HBHERecHitCollection &rec)
HcalOtherSubdetector subdetOther_
static void Correct(HBHERecHit &rechit, const HBHEDataFrame &digi, int favorite_capid)
void SetPulseShapeFlags(HBHERecHit &hbhe, const HBHEDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib)
unsigned int firstAuxTS() const
Definition: HcalRecoParam.h:41
volatile std::atomic< bool > shutdown_flag false
HFTimingTrustFlag * HFTimingTrustFlagSetter_
uint32_t getValue() const
void SetFlagsFromDigi(const HcalTopology *topo, HBHERecHit &hbhe, const HBHEDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib, int firstSample=3, int samplesToAdd=4)
std::string mcOOTCorrectionCategory_
edm::EDGetTokenT< HFDigiCollection > tok_hf_
void setTopo(const HcalTopology *topo)
void setHFPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
Definition: Run.h:41
HcalSimpleRecAlgo reco_
void setpuCorrParams(bool iPedestalConstraint, bool iTimeConstraint, bool iAddPulseJitter, bool iUnConstrainedFit, bool iApplyTimeSlew, double iTS4Min, double iTS4Max, double iPulseJitter, double iTimeMean, double iTimeSig, double iPedMean, double iPedSig, double iNoise, double iTMin, double iTMax, double its3Chi2, double its4Chi2, double its345Chi2, double iChargeThreshold, int iFitTimes)
double HFdigiflagMinEThreshold() const
bool useLeakCorrection() const
Definition: HcalRecoParam.h:36