File indexing completed on 2025-12-17 09:23:56
0001
0002
0003
0004
0005 #include "get_runstr.h"
0006
0007 #include <mbd/MbdCalib.h>
0008 #include <mbd/MbdDefs.h>
0009 #include <mbd/MbdGeomV1.h>
0010
0011 #include <TF1.h>
0012 #include <TFile.h>
0013 #include <TGraphErrors.h>
0014 #include <TPad.h>
0015 #include <TSystem.h>
0016
0017 #include <iostream>
0018
0019 #include <fstream>
0020 #include <vector>
0021
0022 R__LOAD_LIBRARY(libmbd_io.so)
0023
0024 const int NPOINTS = 1000;
0025 Int_t feech[MbdDefs::MBD_N_FEECH];
0026 Int_t npts[MbdDefs::MBD_N_FEECH];
0027 Double_t mintdc[MbdDefs::MBD_N_FEECH];
0028 Double_t maxtdc[MbdDefs::MBD_N_FEECH];
0029 Double_t mintime[MbdDefs::MBD_N_FEECH];
0030 Double_t maxtime[MbdDefs::MBD_N_FEECH];
0031 Double_t timecorr[MbdDefs::MBD_N_FEECH][NPOINTS];
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 void interpolate_timecorr(const int ifeech, TGraphErrors *g, TF1 *f)
0124 {
0125 Int_t n = g->GetN();
0126 Double_t *x = g->GetX();
0127 Double_t *y = g->GetY();
0128
0129 g->Fit(f, "R");
0130
0131 g->Draw("ap");
0132 gPad->Modified();
0133 gPad->Update();
0134
0135 float mintimelocal = TMath::MinElement(n, y);
0136 float maxtimelocal = TMath::MaxElement(n, y);
0137 float mintdclocal = TMath::MinElement(n, x);
0138 float maxtdclocal = TMath::MaxElement(n, x);
0139 std::cout << ifeech << "\t" << mintimelocal << "\t" << maxtimelocal << "\t" << maxtimelocal - mintimelocal << std::endl;
0140 std::cout << "tdc\t" << mintdclocal << "\t" << maxtdclocal << std::endl;
0141
0142
0143 feech[ifeech] = ifeech;
0144 npts[ifeech] = NPOINTS;
0145 mintdc[ifeech] = mintdclocal;
0146 maxtdc[ifeech] = maxtdclocal;
0147 mintime[ifeech] = mintimelocal;
0148 maxtime[ifeech] = maxtimelocal;
0149
0150
0151
0152
0153
0154 double dstep = 14985. / (NPOINTS - 1);
0155 double tdc = 0;
0156 for (int istep = 0; istep < NPOINTS; istep++)
0157 {
0158
0159 timecorr[ifeech][istep] = g->Eval(tdc) - mintimelocal;
0160
0161 if (istep == 0 || istep == NPOINTS - 1)
0162 {
0163 std::cout << "ch " << ifeech << "\t" << istep << "\t" << tdc << "\t" << timecorr[ifeech][istep] << std::endl;
0164 }
0165
0166 tdc += dstep;
0167 }
0168 }
0169
0170 void make_timecorr(const char *rootfname = "calib_seb18-00029705-0000_mbdtimecalib.root")
0171 {
0172 MbdGeom *mbdgeom = new MbdGeomV1();
0173
0174
0175
0176 TString dir = "results/";
0177 dir += get_runstr(rootfname);
0178 dir.ReplaceAll("_mbdtimecalib", "");
0179
0180 dir += "/";
0181
0182 TString name = "echo " + dir;
0183 gSystem->Exec(name);
0184 std::cout << name << std::endl;
0185
0186
0187
0188 TF1 *fpoly = new TF1("fpoly", "pol4", 0, 15000);
0189 fpoly->SetParameters(28., -0.0018, -1e-7, 1.3e-11, -5e-16);
0190 fpoly->SetLineColor(4);
0191 TGraphErrors *g_delaytime[MbdDefs::MBD_N_FEECH];
0192 TFile *tfile = new TFile(rootfname, "READ");
0193 for (int ifeech = 0; ifeech < MbdDefs::MBD_N_FEECH; ifeech++)
0194 {
0195 if (mbdgeom->get_type(ifeech) == 1)
0196 {
0197 continue;
0198 }
0199
0200 name = "g_delaytime";
0201 name += ifeech;
0202 g_delaytime[ifeech] = (TGraphErrors *) tfile->Get(name);
0203 std::cout << name << std::endl;
0204
0205
0206 if (ifeech == 0)
0207 {
0208 g_delaytime[ifeech]->Fit(fpoly, "R");
0209 }
0210
0211
0212
0213 interpolate_timecorr(ifeech, g_delaytime[ifeech], fpoly);
0214
0215
0216
0217 }
0218
0219
0220 TString tscan_fname = dir;
0221 tscan_fname += "/mbd_tpscan.txt";
0222 std::cout << tscan_fname << std::endl;
0223 std::ofstream tscan_file(tscan_fname);
0224 for (int ifeech = 0; ifeech < MbdDefs::MBD_N_FEECH; ifeech++)
0225 {
0226 if (mbdgeom->get_type(ifeech) == 1)
0227 {
0228 continue;
0229 }
0230
0231 tscan_file << feech[ifeech] << "\t" << mintdc[ifeech] << "\t" << maxtdc[ifeech] << "\t"
0232 << maxtdc[ifeech] - mintdc[ifeech] << "\t"
0233 << mintime[ifeech] << "\t" << maxtime[ifeech] << "\t" << maxtime[ifeech] - mintime[ifeech] << std::endl;
0234 }
0235 tscan_file.close();
0236
0237
0238 TString tcorr_fname = dir;
0239 tcorr_fname += "/mbd_timecorr.calib";
0240
0241 std::cout << "tcorr_fname " << tcorr_fname << std::endl;
0242 std::ofstream tcorr_file(tcorr_fname);
0243 for (int ifeech = 0; ifeech < MbdDefs::MBD_N_FEECH; ifeech++)
0244 {
0245 if (mbdgeom->get_type(ifeech) == 1)
0246 {
0247 continue;
0248 }
0249
0250
0251 tcorr_file << feech[ifeech] << "\t" << npts[ifeech] << "\t" << 0 << "\t" << 14985 << std::endl;
0252 for (int ipt = 0; ipt < NPOINTS; ipt++)
0253 {
0254 tcorr_file << timecorr[ifeech][ipt] << " ";
0255 if (ipt % 10 == 9)
0256 {
0257 tcorr_file << std::endl;
0258 }
0259 }
0260 }
0261 tcorr_file.close();
0262 }