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"
16 
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 {
42 
43  std::string subd=conf.getParameter<std::string>("Subdetector");
44  //Set all FlagSetters to 0
45  /* Important to do this! Otherwise, if the setters are turned off,
46  the "if (XSetter_) delete XSetter_;" commands can crash
47  */
48 
49  recoParamsFromDB_ = conf.getParameter<bool>("recoParamsFromDB");
50  // recoParamsFromDB_ = false ; // trun off for now.
51 
52  // std::cout<<" HcalHitReconstructor recoParamsFromDB_ "<<recoParamsFromDB_<<std::endl;
53 
54  hbheFlagSetter_ = 0;
58  hfdigibit_ = 0;
59 
60  hfS9S1_ = 0;
61  hfS8S1_ = 0;
62  hfPET_ = 0;
65  digiTimeFromDB_ = false; // only need for HF
66 
68  {
69  const edm::ParameterSet& pssat = conf.getParameter<edm::ParameterSet>("saturationParameters");
70  saturationFlagSetter_ = new HcalADCSaturationFlag(pssat.getParameter<int>("maxADCvalue"));
71  }
72 
73  if (!strcasecmp(subd.c_str(),"HBHE")) {
75  bool timingShapedCutsFlags = conf.getParameter<bool>("setTimingShapedCutsFlags");
76  if (timingShapedCutsFlags)
77  {
78  const edm::ParameterSet& psTshaped = conf.getParameter<edm::ParameterSet>("timingshapedcutsParameters");
79  hbheTimingShapedFlagSetter_ = new HBHETimingShapedFlagSetter(psTshaped.getParameter<std::vector<double> >("tfilterEnvelope"),
80  psTshaped.getParameter<bool>("ignorelowest"),
81  psTshaped.getParameter<bool>("ignorehighest"),
82  psTshaped.getParameter<double>("win_offset"),
83  psTshaped.getParameter<double>("win_gain"));
84  }
85 
86  if (setNoiseFlags_)
87  {
88  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("flagParameters");
89  hbheFlagSetter_=new HBHEStatusBitSetter(psdigi.getParameter<double>("nominalPedestal"),
90  psdigi.getParameter<double>("hitEnergyMinimum"),
91  psdigi.getParameter<int>("hitMultiplicityThreshold"),
92  psdigi.getParameter<std::vector<edm::ParameterSet> >("pulseShapeParameterSets")
93  );
94  } // if (setNoiseFlags_)
95  if (setHSCPFlags_)
96  {
97  const edm::ParameterSet& psHSCP = conf.getParameter<edm::ParameterSet>("hscpParameters");
99  psHSCP.getParameter<double>("r1Max"),
100  psHSCP.getParameter<double>("r2Min"),
101  psHSCP.getParameter<double>("r2Max"),
102  psHSCP.getParameter<double>("fracLeaderMin"),
103  psHSCP.getParameter<double>("fracLeaderMax"),
104  psHSCP.getParameter<double>("slopeMin"),
105  psHSCP.getParameter<double>("slopeMax"),
106  psHSCP.getParameter<double>("outerMin"),
107  psHSCP.getParameter<double>("outerMax"),
108  psHSCP.getParameter<double>("TimingEnergyThreshold"));
109  } // if (setHSCPFlags_)
111  {
112  const edm::ParameterSet &psPulseShape = conf.getParameter<edm::ParameterSet>("pulseShapeParameters");
114  psPulseShape.getParameter<double>("MinimumChargeThreshold"),
115  psPulseShape.getParameter<double>("TS4TS5ChargeThreshold"),
116  psPulseShape.getParameter<unsigned int>("TrianglePeakTS"),
117  psPulseShape.getParameter<std::vector<double> >("LinearThreshold"),
118  psPulseShape.getParameter<std::vector<double> >("LinearCut"),
119  psPulseShape.getParameter<std::vector<double> >("RMS8MaxThreshold"),
120  psPulseShape.getParameter<std::vector<double> >("RMS8MaxCut"),
121  psPulseShape.getParameter<std::vector<double> >("LeftSlopeThreshold"),
122  psPulseShape.getParameter<std::vector<double> >("LeftSlopeCut"),
123  psPulseShape.getParameter<std::vector<double> >("RightSlopeThreshold"),
124  psPulseShape.getParameter<std::vector<double> >("RightSlopeCut"),
125  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallThreshold"),
126  psPulseShape.getParameter<std::vector<double> >("RightSlopeSmallCut"),
127  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerThreshold"),
128  psPulseShape.getParameter<std::vector<double> >("TS4TS5LowerCut"),
129  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperThreshold"),
130  psPulseShape.getParameter<std::vector<double> >("TS4TS5UpperCut"),
131  psPulseShape.getParameter<bool>("UseDualFit"),
132  psPulseShape.getParameter<bool>("TriangleIgnoreSlow"));
133  } // if (setPulseShapeFlags_)
134 
135  produces<HBHERecHitCollection>();
136  } else if (!strcasecmp(subd.c_str(),"HO")) {
138  produces<HORecHitCollection>();
139  } else if (!strcasecmp(subd.c_str(),"HF")) {
141  digiTimeFromDB_=conf.getParameter<bool>("digiTimeFromDB");
142 
143  if (setTimingTrustFlags_) {
144 
145  const edm::ParameterSet& pstrust = conf.getParameter<edm::ParameterSet>("hfTimingTrustParameters");
146  HFTimingTrustFlagSetter_=new HFTimingTrustFlag(pstrust.getParameter<int>("hfTimingTrustLevel1"),
147  pstrust.getParameter<int>("hfTimingTrustLevel2"));
148  }
149 
150  if (setNoiseFlags_)
151  {
152  const edm::ParameterSet& psdigi =conf.getParameter<edm::ParameterSet>("digistat");
153  const edm::ParameterSet& psTimeWin =conf.getParameter<edm::ParameterSet>("HFInWindowStat");
154  hfdigibit_=new HcalHFStatusBitFromDigis(psdigi,psTimeWin);
155 
156  const edm::ParameterSet& psS9S1 = conf.getParameter<edm::ParameterSet>("S9S1stat");
157  hfS9S1_ = new HcalHF_S9S1algorithm(psS9S1.getParameter<std::vector<double> >("short_optimumSlope"),
158  psS9S1.getParameter<std::vector<double> >("shortEnergyParams"),
159  psS9S1.getParameter<std::vector<double> >("shortETParams"),
160  psS9S1.getParameter<std::vector<double> >("long_optimumSlope"),
161  psS9S1.getParameter<std::vector<double> >("longEnergyParams"),
162  psS9S1.getParameter<std::vector<double> >("longETParams"),
163  psS9S1.getParameter<int>("HcalAcceptSeverityLevel"),
164  psS9S1.getParameter<bool>("isS8S1")
165  );
166 
167  const edm::ParameterSet& psS8S1 = conf.getParameter<edm::ParameterSet>("S8S1stat");
168  hfS8S1_ = new HcalHF_S9S1algorithm(psS8S1.getParameter<std::vector<double> >("short_optimumSlope"),
169  psS8S1.getParameter<std::vector<double> >("shortEnergyParams"),
170  psS8S1.getParameter<std::vector<double> >("shortETParams"),
171  psS8S1.getParameter<std::vector<double> >("long_optimumSlope"),
172  psS8S1.getParameter<std::vector<double> >("longEnergyParams"),
173  psS8S1.getParameter<std::vector<double> >("longETParams"),
174  psS8S1.getParameter<int>("HcalAcceptSeverityLevel"),
175  psS8S1.getParameter<bool>("isS8S1")
176  );
177 
178  const edm::ParameterSet& psPET = conf.getParameter<edm::ParameterSet>("PETstat");
179  hfPET_ = new HcalHF_PETalgorithm(psPET.getParameter<std::vector<double> >("short_R"),
180  psPET.getParameter<std::vector<double> >("shortEnergyParams"),
181  psPET.getParameter<std::vector<double> >("shortETParams"),
182  psPET.getParameter<std::vector<double> >("long_R"),
183  psPET.getParameter<std::vector<double> >("longEnergyParams"),
184  psPET.getParameter<std::vector<double> >("longETParams"),
185  psPET.getParameter<int>("HcalAcceptSeverityLevel"),
186  psPET.getParameter<std::vector<double> >("short_R_29"),
187  psPET.getParameter<std::vector<double> >("long_R_29")
188  );
189  }
190  produces<HFRecHitCollection>();
191  } else if (!strcasecmp(subd.c_str(),"ZDC")) {
194  produces<ZDCRecHitCollection>();
195  } else if (!strcasecmp(subd.c_str(),"CALIB")) {
198  produces<HcalCalibRecHitCollection>();
199  } else {
200  std::cout << "HcalHitReconstructor is not associated with a specific subdetector!" << std::endl;
201  }
202 
203 }
204 
206  if (hbheFlagSetter_) delete hbheFlagSetter_;
207  if (hfdigibit_) delete hfdigibit_;
210  if (hfS9S1_) delete hfS9S1_;
211  if (hfPET_) delete hfPET_;
212 }
213 
215 
216  if ( tsFromDB_== true || recoParamsFromDB_ == true )
217  {
219  es.get<HcalRecoParamsRcd>().get(p);
220  paramTS = new HcalRecoParams(*p.product());
221 
222  // std::cout<<" skdump in HcalHitReconstructor::beginRun dupm RecoParams "<<std::endl;
223  // std::ofstream skfile("skdumpRecoParamsNewFormat.txt");
224  // HcalDbASCIIIO::dumpObject(skfile, (*paramTS) );
225  }
226 
227  if (digiTimeFromDB_==true)
228  {
230  es.get<HcalFlagHFDigiTimeParamsRcd>().get(p);
232  }
233  reco_.beginRun(es);
234 }
235 
237  if (tsFromDB_==true)
238  {
239  if (paramTS) delete paramTS;
240  }
241  if (digiTimeFromDB_==true)
242  {
244  }
245  reco_.endRun();
246 }
247 
249 {
250 
251  // get conditions
252  edm::ESHandle<HcalDbService> conditions;
253  eventSetup.get<HcalDbRecord>().get(conditions);
254  const HcalQIEShape* shape = conditions->getHcalShape (); // this one is generic
255  // HACK related to HB- corrections
256  if(e.isRealData()) reco_.setForData();
258 
260  eventSetup.get<HcalChannelQualityRcd>().get(p);
261  HcalChannelQuality* myqual = new HcalChannelQuality(*p.product());
262 
264  eventSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
265  const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
266 
267  if (det_==DetId::Hcal) {
268 
269  // HBHE -------------------------------------------------------------------
272 
273  e.getByLabel(inputLabel_,digi);
274 
275  // create empty output
276  std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
277  rec->reserve(digi->size());
278  // run the algorithm
281  std::vector<HBHEDataFrame> HBDigis;
282  std::vector<int> RecHitIndex;
283 
284  // Vote on majority TS0 CapId
285  int favorite_capid = 0;
286  if (correctTiming_) {
287  long capid_votes[4] = {0,0,0,0};
288  for (i=digi->begin(); i!=digi->end(); i++) {
289  capid_votes[(*i)[0].capid()]++;
290  }
291  for (int k = 0; k < 4; k++)
292  if (capid_votes[k] > capid_votes[favorite_capid])
293  favorite_capid = k;
294  }
295 
296  int first = firstSample_;
297  int toadd = samplesToAdd_;
298 
299  for (i=digi->begin(); i!=digi->end(); i++) {
300  HcalDetId cell = i->id();
301  DetId detcell=(DetId)cell;
302 
304  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
305  firstSample_ = param_ts->firstSample();
306  samplesToAdd_ = param_ts->samplesToAdd();
307  if(recoParamsFromDB_) {
308  bool correctForTimeslew=param_ts->correctForTimeslew();
309  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
310  float phaseNS=param_ts->correctionPhaseNS();
312  correctTiming_ = param_ts->correctTiming();
313  firstAuxTS_ = param_ts->firstAuxTS();
314  int pileupCleaningID = param_ts->pileupCleaningID();
315 
316  /*
317  int sub = cell.subdet();
318  int depth = cell.depth();
319  int inteta = cell.ieta();
320  int intphi = cell.iphi();
321 
322  std::cout << "HcalHitReconstructor::produce cell:"
323  << " sub, ieta, iphi, depth = "
324  << sub << " " << inteta << " " << intphi
325  << " " << depth << std::endl
326  << " first, toadd = " << firstSample_ << ", "
327  << samplesToAdd_ << std::endl
328  << " correctForTimeslew " << correctForTimeslew
329  << std::endl
330  << " correctForPhaseContainment "
331  << correctForPhaseContainment << std::endl
332  << " phaseNS " << phaseNS << std::endl
333  << " useLeakCorrection " << useLeakCorrection_
334  << std::endl
335  << " correctTiming " << correctTiming_ << std::endl
336  << " firstAuxTS " << firstAuxTS_ << std::endl
337  << " pileupCleaningID " << pileupCleaningID
338  << std::endl;
339  */
340 
341  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
342  }
343  }
344 
345  first = firstSample_;
346  toadd = samplesToAdd_;
347 
348  // check on cells to be ignored and dropped: (rof,20.Feb.09)
349  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
350  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
352  if (i->zsMarkAndPass()) continue;
353 
354  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
355  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
356  HcalCoderDb coder (*channelCoder, *shape);
357 
358  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
359 
360  // Set auxiliary flag
361  int auxflag=0;
362  int fTS = firstAuxTS_;
363  if (fTS<0) fTS=0; // silly protection against time slice <0
364  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
365  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
366  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
367  auxflag+=((i->sample(fTS).capid())<<28);
368  (rec->back()).setAux(auxflag);
369 
370  (rec->back()).setFlags(0); // this sets all flag bits to 0
371  // Set presample flag
372  if (fTS>0)
373  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
374 
377  if (setNoiseFlags_)
378  hbheFlagSetter_->SetFlagsFromDigi(rec->back(),*i,coder,calibrations,first,toadd);
379  if (setPulseShapeFlags_ == true)
380  hbhePulseShapeFlagSetter_->SetPulseShapeFlags(rec->back(), *i, coder, calibrations);
383  if (correctTiming_)
384  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
385  if (setHSCPFlags_ && i->id().ietaAbs()<16)
386  {
387  double DigiEnergy=0;
388  for(int j=0; j!=i->size(); DigiEnergy += i->sample(j++).nominal_fC());
389  if(DigiEnergy > hbheHSCPFlagSetter_->EnergyThreshold())
390  {
391  HBDigis.push_back(*i);
392  RecHitIndex.push_back(rec->size()-1);
393  }
394 
395  } // if (set HSCPFlags_ && |ieta|<16)
396  } // loop over HBHE digis
397 
398 
400  if (setHSCPFlags_) hbheHSCPFlagSetter_->hbheSetTimeFlagsFromDigi(rec.get(), HBDigis, RecHitIndex);
401  // return result
402  e.put(rec);
403 
404  // HO ------------------------------------------------------------------
405  } else if (subdet_==HcalOuter) {
407  e.getByLabel(inputLabel_,digi);
408 
409  // create empty output
410  std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
411  rec->reserve(digi->size());
412  // run the algorithm
414 
415  // Vote on majority TS0 CapId
416  int favorite_capid = 0;
417  if (correctTiming_) {
418  long capid_votes[4] = {0,0,0,0};
419  for (i=digi->begin(); i!=digi->end(); i++) {
420  capid_votes[(*i)[0].capid()]++;
421  }
422  for (int k = 0; k < 4; k++)
423  if (capid_votes[k] > capid_votes[favorite_capid])
424  favorite_capid = k;
425  }
426 
427  int first = firstSample_;
428  int toadd = samplesToAdd_;
429 
430  for (i=digi->begin(); i!=digi->end(); i++) {
431  HcalDetId cell = i->id();
432  DetId detcell=(DetId)cell;
433  // firstSample & samplesToAdd
435  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
436  firstSample_ = param_ts->firstSample();
437  samplesToAdd_ = param_ts->samplesToAdd();
438  if(recoParamsFromDB_) {
439  bool correctForTimeslew=param_ts->correctForTimeslew();
440  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
441  float phaseNS=param_ts->correctionPhaseNS();
443  correctTiming_ = param_ts->correctTiming();
444  firstAuxTS_ = param_ts->firstAuxTS();
445  int pileupCleaningID = param_ts->pileupCleaningID();
446  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
447  }
448  }
449 
450  first = firstSample_;
451  toadd = samplesToAdd_;
452 
453  // check on cells to be ignored and dropped: (rof,20.Feb.09)
454  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
455  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
457  if (i->zsMarkAndPass()) continue;
458 
459  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
460  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
461  HcalCoderDb coder (*channelCoder, *shape);
462 
463  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
464 
465  // Set auxiliary flag
466  int auxflag=0;
467  int fTS = firstAuxTS_;
468  if (fTS<0) fTS=0; //silly protection against negative time slice values
469  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
470  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
471  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
472  auxflag+=((i->sample(fTS).capid())<<28);
473  (rec->back()).setAux(auxflag);
474 
475  (rec->back()).setFlags(0);
476  // Fill Presample ADC flag
477  if (fTS>0)
478  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
479 
482  if (correctTiming_)
483  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
484  }
485  // return result
486  e.put(rec);
487 
488  // HF -------------------------------------------------------------------
489  } else if (subdet_==HcalForward) {
491  e.getByLabel(inputLabel_,digi);
492 
493 
495  // create empty output
496  std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
497  rec->reserve(digi->size());
498  // run the algorithm
500 
501  // Vote on majority TS0 CapId
502  int favorite_capid = 0;
503  if (correctTiming_) {
504  long capid_votes[4] = {0,0,0,0};
505  for (i=digi->begin(); i!=digi->end(); i++) {
506  capid_votes[(*i)[0].capid()]++;
507  }
508  for (int k = 0; k < 4; k++)
509  if (capid_votes[k] > capid_votes[favorite_capid])
510  favorite_capid = k;
511  }
512 
513  int first = firstSample_;
514  int toadd = samplesToAdd_;
515 
516  for (i=digi->begin(); i!=digi->end(); i++) {
517  HcalDetId cell = i->id();
518  DetId detcell=(DetId)cell;
519 
521  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
522  firstSample_ = param_ts->firstSample();
523  samplesToAdd_ = param_ts->samplesToAdd();
524  if(recoParamsFromDB_) {
525  bool correctForTimeslew=param_ts->correctForTimeslew();
526  bool correctForPhaseContainment= param_ts->correctForPhaseContainment();
527  float phaseNS=param_ts->correctionPhaseNS();
529  correctTiming_ = param_ts->correctTiming();
530  firstAuxTS_ = param_ts->firstAuxTS();
531  int pileupCleaningID = param_ts->pileupCleaningID();
532  reco_.setRecoParams(correctForTimeslew,correctForPhaseContainment,useLeakCorrection_,pileupCleaningID,phaseNS);
533  }
534  }
535 
536  first = firstSample_;
537  toadd = samplesToAdd_;
538 
539  // check on cells to be ignored and dropped: (rof,20.Feb.09)
540  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
541  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
543  if (i->zsMarkAndPass()) continue;
544 
545  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
546  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
547  HcalCoderDb coder (*channelCoder, *shape);
548 
549  // Set HFDigiTime flag values from digiTimeFromDB_
550  if (digiTimeFromDB_==true && hfdigibit_!=0)
551  {
552  const HcalFlagHFDigiTimeParam* hfDTparam = HFDigiTimeParams->getValues(detcell.rawId());
554  hfDTparam->HFdigiflagSamplesToAdd(),
555  hfDTparam->HFdigiflagExpectedPeak(),
556  hfDTparam->HFdigiflagMinEThreshold(),
557  hfDTparam->HFdigiflagCoefficients()
558  );
559  }
560 
561  //std::cout << "TOADDHF " << toadd << " " << first << " " << std::endl;
562  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
563 
564  // Set auxiliary flag
565  int auxflag=0;
566  int fTS = firstAuxTS_;
567  if (fTS<0) fTS=0; // silly protection against negative time slice values
568  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
569  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
570  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
571  auxflag+=((i->sample(fTS).capid())<<28);
572  (rec->back()).setAux(auxflag);
573 
574  // Clear flags
575  (rec->back()).setFlags(0);
576 
577  // Fill Presample ADC flag
578  if (fTS>0)
579  (rec->back()).setFlagField((i->sample(fTS-1).adc()), HcalCaloFlagLabels::PresampleADC,7);
580 
581  // This calls the code for setting the HF noise bit determined from digi shape
582  if (setNoiseFlags_)
583  hfdigibit_->hfSetFlagFromDigi(rec->back(),*i,coder,calibrations);
588  if (correctTiming_)
589  HcalTimingCorrector::Correct(rec->back(), *i, favorite_capid);
590  } // for (i=digi->begin(); i!=digi->end(); i++) -- loop on all HF digis
591 
592  // The following flags require the full set of rechits
593  // These need to be set consecutively, so an energy check should be the first
594  // test performed on these hits (to minimize the loop time)
595  if (setNoiseFlags_)
596  {
597  // Step 1: Set PET flag (short fibers of |ieta|==29)
598  // Neighbor/partner channels that are flagged by Pulse Shape algorithm (HFDigiTime)
599  // won't be considered in these calculations
600  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
601  {
602  int depth=i->id().depth();
603  int ieta=i->id().ieta();
604  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
605  if (depth==2 || abs(ieta)==29 )
606  hfPET_->HFSetFlagFromPET(*i,*rec,myqual,mySeverity);
607  }
608 
609  // Step 2: Set S8S1 flag (short fibers or |ieta|==29)
610  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
611  {
612  int depth=i->id().depth();
613  int ieta=i->id().ieta();
614  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
615  if (depth==2 || abs(ieta)==29 )
616  hfS8S1_->HFSetFlagFromS9S1(*i,*rec,myqual,mySeverity);
617  }
618 
619  // Set 3: Set S9S1 flag (long fibers)
620  for (HFRecHitCollection::iterator i = rec->begin();i!=rec->end();++i)
621  {
622  int depth=i->id().depth();
623  int ieta=i->id().ieta();
624  // Short fibers and all channels at |ieta|=29 use PET settings in Algo 3
625  if (depth==1 && abs(ieta)!=29 )
626  hfS9S1_->HFSetFlagFromS9S1(*i,*rec,myqual, mySeverity);
627  }
628  }
629 
630  // return result
631  e.put(rec);
632  } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
634  e.getByLabel(inputLabel_,digi);
635 
636  // create empty output
637  std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
638  rec->reserve(digi->size());
639  // run the algorithm
640  int first = firstSample_;
641  int toadd = samplesToAdd_;
642 
644  for (i=digi->begin(); i!=digi->end(); i++) {
645  HcalCalibDetId cell = i->id();
646  // HcalDetId cellh = i->id();
647  DetId detcell=(DetId)cell;
648  // check on cells to be ignored and dropped: (rof,20.Feb.09)
649  const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
650  if (mySeverity->dropChannel(mydigistatus->getValue() ) ) continue;
652  if (i->zsMarkAndPass()) continue;
653 
654  const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
655  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
656  HcalCoderDb coder (*channelCoder, *shape);
657 
658  // firstSample & samplesToAdd
659  if(tsFromDB_) {
660  const HcalRecoParam* param_ts = paramTS->getValues(detcell.rawId());
661  first = param_ts->firstSample();
662  toadd = param_ts->samplesToAdd();
663  }
664  rec->push_back(reco_.reconstruct(*i,first,toadd,coder,calibrations));
665 
666  /*
667  // Flag setting not available for calibration rechits
668  // Set auxiliary flag
669  int auxflag=0;
670  int fTS = firstAuxTS_;
671  for (int xx=fTS; xx<fTS+4 && xx<i->size();++xx)
672  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
673  // bits 28 and 29 are reserved for capid of the first time slice saved in aux
674  auxflag+=((i->sample(fTS).capid())<<28);
675  (rec->back()).setAux(auxflag);
676 
677  (rec->back()).setFlags(0); // Not yet implemented for HcalCalibRecHit
678  */
679  }
680  // return result
681  e.put(rec);
682  }
683  }
684  delete myqual;
685 } // void HcalHitReconstructor::produce(...)
unsigned int firstSample() const
Definition: HcalRecoParam.h:30
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
HcalRecoParams * paramTS
HBHERecHit reconstruct(const HBHEDataFrame &digi, int first, int toadd, const HcalCoder &coder, const HcalCalibrations &calibs) const
void hbheSetTimeFlagsFromDigi(HBHERecHitCollection *, std::vector< HBHEDataFrame >, std::vector< int >)
void setHFTimingTrustFlag(HFRecHit &rechit, const HFDataFrame &digi)
unsigned int pileupCleaningID() const
Definition: HcalRecoParam.h:42
HcalADCSaturationFlag * saturationFlagSetter_
uint32_t HFdigiflagSamplesToAdd() const
void beginRun(edm::EventSetup const &es)
bool correctForPhaseContainment() const
Definition: HcalRecoParam.h:27
void hfSetFlagFromDigi(HFRecHit &hf, const HFDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib)
void resetParamsFromDB(int firstSample, int samplesToAdd, int expectedPeak, double minthreshold, std::vector< double > coef)
std::vector< T >::const_iterator const_iterator
#define abs(x)
Definition: mlp_lapack.h:159
bool isRealData() const
Definition: EventBase.h:60
HcalFlagHFDigiTimeParams * HFDigiTimeParams
void SetFlagsFromDigi(HBHERecHit &hbhe, const HBHEDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib, int firstSample=3, int samplesToAdd=4)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
void HFSetFlagFromPET(HFRecHit &hf, HFRecHitCollection &rec, HcalChannelQuality *myqual, const HcalSeverityLevelComputer *mySeverity)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
bool correctForTimeslew() const
Definition: HcalRecoParam.h:36
bool correctTiming() const
Definition: HcalRecoParam.h:38
HcalHFStatusBitFromDigis * hfdigibit_
int j
Definition: DBlmapReader.cc:9
bool dropChannel(const uint32_t &mystatus) const
uint32_t HFdigiflagExpectedPeak() const
void setSaturationFlag(HBHERecHit &rechit, const HBHEDataFrame &digi)
unsigned int samplesToAdd() const
Definition: HcalRecoParam.h:31
bool first
Definition: L1TdeRCT.cc:94
virtual void produce(edm::Event &e, const edm::EventSetup &c)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
HcalHitReconstructor(const edm::ParameterSet &ps)
float correctionPhaseNS() const
Definition: HcalRecoParam.h:29
tuple conf
Definition: dbtoconf.py:185
std::vector< T >::iterator iterator
int k[5][pyjets_maxn]
std::vector< double > HFdigiflagCoefficients() const
HcalHF_PETalgorithm * hfPET_
Definition: DetId.h:20
void HFSetFlagFromS9S1(HFRecHit &hf, HFRecHitCollection &rec, HcalChannelQuality *myqual, const HcalSeverityLevelComputer *mySeverity)
HcalHF_S9S1algorithm * hfS9S1_
HBHEPulseShapeFlagSetter * hbhePulseShapeFlagSetter_
static const int SubdetectorId
Definition: HcalZDCDetId.h:22
void setRecoParams(bool correctForTimeslew, bool correctForPulse, bool setLeakCorrection, int pileupCleaningID, float phaseNS)
void SetTimingShapedFlags(HBHERecHit &hbhe)
uint32_t HFdigiflagFirstSample() const
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
HBHEStatusBitSetter * hbheFlagSetter_
HBHETimeProfileStatusBitSetter * hbheHSCPFlagSetter_
HBHETimingShapedFlagSetter * hbheTimingShapedFlagSetter_
HcalHF_S9S1algorithm * hfS8S1_
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:39
virtual void endRun(edm::Run &r, edm::EventSetup const &es)
HFTimingTrustFlag * HFTimingTrustFlagSetter_
virtual void beginRun(edm::Run &r, edm::EventSetup const &es)
uint32_t getValue() const
const Item * getValues(DetId fId) const
void SetFlagsFromRecHits(HBHERecHitCollection &rec)
Definition: Run.h:33
HcalSimpleRecAlgo reco_
double HFdigiflagMinEThreshold() const
bool useLeakCorrection() const
Definition: HcalRecoParam.h:34