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<double>("TS3TS4ChargeThreshold"),
143  psPulseShape.getParameter<double>("TS3TS4UpperChargeThreshold"),
144  psPulseShape.getParameter<double>("TS5TS6ChargeThreshold"),
145  psPulseShape.getParameter<double>("TS5TS6UpperChargeThreshold"),
146  psPulseShape.getParameter<double>("R45PlusOneRange"),
147  psPulseShape.getParameter<double>("R45MinusOneRange"),
148  psPulseShape.getParameter<unsigned int>("TrianglePeakTS"),
149  psPulseShape.getParameter<std::vector<double> >("LinearThreshold"),
150  psPulseShape.getParameter<std::vector<double> >("LinearCut"),
151  psPulseShape.getParameter<std::vector<double> >("RMS8MaxThreshold"),
152  psPulseShape.getParameter<std::vector<double> >("RMS8MaxCut"),
153  psPulseShape.getParameter<std::vector<double> >("LeftSlopeThreshold"),
154  psPulseShape.getParameter<std::vector<double> >("LeftSlopeCut"),
155  psPulseShape.getParameter<std::vector<double> >("RightSlopeThreshold"),
156  psPulseShape.getParameter<std::vector<double> >("RightSlopeCut"),
157  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallThreshold"),
158  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallCut"),
159  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerThreshold"),
160  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerCut"),
161  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperThreshold"),
162  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperCut"),
163  psPulseShape.getParameter<bool>("UseDualFit"),
164  psPulseShape.getParameter<bool>("TriangleIgnoreSlow"));
165  } // if (setPulseShapeFlags_)
166  if (setNegativeFlags_)
168 
169  produces<HBHERecHitCollection>();
170  } else if (!strcasecmp(subd.c_str(),"HO")) {
172  // setPileupCorrection_ = &HcalSimpleRecAlgo::setHOPileupCorrection;
174  produces<HORecHitCollection>();
175  } else if (!strcasecmp(subd.c_str(),"HF")) {
177  // setPileupCorrection_ = &HcalSimpleRecAlgo::setHFPileupCorrection;
179  digiTimeFromDB_=conf.getParameter<bool>("digiTimeFromDB");
180 
181  if (setTimingTrustFlags_) {
182 
183  const edm::ParameterSet& pstrust = conf.getParameter<edm::ParameterSet>("hfTimingTrustParameters");
184  HFTimingTrustFlagSetter_=new HFTimingTrustFlag(pstrust.getParameter<int>("hfTimingTrustLevel1"),
185  pstrust.getParameter<int>("hfTimingTrustLevel2"));
186  }
187 
188  if (setNoiseFlags_)
189  {
190  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("digistat");
191  const edm::ParameterSet& psTimeWin =conf.getParameter<edm::ParameterSet>("HFInWindowStat");
192  hfdigibit_=new HcalHFStatusBitFromDigis(psdigi,psTimeWin);
193 
194  const edm::ParameterSet& psS9S1 = conf.getParameter<edm::ParameterSet>("S9S1stat");
195  hfS9S1_ = new HcalHF_S9S1algorithm(psS9S1.getParameter<std::vector<double> >("short_optimumSlope"),
196  psS9S1.getParameter<std::vector<double> >("shortEnergyParams"),
197  psS9S1.getParameter<std::vector<double> >("shortETParams"),
198  psS9S1.getParameter<std::vector<double> >("long_optimumSlope"),
199  psS9S1.getParameter<std::vector<double> >("longEnergyParams"),
200  psS9S1.getParameter<std::vector<double> >("longETParams"),
201  psS9S1.getParameter<int>("HcalAcceptSeverityLevel"),
202  psS9S1.getParameter<bool>("isS8S1")
203  );
204 
205  const edm::ParameterSet& psS8S1 = conf.getParameter<edm::ParameterSet>("S8S1stat");
206  hfS8S1_ = new HcalHF_S9S1algorithm(psS8S1.getParameter<std::vector<double> >("short_optimumSlope"),
207  psS8S1.getParameter<std::vector<double> >("shortEnergyParams"),
208  psS8S1.getParameter<std::vector<double> >("shortETParams"),
209  psS8S1.getParameter<std::vector<double> >("long_optimumSlope"),
210  psS8S1.getParameter<std::vector<double> >("longEnergyParams"),
211  psS8S1.getParameter<std::vector<double> >("longETParams"),
212  psS8S1.getParameter<int>("HcalAcceptSeverityLevel"),
213  psS8S1.getParameter<bool>("isS8S1")
214  );
215 
216  const edm::ParameterSet& psPET = conf.getParameter<edm::ParameterSet>("PETstat");
217  hfPET_ = new HcalHF_PETalgorithm(psPET.getParameter<std::vector<double> >("short_R"),
218  psPET.getParameter<std::vector<double> >("shortEnergyParams"),
219  psPET.getParameter<std::vector<double> >("shortETParams"),
220  psPET.getParameter<std::vector<double> >("long_R"),
221  psPET.getParameter<std::vector<double> >("longEnergyParams"),
222  psPET.getParameter<std::vector<double> >("longETParams"),
223  psPET.getParameter<int>("HcalAcceptSeverityLevel"),
224  psPET.getParameter<std::vector<double> >("short_R_29"),
225  psPET.getParameter<std::vector<double> >("long_R_29")
226  );
227  }
228  produces<HFRecHitCollection>();
229  } else if (!strcasecmp(subd.c_str(),"ZDC")) {
232  produces<ZDCRecHitCollection>();
233  } else if (!strcasecmp(subd.c_str(),"CALIB")) {
236  produces<HcalCalibRecHitCollection>();
237  } else {
238  edm::LogWarning("Configuration") << "HcalHitReconstructor is not associated with a specific subdetector!" << std::endl;
239  }
240 
241  // If no valid OOT pileup correction name specified,
242  // disable the correction
243  if (conf.existsAs<std::string>("dataOOTCorrectionName"))
244  dataOOTCorrectionName_ = conf.getParameter<std::string>("dataOOTCorrectionName");
245  if (conf.existsAs<std::string>("dataOOTCorrectionCategory"))
246  dataOOTCorrectionCategory_ = conf.getParameter<std::string>("dataOOTCorrectionCategory");
247  if (conf.existsAs<std::string>("mcOOTCorrectionName"))
248  mcOOTCorrectionName_ = conf.getParameter<std::string>("mcOOTCorrectionName");
249  if (conf.existsAs<std::string>("mcOOTCorrectionCategory"))
250  mcOOTCorrectionCategory_ = conf.getParameter<std::string>("mcOOTCorrectionCategory");
251  if (dataOOTCorrectionName_.empty() && mcOOTCorrectionName_.empty())
253 
255  if(puCorrMethod_ == 2) {
257  conf.getParameter<bool> ("applyPedConstraint"),
258  conf.getParameter<bool> ("applyTimeConstraint"),
259  conf.getParameter<bool> ("applyPulseJitter"),
260  conf.getParameter<bool> ("applyUnconstrainedFit"),
261  conf.getParameter<bool> ("applyTimeSlew"),
262  conf.getParameter<double>("ts4Min"),
263  conf.getParameter<double>("ts4Max"),
264  conf.getParameter<double>("pulseJitter"),
265  conf.getParameter<double>("meanTime"),
266  conf.getParameter<double>("timeSigma"),
267  conf.getParameter<double>("meanPed"),
268  conf.getParameter<double>("pedSigma"),
269  conf.getParameter<double>("noise"),
270  conf.getParameter<double>("timeMin"),
271  conf.getParameter<double>("timeMax"),
272  conf.getParameter<double>("ts3chi2"),
273  conf.getParameter<double>("ts4chi2"),
274  conf.getParameter<double>("ts345chi2"),
275  conf.getParameter<double>("chargeMax"), //For the unconstrained Fit
276  conf.getParameter<int> ("fitTimes")
277  );
278  }
280  conf.getParameter<int> ("pedestalSubtractionType"),
281  conf.getParameter<double> ("pedestalUpperLimit"),
282  conf.getParameter<int> ("timeSlewParsType"),
283  conf.getParameter<std::vector<double> >("timeSlewPars"),
284  conf.getParameter<double> ("respCorrM3")
285  );
286 }
287 
288 
289 
292  desc.setAllowAnything();
293  desc.add<int>("pedestalSubtractionType", 1);
294  desc.add<double>("pedestalUpperLimit", 2.7);
295  desc.add<int>("timeSlewParsType",3);
296  desc.add<std::vector<double>>("timeSlewPars", { 12.2999, -2.19142, 0, 12.2999, -2.19142, 0, 12.2999, -2.19142, 0 });
297  desc.add<double>("respCorrM3", 0.95);
298  descriptions.add("hltHbhereco",desc);
299 }
300 
302  delete hbheFlagSetter_;
303  delete hbheHSCPFlagSetter_;
307  delete hfdigibit_;
308 
309  delete hfS9S1_;
310  delete hfS8S1_;
311  delete hfPET_;
312  delete saturationFlagSetter_;
314 
315  delete paramTS;
316 }
317 
319 
321  es.get<HcalRecNumberingRecord>().get(htopo);
322 
323  if ( tsFromDB_== true || recoParamsFromDB_ == true )
324  {
326  es.get<HcalRecoParamsRcd>().get(p);
327  paramTS = new HcalRecoParams(*p.product());
328  paramTS->setTopo(htopo.product());
329 
330 
331 
332 
333  // std::cout<<" skdump in HcalHitReconstructor::beginRun dupm RecoParams "<<std::endl;
334  // std::ofstream skfile("skdumpRecoParamsNewFormat.txt");
335  // HcalDbASCIIIO::dumpObject(skfile, (*paramTS) );
336  }
337 
338  if (digiTimeFromDB_==true)
339  {
341  es.get<HcalFlagHFDigiTimeParamsRcd>().get(p);
342  HFDigiTimeParams.reset( new HcalFlagHFDigiTimeParams( *p ) );
343 
345  es.get<HcalRecNumberingRecord>().get(htopo);
346  HFDigiTimeParams->setTopo(htopo.product());
347 
348  }
349 
350  reco_.beginRun(es);
351 }
352 
354  if (tsFromDB_==true)
355  {
356  delete paramTS; paramTS=0;
357  }
358  if (digiTimeFromDB_==true)
359  {
360  //DL delete HFDigiTimeParams; HFDigiTimeParams = 0;
361  }
362  reco_.endRun();
363 }
364 
366 {
367 
368  // get conditions
370  eventSetup.get<HcalRecNumberingRecord>().get(topo);
371 
372  edm::ESHandle<HcalDbService> conditions;
373  eventSetup.get<HcalDbRecord>().get(conditions);
374 
375  // HACK related to HB- corrections
376  if ( first_ ) {
377  const bool isData = e.isRealData();
378  if (isData) reco_.setForData(e.run()); else reco_.setForData(0);
381  first_=false;
382  }
384 
386  eventSetup.get<HcalChannelQualityRcd>().get("withTopo",p);
387  const HcalChannelQuality* myqual = p.product();
388 
390  eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
391  const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
392 
393  // Configure OOT pileup corrections
394  bool isMethod1Set = false;
395  if (!corrName_.empty())
396  {
397  edm::ESHandle<OOTPileupCorrectionColl> pileupCorrections;
398  if (eventSetup.find(edm::eventsetup::EventSetupRecordKey::makeKey<HcalOOTPileupCorrectionRcd>()))
399  eventSetup.get<HcalOOTPileupCorrectionRcd>().get(pileupCorrections);
400  else
401  eventSetup.get<HcalOOTPileupCompatibilityRcd>().get(pileupCorrections);
402 
403  if( setPileupCorrection_ ){
404  const OOTPileupCorrData * testMethod1Ptr = dynamic_cast<OOTPileupCorrData*>((pileupCorrections->get(corrName_, cat_)).get());
405  if( testMethod1Ptr ) isMethod1Set = true;
406  (reco_.*setPileupCorrection_)(pileupCorrections->get(corrName_, cat_));
407  }
408  }
409 
410  // Configure the negative energy filter
413  {
414  eventSetup.get<HBHENegativeEFilterRcd>().get(negEhandle);
416  }
417 
418  // Only for HBHE
419  if( subdet_ == HcalBarrel ) {
420  if( !cntprtCorrMethod_ ) {
422  if( puCorrMethod_ == 2 ) LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 2" << std::endl;
423  else if( puCorrMethod_ == 1 ){
424  if( isMethod1Set ) LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 1" << std::endl;
425  else edm::LogWarning("HcalPUcorrMethod") <<"puCorrMethod_ set to be 1 but method 1 is NOT activated (method 0 used instead)!\n"
426  <<"Please check GlobalTag usage or method 1 separately disabled by dataOOTCorrectionName & mcOOTCorrectionName?" << std::endl;
427  } else if (puCorrMethod_ == 3) {
428  LogTrace("HcalPUcorrMethod") << "Using Hcal Deterministic Fit Method!" << std::endl;
429  } else LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 0" << std::endl;
430  }
431  }
432 
433  // GET THE BEAM CROSSING INFO HERE, WHEN WE UNDERSTAND HOW THINGS WORK.
434  // Then, call "setBXInfo" method of the reco_ object.
435  // Also remember to call SetBXInfo in the negative energy flag setter.
436 
437  if (det_==DetId::Hcal) {
438 
439  // HBHE -------------------------------------------------------------------
442 
443  e.getByToken(tok_hbhe_,digi);
444 
445  // create empty output
446  std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
447  rec->reserve(digi->size());
448  // run the algorithm
451  std::vector<HBHEDataFrame> HBDigis;
452  std::vector<int> RecHitIndex;
453 
454  // Vote on majority TS0 CapId
455  int favorite_capid = 0;
456  if (correctTiming_) {
457  long capid_votes[4] = {0,0,0,0};
458  for (i=digi->begin(); i!=digi->end(); i++) {
459  capid_votes[(*i)[0].capid()]++;
460  }
461  for (int k = 0; k < 4; k++)
462  if (capid_votes[k] > capid_votes[favorite_capid])
463  favorite_capid = k;
464  }
465 
466  for (i=digi->begin(); i!=digi->end(); i++) {
467  HcalDetId cell = i->id();
468  DetId detcell=(DetId)cell;
469 
471  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
472  if(tsFromDB_) {
473  firstSample_ = param_ts->firstSample();
474  samplesToAdd_ = param_ts->samplesToAdd();
475  }
476  if(recoParamsFromDB_) {
477  bool correctForTimeslew=param_ts->correctForTimeslew();
479  float phaseNS=param_ts->correctionPhaseNS();
481  correctTiming_ = param_ts->correctTiming();
482  firstAuxTS_ = param_ts->firstAuxTS();
483  int pileupCleaningID = param_ts->pileupCleaningID();
484 
485  /*
486  int sub = cell.subdet();
487  int depth = cell.depth();
488  int inteta = cell.ieta();
489  int intphi = cell.iphi();
490 
491  std::cout << "HcalHitReconstructor::produce cell:"
492  << " sub, ieta, iphi, depth = "
493  << sub << " " << inteta << " " << intphi
494  << " " << depth << std::endl
495  << " first, toadd = " << firstSample_ << ", "
496  << samplesToAdd_ << std::endl
497  << " correctForTimeslew " << correctForTimeslew
498  << std::endl
499  << " correctForPhaseContainment "
500  << correctForPhaseContainment << std::endl
501  << " phaseNS " << phaseNS << std::endl
502  << " useLeakCorrection " << useLeakCorrection_
503  << std::endl
504  << " correctTiming " << correctTiming_ << std::endl
505  << " firstAuxTS " << firstAuxTS_ << std::endl
506  << " pileupCleaningID " << pileupCleaningID
507  << std::endl;
508  */
509 
510  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
511  }
512  }
513 
514  int first = firstSample_;
515  int toadd = samplesToAdd_;
516 
517  // check on cells to be ignored and dropped: (rof,20.Feb.09)
518  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
519  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
521  if (i->zsMarkAndPass()) continue;
522 
523  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
524  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
525  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
526  HcalCoderDb coder (*channelCoder, *shape);
527 
528  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
529 
530  // Fill first auxiliary word
531  unsigned int auxflag=0;
532  int fTS = firstAuxTS_;
533  if (fTS<0) fTS=0; // silly protection against time slice <0
534  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx) {
535  int adcv = i->sample(xx).adc();
536  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
537  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
538  }
539  auxflag+=((i->sample(fTS).capid())<<28);
540  (rec->back()).setAux(auxflag);
541 
542  // Fill second auxiliary word
543  auxflag=0;
544  int fTS2 = (firstAuxTS_-4 < 0) ? 0 : firstAuxTS_-4;
545  for (int xx = fTS2; xx < fTS2+4 && xx<i->size(); ++xx) {
546  int adcv = i->sample(xx).adc();
547  auxflag+=((adcv&0x7F)<<(7*(xx-fTS2)));
548  }
549  auxflag+=((i->sample(fTS2).capid())<<28);
550  (rec->back()).setAuxHBHE(auxflag);
551 
552  (rec->back()).setFlags(0); // this sets all flag bits to 0
553  // Set presample flag
554  if (fTS>0)
555  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
556 
559  if (setNoiseFlags_)
560  hbheFlagSetter_->SetFlagsFromDigi(&(*topo),rec->back(),*i,coder,calibrations,first,toadd);
562  hbhePulseShapeFlagSetter_->SetPulseShapeFlags(rec->back(), *i, coder, calibrations);
563  if (setNegativeFlags_)
564  hbheNegativeFlagSetter_->setPulseShapeFlags(rec->back(), *i, coder, calibrations);
567  if (correctTiming_)
568  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
569  if (setHSCPFlags_ && i->id().ietaAbs()<16)
570  {
571  double DigiEnergy=0;
572  for(int j=0; j!=i->size(); DigiEnergy += i->sample(j++).nominal_fC());
573  if(DigiEnergy > hbheHSCPFlagSetter_->EnergyThreshold())
574  {
575  HBDigis.push_back(*i);
576  RecHitIndex.push_back(rec->size()-1);
577  }
578 
579  } // if (set HSCPFlags_ && |ieta|<16)
580  } // loop over HBHE digis
581 
582 
584  if (setHSCPFlags_) hbheHSCPFlagSetter_->hbheSetTimeFlagsFromDigi(rec.get(), HBDigis, RecHitIndex);
585  // return result
586  e.put(rec);
587 
588  // HO ------------------------------------------------------------------
589  } else if (subdet_==HcalOuter) {
591  e.getByToken(tok_ho_,digi);
592 
593  // create empty output
594  std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
595  rec->reserve(digi->size());
596  // run the algorithm
598 
599  // Vote on majority TS0 CapId
600  int favorite_capid = 0;
601  if (correctTiming_) {
602  long capid_votes[4] = {0,0,0,0};
603  for (i=digi->begin(); i!=digi->end(); i++) {
604  capid_votes[(*i)[0].capid()]++;
605  }
606  for (int k = 0; k < 4; k++)
607  if (capid_votes[k] > capid_votes[favorite_capid])
608  favorite_capid = k;
609  }
610 
611  for (i=digi->begin(); i!=digi->end(); i++) {
612  HcalDetId cell = i->id();
613  DetId detcell=(DetId)cell;
614  // firstSample & samplesToAdd
616  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
617  if(tsFromDB_) {
618  firstSample_ = param_ts->firstSample();
619  samplesToAdd_ = param_ts->samplesToAdd();
620  }
621  if(recoParamsFromDB_) {
622  bool correctForTimeslew=param_ts->correctForTimeslew();
624  float phaseNS=param_ts->correctionPhaseNS();
626  correctTiming_ = param_ts->correctTiming();
627  firstAuxTS_ = param_ts->firstAuxTS();
628  int pileupCleaningID = param_ts->pileupCleaningID();
629  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
630  }
631  }
632 
633  int first = firstSample_;
634  int toadd = samplesToAdd_;
635 
636  // check on cells to be ignored and dropped: (rof,20.Feb.09)
637  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
638  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
640  if (i->zsMarkAndPass()) continue;
641 
642  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
643  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
644  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
645  HcalCoderDb coder (*channelCoder, *shape);
646 
647  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
648 
649  // Set auxiliary flag
650  int auxflag=0;
651  int fTS = firstAuxTS_;
652  if (fTS<0) fTS=0; //silly protection against negative time slice values
653  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
654  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
655  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
656  auxflag+=((i->sample(fTS).capid())<<28);
657  (rec->back()).setAux(auxflag);
658  (rec->back()).setFlags(0);
659  // Fill Presample ADC flag
660  if (fTS>0)
661  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
662 
665  if (correctTiming_)
666  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
667  }
668  // return result
669  e.put(rec);
670 
671  // HF -------------------------------------------------------------------
672  } else if (subdet_==HcalForward) {
674  e.getByToken(tok_hf_,digi);
675 
676 
678  // create empty output
679  std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
680  rec->reserve(digi->size());
681  // run the algorithm
683 
684  // Vote on majority TS0 CapId
685  int favorite_capid = 0;
686  if (correctTiming_) {
687  long capid_votes[4] = {0,0,0,0};
688  for (i=digi->begin(); i!=digi->end(); i++) {
689  capid_votes[(*i)[0].capid()]++;
690  }
691  for (int k = 0; k < 4; k++)
692  if (capid_votes[k] > capid_votes[favorite_capid])
693  favorite_capid = k;
694  }
695 
696  for (i=digi->begin(); i!=digi->end(); i++) {
697  HcalDetId cell = i->id();
698  DetId detcell=(DetId)cell;
699 
701  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
702  if(tsFromDB_) {
703  firstSample_ = param_ts->firstSample();
704  samplesToAdd_ = param_ts->samplesToAdd();
705  }
706  if(recoParamsFromDB_) {
707  bool correctForTimeslew=param_ts->correctForTimeslew();
709  float phaseNS=param_ts->correctionPhaseNS();
711  correctTiming_ = param_ts->correctTiming();
712  firstAuxTS_ = param_ts->firstAuxTS();
713  int pileupCleaningID = param_ts->pileupCleaningID();
714  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
715  }
716  }
717 
718  int first = firstSample_;
719  int toadd = samplesToAdd_;
720 
721  // check on cells to be ignored and dropped: (rof,20.Feb.09)
722  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
723  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
725  if (i->zsMarkAndPass()) continue;
726 
727  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
728  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
729  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
730  HcalCoderDb coder (*channelCoder, *shape);
731 
732  // Set HFDigiTime flag values from digiTimeFromDB_
733  if (digiTimeFromDB_==true && hfdigibit_!=0)
734  {
735  const HcalFlagHFDigiTimeParam* hfDTparam = HFDigiTimeParams->getValues(detcell.rawId());
737  hfDTparam->HFdigiflagSamplesToAdd(),
738  hfDTparam->HFdigiflagExpectedPeak(),
739  hfDTparam->HFdigiflagMinEThreshold(),
740  hfDTparam->HFdigiflagCoefficients()
741  );
742  }
743 
744  //std::cout << "TOADDHF " << toadd << " " << first << " " << std::endl;
745  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
746 
747  // Set auxiliary flag
748  int auxflag=0;
749  int fTS = firstAuxTS_;
750  if (fTS<0) fTS=0; // silly protection against negative time slice values
751  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
752  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
753  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
754  auxflag+=((i->sample(fTS).capid())<<28);
755  (rec->back()).setAux(auxflag);
756 
757  // Clear flags
758  (rec->back()).setFlags(0);
759 
760  // Fill Presample ADC flag
761  if (fTS>0)
762  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
763 
764  // This calls the code for setting the HF noise bit determined from digi shape
765  if (setNoiseFlags_)
766  hfdigibit_->hfSetFlagFromDigi(rec->back(),*i,coder,calibrations);
771  if (correctTiming_)
772  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
773  } // for (i=digi->begin(); i!=digi->end(); i++) -- loop on all HF digis
774 
775  // The following flags require the full set of rechits
776  // These need to be set consecutively, so an energy check should be the first
777  // test performed on these hits (to minimize the loop time)
778  if (setNoiseFlags_)
779  {
780  // Step 1: Set PET flag (short fibers of |ieta|==29)
781  // Neighbor/partner channels that are flagged by Pulse Shape algorithm (HFDigiTime)
782  // won't be considered in these calculations
783  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
784  {
785  int depth=i->id().depth();
786  int ieta=i->id().ieta();
787  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
788  if (depth==2 || abs(ieta)==29 )
789  hfPET_->HFSetFlagFromPET(*i,*rec,myqual,mySeverity);
790  }
791 
792  // Step 2: Set S8S1 flag (short fibers or |ieta|==29)
793  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
794  {
795  int depth=i->id().depth();
796  int ieta=i->id().ieta();
797  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
798  if (depth==2 || abs(ieta)==29 )
799  hfS8S1_->HFSetFlagFromS9S1(*i,*rec,myqual,mySeverity);
800  }
801 
802  // Set 3: Set S9S1 flag (long fibers)
803  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
804  {
805  int depth=i->id().depth();
806  int ieta=i->id().ieta();
807  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
808  if (depth==1 && abs(ieta)!=29 )
809  hfS9S1_->HFSetFlagFromS9S1(*i,*rec,myqual, mySeverity);
810  }
811  }
812 
813  // return result
814  e.put(rec);
815  } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
817  e.getByToken(tok_calib_,digi);
818 
819  // create empty output
820  std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
821  rec->reserve(digi->size());
822  // run the algorithm
823  int first = firstSample_;
824  int toadd = samplesToAdd_;
825 
827  for (i=digi->begin(); i!=digi->end(); i++) {
828  HcalCalibDetId cell = i->id();
829  // HcalDetId cellh = i->id();
830  DetId detcell=(DetId)cell;
831  // check on cells to be ignored and dropped: (rof,20.Feb.09)
832  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
833  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
835  if (i->zsMarkAndPass()) continue;
836 
837  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
838  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
839  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
840  HcalCoderDb coder (*channelCoder, *shape);
841 
842  // firstSample & samplesToAdd
843  if(tsFromDB_) {
844  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
845  first = param_ts->firstSample();
846  toadd = param_ts->samplesToAdd();
847  }
848  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
849 
850  /*
851  // Flag setting not available for calibration rechits
852  // Set auxiliary flag
853  int auxflag=0;
854  int fTS = firstAuxTS_;
855  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
856  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
857  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
858  auxflag+=((i->sample(fTS).capid())<<28);
859  (rec->back()).setAux(auxflag);
860 
861  (rec->back()).setFlags(0); // Not yet implemented for HcalCalibRecHit
862  */
863  }
864  // return result
865  e.put(rec);
866  }
867  }
868  //DL delete myqual;
869 } // 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:462
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:63
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:121
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:93
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
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