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.getParameter<int>("puCorrMethod")),
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")) {
166  // setPileupCorrection_ = &HcalSimpleRecAlgo::setHOPileupCorrection;
168  produces<HORecHitCollection>();
169  } else if (!strcasecmp(subd.c_str(),"HF")) {
171  // setPileupCorrection_ = &HcalSimpleRecAlgo::setHFPileupCorrection;
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  }
274  conf.getParameter<int> ("pedestalSubtractionType"),
275  conf.getParameter<double> ("pedestalUpperLimit"),
276  conf.getParameter<int> ("timeSlewParsType"),
277  conf.getParameter<std::vector<double> >("timeSlewPars"),
278  conf.getParameter<double> ("respCorrM3")
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", { 12.2999, -2.19142, 0, 12.2999, -2.19142, 0, 12.2999, -2.19142, 0 });
291  desc.add<double>("respCorrM3", 0.95);
292  descriptions.add("hltHbhereco",desc);
293 }
294 
296  delete hbheFlagSetter_;
297  delete hbheHSCPFlagSetter_;
301  delete hfdigibit_;
302 
303  delete hfS9S1_;
304  delete hfS8S1_;
305  delete hfPET_;
306  delete saturationFlagSetter_;
308 
309  delete paramTS;
310 }
311 
313 
315  es.get<HcalRecNumberingRecord>().get(htopo);
316 
317  if ( tsFromDB_== true || recoParamsFromDB_ == true )
318  {
320  es.get<HcalRecoParamsRcd>().get(p);
321  paramTS = new HcalRecoParams(*p.product());
322  paramTS->setTopo(htopo.product());
323 
324 
325 
326 
327  // std::cout<<" skdump in HcalHitReconstructor::beginRun dupm RecoParams "<<std::endl;
328  // std::ofstream skfile("skdumpRecoParamsNewFormat.txt");
329  // HcalDbASCIIIO::dumpObject(skfile, (*paramTS) );
330  }
331 
332  if (digiTimeFromDB_==true)
333  {
335  es.get<HcalFlagHFDigiTimeParamsRcd>().get(p);
336  HFDigiTimeParams.reset( new HcalFlagHFDigiTimeParams( *p ) );
337 
339  es.get<HcalRecNumberingRecord>().get(htopo);
340  HFDigiTimeParams->setTopo(htopo.product());
341 
342  }
343 
344  reco_.beginRun(es);
345 }
346 
348  if (tsFromDB_==true)
349  {
350  delete paramTS; paramTS=0;
351  }
352  if (digiTimeFromDB_==true)
353  {
354  //DL delete HFDigiTimeParams; HFDigiTimeParams = 0;
355  }
356  reco_.endRun();
357 }
358 
360 {
361 
362  // get conditions
364  eventSetup.get<HcalRecNumberingRecord>().get(topo);
365 
366  edm::ESHandle<HcalDbService> conditions;
367  eventSetup.get<HcalDbRecord>().get(conditions);
368 
369  // HACK related to HB- corrections
370  if ( first_ ) {
371  const bool isData = e.isRealData();
372  if (isData) reco_.setForData(e.run()); else reco_.setForData(0);
375  first_=false;
376  }
378 
380  eventSetup.get<HcalChannelQualityRcd>().get("withTopo",p);
381  const HcalChannelQuality* myqual = p.product();
382 
384  eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
385  const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
386 
387  // Configure OOT pileup corrections
388  bool isMethod1Set = false;
389  if (!corrName_.empty())
390  {
391  edm::ESHandle<OOTPileupCorrectionColl> pileupCorrections;
392  if (eventSetup.find(edm::eventsetup::EventSetupRecordKey::makeKey<HcalOOTPileupCorrectionRcd>()))
393  eventSetup.get<HcalOOTPileupCorrectionRcd>().get(pileupCorrections);
394  else
395  eventSetup.get<HcalOOTPileupCompatibilityRcd>().get(pileupCorrections);
396 
397  if( setPileupCorrection_ ){
398  const OOTPileupCorrData * testMethod1Ptr = dynamic_cast<OOTPileupCorrData*>((pileupCorrections->get(corrName_, cat_)).get());
399  if( testMethod1Ptr ) isMethod1Set = true;
400  (reco_.*setPileupCorrection_)(pileupCorrections->get(corrName_, cat_));
401  }
402  }
403 
404  // Configure the negative energy filter
407  {
408  eventSetup.get<HBHENegativeEFilterRcd>().get(negEhandle);
410  }
411 
412  // Only for HBHE
413  if( subdet_ == HcalBarrel ) {
414  if( !cntprtCorrMethod_ ) {
416  if( puCorrMethod_ == 2 ) LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 2" << std::endl;
417  else if( puCorrMethod_ == 1 ){
418  if( isMethod1Set ) LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 1" << std::endl;
419  else edm::LogWarning("HcalPUcorrMethod") <<"puCorrMethod_ set to be 1 but method 1 is NOT activated (method 0 used instead)!\n"
420  <<"Please check GlobalTag usage or method 1 separately disabled by dataOOTCorrectionName & mcOOTCorrectionName?" << std::endl;
421  } else if (puCorrMethod_ == 3) {
422  LogTrace("HcalPUcorrMethod") << "Using Hcal Deterministic Fit Method!" << std::endl;
423  } else LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 0" << std::endl;
424  }
425  }
426 
427  // GET THE BEAM CROSSING INFO HERE, WHEN WE UNDERSTAND HOW THINGS WORK.
428  // Then, call "setBXInfo" method of the reco_ object.
429  // Also remember to call SetBXInfo in the negative energy flag setter.
430 
431  if (det_==DetId::Hcal) {
432 
433  // HBHE -------------------------------------------------------------------
436 
437  e.getByToken(tok_hbhe_,digi);
438 
439  // create empty output
440  std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
441  rec->reserve(digi->size());
442  // run the algorithm
445  std::vector<HBHEDataFrame> HBDigis;
446  std::vector<int> RecHitIndex;
447 
448  // Vote on majority TS0 CapId
449  int favorite_capid = 0;
450  if (correctTiming_) {
451  long capid_votes[4] = {0,0,0,0};
452  for (i=digi->begin(); i!=digi->end(); i++) {
453  capid_votes[(*i)[0].capid()]++;
454  }
455  for (int k = 0; k < 4; k++)
456  if (capid_votes[k] > capid_votes[favorite_capid])
457  favorite_capid = k;
458  }
459 
460  for (i=digi->begin(); i!=digi->end(); i++) {
461  HcalDetId cell = i->id();
462  DetId detcell=(DetId)cell;
463 
465  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
466  if(tsFromDB_) {
467  firstSample_ = param_ts->firstSample();
468  samplesToAdd_ = param_ts->samplesToAdd();
469  }
470  if(recoParamsFromDB_) {
471  bool correctForTimeslew=param_ts->correctForTimeslew();
473  float phaseNS=param_ts->correctionPhaseNS();
475  correctTiming_ = param_ts->correctTiming();
476  firstAuxTS_ = param_ts->firstAuxTS();
477  int pileupCleaningID = param_ts->pileupCleaningID();
478 
479  /*
480  int sub = cell.subdet();
481  int depth = cell.depth();
482  int inteta = cell.ieta();
483  int intphi = cell.iphi();
484 
485  std::cout << "HcalHitReconstructor::produce cell:"
486  << " sub, ieta, iphi, depth = "
487  << sub << " " << inteta << " " << intphi
488  << " " << depth << std::endl
489  << " first, toadd = " << firstSample_ << ", "
490  << samplesToAdd_ << std::endl
491  << " correctForTimeslew " << correctForTimeslew
492  << std::endl
493  << " correctForPhaseContainment "
494  << correctForPhaseContainment << std::endl
495  << " phaseNS " << phaseNS << std::endl
496  << " useLeakCorrection " << useLeakCorrection_
497  << std::endl
498  << " correctTiming " << correctTiming_ << std::endl
499  << " firstAuxTS " << firstAuxTS_ << std::endl
500  << " pileupCleaningID " << pileupCleaningID
501  << std::endl;
502  */
503 
504  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
505  }
506  }
507 
508  int first = firstSample_;
509  int toadd = samplesToAdd_;
510 
511  // check on cells to be ignored and dropped: (rof,20.Feb.09)
512  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
513  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
515  if (i->zsMarkAndPass()) continue;
516 
517  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
518  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
519  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
520  HcalCoderDb coder (*channelCoder, *shape);
521 
522  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
523 
524  // Fill first auxiliary word
525  unsigned int auxflag=0;
526  int fTS = firstAuxTS_;
527  if (fTS<0) fTS=0; // silly protection against time slice <0
528  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx) {
529  int adcv = i->sample(xx).adc();
530  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
531  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
532  }
533  auxflag+=((i->sample(fTS).capid())<<28);
534  (rec->back()).setAux(auxflag);
535 
536  // Fill second auxiliary word
537  auxflag=0;
538  int fTS2 = (firstAuxTS_-4 < 0) ? 0 : firstAuxTS_-4;
539  for (int xx = fTS2; xx < fTS2+4 && xx<i->size(); ++xx) {
540  int adcv = i->sample(xx).adc();
541  auxflag+=((adcv&0x7F)<<(7*(xx-fTS2)));
542  }
543  auxflag+=((i->sample(fTS2).capid())<<28);
544  (rec->back()).setAuxHBHE(auxflag);
545 
546  (rec->back()).setFlags(0); // this sets all flag bits to 0
547  // Set presample flag
548  if (fTS>0)
549  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
550 
553  if (setNoiseFlags_)
554  hbheFlagSetter_->SetFlagsFromDigi(&(*topo),rec->back(),*i,coder,calibrations,first,toadd);
556  hbhePulseShapeFlagSetter_->SetPulseShapeFlags(rec->back(), *i, coder, calibrations);
557  if (setNegativeFlags_)
558  hbheNegativeFlagSetter_->setPulseShapeFlags(rec->back(), *i, coder, calibrations);
561  if (correctTiming_)
562  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
563  if (setHSCPFlags_ && i->id().ietaAbs()<16)
564  {
565  double DigiEnergy=0;
566  for(int j=0; j!=i->size(); DigiEnergy += i->sample(j++).nominal_fC());
567  if(DigiEnergy > hbheHSCPFlagSetter_->EnergyThreshold())
568  {
569  HBDigis.push_back(*i);
570  RecHitIndex.push_back(rec->size()-1);
571  }
572 
573  } // if (set HSCPFlags_ && |ieta|<16)
574  } // loop over HBHE digis
575 
576 
578  if (setHSCPFlags_) hbheHSCPFlagSetter_->hbheSetTimeFlagsFromDigi(rec.get(), HBDigis, RecHitIndex);
579  // return result
580  e.put(rec);
581 
582  // HO ------------------------------------------------------------------
583  } else if (subdet_==HcalOuter) {
585  e.getByToken(tok_ho_,digi);
586 
587  // create empty output
588  std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
589  rec->reserve(digi->size());
590  // run the algorithm
592 
593  // Vote on majority TS0 CapId
594  int favorite_capid = 0;
595  if (correctTiming_) {
596  long capid_votes[4] = {0,0,0,0};
597  for (i=digi->begin(); i!=digi->end(); i++) {
598  capid_votes[(*i)[0].capid()]++;
599  }
600  for (int k = 0; k < 4; k++)
601  if (capid_votes[k] > capid_votes[favorite_capid])
602  favorite_capid = k;
603  }
604 
605  for (i=digi->begin(); i!=digi->end(); i++) {
606  HcalDetId cell = i->id();
607  DetId detcell=(DetId)cell;
608  // firstSample & samplesToAdd
610  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
611  if(tsFromDB_) {
612  firstSample_ = param_ts->firstSample();
613  samplesToAdd_ = param_ts->samplesToAdd();
614  }
615  if(recoParamsFromDB_) {
616  bool correctForTimeslew=param_ts->correctForTimeslew();
618  float phaseNS=param_ts->correctionPhaseNS();
620  correctTiming_ = param_ts->correctTiming();
621  firstAuxTS_ = param_ts->firstAuxTS();
622  int pileupCleaningID = param_ts->pileupCleaningID();
623  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
624  }
625  }
626 
627  int first = firstSample_;
628  int toadd = samplesToAdd_;
629 
630  // check on cells to be ignored and dropped: (rof,20.Feb.09)
631  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
632  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
634  if (i->zsMarkAndPass()) continue;
635 
636  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
637  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
638  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
639  HcalCoderDb coder (*channelCoder, *shape);
640 
641  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
642 
643  // Set auxiliary flag
644  int auxflag=0;
645  int fTS = firstAuxTS_;
646  if (fTS<0) fTS=0; //silly protection against negative time slice values
647  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
648  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
649  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
650  auxflag+=((i->sample(fTS).capid())<<28);
651  (rec->back()).setAux(auxflag);
652  (rec->back()).setFlags(0);
653  // Fill Presample ADC flag
654  if (fTS>0)
655  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
656 
659  if (correctTiming_)
660  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
661  }
662  // return result
663  e.put(rec);
664 
665  // HF -------------------------------------------------------------------
666  } else if (subdet_==HcalForward) {
668  e.getByToken(tok_hf_,digi);
669 
670 
672  // create empty output
673  std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
674  rec->reserve(digi->size());
675  // run the algorithm
677 
678  // Vote on majority TS0 CapId
679  int favorite_capid = 0;
680  if (correctTiming_) {
681  long capid_votes[4] = {0,0,0,0};
682  for (i=digi->begin(); i!=digi->end(); i++) {
683  capid_votes[(*i)[0].capid()]++;
684  }
685  for (int k = 0; k < 4; k++)
686  if (capid_votes[k] > capid_votes[favorite_capid])
687  favorite_capid = k;
688  }
689 
690  for (i=digi->begin(); i!=digi->end(); i++) {
691  HcalDetId cell = i->id();
692  DetId detcell=(DetId)cell;
693 
695  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
696  if(tsFromDB_) {
697  firstSample_ = param_ts->firstSample();
698  samplesToAdd_ = param_ts->samplesToAdd();
699  }
700  if(recoParamsFromDB_) {
701  bool correctForTimeslew=param_ts->correctForTimeslew();
703  float phaseNS=param_ts->correctionPhaseNS();
705  correctTiming_ = param_ts->correctTiming();
706  firstAuxTS_ = param_ts->firstAuxTS();
707  int pileupCleaningID = param_ts->pileupCleaningID();
708  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
709  }
710  }
711 
712  int first = firstSample_;
713  int toadd = samplesToAdd_;
714 
715  // check on cells to be ignored and dropped: (rof,20.Feb.09)
716  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
717  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
719  if (i->zsMarkAndPass()) continue;
720 
721  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
722  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
723  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
724  HcalCoderDb coder (*channelCoder, *shape);
725 
726  // Set HFDigiTime flag values from digiTimeFromDB_
727  if (digiTimeFromDB_==true && hfdigibit_!=0)
728  {
729  const HcalFlagHFDigiTimeParam* hfDTparam = HFDigiTimeParams->getValues(detcell.rawId());
731  hfDTparam->HFdigiflagSamplesToAdd(),
732  hfDTparam->HFdigiflagExpectedPeak(),
733  hfDTparam->HFdigiflagMinEThreshold(),
734  hfDTparam->HFdigiflagCoefficients()
735  );
736  }
737 
738  //std::cout << "TOADDHF " << toadd << " " << first << " " << std::endl;
739  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
740 
741  // Set auxiliary flag
742  int auxflag=0;
743  int fTS = firstAuxTS_;
744  if (fTS<0) fTS=0; // silly protection against negative time slice values
745  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
746  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
747  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
748  auxflag+=((i->sample(fTS).capid())<<28);
749  (rec->back()).setAux(auxflag);
750 
751  // Clear flags
752  (rec->back()).setFlags(0);
753 
754  // Fill Presample ADC flag
755  if (fTS>0)
756  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
757 
758  // This calls the code for setting the HF noise bit determined from digi shape
759  if (setNoiseFlags_)
760  hfdigibit_->hfSetFlagFromDigi(rec->back(),*i,coder,calibrations);
765  if (correctTiming_)
766  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
767  } // for (i=digi->begin(); i!=digi->end(); i++) -- loop on all HF digis
768 
769  // The following flags require the full set of rechits
770  // These need to be set consecutively, so an energy check should be the first
771  // test performed on these hits (to minimize the loop time)
772  if (setNoiseFlags_)
773  {
774  // Step 1: Set PET flag (short fibers of |ieta|==29)
775  // Neighbor/partner channels that are flagged by Pulse Shape algorithm (HFDigiTime)
776  // won't be considered in these calculations
777  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
778  {
779  int depth=i->id().depth();
780  int ieta=i->id().ieta();
781  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
782  if (depth==2 || abs(ieta)==29 )
783  hfPET_->HFSetFlagFromPET(*i,*rec,myqual,mySeverity);
784  }
785 
786  // Step 2: Set S8S1 flag (short fibers or |ieta|==29)
787  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
788  {
789  int depth=i->id().depth();
790  int ieta=i->id().ieta();
791  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
792  if (depth==2 || abs(ieta)==29 )
793  hfS8S1_->HFSetFlagFromS9S1(*i,*rec,myqual,mySeverity);
794  }
795 
796  // Set 3: Set S9S1 flag (long fibers)
797  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
798  {
799  int depth=i->id().depth();
800  int ieta=i->id().ieta();
801  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
802  if (depth==1 && abs(ieta)!=29 )
803  hfS9S1_->HFSetFlagFromS9S1(*i,*rec,myqual, mySeverity);
804  }
805  }
806 
807  // return result
808  e.put(rec);
809  } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
811  e.getByToken(tok_calib_,digi);
812 
813  // create empty output
814  std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
815  rec->reserve(digi->size());
816  // run the algorithm
817  int first = firstSample_;
818  int toadd = samplesToAdd_;
819 
821  for (i=digi->begin(); i!=digi->end(); i++) {
822  HcalCalibDetId cell = i->id();
823  // HcalDetId cellh = i->id();
824  DetId detcell=(DetId)cell;
825  // check on cells to be ignored and dropped: (rof,20.Feb.09)
826  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
827  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
829  if (i->zsMarkAndPass()) continue;
830 
831  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
832  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
833  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
834  HcalCoderDb coder (*channelCoder, *shape);
835 
836  // firstSample & samplesToAdd
837  if(tsFromDB_) {
838  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
839  first = param_ts->firstSample();
840  toadd = param_ts->samplesToAdd();
841  }
842  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
843 
844  /*
845  // Flag setting not available for calibration rechits
846  // Set auxiliary flag
847  int auxflag=0;
848  int fTS = firstAuxTS_;
849  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
850  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
851  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
852  auxflag+=((i->sample(fTS).capid())<<28);
853  (rec->back()).setAux(auxflag);
854 
855  (rec->back()).setFlags(0); // Not yet implemented for HcalCalibRecHit
856  */
857  }
858  // return result
859  e.put(rec);
860  }
861  }
862  //DL delete myqual;
863 } // void HcalHitReconstructor::produce(...)
void setMeth3Params(int iPedSubMethod, float iPedSubThreshold, int iTimeSlewParsType, std::vector< double > iTimeSlewPars, double irespCorrM3)
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:464
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
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:91
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:120
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:92
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 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:56
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)
Definition: Run.h:43
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