Class Reference for E1039 Core & Analysis Software
AnaCleanAndMessyData.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <TFile.h>
4 #include <TTree.h>
5 #include <TSystem.h>
6 #include <TH1D.h>
7 #include <TEfficiency.h>
8 #include <TCanvas.h>
9 #include "AnaCleanAndMessyData.h"
10 using namespace std;
11 
13  : m_verb(0)
14  , m_cl_file(0)
15  , m_cl_tree(0)
16  , m_me_file(0)
17  , m_me_tree(0)
18 {
19  ;
20 }
21 
23 {
24  ;
25 }
26 
27 void AnaCleanAndMessyData::Init(const char* fn_clean, const char* fn_messy)
28 {
29  m_cl_file = new TFile(fn_clean);
30  m_cl_tree = (TTree*)m_cl_file->Get("tree");
31  m_cl_evt = new EventData ();
32  m_cl_trk_true = new TrackList ();
33  m_cl_trk_reco = new TrackList ();
34  m_cl_dim_true = new DimuonList();
35  m_cl_dim_reco = new DimuonList();
36  m_cl_tree->SetBranchAddress("evt" , &m_cl_evt);
37  m_cl_tree->SetBranchAddress("trk_true", &m_cl_trk_true);
38  m_cl_tree->SetBranchAddress("trk_reco", &m_cl_trk_reco);
39  m_cl_tree->SetBranchAddress("dim_true", &m_cl_dim_true);
40  m_cl_tree->SetBranchAddress("dim_reco", &m_cl_dim_reco);
41 
42  m_me_file = new TFile(fn_messy);
43  m_me_tree = (TTree*)m_me_file->Get("tree");
44  m_me_evt = new EventData ();
45  m_me_trk_true = new TrackList ();
46  m_me_trk_reco = new TrackList ();
47  m_me_dim_true = new DimuonList();
48  m_me_dim_reco = new DimuonList();
49  m_me_tree->SetBranchAddress("evt" , &m_me_evt);
50  m_me_tree->SetBranchAddress("trk_true", &m_me_trk_true);
51  m_me_tree->SetBranchAddress("trk_reco", &m_me_trk_reco);
52  m_me_tree->SetBranchAddress("dim_true", &m_me_dim_true);
53  m_me_tree->SetBranchAddress("dim_reco", &m_me_dim_reco);
54 
55  gSystem->mkdir("result", true);
56  m_out_file = new TFile("result/output.root", "RECREATE");
57  m_h1_trk_pos_cl = new TH1D("h1_trk_pos_cl", ";RF+00;", 20, 0, 1000);
58  m_h1_trk_pos_me = new TH1D("h1_trk_pos_me", ";RF+00;", 20, 0, 1000);
59  m_h1_trk_neg_cl = new TH1D("h1_trk_neg_cl", ";RF+00;", 20, 0, 1000);
60  m_h1_trk_neg_me = new TH1D("h1_trk_neg_me", ";RF+00;", 20, 0, 1000);
61  m_h1_dim_cl = new TH1D("h1_dim_cl" , ";RF+00;", 20, 0, 1000);
62  m_h1_dim_me = new TH1D("h1_dim_me" , ";RF+00;", 20, 0, 1000);
63 }
64 
66 
70 {
71  int n_cl_evt = m_cl_tree->GetEntries();
72  int n_me_evt = m_me_tree->GetEntries();
73  int i_cl_evt = 0;
74  int i_me_evt = 0;
75 
76  bool no_event = false;
77  while (! no_event) {
78  if (i_cl_evt >= n_cl_evt || i_me_evt >= n_me_evt) return;
79  m_cl_tree->GetEntry(i_cl_evt);
80  m_me_tree->GetEntry(i_me_evt);
81  pair<int, int> job_evt_cl(m_cl_evt->job_id, m_cl_evt->event_id);
82  pair<int, int> job_evt_me(m_me_evt->job_id, m_me_evt->event_id);
83 
84  while (job_evt_cl != job_evt_me) { // job+event IDs are different
85  if (job_evt_cl < job_evt_me) {
86  i_cl_evt++;
87  if (i_cl_evt >= n_cl_evt) return;
88  m_cl_tree->GetEntry(i_cl_evt);
89  job_evt_cl = pair<int, int>(m_cl_evt->job_id, m_cl_evt->event_id);
90  } else { // >
91  i_me_evt++;
92  if (i_me_evt >= n_me_evt) return;
93  m_me_tree->GetEntry(i_me_evt);
94  job_evt_me = pair<int, int>(m_me_evt->job_id, m_me_evt->event_id);
95  }
96  }
97 
98  if (Verbosity() > 9) {
99  cout << "AnaCleanAndMessyData::Analyze(): Job ID " << m_cl_evt->job_id << ", Event ID " << m_cl_evt->event_id << ": Clean " << i_cl_evt << "/" << n_cl_evt << ", Messy " << i_me_evt << "/" << n_me_evt << endl;
100  }
101  AnalyzeEvent();
102  i_cl_evt++;
103  i_me_evt++;
104  }
105 }
106 
108 {
109  if (m_cl_file) m_cl_file->Close();
110  if (m_me_file) m_me_file->Close();
111  if (m_out_file) DrawAndWriteOutput();
112 }
113 
115 
118 void AnaCleanAndMessyData::AnalyzeEvent()
119 {
120  double ww = m_cl_evt->weight;
121  int rfp01 = m_me_evt->rfp01;
122  int rfp00 = m_me_evt->rfp00;
123  int rfm01 = m_me_evt->rfm01;
124  int n_h1x = m_me_evt->n_h1x;
125  int n_h2x = m_me_evt->n_h2x;
126  int n_h3x = m_me_evt->n_h3x;
127  int n_h4x = m_me_evt->n_h4x;
128 
129  int n_trk_pos_cl = 0;
130  int n_trk_neg_cl = 0;
131  for (int ii = 0; ii < m_cl_trk_reco->size(); ii++) {
132  TrackData* td = &m_cl_trk_reco->at(ii);
133  if (td->charge > 0) n_trk_pos_cl++;
134  else n_trk_neg_cl++;
135  }
136 
137  int n_trk_pos_me = 0;
138  int n_trk_neg_me = 0;
139  for (int ii = 0; ii < m_me_trk_reco->size(); ii++) {
140  TrackData* td = &m_me_trk_reco->at(ii);
141  if (td->charge > 0) n_trk_pos_me++;
142  else n_trk_neg_me++;
143  }
144 
145  int n_dim_cl = m_cl_dim_reco->size();
146  int n_dim_me = m_me_dim_reco->size();
147 
148  m_h1_trk_pos_cl->Fill(rfp00, n_trk_pos_cl);
149  m_h1_trk_pos_me->Fill(rfp00, n_trk_pos_me);
150  m_h1_trk_neg_cl->Fill(rfp00, n_trk_neg_cl);
151  m_h1_trk_neg_me->Fill(rfp00, n_trk_neg_me);
152  m_h1_dim_cl ->Fill(rfp00, n_dim_cl );
153  m_h1_dim_me ->Fill(rfp00, n_dim_me );
154 }
155 
157 void AnaCleanAndMessyData::DrawAndWriteOutput()
158 {
159  m_out_file->cd();
160  m_out_file->Write();
161  TEfficiency* teff_trk_pos = new TEfficiency(*m_h1_trk_pos_me, *m_h1_trk_pos_cl);
162  TEfficiency* teff_trk_neg = new TEfficiency(*m_h1_trk_neg_me, *m_h1_trk_neg_cl);
163  TEfficiency* teff_dim = new TEfficiency(*m_h1_dim_me , *m_h1_dim_cl );
164  teff_trk_pos->SetName("teff_trk_pos");
165  teff_trk_neg->SetName("teff_trk_neg");
166  teff_dim ->SetName("teff_dim");
167  teff_trk_pos->SetTitle(";RF+00;Reco. efficiency of #mu^{#plus}");
168  teff_trk_neg->SetTitle(";RF+00;Reco. efficiency of #mu^{#minus}");
169  teff_dim ->SetTitle(";RF+00;Reco. efficiency of dimuon");
170 
171  TCanvas* c1 = new TCanvas("c1", "");
172  c1->SetGrid();
173  teff_trk_pos->Draw();
174  c1->SaveAs("result/teff_trk_pos.png");
175  teff_trk_neg->Draw();
176  c1->SaveAs("result/teff_trk_neg.png");
177  teff_dim ->Draw();
178  c1->SaveAs("result/teff_dim.png");
179  delete c1;
180 
181  teff_trk_pos->Write();
182  teff_trk_neg->Write();
183  teff_dim ->Write();
184  m_out_file->Close();
185 }
std::vector< DimuonData > DimuonList
Definition: TreeData.h:54
std::vector< TrackData > TrackList
Definition: TreeData.h:53
void Init(const char *fn_clean, const char *fn_messy)
void Analyze()
Function to analyze a pair of non-embedded and embedded (i.e. clean and messy) data.
double weight
Definition: TreeData.h:10
int n_h3x
Definition: TreeData.h:16
int event_id
Definition: TreeData.h:10
int n_h2x
Definition: TreeData.h:15
int rfp00
Definition: TreeData.h:10
int n_h1x
Definition: TreeData.h:14
int n_h4x
Definition: TreeData.h:17
int rfp01
Definition: TreeData.h:9
int rfm01
Definition: TreeData.h:11
int job_id
Definition: TreeData.h:6
int charge
Definition: TreeData.h:23