319 TCanvas *
c =
new TCanvas();
326 RooRealVar meanPos(
"<E/p>+",
"meanPos",1,0.,2.8,
"") ;
327 RooRealVar meanNeg(
"<E/p>-",
"meanNeg",1,0.,2.8,
"") ;
328 RooRealVar
sigma(
"#sigma",
"sigma",0.1,0,5,
"") ;
329 RooRealVar alpha(
"#alpha",
"alpha",-1,-100,-0.0001,
"") ;
330 RooRealVar
n(
"n",
"n",1,0.1,1000,
"") ;
333 RooRealVar LandauMeanPos (
"LandauM+",
"LandauMeanPos", 1,0.7,1.5,
"");
334 LandauMeanPos.setConstant(kFALSE);
335 RooRealVar LandauMeanNeg (
"LandauM-",
"LandauMeanNeg", 1,0.7,1.5,
"");
336 LandauMeanNeg.setConstant(kFALSE);
337 RooRealVar LandauS (
"Landau #sigma",
"Landau Sigma", 0.1,0,5,
"");
338 LandauS.setConstant(kFALSE);
341 RooGaussian gaussianPos(
"PosGauss",
"Initial Gauss", eOverP, meanPos,
sigma);
342 RooGaussian gaussianNeg(
"NegGauss",
"Initial Gauss", eOverP, meanNeg,
sigma);
343 RooCBShape crystalBallPos(
"PosCB",
"Crystal Ball shape", eOverP, meanPos,
sigma, alpha,
n);
344 RooCBShape crystalBallNeg(
"NegCB",
"Crystal Ball shape", eOverP, meanNeg,
sigma, alpha,
n);
345 RooLandau LandauPos (
"PosLandau",
"Initial Landau", eOverP, LandauMeanPos, LandauS);
346 RooLandau LandauNeg (
"NegLandau",
"Initial Landau", eOverP, LandauMeanNeg, LandauS);
349 RooFFTConvPdf LcwGPos (
"LcwG_Pos",
"Landau (x) Gauss", eOverP, LandauPos, gaussianPos);
350 RooFFTConvPdf LcwGNeg (
"LcwG_Neg",
"Landau (x) Gauss", eOverP, LandauNeg, gaussianNeg);
354 eOverP.setRange(
"fitGauss",0.5,1.5);
355 eOverP.setRange(
"fitLandau",0.5,1.5);
356 eOverP.setRange(
"final",0.0,3.0);
357 eOverP.setRange(
"finalFit",0.8,2.5);
363 static const int nBinsX = meanPlotPos->GetXaxis()->GetNbins();
364 static const int nBinsY = meanPlotPos->GetYaxis()->GetNbins();
366 RooAbsData* absDataSetPos = originalDataSet->reduce(
Cut(
"charge > 0"+ additionalCut) );
367 RooAbsData* absDataSetNeg = originalDataSet->reduce(
Cut(
"charge < 0"+ additionalCut) );
368 RooDataSet* dataSetPos =
dynamic_cast<RooDataSet*
>( absDataSetPos );
369 RooDataSet* dataSetNeg =
dynamic_cast<RooDataSet*
>( absDataSetNeg );
370 RooArgSet vars(xvar,yvar,eOverP);
372 RooDataSet* binnedDataPos[nBinsX][nBinsY];
373 RooDataSet* binnedDataNeg[nBinsX][nBinsY];
376 for(
int xvarStep = 0; xvarStep<nBinsX; xvarStep++){
377 for(
int yvarStep = 0; yvarStep<nBinsY; yvarStep++){
379 TString rangeName = xvar.getTitle() +
"Bin";
380 rangeName += xvarStep;
381 rangeName +=
"_"+yvar.getTitle()+
"Bin";
382 rangeName += yvarStep;
384 binnedDataPos[xvarStep][yvarStep] = (RooDataSet*)originalDataSet->emptyClone() ;
385 binnedDataNeg[xvarStep][yvarStep] = (RooDataSet*)originalDataSet->emptyClone() ;
387 binnedDataPos[xvarStep][yvarStep]->SetName(rangeName+
"_Pos");
388 binnedDataNeg[xvarStep][yvarStep]->SetName(rangeName+
"_Neg");
397 for (
int i=0;
i<dataSetPos->numEntries();
i++) {
398 const RooArgSet*
args = dataSetPos->get(
i);
400 int globalbin = meanPlotPos->FindBin(xvar.getVal(),yvar.getVal());
402 meanPlotPos->GetBinXYZ(
globalbin,binx,biny,binz);
403 binnedDataPos[binx-1][biny-1]->add(*
args);
406 for (
int i=0;
i<dataSetNeg->numEntries();
i++) {
407 const RooArgSet*
args = dataSetNeg->get(
i);
409 int globalbin = meanPlotNeg->FindBin(xvar.getVal(),yvar.getVal());
411 meanPlotNeg->GetBinXYZ(
globalbin,binx,biny,binz);
412 binnedDataNeg[binx-1][biny-1]->add(*
args);
418 for(
int xvarStep = 0; xvarStep<nBinsX; xvarStep++){
419 for(
int yvarStep = 0; yvarStep<nBinsY; yvarStep++){
421 TString rangeName = xvar.getTitle() +
"Bin";
422 rangeName += xvarStep;
423 rangeName +=
"_"+yvar.getTitle()+
"Bin";
424 rangeName += yvarStep;
427 RooPlot* framePos = eOverP.frame(
Title(
"E/P pos"),
Range(
"final"));
428 RooPlot* frameNeg = eOverP.frame(
Title(
"E/P neg"),
Range(
"final"));
431 RooDataSet* smallDataSetPos = binnedDataPos[xvarStep][yvarStep];
432 RooDataSet* smallDataSetNeg = binnedDataNeg[xvarStep][yvarStep];
435 smallDataSetPos->plotOn(framePos,LineColor(kBlue),MarkerColor(kBlue));
436 smallDataSetNeg->plotOn(frameNeg,LineColor(kRed),MarkerColor(kRed));
448 RooCategory
sample(
"sample",
"sample");
451 RooDataSet combData(
"combData",
"combined data",eOverP,
Index(
sample),Import(
"Pos",*smallDataSetPos),Import(
"Neg",*smallDataSetNeg));
457 RooSimultaneous simPdfGS(
"simPdfGS",
"simultaneous pdf",
sample);
458 simPdfGS.addPdf(gaussianPos,
"Pos");
459 simPdfGS.addPdf(gaussianNeg,
"Neg");
461 RooSimultaneous simPdfCB(
"simPdfCB",
"simultaneous pdf",
sample);
462 simPdfCB.addPdf(crystalBallPos,
"Pos");
463 simPdfCB.addPdf(crystalBallNeg,
"Neg");
465 RooSimultaneous simPdfLnd(
"simPdfLnd",
"simultaneous pdf",
sample);
466 simPdfLnd.addPdf(LandauPos,
"Pos");
467 simPdfLnd.addPdf(LandauNeg,
"Neg");
469 RooSimultaneous simPdfLcwG(
"simPdfLcwG",
"simultaneous pdf",
sample);
470 simPdfLcwG.addPdf(LcwGPos,
"Pos");
471 simPdfLcwG.addPdf(LcwGNeg,
"Neg");
477 double fitMeanPos = -999.;
478 double fitMeanNeg = -999.;
479 double fitSigma = -999.;
482 eOverP.setRange(
"fitGauss_Pos",0.5,1.5);
483 eOverP.setRange(
"fitGauss_Neg",0.5,1.5);
485 RooFitResult* fitResult = simPdfGS.fitTo(combData,
Range(
"fitGauss"),SplitRange(),Save());
487 std::cout <<
"WARNING:: FIRST GAUSSIAN FIT PRODUCED A FIT RESULT" <<std::endl;
489 std::cout <<
"WARNING:: FIRST GAUSSIAN FIT DID NOT PRODUCE A FIT RESULT" <<std::endl;
491 fitMeanPos = meanPos.getVal();
492 fitMeanNeg = meanNeg.getVal();
493 fitSigma =
sigma.getVal();
495 eOverP.setRange(
"fitGauss_Pos",fitMeanPos-2*fitSigma,fitMeanPos+2*fitSigma);
496 eOverP.setRange(
"fitGauss_Neg",fitMeanNeg-2*fitSigma,fitMeanNeg+2*fitSigma);
497 if ( fitResult && fitResult->status() != 0){
498 std::cout <<
"WARNING:: FIRST GAUSSIAN FIT DID NOT CONVERGE" <<std::endl;
502 eOverP.setRange(
"fitGauss_Pos",0.1,1.9);
503 eOverP.setRange(
"fitGauss_Neg",0.1,1.9);
507 fitResult = simPdfGS.fitTo(combData,
Range(
"fitGauss"),SplitRange(),Save() );
508 if ( fitResult && fitResult->status() != 0){
509 std::cout <<
"WARNING::SECOND GAUSSIAN FIT DID NOT CONVERGE" <<std::endl;
538 if (fitResult)
delete fitResult;
539 fitMeanPos = meanPos.getVal();
540 fitMeanNeg = meanNeg.getVal();
541 fitSigma =
sigma.getVal();
543 eOverP.setRange(
"fitGauss_Pos",fitMeanPos-1.25*fitSigma,fitMeanPos+1*fitSigma);
544 eOverP.setRange(
"fitGauss_Neg",fitMeanNeg-1.25*fitSigma,fitMeanNeg+1*fitSigma);
547 fitResult = simPdfGS.fitTo(combData,
Range(
"fitGauss"),SplitRange(), Save() );
548 if ( fitResult && fitResult->status() != 0){
549 std::cout <<
"WARNING::FINAL GAUSSIAN FIT DID NOT CONVERGE" <<std::endl;
555 if(fitResult)
delete fitResult;
581 eOverP.setRange(
"finalFit_Pos",fitMeanPos-1.5*fitSigma,2.5);
582 eOverP.setRange(
"finalFit_Neg",fitMeanNeg-1.5*fitSigma,2.5);
584 if (fitMeanPos-1.5*fitSigma > 1.4 )
585 eOverP.setRange(
"finalFit_Pos",1.2,2.5);
586 if (fitMeanNeg-1.5*fitSigma > 1.4 )
587 eOverP.setRange(
"finalFit_Neg",1.2,2.5);
590 eOverP.setRange(
"finalFit_Pos",0.8,2.5);
591 eOverP.setRange(
"finalFit_Neg",0.8,2.5);
604 fitResult = simPdfCB.fitTo(combData,
Range(
"finalFit"),SplitRange(), Save() ) ;
605 crystalBallPos.plotOn(framePos,LineColor(kAzure-2),
Range(
"finalFit_Pos"),NormRange(
"finalFit_Pos"));
606 crystalBallNeg.plotOn(frameNeg,LineColor(kRed-7),
Range(
"finalFit_Neg"),NormRange(
"finalFit_Neg"));
619 if(simCount > 5)
break;
620 fitResult = simPdfLcwG.fitTo(combData,
Range(
"finalFit"),SplitRange(), Save() ) ;
622 }
while(fitResult && ( fitResult->status() != 0 || fitResult->covQual() != 3 ));
624 LcwGPos.plotOn(framePos,LineColor(kAzure-2),
Range(
"finalFit_Pos"),NormRange(
"finalFit_Pos"));
625 LcwGNeg.plotOn(frameNeg,LineColor(kRed-7),
Range(
"finalFit_Neg"),NormRange(
"finalFit_Neg"));
631 cout <<
" ** fit_EoverP ** Please type RETURN to continue:\n>";
637 meanPlotPos->SetBinContent(xvarStep+1,yvarStep+1,meanPos.getVal());
638 meanPlotPos->SetBinError (xvarStep+1,yvarStep+1,meanPos.getError());
639 meanPlotNeg->SetBinContent(xvarStep+1,yvarStep+1,meanNeg.getVal());
640 meanPlotNeg->SetBinError (xvarStep+1,yvarStep+1,meanNeg.getError());
642 if( fitResult && ( fitResult->status() != 0 || fitResult->covQual() != 3 ) ){
643 std::cout <<
"WARNING::FINAL SIM FIT DID NOT CONVERGE FULLY" <<std::endl;
644 meanPlotPos->SetBinContent(xvarStep+1,yvarStep+1,1);
645 meanPlotPos->SetBinError (xvarStep+1,yvarStep+1,0.5);
646 meanPlotNeg->SetBinContent(xvarStep+1,yvarStep+1,1);
647 meanPlotNeg->SetBinError (xvarStep+1,yvarStep+1,0.5);
650 if(fitResult)
delete fitResult;
656 frameNeg->Draw(
"same");
659 TString* xvarTString =
new TString(xvar.getTitle());
660 TString* yvarTString =
new TString(yvar.getTitle());
662 const char *yvarChar = *yvarTString;
663 const char *xvarChar = *xvarTString;
666 myText(0.25,0.96,kBlack,Form(
"Slice %01.2f< %s <%01.2f, %01.2f< %s <%01.2f"
667 ,meanPlotPos->GetXaxis()->GetBinLowEdge(xvarStep+1)
669 ,meanPlotPos->GetXaxis()->GetBinLowEdge(xvarStep+2)
670 ,meanPlotPos->GetYaxis()->GetBinLowEdge(yvarStep+1)
672 ,meanPlotPos->GetYaxis()->GetBinLowEdge(yvarStep+2)) );
674 myMarkerText(0.65,0.85,kBlue,20,Form(
"e^{+}, <E/p> %01.3f #pm %01.3f",meanPlotPos->GetBinContent(xvarStep+1,yvarStep+1), meanPlotNeg->GetBinError(xvarStep+1,yvarStep+1) ),1.0,0.03);
675 myMarkerText(0.65,0.80,kRed,20,Form(
"e^{-}, <E/p> %01.3f #pm %01.3f",meanPlotNeg->GetBinContent(xvarStep+1,yvarStep+1), meanPlotPos->GetBinError(xvarStep+1,yvarStep+1) ),1.0,0.03);
678 c->Print(
PATH+
"new_eoverp_plots.pdf");
682 delete smallDataSetPos;
683 delete smallDataSetNeg;
690 const UInt_t Number = 3;
691 Double_t
Green[Number] = { 0.00, 1.00, 0.00};
692 Double_t
Red[Number] = { 1.00, 0.10, 0.00};
693 Double_t Blue[Number] = { 0.10, 0.10, 1.00};
694 Double_t Length[Number] = { 0.00, 0.50, 1.00 };
700 clone->Divide(meanPlotNeg);
703 TH2F* clone2 =(
TH2F*) meanPlotPos->Clone();
704 clone2->Add( meanPlotNeg, -1);
705 clone2->SetContour(
nb);
707 Double_t minPlot,maxPlot;
710 c->SetRightMargin(0.12);
715 minPlot=
clone->GetMinimum();
716 maxPlot=
clone->GetMaximum();
717 if (maxPlot-1 > 1-minPlot)
clone->SetMinimum(2-maxPlot);
718 else clone->SetMaximum(2-minPlot);
720 c->Print(
PATH+
"new_eoverp_plots.pdf");
722 meanPlotPos->Draw(
"colz");
723 meanPlotPos->SetContour(
nb);
726 minPlot= meanPlotPos->GetMinimum();
727 maxPlot= meanPlotPos->GetMaximum();
728 if (maxPlot-1 > 1-minPlot) meanPlotPos->SetMinimum(2-maxPlot);
729 else meanPlotPos->SetMaximum(2-minPlot);
731 c->Print(
PATH+
"new_eoverp_plots.pdf");
733 meanPlotNeg->Draw(
"colz");
734 meanPlotNeg->SetContour(
nb);
737 minPlot= meanPlotNeg->GetMinimum();
738 maxPlot= meanPlotNeg->GetMaximum();
739 if (maxPlot-1 > 1-minPlot) meanPlotNeg->SetMinimum(2-maxPlot);
740 else meanPlotNeg->SetMaximum(2-minPlot);
742 c->Print(
PATH+
"new_eoverp_plots.pdf");
745 pull->GetXaxis()->SetTitle(
"Fit Pull");
746 pull->GetYaxis()->SetTitle(
"Entries per 0.2");
748 c->SetRightMargin(0.03);
749 TF1 myGauss(
"myGaus",
"gaus");
750 for(
int xvarStep(0); xvarStep<nBinsX; ++xvarStep){
751 for(
int yvarStep(0); yvarStep<nBinsY; ++yvarStep){
752 double R =
clone->GetBinContent(xvarStep+1,yvarStep+1);
753 std::cout <<
"INFO : R "<<
R <<
" Ratio delta " << (1-
R)/(1+
R) <<
" Diff Delta "<< clone2->GetBinContent(xvarStep+1,yvarStep+1)/-2. <<
" Diff Delta "<< 1-(clone2->GetBinContent(xvarStep+1,yvarStep+1)/-2.)/((1-
R)/(1+
R)) <<std::endl;
754 pull->Fill( ( 1-
clone->GetBinContent(xvarStep+1,yvarStep+1))/
clone->GetBinError (xvarStep+1,yvarStep+1) );
759 myMarkerText(0.7,0.85,kWhite,1,Form(
"Gaussian, #mu = %01.3f #pm %01.3f",myGauss.GetParameter(1), myGauss.GetParError(1) ),1.0,0.03);
760 myMarkerText(0.7,0.80,kWhite,1,Form(
"Gaussian, #sigma = %01.3f #pm %01.3f",myGauss.GetParameter(2), myGauss.GetParError(2) ),1.0,0.03);
761 myMarkerText(0.7,0.75,kWhite,1,Form(
"Mean, = %01.3f #pm %01.3f",
pull->GetMean(),
pull->GetMeanError() ),1.0,0.03);
762 myMarkerText(0.7,0.70,kWhite,1,Form(
"RMS, = %01.3f #pm %01.3f",
pull->GetRMS(),
pull->GetRMSError() ),1.0,0.03);
764 c->Print(
PATH+
"new_eoverp_plots.pdf");