21 readLabels( cfg.
read<std::string>(
"xAxesFit" ), xAxesFit_ );
22 readLabels( cfg.
read<std::string>(
"yAxesFit" ), yAxesFit_ );
27 readVector( cfg.
read<std::string>(
"targetLabel" ), targetHistList_);
28 fitFuncName_ = cfg.
read<std::string>(
"fitFunctionName" );
29 fitFuncTitle_= cfg.
read<std::string>(
"fitFunctionTitle");
30 fitFuncType_ = cfg.
read<
int> (
"fitFunctionType" );
31 fitFuncLowerBound_= cfg.
read<
double>(
"fitLowerBound" );
32 fitFuncUpperBound_= cfg.
read<
double>(
"fitUpperBound" );
33 evalType_ = cfg.
read<
int>(
"evalType" );
36 std::cerr <<
"ERROR during reading of config file" << std::endl;
37 std::cerr <<
" misspelled variables in cfg ?" << std::endl;
38 std::cerr <<
" [--called in configBlockFit]" << std::endl;
52 for(
unsigned int idx=0; idx<targetHistList_.size(); ++idx){
53 if( statusOk ) statusOk=isInFitTargetList(targetHistList_[idx]);
69 std::cerr <<
"ERROR while filling target histogram" << std::endl;
70 std::cerr <<
" can't find prefix: " << target << std::endl;
85 TString refName( name );
88 refName.Remove(0, refName.First(
'_')+1);
93 for(
int idx=0; idx<hist.GetEntriesFast(); ++idx){
94 TH1F& cmp = *((TH1F*)(hist)[idx]);
95 TString buffer( cmp.GetName() );
96 if( buffer.BeginsWith( zip ) ){
97 TString cmpName( cmp.GetName() );
98 cmpName.Remove(0, cmpName.First(
'/')+1);
99 if( cmpName.BeginsWith(
FitTarget::Fit) && cmpName.Contains(refName) ){
104 std::cout <<
"WARNING: could not find required histogram fit_"
105 << refName <<
"_x" << std::endl
106 <<
" return reference to Null" << std::endl;
119 TString refName( name );
120 refName.Remove(0, refName.First(
'_')+1);
121 refName.Remove(refName.Last(
'_'), refName.Length());
126 for(
int idx=0; idx<hist.GetEntriesFast(); ++idx){
127 TH1F& cmp = *((TH1F*)(hist)[idx]);
128 TString buffer( cmp.GetName() );
129 if( buffer.BeginsWith( zip ) ){
131 TString cmpName( cmp.GetName() );
132 cmpName.Remove(0, cmpName.First(
'/')+1);
133 if( cmpName.BeginsWith(target) && cmpName.Contains(refName) ){
138 std::cout <<
"WARNING: could not find required histogram "
139 << target << refName << std::endl
140 <<
" return reference to Null" << std::endl;
147 return ( (!buffer.CompareTo(
FitTarget::Res ) && val>0.) ) ? 1./val : 1.;
154 htarget.SetBinContent( bin, func.
value( hfit ) ); htarget.SetBinError( bin, func.
valueError( hfit ) );
157 double norm=normalize(buffer, func.
value( hfit ));
158 htarget.SetBinContent( bin, norm*func.
spread( hfit ) ); htarget.SetBinError ( bin, norm*func.
spreadError( hfit ) );
166 htarget.SetBinContent( bin, func.
value( hfit ) ); htarget.SetBinError( bin, func.
valueError( hfit ) );
169 double norm=normalize(buffer, func.
value( hfit ));
170 htarget.SetBinContent( bin, norm*func.
spread( hfit ) ); htarget.SetBinError ( bin, norm*func.
spreadError( hfit ) );
178 htarget.SetBinContent( bin, func.
value( hfit ) ); htarget.SetBinError( bin, func.
valueError( hfit ) );
181 double norm=normalize(buffer, func.
value( hfit ));
182 htarget.SetBinContent( bin, norm*func.
spread( hfit ) ); htarget.SetBinError ( bin, norm*func.
spreadError( hfit ) );
190 htarget.SetBinContent( bin, func.
value( hfit ) ); htarget.SetBinError( bin, func.
valueError( hfit ) );
193 double norm=normalize(buffer, func.
value( hfit ));
194 htarget.SetBinContent( bin, norm*func.
spread( hfit ) ); htarget.SetBinError ( bin, norm*func.
spreadError( hfit ) );
201 if( !hfit.GetEntries()>0 )
return;
206 TString buffer(htarget.GetName());
207 buffer.Remove(0, buffer.First(
'/')+1);
208 buffer.Remove(buffer.First(
'_')+1, buffer.Length());
211 case kStabilizedGauss:
214 fillTargetHistogramBin(htarget, hfit, bin, buffer, func);
220 fillTargetHistogramBin(htarget, hfit, bin, buffer, func);
226 fillTargetHistogramBin(htarget, hfit, bin, buffer, func);
232 fillTargetHistogramBin(htarget, hfit, bin, buffer, func);
251 if(idx<(
int)axesIndex_.size()){
252 int jdx = axesIndex_[idx];
253 if( jdx<(
int)xAxesFit_.size() && jdx<(int)yAxesFit_.size() ){
254 setAxesStyle( hist, xAxesFit_[jdx].c_str(), yAxesFit_[jdx].c_str() );
256 else if( jdx<(
int)xAxesFit_.size() ){
257 setAxesStyle( hist, xAxesFit_[jdx].c_str(),
"events" );
261 setAxesStyle( hist, hist.GetName(),
"events" );
272 TPaveText*
text =
new TPaveText(0.25, 0.85, 0.95, 0.95,
"NDC");
273 text->SetBorderSize( 0 );
274 text->SetFillStyle( 4000 );
275 text->SetTextAlign( 12 );
276 text->SetTextSize ( 0.06 );
277 text->SetTextColor( 1 );
278 text->SetTextFont ( 62 );
281 TString buffer(targetHistList_[0]); buffer+=
"_";
282 TH1F&
target = findTargetHistogram(hist, zip, name, buffer);
283 double lowerEdge = target.GetBinLowEdge(bin+1);
284 double upperEdge = target.GetBinLowEdge(bin+1)+target.GetBinWidth(bin+1);
285 sprintf(labelname,
"[%3.0f GeV; %3.0f GeV]", lowerEdge, upperEdge );
286 text->AddText( labelname );
293 if( hist.GetFunction(fitFuncName_.c_str()) ){
294 TPaveText* pars =
new TPaveText(0.40, 0.55, 0.95, 0.70,
"NDC");
295 pars->SetBorderSize( 0 );
296 pars->SetFillStyle( 4000 );
297 pars->SetTextAlign( 12 );
298 pars->SetTextSize ( 0.06 );
299 pars->SetTextColor( 1 );
300 pars->SetTextFont ( 62 );
304 sprintf(parstring,
"#mu=%3.2f ; #sigma=%3.2f",
305 hist.GetFunction(fitFuncName_.c_str())->GetParameter( 1 ),
306 hist.GetFunction(fitFuncName_.c_str())->GetParameter( 2 ) );
308 pars->AddText( parstring );
319 TCanvas *canv =
new TCanvas(
"canv",
"fit histograms", 600, 600);
320 setCanvasStyle( *canv );
321 canv->SetGridx( 1 ); canv->SetLogx ( 0 );
322 canv->SetGridy( 1 ); canv->SetLogy ( 0 );
330 std::vector<TObjArray>::const_iterator
hist = sampleList_.begin();
331 for(
int idx=0; hist!=sampleList_.end(); ++
hist, ++idx){
335 TString
output( writeTo_.c_str() );
337 if(outputLabelList_.size()>=sampleList_.size())
338 output += outputLabelList_[idx];
342 TPostScript psFile( output, 111 );
350 for(
int jdx=0; jdx<(*hist).GetEntriesFast(); ++jdx){
351 TH1F& hfit = *((TH1F*)(*hist)[jdx]);
353 TString cmp( hfit.GetName() );
354 cmp.Remove(0, cmp.First(
'/')+1);
356 TString zip( hfit.GetName() );
357 zip.Remove(zip.First(
'/'), zip.Length());
361 std::cout << std::endl <<
"about to fit histogram: "
362 << hfit.GetName() <<
" as " << cmp << std::endl;
369 TString buffer( cmp );
370 int bin = buffer.Remove(0, buffer.Last(
'_')+1).Atoi();
372 hfit.SetLineWidth( 5 );
373 hfit.SetLineColor( 4 );
374 hfit.SetLineStyle( 1 );
375 hfit.SetMarkerStyle( 20 );
376 hfit.SetMarkerSize( 2.0 );
377 hfit.SetMarkerColor( 4 );
378 hfit.SetMaximum(1.5*hfit.GetMaximum());
379 setFitHistogramAxes( hfit, label++ );
383 StabilizedGauss func(fitFuncName_.c_str(), fitFuncType_, fitFuncLowerBound_, fitFuncUpperBound_);
391 addParLabelToFitHist( hfit );
392 addBinLabelToFitHist(*hist, bin, cmp, zip);
397 TLegend* leg =
new TLegend(0.25,0.70,0.95,0.87);
398 setLegendStyle( *leg );
399 leg->AddEntry( &hfit,
legend(idx).c_str(),
"PL" );
400 leg->AddEntry( hfit.GetFunction(fitFuncName_.c_str()), fitFuncTitle_.c_str(),
"L" );
404 if(jdx<((*hist).GetEntriesFast()-1))
delete leg;
419 TCanvas *canv =
new TCanvas(
"canv",
"fit histograms", 600, 600);
420 setCanvasStyle( *canv );
421 canv->SetGridx( 1 ); canv->SetLogx ( 0 );
422 canv->SetGridy( 1 ); canv->SetLogy ( 0 );
430 std::vector<TObjArray>::const_iterator
hist = sampleList_.begin();
431 for(
int idx=0; hist!=sampleList_.end(); ++
hist, ++idx){
439 for(
int jdx=0; jdx<(*hist).GetEntriesFast(); ++jdx){
440 TH1F& hfit = *((TH1F*)(*hist)[jdx]);
442 TString cmp( hfit.GetName() );
443 cmp.Remove(0, cmp.First(
'/')+1);
445 TString zip( hfit.GetName() );
446 zip.Remove(zip.First(
'/'), zip.Length());
451 TString
output( writeTo_.c_str() );
453 output += histList_[ jdx ];
455 if(outputLabelList_.size()>=sampleList_.size())
456 output += outputLabelList_[idx];
460 TPostScript psFile( output, 113 );
468 TString buffer( cmp );
469 int bin = buffer.Remove(0, buffer.Last(
'_')+1).Atoi();
471 hfit.SetLineWidth( 5 );
472 hfit.SetLineColor( 4 );
473 hfit.SetLineStyle( 1 );
474 hfit.SetMarkerStyle( 20 );
475 hfit.SetMarkerSize( 2.0 );
476 hfit.SetMarkerColor( 4 );
477 setFitHistogramAxes( hfit, label++ );
481 StabilizedGauss func(fitFuncName_.c_str(), fitFuncType_, fitFuncLowerBound_, fitFuncUpperBound_);
489 addParLabelToFitHist( hfit );
490 addBinLabelToFitHist( *hist, bin, cmp, zip );
495 TLegend* leg =
new TLegend(0.25,0.70,0.95,0.87);
496 setLegendStyle( *leg );
497 leg->AddEntry( &hfit,
legend(idx).c_str(),
"PL" );
498 leg->AddEntry( hfit.GetFunction(fitFuncName_.c_str()), fitFuncTitle_.c_str(),
"L" );
517 for(
unsigned int idx=0; idx<targetHistList_.size(); ++idx){
518 fillTargetHistogram(targetHistList_[idx]);
530 std::vector<TObjArray>::const_iterator
hist = sampleList_.begin();
531 for(; hist!=sampleList_.end(); ++
hist){
537 TString buffer( target );
538 if( isInFitTargetList(target) ){
539 for(
int jdx=0; jdx<(*hist).GetEntriesFast(); ++jdx){
540 TH1F& htarget = *((TH1F*)(*hist)[jdx]);
542 TString cmp( htarget.GetName() );
543 cmp.Remove(0, cmp.First(
'/')+1);
545 TString zip( htarget.GetName() );
546 zip.Remove(zip.First(
'/'), zip.Length());
547 if( cmp.BeginsWith( buffer ) ){
551 for(
int kdx=0; kdx<htarget.GetNbinsX(); ++kdx){
552 TH1F& hfit = findFitHistogram(*hist, zip, cmp, kdx);
553 fillTargetHistogramBin(htarget, hfit, (kdx+1));
568 if( isOutputRequested() ){
572 TString
name( output_ );
573 name.Remove(name.Last(
'.'), name.Length());
581 TFile
file( output_.c_str(),
"update" );
582 if( !
file.GetDirectory(rootOutDir_.c_str()) )
584 file.mkdir( rootOutDir_.c_str(), rootOutDir_.c_str() );
587 (
file.GetDirectory(rootOutDir_.c_str()))->Delete(
"*;*");
588 file.cd(rootOutDir_.c_str());
591 for(
unsigned int jdx=0; jdx<targetHistList_.size(); ++jdx){
592 TString buffer( targetHistList_[jdx] );
596 std::vector<TObjArray>::const_iterator
hist = sampleList_.begin();
597 for( ;hist!=sampleList_.end(); ++
hist){
598 for(
int idx=0; idx<(int)histList_.size(); ++idx){
599 TString cmp( ((TH1F*)(*hist)[idx])->GetName() );
600 if( cmp.BeginsWith( buffer ) ){
601 histFile << ((TH1F*)(*hist)[idx])->GetName() <<
"\n";
602 ((TH1F*)(*hist)[idx])->Write();
double spreadError(TH1F &hist)
T read(const std::string &key) const
double valueError(TH1F &hist)
void addBinLabelToFitHist(const TObjArray &, int &, TString &, TString &)
double valueError(TH1F &hist)
void configBlockFit(ConfigFile &)
TH1F & findFitHistogram(const TObjArray &, TString &, TString &, int &)
bool isInFitTargetList(std::string &)
double valueError(TH1F &hist)
double spreadError(TH1F &hist)
void readVector(std::string s, std::vector< T > &vec)
double valueError(TH1F &hist)
void addParLabelToFitHist(const TH1F &)
double spread(TH1F &hist)
void fillTargetHistograms()
double normalize(TString &, double)
static const char * Sigma
void fillTargetHistogram(std::string &)
bool checkTargetHistList()
void setFitHistogramAxes(TH1F &, int)
TH1F & findTargetHistogram(const TObjArray &, TString &, TString &, TString &)
double spread(TH1F &hist)
double spreadError(TH1F &hist)
double spreadError(TH1F &hist)
double spread(TH1F &hist)
void fillTargetHistogramBin(TH1F &, TH1F &, int)
double spread(TH1F &hist)