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