00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DTNoiseTask.h"
00011
00012
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include <FWCore/Framework/interface/EventSetup.h>
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019
00020
00021 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00022 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00023 #include "Geometry/DTGeometry/interface/DTLayer.h"
00024 #include "Geometry/DTGeometry/interface/DTTopology.h"
00025
00026
00027 #include <DataFormats/DTDigi/interface/DTDigi.h>
00028 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
00029 #include "CondFormats/DataRecord/interface/DTStatusFlagRcd.h"
00030 #include "CondFormats/DTObjects/interface/DTStatusFlag.h"
00031 #include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
00032
00033
00034 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00035
00036
00037 #include <CondFormats/DTObjects/interface/DTTtrig.h>
00038 #include <CondFormats/DataRecord/interface/DTTtrigRcd.h>
00039
00040 #include <sstream>
00041 #include <string>
00042
00043 using namespace edm;
00044 using namespace std;
00045
00046
00047
00048 DTNoiseTask::DTNoiseTask(const ParameterSet& ps) : evtNumber(0) {
00049
00050 LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: Constructor"<<endl;
00051
00052 dbe = edm::Service<DQMStore>().operator->();
00053
00054
00055 doTimeBoxHistos = ps.getUntrackedParameter<bool>("doTbHistos", false);
00056
00057
00058 dtDigiLabel = ps.getParameter<InputTag>("dtDigiLabel");
00059
00060
00061 theRecHits4DLabel = ps.getParameter<string>("recHits4DLabel");
00062
00063
00064 doSegmentVeto = ps.getUntrackedParameter<bool>("doSegmentVeto", false);
00065
00066
00067 safeMargin = ps.getUntrackedParameter<double>("safeMargin", 200.);
00068
00069 }
00070
00071
00072
00073
00074 DTNoiseTask::~DTNoiseTask(){}
00075
00076
00077
00079 void DTNoiseTask::beginJob() {
00080
00081 LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: BeginJob"<<endl;
00082
00083 }
00084
00085
00086
00088 void DTNoiseTask::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00089 const edm::EventSetup& context) {
00090
00091 LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Begin of LS transition"<<endl;
00092
00093 }
00094
00095
00096
00098 void DTNoiseTask::analyze(const edm::Event& e, const edm::EventSetup& c) {
00099
00100 evtNumber++;
00101 if(evtNumber%1000==0)
00102 LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Analyzing evt number :"<<evtNumber<<endl;
00103
00104
00105 std::map<DTChamberId, int> segmentsChId;
00106
00107
00108 edm::Handle<DTRecSegment4DCollection> all4DSegments;
00109 if(doSegmentVeto) {
00110 e.getByLabel(theRecHits4DLabel, all4DSegments);
00111
00112
00113 DTRecSegment4DCollection::id_iterator chamberId;
00114 for (chamberId = all4DSegments->id_begin();
00115 chamberId != all4DSegments->id_end();
00116 ++chamberId){
00117 segmentsChId[*chamberId]=1;
00118 }
00119 }
00120
00121
00122 edm::Handle<DTDigiCollection> dtdigis;
00123 e.getByLabel(dtDigiLabel, dtdigis);
00124
00125
00126 DTDigiCollection::DigiRangeIterator dtLayerId_It;
00127 for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
00128 for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
00129 digiIt!=((*dtLayerId_It).second).second; ++digiIt){
00130
00131
00132 int tdcTime = (*digiIt).countsTDC();
00133 double upperLimit = tTrigStMap[(*dtLayerId_It).first.superlayerId().chamberId()]-safeMargin;
00134 if(doTimeBoxHistos)
00135 tbHistos[(*dtLayerId_It).first.superlayerId()]->Fill(tdcTime);
00136 if(tdcTime>upperLimit)
00137 continue;
00138
00139
00140 if(doSegmentVeto &&
00141 segmentsChId.find((*dtLayerId_It).first.superlayerId().chamberId())!=segmentsChId.end())
00142 continue;
00143
00144
00145
00146 TH2F* noise_root = noiseHistos[(*dtLayerId_It).first.superlayerId().chamberId()]->getTH2F();
00147 double normalization=0;
00148 if(mapEvt.find((*dtLayerId_It).first.superlayerId().chamberId())!=mapEvt.end()) {
00149 LogVerbatim("DTNoiseTask") << " Last fill: # of events: "
00150 << mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]
00151 << endl;
00152 normalization = 1e-9*upperLimit*mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()];
00153
00154 noise_root->Scale(normalization);
00155 }
00156 int yBin=(*dtLayerId_It).first.layer()+(4*((*dtLayerId_It).first.superlayerId().superlayer()-1));
00157 noise_root->Fill((*digiIt).wire(),yBin);
00158
00159 mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()] = evtNumber;
00160 LogVerbatim("DTNoiseTask") << (*dtLayerId_It).first << " wire: " << (*digiIt).wire()
00161 << " # counts: " << noise_root->GetBinContent((*digiIt).wire(),yBin)
00162 << " Time interval: " << upperLimit
00163 << " # of events: " << evtNumber << endl;;
00164 normalization = double( 1e-9*upperLimit*mapEvt[(*dtLayerId_It).first.superlayerId().chamberId()]);
00165
00166 noise_root->Scale(1./normalization);
00167 LogVerbatim("DTNoiseTask") << " noise rate: "
00168 << noise_root->GetBinContent((*digiIt).wire(),yBin) << endl;
00169 }
00170 }
00171 }
00172
00173
00174
00176 void DTNoiseTask::endJob() {}
00177
00178
00179 void DTNoiseTask::bookHistos(DTChamberId chId) {
00180
00181
00182 stringstream wheel; wheel << chId.wheel();
00183 stringstream station; station << chId.station();
00184 stringstream sector; sector << chId.sector();
00185 dbe->setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
00186
00187 "/Sector" + sector.str());
00188
00189
00190 string histoName = string("NoiseRate")
00191 + "_W" + wheel.str()
00192 + "_St" + station.str()
00193 + "_Sec" + sector.str() ;
00194
00195 LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: booking chamber histo:"<<endl;
00196 LogVerbatim("DTNoiseTask") << " folder "<< "DT/05-Noise/Wheel" + wheel.str() +
00197
00198 "/Sector" + sector.str() + "/"<<endl;
00199 LogVerbatim("DTNoiseTask") << " histoName "<<histoName<<endl;
00200
00201
00202 int nWires_max = 0;
00203 const DTChamber* dtchamber = dtGeom->chamber(chId);
00204 const vector<const DTSuperLayer*> superlayers = dtchamber->superLayers();
00205
00206
00207 for(vector<const DTSuperLayer*>::const_iterator sl = superlayers.begin();
00208 sl != superlayers.end(); ++sl) {
00209 vector<const DTLayer*> layers = (*sl)->layers();
00210 for(vector<const DTLayer*>::const_iterator lay = layers.begin();
00211 lay != layers.end(); ++lay) {
00212 int nWires = (*lay)->specificTopology().channels();
00213 if(nWires > nWires_max) nWires_max = nWires;
00214 }
00215 }
00216
00217 noiseHistos[chId] = dbe->book2D(histoName,"Noise rate (Hz) per channel", nWires_max,1, nWires_max+1,12,1,13);
00218 noiseHistos[chId]->setAxisTitle("wire number",1);
00219 noiseHistos[chId]->setBinLabel(1,"SL1-L1",2);
00220 noiseHistos[chId]->setBinLabel(2,"SL1-L2",2);
00221 noiseHistos[chId]->setBinLabel(3,"SL1-L3",2);
00222 noiseHistos[chId]->setBinLabel(4,"SL1-L4",2);
00223 noiseHistos[chId]->setBinLabel(5,"SL2-L1",2);
00224 noiseHistos[chId]->setBinLabel(6,"SL2-L2",2);
00225 noiseHistos[chId]->setBinLabel(7,"SL2-L3",2);
00226 noiseHistos[chId]->setBinLabel(8,"SL2-L4",2);
00227 noiseHistos[chId]->setBinLabel(9,"SL3-L1",2);
00228 noiseHistos[chId]->setBinLabel(10,"SL3-L2",2);
00229 noiseHistos[chId]->setBinLabel(11,"SL3-L3",2);
00230 noiseHistos[chId]->setBinLabel(12,"SL3-L4",2);
00231
00232 }
00233
00234
00235 void DTNoiseTask::bookHistos(DTSuperLayerId slId) {
00236
00237
00238 stringstream wheel; wheel << slId.chamberId().wheel();
00239 stringstream station; station << slId.chamberId().station();
00240 stringstream sector; sector << slId.chamberId().sector();
00241 stringstream superlayer; superlayer << slId.superlayer();
00242 dbe->setCurrentFolder("DT/05-Noise/Wheel" + wheel.str() +
00243 "/Station" + station.str() +
00244 "/Sector" + sector.str());
00245
00246
00247 string histoName = string("TimeBox")
00248 + "_W" + wheel.str()
00249 + "_St" + station.str()
00250 + "_Sec" + sector.str()
00251 + "_SL" + superlayer.str();
00252
00253 LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: booking SL histo:"<<endl;
00254 LogVerbatim("DTNoiseTask") <<" folder "<< "DT/05-Noise/Wheel" + wheel.str() +
00255 "/Station" + station.str() +
00256 "/Sector" + sector.str() + "/" << endl;
00257 LogVerbatim("DTNoiseTask") <<" histoName "<<histoName<<endl;
00258
00259 tbHistos[slId] = dbe->book1D(histoName,"Time Box (TDC counts)", 1000, 0, 6000);
00260
00261 }
00262
00263
00264 void DTNoiseTask::beginRun(const Run& run, const EventSetup& setup) {
00265
00266 LogVerbatim("DTNoiseTask") <<"[DTNoiseTask]: Begin of run"<<endl;
00267
00268
00269 edm::ESHandle<DTTtrig> tTrigMap;
00270 setup.get<DTTtrigRcd>().get(tTrigMap);
00271
00272
00273 setup.get<MuonGeometryRecord>().get(dtGeom);
00274
00275
00276 vector<DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
00277 vector<DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
00278 for (; ch_it != ch_end; ++ch_it) {
00279 DTChamberId chId = (*ch_it)->id();
00280
00281 bookHistos(chId);
00282 vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
00283 vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
00284
00285 for(; sl_it != sl_end; ++sl_it) {
00286 DTSuperLayerId slId = (*sl_it)->id();
00287 if(doTimeBoxHistos)
00288 bookHistos(slId);
00289 float tTrig, tTrigRMS, kFactor;
00290 tTrigMap->get(slId, tTrig, tTrigRMS,kFactor,DTTimeUnits::ns);
00291
00292
00293 if(tTrigStMap.find(chId)==tTrigStMap.end() ||
00294 (tTrigStMap.find(chId)!=tTrigStMap.end() && tTrig < tTrigStMap[chId]))
00295 tTrigStMap[chId] = tTrig;
00296 }
00297 }
00298
00299
00300 }
00301
00302 void DTNoiseTask::endLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& setup) {
00303 LogVerbatim("DTNoiseTask") << "[DTNoiseTask]: End LS, update rates in all histos" << endl;
00304
00305
00306 for(map<DTChamberId, MonitorElement*>::const_iterator meAndChamber = noiseHistos.begin();
00307 meAndChamber != noiseHistos.end(); ++meAndChamber) {
00308 DTChamberId chId = (*meAndChamber).first;
00309 TH2F* noise_root = (*meAndChamber).second->getTH2F();
00310 double upperLimit = tTrigStMap[chId]-safeMargin;
00311
00312 double normalization=0;
00313 if(mapEvt.find(chId) != mapEvt.end()) {
00314 LogVerbatim("DTNoiseTask") << " Ch: " << chId << " Last fill: # of events: " << mapEvt[chId] << endl;
00315 normalization = 1e-9*upperLimit*mapEvt[chId];
00316
00317 noise_root->Scale(normalization);
00318 }
00319
00320 if (evtNumber) {
00321
00322 LogVerbatim("DTNoiseTask") << " Update for events: " << evtNumber << endl;
00323 mapEvt[chId] = evtNumber;
00324
00325 normalization = double( 1e-9*upperLimit*evtNumber);
00326 noise_root->Scale(1./normalization);
00327 }
00328 }
00329 }