Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
st_prop_time_v1.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;
29 
34 
39 const int NOXbins = 300;
40 const int NOYbins = 200;
43 Double_t ss_max[NCHANNELS];
44 Double_t low_cut = 0.25;
45 // Declare canvas
46 TCanvas *PT_can[30];
47 TDirectory* TopDirectory;
48 TH1I* h2_ss;
49 TH1I* h2_bs;
50 TH1I* h2_ns;
51 void st_prop_time_v1(char const* input_filename)
52 //void st_tw_fits()
53 {
54  TFile *df = new TFile(input_filename);
55  std::ofstream st_prop_time_constants;
56  st_prop_time_constants.open ("st_prop_time_constants.txt", std::ofstream::out);
57  //*****************************************************************
58  //*********** Grab the histograms from the root file **************
59  //*****************************************************************
60  for (unsigned int j = 0; j < NCHANNELS; j++)
61  {
62  //Create the canvas
63  PT_can[j] = new TCanvas( Form("PT_can_%i",j+1), Form("PT_can_%i",j+1), 800, 450);
64  PT_can[j]->Divide(3, 1);
65  // The top directory
66  TopDirectory = (TDirectory*) df->FindObjectAny("ST_Propagation_Time");
67  TopDirectory->cd();
68  // Grab the histograms
69  char* ss = Form("h2_PropTime_z_SS_chan_%i",j+1);
70  // TH1I* h2_ss = (TH1I*) df->Get(ss);
71  h2_ss = (TH1I*) TopDirectory->FindObjectAny(ss);
72  char* bs = Form("h2_PropTime_z_BS_chan_%i",j+1);
73  h2_bs = (TH1I*) TopDirectory->FindObjectAny(bs);
74  char* ns = Form("h2_PropTime_z_NS_chan_%i",j+1);
75  h2_ns = (TH1I*) TopDirectory->FindObjectAny(ns);
76 
77  cout << "==================================================" << endl;
78  cout << "Processing Channel " << j+1 << endl;
79  cout << "==================================================" << endl;
80  //*****************************************************************
81  //*********** Plot stt vs z SS ******************
82  //*****************************************************************
83  PT_can[j]->cd(1);
84  gStyle->SetOptFit(111111);
85  gStyle->SetErrorX(0);
86  gPad->SetTicks();
87  gPad->SetGrid();
88  h2_ss->SetTitle("Straight Section");
89  h2_ss->GetZaxis()->SetRangeUser(0,4);
90  h2_ss->GetYaxis()->SetRangeUser(0.,5.);
91  h2_ss->GetYaxis()->SetTitle("ST Propagation Time (ns)");
92  h2_ss->GetXaxis()->SetTitle("Path Length (cm)");
93  h2_ss->GetXaxis()->SetRangeUser(0.,40.0);
94  h2_ss->Draw("colz");
95  h2_ss->Fit("pol1");
96  TF1 *pol1 = h2_ss->GetFunction("pol1");
97  t_z_ss_fit_slope[j][1] = pol1->GetParameter(1);
98  t_z_ss_fit_slope_err[j][1] = pol1->GetParError(1);
99  t_z_ss_fit_intercept[j][0] = pol1->GetParameter(0);
100  t_z_ss_fit_intercept_err[0][1] = pol1->GetParError(0);
101 
102  //*****************************************************************
103  //*********** Plot stt vs z BS ******************
104  //*****************************************************************
105  PT_can[j]->cd(2);
106  gPad->SetTicks();
107  gPad->SetGrid();
108  h2_bs->Draw("colz");
109  h2_bs->SetTitle("Bend Section");
110  h2_bs->GetZaxis()->SetRangeUser(0,4);
111  h2_bs->GetYaxis()->SetRangeUser(0.,5.);
112  h2_bs->GetYaxis()->SetTitle("ST Propagation Time (ns)");
113  h2_bs->GetXaxis()->SetTitle("Path Length (cm)");
114  h2_bs->GetXaxis()->SetRangeUser(39.,43.0);
115 
116 
117  h2_bs->Fit("pol1");
118  pol1 = h2_bs->GetFunction("pol1");
119  t_z_bs_fit_slope[j][1] = pol1->GetParameter(1);
120  t_z_bs_fit_slope_err[j][1] = pol1->GetParError(1);
121  t_z_bs_fit_intercept[j][0] = pol1->GetParameter(0);
122  t_z_bs_fit_intercept_err[0][1] = pol1->GetParError(0);
123  //*****************************************************************
124  //*********** Plot stt vs z NS ******************
125  //*****************************************************************
126  PT_can[j]->cd(3);
127  gStyle->SetOptStat(0);
128  gStyle->SetErrorX(0);
129  gPad->SetTicks();
130  gPad->SetGrid();
131  h2_ns->Draw("colz");
132  h2_ns->SetTitle("Nose Section");
133  h2_ns->GetZaxis()->SetRangeUser(0,4);
134  h2_ns->GetYaxis()->SetRangeUser(0.,5.);
135  h2_ns->GetYaxis()->SetTitle("ST Propagation Time (ns)");
136  h2_ns->GetXaxis()->SetTitle("Path Length (cm)");
137  h2_ns->GetXaxis()->SetRangeUser(43.,60.0);
138  h2_ns->Fit("pol1");
139  pol1 = h2_ns->GetFunction("pol1");
140  t_z_ns_fit_slope[j][1] = pol1->GetParameter(1);
141  t_z_ns_fit_slope_err[j][1] = pol1->GetParError(1);
142  t_z_ns_fit_intercept[j][0] = pol1->GetParameter(0);
143  t_z_ns_fit_intercept_err[0][1] = pol1->GetParError(0);
144  //*****************************************************************
145  //*********** save data to dump it to ccdb ******************
146  //*****************************************************************
147  st_prop_time_constants << "\t"<< t_z_ss_fit_intercept[j][0] << "\t"<< t_z_ss_fit_slope[j][1]<< "\t"<< t_z_bs_fit_intercept[j][0] << "\t"<< t_z_bs_fit_slope[j][1]<< "\t"<< t_z_ns_fit_intercept[j][0] << "\t"<< t_z_ns_fit_slope[j][1]<< endl;
148  }
149  st_prop_time_constants.close();
150 }
151 
Double_t t_z_ss_fit_intercept[NCHANNELS][3]
Definition: SC_PTC.C:63
void st_prop_time_v1(char const *input_filename)
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
const Int_t NCHANNELS
char string[256]
TH2I * h2_ns
Definition: SC_PTC.C:45
Double_t t_z_bs_fit_intercept[NCHANNELS][3]
Definition: SC_PTC.C:67
TDirectory * TopDirectory
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 t_z_bs_fit_slope[NCHANNELS][3]
Definition: SC_PTC.C:65
const int NOYbins
Definition: SC_PTC.C:74
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_z_ns_fit_intercept_err[NCHANNELS][3]
Definition: SC_PTC.C:72
TCanvas * PT_can[30]
Double_t t_z_ns_fit_slope[NCHANNELS][3]
Definition: SC_PTC.C:69
int sss[NCHANNELS][NOXbins][NOYbins]
Definition: SC_PTC.C:75
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
TH2I * h2_bs
Definition: SC_PTC.C:44
Double_t ss_max[NCHANNELS]
Definition: SC_PTC.C:77