CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonAnalyzer.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * $Date: 2012/02/17 12:01:23 $
6  * $Revision: 1.28 $
7  * \author G. Mila - INFN Torino
8  */
9 
11 
20 
24 
27 
35 
38 
39 #include <string>
40 using namespace std;
41 using namespace edm;
42 
44  parameters = pSet;
45 
46  // the services
47  theService = new MuonServiceProxy(parameters.getParameter<ParameterSet>("ServiceParameters"));
48 
49  // Muon Collection Label
50  theMuonCollectionLabel = parameters.getParameter<edm::InputTag>("MuonCollection");
51  theGlbMuTrackCollectionLabel = parameters.getParameter<edm::InputTag>("GlobalMuTrackCollection");
52  theStaMuTrackCollectionLabel = parameters.getParameter<edm::InputTag>("STAMuTrackCollection");
53  theSeedsCollectionLabel = parameters.getParameter<edm::InputTag>("SeedCollection");
54  theTriggerResultsLabel = parameters.getParameter<edm::InputTag>("TriggerResultsLabel");
55 
56  // Analyzer Flags - define wheter or not run a submodule
57  theMuEnergyAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoMuonEnergyAnalysis" ,true);
58  theSeedsAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoMuonSeedAnalysis" ,true);
59  theMuonRecoAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoMuonRecoAnalysis" ,true);
60  theMuonSegmentsAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoTrackSegmentsAnalysis",true);
61  theMuonKinVsEtaAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoMuonKinVsEtaAnalysis" ,true);
62  theDiMuonHistogramsFlag = parameters.getUntrackedParameter<bool>("DoDiMuonHistograms" ,true);
63  theMuonRecoOneHLTAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoMuonRecoOneHLT" ,true);
64  theEfficiencyAnalyzerFlag = parameters.getUntrackedParameter<bool>("DoEfficiencyAnalysis" ,true);
65 
66  // If the previous are defined... create the analyzer class
67  if(theMuEnergyAnalyzerFlag)
68  theMuEnergyAnalyzer = new MuonEnergyDepositAnalyzer(parameters.getParameter<ParameterSet>("muonEnergyAnalysis"), theService);
69  if(theSeedsAnalyzerFlag)
70  theSeedsAnalyzer = new MuonSeedsAnalyzer(parameters.getParameter<ParameterSet>("seedsAnalysis"), theService);
71  if(theMuonRecoAnalyzerFlag)
72  theMuonRecoAnalyzer = new MuonRecoAnalyzer(parameters.getParameter<ParameterSet>("muonRecoAnalysis"), theService);
73  if(theMuonRecoAnalyzerFlag)
74  theMuonKinVsEtaAnalyzer = new MuonKinVsEtaAnalyzer(parameters.getParameter<ParameterSet>("muonKinVsEtaAnalysis"), theService);
75  if(theDiMuonHistogramsFlag)
76  theDiMuonHistograms = new DiMuonHistograms(parameters.getParameter<ParameterSet>("dimuonHistograms"), theService);
77  if(theMuonSegmentsAnalyzerFlag){
78  // analysis on glb muon tracks
79  ParameterSet trackGlbMuAnalysisParameters = parameters.getParameter<ParameterSet>("trackSegmentsAnalysis");
80  trackGlbMuAnalysisParameters.addParameter<edm::InputTag>("MuTrackCollection",theGlbMuTrackCollectionLabel);
81  theGlbMuonSegmentsAnalyzer = new SegmentTrackAnalyzer(trackGlbMuAnalysisParameters, theService);
82  // analysis on sta muon tracks
83  ParameterSet trackStaMuAnalysisParameters = parameters.getParameter<ParameterSet>("trackSegmentsAnalysis");
84  trackStaMuAnalysisParameters.addParameter<edm::InputTag>("MuTrackCollection",theStaMuTrackCollectionLabel);
85  theStaMuonSegmentsAnalyzer = new SegmentTrackAnalyzer(trackStaMuAnalysisParameters, theService);
86  }
87  if (theMuonRecoOneHLTAnalyzerFlag)
88  theMuonRecoOneHLTAnalyzer = new MuonRecoOneHLT(parameters.getParameter<ParameterSet>("muonRecoOneHLTAnalysis"),theService);
89  if(theEfficiencyAnalyzerFlag)
90  theEfficiencyAnalyzer = new EfficiencyAnalyzer(parameters.getParameter<ParameterSet>("efficiencyAnalysis"), theService);
91 }
92 
94 
95  delete theService;
96  if(theMuEnergyAnalyzerFlag) delete theMuEnergyAnalyzer;
97  if(theSeedsAnalyzerFlag) delete theSeedsAnalyzer;
98  if(theMuonRecoAnalyzerFlag) delete theMuonRecoAnalyzer;
99  if(theMuonSegmentsAnalyzerFlag) {
100  delete theGlbMuonSegmentsAnalyzer;
101  delete theStaMuonSegmentsAnalyzer;
102  }
103  if(theMuonKinVsEtaAnalyzerFlag) delete theMuonKinVsEtaAnalyzer;
104  if(theDiMuonHistogramsFlag) delete theDiMuonHistograms;
105  if(theMuonRecoOneHLTAnalyzerFlag) delete theMuonRecoOneHLTAnalyzer;
106  if(theEfficiencyAnalyzerFlag) delete theEfficiencyAnalyzer;
107 }
108 void MuonAnalyzer::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
109  if (theMuonRecoOneHLTAnalyzerFlag) theMuonRecoOneHLTAnalyzer->beginRun(iRun,iSetup);
110 }
112  metname = "muonAnalyzer";
113 
114  LogTrace(metname)<<"[MuonAnalyzer] Parameters initialization";
115  theDbe = edm::Service<DQMStore>().operator->();
116 
117  if(theMuEnergyAnalyzerFlag) theMuEnergyAnalyzer->beginJob(theDbe);
118  if(theSeedsAnalyzerFlag) theSeedsAnalyzer->beginJob(theDbe);
119  if(theMuonRecoAnalyzerFlag) theMuonRecoAnalyzer->beginJob(theDbe);
120  if(theMuonSegmentsAnalyzerFlag) theGlbMuonSegmentsAnalyzer->beginJob(theDbe);
121  if(theMuonSegmentsAnalyzerFlag) theStaMuonSegmentsAnalyzer->beginJob(theDbe);
122  if(theMuonKinVsEtaAnalyzerFlag) theMuonKinVsEtaAnalyzer->beginJob(theDbe);
123  if(theDiMuonHistogramsFlag) theDiMuonHistograms->beginJob(theDbe);
124  if(theMuonRecoOneHLTAnalyzerFlag) theMuonRecoOneHLTAnalyzer->beginJob(theDbe);
125  if(theDiMuonHistogramsFlag) theDiMuonHistograms->beginJob(theDbe);
126  if(theEfficiencyAnalyzerFlag) theEfficiencyAnalyzer->beginJob(theDbe);
127 }
129  LogTrace(metname)<<"[MuonAnalyzer] Analysis of event # ";
130  theService->update(iSetup);
131 
132  // Take the STA muon container
134  iEvent.getByLabel(theMuonCollectionLabel,muons);
135 
137  iEvent.getByLabel(theTriggerResultsLabel, triggerResults);
138 
139  if(muons.isValid()){
140  for (reco::MuonCollection::const_iterator recoMu = muons->begin(); recoMu!=muons->end(); ++recoMu){
141  if(theMuEnergyAnalyzerFlag){
142  LogTrace(metname)<<"[MuonAnalyzer] Call to the muon energy analyzer";
143  theMuEnergyAnalyzer->analyze(iEvent, iSetup, *recoMu);
144  }
145  if(theMuonRecoAnalyzerFlag){
146  LogTrace(metname)<<"[MuonAnalyzer] Call to the muon reco analyzer";
147  theMuonRecoAnalyzer->analyze(iEvent, iSetup, *recoMu);
148  }
149  if(theMuonKinVsEtaAnalyzerFlag){
150  LogTrace(metname)<<"[MuonAnalyzer] Call to the muon KinVsEta analyzer";
151  theMuonKinVsEtaAnalyzer->analyze(iEvent, iSetup, *recoMu);
152  }
153  // if(theMuonRecoOneHLTAnalyzerFlag) {
154  // LogTrace(metname)<<"[MuonAnalyzer] Call to the muon reco One HLT analyzer";
155  // theMuonRecoOneHLTAnalyzer->analyze(iEvent, iSetup, *recoMu, *triggerResults);
156  // theMuonRecoOneHLTAnalyzer->analyze(iEvent, iSetup, *triggerResults);
157  // }
158  }
159  if(theMuonRecoOneHLTAnalyzerFlag) {
160  LogTrace(metname)<<"[MuonAnalyzer] Call to the muon reco One HLT analyzer";
161  theMuonRecoOneHLTAnalyzer->analyze(iEvent, iSetup, *triggerResults);
162  }
163  if (theEfficiencyAnalyzerFlag){
164  LogTrace(metname)<<"[MuonAnalyzer] Call to the efficiency analyzer";
165  theEfficiencyAnalyzer->analyze(iEvent,iSetup);
166  }
167  if (theDiMuonHistogramsFlag){
168  LogTrace(metname)<<"[MuonAnalyzer] Call to the dimuon analyzer";
169  theDiMuonHistograms->analyze(iEvent,iSetup);
170  }
171  }
172 
173  // Take the track containers
175  iEvent.getByLabel(theGlbMuTrackCollectionLabel,glbTracks);
177  iEvent.getByLabel(theStaMuTrackCollectionLabel,staTracks);
178 
179  if(glbTracks.isValid()){
180  for (reco::TrackCollection::const_iterator recoTrack = glbTracks->begin(); recoTrack!=glbTracks->end(); ++recoTrack){
181  if(theMuonSegmentsAnalyzerFlag){
182  LogTrace(metname)<<"[SegmentsAnalyzer] Call to the track segments analyzer for glb muons";
183  theGlbMuonSegmentsAnalyzer->analyze(iEvent, iSetup, *recoTrack);
184  }
185  }
186  }
187  if(staTracks.isValid()){
188  for (reco::TrackCollection::const_iterator recoTrack = staTracks->begin(); recoTrack!=staTracks->end(); ++recoTrack){
189  if(theMuonSegmentsAnalyzerFlag){
190  LogTrace(metname)<<"[SegmentsAnalyzer] Call to the track segments analyzer for sta muons";
191  theStaMuonSegmentsAnalyzer->analyze(iEvent, iSetup, *recoTrack);
192  }
193  }
194  }
195 
196 
197 
198 
199  // Take the seeds container
201  iEvent.getByLabel(theSeedsCollectionLabel, seeds);
202  if(seeds.isValid()){
203  for(TrajectorySeedCollection::const_iterator seed = seeds->begin(); seed != seeds->end(); ++seed){
204  if(theSeedsAnalyzerFlag){
205  LogTrace(metname)<<"[MuonAnalyzer] Call to the seeds analyzer";
206  theSeedsAnalyzer->analyze(iEvent, iSetup, *seed);
207  }
208  }
209  }
210 
211 }
212 
213 
215  LogTrace(metname)<<"[MuonAnalyzer] Saving the histos";
216  bool outputMEsInRootFile = parameters.getParameter<bool>("OutputMEsInRootFile");
217  std::string outputFileName = parameters.getParameter<std::string>("OutputFileName");
218  if(outputMEsInRootFile){
219  theDbe->showDirStructure();
220  theDbe->save(outputFileName);
221  }
222 }
223 
dictionary parameters
Definition: Parameters.py:2
const std::string metname
void beginJob(void)
Inizialize parameters for histo binning.
void endJob(void)
Save the histos.
int iEvent
Definition: GenABIO.cc:243
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:145
virtual ~MuonAnalyzer()
Destructor.
Definition: MuonAnalyzer.cc:93
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
#define LogTrace(id)
tuple muons
Definition: patZpeak.py:38
void beginRun(const edm::Run &, const edm::EventSetup &)
MuonAnalyzer(const edm::ParameterSet &)
Constructor.
Definition: MuonAnalyzer.cc:43
Definition: Run.h:33
void analyze(const edm::Event &, const edm::EventSetup &)
Get the analysis.