Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SC_PTC.C
Go to the documentation of this file.
1 // File: st_tw_fits.C
2 // Last Modified: 01/12/2016
3 // Creator: Mahmoud Kamel mkame006@fiu.edu
4 // Purpose: Displaying histograms and propagation time correction.
5 #include "TH1.h"
6 #include <TH2I.h>
7 #include "TF1.h"
8 #include "TROOT.h"
9 #include "TStyle.h"
10 #include "TMath.h"
11 #include "TFile.h"
12 #include "TCanvas.h"
13 #include "TAxis.h"
14 #include <TDirectory.h>
15 #include <TLine.h>
16 #include <TPaveLabel.h>
17 #include <TPaletteAxis.h>
18 #include <stdio.h>
19 #include <stdint.h>
20 #include <fstream>
21 using namespace std;
22 using std::string;
23 // ***************** define constants and varibles*************************
24 const Int_t NCHANNELS = 30;
25 Double_t t_ns_fit_mean[NCHANNELS][300][3];
26 Double_t t_ns_fit_mean_err[NCHANNELS][300][3];
27 Double_t t_ss_fit_mean[NCHANNELS][300][3];
28 Double_t t_ss_fit_mean_err[NCHANNELS][300][3];
29 Double_t t_bs_fit_mean[NCHANNELS][300][3];
30 Double_t t_bs_fit_mean_err[NCHANNELS][300][3];
31 Double_t t_ss_fit_sigma[NCHANNELS][300][3];
32 Double_t t_ss_fit_sigma_err[NCHANNELS][300][3];
33 Double_t t_bs_fit_sigma[NCHANNELS][300][3];
34 Double_t t_bs_fit_sigma_err[NCHANNELS][300][3];
35 Double_t t_ns_fit_sigma[NCHANNELS][300][3];
36 Double_t t_ns_fit_sigma_err[NCHANNELS][300][3];
37 // Declare canvas
38 TCanvas *PT_can[30];
39 TCanvas *PTC[30];
40 TCanvas *PTC_BS[30];
41 TCanvas *PTC_NS[30];
42 TDirectory* TopDirectory;
43 TH2I* h2_ss;
44 TH2I* h2_bs;
45 TH2I* h2_ns;
46 TH2I* h2All;
47 double bin1[30][100];
48 double bin2[30][100];
49 TH1D* h1_ns_Bin[30][100];
50 TH1D* h1_ss_Bin[30][100];
51 TH1D* h1_bs_Bin[30][100];
52 Double_t t_max[NCHANNELS][300];
53 Double_t t_max_BS[NCHANNELS][300];
54 Double_t t_max_NS[NCHANNELS][300];
55 double bin1bs[30][100];
56 double bin2bs[30][100];
57 double bin1ns[30][100];
58 double bin2ns[30][100];
59 
60 
73 const int NOXbins = 300;
74 const int NOYbins = 200;
77 Double_t ss_max[NCHANNELS];
78 Double_t low_cut = 0.10;
79 Double_t global[NCHANNELS];
80 
81 Double_t N_x_bin[NCHANNELS];
82 Double_t N_y_bin[NCHANNELS];
85 Double_t bins[500][500];
86 
87 //h1_ns_Bin = new TH1D *[300];
88 //TH1D** h1_ns_Bin = new TH1D *[300];
89 void SC_PTC(char const* input_filename)
90 //void st_tw_fits()
91 {
92  TFile *df = new TFile(input_filename);
93  std::ofstream SC_PTC;
94  SC_PTC.open ("SC_PTC.txt", std::ofstream::out);
95  //*****************************************************************
96  //*********** Grab the histograms from the root file **************
97  //*****************************************************************
98  for (unsigned int j = 0; j < NCHANNELS; j++)
99  // for (unsigned int j = 0; j < 1; j++)
100  {
101  PTC[j] = new TCanvas( Form("PTC_%i",j+1), Form("PTC_%i",j+1), 800, 450);
102  PTC[j]->Divide(3,2);
103  PTC_BS[j] = new TCanvas( Form("PTC_BS_%i",j+1), Form("PTC_BS_%i",j+1), 800, 450);
104  PTC_BS[j]->Divide(3,1);
105  PTC_NS[j] = new TCanvas( Form("PTC_NS_%i",j+1), Form("PTC_NS_%i",j+1), 800, 450);
106  PTC_NS[j]->Divide(3,3);
107  // The top directory
108  TopDirectory = (TDirectory*) df->FindObjectAny("ST_Propagation_Time");
109  TopDirectory->cd();
110  // Grab the uncorrected 2D histogram
111  char* All = Form("h2_PpropTime_z_%i",j+1);
112  h2All = (TH2I*) TopDirectory->FindObjectAny(All);
113 
114  cout << "==================================================" << endl;
115  cout << "Processing Channel " << j+1 << endl;
116  cout << "==================================================" << endl;
117  //*****************************************************************
118  //*********** SS intervals ******************
119  //*****************************************************************
120 
121  for (Int_t i = 10; i < 40; i+=5)
122  {
123  Int_t k =(i/5)-1;
124  cout << " k = " << k << endl;
125  PTC[j]->cd(k);
126  bin1[j][i] = h2All->GetXaxis()->FindBin(i);
127  bin2[j][i] = h2All->GetXaxis()->FindBin(i+5);
128  h1_ss_Bin[j][i] = h2All->ProjectionY(Form("h1_ss_Bin_%i_%i",i,j+1),bin1[j][i],bin2[j][i],"");
129 
130  t_max[j][i]= h1_ss_Bin[j][i]->GetMaximumBin();
131  double LL_fit = (t_max[j][i] -100)*0.1 - 0.5 ;
132  double UL_fit = (t_max[j][i] -100)*0.1 + 0.5 ;
133  h1_ss_Bin[j][i]->Draw();
134  h1_ss_Bin[j][i]->Fit("gaus","","",LL_fit,UL_fit);
135  TF1 *gaus = h1_ss_Bin[j][i]->GetFunction("gaus");
136  t_ss_fit_mean[j][i][1] = gaus->GetParameter(1);
137  t_ss_fit_mean_err[j][i][1] = gaus->GetParError(1);
138  t_ss_fit_sigma[j][i][2] = gaus->GetParameter(2);
139  t_ss_fit_sigma_err[j][i][2] = gaus->GetParError(2);
140 
141  SC_PTC <<"\t"<< j+1 <<"\t"<< i+2.5 <<"\t"<< 0.0 <<"\t"<< t_ss_fit_mean[j][i][1] <<"\t"<< t_ss_fit_mean_err[j][i][1]<<"\t"<< t_ss_fit_sigma[j][i][2] << "\t"<< t_ss_fit_sigma_err[j][i][2] <<endl;
142  }
143  //*****************************************************************
144  //*********** BS intervals ******************
145  //*****************************************************************
146  for (Int_t i = 40; i < 43; i+=1)
147  {
148 
149  Int_t k = i - 39;
150  PTC_BS[j]->cd(k);
151  bin1bs[j][i] = h2All->GetXaxis()->FindBin(i);
152  bin2bs[j][i] = h2All->GetXaxis()->FindBin(i+1);
153  h1_bs_Bin[j][i] = h2All->ProjectionY(Form("h1_bs_Bin_%i_%i",i,j+1),bin1bs[j][i],bin2bs[j][i],"");
154 
155  t_max_BS[j][i]= h1_bs_Bin[j][i]->GetMaximumBin();
156  double LL_fit = (t_max_BS[j][i] -100)*0.1 - 0.5 ;
157  double UL_fit = (t_max_BS[j][i] -100)*0.1 + 0.5 ;
158  h1_bs_Bin[j][i]->Draw();
159  h1_bs_Bin[j][i]->Fit("gaus","","",LL_fit,UL_fit);
160  TF1 *gaus_BS = h1_bs_Bin[j][i]->GetFunction("gaus");
161  t_bs_fit_mean[j][i][1] = gaus_BS->GetParameter(1);
162  t_bs_fit_mean_err[j][i][1] = gaus_BS->GetParError(1);
163  t_bs_fit_sigma[j][i][2] = gaus_BS->GetParameter(2);
164  t_bs_fit_sigma_err[j][i][2] = gaus_BS->GetParError(2);
165 
166  SC_PTC <<"\t"<< j+1 <<"\t"<< i+0.5 <<"\t"<< 0.0 <<"\t"<< t_bs_fit_mean[j][i][1] <<"\t"<< t_bs_fit_mean_err[j][i][1]<<"\t"<< t_bs_fit_sigma[j][i][2] << "\t"<< t_bs_fit_sigma_err[j][i][2] <<endl;
167  }
168 
169  // //*****************************************************************
170  // //*********** NS intervals ******************
171  // //*****************************************************************
172  Int_t k =0;
173  for (Int_t i = 43; i < 61; i+=2)
174  {
175  k = (i - 42) - k;
176  PTC_NS[j]->cd(k);
177  bin1ns[j][i] = h2All->GetXaxis()->FindBin(i);
178  bin2ns[j][i] = h2All->GetXaxis()->FindBin(i+2);
179  h1_ns_Bin[j][i] = h2All->ProjectionY(Form("h1_ns_Bin_%i_%i",i,j+1),bin1ns[j][i],bin2ns[j][i],"");
180 
181  t_max_NS[j][i]= h1_ns_Bin[j][i]->GetMaximumBin();
182  double LL_fit = (t_max_NS[j][i] -100)*0.1 - 0.5 ;
183  double UL_fit = (t_max_NS[j][i] -100)*0.1 + 0.5 ;
184  h1_ns_Bin[j][i]->Draw();
185  h1_ns_Bin[j][i]->Fit("gaus","","",LL_fit,UL_fit);
186  TF1 *gaus_NS = h1_ns_Bin[j][i]->GetFunction("gaus");
187  t_ns_fit_mean[j][i][1] = gaus_NS->GetParameter(1);
188  t_ns_fit_mean_err[j][i][1] = gaus_NS->GetParError(1);
189  t_ns_fit_sigma[j][i][2] = gaus_NS->GetParameter(2);
190  t_ns_fit_sigma_err[j][i][2] = gaus_NS->GetParError(2);
191 
192  SC_PTC <<"\t"<< j+1 <<"\t"<< i+1 <<"\t"<< 0.0 <<"\t"<< t_ns_fit_mean[j][i][1] <<"\t"<< t_ns_fit_mean_err[j][i][1]<<"\t"<< t_ns_fit_sigma[j][i][2] << "\t"<< t_ns_fit_sigma_err[j][i][2] <<endl;
193  }
194  }
195 
196  SC_PTC.close();
197 }
198 
Double_t t_z_ss_fit_intercept[NCHANNELS][3]
Definition: SC_PTC.C:63
TH1D * h1_ns_Bin[30][100]
Definition: SC_PTC.C:49
double bin2[30][100]
Definition: SC_PTC.C:48
Double_t t_z_ss_fit_intercept_err[NCHANNELS][3]
Definition: SC_PTC.C:64
Double_t low_cut
Definition: SC_PTC.C:78
TFile * df
Definition: ST_slices_eff.C:17
Double_t t_z_bs_fit_slope_err[NCHANNELS][3]
Definition: SC_PTC.C:66
TH2I * h2All
Definition: SC_PTC.C:46
const Int_t NCHANNELS
char string[256]
void SC_PTC(char const *input_filename)
Definition: SC_PTC.C:89
Double_t t_ns_fit_sigma_err[NCHANNELS][300][3]
Definition: SC_PTC.C:36
Double_t t_max_NS[NCHANNELS][300]
Definition: SC_PTC.C:54
TCanvas * PTC_NS[30]
Definition: SC_PTC.C:41
TH2I * h2_ns
Definition: SC_PTC.C:45
Double_t t_z_bs_fit_intercept[NCHANNELS][3]
Definition: SC_PTC.C:67
Double_t t_ss_fit_sigma_err[NCHANNELS][300][3]
Definition: SC_PTC.C:32
TDirectory * TopDirectory
Double_t t_ss_fit_mean[NCHANNELS][300][3]
Definition: SC_PTC.C:27
Double_t t_bs_fit_mean[NCHANNELS][300][3]
Definition: SC_PTC.C:29
Double_t t_z_ns_fit_slope_err[NCHANNELS][3]
Definition: SC_PTC.C:70
const int NOXbins
Definition: SC_PTC.C:73
Double_t global[NCHANNELS]
Definition: SC_PTC.C:79
TCanvas * PTC[30]
Definition: SC_PTC.C:39
Double_t t_bs_fit_sigma[NCHANNELS][300][3]
Definition: SC_PTC.C:33
Double_t t_max_BS[NCHANNELS][300]
Definition: SC_PTC.C:53
Double_t t_z_bs_fit_slope[NCHANNELS][3]
Definition: SC_PTC.C:65
TH1D * h1_ss_Bin[30][100]
Definition: SC_PTC.C:50
const int NOYbins
Definition: SC_PTC.C:74
Double_t t_ss_fit_mean_err[NCHANNELS][300][3]
Definition: SC_PTC.C:28
Double_t t_z_ss_fit_slope[NCHANNELS][3]
Definition: SC_PTC.C:61
TH2I * h2_ss
Definition: SC_PTC.C:43
Double_t t_z_ns_fit_intercept[NCHANNELS][3]
Definition: SC_PTC.C:71
Double_t t_bs_fit_sigma_err[NCHANNELS][300][3]
Definition: SC_PTC.C:34
Double_t t_z_ns_fit_intercept_err[NCHANNELS][3]
Definition: SC_PTC.C:72
double bin1ns[30][100]
Definition: SC_PTC.C:57
Double_t t_bs_fit_mean_err[NCHANNELS][300][3]
Definition: SC_PTC.C:30
TCanvas * PT_can[30]
double bin2ns[30][100]
Definition: SC_PTC.C:58
Double_t t_z_ns_fit_slope[NCHANNELS][3]
Definition: SC_PTC.C:69
double bin1bs[30][100]
Definition: SC_PTC.C:55
double bin1[30][100]
Definition: SC_PTC.C:47
Double_t t_ss_fit_sigma[NCHANNELS][300][3]
Definition: SC_PTC.C:31
Double_t max_y_axis_value[NCHANNELS]
Definition: SC_PTC.C:84
Double_t t_ns_fit_mean_err[NCHANNELS][300][3]
Definition: SC_PTC.C:26
int sss[NCHANNELS][NOXbins][NOYbins]
Definition: SC_PTC.C:75
Double_t N_y_bin[NCHANNELS]
Definition: SC_PTC.C:82
Double_t t_z_bs_fit_intercept_err[NCHANNELS][3]
Definition: SC_PTC.C:68
Double_t t_z_ss_fit_slope_err[NCHANNELS][3]
Definition: SC_PTC.C:62
TH1D * h1_bs_Bin[30][100]
Definition: SC_PTC.C:51
double bin2bs[30][100]
Definition: SC_PTC.C:56
Double_t t_ns_fit_mean[NCHANNELS][300][3]
Definition: SC_PTC.C:25
TH2I * h2_bs
Definition: SC_PTC.C:44
Double_t N_x_bin[NCHANNELS]
Definition: SC_PTC.C:81
Double_t t_max[NCHANNELS]
Double_t ss_max[NCHANNELS]
Definition: SC_PTC.C:77
TCanvas * PTC_BS[30]
Definition: SC_PTC.C:40
Double_t t_ns_fit_sigma[NCHANNELS][300][3]
Definition: SC_PTC.C:35
Double_t max_y_axis_bin[NCHANNELS]
Definition: SC_PTC.C:83