CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/DQM/DTMonitorClient/src/DTRunConditionVarClient.cc

Go to the documentation of this file.
00001 /******* \class DTRunConditionVarClient *******
00002  *
00003  * Description:
00004  *  
00005  *  detailed description
00006  *
00007  * \author : Paolo Bellan, Antonio Branca
00008  * $date   : 23/09/2011 15:42:04 CET $
00009  * $Revision: 1.2 $
00010  *
00011  * Modification:
00012  *
00013  *********************************/
00014 
00015 #include <DQM/DTMonitorClient/src/DTRunConditionVarClient.h>
00016 #include <DQMServices/Core/interface/MonitorElement.h>
00017 #include <DQMServices/Core/interface/DQMStore.h>
00018 
00019 #include <FWCore/Framework/interface/EventSetup.h>
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 
00022 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00023 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00024 #include "CondFormats/DataRecord/interface/DTMtimeRcd.h"
00025 
00026 #include <stdio.h>
00027 #include <sstream>
00028 #include <math.h>
00029 
00030 using namespace edm;
00031 using namespace std;
00032 
00033 DTRunConditionVarClient::DTRunConditionVarClient(const ParameterSet& pSet)
00034 {
00035 
00036   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00037     << "DTRunConditionVarClient: Constructor called";
00038 
00039 
00040   minRangeVDrift = pSet.getUntrackedParameter<double>("minRangeVDrift");
00041   maxRangeVDrift = pSet.getUntrackedParameter<double>("maxRangeVDrift");
00042   minRangeT0 = pSet.getUntrackedParameter<double>("minRangeT0");
00043   maxRangeT0 = pSet.getUntrackedParameter<double>("maxRangeT0");
00044 
00045   maxGoodVDriftDev = pSet.getUntrackedParameter<double>("maxGoodVDriftDev");
00046   minBadVDriftDev = pSet.getUntrackedParameter<double>("minBadVDriftDev");
00047   maxGoodT0 = pSet.getUntrackedParameter<double>("maxGoodT0");
00048   minBadT0 = pSet.getUntrackedParameter<double>("minBadT0");
00049 
00050   maxGoodVDriftSigma = pSet.getUntrackedParameter<double>("maxGoodVDriftSigma");
00051   minBadVDriftSigma = pSet.getUntrackedParameter<double>("minBadVDriftSigma");
00052   maxGoodT0Sigma = pSet.getUntrackedParameter<double>("maxGoodT0Sigma");
00053   minBadT0Sigma = pSet.getUntrackedParameter<double>("minBadT0Sigma");
00054 
00055   theDbe = Service<DQMStore>().operator->();
00056 
00057 }
00058 
00059 DTRunConditionVarClient::~DTRunConditionVarClient()
00060 {
00061   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00062     << "DTRunConditionVarClient: Destructor called";
00063 }
00064 
00065 void DTRunConditionVarClient::beginJob()
00066 {
00067   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00068     << "DTRunConditionVarClient: BeginJob";
00069 
00070   nevents = 0;
00071 
00072   theDbe -> setCurrentFolder("DT/02-Segments");
00073 
00074   glbVDriftSummary = theDbe->book2D("VDriftGlbSummary", "# of MBs with good mean and good sigma of vDrift",12,1,13,5,-2,3);
00075   glbT0Summary = theDbe->book2D("T0GlbSummary", "# of MBs with good mean and good sigma of t0",12,1,13,5,-2,3);
00076 
00077   theDbe -> setCurrentFolder("DT/02-Segments/02-MeanVDrift");
00078 
00079   summaryHistos["MeanVDriftGlbSummary"] = theDbe -> book2D("MeanVDriftGlbSummary","mean VDrift average per sector",12,1.,13.,5,-2.,3.);
00080   allwheelHistos["allMeanVDrift"] = theDbe -> book1D("VDriftMeanAllWheels","mean VDrift for all chambers",60,0.0048,0.006);
00081 
00082   theDbe -> setCurrentFolder("DT/02-Segments/02-SigmaVDrift");
00083 
00084   summaryHistos["SigmaVDriftGlbSummary"] = theDbe -> book2D("SigmaVDriftGlbSummary","# of Chambers with good sigma VDrift",12,1.,13.,5,-2.,3.);
00085   allwheelHistos["allSigmaVDrift"] = theDbe -> book1D("VDriftSigmaAllWheels","sigma VDrift for all chambers",30,0.,0.0006);
00086 
00087   theDbe -> setCurrentFolder("DT/02-Segments/03-MeanT0");
00088 
00089   summaryHistos["MeanT0GlbSummary"] = theDbe -> book2D("MeanT0GlbSummary","mean T0 average per sector",12,1.,13.,5,-2.,3.); 
00090   allwheelHistos["allMeanT0"] = theDbe -> book1D("T0MeanAllWheels","mean T0 for all chambers",100,-25.,25.);
00091 
00092   theDbe -> setCurrentFolder("DT/02-Segments/03-SigmaT0");
00093 
00094   summaryHistos["SigmaT0GlbSummary"] = theDbe -> book2D("SigmaT0GlbSummary","# of Chambers with good sigma T0",12,1.,13.,5,-2.,3.);
00095   allwheelHistos["allSigmaT0"] = theDbe -> book1D("T0SigmaAllWheels","sigma T0 for alla chambers",50,0,25);
00096 
00097   for(int wh=-2; wh<=2; wh++) {
00098     bookWheelHistos("MeanVDrift","02-MeanVDrift",wh,60,0.0048,0.006,true);
00099     bookWheelHistos("SigmaVDrift","02-SigmaVDrift",wh,30,0.,0.0006);
00100     bookWheelHistos("MeanT0","03-MeanT0",wh,100,-25.,25.);
00101     bookWheelHistos("SigmaT0","03-SigmaT0",wh,50,0,25);
00102   }
00103 
00104   return;
00105 }
00106 
00107 void DTRunConditionVarClient::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context)
00108 {
00109   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00110     << "[DTRunConditionVarClient]: Begin of LS transition";
00111 
00112   return;
00113 }
00114 
00115 void DTRunConditionVarClient::beginRun(const Run& run, const EventSetup& setup)
00116 {
00117   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00118     << "DTRunConditionVarClient: beginRun";
00119 
00120   return;
00121 }
00122 
00123 void DTRunConditionVarClient::analyze(const Event& e, const EventSetup& context)
00124 {
00125 
00126   nevents++;
00127   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00128     << "[DTRunConditionVarClient]: " << nevents << " events";
00129   return;
00130 }
00131 
00132 void DTRunConditionVarClient::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context)
00133 {
00134   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00135     << "DTRunConditionVarClient: endluminosityBlock";
00136 }  
00137 
00138 
00139 void DTRunConditionVarClient::endRun(Run const& run, EventSetup const& context)
00140 {
00141   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00142     << "DTRunConditionVarClient: endRun";
00143 
00144   // Get the map of vdrift from the setup
00145   context.get<DTMtimeRcd>().get(mTime);
00146   mTimeMap_ = &*mTime;
00147 
00148   for(int wheel=-2;wheel<=2;wheel++){
00149     for(int sec=1; sec<=14; sec++) {
00150       for(int stat=1; stat<=4; stat++) {
00151 
00152         if( (sec == 13 || sec == 14) && stat != 4  ) continue;
00153 
00154         // Get the ME produced by DTRunConditionVar Source
00155         MonitorElement* VDriftME = getChamberHistos(DTChamberId(wheel,stat,sec),"VDrift_FromSegm"); 
00156         MonitorElement* T0ME = getChamberHistos(DTChamberId(wheel,stat,sec),"T0_FromSegm"); 
00157 
00158         // Get the means per chamber
00159         float vDriftMean = VDriftME->getMean();
00160         float t0Mean = T0ME->getMean();
00161 
00162         // Get the sigma per chamber
00163         float vDriftSigma = VDriftME->getRMS();
00164         float t0Sigma = T0ME->getRMS();
00165 
00166         allwheelHistos["allMeanVDrift"] -> Fill(vDriftMean);
00167         allwheelHistos["allMeanT0"] -> Fill(t0Mean);
00168 
00169         allwheelHistos["allSigmaVDrift"] -> Fill(vDriftSigma);
00170         allwheelHistos["allSigmaT0"] -> Fill(t0Sigma);
00171 
00172         (wheelHistos[wheel])["MeanVDrift"] -> Fill(vDriftMean); 
00173         (wheelHistos[wheel])["MeanT0"] -> Fill(t0Mean); 
00174 
00175         (wheelHistos[wheel])["SigmaVDrift"] -> Fill(vDriftSigma); 
00176         (wheelHistos[wheel])["SigmaT0"] -> Fill(t0Sigma);
00177 
00178         //
00179         DTChamberId indexCh(wheel,stat,sec);
00180 
00181         float vDriftDev(0.), errvDriftDev(0.);
00182         percDevVDrift(indexCh, vDriftMean, vDriftSigma, vDriftDev, errvDriftDev);
00183 
00184         int sec_ = sec;
00185         if( sec == 13 || sec == 14 ) sec_ = ( sec == 13 ) ? 4 : 10;
00186 
00187         float fillvDriftDev = max(min(vDriftDev,maxRangeVDrift),minRangeVDrift);
00188         float fillT0Mean = max(min(t0Mean,maxRangeT0),minRangeT0);
00189 
00190         float vDriftDevQ = varQuality(fabs(vDriftDev),maxGoodVDriftDev,minBadVDriftDev);
00191         float t0MeanQ = varQuality(fabs(t0Mean),maxGoodT0,minBadT0);
00192 
00193         float vDriftSigmQ = varQuality(vDriftSigma,maxGoodVDriftSigma,minBadVDriftSigma);
00194         float t0SigmQ = varQuality(t0Sigma,maxGoodT0Sigma,minBadT0Sigma);
00195 
00196         if( sec == 13 ||  sec == 14 ) {
00197 
00198           float binVDriftDev = (wheelHistos[wheel])["MeanVDriftSummary"]->getBinContent(sec_,stat);
00199           binVDriftDev = (fabs(binVDriftDev) > fabs(fillvDriftDev)) ? binVDriftDev : fillvDriftDev;
00200           (wheelHistos[wheel])["MeanVDriftSummary"] -> setBinContent(sec_,stat,binVDriftDev);
00201 
00202           float binT0MeanVal = (wheelHistos[wheel])["MeanT0Summary"] -> getBinContent(sec_,stat);
00203           binT0MeanVal = (fabs(binT0MeanVal) > fabs(fillT0Mean)) ? binT0MeanVal : fillT0Mean;
00204           (wheelHistos[wheel])["MeanT0Summary"] -> setBinContent(sec_,stat,binT0MeanVal);
00205 
00206           float binVDriftSigmVal = (wheelHistos[wheel])["SigmaVDriftSummary"] -> getBinContent(sec_,stat);
00207           binVDriftSigmVal = (binVDriftSigmVal > 0. && binVDriftSigmVal < vDriftSigmQ) ? binVDriftSigmVal : vDriftSigmQ;
00208           (wheelHistos[wheel])["SigmaVDriftSummary"] -> setBinContent(sec_,stat,binVDriftSigmVal); 
00209 
00210           float binT0SigmVal = (wheelHistos[wheel])["SigmaT0Summary"] -> getBinContent(sec_,stat);
00211           binT0SigmVal = (binT0SigmVal > 0. && binT0SigmVal < t0SigmQ) ? binT0SigmVal : t0SigmQ;
00212           (wheelHistos[wheel])["SigmaT0Summary"] -> setBinContent(sec_,stat,binT0SigmVal);
00213 
00214         } else {
00215 
00216           (wheelHistos[wheel])["MeanVDriftSummary"] -> setBinContent(sec_,stat,fillvDriftDev);
00217           (wheelHistos[wheel])["MeanT0Summary"] -> setBinContent(sec_,stat,fillT0Mean);
00218           (wheelHistos[wheel])["SigmaVDriftSummary"] -> setBinContent(sec_,stat,vDriftSigmQ); 
00219           (wheelHistos[wheel])["SigmaT0Summary"] -> setBinContent(sec_,stat,t0SigmQ);
00220 
00221         }
00222 
00223         double weight = 1/4.;
00224         if(( sec_ == 4 || sec_ == 10) && stat == 4)  weight = 1/8.;
00225 
00226         if( vDriftDevQ > 0.85 && vDriftSigmQ > 0.85 ) {
00227           glbVDriftSummary -> Fill(sec_,wheel,weight);
00228           summaryHistos["MeanVDriftGlbSummary"] -> Fill(sec_,wheel,weight); 
00229           summaryHistos["SigmaVDriftGlbSummary"] -> Fill(sec_,wheel,weight);
00230 
00231         } else {
00232           if( vDriftDevQ > 0.85 && vDriftSigmQ < 0.85 ) {
00233             summaryHistos["MeanVDriftGlbSummary"] -> Fill(sec_,wheel,weight); 
00234           }
00235           if( vDriftDevQ < 0.85 && vDriftSigmQ > 0.85 ) {
00236             summaryHistos["SigmaVDriftGlbSummary"] -> Fill(sec_,wheel,weight);
00237           }
00238         }
00239 
00240         if( t0MeanQ > 0.85 && t0SigmQ > 0.85 ) {
00241           glbT0Summary -> Fill(sec_,wheel,weight);
00242           summaryHistos["MeanT0GlbSummary"] -> Fill(sec_,wheel,weight);
00243           summaryHistos["SigmaT0GlbSummary"] -> Fill(sec_,wheel,weight);
00244         } else {
00245           if( t0MeanQ > 0.85 && t0SigmQ < 0.85 ) {
00246             summaryHistos["MeanT0GlbSummary"] -> Fill(sec_,wheel,weight);
00247 
00248           }
00249           if( t0MeanQ < 0.85 && t0SigmQ > 0.85 ) {
00250             summaryHistos["SigmaT0GlbSummary"] -> Fill(sec_,wheel,weight);
00251           }
00252         }
00253 
00254 
00255       }// end loop on stations
00256     }// end loop on sectors
00257   }//end loop on wheels
00258 
00259   return;
00260 }
00261 
00262 void DTRunConditionVarClient::endJob()
00263 {
00264   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00265     << "DTRunConditionVarClient: endJob";
00266   return;
00267 }
00268 
00269 float DTRunConditionVarClient::varQuality(float var, float maxGood, float minBad) {
00270 
00271   float qual(0);
00272   if( var <= maxGood ) {qual = 1.;}
00273   else if( var > maxGood && var < minBad ) {qual = 0.9;}
00274   else if( var >= minBad ) {qual = 0.1;}
00275 
00276   return qual;
00277 }
00278 
00279 void DTRunConditionVarClient::percDevVDrift(DTChamberId indexCh, float meanVD, float sigmaVD, float& devVD, float& errdevVD) {
00280 
00281   DTSuperLayerId indexSLPhi1(indexCh,1);
00282   DTSuperLayerId indexSLPhi2(indexCh,3);
00283 
00284   float vDriftPhi1(0.), vDriftPhi2(0.); 
00285   float ResPhi1(0.), ResPhi2(0.);
00286   int status1 = mTimeMap_->get(indexSLPhi1,vDriftPhi1,ResPhi1,DTVelocityUnits::cm_per_ns); 
00287   int status2 = mTimeMap_->get(indexSLPhi2,vDriftPhi2,ResPhi2,DTVelocityUnits::cm_per_ns); 
00288 
00289   if(status1 != 0 || status2 != 0) {
00290     DTSuperLayerId sl = (status1 != 0) ? indexSLPhi1 : indexSLPhi2; 
00291     throw cms::Exception("DTRunConditionVarClient") << "Could not find vDrift entry in DB for"
00292       << sl << endl;
00293   }
00294 
00295   float vDriftMed = (vDriftPhi1 + vDriftPhi2) / 2.;
00296 
00297   devVD = (meanVD - vDriftMed) / vDriftMed;
00298   devVD = devVD < 1. ? devVD  : 1.;
00299 
00300   errdevVD = sigmaVD/vDriftMed;
00301 
00302   return;
00303 }
00304 
00305 void DTRunConditionVarClient::bookWheelHistos(string histoType, string subfolder, int wh, int nbins, float min, float max, bool isVDCorr )
00306 {
00307   stringstream wheel; wheel << wh;
00308 
00309   string folder = "DT/02-Segments/" + subfolder; 
00310 
00311   theDbe->setCurrentFolder(folder);
00312 
00313   string histoName = histoType + "_W" + wheel.str();
00314   string histoLabel = histoType;
00315 
00316   (wheelHistos[wh])[histoType] = theDbe -> book1D(histoName, histoLabel, nbins, min, max);
00317 
00318 
00319   if( isVDCorr ) {
00320     histoLabel = "Summary of corrections to VDrift DB values";
00321     histoName = "CorrTo" + histoType + "Summary_W" + wheel.str();
00322   } else {
00323     histoLabel = histoType + "Summary";
00324     histoName = histoType + "Summary_W" + wheel.str();
00325   }
00326 
00327   MonitorElement* me = theDbe -> book2D(histoName, histoLabel,12,1,13,4,1,5);
00328 
00329   me->setBinLabel(1,"MB1",2);
00330   me->setBinLabel(2,"MB2",2);
00331   me->setBinLabel(3,"MB3",2);
00332   me->setBinLabel(4,"MB4",2);
00333   me->setAxisTitle("Sector",1);
00334 
00335   (wheelHistos[wh])[histoType + "Summary"] = me;
00336 
00337   return;
00338 }
00339 
00340 MonitorElement* DTRunConditionVarClient::getChamberHistos(const DTChamberId& dtCh, string histoType) {
00341 
00342   int wh = dtCh.wheel();                
00343   int sc = dtCh.sector();       
00344   int st = dtCh.station();
00345   stringstream wheel; wheel << wh;      
00346   stringstream station; station << st;  
00347   stringstream sector; sector << sc;    
00348 
00349   string folder = "DT/02-Segments/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
00350   string histoTag      = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00351   string MEpath = folder + "/" + histoType + histoTag;
00352 
00353   theDbe->setCurrentFolder(folder);
00354 
00355   LogTrace ("DTDQM|DTMonitorModule|DTRunConditionVar") 
00356     << "[DTRunConditionVar]: getting ME from " << folder << endl;
00357 
00358   MonitorElement* ME = theDbe -> get(MEpath);
00359 
00360   return ME;
00361 }