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 {
53  // register for data access
54  tok_hbhe_ = consumes<HBHEDigiCollection>(inputLabel_);
55  tok_ho_ = consumes<HODigiCollection>(inputLabel_);
56  tok_hf_ = consumes<HFDigiCollection>(inputLabel_);
57  tok_calib_ = consumes<HcalCalibDigiCollection>(inputLabel_);
58 
59  std::string subd=conf.getParameter<std::string>("Subdetector");
60  //Set all FlagSetters to 0
61  /* Important to do this! Otherwise, if the setters are turned off,
62  the "if (XSetter_) delete XSetter_;" commands can crash
63  */
64 
65  recoParamsFromDB_ = conf.getParameter<bool>("recoParamsFromDB");
66  // recoParamsFromDB_ = false ; // trun off for now.
67 
68  // std::cout<<" HcalHitReconstructor recoParamsFromDB_ "<<recoParamsFromDB_<<std::endl;
69 
70  if (conf.existsAs<bool>("setNegativeFlags"))
71  setNegativeFlags_ = conf.getParameter<bool>("setNegativeFlags");
72 
73  hbheFlagSetter_ = 0;
78  hfdigibit_ = 0;
79 
80  hfS9S1_ = 0;
81  hfS8S1_ = 0;
82  hfPET_ = 0;
85  digiTimeFromDB_ = false; // only need for HF
86 
88  {
89  const edm::ParameterSet& pssat = conf.getParameter<edm::ParameterSet>("saturationParameters");
90  saturationFlagSetter_ = new HcalADCSaturationFlag(pssat.getParameter<int>("maxADCvalue"));
91  }
92 
93  if (!strcasecmp(subd.c_str(),"HBHE")) {
95 
99 
100  bool timingShapedCutsFlags = conf.getParameter<bool>("setTimingShapedCutsFlags");
101  if (timingShapedCutsFlags)
102  {
103  const edm::ParameterSet& psTshaped = conf.getParameter<edm::ParameterSet>("timingshapedcutsParameters");
104  hbheTimingShapedFlagSetter_ = new HBHETimingShapedFlagSetter(psTshaped.getParameter<std::vector<double> >("tfilterEnvelope"),
105  psTshaped.getParameter<bool>("ignorelowest"),
106  psTshaped.getParameter<bool>("ignorehighest"),
107  psTshaped.getParameter<double>("win_offset"),
108  psTshaped.getParameter<double>("win_gain"));
109  }
110 
111  if (setNoiseFlags_)
112  {
113  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("flagParameters");
114  hbheFlagSetter_=new HBHEStatusBitSetter(psdigi.getParameter<double>("nominalPedestal"),
115  psdigi.getParameter<double>("hitEnergyMinimum"),
116  psdigi.getParameter<int>("hitMultiplicityThreshold"),
117  psdigi.getParameter<std::vector<edm::ParameterSet> >("pulseShapeParameterSets")
118  );
119  } // if (setNoiseFlags_)
120  if (setHSCPFlags_)
121  {
122  const edm::ParameterSet& psHSCP = conf.getParameter<edm::ParameterSet>("hscpParameters");
124  psHSCP.getParameter<double>("r1Max"),
125  psHSCP.getParameter<double>("r2Min"),
126  psHSCP.getParameter<double>("r2Max"),
127  psHSCP.getParameter<double>("fracLeaderMin"),
128  psHSCP.getParameter<double>("fracLeaderMax"),
129  psHSCP.getParameter<double>("slopeMin"),
130  psHSCP.getParameter<double>("slopeMax"),
131  psHSCP.getParameter<double>("outerMin"),
132  psHSCP.getParameter<double>("outerMax"),
133  psHSCP.getParameter<double>("TimingEnergyThreshold"));
134  } // if (setHSCPFlags_)
136  {
137  const edm::ParameterSet &psPulseShape = conf.getParameter<edm::ParameterSet>("pulseShapeParameters");
139  psPulseShape.getParameter<double>("MinimumChargeThreshold"),
140  psPulseShape.getParameter<double>("TS4TS5ChargeThreshold"),
141  psPulseShape.getParameter<unsigned int>("TrianglePeakTS"),
142  psPulseShape.getParameter<std::vector<double> >("LinearThreshold"),
143  psPulseShape.getParameter<std::vector<double> >("LinearCut"),
144  psPulseShape.getParameter<std::vector<double> >("RMS8MaxThreshold"),
145  psPulseShape.getParameter<std::vector<double> >("RMS8MaxCut"),
146  psPulseShape.getParameter<std::vector<double> >("LeftSlopeThreshold"),
147  psPulseShape.getParameter<std::vector<double> >("LeftSlopeCut"),
148  psPulseShape.getParameter<std::vector<double> >("RightSlopeThreshold"),
149  psPulseShape.getParameter<std::vector<double> >("RightSlopeCut"),
150  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallThreshold"),
151  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallCut"),
152  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerThreshold"),
153  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerCut"),
154  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperThreshold"),
155  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperCut"),
156  psPulseShape.getParameter<bool>("UseDualFit"),
157  psPulseShape.getParameter<bool>("TriangleIgnoreSlow"));
158  } // if (setPulseShapeFlags_)
159  if (setNegativeFlags_)
160  {
161  const edm::ParameterSet &psNegative = conf.getParameter<edm::ParameterSet>("negativeParameters");
163  psNegative.getParameter<double>("MinimumChargeThreshold"),
164  psNegative.getParameter<double>("TS4TS5ChargeThreshold"),
165  psNegative.getParameter<int>("First"),
166  psNegative.getParameter<int>("Last"),
167  psNegative.getParameter<std::vector<double> >("Threshold"),
168  psNegative.getParameter<std::vector<double> >("Cut"));
169  }
170 
171  produces<HBHERecHitCollection>();
172  } else if (!strcasecmp(subd.c_str(),"HO")) {
176  produces<HORecHitCollection>();
177  } else if (!strcasecmp(subd.c_str(),"HF")) {
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())
254  {
257  }
258 
260  if(puCorrMethod_ == 2) {
262  conf.getParameter<bool> ("applyPedConstraint"),
263  conf.getParameter<bool> ("applyTimeConstraint"),
264  conf.getParameter<bool> ("applyPulseJitter"),
265  conf.getParameter<bool> ("applyUnconstrainedFit"),
266  conf.getParameter<bool> ("applyTimeSlew"),
267  conf.getParameter<double>("ts4Min"),
268  conf.getParameter<double>("ts4Max"),
269  conf.getParameter<double>("pulseJitter"),
270  conf.getParameter<double>("meanTime"),
271  conf.getParameter<double>("timeSigma"),
272  conf.getParameter<double>("meanPed"),
273  conf.getParameter<double>("pedSigma"),
274  conf.getParameter<double>("noise"),
275  conf.getParameter<double>("timeMin"),
276  conf.getParameter<double>("timeMax"),
277  conf.getParameter<double>("ts3chi2"),
278  conf.getParameter<double>("ts4chi2"),
279  conf.getParameter<double>("ts345chi2"),
280  conf.getParameter<double>("chargeMax"), //For the unconstrained Fit
281  conf.getParameter<int> ("fitTimes")
282  );
283  }
284 }
285 
287  delete hbheFlagSetter_;
288  delete hfdigibit_;
289  delete hbheHSCPFlagSetter_;
291  delete hfS9S1_;
292  delete hfPET_;
293  delete paramTS;
294 }
295 
297 
299  es.get<IdealGeometryRecord>().get(htopo);
300 
301  if ( tsFromDB_== true || recoParamsFromDB_ == true )
302  {
304  es.get<HcalRecoParamsRcd>().get(p);
305  paramTS = new HcalRecoParams(*p.product());
306  paramTS->setTopo(htopo.product());
307 
308 
309 
310 
311  // std::cout<<" skdump in HcalHitReconstructor::beginRun dupm RecoParams "<<std::endl;
312  // std::ofstream skfile("skdumpRecoParamsNewFormat.txt");
313  // HcalDbASCIIIO::dumpObject(skfile, (*paramTS) );
314  }
315 
316  if (digiTimeFromDB_==true)
317  {
319  es.get<HcalFlagHFDigiTimeParamsRcd>().get(p);
320  HFDigiTimeParams.reset( new HcalFlagHFDigiTimeParams( *p ) );
321 
323  es.get<IdealGeometryRecord>().get(htopo);
324  HFDigiTimeParams->setTopo(htopo.product());
325 
326  }
327 
328  reco_.beginRun(es);
329 }
330 
332  if (tsFromDB_==true)
333  {
334  delete paramTS; paramTS=0;
335  }
336  if (digiTimeFromDB_==true)
337  {
338  //DL delete HFDigiTimeParams; HFDigiTimeParams = 0;
339  }
340  reco_.endRun();
341 }
342 
344 {
345 
346  // get conditions
348  eventSetup.get<IdealGeometryRecord>().get(topo);
349 
350  edm::ESHandle<HcalDbService> conditions;
351  eventSetup.get<HcalDbRecord>().get(conditions);
352 
353  // HACK related to HB- corrections
354  const bool isData = e.isRealData();
355  if (isData) reco_.setForData(e.run()); else reco_.setForData(0);
357 
359  eventSetup.get<HcalChannelQualityRcd>().get("withTopo",p);
360  const HcalChannelQuality* myqual = p.product();
361 
363  eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
364  const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
365 
366  // Configure OOT pileup corrections
367  bool isMethod1Set = false;
368  const std::string& corrName = isData ? dataOOTCorrectionName_ : mcOOTCorrectionName_;
369  if (!corrName.empty())
370  {
371  edm::ESHandle<OOTPileupCorrectionColl> pileupCorrections;
372  if (eventSetup.find(edm::eventsetup::EventSetupRecordKey::makeKey<HcalOOTPileupCorrectionRcd>()))
373  eventSetup.get<HcalOOTPileupCorrectionRcd>().get(pileupCorrections);
374  else
375  eventSetup.get<HcalOOTPileupCompatibilityRcd>().get(pileupCorrections);
376 
378  if( setPileupCorrection_ ){
379  const OOTPileupCorrData * testMethod1Ptr = dynamic_cast<OOTPileupCorrData*>((pileupCorrections->get(corrName, cat)).get());
380  if( testMethod1Ptr ) isMethod1Set = true;
381  (reco_.*setPileupCorrection_)(pileupCorrections->get(corrName, cat));
382  }
383 
385  (hbheNegativeFlagSetter_->*setPileupCorrectionForNegative_)(pileupCorrections->get(corrName, cat));
386  }
387 // Only for HBHE
388  if( subdet_ == HcalBarrel ){
389  if( !cntprtCorrMethod_ ){
391  if( puCorrMethod_ == 2 ) edm::LogWarning("HcalPUcorrMethod") << "Using Hcal OOTPU method 2" << std::endl;
392  else if( puCorrMethod_ == 1 ){
393  if( isMethod1Set ) edm::LogWarning("HcalPUcorrMethod") << "Using Hcal OOTPU method 1" << std::endl;
394  else edm::LogWarning("HcalPUcorrMethod") <<"puCorrMethod_ set to be 1 but method 1 is NOT activated (method 0 used instead)!\n"
395  <<"Please check GlobalTag usage or method 1 seperately disabled by dataOOTCorrectionName & mcOOTCorrectionName?" << std::endl;
396  }else edm::LogWarning("HcalPUcorrMethod") << "Using Hcal OOTPU method 0" << std::endl;
397  }
398  }
399 
400  // GET THE BEAM CROSSING INFO HERE, WHEN WE UNDERSTAND HOW THINGS WORK.
401  // Then, call "setBXInfo" method of the reco_ object.
402  // Also remember to call SetBXInfo in the negative energy flag setter.
403 
404  if (det_==DetId::Hcal) {
405 
406  // HBHE -------------------------------------------------------------------
409 
410  e.getByToken(tok_hbhe_,digi);
411 
412  // create empty output
413  std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
414  rec->reserve(digi->size());
415  // run the algorithm
418  std::vector<HBHEDataFrame> HBDigis;
419  std::vector<int> RecHitIndex;
420 
421  // Vote on majority TS0 CapId
422  int favorite_capid = 0;
423  if (correctTiming_) {
424  long capid_votes[4] = {0,0,0,0};
425  for (i=digi->begin(); i!=digi->end(); i++) {
426  capid_votes[(*i)[0].capid()]++;
427  }
428  for (int k = 0; k < 4; k++)
429  if (capid_votes[k] > capid_votes[favorite_capid])
430  favorite_capid = k;
431  }
432 
433  for (i=digi->begin(); i!=digi->end(); i++) {
434  HcalDetId cell = i->id();
435  DetId detcell=(DetId)cell;
436 
438  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
439  if(tsFromDB_) {
440  firstSample_ = param_ts->firstSample();
441  samplesToAdd_ = param_ts->samplesToAdd();
442  }
443  if(recoParamsFromDB_) {
444  bool correctForTimeslew=param_ts->correctForTimeslew();
445  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
446  float phaseNS=param_ts->correctionPhaseNS();
448  correctTiming_ = param_ts->correctTiming();
449  firstAuxTS_ = param_ts->firstAuxTS();
450  int pileupCleaningID = param_ts->pileupCleaningID();
451 
452  /*
453  int sub = cell.subdet();
454  int depth = cell.depth();
455  int inteta = cell.ieta();
456  int intphi = cell.iphi();
457 
458  std::cout << "HcalHitReconstructor::produce cell:"
459  << " sub, ieta, iphi, depth = "
460  << sub << " " << inteta << " " << intphi
461  << " " << depth << std::endl
462  << " first, toadd = " << firstSample_ << ", "
463  << samplesToAdd_ << std::endl
464  << " correctForTimeslew " << correctForTimeslew
465  << std::endl
466  << " correctForPhaseContainment "
467  << correctForPhaseContainment << std::endl
468  << " phaseNS " << phaseNS << std::endl
469  << " useLeakCorrection " << useLeakCorrection_
470  << std::endl
471  << " correctTiming " << correctTiming_ << std::endl
472  << " firstAuxTS " << firstAuxTS_ << std::endl
473  << " pileupCleaningID " << pileupCleaningID
474  << std::endl;
475  */
476 
477  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
478  }
479  }
480 
481  int first = firstSample_;
482  int toadd = samplesToAdd_;
483 
484  // check on cells to be ignored and dropped: (rof,20.Feb.09)
485  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
486  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
488  if (i->zsMarkAndPass()) continue;
489 
490  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
491  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
492  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
493  HcalCoderDb coder (*channelCoder, *shape);
494 
495  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
496 
497  // Fill first auxiliary word
498  unsigned int auxflag=0;
499  int fTS = firstAuxTS_;
500  if (fTS<0) fTS=0; // silly protection against time slice <0
501  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx) {
502  int adcv = i->sample(xx).adc();
503  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
504  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
505  }
506  auxflag+=((i->sample(fTS).capid())<<28);
507  (rec->back()).setAux(auxflag);
508 
509  // Fill second auxiliary word
510  auxflag=0;
511  int fTS2 = (firstAuxTS_-4 < 0) ? 0 : firstAuxTS_-4;
512  for (int xx = fTS2; xx < fTS2+4 && xx<i->size(); ++xx) {
513  int adcv = i->sample(xx).adc();
514  auxflag+=((adcv&0x7F)<<(7*(xx-fTS2)));
515  }
516  auxflag+=((i->sample(fTS2).capid())<<28);
517  (rec->back()).setAuxHBHE(auxflag);
518 
519  (rec->back()).setFlags(0); // this sets all flag bits to 0
520  // Set presample flag
521  if (fTS>0)
522  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
523 
526  if (setNoiseFlags_)
527  hbheFlagSetter_->SetFlagsFromDigi(&(*topo),rec->back(),*i,coder,calibrations,first,toadd);
528  if (setPulseShapeFlags_ == true)
529  hbhePulseShapeFlagSetter_->SetPulseShapeFlags(rec->back(), *i, coder, calibrations);
530  if (setNegativeFlags_ == true)
531  hbheNegativeFlagSetter_->setPulseShapeFlags(rec->back(), *i, coder, calibrations);
534  if (correctTiming_)
535  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
536  if (setHSCPFlags_ && i->id().ietaAbs()<16)
537  {
538  double DigiEnergy=0;
539  for(int j=0; j!=i->size(); DigiEnergy += i->sample(j++).nominal_fC());
540  if(DigiEnergy > hbheHSCPFlagSetter_->EnergyThreshold())
541  {
542  HBDigis.push_back(*i);
543  RecHitIndex.push_back(rec->size()-1);
544  }
545 
546  } // if (set HSCPFlags_ && |ieta|<16)
547  } // loop over HBHE digis
548 
549 
551  if (setHSCPFlags_) hbheHSCPFlagSetter_->hbheSetTimeFlagsFromDigi(rec.get(), HBDigis, RecHitIndex);
552  // return result
553  e.put(rec);
554 
555  // HO ------------------------------------------------------------------
556  } else if (subdet_==HcalOuter) {
558  e.getByToken(tok_ho_,digi);
559 
560  // create empty output
561  std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
562  rec->reserve(digi->size());
563  // run the algorithm
565 
566  // Vote on majority TS0 CapId
567  int favorite_capid = 0;
568  if (correctTiming_) {
569  long capid_votes[4] = {0,0,0,0};
570  for (i=digi->begin(); i!=digi->end(); i++) {
571  capid_votes[(*i)[0].capid()]++;
572  }
573  for (int k = 0; k < 4; k++)
574  if (capid_votes[k] > capid_votes[favorite_capid])
575  favorite_capid = k;
576  }
577 
578  for (i=digi->begin(); i!=digi->end(); i++) {
579  HcalDetId cell = i->id();
580  DetId detcell=(DetId)cell;
581  // firstSample & samplesToAdd
583  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
584  if(tsFromDB_) {
585  firstSample_ = param_ts->firstSample();
586  samplesToAdd_ = param_ts->samplesToAdd();
587  }
588  if(recoParamsFromDB_) {
589  bool correctForTimeslew=param_ts->correctForTimeslew();
590  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
591  float phaseNS=param_ts->correctionPhaseNS();
593  correctTiming_ = param_ts->correctTiming();
594  firstAuxTS_ = param_ts->firstAuxTS();
595  int pileupCleaningID = param_ts->pileupCleaningID();
596  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
597  }
598  }
599 
600  int first = firstSample_;
601  int toadd = samplesToAdd_;
602 
603  // check on cells to be ignored and dropped: (rof,20.Feb.09)
604  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
605  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
607  if (i->zsMarkAndPass()) continue;
608 
609  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
610  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
611  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
612  HcalCoderDb coder (*channelCoder, *shape);
613 
614  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
615 
616  // Set auxiliary flag
617  int auxflag=0;
618  int fTS = firstAuxTS_;
619  if (fTS<0) fTS=0; //silly protection against negative time slice values
620  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
621  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
622  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
623  auxflag+=((i->sample(fTS).capid())<<28);
624  (rec->back()).setAux(auxflag);
625 
626  (rec->back()).setFlags(0);
627  // Fill Presample ADC flag
628  if (fTS>0)
629  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
630 
633  if (correctTiming_)
634  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
635  }
636  // return result
637  e.put(rec);
638 
639  // HF -------------------------------------------------------------------
640  } else if (subdet_==HcalForward) {
642  e.getByToken(tok_hf_,digi);
643 
644 
646  // create empty output
647  std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
648  rec->reserve(digi->size());
649  // run the algorithm
651 
652  // Vote on majority TS0 CapId
653  int favorite_capid = 0;
654  if (correctTiming_) {
655  long capid_votes[4] = {0,0,0,0};
656  for (i=digi->begin(); i!=digi->end(); i++) {
657  capid_votes[(*i)[0].capid()]++;
658  }
659  for (int k = 0; k < 4; k++)
660  if (capid_votes[k] > capid_votes[favorite_capid])
661  favorite_capid = k;
662  }
663 
664  for (i=digi->begin(); i!=digi->end(); i++) {
665  HcalDetId cell = i->id();
666  DetId detcell=(DetId)cell;
667 
669  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
670  if(tsFromDB_) {
671  firstSample_ = param_ts->firstSample();
672  samplesToAdd_ = param_ts->samplesToAdd();
673  }
674  if(recoParamsFromDB_) {
675  bool correctForTimeslew=param_ts->correctForTimeslew();
676  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
677  float phaseNS=param_ts->correctionPhaseNS();
679  correctTiming_ = param_ts->correctTiming();
680  firstAuxTS_ = param_ts->firstAuxTS();
681  int pileupCleaningID = param_ts->pileupCleaningID();
682  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
683  }
684  }
685 
686  int first = firstSample_;
687  int toadd = samplesToAdd_;
688 
689  // check on cells to be ignored and dropped: (rof,20.Feb.09)
690  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
691  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
693  if (i->zsMarkAndPass()) continue;
694 
695  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
696  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
697  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
698  HcalCoderDb coder (*channelCoder, *shape);
699 
700  // Set HFDigiTime flag values from digiTimeFromDB_
701  if (digiTimeFromDB_==true && hfdigibit_!=0)
702  {
703  const HcalFlagHFDigiTimeParam* hfDTparam = HFDigiTimeParams->getValues(detcell.rawId());
705  hfDTparam->HFdigiflagSamplesToAdd(),
706  hfDTparam->HFdigiflagExpectedPeak(),
707  hfDTparam->HFdigiflagMinEThreshold(),
708  hfDTparam->HFdigiflagCoefficients()
709  );
710  }
711 
712  //std::cout << "TOADDHF " << toadd << " " << first << " " << std::endl;
713  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
714 
715  // Set auxiliary flag
716  int auxflag=0;
717  int fTS = firstAuxTS_;
718  if (fTS<0) fTS=0; // silly protection against negative time slice values
719  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
720  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
721  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
722  auxflag+=((i->sample(fTS).capid())<<28);
723  (rec->back()).setAux(auxflag);
724 
725  // Clear flags
726  (rec->back()).setFlags(0);
727 
728  // Fill Presample ADC flag
729  if (fTS>0)
730  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
731 
732  // This calls the code for setting the HF noise bit determined from digi shape
733  if (setNoiseFlags_)
734  hfdigibit_->hfSetFlagFromDigi(rec->back(),*i,coder,calibrations);
739  if (correctTiming_)
740  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
741  } // for (i=digi->begin(); i!=digi->end(); i++) -- loop on all HF digis
742 
743  // The following flags require the full set of rechits
744  // These need to be set consecutively, so an energy check should be the first
745  // test performed on these hits (to minimize the loop time)
746  if (setNoiseFlags_)
747  {
748  // Step 1: Set PET flag (short fibers of |ieta|==29)
749  // Neighbor/partner channels that are flagged by Pulse Shape algorithm (HFDigiTime)
750  // won't be considered in these calculations
751  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
752  {
753  int depth=i->id().depth();
754  int ieta=i->id().ieta();
755  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
756  if (depth==2 || abs(ieta)==29 )
757  hfPET_->HFSetFlagFromPET(*i,*rec,myqual,mySeverity);
758  }
759 
760  // Step 2: Set S8S1 flag (short fibers or |ieta|==29)
761  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
762  {
763  int depth=i->id().depth();
764  int ieta=i->id().ieta();
765  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
766  if (depth==2 || abs(ieta)==29 )
767  hfS8S1_->HFSetFlagFromS9S1(*i,*rec,myqual,mySeverity);
768  }
769 
770  // Set 3: Set S9S1 flag (long fibers)
771  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
772  {
773  int depth=i->id().depth();
774  int ieta=i->id().ieta();
775  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
776  if (depth==1 && abs(ieta)!=29 )
777  hfS9S1_->HFSetFlagFromS9S1(*i,*rec,myqual, mySeverity);
778  }
779  }
780 
781  // return result
782  e.put(rec);
783  } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
785  e.getByToken(tok_calib_,digi);
786 
787  // create empty output
788  std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
789  rec->reserve(digi->size());
790  // run the algorithm
791  int first = firstSample_;
792  int toadd = samplesToAdd_;
793 
795  for (i=digi->begin(); i!=digi->end(); i++) {
796  HcalCalibDetId cell = i->id();
797  // HcalDetId cellh = i->id();
798  DetId detcell=(DetId)cell;
799  // check on cells to be ignored and dropped: (rof,20.Feb.09)
800  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
801  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
803  if (i->zsMarkAndPass()) continue;
804 
805  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
806  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
807  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
808  HcalCoderDb coder (*channelCoder, *shape);
809 
810  // firstSample & samplesToAdd
811  if(tsFromDB_) {
812  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
813  first = param_ts->firstSample();
814  toadd = param_ts->samplesToAdd();
815  }
816  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
817 
818  /*
819  // Flag setting not available for calibration rechits
820  // Set auxiliary flag
821  int auxflag=0;
822  int fTS = firstAuxTS_;
823  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
824  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
825  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
826  auxflag+=((i->sample(fTS).capid())<<28);
827  (rec->back()).setAux(auxflag);
828 
829  (rec->back()).setFlags(0); // Not yet implemented for HcalCalibRecHit
830  */
831  }
832  // return result
833  e.put(rec);
834  }
835  }
836  //DL delete myqual;
837 } // 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:184
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:446
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:60
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
bool first
Definition: L1TdeRCT.cc:75
edm::EDGetTokenT< HODigiCollection > tok_ho_
HcalHitReconstructor(const edm::ParameterSet &ps)
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