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