1 namespace ExtractTDCADCTimingNS {
4 TH1I *
Get1DHistogram(
const char * plugin,
const char * directoryName,
const char * name,
bool print =
true){
6 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
7 thisFile->GetObject(fullName, histogram);
9 if (print) cout <<
"Unable to find histogram " << fullName.Data() << endl;
15 TH2I *
Get2DHistogram(
const char * plugin,
const char * directoryName,
const char * name){
17 TString fullName = TString(plugin) +
"/" + TString(directoryName) +
"/" + TString(name);
18 thisFile->GetObject(fullName, histogram);
20 cout <<
"Unable to find histogram " << fullName.Data() << endl;
29 sprintf(command,
"ccdb dump %s:%i:%s", path.Data(),
run, variation.Data());
30 FILE* inputPipe = gSystem->OpenPipe(command,
"r");
35 if(fgets(buff,
sizeof(buff), inputPipe) == NULL)
40 while(fgets(buff,
sizeof(buff), inputPipe) != NULL){
41 istringstream locConstantsStream(buff);
42 while (locConstantsStream >> entry){
44 if (counter %
column == 0) container.push_back(entry);
48 gSystem->ClosePipe(inputPipe);
53 sprintf(command,
"ccdb dump %s:%i:%s", path.Data(),
run, variation.Data());
54 FILE* inputPipe = gSystem->OpenPipe(command,
"r");
59 if(fgets(buff,
sizeof(buff), inputPipe) == NULL)
62 while(fgets(buff,
sizeof(buff), inputPipe) != NULL){
63 istringstream locConstantsStream(buff);
64 locConstantsStream >> constant1;
67 gSystem->ClosePipe(inputPipe);
72 sprintf(command,
"ccdb dump %s:%i:%s", path.Data(),
run, variation.Data());
73 FILE* inputPipe = gSystem->OpenPipe(command,
"r");
78 if(fgets(buff,
sizeof(buff), inputPipe) == NULL)
81 while(fgets(buff,
sizeof(buff), inputPipe) != NULL){
82 istringstream locConstantsStream(buff);
83 locConstantsStream >> constant1 >> constant2;
86 gSystem->ClosePipe(inputPipe);
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;
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;
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) ) );
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) ) );
120 void ExtractTDCADCTiming(TString fileName =
"hd_root.root",
int runNumber = 10390, TString variation =
"default", TString prefix =
""){
123 cout <<
"Performing TDC/ADC timing fits for File: " << fileName.Data() <<
" Run: " << runNumber <<
" Variation: " << variation.Data() << endl;
127 cout <<
"Unable to open file " << fileName.Data() <<
"...Exiting" << endl;
133 cout <<
"Grabbing CCDB constants..." << endl;
136 double cdc_base_time, fcal_base_time;
137 double sc_base_time_tdc, sc_base_time_adc;
138 double fdc_base_time_tdc, fdc_base_time_adc;
139 double bcal_base_time_tdc, bcal_base_time_adc;
140 double tagm_base_time_tdc, tagm_base_time_adc;
141 double tagh_base_time_tdc, tagh_base_time_adc;
142 double tof_base_time_tdc, tof_base_time_adc;
147 GetCCDBConstants1(
"/FCAL/base_time_offset",runNumber, variation, fcal_base_time);
148 GetCCDBConstants1(
"/PHOTON_BEAM/RF/beam_period",runNumber, variation, beam_period);
149 GetCCDBConstants2(
"/FDC/base_time_offset" ,runNumber, variation, fdc_base_time_adc, fdc_base_time_tdc);
150 GetCCDBConstants2(
"/BCAL/base_time_offset" ,runNumber, variation, bcal_base_time_adc, bcal_base_time_tdc);
151 GetCCDBConstants2(
"/PHOTON_BEAM/microscope/base_time_offset" ,runNumber, variation, tagm_base_time_adc, tagm_base_time_tdc);
152 GetCCDBConstants2(
"/PHOTON_BEAM/hodoscope/base_time_offset" ,runNumber, variation, tagh_base_time_adc, tagh_base_time_tdc);
153 GetCCDBConstants2(
"/START_COUNTER/base_time_offset" ,runNumber, variation, sc_base_time_adc, sc_base_time_tdc);
154 GetCCDBConstants2(
"/TOF/base_time_offset" ,runNumber, variation, tof_base_time_adc, tof_base_time_tdc);
156 cout <<
"CDC base times = " << cdc_base_time << endl;
157 cout <<
"FCAL base times = " << fcal_base_time << endl;
158 cout <<
"FDC base times = " << fdc_base_time_adc <<
", " << fdc_base_time_tdc << endl;
159 cout <<
"BCAL base times = " << bcal_base_time_adc <<
", " << bcal_base_time_tdc << endl;
160 cout <<
"SC base times = " << sc_base_time_adc <<
", " << sc_base_time_tdc << endl;
161 cout <<
"TOF base times = " << tof_base_time_adc <<
", " << tof_base_time_tdc << endl;
162 cout <<
"TAGH base times = " << tagh_base_time_adc <<
", " << tagh_base_time_tdc << endl;
163 cout <<
"TAGM base times = " << tagm_base_time_adc <<
", " << tagm_base_time_tdc << endl;
165 cout <<
"beam_period = " << beam_period << endl;
168 vector<double> bcal_tdc_offsets;
169 vector<double> fcal_adc_offsets;
170 vector<double> sc_adc_offsets, sc_tdc_offsets;
171 vector<double> tagm_adc_offsets, tagm_tdc_offsets;
172 vector<double> tagh_adc_offsets, tagh_tdc_offsets, tagh_counter_quality;
173 vector<double> tof_adc_offsets, tof_tdc_offsets;
174 GetCCDBConstants(
"/BCAL/TDC_offsets" ,runNumber, variation, bcal_tdc_offsets);
175 GetCCDBConstants(
"/FCAL/timing_offsets" ,runNumber, variation, fcal_adc_offsets);
176 GetCCDBConstants(
"/START_COUNTER/adc_timing_offsets" ,runNumber, variation, sc_adc_offsets);
177 GetCCDBConstants(
"/START_COUNTER/tdc_timing_offsets" ,runNumber, variation, sc_tdc_offsets);
178 GetCCDBConstants(
"/PHOTON_BEAM/microscope/fadc_time_offsets" ,runNumber, variation, tagm_adc_offsets,3);
179 GetCCDBConstants(
"/PHOTON_BEAM/microscope/tdc_time_offsets" ,runNumber, variation, tagm_tdc_offsets,3);
180 GetCCDBConstants(
"/PHOTON_BEAM/hodoscope/fadc_time_offsets" ,runNumber, variation, tagh_adc_offsets,2);
181 GetCCDBConstants(
"/PHOTON_BEAM/hodoscope/tdc_time_offsets" ,runNumber, variation, tagh_tdc_offsets,2);
182 GetCCDBConstants(
"/PHOTON_BEAM/hodoscope/counter_quality" ,runNumber, variation, tagh_counter_quality,2);
183 GetCCDBConstants(
"/TOF/adc_timing_offsets",runNumber, variation, tof_adc_offsets);
184 GetCCDBConstants(
"/TOF/timing_offsets",runNumber, variation, tof_tdc_offsets);
186 cout <<
"Done grabbing CCDB constants...Entering fits..." << endl;
190 float CDC_ADC_Offset = 0.0;
192 if(this1DHist != NULL){
193 Int_t firstBin = this1DHist->FindLastBinAbove( 1 , 1);
194 for (
int i = 0; i <= 25; i++){
195 if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
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);
203 double mean = fr->Parameter(1);
204 float sigma = fr->Parameter(2);
205 CDC_ADC_Offset = mean -
sigma;
209 CDC_ADC_Offset *= -1;
210 outFile.open(prefix +
"cdc_base_time.txt");
211 outFile << cdc_base_time + CDC_ADC_Offset << endl;
214 float FDC_ADC_Offset = 0.0, FDC_TDC_Offset = 0.0;
216 if(this1DHist != NULL){
217 Int_t firstBin = this1DHist->FindLastBinAbove( 1 , 1);
218 for (
int i = 0; i <= 25; i++){
219 if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
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 - 30, maximum + 20);
227 double mean = fr->Parameter(1);
228 float sigma = fr->Parameter(2);
229 FDC_ADC_Offset = mean;
233 if(this1DHist != NULL){
234 Int_t firstBin = this1DHist->FindLastBinAbove( 1 , 1);
235 for (
int i = 0; i <= 25; i++){
236 if ((firstBin + i) > 0) this1DHist->SetBinContent((firstBin + i), 0);
239 Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
240 TF1 *
f =
new TF1(
"f",
"gaus");
241 f->SetParameters(100, maximum, 20);
242 f->FixParameter(1 , maximum);
243 TFitResultPtr fr = this1DHist->Fit(f,
"S",
"", maximum - 30, maximum + 20);
244 double mean = fr->Parameter(1);
245 float sigma = fr->Parameter(2);
246 FDC_TDC_Offset = mean;
250 FDC_ADC_Offset *= -1; FDC_TDC_Offset *= -1;
251 outFile.open(prefix +
"fdc_base_time.txt");
252 outFile << fdc_base_time_adc + FDC_ADC_Offset <<
" " << fdc_base_time_tdc + FDC_TDC_Offset << endl;
263 float sc_tdc_base_time = 0.0;
266 if(this1DHist != NULL){
268 Double_t maximum = this1DHist->GetBinCenter(this1DHist->GetMaximumBin());
269 TFitResultPtr fr = this1DHist->Fit(
"gaus",
"S",
"", maximum - 5, maximum + 5);
270 double mean = fr->Parameter(1);
271 sc_tdc_base_time = mean;
275 TH1D * selected_SC_TDCADCOffset = NULL;
276 TH1I * SCOffsetDistribution = NULL;
277 if(thisHist != NULL){
279 int nBinsX = thisHist->GetNbinsX();
280 int nBinsY = thisHist->GetNbinsY();
282 selected_SC_TDCADCOffset =
new TH1D(
"selected_SC_TDCADCOffset",
"Selected SC TDC/ADC Offset; CCDB Index; Offset [ns]", nBinsX, 0.5, nBinsX + 0.5);
283 SCOffsetDistribution =
new TH1I(
"SCOffsetDistribution",
"SC ADC Offset; ADC Offset [ns]; Entries", 1000, -500, 500);
285 for (
int i = 1 ; i <= nBinsX; i++){
286 TH1D *projY = thisHist->ProjectionY(
"temp", i, i);
288 float nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
289 float timeWindow = 2;
290 int binWindow = int(timeWindow / nsPerBin);
291 double maxEntries = 0;
293 for (
int j = 1 ; j <= projY->GetNbinsX();j++){
295 int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
296 double sum = 0, nEntries = 0;
297 for (
int bin = minBin; bin <= maxBin; bin++){
298 sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
299 nEntries += projY->GetBinContent(bin);
301 if (nEntries > maxEntries) {
302 maxMean = sum / nEntries;
303 maxEntries = nEntries;
312 selected_SC_TDCADCOffset->SetBinContent(i, -1*maxMean);
313 SCOffsetDistribution->Fill(-1*maxMean);
318 float meanDiff = 0.0;
319 if (selected_SC_TDCADCOffset != NULL){
320 meanDiff = SCOffsetDistribution->GetMean();
321 outFile.open(prefix +
"sc_adc_timing_offsets.txt", ios::out);
322 for(
int iSC = 1; iSC <= 30; iSC++){
323 float SC_ADC_Offset = selected_SC_TDCADCOffset->GetBinContent(iSC);
324 outFile << SC_ADC_Offset + sc_adc_offsets[iSC-1] - meanDiff << endl;
329 outFile.open(prefix +
"sc_base_time.txt", ios::out);
330 outFile << sc_base_time_adc - (sc_tdc_base_time + meanDiff) <<
" " << sc_base_time_tdc - sc_tdc_base_time << endl;
334 if(thisHist != NULL){
335 int nBinsX = thisHist->GetNbinsX();
336 int nBinsY = thisHist->GetNbinsY();
338 TH1D * selected_TOF_TDCADCOffset =
new TH1D(
"selected_TOF_TDCADCOffset",
"Selected TOF TDC/ADC Offset; CCDB Index; Offset [ns]", nBinsX, 0.5, nBinsX + 0.5);
339 TH1I * TOFOffsetDistribution =
new TH1I(
"TOFOffsetDistribution",
"TOF ADC Offset; ADC Offset [ns]; Entries", 1000, -500, 500);
341 outFile.open(prefix +
"tof_adc_timing_offsets.txt");
344 for (
int i = 1 ; i <= nBinsX; i++){
345 TH1D *projY = thisHist->ProjectionY(
"temp", i, i);
348 float nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
349 float timeWindow = 0.5;
350 int binWindow = int(timeWindow / nsPerBin);
351 double maxEntries = 0;
353 for (
int j = 1 ; j <= projY->GetNbinsX();j++){
355 int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
356 double sum = 0, nEntries = 0;
357 for (
int bin = minBin; bin <= maxBin; bin++){
358 sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
359 nEntries += projY->GetBinContent(bin);
361 if (nEntries > maxEntries) {
362 maxMean = sum / nEntries;
363 maxEntries = nEntries;
369 selected_TOF_TDCADCOffset->SetBinContent(i, -1*maxMean);
370 if (maxMean != 0) TOFOffsetDistribution->Fill(-1*maxMean);
373 double meanOffset = TOFOffsetDistribution->GetMean();
374 outFile.open(prefix +
"tof_adc_timing_offsets.txt", ios::out);
375 for (
int i = 1 ; i <= nBinsX; i++){
376 double valueToUse = selected_TOF_TDCADCOffset->GetBinContent(i);
377 if (valueToUse == 0) valueToUse = meanOffset;
378 outFile << tof_adc_offsets[i-1] + valueToUse - meanOffset << endl;
381 outFile.open(prefix +
"tof_base_time.txt", ios::out);
382 outFile << tof_base_time_adc - meanOffset <<
" " << tof_base_time_tdc << endl;
388 if(thisHist != NULL){
389 float tdcRFOffset[122] = {};
392 TF1 * fitLeft =
new TF1(
"fa",
FitFunctionLeft, -1*beam_period / 2, beam_period / 2, 4);
393 TF1 * fitRight =
new TF1(
"fa",
FitFunctionRight, -1*beam_period / 2, beam_period / 2, 4);
395 for (
unsigned int row = 0; row <= 5; row++){
398 if (rf_hist != NULL){
401 cout <<
"Fitting TAGM " << name << endl;
403 if (rf_hist->GetBinCenter(rf_hist->GetMaximumBin()) < 0.0) fa = fitLeft;
405 fa->SetParLimits(1, -1*beam_period / 2, beam_period / 2);
406 fa->SetParameter(1,rf_hist->GetBinCenter(rf_hist->GetMaximumBin()));
407 fa->SetParLimits(2, 0.175, 1.2);
408 fa->SetParameter(2, 0.4);
409 fa->FixParameter(3, beam_period);
410 TFitResultPtr r = rf_hist->Fit(fa,
"S",
"", -1*beam_period / 2, beam_period / 2);
413 Double_t offset = r->Parameter(1);
421 int nBinsX = thisHist->GetNbinsX();
422 int nBinsY = thisHist->GetNbinsY();
424 TH1D * selectedTAGMOffset =
new TH1D(
"selectedTAGMOffset",
"Selected TAGM Offset; Column; Offset [ns]", nBinsX, 0.5, nBinsX + 0.5);
425 TH1I * TAGMOffsetDistribution =
new TH1I(
"TAGMOffsetDistribution",
"TAGM ADC Offset; ADC Offset [ns]; Entries", 1000, -500, 500);
427 for (
int i = 1 ; i <= nBinsX; i++){
428 TH1D *projY = thisHist->ProjectionY(
"temp", i, i);
431 float nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
432 float timeWindow = 2;
433 int binWindow = int(timeWindow / nsPerBin);
434 double maxEntries = 0;
436 for (
int j = 1 ; j <= projY->GetNbinsX();j++){
438 int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
439 double sum = 0, nEntries = 0;
440 for (
int bin = minBin; bin <= maxBin; bin++){
441 sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
442 nEntries += projY->GetBinContent(bin);
444 if (nEntries > maxEntries) {
445 maxMean = sum / nEntries;
446 maxEntries = nEntries;
451 selectedTAGMOffset->SetBinContent(i, -1 * maxMean);
452 if (maxMean != 0) TAGMOffsetDistribution->Fill(-1 * maxMean);
455 double meanOffset = TAGMOffsetDistribution->GetMean();
456 outFile.open(prefix +
"tagm_adc_timing_offsets.txt", ios::out);
461 double valueToUse = selectedTAGMOffset->GetBinContent(index);
462 if (valueToUse == 0) valueToUse = meanOffset;
463 outFile <<
"0 " <<
column <<
" " << tagm_adc_offsets[index-1] + valueToUse - meanOffset + tdcRFOffset[index-1] << endl;
465 for (
unsigned int row = 1; row <= 5; row++){
467 valueToUse = selectedTAGMOffset->GetBinContent(index);
468 double valueToUse = selectedTAGMOffset->GetBinContent(index);
469 if (valueToUse == 0) valueToUse = meanOffset;
470 outFile << row <<
" " <<
column <<
" " << tagm_adc_offsets[index-1] + valueToUse - meanOffset + tdcRFOffset[index-1] << endl;
476 outFile.open(prefix +
"tagm_tdc_timing_offsets.txt", ios::out);
481 outFile <<
"0 " <<
column <<
" " << tagm_tdc_offsets[index-1] + tdcRFOffset[index-1] << endl;
483 for (
unsigned int row = 1; row <= 5; row++){
485 outFile << row <<
" " <<
column <<
" " << tagm_tdc_offsets[index-1] + tdcRFOffset[index-1] << endl;
491 outFile.open(prefix +
"tagm_base_time.txt", ios::out);
492 outFile << tagm_base_time_adc - meanOffset <<
" " << tagm_base_time_tdc << endl;
497 if (thisHist != NULL) {
501 const int NtdcSlots = 8;
502 TH1I * tdcDist[NtdcSlots];
503 TH1I * tdcadcDist[NtdcSlots];
504 for (
int i = 1; i <= NtdcSlots; i++) {
505 stringstream ss; ss << i;
506 TString s = ss.str();
507 double range = 1000.0;
double width = 0.1;
508 int Nbins = range/width;
509 double low = -0.5*range - 0.5*width;
510 double high = 0.5*range - 0.5*width;
511 tdcDist[i-1] =
new TH1I(
"TAGHTDCOffsetDistribution_"+s,
"TAGH TDC Offset (slot "+s+
"); TDC Offset [ns]; Entries", Nbins, low, high);
512 tdcadcDist[i-1] =
new TH1I(
"TAGHTDCADCOffsetDistribution_"+s,
"TAGH TDC/ADC Offset (slot "+s+
"); TDC/ADC Offset [ns]; Entries", Nbins, low, high);
516 double tdcRFOffsetTAGH[274] = {};
519 TF1 * fitLeft =
new TF1(
"fa",
FitFunctionLeft, -1*beam_period / 2, beam_period / 2, 4);
520 TF1 * fitRight =
new TF1(
"fa",
FitFunctionRight, -1*beam_period / 2, beam_period / 2, 4);
522 for (
unsigned int counter_id = 1; counter_id <= 274; counter_id++) {
523 sprintf(name,
"Counter ID %.3i", counter_id);
524 cout <<
"Fitting TAGH " << name << endl;
526 if (rf_hist != NULL) {
530 if (rf_hist->GetBinCenter(rf_hist->GetMaximumBin()) < 0.0) fa = fitLeft;
532 fa->SetParLimits(1, -1*beam_period / 2, beam_period / 2);
533 fa->SetParameter(1,rf_hist->GetBinCenter(rf_hist->GetMaximumBin()));
534 fa->SetParLimits(2, 0.175, 1.2);
535 fa->SetParameter(2, 0.4);
536 fa->FixParameter(3, beam_period);
537 TFitResultPtr r = rf_hist->Fit(fa,
"S",
"", -1*beam_period / 2, beam_period / 2);
540 Double_t offset = r->Parameter(1);
541 tdcRFOffsetTAGH[counter_id - 1] = offset;
542 if (tagh_counter_quality[counter_id-1] == 0.0)
continue;
544 tdcDist[tdc_slot - 1]->Fill(offset);
549 double mpDeltaTDC[NtdcSlots];
550 for (
int i = 1; i <= NtdcSlots; i++) {
551 int mpBin = tdcDist[i-1]->GetMaximumBin();
552 mpDeltaTDC[i-1] = (mpBin > 0) ? tdcDist[i-1]->GetBinCenter(mpBin) : 0.0;
555 outFile.open(prefix +
"tagh_adc_timing_offsets.txt", ios::out | ios::trunc);
558 int nBinsX = thisHist->GetNbinsX();
560 TH1D * selectedTAGHOffset =
new TH1D(
"selectedTAGHOffset",
"Selected TAGH Offset; Column; Offset [ns]", nBinsX, 0.5, nBinsX + 0.5);
561 for (
int i = 1 ; i <= nBinsX; i++) {
562 TH1D *projY = thisHist->ProjectionY(
"temp", i, i);
564 double nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
565 double timeWindow = 2.0;
566 int binWindow = int(timeWindow / nsPerBin);
567 double maxEntries = 0;
569 for (
int j = 1 ; j <= projY->GetNbinsX();j++) {
571 int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
572 double sum = 0, nEntries = 0;
573 for (
int bin = minBin; bin <= maxBin; bin++) {
574 sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
575 nEntries += projY->GetBinContent(bin);
577 if (nEntries > maxEntries) {
578 maxMean = sum / nEntries;
579 maxEntries = nEntries;
584 selectedTAGHOffset->SetBinContent(i, maxMean);
585 if (tagh_counter_quality[i-1] == 0.0)
continue;
587 if (maxEntries != 0.0) tdcadcDist[tdc_slot - 1]->Fill(maxMean);
590 double mpDeltaADC[NtdcSlots];
591 for (
int i = 1; i <= NtdcSlots; i++) {
592 int mpBin = tdcadcDist[i-1]->GetMaximumBin();
593 double mpDeltaTDCADC = (mpBin > 0) ? tdcadcDist[i-1]->GetBinCenter(mpBin) : 0.0;
594 mpDeltaADC[i-1] = mpDeltaTDC[i-1] - mpDeltaTDCADC;
597 outFile.open(prefix +
"tagh_adc_timing_offsets.txt");
599 double ccdb_sum = 0.0;
600 for (
int i = 1; i <= nBinsX; i++) ccdb_sum += tagh_adc_offsets[i-1];
601 double c1_adcOffset = 0.0;
602 for (
int i = 1; i <= nBinsX; i++) {
603 if (tagh_counter_quality[i-1] == 0.0) {
604 outFile << i <<
" " << 0 << endl;
608 double ccdb = tagh_adc_offsets[i-1];
609 double delta = tdcRFOffsetTAGH[i-1] - selectedTAGHOffset->GetBinContent(i);
610 if (ccdb_sum > 0.0 && fabs(delta - mpDeltaADC[tdc_slot-1]) > limit) {
611 delta = mpDeltaADC[tdc_slot-1];
613 double offset = ccdb + delta;
614 if (i == 1) c1_adcOffset = offset;
615 offset -= c1_adcOffset;
616 outFile << i <<
" " << offset << endl;
620 outFile.open(prefix +
"tagh_tdc_timing_offsets.txt");
622 for (
int i = 1; i <= nBinsX; i++) ccdb_sum += tagh_tdc_offsets[i-1];
623 double c1_tdcOffset = 0.0;
624 for (
int i = 1; i <= nBinsX; i++) {
625 if (tagh_counter_quality[i-1] == 0.0) {
626 outFile << i <<
" " << 0 << endl;
630 double ccdb = tagh_tdc_offsets[i-1];
631 double delta = tdcRFOffsetTAGH[i-1];
632 if (ccdb_sum > 0.0 && fabs(delta - mpDeltaTDC[tdc_slot-1]) > limit) {
633 delta = mpDeltaTDC[tdc_slot-1];
635 double offset = ccdb + delta;
636 if (i == 1) c1_tdcOffset = offset;
637 offset -= c1_tdcOffset;
638 outFile << i <<
" " << offset << endl;
642 outFile.open(prefix +
"tagh_base_time.txt", ios::out);
643 outFile << tagh_base_time_adc - c1_adcOffset <<
" " << tagh_base_time_tdc - c1_tdcOffset << endl;
652 outFile.open(prefix +
"bcal_tdc_timing_offsets.txt", ios::out | ios::trunc);
655 TH1D * selectedBCALOffset =
new TH1D(
"selectedBCALOffset",
"Selected BCAL TDC Offset; Column; Offset [ns]", 1152, 0.5, 1152 + 0.5);
656 TH1I * BCALOffsetDistribution =
new TH1I(
"BCALOffsetDistribution",
"BCAL TDC Offset; TDC Offset [ns]; Entries", 500, -500, 500);
659 if(thisHist != NULL){
660 int nBinsX = thisHist->GetNbinsX();
661 int nBinsY = thisHist->GetNbinsY();
662 for (
int i = 1 ; i <= nBinsX; i++){
663 TH1D *projY = thisHist->ProjectionY(
"temp", i, i);
665 float nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
666 float timeWindow = 2;
667 int binWindow = int(timeWindow / nsPerBin);
668 double maxEntries = 0;
670 for (
int j = 1 ; j <= projY->GetNbinsX();j++){
672 int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
673 double sum = 0, nEntries = 0;
674 for (
int bin = minBin; bin <= maxBin; bin++){
675 sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
676 nEntries += projY->GetBinContent(bin);
678 if (nEntries > maxEntries) {
679 maxMean = sum / nEntries;
680 maxEntries = nEntries;
685 selectedBCALOffset->SetBinContent(2*i - 1, maxMean);
686 BCALOffsetDistribution->Fill(maxMean+bcal_tdc_offsets[2*i -2]);
691 if(thisHist != NULL){
692 int nBinsX = thisHist->GetNbinsX();
693 int nBinsY = thisHist->GetNbinsY();
694 for (
int i = 1 ; i <= nBinsX; i++){
695 TH1D *projY = thisHist->ProjectionY(
"temp", i, i);
697 float nsPerBin = (projY->GetBinCenter(projY->GetNbinsX()) - projY->GetBinCenter(1)) / projY->GetNbinsX();
698 float timeWindow = 2;
699 int binWindow = int(timeWindow / nsPerBin);
700 double maxEntries = 0;
702 for (
int j = 1 ; j <= projY->GetNbinsX();j++){
704 int maxBin = (j + binWindow) <= projY->GetNbinsX() ? (j + binWindow) : projY->GetNbinsX();
705 double sum = 0, nEntries = 0;
706 for (
int bin = minBin; bin <= maxBin; bin++){
707 sum += projY->GetBinContent(bin) * projY->GetBinCenter(bin);
708 nEntries += projY->GetBinContent(bin);
710 if (nEntries > maxEntries) {
711 maxMean = sum / nEntries;
712 maxEntries = nEntries;
718 selectedBCALOffset->SetBinContent(2*i, maxMean);
719 BCALOffsetDistribution->Fill(maxMean+bcal_tdc_offsets[2*i -1]);
724 double meanTDCOffset = BCALOffsetDistribution->GetMean();
727 outFile.open(prefix +
"bcal_base_time.txt", ios::out);
728 outFile << bcal_base_time_adc <<
" " << bcal_base_time_tdc - meanTDCOffset << endl;
731 for (
int i = 1 ; i <= selectedBCALOffset->GetNbinsX(); i++){
732 double valueToUse = selectedBCALOffset->GetBinContent(i);
733 if (valueToUse == 0) valueToUse = meanTDCOffset;
734 outFile.open(prefix +
"bcal_tdc_timing_offsets.txt", ios::out | ios::app);
735 outFile << bcal_tdc_offsets[i-1] + valueToUse - meanTDCOffset << endl;
int GetF1TDCslotTAGH(int id)
sprintf(text,"Post KinFit Cut")
static char index(char c)
void GetCCDBConstants(TString path, Int_t run, TString variation, vector< double > &container, Int_t column=1)
Double_t sigma[NCHANNELS]
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)