ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/GPetrucc/plugins/L1DataPlotter.cc
Revision: 1.3
Committed: Wed Mar 10 14:05:01 2010 UTC (15 years, 2 months ago) by gpetrucc
Content type: text/plain
Branch: MAIN
CVS Tags: V03-00-00, HEAD
Changes since 1.2: +2 -2 lines
Log Message:
Migration to 3_5_X (probably works in 3_4_X too)

File Contents

# Content
1 // -*- C++ -*-
2 //
3 // Package: L1DataPlotter
4 // Class: L1DataPlotter
5 //
6 /**\class L1DataPlotter L1DataPlotter.cc Gio/L1DataPlotter/src/L1DataPlotter.cc
7
8 Description: <one line class summary>
9
10 Implementation:
11 <Notes on implementation>
12 */
13 //
14 // Original Author: Sep 15 09:45
15 // Created: Mon Sep 15 09:49:08 CEST 2008
16 // $Id: L1DataPlotter.cc,v 1.2 2009/09/30 14:03:35 gpetrucc Exp $
17 //
18 //
19
20
21 // system include files
22 #include <memory>
23
24 // user include files
25 #include "FWCore/Framework/interface/Frameworkfwd.h"
26 #include "FWCore/Framework/interface/EDFilter.h"
27
28 #include "FWCore/Framework/interface/Event.h"
29 #include "FWCore/Framework/interface/MakerMacros.h"
30
31 #include "FWCore/ParameterSet/interface/ParameterSet.h"
32
33 #include "FWCore/ServiceRegistry/interface/Service.h"
34 #include "CommonTools/UtilAlgos/interface/TFileService.h"
35 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
36
37 #include "DataFormats/PatCandidates/interface/Muon.h"
38
39 #include "DataFormats/Math/interface/deltaR.h"
40
41 #include <TTree.h>
42
43 //
44 // class decleration
45 //
46
47 class L1DataPlotter : public edm::EDFilter {
48 public:
49 explicit L1DataPlotter(const edm::ParameterSet&);
50 ~L1DataPlotter();
51
52
53 private:
54 virtual void beginJob(const edm::EventSetup&) ;
55 virtual bool filter(edm::Event&, const edm::EventSetup&);
56 virtual void endJob() ;
57
58 // ----------member data ---------------------------
59 typedef StringCutObjectSelector<pat::Muon> Selector;
60 edm::InputTag muons_;
61 Selector muonCut_;
62
63 TTree *tree;
64 enum { MaxNMu = 3 };
65 float mu1Pt,mu1Eta,mu1Phi,mu1Rho,mu1Z;
66 int mu1Charge;
67 int mu1PropagatedOk, mu1L1Ok;
68 float mu1PropagatedPt,mu1PropagatedEta,mu1PropagatedPhi,mu1PropagatedDR;
69 float mu1L1Pt,mu1L1Eta,mu1L1Phi,mu1L1DR,mu1L1PropDR;
70 };
71
72 //
73 // constructors and destructor
74 //
75 L1DataPlotter::L1DataPlotter(const edm::ParameterSet& iConfig) :
76 muons_(iConfig.getParameter<edm::InputTag>("muons")),
77 muonCut_(iConfig.getParameter<std::string>("muonCut"))
78 {
79 edm::Service<TFileService> fs;
80 std::string name = iConfig.getParameter<std::string>("@module_label");
81 tree = fs->make<TTree>( muons_.label().c_str(), iConfig.getParameter<std::string>("muonCut").c_str() );
82
83 tree->Branch("muPt", & mu1Pt, "muPt/F");
84 tree->Branch("muEta", & mu1Eta, "muEta/F");
85 tree->Branch("muPhi", & mu1Phi, "muPhi/F");
86 tree->Branch("muRho", & mu1Rho, "muRho/F");
87 tree->Branch("muZ", & mu1Z, "muZ/F");
88 tree->Branch("muCharge", & mu1Charge, "muCharge/I");
89 tree->Branch("muPropagatedOk", & mu1PropagatedOk, "muPropagatedOk/I");
90 tree->Branch("muPropagatedPt", & mu1PropagatedPt, "muPropagatedPt/F");
91 tree->Branch("muPropagatedEta", & mu1PropagatedEta, "muPropagatedEta/F");
92 tree->Branch("muPropagatedPhi", & mu1PropagatedPhi, "muPropagatedPhi/F");
93 tree->Branch("muPropagatedDR", & mu1PropagatedDR, "muPropagatedDR/F");
94 tree->Branch("muL1Ok", & mu1L1Ok, "muL1Ok/I");
95 tree->Branch("muL1Pt", & mu1L1Pt, "muL1Pt/F");
96 tree->Branch("muL1Eta", & mu1L1Eta, "muL1Eta/F");
97 tree->Branch("muL1Phi", & mu1L1Phi, "muL1Phi/F");
98 tree->Branch("muL1DR", & mu1L1DR, "muL1DR/F");
99 tree->Branch("muL1PropDR", & mu1L1PropDR, "muL1PropDR/F");
100 }
101
102
103 L1DataPlotter::~L1DataPlotter()
104 {
105 }
106
107
108 //
109 // member functions
110 //
111
112 // ------------ method called to for each event ------------
113 bool
114 L1DataPlotter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
115 {
116 using namespace edm; using namespace std;
117 using reco::Track;
118 using pat::Muon;
119
120 Handle<View<Muon> > muons;
121 iEvent.getByLabel(muons_, muons);
122
123 for (View<Muon>::const_iterator it = muons->begin(); it != muons->end(); ++it) {
124 if (!muonCut_(*it)) continue;
125 const Muon & mu1 = *it;
126
127 mu1Pt = mu1.pt();
128 mu1Eta = mu1.eta();
129 mu1Phi = mu1.phi();
130 mu1Rho = mu1.vertex().rho();
131 mu1Z = mu1.vz();
132 mu1Charge = mu1.charge();
133
134 std::vector<pat::TriggerObjectStandAlone> propagated = mu1.triggerObjectMatchesByFilter("propagated");
135 if (!propagated.empty()) {
136 mu1PropagatedOk = true;
137 mu1PropagatedPt = propagated.front().pt();
138 mu1PropagatedEta = propagated.front().eta();
139 mu1PropagatedPhi = propagated.front().phi();
140 mu1PropagatedDR = ::deltaR(propagated.front(), mu1);
141 } else {
142 mu1PropagatedOk = false;
143 mu1PropagatedPt = 0;
144 mu1PropagatedEta = 0;
145 mu1PropagatedPhi = 0;
146 mu1PropagatedDR = 0;
147 }
148
149 std::vector<pat::TriggerObjectStandAlone> l1 = mu1.triggerObjectMatchesByFilter("l1");
150 if (!l1.empty()) {
151 mu1L1Ok = true;
152 mu1L1Pt = l1.front().pt();
153 mu1L1Eta = l1.front().eta();
154 mu1L1Phi = l1.front().phi();
155 mu1L1DR = ::deltaR(l1.front(), mu1);
156 if (!propagated.empty()) {
157 mu1L1PropDR = ::deltaR(l1.front(), propagated.front());
158 } else mu1L1PropDR = 0;
159 } else {
160 mu1L1Ok = false;
161 mu1L1Pt = 0;
162 mu1L1Eta = 0;
163 mu1L1Phi = 0;
164 mu1L1DR = 0;
165 mu1L1PropDR = 0;
166 }
167
168
169 tree->Fill();
170 }
171 return true;
172 }
173
174
175 // ------------ method called once each job just before starting event loop ------------
176 void
177 L1DataPlotter::beginJob(const edm::EventSetup&)
178 {
179 }
180
181 // ------------ method called once each job just after ending the event loop ------------
182 void
183 L1DataPlotter::endJob() {
184 }
185
186 //define this as a plug-in
187 DEFINE_FWK_MODULE(L1DataPlotter);