CMS 3D CMS Logo

DTt0DBValidation.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2008/04/24 17:23:49 $
00006  *  $Revision: 1.3 $
00007  *  \author G. Mila - INFN Torino
00008  */
00009 
00010 #include "DQMOffline/CalibMuon/interface/DTt0DBValidation.h"
00011 
00012 // Framework
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/ServiceRegistry/interface/Service.h"
00017 
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 #include "DQMServices/Core/interface/MonitorElement.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 
00022 // Geometry
00023 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00024 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00025 #include "Geometry/DTGeometry/interface/DTLayer.h"
00026 #include "Geometry/DTGeometry/interface/DTTopology.h"
00027 
00028 // t0
00029 #include "CondFormats/DTObjects/interface/DTT0.h"
00030 #include "CondFormats/DataRecord/interface/DTT0Rcd.h"
00031 
00032 #include <stdio.h>
00033 #include <sstream>
00034 #include <math.h>
00035 #include "TFile.h"
00036 
00037 using namespace edm;
00038 using namespace std;
00039 
00040 
00041 
00042 
00043 DTt0DBValidation::DTt0DBValidation(const ParameterSet& pset) {
00044 
00045   cout << "[DTt0DBValidation] Constructor called!" << endl;
00046 
00047   // Get the DQM needed services
00048   dbe = edm::Service<DQMStore>().operator->();
00049   dbe->setCurrentFolder("DT/DTDBValidation");
00050 
00051   // Get dataBase label
00052   labelDBRef = pset.getUntrackedParameter<string>("labelDBRef");
00053   labelDB = pset.getUntrackedParameter<string>("labelDB");
00054 
00055   parameters = pset;
00056 }
00057 
00058 
00059 DTt0DBValidation::~DTt0DBValidation(){}
00060 
00061 
00062 void DTt0DBValidation::beginJob(const EventSetup& setup) {
00063 
00064 
00065   metname = "t0dbValidation";
00066   LogTrace(metname)<<"[DTt0DBValidation] Parameters initialization";
00067  
00068   outputFileName = parameters.getUntrackedParameter<std::string>("OutputFileName");
00069 
00070   ESHandle<DTT0> t0_Ref;
00071   setup.get<DTT0Rcd>().get(labelDBRef, t0_Ref);
00072   tZeroRefMap = &*t0_Ref;
00073   LogTrace(metname)<<"[DTt0DBValidation] reference T0 version: " << t0_Ref->version();
00074 
00075   ESHandle<DTT0> t0;
00076   setup.get<DTT0Rcd>().get(labelDB, t0);
00077   tZeroMap = &*t0;
00078   LogTrace(metname)<<"[DTt0DBValidation] T0 to validate version: " << t0->version();
00079 
00080   // Get the geometry
00081   setup.get<MuonGeometryRecord>().get(dtGeom);
00082 
00083   // Loop over Ref DB entries
00084   for(DTT0::const_iterator tzero = tZeroRefMap->begin();
00085       tzero != tZeroRefMap->end(); tzero++) {
00086     DTWireId wireId((*tzero).first.wheelId,
00087                     (*tzero).first.stationId,
00088                     (*tzero).first.sectorId,
00089                     (*tzero).first.slId,
00090                     (*tzero).first.layerId,
00091                     (*tzero).first.cellId);
00092     float t0mean = (*tzero).second.t0mean;
00093     float t0rms = (*tzero).second.t0rms;
00094     LogTrace(metname)<< "Ref Wire: " <<  wireId <<endl
00095                      << " T0 mean (TDC counts): " << t0mean
00096                      << " T0_rms (TDC counts): " << t0rms;
00097 
00098     t0RefMap[wireId].push_back(t0mean);
00099     t0RefMap[wireId].push_back(t0rms);
00100   }
00101 
00102   // Loop over Ref DB entries
00103   for(DTT0::const_iterator tzero = tZeroMap->begin();
00104       tzero != tZeroMap->end(); tzero++) {
00105     DTWireId wireId((*tzero).first.wheelId,
00106                     (*tzero).first.stationId,
00107                     (*tzero).first.sectorId,
00108                     (*tzero).first.slId,
00109                     (*tzero).first.layerId,
00110                     (*tzero).first.cellId);
00111     float t0mean = (*tzero).second.t0mean;
00112     float t0rms = (*tzero).second.t0rms;
00113     LogTrace(metname)<< "Wire: " <<  wireId <<endl
00114                      << " T0 mean (TDC counts): " << t0mean
00115                      << " T0_rms (TDC counts): " << t0rms;
00116 
00117     t0Map[wireId].push_back(t0mean);
00118     t0Map[wireId].push_back(t0rms);
00119   }
00120 
00121   double difference=0;
00122   for(map<DTWireId, vector<float> >::const_iterator theMap = t0RefMap.begin();
00123       theMap != t0RefMap.end();
00124       theMap++) {  
00125     if(t0Map.find((*theMap).first) != t0Map.end()) {
00126 
00127       // compute the difference
00128       difference = t0Map[(*theMap).first][0]-(*theMap).second[0];
00129 
00130       //book histo
00131       DTLayerId layerId = (*theMap).first.layerId();
00132       if(t0DiffHistos.find(layerId) == t0DiffHistos.end()) {
00133         const DTTopology& dtTopo = dtGeom->layer(layerId)->specificTopology();
00134         const int firstWire = dtTopo.firstChannel();
00135         const int lastWire = dtTopo.lastChannel();
00136         bookHistos(layerId, firstWire, lastWire);
00137       }
00138 
00139       cout<< "Filling the histo for wire: "<<(*theMap).first
00140           <<"  difference: "<<difference<<endl;
00141       t0DiffHistos[layerId]->Fill((*theMap).first.wire(),difference);
00142 
00143     }
00144   } // Loop over the t0 map reference
00145   
00146   
00147 }
00148 
00149 
00150 void DTt0DBValidation::endJob() {
00151 
00152   //check the histos
00153   string testCriterionName = parameters.getUntrackedParameter<string>("t0TestName","t0DifferenceInRange"); 
00154   for(map<DTLayerId, MonitorElement*>::const_iterator hDiff = t0DiffHistos.begin();
00155       hDiff != t0DiffHistos.end();
00156       hDiff++) {
00157     const QReport * theDiffQReport = (*hDiff).second->getQReport(testCriterionName);
00158     if(theDiffQReport) {
00159       vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
00160       for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00161            channel != badChannels.end(); channel++) {
00162         cout << "layer:"<<(*hDiff).first<<" Bad mean channels: "<<(*channel).getBin()<<"  Contents : "<<(*channel).getContents()<<endl;
00163       }
00164       cout << "-------- layer: "<<(*hDiff).first<<"  "<<theDiffQReport->getMessage()<<" ------- "<<theDiffQReport->getStatus()<<endl; 
00165     }
00166   }
00167 
00168   // write the histos on a file
00169   dbe->save(outputFileName);
00170 
00171 }
00172 
00173   // Book a set of histograms for a given Layer
00174 void DTt0DBValidation::bookHistos(DTLayerId lId, int firstWire, int lastWire) {
00175   
00176   LogTrace(metname)<< "   Booking histos for L: " << lId;
00177 
00178   // Compose the chamber name
00179   stringstream wheel; wheel << lId.superlayerId().chamberId().wheel();  
00180   stringstream station; station << lId.superlayerId().chamberId().station();    
00181   stringstream sector; sector << lId.superlayerId().chamberId().sector();       
00182   stringstream superLayer; superLayer << lId.superlayerId().superlayer();       
00183   stringstream layer; layer << lId.layer();
00184 
00185   string lHistoName =
00186     "_W" + wheel.str() +
00187     "_St" + station.str() +
00188     "_Sec" + sector.str() +
00189     "_SL" + superLayer.str()+
00190     "_L" + layer.str();
00191   
00192   dbe->setCurrentFolder("DT/t0Validation/Wheel" + wheel.str() +
00193                            "/Station" + station.str() +
00194                            "/Sector" + sector.str() +
00195                            "/SuperLayer" +superLayer.str());
00196   // Create the monitor elements
00197   MonitorElement * hDifference;
00198   hDifference = dbe->book1D("hDifference"+lHistoName, "difference between the two t0 values",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5);
00199   
00200   t0DiffHistos[lId] = hDifference;
00201 }
00202 
00203 

Generated on Tue Jun 9 17:33:44 2009 for CMSSW by  doxygen 1.5.4