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