Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SetPrimaryPeaks.C
Go to the documentation of this file.
1 namespace ExtractTDCADCTimingNS {
2 TFile * thisFile;
3 
4 TH1I * Get1DHistogram(const char * plugin, const char * directoryName, const char * name, bool print = true){
5  TH1I * histogram;
6  TString fullName = TString(plugin) + "/" + TString(directoryName) + "/" + TString(name);
7  thisFile->GetObject(fullName, histogram);
8  if (histogram == 0){
9  if (print) cout << "Unable to find histogram " << fullName.Data() << endl;
10  return NULL;
11  }
12  return histogram;
13 }
14 
15 TH2I * Get2DHistogram(const char * plugin, const char * directoryName, const char * name){
16  TH2I * histogram;
17  TString fullName = TString(plugin) + "/" + TString(directoryName) + "/" + TString(name);
18  thisFile->GetObject(fullName, histogram);
19  if (histogram == 0){
20  cout << "Unable to find histogram " << fullName.Data() << endl;
21  return NULL;
22  }
23  return histogram;
24 }
25 };
26 
27 void GetCCDBConstants(TString path, Int_t run, TString variation, vector<double>& container, Int_t column = 1){
28  char command[256];
29  sprintf(command, "ccdb dump %s:%i:%s", path.Data(), run, variation.Data());
30  FILE* inputPipe = gSystem->OpenPipe(command, "r");
31  if(inputPipe == NULL)
32  return;
33  //get the first (comment) line
34  char buff[1024];
35  if(fgets(buff, sizeof(buff), inputPipe) == NULL)
36  return;
37  //get the remaining lines
38  double entry;
39  int counter = 0;
40  while(fgets(buff, sizeof(buff), inputPipe) != NULL){
41  istringstream locConstantsStream(buff);
42  while (locConstantsStream >> entry){
43  counter++;
44  if (counter % column == 0) container.push_back(entry);
45  }
46  }
47  //Close the pipe
48  gSystem->ClosePipe(inputPipe);
49 }
50 //Overload this function to handle the base time offsets
51 void GetCCDBConstants1(TString path, Int_t run, TString variation, double& constant1){
52  char command[256];
53  sprintf(command, "ccdb dump %s:%i:%s", path.Data(), run, variation.Data());
54  FILE* inputPipe = gSystem->OpenPipe(command, "r");
55  if(inputPipe == NULL)
56  return;
57  //get the first (comment) line
58  char buff[1024];
59  if(fgets(buff, sizeof(buff), inputPipe) == NULL)
60  return;
61  //get the line containing the values
62  while(fgets(buff, sizeof(buff), inputPipe) != NULL){
63  istringstream locConstantsStream(buff);
64  locConstantsStream >> constant1;
65  }
66  //Close the pipe
67  gSystem->ClosePipe(inputPipe);
68 }
69 
70 void GetCCDBConstants2(TString path, Int_t run, TString variation, double& constant1, double& constant2){
71  char command[256];
72  sprintf(command, "ccdb dump %s:%i:%s", path.Data(), run, variation.Data());
73  FILE* inputPipe = gSystem->OpenPipe(command, "r");
74  if(inputPipe == NULL)
75  return;
76  //get the first (comment) line
77  char buff[1024];
78  if(fgets(buff, sizeof(buff), inputPipe) == NULL)
79  return;
80  //get the line containing the values
81  while(fgets(buff, sizeof(buff), inputPipe) != NULL){
82  istringstream locConstantsStream(buff);
83  locConstantsStream >> constant1 >> constant2;
84  }
85  //Close the pipe
86  gSystem->ClosePipe(inputPipe);
87 }
88 
89 int GetCCDBIndexTAGM(int column, int row){
90  int CCDBIndex = column + row;
91  if (column > 9) CCDBIndex += 5;
92  if (column > 27) CCDBIndex += 5;
93  if (column > 81) CCDBIndex += 5;
94  if (column > 99) CCDBIndex += 5;
95 
96  return CCDBIndex;
97 }
98 
99 int GetF1TDCslotTAGH(int id) {
100  double N = 32.0; // channels per slot
101  if (id >= 132 && id <= 172) throw("TAGH: unknown id in [132,172]");
102  int HVid = (id <= 131) ? id : (id - 274 + 233);
103  return int((HVid-1)/N) + 1;
104 }
105 
106 Double_t FitFunctionLeft(Double_t *x, Double_t *par)
107 {
108  Float_t xx =x[0];
109  Double_t f = par[0]*TMath::Exp(-0.5 * (TMath::Power((xx - par[1]) / par[2] , 2) ) )+ par[0]*TMath::Exp(-0.5 * (TMath::Power((xx - par[1] - par[3]) / par[2] , 2) ) );
110  return f;
111 }
112 
113 Double_t FitFunctionRight(Double_t *x, Double_t *par)
114 {
115  Float_t xx =x[0];
116  Double_t f = par[0]*TMath::Exp(-0.5 * (TMath::Power((xx - par[1]) / par[2] , 2) ) )+ par[0]*TMath::Exp(-0.5 * (TMath::Power((xx - par[1] + par[3]) / par[2] , 2) ) );
117  return f;
118 }
119 
120 void SetPrimaryPeaks(TString fileName = "hd_root.root", int runNumber = 10390, TString variation = "default", TString prefix = ""){
121 
122  // set "prefix" in case you want to think about thowing the text files into another directory
123  cout << "Performing TDC/ADC timing fits for File: " << fileName.Data() << " Run: " << runNumber << " Variation: " << variation.Data() << endl;
124 
125  ExtractTDCADCTimingNS::thisFile = TFile::Open( fileName , "UPDATE");
127  cout << "Unable to open file " << fileName.Data() << "...Exiting" << endl;
128  return;
129  }
130  ofstream outFile;
131 
132  // If we've already aligned ADC's and TDC's, say from an earlier run,
133  // realign detectors using ADC/TDC matched hits to preserve the alignment
134  // otherwise, align them separately
135  bool AssumeADCTDCAlignment = true;
136 
137  //Setpoints - assume SC peak set to 0, may need to adjust in the future
138  double nominalFCALTime = 17.;
139  double nominalBCALADCTime = 15.;
140  double nominalBCALTDCTime = 15.;
141  double nominalSCTime = 0.;
142  double nominalTOFTime = 21.;
143  double nominalCDCTime = 6.;
144  double nominalFDCCathodeTime = 14.;
145  double nominalFDCWireTime = 5.5;
146  double nominalTAGHTime = -5.;
147  double nominalTAGMTime = -4.;
148 
149 
150  // We need to grab the existing values from the CCDB so that we know what was used in the creation of the ROOT file
151  cout << "Grabbing CCDB constants..." << endl;
152 
153  // First are the base times for all of the detectors
154  double cdc_base_time, fcal_base_time;
155  double sc_base_time_tdc, sc_base_time_adc;
156  double fdc_base_time_tdc, fdc_base_time_adc;
157  double bcal_base_time_tdc, bcal_base_time_adc;
158  double tagm_base_time_tdc, tagm_base_time_adc;
159  double tagh_base_time_tdc, tagh_base_time_adc;
160  double tof_base_time_tdc, tof_base_time_adc;
161 
162  double beam_period;
163 
164  GetCCDBConstants1("/CDC/base_time_offset" ,runNumber, variation, cdc_base_time);
165  GetCCDBConstants1("/FCAL/base_time_offset",runNumber, variation, fcal_base_time);
166  GetCCDBConstants1("/PHOTON_BEAM/RF/beam_period",runNumber, variation, beam_period);
167  GetCCDBConstants2("/FDC/base_time_offset" ,runNumber, variation, fdc_base_time_adc, fdc_base_time_tdc);
168  GetCCDBConstants2("/BCAL/base_time_offset" ,runNumber, variation, bcal_base_time_adc, bcal_base_time_tdc);
169  GetCCDBConstants2("/PHOTON_BEAM/microscope/base_time_offset" ,runNumber, variation, tagm_base_time_adc, tagm_base_time_tdc);
170  GetCCDBConstants2("/PHOTON_BEAM/hodoscope/base_time_offset" ,runNumber, variation, tagh_base_time_adc, tagh_base_time_tdc);
171  GetCCDBConstants2("/START_COUNTER/base_time_offset" ,runNumber, variation, sc_base_time_adc, sc_base_time_tdc);
172  GetCCDBConstants2("/TOF/base_time_offset" ,runNumber, variation, tof_base_time_adc, tof_base_time_tdc);
173 
174  cout << "CDC base times = " << cdc_base_time << endl;
175  cout << "FCAL base times = " << fcal_base_time << endl;
176  cout << "FDC base times = " << fdc_base_time_adc << ", " << fdc_base_time_tdc << endl;
177  cout << "BCAL base times = " << bcal_base_time_adc << ", " << bcal_base_time_tdc << endl;
178  cout << "SC base times = " << sc_base_time_adc << ", " << sc_base_time_tdc << endl;
179  cout << "TOF base times = " << tof_base_time_adc << ", " << tof_base_time_tdc << endl;
180  cout << "TAGH base times = " << tagh_base_time_adc << ", " << tagh_base_time_tdc << endl;
181  cout << "TAGM base times = " << tagm_base_time_adc << ", " << tagm_base_time_tdc << endl;
182 
183  cout << "beam_period = " << beam_period << endl;
184 
185  cout << "Done grabbing CCDB constants...Entering fits..." << endl;
186 
187  //Move the base times
188 
189  // CDC
190  float CDC_ADC_Offset = 0.0;
191  TH1I * this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "CDC", "CDCHit time");
192  if(this1DHist != NULL){
193  Int_t firstBin = this1DHist->FindLastBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
194  for (int i = 0; i <= 25; i++){
195  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
196  }
197  //Fit a gaussian to the left of the main peak
198  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
199  TF1 *f = new TF1("f", "gaus");
200  f->SetParameters(100, maximum, 20);
201  f->FixParameter(1 , maximum);
202  TFitResultPtr fr = this1DHist->Fit(f, "S", "", maximum - 20, maximum + 20); // Cant fix value at end of range
203  double mean = fr->Parameter(1);
204  float sigma = fr->Parameter(2);
205  CDC_ADC_Offset = mean - sigma;
206  delete f;
207  }
208 
209  outFile.open(prefix + "cdc_base_time.txt");
210  outFile << cdc_base_time - (CDC_ADC_Offset-nominalCDCTime) << endl;
211  outFile.close();
212 
213  // FDC
214  float FDC_ADC_Offset = 0.0, FDC_TDC_Offset = 0.0;
215  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "FDC", "FDCHit Cathode time");
216  if(this1DHist != NULL){
217  Int_t firstBin = this1DHist->FindFirstBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
218  for (int i = 0; i <= 30; i++){
219  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
220  }
221  //Fit a gaussian to the left of the main peak
222  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
223  TF1 *f = new TF1("f", "gaus");
224  f->SetParameters(100, maximum, 20);
225  f->FixParameter(1 , maximum);
226  TFitResultPtr fr = this1DHist->Fit(f, "S", "", maximum - 25, maximum + 20); // Cant fix value at end of range
227  double mean = fr->Parameter(1);
228  float sigma = fr->Parameter(2);
229  FDC_ADC_Offset = mean;
230  delete f;
231  }
232  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "FDC", "FDCHit Wire time");
233  if(this1DHist != NULL){
234  Int_t firstBin = this1DHist->FindLastBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
235  for (int i = 0; i <= 25; i++){
236  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
237  }
238  //Fit a gaussian to the left of the main peak
239  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
240  TF1 *f = new TF1("f", "gaus");
241  f->SetParameters(10000, maximum, 30);
242  //f->FixParameter(1 , maximum);
243  TFitResultPtr fr = this1DHist->Fit(f, "S", "", maximum - 18, maximum + 6); // Cant fix value at end of range
244  double mean = fr->Parameter(1);
245  float sigma = fr->Parameter(2);
246  FDC_TDC_Offset = mean;
247  delete f;
248  }
249 
250  outFile.open(prefix + "fdc_base_time.txt");
251  outFile << fdc_base_time_adc - (FDC_ADC_Offset-nominalFDCCathodeTime)
252  << " " << fdc_base_time_tdc - (FDC_TDC_Offset-nominalFDCWireTime) << endl;
253  outFile.close();
254 
255  // Now that we have the file open, do all of the fits and write the output
256  // Fit all plots with expected funtional form, output files for CCDB input
257  int minHits = 7;
258 
259  // In order to calibrate the SC in one step, we need to work with the base times and with the TDC/ADC offsets at the same time
260  // Sort of complicates things but saves considerable time.
261 
262  float SC_ADC_Offset = 0.0;
263  float SC_TDC_Offset = 0.0;
264  float TOF_ADC_Offset = 0.0;
265  float TOF_TDC_Offset = 0.0;
266  float FCAL_Offset = 0.0;
267  float BCAL_ADC_Offset = 0.0;
268  float BCAL_TDC_Offset = 0.0; // handle TDC's differently some day
269  float TAGH_ADC_Offset = 0.0;
270  float TAGH_TDC_Offset = 0.0;
271  float TAGM_ADC_Offset = 0.0;
272  float TAGM_TDC_Offset = 0.0;
273 
274  // FCAL
275  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "FCAL", "FCALHit time");
276  if(this1DHist != NULL){
277  //Gaussian
278  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
279  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 5, maximum + 5);
280  double mean = fr->Parameter(1);
281  FCAL_Offset = mean;
282  }
283  outFile.open(prefix + "fcal_base_time.txt");
284  outFile << fcal_base_time - (FCAL_Offset-nominalFCALTime) << endl;
285  outFile.close();
286 
287  // BCAL
288  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "BCAL", "BCALHit ADC time");
289  if(this1DHist != NULL){
290  //Gaussian
291  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
292  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 7, maximum + 7);
293  double mean = fr->Parameter(1);
294  BCAL_ADC_Offset = mean;
295  }
296  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "BCAL", "BCALHit TDC time");
297  if(this1DHist != NULL){
298  //Gaussian
299  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
300  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 7, maximum + 7);
301  double mean = fr->Parameter(1);
302  BCAL_TDC_Offset = mean;
303  }
304  outFile.open(prefix + "bcal_base_time.txt");
305  outFile << bcal_base_time_adc - (BCAL_ADC_Offset-nominalBCALADCTime)
306  << " " << bcal_base_time_tdc - (BCAL_TDC_Offset-nominalBCALTDCTime) << endl;
307  outFile.close();
308 
309  // SC, TOF, TAGH, TAGM
310  if(AssumeADCTDCAlignment) {
311  double SC_Offset = 0.;
312  double TOF_Offset = 0.;
313  double TAGM_Offset = 0.;
314  double TAGH_Offset = 0.;
315 
316  // START COUNTER
317  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "SC", "SCHit Matched time");
318  if(this1DHist != NULL){
319  //Gaussian
320  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
321  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 5, maximum + 5);
322  double mean = fr->Parameter(1);
323  SC_Offset = mean;
324  }
325  outFile.open(prefix + "sc_base_time.txt");
326  outFile << sc_base_time_adc - (SC_Offset-nominalSCTime)
327  << " " << sc_base_time_tdc - (SC_Offset-nominalSCTime) << endl;
328  outFile.close();
329 
330  // TOF
331  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TOF", "TOFHit Matched time");
332  if(this1DHist != NULL){
333  Int_t firstBin = this1DHist->FindFirstBinAbove(1 , 1); // Find first bin with content above 1 in the histogram
334  for (int i = 0; i <= 20; i++){
335  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
336  }
337  //Gaussian
338  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
339  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 4, maximum + 4);
340  double mean = fr->Parameter(1);
341  TOF_Offset = mean;
342  }
343  outFile.open(prefix + "tof_base_time.txt");
344  outFile << tof_base_time_adc - (TOF_Offset-nominalTOFTime)
345  << " " << tof_base_time_tdc - (TOF_Offset-nominalTOFTime) << endl;
346  outFile.close();
347 
348  // TAGH
349  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TAGH", "TAGHHit Matched time");
350  if(this1DHist != NULL){
351  //Gaussian
352  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
353  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 10, maximum + 10);
354  double mean = fr->Parameter(1);
355  TAGH_Offset = mean;
356  }
357  outFile.open(prefix + "tagh_base_time.txt");
358  outFile << tagh_base_time_adc - (TAGH_Offset-nominalTAGHTime)
359  << " " << tagh_base_time_tdc - (TAGH_Offset-nominalTAGHTime) << endl;
360  outFile.close();
361 
362  // TAGM
363  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TAGM", "TAGMHit Matched time");
364  if(this1DHist != NULL){
365  Int_t firstBin = this1DHist->FindFirstBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
366  for (int i = 0; i <= 100; i++){
367  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
368  }
369  //Gaussian
370  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
371  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 10, maximum + 8);
372  double mean = fr->Parameter(1);
373  TAGM_Offset = mean;
374  }
375  outFile.open(prefix + "tagm_base_time.txt");
376  outFile << tagm_base_time_adc - (TAGM_Offset-nominalTAGMTime)
377  << " " << tagm_base_time_tdc - (TAGM_Offset-nominalTAGMTime) << endl;
378  outFile.close();
379 
380  } else { // AssumeADCTDCAlign
381 
382  // START COUNTER
383  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "SC", "SCHit ADC time");
384  if(this1DHist != NULL){
385  //Gaussian
386  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
387  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 5, maximum + 5);
388  double mean = fr->Parameter(1);
389  SC_ADC_Offset = mean;
390  }
391  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "SC", "SCHit TDC time");
392  if(this1DHist != NULL){
393  //Gaussian
394  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
395  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 5, maximum + 5);
396  double mean = fr->Parameter(1);
397  SC_TDC_Offset = mean;
398  }
399  outFile.open(prefix + "sc_base_time.txt");
400  outFile << sc_base_time_adc - (SC_ADC_Offset-nominalSCTime)
401  << " " << sc_base_time_tdc - (SC_TDC_Offset-nominalSCTime) << endl;
402  outFile.close();
403 
404  // TOF
405  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TOF", "TOFHit ADC time");
406  if(this1DHist != NULL){
407  Int_t firstBin = this1DHist->FindFirstBinAbove(1 , 1); // Find first bin with content above 1 in the histogram
408  for (int i = 0; i <= 20; i++){
409  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
410  }
411  //Gaussian
412  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
413  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 4, maximum + 4);
414  double mean = fr->Parameter(1);
415  TOF_ADC_Offset = mean;
416  }
417  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TOF", "TOFHit TDC time");
418  if(this1DHist != NULL){
419  //Gaussian
420  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
421  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 4, maximum + 4);
422  double mean = fr->Parameter(1);
423  TOF_TDC_Offset = mean;
424  }
425  outFile.open(prefix + "tof_base_time.txt");
426  outFile << tof_base_time_adc - (TOF_ADC_Offset-nominalTOFTime)
427  << " " << tof_base_time_tdc - (TOF_TDC_Offset-nominalTOFTime) << endl;
428  outFile.close();
429 
430  // TAGH
431  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TAGH", "TAGHHit ADC time");
432  if(this1DHist != NULL){
433  //Gaussian
434  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
435  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 10, maximum + 10);
436  double mean = fr->Parameter(1);
437  TAGH_ADC_Offset = mean;
438  }
439  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TAGH", "TAGHHit TDC time");
440  if(this1DHist != NULL){
441  //Gaussian
442  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
443  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 10, maximum + 10);
444  double mean = fr->Parameter(1);
445  TAGH_TDC_Offset = mean;
446  }
447  outFile.open(prefix + "tagh_base_time.txt");
448  outFile << tagh_base_time_adc - (TAGH_ADC_Offset-nominalTAGHTime)
449  << " " << tagh_base_time_tdc - (TAGH_TDC_Offset-nominalTAGHTime) << endl;
450  outFile.close();
451 
452  // TAGM
453  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TAGM", "TAGMHit ADC time");
454  if(this1DHist != NULL){
455  Int_t firstBin = this1DHist->FindFirstBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
456  for (int i = 0; i <= 90; i++){
457  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
458  }
459  //Gaussian
460  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
461  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 10, maximum + 8);
462  double mean = fr->Parameter(1);
463  TAGM_ADC_Offset = mean;
464  }
465  this1DHist = ExtractTDCADCTimingNS::Get1DHistogram("HLDetectorTiming", "TAGM", "TAGMHit TDC time");
466  if(this1DHist != NULL){
467  Int_t firstBin = this1DHist->FindFirstBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
468  for (int i = 0; i <= 90; i++){
469  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
470  }
471  //Gaussian
472  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
473  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 10, maximum + 8);
474  double mean = fr->Parameter(1);
475  TAGM_TDC_Offset = mean;
476  }
477  outFile.open(prefix + "tagm_base_time.txt");
478  outFile << tagm_base_time_adc - (TAGM_ADC_Offset-nominalTAGMTime)
479  << " " << tagm_base_time_tdc - (TAGM_TDC_Offset-nominalTAGMTime) << endl;
480  outFile.close();
481 
482  }
483 
484 
486  return;
487  }
TFile * outFile
Definition: FitGains.C:15
Double_t x[NCHANNELS]
Definition: st_tw_resols.C:39
sprintf(text,"Post KinFit Cut")
Double_t FitFunctionLeft(Double_t *x, Double_t *par)
Double_t FitFunctionRight(Double_t *x, Double_t *par)
TF1 * f
Definition: FitGains.C:21
double counter
Definition: FitGains.C:151
TH1I * Get1DHistogram(const char *plugin, const char *directoryName, const char *name, bool print=true)
void GetCCDBConstants(TString path, Int_t run, TString variation, vector< double > &container, Int_t column=1)
TH2I * Get2DHistogram(const char *plugin, const char *directoryName, const char *name)
Double_t sigma[NCHANNELS]
Definition: st_tw_resols.C:37
void GetCCDBConstants2(TString path, Int_t run, TString variation, double &constant1, double &constant2)
void SetPrimaryPeaks(TString fileName="hd_root.root", int runNumber=10390, TString variation="default", TString prefix="")
void GetCCDBConstants1(TString path, Int_t run, TString variation, double &constant1)
int GetCCDBIndexTAGM(unsigned int column, unsigned int row)