CMS 3D CMS Logo

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