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