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"
18 #include <iostream>
19 #include <fstream>
20 
21 
22 /* Hcal Hit reconstructor allows for CaloRecHits with status words */
23 
25  reco_(conf.getParameter<bool>("correctForTimeslew"),
26  conf.getParameter<bool>("correctForPhaseContainment"),
27  conf.getParameter<double>("correctionPhaseNS")),
28  det_(DetId::Hcal),
29  inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
30  correctTiming_(conf.getParameter<bool>("correctTiming")),
31  setNoiseFlags_(conf.getParameter<bool>("setNoiseFlags")),
32  setHSCPFlags_(conf.getParameter<bool>("setHSCPFlags")),
33  setSaturationFlags_(conf.getParameter<bool>("setSaturationFlags")),
34  setTimingTrustFlags_(conf.getParameter<bool>("setTimingTrustFlags")),
35  setPulseShapeFlags_(conf.getParameter<bool>("setPulseShapeFlags")),
36  setNegativeFlags_(false),
37  dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
38  firstAuxTS_(conf.getParameter<int>("firstAuxTS")),
39  firstSample_(conf.getParameter<int>("firstSample")),
40  samplesToAdd_(conf.getParameter<int>("samplesToAdd")),
41  tsFromDB_(conf.getParameter<bool>("tsFromDB")),
42  useLeakCorrection_(conf.getParameter<bool>("useLeakCorrection")),
43  dataOOTCorrectionName_(""),
44  dataOOTCorrectionCategory_("Data"),
45  mcOOTCorrectionName_(""),
46  mcOOTCorrectionCategory_("MC"),
47  setPileupCorrection_(0),
48  setPileupCorrectionForNegative_(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 
101 
102  bool timingShapedCutsFlags = conf.getParameter<bool>("setTimingShapedCutsFlags");
103  if (timingShapedCutsFlags)
104  {
105  const edm::ParameterSet& psTshaped = conf.getParameter<edm::ParameterSet>("timingshapedcutsParameters");
106  hbheTimingShapedFlagSetter_ = new HBHETimingShapedFlagSetter(psTshaped.getParameter<std::vector<double> >("tfilterEnvelope"),
107  psTshaped.getParameter<bool>("ignorelowest"),
108  psTshaped.getParameter<bool>("ignorehighest"),
109  psTshaped.getParameter<double>("win_offset"),
110  psTshaped.getParameter<double>("win_gain"));
111  }
112 
113  if (setNoiseFlags_)
114  {
115  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("flagParameters");
116  hbheFlagSetter_=new HBHEStatusBitSetter(psdigi.getParameter<double>("nominalPedestal"),
117  psdigi.getParameter<double>("hitEnergyMinimum"),
118  psdigi.getParameter<int>("hitMultiplicityThreshold"),
119  psdigi.getParameter<std::vector<edm::ParameterSet> >("pulseShapeParameterSets")
120  );
121  } // if (setNoiseFlags_)
122  if (setHSCPFlags_)
123  {
124  const edm::ParameterSet& psHSCP = conf.getParameter<edm::ParameterSet>("hscpParameters");
126  psHSCP.getParameter<double>("r1Max"),
127  psHSCP.getParameter<double>("r2Min"),
128  psHSCP.getParameter<double>("r2Max"),
129  psHSCP.getParameter<double>("fracLeaderMin"),
130  psHSCP.getParameter<double>("fracLeaderMax"),
131  psHSCP.getParameter<double>("slopeMin"),
132  psHSCP.getParameter<double>("slopeMax"),
133  psHSCP.getParameter<double>("outerMin"),
134  psHSCP.getParameter<double>("outerMax"),
135  psHSCP.getParameter<double>("TimingEnergyThreshold"));
136  } // if (setHSCPFlags_)
138  {
139  const edm::ParameterSet &psPulseShape = conf.getParameter<edm::ParameterSet>("pulseShapeParameters");
141  psPulseShape.getParameter<double>("MinimumChargeThreshold"),
142  psPulseShape.getParameter<double>("TS4TS5ChargeThreshold"),
143  psPulseShape.getParameter<unsigned int>("TrianglePeakTS"),
144  psPulseShape.getParameter<std::vector<double> >("LinearThreshold"),
145  psPulseShape.getParameter<std::vector<double> >("LinearCut"),
146  psPulseShape.getParameter<std::vector<double> >("RMS8MaxThreshold"),
147  psPulseShape.getParameter<std::vector<double> >("RMS8MaxCut"),
148  psPulseShape.getParameter<std::vector<double> >("LeftSlopeThreshold"),
149  psPulseShape.getParameter<std::vector<double> >("LeftSlopeCut"),
150  psPulseShape.getParameter<std::vector<double> >("RightSlopeThreshold"),
151  psPulseShape.getParameter<std::vector<double> >("RightSlopeCut"),
152  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallThreshold"),
153  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallCut"),
154  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerThreshold"),
155  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerCut"),
156  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperThreshold"),
157  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperCut"),
158  psPulseShape.getParameter<bool>("UseDualFit"),
159  psPulseShape.getParameter<bool>("TriangleIgnoreSlow"));
160  } // if (setPulseShapeFlags_)
161  if (setNegativeFlags_)
162  {
163  const edm::ParameterSet &psNegative = conf.getParameter<edm::ParameterSet>("negativeParameters");
165  psNegative.getParameter<double>("MinimumChargeThreshold"),
166  psNegative.getParameter<double>("TS4TS5ChargeThreshold"),
167  psNegative.getParameter<int>("First"),
168  psNegative.getParameter<int>("Last"),
169  psNegative.getParameter<std::vector<double> >("Threshold"),
170  psNegative.getParameter<std::vector<double> >("Cut"));
171  }
172 
173  produces<HBHERecHitCollection>();
174  } else if (!strcasecmp(subd.c_str(),"HO")) {
178  produces<HORecHitCollection>();
179  } else if (!strcasecmp(subd.c_str(),"HF")) {
183  digiTimeFromDB_=conf.getParameter<bool>("digiTimeFromDB");
184 
185  if (setTimingTrustFlags_) {
186 
187  const edm::ParameterSet& pstrust = conf.getParameter<edm::ParameterSet>("hfTimingTrustParameters");
188  HFTimingTrustFlagSetter_=new HFTimingTrustFlag(pstrust.getParameter<int>("hfTimingTrustLevel1"),
189  pstrust.getParameter<int>("hfTimingTrustLevel2"));
190  }
191 
192  if (setNoiseFlags_)
193  {
194  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("digistat");
195  const edm::ParameterSet& psTimeWin =conf.getParameter<edm::ParameterSet>("HFInWindowStat");
196  hfdigibit_=new HcalHFStatusBitFromDigis(psdigi,psTimeWin);
197 
198  const edm::ParameterSet& psS9S1 = conf.getParameter<edm::ParameterSet>("S9S1stat");
199  hfS9S1_ = new HcalHF_S9S1algorithm(psS9S1.getParameter<std::vector<double> >("short_optimumSlope"),
200  psS9S1.getParameter<std::vector<double> >("shortEnergyParams"),
201  psS9S1.getParameter<std::vector<double> >("shortETParams"),
202  psS9S1.getParameter<std::vector<double> >("long_optimumSlope"),
203  psS9S1.getParameter<std::vector<double> >("longEnergyParams"),
204  psS9S1.getParameter<std::vector<double> >("longETParams"),
205  psS9S1.getParameter<int>("HcalAcceptSeverityLevel"),
206  psS9S1.getParameter<bool>("isS8S1")
207  );
208 
209  const edm::ParameterSet& psS8S1 = conf.getParameter<edm::ParameterSet>("S8S1stat");
210  hfS8S1_ = new HcalHF_S9S1algorithm(psS8S1.getParameter<std::vector<double> >("short_optimumSlope"),
211  psS8S1.getParameter<std::vector<double> >("shortEnergyParams"),
212  psS8S1.getParameter<std::vector<double> >("shortETParams"),
213  psS8S1.getParameter<std::vector<double> >("long_optimumSlope"),
214  psS8S1.getParameter<std::vector<double> >("longEnergyParams"),
215  psS8S1.getParameter<std::vector<double> >("longETParams"),
216  psS8S1.getParameter<int>("HcalAcceptSeverityLevel"),
217  psS8S1.getParameter<bool>("isS8S1")
218  );
219 
220  const edm::ParameterSet& psPET = conf.getParameter<edm::ParameterSet>("PETstat");
221  hfPET_ = new HcalHF_PETalgorithm(psPET.getParameter<std::vector<double> >("short_R"),
222  psPET.getParameter<std::vector<double> >("shortEnergyParams"),
223  psPET.getParameter<std::vector<double> >("shortETParams"),
224  psPET.getParameter<std::vector<double> >("long_R"),
225  psPET.getParameter<std::vector<double> >("longEnergyParams"),
226  psPET.getParameter<std::vector<double> >("longETParams"),
227  psPET.getParameter<int>("HcalAcceptSeverityLevel"),
228  psPET.getParameter<std::vector<double> >("short_R_29"),
229  psPET.getParameter<std::vector<double> >("long_R_29")
230  );
231  }
232  produces<HFRecHitCollection>();
233  } else if (!strcasecmp(subd.c_str(),"ZDC")) {
236  produces<ZDCRecHitCollection>();
237  } else if (!strcasecmp(subd.c_str(),"CALIB")) {
240  produces<HcalCalibRecHitCollection>();
241  } else {
242  edm::LogWarning("Configuration") << "HcalHitReconstructor is not associated with a specific subdetector!" << std::endl;
243  }
244 
245  // If no valid OOT pileup correction name specified,
246  // disable the correction
247  if (conf.existsAs<std::string>("dataOOTCorrectionName"))
248  dataOOTCorrectionName_ = conf.getParameter<std::string>("dataOOTCorrectionName");
249  if (conf.existsAs<std::string>("dataOOTCorrectionCategory"))
250  dataOOTCorrectionCategory_ = conf.getParameter<std::string>("dataOOTCorrectionCategory");
251  if (conf.existsAs<std::string>("mcOOTCorrectionName"))
252  mcOOTCorrectionName_ = conf.getParameter<std::string>("mcOOTCorrectionName");
253  if (conf.existsAs<std::string>("mcOOTCorrectionCategory"))
254  mcOOTCorrectionCategory_ = conf.getParameter<std::string>("mcOOTCorrectionCategory");
255  if (dataOOTCorrectionName_.empty() && mcOOTCorrectionName_.empty())
256  {
259  }
260 
262  if(puCorrMethod_ == 2) {
264  conf.getParameter<bool> ("applyPedConstraint"),
265  conf.getParameter<bool> ("applyTimeConstraint"),
266  conf.getParameter<bool> ("applyPulseJitter"),
267  conf.getParameter<bool> ("applyUnconstrainedFit"),
268  conf.getParameter<bool> ("applyTimeSlew"),
269  conf.getParameter<double>("ts4Min"),
270  conf.getParameter<double>("ts4Max"),
271  conf.getParameter<double>("pulseJitter"),
272  conf.getParameter<double>("meanTime"),
273  conf.getParameter<double>("timeSigma"),
274  conf.getParameter<double>("meanPed"),
275  conf.getParameter<double>("pedSigma"),
276  conf.getParameter<double>("noise"),
277  conf.getParameter<double>("timeMin"),
278  conf.getParameter<double>("timeMax"),
279  conf.getParameter<double>("ts3chi2"),
280  conf.getParameter<double>("ts4chi2"),
281  conf.getParameter<double>("ts345chi2"),
282  conf.getParameter<double>("chargeMax"), //For the unconstrained Fit
283  conf.getParameter<int> ("fitTimes")
284  );
285  }
286 }
287 
289  delete hbheFlagSetter_;
290  delete hfdigibit_;
291  delete hbheHSCPFlagSetter_;
293  delete hfS9S1_;
294  delete hfPET_;
295  delete paramTS;
296 }
297 
299 
301  es.get<IdealGeometryRecord>().get(htopo);
302 
303  if ( tsFromDB_== true || recoParamsFromDB_ == true )
304  {
306  es.get<HcalRecoParamsRcd>().get(p);
307  paramTS = new HcalRecoParams(*p.product());
308  paramTS->setTopo(htopo.product());
309 
310 
311 
312 
313  // std::cout<<" skdump in HcalHitReconstructor::beginRun dupm RecoParams "<<std::endl;
314  // std::ofstream skfile("skdumpRecoParamsNewFormat.txt");
315  // HcalDbASCIIIO::dumpObject(skfile, (*paramTS) );
316  }
317 
318  if (digiTimeFromDB_==true)
319  {
321  es.get<HcalFlagHFDigiTimeParamsRcd>().get(p);
322  HFDigiTimeParams.reset( new HcalFlagHFDigiTimeParams( *p ) );
323 
325  es.get<IdealGeometryRecord>().get(htopo);
326  HFDigiTimeParams->setTopo(htopo.product());
327 
328  }
329 
330  reco_.beginRun(es);
331 }
332 
334  if (tsFromDB_==true)
335  {
336  delete paramTS; paramTS=0;
337  }
338  if (digiTimeFromDB_==true)
339  {
340  //DL delete HFDigiTimeParams; HFDigiTimeParams = 0;
341  }
342  reco_.endRun();
343 }
344 
346 {
347 
348  // get conditions
350  eventSetup.get<IdealGeometryRecord>().get(topo);
351 
352  edm::ESHandle<HcalDbService> conditions;
353  eventSetup.get<HcalDbRecord>().get(conditions);
354 
355  // HACK related to HB- corrections
356  if ( first_ ) {
357  const bool isData = e.isRealData();
358  if (isData) reco_.setForData(e.run()); else reco_.setForData(0);
361  first_=false;
362  }
364 
366  eventSetup.get<HcalChannelQualityRcd>().get("withTopo",p);
367  const HcalChannelQuality* myqual = p.product();
368 
370  eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
371  const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
372 
373  // Configure OOT pileup corrections
374  bool isMethod1Set = false;
375  if (!corrName_.empty())
376  {
377  edm::ESHandle<OOTPileupCorrectionColl> pileupCorrections;
378  if (eventSetup.find(edm::eventsetup::EventSetupRecordKey::makeKey<HcalOOTPileupCorrectionRcd>()))
379  eventSetup.get<HcalOOTPileupCorrectionRcd>().get(pileupCorrections);
380  else
381  eventSetup.get<HcalOOTPileupCompatibilityRcd>().get(pileupCorrections);
382 
383  if( setPileupCorrection_ ){
384  const OOTPileupCorrData * testMethod1Ptr = dynamic_cast<OOTPileupCorrData*>((pileupCorrections->get(corrName_, cat_)).get());
385  if( testMethod1Ptr ) isMethod1Set = true;
386  (reco_.*setPileupCorrection_)(pileupCorrections->get(corrName_, cat_));
387  }
388 
391  }
392 // Only for HBHE
393  if( subdet_ == HcalBarrel ){
394  if( !cntprtCorrMethod_ ){
396  if( puCorrMethod_ == 2 ) LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 2" << std::endl;
397  else if( puCorrMethod_ == 1 ){
398  if( isMethod1Set ) LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 1" << std::endl;
399  else edm::LogWarning("HcalPUcorrMethod") <<"puCorrMethod_ set to be 1 but method 1 is NOT activated (method 0 used instead)!\n"
400  <<"Please check GlobalTag usage or method 1 seperately disabled by dataOOTCorrectionName & mcOOTCorrectionName?" << std::endl;
401  }else if (puCorrMethod_ == 3) {
402  LogTrace("HcalPUcorrMethod") << "Using Hcal Deterministic Fit Method!" << std::endl;
403  } else LogTrace("HcalPUcorrMethod") << "Using Hcal OOTPU method 0" << std::endl;
404  }
405  }
406 
407  // GET THE BEAM CROSSING INFO HERE, WHEN WE UNDERSTAND HOW THINGS WORK.
408  // Then, call "setBXInfo" method of the reco_ object.
409  // Also remember to call SetBXInfo in the negative energy flag setter.
410 
411  if (det_==DetId::Hcal) {
412 
413  // HBHE -------------------------------------------------------------------
416 
417  e.getByToken(tok_hbhe_,digi);
418 
419  // create empty output
420  std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
421  rec->reserve(digi->size());
422  // run the algorithm
425  std::vector<HBHEDataFrame> HBDigis;
426  std::vector<int> RecHitIndex;
427 
428  // Vote on majority TS0 CapId
429  int favorite_capid = 0;
430  if (correctTiming_) {
431  long capid_votes[4] = {0,0,0,0};
432  for (i=digi->begin(); i!=digi->end(); i++) {
433  capid_votes[(*i)[0].capid()]++;
434  }
435  for (int k = 0; k < 4; k++)
436  if (capid_votes[k] > capid_votes[favorite_capid])
437  favorite_capid = k;
438  }
439 
440  for (i=digi->begin(); i!=digi->end(); i++) {
441  HcalDetId cell = i->id();
442  DetId detcell=(DetId)cell;
443 
445  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
446  if(tsFromDB_) {
447  firstSample_ = param_ts->firstSample();
448  samplesToAdd_ = param_ts->samplesToAdd();
449  }
450  if(recoParamsFromDB_) {
451  bool correctForTimeslew=param_ts->correctForTimeslew();
453  float phaseNS=param_ts->correctionPhaseNS();
455  correctTiming_ = param_ts->correctTiming();
456  firstAuxTS_ = param_ts->firstAuxTS();
457  int pileupCleaningID = param_ts->pileupCleaningID();
458 
459  /*
460  int sub = cell.subdet();
461  int depth = cell.depth();
462  int inteta = cell.ieta();
463  int intphi = cell.iphi();
464 
465  std::cout << "HcalHitReconstructor::produce cell:"
466  << " sub, ieta, iphi, depth = "
467  << sub << " " << inteta << " " << intphi
468  << " " << depth << std::endl
469  << " first, toadd = " << firstSample_ << ", "
470  << samplesToAdd_ << std::endl
471  << " correctForTimeslew " << correctForTimeslew
472  << std::endl
473  << " correctForPhaseContainment "
474  << correctForPhaseContainment << std::endl
475  << " phaseNS " << phaseNS << std::endl
476  << " useLeakCorrection " << useLeakCorrection_
477  << std::endl
478  << " correctTiming " << correctTiming_ << std::endl
479  << " firstAuxTS " << firstAuxTS_ << std::endl
480  << " pileupCleaningID " << pileupCleaningID
481  << std::endl;
482  */
483 
484  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
485  }
486  }
487 
488  int first = firstSample_;
489  int toadd = samplesToAdd_;
490 
491  // check on cells to be ignored and dropped: (rof,20.Feb.09)
492  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
493  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
495  if (i->zsMarkAndPass()) continue;
496 
497  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
498  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
499  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
500  HcalCoderDb coder (*channelCoder, *shape);
501 
502  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
503 
504  // Fill first auxiliary word
505  unsigned int auxflag=0;
506  int fTS = firstAuxTS_;
507  if (fTS<0) fTS=0; // silly protection against time slice <0
508  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx) {
509  int adcv = i->sample(xx).adc();
510  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
511  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
512  }
513  auxflag+=((i->sample(fTS).capid())<<28);
514  (rec->back()).setAux(auxflag);
515 
516  // Fill second auxiliary word
517  auxflag=0;
518  int fTS2 = (firstAuxTS_-4 < 0) ? 0 : firstAuxTS_-4;
519  for (int xx = fTS2; xx < fTS2+4 && xx<i->size(); ++xx) {
520  int adcv = i->sample(xx).adc();
521  auxflag+=((adcv&0x7F)<<(7*(xx-fTS2)));
522  }
523  auxflag+=((i->sample(fTS2).capid())<<28);
524  (rec->back()).setAuxHBHE(auxflag);
525 
526  (rec->back()).setFlags(0); // this sets all flag bits to 0
527  // Set presample flag
528  if (fTS>0)
529  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
530 
533  if (setNoiseFlags_)
534  hbheFlagSetter_->SetFlagsFromDigi(&(*topo),rec->back(),*i,coder,calibrations,first,toadd);
535  if (setPulseShapeFlags_ == true)
536  hbhePulseShapeFlagSetter_->SetPulseShapeFlags(rec->back(), *i, coder, calibrations);
537  if (setNegativeFlags_ == true)
538  hbheNegativeFlagSetter_->setPulseShapeFlags(rec->back(), *i, coder, calibrations);
541  if (correctTiming_)
542  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
543  if (setHSCPFlags_ && i->id().ietaAbs()<16)
544  {
545  double DigiEnergy=0;
546  for(int j=0; j!=i->size(); DigiEnergy += i->sample(j++).nominal_fC());
547  if(DigiEnergy > hbheHSCPFlagSetter_->EnergyThreshold())
548  {
549  HBDigis.push_back(*i);
550  RecHitIndex.push_back(rec->size()-1);
551  }
552 
553  } // if (set HSCPFlags_ && |ieta|<16)
554  } // loop over HBHE digis
555 
556 
558  if (setHSCPFlags_) hbheHSCPFlagSetter_->hbheSetTimeFlagsFromDigi(rec.get(), HBDigis, RecHitIndex);
559  // return result
560  e.put(rec);
561 
562  // HO ------------------------------------------------------------------
563  } else if (subdet_==HcalOuter) {
565  e.getByToken(tok_ho_,digi);
566 
567  // create empty output
568  std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
569  rec->reserve(digi->size());
570  // run the algorithm
572 
573  // Vote on majority TS0 CapId
574  int favorite_capid = 0;
575  if (correctTiming_) {
576  long capid_votes[4] = {0,0,0,0};
577  for (i=digi->begin(); i!=digi->end(); i++) {
578  capid_votes[(*i)[0].capid()]++;
579  }
580  for (int k = 0; k < 4; k++)
581  if (capid_votes[k] > capid_votes[favorite_capid])
582  favorite_capid = k;
583  }
584 
585  for (i=digi->begin(); i!=digi->end(); i++) {
586  HcalDetId cell = i->id();
587  DetId detcell=(DetId)cell;
588  // firstSample & samplesToAdd
590  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
591  if(tsFromDB_) {
592  firstSample_ = param_ts->firstSample();
593  samplesToAdd_ = param_ts->samplesToAdd();
594  }
595  if(recoParamsFromDB_) {
596  bool correctForTimeslew=param_ts->correctForTimeslew();
598  float phaseNS=param_ts->correctionPhaseNS();
600  correctTiming_ = param_ts->correctTiming();
601  firstAuxTS_ = param_ts->firstAuxTS();
602  int pileupCleaningID = param_ts->pileupCleaningID();
603  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
604  }
605  }
606 
607  int first = firstSample_;
608  int toadd = samplesToAdd_;
609 
610  // check on cells to be ignored and dropped: (rof,20.Feb.09)
611  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
612  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
614  if (i->zsMarkAndPass()) continue;
615 
616  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
617  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
618  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
619  HcalCoderDb coder (*channelCoder, *shape);
620 
621  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
622 
623  // Set auxiliary flag
624  int auxflag=0;
625  int fTS = firstAuxTS_;
626  if (fTS<0) fTS=0; //silly protection against negative time slice values
627  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
628  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
629  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
630  auxflag+=((i->sample(fTS).capid())<<28);
631  (rec->back()).setAux(auxflag);
632  (rec->back()).setFlags(0);
633  // Fill Presample ADC flag
634  if (fTS>0)
635  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
636 
639  if (correctTiming_)
640  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
641  }
642  // return result
643  e.put(rec);
644 
645  // HF -------------------------------------------------------------------
646  } else if (subdet_==HcalForward) {
648  e.getByToken(tok_hf_,digi);
649 
650 
652  // create empty output
653  std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
654  rec->reserve(digi->size());
655  // run the algorithm
657 
658  // Vote on majority TS0 CapId
659  int favorite_capid = 0;
660  if (correctTiming_) {
661  long capid_votes[4] = {0,0,0,0};
662  for (i=digi->begin(); i!=digi->end(); i++) {
663  capid_votes[(*i)[0].capid()]++;
664  }
665  for (int k = 0; k < 4; k++)
666  if (capid_votes[k] > capid_votes[favorite_capid])
667  favorite_capid = k;
668  }
669 
670  for (i=digi->begin(); i!=digi->end(); i++) {
671  HcalDetId cell = i->id();
672  DetId detcell=(DetId)cell;
673 
675  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
676  if(tsFromDB_) {
677  firstSample_ = param_ts->firstSample();
678  samplesToAdd_ = param_ts->samplesToAdd();
679  }
680  if(recoParamsFromDB_) {
681  bool correctForTimeslew=param_ts->correctForTimeslew();
683  float phaseNS=param_ts->correctionPhaseNS();
685  correctTiming_ = param_ts->correctTiming();
686  firstAuxTS_ = param_ts->firstAuxTS();
687  int pileupCleaningID = param_ts->pileupCleaningID();
688  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
689  }
690  }
691 
692  int first = firstSample_;
693  int toadd = samplesToAdd_;
694 
695  // check on cells to be ignored and dropped: (rof,20.Feb.09)
696  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
697  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
699  if (i->zsMarkAndPass()) continue;
700 
701  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
702  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
703  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
704  HcalCoderDb coder (*channelCoder, *shape);
705 
706  // Set HFDigiTime flag values from digiTimeFromDB_
707  if (digiTimeFromDB_==true && hfdigibit_!=0)
708  {
709  const HcalFlagHFDigiTimeParam* hfDTparam = HFDigiTimeParams->getValues(detcell.rawId());
711  hfDTparam->HFdigiflagSamplesToAdd(),
712  hfDTparam->HFdigiflagExpectedPeak(),
713  hfDTparam->HFdigiflagMinEThreshold(),
714  hfDTparam->HFdigiflagCoefficients()
715  );
716  }
717 
718  //std::cout << "TOADDHF " << toadd << " " << first << " " << std::endl;
719  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
720 
721  // Set auxiliary flag
722  int auxflag=0;
723  int fTS = firstAuxTS_;
724  if (fTS<0) fTS=0; // silly protection against negative time slice values
725  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
726  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
727  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
728  auxflag+=((i->sample(fTS).capid())<<28);
729  (rec->back()).setAux(auxflag);
730 
731  // Clear flags
732  (rec->back()).setFlags(0);
733 
734  // Fill Presample ADC flag
735  if (fTS>0)
736  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
737 
738  // This calls the code for setting the HF noise bit determined from digi shape
739  if (setNoiseFlags_)
740  hfdigibit_->hfSetFlagFromDigi(rec->back(),*i,coder,calibrations);
745  if (correctTiming_)
746  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
747  } // for (i=digi->begin(); i!=digi->end(); i++) -- loop on all HF digis
748 
749  // The following flags require the full set of rechits
750  // These need to be set consecutively, so an energy check should be the first
751  // test performed on these hits (to minimize the loop time)
752  if (setNoiseFlags_)
753  {
754  // Step 1: Set PET flag (short fibers of |ieta|==29)
755  // Neighbor/partner channels that are flagged by Pulse Shape algorithm (HFDigiTime)
756  // won't be considered in these calculations
757  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
758  {
759  int depth=i->id().depth();
760  int ieta=i->id().ieta();
761  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
762  if (depth==2 || abs(ieta)==29 )
763  hfPET_->HFSetFlagFromPET(*i,*rec,myqual,mySeverity);
764  }
765 
766  // Step 2: Set S8S1 flag (short fibers or |ieta|==29)
767  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
768  {
769  int depth=i->id().depth();
770  int ieta=i->id().ieta();
771  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
772  if (depth==2 || abs(ieta)==29 )
773  hfS8S1_->HFSetFlagFromS9S1(*i,*rec,myqual,mySeverity);
774  }
775 
776  // Set 3: Set S9S1 flag (long fibers)
777  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
778  {
779  int depth=i->id().depth();
780  int ieta=i->id().ieta();
781  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
782  if (depth==1 && abs(ieta)!=29 )
783  hfS9S1_->HFSetFlagFromS9S1(*i,*rec,myqual, mySeverity);
784  }
785  }
786 
787  // return result
788  e.put(rec);
789  } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
791  e.getByToken(tok_calib_,digi);
792 
793  // create empty output
794  std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
795  rec->reserve(digi->size());
796  // run the algorithm
797  int first = firstSample_;
798  int toadd = samplesToAdd_;
799 
801  for (i=digi->begin(); i!=digi->end(); i++) {
802  HcalCalibDetId cell = i->id();
803  // HcalDetId cellh = i->id();
804  DetId detcell=(DetId)cell;
805  // check on cells to be ignored and dropped: (rof,20.Feb.09)
806  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
807  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
809  if (i->zsMarkAndPass()) continue;
810 
811  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
812  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
813  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
814  HcalCoderDb coder (*channelCoder, *shape);
815 
816  // firstSample & samplesToAdd
817  if(tsFromDB_) {
818  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
819  first = param_ts->firstSample();
820  toadd = param_ts->samplesToAdd();
821  }
822  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
823 
824  /*
825  // Flag setting not available for calibration rechits
826  // Set auxiliary flag
827  int auxflag=0;
828  int fTS = firstAuxTS_;
829  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
830  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
831  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
832  auxflag+=((i->sample(fTS).capid())<<28);
833  (rec->back()).setAux(auxflag);
834 
835  (rec->back()).setFlags(0); // Not yet implemented for HcalCalibRecHit
836  */
837  }
838  // return result
839  e.put(rec);
840  }
841  }
842  //DL delete myqual;
843 } // void HcalHitReconstructor::produce(...)
unsigned int firstSample() const
Definition: HcalRecoParam.h:32
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void HFSetFlagFromS9S1(HFRecHit &hf, HFRecHitCollection &rec, const HcalChannelQuality *myqual, const HcalSeverityLevelComputer *mySeverity)
HBHERecHit reconstruct(const HBHEDataFrame &digi, int first, int toadd, const HcalCoder &coder, const HcalCalibrations &calibs) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
edm::EDGetTokenT< HBHEDigiCollection > tok_hbhe_
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:449
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
SetCorrectionFcnForNegative setPileupCorrectionForNegative_
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:113
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:85
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)
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
std::vector< HFRecHit >::iterator iterator
void setHBHEPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
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
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