Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
monitoring/timing_online/FitScripts/AdjustTiming.C
Go to the documentation of this file.
1 namespace ExtractTrackBasedTimingNS {
2  TFile * thisFile;
3 
4  TH1I * Get1DHistogram(const char * plugin, const char * directoryName, const char * name){
5  TH1I * histogram;
6  TString fullName = TString(plugin) + "/" + TString(directoryName) + "/" + TString(name);
7  thisFile->GetObject(fullName, histogram);
8  if (histogram == 0){
9  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 
30  sprintf(command, "ccdb dump %s:%i:%s", path.Data(), run, variation.Data());
31  FILE* inputPipe = gSystem->OpenPipe(command, "r");
32  if(inputPipe == NULL)
33  return;
34  //get the first (comment) line
35  char buff[1024];
36  if(fgets(buff, sizeof(buff), inputPipe) == NULL)
37  return;
38  //get the remaining lines
39  double entry;
40  int counter = 0;
41  while(fgets(buff, sizeof(buff), inputPipe) != NULL){
42  istringstream locConstantsStream(buff);
43  while (locConstantsStream >> entry){
44  counter++;
45  if (counter % column == 0) container.push_back(entry);
46  }
47  }
48  //Close the pipe
49  gSystem->ClosePipe(inputPipe);
50 }
51 
52 //Overload this function to handle the base time offsets
53 void GetCCDBConstants1(TString path, Int_t run, TString variation, double& constant1){
54  char command[256];
55  sprintf(command, "ccdb dump %s:%i:%s", path.Data(), run, variation.Data());
56  FILE* inputPipe = gSystem->OpenPipe(command, "r");
57  if(inputPipe == NULL)
58  return;
59  //get the first (comment) line
60  char buff[1024];
61  if(fgets(buff, sizeof(buff), inputPipe) == NULL)
62  return;
63  //get the line containing the values
64  while(fgets(buff, sizeof(buff), inputPipe) != NULL){
65  istringstream locConstantsStream(buff);
66  locConstantsStream >> constant1;
67  }
68  //Close the pipe
69  gSystem->ClosePipe(inputPipe);
70 }
71 
72 void GetCCDBConstants2(TString path, Int_t run, TString variation, double& constant1, double& constant2){
73  char command[256];
74  sprintf(command, "ccdb dump %s:%i:%s", path.Data(), run, variation.Data());
75  FILE* inputPipe = gSystem->OpenPipe(command, "r");
76  if(inputPipe == NULL)
77  return;
78  //get the first (comment) line
79  char buff[1024];
80  if(fgets(buff, sizeof(buff), inputPipe) == NULL)
81  return;
82  //get the line containing the values
83  while(fgets(buff, sizeof(buff), inputPipe) != NULL){
84  istringstream locConstantsStream(buff);
85  locConstantsStream >> constant1 >> constant2;
86  }
87  //Close the pipe
88  gSystem->ClosePipe(inputPipe);
89 }
90 
91 int GetCCDBIndexTAGM(unsigned int column, unsigned int row){
92  int CCDBIndex = column + row;
93  if (column > 9) CCDBIndex += 5;
94  if (column > 27) CCDBIndex += 5;
95  if (column > 81) CCDBIndex += 5;
96  if (column > 99) CCDBIndex += 5;
97 
98  return CCDBIndex;
99 }
100 
101 int GetF1TDCslotTAGH(int id) {
102  double N = 32.0; // channels per slot
103  if (id >= 132 && id <= 172) throw("TAGH: unknown id in [132,172]");
104  int HVid = (id <= 131) ? id : (id - 274 + 233);
105  return int((HVid-1)/N) + 1;
106 }
107 
108 void FindFDCPackageChamber(int plane, int &package, int &chamber) {
109  package = plane / 6 + 1;
110  chamber = plane % 6;
111  if(chamber == 0) chamber = 6;
112 }
113 
114 void AdjustTiming(TString fileName = "hd_root.root", int runNumber = 10390, TString variation = "default", bool verbose = false,TString prefix = ""){
115  // configuration parameters
116  bool FIX_START_COUNTER = false; // should we keep the start counter peak aligned to a certain time?
117  // this helps in certain analysis without tracks
118  double start_counter_t0 = 0.; // time we should move the start counter time peak to
119 
120  // set "prefix" in case you want to ship the txt files elsewhere...
121  cout << "Performing adjustment timing fits for File: " << fileName.Data() << " Run: " << runNumber << " Variation: " << variation.Data() << endl;
122 
123  ExtractTrackBasedTimingNS::thisFile = TFile::Open( fileName , "UPDATE");
125  cout << "Unable to open file " << fileName.Data() << "...Exiting" << endl;
126  return;
127  }
128 
129  //We need the existing constants, The best we can do here is just read them from the file.
130  vector<double> sc_tdc_time_offsets;
131  vector<double> sc_fadc_time_offsets;
132  vector<double> tof_tdc_time_offsets;
133  vector<double> tof_fadc_time_offsets;
134  vector<double> tagm_tdc_time_offsets;
135  vector<double> tagm_fadc_time_offsets;
136  vector<double> tagh_tdc_time_offsets;
137  vector<double> tagh_fadc_time_offsets;
138  vector<double> tagh_counter_quality;
139 
140  double sc_t_base_fadc, sc_t_base_tdc;
141  double tof_t_base_fadc, tof_t_base_tdc;
142  double bcal_t_base_fadc, bcal_t_base_tdc;
143  double tagm_t_base_fadc, tagm_t_base_tdc;
144  double tagh_t_base_fadc, tagh_t_base_tdc;
145  double fdc_t_base_fadc, fdc_t_base_tdc;
146  double fcal_t_base;
147  double cdc_t_base;
148  double RF_Period;
149 
150  cout << "Grabbing CCDB constants..." << endl;
151  // Base times
152  GetCCDBConstants1("/CDC/base_time_offset" ,runNumber, variation, cdc_t_base);
153  GetCCDBConstants1("/FCAL/base_time_offset",runNumber, variation, fcal_t_base);
154  GetCCDBConstants1("/PHOTON_BEAM/RF/beam_period",runNumber, variation, RF_Period);
155  GetCCDBConstants2("/FDC/base_time_offset" ,runNumber, variation, fdc_t_base_fadc, fdc_t_base_tdc);
156  GetCCDBConstants2("/BCAL/base_time_offset" ,runNumber, variation, bcal_t_base_fadc, bcal_t_base_tdc);
157  GetCCDBConstants2("/PHOTON_BEAM/microscope/base_time_offset" ,runNumber, variation, tagm_t_base_fadc, tagm_t_base_tdc);
158  GetCCDBConstants2("/PHOTON_BEAM/hodoscope/base_time_offset" ,runNumber, variation, tagh_t_base_fadc, tagh_t_base_tdc);
159  GetCCDBConstants2("/START_COUNTER/base_time_offset" ,runNumber, variation, sc_t_base_fadc, sc_t_base_tdc);
160  GetCCDBConstants2("/TOF/base_time_offset" ,runNumber, variation, tof_t_base_fadc, tof_t_base_tdc);
161  // Per channel
162  //GetCCDBConstants("/BCAL/TDC_offsets" ,runNumber, variation, bcal_tdc_offsets);
163  //GetCCDBConstants("/FCAL/timing_offsets" ,runNumber, variation, fcal_adc_offsets);
164  GetCCDBConstants("/START_COUNTER/adc_timing_offsets" ,runNumber, variation, sc_fadc_time_offsets);
165  GetCCDBConstants("/START_COUNTER/tdc_timing_offsets" ,runNumber, variation, sc_tdc_time_offsets);
166  GetCCDBConstants("/PHOTON_BEAM/microscope/fadc_time_offsets" ,runNumber, variation, tagm_fadc_time_offsets,3);// Interested in 3rd column
167  GetCCDBConstants("/PHOTON_BEAM/microscope/tdc_time_offsets" ,runNumber, variation, tagm_tdc_time_offsets,3);
168  GetCCDBConstants("/PHOTON_BEAM/hodoscope/fadc_time_offsets" ,runNumber, variation, tagh_fadc_time_offsets,2);// Interested in 2nd column
169  GetCCDBConstants("/PHOTON_BEAM/hodoscope/tdc_time_offsets" ,runNumber, variation, tagh_tdc_time_offsets,2);
170  GetCCDBConstants("/PHOTON_BEAM/hodoscope/counter_quality" ,runNumber, variation, tagh_counter_quality,2);
171  GetCCDBConstants("/TOF/adc_timing_offsets",runNumber, variation, tof_fadc_time_offsets);
172  GetCCDBConstants("/TOF/timing_offsets",runNumber, variation, tof_tdc_time_offsets);
173 
174  cout << "CDC base times = " << cdc_t_base << endl;
175  cout << "FCAL base times = " << fcal_t_base << endl;
176  cout << "FDC base times = " << fdc_t_base_fadc << ", " << fdc_t_base_tdc << endl;
177  cout << "BCAL base times = " << bcal_t_base_fadc << ", " << bcal_t_base_tdc << endl;
178  cout << "SC base times = " << sc_t_base_fadc << ", " << sc_t_base_tdc << endl;
179  cout << "TOF base times = " << tof_t_base_fadc << ", " << tof_t_base_tdc << endl;
180  cout << "TAGH base times = " << tagh_t_base_fadc << ", " << tagh_t_base_tdc << endl;
181  cout << "TAGM base times = " << tagm_t_base_fadc << ", " << tagm_t_base_tdc << endl;
182 
183  cout << endl;
184  cout << "RF_Period = " << RF_Period << endl;
185  cout << endl;
186 
187  cout << "Done grabbing CCDB constants...Entering fits..." << endl;
188 
189  // Assume our alignment is okay, and mainly we need to either correct for some overall timing shifts
190  // or per-channel shifts due to some firmware timing "features". These include:
191  // - 2 ns shifts of RF time
192  // - 32 ns shifts of high-res TDC modules
193  // - 4 ns shifts of fADC250 channels
194  // - FDC TDC crate shifts
195  // Note that BCAL/FCAL 4ns shifts are handled with different plugins
196 
197  //When the RF is present we can try to simply pick out the correct beam bucket for each of the runs
198  //First just a simple check to see if we have the appropriate data
199  bool useRF = false;
200  TH1I *testHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "TAGH_TDC_RF_Compare","Counter ID 001");
201  if (testHist != NULL){ // Not great since we rely on channel 1 working, but can be craftier later.
202  cout << "Using RF Times for Calibration" << endl;
203  useRF = true;
204  }
205  ofstream outFile;
206  TH2I *thisHist;
207  thisHist = ExtractTrackBasedTimingNS::Get2DHistogram("HLDetectorTiming", "TRACKING", "TAGM - SC Target Time");
208 
209  /** DISABLE this - microscope calibrations are mostly handled in TAGM_TW. just need to align the main peak
210  if (useRF) thisHist = ExtractTrackBasedTimingNS::Get2DHistogram("HLDetectorTiming", "TRACKING", "TAGM - RFBunch Time");
211  if (thisHist != NULL){
212  //Statistics on these histograms are really quite low we will have to rebin and do some interpolation
213  outFile.open(prefix + "tagm_tdc_timing_offsets.txt", ios::out | ios::trunc);
214  outFile.close(); // clear file
215  outFile.open(prefix + "tagm_adc_timing_offsets.txt", ios::out | ios::trunc);
216  outFile.close(); // clear file
217  int nBinsX = thisHist->GetNbinsX();
218  int nBinsY = thisHist->GetNbinsY();
219  TH1D * selectedTAGMOffset = new TH1D("selectedTAGMOffset", "Selected TAGM Offset; Column; Offset [ns]", nBinsX, 0.5, nBinsX + 0.5);
220  TH1I * TAGMOffsetDistribution = new TH1I("TAGMOffsetDistribution", "TAGM Offset; TAGM Offset [ns]; Entries", 500, -250, 250);
221  for (int i = 1 ; i <= nBinsX; i++){
222  TH1D *projY = thisHist->ProjectionY("temp", i, i);
223  // Scan over the histogram
224  //chose the correct number of bins based on the histogram
225  float nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
226  float timeWindow = 3; //ns (Full Width)
227  int binWindow = int(timeWindow / nsPerBin);
228  double maxEntries = 0;
229  double maxMean = 0;
230  for (int j = 1 ; j <= projY->GetNbinsX();j++){
231  int minBin = j;
232  int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
233  double sum = 0, nEntries = 0;
234  for (int bin = minBin; bin <= maxBin; bin++){
235  sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
236  nEntries += projY->GetBinContent(bin);
237  if (bin == maxBin){
238  if (nEntries > maxEntries) {
239  maxMean = sum / nEntries;
240  maxEntries = nEntries;
241  }
242  }
243  }
244  }
245  //In the case there is RF, our job is to pick just the number of the correct beam bunch, so that's really all we need.
246  if(useRF) {
247  int beamBucket = int((maxMean / RF_Period) + 0.5); // +0.5 to handle rounding correctly
248  selectedTAGMOffset->SetBinContent(i, beamBucket);
249  TAGMOffsetDistribution->Fill(beamBucket);
250  }
251  else{
252  selectedTAGMOffset->SetBinContent(i, maxMean);
253  TAGMOffsetDistribution->Fill(maxMean);
254  }
255  }
256  double meanOffset = TAGMOffsetDistribution->GetMean();
257  // This might be in units of beam bunches, so we need to convert
258  if (useRF) meanOffset *= RF_Period;
259  if (verbose) {
260  cout << "Dumping TAGM results...\n=======================================" << endl;
261  cout << "TAGM mean Offset = " << meanOffset << endl;
262  cout << "fADC Offsets" << endl;
263  }
264 
265  outFile.open(prefix + "tagm_adc_timing_offsets.txt", ios::out);
266  //for (int i = 1 ; i <= nBinsX; i++){
267  // Loop over rows
268  if (verbose) cout << "Column\tRow\tvalueToUse\toldValue\tmeanOffset\tTotal" << endl;
269  for (unsigned int column = 1; column <= 102; column++){
270  int index = GetCCDBIndexTAGM(column, 0);
271  double valueToUse = selectedTAGMOffset->GetBinContent(index);
272  if (useRF) valueToUse *= RF_Period;
273 
274  //if (valueToUse == 0) valueToUse = meanOffset;
275  outFile << "0 " << column << " " << valueToUse + tagm_fadc_time_offsets[index-1] - meanOffset<< endl;
276  if (verbose) printf("0\t%i\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n", column, valueToUse, tagm_fadc_time_offsets[index-1], meanOffset,
277  valueToUse + tagm_fadc_time_offsets[index-1] - meanOffset);
278  if (column == 9 || column == 27 || column == 81 || column == 99){
279  for (unsigned int row = 1; row <= 5; row++){
280  index = GetCCDBIndexTAGM(column, row);
281  valueToUse = selectedTAGMOffset->GetBinContent(index);
282  if (useRF) valueToUse *= RF_Period;
283  //if (valueToUse == 0) valueToUse = meanOffset;
284  outFile << row << " " << column << " " << valueToUse + tagm_fadc_time_offsets[index-1] - meanOffset<< endl;
285  if (verbose) printf("%i\t%i\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n", row, column, valueToUse, tagm_fadc_time_offsets[index-1], meanOffset,
286  valueToUse + tagm_fadc_time_offsets[index-1] - meanOffset);
287  }
288  }
289  }
290  outFile.close();
291 
292  if (verbose) {
293  cout << "TDC Offsets" << endl;
294  cout << "Column\tRow\tvalueToUse\toldValue\tmeanOffset\tTotal" << endl;
295  }
296  outFile.open(prefix + "tagm_tdc_timing_offsets.txt", ios::out);
297  //for (int i = 1 ; i <= nBinsX; i++){
298  // Loop over rows
299  for (unsigned int column = 1; column <= 102; column++){
300  int index = GetCCDBIndexTAGM(column, 0);
301  double valueToUse = selectedTAGMOffset->GetBinContent(index);
302  if (useRF) valueToUse *= RF_Period;
303  //if (valueToUse == 0) valueToUse = meanOffset;
304  outFile << "0 " << column << " " << valueToUse + tagm_tdc_time_offsets[index-1] - meanOffset << endl;
305  if (verbose) printf("0\t%i\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n", column, valueToUse, tagm_tdc_time_offsets[index-1], meanOffset,
306  valueToUse + tagm_tdc_time_offsets[index-1] - meanOffset);
307  if (column == 9 || column == 27 || column == 81 || column == 99){
308  for (unsigned int row = 1; row <= 5; row++){
309  index = GetCCDBIndexTAGM(column, row);
310  valueToUse = selectedTAGMOffset->GetBinContent(index);
311  if (useRF) valueToUse *= RF_Period;
312  //if (valueToUse == 0) valueToUse = meanOffset;
313  outFile << row << " " << column << " " << valueToUse + tagm_tdc_time_offsets[index-1] - meanOffset << endl;
314  if (verbose) printf("%i\t%i\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n", row, column, valueToUse, tagm_tdc_time_offsets[index-1], meanOffset,
315  valueToUse + tagm_tdc_time_offsets[index-1] - meanOffset);
316  }
317  }
318  }
319  outFile.close();
320  outFile.open(prefix + "tagm_base_time.txt", ios::out);
321  if (verbose) {
322  printf("TAGM ADC Base = %f - (%f) = %f\n", tagm_t_base_fadc, meanOffset, tagm_t_base_fadc - meanOffset);
323  printf("TAGM TDC Base = %f - (%f) = %f\n", tagm_t_base_tdc, meanOffset, tagm_t_base_tdc - meanOffset);
324  }
325  outFile << tagm_t_base_fadc - meanOffset << " " << tagm_t_base_tdc - meanOffset << endl;
326  outFile.close();
327 
328  }
329  **/
330 
331  TH1I *tagmRFalignHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "TRACKING", "TAGM - RFBunch 1D Time");
332  if(tagmRFalignHist != NULL) {
333  double maximum = tagmRFalignHist->GetBinCenter(tagmRFalignHist->GetMaximumBin());
334  TFitResultPtr fr = tagmRFalignHist->Fit("gaus", "SQ", "", maximum - 0.3, maximum + 0.3);
335  double meanOffset = fr->Parameter(1);
336 
337  outFile.open(prefix + "tagm_base_time.txt", ios::out);
338  if (verbose) {
339  printf("TAGM ADC Base = %f - (%f) = %f\n", tagm_t_base_fadc, meanOffset, tagm_t_base_fadc - meanOffset);
340  printf("TAGM TDC Base = %f - (%f) = %f\n", tagm_t_base_tdc, meanOffset, tagm_t_base_tdc - meanOffset);
341  }
342  outFile << tagm_t_base_fadc - meanOffset << " " << tagm_t_base_tdc - meanOffset << endl;
343  outFile.close();
344  }
345 
346  thisHist = ExtractTrackBasedTimingNS::Get2DHistogram("HLDetectorTiming", "TRACKING", "TAGH - SC Target Time");
347  if (useRF) thisHist = ExtractTrackBasedTimingNS::Get2DHistogram("HLDetectorTiming", "TRACKING", "TAGH - RFBunch Time");
348  if (thisHist != NULL) {
349  outFile.open(prefix + "tagh_tdc_timing_offsets.txt", ios::out | ios::trunc);
350  outFile.close(); // clear file
351  outFile.open(prefix + "tagh_adc_timing_offsets.txt", ios::out | ios::trunc);
352  outFile.close(); // clear file
353 
354 
355  // Also realign ADCs and TDCs
356  // assuming anything larger than 28 ns is due to a TDC shift, otherwise the ADCs are shifted
357  TH2I *taghADCTDCHist = ExtractTrackBasedTimingNS::Get2DHistogram("HLDetectorTiming", "TAGH", "TAGHHit TDC_ADC Difference");
358  int nBinsX = thisHist->GetNbinsX();
359  double taghAdcOffsets[274] = { 0. };
360  double taghTdcOffsets[274] = { 0. };
361 
362  //TH1D * selectedTAGHOffset = new TH1D("selectedTAGHOffset", "Selected TAGH Offset; Column; Offset [ns]", nBinsX, 0.5, nBinsX + 0.5);
363  for (int i = 1 ; i <= nBinsX; i++) {
364  TH1D *projY = taghADCTDCHist->ProjectionY("temp", i, i);
365  // Scan over histogram to find mean offset in timeWindow with largest integral
366  double nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
367  double timeWindow = 2.0; //ns (Full Width)
368  int binWindow = int(timeWindow / nsPerBin);
369  double maxEntries = 0;
370  double maxMean = 0;
371  for (int j = 1 ; j <= projY->GetNbinsX();j++) {
372  int minBin = j;
373  int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
374  double sum = 0, nEntries = 0;
375  for (int bin = minBin; bin <= maxBin; bin++) {
376  sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
377  nEntries += projY->GetBinContent(bin);
378  if (bin == maxBin) {
379  if (nEntries > maxEntries) {
380  maxMean = sum / nEntries;
381  maxEntries = nEntries;
382  }
383  }
384  }
385  }
386  //selectedTAGHOffset->SetBinContent(i, maxMean);
387 
388  // classify offset
389  if(fabs(maxMean) > 1.5) { // only correct shifts more than 1.5 ns, to avoid specious shifts
390  if(fabs(maxMean) > 28.)
391  taghTdcOffsets[i-1] = maxMean;
392  else
393  taghAdcOffsets[i-1] = maxMean;
394  }
395  }
396 
397  // Setup histogram for determining the most probable change in offset for each F1TDC slot
398  // This is needed to account for the occasional uniform shift in offsets of the 32 counters in a slot
399  // Disable this for now, it hasn't been working well...
400  //const int NtdcSlots = 8;
401  //TH1I * tdcDist[NtdcSlots];
402  //for (int i = 1; i <= NtdcSlots; i++) {
403  // stringstream ss; ss << i;
404  // TString s = ss.str();
405  // double range = 500.0; double width = 0.1;
406  // int Nbins = range/width;
407  // double low = -0.5*range - 0.5*width;
408  // double high = 0.5*range - 0.5*width;
409  // tdcDist[i-1] = new TH1I("TAGHOffsetDistribution_"+s, "TAGH Offset (slot "+s+"); TAGH Offset [ns]; Entries", Nbins, low, high);
410  // }
411 
412  //int nBinsX = thisHist->GetNbinsX();
413  TH1D * selectedTAGHOffset = new TH1D("selectedTAGHOffset", "Selected TAGH Offset; ID; Offset [ns]", nBinsX, 0.5, nBinsX + 0.5);
414  for (int i = 1 ; i <= nBinsX; i++) {
415  TH1D *projY = thisHist->ProjectionY("temp", i, i);
416  // Scan over histogram to find mean offset in timeWindow with largest integral
417  // Choose the correct number of bins based on the histogram
418  double nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
419  double timeWindow = 2.0; // ns (Full Width)
420  int binWindow = int(timeWindow / nsPerBin);
421 
422  double maxEntries = 0;
423  double maxMean = 0;
424  for (int j = 1; j <= projY->GetNbinsX(); j++) {
425  int minBin = j;
426  int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
427  double sum = 0;
428  double nEntries = 0;
429  for (int bin = minBin; bin <= maxBin; bin++) {
430  sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
431  nEntries += projY->GetBinContent(bin);
432  if (bin == maxBin) {
433  if (nEntries > maxEntries) {
434  maxMean = sum / nEntries;
435  maxEntries = nEntries;
436  }
437  }
438  }
439  }
440 
441  if (tagh_counter_quality[i-1] == 0.0) {
442  selectedTAGHOffset->SetBinContent(i, 0);
443  continue;
444  }
445  //int tdc_slot = GetF1TDCslotTAGH(i);
446  // if the shift is too large, it's probably due to a TDC module shifting, so ignore that
447  if(fabs(maxMean) > 28.)
448  maxMean = 0.;
449  if (useRF) {
450  int beamBucket;
451  if (maxMean >= 0) beamBucket = int((maxMean / RF_Period) + 0.5); // +0.5 to handle rounding correctly
452  else beamBucket = int((maxMean / RF_Period) - 0.5);
453  selectedTAGHOffset->SetBinContent(i, beamBucket);
454  //if (maxEntries != 0.0) tdcDist[tdc_slot - 1]->Fill(beamBucket);
455  } else {
456  selectedTAGHOffset->SetBinContent(i, maxMean);
457  //if (maxEntries != 0.0) tdcDist[tdc_slot - 1]->Fill(maxMean);
458  }
459  }
460  // Most probable change in offset or beam bucket per F1TDC slot
461  //double mpDelta[NtdcSlots];
462  //for (int i = 1; i <= NtdcSlots; i++) {
463  // int mpBin = tdcDist[i-1]->GetMaximumBin();
464  // mpDelta[i-1] = (mpBin > 0) ? tdcDist[i-1]->GetBinCenter(mpBin) : 0.0;
465  // if (useRF) mpDelta[i-1] *= RF_Period;
466  // if (verbose) {
467  // cout << "TAGH most probable Offset = " << i << ", " << mpDelta[i-1] << endl;
468  // }
469  // }
470 
471  if (verbose) {
472  cout << "Dumping TAGH results...\n=======================================" << endl;
473  //cout << "Type\tChannel\tvalueToUse\toldValue\tmpDelta\tTotal" << endl;
474  cout << "Type\tChannel\tvalueToUse\toldValue\tTotal" << endl;
475  }
476 
477  double limit = 2.5; // ns
478  double ccdb_sum = 0.0;
479  for (int i = 1; i <= nBinsX; i++) ccdb_sum += tagh_tdc_time_offsets[i-1];
480  double c1_tdcOffset = 0.0;
481  outFile.open(prefix + "tagh_tdc_timing_offsets.txt");
482  for (int i = 1; i <= nBinsX; i++) {
483  if (tagh_counter_quality[i-1] == 0.0) {
484  outFile << i << " " << 0 << endl;
485  continue;
486  }
487  //int tdc_slot = GetF1TDCslotTAGH(i);
488  double delta = selectedTAGHOffset->GetBinContent(i);
489  if (useRF) delta *= RF_Period;
490  //if (ccdb_sum > 0.0 && fabs(delta - mpDelta[tdc_slot-1]) > limit) {
491  // delta = mpDelta[tdc_slot-1];
492  // }
493  double ccdb = tagh_tdc_time_offsets[i-1];
494  double offset = ccdb + delta - taghTdcOffsets[i-1];
495  if (i == 1) c1_tdcOffset = offset;
496  offset -= c1_tdcOffset;
497  outFile << i << " " << offset << endl;
498  //if (verbose) printf("TDC\t%i\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n", i, delta, ccdb, mpDelta[tdc_slot-1], offset);
499  if (verbose) printf("TDC\t%i\t%.3f\t\t%.3f\t\t%.3f\n", i, delta, ccdb, offset);
500  }
501  outFile.close();
502 
503  ccdb_sum = 0.0;
504  for (int i = 1; i <= nBinsX; i++) ccdb_sum += tagh_fadc_time_offsets[i-1];
505  double c1_adcOffset = 0.0;
506  outFile.open(prefix + "tagh_adc_timing_offsets.txt");
507  for (int i = 1; i <= nBinsX; i++) {
508  if (tagh_counter_quality[i-1] == 0.0) {
509  outFile << i << " " << 0 << endl;
510  continue;
511  }
512  //int tdc_slot = GetF1TDCslotTAGH(i);
513  double delta = selectedTAGHOffset->GetBinContent(i);
514  if (useRF) delta *= RF_Period;
515  //if (ccdb_sum > 0.0 && fabs(delta - mpDelta[tdc_slot-1]) > limit) {
516  // delta = mpDelta[tdc_slot-1];
517  // }
518  double ccdb = tagh_fadc_time_offsets[i-1];
519  double offset = ccdb + delta - taghAdcOffsets[i-1];
520  if (i == 1) c1_adcOffset = offset;
521  offset -= c1_adcOffset;
522  outFile << i << " " << offset << endl;
523  //if (verbose) printf("ADC\t%i\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n", i, delta, ccdb, mpDelta[tdc_slot-1], offset);
524  if (verbose) printf("ADC\t%i\t%.3f\t\t%.3f\t\t%.3f\n", i, delta, ccdb, offset);
525  }
526  outFile.close();
527 
528  outFile.open(prefix + "tagh_base_time.txt");
529  outFile << tagh_t_base_fadc - c1_adcOffset << " " << tagh_t_base_tdc - c1_tdcOffset << endl;
530  if (verbose) {
531  printf("TAGH ADC Base = %f - (%f) = %f\n", tagh_t_base_fadc, c1_adcOffset, tagh_t_base_fadc - c1_adcOffset);
532  printf("TAGH TDC Base = %f - (%f) = %f\n", tagh_t_base_tdc, c1_tdcOffset, tagh_t_base_tdc - c1_tdcOffset);
533  }
534  outFile.close();
535  }
536 
537  // We can use the RF time to calibrate the SC time
538  double meanSCOffset = 0.0; // In case we change the time of the SC, we need this in this scope
539  if(useRF){
540  TH1F * selectedSCSectorOffset = new TH1F("selectedSCSectorOffset", "Selected TDC-RF offset;Sector; Time", 30, 0.5, 30.5);
541  TH1F * selectedSCSectorOffsetDistribution = new TH1F("selectedSCSectorOffsetDistribution", "Selected TDC-RF offset;Time;Entries", 100, -3.0, 3.0);
542  TF1* f = new TF1("f","pol0(0)+gaus(1)", -3.0, 3.0);
543 
544  // Also realign ADCs and TDCs
545  // assuming anything larger than 28 ns is due to a TDC shift, otherwise the ADCs are shifted
546  double scAdcOffsets[30] = { 0. };
547  double scTdcOffsets[30] = { 0. };
548  TH2I *scADCTDCHist = ExtractTrackBasedTimingNS::Get2DHistogram("HLDetectorTiming", "SC", "SCHit TDC_ADC Difference");
549 
550  for (int sector = 1; sector <= 30; sector++){
551  // first realign ADCs and TDCs
552  TH1D *projY = scADCTDCHist->ProjectionY("temp", sector, sector);
553  float nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
554  float timeWindow = 2; //ns (Full Width)
555  int binWindow = int(timeWindow / nsPerBin);
556  double maxEntries = 0;
557  double maxMean = 0;
558  for (int j = 1 ; j <= projY->GetNbinsX();j++){
559  int minBin = j;
560  int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
561  double sum = 0, nEntries = 0;
562  for (int bin = minBin; bin <= maxBin; bin++){
563  sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
564  nEntries += projY->GetBinContent(bin);
565  if (bin == maxBin){
566  if (nEntries > maxEntries) {
567  maxMean = sum / nEntries;
568  maxEntries = nEntries;
569  }
570  }
571  }
572  }
573 
574  // classify offset
575  if(fabs(maxMean) > 1.5) { // only correct shifts more than 1.5 ns, to avoid specious shifts
576  if(fabs(maxMean) > 28.)
577  scTdcOffsets[sector-1] = maxMean;
578  else
579  scAdcOffsets[sector-1] = maxMean;
580  }
581 
582  // now align RF times
583  TH1I *scRFHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "SC_Target_RF_Compare", Form("Sector %.2i", sector));
584  if (scRFHist == NULL) continue;
585  //Do the fit
586  TFitResultPtr fr = scRFHist->Fit("pol0", "SQ", "", -2, 2);
587  double p0 = fr->Parameter(0);
588 
589  f->FixParameter(0,p0);
590  f->SetParLimits(2, -2, 2);
591  f->SetParLimits(3, 0, 2);
592  f->SetParameter(1, 10);
593  f->SetParameter(2, scRFHist->GetBinCenter(scRFHist->GetMaximumBin()));
594  f->SetParameter(3, 0);
595 
596  fr = scRFHist->Fit(f, "SQ", "", -2, 2);
597  double SCOffset = fr->Parameter(2);
598  selectedSCSectorOffset->SetBinContent(sector, SCOffset);
599  selectedSCSectorOffsetDistribution->Fill(SCOffset);
600  }
601  // Now write out the offsets
602  meanSCOffset = selectedSCSectorOffsetDistribution->GetMean();
603  // Move mean SC time around if we want it to end up in a particular location
604  if(FIX_START_COUNTER) { // experimental
605  TH1I *scHitTimeHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "SC", "SCHitMatchedTime");
606  double scMax = scHitTimeHist->GetBinCenter(scHitTimeHist->GetMaximumBin());
607  TFitResultPtr fr = scHitTimeHist->Fit("gaus", "S", "", scMax - 5., scMax + 5.);
608 
609  meanSCOffset = fr->Parameter(0) - meanSCOffset - start_counter_t0; // this will get it close, need to make it line up
610  }
611  if (verbose){
612  cout << "Dumping SC results...\n=======================================" << endl;
613  cout << "SC mean Offset = " << meanSCOffset << endl;
614  cout << "TDC Offsets" << endl;
615  cout << "Sector\toldValue\tValueToUse\tmeanOffset\tTotal" << endl;
616  }
617  outFile.open(prefix + "sc_tdc_timing_offsets.txt");
618  for (int sector = 1; sector <= 30; sector++){
619  outFile << sc_tdc_time_offsets[sector-1] + scTdcOffsets[sector-1] + selectedSCSectorOffset->GetBinContent(sector) - meanSCOffset << endl;
620  if (verbose) printf("%i\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n",sector, sc_tdc_time_offsets[sector-1], selectedSCSectorOffset->GetBinContent(sector), meanSCOffset,
621  sc_tdc_time_offsets[sector-1] - scTdcOffsets[sector-1] + selectedSCSectorOffset->GetBinContent(sector) - meanSCOffset);
622  }
623  outFile.close();
624  if (verbose){
625  cout << "ADC Offsets" << endl;
626  cout << "Sector\tvalueToUse\toldValue\tmeanOffset\tTotal" << endl;
627  }
628  outFile.open(prefix + "sc_adc_timing_offsets.txt");
629  for (int sector = 1; sector <= 30; sector++){
630  outFile << sc_fadc_time_offsets[sector-1] + scAdcOffsets[sector-1] + selectedSCSectorOffset->GetBinContent(sector) - meanSCOffset << endl;
631  if (verbose) printf("%i\t%.3f\t\t%.3f\t\t%.3f\t\t%.3f\n",sector,sc_fadc_time_offsets[sector-1], selectedSCSectorOffset->GetBinContent(sector), meanSCOffset,
632  sc_fadc_time_offsets[sector-1] - scAdcOffsets[sector-1] + selectedSCSectorOffset->GetBinContent(sector) - meanSCOffset);
633  }
634  outFile.close();
635 
636  outFile.open(prefix + "sc_base_time.txt");
637  outFile << sc_t_base_fadc - meanSCOffset << " " << sc_t_base_tdc - meanSCOffset << endl;
638  if (verbose) {
639  printf("SC ADC Base = %f - (%f) = %f\n", sc_t_base_fadc, meanSCOffset, sc_t_base_fadc - meanSCOffset);
640  printf("SC TDC Base = %f - (%f) = %f\n", sc_t_base_tdc, meanSCOffset, sc_t_base_tdc - meanSCOffset);
641  }
642  outFile.close();
643  }
644 
645  TH1I *this1DHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "TRACKING", "TOF - RF Time");
646  if(this1DHist != NULL){
647  //Gaussian
648  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
649  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 1.5, maximum + 1.5);
650  float mean = fr->Parameter(1);
651  outFile.open(prefix + "tof_base_time.txt");
652  if (verbose) {
653  printf("TOF ADC Base = %f - (%f) - (%f) = %f\n", tof_t_base_fadc, mean, meanSCOffset, tof_t_base_fadc - mean - meanSCOffset);
654  printf("TOF TDC Base = %f - (%f) - (%f) = %f\n", tof_t_base_tdc, mean, meanSCOffset, tof_t_base_tdc - mean - meanSCOffset);
655  }
656  outFile << tof_t_base_fadc - mean - meanSCOffset<< " " << tof_t_base_tdc - mean - meanSCOffset<< endl;
657  outFile.close();
658  }
659 
660  this1DHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "TRACKING", "BCAL - RF Time");
661  if(this1DHist != NULL){
662  //Gaussian
663  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
664  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 5, maximum + 5);
665  float mean = fr->Parameter(1);
666  outFile.open(prefix + "bcal_base_time.txt");
667  if (verbose) {
668  printf("BCAL ADC Base = %f - (%f) - (%f) = %f\n", bcal_t_base_fadc, mean, meanSCOffset, bcal_t_base_fadc - mean - meanSCOffset);
669  printf("BCAL TDC Base = %f - (%f) - (%f) = %f\n", bcal_t_base_tdc, mean, meanSCOffset, bcal_t_base_tdc - mean - meanSCOffset);
670  }
671  outFile << bcal_t_base_fadc - mean - meanSCOffset << " " << bcal_t_base_tdc - mean - meanSCOffset << endl; // TDC info not used
672  outFile.close();
673  }
674 
675  this1DHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "TRACKING", "FCAL - RF Time");
676  if(this1DHist != NULL){
677  //Gaussian
678  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
679  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 5, maximum + 5);
680  float mean = fr->Parameter(1);
681  outFile.open(prefix + "fcal_base_time.txt");
682  if (verbose) {
683  printf("FCAL ADC Base = %f - (%f) - (%f) = %f\n",fcal_t_base, mean, meanSCOffset, fcal_t_base - mean - meanSCOffset);
684  }
685  outFile << fcal_t_base - mean - meanSCOffset<< endl;
686  outFile.close();
687  }
688 
689  this1DHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "TRACKING", "Earliest CDC Time Minus Matched SC Time");
690  if(this1DHist != NULL){
691  //Gaussian
692  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
693  TFitResultPtr fr = this1DHist->Fit("gaus", "S", "", maximum - 15, maximum + 10);
694  float mean = fr->Parameter(1);
695  outFile.open(prefix + "cdc_base_time.txt");
696  if (verbose) {
697  printf("CDC ADC Base = %f - (%f) - (%f) = %f\n",cdc_t_base, mean, meanSCOffset, cdc_t_base - mean - meanSCOffset);
698  }
699  outFile << cdc_t_base - mean - meanSCOffset << endl;
700  outFile.close();
701  }
702 
703  // We want to account for any residual difference between the cathode and anode times.
704  double FDC_ADC_Offset = 0.0, FDC_TDC_Offset = 0.0;
705  this1DHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "FDC", "FDCHit Cathode time;1");
706  if(this1DHist != NULL){
707  Int_t firstBin = this1DHist->FindFirstBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
708  for (int i = 0; i <= 16; i++){
709  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
710  }
711  //Fit a gaussian to the left of the main peak
712  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
713  TF1 *f = new TF1("f", "gaus");
714  f->SetParameters(100, maximum, 20);
715  //this1DHist->Rebin(2);
716  TFitResultPtr fr = this1DHist->Fit(f, "S", "", maximum - 10, maximum + 7); // Cant fix value at end of range
717  double mean = fr->Parameter(1);
718  float sigma = fr->Parameter(2);
719  FDC_ADC_Offset = mean;
720  delete f;
721  }
722 
723  this1DHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "FDC", "FDCHit Wire time;1");
724  if(this1DHist != NULL){
725  Int_t firstBin = this1DHist->FindLastBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
726  for (int i = 0; i <= 25; i++){
727  if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
728  }
729  //Fit a gaussian to the left of the main peak
730  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
731  TF1 *f = new TF1("f", "gaus");
732  f->SetParameters(100, maximum, 20);
733  TFitResultPtr fr = this1DHist->Fit(f, "S", "", maximum - 10, maximum + 5); // Cant fix value at end of range
734  double mean = fr->Parameter(1);
735  float sigma = fr->Parameter(2);
736  FDC_TDC_Offset = mean;
737  delete f;
738  }
739  double FDC_ADC_TDC_Offset = FDC_ADC_Offset - FDC_TDC_Offset;
740 
741  this1DHist = ExtractTrackBasedTimingNS::Get1DHistogram("HLDetectorTiming", "TRACKING", "Earliest Flight-time Corrected FDC Time");
742  float MPV = 0;
743  if(this1DHist != NULL){
744  //Landau
745  Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
746  TFitResultPtr fr = this1DHist->Fit("landau", "S", "", maximum - 2.5, maximum + 4);
747  //float MPV = fr->Parameter(1);
748  MPV = fr->Parameter(1);
749  outFile.open(prefix + "fdc_base_time.txt");
750  if (verbose) {
751  printf("FDC ADC Base = %f - (%f) - (%f) - (%f) = %f\n",fdc_t_base_fadc, MPV, meanSCOffset, FDC_ADC_TDC_Offset, fdc_t_base_fadc - MPV - meanSCOffset - FDC_ADC_TDC_Offset);
752  printf("FDC TDC Base = %f - (%f) - (%f) = %f\n",fdc_t_base_tdc, MPV, meanSCOffset, fdc_t_base_tdc - MPV - meanSCOffset);
753  }
754  outFile << fdc_t_base_fadc - MPV - meanSCOffset - FDC_ADC_TDC_Offset << " " << fdc_t_base_tdc - MPV - meanSCOffset << endl;
755  outFile.close();
756  }
757 
758  //cerr << "*** MPV = " << MPV << endl;
759 
760  // see if we need to correct any FDC individual wire times. generally, assume that most of the detector is in time
761  // so the main wire timing peak is correct. then if any TDC modules deviate from this, then align them to the main peak
762  thisHist = ExtractTrackBasedTimingNS::Get2DHistogram("HLDetectorTiming", "FDC", "FDCHit Wire time vs. module");
763  if(thisHist != NULL){
764  bool package_times_shifted[4] = { false, false, false, false };
765  double FDC_wire_offsets[4][6][96] = { 0. };
766  for(int plane=1; plane<=24; plane++) {
767  // check one half of the plane
768  char buf[50];
769  sprintf(buf,"temp_%d", 2*plane-1);
770  TH1D *projY = thisHist->ProjectionY(buf, 2*plane-1, 2*plane-1);
771  //TH1D *projY = thisHist->ProjectionY("temp", 2*plane-1, 2*plane-1);
772  //Int_t firstBin = projY->FindLastBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
773  //for (int i = 0; i <= 15; i++){
774  // if ((firstBin + i) > 0) projY->SetBinContent((firstBin + i), 0);
775  //}
776  //Fit a gaussian to the left of the main peak
777  Double_t maximum = projY->GetBinCenter(projY->GetMaximumBin());
778  //cout << " plane " << plane << " max = " << maximum << endl;
779  double mean1 = 40.;
780  float sigma1 = 0.;
781  TF1 *f = new TF1("f", "gaus");
782 
783  if(maximum > -190.) {
784  //TF1 *f = new TF1("f", "gaus");
785  f->SetParameters(100, maximum, 20);
786  TFitResultPtr fr = projY->Fit(f, "S", "", maximum - 10, maximum + 5); // Cant fix value at end of range
787  mean1 = fr->Parameter(1) + MPV;
788  sigma1 = fr->Parameter(2);
789  //cerr << " mean = " << mean1 << endl;
790  //delete f;
791  }
792 
793 
794  // now check the other half
795  sprintf(buf,"temp_%d", 2*plane);
796  projY = thisHist->ProjectionY(buf, 2*plane, 2*plane);
797  //projY = thisHist->ProjectionY("temp", 2*plane, 2*plane);
798  //firstBin = projY->FindLastBinAbove( 1 , 1); // Find first bin with content above 1 in the histogram
799  //for (int i = 0; i <= 15; i++){
800  // if ((firstBin + i) > 0) projY->SetBinContent((firstBin + i), 0);
801  //}
802  //Fit a gaussian to the left of the main peak
803  maximum = projY->GetBinCenter(projY->GetMaximumBin());
804  //cout << " plane' " << plane << " max = " << maximum << endl;
805  double mean2 = 40.;
806  float sigma2 = 0.;
807 
808  if(maximum > -190.) {
809  //f = new TF1("f", "gaus");
810  f->SetParameters(100, maximum, 20);
811  TFitResultPtr fr2 = projY->Fit(f, "S", "", maximum - 10, maximum + 5); // Cant fix value at end of range
812  mean2 = fr2->Parameter(1) + MPV;
813  sigma2 = fr2->Parameter(2);
814  //cerr << " mean = " << mean2 << endl;
815  //delete f;
816  }
817 
818 
819  // ignore any shift smaller than 5 ns
820  if( (fabs(mean1) < 5.) && (fabs(mean2) < 5.) )
821  continue;
822 
823  int package = 0;
824  int chamber = 0;
825  FindFDCPackageChamber(plane, package, chamber);
826 
827  package_times_shifted[package-1] = true;
828 
829  // handle TDC modules separately
830  if(fabs(mean1) > 5.) {
831  for(int wire=0; wire<48; wire++)
832  FDC_wire_offsets[package-1][chamber-1][wire] = mean1;
833  }
834  if(fabs(mean2) > 5.) {
835  for(int wire=48; wire<96; wire++)
836  FDC_wire_offsets[package-1][chamber-1][wire] = mean2;
837  }
838  }
839 
840  // now write out anything we need
841  for(int package = 0; package<4; package++) {
842  if(package_times_shifted[package]) {
843  char buf[50];
844  sprintf(buf, "%sfdc_package%d_wire_offsets.txt", prefix.Data(), package+1);
845  outFile.open(buf);
846  for(int chamber=0; chamber<6; chamber++) {
847  for(int wire=0; wire<96; wire++) {
848  outFile << FDC_wire_offsets[package][chamber][wire] << " ";
849  }
850  outFile << endl;
851  }
852  outFile.close();
853  }
854  }
855 
856  }
857 
859  return;
860 }
TFile * outFile
Definition: FitGains.C:15
sprintf(text,"Post KinFit Cut")
void AdjustTiming(TString fileName="hd_root.root", int runNumber=10390, TString variation="default", bool verbose=false, TString prefix="")
TH1I * Get1DHistogram(const char *plugin, const char *directoryName, const char *name)
TF1 * f
Definition: FitGains.C:21
double counter
Definition: FitGains.C:151
TH2I * Get2DHistogram(const char *plugin, const char *directoryName, const char *name)
void FindFDCPackageChamber(int plane, int &package, int &chamber)
void GetCCDBConstants(TString path, Int_t run, TString variation, vector< double > &container, Int_t column=1)
Double_t sigma[NCHANNELS]
Definition: st_tw_resols.C:37
void GetCCDBConstants2(TString path, Int_t run, TString variation, double &constant1, double &constant2)
void GetCCDBConstants1(TString path, Int_t run, TString variation, double &constant1)
int GetCCDBIndexTAGM(unsigned int column, unsigned int row)
printf("string=%s", string)