00001 #include "RecoMET/METAlgorithms/interface/HcalNoiseAlgo.h" 00002 00003 CommonHcalNoiseRBXData::CommonHcalNoiseRBXData(const reco::HcalNoiseRBX& rbx, double minRecHitE, double minLowHitE, double minHighHitE) 00004 { 00005 // energy 00006 energy_ = rbx.recHitEnergy(minRecHitE); 00007 00008 // ratio 00009 e2ts_ = rbx.allChargeHighest2TS(); 00010 e10ts_ = rbx.allChargeTotal(); 00011 00012 // # of hits 00013 numHPDHits_ = 0; 00014 for(std::vector<reco::HcalNoiseHPD>::const_iterator it1=rbx.HPDsBegin(); it1!=rbx.HPDsEnd(); ++it1) { 00015 int nhpdhits=it1->numRecHits(minRecHitE); 00016 if(numHPDHits_ < nhpdhits) numHPDHits_ = nhpdhits; 00017 } 00018 numRBXHits_ = rbx.numRecHits(minRecHitE); 00019 numHPDNoOtherHits_ = (numHPDHits_ == numRBXHits_) ? numHPDHits_ : 0; 00020 00021 // # of ADC zeros 00022 numZeros_ = rbx.totalZeros(); 00023 00024 // timing 00025 minLowEHitTime_ = minHighEHitTime_ = 99999.; 00026 maxLowEHitTime_ = maxHighEHitTime_ = -99999.; 00027 lowEHitTimeSqrd_ = highEHitTimeSqrd_ = 0; 00028 numLowEHits_ = numHighEHits_ = 0; 00029 for(std::vector<reco::HcalNoiseHPD>::const_iterator it1=rbx.HPDsBegin(); it1!=rbx.HPDsEnd(); ++it1) { 00030 edm::RefVector<HBHERecHitCollection> rechits=it1->recHits(); 00031 for(edm::RefVector<HBHERecHitCollection>::const_iterator it2=rechits.begin(); it2!=rechits.end(); ++it2) { 00032 float energy=(*it2)->energy(); 00033 float time=(*it2)->time(); 00034 if(energy>=minLowHitE) { 00035 if(minLowEHitTime_ > time) minLowEHitTime_ = time; 00036 if(maxLowEHitTime_ < time) maxLowEHitTime_ = time; 00037 lowEHitTimeSqrd_ += time*time; 00038 ++numLowEHits_; 00039 } 00040 if(energy>=minHighHitE) { 00041 if(minHighEHitTime_ > time) minHighEHitTime_ = time; 00042 if(maxHighEHitTime_ < time) maxHighEHitTime_ = time; 00043 highEHitTimeSqrd_ += time*time; 00044 ++numHighEHits_; 00045 } 00046 } 00047 } 00048 00049 // emf 00050 HPDEMF_ = 999.; 00051 for(std::vector<reco::HcalNoiseHPD>::const_iterator it1=rbx.HPDsBegin(); it1!=rbx.HPDsEnd(); ++it1) { 00052 double eme=it1->caloTowerEmE(); 00053 double hade=it1->recHitEnergy(minRecHitE); 00054 double emf=(eme+hade)==0 ? 999 : eme/(eme+hade); 00055 if(HPDEMF_ > emf) emf = HPDEMF_; 00056 } 00057 double eme=rbx.caloTowerEmE(); 00058 RBXEMF_ = (eme+energy_)==0 ? 999 : eme/(eme+energy_); 00059 00060 // calotowers 00061 rbxtowers_.clear(); 00062 JoinCaloTowerRefVectorsWithoutDuplicates join; 00063 for(std::vector<reco::HcalNoiseHPD>::const_iterator it1=rbx.HPDsBegin(); it1!=rbx.HPDsEnd(); ++it1) { 00064 join(rbxtowers_, it1->caloTowers()); 00065 } 00066 00067 return; 00068 } 00069 00070 HcalNoiseAlgo::HcalNoiseAlgo(const edm::ParameterSet& iConfig) 00071 { 00072 pMinERatio_ = iConfig.getParameter<double>("pMinERatio"); 00073 pMinEZeros_ = iConfig.getParameter<double>("pMinEZeros"); 00074 pMinEEMF_ = iConfig.getParameter<double>("pMinEEMF"); 00075 00076 minERatio_ = iConfig.getParameter<double>("minERatio"); 00077 minEZeros_ = iConfig.getParameter<double>("minEZeros"); 00078 minEEMF_ = iConfig.getParameter<double>("minEEMF"); 00079 00080 pMinE_ = iConfig.getParameter<double>("pMinE"); 00081 pMinRatio_ = iConfig.getParameter<double>("pMinRatio"); 00082 pMaxRatio_ = iConfig.getParameter<double>("pMaxRatio"); 00083 pMinHPDHits_ = iConfig.getParameter<int>("pMinHPDHits"); 00084 pMinRBXHits_ = iConfig.getParameter<int>("pMinRBXHits"); 00085 pMinHPDNoOtherHits_ = iConfig.getParameter<int>("pMinHPDNoOtherHits"); 00086 pMinZeros_ = iConfig.getParameter<int>("pMinZeros"); 00087 pMinLowEHitTime_ = iConfig.getParameter<double>("pMinLowEHitTime"); 00088 pMaxLowEHitTime_ = iConfig.getParameter<double>("pMaxLowEHitTime"); 00089 pMinHighEHitTime_ = iConfig.getParameter<double>("pMinHighEHitTime"); 00090 pMaxHighEHitTime_ = iConfig.getParameter<double>("pMaxHighEHitTime"); 00091 pMaxHPDEMF_ = iConfig.getParameter<double>("pMaxHPDEMF"); 00092 pMaxRBXEMF_ = iConfig.getParameter<double>("pMaxRBXEMF"); 00093 00094 lMinRatio_ = iConfig.getParameter<double>("lMinRatio"); 00095 lMaxRatio_ = iConfig.getParameter<double>("lMaxRatio"); 00096 lMinHPDHits_ = iConfig.getParameter<int>("lMinHPDHits"); 00097 lMinRBXHits_ = iConfig.getParameter<int>("lMinRBXHits"); 00098 lMinHPDNoOtherHits_ = iConfig.getParameter<int>("lMinHPDNoOtherHits"); 00099 lMinZeros_ = iConfig.getParameter<int>("lMinZeros"); 00100 lMinLowEHitTime_ = iConfig.getParameter<double>("lMinLowEHitTime"); 00101 lMaxLowEHitTime_ = iConfig.getParameter<double>("lMaxLowEHitTime"); 00102 lMinHighEHitTime_ = iConfig.getParameter<double>("lMinHighEHitTime"); 00103 lMaxHighEHitTime_ = iConfig.getParameter<double>("lMaxHighEHitTime"); 00104 00105 tMinRatio_ = iConfig.getParameter<double>("tMinRatio"); 00106 tMaxRatio_ = iConfig.getParameter<double>("tMaxRatio"); 00107 tMinHPDHits_ = iConfig.getParameter<int>("tMinHPDHits"); 00108 tMinRBXHits_ = iConfig.getParameter<int>("tMinRBXHits"); 00109 tMinHPDNoOtherHits_ = iConfig.getParameter<int>("tMinHPDNoOtherHits"); 00110 tMinZeros_ = iConfig.getParameter<int>("tMinZeros"); 00111 tMinLowEHitTime_ = iConfig.getParameter<double>("tMinLowEHitTime"); 00112 tMaxLowEHitTime_ = iConfig.getParameter<double>("tMaxLowEHitTime"); 00113 tMinHighEHitTime_ = iConfig.getParameter<double>("tMinHighEHitTime"); 00114 tMaxHighEHitTime_ = iConfig.getParameter<double>("tMaxHighEHitTime"); 00115 00116 hlMaxHPDEMF_ = iConfig.getParameter<double>("hlMaxHPDEMF"); 00117 hlMaxRBXEMF_ = iConfig.getParameter<double>("hlMaxRBXEMF"); 00118 } 00119 00120 bool HcalNoiseAlgo::isProblematic(const CommonHcalNoiseRBXData& data) const 00121 { 00122 if(data.energy()>pMinE_) return true; 00123 if(data.validRatio() && data.energy()>pMinERatio_ && data.ratio()<pMinRatio_) return true; 00124 if(data.validRatio() && data.energy()>pMinERatio_ && data.ratio()>pMaxRatio_) return true; 00125 if(data.numHPDHits()>=pMinHPDHits_) return true; 00126 if(data.numRBXHits()>=pMinRBXHits_) return true; 00127 if(data.numHPDNoOtherHits()>=pMinHPDNoOtherHits_) return true; 00128 if(data.numZeros()>=pMinZeros_ && data.energy()>pMinEZeros_) return true; 00129 if(data.minLowEHitTime()<pMinLowEHitTime_) return true; 00130 if(data.maxLowEHitTime()>pMaxLowEHitTime_) return true; 00131 if(data.minHighEHitTime()<pMinHighEHitTime_) return true; 00132 if(data.maxHighEHitTime()>pMaxHighEHitTime_) return true; 00133 if(data.HPDEMF()<pMaxHPDEMF_ && data.energy()>pMinEEMF_) return true; 00134 if(data.RBXEMF()<pMaxRBXEMF_ && data.energy()>pMinEEMF_) return true; return false; 00135 } 00136 00137 00138 bool HcalNoiseAlgo::passLooseNoiseFilter(const CommonHcalNoiseRBXData& data) const 00139 { 00140 return (passLooseRatio(data) && passLooseHits(data) && passLooseZeros(data) && passLooseTiming(data)); 00141 } 00142 00143 bool HcalNoiseAlgo::passTightNoiseFilter(const CommonHcalNoiseRBXData& data) const 00144 { 00145 return (passTightRatio(data) && passTightHits(data) && passTightZeros(data) && passTightTiming(data)); 00146 } 00147 00148 bool HcalNoiseAlgo::passHighLevelNoiseFilter(const CommonHcalNoiseRBXData& data) const 00149 { 00150 if(passEMFThreshold(data)) { 00151 if(data.HPDEMF()<hlMaxHPDEMF_) return false; 00152 if(data.RBXEMF()<hlMaxRBXEMF_) return false; 00153 } 00154 return true; 00155 } 00156 00157 bool HcalNoiseAlgo::passLooseRatio(const CommonHcalNoiseRBXData& data) const 00158 { 00159 if(passRatioThreshold(data)) { 00160 if(data.validRatio() && data.ratio()<lMinRatio_) return false; 00161 if(data.validRatio() && data.ratio()>lMaxRatio_) return false; 00162 } 00163 return true; 00164 } 00165 00166 bool HcalNoiseAlgo::passLooseHits(const CommonHcalNoiseRBXData& data) const 00167 { 00168 if(data.numHPDHits()>=lMinHPDHits_) return false; 00169 if(data.numRBXHits()>=lMinRBXHits_) return false; 00170 if(data.numHPDNoOtherHits()>=lMinHPDNoOtherHits_) return false; 00171 return true; 00172 } 00173 00174 bool HcalNoiseAlgo::passLooseZeros(const CommonHcalNoiseRBXData& data) const 00175 { 00176 if(passZerosThreshold(data)) { 00177 if(data.numZeros()>=lMinZeros_) return false; 00178 } 00179 return true; 00180 } 00181 00182 bool HcalNoiseAlgo::passLooseTiming(const CommonHcalNoiseRBXData& data) const 00183 { 00184 if(data.minLowEHitTime()<lMinLowEHitTime_) return false; 00185 if(data.maxLowEHitTime()>lMaxLowEHitTime_) return false; 00186 if(data.minHighEHitTime()<lMinHighEHitTime_) return false; 00187 if(data.maxHighEHitTime()>lMaxHighEHitTime_) return false; 00188 return true; 00189 } 00190 00191 bool HcalNoiseAlgo::passTightRatio(const CommonHcalNoiseRBXData& data) const 00192 { 00193 if(passRatioThreshold(data)) { 00194 if(data.validRatio() && data.ratio()<tMinRatio_) return false; 00195 if(data.validRatio() && data.ratio()>tMaxRatio_) return false; 00196 } 00197 return true; 00198 } 00199 00200 bool HcalNoiseAlgo::passTightHits(const CommonHcalNoiseRBXData& data) const 00201 { 00202 if(data.numHPDHits()>=tMinHPDHits_) return false; 00203 if(data.numRBXHits()>=tMinRBXHits_) return false; 00204 if(data.numHPDNoOtherHits()>=tMinHPDNoOtherHits_) return false; 00205 return true; 00206 } 00207 00208 bool HcalNoiseAlgo::passTightZeros(const CommonHcalNoiseRBXData& data) const 00209 { 00210 if(passZerosThreshold(data)) { 00211 if(data.numZeros()>=tMinZeros_) return false; 00212 } 00213 return true; 00214 } 00215 00216 bool HcalNoiseAlgo::passTightTiming(const CommonHcalNoiseRBXData& data) const 00217 { 00218 if(data.minLowEHitTime()<tMinLowEHitTime_) return false; 00219 if(data.maxLowEHitTime()>tMaxLowEHitTime_) return false; 00220 if(data.minHighEHitTime()<tMinHighEHitTime_) return false; 00221 if(data.maxHighEHitTime()>tMaxHighEHitTime_) return false; 00222 return true; 00223 } 00224 00225 bool HcalNoiseAlgo::passRatioThreshold(const CommonHcalNoiseRBXData& data) const 00226 { 00227 return (data.energy()>minERatio_); 00228 } 00229 00230 bool HcalNoiseAlgo::passZerosThreshold(const CommonHcalNoiseRBXData& data) const 00231 { 00232 return (data.energy()>minEZeros_); 00233 } 00234 00235 bool HcalNoiseAlgo::passEMFThreshold(const CommonHcalNoiseRBXData& data) const 00236 { 00237 return (data.energy()>minEEMF_); 00238 } 00239 00240 void JoinCaloTowerRefVectorsWithoutDuplicates::operator()(edm::RefVector<CaloTowerCollection>& v1, const edm::RefVector<CaloTowerCollection>& v2) const 00241 { 00242 // combines them first into a set to get rid of duplicates and then puts them into the first vector 00243 00244 // sorts them first to get rid of duplicates, then puts them into another RefVector 00245 twrrefset_t twrrefset; 00246 for(edm::RefVector<CaloTowerCollection>::const_iterator it=v1.begin(); it!=v1.end(); ++it) 00247 twrrefset.insert(*it); 00248 for(edm::RefVector<CaloTowerCollection>::const_iterator it=v2.begin(); it!=v2.end(); ++it) 00249 twrrefset.insert(*it); 00250 00251 // clear the original refvector and put them back in 00252 v1.clear(); 00253 for(twrrefset_t::const_iterator it=twrrefset.begin(); it!=twrrefset.end(); ++it) { 00254 v1.push_back(*it); 00255 } 00256 return; 00257 }