CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/DTMonitorModule/src/DTTriggerEfficiencyTask.cc

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