CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQMOffline/CalibMuon/src/DTPreCalibrationTask.cc

Go to the documentation of this file.
00001 #include "DQMOffline/CalibMuon/interface/DTPreCalibrationTask.h"
00002 
00003 
00004 // Framework
00005 #include "FWCore/Framework/interface/Event.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include <FWCore/Framework/interface/EventSetup.h>
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 
00014 // Geometry
00015 #include "Geometry/DTGeometry/interface/DTLayer.h"
00016 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00017 #include "Geometry/DTGeometry/interface/DTTopology.h"
00018 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00019 
00020 // Digis
00021 #include <DataFormats/DTDigi/interface/DTDigi.h>
00022 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
00023 #include "CondFormats/DataRecord/interface/DTStatusFlagRcd.h"
00024 #include "CondFormats/DTObjects/interface/DTStatusFlag.h"
00025 #include "CondFormats/DTObjects/interface/DTReadOutMapping.h"
00026 
00027 
00028 #include "TH2F.h"
00029 #include "TFile.h"
00030 
00031 using namespace edm;
00032 using namespace std;
00033 
00034 
00035 
00036 DTPreCalibrationTask::DTPreCalibrationTask(const edm::ParameterSet& ps){
00037 
00038   LogTrace("DTPreCalibSummary") <<"[DTPrecalibrationTask]: Constructor"<<endl;
00039 
00040   dbe = Service<DQMStore>().operator->();
00041 
00042   // Label to retrieve DT digis from the event
00043   digiLabel = ps.getUntrackedParameter<string>("digiLabel"); 
00044 
00045   // parameter for Time Boxes booking
00046   minTriggerWidth = ps.getUntrackedParameter<int>("minTriggerWidth",2000); 
00047   maxTriggerWidth = ps.getUntrackedParameter<int>("maxTriggerWidth",6000); 
00048 
00049   // histo saving on file
00050   saveFile = ps.getUntrackedParameter<bool>("SaveFile",false); 
00051   // output file name
00052   outputFileName = ps.getUntrackedParameter<string>("outputFileName"); 
00053   // get the histo folder name
00054   folderName = ps.getUntrackedParameter<string>("folderName");
00055 
00056 }
00057 
00058 
00059 DTPreCalibrationTask::~DTPreCalibrationTask(){}
00060 
00061 
00062 void DTPreCalibrationTask::beginJob(){
00063  
00064   for(int wheel=-2; wheel<=2; wheel++){
00065    for(int sector=1; sector<=14; sector++){
00066      LogTrace("DTPreCalibSummary") <<"[DTPrecalibrationTask]: Book histos for wheel "<<wheel<<", sector "<<sector<<endl;
00067      dbe->setCurrentFolder(folderName+"/TimeBoxes");  
00068      bookTimeBoxes(wheel, sector);
00069      dbe->setCurrentFolder(folderName+"/OccupancyHistos");
00070      if(sector<13) bookOccupancyPlot(wheel, sector);
00071     }
00072   }
00073 
00074 }
00075 
00076 
00077 void DTPreCalibrationTask::analyze(const edm::Event& event, const edm::EventSetup& setup) {
00078   
00079   // Get the digis from the event
00080   edm::Handle<DTDigiCollection> dtdigis;
00081   event.getByLabel(digiLabel, dtdigis);
00082 
00083   // LOOP OVER ALL THE DIGIS OF THE EVENT
00084   DTDigiCollection::DigiRangeIterator dtLayerId_It;
00085   for (dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){
00086     for (DTDigiCollection::const_iterator digiIt = ((*dtLayerId_It).second).first;
00087          digiIt!=((*dtLayerId_It).second).second; ++digiIt){
00088 
00089       //Fill the Time Boxes
00090       int tdcTime = (*digiIt).countsTDC();
00091       TimeBoxes[make_pair((*dtLayerId_It).first.superlayerId().chamberId().wheel(),
00092                           (*dtLayerId_It).first.superlayerId().chamberId().sector())]->Fill(tdcTime);
00093 
00094       //Fill the occupancy plot
00095       const  DTLayerId dtLId = (*dtLayerId_It).first;
00096       int yBin = (dtLId.station()-1)*12+dtLId.layer()+4*(dtLId.superlayer()-1);
00097       if(dtLId.station()==4 && dtLId.superlayer()==3)
00098         yBin = (dtLId.station()-1)*12+dtLId.layer()+4*(dtLId.superlayer()-2);
00099       if((*dtLayerId_It).first.superlayerId().chamberId().sector()<13)
00100         OccupancyHistos[make_pair((*dtLayerId_It).first.superlayerId().chamberId().wheel(),
00101                                   (*dtLayerId_It).first.superlayerId().chamberId().sector())]->Fill((*digiIt).wire(),yBin);
00102       else{
00103         if(dtLId.superlayer()!=3) yBin = 44 + dtLId.layer();
00104         else yBin = 48 + dtLId.layer();
00105         if((*dtLayerId_It).first.superlayerId().chamberId().sector()==13)
00106           OccupancyHistos[make_pair((*dtLayerId_It).first.superlayerId().chamberId().wheel(),4)]->Fill((*digiIt).wire(),yBin);
00107         if((*dtLayerId_It).first.superlayerId().chamberId().sector()==14)
00108           OccupancyHistos[make_pair((*dtLayerId_It).first.superlayerId().chamberId().wheel(),10)]->Fill((*digiIt).wire(),yBin);
00109       }
00110         
00111     }
00112   }
00113 
00114 }
00115 
00116 
00117 void DTPreCalibrationTask::endJob(){
00118   
00119   // save file for offLine analysis
00120   if(saveFile)
00121     dbe->save(outputFileName);
00122 
00123 }
00124 
00125 
00126 void DTPreCalibrationTask::bookTimeBoxes(int wheel, int sector) {
00127 
00128   stringstream wh; wh << wheel;
00129   stringstream sec; sec << sector;
00130 
00131   // book the time boxes
00132   TimeBoxes[make_pair(wheel, sector)]= dbe->book1D("TimeBox_W"+wh.str()+"_Sec"+sec.str(), "Time Box W"+wh.str()+"_Sec"+sec.str(),(maxTriggerWidth-minTriggerWidth)/50, minTriggerWidth, maxTriggerWidth);
00133   TimeBoxes[make_pair(wheel, sector)]->setAxisTitle("TDC counts");
00134 
00135 }
00136 
00137 
00138 
00139 void DTPreCalibrationTask::bookOccupancyPlot(int wheel, int sector) {
00140 
00141   stringstream wh; wh << wheel;
00142   stringstream sec; sec << sector;
00143 
00144   // book the occpancy plot
00145   if(sector==4 || sector==10)
00146     OccupancyHistos[make_pair(wheel, sector)]= dbe->book2D("Occupancy_W"+wh.str()+"_Sec"+sec.str(), "Occupancy W"+wh.str()+"_Sec"+sec.str(),100,1,100,52,1,53);
00147   else
00148     OccupancyHistos[make_pair(wheel, sector)]= dbe->book2D("Occupancy_W"+wh.str()+"_Sec"+sec.str(), "Occupancy W"+wh.str()+"_Sec"+sec.str(),100,1,100,44,1,45);
00149   OccupancyHistos[make_pair(wheel, sector)]->setAxisTitle("wire number", 1);
00150   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(1,"M1L1",2);
00151   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(2,"M1L2",2);
00152   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(3,"M1L3",2);
00153   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(4,"M1L4",2);
00154   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(5,"M1L5",2);
00155   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(6,"M1L6",2);
00156   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(7,"M1L7",2);
00157   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(8,"M1L8",2);
00158   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(9,"M1L9",2);
00159   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(10,"M1L10",2);
00160   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(11,"M1L11",2);
00161   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(12,"M1L12",2);
00162   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(13,"M2L1",2);
00163   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(14,"M2L2",2);
00164   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(15,"M2L3",2);
00165   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(16,"M2L4",2);
00166   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(17,"M2L5",2);
00167   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(18,"M2L6",2);
00168   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(19,"M2L7",2);
00169   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(20,"M2L8",2);
00170   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(21,"M2L9",2);
00171   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(22,"M2L10",2);
00172   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(23,"M2L11",2);
00173   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(24,"M2L12",2);
00174   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(25,"M3L1",2);
00175   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(26,"M3L2",2);
00176   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(27,"M3L3",2);
00177   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(28,"M3L4",2);
00178   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(29,"M3L5",2);
00179   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(30,"M3L6",2);
00180   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(31,"M3L7",2);
00181   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(32,"M3L8",2);
00182   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(33,"M3L9",2);
00183   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(34,"M3L10",2);
00184   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(35,"M3L11",2);
00185   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(36,"M3L12",2);
00186   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(37,"M4L1",2);
00187   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(38,"M4L2",2);
00188   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(39,"M4L3",2);
00189   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(40,"M4L4",2);
00190   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(41,"M4L5",2);
00191   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(42,"M4L6",2);
00192   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(43,"M4L7",2);
00193   OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(44,"M4L8",2);
00194   if(sector==4){
00195     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(45,"M4Sec13L1",2);
00196     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(46,"M4Sec13L2",2);
00197     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(47,"M4Sec13L3",2);
00198     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(48,"M4Sec13L4",2);
00199     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(49,"M4Sec13L5",2);
00200     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(50,"M4Sec13L6",2);
00201     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(51,"M4Sec13L7",2);
00202     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(52,"M4Sec13L8",2);
00203   }
00204   if(sector==10){
00205     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(45,"M4Sec14L1",2);
00206     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(46,"M4Sec14L2",2);
00207     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(47,"M4Sec14L3",2);
00208     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(48,"M4Sec14L4",2);
00209     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(49,"M4Sec14L5",2);
00210     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(50,"M4Sec14L6",2);
00211     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(51,"M4Sec14L7",2);
00212     OccupancyHistos[make_pair(wheel, sector)]->setBinLabel(52,"M4Sec14L8",2);
00213   }
00214 
00215 }