00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "RecoMET/METProducers/interface/HcalNoiseInfoProducer.h"
00011 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00012 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00013 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
00014 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "FWCore/Framework/interface/ESHandle.h"
00017 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
00018 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
00019 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00020 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00021 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputer.h"
00022 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalSeverityLevelComputerRcd.h"
00023 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalCaloFlagLabels.h"
00024 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00025 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00026
00027 using namespace reco;
00028
00029
00030
00031
00032
00033 HcalNoiseInfoProducer::HcalNoiseInfoProducer(const edm::ParameterSet& iConfig) : algo_(iConfig)
00034 {
00035
00036 fillDigis_ = iConfig.getParameter<bool>("fillDigis");
00037 fillRecHits_ = iConfig.getParameter<bool>("fillRecHits");
00038 fillCaloTowers_ = iConfig.getParameter<bool>("fillCaloTowers");
00039 fillTracks_ = iConfig.getParameter<bool>("fillTracks");
00040
00041 maxProblemRBXs_ = iConfig.getParameter<int>("maxProblemRBXs");
00042
00043 maxCaloTowerIEta_ = iConfig.getParameter<int>("maxCaloTowerIEta");
00044 maxTrackEta_ = iConfig.getParameter<double>("maxTrackEta");
00045 minTrackPt_ = iConfig.getParameter<double>("minTrackPt");
00046
00047 digiCollName_ = iConfig.getParameter<std::string>("digiCollName");
00048 recHitCollName_ = iConfig.getParameter<std::string>("recHitCollName");
00049 caloTowerCollName_ = iConfig.getParameter<std::string>("caloTowerCollName");
00050 trackCollName_ = iConfig.getParameter<std::string>("trackCollName");
00051
00052 minRecHitE_ = iConfig.getParameter<double>("minRecHitE");
00053 minLowHitE_ = iConfig.getParameter<double>("minLowHitE");
00054 minHighHitE_ = iConfig.getParameter<double>("minHighHitE");
00055
00056 HcalAcceptSeverityLevel_ = iConfig.getParameter<uint32_t>("HcalAcceptSeverityLevel");
00057
00058 TS4TS5EnergyThreshold_ = iConfig.getParameter<double>("TS4TS5EnergyThreshold");
00059
00060 std::vector<double> TS4TS5UpperThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperThreshold");
00061 std::vector<double> TS4TS5UpperCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5UpperCut");
00062 std::vector<double> TS4TS5LowerThresholdTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerThreshold");
00063 std::vector<double> TS4TS5LowerCutTemp = iConfig.getParameter<std::vector<double> >("TS4TS5LowerCut");
00064
00065 for(int i = 0; i < (int)TS4TS5UpperThresholdTemp.size() && i < (int)TS4TS5UpperCutTemp.size(); i++)
00066 TS4TS5UpperCut_.push_back(std::pair<double, double>(TS4TS5UpperThresholdTemp[i], TS4TS5UpperCutTemp[i]));
00067 sort(TS4TS5UpperCut_.begin(), TS4TS5UpperCut_.end());
00068
00069 for(int i = 0; i < (int)TS4TS5LowerThresholdTemp.size() && i < (int)TS4TS5LowerCutTemp.size(); i++)
00070 TS4TS5LowerCut_.push_back(std::pair<double, double>(TS4TS5LowerThresholdTemp[i], TS4TS5LowerCutTemp[i]));
00071 sort(TS4TS5LowerCut_.begin(), TS4TS5LowerCut_.end());
00072
00073
00074 if(fillDigis_ && !fillRecHits_) {
00075 fillRecHits_=true;
00076 edm::LogWarning("HCalNoiseInfoProducer") << " forcing fillRecHits to be true if fillDigis is true.\n";
00077 }
00078
00079
00080 produces<HcalNoiseRBXCollection>();
00081
00082 produces<HcalNoiseSummary>();
00083 }
00084
00085
00086 HcalNoiseInfoProducer::~HcalNoiseInfoProducer()
00087 {
00088 }
00089
00090
00091
00092
00093
00094
00095
00096 void
00097 HcalNoiseInfoProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00098 {
00099
00100 std::auto_ptr<HcalNoiseRBXCollection> result1(new HcalNoiseRBXCollection);
00101 std::auto_ptr<HcalNoiseSummary> result2(new HcalNoiseSummary);
00102
00103
00104 HcalNoiseRBXArray rbxarray;
00105 HcalNoiseSummary &summary=*result2;
00106
00107
00108
00109 if(fillRecHits_) fillrechits(iEvent, iSetup, rbxarray, summary);
00110 if(fillDigis_) filldigis(iEvent, iSetup, rbxarray);
00111 if(fillCaloTowers_) fillcalotwrs(iEvent, iSetup, rbxarray, summary);
00112 if(fillTracks_) filltracks(iEvent, iSetup, summary);
00113
00114
00115
00116 HcalNoiseRBXArray::iterator maxit=rbxarray.begin();
00117 double maxenergy=-999;
00118 bool maxwritten=false;
00119 for(HcalNoiseRBXArray::iterator rit = rbxarray.begin(); rit!=rbxarray.end(); ++rit) {
00120 HcalNoiseRBX &rbx=(*rit);
00121 CommonHcalNoiseRBXData data(rbx, minRecHitE_, minLowHitE_, minHighHitE_, TS4TS5EnergyThreshold_,
00122 TS4TS5UpperCut_, TS4TS5LowerCut_);
00123
00124
00125 if(data.energy()>maxenergy) {
00126 maxenergy=data.energy();
00127 maxit=rit;
00128 maxwritten=false;
00129 }
00130
00131
00132 bool writerbx = algo_.isProblematic(data) || !algo_.passLooseNoiseFilter(data) ||
00133 !algo_.passTightNoiseFilter(data) || !algo_.passHighLevelNoiseFilter(data);
00134
00135
00136 fillOtherSummaryVariables(summary, data);
00137
00138 if(writerbx) {
00139 summary.nproblemRBXs_++;
00140 if(summary.nproblemRBXs_<=maxProblemRBXs_) {
00141 result1->push_back(rbx);
00142 if(maxit==rit) maxwritten=true;
00143 }
00144 }
00145 }
00146
00147
00148 if(!maxwritten) {
00149 HcalNoiseRBX &rbx=(*maxit);
00150
00151
00152 result1->push_back(rbx);
00153 }
00154
00155
00156 iEvent.put(result1);
00157 iEvent.put(result2);
00158
00159 return;
00160 }
00161
00162
00163 void
00164 HcalNoiseInfoProducer::beginJob()
00165 {
00166 return;
00167 }
00168
00169
00170 void
00171 HcalNoiseInfoProducer::endJob()
00172 {
00173 return;
00174 }
00175
00176
00177
00178
00179 void
00180 HcalNoiseInfoProducer::beginRun(edm::Run&, const edm::EventSetup&)
00181 {
00182 return;
00183 }
00184
00185
00186 void
00187 HcalNoiseInfoProducer::endRun(edm::Run&, const edm::EventSetup&)
00188 {
00189 return;
00190 }
00191
00192
00193 void
00194 HcalNoiseInfoProducer::fillOtherSummaryVariables(HcalNoiseSummary& summary, const CommonHcalNoiseRBXData& data) const
00195 {
00196
00197 if(algo_.passRatioThreshold(data) && data.validRatio()) {
00198 if(data.ratio()<summary.minE2Over10TS()) {
00199 summary.mine2ts_ = data.e2ts();
00200 summary.mine10ts_ = data.e10ts(); }
00201 if(data.ratio()>summary.maxE2Over10TS()) {
00202 summary.maxe2ts_ = data.e2ts();
00203 summary.maxe10ts_ = data.e10ts();
00204 }
00205 }
00206
00207
00208 if(algo_.passZerosThreshold(data)) {
00209 if(data.numZeros()>summary.maxZeros()) {
00210 summary.maxzeros_ = data.numZeros();
00211 }
00212 }
00213
00214
00215 if(data.numHPDHits() > summary.maxHPDHits()) {
00216 summary.maxhpdhits_ = data.numHPDHits();
00217 }
00218 if(data.numRBXHits() > summary.maxRBXHits()) {
00219 summary.maxrbxhits_ = data.numRBXHits();
00220 }
00221 if(data.numHPDNoOtherHits() > summary.maxHPDNoOtherHits()) {
00222 summary.maxhpdhitsnoother_ = data.numHPDNoOtherHits();
00223 }
00224
00225
00226 if(data.PassTS4TS5() == false)
00227 summary.hasBadRBXTS4TS5_ = true;
00228
00229
00230 if(data.minLowEHitTime()<summary.min10GeVHitTime()) {
00231 summary.min10_ = data.minLowEHitTime();
00232 }
00233 if(data.maxLowEHitTime()>summary.max10GeVHitTime()) {
00234 summary.max10_ = data.maxLowEHitTime();
00235 }
00236 summary.rms10_ += data.lowEHitTimeSqrd();
00237 summary.cnthit10_ += data.numLowEHits();
00238 if(data.minHighEHitTime()<summary.min25GeVHitTime()) {
00239 summary.min25_ = data.minHighEHitTime();
00240 }
00241 if(data.maxHighEHitTime()>summary.max25GeVHitTime()) {
00242 summary.max25_ = data.maxHighEHitTime();
00243 }
00244 summary.rms25_ += data.highEHitTimeSqrd();
00245 summary.cnthit25_ += data.numHighEHits();
00246
00247
00248 if(algo_.passEMFThreshold(data)) {
00249 if(summary.minHPDEMF() > data.HPDEMF()) {
00250 summary.minhpdemf_ = data.HPDEMF();
00251 }
00252 if(summary.minRBXEMF() > data.RBXEMF()) {
00253 summary.minrbxemf_ = data.RBXEMF();
00254 }
00255 }
00256
00257
00258 if(!algo_.passLooseRatio(data)) summary.filterstatus_ |= 0x1;
00259 if(!algo_.passLooseHits(data)) summary.filterstatus_ |= 0x2;
00260 if(!algo_.passLooseZeros(data)) summary.filterstatus_ |= 0x4;
00261 if(!algo_.passLooseTiming(data)) summary.filterstatus_ |= 0x8;
00262
00263 if(!algo_.passTightRatio(data)) summary.filterstatus_ |= 0x100;
00264 if(!algo_.passTightHits(data)) summary.filterstatus_ |= 0x200;
00265 if(!algo_.passTightZeros(data)) summary.filterstatus_ |= 0x400;
00266 if(!algo_.passTightTiming(data)) summary.filterstatus_ |= 0x800;
00267
00268 if(!algo_.passHighLevelNoiseFilter(data)) summary.filterstatus_ |= 0x10000;
00269
00270
00271 JoinCaloTowerRefVectorsWithoutDuplicates join;
00272 if(!algo_.passLooseNoiseFilter(data))
00273 join(summary.loosenoisetwrs_, data.rbxTowers());
00274 if(!algo_.passTightNoiseFilter(data))
00275 join(summary.tightnoisetwrs_, data.rbxTowers());
00276 if(!algo_.passHighLevelNoiseFilter(data))
00277 join(summary.hlnoisetwrs_, data.rbxTowers());
00278
00279 return;
00280 }
00281
00282
00283
00284 void
00285 HcalNoiseInfoProducer::filldigis(edm::Event& iEvent, const edm::EventSetup& iSetup, HcalNoiseRBXArray& array) const
00286 {
00287
00288
00289 edm::ESHandle<HcalDbService> conditions;
00290 iSetup.get<HcalDbRecord>().get(conditions);
00291 const HcalQIEShape* shape = conditions->getHcalShape();
00292 edm::ESHandle<HcalChannelQuality> qualhandle;
00293 iSetup.get<HcalChannelQualityRcd>().get(qualhandle);
00294 const HcalChannelQuality* myqual = qualhandle.product();
00295 edm::ESHandle<HcalSeverityLevelComputer> mycomputer;
00296 iSetup.get<HcalSeverityLevelComputerRcd>().get(mycomputer);
00297 const HcalSeverityLevelComputer* mySeverity = mycomputer.product();
00298
00299
00300 edm::Handle<HBHEDigiCollection> handle;
00301 iEvent.getByLabel(digiCollName_, handle);
00302 if(!handle.isValid()) {
00303 throw edm::Exception(edm::errors::ProductNotFound) << " could not find HBHEDigiCollection named " << digiCollName_ << "\n.";
00304 return;
00305 }
00306
00307
00308 for(HBHEDigiCollection::const_iterator it=handle->begin(); it!=handle->end(); ++it) {
00309 const HBHEDataFrame &digi=(*it);
00310 HcalDetId cell = digi.id();
00311 DetId detcell=(DetId)cell;
00312
00313
00314 const HcalChannelStatus* mydigistatus=myqual->getValues(detcell.rawId());
00315 if(mySeverity->dropChannel(mydigistatus->getValue())) continue;
00316 if(digi.zsMarkAndPass()) continue;
00317
00318
00319 const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
00320 const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
00321 HcalCoderDb coder (*channelCoder, *shape);
00322
00323
00324 HcalNoiseRBX &rbx=(*array.findRBX(digi));
00325 HcalNoiseHPD &hpd=(*array.findHPD(digi));
00326
00327
00328
00329 bool isBig=false, isBig5=false, isRBX=false;
00330 int counter=0;
00331 edm::RefVector<HBHERecHitCollection> &rechits=hpd.rechits_;
00332 for(edm::RefVector<HBHERecHitCollection>::const_iterator rit=rechits.begin();
00333 rit!=rechits.end(); ++rit, ++counter) {
00334 if((*rit)->id() == digi.id()) {
00335 if(counter==0) isBig=isBig5=true;
00336 if(counter<5) isBig5=true;
00337 isRBX=true;
00338 }
00339 }
00340
00341
00342 int totalzeros=0;
00343 CaloSamples tool;
00344 coder.adc2fC(digi,tool);
00345 for(int ts=0; ts<tool.size(); ++ts) {
00346
00347
00348 if(digi[ts].adc()==0) {
00349 ++hpd.totalZeros_;
00350 ++totalzeros;
00351 }
00352
00353
00354 double corrfc = tool[ts]-calibrations.pedestal(digi[ts].capid());
00355
00356
00357 if(isBig) hpd.bigCharge_[ts]+=corrfc;
00358 if(isBig5) hpd.big5Charge_[ts]+=corrfc;
00359 if(isRBX) rbx.allCharge_[ts]+=corrfc;
00360 }
00361
00362
00363 if(totalzeros>hpd.maxZeros_)
00364 hpd.maxZeros_=totalzeros;
00365 }
00366
00367 return;
00368 }
00369
00370
00371 void
00372 HcalNoiseInfoProducer::fillrechits(edm::Event& iEvent, const edm::EventSetup& iSetup, HcalNoiseRBXArray& array, HcalNoiseSummary& summary) const
00373 {
00374
00375 edm::ESHandle<HcalChannelQuality> hcalChStatus;
00376 iSetup.get<HcalChannelQualityRcd>().get( hcalChStatus );
00377 const HcalChannelQuality* dbHcalChStatus = hcalChStatus.product();
00378
00379
00380 edm::ESHandle<HcalSeverityLevelComputer> hcalSevLvlComputerHndl;
00381 iSetup.get<HcalSeverityLevelComputerRcd>().get(hcalSevLvlComputerHndl);
00382 const HcalSeverityLevelComputer* hcalSevLvlComputer = hcalSevLvlComputerHndl.product();
00383
00384
00385 edm::ESHandle<CaloGeometry> pG;
00386 iSetup.get<CaloGeometryRecord>().get(pG);
00387 const CaloGeometry* geo = pG.product();
00388
00389
00390 edm::Handle<HBHERecHitCollection> handle;
00391 iEvent.getByLabel(recHitCollName_, handle);
00392 if(!handle.isValid()) {
00393 throw edm::Exception(edm::errors::ProductNotFound)
00394 << " could not find HBHERecHitCollection named " << recHitCollName_ << "\n.";
00395 return;
00396 }
00397
00398
00399 for(HBHERecHitCollection::const_iterator it=handle->begin(); it!=handle->end(); ++it) {
00400 const HBHERecHit &rechit=(*it);
00401
00402
00403 const DetId id = rechit.detid();
00404 uint32_t recHitFlag = rechit.flags();
00405 uint32_t noisebitset = (1 << HcalCaloFlagLabels::HBHEIsolatedNoise);
00406 uint32_t flatbitset = (1 << HcalCaloFlagLabels::HBHEFlatNoise);
00407 uint32_t spikebitset = (1 << HcalCaloFlagLabels::HBHESpikeNoise);
00408 uint32_t trianglebitset = (1 << HcalCaloFlagLabels::HBHETriangleNoise);
00409 uint32_t ts4ts5bitset = (1 << HcalCaloFlagLabels::HBHETS4TS5Noise);
00410 recHitFlag = (recHitFlag & noisebitset) ? recHitFlag-noisebitset : recHitFlag;
00411 const uint32_t dbStatusFlag = dbHcalChStatus->getValues(id)->getValue();
00412 int severityLevel = hcalSevLvlComputer->getSeverityLevel(id, recHitFlag, dbStatusFlag);
00413 bool isRecovered = hcalSevLvlComputer->recoveredRecHit(id, recHitFlag);
00414 if(severityLevel!=0 && !isRecovered && severityLevel>static_cast<int>(HcalAcceptSeverityLevel_)) continue;
00415
00416
00417 if(rechit.flags() & noisebitset) {
00418 summary.nisolnoise_++;
00419 summary.isolnoisee_ += rechit.energy();
00420 GlobalPoint gp = geo->getPosition(rechit.id());
00421 double et = rechit.energy()*gp.perp()/gp.mag();
00422 summary.isolnoiseet_ += et;
00423 }
00424
00425 if(rechit.flags() & flatbitset) {
00426 summary.nflatnoise_++;
00427 summary.flatnoisee_ += rechit.energy();
00428 GlobalPoint gp = geo->getPosition(rechit.id());
00429 double et = rechit.energy()*gp.perp()/gp.mag();
00430 summary.flatnoiseet_ += et;
00431 }
00432
00433 if(rechit.flags() & spikebitset) {
00434 summary.nspikenoise_++;
00435 summary.spikenoisee_ += rechit.energy();
00436 GlobalPoint gp = geo->getPosition(rechit.id());
00437 double et = rechit.energy()*gp.perp()/gp.mag();
00438 summary.spikenoiseet_ += et;
00439 }
00440
00441 if(rechit.flags() & trianglebitset) {
00442 summary.ntrianglenoise_++;
00443 summary.trianglenoisee_ += rechit.energy();
00444 GlobalPoint gp = geo->getPosition(rechit.id());
00445 double et = rechit.energy()*gp.perp()/gp.mag();
00446 summary.trianglenoiseet_ += et;
00447 }
00448
00449 if(rechit.flags() & ts4ts5bitset) {
00450 summary.nts4ts5noise_++;
00451 summary.ts4ts5noisee_ += rechit.energy();
00452 GlobalPoint gp = geo->getPosition(rechit.id());
00453 double et = rechit.energy()*gp.perp()/gp.mag();
00454 summary.ts4ts5noiseet_ += et;
00455 }
00456
00457
00458 HcalNoiseHPD& hpd=(*array.findHPD(rechit));
00459
00460
00461 edm::Ref<HBHERecHitCollection> myRef(handle, it-handle->begin());
00462
00463
00464 hpd.refrechitset_.insert(myRef);
00465
00466 }
00467
00468
00469 for(HcalNoiseRBXArray::iterator rbxit=array.begin(); rbxit!=array.end(); ++rbxit) {
00470 for(std::vector<HcalNoiseHPD>::iterator hpdit=rbxit->hpds_.begin(); hpdit!=rbxit->hpds_.end(); ++hpdit) {
00471
00472
00473 for(std::set<edm::Ref<HBHERecHitCollection>, RefHBHERecHitEnergyComparison>::const_iterator
00474 it=hpdit->refrechitset_.begin(); it!=hpdit->refrechitset_.end(); ++it) {
00475 hpdit->rechits_.push_back(*it);
00476 }
00477 }
00478 }
00479
00480
00481 return;
00482 }
00483
00484
00485 void
00486 HcalNoiseInfoProducer::fillcalotwrs(edm::Event& iEvent, const edm::EventSetup& iSetup, HcalNoiseRBXArray& array, HcalNoiseSummary& summary) const
00487 {
00488
00489 edm::Handle<CaloTowerCollection> handle;
00490 iEvent.getByLabel(caloTowerCollName_, handle);
00491 if(!handle.isValid()) {
00492 throw edm::Exception(edm::errors::ProductNotFound)
00493 << " could not find CaloTowerCollection named " << caloTowerCollName_ << "\n.";
00494 return;
00495 }
00496
00497 summary.emenergy_ = summary.hadenergy_ = 0.0;
00498
00499
00500 for(CaloTowerCollection::const_iterator it = handle->begin(); it!=handle->end(); ++it) {
00501 const CaloTower& twr=(*it);
00502
00503
00504 edm::Ref<CaloTowerCollection> myRef(handle, it-handle->begin());
00505
00506
00507 std::vector<std::vector<HcalNoiseHPD>::iterator> hpditervec;
00508 array.findHPD(twr, hpditervec);
00509
00510
00511 for(std::vector<std::vector<HcalNoiseHPD>::iterator>::iterator it=hpditervec.begin();
00512 it!=hpditervec.end(); ++it)
00513 (*it)->calotowers_.push_back(myRef);
00514
00515
00516 if(twr.ietaAbs()>maxCaloTowerIEta_) {
00517 summary.emenergy_ += twr.emEnergy();
00518 summary.hadenergy_ += twr.hadEnergy();
00519 }
00520 }
00521
00522 return;
00523 }
00524
00525
00526 void
00527 HcalNoiseInfoProducer::filltracks(edm::Event& iEvent, const edm::EventSetup& iSetup, HcalNoiseSummary& summary) const
00528 {
00529 edm::Handle<reco::TrackCollection> handle;
00530 iEvent.getByLabel(trackCollName_, handle);
00531
00532
00533 if(!handle.isValid()) {
00534
00535
00536 return;
00537 }
00538
00539 summary.trackenergy_=0.0;
00540 for(reco::TrackCollection::const_iterator iTrack = handle->begin(); iTrack!=handle->end(); ++iTrack) {
00541 reco::Track trk=*iTrack;
00542 if(trk.pt()<minTrackPt_ || fabs(trk.eta())>maxTrackEta_) continue;
00543
00544 summary.trackenergy_ += trk.p();
00545 }
00546
00547 return;
00548 }
00549
00550
00551 DEFINE_FWK_MODULE(HcalNoiseInfoProducer);