Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
z_point_pol2.C
Go to the documentation of this file.
1 
2 // macro that gets TGraphs from the ROOT file generated from the BCAL_point_calibs plugin and returns the effective velocities for each channel, using a quadratic fit
3 void z_point_pol2(TString fileName = "hd_root.root", int runNumber = 22016, TString variation = "default")
4 {
5  ofstream outfile("z_point_pol2.out");
6 
7  //gROOT->Reset();
8 
9  // change this to the location and name of your own ROOT file
10  TFile *in = TFile::Open( fileName , "READ");
11  if (in == 0) {
12  cout << "Unable to open file " << fileName.Data() << "...Exiting" << endl;
13  return;
14  }
15 
16  // function to hold the fit results
17  TF1* func2 = NULL;
18 
19  // graph for storing the graphs returned from the ROOT file
20  TGraph* h2_tgraph = NULL;
21 
22 
23  int channels = 768;
24 
25  // variables for saving the parameters of the fit
26  float eff_velocities_graphs = 0;
27  float eff_velocities_graphs_errors = 0;
28  float p2_graphs = 0;
29  float p1_graphs = 0;
30  float p2_graphs_error = 0;
31  float p1_graphs_error = 0;
32  char string[20];
33 
34  // loop over the channels, apply a quadratic fit for each one and calculate the effective velocities
35  for(int m = 0; m < channels; ++m){
36 
37  sprintf(string,"bcal_point_calibs/h2_tgraph_deltat[%d]", m+1);
38 
39  h2_tgraph = (TGraph*)in->Get(string);
40 
41  if(h2_tgraph->GetN() > 2){
42  // quadratic fit
43  h2_tgraph->Fit("pol2");
44  func2 = h2_tgraph->GetFunction("pol2");
45  //p2_graphs = func2->GetParameter(2);
46  //p2_graphs_error = func2->GetParError(2);
47  //p1_graphs = func2->GetParameter(1);
48  //p1_graphs_error = func2->GetParError(1);
49 
50  outfile << func2->GetParameter(0) << " " << func2->GetParameter(1) << " " << func2->GetParameter(2) << endl;
51  }
52 
53  //h2_tgraph->Delete();
54 
55  } // end of loop over channels
56 
57 
58  in->Close();
59  outfile.close();
60 }
sprintf(text,"Post KinFit Cut")
TFile * outfile
Definition: tw_corr.C:46
static TGraph * h2_tgraph[768]
void z_point_pol2(TString fileName="hd_root.root", int runNumber=22016, TString variation="default")
Definition: z_point_pol2.C:3