00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "DQMOffline/Muon/src/MuonAnalyzer.h"
00011
00012 #include "DQMOffline/Muon/src/MuonEnergyDepositAnalyzer.h"
00013 #include "DQMOffline/Muon/src/MuonSeedsAnalyzer.h"
00014 #include "DQMOffline/Muon/src/MuonRecoAnalyzer.h"
00015 #include "DQMOffline/Muon/src/SegmentTrackAnalyzer.h"
00016
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/EventSetup.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022 #include "DQMServices/Core/interface/MonitorElement.h"
00023
00024 #include "DataFormats/Common/interface/Handle.h"
00025 #include "DataFormats/MuonReco/interface/Muon.h"
00026 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00027 #include "DataFormats/TrackReco/interface/Track.h"
00028 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00029 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00030 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00031
00032 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00034
00035 #include <string>
00036 using namespace std;
00037 using namespace edm;
00038
00039
00040
00041 MuonAnalyzer::MuonAnalyzer(const edm::ParameterSet& pSet) {
00042
00043 parameters = pSet;
00044
00045
00046 theService = new MuonServiceProxy(parameters.getParameter<ParameterSet>("ServiceParameters"));
00047
00048
00049 theMuonCollectionLabel = parameters.getParameter<edm::InputTag>("MuonCollection");
00050
00051 theGlbMuTrackCollectionLabel = parameters.getParameter<edm::InputTag>("GlobalMuTrackCollection");
00052
00053 theStaMuTrackCollectionLabel = parameters.getParameter<edm::InputTag>("STAMuTrackCollection");
00054
00055 theSeedsCollectionLabel = parameters.getParameter<edm::InputTag>("SeedCollection");
00056
00057 theMuEnergyAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoMuonEnergyAnalysis",true);
00058 theSeedsAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoMuonSeedAnalysis",true);
00059 theMuonRecoAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoMuonRecoAnalysis",true);
00060 theMuonSegmentsAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoTrackSegmentsAnalysis",true);
00061
00062
00063 if(theMuEnergyAnalyzerFlag)
00064 theMuEnergyAnalyzer = new MuonEnergyDepositAnalyzer(parameters.getParameter<ParameterSet>("muonEnergyAnalysis"), theService);
00065
00066 if(theSeedsAnalyzerFlag)
00067 theSeedsAnalyzer = new MuonSeedsAnalyzer(parameters.getParameter<ParameterSet>("seedsAnalysis"), theService);
00068
00069 if(theMuonRecoAnalyzerFlag)
00070 theMuonRecoAnalyzer = new MuonRecoAnalyzer(parameters.getParameter<ParameterSet>("muonRecoAnalysis"), theService);
00071
00072 if(theMuonSegmentsAnalyzerFlag){
00073
00074 ParameterSet trackGlbMuAnalysisParameters = parameters.getParameter<ParameterSet>("trackSegmentsAnalysis");
00075 trackGlbMuAnalysisParameters.addParameter<edm::InputTag>("MuTrackCollection",
00076 theGlbMuTrackCollectionLabel);
00077 theGlbMuonSegmentsAnalyzer = new SegmentTrackAnalyzer(trackGlbMuAnalysisParameters, theService);
00078
00079 ParameterSet trackStaMuAnalysisParameters = parameters.getParameter<ParameterSet>("trackSegmentsAnalysis");
00080 trackStaMuAnalysisParameters.addParameter<edm::InputTag>("MuTrackCollection",
00081 theStaMuTrackCollectionLabel);
00082 theStaMuonSegmentsAnalyzer = new SegmentTrackAnalyzer(trackStaMuAnalysisParameters, theService);
00083 }
00084 }
00085
00086 MuonAnalyzer::~MuonAnalyzer() {
00087
00088 if(theMuEnergyAnalyzerFlag) delete theMuEnergyAnalyzer;
00089 if(theSeedsAnalyzerFlag) delete theSeedsAnalyzer;
00090 if(theMuonRecoAnalyzerFlag) delete theMuonRecoAnalyzer;
00091 if(theMuonSegmentsAnalyzerFlag) {
00092 delete theGlbMuonSegmentsAnalyzer;
00093 delete theStaMuonSegmentsAnalyzer;
00094 }
00095 }
00096
00097
00098 void MuonAnalyzer::beginJob(edm::EventSetup const& iSetup) {
00099
00100 metname = "muonAnalyzer";
00101
00102 LogTrace(metname)<<"[MuonAnalyzer] Parameters initialization";
00103 theDbe = edm::Service<DQMStore>().operator->();
00104
00105 if(theMuEnergyAnalyzerFlag) theMuEnergyAnalyzer->beginJob(iSetup, theDbe);
00106 if(theSeedsAnalyzerFlag) theSeedsAnalyzer->beginJob(iSetup, theDbe);
00107 if(theMuonRecoAnalyzerFlag) theMuonRecoAnalyzer->beginJob(iSetup, theDbe);
00108 if(theMuonSegmentsAnalyzerFlag) {
00109 theGlbMuonSegmentsAnalyzer->beginJob(iSetup, theDbe);
00110 theStaMuonSegmentsAnalyzer->beginJob(iSetup, theDbe);
00111 }
00112
00113 }
00114
00115
00116 void MuonAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
00117
00118 LogTrace(metname)<<"[MuonAnalyzer] Analysis of event # ";
00119
00120 theService->update(iSetup);
00121
00122
00123 edm::Handle<reco::MuonCollection> muons;
00124 iEvent.getByLabel(theMuonCollectionLabel,muons);
00125
00126 if(muons.isValid()){
00127 for (reco::MuonCollection::const_iterator recoMu = muons->begin(); recoMu!=muons->end(); ++recoMu){
00128 if(theMuEnergyAnalyzerFlag){
00129 LogTrace(metname)<<"[MuonAnalyzer] Call to the muon energy analyzer";
00130 theMuEnergyAnalyzer->analyze(iEvent, iSetup, *recoMu);
00131 }
00132 if(theMuonRecoAnalyzerFlag){
00133 LogTrace(metname)<<"[MuonAnalyzer] Call to the muon reco analyzer";
00134 theMuonRecoAnalyzer->analyze(iEvent, iSetup, *recoMu);
00135 }
00136 }
00137 }
00138
00139
00140
00141 Handle<reco::TrackCollection> glbTracks;
00142 iEvent.getByLabel(theGlbMuTrackCollectionLabel,glbTracks);
00143 Handle<reco::TrackCollection> staTracks;
00144 iEvent.getByLabel(theStaMuTrackCollectionLabel,staTracks);
00145
00146 if(glbTracks.isValid()){
00147 for (reco::TrackCollection::const_iterator recoTrack = glbTracks->begin(); recoTrack!=glbTracks->end(); ++recoTrack){
00148 if(theMuonSegmentsAnalyzerFlag){
00149 LogTrace(metname)<<"[SegmentsAnalyzer] Call to the track segments analyzer for glb muons";
00150 theGlbMuonSegmentsAnalyzer->analyze(iEvent, iSetup, *recoTrack);
00151 }
00152 }
00153 }
00154 if(staTracks.isValid()){
00155 for (reco::TrackCollection::const_iterator recoTrack = staTracks->begin(); recoTrack!=staTracks->end(); ++recoTrack){
00156 if(theMuonSegmentsAnalyzerFlag){
00157 LogTrace(metname)<<"[SegmentsAnalyzer] Call to the track segments analyzer for sta muons";
00158 theStaMuonSegmentsAnalyzer->analyze(iEvent, iSetup, *recoTrack);
00159 }
00160 }
00161 }
00162
00163
00164
00165
00166
00167 edm::Handle<TrajectorySeedCollection> seeds;
00168 iEvent.getByLabel(theSeedsCollectionLabel, seeds);
00169 if(seeds.isValid()){
00170 for(TrajectorySeedCollection::const_iterator seed = seeds->begin(); seed != seeds->end(); ++seed){
00171 if(theSeedsAnalyzerFlag){
00172 LogTrace(metname)<<"[MuonAnalyzer] Call to the seeds analyzer";
00173 theSeedsAnalyzer->analyze(iEvent, iSetup, *seed);
00174 }
00175 }
00176 }
00177
00178 }
00179
00180
00181 void MuonAnalyzer::endJob(void) {
00182 LogTrace(metname)<<"[MuonAnalyzer] Saving the histos";
00183 bool outputMEsInRootFile = parameters.getParameter<bool>("OutputMEsInRootFile");
00184 std::string outputFileName = parameters.getParameter<std::string>("OutputFileName");
00185 if(outputMEsInRootFile){
00186 theDbe->showDirStructure();
00187 theDbe->save(outputFileName);
00188 }
00189 }
00190