48 std::ifstream parfile(infile.c_str());
49 if( !parfile.fail() ){
50 for(
int i = 0; i < 5; ++i ){
57 std::cout <<
"HadronSaturation: WARNING - parameter file " << infile <<
" does not exist, using defaults..." << std::endl;
63 std::cout <<
"HadronSaturation: filling sample events..." << std::endl;
68 std::vector< TString > types;
69 types.push_back(
"pion");
70 types.push_back(
"kaon");
71 types.push_back(
"proton");
72 types.push_back(
"muon");
73 types.push_back(
"electron");
76 TFile* satFile =
new TFile(infilename);
78 for(
int i = 0; i < 4; ++i ){
79 TTree* satTree = (TTree*)satFile->Get(types[i]);
81 double satdedx, saterror, satbg, satcosth;
82 satTree->SetBranchAddress(
"dedx",&satdedx);
83 satTree->SetBranchAddress(
"error",&saterror);
84 satTree->SetBranchAddress(
"bg",&satbg);
85 satTree->SetBranchAddress(
"costh",&satcosth);
88 for(
unsigned int i = 0; i < satTree->GetEntries(); ++i ){
91 if( saterror == 0 )
continue;
93 m_dedx.push_back(satdedx);
94 m_dedxerror.push_back(saterror);
95 m_betagamma.push_back(satbg);
96 m_costheta.push_back(satcosth);
106 if( firstevent < 0 || (nevents+firstevent) > m_dedx.size() ){
107 std::cout <<
"HadronSaturation: trying to print events out of range (" << m_dedx.size() <<
")" << std::endl;
111 std::cout << std::endl << std::endl;
112 for(
int i = firstevent; i < nevents; ++i ){
113 std::cout <<
"Event " << i <<
":\t bg = " << m_betagamma[i] <<
"\t cos(theta) = " << m_costheta[i] <<
"\t dE/dx mean = " << m_dedx[i] <<
"\t dE/dx error = " << m_dedxerror[i] << std::endl;
115 std::cout << std::endl;
121 double absCosTheta = fabs(cosTheta);
122 double projection = pow(absCosTheta, power) +
delta;
123 double chargeDensity = D / projection;
124 double numerator = 1 +
alpha * chargeDensity;
125 double denominator = 1 + gamma * chargeDensity;
127 double I = D * ratio * numerator / denominator;
135 double absCosTheta = fabs(cosTheta);
136 double projection = pow(absCosTheta, power) +
delta;
138 double a =
alpha/projection;
139 double b = 1 - gamma/projection * (
I/ratio);
140 double c = -1.0 *
I/ratio;
142 if(
b == 0 && a == 0 ){
143 std::cout <<
"both a and b coefficiants for hadron correction are 0" << std::endl;
147 double D = (a != 0) ? (-
b + sqrt(
b *
b - 4.0 * a * c)) / (2.0 * a) : -c /
b;
150 D = (a != 0) ? (-
b - sqrt(
b *
b + 4.0 * a * c)) / (2.0 * a) : -c /
b;
163 unsigned int nevt = m_dedx.size();
164 double chisq = 0, dedxsum = 0;
165 std::vector< double > vdedxavg;
171 for(
unsigned int i = 0; i <
nevt; i++ ){
173 dedxcor =
D2I(m_costheta[i],
I2D(m_costheta[i],1.0,
alpha,gamma,
delta,power,ratio)*m_dedx[i],
alpha,gamma,
delta,power,ratio);
175 dedxcor =
D2I(m_costheta[i],m_dedx[i],
alpha,gamma,
delta,power,ratio);
178 if( (i+1)%m_cosbins == 0 ){
179 vdedxavg.push_back(dedxsum/m_cosbins);
186 for(
unsigned int i = 0; i <
nevt; i++ ){
188 dedxcor =
D2I(m_costheta[i],
I2D(m_costheta[i],1.0,
alpha,gamma,
delta,power,ratio)*m_dedx[i],
alpha,gamma,
delta,power,ratio);
190 dedxcor =
D2I(m_costheta[i],m_dedx[i],
alpha,gamma,
delta,power,ratio);
192 int j = (int)i/m_cosbins;
193 chisq += pow((dedxcor-vdedxavg[j])/m_dedxerror[i],2);
201 result = HC_obj->
myFunction(par[0],par[1],par[2],par[3],par[4]);
207 std::cout <<
"Performing the hadron saturation fit..." << std::endl;
210 TFitter* minimizer =
new TFitter(5);
213 TRandom* rand =
new TRandom();
215 minimizer->SetParameter(0,
"alpha",m_alpha,rand->Rndm()*0.001,0.0,0.5);
216 minimizer->SetParameter(1,
"gamma",m_gamma,rand->Rndm()*0.001,-2,2);
217 minimizer->SetParameter(2,
"delta",m_delta,rand->Rndm()*0.001,-2,2);
218 minimizer->SetParameter(3,
"power",m_power,rand->Rndm()*0.01,-5,5);
219 minimizer->SetParameter(4,
"ratio",m_ratio,rand->Rndm()*0.01,-100,100);
224 minimizer->ExecuteCommand(
"SET STR",
arg,1);
228 minimizer->ExecuteCommand(
"SET PRINT",
arg,1);
233 double fitpar[5], fiterr[5];
234 for(
int i = 0; i < 20; ++i ){
236 minimizer->SetParameter(0,
"alpha",m_alpha,rand->Rndm()*0.001,0.0,0.5);
237 minimizer->SetParameter(1,
"gamma",m_gamma,rand->Rndm()*0.001,-2,2);
238 minimizer->SetParameter(2,
"delta",m_delta,rand->Rndm()*0.001,-2,2);
239 minimizer->SetParameter(3,
"power",m_power,rand->Rndm()*0.01,-5,5);
240 minimizer->SetParameter(4,
"ratio",m_ratio,rand->Rndm()*0.01,-100,100);
242 int status = minimizer->ExecuteCommand(
"MIGRAD",
arg,1);
243 status = minimizer->ExecuteCommand(
"MIGRAD",
arg,1);
244 minimizer->PrintResults(1,0);
245 std::cout <<
"Fit status: " << status << std::endl;
248 while( status != 0 && counter < 10 ){
251 minimizer->SetParameter(0,
"alpha",m_alpha,rand->Rndm()*0.001,0.0,0.5);
252 minimizer->SetParameter(1,
"gamma",m_gamma,rand->Rndm()*0.001,-2,2);
253 minimizer->SetParameter(2,
"delta",m_delta,rand->Rndm()*0.001,-2,2);
254 minimizer->SetParameter(3,
"power",m_power,rand->Rndm()*0.01,-5,5);
255 minimizer->SetParameter(4,
"ratio",m_ratio,rand->Rndm()*0.01,-100,100);
257 status = minimizer->ExecuteCommand(
"MIGRAD",
arg,1);
258 std::cout <<
"Fit status: " << status << std::endl;
261 std::cout <<
"HadronSaturation::ERROR - BAD FIT!" << std::endl;
266 for(
int par = 0; par < 5; ++par ){
267 fitpar[par] = minimizer->GetParameter(par);
268 fiterr[par] = minimizer->GetParError(par);
271 std::cout <<
"HadronSaturation: fit results" << std::endl;
272 std::cout <<
"\t alpha (" << m_alpha <<
"): " << fitpar[0] <<
" +- " << fiterr[0] << std::endl;
273 std::cout <<
"\t gamma (" << m_gamma <<
"): " << fitpar[1] <<
" +- " << fiterr[1] << std::endl;
274 std::cout <<
"\t delta (" << m_delta <<
"): " << fitpar[2] <<
" +- " << fiterr[2] << std::endl;
275 std::cout <<
"\t power (" << m_power <<
"): " << fitpar[3] <<
" +- " << fiterr[3] << std::endl;
276 std::cout <<
"\t ratio (" << m_ratio <<
"): " << fitpar[4] <<
" +- " << fiterr[4] << std::endl;
280 double chi2, edm, errdef;
282 minimizer->GetStats(chi2,edm,errdef,nvpar,nparx);
283 std::cout <<
"\t\t Fit chi^2: " << chi2 << std::endl;
285 std::ofstream parfile;
286 parfile.open(
"sat-pars.fit.txt");
288 parfile << fitpar[0] << std::endl;
289 parfile << fitpar[1] << std::endl;
290 parfile << fitpar[2] << std::endl;
291 parfile << fitpar[3] << std::endl;
292 parfile << fitpar[4] << std::endl;
*********Class see also m_nmax DOUBLE PRECISION m_delta
double arg(const EvtComplex &c)
void printEvents(int firstevent, int nevents)
double myFunction(double alpha, double gamma, double delta, double power, double ratio)
double I2D(double cosTheta, double I, double alpha, double gamma, double delta, double power, double ratio) const
void fillSample(TString infilename)
double D2I(double cosTheta, double D, double alpha, double gamma, double delta, double power, double ratio) const
void setParameters(double par[])
static void minuitFunction(int &nDim, double *gout, double &result, double *para, int flg)