00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DQMOffline/CalibMuon/interface/DTt0DBValidation.h"
00011
00012
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 #include "DQMServices/Core/interface/MonitorElement.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.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
00032 #include <stdio.h>
00033 #include <sstream>
00034 #include <math.h>
00035 #include "TFile.h"
00036
00037 using namespace edm;
00038 using namespace std;
00039
00040
00041
00042
00043 DTt0DBValidation::DTt0DBValidation(const ParameterSet& pset) {
00044
00045 cout << "[DTt0DBValidation] Constructor called!" << endl;
00046
00047
00048 dbe = edm::Service<DQMStore>().operator->();
00049 dbe->setCurrentFolder("DT/DTDBValidation");
00050
00051
00052 labelDBRef = pset.getUntrackedParameter<string>("labelDBRef");
00053 labelDB = pset.getUntrackedParameter<string>("labelDB");
00054
00055 parameters = pset;
00056 }
00057
00058
00059 DTt0DBValidation::~DTt0DBValidation(){}
00060
00061
00062 void DTt0DBValidation::beginRun(const edm::Run& run, const EventSetup& setup) {
00063
00064 metname = "t0dbValidation";
00065 LogTrace(metname)<<"[DTt0DBValidation] Parameters initialization";
00066
00067 outputFileName = parameters.getUntrackedParameter<std::string>("OutputFileName");
00068
00069 ESHandle<DTT0> t0_Ref;
00070 setup.get<DTT0Rcd>().get(labelDBRef, t0_Ref);
00071 tZeroRefMap = &*t0_Ref;
00072 LogTrace(metname)<<"[DTt0DBValidation] reference T0 version: " << t0_Ref->version();
00073
00074 ESHandle<DTT0> t0;
00075 setup.get<DTT0Rcd>().get(labelDB, t0);
00076 tZeroMap = &*t0;
00077 LogTrace(metname)<<"[DTt0DBValidation] T0 to validate version: " << t0->version();
00078
00079
00080 for(int wheel=-2; wheel<=2; wheel++){
00081 bookHistos(wheel);
00082 wheelSummary[wheel]->Reset();
00083 }
00084
00085
00086 setup.get<MuonGeometryRecord>().get(dtGeom);
00087
00088
00089 for(DTT0::const_iterator tzero = tZeroRefMap->begin();
00090 tzero != tZeroRefMap->end(); tzero++) {
00091
00092 DTWireId wireId((*tzero).first.wheelId,
00093 (*tzero).first.stationId,
00094 (*tzero).first.sectorId,
00095 (*tzero).first.slId,
00096 (*tzero).first.layerId,
00097 (*tzero).first.cellId);
00098 float t0mean;
00099 float t0rms;
00100 tZeroRefMap->get( wireId, t0mean, t0rms, DTTimeUnits::counts );
00101 LogTrace(metname)<< "Ref Wire: " << wireId <<endl
00102 << " T0 mean (TDC counts): " << t0mean
00103 << " T0_rms (TDC counts): " << t0rms;
00104
00105 t0RefMap[wireId].push_back(t0mean);
00106 t0RefMap[wireId].push_back(t0rms);
00107 }
00108
00109
00110 for(DTT0::const_iterator tzero = tZeroMap->begin();
00111 tzero != tZeroMap->end(); tzero++) {
00112
00113 DTWireId wireId((*tzero).first.wheelId,
00114 (*tzero).first.stationId,
00115 (*tzero).first.sectorId,
00116 (*tzero).first.slId,
00117 (*tzero).first.layerId,
00118 (*tzero).first.cellId);
00119 float t0mean;
00120 float t0rms;
00121 tZeroMap->get( wireId, t0mean, t0rms, DTTimeUnits::counts );
00122 LogTrace(metname)<< "Wire: " << wireId <<endl
00123 << " T0 mean (TDC counts): " << t0mean
00124 << " T0_rms (TDC counts): " << t0rms;
00125
00126 t0Map[wireId].push_back(t0mean);
00127 t0Map[wireId].push_back(t0rms);
00128 }
00129
00130 double difference=0;
00131 for(map<DTWireId, vector<float> >::const_iterator theMap = t0RefMap.begin();
00132 theMap != t0RefMap.end();
00133 theMap++) {
00134 if(t0Map.find((*theMap).first) != t0Map.end()) {
00135
00136
00137 difference = t0Map[(*theMap).first][0]-(*theMap).second[0];
00138
00139
00140 DTLayerId layerId = (*theMap).first.layerId();
00141 if(t0DiffHistos.find(layerId) == t0DiffHistos.end()) {
00142 const DTTopology& dtTopo = dtGeom->layer(layerId)->specificTopology();
00143 const int firstWire = dtTopo.firstChannel();
00144 const int lastWire = dtTopo.lastChannel();
00145 bookHistos(layerId, firstWire, lastWire);
00146 }
00147
00148 cout<< "Filling the histo for wire: "<<(*theMap).first
00149 <<" difference: "<<difference<<endl;
00150 t0DiffHistos[layerId]->Fill((*theMap).first.wire(),difference);
00151
00152 }
00153 }
00154
00155 }
00156
00157
00158 void DTt0DBValidation::endJob() {
00159
00160
00161 string testCriterionName = parameters.getUntrackedParameter<string>("t0TestName","t0DifferenceInRange");
00162 for(map<DTLayerId, MonitorElement*>::const_iterator hDiff = t0DiffHistos.begin();
00163 hDiff != t0DiffHistos.end();
00164 hDiff++) {
00165 const QReport * theDiffQReport = (*hDiff).second->getQReport(testCriterionName);
00166 if(theDiffQReport) {
00167 vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
00168 for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin();
00169 channel != badChannels.end(); channel++) {
00170 cout << "layer:"<<(*hDiff).first<<" Bad mean channels: "<<(*channel).getBin()<<" Contents : "<<(*channel).getContents()<<endl;
00171
00172 int xBin = ((*hDiff).first.station()-1)*12+(*hDiff).first.layer()+4*((*hDiff).first.superlayer()-1);
00173 if((*hDiff).first.station()==4 && (*hDiff).first.superlayer()==3)
00174 xBin = ((*hDiff).first.station()-1)*12+(*hDiff).first.layer()+4*((*hDiff).first.superlayer()-2);
00175 wheelSummary[(*hDiff).first.wheel()]->Fill(xBin,(*hDiff).first.sector());
00176
00177 }
00178 cout << "-------- layer: "<<(*hDiff).first<<" "<<theDiffQReport->getMessage()<<" ------- "<<theDiffQReport->getStatus()<<endl;
00179 }
00180 }
00181
00182
00183 dbe->save(outputFileName);
00184
00185 }
00186
00187
00188 void DTt0DBValidation::bookHistos(DTLayerId lId, int firstWire, int lastWire) {
00189
00190 LogTrace(metname)<< " Booking histos for L: " << lId;
00191
00192
00193 stringstream wheel; wheel << lId.superlayerId().chamberId().wheel();
00194 stringstream station; station << lId.superlayerId().chamberId().station();
00195 stringstream sector; sector << lId.superlayerId().chamberId().sector();
00196 stringstream superLayer; superLayer << lId.superlayerId().superlayer();
00197 stringstream layer; layer << lId.layer();
00198
00199 string lHistoName =
00200 "_W" + wheel.str() +
00201 "_St" + station.str() +
00202 "_Sec" + sector.str() +
00203 "_SL" + superLayer.str()+
00204 "_L" + layer.str();
00205
00206 dbe->setCurrentFolder("DT/t0Validation/Wheel" + wheel.str() +
00207 "/Station" + station.str() +
00208 "/Sector" + sector.str() +
00209 "/SuperLayer" +superLayer.str());
00210
00211 MonitorElement * hDifference;
00212 hDifference = dbe->book1D("hDifference"+lHistoName, "difference between the two t0 values",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5);
00213
00214 t0DiffHistos[lId] = hDifference;
00215 }
00216
00217
00218 void DTt0DBValidation::bookHistos(int wheel) {
00219 dbe->setCurrentFolder("DT/t0Validation/Summary");
00220 stringstream wh; wh << wheel;
00221 wheelSummary[wheel]= dbe->book2D("summaryWrongT0_W"+wh.str(), "W"+wh.str()+": summary of wrong t0 differences",44,1,45,14,1,15);
00222 wheelSummary[wheel]->setBinLabel(1,"M1L1",1);
00223 wheelSummary[wheel]->setBinLabel(2,"M1L2",1);
00224 wheelSummary[wheel]->setBinLabel(3,"M1L3",1);
00225 wheelSummary[wheel]->setBinLabel(4,"M1L4",1);
00226 wheelSummary[wheel]->setBinLabel(5,"M1L5",1);
00227 wheelSummary[wheel]->setBinLabel(6,"M1L6",1);
00228 wheelSummary[wheel]->setBinLabel(7,"M1L7",1);
00229 wheelSummary[wheel]->setBinLabel(8,"M1L8",1);
00230 wheelSummary[wheel]->setBinLabel(9,"M1L9",1);
00231 wheelSummary[wheel]->setBinLabel(10,"M1L10",1);
00232 wheelSummary[wheel]->setBinLabel(11,"M1L11",1);
00233 wheelSummary[wheel]->setBinLabel(12,"M1L12",1);
00234 wheelSummary[wheel]->setBinLabel(13,"M2L1",1);
00235 wheelSummary[wheel]->setBinLabel(14,"M2L2",1);
00236 wheelSummary[wheel]->setBinLabel(15,"M2L3",1);
00237 wheelSummary[wheel]->setBinLabel(16,"M2L4",1);
00238 wheelSummary[wheel]->setBinLabel(17,"M2L5",1);
00239 wheelSummary[wheel]->setBinLabel(18,"M2L6",1);
00240 wheelSummary[wheel]->setBinLabel(19,"M2L7",1);
00241 wheelSummary[wheel]->setBinLabel(20,"M2L8",1);
00242 wheelSummary[wheel]->setBinLabel(21,"M2L9",1);
00243 wheelSummary[wheel]->setBinLabel(22,"M2L10",1);
00244 wheelSummary[wheel]->setBinLabel(23,"M2L11",1);
00245 wheelSummary[wheel]->setBinLabel(24,"M2L12",1);
00246 wheelSummary[wheel]->setBinLabel(25,"M3L1",1);
00247 wheelSummary[wheel]->setBinLabel(26,"M3L2",1);
00248 wheelSummary[wheel]->setBinLabel(27,"M3L3",1);
00249 wheelSummary[wheel]->setBinLabel(28,"M3L4",1);
00250 wheelSummary[wheel]->setBinLabel(29,"M3L5",1);
00251 wheelSummary[wheel]->setBinLabel(30,"M3L6",1);
00252 wheelSummary[wheel]->setBinLabel(31,"M3L7",1);
00253 wheelSummary[wheel]->setBinLabel(32,"M3L8",1);
00254 wheelSummary[wheel]->setBinLabel(33,"M3L9",1);
00255 wheelSummary[wheel]->setBinLabel(34,"M3L10",1);
00256 wheelSummary[wheel]->setBinLabel(35,"M3L11",1);
00257 wheelSummary[wheel]->setBinLabel(36,"M3L12",1);
00258 wheelSummary[wheel]->setBinLabel(37,"M4L1",1);
00259 wheelSummary[wheel]->setBinLabel(38,"M4L2",1);
00260 wheelSummary[wheel]->setBinLabel(39,"M4L3",1);
00261 wheelSummary[wheel]->setBinLabel(40,"M4L4",1);
00262 wheelSummary[wheel]->setBinLabel(41,"M4L5",1);
00263 wheelSummary[wheel]->setBinLabel(42,"M4L6",1);
00264 wheelSummary[wheel]->setBinLabel(43,"M4L7",1);
00265 wheelSummary[wheel]->setBinLabel(44,"M4L8",1);
00266 }