CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/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.3 $
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         if( VDriftME->getEntries() != 0 ) {
00167 
00168           allwheelHistos["allMeanVDrift"] -> Fill(vDriftMean);
00169           allwheelHistos["allSigmaVDrift"] -> Fill(vDriftSigma);
00170 
00171           (wheelHistos[wheel])["MeanVDrift"] -> Fill(vDriftMean); 
00172           (wheelHistos[wheel])["SigmaVDrift"] -> Fill(vDriftSigma); 
00173 
00174         }
00175 
00176 
00177         if( T0ME->getEntries() != 0 ) {
00178 
00179           allwheelHistos["allMeanT0"] -> Fill(t0Mean);
00180           allwheelHistos["allSigmaT0"] -> Fill(t0Sigma);
00181 
00182           (wheelHistos[wheel])["MeanT0"] -> Fill(t0Mean); 
00183           (wheelHistos[wheel])["SigmaT0"] -> Fill(t0Sigma);
00184 
00185         }
00186 
00187         //
00188         DTChamberId indexCh(wheel,stat,sec);
00189 
00190         float vDriftDev(0.), errvDriftDev(0.);
00191         percDevVDrift(indexCh, vDriftMean, vDriftSigma, vDriftDev, errvDriftDev);
00192 
00193         int sec_ = sec;
00194         if( sec == 13 || sec == 14 ) sec_ = ( sec == 13 ) ? 4 : 10;
00195 
00196         float fillvDriftDev = max(min(vDriftDev,maxRangeVDrift),minRangeVDrift);
00197         float fillT0Mean = max(min(t0Mean,maxRangeT0),minRangeT0);
00198 
00199         float vDriftDevQ = varQuality(fabs(vDriftDev),maxGoodVDriftDev,minBadVDriftDev);
00200         float t0MeanQ = varQuality(fabs(t0Mean),maxGoodT0,minBadT0);
00201 
00202         float vDriftSigmQ = varQuality(vDriftSigma,maxGoodVDriftSigma,minBadVDriftSigma);
00203         float t0SigmQ = varQuality(t0Sigma,maxGoodT0Sigma,minBadT0Sigma);
00204 
00205         if( sec == 13 ||  sec == 14 ) {
00206 
00207           float binVDriftDev = (wheelHistos[wheel])["MeanVDriftSummary"]->getBinContent(sec_,stat);
00208           binVDriftDev = (fabs(binVDriftDev) > fabs(fillvDriftDev)) ? binVDriftDev : fillvDriftDev;
00209           (wheelHistos[wheel])["MeanVDriftSummary"] -> setBinContent(sec_,stat,binVDriftDev);
00210 
00211           float binT0MeanVal = (wheelHistos[wheel])["MeanT0Summary"] -> getBinContent(sec_,stat);
00212           binT0MeanVal = (fabs(binT0MeanVal) > fabs(fillT0Mean)) ? binT0MeanVal : fillT0Mean;
00213           (wheelHistos[wheel])["MeanT0Summary"] -> setBinContent(sec_,stat,binT0MeanVal);
00214 
00215           float binVDriftSigmVal = (wheelHistos[wheel])["SigmaVDriftSummary"] -> getBinContent(sec_,stat);
00216           binVDriftSigmVal = (binVDriftSigmVal > 0. && binVDriftSigmVal < vDriftSigmQ) ? binVDriftSigmVal : vDriftSigmQ;
00217           (wheelHistos[wheel])["SigmaVDriftSummary"] -> setBinContent(sec_,stat,binVDriftSigmVal); 
00218 
00219           float binT0SigmVal = (wheelHistos[wheel])["SigmaT0Summary"] -> getBinContent(sec_,stat);
00220           binT0SigmVal = (binT0SigmVal > 0. && binT0SigmVal < t0SigmQ) ? binT0SigmVal : t0SigmQ;
00221           (wheelHistos[wheel])["SigmaT0Summary"] -> setBinContent(sec_,stat,binT0SigmVal);
00222 
00223         } else {
00224 
00225           (wheelHistos[wheel])["MeanVDriftSummary"] -> setBinContent(sec_,stat,fillvDriftDev);
00226           (wheelHistos[wheel])["MeanT0Summary"] -> setBinContent(sec_,stat,fillT0Mean);
00227           (wheelHistos[wheel])["SigmaVDriftSummary"] -> setBinContent(sec_,stat,vDriftSigmQ); 
00228           (wheelHistos[wheel])["SigmaT0Summary"] -> setBinContent(sec_,stat,t0SigmQ);
00229 
00230         }
00231 
00232         double weight = 1/4.;
00233         if(( sec_ == 4 || sec_ == 10) && stat == 4)  weight = 1/8.;
00234 
00235         if( vDriftDevQ > 0.85 && vDriftSigmQ > 0.85 ) {
00236           glbVDriftSummary -> Fill(sec_,wheel,weight);
00237           summaryHistos["MeanVDriftGlbSummary"] -> Fill(sec_,wheel,weight); 
00238           summaryHistos["SigmaVDriftGlbSummary"] -> Fill(sec_,wheel,weight);
00239 
00240         } else {
00241           if( vDriftDevQ > 0.85 && vDriftSigmQ < 0.85 ) {
00242             summaryHistos["MeanVDriftGlbSummary"] -> Fill(sec_,wheel,weight); 
00243           }
00244           if( vDriftDevQ < 0.85 && vDriftSigmQ > 0.85 ) {
00245             summaryHistos["SigmaVDriftGlbSummary"] -> Fill(sec_,wheel,weight);
00246           }
00247         }
00248 
00249         if( t0MeanQ > 0.85 && t0SigmQ > 0.85 ) {
00250           glbT0Summary -> Fill(sec_,wheel,weight);
00251           summaryHistos["MeanT0GlbSummary"] -> Fill(sec_,wheel,weight);
00252           summaryHistos["SigmaT0GlbSummary"] -> Fill(sec_,wheel,weight);
00253         } else {
00254           if( t0MeanQ > 0.85 && t0SigmQ < 0.85 ) {
00255             summaryHistos["MeanT0GlbSummary"] -> Fill(sec_,wheel,weight);
00256 
00257           }
00258           if( t0MeanQ < 0.85 && t0SigmQ > 0.85 ) {
00259             summaryHistos["SigmaT0GlbSummary"] -> Fill(sec_,wheel,weight);
00260           }
00261         }
00262 
00263 
00264       }// end loop on stations
00265     }// end loop on sectors
00266   }//end loop on wheels
00267 
00268   return;
00269 }
00270 
00271 void DTRunConditionVarClient::endJob()
00272 {
00273   LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
00274     << "DTRunConditionVarClient: endJob";
00275   return;
00276 }
00277 
00278 float DTRunConditionVarClient::varQuality(float var, float maxGood, float minBad) {
00279 
00280   float qual(0);
00281   if( var <= maxGood ) {qual = 1.;}
00282   else if( var > maxGood && var < minBad ) {qual = 0.9;}
00283   else if( var >= minBad ) {qual = 0.1;}
00284 
00285   return qual;
00286 }
00287 
00288 void DTRunConditionVarClient::percDevVDrift(DTChamberId indexCh, float meanVD, float sigmaVD, float& devVD, float& errdevVD) {
00289 
00290   DTSuperLayerId indexSLPhi1(indexCh,1);
00291   DTSuperLayerId indexSLPhi2(indexCh,3);
00292 
00293   float vDriftPhi1(0.), vDriftPhi2(0.); 
00294   float ResPhi1(0.), ResPhi2(0.);
00295   int status1 = mTimeMap_->get(indexSLPhi1,vDriftPhi1,ResPhi1,DTVelocityUnits::cm_per_ns); 
00296   int status2 = mTimeMap_->get(indexSLPhi2,vDriftPhi2,ResPhi2,DTVelocityUnits::cm_per_ns); 
00297 
00298   if(status1 != 0 || status2 != 0) {
00299     DTSuperLayerId sl = (status1 != 0) ? indexSLPhi1 : indexSLPhi2; 
00300     throw cms::Exception("DTRunConditionVarClient") << "Could not find vDrift entry in DB for"
00301       << sl << endl;
00302   }
00303 
00304   float vDriftMed = (vDriftPhi1 + vDriftPhi2) / 2.;
00305 
00306   devVD = (meanVD - vDriftMed) / vDriftMed;
00307   devVD = devVD < 1. ? devVD  : 1.;
00308 
00309   errdevVD = sigmaVD/vDriftMed;
00310 
00311   return;
00312 }
00313 
00314 void DTRunConditionVarClient::bookWheelHistos(string histoType, string subfolder, int wh, int nbins, float min, float max, bool isVDCorr )
00315 {
00316   stringstream wheel; wheel << wh;
00317 
00318   string folder = "DT/02-Segments/" + subfolder; 
00319 
00320   theDbe->setCurrentFolder(folder);
00321 
00322   string histoName = histoType + "_W" + wheel.str();
00323   string histoLabel = histoType;
00324 
00325   (wheelHistos[wh])[histoType] = theDbe -> book1D(histoName, histoLabel, nbins, min, max);
00326 
00327 
00328   if( isVDCorr ) {
00329     histoLabel = "Summary of corrections to VDrift DB values";
00330     histoName = "CorrTo" + histoType + "Summary_W" + wheel.str();
00331   } else {
00332     histoLabel = histoType + "Summary";
00333     histoName = histoType + "Summary_W" + wheel.str();
00334   }
00335 
00336   MonitorElement* me = theDbe -> book2D(histoName, histoLabel,12,1,13,4,1,5);
00337 
00338   me->setBinLabel(1,"MB1",2);
00339   me->setBinLabel(2,"MB2",2);
00340   me->setBinLabel(3,"MB3",2);
00341   me->setBinLabel(4,"MB4",2);
00342   me->setAxisTitle("Sector",1);
00343 
00344   (wheelHistos[wh])[histoType + "Summary"] = me;
00345 
00346   return;
00347 }
00348 
00349 MonitorElement* DTRunConditionVarClient::getChamberHistos(const DTChamberId& dtCh, string histoType) {
00350 
00351   int wh = dtCh.wheel();                
00352   int sc = dtCh.sector();       
00353   int st = dtCh.station();
00354   stringstream wheel; wheel << wh;      
00355   stringstream station; station << st;  
00356   stringstream sector; sector << sc;    
00357 
00358   string folder = "DT/02-Segments/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
00359   string histoTag      = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
00360   string MEpath = folder + "/" + histoType + histoTag;
00361 
00362   theDbe->setCurrentFolder(folder);
00363 
00364   LogTrace ("DTDQM|DTMonitorModule|DTRunConditionVar") 
00365     << "[DTRunConditionVar]: getting ME from " << folder << endl;
00366 
00367   MonitorElement* ME = theDbe -> get(MEpath);
00368 
00369   return ME;
00370 }