CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/DTMonitorModule/src/DTDigiForNoiseTask.cc

Go to the documentation of this file.
00001  /*
00002  * \file DTDigiForNoiseTask.cc
00003  * 
00004  * $Date: 2011/06/14 08:53:04 $
00005  * $Revision: 1.10 $
00006  * \author G. Mila - INFN Torino
00007  *
00008  */
00009 
00010 #include <DQM/DTMonitorModule/src/DTDigiForNoiseTask.h>
00011 
00012 // Framework
00013 #include <FWCore/Framework/interface/EventSetup.h>
00014 
00015 // Digis
00016 #include <DataFormats/DTDigi/interface/DTDigi.h>
00017 #include <DataFormats/DTDigi/interface/DTDigiCollection.h>
00018 #include <DataFormats/MuonDetId/interface/DTLayerId.h>
00019 #include <DataFormats/MuonDetId/interface/DTChamberId.h>
00020 
00021 // Geometry
00022 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00023 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00024 #include "Geometry/DTGeometry/interface/DTLayer.h"
00025 #include "Geometry/DTGeometry/interface/DTTopology.h"
00026 
00027 #include "DQMServices/Core/interface/DQMStore.h"
00028 #include "DQMServices/Core/interface/MonitorElement.h"
00029 
00030 #include <stdio.h>
00031 #include <sstream>
00032 #include <math.h>
00033 
00034 using namespace edm;
00035 using namespace std;
00036 
00037 
00038 DTDigiForNoiseTask::DTDigiForNoiseTask(const edm::ParameterSet& ps){
00039   
00040   debug = ps.getUntrackedParameter<bool>("debug", false);
00041   if(debug)
00042     cout<<"[DTDigiForNoiseTask]: Constructor"<<endl;
00043 
00044   parameters = ps;
00045   
00046   dbe = edm::Service<DQMStore>().operator->();
00047 
00048 }
00049 
00050 
00051 DTDigiForNoiseTask::~DTDigiForNoiseTask(){
00052 
00053   if(debug)
00054     cout << "DTDigiForNoiseTask: analyzed " << nevents << " events" << endl;
00055 
00056 }
00057 
00058 
00059 void DTDigiForNoiseTask::endJob(){
00060 
00061   if(debug)
00062     cout<<"[DTDigiForNoiseTask] endjob called!"<<endl;
00063 
00064   dbe->rmdir("DT/DTDigiForNoiseTask");
00065 
00066 }
00067 
00068 
00069 void DTDigiForNoiseTask::beginJob(){
00070 
00071   if(debug)
00072     cout<<"[DTDigiForNoiseTask]: BeginJob"<<endl;
00073 
00074   nevents = 0;
00075 
00076 }
00077 
00078 void DTDigiForNoiseTask::beginRun(const edm::Run& run, const edm::EventSetup& context) {
00079 
00080   if(debug)
00081     cout<<"[DTDigiForNoiseTask]: BeginRun"<<endl;
00082 
00083   // Get the geometry
00084   context.get<MuonGeometryRecord>().get(muonGeom);
00085 
00086 }
00087 
00088 void DTDigiForNoiseTask::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& context) {
00089   
00090   if(debug)
00091     cout<<"[DTDigiForNoiseTask]: Begin of LS transition"<<endl;
00092   
00093   if(lumiSeg.id().luminosityBlock()%parameters.getUntrackedParameter<int>("ResetCycle", 3) == 0) {
00094     for(map< DTLayerId, MonitorElement* > ::const_iterator histo = digiHistos.begin();
00095         histo != digiHistos.end();
00096         histo++) {
00097       (*histo).second->Reset();
00098     }
00099   }
00100   
00101 }
00102 
00103 
00104 void DTDigiForNoiseTask::bookHistos(const DTLayerId& lId) {
00105   
00106   if (debug) cout<<"[DTDigiForNoiseTask]: booking"<<endl;
00107 
00108   const  DTSuperLayerId dtSLId = lId.superlayerId();
00109   const  DTChamberId dtChId = dtSLId.chamberId(); 
00110   stringstream layer; layer << lId.layer();
00111   stringstream superLayer; superLayer << dtSLId.superlayer();
00112   stringstream wheel; wheel << dtChId.wheel();  
00113   stringstream station; station << dtChId.station();    
00114   stringstream sector; sector << dtChId.sector();
00115 
00116   dbe->setCurrentFolder("DT/DTDigiForNoiseTask/Wheel" + wheel.str() +
00117                         "/Station" + station.str() +
00118                         "/Sector" + sector.str() + "/DigiPerEvent");
00119 
00120   if (debug){
00121     cout<<"[DTDigiForNoiseTask]: folder "<< "DT/DTDigiTask/Wheel" + wheel.str() +
00122       "/Station" + station.str() +
00123       "/Sector" + sector.str() + "/DigiPerEvent"<<endl;
00124   }
00125   
00126   string histoName =
00127     "DigiPerEvent_W" + wheel.str() 
00128     + "_St" + station.str() 
00129     + "_Sec" + sector.str()
00130     + "_SL" + superLayer.str()  
00131     + "_L" + layer.str();
00132   
00133   if (debug) cout<<"[DTDigiTask]: histoName "<<histoName<<endl;
00134 
00135   const DTTopology& dtTopo = muonGeom->layer(lId)->specificTopology();
00136   const int firstWire = dtTopo.firstChannel();
00137   const int lastWire = dtTopo.lastChannel();
00138   int nWires = lastWire-firstWire+1;
00139   
00140   digiHistos[lId] = dbe->book2D(histoName,histoName,nWires,firstWire,lastWire,10,-0.5,9.5);
00141 
00142 }
00143   
00144 
00145 void DTDigiForNoiseTask::analyze(const edm::Event& e, const edm::EventSetup& c){
00146   
00147   nevents++;
00148   //  cout << "events:  " << nevents << endl;
00149   if (nevents%1000 == 0 && debug) {}
00150   
00151   edm::Handle<DTDigiCollection> dtdigis;
00152   e.getByLabel("dtunpacker", dtdigis);
00153 
00154   std::map< int,int > DigiPerWirePerEvent;
00155   
00156   // Loop over all the chambers
00157   vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
00158   vector<DTChamber*>::const_iterator ch_end = muonGeom->chambers().end();
00159   // Loop over the SLs
00160   for (; ch_it != ch_end; ++ch_it) {
00161     //    DTChamberId ch = (*ch_it)->id();
00162     vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin(); 
00163     vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
00164     // Loop over the SLs
00165     for(; sl_it != sl_end; ++sl_it) {
00166       vector<const DTLayer*>::const_iterator l_it = (*sl_it)->layers().begin(); 
00167       vector<const DTLayer*>::const_iterator l_end = (*sl_it)->layers().end();
00168       // Loop over the Ls
00169       for(; l_it != l_end; ++l_it) {
00170         DTLayerId layerId = (*l_it)->id();
00171 
00172         DTDigiCollection::Range layerDigi= dtdigis->get(layerId);
00173         if(layerDigi.first != layerDigi.second){
00174 
00175           const DTTopology& dtTopo = muonGeom->layer(layerId)->specificTopology();
00176           const int firstWire = dtTopo.firstChannel();
00177           const int lastWire = dtTopo.lastChannel();
00178           
00179           if (digiHistos.find(layerId) == digiHistos.end())
00180             bookHistos(layerId);
00181           
00182           if (digiHistos.find(layerId) != digiHistos.end()){
00183             for (int wire=firstWire; wire<=lastWire; wire++) {
00184               DigiPerWirePerEvent[wire]= 0;
00185             }
00186 
00187             for (DTDigiCollection::const_iterator digi = layerDigi.first;
00188                  digi!=layerDigi.second;
00189                  ++digi){
00190               DigiPerWirePerEvent[(*digi).wire()]+=1;
00191             }
00192 
00193             for (int wire=firstWire; wire<=lastWire; wire++) {
00194               digiHistos.find(layerId)->second->Fill(wire,DigiPerWirePerEvent[wire]);
00195             }
00196           }
00197         }
00198 
00199       } //Loop Ls
00200     } //Loop SLs
00201   } //Loop over chambers
00202    
00203 }