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/PatternTools/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 "DataFormats/SiStripDetId/interface/TECDetId.h"
00018 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00019 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00020 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00021 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00022 #include "Alignment/OfflineValidation/interface/TrackerValidationVariables.h"
00023 #include "Alignment/TrackerAlignment/interface/TrackerAlignableId.h"
00024 #include "DQMServices/Core/interface/DQMStore.h"
00025 #include "DQMServices/Core/interface/MonitorElement.h"
00026
00027 MonitorTrackResiduals::MonitorTrackResiduals(const edm::ParameterSet& iConfig) : conf_(iConfig), m_cacheID_(0) {
00028 dqmStore_ = edm::Service<DQMStore>().operator->();
00029 folder_organizer = new SiStripFolderOrganizer();
00030 }
00031
00032
00033
00034 MonitorTrackResiduals::~MonitorTrackResiduals() { }
00035
00036
00037 void MonitorTrackResiduals::beginJob(const edm::EventSetup& es) {
00038 ModOn = conf_.getParameter<bool>("Mod_On");
00039 reset_me_after_each_run = conf_.getParameter<bool>("ResetAfterRun");
00040 }
00041
00042 void MonitorTrackResiduals::beginRun(edm::Run const& run, edm::EventSetup const& iSetup) {
00043
00044
00045 unsigned long long cacheID = iSetup.get<SiStripDetCablingRcd>().cacheIdentifier();
00046 if (m_cacheID_ != cacheID) {
00047 m_cacheID_ = cacheID;
00048 this->createMEs(iSetup);
00049 }
00050 if(reset_me_after_each_run) {
00051 if(ModOn) {
00052 for(std::map<int32_t, MonitorElement*>::const_iterator it = HitResidual.begin(),
00053 itEnd = HitResidual.end(); it!= itEnd;++it) {
00054 this->resetModuleMEs(it->first);
00055 this->resetLayerMEs(folder_organizer->GetSubDetAndLayer(it->first));
00056 }
00057 } else {
00058 for(std::map< std::pair<std::string,int32_t>, MonitorElement*>::const_iterator it = m_SubdetLayerResiduals.begin(),
00059 itEnd = m_SubdetLayerResiduals.end(); it!= itEnd;++it) {
00060 this->resetLayerMEs(it->first);
00061 }
00062 }
00063 }
00064
00065 }
00066
00067 void MonitorTrackResiduals::createMEs(const edm::EventSetup& iSetup){
00068 Parameters = conf_.getParameter<edm::ParameterSet>("TH1ResModules");
00069 int32_t i_residuals_Nbins = Parameters.getParameter<int32_t>("Nbinx");
00070 double d_residual_xmin = Parameters.getParameter<double>("xmin");
00071 double d_residual_xmax = Parameters.getParameter<double>("xmax");
00072 Parameters = conf_.getParameter<edm::ParameterSet>("TH1NormResModules");
00073 int32_t i_normres_Nbins = Parameters.getParameter<int32_t>("Nbinx");
00074 double d_normres_xmin = Parameters.getParameter<double>("xmin");
00075 double d_normres_xmax = Parameters.getParameter<double>("xmax");
00076
00077
00078
00079 SiStripHistoId hidmanager;
00080 folder_organizer->setSiStripFolder();
00081
00082
00083 edm::ESHandle<SiStripDetCabling> tkmechstruct;
00084 iSetup.get<SiStripDetCablingRcd>().get(tkmechstruct);
00085
00086
00087 std::vector<uint32_t> activeDets;
00088 activeDets.clear();
00089 tkmechstruct->addActiveDetectorsRawIds(activeDets);
00090
00091
00092 SiStripSubStructure substructure;
00093 std::vector<uint32_t> DetIds = activeDets;
00094
00095
00096 for (std::vector<uint32_t>::const_iterator DetItr=activeDets.begin(),
00097 DetItrEnd = activeDets.end(); DetItr!=DetItrEnd; ++DetItr)
00098 {
00099 uint ModuleID = (*DetItr);
00100
00101
00102 if( SiStripDetId(ModuleID).subDetector() != 0 ) {
00103
00104 folder_organizer->setDetectorFolder(ModuleID);
00105
00106 if (ModOn) {
00107 std::string hid = hidmanager.createHistoId("HitResiduals","det",ModuleID);
00108 std::string normhid = hidmanager.createHistoId("NormalizedHitResiduals","det",ModuleID);
00109 HitResidual[ModuleID] = dqmStore_->book1D(hid, hid,
00110 i_residuals_Nbins,d_residual_xmin,d_residual_xmax);
00111 HitResidual[ModuleID]->setAxisTitle("x_{pred} - x_{rec} [cm]");
00112 NormedHitResiduals[ModuleID] = dqmStore_->book1D(normhid, normhid,
00113 i_normres_Nbins,d_normres_xmin,d_normres_xmax);
00114 NormedHitResiduals[ModuleID]->setAxisTitle("x_{pred} - x_{rec}/#sigma");
00115 }
00116
00117 std::pair<std::string,int32_t> subdetandlayer = folder_organizer->GetSubDetAndLayer(ModuleID);
00118 folder_organizer->setLayerFolder(ModuleID,subdetandlayer.second);
00119 if(! m_SubdetLayerResiduals[subdetandlayer ] ) {
00120
00121 std::string histoname = Form(subdetandlayer.first.find("B") != std::string::npos ?
00122 "HitResiduals_%s__Layer__%d" : "HitResiduals_%s__wheel__%d" ,
00123 subdetandlayer.first.c_str(),abs(subdetandlayer.second));
00124 std::string normhistoname =
00125 Form(subdetandlayer.first.find("B") != std::string::npos ?
00126 "NormalizedHitResidual_%s__Layer__%d" : "NormalizedHitResidual_%s__wheel__%d" ,
00127 subdetandlayer.first.c_str(),abs(subdetandlayer.second));
00128 m_SubdetLayerResiduals[subdetandlayer] =
00129 dqmStore_->book1D(histoname.c_str(),histoname.c_str(),
00130 i_residuals_Nbins,d_residual_xmin,d_residual_xmax);
00131 m_SubdetLayerResiduals[subdetandlayer]->setAxisTitle("x_{pred} - x_{rec} [cm]");
00132 m_SubdetLayerNormedResiduals[subdetandlayer] =
00133 dqmStore_->book1D(normhistoname.c_str(),normhistoname.c_str(),
00134 i_normres_Nbins,d_normres_xmin,d_normres_xmax);
00135 m_SubdetLayerNormedResiduals[subdetandlayer]->setAxisTitle("x_{pred} - x_{rec} [cm]/#sigma");
00136 }
00137 }
00138 }
00139 }
00140
00141
00142 void MonitorTrackResiduals::resetModuleMEs(int32_t modid) {
00143 HitResidual[modid]->Reset();
00144 NormedHitResiduals[modid]->Reset();
00145 }
00146
00147 void MonitorTrackResiduals::resetLayerMEs(const std::pair<std::string, int32_t> &subdetandlayer) {
00148 m_SubdetLayerResiduals [subdetandlayer]->Reset();
00149 m_SubdetLayerNormedResiduals[subdetandlayer]->Reset();
00150 }
00151
00152
00153
00154 void MonitorTrackResiduals::endRun(const edm::Run&, const edm::EventSetup&){
00155 }
00156
00157
00158 void MonitorTrackResiduals::endJob(void){
00159
00160
00161 bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00162 std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00163 if(outputMEsInRootFile){
00164 dqmStore_->save(outputFileName);
00165 }
00166 }
00167
00168
00169 void MonitorTrackResiduals::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00170
00171 TrackerValidationVariables avalidator_(iSetup,conf_);
00172 std::vector<TrackerValidationVariables::AVHitStruct> v_hitstruct;
00173 avalidator_.fillHitQuantities(iEvent,v_hitstruct);
00174 for (std::vector<TrackerValidationVariables::AVHitStruct>::const_iterator it = v_hitstruct.begin(),
00175 itEnd = v_hitstruct.end(); it != itEnd; ++it) {
00176 uint RawId = it->rawDetId;
00177
00178
00179 if( it->resErrX != 0 && SiStripDetId(RawId).subDetector() != 0 ) {
00180 if (ModOn && HitResidual[RawId]) {
00181 HitResidual[RawId]->Fill(it->resX);
00182 NormedHitResiduals[RawId]->Fill(it->resX/it->resErrX);
00183 }
00184 std::pair<std::string, int32_t> subdetandlayer = folder_organizer->GetSubDetAndLayer(RawId);
00185 if(m_SubdetLayerResiduals[subdetandlayer]) {
00186 m_SubdetLayerResiduals[subdetandlayer]->Fill(it->resX);
00187 m_SubdetLayerNormedResiduals[subdetandlayer]->Fill(it->resX/it->resErrX);
00188 }
00189 }
00190 }
00191
00192 }
00193
00194
00195
00196 DEFINE_FWK_MODULE(MonitorTrackResiduals);
00197