CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/TrackerMonitorTrack/src/MonitorTrackResiduals.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/ESHandle.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00005 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00006 #include "DataFormats/SiStripDetId/interface/SiStripSubStructure.h"
00007 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
00008 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
00009 #include "DQM/TrackerMonitorTrack/interface/MonitorTrackResiduals.h"
00010 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00011 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00012 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
00013 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00014 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h"
00015 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00016 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00017 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00018 #include "Alignment/OfflineValidation/interface/TrackerValidationVariables.h"
00019 #include "Alignment/TrackerAlignment/interface/TrackerAlignableId.h"
00020 #include "DQMServices/Core/interface/DQMStore.h"
00021 #include "DQMServices/Core/interface/MonitorElement.h"
00022 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
00023 
00024 MonitorTrackResiduals::MonitorTrackResiduals(const edm::ParameterSet& iConfig) 
00025    : dqmStore_( edm::Service<DQMStore>().operator->() )
00026    , conf_(iConfig), m_cacheID_(0) 
00027    , genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig)) {
00028 }
00029 
00030 MonitorTrackResiduals::~MonitorTrackResiduals() {
00031   if (genTriggerEventFlag_) delete genTriggerEventFlag_; 
00032 }
00033 
00034 
00035 void MonitorTrackResiduals::beginJob(void) {
00036   ModOn = conf_.getParameter<bool>("Mod_On");
00037   reset_me_after_each_run = conf_.getParameter<bool>("ResetAfterRun");
00038 }
00039 
00040 void MonitorTrackResiduals::beginRun(edm::Run const& run, edm::EventSetup const& iSetup) {
00041   
00042   //Retrieve tracker topology from geometry
00043   edm::ESHandle<TrackerTopology> tTopoHandle;
00044   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00045   const TrackerTopology* const tTopo = tTopoHandle.product();
00046   
00047   unsigned long long cacheID = iSetup.get<SiStripDetCablingRcd>().cacheIdentifier();
00048   if (m_cacheID_ != cacheID) {
00049     m_cacheID_ = cacheID;     
00050     this->createMEs(iSetup);
00051   }
00052   if(reset_me_after_each_run) {
00053     if(ModOn) {
00054       for(std::map<int32_t, MonitorElement*>::const_iterator it = HitResidual.begin(), 
00055             itEnd = HitResidual.end(); it!= itEnd;++it) {
00056         this->resetModuleMEs(it->first);
00057         this->resetLayerMEs(folder_organizer.GetSubDetAndLayer(it->first, tTopo));
00058       }
00059     } else {
00060       for(std::map< std::pair<std::string,int32_t>, MonitorElement*>::const_iterator it = m_SubdetLayerResiduals.begin(), 
00061             itEnd = m_SubdetLayerResiduals.end(); it!= itEnd;++it) {
00062         this->resetLayerMEs(it->first);
00063       }
00064     } // end if-else Module level on
00065   } // end reset after run
00066 
00067   // Initialize the GenericTriggerEventFlag
00068   if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( run, iSetup );
00069 }
00070 
00071 void MonitorTrackResiduals::createMEs(const edm::EventSetup& iSetup){
00072 
00073   //Retrieve tracker topology from geometry
00074   edm::ESHandle<TrackerTopology> tTopoHandle;
00075   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00076   const TrackerTopology* const tTopo = tTopoHandle.product();
00077 
00078   Parameters = conf_.getParameter<edm::ParameterSet>("TH1ResModules");
00079   int32_t i_residuals_Nbins =  Parameters.getParameter<int32_t>("Nbinx");
00080   double d_residual_xmin = Parameters.getParameter<double>("xmin");
00081   double d_residual_xmax = Parameters.getParameter<double>("xmax");
00082   Parameters = conf_.getParameter<edm::ParameterSet>("TH1NormResModules");
00083   int32_t i_normres_Nbins =  Parameters.getParameter<int32_t>("Nbinx");
00084   double d_normres_xmin = Parameters.getParameter<double>("xmin");
00085   double d_normres_xmax = Parameters.getParameter<double>("xmax");
00086 
00087   
00088   // use SistripHistoId for producing histogram id (and title)
00089   SiStripHistoId hidmanager;
00090   folder_organizer.setSiStripFolder(); // top SiStrip folder
00091   
00092   // take from eventSetup the SiStripDetCabling object
00093   edm::ESHandle<SiStripDetCabling> tkmechstruct;
00094   iSetup.get<SiStripDetCablingRcd>().get(tkmechstruct);
00095   
00096   // get list of active detectors from SiStripDetCabling
00097   std::vector<uint32_t> activeDets;
00098   activeDets.clear(); // just in case
00099   tkmechstruct->addActiveDetectorsRawIds(activeDets);
00100   
00101   // use SiStripSubStructure for selecting certain regions
00102   SiStripSubStructure substructure;
00103   std::vector<uint32_t> DetIds = activeDets;
00104   
00105   // book histo per each detector module
00106   for (std::vector<uint32_t>::const_iterator DetItr=activeDets.begin(),  
00107          DetItrEnd = activeDets.end(); DetItr!=DetItrEnd; ++DetItr)
00108     {
00109       uint ModuleID = (*DetItr);
00110       
00111       // is this a StripModule?
00112       if( SiStripDetId(ModuleID).subDetector() != 0 ) {
00113         
00114         folder_organizer.setDetectorFolder(ModuleID, tTopo); //  detid sets appropriate detector folder         
00115         // Book module histogramms? 
00116         if (ModOn) { 
00117           std::string hid = hidmanager.createHistoId("HitResiduals","det",ModuleID);
00118           std::string normhid = hidmanager.createHistoId("NormalizedHitResiduals","det",ModuleID);      
00119           HitResidual[ModuleID] = dqmStore_->book1D(hid, hid, 
00120                                                     i_residuals_Nbins,d_residual_xmin,d_residual_xmax);
00121           HitResidual[ModuleID]->setAxisTitle("(x_{pred} - x_{rec})' [cm]");
00122           NormedHitResiduals[ModuleID] = dqmStore_->book1D(normhid, normhid, 
00123                                                            i_normres_Nbins,d_normres_xmin,d_normres_xmax);
00124           NormedHitResiduals[ModuleID]->setAxisTitle("(x_{pred} - x_{rec})'/#sigma");
00125         }
00126         // book layer level histogramms
00127         std::pair<std::string,int32_t> subdetandlayer = folder_organizer.GetSubDetAndLayer(ModuleID, tTopo);
00128         folder_organizer.setLayerFolder(ModuleID,tTopo,subdetandlayer.second);
00129         if(! m_SubdetLayerResiduals[subdetandlayer ] ) {
00130           // book histogramms on layer level, check for barrel for correct labeling
00131           std::string histoname = Form(subdetandlayer.first.find("B") != std::string::npos ? 
00132                                        "HitResiduals_%s__Layer__%d" : "HitResiduals_%s__wheel__%d" ,
00133                                        subdetandlayer.first.c_str(),std::abs(subdetandlayer.second));
00134           std::string normhistoname = 
00135             Form(subdetandlayer.first.find("B") != std::string::npos ? 
00136                  "NormalizedHitResidual_%s__Layer__%d" : "NormalizedHitResidual_%s__wheel__%d" ,
00137                  subdetandlayer.first.c_str(),std::abs(subdetandlayer.second));
00138           m_SubdetLayerResiduals[subdetandlayer] = 
00139             dqmStore_->book1D(histoname.c_str(),histoname.c_str(),
00140                               i_residuals_Nbins,d_residual_xmin,d_residual_xmax);
00141           m_SubdetLayerResiduals[subdetandlayer]->setAxisTitle("(x_{pred} - x_{rec})' [cm]");
00142           m_SubdetLayerNormedResiduals[subdetandlayer] = 
00143             dqmStore_->book1D(normhistoname.c_str(),normhistoname.c_str(),
00144                               i_normres_Nbins,d_normres_xmin,d_normres_xmax);
00145           m_SubdetLayerNormedResiduals[subdetandlayer]->setAxisTitle("(x_{pred} - x_{rec})'/#sigma");
00146         } 
00147       } // end 'is strip module'
00148     } // end loop over activeDets
00149 }
00150 
00151 
00152 void MonitorTrackResiduals::resetModuleMEs(int32_t modid) {
00153   HitResidual[modid]->Reset();
00154   NormedHitResiduals[modid]->Reset();
00155 }
00156 
00157 void MonitorTrackResiduals::resetLayerMEs(const std::pair<std::string, int32_t> &subdetandlayer) {
00158   m_SubdetLayerResiduals      [subdetandlayer]->Reset();
00159   m_SubdetLayerNormedResiduals[subdetandlayer]->Reset();
00160 }
00161 
00162 
00163 
00164 void MonitorTrackResiduals::endRun(const edm::Run&, const edm::EventSetup&){
00165 }
00166 
00167 
00168 void MonitorTrackResiduals::endJob(void){
00169 
00170   //dqmStore_->showDirStructure();
00171   bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00172   std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00173   if(outputMEsInRootFile){
00174     dqmStore_->save(outputFileName);
00175   }
00176 }
00177 
00178 
00179 void MonitorTrackResiduals::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00180 
00181   // Filter out events if Trigger Filtering is requested                                                                                           
00182   if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
00183 
00184   //Retrieve tracker topology from geometry
00185   edm::ESHandle<TrackerTopology> tTopoHandle;
00186   iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
00187   const TrackerTopology* const tTopo = tTopoHandle.product();
00188 
00189   TrackerValidationVariables avalidator_(iSetup,conf_);
00190   std::vector<TrackerValidationVariables::AVHitStruct> v_hitstruct;
00191   avalidator_.fillHitQuantities(iEvent,v_hitstruct);
00192   for (std::vector<TrackerValidationVariables::AVHitStruct>::const_iterator it = v_hitstruct.begin(),
00193        itEnd = v_hitstruct.end(); it != itEnd; ++it) {
00194     uint RawId = it->rawDetId;
00195     
00196     // fill if hit belongs to StripDetector and its error is not zero
00197     if( it->resXprimeErr != 0 && SiStripDetId(RawId).subDetector()  != 0 )  {
00198       if (ModOn && HitResidual[RawId]) { 
00199         HitResidual[RawId]->Fill(it->resXprime);
00200         NormedHitResiduals[RawId]->Fill(it->resXprime/it->resXprimeErr);
00201       }
00202       std::pair<std::string, int32_t> subdetandlayer = folder_organizer.GetSubDetAndLayer(RawId, tTopo);
00203       if(m_SubdetLayerResiduals[subdetandlayer]) {
00204         m_SubdetLayerResiduals[subdetandlayer]->Fill(it->resXprime);
00205         m_SubdetLayerNormedResiduals[subdetandlayer]->Fill(it->resXprime/it->resXprimeErr);
00206       }
00207     }
00208   }
00209 
00210 }
00211 
00212 
00213 
00214 DEFINE_FWK_MODULE(MonitorTrackResiduals);
00215