00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DQM/DTMonitorModule/src/DTTriggerEfficiencyTask.h"
00011
00012
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 #include "FWCore/Utilities/interface/InputTag.h"
00015
00016
00017 #include "DQM/DTMonitorModule/interface/DTTrigGeomUtils.h"
00018 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h"
00019 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h"
00020
00021
00022 #include "DataFormats/GeometryVector/interface/Pi.h"
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/DTSuperLayer.h"
00027 #include "Geometry/DTGeometry/interface/DTTopology.h"
00028
00029
00030 #include <DataFormats/DTDigi/interface/DTDigi.h>
00031 #include <DataFormats/DTDigi/interface/DTDigiCollection.h>
00032
00033
00034
00035 #include"TH1.h"
00036 #include"TAxis.h"
00037
00038 #include <sstream>
00039 #include <iostream>
00040 #include <fstream>
00041
00042
00043 using namespace edm;
00044 using namespace std;
00045
00046 DTTriggerEfficiencyTask::DTTriggerEfficiencyTask(const edm::ParameterSet& ps) : trigGeomUtils(0) {
00047
00048 LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: Constructor" << endl;
00049
00050 parameters = ps;
00051 dbe = edm::Service<DQMStore>().operator->();
00052
00053 }
00054
00055
00056 DTTriggerEfficiencyTask::~DTTriggerEfficiencyTask() {
00057
00058 LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: analyzed " << nevents << " events" << endl;
00059
00060 }
00061
00062
00063 void DTTriggerEfficiencyTask::beginJob(){
00064
00065 LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: BeginJob" << endl;
00066
00067 detailedPlots = parameters.getUntrackedParameter<bool>("detailedAnalysis",false);
00068 processDCC = parameters.getUntrackedParameter<bool>("processDCC",true);
00069 processDDU = parameters.getUntrackedParameter<bool>("processDDU",true);
00070 minBXDDU = parameters.getUntrackedParameter<int>("minBXDDU",0);
00071 maxBXDDU = parameters.getUntrackedParameter<int>("maxBXDDU",20);
00072
00073 nevents = 0;
00074
00075 for (int wh=-2;wh<=2;++wh){
00076 if (processDCC) {
00077 bookWheelHistos(wh,"DCC_TrigEffDenum");
00078 bookWheelHistos(wh,"DCC_TrigEffNum");
00079 bookWheelHistos(wh,"DCC_TrigEffCorrNum");
00080 if (detailedPlots) {
00081 for (int stat=1;stat<=4;++stat){
00082 for (int sect=1;sect<=12;++sect){
00083 DTChamberId dtChId(wh,stat,sect);
00084 bookChamberHistos(dtChId,"DCC_TrackPosvsAngleAnyQual","Segment");
00085 bookChamberHistos(dtChId,"DCC_TrackPosvsAngleCorr","Segment");
00086 bookChamberHistos(dtChId,"DCC_TrackPosvsAngle","Segment");
00087 }
00088 }
00089 }
00090 }
00091 if (processDDU) {
00092 bookWheelHistos(wh,"DDU_TrigEffDenum");
00093 bookWheelHistos(wh,"DDU_TrigEffNum");
00094 bookWheelHistos(wh,"DDU_TrigEffCorrNum");
00095 if (detailedPlots) {
00096 for (int stat=1;stat<=4;++stat){
00097 for (int sect=1;sect<=12;++sect){
00098 DTChamberId dtChId(wh,stat,sect);
00099 bookChamberHistos(dtChId,"DDU_TrackPosvsAngleAnyQual","Segment");
00100 bookChamberHistos(dtChId,"DDU_TrackPosvsAngleCorr","Segment");
00101 bookChamberHistos(dtChId,"DDU_TrackPosvsAngle","Segment");
00102 }
00103 }
00104 }
00105 }
00106 }
00107
00108 }
00109
00110 void DTTriggerEfficiencyTask::beginRun(const edm::Run& run, const edm::EventSetup& context){
00111
00112 LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: BeginRun" << endl;
00113
00114 context.get<MuonGeometryRecord>().get(muonGeom);
00115 trigGeomUtils = new DTTrigGeomUtils(muonGeom);
00116
00117 }
00118
00119 void DTTriggerEfficiencyTask::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00120
00121 LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") <<"[DTTriggerEfficiencyTask]: Begin of LS transition"<<endl;
00122
00123 }
00124
00125
00126 void DTTriggerEfficiencyTask::endJob(){
00127
00128 LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: analyzed " << nevents << " events" << endl;
00129
00130
00131
00132 }
00133
00134
00135 void DTTriggerEfficiencyTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00136
00137 nevents++;
00138
00139 if (!hasRPCTriggers(e)) { return; }
00140
00141 InputTag inputTagDCC = parameters.getUntrackedParameter<edm::InputTag>("inputTagDCC");
00142 InputTag inputTagDDU = parameters.getUntrackedParameter<edm::InputTag>("inputTagDDU");
00143 InputTag inputTagSEG = parameters.getUntrackedParameter<edm::InputTag>("inputTagSEG");
00144
00145 for (int i=0;i<5;++i){
00146 for (int j=0;j<6;++j){
00147 for (int k=0;k<13;++k){
00148 phCodeBestDCC[j][i][k] = -1;
00149 phCodeBestDDU[j][i][k] = -1;
00150 }
00151 }
00152 }
00153
00154
00155 edm::Handle<L1MuDTChambPhContainer> l1DTTPGPh;
00156 e.getByLabel(inputTagDCC,l1DTTPGPh);
00157 vector<L1MuDTChambPhDigi>* phTrigs = l1DTTPGPh->getContainer();
00158
00159 vector<L1MuDTChambPhDigi>::const_iterator iph = phTrigs->begin();
00160 vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
00161 for(; iph !=iphe ; ++iph) {
00162
00163 int phwheel = iph->whNum();
00164 int phsec = iph->scNum() + 1;
00165 int phst = iph->stNum();
00166 int phcode = iph->code();
00167
00168 if(phcode>phCodeBestDCC[phwheel+3][phst][phsec] && phcode<7) {
00169 phCodeBestDCC[phwheel+3][phst][phsec]=phcode;
00170 phBestDCC[phwheel+3][phst][phsec] = &(*iph);
00171 }
00172 }
00173
00174
00175 Handle<DTLocalTriggerCollection> trigsDDU;
00176 e.getByLabel(inputTagDDU,trigsDDU);
00177 DTLocalTriggerCollection::DigiRangeIterator detUnitIt;
00178
00179 for (detUnitIt=trigsDDU->begin();detUnitIt!=trigsDDU->end();++detUnitIt){
00180
00181 const DTChamberId& id = (*detUnitIt).first;
00182 const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
00183
00184 int wh = id.wheel();
00185 int sec = id.sector();
00186 int st = id.station();
00187
00188 for (DTLocalTriggerCollection::const_iterator trigIt = range.first; trigIt!=range.second;++trigIt){
00189
00190 int quality = trigIt->quality();
00191
00192 if(quality>-1 && quality<7 &&
00193 quality>phCodeBestDDU[wh+3][st][sec]) {
00194 phCodeBestDDU[wh+3][st][sec]=quality;
00195 phBestDDU[wh+3][st][sec] = &(*trigIt);
00196 }
00197 }
00198 }
00199
00200
00201 vector<const DTRecSegment4D*> best4DSegments;
00202
00203 Handle<DTRecSegment4DCollection> segments4D;
00204 e.getByLabel(inputTagSEG, segments4D);
00205 DTRecSegment4DCollection::const_iterator track;
00206 DTRecSegment4DCollection::id_iterator chamberId;
00207
00208 for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId){
00209
00210 DTRecSegment4DCollection::range range = segments4D->get(*chamberId);
00211 const DTRecSegment4D* tmpBest=0;
00212 int tmpHit = 0;
00213 int hit = 0;
00214
00215 for ( track = range.first; track != range.second; ++track){
00216 if( (*track).hasPhi() ) {
00217 hit = (*track).phiSegment()->degreesOfFreedom()+2;
00218 if ( hit>tmpHit ){
00219 tmpBest = &(*track);
00220 tmpHit = hit;
00221 int sec = (*track).chamberId().sector();
00222 if (sec==13){
00223 sec=4;
00224 }
00225 else if (sec==14){
00226 sec=10;
00227 }
00228 }
00229 }
00230 }
00231 if (tmpBest) {
00232 best4DSegments.push_back(tmpBest);
00233 }
00234 }
00235
00236
00237 vector<const DTRecSegment4D*>::const_iterator btrack;
00238 for ( btrack = best4DSegments.begin(); btrack != best4DSegments.end(); ++btrack ){
00239
00240 int wheel = (*btrack)->chamberId().wheel();
00241 int station = (*btrack)->chamberId().station();
00242 int scsector = 0;
00243 float x, xdir, y, ydir;
00244 trigGeomUtils->computeSCCoordinates((*btrack),scsector,x,xdir,y,ydir);
00245 int nHitsPhi = (*btrack)->phiSegment()->degreesOfFreedom()+2;
00246 DTChamberId dtChId(wheel,station,scsector);
00247 uint32_t indexCh = dtChId.rawId();
00248 map<string, MonitorElement*> &innerChME = chamberHistos[indexCh];
00249 map<string, MonitorElement*> &innerWhME = wheelHistos[wheel];
00250
00251 if (fabs(xdir)<30. && nHitsPhi>=7){
00252
00253 if (processDCC) {
00254 int qual = phCodeBestDCC[wheel+3][station][scsector];
00255 innerWhME.find("DCC_TrigEffDenum")->second->Fill(scsector,station);
00256 if ( qual>=0 && qual<7 ) {
00257 innerWhME.find("DCC_TrigEffNum")->second->Fill(scsector,station);
00258 if ( qual>=4 ) {
00259 innerWhME.find("DCC_TrigEffCorrNum")->second->Fill(scsector,station);
00260
00261
00262
00263 }
00264 }
00265 if (detailedPlots) {
00266 innerChME.find("DCC_TrackPosvsAngle")->second->Fill(xdir,x);
00267 if ( qual>=0 && qual<7 ) {
00268 innerChME.find("DCC_TrackPosvsAngleAnyQual")->second->Fill(xdir,x);
00269 if ( qual>=4 ) {
00270 innerChME.find("DCC_TrackPosvsAngleCorr")->second->Fill(xdir,x);
00271
00272
00273
00274 }
00275 }
00276 }
00277 }
00278
00279 if (processDDU) {
00280 int qual = phCodeBestDDU[wheel+3][station][scsector];
00281 innerWhME.find("DDU_TrigEffDenum")->second->Fill(scsector,station);
00282 bool qualOK = qual>=0 && qual<7;
00283 int bx = qualOK ? phBestDDU[wheel+3][station][scsector]->bx() : -10;
00284 if ( qualOK && bx>=minBXDDU && bx<=maxBXDDU ) {
00285 innerWhME.find("DDU_TrigEffNum")->second->Fill(scsector,station);
00286 if ( qual>=4 ) {
00287 innerWhME.find("DDU_TrigEffCorrNum")->second->Fill(scsector,station);
00288
00289
00290
00291 }
00292 }
00293 if (detailedPlots) {
00294 innerChME.find("DDU_TrackPosvsAngle")->second->Fill(xdir,x);
00295 if ( qualOK && bx>+minBXDDU && bx<maxBXDDU ) {
00296 innerChME.find("DDU_TrackPosvsAngleAnyQual")->second->Fill(xdir,x);
00297 if ( qual>=4 ) {
00298 innerChME.find("DDU_TrackPosvsAngleCorr")->second->Fill(xdir,x);
00299
00300
00301
00302 }
00303 }
00304 }
00305 }
00306 }
00307 }
00308
00309 }
00310
00311 bool DTTriggerEfficiencyTask::hasRPCTriggers(const edm::Event& e) {
00312
00313 InputTag inputTagGMT = parameters.getUntrackedParameter<edm::InputTag>("inputTagGMT");
00314 edm::Handle<L1MuGMTReadoutCollection> gmtrc;
00315 e.getByLabel(inputTagGMT,gmtrc);
00316
00317 std::vector<L1MuGMTReadoutRecord> gmt_records = gmtrc->getRecords();
00318 std::vector<L1MuGMTReadoutRecord>::const_iterator igmtrr;
00319
00320 for(igmtrr=gmt_records.begin(); igmtrr!=gmt_records.end(); igmtrr++) {
00321 if( (*igmtrr).getBxInEvent()==0 ) {
00322 std::vector<L1MuRegionalCand>::const_iterator iter1;
00323 std::vector<L1MuRegionalCand> rmc = (*igmtrr).getBrlRPCCands();
00324 for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00325 if ( !(*iter1).empty() ) {
00326 return true;
00327 }
00328 }
00329 }
00330 }
00331
00332 return false;
00333
00334 }
00335
00336 void DTTriggerEfficiencyTask::bookChamberHistos(const DTChamberId& dtCh, string histoTag, string folder) {
00337
00338 int wh = dtCh.wheel();
00339 int sc = dtCh.sector();
00340 int st = dtCh.station();
00341 stringstream wheel; wheel << wh;
00342 stringstream station; station << st;
00343 stringstream sector; sector << sc;
00344
00345 string histoType = histoTag.substr(4,histoTag.find("_",4)-4);
00346 string hwFolder = topFolder(histoTag.substr(0,3)=="DCC");
00347 string bookingFolder = hwFolder + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() + "/" + folder;
00348 string histoName = histoTag + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00349
00350 dbe->setCurrentFolder(bookingFolder);
00351
00352 LogTrace ("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: booking " << bookingFolder << "/" << histoName << endl;
00353
00354 if( histoType.find("TrackPosvsAngle") == 0 ){
00355 float min, max;
00356 int nbins;
00357 trigGeomUtils->phiRange(dtCh,min,max,nbins,20);
00358 string histoLabel = "Position vs Angle (phi)";
00359 if (histoType.find("Corr") != string::npos) histoLabel += " for correlated triggers";
00360 else if (histoType.find("AnyQual") != string::npos) histoLabel += " for any qual triggers";
00361 (chamberHistos[dtCh.rawId()])[histoTag] = dbe->book2D(histoName,histoLabel,12,-30.,30.,nbins,min,max);
00362 return ;
00363 }
00364
00365 }
00366
00367 void DTTriggerEfficiencyTask::bookWheelHistos(int wheel,string hTag,string folder) {
00368
00369 stringstream wh; wh << wheel;
00370 string basedir;
00371 bool isDCC = hTag.substr(0,3)=="DCC" ;
00372 if (hTag.find("Summary") != string::npos ) {
00373 basedir = topFolder(isDCC);
00374 } else {
00375 basedir = topFolder(isDCC) + "Wheel" + wh.str() + "/" ;
00376
00377 }
00378 if (folder != "") {
00379 basedir += folder +"/" ;
00380 }
00381 dbe->setCurrentFolder(basedir);
00382
00383 string hname = hTag+ "_W" + wh.str();
00384
00385 LogTrace("DTDQM|DTMonitorModule|DTTriggerEfficiencyTask") << "[DTTriggerEfficiencyTask]: booking "<< basedir << hname;
00386
00387
00388
00389 MonitorElement* me = dbe->book2D(hname.c_str(),hname.c_str(),12,1,13,4,1,5);
00390
00391 me->setBinLabel(1,"MB1",2);
00392 me->setBinLabel(2,"MB2",2);
00393 me->setBinLabel(3,"MB3",2);
00394 me->setBinLabel(4,"MB4",2);
00395 me->setAxisTitle("Sector",1);
00396
00397 wheelHistos[wheel][hTag] = me;
00398 return;
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 }
00414