File indexing completed on 2025-08-05 08:19:43
0001
0002
0003
0004
0005 #include <iostream>
0006 #include <MbdCalib.h>
0007 #include <MbdDefs.h>
0008 #include <MbdGeomV1.h>
0009 #include "get_runstr.h"
0010
0011 #include <vector>
0012 #include <fstream>
0013
0014 #if defined(__CLING__)
0015 R__LOAD_LIBRARY(libmbd_io.so)
0016
0017 #endif
0018
0019 const int NPOINTS = 1000;
0020 Int_t _feech[MbdDefs::MBD_N_FEECH];
0021 Int_t _npts[MbdDefs::MBD_N_FEECH];
0022 Double_t _mintdc[MbdDefs::MBD_N_FEECH];
0023 Double_t _maxtdc[MbdDefs::MBD_N_FEECH];
0024 Double_t _mintime[MbdDefs::MBD_N_FEECH];
0025 Double_t _maxtime[MbdDefs::MBD_N_FEECH];
0026 Double_t _timecorr[MbdDefs::MBD_N_FEECH][NPOINTS];
0027
0028
0029
0030
0031
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 void interpolate_timecorr( const int ifeech, TGraphErrors *g, TF1 *f )
0119 {
0120 Int_t n = g->GetN();
0121 Double_t *x = g->GetX();
0122 Double_t *y = g->GetY();
0123
0124 g->Fit(f,"R");
0125
0126 g->Draw("ap");
0127 gPad->Modified();
0128 gPad->Update();
0129
0130 float mintime = TMath::MinElement( n, y );
0131 float maxtime = TMath::MaxElement( n, y );
0132 float mintdc = TMath::MinElement( n, x );
0133 float maxtdc = TMath::MaxElement( n, x );
0134 cout << ifeech << "\t" << mintime << "\t" << maxtime << "\t" << maxtime - mintime << endl;
0135 cout << "tdc\t" << mintdc << "\t" << maxtdc << endl;
0136
0137
0138 _feech[ifeech] = ifeech;
0139 _npts[ifeech] = NPOINTS;
0140 _mintdc[ifeech] = mintdc;
0141 _maxtdc[ifeech] = maxtdc;
0142 _mintime[ifeech] = mintime;
0143 _maxtime[ifeech] = maxtime;
0144
0145
0146
0147
0148
0149 double dstep = 14985./(NPOINTS-1);
0150 double tdc = 0;
0151 for (int istep=0; istep<NPOINTS; istep++)
0152 {
0153
0154 _timecorr[ifeech][istep] = g->Eval(tdc) - mintime;
0155
0156 if ( istep==0 || istep==NPOINTS-1 )
0157 {
0158 cout << "ch " << ifeech << "\t" << istep << "\t" << tdc << "\t" << _timecorr[ifeech][istep] << endl;
0159 }
0160
0161 tdc += dstep;
0162 }
0163
0164 }
0165
0166
0167 void make_timecorr(const char *rootfname = "calib_seb18-00029705-0000_mbdtimecalib.root")
0168 {
0169 MbdGeom *mbdgeom = new MbdGeomV1();
0170
0171
0172
0173 TString dir = "results/";
0174 dir += get_runstr(rootfname);
0175 dir.ReplaceAll("_mbdtimecalib","");
0176
0177 dir += "/";
0178
0179 TString name = "echo " + dir;
0180 gSystem->Exec( name );
0181 cout << name << endl;
0182
0183
0184
0185 TF1 *fpoly = new TF1("fpoly","pol4",0,15000);
0186 fpoly->SetParameters(28.,-0.0018,-1e-7,1.3e-11,-5e-16);
0187 fpoly->SetLineColor(4);
0188 TGraphErrors *g_delaytime[MbdDefs::MBD_N_FEECH];
0189 TFile *tfile = new TFile(rootfname,"READ");
0190 for (int ifeech=0; ifeech<MbdDefs::MBD_N_FEECH; ifeech++)
0191 {
0192 if ( mbdgeom->get_type(ifeech) == 1 ) continue;
0193
0194 name = "g_delaytime"; name += ifeech;
0195 g_delaytime[ifeech] = (TGraphErrors*)tfile->Get(name);
0196 cout << name << endl;
0197
0198
0199 if ( ifeech==0 )
0200 {
0201 g_delaytime[ifeech]->Fit(fpoly,"R");
0202 }
0203
0204
0205
0206 interpolate_timecorr( ifeech, g_delaytime[ifeech], fpoly );
0207
0208
0209
0210 }
0211
0212
0213 TString tscan_fname = dir; tscan_fname += "/mbd_tpscan.txt";
0214 cout << tscan_fname << endl;
0215 ofstream tscan_file( tscan_fname );
0216 for (int ifeech=0; ifeech<MbdDefs::MBD_N_FEECH; ifeech++)
0217 {
0218 if ( mbdgeom->get_type(ifeech) == 1 ) continue;
0219
0220 tscan_file << _feech[ifeech] << "\t" << _mintdc[ifeech] << "\t" << _maxtdc[ifeech] << "\t"
0221 << _maxtdc[ifeech] - _mintdc[ifeech] << "\t"
0222 << _mintime[ifeech] << "\t" << _maxtime[ifeech] << "\t" << _maxtime[ifeech] - _mintime[ifeech] << endl;
0223 }
0224 tscan_file.close();
0225
0226
0227
0228 TString tcorr_fname = dir; tcorr_fname += "/mbd_timecorr.calib";
0229
0230 cout << "tcorr_fname " << tcorr_fname << endl;
0231 ofstream tcorr_file( tcorr_fname );
0232 for (int ifeech=0; ifeech<MbdDefs::MBD_N_FEECH; ifeech++)
0233 {
0234 if ( mbdgeom->get_type(ifeech) == 1 ) continue;
0235
0236
0237 tcorr_file << _feech[ifeech] << "\t" << _npts[ifeech] << "\t" << 0 << "\t" << 14985 << endl;
0238 for (int ipt=0; ipt<NPOINTS; ipt++)
0239 {
0240 tcorr_file << _timecorr[ifeech][ipt] << " ";
0241 if ( ipt%10 == 9 ) tcorr_file << endl;
0242 }
0243 }
0244 tcorr_file.close();
0245 }
0246