Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:15:05

0001 #include "EventFilter/HcalRawToDigi/interface/HcalDataFrameFilter.h"
0002 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
0003 #include "CalibFormats/CaloObjects/interface/CaloSamples.h"
0004 #include "CondFormats/HcalObjects/interface/HcalQIECoder.h"
0005 #include "CondFormats/HcalObjects/interface/HcalQIEShape.h"
0006 
0007 namespace HcalDataFrameFilter_impl {
0008 
0009   template <class DataFrame>
0010   bool check(const DataFrame& df, bool capcheck, bool dvercheck) {
0011     if (capcheck || dvercheck) {
0012       int lastcapid = 0, capid = 0;
0013       for (int i = 0; i < df.size(); i++) {
0014         capid = df[i].capid();
0015         if (capcheck && i != 0 && ((lastcapid + 1) % 4) != capid)
0016           return false;
0017         if (dvercheck && (df[i].er() || !df[i].dv()))
0018           return false;
0019         lastcapid = capid;
0020       }
0021     }
0022     return true;
0023   }
0024 
0025   template <>
0026   bool check<QIE10DataFrame>(const QIE10DataFrame& df, bool capcheck, bool linkerrcheck) {
0027     if (linkerrcheck && df.linkError())
0028       return false;
0029     if (capcheck) {
0030       for (int i = 0; i < df.samples(); i++) {
0031         if (!df[i].ok())
0032           return false;
0033       }
0034     }
0035     return true;
0036   }
0037 
0038   template <>
0039   bool check<QIE11DataFrame>(const QIE11DataFrame& df, bool capcheck, bool linkerrcheck) {
0040     if (linkerrcheck && df.linkError())
0041       return false;
0042     if (capcheck && df.capidError())
0043       return false;
0044     return true;
0045   }
0046 
0047   template <class DataFrame>
0048   double energySum(const DataFrame& df, int fs, int ls, const HcalDbService* conditions = nullptr) {
0049     double es = 0;
0050     for (int i = fs; i <= ls && i <= df.size(); i++)
0051       es += df[i].nominal_fC();
0052     return es;
0053   }
0054 
0055   template <>
0056   double energySum<QIE11DataFrame>(const QIE11DataFrame& df, int fs, int ls, const HcalDbService* conditions) {
0057     const HcalQIECoder* channelCoder = conditions->getHcalCoder(df.id());
0058     const HcalQIEShape* shape = conditions->getHcalShape(channelCoder);
0059     CaloSamples tool;
0060     HcalCoderDb coder(*channelCoder, *shape);
0061     coder.adc2fC(df, tool);
0062     double es = 0;
0063     for (int i = fs; i <= ls && i <= (int)df.samples(); i++)
0064       es += tool[i];
0065     return es;
0066   }
0067 
0068 }  // namespace HcalDataFrameFilter_impl
0069 
0070 HcalDataFrameFilter::HcalDataFrameFilter(
0071     bool requireCapid, bool requireDVER, bool energyFilter, int firstSample, int lastSample, double minAmpl)
0072     : requireCapid_(requireCapid),
0073       requireDVER_(requireDVER),
0074       energyFilter_(energyFilter),
0075       firstSample_(firstSample),
0076       lastSample_(lastSample),
0077       minimumAmplitude_(minAmpl),
0078       conditions_(nullptr) {}
0079 
0080 void HcalDataFrameFilter::setConditions(const HcalDbService* conditions) { conditions_ = conditions; }
0081 
0082 HBHEDigiCollection HcalDataFrameFilter::filter(const HBHEDigiCollection& incol, HcalUnpackerReport& r) {
0083   HBHEDigiCollection output;
0084   for (HBHEDigiCollection::const_iterator i = incol.begin(); i != incol.end(); i++) {
0085     if (!HcalDataFrameFilter_impl::check(*i, requireCapid_, requireDVER_))
0086       r.countBadQualityDigi(i->id());
0087     else if (!energyFilter_ || minimumAmplitude_ < HcalDataFrameFilter_impl::energySum(*i, firstSample_, lastSample_))
0088       output.push_back(*i);
0089   }
0090   return output;
0091 }
0092 
0093 HODigiCollection HcalDataFrameFilter::filter(const HODigiCollection& incol, HcalUnpackerReport& r) {
0094   HODigiCollection output;
0095   for (HODigiCollection::const_iterator i = incol.begin(); i != incol.end(); i++) {
0096     if (!HcalDataFrameFilter_impl::check(*i, requireCapid_, requireDVER_))
0097       r.countBadQualityDigi(i->id());
0098     else if (!energyFilter_ || minimumAmplitude_ < HcalDataFrameFilter_impl::energySum(*i, firstSample_, lastSample_))
0099       output.push_back(*i);
0100   }
0101   return output;
0102 }
0103 
0104 HcalCalibDigiCollection HcalDataFrameFilter::filter(const HcalCalibDigiCollection& incol, HcalUnpackerReport& r) {
0105   HcalCalibDigiCollection output;
0106   for (HcalCalibDigiCollection::const_iterator i = incol.begin(); i != incol.end(); i++) {
0107     if (!HcalDataFrameFilter_impl::check(*i, requireCapid_, requireDVER_))
0108       r.countBadQualityDigi(i->id());
0109     else if (!energyFilter_ || minimumAmplitude_ < HcalDataFrameFilter_impl::energySum(*i, firstSample_, lastSample_))
0110       output.push_back(*i);
0111   }
0112   return output;
0113 }
0114 
0115 HFDigiCollection HcalDataFrameFilter::filter(const HFDigiCollection& incol, HcalUnpackerReport& r) {
0116   HFDigiCollection output;
0117   for (HFDigiCollection::const_iterator i = incol.begin(); i != incol.end(); i++) {
0118     if (!HcalDataFrameFilter_impl::check(*i, requireCapid_, requireDVER_))
0119       r.countBadQualityDigi(i->id());
0120     else if (!energyFilter_ || minimumAmplitude_ < HcalDataFrameFilter_impl::energySum(*i, firstSample_, lastSample_))
0121       output.push_back(*i);
0122   }
0123   return output;
0124 }
0125 
0126 ZDCDigiCollection HcalDataFrameFilter::filter(const ZDCDigiCollection& incol, HcalUnpackerReport& r) {
0127   ZDCDigiCollection output;
0128   for (ZDCDigiCollection::const_iterator i = incol.begin(); i != incol.end(); i++) {
0129     if (!HcalDataFrameFilter_impl::check(*i, requireCapid_, requireDVER_))
0130       r.countBadQualityDigi(i->id());
0131     else if (!energyFilter_ || minimumAmplitude_ < HcalDataFrameFilter_impl::energySum(*i, firstSample_, lastSample_))
0132       output.push_back(*i);
0133   }
0134   return output;
0135 }
0136 
0137 QIE10DigiCollection HcalDataFrameFilter::filter(const QIE10DigiCollection& incol, HcalUnpackerReport& r) {
0138   QIE10DigiCollection output(incol.samples());
0139   for (QIE10DigiCollection::const_iterator i = incol.begin(); i != incol.end(); i++) {
0140     QIE10DataFrame df(*i);
0141     if (!HcalDataFrameFilter_impl::check(df, requireCapid_, requireDVER_))
0142       r.countBadQualityDigi(i->id());
0143     // Never exclude QIE10 digis as their absence would be
0144     // treated as a digi with zero charged deposited in that channel
0145     output.push_back(df);
0146   }
0147   return output;
0148 }
0149 
0150 QIE11DigiCollection HcalDataFrameFilter::filter(const QIE11DigiCollection& incol, HcalUnpackerReport& r) {
0151   QIE11DigiCollection output(incol.samples());
0152   for (QIE11DigiCollection::const_iterator i = incol.begin(); i != incol.end(); i++) {
0153     QIE11DataFrame df(*i);
0154     if (!HcalDataFrameFilter_impl::check(df, requireCapid_, requireDVER_))
0155       r.countBadQualityDigi(i->id());
0156     else if (!energyFilter_ ||
0157              minimumAmplitude_ < HcalDataFrameFilter_impl::energySum(df, firstSample_, lastSample_, conditions_))
0158       output.push_back(df);
0159   }
0160   return output;
0161 }
0162 
0163 bool HcalDataFrameFilter::active() const { return requireCapid_ | requireDVER_ | energyFilter_; }