Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
st_tw_resols.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 "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 <TGraph.h>
17 #include <TPaveLabel.h>
18 #include <TPaletteAxis.h>
19 #include <stdio.h>
20 #include <stdint.h>
21 #include <fstream>
22 
23 using namespace std;
24 using std::string;
25 // ***************** define constants and varibles*************************
26 const Int_t NCHANNELS = 30;
27 const Double_t tdc_thresh_mV = 50.0;
28 const Double_t tdc_gain_factor = 5.0;
29 const Double_t adc_max_chan = 4096.0;
30 const Double_t adc_max_mV = 2000.0;
37 Double_t sigma[NCHANNELS];
38 Double_t Err[NCHANNELS];
39 Double_t x[NCHANNELS];
40 Double_t ex[NCHANNELS];
41 //**** Declare fits *****************************
43 TGraph *gr[NCHANNELS];
44 // Declare canvas
45 TCanvas *TW_can[30];
46 TCanvas *Time_can;
47 Double_t fitf_pp(Double_t *x, Double_t *par)
48 {
49  Double_t fitval_pp = par[0] + par[1]*(TMath::Power(x[0]/adc_thresh_calc, par[2]));
50  return fitval_pp;
51 }
52 
53 void st_tw_resols(char const*input_filename)
54 
55 {
56  TFile *df = new TFile(input_filename);
57  std::ofstream Time_resol;
58  Time_resol.open ("SC_time_resol.txt", std::ofstream::out);
59 
60  //*****************************************************************
61  //*********** Grab the histograms from the root file **************
62  //*****************************************************************
63  for (unsigned int j = 0; j < 30; j++)
64  {
65  t_fit_chan[j] = new TF1(Form("t_fit_chan_%i", j+1), "gaus", -2.0,2.0);
66  //t_fit_chan[j] = new TF1(Form("t_fit_chan_%i", j), "[0]*exp(-0.5*((x-[1])/[2])**2)", -2.0,2.0);
67  t_fit_chan[j]->SetParameters(1000,0.,0.3);
68  x[j]=j+1;
69  ex[j]=0.0;
70  //Create the canvas
71  TW_can[j] = new TCanvas( Form("TW_can_%i",j+1), "TW_can", 800, 600);
72  TW_can[j]->Divide(2, 2);
73 
74  // Grab the histograms
75  char* stt = Form("h_stt_chan_%i",j+1);
76  TH1I* h_st = (TH1I*) df->Get(stt);
77  char* stt_corr = Form("h1_st_corr_time_%i",j+1);
78  TH1I* h_st_cr = (TH1I*) df->Get(stt_corr);
79  char* h2_st_corr_vs_pp = Form("h2_st_corr_vs_pp_%i",j+1);
80  TH2I* h2_st_cr_pp = (TH2I*) df->Get(h2_st_corr_vs_pp);
81 
82  //*****************************************************************
83  //*********** Plot 1D stt histos ******************
84  //*****************************************************************
85  TW_can[j]->cd(1);
86  gStyle->SetOptStat(10);
87  gStyle->SetErrorX(0);
88  gPad->SetTicks();
89  gPad->SetGrid();
90  h_st->Draw();
91  h_st->GetXaxis()->SetRangeUser(-2.,2.);
92  //*****************************************************************
93  //*********** Plot 1D histos for the Corrected stt ***************
94  //*****************************************************************
95  TW_can[j]->cd(2);
96  gStyle->SetOptStat(10);
97  gStyle->SetErrorX(0);
98  gPad->SetTicks();
99  gPad->SetGrid();
100  h_st_cr->Draw();
101  h_st_cr->GetXaxis()->SetRangeUser(-2.,2.);
102  h_st_cr->Fit(t_fit_chan[j]);
103  sigma[j] = t_fit_chan[j]->GetParameter(2);
104  Err[j] = t_fit_chan[j]->GetParError(2);
105  Time_resol << x[j] << "\t" <<sigma[j]*1000 << "\t" << ex[j] << "\t" << Err[j]*1000 << endl;
106 
107  //*****************************************************************
108  //*********** Plot 2D histos the Corrected stt vs pp *************
109  //*****************************************************************
110  TW_can[j]->cd(3);
111  gStyle->SetOptStat(10);
112  gStyle->SetErrorX(0);
113  gPad->SetTicks();
114  gPad->SetGrid();
115  h2_st_cr_pp->Draw("colz");
116  h2_st_cr_pp->GetXaxis()->SetRangeUser(120.,3500.);
117  h2_st_cr_pp->GetYaxis()->SetRangeUser(-2.0,2.0);
118  }
119  //*****************************************************************
120  //*********** Plot 1D histos of the time resolution *************
121  //*****************************************************************
122  Time_resol.close();
123  ifstream in;
124  in.open(Form("SC_time_resol.txt"));
125  float sector, t, es ,e;
126  TNtuple *ntuple = new TNtuple("ntuple","data from text file","sector:t:es:e");
127  ntuple->ReadFile("SC_time_resol.txt");
128  ntuple->Write();
129  in.close();
130  //Create the canvas
131  Time_can = new TCanvas( "Time_can", "Time_can", 800, 600);
132  Time_can->SetFillColor(41);
133  gStyle->SetOptFit(0111);
134  ntuple->Draw("sector:t:es:e");
135  TGraphErrors *gr=new TGraphErrors(ntuple->GetSelectedRows(),ntuple->GetV1(),ntuple->GetV2(),ntuple->GetV3(),ntuple->GetV4());
136  gr->Draw("AP");
137  gr->SetTitle("ST Self Time Resolution Vs Sector Number");
138  gr->GetXaxis()->SetTitle("Sector Number");
139  gr->GetYaxis()->SetTitle("ST Self Time Resolution (ps)");
140  gr->SetMarkerStyle(21);
141  gr->SetMarkerSize(3);
142  gr->SetMarkerColor(4);
143  gr->Fit("pol0");
144 
145 
146 }
147 
Double_t stt_fit_params[NCHANNELS][3]
Definition: st_tw_resols.C:35
TFile * df
Definition: ST_slices_eff.C:17
const Int_t NCHANNELS
Double_t stt_fit_params_err[NCHANNELS][3]
Definition: st_tw_resols.C:36
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
char string[256]
TGraph * gr[NCHANNELS]
Definition: st_tw_resols.C:43
Double_t Err[NCHANNELS]
Definition: st_tw_resols.C:38
const Double_t adc_max_mV
Definition: st_tw_fits.C:28
TF1 * t_fit_chan[NCHANNELS]
Definition: st_tw_resols.C:42
Double_t ex[NCHANNELS]
const Double_t adc_max_chan
Definition: st_tw_fits.C:27
Double_t sudo_mpv_chan[NCHANNELS]
Definition: st_tw_fits.C:30
TEllipse * e
void st_tw_resols(char const *input_filename)
Definition: st_tw_resols.C:53
Double_t sigma[NCHANNELS]
Definition: st_tw_resols.C:37
const Double_t adc_thresh_calc
Definition: st_tw_fits.C:29
TCanvas * TW_can[30]
Definition: st_tw_fits.C:36
Double_t t_pp_fit_params[NCHANNELS][3]
Definition: st_tw_fits.C:31
const Double_t tdc_thresh_mV
Definition: st_tw_fits.C:25
Double_t t_pp_fit_params_err[NCHANNELS][3]
Definition: st_tw_fits.C:32
Double_t fitf_pp(Double_t *x, Double_t *par)
const Double_t tdc_gain_factor
Definition: st_tw_fits.C:26
TCanvas * Time_can
Definition: st_tw_resols.C:46