File indexing completed on 2024-04-06 12:25:48
0001 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalHFStatusBitFromDigis.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003
0004 #include <algorithm> // for "max"
0005 #include <cmath>
0006 #include <iostream>
0007
0008 HcalHFStatusBitFromDigis::HcalHFStatusBitFromDigis() {
0009
0010 minthreshold_ = 40;
0011
0012 firstSample_ =
0013 1;
0014 samplesToAdd_ = 3;
0015 expectedPeak_ = 2;
0016
0017
0018
0019 coef_.push_back(0.93);
0020 coef_.push_back(-0.38275);
0021 coef_.push_back(-0.012667);
0022
0023 HFlongwindowEthresh_ = 40;
0024 HFlongwindowMinTime_.clear();
0025 HFlongwindowMinTime_.push_back(-10);
0026 HFlongwindowMaxTime_.clear();
0027 HFlongwindowMaxTime_.push_back(8);
0028 HFshortwindowEthresh_ = 40;
0029 HFshortwindowMinTime_.clear();
0030 HFshortwindowMinTime_.push_back(-10);
0031 HFshortwindowMaxTime_.clear();
0032 HFshortwindowMaxTime_.push_back(8);
0033 }
0034
0035 HcalHFStatusBitFromDigis::HcalHFStatusBitFromDigis(const edm::ParameterSet& HFDigiTimeParams,
0036 const edm::ParameterSet& HFTimeInWindowParams) {
0037
0038 firstSample_ = HFDigiTimeParams.getParameter<int>("HFdigiflagFirstSample");
0039 samplesToAdd_ = HFDigiTimeParams.getParameter<int>("HFdigiflagSamplesToAdd");
0040 expectedPeak_ = HFDigiTimeParams.getParameter<int>("HFdigiflagExpectedPeak");
0041 minthreshold_ = HFDigiTimeParams.getParameter<double>("HFdigiflagMinEthreshold");
0042 coef_ = HFDigiTimeParams.getParameter<std::vector<double> >("HFdigiflagCoef");
0043
0044
0045 HFlongwindowMinTime_ = HFTimeInWindowParams.getParameter<std::vector<double> >("hflongMinWindowTime");
0046 HFlongwindowMaxTime_ = HFTimeInWindowParams.getParameter<std::vector<double> >("hflongMaxWindowTime");
0047 HFlongwindowEthresh_ = HFTimeInWindowParams.getParameter<double>("hflongEthresh");
0048 HFshortwindowMinTime_ = HFTimeInWindowParams.getParameter<std::vector<double> >("hfshortMinWindowTime");
0049 HFshortwindowMaxTime_ = HFTimeInWindowParams.getParameter<std::vector<double> >("hfshortMaxWindowTime");
0050 HFshortwindowEthresh_ = HFTimeInWindowParams.getParameter<double>("hfshortEthresh");
0051 }
0052
0053 HcalHFStatusBitFromDigis::~HcalHFStatusBitFromDigis() {}
0054
0055 void HcalHFStatusBitFromDigis::resetParamsFromDB(
0056 int firstSample, int samplesToAdd, int expectedPeak, double minthreshold, const std::vector<double>& coef) {
0057
0058 firstSample_ = firstSample;
0059 samplesToAdd_ = samplesToAdd;
0060 expectedPeak_ = expectedPeak;
0061 minthreshold_ = minthreshold;
0062 coef_ = coef;
0063 }
0064
0065 void HcalHFStatusBitFromDigis::resetFlagTimeSamples(int firstSample, int samplesToAdd, int expectedPeak) {
0066
0067
0068 firstSample_ = firstSample;
0069 samplesToAdd_ = samplesToAdd;
0070 expectedPeak_ = expectedPeak;
0071 }
0072
0073 void HcalHFStatusBitFromDigis::hfSetFlagFromDigi(HFRecHit& hf,
0074 const HFDataFrame& digi,
0075 const HcalCoder& coder,
0076 const HcalCalibrations& calib) {
0077
0078
0079
0080
0081 double totalCharge = 0;
0082 double peakCharge = 0;
0083 double RecomputedEnergy = 0;
0084
0085 CaloSamples tool;
0086 coder.adc2fC(digi, tool);
0087
0088
0089 for (int i = 0; i < digi.size(); ++i) {
0090 int capid = digi.sample(i).capid();
0091 double value = tool[i] - calib.pedestal(capid);
0092
0093
0094 if (i >= firstSample_ && i < firstSample_ + samplesToAdd_) {
0095 totalCharge += value;
0096 RecomputedEnergy += value * calib.respcorrgain(capid);
0097 if (i == expectedPeak_)
0098 peakCharge = value;
0099 }
0100 }
0101
0102
0103
0104 if (RecomputedEnergy >= minthreshold_)
0105 {
0106
0107 double cutoff = 0;
0108 if (!coef_.empty())
0109 cutoff = coef_[0];
0110
0111
0112 double powRE = 1;
0113 double expo_arg = 0;
0114 for (unsigned int zz = 1; zz < coef_.size(); ++zz) {
0115 expo_arg += coef_[zz] * powRE;
0116 powRE *= RecomputedEnergy;
0117 }
0118 cutoff -= exp(expo_arg);
0119
0120 if (peakCharge / totalCharge < cutoff)
0121 hf.setFlagField(1, HcalCaloFlagLabels::HFDigiTime);
0122 }
0123
0124
0125
0126 if (hf.id().depth() == 1) {
0127 if (hf.energy() >= HFlongwindowEthresh_) {
0128 float mult = 1. / hf.energy();
0129 float enPow = 1.;
0130 float mintime = 0;
0131 float maxtime = 0;
0132 for (unsigned int i = 0; i < HFlongwindowMinTime_.size(); ++i) {
0133 mintime += HFlongwindowMinTime_[i] * enPow;
0134 maxtime += HFlongwindowMaxTime_[i] * enPow;
0135 enPow *= mult;
0136 }
0137 if (hf.time() < mintime || hf.time() > maxtime)
0138 hf.setFlagField(1, HcalCaloFlagLabels::HFInTimeWindow);
0139 }
0140 } else if (hf.id().depth() == 2) {
0141 if (hf.energy() >= HFshortwindowEthresh_) {
0142 float mult = 1. / hf.energy();
0143 float enPow = 1.;
0144 float mintime = 0;
0145 float maxtime = 0;
0146 for (unsigned int i = 0; i < HFshortwindowMinTime_.size(); ++i) {
0147 mintime += HFshortwindowMinTime_[i] * enPow;
0148 maxtime += HFshortwindowMaxTime_[i] * enPow;
0149 enPow *= mult;
0150 }
0151 if (hf.time() < mintime || hf.time() > maxtime)
0152 hf.setFlagField(1, HcalCaloFlagLabels::HFInTimeWindow);
0153 }
0154 }
0155
0156 return;
0157 }