Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fun4SimTree.C
Go to the documentation of this file.
1 R__LOAD_LIBRARY(libana_sim_dst)
3 
4 using namespace std;
5 TCanvas* c1;
6 void DrawDimTrueKin(TTree* tr);
7 void DrawDimRecoKin(TTree* tr);
8 void DrawTrkTrueKin(TTree* tr);
9 void DrawTrueVar(TTree* tr, const string varname, const string title_x, const int n_x, const double x_lo, const double x_hi);
10 void FitCosTheta(TTree* tr);
11 void AnaEvents(TTree* tr);
12 
13 void Fun4SimTree(const char* fname="sim_tree.root", const char* tname="tree")
14 {
15  TFile* file = new TFile(fname);
16  TTree* tr = (TTree*)file->Get(tname);
17  gSystem->mkdir("result", true);
18  c1 = new TCanvas("c1", "");
19  c1->SetGrid();
20  //c1->SetLogy(true);
21 
23  DrawDimTrueKin(tr);
24  //DrawDimRecoKin(tr);
25  //DrawTrkTrueKin(tr);
26  FitCosTheta(tr);
27  //AnaEvents(tr);
28 
29  exit(0);
30 }
31 
35 void DrawDimTrueKin(TTree* tr)
36 {
37  tr->Draw("n_dim_true");
38  c1->SaveAs("result/h1_true_n_dim.png");
39 
40  const double PI = TMath::Pi();
41  DrawTrueVar(tr, "dim_true.pdg_id" , "True dimuon PDG ID", 1000, 0, 0);
42  DrawTrueVar(tr, "dim_true.mom.X()" , "True dimuon px (GeV)", 100, -5, 5);
43  DrawTrueVar(tr, "dim_true.mom.Y()" , "True dimuon py (GeV)", 100, -5, 5);
44  DrawTrueVar(tr, "dim_true.mom.Z()" , "True dimuon pz (GeV)", 100, 0, 100);
45  DrawTrueVar(tr, "dim_true.mom.M()" , "True dimuon mass (GeV)", 100, 0, 5);
46  DrawTrueVar(tr, "dim_true.mom.Eta()" , "True dimuon #eta", 110, 0, 11);
47  DrawTrueVar(tr, "dim_true.mom.Phi()" , "True dimuon #phi", 100, -PI, PI);
48  DrawTrueVar(tr, "dim_true.x1" , "True x1", 50, 0, 1);
49  DrawTrueVar(tr, "dim_true.x2" , "True x2", 50, 0, 1);
50  DrawTrueVar(tr, "dim_true.xF" , "True xF", 50, -1, 1);
51  DrawTrueVar(tr, "dim_true.costh" , "True cos#theta", 50, -1, 1);
52  DrawTrueVar(tr, "dim_true.phi" , "True #phi" , 50, -PI, PI);
53 }
54 
55 void DrawDimRecoKin(TTree* tr)
56 {
57  tr->Draw("n_dim_reco");
58  c1->SaveAs("result/h1_reco_n_dim.png");
59 
60  tr->Draw("rec_stat"); // cf. GlobalConsts.h.
61  c1->SaveAs("result/h1_rec_stat.png");
62 
63  tr->Draw("trig_bits", "rec_stat==0");
64  c1->SaveAs("result/h1_trig_bits.png");
65 
66  tr->Draw("dim_reco.mom.M()", "rec_stat==0");
67  c1->SaveAs("result/h1_dim_reco_mass.png");
68 
69  tr->Draw("dim_reco.x1", "rec_stat==0");
70  c1->SaveAs("result/h1_dim_reco_x1.png");
71 
72  tr->Draw("dim_reco.x2", "rec_stat==0");
73  c1->SaveAs("result/h1_dim_reco_x2.png");
74 }
75 
76 
77 void DrawTrkTrueKin(TTree* tr)
78 {
79  DrawTrueVar(tr, "dim_true.mom_pos.X()", "True px (GeV) of mu+", 100, -5, 5);
80  DrawTrueVar(tr, "dim_true.mom_pos.Y()", "True py (GeV) of mu+", 100, -5, 5);
81  DrawTrueVar(tr, "dim_true.mom_pos.Z()", "True pz (GeV) of mu+", 100, 0, 100);
82  DrawTrueVar(tr, "dim_true.mom_neg.X()", "True px (GeV) of mu-", 100, -5, 5);
83  DrawTrueVar(tr, "dim_true.mom_neg.Y()", "True py (GeV) of mu-", 100, -5, 5);
84  DrawTrueVar(tr, "dim_true.mom_neg.Z()", "True pz (GeV) of mu-", 100, 0, 100);
85 
86  THStack* hs;
87  TH1* h1_all = new TH1D("h1_all", "", 100, -1, 1);
88  TH1* h1_rec = new TH1D("h1_rec", "", 100, -1, 1);
89  tr->Project("h1_all", "(dim_true.mom_pos.Z() - dim_true.mom_neg.Z())/(dim_true.mom_pos.Z() + dim_true.mom_neg.Z())");
90  tr->Project("h1_rec", "(dim_true.mom_pos.Z() - dim_true.mom_neg.Z())/(dim_true.mom_pos.Z() + dim_true.mom_neg.Z())", "rec_stat==0");
91  hs = new THStack("hs", "J/#psi GMC;gpz+gpz (GeV) of tracks;N of tracks");
92  hs->Add(h1_all);
93  hs->Add(h1_rec);
94  h1_rec->SetLineColor(kRed);
95  hs->Draw("nostack");
96  c1->SaveAs("result/h1_trk_true_pz_asym.png");
97 }
98 
99 void DrawTrueVar(TTree* tr, const string varname, const string title_x, const int n_x, const double x_lo, const double x_hi)
100 {
101  TH1* h1_all = new TH1D("h1_all", "", n_x, x_lo, x_hi);
102  TH1* h1_rec = new TH1D("h1_rec", "", n_x, x_lo, x_hi);
103  tr->Project("h1_all", varname.c_str());
104  tr->Project("h1_rec", varname.c_str(), "rec_stat==0");
105 
106  ostringstream oss;
107  oss << "J/#psi GMC;" << title_x << ";Yield";
108  THStack hs("hs", oss.str().c_str());
109  hs.Add(h1_all);
110  hs.Add(h1_rec);
111  h1_rec->SetLineColor(kRed);
112  hs.Draw("nostack");
113 
114  oss.str("");
115  oss << "result/h1_";
116  for (string::const_iterator it = varname.begin(); it != varname.end(); it++) {
117  switch (*it) { // modify bad chars for file name
118  case '.': case '*': case '/': oss << '_'; break;
119  case '(': case ')': case ' ': /* omit */ break;
120  default: oss << *it;
121  }
122  }
123  oss << ".png";
124  c1->SaveAs(oss.str().c_str());
125 
126  delete h1_all;
127  delete h1_rec;
128 }
129 
130 void FitCosTheta(TTree* tr)
131 {
132  gStyle->SetOptFit(true);
133  TH1* h1_costh = new TH1D("h1_costh", "", 100, -1, 1);
134  tr->Project("h1_costh", "dim_true.costh");
135  TF1* f1 = new TF1("f1", "[0]*(1 + [1]*pow(x,2))", -0.8, 0.8);
136  h1_costh->Fit(f1, "REM");
137  c1->SaveAs("result/h1_costh_fit.png");
138  delete f1;
139  delete h1_costh;
140 }
141 
142 void AnaEvents(TTree* tr)
143 {
144  typedef map<int, int> IntCount_t;
145  IntCount_t id_cnt;
146  DimuonList* list_dim = new DimuonList();
147  tr->SetBranchAddress("dim_true", &list_dim);
148 
149  int n_ent = tr->GetEntries();
150  cout << "AnaEvents(): n = " << n_ent << endl;
151  for (int i_ent = 0; i_ent < n_ent; i_ent++) {
152  if ((i_ent+1) % (n_ent/10) == 0) cout << " " << 100*(i_ent+1)/n_ent << "%" << flush;
153  tr->GetEntry(i_ent);
154  for (DimuonList::iterator it = list_dim->begin(); it != list_dim->end(); it++) {
155  DimuonData* dd = &(*it);
156  int pdg_id = dd->pdg_id;
157  if (id_cnt.find(pdg_id) == id_cnt.end()) id_cnt[pdg_id] = 1;
158  else id_cnt[pdg_id]++;
159  }
160  }
161  cout << endl;
162  for (IntCount_t::iterator it = id_cnt.begin(); it != id_cnt.end(); it++) {
163  cout << setw(10) << it->first << " " << setw(10) << it->second << endl;
164  }
165 }
void FitCosTheta(TTree *tr)
Definition: Fun4SimTree.C:130
void Fun4SimTree(const char *fname="sim_tree.root", const char *tname="tree")
Definition: Fun4SimTree.C:13
void DrawTrueVar(TTree *tr, const string varname, const string title_x, const int n_x, const double x_lo, const double x_hi)
Definition: Fun4SimTree.C:99
int pdg_id
Definition: TreeData.h:33
std::vector< DimuonData > DimuonList
Definition: TreeData.h:53
void DrawTrkTrueKin(TTree *tr)
Definition: Fun4SimTree.C:77
void DrawDimRecoKin(TTree *tr)
Definition: Fun4SimTree.C:55
void DrawDimTrueKin(TTree *tr)
Definition: Fun4SimTree.C:35
void AnaEvents(TTree *tr)
Definition: Fun4SimTree.C:142
TCanvas * c1
Definition: Fun4SimTree.C:5