ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/TransMassTwo/src/TransMassTwo.cc
Revision: 1.1
Committed: Thu Sep 2 17:23:09 2010 UTC (14 years, 8 months ago) by mrenna
Content type: text/plain
Branch: MAIN
CVS Tags: v_1_0_0, HEAD
Error occurred while calculating annotation data.
Log Message:
first check-in

File Contents

# Content
1 // -*- C++ -*-
2 //
3 // Package: TransMassTwo
4 // Class: TransMassTwo
5 //
6 /**\class TransMassTwo TransMassTwo.cc UserCode/TransMassTwo/src/TransMassTwo.cc
7
8 Description: [one line class summary]
9
10 Implementation:
11 [Notes on implementation]
12 */
13 //
14 // Original Author: Stephen Mrenna
15 // Created: Tue Aug 24 11:59:56 CDT 2010
16 // $Id$
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/EDAnalyzer.h"
27
28 #include "FWCore/Framework/interface/Event.h"
29 #include "FWCore/Framework/interface/MakerMacros.h"
30 #include "FWCore/Utilities/interface/InputTag.h"
31 //#include "FWCore/ParameterSet/interface/InputTag.h"
32
33 #include "FWCore/ParameterSet/interface/ParameterSet.h"
34 #include "UserCode/TransMassTwo/interface/mt2_bisect.h"
35 #include "DataFormats/PatCandidates/interface/Jet.h"
36 #include "DataFormats/PatCandidates/interface/MET.h"
37 #include "DataFormats/PatCandidates/interface/Photon.h"
38 #include "DataFormats/PatCandidates/interface/Muon.h"
39 #include "DataFormats/PatCandidates/interface/Electron.h"
40 #include "DataFormats/PatCandidates/interface/Tau.h"
41 #include "DataFormats/Math/interface/LorentzVector.h"
42 #include "UserCode/TransMassTwo/interface/MuonPair.h"
43 #include "TTree.h"
44 #include "TLorentzVector.h"
45 #include "TFile.h"
46
47 //
48 // class declaration
49 //
50
51 class TransMassTwo : public edm::EDAnalyzer {
52 public:
53 TransMassTwo(const edm::ParameterSet&);
54 ~TransMassTwo();
55
56
57 private:
58 virtual void beginJob() ;
59 virtual void analyze(const edm::Event&, const edm::EventSetup&);
60 virtual void endJob() ;
61 edm::InputTag jetSrc_;
62 edm::InputTag muonSrc_;
63 edm::InputTag elecSrc_ ;
64 edm::InputTag metSrc_;
65 MuonPair *MuonPair_;
66 TTree *tree_;
67 TFile *rootfile_;
68 };
69 //
70 // constants, enums and typedefs
71 //
72
73 //
74 // static data member definitions
75 //
76
77 //
78 // constructors and destructor
79 //
80 TransMassTwo::TransMassTwo(const edm::ParameterSet& iConfig) :
81 jetSrc_(iConfig.getParameter<edm::InputTag>("jetSrc")),
82 muonSrc_(iConfig.getParameter<edm::InputTag>("muonSrc")),
83 elecSrc_(iConfig.getParameter<edm::InputTag>("elecSrc")),
84 metSrc_(iConfig.getParameter<edm::InputTag>("metSrc"))
85
86 {
87 //now do what ever initialization is needed
88
89 // if you just want a local file or do not care, do this
90 // else, you can you file services
91 std::string rootFileName = "testFile.root";
92 rootfile_ = new TFile(rootFileName.c_str(),"RECREATE");
93
94 // create tree
95 tree_ = new TTree("top","top");
96 tree_->AutoSave();
97
98 MuonPair_ = new MuonPair();
99
100 std::cout << "making branch " << std::endl;
101
102 tree_ ->Branch("muonpair",&MuonPair_);
103
104 std::cout << "made branch " << std::endl;
105
106
107 }
108
109
110 TransMassTwo::~TransMassTwo()
111 {
112
113 // do anything here that needs to be done at desctruction time
114 // (e.g. close files, deallocate resources etc.)
115
116 rootfile_ -> cd();
117 tree_ -> Write();
118
119 rootfile_ -> Close();
120 delete MuonPair_;
121
122 }
123
124
125 //
126 // member functions
127 //
128
129 // ------------ method called to for each event ------------
130 void
131 TransMassTwo::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
132 {
133 using namespace edm;
134
135
136 edm::Handle<std::vector<pat::Jet> > allJets;
137 edm::Handle<std::vector<pat::Muon> > allMuons;
138 edm::Handle<std::vector<pat::Electron> > allElecs;
139 edm::Handle<std::vector<pat::MET> > allMET;
140
141 iEvent.getByLabel(jetSrc_ ,allJets);
142 iEvent.getByLabel(muonSrc_,allMuons);
143 iEvent.getByLabel(elecSrc_,allElecs);
144 iEvent.getByLabel(metSrc_ ,allMET);
145
146
147 if(!allJets.isValid() ) {
148 std::cerr << "[FWLiteJetAnalyzer_Selector] caught std::excepton" << std::endl;
149 std::cerr << "Jet Collection is not valid" << std::endl;
150 return;
151 }
152 if(!allMuons.isValid() ) {
153 std::cerr << "[FWLiteJetAnalyzer_Selector] caught std::excepton" << std::endl;
154 std::cerr << "Muon Collection is not valid" << std::endl;
155 return;
156 }
157 if(!allElecs.isValid() ) {
158 std::cerr << "[FWLiteJetAnalyzer_Selector] caught std::excepton" << std::endl;
159 std::cerr << "Electron Collection is not valid" << std::endl;
160 return;
161 }
162 if(!allMET.isValid() ) {
163 std::cerr << "[FWLiteJetAnalyzer_Selector] caught std::excepton" << std::endl;
164 std::cerr << "MET Collection is not valid" << std::endl;
165 return;
166 }
167
168 std::vector<pat::Jet> allAnalJets = *allJets;
169 std::vector<pat::Muon> allAnalMuons = *allMuons;
170 std::vector<pat::Electron> allAnalElecs = *allElecs;
171 std::vector<pat::MET> allAnalMET = *allMET;
172
173 int nMuons=0;
174 size_t muonOne=-1;
175 size_t muonTwo=-1;
176 double ptMuonOne=-1.0;
177 double ptMuonTwo=-1.0;
178 int count=0;
179 for ( std::vector<pat::Muon>::const_iterator it = allAnalMuons.begin();
180 it!=allAnalMuons.end();++it,++count) {
181
182 const pat::Muon & mu = *it;
183 double pt = mu.pt();
184 // hists["hist_muonPt"]->Fill( pt );
185 ++nMuons;
186 if( pt>ptMuonTwo ) {
187 if( pt>ptMuonOne ) {
188 ptMuonTwo = ptMuonOne;
189 muonTwo = muonOne;
190 ptMuonOne = pt;
191 muonOne = count;
192 } else {
193 ptMuonTwo=pt;
194 muonTwo=count;
195 }
196 }
197 }
198 // hists["hist_nMuon"]->Fill(double(nMuons));
199 int nElecs=0;
200 size_t elecOne=-1;
201 size_t elecTwo=-1;
202 double ptElecOne=-1;
203 double ptElecTwo=-1;
204 count=0;
205 for ( std::vector<pat::Electron>::const_iterator it = allAnalElecs.begin();
206 it!=allAnalElecs.end();++it,++count) {
207
208 const pat::Electron & mu = *it;
209 double pt = mu.pt();
210 // hists["hist_elecPt"]->Fill( pt );
211 ++nElecs;
212 if( pt>ptElecTwo ) {
213 if( pt>ptElecOne ) {
214 ptElecTwo = ptElecOne;
215 elecTwo = elecOne;
216 ptElecOne = pt;
217 elecOne = count;
218 } else {
219 ptElecTwo=pt;
220 elecTwo=count;
221 }
222 }
223 }
224 // hists["hist_nElec"]->Fill(double(nElecs));
225 int nLeptons=nElecs+nMuons;
226 // hists["hist_nLepton"]->Fill(double(nLeptons));
227
228 /* char temp[100];
229 int n = sprintf(temp," %f %f %d %d %d %d %d %d\n",ptMuonOne,ptElecOne,muonOne,muonTwo,elecOne,elecTwo,nMuons,nElecs);
230 std::cout << temp << std::endl; */
231
232 double ptax=0,ptay=0;
233 double ptbx=0,ptby=0;
234 if(nElecs + nMuons > 1 ) {
235
236 if( ptElecTwo > ptMuonOne ) {
237 pat::Electron & mu = allAnalElecs[elecOne];
238 ptax = mu.px();
239 ptay = mu.py();
240 mu = allAnalElecs[elecTwo];
241 ptbx = mu.px();
242 ptby = mu.py();
243 } else if( ptMuonTwo > ptElecOne ) {
244 pat::Muon & mu = allAnalMuons[muonOne];
245 ptax = mu.px();
246 ptay = mu.py();
247 mu = allAnalMuons[muonTwo];
248 ptbx = mu.px();
249 ptby = mu.py();
250 } else {
251 pat::Electron & el = allAnalElecs[elecOne];
252 ptax = el.px();
253 ptay = el.py();
254 pat::Muon & mu = allAnalMuons[muonOne];
255 ptbx = mu.px();
256 ptby = mu.py();
257 }
258
259
260
261 pat::MET & met = allAnalMET[0];
262 //pa, pb = {mass, px, py}
263 //pmiss = {NULL, pxmiss, pymiss}
264 //mn = invisible particle mass
265 double pa[3] = { 0.0, ptax, ptay };
266 double pb[3] = { 0.0, ptbx, ptby };
267 double pmiss[3] = { 0, met.px(), met.py() };
268 double mn = 0.;
269
270 mt2_bisect::mt2 mt2_event;
271
272 mt2_event.set_momenta(pa,pb,pmiss);
273 mt2_event.set_mn(mn);
274 // mt2_event.print();
275 // std::cout << std::endl << " mt2 = " << mt2_event.get_mt2() << " " << allAnalMET.size() << std::endl;
276 double mt2Out = mt2_event.get_mt2();
277
278 MuonPair_->mu1 = TLorentzVector(ptax,ptay,0.,0.);
279 MuonPair_->mu2 = TLorentzVector(ptbx,ptby,0.,0.);
280 MuonPair_->mT2 = mt2Out;
281
282 tree_ -> Fill();
283
284 // if( mt2Out > 0.0 ) hists["hist_mT2"]->Fill(mt2Out);
285
286 }
287
288 }
289
290
291 // ------------ method called once each job just before starting event loop ------------
292 void
293 TransMassTwo::beginJob()
294 {
295 }
296
297 // ------------ method called once each job just after ending the event loop ------------
298 void
299 TransMassTwo::endJob() {
300 }
301
302 #include "FWCore/Framework/interface/MakerMacros.h"
303 DEFINE_FWK_MODULE(TransMassTwo);