CMS 3D CMS Logo

DTtTrigCalibrationTest.cc

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

Generated on Tue Jun 9 17:32:35 2009 for CMSSW by  doxygen 1.5.4