File indexing completed on 2026-05-23 08:15:38
0001 #include "get_runstr.h"
0002 #include "make_cdbtree.C"
0003
0004 #include "pro_recal_mbd_mip.C"
0005
0006 #include <mbd/MbdCalib.h>
0007 #include <mbd/MbdDefs.h>
0008
0009 #include <ffamodules/CDBInterface.h>
0010
0011 #include <phool/recoConsts.h>
0012
0013 #include <TString.h>
0014 #include <TFile.h>
0015 #include <TTree.h>
0016 #include <TH1.h>
0017 #include <TH2.h>
0018 #include <TF1.h>
0019 #include <TCanvas.h>
0020 #include <TPad.h>
0021 #include <TSystem.h>
0022 #include <TStyle.h>
0023
0024 #include <iostream>
0025 #include <fstream>
0026
0027
0028 R__LOAD_LIBRARY(libffamodules.so)
0029 R__LOAD_LIBRARY(libphool.so)
0030 R__LOAD_LIBRARY(libmbd.so)
0031
0032
0033
0034
0035
0036
0037
0038 void pro_cal_mbd(const int runnumber, const int subpass = 0)
0039 {
0040 gStyle->SetOptFit(1111);
0041 gStyle->SetOptStat(111111);
0042
0043
0044
0045
0046
0047 TString dir = "results/";
0048 dir += runnumber;
0049 dir += "/";
0050 TString name = "mkdir -p " + dir;
0051 gSystem->Exec( name );
0052
0053 std::cout << name << std::endl;
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 MbdCalib *mcal = new MbdCalib();
0064 mcal->Verbosity(1);
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 TString savefname = dir;
0081 if ( subpass==0 )
0082 {
0083 savefname += "calmbdpass2."; savefname += subpass; savefname += "_time-"; savefname += runnumber; savefname += ".root";
0084
0085
0086
0087
0088
0089
0090
0091 }
0092 else if ( subpass==1 || subpass==2 )
0093 {
0094 savefname += "calmbdpass2."; savefname += subpass; savefname += "_slew-"; savefname += runnumber; savefname += ".root";
0095 }
0096 else if ( subpass==3 )
0097 {
0098 savefname += "calmbdpass2."; savefname += subpass; savefname += "_q-"; savefname += runnumber; savefname += ".root";
0099 }
0100 std::cout << "saving to " << savefname << std::endl;
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142 TFile *savefile = new TFile(savefname,"READ");
0143
0144 TH1 *h_qp[MbdDefs::MBD_N_PMT];
0145 TH1 *h_tt[MbdDefs::MBD_N_PMT];
0146 TH1 *h_tqp[MbdDefs::MBD_N_PMT];
0147
0148 TH2 *h2_slew[MbdDefs::MBD_N_PMT];
0149
0150 TString title;
0151 for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0152 {
0153 name = "h_q"; name += ipmt;
0154
0155
0156
0157 h_qp[ipmt] = (TH1*)savefile->Get( name );
0158
0159 name = "h_tt"; name += ipmt;
0160 h_tt[ipmt] = (TH1*)savefile->Get( name );
0161
0162
0163
0164
0165
0166
0167
0168 name = "h_tq"; name += ipmt;
0169 h_tqp[ipmt] = (TH1*)savefile->Get( name );
0170
0171
0172
0173
0174
0175
0176 if ( subpass>0 )
0177 {
0178 name = "h2_slew"; name += ipmt;
0179 h2_slew[ipmt] = (TH2*)savefile->Get( name );
0180
0181
0182
0183
0184
0185
0186 }
0187 }
0188 TH2 *h2_tq = (TH2*)savefile->Get("h2_tq");
0189 TH2 *h2_tt = (TH2*)savefile->Get("h2_tt");
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337 TCanvas *ac[100];
0338 int cvindex = 0;
0339
0340 TString pdfname;
0341
0342
0343 ac[cvindex] = new TCanvas("cal_tt","ch vs tt",425*1.5,550*1.5);
0344 h2_tt->Draw("colz");
0345 pdfname = dir; pdfname += "calmbdpass2."; pdfname += subpass; pdfname += "_time-"; pdfname += runnumber; pdfname += ".pdf";
0346 if ( subpass==0 )
0347 {
0348
0349 title = "t0, Timing Ch's";
0350 }
0351 else if ( subpass>0 )
0352 {
0353
0354 title = "t0 corrected, Timing Ch's";
0355 h2_tt->GetXaxis()->SetRangeUser( -12.5, 12.5 );
0356 gPad->Modified();
0357 gPad->Update();
0358 }
0359 std::cout << pdfname << std::endl;
0360 ac[cvindex]->Print( pdfname + "[");
0361 ac[cvindex]->Print( pdfname, title );
0362 ++cvindex;
0363
0364
0365 ac[cvindex] = new TCanvas("cal_tq","ch vs tq",425*1.5,550*1.5);
0366 h2_tq->Draw("colz");
0367 if ( subpass==0 )
0368 {
0369
0370 title = "t0, Charge Ch's";
0371 }
0372 else if ( subpass>0 )
0373 {
0374
0375 title = "t0 corrected, Charge Ch's";
0376 h2_tq->GetXaxis()->SetRangeUser( -20,20 );
0377 gPad->Modified();
0378 gPad->Update();
0379 }
0380 std::cout << pdfname << std::endl;
0381 ac[cvindex]->Print( pdfname, title );
0382 ++cvindex;
0383
0384
0385 ac[cvindex] = new TCanvas("cal_tt_ch","tt",550*1.5,425*1.5);
0386 gPad->SetLogy(1);
0387
0388 std::ofstream cal_tt_t0_file;
0389 TString cal_fname = dir; cal_fname += "pass"; cal_fname += subpass; cal_fname += "_mbd_tt_t0.calib";
0390 cal_tt_t0_file.open( cal_fname );
0391 std::cout << "Creating " << cal_fname << std::endl;
0392
0393 TF1 *gaussian = new TF1("gaussian","gaus",-25,25);
0394 gaussian->SetLineColor(2);
0395 double min_twindow = -25.;
0396 double max_twindow = 25.;
0397
0398 for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0399 {
0400
0401 if ( ipmt==0 || ipmt==64 )
0402 {
0403
0404 h_tt[ipmt]->SetAxisRange(-25.,25.);
0405
0406 }
0407 else
0408 {
0409
0410
0411 h_tt[ipmt]->SetAxisRange(min_twindow,max_twindow);
0412 }
0413 Double_t thispeak = h_tt[ipmt]->GetMaximum();
0414 int peakbin = h_tt[ipmt]->GetMaximumBin();
0415 Double_t mean = h_tt[ipmt]->GetBinCenter( peakbin );
0416 Double_t sigma = 1.0;
0417
0418 gaussian->SetParameters( thispeak, mean, 5 );
0419 gaussian->SetRange( mean-3*sigma, mean+3*sigma );
0420
0421 if ( ipmt==0 || ipmt==64 )
0422 {
0423 min_twindow = mean - 3*sigma;
0424 max_twindow = mean + 3*sigma;
0425 }
0426
0427 h_tt[ipmt]->Fit(gaussian,"R");
0428 h_tt[ipmt]->SetAxisRange(mean-15.*sigma,mean+15.*sigma);
0429
0430 mean = gaussian->GetParameter(1);
0431 Double_t meanerr = gaussian->GetParError(1);
0432 sigma = gaussian->GetParameter(2);
0433 Double_t sigmaerr = gaussian->GetParError(2);
0434
0435
0436 int nbinsx = h2_tt->GetNbinsX();
0437 for (int ibinx=1; ibinx<=nbinsx; ibinx++)
0438 {
0439 Double_t fitpeak = gaussian->GetParameter(0);
0440 if ( fitpeak!=0 )
0441 {
0442 Float_t bincontent = h2_tt->GetBinContent(ibinx,ipmt+1);
0443 h2_tt->SetBinContent(ibinx,ipmt+1,bincontent/fitpeak);
0444 }
0445 }
0446
0447 cal_tt_t0_file << ipmt << "\t" << mean << "\t" << meanerr << "\t" << sigma << "\t" << sigmaerr << std::endl;
0448 std::cout << ipmt << "\t" << mean << "\t" << meanerr << "\t" << sigma << "\t" << sigmaerr << std::endl;
0449
0450 if ( subpass==0 )
0451 {
0452
0453 title = "h_tt"; title += ipmt;
0454 }
0455 else if ( subpass==1 || subpass==2 )
0456 {
0457
0458 title = "h_ttcorr"; title += ipmt;
0459 }
0460
0461 ac[cvindex]->Print( pdfname, title );
0462 }
0463 cal_tt_t0_file.close();
0464 make_cdbtree( cal_fname );
0465 ++cvindex;
0466
0467
0468 ac[cvindex] = new TCanvas("cal_tq_ch","tq",550*1.5,425*1.5);
0469 gPad->SetLogy(1);
0470
0471 std::ofstream cal_tq_t0_file;
0472 cal_fname = dir; cal_fname += "pass"; cal_fname += subpass; cal_fname += "_mbd_tq_t0.calib";
0473 cal_tq_t0_file.open( cal_fname );
0474
0475 for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0476 {
0477
0478 if ( ipmt==0 || ipmt==64 )
0479 {
0480
0481 h_tqp[ipmt]->SetAxisRange(-25.,25.);
0482
0483 }
0484 else
0485 {
0486
0487
0488 h_tqp[ipmt]->SetAxisRange(min_twindow,max_twindow);
0489 }
0490 Double_t thispeak = h_tqp[ipmt]->GetMaximum();
0491 int peakbin = h_tqp[ipmt]->GetMaximumBin();
0492 Double_t mean = h_tqp[ipmt]->GetBinCenter( peakbin );
0493 Double_t sigma = 1.0;
0494
0495 gaussian->SetParameters( thispeak, mean, 5 );
0496 gaussian->SetRange( mean-3*sigma, mean+3*sigma );
0497
0498 if ( ipmt==0 || ipmt==64 )
0499 {
0500 min_twindow = mean - 3*sigma;
0501 max_twindow = mean + 3*sigma;
0502 }
0503
0504 h_tqp[ipmt]->Fit(gaussian,"R");
0505 h_tqp[ipmt]->SetAxisRange(mean-12.*sigma,mean+12.*sigma);
0506
0507 mean = gaussian->GetParameter(1);
0508 Double_t meanerr = gaussian->GetParError(1);
0509 sigma = gaussian->GetParameter(2);
0510 Double_t sigmaerr = gaussian->GetParError(2);
0511
0512
0513 int nbinsx = h2_tq->GetNbinsX();
0514 for (int ibinx=1; ibinx<=nbinsx; ibinx++)
0515 {
0516 Double_t fitpeak = gaussian->GetParameter(0);
0517 if ( fitpeak!=0 )
0518 {
0519 Float_t bincontent = h2_tq->GetBinContent(ibinx,ipmt+1);
0520 h2_tq->SetBinContent(ibinx,ipmt+1,bincontent/fitpeak);
0521 }
0522 }
0523
0524 cal_tq_t0_file << ipmt << "\t" << mean << "\t" << meanerr << "\t" << sigma << "\t" << sigmaerr << std::endl;
0525
0526 if ( subpass==0 )
0527 {
0528
0529 title = "h_tq"; title += ipmt;
0530 }
0531 else if ( subpass==1 || subpass==2 )
0532 {
0533
0534 title = "h_tqcorr"; title += ipmt;
0535 }
0536
0537 ac[cvindex]->Print( pdfname, title );
0538 }
0539
0540 cal_tq_t0_file.close();
0541 make_cdbtree( cal_fname );
0542
0543 ac[0]->Print( pdfname + "]" );
0544 ++cvindex;
0545
0546 if ( subpass==1 || subpass==2 )
0547 {
0548
0549 ac[cvindex] = new TCanvas("cal_slew","slew",425*1.5,550*1.5);
0550 pdfname = dir; pdfname += "calmbdpass2."; pdfname += subpass; pdfname += "_slew-"; pdfname += runnumber; pdfname += ".pdf";
0551 ac[cvindex]->Print( pdfname + "[" );
0552
0553 for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0554 {
0555 h2_slew[ipmt]->Draw("colz");
0556 gPad->SetLogz(1);
0557
0558
0559 name = dir + "h2_slew"; name += ipmt; name += "_pass"; name += subpass;
0560 std::cout << name << std::endl;
0561 ac[cvindex]->Print( pdfname, name );
0562 }
0563
0564
0565
0566 ac[cvindex]->Print( pdfname + "]" );
0567 ++cvindex;
0568 }
0569
0570
0571 if ( subpass==0 )
0572 {
0573 ac[cvindex] = new TCanvas("cal_q","q",425*1.5,550*1.5);
0574
0575 pdfname = dir; pdfname += "calmbdpass2."; pdfname += subpass; pdfname += "_adc-"; pdfname += runnumber; pdfname += ".pdf";
0576 ac[cvindex]->Print( pdfname + "[" );
0577
0578 gPad->SetLogy(1);
0579
0580 for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT && subpass==0; ipmt++)
0581 {
0582 h_qp[ipmt]->Draw();
0583
0584
0585 title = "h_adc"; title += ipmt;
0586
0587 ac[cvindex]->Print( pdfname, title );
0588 }
0589 ac[cvindex]->Print( pdfname + "]" );
0590 ++cvindex;
0591 }
0592
0593
0594
0595
0596 if ( subpass==3 )
0597 {
0598 pro_recal_mbd_mip( runnumber, subpass );
0599 }
0600
0601 }
0602