CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/DTMonitorClient/src/DTtTrigCalibrationTest.cc

Go to the documentation of this file.
00001 /*
00002  * \file DTtTrigCalibrationTest.cc
00003  * 
00004  * $Date: 2010/01/05 10:15:46 $
00005  * $Revision: 1.20 $
00006  * \author M. Zanetti - CERN
00007  * Modified by G. Mila - INFN Torino
00008  *
00009  */
00010 
00011 
00012 #include "DQM/DTMonitorClient/src/DTtTrigCalibrationTest.h"
00013 
00014 // Framework
00015 #include <FWCore/Framework/interface/EventSetup.h>
00016 
00017 
00018 // Geometry
00019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00020 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00021 
00022 #include <CondFormats/DTObjects/interface/DTTtrig.h>
00023 #include <CondFormats/DataRecord/interface/DTTtrigRcd.h>
00024 
00025 #include "DQMServices/Core/interface/DQMStore.h"
00026 #include "DQMServices/Core/interface/MonitorElement.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028 
00029 // the Timebox fitter
00030 #include "CalibMuon/DTCalibration/interface/DTTimeBoxFitter.h"
00031 
00032 #include <stdio.h>
00033 #include <sstream>
00034 #include <math.h>
00035 
00036 using namespace edm;
00037 using namespace std;
00038 
00039 DTtTrigCalibrationTest::DTtTrigCalibrationTest(const edm::ParameterSet& ps){
00040   
00041   edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: Constructor";
00042 
00043   parameters = ps;
00044   
00045   dbe = edm::Service<DQMStore>().operator->();
00046 
00047   theFitter = new DTTimeBoxFitter();
00048 
00049   prescaleFactor = parameters.getUntrackedParameter<int>("diagnosticPrescale", 3);
00050 
00051   percentual = parameters.getUntrackedParameter<int>("BadSLpercentual", 10);
00052 
00053 }
00054 
00055 
00056 DTtTrigCalibrationTest::~DTtTrigCalibrationTest(){
00057 
00058   edm::LogVerbatim ("tTrigCalibration") <<"DTtTrigCalibrationTest: analyzed " << nevents << " events";
00059 
00060   delete theFitter;
00061 
00062 }
00063 
00064 
00065 void DTtTrigCalibrationTest::beginJob(){
00066 
00067   edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: BeginJob";
00068 
00069   nevents = 0;
00070 
00071 }
00072 
00073 
00074 void DTtTrigCalibrationTest::beginRun(Run const& run, EventSetup const& context) {
00075 
00076   edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: BeginRun";
00077 
00078   // Get the geometry
00079   context.get<MuonGeometryRecord>().get(muonGeom);
00080 
00081 }
00082 
00083 void DTtTrigCalibrationTest::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00084 
00085   edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: Begin of LS transition";
00086 
00087   // Get the run number
00088   run = lumiSeg.run();
00089 
00090 }
00091 
00092 
00093 void DTtTrigCalibrationTest::analyze(const edm::Event& e, const edm::EventSetup& context){
00094 
00095   nevents++;
00096   edm::LogVerbatim ("tTrigCalibration") << "[DTtTrigCalibrationTest]: "<<nevents<<" events";
00097 
00098 }
00099 
00100 
00101 void DTtTrigCalibrationTest::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00102 
00103 
00104   // counts number of updats (online mode) or number of events (standalone mode)
00105   //nevents++;
00106   // if running in standalone perform diagnostic only after a reasonalbe amount of events
00107   //if ( parameters.getUntrackedParameter<bool>("runningStandalone", false) && 
00108   //   nevents%parameters.getUntrackedParameter<int>("diagnosticPrescale", 1000) != 0 ) return;
00109   //edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: "<<nevents<<" updates";
00110 
00111 
00112   edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: End of LS transition, performing the DQM client operation";
00113 
00114   // counts number of lumiSegs 
00115   nLumiSegs = lumiSeg.id().luminosityBlock();
00116 
00117   // prescale factor
00118   if ( nLumiSegs%prescaleFactor != 0 ) return;
00119 
00120   for(map<int, MonitorElement*> ::const_iterator histo = wheelHistos.begin();
00121       histo != wheelHistos.end();
00122       histo++) {
00123     (*histo).second->Reset();
00124   }
00125   
00126   edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: "<<nLumiSegs<<" updates";
00127 
00128   context.get<DTTtrigRcd>().get(tTrigMap);
00129   float tTrig, tTrigRMS,kFactor;
00130 
00131   map <pair<int,int>, int> cmsHistos;
00132   cmsHistos.clear();
00133   map <pair<int,int>, bool> filled;
00134   for(int i=-2; i<3; i++){
00135     for(int j=1; j<15; j++){
00136       filled[make_pair(i,j)]=false;
00137     }
00138   }
00139   
00140   vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00141   vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00142   for (; ch_it != ch_end; ++ch_it) {
00143     
00144     vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin(); 
00145     vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
00146     for(; sl_it != sl_end; ++sl_it) {
00147       
00148       DTSuperLayerId slID = (*sl_it)->id();
00149       
00150       MonitorElement * tb_histo = dbe->get(getMEName(slID));
00151       if (tb_histo) {
00152         
00153         edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest]: I've got the histo!!";       
00154 
00155         TH1F * tb_histo_root = tb_histo->getTH1F();
00156             
00157         pair<double, double> meanAndSigma = theFitter->fitTimeBox(tb_histo_root);
00158             
00159         // ttrig and rms are counts
00160         tTrigMap->get(slID, tTrig, tTrigRMS, kFactor, DTTimeUnits::counts );
00161 
00162         if (histos.find((*ch_it)->id().rawId()) == histos.end()) bookHistos((*ch_it)->id());
00163         histos.find((*ch_it)->id().rawId())->second->setBinContent(slID.superLayer(), meanAndSigma.first-tTrig);
00164 
00165       }
00166     }
00167     
00168     if (histos.find((*ch_it)->id().rawId()) != histos.end()) {
00169       string criterionName = parameters.getUntrackedParameter<string>("tTrigTestName","tTrigOffSet"); 
00170       const QReport * theQReport = histos.find((*ch_it)->id().rawId())->second->getQReport(criterionName);
00171       if(theQReport) {
00172         vector<dqm::me_util::Channel> badChannels = theQReport->getBadChannels();
00173         for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00174              channel != badChannels.end(); channel++) {
00175           edm::LogError ("tTrigCalibration") <<"Chamber ID : "<<(*ch_it)->id()<<" Bad channels: "<<(*channel).getBin()<<" "<<(*channel).getContents();
00176           if(wheelHistos.find((*ch_it)->id().wheel()) == wheelHistos.end()) bookHistos((*ch_it)->id(), (*ch_it)->id().wheel());
00177           // fill the wheel summary histos if the SL has not passed the test
00178           if(!((*ch_it)->id().station() == 4 && (*channel).getBin() == 3))
00179             wheelHistos[(*ch_it)->id().wheel()]->Fill((*ch_it)->id().sector()-1,((*channel).getBin()-1)+3*((*ch_it)->id().station()-1));
00180           else 
00181             wheelHistos[(*ch_it)->id().wheel()]->Fill((*ch_it)->id().sector()-1,10);
00182           // fill the cms summary histo if the percentual of SL which have not passed the test 
00183           // is more than a predefined treshold
00184           cmsHistos[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())]++;
00185           if(((*ch_it)->id().sector()<13 &&
00186               double(cmsHistos[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())])/11>double(percentual)/100 &&
00187               filled[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())]==false) ||
00188              ((*ch_it)->id().sector()>=13 && 
00189               double(cmsHistos[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())])/2>double(percentual)/100 &&
00190               filled[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())]==false)){
00191             filled[make_pair((*ch_it)->id().wheel(),(*ch_it)->id().sector())]=true;
00192             wheelHistos[3]->Fill((*ch_it)->id().sector()-1,(*ch_it)->id().wheel());
00193           }
00194         }
00195         // FIXME: getMessage() sometimes returns and invalid string (null pointer inside QReport data member)
00196         // edm::LogWarning ("tTrigCalibration") <<"-------- "<<theQReport->getMessage()<<" ------- "<<theQReport->getStatus();
00197       } 
00198     }
00199 
00200   }
00201 
00202 }
00203 
00204 
00205 void DTtTrigCalibrationTest::endJob(){
00206 
00207   edm::LogVerbatim ("tTrigCalibration") <<"[DTtTrigCalibrationTest] endjob called!";
00208 
00209   dbe->rmdir("DT/Tests/DTtTrigCalibration");
00210 }
00211 
00212 
00213 
00214 
00215 string DTtTrigCalibrationTest::getMEName(const DTSuperLayerId & slID) {
00216 
00217   stringstream wheel; wheel << slID.wheel();    
00218   stringstream station; station << slID.station();      
00219   stringstream sector; sector << slID.sector(); 
00220   stringstream superLayer; superLayer << slID.superlayer();
00221 
00222   string folderRoot = parameters.getUntrackedParameter<string>("folderRoot", "Collector/FU0/");
00223   string folderTag = parameters.getUntrackedParameter<string>("folderTag", "TimeBoxes");
00224   string folderName = 
00225     folderRoot + "DT/DTDigiTask/Wheel" +  wheel.str() +
00226     "/Station" + station.str() +
00227     "/Sector" + sector.str() + "/" + folderTag + "/";
00228 
00229   string histoTag = parameters.getUntrackedParameter<string>("histoTag", "TimeBox");
00230   string histoname = folderName + histoTag  
00231     + "_W" + wheel.str() 
00232     + "_St" + station.str() 
00233     + "_Sec" + sector.str() 
00234     + "_SL" + superLayer.str(); 
00235   
00236   return histoname;
00237   
00238 }
00239 
00240 
00241 
00242 void DTtTrigCalibrationTest::bookHistos(const DTChamberId & ch) {
00243 
00244   stringstream wheel; wheel << ch.wheel();      
00245   stringstream station; station << ch.station();        
00246   stringstream sector; sector << ch.sector();   
00247 
00248   string histoName =  "tTrigTest_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str(); 
00249 
00250   dbe->setCurrentFolder("DT/Tests/DTtTrigCalibration");
00251   
00252   histos[ch.rawId()] = dbe->book1D(histoName.c_str(),histoName.c_str(),3,0,2);
00253 
00254 }
00255 
00256 void DTtTrigCalibrationTest::bookHistos(const DTChamberId & ch, int wh) {
00257   
00258   dbe->setCurrentFolder("DT/Tests/DTtTrigCalibration/SummaryPlot");
00259 
00260   if(wheelHistos.find(3) == wheelHistos.end()){
00261     string histoName =  "t_TrigSummary_testFailedByAtLeastBadSL";
00262     wheelHistos[3] = dbe->book2D(histoName.c_str(),histoName.c_str(),14,0,14,5,-2,2);
00263     wheelHistos[3]->setBinLabel(1,"Sector1",1);
00264     wheelHistos[3]->setBinLabel(1,"Sector1",1);
00265     wheelHistos[3]->setBinLabel(2,"Sector2",1);
00266     wheelHistos[3]->setBinLabel(3,"Sector3",1);
00267     wheelHistos[3]->setBinLabel(4,"Sector4",1);
00268     wheelHistos[3]->setBinLabel(5,"Sector5",1);
00269     wheelHistos[3]->setBinLabel(6,"Sector6",1);
00270     wheelHistos[3]->setBinLabel(7,"Sector7",1);
00271     wheelHistos[3]->setBinLabel(8,"Sector8",1);
00272     wheelHistos[3]->setBinLabel(9,"Sector9",1);
00273     wheelHistos[3]->setBinLabel(10,"Sector10",1);
00274     wheelHistos[3]->setBinLabel(11,"Sector11",1);
00275     wheelHistos[3]->setBinLabel(12,"Sector12",1);
00276     wheelHistos[3]->setBinLabel(13,"Sector13",1);
00277     wheelHistos[3]->setBinLabel(14,"Sector14",1);
00278     wheelHistos[3]->setBinLabel(1,"Wheel-2",2);
00279     wheelHistos[3]->setBinLabel(2,"Wheel-1",2);
00280     wheelHistos[3]->setBinLabel(3,"Wheel0",2);
00281     wheelHistos[3]->setBinLabel(4,"Wheel+1",2);
00282     wheelHistos[3]->setBinLabel(5,"Wheel+2",2);
00283   }
00284 
00285   stringstream wheel; wheel <<wh;
00286   string histoName =  "t_TrigSummary_testFailed_W" + wheel.str();
00287   wheelHistos[wh] = dbe->book2D(histoName.c_str(),histoName.c_str(),14,0,14,11,0,11);
00288   wheelHistos[wh]->setBinLabel(1,"Sector1",1);
00289   wheelHistos[wh]->setBinLabel(2,"Sector2",1);
00290   wheelHistos[wh]->setBinLabel(3,"Sector3",1);
00291   wheelHistos[wh]->setBinLabel(4,"Sector4",1);
00292   wheelHistos[wh]->setBinLabel(5,"Sector5",1);
00293   wheelHistos[wh]->setBinLabel(6,"Sector6",1);
00294   wheelHistos[wh]->setBinLabel(7,"Sector7",1);
00295   wheelHistos[wh]->setBinLabel(8,"Sector8",1);
00296   wheelHistos[wh]->setBinLabel(9,"Sector9",1);
00297   wheelHistos[wh]->setBinLabel(10,"Sector10",1);
00298   wheelHistos[wh]->setBinLabel(11,"Sector11",1);
00299   wheelHistos[wh]->setBinLabel(12,"Sector12",1);
00300   wheelHistos[wh]->setBinLabel(13,"Sector13",1);
00301   wheelHistos[wh]->setBinLabel(14,"Sector14",1);
00302   wheelHistos[wh]->setBinLabel(1,"MB1_SL1",2);
00303   wheelHistos[wh]->setBinLabel(2,"MB1_SL2",2);
00304   wheelHistos[wh]->setBinLabel(3,"MB1_SL3",2);
00305   wheelHistos[wh]->setBinLabel(4,"MB2_SL1",2);
00306   wheelHistos[wh]->setBinLabel(5,"MB2_SL2",2);
00307   wheelHistos[wh]->setBinLabel(6,"MB2_SL3",2);
00308   wheelHistos[wh]->setBinLabel(7,"MB3_SL1",2);
00309   wheelHistos[wh]->setBinLabel(8,"MB3_SL2",2);
00310   wheelHistos[wh]->setBinLabel(9,"MB3_SL3",2);
00311   wheelHistos[wh]->setBinLabel(10,"MB4_SL1",2);
00312   wheelHistos[wh]->setBinLabel(11,"MB4_SL3",2);
00313 
00314 }
00315