CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/DTMonitorClient/src/DTLocalTriggerTest.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2010/01/05 10:15:46 $
00005  *  $Revision: 1.31 $
00006  *  \author C. Battilana S. Marcellini - INFN Bologna
00007  */
00008 
00009 
00010 // This class header
00011 #include "DQM/DTMonitorClient/src/DTLocalTriggerTest.h"
00012 
00013 // Framework headers
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 #include "DQMServices/Core/interface/MonitorElement.h"
00017 #include "DQMServices/Core/interface/DQMStore.h"
00018 
00019 // Geometry
00020 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00021 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00022 
00023 // Root
00024 #include "TF1.h"
00025 #include "TProfile.h"
00026 
00027 
00028 //C++ headers
00029 #include <iostream>
00030 #include <sstream>
00031 
00032 using namespace edm;
00033 using namespace std;
00034 
00035 
00036 DTLocalTriggerTest::DTLocalTriggerTest(const edm::ParameterSet& ps){
00037 
00038   setConfig(ps,"DTLocalTrigger");
00039   baseFolderDCC = "DT/03-LocalTrigger-DCC/";
00040   baseFolderDDU = "DT/04-LocalTrigger-DDU/";
00041 
00042 }
00043 
00044 
00045 DTLocalTriggerTest::~DTLocalTriggerTest(){
00046 
00047 }
00048 
00049 void DTLocalTriggerTest::beginJob(){
00050   
00051   DTLocalTriggerBaseTest::beginJob();
00052 
00053 
00054   vector<string>::const_iterator iTr   = trigSources.begin();
00055   vector<string>::const_iterator trEnd = trigSources.end();
00056   vector<string>::const_iterator iHw   = hwSources.begin();
00057   vector<string>::const_iterator hwEnd = hwSources.end();
00058 
00059 
00060   //Booking
00061   if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
00062     for (; iTr != trEnd; ++iTr){
00063       trigSource = (*iTr);
00064       for (; iHw != hwEnd; ++iHw){
00065         hwSource = (*iHw);
00066         // Loop over the TriggerUnits
00067         for (int wh=-2; wh<=2; ++wh){
00068           if (hwSource=="COM") {
00069             bookWheelHistos(wh,"MatchingPhi");
00070           } 
00071           else { 
00072             for (int sect=1; sect<=12; ++sect){
00073               bookSectorHistos(wh,sect,"BXDistribPhi");
00074               bookSectorHistos(wh,sect,"QualDistribPhi");
00075             }
00076             bookWheelHistos(wh,"CorrectBXPhi");
00077             bookWheelHistos(wh,"ResidualBXPhi");
00078             bookWheelHistos(wh,"CorrFractionPhi");
00079             bookWheelHistos(wh,"2ndFractionPhi");
00080             bookWheelHistos(wh,"TriggerInclusivePhi");
00081             bookWheelHistos(wh,"CorrectBXTheta");
00082             if (hwSource=="DDU") {
00083               bookWheelHistos(wh,"HFractionTheta");
00084             }
00085           }
00086         }
00087       }
00088     }
00089   }
00090   // Summary test histo booking (only static)
00091   for (iTr = trigSources.begin(); iTr != trEnd; ++iTr){
00092     trigSource = (*iTr);
00093     for (iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00094       hwSource = (*iHw);
00095       // Loop over the TriggerUnits
00096       for (int wh=-2; wh<=2; ++wh){
00097         if (hwSource=="COM") {
00098           bookWheelHistos(wh,"MatchingSummary","Matching");
00099         }
00100         else {
00101           bookWheelHistos(wh,"CorrFractionSummary");
00102           bookWheelHistos(wh,"2ndFractionSummary");
00103         }
00104       }
00105       if (hwSource=="COM") {
00106         bookCmsHistos("MatchingSummary","Matching");
00107       }
00108       else {
00109         bookCmsHistos("CorrFractionSummary");
00110         bookCmsHistos("2ndFractionSummary");
00111       } 
00112     }   
00113   }
00114 
00115 }
00116 
00117 
00118 void DTLocalTriggerTest::beginRun(const edm::Run& r, const edm::EventSetup& c){
00119   
00120   DTLocalTriggerBaseTest::beginRun(r,c);
00121 
00122 }
00123 
00124 
00125 void DTLocalTriggerTest::runClientDiagnostic() {
00126 
00127   // Loop over Trig & Hw sources
00128   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00129     trigSource = (*iTr);
00130     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00131       hwSource = (*iHw);
00132       // Loop over the TriggerUnits
00133       for (int stat=1; stat<=4; ++stat){
00134         for (int wh=-2; wh<=2; ++wh){
00135           for (int sect=1; sect<=12; ++sect){
00136             DTChamberId chId(wh,stat,sect);
00137             int sector_id = (wh+3)+(sect-1)*5;
00138             // uint32_t indexCh = chId.rawId();
00139             
00140             if (hwSource=="COM") {
00141               // Perform DCC-DDU matching test and generates summaries (Phi view)
00142               TH2F * DDUvsDCC = getHisto<TH2F>(dbe->get(getMEName("QualDDUvsQualDCC","LocalTriggerPhi", chId)));
00143               if (DDUvsDCC) {
00144                 
00145                 int matchSummary   = 1;
00146                 
00147                 if (DDUvsDCC->GetEntries()>1) {
00148                   
00149                   double entries     = DDUvsDCC->GetEntries();
00150                   double corrEntries = 0;
00151                   for (int ibin=2; ibin<=8; ++ibin) {
00152                     corrEntries += DDUvsDCC->GetBinContent(ibin,ibin);
00153                   }
00154                   double corrRatio   = corrEntries/entries;
00155                   
00156                   if (corrRatio < parameters.getUntrackedParameter<double>("matchingFracError",.65)){
00157                     matchSummary = 2;
00158                   }
00159                   else if (corrRatio < parameters.getUntrackedParameter<double>("matchingFracWarning",.85)){
00160                     matchSummary = 3;
00161                   }
00162                   else {
00163                     matchSummary = 0;
00164                   }
00165                   
00166                   if( whME[wh].find(fullName("MatchingPhi")) == whME[wh].end() ){
00167                     bookWheelHistos(wh,"MatchingPhi");
00168                   }
00169                   
00170                   whME[wh].find(fullName("MatchingPhi"))->second->setBinContent(sect,stat,corrRatio);
00171                   
00172                 }
00173                 
00174                 whME[wh].find(fullName("MatchingSummary"))->second->setBinContent(sect,stat,matchSummary);
00175 
00176               }
00177             }
00178             else {
00179               // Perform DCC/DDU common plot analysis (Phi ones)
00180               TH2F * BXvsQual      = getHisto<TH2F>(dbe->get(getMEName("BXvsQual","LocalTriggerPhi", chId)));
00181               TH1F * BestQual      = getHisto<TH1F>(dbe->get(getMEName("BestQual","LocalTriggerPhi", chId)));
00182               TH2F * Flag1stvsQual = getHisto<TH2F>(dbe->get(getMEName("Flag1stvsQual","LocalTriggerPhi", chId))); 
00183               if (BXvsQual && Flag1stvsQual && BestQual) {
00184 
00185                 int corrSummary   = 1;
00186                 int secondSummary = 1;
00187                 
00188                 if (BestQual->GetEntries()>1) {
00189                   
00190                   TH1D* BXHH    = BXvsQual->ProjectionY("",6,7,"");
00191                   TH1D* Flag1st = Flag1stvsQual->ProjectionY();
00192                   int BXOK_bin  = BXHH->GetEntries()>=1 ? BXHH->GetMaximumBin() : 51;
00193                   double BXMean = BXHH->GetEntries()>=1 ? BXHH->GetMean() : 51;
00194                   double BX_OK  = BXvsQual->GetYaxis()->GetBinCenter(BXOK_bin);
00195                   double trigsFlag2nd = Flag1st->GetBinContent(2);
00196                   double trigs = Flag1st->GetEntries();
00197                   double besttrigs = BestQual->GetEntries();
00198                   double besttrigsCorr = BestQual->Integral(5,7,"");
00199                   delete BXHH;
00200                   delete Flag1st;
00201                   
00202                   double corrFrac   = besttrigsCorr/besttrigs;
00203                   double secondFrac = trigsFlag2nd/trigs;
00204                   if (corrFrac < parameters.getUntrackedParameter<double>("corrFracError",.5)){
00205                     corrSummary = 2;
00206                   }
00207                   else if (corrFrac < parameters.getUntrackedParameter<double>("corrFracWarning",.6)){
00208                     corrSummary = 3;
00209                   }
00210                   else {
00211                     corrSummary = 0;
00212                   }
00213                   if (secondFrac > parameters.getUntrackedParameter<double>("secondFracError",.2)){
00214                     secondSummary = 2;
00215                   }
00216                   else if (secondFrac > parameters.getUntrackedParameter<double>("secondFracWarning",.1)){
00217                     secondSummary = 3;
00218                   }
00219                   else {
00220                     secondSummary = 0;
00221                   }
00222                   
00223                   if( secME[sector_id].find(fullName("BXDistribPhi")) == secME[sector_id].end() ){
00224                     bookSectorHistos(wh,sect,"QualDistribPhi");
00225                     bookSectorHistos(wh,sect,"BXDistribPhi");
00226                   }
00227 
00228                   TH1D* BXDistr   = BXvsQual->ProjectionY();
00229                   TH1D* QualDistr = BXvsQual->ProjectionX();
00230                   std::map<std::string,MonitorElement*> *innerME = &(secME[sector_id]);
00231                   
00232                   int nbinsBX        = BXDistr->GetNbinsX();
00233                   int firstBinCenter = static_cast<int>(BXDistr->GetBinCenter(1));
00234                   int lastBinCenter  = static_cast<int>(BXDistr->GetBinCenter(nbinsBX));
00235                   int iMin = firstBinCenter>-4 ? firstBinCenter : -4;
00236                   int iMax = lastBinCenter<20  ? lastBinCenter  : 20;
00237                   for (int ibin=iMin+5;ibin<=iMax+5; ++ibin) {
00238                     innerME->find(fullName("BXDistribPhi"))->second->setBinContent(ibin,stat,BXDistr->GetBinContent(ibin-5-firstBinCenter+1));
00239                   }
00240                   for (int ibin=1;ibin<=7;++ibin) {
00241                     innerME->find(fullName("QualDistribPhi"))->second->setBinContent(ibin,stat,QualDistr->GetBinContent(ibin));
00242                   }
00243 
00244                   delete BXDistr;
00245                   delete QualDistr;
00246 
00247                   if( whME[wh].find(fullName("CorrectBXPhi")) == whME[wh].end() ){
00248                     bookWheelHistos(wh,"ResidualBXPhi");
00249                     bookWheelHistos(wh,"CorrectBXPhi");
00250                     bookWheelHistos(wh,"CorrFractionPhi");
00251                     bookWheelHistos(wh,"2ndFractionPhi");
00252                     bookWheelHistos(wh,"TriggerInclusivePhi");
00253                   }
00254                   
00255                   innerME = &(whME[wh]);
00256                   innerME->find(fullName("CorrectBXPhi"))->second->setBinContent(sect,stat,BX_OK+0.00001);
00257                   innerME->find(fullName("ResidualBXPhi"))->second->setBinContent(sect,stat,round(25.*(BXMean-BX_OK))+0.00001);
00258                   innerME->find(fullName("CorrFractionPhi"))->second->setBinContent(sect,stat,corrFrac);
00259                   innerME->find(fullName("TriggerInclusivePhi"))->second->setBinContent(sect,stat,besttrigs);
00260                   innerME->find(fullName("2ndFractionPhi"))->second->setBinContent(sect,stat,secondFrac);
00261                   
00262                 }
00263 
00264                 whME[wh].find(fullName("CorrFractionSummary"))->second->setBinContent(sect,stat,corrSummary);
00265                 whME[wh].find(fullName("2ndFractionSummary"))->second->setBinContent(sect,stat,secondSummary);
00266 
00267               }
00268 
00269               if (hwSource=="DDU") {
00270                 // Perform DDU plot analysis (Theta ones)           
00271                 TH2F * ThetaBXvsQual = getHisto<TH2F>(dbe->get(getMEName("ThetaBXvsQual","LocalTriggerTheta", chId)));
00272                 TH1F * ThetaBestQual = getHisto<TH1F>(dbe->get(getMEName("ThetaBestQual","LocalTriggerTheta", chId)));
00273         
00274                 // no theta triggers in stat 4!
00275                 if (ThetaBXvsQual && ThetaBestQual && stat<4 && ThetaBestQual->GetEntries()>1) {
00276                   TH1D* BXH       = ThetaBXvsQual->ProjectionY("",4,4,"");
00277                   int    BXOK_bin = BXH->GetEffectiveEntries()>=1 ? BXH->GetMaximumBin(): 10;
00278                   double BX_OK    = ThetaBXvsQual->GetYaxis()->GetBinCenter(BXOK_bin);
00279                   double trigs    = ThetaBestQual->GetEntries(); 
00280                   double trigsH   = ThetaBestQual->GetBinContent(4);
00281                   delete BXH; 
00282                 
00283                   // if( secME[sector_id].find(fullName("HFractionTheta")) == secME[sector_id].end() ){
00284                   //            // bookSectorHistos(wh,sect,"CorrectBXTheta");
00285                   //            bookSectorHistos(wh,sect,"HFractionTheta");
00286                   //          }
00287                   //std::map<std::string,MonitorElement*> *innerME = &(secME.find(sector_id)->second);
00288                   // innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(stat,BX_OK);
00289                   //innerME->find(fullName("HFractionTheta"))->second->setBinContent(stat,trigsH/trigs);
00290                 
00291                   if( whME[wh].find(fullName("HFractionTheta")) == whME[wh].end() ){
00292                     bookWheelHistos(wh,"CorrectBXTheta");
00293                     bookWheelHistos(wh,"HFractionTheta");
00294                   }
00295                   std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
00296                   innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(sect,stat,BX_OK+0.00001);
00297                   innerME->find(fullName("HFractionTheta"))->second->setBinContent(sect,stat,trigsH/trigs);
00298                 
00299                 }
00300               }
00301               else if (hwSource=="DCC") {
00302                 // Perform DCC plot analysis (Theta ones)           
00303                 TH2F * ThetaPosvsBX = getHisto<TH2F>(dbe->get(getMEName("PositionvsBX","LocalTriggerTheta", chId)));
00304               
00305                 // no theta triggers in stat 4!
00306                 if (ThetaPosvsBX && stat<4 && ThetaPosvsBX->GetEntries()>1) {
00307                   TH1D* BX        = ThetaPosvsBX->ProjectionX();
00308                   int    BXOK_bin = BX->GetEffectiveEntries()>=1 ? BX->GetMaximumBin(): 10;
00309                   double BX_OK    = ThetaPosvsBX->GetXaxis()->GetBinCenter(BXOK_bin);
00310                   delete BX; 
00311                 
00312                   if( whME[wh].find(fullName("CorrectBXTheta")) == whME[wh].end() ){
00313                     bookWheelHistos(wh,"CorrectBXTheta");
00314                   }
00315                   std::map<std::string,MonitorElement*> *innerME = &(whME.find(wh)->second);
00316                   innerME->find(fullName("CorrectBXTheta"))->second->setBinContent(sect,stat,BX_OK+0.00001);
00317                 
00318                 }
00319               }
00320             }
00321 
00322           }
00323         }
00324       }
00325     }
00326   }     
00327 
00328   for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
00329     trigSource = (*iTr);
00330     for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
00331       hwSource = (*iHw);  
00332       for (int wh=-2; wh<=2; ++wh){
00333         std::map<std::string,MonitorElement*> *innerME = &(whME[wh]);
00334         if(hwSource=="COM") {
00335           TH2F* matchWhSummary   = getHisto<TH2F>(innerME->find(fullName("MatchingSummary"))->second);
00336           for (int sect=1; sect<=12; ++sect){
00337             int matchErr      = 0;
00338             int matchNoData   = 0;
00339             for (int stat=1; stat<=4; ++stat){
00340               switch (static_cast<int>(matchWhSummary->GetBinContent(sect,stat))) {
00341               case 1:
00342                 matchNoData++;
00343               case 2:
00344                 matchErr++;
00345               }
00346             }
00347             if (matchNoData == 4)   matchErr   = 5;
00348             cmsME.find(fullName("MatchingSummary"))->second->setBinContent(sect,wh+3,matchErr);
00349           }
00350         }
00351         else {
00352           TH2F* corrWhSummary   = getHisto<TH2F>(innerME->find(fullName("CorrFractionSummary"))->second);
00353           TH2F* secondWhSummary = getHisto<TH2F>(innerME->find(fullName("2ndFractionSummary"))->second);
00354           for (int sect=1; sect<=12; ++sect){
00355             int corrErr      = 0;
00356             int secondErr    = 0;
00357             int corrNoData   = 0;
00358             int secondNoData = 0;
00359             for (int stat=1; stat<=4; ++stat){
00360               switch (static_cast<int>(corrWhSummary->GetBinContent(sect,stat))) {
00361               case 1:
00362                 corrNoData++;
00363               case 2:
00364                 corrErr++;
00365               }
00366               switch (static_cast<int>(secondWhSummary->GetBinContent(sect,stat))) {
00367               case 1:
00368                 secondNoData++;
00369               case 2:
00370                 secondErr++;
00371               }
00372             }
00373             if (corrNoData == 4)   corrErr   = 5;
00374             if (secondNoData == 4) secondErr = 5;
00375             cmsME.find(fullName("CorrFractionSummary"))->second->setBinContent(sect,wh+3,corrErr);
00376             cmsME.find(fullName("2ndFractionSummary"))->second->setBinContent(sect,wh+3,secondErr);
00377           }
00378         }
00379       }
00380     }
00381   }
00382 
00383 }
00384