CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQM/DTMonitorModule/src/DTSegmentAnalysisTask.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2010/04/26 22:22:08 $
00006  *  $Revision: 1.28 $
00007  *  \author G. Cerminara - INFN Torino
00008  *  revised by G. Mila - INFN Torino
00009  */
00010 
00011 #include "DTSegmentAnalysisTask.h"
00012 
00013 // Framework
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "FWCore/Framework/interface/LuminosityBlock.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022 #include "DQMServices/Core/interface/MonitorElement.h"
00023 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00024 
00025 //Geometry
00026 #include "DataFormats/GeometryVector/interface/Pi.h"
00027 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00028 #include "Geometry/DTGeometry/interface/DTTopology.h"
00029 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00030 //RecHit
00031 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
00032 
00033 #include "CondFormats/DataRecord/interface/DTStatusFlagRcd.h"
00034 #include "CondFormats/DTObjects/interface/DTStatusFlag.h"
00035 
00036 #include "DQM/DTMonitorModule/interface/DTTimeEvolutionHisto.h"
00037 
00038 #include <iterator>
00039 
00040 using namespace edm;
00041 using namespace std;
00042 
00043 DTSegmentAnalysisTask::DTSegmentAnalysisTask(const edm::ParameterSet& pset) : nEventsInLS(0), hNevtPerLS(0) {
00044 
00045   edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Constructor called!";
00046 
00047   // switch for detailed analysis
00048   detailedAnalysis = pset.getUntrackedParameter<bool>("detailedAnalysis","false");
00049   // the name of the 4D rec hits collection
00050   theRecHits4DLabel = pset.getParameter<string>("recHits4DLabel");
00051   // Get the map of noisy channels
00052   checkNoisyChannels = pset.getUntrackedParameter<bool>("checkNoisyChannels","false");
00053   // # of bins in the time histos
00054   nTimeBins = pset.getUntrackedParameter<int>("nTimeBins",100);
00055   // # of LS per bin in the time histos
00056   nLSTimeBin = pset.getUntrackedParameter<int>("nLSTimeBin",2);
00057   // switch on/off sliding bins in time histos
00058   slideTimeBins = pset.getUntrackedParameter<bool>("slideTimeBins",true);
00059 
00060   // Get the DQM needed services
00061   theDbe = edm::Service<DQMStore>().operator->();
00062   
00063   // top folder for the histograms in DQMStore
00064   topHistoFolder = pset.getUntrackedParameter<string>("topHistoFolder","DT/02-Segments");
00065   // hlt DQM mode
00066   hltDQMMode = pset.getUntrackedParameter<bool>("hltDQMMode",false);
00067 
00068  }
00069 
00070 
00071 DTSegmentAnalysisTask::~DTSegmentAnalysisTask(){
00072     edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Destructor called!";
00073 }
00074 
00075 
00076 void DTSegmentAnalysisTask::beginRun(const Run& run, const edm::EventSetup& context){ 
00077 
00078    // Get the DT Geometry
00079   context.get<MuonGeometryRecord>().get(dtGeom);
00080 
00081   // loop over all the DT chambers & book the histos
00082   vector<DTChamber*> chambers = dtGeom->chambers();
00083   vector<DTChamber*>::const_iterator ch_it = chambers.begin();
00084   vector<DTChamber*>::const_iterator ch_end = chambers.end();
00085   for (; ch_it != ch_end; ++ch_it) {
00086     bookHistos((*ch_it)->id());
00087   }
00088 
00089   // book sector time-evolution histos
00090   int modeTimeHisto = 0;
00091   if(!slideTimeBins) modeTimeHisto = 1;
00092   for(int wheel = -2; wheel != 3; ++wheel) { // loop over wheels
00093     for(int sector = 1; sector <= 12; ++sector) { // loop over sectors
00094       stringstream wheelstr; wheelstr << wheel; 
00095       stringstream sectorstr; sectorstr << sector;
00096       string sectorHistoName = "NSegmPerEvent_W" + wheelstr.str()
00097         + "_Sec" + sectorstr.str();
00098       string sectorHistoTitle = "# segm. W" + wheelstr.str() + " Sect." + sectorstr.str();
00099 
00100       theDbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheelstr.str() +
00101                                "/Sector" + sectorstr.str());
00102       histoTimeEvol[wheel][sector] = new DTTimeEvolutionHisto(&(*theDbe),sectorHistoName,sectorHistoTitle,
00103                                                               nTimeBins,nLSTimeBin,slideTimeBins,modeTimeHisto);
00104     }
00105   }
00106 
00107   if(hltDQMMode) theDbe->setCurrentFolder(topHistoFolder);
00108   else theDbe->setCurrentFolder("DT/EventInfo/");
00109 
00110   hNevtPerLS = new DTTimeEvolutionHisto(&(*theDbe),"NevtPerLS","# evt.",nTimeBins,nLSTimeBin,slideTimeBins,2);
00111 
00112 }
00113 
00114 
00115 void DTSegmentAnalysisTask::endJob() {
00116  
00117   edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") <<"[DTSegmentAnalysisTask] endjob called!";
00118 
00119   delete hNevtPerLS;
00120   //theDbe->save("testMonitoring.root");
00121 
00122 }
00123   
00124 
00125 
00126 void DTSegmentAnalysisTask::analyze(const edm::Event& event, const edm::EventSetup& setup) {
00127   nEventsInLS++;
00128   edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run()
00129                                << " #Event: " << event.id().event();
00130   if(!(event.id().event()%1000))
00131     edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "[DTSegmentAnalysisTask] Analyze #Run: " << event.id().run()
00132                                  << " #Event: " << event.id().event();
00133   
00134   ESHandle<DTStatusFlag> statusMap;
00135   if(checkNoisyChannels) {
00136     setup.get<DTStatusFlagRcd>().get(statusMap);
00137   } 
00138 
00139 
00140   // -- 4D segment analysis  -----------------------------------------------------
00141   
00142   // Get the 4D segment collection from the event
00143   edm::Handle<DTRecSegment4DCollection> all4DSegments;
00144   event.getByLabel(theRecHits4DLabel, all4DSegments);
00145 
00146   if(!all4DSegments.isValid()) return;
00147   
00148   // Loop over all chambers containing a segment
00149   DTRecSegment4DCollection::id_iterator chamberId;
00150   for (chamberId = all4DSegments->id_begin();
00151        chamberId != all4DSegments->id_end();
00152        ++chamberId){
00153     // Get the range for the corresponding ChamerId
00154     DTRecSegment4DCollection::range  range = all4DSegments->get(*chamberId);
00155 
00156     edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "   Chamber: " << *chamberId << " has " << distance(range.first, range.second)
00157                                  << " 4D segments";
00158 
00159     // Loop over the rechits of this ChamerId
00160     for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
00161          segment4D!=range.second;
00162            ++segment4D){
00163 
00164       //FOR NOISY CHANNELS////////////////////////////////
00165      bool segmNoisy = false;
00166      if(checkNoisyChannels) {
00167        
00168        if((*segment4D).hasPhi()){
00169          const DTChamberRecSegment2D* phiSeg = (*segment4D).phiSegment();
00170          vector<DTRecHit1D> phiHits = phiSeg->specificRecHits();
00171          map<DTSuperLayerId,vector<DTRecHit1D> > hitsBySLMap; 
00172          for(vector<DTRecHit1D>::const_iterator hit = phiHits.begin();
00173              hit != phiHits.end(); ++hit) {
00174            DTWireId wireId = (*hit).wireId();
00175            
00176            // Check for noisy channels to skip them
00177            bool isNoisy = false;
00178            bool isFEMasked = false;
00179            bool isTDCMasked = false;
00180            bool isTrigMask = false;
00181            bool isDead = false;
00182            bool isNohv = false;
00183            statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
00184            if(isNoisy) {
00185              edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "Wire: " << wireId << " is noisy, skipping!";
00186              segmNoisy = true;
00187            }      
00188          }
00189        }
00190        
00191        if((*segment4D).hasZed()) {
00192          const DTSLRecSegment2D* zSeg = (*segment4D).zSegment();  // zSeg lives in the SL RF
00193          // Check for noisy channels to skip them
00194          vector<DTRecHit1D> zHits = zSeg->specificRecHits();
00195          for(vector<DTRecHit1D>::const_iterator hit = zHits.begin();
00196              hit != zHits.end(); ++hit) {
00197            DTWireId wireId = (*hit).wireId();
00198            bool isNoisy = false;
00199            bool isFEMasked = false;
00200            bool isTDCMasked = false;
00201            bool isTrigMask = false;
00202            bool isDead = false;
00203            bool isNohv = false;
00204            statusMap->cellStatus(wireId, isNoisy, isFEMasked, isTDCMasked, isTrigMask, isDead, isNohv);
00205            if(isNoisy) {
00206              edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "Wire: " << wireId << " is noisy, skipping!";
00207              segmNoisy = true;
00208            }     
00209          }
00210        } 
00211 
00212      } // end of switch on noisy channels
00213      if (segmNoisy) {
00214        edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask")<<"skipping the segment: it contains noisy cells";
00215        continue;
00216      }
00217      //END FOR NOISY CHANNELS////////////////////////////////
00218       
00219      int nHits=0;
00220      LocalPoint segment4DLocalPos = (*segment4D).localPosition();
00221      LocalVector segment4DLocalDirection = (*segment4D).localDirection();
00222      if((*segment4D).hasPhi())
00223        nHits = (((*segment4D).phiSegment())->specificRecHits()).size();
00224      if((*segment4D).hasZed()) 
00225        nHits = nHits + ((((*segment4D).zSegment())->specificRecHits()).size());
00226       
00227      fillHistos(*chamberId,
00228                 nHits,
00229                 (*segment4D).chi2()/(*segment4D).degreesOfFreedom());
00230     }
00231   }
00232 
00233   // -----------------------------------------------------------------------------
00234 }
00235   
00236 
00237 // Book a set of histograms for a give chamber
00238 void DTSegmentAnalysisTask::bookHistos(DTChamberId chamberId) {
00239 
00240   edm::LogVerbatim ("DTDQM|DTMonitorModule|DTSegmentAnalysisTask") << "   Booking histos for chamber: " << chamberId;
00241 
00242 
00243   // Compose the chamber name
00244   stringstream wheel; wheel << chamberId.wheel();       
00245   stringstream station; station << chamberId.station(); 
00246   stringstream sector; sector << chamberId.sector();
00247   
00248   string chamberHistoName =
00249     "_W" + wheel.str() +
00250     "_St" + station.str() +
00251     "_Sec" + sector.str();
00252   
00253 
00254   for(int wh=-2; wh<=2; wh++){
00255     stringstream wheel; wheel << wh;
00256     theDbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str());
00257     string histoName =  "numberOfSegments_W" + wheel.str();
00258     summaryHistos[wh] = theDbe->book2D(histoName.c_str(),histoName.c_str(),12,1,13,4,1,5);
00259     summaryHistos[wh]->setAxisTitle("Sector",1);
00260     summaryHistos[wh]->setBinLabel(1,"1",1);
00261     summaryHistos[wh]->setBinLabel(2,"2",1);
00262     summaryHistos[wh]->setBinLabel(3,"3",1);
00263     summaryHistos[wh]->setBinLabel(4,"4",1);
00264     summaryHistos[wh]->setBinLabel(5,"5",1);
00265     summaryHistos[wh]->setBinLabel(6,"6",1);
00266     summaryHistos[wh]->setBinLabel(7,"7",1);
00267     summaryHistos[wh]->setBinLabel(8,"8",1);
00268     summaryHistos[wh]->setBinLabel(9,"9",1);
00269     summaryHistos[wh]->setBinLabel(10,"10",1);
00270     summaryHistos[wh]->setBinLabel(11,"11",1);
00271     summaryHistos[wh]->setBinLabel(12,"12",1);
00272     summaryHistos[wh]->setBinLabel(1,"MB1",2);
00273     summaryHistos[wh]->setBinLabel(2,"MB2",2);
00274     summaryHistos[wh]->setBinLabel(3,"MB3",2);
00275     summaryHistos[wh]->setBinLabel(4,"MB4",2);  
00276   }
00277 
00278 
00279   theDbe->setCurrentFolder(topHistoFolder + "/Wheel" + wheel.str() +
00280                            "/Sector" + sector.str() +
00281                            "/Station" + station.str());
00282 
00283   // Create the monitor elements
00284   vector<MonitorElement *> histos;
00285   histos.push_back(theDbe->book1D("h4DSegmNHits"+chamberHistoName,
00286                                   "# of hits per segment",
00287                                   16, 0.5, 16.5));
00288   if(detailedAnalysis){
00289     histos.push_back(theDbe->book1D("h4DChi2"+chamberHistoName,
00290                                     "4D Segment reduced Chi2",
00291                                     20, 0, 20));
00292   }
00293   histosPerCh[chamberId] = histos;
00294 }
00295 
00296 
00297 // Fill a set of histograms for a give chamber 
00298 void DTSegmentAnalysisTask::fillHistos(DTChamberId chamberId,
00299                                    int nHits,
00300                                    float chi2) {
00301   int sector = chamberId.sector();
00302   if(chamberId.sector()==13) {
00303     sector = 4;
00304   } else if(chamberId.sector()==14) {
00305      sector = 10;
00306   }
00307 
00308   summaryHistos[chamberId.wheel()]->Fill(sector,chamberId.station());
00309   histoTimeEvol[chamberId.wheel()][sector]->accumulateValueTimeSlot(1);
00310 
00311   vector<MonitorElement *> histos =  histosPerCh[chamberId];                          
00312   histos[0]->Fill(nHits);
00313   if(detailedAnalysis){
00314     histos[1]->Fill(chi2);
00315   }
00316 
00317 }
00318 
00319 
00320 void DTSegmentAnalysisTask::endLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& eSetup) {
00321 
00322   hNevtPerLS->updateTimeSlot(lumiSeg.luminosityBlock(), nEventsInLS);
00323  // book sector time-evolution histos
00324   for(int wheel = -2; wheel != 3; ++wheel) {
00325     for(int sector = 1; sector <= 12; ++sector) {
00326       histoTimeEvol[wheel][sector]->updateTimeSlot(lumiSeg.luminosityBlock(), nEventsInLS);
00327     }
00328   }
00329 }
00330 
00331 
00332 void DTSegmentAnalysisTask::beginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const& eSetup) {
00333   nEventsInLS = 0;
00334 }
00335 
00336