CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/DQMOffline/CalibMuon/src/DTt0DBValidation.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2012/02/20 15:11:54 $
00006  *  $Revision: 1.13 $
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 "TFile.h"
00033 
00034 #include <sstream>
00035 #include <iomanip>
00036 
00037 using namespace edm;
00038 using namespace std;
00039 
00040 DTt0DBValidation::DTt0DBValidation(const ParameterSet& pset) {
00041 
00042   metname_ = "InterChannelSynchDBValidation";
00043   LogVerbatim(metname_) << "[DTt0DBValidation] Constructor called!";
00044 
00045   // Get the DQM needed services
00046   dbe_ = edm::Service<DQMStore>().operator->();
00047   dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation");
00048 
00049   // Get dataBase label
00050   labelDBRef_ = pset.getParameter<string>("labelDBRef");
00051   labelDB_ = pset.getParameter<string>("labelDB");
00052 
00053   t0TestName_ = "t0DifferenceInRange";
00054   if( pset.exists("t0TestName") ) t0TestName_ = pset.getParameter<string>("t0TestName");
00055   
00056   outputMEsInRootFile_ = false;
00057   if( pset.exists("OutputFileName") ){
00058      outputMEsInRootFile_ = true;
00059      outputFileName_ = pset.getParameter<std::string>("OutputFileName");
00060   }
00061 }
00062 
00063 
00064 DTt0DBValidation::~DTt0DBValidation(){}
00065 
00066 
00067 void DTt0DBValidation::beginRun(const edm::Run& run, const EventSetup& setup) {
00068 
00069   metname_ = "InterChannelSynchDBValidation";
00070   LogVerbatim(metname_) << "[DTt0DBValidation] Parameters initialization";
00071  
00072   ESHandle<DTT0> t0_Ref;
00073   setup.get<DTT0Rcd>().get(labelDBRef_, t0_Ref);
00074   tZeroRefMap_ = &*t0_Ref;
00075   LogVerbatim(metname_) << "[DTt0DBValidation] reference T0 version: " << t0_Ref->version();
00076 
00077   ESHandle<DTT0> t0;
00078   setup.get<DTT0Rcd>().get(labelDB_, t0);
00079   tZeroMap_ = &*t0;
00080   LogVerbatim(metname_) << "[DTt0DBValidation] T0 to validate version: " << t0->version();
00081 
00082   //book&reset the summary histos
00083   for(int wheel=-2; wheel<=2; wheel++){
00084     bookHistos(wheel);
00085     wheelSummary_[wheel]->Reset();
00086   }
00087 
00088   // Get the geometry
00089   setup.get<MuonGeometryRecord>().get(dtGeom_);
00090 
00091   // Loop over Ref DB entries
00092   for(DTT0::const_iterator tzero = tZeroRefMap_->begin();
00093                            tzero != tZeroRefMap_->end(); tzero++) {
00094     // t0s and rms are TDC counts
00095 // @@@ NEW DTT0 FORMAT
00096 //    DTWireId wireId((*tzero).first.wheelId,
00097 //                  (*tzero).first.stationId,
00098 //                  (*tzero).first.sectorId,
00099 //                  (*tzero).first.slId,
00100 //                  (*tzero).first.layerId,
00101 //                  (*tzero).first.cellId);
00102     int channelId = tzero->channelId;
00103     if ( channelId == 0 ) continue;
00104     DTWireId wireId(channelId);
00105 // @@@ NEW DTT0 END
00106     float t0mean;
00107     float t0rms;
00108     tZeroRefMap_->get( wireId, t0mean, t0rms, DTTimeUnits::counts );
00109     LogTrace(metname_)<< "Ref Wire: " <<  wireId <<endl
00110                      << " T0 mean (TDC counts): " << t0mean
00111                      << " T0_rms (TDC counts): " << t0rms;
00112 
00113     t0RefMap_[wireId].push_back(t0mean);
00114     t0RefMap_[wireId].push_back(t0rms);
00115   }
00116 
00117   // Loop over Ref DB entries
00118   for(DTT0::const_iterator tzero = tZeroMap_->begin();
00119                            tzero != tZeroMap_->end(); tzero++) {
00120     // t0s and rms are TDC counts
00121 // @@@ NEW DTT0 FORMAT
00122 //    DTWireId wireId((*tzero).first.wheelId,
00123 //                  (*tzero).first.stationId,
00124 //                  (*tzero).first.sectorId,
00125 //                  (*tzero).first.slId,
00126 //                  (*tzero).first.layerId,
00127 //                  (*tzero).first.cellId);
00128     int channelId = tzero->channelId;
00129     if ( channelId == 0 ) continue;
00130     DTWireId wireId(channelId);
00131 // @@@ NEW DTT0 END
00132     float t0mean;
00133     float t0rms;
00134     tZeroMap_->get( wireId, t0mean, t0rms, DTTimeUnits::counts );
00135     LogTrace(metname_)<< "Wire: " <<  wireId <<endl
00136                      << " T0 mean (TDC counts): " << t0mean
00137                      << " T0_rms (TDC counts): " << t0rms;
00138 
00139     t0Map_[wireId].push_back(t0mean);
00140     t0Map_[wireId].push_back(t0rms);
00141   }
00142 
00143   double difference = 0;
00144   for(map<DTWireId, vector<float> >::const_iterator theMap = t0RefMap_.begin();
00145       theMap != t0RefMap_.end();
00146       theMap++) {  
00147     if(t0Map_.find((*theMap).first) != t0Map_.end()) {
00148 
00149       // Compute the difference
00150       difference = t0Map_[(*theMap).first][0]-(*theMap).second[0];
00151 
00152       //book histo
00153       DTLayerId layerId = (*theMap).first.layerId();
00154       if(t0DiffHistos_.find(layerId) == t0DiffHistos_.end()) {
00155         const DTTopology& dtTopo = dtGeom_->layer(layerId)->specificTopology();
00156         const int firstWire = dtTopo.firstChannel();
00157         const int lastWire = dtTopo.lastChannel();
00158         bookHistos(layerId, firstWire, lastWire);
00159       }
00160 
00161       LogTrace(metname_)<< "Filling the histo for wire: "<<(*theMap).first
00162                         <<"  difference: "<<difference;
00163       t0DiffHistos_[layerId]->Fill((*theMap).first.wire(),difference);
00164 
00165     }
00166   } // Loop over the t0 map reference
00167    
00168 }
00169 
00170 void DTt0DBValidation::endRun(edm::Run const& run, edm::EventSetup const& setup) {
00171 
00172   // Check the histos
00173   string testCriterionName = t0TestName_; 
00174   for(map<DTLayerId, MonitorElement*>::const_iterator hDiff = t0DiffHistos_.begin();
00175       hDiff != t0DiffHistos_.end();
00176       hDiff++) {
00177 
00178      const QReport * theDiffQReport = (*hDiff).second->getQReport(testCriterionName);
00179      if(theDiffQReport) {
00180         int xBin = ((*hDiff).first.station()-1)*12+(*hDiff).first.layer()+4*((*hDiff).first.superlayer()-1);
00181         if( (*hDiff).first.station()==4 && (*hDiff).first.superlayer()==3 )
00182            xBin = ((*hDiff).first.station()-1)*12+(*hDiff).first.layer()+4*((*hDiff).first.superlayer()-2);
00183 
00184         int qReportStatus = theDiffQReport->getStatus()/100;
00185         wheelSummary_[(*hDiff).first.wheel()]->setBinContent(xBin,(*hDiff).first.sector(),qReportStatus);
00186  
00187         LogVerbatim(metname_) << "-------- layer: " << (*hDiff).first << "  " << theDiffQReport->getMessage()
00188                               << " ------- " << theDiffQReport->getStatus()
00189                               << " ------- " << setprecision(3) << theDiffQReport->getQTresult();
00190         vector<dqm::me_util::Channel> badChannels = theDiffQReport->getBadChannels();
00191         for (vector<dqm::me_util::Channel>::iterator channel = badChannels.begin(); 
00192                                                    channel != badChannels.end(); channel++) {
00193            LogVerbatim(metname_) << "layer: " << (*hDiff).first << " Bad channel: " 
00194                                              << (*channel).getBin() << "  Contents : "
00195                                              << (*channel).getContents();
00196 
00197            //wheelSummary_[(*hDiff).first.wheel()]->Fill(xBin,(*hDiff).first.sector());
00198         }
00199      }
00200       
00201   }
00202 
00203 }
00204 
00205 void DTt0DBValidation::endJob() {
00206   // Write the histos on a file
00207   if(outputMEsInRootFile_) dbe_->save(outputFileName_); 
00208 }
00209 
00210   // Book a set of histograms for a given Layer
00211 void DTt0DBValidation::bookHistos(DTLayerId lId, int firstWire, int lastWire) {
00212   
00213   LogTrace(metname_)<< "   Booking histos for L: " << lId;
00214 
00215   // Compose the chamber name
00216   stringstream wheel; wheel << lId.superlayerId().chamberId().wheel();  
00217   stringstream station; station << lId.superlayerId().chamberId().station();    
00218   stringstream sector; sector << lId.superlayerId().chamberId().sector();       
00219   stringstream superLayer; superLayer << lId.superlayerId().superlayer();       
00220   stringstream layer; layer << lId.layer();
00221 
00222   string lHistoName =
00223     "_W" + wheel.str() +
00224     "_St" + station.str() +
00225     "_Sec" + sector.str() +
00226     "_SL" + superLayer.str()+
00227     "_L" + layer.str();
00228   
00229   dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation/Wheel" + wheel.str() +
00230                            "/Station" + station.str() +
00231                            "/Sector" + sector.str() +
00232                            "/SuperLayer" +superLayer.str());
00233   // Create the monitor elements
00234   MonitorElement * hDifference;
00235   hDifference = dbe_->book1D("T0Difference"+lHistoName, "difference between the two t0 values",lastWire-firstWire+1, firstWire-0.5, lastWire+0.5);
00236   
00237   t0DiffHistos_[lId] = hDifference;
00238 }
00239 
00240 // Book the summary histos
00241 void DTt0DBValidation::bookHistos(int wheel) {
00242   dbe_->setCurrentFolder("DT/DtCalib/InterChannelSynchDBValidation");
00243   stringstream wh; wh << wheel;
00244     wheelSummary_[wheel]= dbe_->book2D("SummaryWrongT0_W"+wh.str(), "W"+wh.str()+": summary of wrong t0 differences",44,1,45,14,1,15);
00245     wheelSummary_[wheel]->setBinLabel(1,"M1L1",1);
00246     wheelSummary_[wheel]->setBinLabel(2,"M1L2",1);
00247     wheelSummary_[wheel]->setBinLabel(3,"M1L3",1);
00248     wheelSummary_[wheel]->setBinLabel(4,"M1L4",1);
00249     wheelSummary_[wheel]->setBinLabel(5,"M1L5",1);
00250     wheelSummary_[wheel]->setBinLabel(6,"M1L6",1);
00251     wheelSummary_[wheel]->setBinLabel(7,"M1L7",1);
00252     wheelSummary_[wheel]->setBinLabel(8,"M1L8",1);
00253     wheelSummary_[wheel]->setBinLabel(9,"M1L9",1);
00254     wheelSummary_[wheel]->setBinLabel(10,"M1L10",1);
00255     wheelSummary_[wheel]->setBinLabel(11,"M1L11",1);
00256     wheelSummary_[wheel]->setBinLabel(12,"M1L12",1);
00257     wheelSummary_[wheel]->setBinLabel(13,"M2L1",1);
00258     wheelSummary_[wheel]->setBinLabel(14,"M2L2",1);
00259     wheelSummary_[wheel]->setBinLabel(15,"M2L3",1);
00260     wheelSummary_[wheel]->setBinLabel(16,"M2L4",1);
00261     wheelSummary_[wheel]->setBinLabel(17,"M2L5",1);
00262     wheelSummary_[wheel]->setBinLabel(18,"M2L6",1);
00263     wheelSummary_[wheel]->setBinLabel(19,"M2L7",1);
00264     wheelSummary_[wheel]->setBinLabel(20,"M2L8",1);
00265     wheelSummary_[wheel]->setBinLabel(21,"M2L9",1);
00266     wheelSummary_[wheel]->setBinLabel(22,"M2L10",1);
00267     wheelSummary_[wheel]->setBinLabel(23,"M2L11",1);
00268     wheelSummary_[wheel]->setBinLabel(24,"M2L12",1);
00269     wheelSummary_[wheel]->setBinLabel(25,"M3L1",1);
00270     wheelSummary_[wheel]->setBinLabel(26,"M3L2",1);
00271     wheelSummary_[wheel]->setBinLabel(27,"M3L3",1);
00272     wheelSummary_[wheel]->setBinLabel(28,"M3L4",1);
00273     wheelSummary_[wheel]->setBinLabel(29,"M3L5",1);
00274     wheelSummary_[wheel]->setBinLabel(30,"M3L6",1);
00275     wheelSummary_[wheel]->setBinLabel(31,"M3L7",1);
00276     wheelSummary_[wheel]->setBinLabel(32,"M3L8",1);
00277     wheelSummary_[wheel]->setBinLabel(33,"M3L9",1);
00278     wheelSummary_[wheel]->setBinLabel(34,"M3L10",1);
00279     wheelSummary_[wheel]->setBinLabel(35,"M3L11",1);
00280     wheelSummary_[wheel]->setBinLabel(36,"M3L12",1);
00281     wheelSummary_[wheel]->setBinLabel(37,"M4L1",1);
00282     wheelSummary_[wheel]->setBinLabel(38,"M4L2",1);
00283     wheelSummary_[wheel]->setBinLabel(39,"M4L3",1);
00284     wheelSummary_[wheel]->setBinLabel(40,"M4L4",1);
00285     wheelSummary_[wheel]->setBinLabel(41,"M4L5",1);
00286     wheelSummary_[wheel]->setBinLabel(42,"M4L6",1);
00287     wheelSummary_[wheel]->setBinLabel(43,"M4L7",1);
00288     wheelSummary_[wheel]->setBinLabel(44,"M4L8",1);
00289 }