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"
17 #include <iostream>
18 #include <fstream>
19 
20 
21 /* Hcal Hit reconstructor allows for CaloRecHits with status words */
22 
24  reco_(conf.getParameter<bool>("correctForTimeslew"),
25  conf.getParameter<bool>("correctForPhaseContainment"),
26  conf.getParameter<double>("correctionPhaseNS")),
27  det_(DetId::Hcal),
28  inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
29  correctTiming_(conf.getParameter<bool>("correctTiming")),
30  setNoiseFlags_(conf.getParameter<bool>("setNoiseFlags")),
31  setHSCPFlags_(conf.getParameter<bool>("setHSCPFlags")),
32  setSaturationFlags_(conf.getParameter<bool>("setSaturationFlags")),
33  setTimingTrustFlags_(conf.getParameter<bool>("setTimingTrustFlags")),
34  setPulseShapeFlags_(conf.getParameter<bool>("setPulseShapeFlags")),
35  dropZSmarkedPassed_(conf.getParameter<bool>("dropZSmarkedPassed")),
36  firstAuxTS_(conf.getParameter<int>("firstAuxTS")),
37  firstSample_(conf.getParameter<int>("firstSample")),
38  samplesToAdd_(conf.getParameter<int>("samplesToAdd")),
39  tsFromDB_(conf.getParameter<bool>("tsFromDB")),
40  useLeakCorrection_(conf.getParameter<bool>("useLeakCorrection")),
41  dataOOTCorrectionName_(""),
42  dataOOTCorrectionCategory_("Data"),
43  mcOOTCorrectionName_(""),
44  mcOOTCorrectionCategory_("MC"),
45  setPileupCorrection_(0),
46  paramTS(0),
47  theTopology(0)
48 {
49  // register for data access
50  tok_hbhe_ = consumes<HBHEDigiCollection>(inputLabel_);
51  tok_ho_ = consumes<HODigiCollection>(inputLabel_);
52  tok_hf_ = consumes<HFDigiCollection>(inputLabel_);
53  tok_calib_ = consumes<HcalCalibDigiCollection>(inputLabel_);
54 
55  std::string subd=conf.getParameter<std::string>("Subdetector");
56  //Set all FlagSetters to 0
57  /* Important to do this! Otherwise, if the setters are turned off,
58  the "if (XSetter_) delete XSetter_;" commands can crash
59  */
60 
61  recoParamsFromDB_ = conf.getParameter<bool>("recoParamsFromDB");
62  // recoParamsFromDB_ = false ; // trun off for now.
63 
64  // std::cout<<" HcalHitReconstructor recoParamsFromDB_ "<<recoParamsFromDB_<<std::endl;
65 
66  hbheFlagSetter_ = 0;
70  hfdigibit_ = 0;
71 
72  hfS9S1_ = 0;
73  hfS8S1_ = 0;
74  hfPET_ = 0;
77  digiTimeFromDB_ = false; // only need for HF
78 
80  {
81  const edm::ParameterSet& pssat = conf.getParameter<edm::ParameterSet>("saturationParameters");
82  saturationFlagSetter_ = new HcalADCSaturationFlag(pssat.getParameter<int>("maxADCvalue"));
83  }
84 
85  if (!strcasecmp(subd.c_str(),"HBHE")) {
88  bool timingShapedCutsFlags = conf.getParameter<bool>("setTimingShapedCutsFlags");
89  if (timingShapedCutsFlags)
90  {
91  const edm::ParameterSet& psTshaped = conf.getParameter<edm::ParameterSet>("timingshapedcutsParameters");
92  hbheTimingShapedFlagSetter_ = new HBHETimingShapedFlagSetter(psTshaped.getParameter<std::vector<double> >("tfilterEnvelope"),
93  psTshaped.getParameter<bool>("ignorelowest"),
94  psTshaped.getParameter<bool>("ignorehighest"),
95  psTshaped.getParameter<double>("win_offset"),
96  psTshaped.getParameter<double>("win_gain"));
97  }
98 
99  if (setNoiseFlags_)
100  {
101  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("flagParameters");
102  hbheFlagSetter_=new HBHEStatusBitSetter(psdigi.getParameter<double>("nominalPedestal"),
103  psdigi.getParameter<double>("hitEnergyMinimum"),
104  psdigi.getParameter<int>("hitMultiplicityThreshold"),
105  psdigi.getParameter<std::vector<edm::ParameterSet> >("pulseShapeParameterSets")
106  );
107  } // if (setNoiseFlags_)
108  if (setHSCPFlags_)
109  {
110  const edm::ParameterSet& psHSCP = conf.getParameter<edm::ParameterSet>("hscpParameters");
112  psHSCP.getParameter<double>("r1Max"),
113  psHSCP.getParameter<double>("r2Min"),
114  psHSCP.getParameter<double>("r2Max"),
115  psHSCP.getParameter<double>("fracLeaderMin"),
116  psHSCP.getParameter<double>("fracLeaderMax"),
117  psHSCP.getParameter<double>("slopeMin"),
118  psHSCP.getParameter<double>("slopeMax"),
119  psHSCP.getParameter<double>("outerMin"),
120  psHSCP.getParameter<double>("outerMax"),
121  psHSCP.getParameter<double>("TimingEnergyThreshold"));
122  } // if (setHSCPFlags_)
124  {
125  const edm::ParameterSet &psPulseShape = conf.getParameter<edm::ParameterSet>("pulseShapeParameters");
127  psPulseShape.getParameter<double>("MinimumChargeThreshold"),
128  psPulseShape.getParameter<double>("TS4TS5ChargeThreshold"),
129  psPulseShape.getParameter<unsigned int>("TrianglePeakTS"),
130  psPulseShape.getParameter<std::vector<double> >("LinearThreshold"),
131  psPulseShape.getParameter<std::vector<double> >("LinearCut"),
132  psPulseShape.getParameter<std::vector<double> >("RMS8MaxThreshold"),
133  psPulseShape.getParameter<std::vector<double> >("RMS8MaxCut"),
134  psPulseShape.getParameter<std::vector<double> >("LeftSlopeThreshold"),
135  psPulseShape.getParameter<std::vector<double> >("LeftSlopeCut"),
136  psPulseShape.getParameter<std::vector<double> >("RightSlopeThreshold"),
137  psPulseShape.getParameter<std::vector<double> >("RightSlopeCut"),
138  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallThreshold"),
139  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallCut"),
140  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerThreshold"),
141  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerCut"),
142  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperThreshold"),
143  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperCut"),
144  psPulseShape.getParameter<bool>("UseDualFit"),
145  psPulseShape.getParameter<bool>("TriangleIgnoreSlow"));
146  } // if (setPulseShapeFlags_)
147 
148  produces<HBHERecHitCollection>();
149  } else if (!strcasecmp(subd.c_str(),"HO")) {
152  produces<HORecHitCollection>();
153  } else if (!strcasecmp(subd.c_str(),"HF")) {
156  digiTimeFromDB_=conf.getParameter<bool>("digiTimeFromDB");
157 
158  if (setTimingTrustFlags_) {
159 
160  const edm::ParameterSet& pstrust = conf.getParameter<edm::ParameterSet>("hfTimingTrustParameters");
161  HFTimingTrustFlagSetter_=new HFTimingTrustFlag(pstrust.getParameter<int>("hfTimingTrustLevel1"),
162  pstrust.getParameter<int>("hfTimingTrustLevel2"));
163  }
164 
165  if (setNoiseFlags_)
166  {
167  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("digistat");
168  const edm::ParameterSet& psTimeWin =conf.getParameter<edm::ParameterSet>("HFInWindowStat");
169  hfdigibit_=new HcalHFStatusBitFromDigis(psdigi,psTimeWin);
170 
171  const edm::ParameterSet& psS9S1 = conf.getParameter<edm::ParameterSet>("S9S1stat");
172  hfS9S1_ = new HcalHF_S9S1algorithm(psS9S1.getParameter<std::vector<double> >("short_optimumSlope"),
173  psS9S1.getParameter<std::vector<double> >("shortEnergyParams"),
174  psS9S1.getParameter<std::vector<double> >("shortETParams"),
175  psS9S1.getParameter<std::vector<double> >("long_optimumSlope"),
176  psS9S1.getParameter<std::vector<double> >("longEnergyParams"),
177  psS9S1.getParameter<std::vector<double> >("longETParams"),
178  psS9S1.getParameter<int>("HcalAcceptSeverityLevel"),
179  psS9S1.getParameter<bool>("isS8S1")
180  );
181 
182  const edm::ParameterSet& psS8S1 = conf.getParameter<edm::ParameterSet>("S8S1stat");
183  hfS8S1_ = new HcalHF_S9S1algorithm(psS8S1.getParameter<std::vector<double> >("short_optimumSlope"),
184  psS8S1.getParameter<std::vector<double> >("shortEnergyParams"),
185  psS8S1.getParameter<std::vector<double> >("shortETParams"),
186  psS8S1.getParameter<std::vector<double> >("long_optimumSlope"),
187  psS8S1.getParameter<std::vector<double> >("longEnergyParams"),
188  psS8S1.getParameter<std::vector<double> >("longETParams"),
189  psS8S1.getParameter<int>("HcalAcceptSeverityLevel"),
190  psS8S1.getParameter<bool>("isS8S1")
191  );
192 
193  const edm::ParameterSet& psPET = conf.getParameter<edm::ParameterSet>("PETstat");
194  hfPET_ = new HcalHF_PETalgorithm(psPET.getParameter<std::vector<double> >("short_R"),
195  psPET.getParameter<std::vector<double> >("shortEnergyParams"),
196  psPET.getParameter<std::vector<double> >("shortETParams"),
197  psPET.getParameter<std::vector<double> >("long_R"),
198  psPET.getParameter<std::vector<double> >("longEnergyParams"),
199  psPET.getParameter<std::vector<double> >("longETParams"),
200  psPET.getParameter<int>("HcalAcceptSeverityLevel"),
201  psPET.getParameter<std::vector<double> >("short_R_29"),
202  psPET.getParameter<std::vector<double> >("long_R_29")
203  );
204  }
205  produces<HFRecHitCollection>();
206  } else if (!strcasecmp(subd.c_str(),"ZDC")) {
209  produces<ZDCRecHitCollection>();
210  } else if (!strcasecmp(subd.c_str(),"CALIB")) {
213  produces<HcalCalibRecHitCollection>();
214  } else {
215  std::cout << "HcalHitReconstructor is not associated with a specific subdetector!" << std::endl;
216  }
217 
218  // If no valid OOT pileup correction name specified,
219  // disable the correction
220  if (conf.existsAs<std::string>("dataOOTCorrectionName"))
221  dataOOTCorrectionName_ = conf.getParameter<std::string>("dataOOTCorrectionName");
222  if (conf.existsAs<std::string>("dataOOTCorrectionCategory"))
223  dataOOTCorrectionCategory_ = conf.getParameter<std::string>("dataOOTCorrectionCategory");
224  if (conf.existsAs<std::string>("mcOOTCorrectionName"))
225  mcOOTCorrectionName_ = conf.getParameter<std::string>("mcOOTCorrectionName");
226  if (conf.existsAs<std::string>("mcOOTCorrectionCategory"))
227  mcOOTCorrectionCategory_ = conf.getParameter<std::string>("mcOOTCorrectionCategory");
228  if (dataOOTCorrectionName_.empty() && mcOOTCorrectionName_.empty())
230 }
231 
233  delete hbheFlagSetter_;
234  delete hfdigibit_;
235  delete hbheHSCPFlagSetter_;
237  delete hfS9S1_;
238  delete hfPET_;
239  delete theTopology;
240  delete paramTS;
241 }
242 
244 
245  if ( tsFromDB_== true || recoParamsFromDB_ == true )
246  {
248  es.get<HcalRecoParamsRcd>().get(p);
249  paramTS = new HcalRecoParams(*p.product());
250 
252  es.get<IdealGeometryRecord>().get(htopo);
253  theTopology=new HcalTopology(*htopo);
255 
256 
257 
258  // std::cout<<" skdump in HcalHitReconstructor::beginRun dupm RecoParams "<<std::endl;
259  // std::ofstream skfile("skdumpRecoParamsNewFormat.txt");
260  // HcalDbASCIIIO::dumpObject(skfile, (*paramTS) );
261  }
262 
263  if (digiTimeFromDB_==true)
264  {
266  es.get<HcalFlagHFDigiTimeParamsRcd>().get(p);
268 
269  if (theTopology==0) {
271  es.get<IdealGeometryRecord>().get(htopo);
272  theTopology=new HcalTopology(*htopo);
273  }
275 
276  }
277  reco_.beginRun(es);
278 }
279 
281  if (tsFromDB_==true)
282  {
283  delete paramTS; paramTS=0;
284  }
285  if (digiTimeFromDB_==true)
286  {
287  //DL delete HFDigiTimeParams; HFDigiTimeParams = 0;
288  }
289  reco_.endRun();
290 }
291 
293 {
294 
295  // get conditions
297  eventSetup.get<IdealGeometryRecord>().get(topo);
298 
299  edm::ESHandle<HcalDbService> conditions;
300  eventSetup.get<HcalDbRecord>().get(conditions);
301 
302  // HACK related to HB- corrections
303  const bool isData = e.isRealData();
304  if (isData) reco_.setForData(e.run());
306 
308  eventSetup.get<HcalChannelQualityRcd>().get(p);
309  //DLHcalChannelQuality* myqual = new HcalChannelQuality(*p.product());
310  const HcalChannelQuality* myqual = p.product();
311  if (!myqual->topo()) myqual->setTopo(topo.product());
312 
313 
315  eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
316  const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
317 
318  // Configure OOT pileup corrections
320  {
321  const std::string& corrName = isData ? dataOOTCorrectionName_ : mcOOTCorrectionName_;
322  if (!corrName.empty())
323  {
324  edm::ESHandle<OOTPileupCorrectionColl> pileupCorrections;
325  eventSetup.get<HcalOOTPileupCorrectionRcd>().get(pileupCorrections);
327  (reco_.*setPileupCorrection_)(pileupCorrections->get(corrName, cat));
328  }
329  }
330 
331  // GET THE BEAM CROSSING INFO HERE, WHEN WE UNDERSTAND HOW THINGS WORK.
332  // Then, call "setBXInfo" method of the reco_ object.
333 
334  if (det_==DetId::Hcal) {
335 
336  // HBHE -------------------------------------------------------------------
339 
340  e.getByToken(tok_hbhe_,digi);
341 
342  // create empty output
343  std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
344  rec->reserve(digi->size());
345  // run the algorithm
348  std::vector<HBHEDataFrame> HBDigis;
349  std::vector<int> RecHitIndex;
350 
351  // Vote on majority TS0 CapId
352  int favorite_capid = 0;
353  if (correctTiming_) {
354  long capid_votes[4] = {0,0,0,0};
355  for (i=digi->begin(); i!=digi->end(); i++) {
356  capid_votes[(*i)[0].capid()]++;
357  }
358  for (int k = 0; k < 4; k++)
359  if (capid_votes[k] > capid_votes[favorite_capid])
360  favorite_capid = k;
361  }
362 
363  for (i=digi->begin(); i!=digi->end(); i++) {
364  HcalDetId cell = i->id();
365  DetId detcell=(DetId)cell;
366 
368  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
369  if(tsFromDB_) {
370  firstSample_ = param_ts->firstSample();
371  samplesToAdd_ = param_ts->samplesToAdd();
372  }
373  if(recoParamsFromDB_) {
374  bool correctForTimeslew=param_ts->correctForTimeslew();
375  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
376  float phaseNS=param_ts->correctionPhaseNS();
378  correctTiming_ = param_ts->correctTiming();
379  firstAuxTS_ = param_ts->firstAuxTS();
380  int pileupCleaningID = param_ts->pileupCleaningID();
381 
382  /*
383  int sub = cell.subdet();
384  int depth = cell.depth();
385  int inteta = cell.ieta();
386  int intphi = cell.iphi();
387 
388  std::cout << "HcalHitReconstructor::produce cell:"
389  << " sub, ieta, iphi, depth = "
390  << sub << " " << inteta << " " << intphi
391  << " " << depth << std::endl
392  << " first, toadd = " << firstSample_ << ", "
393  << samplesToAdd_ << std::endl
394  << " correctForTimeslew " << correctForTimeslew
395  << std::endl
396  << " correctForPhaseContainment "
397  << correctForPhaseContainment << std::endl
398  << " phaseNS " << phaseNS << std::endl
399  << " useLeakCorrection " << useLeakCorrection_
400  << std::endl
401  << " correctTiming " << correctTiming_ << std::endl
402  << " firstAuxTS " << firstAuxTS_ << std::endl
403  << " pileupCleaningID " << pileupCleaningID
404  << std::endl;
405  */
406 
407  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
408  }
409  }
410 
411  int first = firstSample_;
412  int toadd = samplesToAdd_;
413 
414  // check on cells to be ignored and dropped: (rof,20.Feb.09)
415  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
416  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
418  if (i->zsMarkAndPass()) continue;
419 
420  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
421  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
422  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
423  HcalCoderDb coder (*channelCoder, *shape);
424 
425  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
426 
427  // Fill first auxiliary word
428  unsigned int auxflag=0;
429  int fTS = firstAuxTS_;
430  if (fTS<0) fTS=0; // silly protection against time slice <0
431  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx) {
432  int adcv = i->sample(xx).adc();
433  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
434  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
435  }
436  auxflag+=((i->sample(fTS).capid())<<28);
437  (rec->back()).setAux(auxflag);
438 
439  // Fill second auxiliary word
440  auxflag=0;
441  int fTS2 = (firstAuxTS_-4 < 0) ? 0 : firstAuxTS_-4;
442  for (int xx = fTS2; xx < fTS2+4 && xx<i->size(); ++xx) {
443  int adcv = i->sample(xx).adc();
444  auxflag+=((adcv&0x7F)<<(7*(xx-fTS2)));
445  }
446  auxflag+=((i->sample(fTS2).capid())<<28);
447  (rec->back()).setAuxHBHE(auxflag);
448 
449  (rec->back()).setFlags(0); // this sets all flag bits to 0
450  // Set presample flag
451  if (fTS>0)
452  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
453 
456  if (setNoiseFlags_)
457  hbheFlagSetter_->SetFlagsFromDigi(&(*topo),rec->back(),*i,coder,calibrations,first,toadd);
458  if (setPulseShapeFlags_ == true)
459  hbhePulseShapeFlagSetter_->SetPulseShapeFlags(rec->back(), *i, coder, calibrations);
462  if (correctTiming_)
463  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
464  if (setHSCPFlags_ && i->id().ietaAbs()<16)
465  {
466  double DigiEnergy=0;
467  for(int j=0; j!=i->size(); DigiEnergy += i->sample(j++).nominal_fC());
468  if(DigiEnergy > hbheHSCPFlagSetter_->EnergyThreshold())
469  {
470  HBDigis.push_back(*i);
471  RecHitIndex.push_back(rec->size()-1);
472  }
473 
474  } // if (set HSCPFlags_ && |ieta|<16)
475  } // loop over HBHE digis
476 
477 
479  if (setHSCPFlags_) hbheHSCPFlagSetter_->hbheSetTimeFlagsFromDigi(rec.get(), HBDigis, RecHitIndex);
480  // return result
481  e.put(rec);
482 
483  // HO ------------------------------------------------------------------
484  } else if (subdet_==HcalOuter) {
486  e.getByToken(tok_ho_,digi);
487 
488  // create empty output
489  std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
490  rec->reserve(digi->size());
491  // run the algorithm
493 
494  // Vote on majority TS0 CapId
495  int favorite_capid = 0;
496  if (correctTiming_) {
497  long capid_votes[4] = {0,0,0,0};
498  for (i=digi->begin(); i!=digi->end(); i++) {
499  capid_votes[(*i)[0].capid()]++;
500  }
501  for (int k = 0; k < 4; k++)
502  if (capid_votes[k] > capid_votes[favorite_capid])
503  favorite_capid = k;
504  }
505 
506  for (i=digi->begin(); i!=digi->end(); i++) {
507  HcalDetId cell = i->id();
508  DetId detcell=(DetId)cell;
509  // firstSample & samplesToAdd
511  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
512  if(tsFromDB_) {
513  firstSample_ = param_ts->firstSample();
514  samplesToAdd_ = param_ts->samplesToAdd();
515  }
516  if(recoParamsFromDB_) {
517  bool correctForTimeslew=param_ts->correctForTimeslew();
518  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
519  float phaseNS=param_ts->correctionPhaseNS();
521  correctTiming_ = param_ts->correctTiming();
522  firstAuxTS_ = param_ts->firstAuxTS();
523  int pileupCleaningID = param_ts->pileupCleaningID();
524  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
525  }
526  }
527 
528  int first = firstSample_;
529  int toadd = samplesToAdd_;
530 
531  // check on cells to be ignored and dropped: (rof,20.Feb.09)
532  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
533  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
535  if (i->zsMarkAndPass()) continue;
536 
537  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
538  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
539  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
540  HcalCoderDb coder (*channelCoder, *shape);
541 
542  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
543 
544  // Set auxiliary flag
545  int auxflag=0;
546  int fTS = firstAuxTS_;
547  if (fTS<0) fTS=0; //silly protection against negative time slice values
548  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
549  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
550  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
551  auxflag+=((i->sample(fTS).capid())<<28);
552  (rec->back()).setAux(auxflag);
553 
554  (rec->back()).setFlags(0);
555  // Fill Presample ADC flag
556  if (fTS>0)
557  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
558 
561  if (correctTiming_)
562  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
563  }
564  // return result
565  e.put(rec);
566 
567  // HF -------------------------------------------------------------------
568  } else if (subdet_==HcalForward) {
570  e.getByToken(tok_hf_,digi);
571 
572 
574  // create empty output
575  std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
576  rec->reserve(digi->size());
577  // run the algorithm
579 
580  // Vote on majority TS0 CapId
581  int favorite_capid = 0;
582  if (correctTiming_) {
583  long capid_votes[4] = {0,0,0,0};
584  for (i=digi->begin(); i!=digi->end(); i++) {
585  capid_votes[(*i)[0].capid()]++;
586  }
587  for (int k = 0; k < 4; k++)
588  if (capid_votes[k] > capid_votes[favorite_capid])
589  favorite_capid = k;
590  }
591 
592  for (i=digi->begin(); i!=digi->end(); i++) {
593  HcalDetId cell = i->id();
594  DetId detcell=(DetId)cell;
595 
597  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
598  if(tsFromDB_) {
599  firstSample_ = param_ts->firstSample();
600  samplesToAdd_ = param_ts->samplesToAdd();
601  }
602  if(recoParamsFromDB_) {
603  bool correctForTimeslew=param_ts->correctForTimeslew();
604  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
605  float phaseNS=param_ts->correctionPhaseNS();
607  correctTiming_ = param_ts->correctTiming();
608  firstAuxTS_ = param_ts->firstAuxTS();
609  int pileupCleaningID = param_ts->pileupCleaningID();
610  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
611  }
612  }
613 
614  int first = firstSample_;
615  int toadd = samplesToAdd_;
616 
617  // check on cells to be ignored and dropped: (rof,20.Feb.09)
618  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
619  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
621  if (i->zsMarkAndPass()) continue;
622 
623  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
624  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
625  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
626  HcalCoderDb coder (*channelCoder, *shape);
627 
628  // Set HFDigiTime flag values from digiTimeFromDB_
629  if (digiTimeFromDB_==true && hfdigibit_!=0)
630  {
631  const HcalFlagHFDigiTimeParam* hfDTparam = HFDigiTimeParams->getValues(detcell.rawId());
633  hfDTparam->HFdigiflagSamplesToAdd(),
634  hfDTparam->HFdigiflagExpectedPeak(),
635  hfDTparam->HFdigiflagMinEThreshold(),
636  hfDTparam->HFdigiflagCoefficients()
637  );
638  }
639 
640  //std::cout << "TOADDHF " << toadd << " " << first << " " << std::endl;
641  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
642 
643  // Set auxiliary flag
644  int auxflag=0;
645  int fTS = firstAuxTS_;
646  if (fTS<0) fTS=0; // silly protection against negative time slice values
647  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
648  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
649  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
650  auxflag+=((i->sample(fTS).capid())<<28);
651  (rec->back()).setAux(auxflag);
652 
653  // Clear flags
654  (rec->back()).setFlags(0);
655 
656  // Fill Presample ADC flag
657  if (fTS>0)
658  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
659 
660  // This calls the code for setting the HF noise bit determined from digi shape
661  if (setNoiseFlags_)
662  hfdigibit_->hfSetFlagFromDigi(rec->back(),*i,coder,calibrations);
667  if (correctTiming_)
668  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
669  } // for (i=digi->begin(); i!=digi->end(); i++) -- loop on all HF digis
670 
671  // The following flags require the full set of rechits
672  // These need to be set consecutively, so an energy check should be the first
673  // test performed on these hits (to minimize the loop time)
674  if (setNoiseFlags_)
675  {
676  // Step 1: Set PET flag (short fibers of |ieta|==29)
677  // Neighbor/partner channels that are flagged by Pulse Shape algorithm (HFDigiTime)
678  // won't be considered in these calculations
679  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
680  {
681  int depth=i->id().depth();
682  int ieta=i->id().ieta();
683  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
684  if (depth==2 || abs(ieta)==29 )
685  hfPET_->HFSetFlagFromPET(*i,*rec,myqual,mySeverity);
686  }
687 
688  // Step 2: Set S8S1 flag (short fibers or |ieta|==29)
689  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
690  {
691  int depth=i->id().depth();
692  int ieta=i->id().ieta();
693  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
694  if (depth==2 || abs(ieta)==29 )
695  hfS8S1_->HFSetFlagFromS9S1(*i,*rec,myqual,mySeverity);
696  }
697 
698  // Set 3: Set S9S1 flag (long fibers)
699  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
700  {
701  int depth=i->id().depth();
702  int ieta=i->id().ieta();
703  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
704  if (depth==1 && abs(ieta)!=29 )
705  hfS9S1_->HFSetFlagFromS9S1(*i,*rec,myqual, mySeverity);
706  }
707  }
708 
709  // return result
710  e.put(rec);
711  } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
713  e.getByToken(tok_calib_,digi);
714 
715  // create empty output
716  std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
717  rec->reserve(digi->size());
718  // run the algorithm
719  int first = firstSample_;
720  int toadd = samplesToAdd_;
721 
723  for (i=digi->begin(); i!=digi->end(); i++) {
724  HcalCalibDetId cell = i->id();
725  // HcalDetId cellh = i->id();
726  DetId detcell=(DetId)cell;
727  // check on cells to be ignored and dropped: (rof,20.Feb.09)
728  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
729  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
731  if (i->zsMarkAndPass()) continue;
732 
733  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
734  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
735  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder);
736  HcalCoderDb coder (*channelCoder, *shape);
737 
738  // firstSample & samplesToAdd
739  if(tsFromDB_) {
740  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
741  first = param_ts->firstSample();
742  toadd = param_ts->samplesToAdd();
743  }
744  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
745 
746  /*
747  // Flag setting not available for calibration rechits
748  // Set auxiliary flag
749  int auxflag=0;
750  int fTS = firstAuxTS_;
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  (rec->back()).setFlags(0); // Not yet implemented for HcalCalibRecHit
758  */
759  }
760  // return result
761  e.put(rec);
762  }
763  }
764  //DL delete myqual;
765 } // 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:434
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)
void setTopo(const HcalTopology *topo) const
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:60
SetCorrectionFcn setPileupCorrection_
void HFSetFlagFromPET(HFRecHit &hf, HFRecHitCollection &rec, const HcalChannelQuality *myqual, const HcalSeverityLevelComputer *mySeverity)
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:116
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:88
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_
virtual void produce(edm::Event &e, const edm::EventSetup &c)
HcalHitReconstructor(const edm::ParameterSet &ps)
float correctionPhaseNS() const
Definition: HcalRecoParam.h:31
tuple conf
Definition: dbtoconf.py:185
std::vector< HFRecHit >::iterator iterator
int k[5][pyjets_maxn]
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:62
std::string dataOOTCorrectionName_
HBHEStatusBitSetter * hbheFlagSetter_
HBHETimeProfileStatusBitSetter * hbheHSCPFlagSetter_
HBHETimingShapedFlagSetter * hbheTimingShapedFlagSetter_
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)
tuple cout
Definition: gather_cfg.py:121
unsigned int firstAuxTS() const
Definition: HcalRecoParam.h:41
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 setHFPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
const HcalFlagHFDigiTimeParams * HFDigiTimeParams
Definition: Run.h:41
const HcalTopology * topo() const
HcalSimpleRecAlgo reco_
double HFdigiflagMinEThreshold() const
bool useLeakCorrection() const
Definition: HcalRecoParam.h:36