Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
make_fmod_calibrations.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file make_fmod_calibrations.C
1 #include "SetOKStyle.C"
2 
3 TTree *tree;
4 const int nbins = 17;
5 float bins[nbins];
6 //organized as fmodeta, fmodphi
7 TH1F *resolutions3x3[nbins-1][nbins-1];
8 TF1 *fits3x3[nbins-1][nbins-1];
10 TH1F *resolutions5x5[nbins-1][nbins-1];
11 TF1 *fits5x5[nbins-1][nbins-1];
13 
15 {
16  for(int i=0; i<nbins; i++)
17  bins[i] = 0. + i * 2. / (float)(nbins-1);
18 
19 
20  gSystem->Load("libPrototype3.so");
21  gSystem->Load("libProto3ShowCalib.so");
22  SetOKStyle();
23  instantiate();
24  TFile *f =TFile::Open("allfmods.root");
25  tree = (TTree*)f->Get("T");
26 
27 
28  loop_tree();
29 
30  fit();
31 
32  write();
33 
35 
36 }
37 void instantiate(){
38 
39  ostringstream name;
40  for(int i=0; i<nbins-1; i++){
41  for(int j=0; j<nbins-1; j++){
42  name.str("");
43  name<<"response_3x3_fmodeta_"<<i<<"_fmodphi_"<<j;
44  resolutions3x3[i][j] = new TH1F(name.str().c_str(),"",
45  50,0.5,1.5);
46 
47  name.str("");
48  name<<"response_5x5_fmodeta_"<<i<<"_fmodphi_"<<j;
49  resolutions5x5[i][j] = new TH1F(name.str().c_str(),"",
50  50,0.5,1.5);
51  }
52  }
53 
54 }
55 void write()
56 {
57 
58  TFile *outfile = new TFile("fmodoutfile.root","recreate");
59  for(int i=0; i<nbins-1; i++){
60  for(int j=0; j<nbins-1; j++){
61  resolutions3x3[i][j]->Write();
62  resolutions5x5[i][j]->Write();
63  }
64  }
65 }
67 {
68 
69  ofstream file3x3;
70  file3x3.open("3x3clus_posdep_recals_fromsim.txt");
71 
72  //write them to the text file in eta bins as a function of phi
73  for(int i=0; i<nbins-1; i++){
74  for(int j=0; j<nbins-1; j++){
75  file3x3 << recal_consts3x3[i][j]<<" ";
76 
77  }
78  file3x3 << "\n";
79  }
80  file3x3.close();
81 
82 
83  ofstream file5x5;
84  file5x5.open("5x5clus_posdep_recals_fromsim.txt");
85 
86  for(int i=0; i<nbins-1; i++){
87  for(int j=0; j<nbins-1; j++){
88  file5x5 << recal_consts5x5[i][j] <<" ";
89  }
90  file5x5 << "\n";
91  }
92  file5x5.close();
93 
94 
95 
96 }
97 void fit()
98 {
99 
100  for(int i=0; i<nbins-1; i++){
101  for(int j=0; j<nbins-1; j++){
102  ostringstream name;
103  name.str("");
104  name<<"fit3x3_eta_"<<i<<"_phi_"<<j;
105  fits3x3[i][j] = new TF1(name.str().c_str(),"gaus",
106  resolutions3x3[i][j]->GetMean()
107  - 2. * resolutions3x3[i][j]->GetRMS(),
108  resolutions3x3[i][j]->GetMean()
109  + 2. * resolutions5x5[i][j]->GetRMS());
110 
111  name.str("");
112  name<<"fit5x5_eta_"<<i<<"_phi_"<<j;
113  fits5x5[i][j] = new TF1(name.str().c_str(),"gaus",
114  resolutions5x5[i][j]->GetMean()
115  - 2. * resolutions5x5[i][j]->GetRMS(),
116  resolutions5x5[i][j]->GetMean()
117  + 2. * resolutions5x5[i][j]->GetRMS());
118 
119 
120  resolutions3x3[i][j]->Fit(fits3x3[i][j],"nqr");
121  recal_consts3x3[i][j] = fits3x3[i][j]->GetParameter(1);
122 
123  resolutions5x5[i][j]->Fit(fits5x5[i][j],"nqr");
124  recal_consts5x5[i][j] = fits5x5[i][j]->GetParameter(1);
125 
126  if(recal_consts3x3[i][j]<0)
127  cout<<"3x3: "<<i<<"_"<<j<<endl;
128  if(recal_consts5x5[i][j]<0)
129  cout<<"5x5: "<<i<<"_"<<j<<endl;
130 
131 
132  }
133  }
134 
135 
136 
137 
138 
139 }
140 
141 void loop_tree()
142 {
143 
144 
145  Proto3ShowerCalib::Eval_Cluster *prod3x3, *prod5x5;
147  tree->SetBranchAddress("clus_3x3_prod",&prod3x3);
148  tree->SetBranchAddress("clus_5x5_prod",&prod5x5);
149  tree->SetBranchAddress("info",&run);
150 
151 
152  for(int i=0; i<tree->GetEntries(); i++){
153  tree->GetEntry(i);
154 
155  float beam_mom = run->getbeammom();
156 
157  float fmodphi3x3 = prod3x3->getfmodphi();
158  float fmodeta3x3 = prod3x3->getfmodeta();
159  float sume3x3 = prod3x3->getsumE();
160 
161  float fmodphi5x5 = prod5x5->getfmodphi();
162  float fmodeta5x5 = prod5x5->getfmodeta();
163  float sume5x5 = prod5x5->getsumE();
164 
165  int fmodphi3x3bin = -99;
166  int fmodeta3x3bin = -99;
167  int fmodphi5x5bin = -99;
168  int fmodeta5x5bin = -99;
169 
170  for(int j=0; j<nbins-1; j++)
171  if(fmodphi3x3>bins[j] && fmodphi3x3<=bins[j+1])
172  fmodphi3x3bin = j;
173  for(int j=0; j<nbins-1; j++)
174  if(fmodeta3x3>bins[j] && fmodeta3x3<=bins[j+1])
175  fmodeta3x3bin = j;
176  for(int j=0; j<nbins-1; j++)
177  if(fmodphi5x5>bins[j] && fmodphi5x5<=bins[j+1])
178  fmodphi5x5bin = j;
179  for(int j=0; j<nbins-1; j++)
180  if(fmodeta5x5>bins[j] && fmodeta5x5<=bins[j+1])
181  fmodeta5x5bin = j;
182 
183  if(fmodphi3x3bin>=0 && fmodeta3x3bin>=0){
184 
185  //fill 3x3 histos
186  resolutions3x3[fmodeta3x3bin][fmodphi3x3bin]->Fill(sume3x3
187  /beam_mom);
188  }
189  if(fmodphi5x5bin>=0 && fmodeta5x5bin>=0){
190 
191  //fill 5x5 histos
192  resolutions5x5[fmodeta5x5bin][fmodphi5x5bin]->Fill(sume5x5
193  /beam_mom);
194 
195  }
196 
197  }
198 
199 }
200 
201 
202 vector<double> GetBeamMom()
203 {
204 
205  vector<double> mom;
206 
207  TH1F * hbeam_mom = new TH1F("hbeam_mom", ";beam momentum (GeV)",
208  32,0.5,32.5);
209 
210  TText * t;
211  TCanvas *c1 = new TCanvas("GetBeamMom", "GetBeamMom", 1800, 900);
212 
213  tree->Draw("abs(info.beam_mom)>>hbeam_mom");
214 
215  for (int bin = 1; bin < hbeam_mom->GetNbinsX(); bin++)
216  {
217  if (hbeam_mom->GetBinContent(bin) > 40)
218  {
219  const double momentum = hbeam_mom->GetBinCenter(bin);
220 
221  if (momentum == 1 || momentum == 2 || momentum == 3 || momentum == 4
222  || momentum == 6 || momentum == 8 || momentum == 12
223  || momentum == 16 || momentum == 24 || momentum == 32)
224  {
225  mom.push_back(momentum);
226 
227  cout << "GetBeamMom - " << momentum << " GeV for "
228  << hbeam_mom->GetBinContent(bin) << " event" << endl;
229  }
230  }
231  }
232  return mom;
233 }