ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/csander/HEPTutorial/MyAnalysis.C
Revision: 1.6
Committed: Tue Feb 14 20:52:25 2012 UTC (13 years, 2 months ago) by csander
Content type: text/plain
Branch: MAIN
Changes since 1.5: +6 -0 lines
Log Message:
added MC LorentzVectors

File Contents

# User Rev Content
1 csander 1.1 #define MyAnalysis_cxx
2     // The class definition in MyAnalysis.h has been generated automatically
3     // by the ROOT utility TTree::MakeSelector(). This class is derived
4     // from the ROOT class TSelector. For more information on the TSelector
5     // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.
6    
7     // The following methods are defined in this file:
8     // Begin(): called every time a loop on the tree starts,
9     // a convenient place to create your histograms.
10     // SlaveBegin(): called after Begin(), when on PROOF called only on the
11     // slave servers.
12     // Process(): called for each event, in this function you decide what
13     // to read and fill your histograms.
14     // SlaveTerminate: called at the end of the loop on the tree, when on PROOF
15     // called only on the slave servers.
16     // Terminate(): called at the end of the loop on the tree,
17     // a convenient place to draw/fit your histograms.
18     //
19     // To use this file, try the following session on your Tree T:
20     //
21     // Root > T->Process("MyAnalysis.C")
22     // Root > T->Process("MyAnalysis.C","some options")
23     // Root > T->Process("MyAnalysis.C+")
24     //
25    
26     #include "MyAnalysis.h"
27 csander 1.3 #include <iostream>
28 csander 1.2 #include <TH1F.h>
29 csander 1.1 #include <TStyle.h>
30 csander 1.4 #include <TCanvas.h>
31 csander 1.1
32 csander 1.3 using namespace std;
33    
34     void MyAnalysis::BuildEvent() {
35     Jets.clear();
36     for (int i = 0; i < NJet; ++i) {
37     MyJet jet(Jet_Px[i], Jet_Py[i], Jet_Pz[i], Jet_E[i]);
38     jet.SetBTagDiscriminator(Jet_btag[i]);
39     Jets.push_back(jet);
40     }
41     Muons.clear();
42     for (int i = 0; i < NMuon; ++i) {
43     MyMuon muon(Muon_Px[i], Muon_Py[i], Muon_Pz[i], Muon_E[i]);
44     muon.SetIsolation(Muon_Iso[i]);
45 csander 1.4 muon.SetCharge(Muon_Charge[i]);
46 csander 1.3 Muons.push_back(muon);
47     }
48 csander 1.4 Electrons.clear();
49     for (int i = 0; i < NElectron; ++i) {
50     MyElectron electron(Electron_Px[i], Electron_Py[i], Electron_Pz[i], Electron_E[i]);
51     electron.SetIsolation(Electron_Iso[i]);
52     electron.SetCharge(Electron_Charge[i]);
53     Electrons.push_back(electron);
54     }
55     Photons.clear();
56     for (int i = 0; i < NPhoton; ++i) {
57     MyPhoton photon(Photon_Px[i], Photon_Py[i], Photon_Pz[i], Photon_E[i]);
58     photon.SetIsolation(Photon_Iso[i]);
59     Photons.push_back(photon);
60     }
61 csander 1.6 hadB.SetXYZM(MChadronicBottom_px, MChadronicBottom_py, MChadronicBottom_pz, 4.8);
62     lepB.SetXYZM(MCleptonicBottom_px, MCleptonicBottom_py, MCleptonicBottom_pz, 4.8);
63     hadWq.SetXYZM(MChadronicWDecayQuark_px, MChadronicWDecayQuark_py, MChadronicWDecayQuark_pz, 0.0);
64     hadWqb.SetXYZM(MChadronicWDecayQuarkBar_px, MChadronicWDecayQuarkBar_py, MChadronicWDecayQuarkBar_pz, 0.0);
65     lepWl.SetXYZM(MClepton_px, MClepton_py, MClepton_pz, 0.0);
66     lepWn.SetXYZM(MCneutrino_px, MCneutrino_py, MCneutrino_pz, 0.0);
67 csander 1.3 }
68    
69 csander 1.2 void MyAnalysis::Begin(TTree * /*tree*/) {
70 csander 1.1 // The Begin() function is called at the start of the query.
71     // When running with PROOF Begin() is only called on the client.
72     // The tree argument is deprecated (on PROOF 0 is passed).
73    
74     TString option = GetOption();
75    
76     }
77    
78 csander 1.2 void MyAnalysis::SlaveBegin(TTree * /*tree*/) {
79 csander 1.1 // The SlaveBegin() function is called after the Begin() function.
80     // When running with PROOF SlaveBegin() is called on each slave server.
81     // The tree argument is deprecated (on PROOF 0 is passed).
82    
83     TString option = GetOption();
84    
85 csander 1.4 h_Mmumu = new TH1F("Mmumu", "Invariant di-muon mass", 100, 0, 200);
86     h_Mmumu->SetXTitle("m_{#mu#mu}");
87     h_Mmumu->SetYTitle("a.u.");
88     h_Mmumu->Sumw2();
89    
90 csander 1.1 }
91    
92 csander 1.2 Bool_t MyAnalysis::Process(Long64_t entry) {
93 csander 1.1 // The Process() function is called for each entry in the tree (or possibly
94     // keyed object in the case of PROOF) to be processed. The entry argument
95     // specifies which entry in the currently loaded tree is to be processed.
96     // It can be passed to either MyAnalysis::GetEntry() or TBranch::GetEntry()
97     // to read either all or the required parts of the data. When processing
98     // keyed objects with PROOF, the object is already loaded and is available
99     // via the fObject pointer.
100     //
101     // This function should contain the "body" of the analysis. It can contain
102     // simple or elaborate selection criteria, run algorithms on the data
103     // of the event and typically fill histograms.
104     //
105     // The processing can be stopped by calling Abort().
106     //
107     // Use fStatus to set the return value of TTree::Process().
108     //
109     // The return value is currently not used.
110    
111 csander 1.3 ++TotalEvents;
112    
113     GetEntry(entry);
114    
115 csander 1.4 if (TotalEvents % 10000 == 0)
116     cout << "Next event -----> " << TotalEvents << endl;
117    
118 csander 1.3 BuildEvent();
119    
120 csander 1.5 cout << "Jets: " << endl;
121     for (vector<MyJet>::iterator it = Jets.begin(); it != Jets.end(); ++it) {
122     cout << "pt, eta, phi, btag: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", " << it->IsBTagged()
123     << endl;
124     }
125     cout << "Muons: " << endl;
126     for (vector<MyMuon>::iterator it = Muons.begin(); it != Muons.end(); ++it) {
127     cout << "pt, eta, phi, iso, charge: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", "
128     << it->GetIsolation() << ", " << it->GetCharge() << endl;
129     }
130     cout << "Electrons: " << endl;
131     for (vector<MyElectron>::iterator it = Electrons.begin(); it != Electrons.end(); ++it) {
132     cout << "pt, eta, phi, iso, charge: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", "
133     << it->GetIsolation() << ", " << it->GetCharge() << endl;
134     }
135     cout << "Photons: " << endl;
136     for (vector<MyPhoton>::iterator it = Photons.begin(); it != Photons.end(); ++it) {
137     cout << "pt, eta, phi, iso: " << it->Pt() << ", " << it->Eta() << ", " << it->Phi() << ", " << it->GetIsolation()
138     << endl;
139     }
140 csander 1.4
141     if (NMuon > 1 && Muons.at(0).GetCharge() * Muons.at(1).GetCharge() < 1) {
142     h_Mmumu->Fill((Muons.at(0) + Muons.at(1)).M());
143 csander 1.3 }
144 csander 1.1
145     return kTRUE;
146     }
147    
148 csander 1.2 void MyAnalysis::SlaveTerminate() {
149 csander 1.1 // The SlaveTerminate() function is called after all entries or objects
150     // have been processed. When running with PROOF SlaveTerminate() is called
151     // on each slave server.
152    
153     }
154    
155 csander 1.2 void MyAnalysis::Terminate() {
156 csander 1.1 // The Terminate() function is the last function to be called during
157     // a query. It always runs on the client, it can be used to present
158     // the results graphically or save the results to file.
159    
160 csander 1.4 TCanvas *c = new TCanvas("c", "c", 600, 600);
161     h_Mmumu->Draw("");
162     c->Print("Mmumu.pdf");
163    
164 csander 1.1 }