3030
3131// O2 header
3232#include <TRDCalibration/CalibratorVdExB.h>
33+ #include "DetectorsBase/Propagator.h"
3334
3435#endif
3536
3637// This root macro reads in 'trdangreshistos.root' and
3738// performs the calibration fits manually as in CalibratorVdExB.cxx
3839// This can be used for checking if the calibration fits make sense.
39- void manualCalibFit ()
40+ void manualCalibFit (int runNumber = 563336 , bool usePreCorrFromCCDB = true )
4041{
4142 //----------------------------------------------------
4243 // TTree and File
4344 //----------------------------------------------------
44- std ::unique_ptr < TFile > inFilePtr (TFile ::Open ("trdangreshistos .root" ));
45+ std ::unique_ptr < TFile > inFilePtr (TFile ::Open ("trdcaliboutput .root" ));
4546 if (inFilePtr == nullptr ) {
4647 printf ("Input File could not be read!\n'" );
4748 return ;
@@ -59,19 +60,49 @@ void manualCalibFit()
5960 mNEntriesPerBinSum .fill (0 );
6061 tree -> SetBranchAddress ("mHistogramEntries[13500]" , & mHistogramEntries );
6162 tree -> SetBranchAddress ("mNEntriesPerBin[13500]" , & mNEntriesPerBin );
63+
64+ // use precorr values from ccdb
65+ // necessary when the angular residuals were calculated already using ccdb calibration (e.g. in a local run)
66+
67+ o2 ::trd ::CalVdriftExB * calObject ;
68+ if (usePreCorrFromCCDB ) {
69+ auto& ccdbmgr = o2 ::ccdb ::BasicCCDBManager ::instance ();
70+
71+ o2 ::ccdb ::CcdbApi ccdb ;
72+ ccdb .init ("http://alice-ccdb.cern.ch" );
73+ auto runDuration = ccdbmgr .getRunDuration (runNumber );
74+
75+ std ::map < std ::string , std ::string > metadata ;
76+ std ::map < std ::string , std ::string > headers ;
77+
78+ calObject = ccdb .retrieveFromTFileAny < o2 ::trd ::CalVdriftExB > ("TRD/Calib/CalVdriftExB" , metadata , runDuration .first + 60000 , & headers , "" , "" , "1689478811721" );
79+ }
80+
6281
6382 //----------------------------------------------------
6483 // Configure Fitter
6584 //----------------------------------------------------
6685 o2 ::trd ::FitFunctor mFitFunctor ;
6786 std ::array < std ::unique_ptr < TProfile > , 540 > profiles ; ///< profile histograms for each TRD chamber
87+ int counter = 0 ;
6888 for (int iDet = 0 ; iDet < 540 ; ++ iDet ) {
6989 mFitFunctor .profiles [iDet ] = std ::make_unique < TProfile > (Form ("profAngleDiff_%i" , iDet ), Form ("profAngleDiff_%i" , iDet ), 25 , -25.f , 25.f );
90+ if (usePreCorrFromCCDB ) {
91+ std ::cout <<iDet <<" " <<calObject -> getVdrift (iDet )<<" " <<calObject -> getExB (iDet )<<" " ;
92+ if (calObject -> isGoodExB (iDet )) counter ++ ;
93+ if (iDet %6 == 5 )std ::cout <<std ::endl ;
94+ mFitFunctor .vdPreCorr [iDet ] = calObject -> getVdriftDefaultAvg (iDet );
95+ mFitFunctor .laPreCorr [iDet ] = calObject -> getExBDefaultAvg (iDet );
96+ }
97+ }
98+ std ::cout << counter << " good entries in the CCDB " << std ::endl ;
99+ mFitFunctor .mAnodePlane = 3.35 ; // don't really care as long as it's not zero, this parameter could be removed
100+ mFitFunctor .lowerBoundAngleFit = 85 * TMath ::DegToRad ();
101+ mFitFunctor .upperBoundAngleFit = 105 * TMath ::DegToRad ();
102+ if (!usePreCorrFromCCDB ) {
103+ mFitFunctor .vdPreCorr .fill (1.546 );
104+ mFitFunctor .laPreCorr .fill (0.0 );
70105 }
71- mFitFunctor .lowerBoundAngleFit = 80 * TMath ::DegToRad ();
72- mFitFunctor .upperBoundAngleFit = 100 * TMath ::DegToRad ();
73- mFitFunctor .vdPreCorr .fill (1.546 );
74- mFitFunctor .laPreCorr .fill (0.0 );
75106
76107 //----------------------------------------------------
77108 // Loop
@@ -88,15 +119,18 @@ void manualCalibFit()
88119 //----------------------------------------------------
89120 // Fill profiles
90121 //----------------------------------------------------
122+ int nEntriesDetTotal [540 ] = {};
91123 for (int iDet = 0 ; iDet < 540 ; ++ iDet ) {
92124 for (int iBin = 0 ; iBin < 25 ; ++ iBin ) {
93125 auto angleDiffSum = mHistogramEntriesSum [iDet * 25 + iBin ];
94126 auto nEntries = mNEntriesPerBinSum [iDet * 25 + iBin ];
127+ nEntriesDetTotal [iDet ] += nEntries ;
95128 if (nEntries > 0 ) { // skip entries which have no entries; ?
96129 // add to the respective profile for fitting later on
97130 mFitFunctor .profiles [iDet ]-> Fill (2 * iBin - 25.f , angleDiffSum / nEntries , nEntries );
98131 }
99132 }
133+ printf ("Det %d: nEntries=%d \n" , iDet , nEntriesDetTotal [iDet ]);
100134 }
101135
102136 //----------------------------------------------------
@@ -105,16 +139,21 @@ void manualCalibFit()
105139 printf ("-------- Started fits\n" );
106140 std ::array < float , 540 > laFitResults {};
107141 std ::array < float , 540 > vdFitResults {};
142+
143+ TH1F * hVd = new TH1F ("hVd" , "v drift" , 150 , 0.5 , 2. );
144+ TH1F * hLa = new TH1F ("hLa" , "lorentz angle" , 200 , -25. , 25. );
145+
108146 for (int iDet = 0 ; iDet < 540 ; ++ iDet ) {
147+ if (nEntriesDetTotal [iDet ] < 75 ) continue ;
109148 mFitFunctor .currDet = iDet ;
110149 ROOT ::Fit ::Fitter fitter ;
111150 double paramsStart [2 ];
112- paramsStart [0 ] = 0. * TMath :: DegToRad () ;
151+ paramsStart [0 ] = 0. ;
113152 paramsStart [1 ] = 1. ;
114153 fitter .SetFCN < o2 ::trd ::FitFunctor > (2 , mFitFunctor , paramsStart );
115154 fitter .Config ().ParSettings (0 ).SetLimits (-0.7 , 0.7 );
116155 fitter .Config ().ParSettings (0 ).SetStepSize (.01 );
117- fitter .Config ().ParSettings (1 ).SetLimits (0. , 3. );
156+ fitter .Config ().ParSettings (1 ).SetLimits (0.01 , 3. );
118157 fitter .Config ().ParSettings (1 ).SetStepSize (.01 );
119158 ROOT ::Math ::MinimizerOptions opt ;
120159 opt .SetMinimizerType ("Minuit2" );
@@ -127,9 +166,26 @@ void manualCalibFit()
127166 auto fitResult = fitter .Result ();
128167 laFitResults [iDet ] = fitResult .Parameter (0 );
129168 vdFitResults [iDet ] = fitResult .Parameter (1 );
130- printf ("Det %d: la=%f\tvd=%f\n" , iDet , laFitResults [iDet ] * TMath ::RadToDeg (), vdFitResults [iDet ]);
169+ printf ("Det %d: la=%.3f +/- %.3f (precorr=:%.3f) \tvd=%.3f +/- %.3f (precorr=:%.3f) \t100*minValue=%f\n" , iDet , laFitResults [iDet ] * TMath ::RadToDeg (), fitResult .LowerError (0 ) * TMath ::RadToDeg (), mFitFunctor .laPreCorr [iDet ] * TMath ::RadToDeg (), vdFitResults [iDet ], fitResult .LowerError (1 ), mFitFunctor .vdPreCorr [iDet ], 100 * fitResult .MinFcnValue ());
170+ hVd -> Fill (vdFitResults [iDet ]);
171+ hLa -> Fill (laFitResults [iDet ]* TMath ::RadToDeg ());
131172 }
132173 printf ("-------- Finished fits\n" );
174+
175+ std ::cout <<"number of chambers with enough entries: " <<hVd -> GetEntries ()<<std ::endl ;;
176+ std ::cout <<"vdrift mean: " <<hVd -> GetMean ()<<" sigma: " <<hVd -> GetStdDev ()<<std ::endl ;
177+ std ::cout <<"lorentz angle mean: " <<hLa -> GetMean ()<<" sigma: " <<hLa -> GetStdDev ()<<std ::endl ;
178+
179+ TCanvas * c = new TCanvas ("c" , "c" , 1200 , 700 );
180+ c -> Divide (2 ,1 );
181+ c -> cd (1 );
182+ hVd -> SetLineColor (kBlue ); hVd -> SetLineWidth (2 );
183+ hVd -> Draw ();
184+ c -> cd (2 );
185+ hLa -> SetLineColor (kBlue ); hLa -> SetLineWidth (2 );
186+ hLa -> Draw ();
187+ c -> SaveAs ("VdExBValues.pdf" );
188+
133189
134190 //----------------------------------------------------
135191 // Write
0 commit comments