6 #include <calobase/RawTower.h>
7 #include <calobase/RawTowerContainer.h>
8 #include <calobase/RawTowerDefs.h>
10 #include <phparameter/PHParameters.h>
22 #include <boost/format.hpp>
38 #include <ROOT/TThreadExecutor.hxx>
39 #include <ROOT/TThreadedObject.hxx>
45 #include "Math/WrappedTF1.h"
46 #include "Math/WrappedMultiTF1.h"
47 #include "Fit/BinData.h"
48 #include "Fit/UnBinData.h"
49 #include "HFitInterface.h"
51 #include "Fit/Chi2FCN.h"
53 #include "Math/Functor.h"
63 Double_t
v1 = par[0]*
h_template->Interpolate(x[0]-par[1])+par[2];
73 ROOT::TThreadExecutor
t(_nthreads);
74 auto func = [&](std::vector<float> &
v) {
75 int size1 =
v.size()-1;
76 auto h =
new TH1F(Form(
"h_%d",(
int)
round(
v.at(size1))),
"",size1,0,size1);
79 for (
int i = 0;
i < size1;
i++)
81 h->SetBinContent(
i+1,
v.at(
i));
82 if (
v.at(
i)>maxheight)
91 pedestal= 0.5* (
v.at(maxbin - 4) +
v.at(maxbin-5));
95 pedestal=(
v.at(maxbin - 4));
99 pedestal = 0.5* (
v.at(size1-3) +
v.at(size1-2));
101 auto f =
new TF1(Form(
"f_%d",(
int)
round(
v.at(size1))),template_function,0,31,3);
102 ROOT::Math::WrappedMultiTF1 * fitFunction =
new ROOT::Math::WrappedMultiTF1(*
f, 3 );
103 ROOT::Fit::BinData
data(
v.size()-1,1);
104 ROOT::Fit::FillData(
data,
h);
105 ROOT::Fit::Chi2Function *EPChi2 =
new ROOT::Fit::Chi2Function(
data, *fitFunction);
106 ROOT::Fit::Fitter *fitter =
new ROOT::Fit::Fitter();
107 fitter->Config().MinimizerOptions().SetMinimizerType(
"GSLMultiFit");
108 double params[] = {
static_cast<double>(maxheight),static_cast<double>(maxbin-5),
static_cast<double>(
pedestal)};
109 fitter->Config().SetParamsSettings(3,params);
110 fitter->FitFCN(*EPChi2,0,
data.Size(),
true);
111 for (
int i =0;
i<3;
i++)
113 v.push_back(
f->GetParameter(
i));
123 t.Foreach(func, chnlvector);
125 int size3 = chnlvector.size();
126 std::vector<std::vector<float>> fit_params;
127 std::vector<float> fit_params_tmp;
128 for (
int i = 0;
i < size3;
i++)
130 std::vector<float> tv = chnlvector.at(
i);
131 int size2 = tv.size();
132 for (
int q = 3; q > 0;q--)
134 fit_params_tmp.push_back(tv.at(size2-q));
136 fit_params.push_back(fit_params_tmp);
137 fit_params_tmp.clear();
151 int size1 = chnlvector.size();
154 for (
int i = 0;
i < size1;
i++)
156 h_data->SetBinContent(
i+1,chnlvector.at(
i));
157 if (chnlvector.at(
i)>maxheight)
159 maxheight = chnlvector.at(
i);
166 pedestal= 0.5* ( chnlvector.at(maxbin - 4) + chnlvector.at(maxbin-5));
170 pedestal=( chnlvector.at(maxbin - 4));
174 pedestal = 0.5* ( chnlvector.at(size1-3) + chnlvector.at(size1-2));
176 ROOT::Math::WrappedMultiTF1 fitFunction(*f_fit, 3 );
177 ROOT::Fit::BinData
data(chnlvector.size()-1,1);
178 ROOT::Fit::FillData(
data,h_data);
179 ROOT::Fit::Chi2Function EPChi2(
data, fitFunction);
180 ROOT::Fit::Fitter fitter;
181 fitter.Config().MinimizerOptions().SetMinimizerType(
"GSLMultiFit");
182 double params[] = {
static_cast<double>(maxheight),static_cast<double>(maxbin-5),
static_cast<double>(
pedestal)};
183 fitter.Config().SetParamsSettings(3,params);
184 fitter.FitFCN(EPChi2,0,
data.Size(),
true);
186 std::vector<float> fit_params;
187 for (
int q = 0; q < 3;q++)
189 fit_params.push_back(f_fit->GetParameter(q));
204 , _calib_towers(nullptr)
205 , _raw_towers(nullptr)
207 , _calib_tower_node_prefix(
"CALIB")
208 , _raw_tower_node_prefix(
"RAW")
211 , template_input_file(
"/gpfs/mnt/gpfs02/sphenix/user/trinn/fitting_algorithm_playing/prdfcode/prototype/offline/packages/Prototype4/templates.root")
212 , _calib_params(name)
213 , _fit_type(kPowerLawDoubleExpWithGlobalFitConstraint)
225 std::cout <<
Name() <<
"::" <<
detector <<
"::" << __PRETTY_FUNCTION__
226 <<
" - print calibration parameters: " << endl;
234 h_template =
static_cast<TProfile*
>(fin->Get(
"hp_electrons_fine_emcal_36_8GeV"));
235 h_template->SetDirectory(0);
240 h_data =
new TH1F(
"h_data",
"",32,0,32);
244 ROOT::EnableThreadSafety();
254 std::cout <<
Name() <<
"::" <<
detector <<
"::" << __PRETTY_FUNCTION__
255 <<
"Process event entered" << std::endl;
258 map<int, double> parameters_constraints;
265 <<
Name() <<
"::" <<
detector <<
"::" << __PRETTY_FUNCTION__
266 <<
"Extract global fit parameter for constraining individual fits"
270 vector<float> waveforms;
271 vector<vector<float>> waveforms2;
275 for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
289 waveforms.push_back(count);
290 waveforms2.push_back(waveforms);
297 for (rtiter = begin_end.first; rtiter != begin_end.second; ++rtiter)
307 std::vector<float>
values = pulse_quantification.at(towernumber);
314 pulse_quantification.clear();
509 std::cerr <<
Name() <<
"::" <<
detector <<
"::" << __PRETTY_FUNCTION__
510 <<
"DST Node missing, doing nothing." << std::endl;
511 throw std::runtime_error(
512 "Failed to find DST node in RawTowerCalibration::CreateNodes");
520 std::cerr <<
Name() <<
"::" << detector <<
"::" << __PRETTY_FUNCTION__
524 " node in RawTowerCalibration::CreateNodes");
530 dstiter.
findFirst(
"PHCompositeNode", detector));
534 dstNode->addNode(DetNode);
547 DetNode->addNode(towerNode);