00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <DQM/DTMonitorModule/src/DTAlbertoBenvenutiTask.h>
00013
00014
00015 #include <FWCore/Framework/interface/EventSetup.h>
00016
00017
00018 #include <DataFormats/DTDigi/interface/DTDigi.h>
00019 #include <DataFormats/DTDigi/interface/DTDigiCollection.h>
00020 #include <DataFormats/MuonDetId/interface/DTLayerId.h>
00021
00022
00023 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00024 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00025 #include "Geometry/DTGeometry/interface/DTLayer.h"
00026 #include "Geometry/DTGeometry/interface/DTTopology.h"
00027
00028
00029 #include <CondFormats/DTObjects/interface/DTT0.h>
00030 #include <CondFormats/DataRecord/interface/DTT0Rcd.h>
00031 #include <CondFormats/DTObjects/interface/DTTtrig.h>
00032 #include <CondFormats/DataRecord/interface/DTTtrigRcd.h>
00033
00034 #include "CondFormats/DataRecord/interface/DTStatusFlagRcd.h"
00035 #include "CondFormats/DTObjects/interface/DTStatusFlag.h"
00036
00037
00038 #include <stdio.h>
00039 #include <sstream>
00040 #include <math.h>
00041 #include "TFile.h"
00042 #include "TPostScript.h"
00043 #include "TCanvas.h"
00044
00045 using namespace edm;
00046 using namespace std;
00047
00048
00049 DTAlbertoBenvenutiTask::DTAlbertoBenvenutiTask(const edm::ParameterSet& ps){
00050
00051 debug = ps.getUntrackedParameter<bool>("debug", false);
00052 if(debug)
00053 cout<<"[DTAlbertoBenvenutiTask]: Constructor"<<endl;
00054
00055 outputFile = ps.getUntrackedParameter<string>("outputFile", "DTDigiSources.root");
00056 maxTDCHits = ps.getUntrackedParameter<int>("maxTDCHits",1000);
00057
00058
00059 tMax = parameters.getParameter<int>("defaultTmax");
00060
00061 parameters = ps;
00062
00063 }
00064
00065
00066 DTAlbertoBenvenutiTask::~DTAlbertoBenvenutiTask(){
00067
00068 if(debug)
00069 cout << "DTAlbertoBenvenutiTask: analyzed " << nevents << " events" << endl;
00070
00071 }
00072
00073
00074 void DTAlbertoBenvenutiTask::endJob(){
00075
00076 if(debug)
00077 cout<<"[DTAlbertoBenvenutiTask] endjob called!"<<endl;
00078
00079 map< DTChamberId, vector<TH1F*> > TBMap_perChamber;
00080
00081 for(map<DTWireId, TH1F* >::const_iterator wHisto = TBMap.begin();
00082 wHisto != TBMap.end();
00083 wHisto++) {
00084 DTChamberId chId = (*wHisto).first.layerId().superlayerId().chamberId();
00085 TBMap_perChamber[chId].push_back((*wHisto).second);
00086 }
00087
00088
00089 for(map<DTChamberId, vector<TH1F*> >::const_iterator Histo = TBMap_perChamber.begin();
00090 Histo != TBMap_perChamber.end();
00091 Histo++) {
00092 stringstream station; station << (*Histo).first.station();
00093 stringstream sector; sector << (*Histo).first.sector();
00094 stringstream wheel; wheel << (*Histo).first.wheel();
00095
00096 string fileTag = "TimeBoxes";
00097 string fileName = fileTag
00098 + "_W" + wheel.str()
00099 + "_Sec" + sector.str()
00100 + "_St" + station.str()
00101 + ".ps";
00102
00103 TPostScript psFile(fileName.c_str(),111);
00104 psFile.Range(20,26);
00105 int counter = 0;
00106 TCanvas c1("c1","",600,780);
00107 c1.Divide(4,4);
00108 psFile.NewPage();
00109
00110 cout<<"[DTAlbertoBenvenutiTask] filling the file: "<<fileName<<endl;
00111 for(vector<TH1F*>::const_iterator tbHisto = (*Histo).second.begin();
00112 tbHisto != (*Histo).second.end();
00113 tbHisto++) {
00114 counter++;
00115 c1.cd(counter);
00116 (*tbHisto)->Draw();
00117 if(counter%16 == 0 && counter>=16){
00118 c1.Update();
00119 psFile.NewPage();
00120 c1.Clear();
00121 c1.Divide(4,4);
00122 counter=0;
00123 }
00124 }
00125
00126 }
00127
00128 }
00129
00130
00131 void DTAlbertoBenvenutiTask::beginJob(){
00132
00133 if(debug)
00134 cout<<"[DTAlbertoBenvenutiTask]: BeginJob"<<endl;
00135
00136 nevents = 0;
00137
00138 }
00139
00140
00141
00142 void DTAlbertoBenvenutiTask::beginRun(const edm::Run&, const edm::EventSetup& context) {
00143
00144
00145 context.get<MuonGeometryRecord>().get(muonGeom);
00146
00147
00148 if (parameters.getUntrackedParameter<bool>("readDB", true))
00149 context.get<DTTtrigRcd>().get(tTrigMap);
00150
00151
00152 if (parameters.getParameter<bool>("performPerWireT0Calibration"))
00153 context.get<DTT0Rcd>().get(t0Map);
00154
00155 }
00156
00157
00158 void DTAlbertoBenvenutiTask::bookHistos(const DTWireId dtWire) {
00159
00160 if (debug) cout<<"[DTAlbertoBenvenutiTask]: booking"<<endl;
00161
00162 stringstream wheel; wheel << dtWire.layerId().superlayerId().chamberId().wheel();
00163 stringstream station; station << dtWire.layerId().superlayerId().chamberId().station();
00164 stringstream sector; sector << dtWire.layerId().superlayerId().chamberId().sector();
00165
00166
00167 vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00168 vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00169
00170 for (; ch_it != ch_end; ++ch_it) {
00171 DTChamberId ch = (*ch_it)->id();
00172 if(ch == dtWire.layerId().superlayerId().chamberId()){
00173 vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
00174 vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
00175
00176 for(; sl_it != sl_end; ++sl_it) {
00177 DTSuperLayerId sl = (*sl_it)->id();
00178 stringstream superLayer; superLayer << sl.superlayer();
00179 vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin();
00180 vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
00181
00182 for(; l_it != l_end; ++l_it) {
00183 DTLayerId layerId = (*l_it)->id();
00184 stringstream layer; layer << layerId.layer();
00185 const int firstWire = muonGeom->layer(layerId)->specificTopology().firstChannel();
00186 const int lastWire = muonGeom->layer(layerId)->specificTopology().lastChannel();
00187
00188 for(int wr=firstWire; wr -lastWire <= 0; wr++) {
00189
00190 stringstream wire; wire << wr;
00191 DTWireId wrId(layerId, wr);
00192
00193 string histoTag = "TimeBox";
00194 string histoName = histoTag
00195 + "_W" + wheel.str()
00196 + "_St" + station.str()
00197 + "_Sec" + sector.str()
00198 + "_SL" + superLayer.str()
00199 + "_L" + layer.str()
00200 + "_wire" + wire.str();
00201
00202 if (debug) cout<<"[DTAlbertoBenvenutiTask]: histoName "<<histoName<<endl;
00203
00204 if ( parameters.getUntrackedParameter<bool>("readDB", false) )
00205
00206 tTrigMap->get(dtWire.layerId().superlayerId(), tTrig, tTrigRMS, kFactor,
00207 DTTimeUnits::counts);
00208 else tTrig = parameters.getParameter<int>("defaultTtrig");
00209
00210 string histoTitle = histoName + " (TDC Counts)";
00211 int timeBoxGranularity = parameters.getUntrackedParameter<int>("timeBoxGranularity",4);
00212
00213 if (!parameters.getUntrackedParameter<bool>("readDB", true)) {
00214 int maxTDCCounts = 6400 * parameters.getUntrackedParameter<int>("tdcRescale", 1);
00215 TH1F *TB = new TH1F(histoName.c_str(),histoTitle.c_str(), maxTDCCounts/timeBoxGranularity, 0, maxTDCCounts);
00216 TBMap[wrId] = TB;
00217 }
00218 else {
00219 TH1F *TB = new TH1F(histoName.c_str(),histoTitle.c_str(), 2*tMax/timeBoxGranularity, tTrig-tMax, tTrig+2*tMax);
00220 TBMap[wrId] = TB;
00221 }
00222
00223 }
00224 }
00225 }
00226 }
00227 }
00228 }
00229
00230
00231 void DTAlbertoBenvenutiTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00232
00233 nevents++;
00234 if (nevents%1000 == 0 && debug) {}
00235
00236 edm::Handle<DTDigiCollection> dtdigis;
00237 e.getByLabel("dtunpacker", dtdigis);
00238
00239 bool checkNoisyChannels = parameters.getUntrackedParameter<bool>("checkNoisyChannels",false);
00240 ESHandle<DTStatusFlag> statusMap;
00241 if(checkNoisyChannels) {
00242
00243 c.get<DTStatusFlagRcd>().get(statusMap);
00244 }
00245
00246 int tdcCount = 0;
00247 DTDigiCollection::DigiRangeIterator dtLayerId_It;
00248 for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
00249 for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
00250 digiIt!=((*dtLayerId_It).second).second; ++digiIt){
00251 tdcCount++;
00252 }
00253 }
00254
00255 bool isSyncNoisy = false;
00256 if (tdcCount > maxTDCHits) isSyncNoisy = true;
00257
00258 for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
00259 for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
00260 digiIt!=((*dtLayerId_It).second).second; ++digiIt){
00261
00262 bool isNoisy = false;
00263 bool isFEMasked = false;
00264 bool isTDCMasked = false;
00265 bool isTrigMask = false;
00266 bool isDead = false;
00267 bool isNohv = false;
00268 const DTWireId wireId(((*dtLayerId_It).first), (*digiIt).wire());
00269 if(checkNoisyChannels) {
00270 statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
00271 }
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 float t0; float t0RMS;
00284 int tdcTime = (*digiIt).countsTDC();
00285
00286 if (parameters.getParameter<bool>("performPerWireT0Calibration")) {
00287 const DTWireId dtWireId(((*dtLayerId_It).first), (*digiIt).wire());
00288 t0Map->get(dtWireId, t0, t0RMS, DTTimeUnits::counts) ;
00289 tdcTime += int(round(t0));
00290 }
00291
00292
00293 if ((!isNoisy ) && (!isSyncNoisy)) {
00294
00295 if (TBMap.find(wireId) == TBMap.end()){
00296 bookHistos(wireId);
00297 TBMap[wireId]->Fill(tdcTime);
00298 }
00299 else
00300 TBMap[wireId]->Fill(tdcTime);
00301 }
00302 }
00303 }
00304 }
00305
00306