Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ST_Tresolution/macros/Resolution.C
Go to the documentation of this file.
1 // File: st_tw_fits.C
2 // Last Modified: 11/10/2015
3 // Creator: Mahmoud Kamel mkame006@fiu.edu
4 // Purpose: Displaying histograms and tw automatic process.
5 #include "TH1.h"
6 #include <TH2I.h>
7 #include <TH1D.h>
8 #include "TF1.h"
9 #include "TROOT.h"
10 #include "TStyle.h"
11 #include "TMath.h"
12 #include "TFile.h"
13 #include "TCanvas.h"
14 #include "TAxis.h"
15 #include <TDirectory.h>
16 #include <TLine.h>
17 #include <TPaveLabel.h>
18 #include <TPaletteAxis.h>
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <fstream>
22 #include <TNtuple.h>
23 #include <TGraphErrors.h>
24 using namespace std;
25 using std::string;
26 // ***************** define constants and varibles*************************
27 const Int_t NCHANNELS = 30;
28 
29 // Double_t sudo_mpv_chan[NCHANNELS];
30 Double_t t_all_fit[NCHANNELS][3];
31 Double_t t_all_fit_err[NCHANNELS][3];
32 
33 Double_t t_ss_fit[NCHANNELS][3];
34 Double_t t_ss_fit_err[NCHANNELS][3];
35 
36 Double_t t_bs_fit[NCHANNELS][3];
37 Double_t t_bs_fit_err[NCHANNELS][3];
38 
39 Double_t t_ns_fit[NCHANNELS][3];
40 Double_t t_ns_fit_err[NCHANNELS][3];
41 
42 Double_t t_bn_fit[NCHANNELS][3];
43 Double_t t_bn_fit_err[NCHANNELS][3];
44 
45 Double_t t_total_fit[NCHANNELS][3];
47 
48 Double_t ex[NCHANNELS];
49 Float_t t_bin[NCHANNELS];
50 Double_t t_max[NCHANNELS];
51 Double_t t_min[NCHANNELS];
52 Double_t tbn_max[NCHANNELS];
53 Double_t tbn_min[NCHANNELS];
54 Double_t tns_max[NCHANNELS];
55 Double_t tns_min[NCHANNELS];
56 Double_t tbs_max[NCHANNELS];
57 Double_t tbs_min[NCHANNELS];
58 Double_t tss_max[NCHANNELS];
59 Double_t tss_min[NCHANNELS];
60 Double_t tall_max[NCHANNELS];
61 Double_t tall_min[NCHANNELS];
62 Float_t bins[210];
63 Float_t binsall[210];
64 Float_t binsss[210];
65 Float_t binsbs[210];
66 Float_t binsns[210];
67 Float_t binsbn[210];
68 //TNtuple *ntuple;
69 //TGraphErrors *gr;
70 //**** Declare fits *****************************
72 TH1D *py[NCHANNELS];
73 // Declare canvas
74 TCanvas *PT_can[30];
75 TDirectory* TopDirectory;
76 TH2I* h2_total;
77 Double_t fitf_pp(Double_t *x, Double_t *par)
78 {
79  Double_t fitval_pp = par[0] + par[1]*x[0];//(TMath::Power(x[0]/adc_thresh_calc, par[2]));
80  return fitval_pp;
81 }
82 
83 void Resolution(char const*input_filename)
84 //void st_tw_fits()
85 {
86  TFile *df = new TFile(input_filename);
87  std::ofstream st_time_res;
88  st_time_res.open ("st_time_res.txt", std::ofstream::out);
89 
90  //*****************************************************************
91  //*********** Grab the histograms from the root file **************
92  //*****************************************************************
93 
94  for (unsigned int j = 0; j < 30; j++)
95  {
96  //Create the canvas
97  PT_can[j] = new TCanvas( Form("PT_can_%i",j+1), Form("PT_can_%i",j+1), 800, 450);
98  PT_can[j]->Divide(2, 1);
99  // The top directory
100  TopDirectory = (TDirectory*) df->FindObjectAny("ST_Tresolution");
101  TopDirectory->cd();
102  // Grab the histograms
103  //Corrected
104  char* total = Form("h2_CorrectedTime_z_%i",j+1);
105  h2_total = (TH2I*) TopDirectory->FindObjectAny(total);
106  char* pj = Form("py_%i",j+1);
107  TH1D* pytotal = (TH1D*)pj;
108 
109  cout << "==================================================" << endl;
110  cout << "Processing Channel " << j+1 << endl;
111  cout << "==================================================" << endl;
112  ex[j]=0.0;
113 
114 
115  //*****************************************************************
116  //*********** Plot Total corrected time from each division *******
117  //*****************************************************************
118  PT_can[j]->cd(1);
119  gStyle->SetOptStat(0);
120  gStyle->SetErrorX(0);
121  gPad->SetTicks();
122  gPad->SetGrid();
123  h2_total->Draw("colz");
124  h2_total->GetZaxis()->SetRangeUser(0,10000);
125  h2_total->GetYaxis()->SetTitle("ST Corrected Time (ns)");
126  h2_total->GetYaxis()->SetRangeUser(-5.0,5.0);
127  gPad->SetLogz();
128  PT_can[j]->cd(2);
129  gStyle->SetOptFit(11);
130  gStyle->SetErrorX(0);
131  gPad->SetTicks();
132  gPad->SetGrid();
133 
134  pytotal = h2_total->ProjectionY();
135  t_max[j]= pytotal->GetMaximum();
136  t_min[j]= pytotal->GetMinimum();
137  // for (unsigned int i = 0; i < 200; i++)
138  // {bins[i]= pytotal->GetBinContent(i);
139  // if (bins[i] < (0.15*t_max[j]))
140  // {
141  // pytotal->SetBinContent(i,0);
142  // pytotal->Draw("][");
143  // pytotal->GetXaxis()->SetRangeUser(-1.5,1.5);
144  // pytotal->GetXaxis()->SetTitle("ST Corrected Time (ns)");
145  // }
146  // }
147  pytotal->GetXaxis()->SetRangeUser(-5.0,5.0);
148  pytotal->Fit("gaus","","",-0.6,0.6);
149  TF1 *gaus = pytotal->GetFunction("gaus");
150  gPad->Update();
151  PT_can[j]->Print(Form("ST_Sector_%i.png",j+1));
152  t_total_fit[j][2] = gaus->GetParameter(2)*1000;
153  t_total_fit_err[j][2] = gaus->GetParError(2)*1000;
154 
155  st_time_res << j+1 <<" " << ex[j] << " "<< t_total_fit[j][2] << " "<< t_total_fit_err[j][2]<< endl;
156 
157  }
158  st_time_res.close();
159  ifstream in;
160  in.open(Form("st_time_res.txt"));
161  float sector,ser,tall,taller;
162  TNtuple *ntuple = new TNtuple("ntuple","data from text file","sector:ser:tall:taller");
163  ntuple->ReadFile("st_time_res.txt");
164  ntuple->Write();
165  in.close();
166  //Create the canvas
167  TCanvas *Time_can = new TCanvas( "Time_can", "Time_can", 800, 600);
168  Time_can->SetFillColor(41);
169  gStyle->SetOptFit(011);
170  ntuple->Draw("sector:tall:taller:ser");
171  TGraphErrors *gr=new TGraphErrors(ntuple->GetSelectedRows(),ntuple->GetV1(),ntuple->GetV2(),ntuple->GetV4(),ntuple->GetV3());
172  gr->Draw("AP");
173  gr->SetTitle("Time Resolution After Applying Propagation Time Corrections");
174  gr->GetXaxis()->SetTitle("Sector Number");
175  gr->GetYaxis()->SetTitle("Time Resolution (ps)");
176  gr->SetMarkerStyle(21);
177  gr->SetMarkerSize(3);
178  gr->SetMarkerColor(4);
179  gr->Fit("pol0");
180  gr->SetMinimum(150);
181  gr->SetMaximum(450);
182  TLine *line = new TLine(0,350,33,350);
183  line->SetLineWidth(4);
184  line->SetLineColor(28);
185  line->SetLineStyle(9);
186 
187  line->Draw();
188  Time_can->Print(Form("ST_Tresolution.png"));
189 }
190 
Double_t tns_min[NCHANNELS]
Double_t t_bs_fit_err[NCHANNELS][3]
Double_t t_bs_fit[NCHANNELS][3]
TFile * df
Definition: ST_slices_eff.C:17
TF1 * t_vs_z_fit_chan[NCHANNELS]
const Int_t NCHANNELS
void Resolution(char const *input_filename)
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
double total
Definition: FitGains.C:151
char string[256]
Double_t tbs_min[NCHANNELS]
Double_t t_total_fit[NCHANNELS][3]
TGraph * gr[NCHANNELS]
Definition: st_tw_resols.C:43
Double_t t_bn_fit[NCHANNELS][3]
Double_t t_min[NCHANNELS]
Double_t tbs_max[NCHANNELS]
TDirectory * TopDirectory
Double_t t_ns_fit_err[NCHANNELS][3]
Double_t ex[NCHANNELS]
Double_t tall_max[NCHANNELS]
Double_t tss_min[NCHANNELS]
Float_t t_bin[NCHANNELS]
Double_t t_bn_fit_err[NCHANNELS][3]
Double_t t_total_fit_err[NCHANNELS][3]
Double_t t_all_fit[NCHANNELS][3]
Double_t t_ns_fit[NCHANNELS][3]
TH1D * py[NCHANNELS]
TCanvas * PT_can[30]
Double_t t_ss_fit_err[NCHANNELS][3]
Double_t tns_max[NCHANNELS]
Double_t tbn_max[NCHANNELS]
Double_t t_ss_fit[NCHANNELS][3]
Double_t t_all_fit_err[NCHANNELS][3]
Double_t tall_min[NCHANNELS]
Double_t t_max[NCHANNELS]
Double_t tss_max[NCHANNELS]
Double_t fitf_pp(Double_t *x, Double_t *par)
Double_t tbn_min[NCHANNELS]
TCanvas * Time_can
Definition: st_tw_resols.C:46