CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/DTMonitorModule/src/DTLocalTriggerTask.cc

Go to the documentation of this file.
00001 /*
00002  * \file DTLocalTriggerTask.cc
00003  * 
00004  * $Date: 2011/11/12 09:18:42 $
00005  * $Revision: 1.39 $
00006  * \author M. Zanetti - INFN Padova
00007  *
00008 */
00009 
00010 #include "DQM/DTMonitorModule/src/DTLocalTriggerTask.h"
00011 
00012 // Framework
00013 #include "FWCore/Framework/interface/EventSetup.h"
00014 
00015 // DT trigger
00016 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h"
00017 #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h"
00018 #include "DataFormats/LTCDigi/interface/LTCDigi.h"
00019 #include "DQM/DTMonitorModule/interface/DTTrigGeomUtils.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/DTTopology.h"
00027 
00028 //Root
00029 #include"TH1.h"
00030 #include"TAxis.h"
00031 
00032 #include <sstream>
00033 #include <iostream>
00034 #include <fstream>
00035 
00036 
00037 using namespace edm;
00038 using namespace std;
00039 
00040 DTLocalTriggerTask::DTLocalTriggerTask(const edm::ParameterSet& ps) : trigGeomUtils(0) {
00041   
00042   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: Constructor"<<endl;
00043 
00044   tpMode           = ps.getUntrackedParameter<bool>("testPulseMode", false);
00045   detailedAnalysis = ps.getUntrackedParameter<bool>("detailedAnalysis", false);
00046   doDCCTheta       = ps.getUntrackedParameter<bool>("enableDCCTheta", false);
00047   
00048   if (tpMode) {
00049     baseFolderDCC = "DT/11-LocalTriggerTP-DCC/";
00050     baseFolderDDU = "DT/12-LocalTriggerTP-DDU/";
00051   }
00052   else {
00053     baseFolderDCC = "DT/03-LocalTrigger-DCC/";
00054     baseFolderDDU = "DT/04-LocalTrigger-DDU/";
00055   }
00056 
00057   parameters = ps;
00058   
00059   dbe = edm::Service<DQMStore>().operator->();
00060 
00061 }
00062 
00063 
00064 DTLocalTriggerTask::~DTLocalTriggerTask() {
00065 
00066   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: analyzed " << nevents << " events" << endl;
00067   if (trigGeomUtils) { delete trigGeomUtils; }
00068 
00069 }
00070 
00071 
00072 void DTLocalTriggerTask::beginJob(){
00073  
00074   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: BeginJob" << endl;
00075 
00076   nevents = 0;
00077 
00078 }
00079 
00080 void DTLocalTriggerTask::beginRun(const edm::Run& run, const edm::EventSetup& context) {
00081 
00082   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: BeginRun" << endl;   
00083 
00084   context.get<MuonGeometryRecord>().get(muonGeom);
00085   trigGeomUtils = new DTTrigGeomUtils(muonGeom);
00086 
00087   if(parameters.getUntrackedParameter<bool>("staticBooking", true)) {  // Static histo booking
00088    
00089     vector<string> trigSources;
00090     if(parameters.getUntrackedParameter<bool>("localrun", true)) {
00091       trigSources.push_back("");
00092     }
00093     else {
00094       trigSources.push_back("_DTonly");
00095       trigSources.push_back("_NoDT");
00096       trigSources.push_back("_DTalso");
00097     }
00098     vector<string>::const_iterator trigSrcIt  = trigSources.begin();
00099     vector<string>::const_iterator trigSrcEnd = trigSources.end();
00100    
00101     if(parameters.getUntrackedParameter<bool>("process_dcc", true)) {
00102       bookBarrelHistos("DCC_ErrorsChamberID");
00103     }
00104 
00105     if (tpMode) {
00106       for (int stat=1;stat<5;++stat){
00107         for (int wh=-2;wh<3;++wh){
00108           for (int sect=1;sect<13;++sect){
00109             DTChamberId dtChId(wh,stat,sect);
00110             
00111             if (parameters.getUntrackedParameter<bool>("process_dcc", true)){ // DCC data
00112               bookHistos(dtChId,"LocalTriggerPhi","DCC_BXvsQual"+(*trigSrcIt));
00113               bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhirad"+(*trigSrcIt));
00114             }
00115             
00116             if (parameters.getUntrackedParameter<bool>("process_ros", true)){ // DDU data             
00117               bookHistos(dtChId,"LocalTriggerPhi","DDU_BXvsQual"+(*trigSrcIt));
00118             }
00119             
00120           }
00121         }
00122       } // end of loop
00123     }
00124     else {
00125       for (;trigSrcIt!=trigSrcEnd;++trigSrcIt){
00126         for (int wh=-2;wh<3;++wh){
00127           if (parameters.getUntrackedParameter<bool>("process_dcc", true) &&
00128               parameters.getUntrackedParameter<bool>("process_ros", true)){ // DCC+DDU data
00129             bookWheelHistos(wh,"COM_BXDiff"+(*trigSrcIt));
00130           }
00131           for (int sect=1;sect<13;++sect){
00132             for (int stat=1;stat<5;++stat){
00133               DTChamberId dtChId(wh,stat,sect);
00134               if (parameters.getUntrackedParameter<bool>("process_dcc", true)){ // DCC data
00135               
00136                 bookHistos(dtChId,"LocalTriggerPhi","DCC_BXvsQual"+(*trigSrcIt));
00137                 if (detailedAnalysis) {
00138                   bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhirad"+(*trigSrcIt));
00139                   bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhibend"+(*trigSrcIt));
00140                 }
00141                 bookHistos(dtChId,"LocalTriggerPhi","DCC_Flag1stvsQual"+(*trigSrcIt));
00142                 bookHistos(dtChId,"LocalTriggerPhi","DCC_BestQual"+(*trigSrcIt));
00143                 if (stat!=4 && doDCCTheta){                                                  
00144                   bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsBX"+(*trigSrcIt));
00145 //                bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsQual"+(*trigSrcIt));  // DCC theta quality not available!        
00146 //                bookHistos(dtChId,"LocalTriggerTheta","DCC_ThetaBXvsQual"+(*trigSrcIt));
00147 //                bookHistos(dtChId,"LocalTriggerTheta","DCC_ThetaBestQual"+(*trigSrcIt));
00148                 }
00149               
00150                 if (parameters.getUntrackedParameter<bool>("process_seg", true)){ // DCC + Segemnt
00151                   bookHistos(dtChId,"Segment","DCC_PhitkvsPhitrig"+(*trigSrcIt));
00152                   bookHistos(dtChId,"Segment","DCC_PhibtkvsPhibtrig"+(*trigSrcIt));
00153                   bookHistos(dtChId,"Segment","DCC_PhiResidual"+(*trigSrcIt));
00154                   bookHistos(dtChId,"Segment","DCC_PhiResidualvsLUTPhi"+(*trigSrcIt));
00155                   bookHistos(dtChId,"Segment","DCC_PhibResidual"+(*trigSrcIt));
00156                   bookHistos(dtChId,"Segment","DCC_HitstkvsQualtrig"+(*trigSrcIt));
00157                   bookHistos(dtChId,"Segment","DCC_TrackPosvsAngle"+(*trigSrcIt));
00158                   bookHistos(dtChId,"Segment","DCC_TrackPosvsAngleandTrig"+(*trigSrcIt));
00159                   bookHistos(dtChId,"Segment","DCC_TrackPosvsAngleandTrigHHHL"+(*trigSrcIt));
00160                   if(stat!=4){
00161                     bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngle"+(*trigSrcIt)); // theta view
00162                     bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngleandTrig"+(*trigSrcIt));
00163 //                  bookHistos(dtChId,"Segment","DCC_TrackThetaPosvsAngleandTrigH"+(*trigSrcIt));     // DCC theta quality not available!
00164                   }
00165                 }
00166               
00167               }
00168             
00169               if (parameters.getUntrackedParameter<bool>("process_ros", true)){ // DDU data
00170               
00171                 bookHistos(dtChId,"LocalTriggerPhi","DDU_BXvsQual"+(*trigSrcIt));
00172                 bookHistos(dtChId,"LocalTriggerPhi","DDU_Flag1stvsQual"+(*trigSrcIt));
00173                 bookHistos(dtChId,"LocalTriggerPhi","DDU_BestQual"+(*trigSrcIt));
00174                 if(stat!=4){                                                    // theta view
00175                   bookHistos(dtChId,"LocalTriggerTheta","DDU_ThetaBXvsQual"+(*trigSrcIt));
00176                   bookHistos(dtChId,"LocalTriggerTheta","DDU_ThetaBestQual"+(*trigSrcIt));
00177                 }
00178               
00179                 if (parameters.getUntrackedParameter<bool>("process_seg", true)){ // DDU + Segment
00180                   bookHistos(dtChId,"Segment","DDU_HitstkvsQualtrig"+(*trigSrcIt));
00181                   bookHistos(dtChId,"Segment","DDU_TrackPosvsAngle"+(*trigSrcIt));
00182                   bookHistos(dtChId,"Segment","DDU_TrackPosvsAngleandTrig"+(*trigSrcIt));
00183                   bookHistos(dtChId,"Segment","DDU_TrackPosvsAngleandTrigHHHL"+(*trigSrcIt));
00184                   if(stat!=4){
00185                     bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngle"+(*trigSrcIt)); // theta view
00186                     bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngleandTrig"+(*trigSrcIt));
00187                     bookHistos(dtChId,"Segment","DDU_TrackThetaPosvsAngleandTrigH"+(*trigSrcIt));
00188                   }
00189                 }
00190               
00191               }
00192             
00193               if (parameters.getUntrackedParameter<bool>("process_dcc", true) &&
00194                   parameters.getUntrackedParameter<bool>("process_ros", true)){ // DCC+DDU data
00195                 bookHistos(dtChId,"LocalTriggerPhi","COM_QualDDUvsQualDCC"+(*trigSrcIt));
00196               }
00197             
00198             }
00199           }
00200           for (int sect=13;sect<15;++sect){
00201             DTChamberId dtChId(wh,4,sect);
00202             if (parameters.getUntrackedParameter<bool>("process_dcc", true) &&
00203                 parameters.getUntrackedParameter<bool>("process_seg", true)){ // DCC+SEG LUTs data
00204               bookHistos(dtChId,"Segment","DCC_PhitkvsPhitrig"+(*trigSrcIt));
00205               bookHistos(dtChId,"Segment","DCC_PhibtkvsPhibtrig"+(*trigSrcIt));
00206               bookHistos(dtChId,"Segment","DCC_PhiResidual"+(*trigSrcIt));
00207               bookHistos(dtChId,"Segment","DCC_PhiResidualvsLUTPhi"+(*trigSrcIt));
00208               bookHistos(dtChId,"Segment","DCC_PhibResidual"+(*trigSrcIt));
00209             }
00210           }     
00211         }                 
00212       }// end of loop
00213     }
00214     
00215   }
00216 
00217 }
00218 
00219 
00220 void DTLocalTriggerTask::beginLuminosityBlock(const LuminosityBlock& lumiSeg, const EventSetup& context) {
00221   
00222   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: Begin of LS transition" << endl;
00223   
00224   if(lumiSeg.id().luminosityBlock()%parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
00225     for(map<uint32_t, map<string, MonitorElement*> > ::const_iterator histo = digiHistos.begin();
00226         histo != digiHistos.end();
00227         histo++) {
00228       for(map<string, MonitorElement*> ::const_iterator ht = (*histo).second.begin();
00229           ht != (*histo).second.end();
00230           ht++) {
00231         (*ht).second->Reset();
00232       }
00233     }
00234   }
00235   
00236 }
00237 
00238 
00239 void DTLocalTriggerTask::endJob(){
00240 
00241   LogVerbatim("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: analyzed " << nevents << " events" << endl;
00242   if (parameters.getUntrackedParameter<bool>("process_dcc", true)) dbe->rmdir(topFolder(0)); //DDU folder
00243   if (parameters.getUntrackedParameter<bool>("process_ros", true)) dbe->rmdir(topFolder(1)); //DCC folder
00244 
00245 }
00246 
00247 
00248 void DTLocalTriggerTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00249   
00250   string dcc_label  = parameters.getUntrackedParameter<string>("dcc_label", "dttpgprod");
00251   string ros_label  = parameters.getUntrackedParameter<string>("ros_label", "dtunpacker");
00252   string seg_label  = parameters.getUntrackedParameter<string>("seg_label", "dt4DSegments");
00253 
00254   if (!nevents){
00255 
00256     edm::Handle<L1MuDTChambPhContainer> l1DTTPGPh;
00257     e.getByLabel(dcc_label, l1DTTPGPh);
00258     edm::Handle<L1MuDTChambThContainer> l1DTTPGTh;
00259     e.getByLabel(dcc_label, l1DTTPGTh);
00260     useDCC = (l1DTTPGPh.isValid() || l1DTTPGTh.isValid()) && parameters.getUntrackedParameter<bool>("process_dcc", true) ;
00261 
00262     Handle<DTLocalTriggerCollection> l1DDUTrigs;
00263     e.getByLabel(ros_label,l1DDUTrigs);
00264     useDDU = l1DDUTrigs.isValid() && parameters.getUntrackedParameter<bool>("process_ros", true) ;
00265 
00266     Handle<DTRecSegment4DCollection> all4DSegments;
00267     e.getByLabel(seg_label, all4DSegments);  
00268     useSEG = all4DSegments.isValid() && parameters.getUntrackedParameter<bool>("process_seg", true) ;
00269     
00270   }
00271 
00272   nevents++;
00273     
00274   triggerSource(e);  
00275 
00276   if ( useDCC ) {   
00277     edm::Handle<L1MuDTChambPhContainer> l1DTTPGPh;
00278     e.getByLabel(dcc_label,l1DTTPGPh);
00279     vector<L1MuDTChambPhDigi>*  l1PhTrig = l1DTTPGPh->getContainer();
00280 
00281     edm::Handle<L1MuDTChambThContainer> l1DTTPGTh;
00282     e.getByLabel(dcc_label,l1DTTPGTh);
00283     vector<L1MuDTChambThDigi>*  l1ThTrig = l1DTTPGTh->getContainer();
00284 
00285     runDCCAnalysis(l1PhTrig,l1ThTrig);
00286   }  
00287   if ( useDDU ) {
00288     Handle<DTLocalTriggerCollection> l1DDUTrigs;
00289     e.getByLabel(ros_label,l1DDUTrigs);
00290 
00291     runDDUAnalysis(l1DDUTrigs);
00292   }
00293   if ( !tpMode && useSEG ) {
00294     Handle<DTRecSegment4DCollection> segments4D;
00295     e.getByLabel(seg_label, segments4D);  
00296     
00297     runSegmentAnalysis(segments4D);
00298   } 
00299   if ( !tpMode && useDCC && useDDU ) {
00300     runDDUvsDCCAnalysis(trigsrc);
00301   }
00302 
00303 }
00304 
00305 
00306 void DTLocalTriggerTask::bookBarrelHistos(string histoTag) {
00307 
00308   bool isDCC = histoTag.substr(0,3) == "DCC";
00309   dbe->setCurrentFolder(topFolder(isDCC));
00310   if (histoTag == "DCC_ErrorsChamberID") {
00311     dcc_IDDataErrorPlot = dbe->book1D(histoTag.c_str(),"DCC Data ID Error",5,-2,3);
00312     dcc_IDDataErrorPlot->setAxisTitle("wheel",1);
00313   }
00314   
00315   return;
00316 
00317 }
00318 
00319 void DTLocalTriggerTask::bookHistos(const DTChamberId& dtCh, string folder, string histoTag) {
00320   
00321   int wh=dtCh.wheel();          
00322   int sc=dtCh.sector(); 
00323   stringstream wheel; wheel << wh;      
00324   stringstream station; station << dtCh.station();      
00325   stringstream sector; sector << sc;    
00326 
00327   double minBX=0;
00328   double maxBX=0;
00329   int  rangeBX=0;
00330 
00331   string histoType = histoTag.substr(4,histoTag.find("_",4)-4);
00332   bool isDCC = histoTag.substr(0,3) == "DCC"; 
00333 
00334   dbe->setCurrentFolder(topFolder(isDCC) + "Wheel" + wheel.str() +
00335                         "/Sector" + sector.str() +
00336                         "/Station" + station.str() + "/" + folder);
00337 
00338   string histoName = histoTag + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00339     
00340   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: booking " << topFolder(isDCC) << "Wheel" << wheel.str()
00341                                                        << "/Sector" << sector.str()
00342                                                        << "/Station"<< station.str() << "/" << folder << "/" << histoName << endl;
00343     
00344   if (histoType.find("BX") != string::npos){
00345     if (histoTag.substr(0,3) == "DCC"){
00346       minBX= parameters.getUntrackedParameter<int>("minBXDCC",-2) - 0.5;
00347       maxBX= parameters.getUntrackedParameter<int>("maxBXDCC",2) + 0.5;
00348     }
00349     else {
00350       minBX= parameters.getUntrackedParameter<int>("minBXDDU",0) - 0.5;
00351       maxBX= parameters.getUntrackedParameter<int>("maxBXDDU",20) + 0.5;
00352     }
00353     rangeBX = (int)(maxBX-minBX);
00354   }
00355     
00356   if ( folder == "LocalTriggerPhi") {
00357       
00358     if( histoType == "BXvsQual" ){
00359       (digiHistos[dtCh.rawId()])[histoTag] = 
00360         dbe->book2D(histoName,"BX vs trigger quality",7,-0.5,6.5,rangeBX,minBX,maxBX);
00361       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00362       return ;
00363     }
00364     if( histoType == "BestQual" ){
00365       (digiHistos[dtCh.rawId()])[histoTag] = 
00366         dbe->book1D(histoName,"Trigger quality of best primitives",7,-0.5,6.5);
00367       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00368       return ;
00369     }
00370     if( histoType == "QualvsPhirad" ){
00371       (digiHistos[dtCh.rawId()])[histoTag] = 
00372         dbe->book2D(histoName,"Trigger quality vs local position",100,-500.,500.,7,-0.5,6.5);
00373       setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);
00374       return ;
00375     }
00376     if( histoType == "QualvsPhibend" ) { 
00377       (digiHistos[dtCh.rawId()])[histoTag] = 
00378         dbe->book2D(histoName,"Trigger quality vs local direction",200,-40.,40.,7,-0.5,6.5);
00379       setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);      
00380       return ;
00381     }
00382     if( histoType == "Flag1stvsQual" ) {
00383       (digiHistos[dtCh.rawId()])[histoTag] = 
00384         dbe->book2D(histoName,"1st/2nd trig flag vs quality",7,-0.5,6.5,2,-0.5,1.5);
00385       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00386       return ;
00387     }
00388     if( histoType == "QualDDUvsQualDCC" ){
00389       (digiHistos[dtCh.rawId()])[histoTag] = 
00390         dbe->book2D(histoName,"DDU quality vs DCC quality",8,-1.5,6.5,8,-1.5,6.5);
00391       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00392       setQLabels((digiHistos[dtCh.rawId()])[histoTag],2);      
00393       return ;
00394     }    
00395       
00396   }
00397   else if ( folder == "LocalTriggerTheta")   {
00398       
00399     if( histoType == "PositionvsBX" ) {
00400       (digiHistos[dtCh.rawId()])[histoTag] = 
00401         dbe->book2D(histoName,"Theta trigger position vs BX",rangeBX,minBX,maxBX,7,-0.5,6.5);
00402       return ;
00403     }
00404     if( histoType == "PositionvsQual" ) {
00405       (digiHistos[dtCh.rawId()])[histoTag] = 
00406         dbe->book2D(histoName,"Theta trigger position vs quality",7,-0.5,6.5,7,-0.5,6.5);
00407       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00408       return ;
00409     }  
00410     if( histoType == "ThetaBXvsQual" ) {
00411       (digiHistos[dtCh.rawId()])[histoTag] = 
00412         dbe->book2D(histoName,"BX vs trigger quality",7,-0.5,6.5,rangeBX,minBX,maxBX);
00413       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00414     }
00415     if( histoType == "ThetaBestQual" ){
00416       (digiHistos[dtCh.rawId()])[histoTag] = 
00417         dbe->book1D(histoName,"Trigger quality of best primitives (theta)",7,-0.5,6.5);
00418       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00419       return ;
00420     }
00421 
00422   }
00423   else if ( folder == "Segment")   {
00424       
00425     if( histoType.find("TrackThetaPosvsAngle" ) == 0 ) {
00426 
00427       string histoLabel = "Position vs Angle (theta)";
00428       if (histoType.find("andTrigH") != string::npos) histoLabel += " for H triggers";
00429       else if (histoType.find("andTrig") != string::npos) histoLabel += " for triggers";
00430 
00431       float min,max;
00432       int nbins;
00433       trigGeomUtils->thetaRange(dtCh,min,max,nbins);
00434       (digiHistos[dtCh.rawId()])[histoTag] = 
00435         dbe->book2D(histoName,histoLabel,16,-40.,40.,nbins,min,max);
00436       return ;
00437     }
00438     if( histoType.find("TrackPosvsAngle") == 0 ){
00439 
00440       float min,max;
00441       int nbins;
00442       trigGeomUtils->phiRange(dtCh,min,max,nbins);
00443 
00444       string histoLabel = "Position vs Angle (phi)";
00445       if (histoType.find("andTrigHHHL")  != string::npos) histoLabel += " for HH/HL triggers";
00446       else if (histoType.find("andTrig") != string::npos) histoLabel += " for triggers";
00447 
00448       (digiHistos[dtCh.rawId()])[histoTag] = 
00449         dbe->book2D(histoName,histoLabel,16,-40.,40.,nbins,min,max);
00450       return ;
00451     }
00452     if( histoType == "PhitkvsPhitrig" ){ 
00453       (digiHistos[dtCh.rawId()])[histoTag] = 
00454         dbe->book2D(histoName,"Local position: segment vs trigger",100,-500.,500.,100,-500.,500.);
00455       return ;
00456     }
00457     if( histoType == "PhibtkvsPhibtrig" ){ 
00458       (digiHistos[dtCh.rawId()])[histoTag] = 
00459         dbe->book2D(histoName,"Local direction : segment vs trigger",200,-40.,40.,200,-40.,40.);
00460       return ;
00461     }
00462     if( histoType == "PhiResidual" ){ 
00463       (digiHistos[dtCh.rawId()])[histoTag] = 
00464         dbe->book1D(histoName,"Trigger local position - Segment local position (correlated triggers)",400,-10.,10.);
00465       return ;
00466     }
00467     if( histoType == "PhibResidual" ){ 
00468       (digiHistos[dtCh.rawId()])[histoTag] = 
00469         dbe->book1D(histoName,"Trigger local direction - Segment local direction (correlated triggers)",500,-10.,10.);
00470       return ;
00471     }
00472     if( histoType == "HitstkvsQualtrig" ){ 
00473       (digiHistos[dtCh.rawId()])[histoTag] = 
00474         dbe->book2D(histoName,"Segment hits (phi) vs trigger quality",7,-0.5,6.5,10,0.5,10.5);
00475       setQLabels((digiHistos[dtCh.rawId()])[histoTag],1);
00476       return ;
00477     }
00478 
00479   }
00480 
00481 }
00482 
00483 void DTLocalTriggerTask::bookWheelHistos(int wh, string histoTag) {
00484   
00485   stringstream wheel; wheel << wh;      
00486 
00487   string histoType = histoTag.substr(4,histoTag.find("_",4)-4);
00488   bool isDCC = histoTag.substr(0,3) == "DCC"; 
00489 
00490   dbe->setCurrentFolder(topFolder(isDCC) + "Wheel" + wheel.str() + "/");
00491 
00492   string histoName = histoTag + "_W" + wheel.str();
00493     
00494   LogTrace("DTDQM|DTMonitorModule|DTLocalTriggerTask") << "[DTLocalTriggerTask]: booking " << topFolder(isDCC) 
00495                                                        << "Wheel" << wheel.str() << "/" << histoName << endl;
00496     
00497   if( histoType.find("BXDiff") != string::npos ){
00498     MonitorElement *me = dbe->bookProfile2D(histoName,"DDU-DCC BX Difference",12,1,13,4,1,5,0.,20.);
00499     me->setAxisTitle("Sector",1);
00500     me->setAxisTitle("station",2);
00501     (wheelHistos[wh])[histoTag] = me;
00502     return ;
00503   }
00504 
00505 }
00506 
00507 void DTLocalTriggerTask::runDCCAnalysis( std::vector<L1MuDTChambPhDigi>* phTrigs, 
00508                                          std::vector<L1MuDTChambThDigi>* thTrigs ){
00509 
00510   string histoType ;
00511   string histoTag ;
00512 
00513   // define best quality trigger segment (phi and theta)  
00514   // in any station start from 1 and zero is kept empty
00515   for (int i=0;i<5;++i){
00516     for (int j=0;j<6;++j){
00517       for (int k=0;k<13;++k){
00518         phcode_best[j][i][k] = -1;
00519         thcode_best[j][i][k] = -1;
00520       }
00521     }
00522   }
00523 
00524   vector<L1MuDTChambPhDigi>::const_iterator iph  = phTrigs->begin();
00525   vector<L1MuDTChambPhDigi>::const_iterator iphe = phTrigs->end();
00526   for(; iph !=iphe ; ++iph) {
00527 
00528     int phwheel = iph->whNum();
00529     int phsec   = iph->scNum() + 1; // SM The track finder goes from 0 to 11. I need them from 1 to 12 !!!!!
00530     int phst    = iph->stNum();
00531     int phbx    = iph->bxNum();
00532     int phcode  = iph->code();
00533     int phi1st  = iph->Ts2Tag();
00534 
00535     // FIXME: workaround for DCC data with station ID 
00536     if(phst == 0) {
00537       dcc_IDDataErrorPlot->Fill(phwheel);
00538       continue;
00539     }
00540 
00541     if(phcode>phcode_best[phwheel+3][phst][phsec] && phcode<7) {
00542       phcode_best[phwheel+3][phst][phsec]=phcode; 
00543       iphbest[phwheel+3][phst][phsec] = &(*iph);
00544     }
00545       
00546     DTChamberId dtChId(phwheel,phst,phsec);
00547       
00548     float x     = trigGeomUtils->trigPos(&(*iph));
00549     float angle = trigGeomUtils->trigDir(&(*iph));
00550     uint32_t indexCh = dtChId.rawId();
00551     
00552     map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00553     if (innerME.find("DCC_BXvsQual"+trigsrc) == innerME.end()){
00554       if (tpMode) {
00555         bookHistos(dtChId,"LocalTriggerPhi","DCC_BXvsQual"+trigsrc);
00556         bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhirad"+trigsrc);
00557       }
00558       else {
00559         bookHistos(dtChId,"LocalTriggerPhi","DCC_BXvsQual"+trigsrc);
00560         bookHistos(dtChId,"LocalTriggerPhi","DCC_Flag1stvsQual"+trigsrc);
00561         if (detailedAnalysis) {
00562           bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhirad"+trigsrc);
00563           bookHistos(dtChId,"LocalTriggerPhi","DCC_QualvsPhibend"+trigsrc);
00564         }
00565       }
00566     }
00567 
00568     if (tpMode) {
00569       innerME.find("DCC_BXvsQual"+trigsrc)->second->Fill(phcode,phbx-phi1st);    // SM BX vs Qual Phi view (1st tracks) 
00570       innerME.find("DCC_QualvsPhirad"+trigsrc)->second->Fill(x,phcode);          // SM Qual vs radial angle Phi view
00571     }
00572     else {
00573       innerME.find("DCC_BXvsQual"+trigsrc)->second->Fill(phcode,phbx-phi1st);    // SM BX vs Qual Phi view (1st tracks) 
00574       innerME.find("DCC_Flag1stvsQual"+trigsrc)->second->Fill(phcode,phi1st);    // SM Qual 1st/2nd track flag Phi view
00575       if (detailedAnalysis) {
00576         innerME.find("DCC_QualvsPhirad"+trigsrc)->second->Fill(x,phcode);          // SM Qual vs radial angle Phi view
00577         innerME.find("DCC_QualvsPhibend"+trigsrc)->second->Fill(angle,phcode);     // SM Qual vs bending Phi view
00578       }
00579     }
00580       
00581   } 
00582 
00583   if (doDCCTheta) {
00584     int thcode[7];
00585     vector<L1MuDTChambThDigi>::const_iterator ith  = thTrigs->begin();
00586     vector<L1MuDTChambThDigi>::const_iterator ithe = thTrigs->end();
00587     for(; ith != ithe; ++ith) {
00588       int thwheel = ith->whNum();
00589       int thsec   = ith->scNum() + 1; // SM The track finder goes from 0 to 11. I need them from 1 to 12 !!!!!
00590       int thst    = ith->stNum();
00591       int thbx    = ith->bxNum();
00592       
00593       for (int pos=0; pos<7; pos++) {
00594         thcode[pos] = ith->code(pos);
00595 
00596         if(thcode[pos]>thcode_best[thwheel+3][thst][thsec] ) {
00597           thcode_best[thwheel+3][thst][thsec]=thcode[pos]; 
00598           ithbest[thwheel+3][thst][thsec] = &(*ith);
00599         }
00600       } 
00601       
00602       DTChamberId dtChId(thwheel,thst,thsec);
00603       uint32_t indexCh = dtChId.rawId();   
00604 
00605       map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00606       if (innerME.find("DCC_PositionvsBX"+trigsrc) == innerME.end()){
00607         bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsBX"+trigsrc);
00608 //      if (detailedAnalysis) {
00609 //        bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsBX"+trigsrc);
00610 //        bookHistos(dtChId,"LocalTriggerTheta","DCC_PositionvsQual"+trigsrc);
00611 //      }
00612       }
00613 
00614       for (int pos=0; pos<7; pos++) { //SM fill position for non zero position bit in theta view
00615         if(thcode[pos]>0){
00616           innerME.find("DCC_PositionvsBX"+trigsrc)->second->Fill(thbx,pos);          // SM BX vs Position Theta view
00617 //        if (detailedAnalysis) {
00618 //          int thqual = (thcode[pos]/2)*2+1;
00619 //          innerME.find("DCC_ThetaBXvsQual"+trigsrc)->second->Fill(thqual,thbx);      // SM BX vs Code Theta view
00620 //          innerME.find("DCC_PositionvsQual"+trigsrc)->second->Fill(thqual,pos);      // SM Code vs Position Theta view
00621 //        }
00622         }
00623       }
00624     }
00625   }
00626 
00627   
00628   // Fill Quality plots with best DCC triggers in phi & theta
00629   if (!tpMode) {
00630     for (int st=1;st<5;++st){
00631       for (int wh=-2;wh<3;++wh){
00632         for (int sc=1;sc<13;++sc){
00633           if (phcode_best[wh+3][st][sc]>-1 && phcode_best[wh+3][st][sc]<7){
00634             DTChamberId id(wh,st,sc);
00635             uint32_t indexCh = id.rawId();
00636             map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00637             if (innerME.find("DCC_BestQual"+trigsrc) == innerME.end())
00638               bookHistos(id,"LocalTriggerPhi","DCC_BestQual"+trigsrc);
00639             innerME.find("DCC_BestQual"+trigsrc)->second->Fill(phcode_best[wh+3][st][sc]);  // Best Qual Trigger Phi view
00640           }
00641 //        if (thcode_best[wh+3][st][sc]>0){
00642 //          DTChamberId id(wh,st,sc);
00643 //          uint32_t indexCh = id.rawId();
00644 //          map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00645 //          if (innerME.find("DCC_ThetaBestQual"+trigsrc) == innerME.end())
00646 //            bookHistos(id,"LocalTriggerTheta","DCC_ThetaBestQual"+trigsrc);
00647 //          innerME.find("DCC_ThetaBestQual"+trigsrc)->second->Fill(thcode_best[wh+3][st][sc]); // Best Qual Trigger Theta view
00648 //        }
00649         }
00650       }
00651     }
00652   }
00653 
00654 }
00655 
00656 void DTLocalTriggerTask::runDDUAnalysis(Handle<DTLocalTriggerCollection>& trigsDDU){
00657     
00658   DTLocalTriggerCollection::DigiRangeIterator detUnitIt;
00659     
00660   for (int i=0;i<5;++i){
00661     for (int j=0;j<6;++j){
00662       for (int k=0;k<13;++k){
00663         dduphcode_best[j][i][k] = -1;
00664         dduthcode_best[j][i][k] = -1;
00665       }
00666     }
00667   }
00668 
00669   for (detUnitIt=trigsDDU->begin();
00670        detUnitIt!=trigsDDU->end();
00671        ++detUnitIt){
00672       
00673     const DTChamberId& id = (*detUnitIt).first;
00674     const DTLocalTriggerCollection::Range& range = (*detUnitIt).second;
00675     uint32_t indexCh = id.rawId();
00676     map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00677       
00678     int wh = id.wheel();
00679     int sec = id.sector();
00680     int st = id.station();
00681 
00682     for (DTLocalTriggerCollection::const_iterator trigIt = range.first;
00683          trigIt!=range.second;
00684          ++trigIt){
00685         
00686       int bx = trigIt->bx();
00687       int quality = trigIt->quality();
00688       int thqual = trigIt->trTheta();
00689       int flag1st = trigIt->secondTrack() ? 1 : 0;
00690 
00691       // check if SC data exist: fill for any trigger
00692       if( quality>-1 && quality<7 ) {     // it is a phi trigger
00693         
00694         if(quality>dduphcode_best[wh+3][st][sec]) {
00695           dduphcode_best[wh+3][st][sec]=quality;
00696           iphbestddu[wh+3][st][sec] = &(*trigIt);
00697         }
00698         
00699         if (innerME.find("DDU_BXvsQual"+trigsrc) == innerME.end()){
00700           bookHistos(id,"LocalTriggerPhi","DDU_BXvsQual"+trigsrc);
00701           bookHistos(id,"LocalTriggerPhi","DDU_Flag1stvsQual"+trigsrc);
00702         }
00703 
00704         if(tpMode) {      
00705           innerME.find("DDU_BXvsQual"+trigsrc)->second->Fill(quality,bx-flag1st);     // SM BX vs Qual Phi view 
00706         }
00707         else {
00708           innerME.find("DDU_BXvsQual"+trigsrc)->second->Fill(quality,bx-flag1st);     // SM BX vs Qual Phi view 
00709           innerME.find("DDU_Flag1stvsQual"+trigsrc)->second->Fill(quality,flag1st); // SM Quality vs 1st/2nd track flag Phi view
00710         }
00711       }
00712       if( thqual>0 && !tpMode ) {  // it is a theta trigger
00713         
00714         if(thqual>dduthcode_best[wh+3][st][sec] ) {
00715           dduthcode_best[wh+3][st][sec]=thqual; 
00716         }
00717         if (innerME.find("DDU_ThetaBXvsQual"+trigsrc) == innerME.end())
00718           bookHistos(id,"LocalTriggerTheta","DDU_ThetaBXvsQual"+trigsrc);
00719         innerME.find("DDU_ThetaBXvsQual"+trigsrc)->second->Fill(thqual,bx);     // SM BX vs Qual Theta view
00720         
00721       }
00722     }
00723     
00724     // Fill Quality plots with best ddu triggers in phi & theta
00725     if (!tpMode) {
00726       if (dduphcode_best[wh+3][st][sec]>-1 &&
00727           dduphcode_best[wh+3][st][sec]<7){
00728         if (innerME.find("DDU_BestQual"+trigsrc) == innerME.end())
00729           bookHistos(id,"LocalTriggerPhi","DDU_BestQual"+trigsrc);
00730         innerME.find("DDU_BestQual"+trigsrc)->second->Fill(dduphcode_best[wh+3][st][sec]);  // Best Qual Trigger Phi view
00731       }
00732       if (dduthcode_best[wh+3][st][sec]>0){
00733         if (innerME.find("DDU_ThetaBestQual"+trigsrc) == innerME.end())
00734           bookHistos(id,"LocalTriggerTheta","DDU_ThetaBestQual"+trigsrc);
00735         innerME.find("DDU_ThetaBestQual"+trigsrc)->second->Fill(dduthcode_best[wh+3][st][sec]); // Best Qual Trigger Theta view
00736       }  
00737     }
00738   }
00739   
00740 }
00741 
00742 
00743 void DTLocalTriggerTask::runSegmentAnalysis(Handle<DTRecSegment4DCollection>& segments4D){    
00744 
00745   DTRecSegment4DCollection::const_iterator track;
00746 
00747   // Find best tracks & good tracks
00748   memset(track_ok,false,450*sizeof(bool));
00749 
00750   DTRecSegment4DCollection::id_iterator chamberId;
00751   vector<const DTRecSegment4D*> best4DSegments;
00752 
00753   // Preliminary loop finds best 4D Segment and high quality ones
00754   for (chamberId = segments4D->id_begin(); chamberId != segments4D->id_end(); ++chamberId){
00755 
00756     DTRecSegment4DCollection::range  range = segments4D->get(*chamberId);
00757     const DTRecSegment4D* tmpBest=0;
00758     int tmpdof = 0;
00759     int dof = 0;
00760 
00761     for ( track = range.first; track != range.second; ++track){
00762 
00763       if( (*track).hasPhi() ) {
00764         
00765         dof = (*track).phiSegment()->degreesOfFreedom();
00766         if ( dof>tmpdof ){
00767           tmpBest = &(*track);
00768           tmpdof = dof;
00769         
00770           int wheel = (*track).chamberId().wheel();
00771           int sector = (*track).chamberId().sector();
00772           int station = (*track).chamberId().station();
00773           if (sector==13){
00774             sector=4;
00775           }
00776           else if (sector==14){
00777             sector=10;
00778           }
00779           track_ok[wheel+3][station][sector] = (!track_ok[wheel+3][station][sector] && dof>=2);
00780         }
00781 
00782       }
00783     }
00784     if (tmpBest) best4DSegments.push_back(tmpBest);
00785   }
00786     
00787   vector<const DTRecSegment4D*>::const_iterator btrack;
00788 
00789   for ( btrack = best4DSegments.begin(); btrack != best4DSegments.end(); ++btrack ){
00790 
00791     if( (*btrack)->hasPhi() ) { // Phi component
00792         
00793       int wheel    = (*btrack)->chamberId().wheel();
00794       int station  = (*btrack)->chamberId().station();
00795       int sector   = (*btrack)->chamberId().sector();
00796       int scsector = 0;
00797       float x_track, y_track, x_angle, y_angle;
00798       trigGeomUtils->computeSCCoordinates((*btrack),scsector,x_track,x_angle,y_track,y_angle);
00799       int nHitsPhi = (*btrack)->phiSegment()->degreesOfFreedom()+2;
00800 
00801       DTChamberId dtChId(wheel,station,sector);      // get chamber for LUTs histograms (Sectors 1 to 14)
00802       uint32_t indexCh = dtChId.rawId(); 
00803       map<string, MonitorElement*> &innerMECh = digiHistos[indexCh];
00804       
00805       DTChamberId dtChIdSC = DTChamberId(wheel,station,scsector);  // get chamber for histograms SC granularity (sectors 1 to 12)
00806       indexCh = dtChIdSC.rawId(); 
00807       map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00808 
00809       if (useDDU && 
00810           dduphcode_best[wheel+3][station][scsector] > -1 && 
00811           dduphcode_best[wheel+3][station][scsector] < 7 ) {
00812 
00813         // SM hits of the track vs quality of the trigger
00814         if (innerME.find("DDU_HitstkvsQualtrig"+trigsrc) == innerME.end())
00815           bookHistos(dtChIdSC,"Segment","DDU_HitstkvsQualtrig"+trigsrc);
00816         innerME.find("DDU_HitstkvsQualtrig"+trigsrc)->second->Fill(dduphcode_best[wheel+3][station][scsector],nHitsPhi);
00817 
00818       }
00819         
00820       if (useDCC &&
00821           phcode_best[wheel+3][station][scsector] > -1 && 
00822           phcode_best[wheel+3][station][scsector] < 7 ) {
00823         
00824         if (innerME.find("DCC_HitstkvsQualtrig"+trigsrc) == innerME.end()){
00825           bookHistos(dtChIdSC,"Segment","DCC_HitstkvsQualtrig"+trigsrc);
00826         }
00827         innerME.find("DCC_HitstkvsQualtrig"+trigsrc)->second->Fill(phcode_best[wheel+3][station][scsector],nHitsPhi);
00828      
00829         if (phcode_best[wheel+3][station][scsector]>3 && nHitsPhi>=7){
00830           
00831           float x_trigger     = trigGeomUtils->trigPos(iphbest[wheel+3][station][scsector]);
00832           float angle_trigger = trigGeomUtils->trigDir(iphbest[wheel+3][station][scsector]);
00833           trigGeomUtils->trigToSeg(station,x_trigger,x_angle);
00834             
00835           if (innerMECh.find("DCC_PhibResidual"+trigsrc) == innerMECh.end()){
00836             bookHistos(dtChId,"Segment","DCC_PhiResidual"+trigsrc);
00837             bookHistos(dtChId,"Segment","DCC_PhibResidual"+trigsrc);
00838             bookHistos(dtChId,"Segment","DCC_PhitkvsPhitrig"+trigsrc);
00839             bookHistos(dtChId,"Segment","DCC_PhibtkvsPhibtrig"+trigsrc);
00840             bookHistos(dtChId,"Segment","DCC_HitstkvsQualtrig"+trigsrc);
00841           }
00842 
00843           innerMECh.find("DCC_PhitkvsPhitrig"+trigsrc)->second->Fill(x_trigger,x_track);
00844           innerMECh.find("DCC_PhibtkvsPhibtrig"+trigsrc)->second->Fill(angle_trigger,x_angle);
00845           innerMECh.find("DCC_PhiResidual"+trigsrc)->second->Fill(x_trigger-x_track);
00846           innerMECh.find("DCC_PhibResidual"+trigsrc)->second->Fill(angle_trigger-x_angle);
00847         }
00848 
00849 
00850 
00851       }
00852 
00853       
00854       if (useDCC) {
00855           
00856         // check for triggers elsewhere in the sector
00857         bool trigFlagDCC =false;
00858         for (int ist=1; ist<5; ist++){
00859           if (ist!=station &&
00860               phcode_best[wheel+3][ist][scsector]>=2 && 
00861               phcode_best[wheel+3][ist][scsector]<7 &&
00862               track_ok[wheel+3][ist][scsector]==true){
00863             trigFlagDCC = true;
00864             break;
00865           }
00866         }
00867           
00868         if (trigFlagDCC && fabs(x_angle)<40. && nHitsPhi>=7){
00869 
00870           if (innerME.find("DCC_TrackPosvsAngle"+trigsrc) == innerME.end()){
00871             bookHistos(dtChIdSC,"Segment","DCC_TrackPosvsAngle"+trigsrc);
00872             bookHistos(dtChIdSC,"Segment","DCC_TrackPosvsAngleandTrig"+trigsrc);
00873             bookHistos(dtChIdSC,"Segment","DCC_TrackPosvsAngleandTrigHHHL"+trigsrc);
00874           }
00875             
00876           // position vs angle of track for reconstruced tracks (denom. for trigger efficiency)
00877           innerME.find("DCC_TrackPosvsAngle"+trigsrc)->second->Fill(x_angle,x_track);     
00878           if (phcode_best[wheel+3][station][scsector] >= 2 && phcode_best[wheel+3][station][scsector] < 7) {
00879             innerME.find("DCC_TrackPosvsAngleandTrig"+trigsrc)->second->Fill(x_angle,x_track);    
00880             if (phcode_best[wheel+3][station][scsector] > 4){  //HH & HL Triggers
00881               innerME.find("DCC_TrackPosvsAngleandTrigHHHL"+trigsrc)->second->Fill(x_angle,x_track);      
00882             }         
00883           }
00884 
00885         }
00886           
00887         if ((*btrack)->hasZed() && trigFlagDCC && fabs(y_angle)<40. && (*btrack)->zSegment()->degreesOfFreedom()>=1){
00888 
00889           if (innerME.find("DCC_TrackThetaPosvsAngle"+trigsrc) == innerME.end()){
00890             bookHistos(dtChIdSC,"Segment","DCC_TrackThetaPosvsAngle"+trigsrc);
00891             bookHistos(dtChIdSC,"Segment","DCC_TrackThetaPosvsAngleandTrig"+trigsrc);
00892 //          bookHistos(dtChIdSC,"Segment","DCC_TrackThetaPosvsAngleandTrigH"+trigsrc);          no DCC theta qual info
00893           }
00894 
00895           // position va angle of track for reconstruced tracks (denom. for trigger efficiency) along theta direction
00896           innerME.find("DCC_TrackThetaPosvsAngle"+trigsrc)->second->Fill(y_angle,y_track);
00897           if (thcode_best[wheel+3][station][scsector] > 0) {            
00898             innerME.find("DCC_TrackThetaPosvsAngleandTrig"+trigsrc)->second->Fill(y_angle,y_track);
00899 //          if (thcode_best[wheel+3][station][scsector] == 3) {
00900 //            innerME.find("DCC_TrackThetaPosvsAngleH"+trigsrc)->second->Fill(y_angle,y_track);
00901 //          }            
00902           }
00903 
00904         }  
00905       }
00906 
00907       if (useDDU) {
00908           
00909         // check for triggers elsewhere in the sector
00910         bool trigFlagDDU =false;
00911         for (int ist=1; ist<5; ist++){
00912           if (ist!=station &&
00913               dduphcode_best[wheel+3][ist][scsector]>=2 && 
00914               dduphcode_best[wheel+3][ist][scsector]<7 &&
00915               track_ok[wheel+3][ist][scsector]==true){
00916             trigFlagDDU = true;
00917             break;
00918           }
00919         }
00920 
00921         if (trigFlagDDU && fabs(x_angle)<40. && nHitsPhi>=7){
00922 
00923           if (innerME.find("DDU_TrackPosvsAngle"+trigsrc) == innerME.end()){
00924             bookHistos(dtChIdSC,"Segment","DDU_TrackPosvsAngle"+trigsrc);
00925             bookHistos(dtChIdSC,"Segment","DDU_TrackPosvsAngleandTrig"+trigsrc);
00926             bookHistos(dtChIdSC,"Segment","DDU_TrackPosvsAngleandTrigHHHL"+trigsrc);
00927           }
00928 
00929           // position vs angle of track for reconstruced tracks (denom. for trigger efficiency)
00930           innerME.find("DDU_TrackPosvsAngle"+trigsrc)->second->Fill(x_angle,x_track);
00931           if (dduphcode_best[wheel+3][station][scsector] >= 2 && dduphcode_best[wheel+3][station][scsector] < 7) {
00932           innerME.find("DDU_TrackPosvsAngleandTrig"+trigsrc)->second->Fill(x_angle,x_track);
00933             if (dduphcode_best[wheel+3][station][scsector] > 4){  //HH & HL Triggers
00934               innerME.find("DDU_TrackPosvsAngleandTrigHHHL"+trigsrc)->second->Fill(x_angle,x_track);      
00935             }         
00936           }
00937 
00938         }
00939           
00940         if ((*btrack)->hasZed() && trigFlagDDU && fabs(y_angle)<40. && (*btrack)->zSegment()->degreesOfFreedom()>=1){
00941 
00942           if (innerME.find("DDU_TrackThetaPosvsAngle"+trigsrc) == innerME.end()){
00943             bookHistos(dtChIdSC,"Segment","DDU_TrackThetaPosvsAngle"+trigsrc);
00944             bookHistos(dtChIdSC,"Segment","DDU_TrackThetaPosvsAngleandTrig"+trigsrc);
00945             bookHistos(dtChIdSC,"Segment","DDU_TrackThetaPosvsAngleandTrigH"+trigsrc);
00946           }
00947 
00948           // position va angle of track for reconstruced tracks (denom. for trigger efficiency) along theta direction
00949           innerME.find("DDU_TrackThetaPosvsAngle"+trigsrc)->second->Fill(y_angle,y_track);
00950           if (dduthcode_best[wheel+3][station][scsector] > 0) {         
00951             innerME.find("DDU_TrackThetaPosvsAngleandTrig"+trigsrc)->second->Fill(y_angle,y_track);
00952             if (dduthcode_best[wheel+3][station][scsector] == 3) {
00953               innerME.find("DDU_TrackThetaPosvsAngleandTrigH"+trigsrc)->second->Fill(y_angle,y_track);
00954             }            
00955           }
00956 
00957         }  
00958       }
00959     }
00960   } 
00961 
00962 }
00963 
00964 
00965 void DTLocalTriggerTask::runDDUvsDCCAnalysis(string& trigsrc){
00966 
00967   string histoType ;
00968   string histoTag ;
00969 
00970   for (int st=1;st<5;++st){
00971     for (int wh=-2;wh<3;++wh){
00972       for (int sc=1;sc<13;++sc){
00973         if ( (phcode_best[wh+3][st][sc]>-1 && phcode_best[wh+3][st][sc]<7) ||
00974              (dduphcode_best[wh+3][st][sc]>-1 && dduphcode_best[wh+3][st][sc]<7) ){
00975           DTChamberId id(wh,st,sc);
00976           uint32_t indexCh = id.rawId();
00977           map<string, MonitorElement*> &innerME = digiHistos[indexCh];
00978           if (innerME.find("COM_QualDDUvsQualDCC"+trigsrc) == innerME.end())
00979             bookHistos(id,"LocalTriggerPhi","COM_QualDDUvsQualDCC"+trigsrc);
00980           innerME.find("COM_QualDDUvsQualDCC"+trigsrc)->second->Fill(phcode_best[wh+3][st][sc],dduphcode_best[wh+3][st][sc]);
00981           if ( (phcode_best[wh+3][st][sc]>-1 && phcode_best[wh+3][st][sc]<7) &&
00982                (dduphcode_best[wh+3][st][sc]>-1 && dduphcode_best[wh+3][st][sc]<7) ){
00983             int bxDDU = iphbestddu[wh+3][st][sc]->bx() - iphbestddu[wh+3][st][sc]->secondTrack();
00984             int bxDCC = iphbest[wh+3][st][sc]->bxNum() - iphbest[wh+3][st][sc]->Ts2Tag();
00985             (wheelHistos[wh]).find("COM_BXDiff"+trigsrc)->second->Fill(sc,st,bxDDU-bxDCC);
00986           }
00987         }
00988       }
00989     }
00990   }
00991 
00992 }
00993 
00994 void DTLocalTriggerTask::setQLabels(MonitorElement* me, short int iaxis){
00995 
00996   TH1* histo = me->getTH1();
00997   if (!histo) return;
00998   
00999   TAxis* axis=0;
01000   if (iaxis==1) {
01001     axis=histo->GetXaxis();
01002   }
01003   else if(iaxis==2) {
01004     axis=histo->GetYaxis();
01005   }
01006   if (!axis) return;
01007 
01008   string labels[7] = {"LI","LO","HI","HO","LL","HL","HH"};
01009   int istart = axis->GetXmin()<-1 ? 2 : 1;
01010   for (int i=0;i<7;i++) {
01011     axis->SetBinLabel(i+istart,labels[i].c_str());
01012   }
01013 
01014 }
01015 
01016 void DTLocalTriggerTask::triggerSource(const edm::Event& e) {
01017   
01018   
01019   if ( !parameters.getUntrackedParameter<bool>("localrun", true) ){
01020     
01021     Handle<LTCDigiCollection> ltcdigis;
01022     e.getByType(ltcdigis);
01023     
01024     for (std::vector<LTCDigi>::const_iterator ltc_it = ltcdigis->begin(); ltc_it != ltcdigis->end(); ltc_it++){
01025       
01026       size_t otherTriggerSum=0;
01027       for (size_t i = 1; i < 6; i++) {
01028         otherTriggerSum += size_t((*ltc_it).HasTriggered(i));
01029       }
01030       if ((*ltc_it).HasTriggered(0) && otherTriggerSum == 0) 
01031         trigsrc = "_DTonly";
01032       else if (!(*ltc_it).HasTriggered(0))
01033         trigsrc = "_NoDT";
01034       else if ((*ltc_it).HasTriggered(0) && otherTriggerSum > 0)
01035         trigsrc = "_DTalso";
01036       
01037     }
01038     return;
01039   }
01040 
01041   trigsrc = "";
01042   return;
01043 
01044 }