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