fastMM_ana.C
Go to the documentation of this file.
1 #include <TH1.h>
2 #include <TH2.h>
3 #include <TTree.h>
4 #include "TAxis.h"
5 #include <TLegend.h>
6 #include <TFile.h>
7 #include <TProfile.h>
8 
9 #include <fstream>
10 #include <iostream>
11 #include <cmath>
12 
13 //This is following the SupperDDTEva convention
14 void readTree()
15 {
16  /*
17  std::ofstream ofs;
18  ofs.open ("trigger_eff.dat", std::ofstream::out | std::ofstream::app);
19  */
20  TFile* infile = new TFile("test.root","READ");
21  TFile* outfile = new TFile("newplots.root","recreate");
22 
23  TTree* MC_Tree = (TTree*)infile->Get("superddteva/MCTruth");
24  int n_MC_hits,evt_mc, nslice, ci,co, pi,po;
25  float beta_MC;
26  double edep, pathL;
27 
28  MC_Tree->SetBranchAddress("nhits",&n_MC_hits);
29  MC_Tree->SetBranchAddress("Beta",&beta_MC);
30  MC_Tree->SetBranchAddress("evtID",&evt_mc);
31  MC_Tree->SetBranchAddress("nslice",&nslice);
32  MC_Tree->SetBranchAddress("PathLength",&pathL);
33  MC_Tree->SetBranchAddress("EnergyDump",&edep);
34  MC_Tree->SetBranchAddress("Cell_in",&ci);
35  MC_Tree->SetBranchAddress("Cell_out",&co);
36  MC_Tree->SetBranchAddress("Plane_in",&pi);
37  MC_Tree->SetBranchAddress("Plane_out",&po);
38 
39  TTree* RC_Tree = (TTree*)infile->Get("superddteva/RCInfo");
40  int n_true_hits, n_hits, n_sh, evt;
41  float sumADC,beta,cosz;
42  RC_Tree->SetBranchAddress("Beta",&beta);
43  RC_Tree->SetBranchAddress("CosZ",&cosz);
44  RC_Tree->SetBranchAddress("SumADC",&sumADC);
45  RC_Tree->SetBranchAddress("nFLShits",&n_true_hits);
46  RC_Tree->SetBranchAddress("nhits",&n_hits);
47  RC_Tree->SetBranchAddress("NSH",&n_sh);
48  RC_Tree->SetBranchAddress("eventID",&evt);
49 
50  TProfile* p_beta_ADC = new TProfile("beta_ADC","#beta Vs. Mean Slice ADC", 1000, 0, 0.4, 200,4100);
51  TProfile* p_beta_st = new TProfile("beta_st","#beta Vs. Number of Slices Contain Hits From Same MM", 1000, 0, 0.4, 0,5);
52 
53  TH1F* beta_ceff = new TH1F("beta_ceff", "", 100, 0, 0.04);
54  TH1F* beta_teff = new TH1F("beta_teff", "", 100, 0, 0.04);
55  TH1F* h_beta = new TH1F("beta", "", 100, 0, 0.04);
56 
57  TH1F* h_missing = new TH1F("beta_missing", "", 100, 0, 0.04);
58 
59  TH2F* M_edepVsnh = new TH2F("eVn","",100,0,10,30,0.5,30.5);
60 
61  TH2F* CP_bound = new TH2F("cp","",1000,-50.5,949.5,500,-50.5,449.5);
62 
63 
64  int nMCevts = 0;
65  int evt_mc_tmp = -1;
66  for (int i =0; i!=MC_Tree->GetEntries();++i) {
67  MC_Tree->GetEntry(i);
68 
69  CP_bound->Fill(pi,ci);
70  CP_bound->Fill(po,co);
71 
72  if (n_MC_hits<1) continue;
73  if (evt_mc_tmp==evt_mc) std::cout<<"Oh?! MC duplicated event entry!"<<std::endl;
74 
75  h_beta->Fill(beta_MC);
76  if (!nslice) {
77  h_missing->Fill(beta_MC);
78  M_edepVsnh->Fill(edep,n_MC_hits);
79  }
80  ++nMCevts;
81  evt_mc_tmp = evt_mc;
82  }
83 
84  std::cout<<"number of real MM evts: "<<nMCevts<<std::endl;
85 
86  int evt_tmp = -1;
87  int sliceTime = 1;
88  int dup_time=0;
89  int rc_evts=0;
90 
91  // bool found = false;
92 
93  for (int k = 0; k!=RC_Tree->GetEntries();++k) {
94  RC_Tree->GetEntry(k);
95  if (n_true_hits<1) continue;
96  p_beta_ADC->Fill(beta,sumADC/(n_hits+0.),1);
97  if (evt_tmp==evt) {
98  ++sliceTime;
99  ++dup_time;
100  }
101  else {
102  ++rc_evts;
103  beta_ceff ->Fill(beta);
104  if (sumADC> 2500*n_hits && n_sh > 6) {
105  beta_teff->Fill(beta);
106  }
107  sliceTime = 1;
108  evt_tmp = evt;
109  }
110  p_beta_st->Fill(beta,sliceTime,1);
111  }
112  std::cout<<"RC Events: "<<rc_evts<<std::endl;
113  std::cout<<"duplicated Slicing time: "<<dup_time<<std::endl;
114 
115  for (int bin =1; bin!=1001; ++bin) {
116  float tot = h_beta->GetBinContent(bin);
117 
118  float ce = 1;
119  float te = 1;
120  float mi = 0;
121  float ce_err = 0;
122  float te_err = 0;
123  float mi_err = 0;
124 
125  if (tot) {
126  ce = beta_ceff->GetBinContent(bin)/tot;
127  te = beta_teff->GetBinContent(bin)/tot;
128  mi = h_missing->GetBinContent(bin)/tot;
129  ce_err = sqrt(ce*(1-ce)/tot);
130  te_err = sqrt(te*(1-te)/tot);
131  mi_err = sqrt(mi*(1-mi)/tot);
132  }
133 
134  if (ce>1 || te>1) std::cout<<"You have some error!"<<std::endl;
135 
136  beta_ceff -> SetBinContent(bin,ce);
137  beta_ceff -> SetBinError(bin,ce_err);
138 
139  beta_teff -> SetBinContent(bin,te);
140  beta_teff -> SetBinError(bin,te_err);
141 
142  h_missing -> SetBinContent(bin,mi);
143  h_missing -> SetBinError(bin,mi_err);
144  }
145 
146  h_beta->Write();
147  beta_ceff->Write();
148  beta_teff->Write();
149  p_beta_ADC->Write();
150  p_beta_st->Write();
151  h_missing->Write();
152  M_edepVsnh->Write();
153  CP_bound -> Write();
154  outfile->Close();
155  infile ->Close();
156 }
157 
158 
T sqrt(T number)
Definition: d0nt_math.hpp:156
Double_t beta
string infile
int evt
float bin[41]
Definition: plottest35.C:14
Double_t edep
Definition: macro.C:13
OStream cout
Definition: OStream.cxx:6
cout<< "--"<< endl;for(Int_t iP=1;iP<=hyz->GetNbinsX();iP++){for(Int_t iC=1;iC<=hyz->GetNbinsY();iC++){if(hyv->GetBinContent(iP, iC)>-999){goal_hyv-> SetBinContent(iP, iC,-(dy[iP-1][iC-1]))
void readTree()
Definition: fastMM_ana.C:14
FILE * outfile
Definition: dump_event.C:13
gm Write()