ATLAS Offline Software
Loading...
Searching...
No Matches
run_EoverP.cxx File Reference
#include "RooGlobalFunc.h"
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooAbsData.h"
#include "RooDataHist.h"
#include "RooGaussian.h"
#include "RooLandau.h"
#include "RooChebychev.h"
#include "RooAddPdf.h"
#include "RooExtendPdf.h"
#include "RooCBShape.h"
#include "RooNovosibirsk.h"
#include "RooFFTConvPdf.h"
#include "RooExponential.h"
#include "RooSimultaneous.h"
#include "RooPolynomial.h"
#include "RooFitResult.h"
#include "RooCategory.h"
#include "RooBinning.h"
#include "RooWorkspace.h"
#include "RooChi2Var.h"
#include "RooMinuit.h"
#include "RooFormulaVar.h"
#include "RooPlot.h"
#include <TFile.h>
#include <TH2F.h>
#include <TH3F.h>
#include <TH1D.h>
#include <TF1.h>
#include <TMath.h>
#include <TTree.h>
#include <TChain.h>
#include <TColor.h>
#include <TGraphErrors.h>
#include <TCanvas.h>
#include <TProfile.h>
#include <TString.h>
#include <iostream>
#include <TLegend.h>
#include <iomanip>
#include <cmath>
#include "TROOT.h"
#include "THStack.h"
#include "AtlasStyle.C"

Go to the source code of this file.

Functions

void initialize ()
int main ()
void makePlots (RooAbsData *originalDataSet, RooRealVar &eOverP, RooRealVar &eta, int nBinsEta, RooRealVar &phi, int nBinsPhi, RooRealVar &Et, TString extraCuts="")
void makeFits (RooAbsData *originalDataSet, RooRealVar &eOverP, RooRealVar &eta, RooRealVar &phi, TH2F *meanPlotPos, TH2F *meanPlotNeg, TString additionalCut="")
void makeSlicePlots (TH2F *pos, TH2F *neg, bool sliceInEta)
void makeRatioPlots (TH1D *h1, TH1D *h2, TString name)
TH2F * makeCorrectionHist ()
double getCorrections (TH2F *corrections, double eta, double phi, double Et, double charge)
void makeScalingHist (TString inputDir)
void run_EoverP (TString fileName="../share/eoverpValidationOut.root", int refit=2, int netabins=12, int nphibins=12)

Variables

TString PATH = "./Results/"

Function Documentation

◆ getCorrections()

double getCorrections ( TH2F * corrections,
double eta,
double phi,
double Et,
double charge )

Definition at line 907 of file run_EoverP.cxx.

907 {
908 //Q/p_constr=Q/p_recon*(1 + pT_recon*Q*delta)
909 if(!corrections)
910 return 1;
911
912
913 std::cout << "INFO :: GetCorrection -> Bin number "; //<< std::endl;
914
915 int binNumber = corrections->FindBin(eta, phi);
916
917 //std::cout<< binNumber << std::endl;
918
919
920 std::cout << "INFO :: GetCorrection -> delta" << std::endl;
921 double delta = corrections->GetBinContent(binNumber);
922
923 return 1+charge*Et*delta;
924}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
double charge(const T &p)
Definition AtlasPID.h:997

◆ initialize()

void initialize ( )

Definition at line 894 of file run_EoverP.cxx.

894 {
895 // Set up ATLAS style and other things before we get started
896 gROOT->LoadMacro("AtlasStyle.C");
898 gROOT->SetBatch();
899 return;
900}

◆ main()

int main ( )

Definition at line 61 of file run_EoverP.cxx.

61 {
62 return 0;
63}

◆ makeCorrectionHist()

TH2F * makeCorrectionHist ( )

Definition at line 902 of file run_EoverP.cxx.

902 {
903 TH2F *FinalCorrections = new TH2F("FinalCorrections","FinalCorrections",16,-2.5,2.5,16,-3.14159,3.14159);
904 return FinalCorrections;
905}

◆ makeFits()

void makeFits ( RooAbsData * originalDataSet,
RooRealVar & eOverP,
RooRealVar & eta,
RooRealVar & phi,
TH2F * meanPlotPos,
TH2F * meanPlotNeg,
TString additionalCut = "" )

Definition at line 307 of file run_EoverP.cxx.

314{
315
316 //----------
317 // Initialize canvas
318 //----------
319 TCanvas *c = new TCanvas();
321
322 //----------
323 // Set up variables for the fits
324 //----------
325 // Variables
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,"") ;
331
332 // Landau parameters
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);
339
340 // Functions
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);
347
348 // Landau-Gaussian convolution
349 RooFFTConvPdf LcwGPos ("LcwG_Pos", "Landau (x) Gauss", eOverP, LandauPos, gaussianPos);
350 RooFFTConvPdf LcwGNeg ("LcwG_Neg", "Landau (x) Gauss", eOverP, LandauNeg, gaussianNeg);
351
352 // Setup fit ranges for eOverP variable we filled earlier
353 eOverP.setBins(50);
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);
358
359 //----------
360 // Set up separate eta/phi binned data sets for positive/negative electrons
361 //----------
362 // get number of bins in eta(x)/phi(y)
363 static const int nBinsX = meanPlotPos->GetXaxis()->GetNbins();
364 static const int nBinsY = meanPlotPos->GetYaxis()->GetNbins();
365
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 ); // positron data set
369 RooDataSet* dataSetNeg = dynamic_cast<RooDataSet*>( absDataSetNeg ); // electron data set
370 RooArgSet vars(xvar,yvar,eOverP);
371
372 RooDataSet* binnedDataPos[nBinsX][nBinsY]; // positron data set broken up by eta/phi bin
373 RooDataSet* binnedDataNeg[nBinsX][nBinsY]; // electron data set broken up by eta/phi bin
374
375 // name each of our eta/phi bins in binnedDataPos/Neg
376 for(int xvarStep = 0; xvarStep<nBinsX; xvarStep++){ // eta
377 for(int yvarStep = 0; yvarStep<nBinsY; yvarStep++){ // phi
378
379 TString rangeName = xvar.getTitle() + "Bin";
380 rangeName += xvarStep;
381 rangeName += "_"+yvar.getTitle()+"Bin";
382 rangeName += yvarStep;
383
384 binnedDataPos[xvarStep][yvarStep] = (RooDataSet*)originalDataSet->emptyClone() ;
385 binnedDataNeg[xvarStep][yvarStep] = (RooDataSet*)originalDataSet->emptyClone() ;
386
387 binnedDataPos[xvarStep][yvarStep]->SetName(rangeName+"_Pos");
388 binnedDataNeg[xvarStep][yvarStep]->SetName(rangeName+"_Neg");
389
390 }
391 }
392
393 //----------
394 // Fill pos/neg binned data sets
395 //----------
396 // positive
397 for (int i=0; i<dataSetPos->numEntries(); i++) {
398 const RooArgSet* args = dataSetPos->get(i);
399 vars= *args;
400 int globalbin = meanPlotPos->FindBin(xvar.getVal(),yvar.getVal());
401 int binx,biny,binz;
402 meanPlotPos->GetBinXYZ(globalbin,binx,biny,binz);
403 binnedDataPos[binx-1][biny-1]->add(*args);
404 }
405 // negative
406 for (int i=0; i<dataSetNeg->numEntries(); i++) {
407 const RooArgSet* args = dataSetNeg->get(i);
408 vars= *args;
409 int globalbin = meanPlotNeg->FindBin(xvar.getVal(),yvar.getVal());
410 int binx,biny,binz;
411 meanPlotNeg->GetBinXYZ(globalbin,binx,biny,binz);
412 binnedDataNeg[binx-1][biny-1]->add(*args);
413 }
414
415 //----------
416 // Time to make the donuts
417 //----------
418 for(int xvarStep = 0; xvarStep<nBinsX; xvarStep++){ // eta
419 for(int yvarStep = 0; yvarStep<nBinsY; yvarStep++){ // phi
420 // some naming like we did before
421 TString rangeName = xvar.getTitle() + "Bin";
422 rangeName += xvarStep;
423 rangeName += "_"+yvar.getTitle()+"Bin";
424 rangeName += yvarStep;
425
426 // set up the framse for pos/neg plots
427 RooPlot* framePos = eOverP.frame(Title("E/P pos"),Range("final"));
428 RooPlot* frameNeg = eOverP.frame(Title("E/P neg"),Range("final"));
429
430 // make data sets from the relevent bin of the binned sets to be easier to work with
431 RooDataSet* smallDataSetPos = binnedDataPos[xvarStep][yvarStep];
432 RooDataSet* smallDataSetNeg = binnedDataNeg[xvarStep][yvarStep];
433
434 // plot the smallDataSet on the corresponding frame: -- Pos(Blue) & Neg(Red)
435 smallDataSetPos->plotOn(framePos,LineColor(kBlue),MarkerColor(kBlue));
436 smallDataSetNeg->plotOn(frameNeg,LineColor(kRed),MarkerColor(kRed));
437
438 // reset the fit paramaters
439 meanPos.setVal(1);
440 meanNeg.setVal(1);
441 sigma.setVal(0.1);
442 alpha.setVal(-1);
443 n.setVal(1);
444
445 //----------
446 // Set up samples
447 //----------
448 RooCategory sample("sample","sample"); // separate positive and negative
449 sample.defineType("Pos");
450 sample.defineType("Neg");
451 RooDataSet combData("combData","combined data",eOverP,Index(sample),Import("Pos",*smallDataSetPos),Import("Neg",*smallDataSetNeg)); // combined data set in (x, sample)
452
453 //----------
454 // Set up simultaneous pdfs in (x,sample)
455 //----------
456 // gaussian
457 RooSimultaneous simPdfGS("simPdfGS","simultaneous pdf",sample);
458 simPdfGS.addPdf(gaussianPos,"Pos");
459 simPdfGS.addPdf(gaussianNeg,"Neg");
460 // cristal ball
461 RooSimultaneous simPdfCB("simPdfCB","simultaneous pdf",sample);
462 simPdfCB.addPdf(crystalBallPos,"Pos");
463 simPdfCB.addPdf(crystalBallNeg,"Neg");
464 // landau
465 RooSimultaneous simPdfLnd("simPdfLnd","simultaneous pdf",sample);
466 simPdfLnd.addPdf(LandauPos,"Pos");
467 simPdfLnd.addPdf(LandauNeg,"Neg");
468 // landau-gaussian convolution
469 RooSimultaneous simPdfLcwG("simPdfLcwG","simultaneous pdf",sample);
470 simPdfLcwG.addPdf(LcwGPos,"Pos");
471 simPdfLcwG.addPdf(LcwGNeg,"Neg");
472
473 //----------
474 // Perform simultaneous fit
475 //----------
476 // some fit vars
477 double fitMeanPos = -999.;
478 double fitMeanNeg = -999.;
479 double fitSigma = -999.;
480
481 // set up ranges for first fit
482 eOverP.setRange("fitGauss_Pos",0.5,1.5);
483 eOverP.setRange("fitGauss_Neg",0.5,1.5);
484 // fit the gaussian & check if it produced a result
485 RooFitResult* fitResult = simPdfGS.fitTo(combData,Range("fitGauss"),SplitRange(),Save());
486 if(fitResult)
487 std::cout << "WARNING:: FIRST GAUSSIAN FIT PRODUCED A FIT RESULT" <<std::endl;
488 else
489 std::cout << "WARNING:: FIRST GAUSSIAN FIT DID NOT PRODUCE A FIT RESULT" <<std::endl;
490 // update fit vars
491 fitMeanPos = meanPos.getVal();
492 fitMeanNeg = meanNeg.getVal();
493 fitSigma = sigma.getVal();
494 // set up for 2nd fit
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;
499 meanPos.setVal(1);
500 meanNeg.setVal(1);
501 sigma.setVal(0.2);
502 eOverP.setRange("fitGauss_Pos",0.1,1.9);
503 eOverP.setRange("fitGauss_Neg",0.1,1.9);
504 }
505 // will ---
506
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;
510 meanPos.setVal(1);
511 meanNeg.setVal(1);
512 sigma.setVal(0.2);
513 }
514
515 //if (fitResult) delete fitResult;
516
517 /*
518 // do some more fits
519 int counter = 0;
520 do{
521 if(counter > 5){
522 std::cout<< "WARNING:: REACHED MAX FIT ATTEMPTS WITH NO CONVERGENCE" << std::endl;
523 break;
524 }
525 std::cout << "INFO:: TRYING GAUSSIAN FIT #"<< counter+2 << std::endl;
526
527 fitResult = simPdfGS.fitTo(combData,Range("fitGauss"),SplitRange(),Save() );
528 if ( fitResult && fitResult->status() != 0){
529 std::cout << "WARNING:: GAUSSIAN FIT #"<< counter+2 << " DID NOT CONVERGE" <<std::endl;
530 meanPos.setVal(1.);
531 meanNeg.setVal(1.);
532 sigma.setVal(0.2+0.2*counter);
533 }
534 counter++;
535 } while(fitResult && fitResult->status() != 0);*/
536 // --- will
537
538 if (fitResult) delete fitResult;
539 fitMeanPos = meanPos.getVal();
540 fitMeanNeg = meanNeg.getVal();
541 fitSigma = sigma.getVal();
542
543 eOverP.setRange("fitGauss_Pos",fitMeanPos-1.25*fitSigma,fitMeanPos+1*fitSigma);
544 eOverP.setRange("fitGauss_Neg",fitMeanNeg-1.25*fitSigma,fitMeanNeg+1*fitSigma);
545
546 // do final fit
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;
550 meanPos.setVal(1);
551 meanNeg.setVal(1);
552 sigma.setVal(0.2);
553 fitSigma = 0.3;
554 }
555 if(fitResult) delete fitResult;
556
557 //std::cout << "INFO: meanPos = " << meanPos.getVal() << " meanNeg = " << meanNeg.getVal() << " sigma = " << sigma.getVal() << std::endl;
558
559 /*
560 //Fit with Landau
561 fitResult = simPdfLnd.fitTo(combData, Range("fitLandau"),SplitRange(), Save() ) ;
562 if ( fitResult && fitResult->status() != 0){
563 std::cout << "WARNING::TEST LANDAU FIT DID NOT CONVERGE" <<std::endl;
564 LandauMeanPos.setVal(1);
565 LandauMeanNeg.setVal(1);
566 LandauS.setVal(0.2);
567 //fitSigma = 0.3;
568 }
569 if(fitResult) delete fitResult;
570
571 fitMeanPos = (meanPos.getVal()+LandauMeanPos.getVal())/2.;
572 fitMeanNeg = (meanNeg.getVal()+LandauMeanNeg.getVal())/2.;
573 fitSigma = sigma.getVal() > LandauS.getVal() ? sigma.getVal() : LandauS.getVal();
574
575 std::cout << "INFO: meanPos = " << meanPos.getVal() << " meanNeg = " << meanNeg.getVal() << " sigma = " << sigma.getVal() << std::endl;
576 std::cout << "INFO: LandauMeanPos = " << LandauMeanPos.getVal() << " LandauMeanNeg = " << LandauMeanNeg.getVal() << " LandauS = " << LandauS.getVal() << std::endl;
577 std::cout << "INFO: Fit Mean Pos: " << fitMeanPos << " Fit Mean Pos: " << fitMeanNeg << "Fit Sigma: " << fitSigma << std::endl;
578 */
579
580 //Perform simultaneous fit of model to data and model_ctl to data_ctl
581 eOverP.setRange("finalFit_Pos",fitMeanPos-1.5*fitSigma,2.5);
582 eOverP.setRange("finalFit_Neg",fitMeanNeg-1.5*fitSigma,2.5);
583
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);
588
589 //Here the range is fixed instead of using all teh above (25/Feb/14, S. Marti)
590 eOverP.setRange("finalFit_Pos",0.8,2.5);
591 eOverP.setRange("finalFit_Neg",0.8,2.5);
592 //LandauMeanPos.setVal(1.);//LandauMeanPos.setConstant(kTRUE);
593 //LandauMeanNeg.setVal(1.);//LandauMeanNeg.setConstant(kTRUE);
594 //meanPos.setVal(0.);meanPos.setConstant(kTRUE);
595 //meanNeg.setVal(0.);meanNeg.setConstant(kTRUE);
596 //sigma.setVal(0.2);
597
598
599//***** Choose one, CB, Landau or LcwG
600 //Fit with CrystalBall
601 alpha.setVal(1.2);
602 meanPos.setVal(1.);
603 meanNeg.setVal(1.);
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"));
607
608
609 //Fit with Landau
610 /* fitResult = simPdfLnd.fitTo(combData, Range("finalFit"),SplitRange(), Save() ) ;
611 LandauPos.plotOn(framePos,LineColor(kOrange+1),Range("finalFit_Pos"),NormRange("finalFit_Pos"));
612 LandauNeg.plotOn(frameNeg,LineColor(kGreen+1),Range("finalFit_Neg"),NormRange("finalFit_Neg")); */
613
614
615 //Fit with Landau convoluted with Gaussian
616 if(false){
617 int simCount = 0;
618 do{
619 if(simCount > 5) break;
620 fitResult = simPdfLcwG.fitTo(combData, Range("finalFit"),SplitRange(), Save() ) ;
621 simCount++;
622 } while(fitResult && ( fitResult->status() != 0 || fitResult->covQual() != 3 ));
623
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"));
626 }
627
628 // hold on
629 if (false) {
630 string input = "";
631 cout << " ** fit_EoverP ** Please type RETURN to continue:\n>";
632 getline(cin, input);
633 }
634
635//*****
636
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());
641
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);
648 }
649
650 if(fitResult) delete fitResult;
651
652 c->Clear();
653 c->SetLogy(false);
654
655 framePos->Draw();
656 frameNeg->Draw("same");
657
658 //ATLASPRELIM_LABEL(0.25,0.88,0.03,1);
659 TString* xvarTString = new TString(xvar.getTitle());
660 TString* yvarTString = new TString(yvar.getTitle());
661
662 const char *yvarChar = *yvarTString;
663 const char *xvarChar = *xvarTString;
664
665
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)
668 ,xvarChar
669 ,meanPlotPos->GetXaxis()->GetBinLowEdge(xvarStep+2)
670 ,meanPlotPos->GetYaxis()->GetBinLowEdge(yvarStep+1)
671 ,yvarChar
672 ,meanPlotPos->GetYaxis()->GetBinLowEdge(yvarStep+2)) );
673
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);
676
677
678 c->Print(PATH+"new_eoverp_plots.pdf");
679
680 delete framePos;
681 delete frameNeg;
682 delete smallDataSetPos;
683 delete smallDataSetNeg;
684 }
685 }
686
687 makeSlicePlots(meanPlotPos ,meanPlotNeg, false);
688 makeSlicePlots(meanPlotPos ,meanPlotNeg, true);
689
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 };
695 Int_t nb=50;
696 //TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
697
698
699 TH2F* clone =(TH2F*) meanPlotPos->Clone();
700 clone->Divide(meanPlotNeg);
701 clone->SetContour(nb);
702
703 TH2F* clone2 =(TH2F*) meanPlotPos->Clone();
704 clone2->Add( meanPlotNeg, -1);
705 clone2->SetContour(nb);
706
707 Double_t minPlot,maxPlot;
708
709 c->Clear();
710 c->SetRightMargin(0.12);
711 c->SetLogy(false);
712 clone->Draw("colz");
713
714 //Set Z axis centered in 1 so good points are in green
715 minPlot= clone->GetMinimum();
716 maxPlot= clone->GetMaximum();
717 if (maxPlot-1 > 1-minPlot) clone->SetMinimum(2-maxPlot);
718 else clone->SetMaximum(2-minPlot);
719
720 c->Print(PATH+"new_eoverp_plots.pdf");
721
722 meanPlotPos->Draw("colz");
723 meanPlotPos->SetContour(nb);
724
725 //Set Z axis centered in 1 so good points are in green
726 minPlot= meanPlotPos->GetMinimum();
727 maxPlot= meanPlotPos->GetMaximum();
728 if (maxPlot-1 > 1-minPlot) meanPlotPos->SetMinimum(2-maxPlot);
729 else meanPlotPos->SetMaximum(2-minPlot);
730
731 c->Print(PATH+"new_eoverp_plots.pdf");
732
733 meanPlotNeg->Draw("colz");
734 meanPlotNeg->SetContour(nb);
735
736 //Set Z axis centered in 1 so good points are in green
737 minPlot= meanPlotNeg->GetMinimum();
738 maxPlot= meanPlotNeg->GetMaximum();
739 if (maxPlot-1 > 1-minPlot) meanPlotNeg->SetMinimum(2-maxPlot);
740 else meanPlotNeg->SetMaximum(2-minPlot);
741
742 c->Print(PATH+"new_eoverp_plots.pdf");
743
744 TH1F* pull = new TH1F("pull","pull",50,-5,5);
745 pull->GetXaxis()->SetTitle("Fit Pull");
746 pull->GetYaxis()->SetTitle("Entries per 0.2");
747
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) );
755 }
756 }
757 pull->Draw();
758 pull->Fit(&myGauss);
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);
763
764 c->Print(PATH+"new_eoverp_plots.pdf");
765
766
767 delete clone;
768 delete clone2;
769
770
771}
IndexedConstituentUserInfo::Index Index
void myText(Double_t x, Double_t y, Color_t color, char *text)
Definition AtlasUtils.h:291
void myMarkerText(Double_t x, Double_t y, Int_t color, Int_t mstyle, char *text, Float_t msize=2., Float_t tsize=0.05)
#define PATH
Definition SealCommon.h:161
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
void makeSlicePlots(TH2F *pos, TH2F *neg, bool sliceInEta)

◆ makePlots()

void makePlots ( RooAbsData * originalDataSet,
RooRealVar & eOverP,
RooRealVar & eta,
int nBinsEta,
RooRealVar & phi,
int nBinsPhi,
RooRealVar & Et,
TString extraCuts = "" )

Definition at line 220 of file run_EoverP.cxx.

228{
229 // Set up ranges
230 double etaRange[nBinsEta+1];
231 double stepSize = 5./nBinsEta;
232 for (int i(0); i<= nBinsEta; ++i){
233 etaRange[i] = -2.5+stepSize*(double)i;
234 }
235
236 double phiRange[nBinsPhi+1];
237 stepSize = 2 * TMath::Pi()/nBinsPhi;
238 for (int i(0); i<= nBinsPhi; ++i){
239 phiRange[i] = -TMath::Pi()+stepSize*(double)i;
240 }
241
242
243 TH2F *meanPlotPos = new TH2F("meanPlotPos"+extraCuts,"meanPlotPos"+extraCuts,nBinsEta,etaRange,nBinsPhi,phiRange );
244 meanPlotPos->SetTitle("Mean Plot Positive "+extraCuts);
245 meanPlotPos->GetXaxis()->SetTitle("#eta");
246 meanPlotPos->GetYaxis()->SetTitle("#phi [rad]");
247 TH2F *meanPlotNeg = new TH2F("meanPlotNeg"+extraCuts,"meanPlotNeg"+extraCuts,nBinsEta,etaRange,nBinsPhi,phiRange );
248 meanPlotNeg->SetTitle("Mean Plot Negative "+extraCuts);
249 meanPlotNeg->GetXaxis()->SetTitle("#eta");
250 meanPlotNeg->GetYaxis()->SetTitle("#phi [rad]");
251
252 makeFits(originalDataSet,
253 eOverP,
254 eta,
255 phi,
256 meanPlotPos,
257 meanPlotNeg,
258 extraCuts);
259
260 TFile f(PATH+"fitEoverP.root","Recreate");
261 meanPlotPos->Write();
262 meanPlotNeg->Write();
263
264
265 //if(Et != NULL ){
266 double ptRange[102];
267 stepSize = 1500;
268 for (int i=0; i<= 100; i++){
269 ptRange[i] = (20e3+stepSize*(double)i)/1000.; // GeV
270 //std::cout << ptRange[i] << std::endl;
271 }
272
273 double eopRange[102];
274 stepSize = 0.05;
275 for (int i=0; i<= 100; i++){
276 eopRange[i] = 0.8+stepSize*(double)i;
277 }
278
279 TH2F *ptvsEta = new TH2F("meanPtVsEta"+extraCuts,"meanPtVsEta"+extraCuts,nBinsEta,etaRange,100,ptRange);
280 TH2F *eoverPvsEta = new TH2F("eoverPvsEta"+extraCuts,"eoverPvsEta"+extraCuts,nBinsEta,etaRange,100,eopRange);
281
282 RooArgSet vars(Et,eOverP,eta);
283 for(int i=0; i < originalDataSet->numEntries(); i++){
284 // wkd2 -- this is giving the same value of all the parameters for all i, need to fix it!
285 const RooArgSet* args = originalDataSet->get(i);
286 vars = *args;
287 //originalDataSet->get(i);
288 double valEt = Et.getVal();
289 double valeOverP = eOverP.getVal();
290 double valEta = eta.getVal();
291
292 //std::cout << "valEta: " << valEta << " valEt: " << valEt << std::endl;
293
294 ptvsEta->Fill(valEta,valEt);
295 eoverPvsEta->Fill(valEta,valeOverP);
296 }
297
298 ptvsEta->Write();
299 eoverPvsEta->Write();
300 //} // end if(Et != NULL)
301
302 //f.Write();
303 f.Close();
304}
phiRange
Filling Phi ranges.
etaRange
Filling Eta range.
void makeFits(RooAbsData *originalDataSet, RooRealVar &eOverP, RooRealVar &eta, RooRealVar &phi, TH2F *meanPlotPos, TH2F *meanPlotNeg, TString additionalCut="")

◆ makeRatioPlots()

void makeRatioPlots ( TH1D * h1,
TH1D * h2,
TString name )

Definition at line 819 of file run_EoverP.cxx.

819 {
820 std::cout << "INFO::Starting makeRatioPlots()" << std::endl;
821 TCanvas c1("C1","C1",600,600);
822 TPad *pad1 = new TPad("pad1","pad1",0,0.5,1,1);
823 pad1->SetTopMargin(0.05/0.5);
824 pad1->SetRightMargin(0.05);
825 pad1->SetBottomMargin(0.16);
826 pad1->SetLeftMargin(0.16);
827
828 pad1->SetBottomMargin(0);
829 pad1->Draw();
830 pad1->cd();
831
832 TH1D* h1clone = (TH1D*) h1->Clone();
833 h1->SetMarkerColor(kBlue);
834 h1->SetMarkerStyle(20);
835 h1->GetYaxis()->SetRangeUser(0.85,1.45);
836 h1->GetYaxis()->SetLabelSize(0.05/0.5);
837 h1->GetYaxis()->SetTitleSize(0.05/0.5);
838 h1->GetYaxis()->SetTitle("<E/p>");
839 h1->DrawCopy("pe");
840 h2->SetMarkerColor(kRed);
841 h2->SetMarkerStyle(22);
842 h2->Draw("samepe");
843 c1.cd();
844 TPad *pad2 = new TPad("pad2","pad2",0,0,1,0.5);
845 pad2->SetTopMargin(0.05);
846 pad2->SetRightMargin(0.05);
847 pad2->SetBottomMargin(0.16/0.5);
848 pad2->SetLeftMargin(0.16);
849
850 //pad2->SetTopMargin(0);
851 pad2->Draw();
852 pad2->cd();
853 h1clone->Sumw2();
854 h1clone->SetStats(0);
855 h1clone->Divide(h2);
856 h1clone->SetMarkerColor(kBlack);
857 h1clone->SetMarkerStyle(20);
858 h1clone->GetYaxis()->SetLabelSize(0.05/0.5);
859 h1clone->GetXaxis()->SetLabelSize(0.05/0.5);
860 h1clone->GetYaxis()->SetTitleSize(0.05/0.5);
861 h1clone->GetXaxis()->SetTitleSize(0.05/0.5);
862 h1clone->GetYaxis()->SetRangeUser(0.8,1.2);
863 h1clone->GetYaxis()->SetTitle("<E/p>^{+}/<E/p>^{-}");
864
865 h1clone->Draw("ep");
866 //h1->GetYaxis()->SetRangeUser(0.95,1.05);
867 c1.cd();
868
869 // legend title setup
870 TString title;
871 if(name.Contains("Y",TString::kExact))
872 title += "Phi slice ";
873 else
874 title += "Eta slice ";
875 title += name[name.Length()-1];
876
877 TLegend *leg1 = new TLegend(0.75,0.82,0.9,0.92);
878 leg1->SetBorderSize(0);
879 leg1->SetFillColor(0);
880 leg1->AddEntry("",title,"");
881 leg1->AddEntry(h1,"Positive","p");
882 leg1->AddEntry(h2,"Negative","p");
883 leg1->Draw();
884
885 //c1.Print( PATH + name+".pdf");
886 c1.Print(PATH+"new_eoverp_plots.pdf");
887 delete h1clone;
888 delete pad1;
889 delete pad2;
890 std::cout << "INFO::Finished makeRatioPlots()" << std::endl;
891
892}

◆ makeScalingHist()

void makeScalingHist ( TString inputDir)

Definition at line 926 of file run_EoverP.cxx.

927{
928 std::cout << "INFO :: In makeScalingHist()" << std::endl;
929
930 TString dir = PATH;
931 if(inputDir != "") dir = inputDir;
932 else{
933 std::cout << "ERROR :: makeScalingHist(): No input directory specified!" << std::endl;
934 return;
935 }
936
937 TFile *file0 = TFile::Open(dir+"fitEoverP.root");
938 file0->ls();
939 TH2F* meanPlotNeg = (TH2F*) file0->Get("meanPlotNeg");
940 TH2F* meanPlotPos = (TH2F*) file0->Get("meanPlotPos");
941
942
943 if(!meanPlotNeg || !meanPlotNeg){
944 std::cout<< "ERROR :: makeScalingHist(): inputfile does not contain the desired histograms " << std::endl;
945 return;
946 }
947
948 meanPlotNeg->Draw("colz");
949 meanPlotPos->Draw("colz");
950 meanPlotNeg->Sumw2();
951 meanPlotPos->Sumw2();
952
953
954 //Need to obtain the mean pt either from a histogram or from hardcoded values
955 double pt[1000]={};
956
957 TH2F* meanPtVsEta = (TH2F*) file0->Get("meanPtVsEta");
958 if(!meanPtVsEta){
959 std::cout << "ERROR :: makeScalingHist(): inputfile does not contain the meanPtVsEta histogram " << std::endl;
960 return;
961 }
962 for(int i=1; i<=meanPtVsEta->GetNbinsX(); i++){
963 TH1D* projection = meanPtVsEta->ProjectionY( "_py", i , i);
964 pt[i-1] = (projection->GetMean()*1000.); //MeV
965 delete projection;
966 }
967
968
969 TH2F* a = (TH2F*) meanPlotPos->Clone();
970 a->Add(meanPlotNeg,-1);
971 a->Scale(-0.5); // divide by 2
972
973 for(int i=1; i <= a->GetNbinsX(); i++){
974 for(int j=1; j <= a->GetNbinsY(); j++){
975 double temp = a->GetBinContent(i,j);
976 a->SetBinContent(i,j, temp/pt[i-1]*1e3);
977 temp = a->GetBinError(i,j);
978 a->SetBinError(i,j, temp/pt[i-1]*1e3);
979 }
980 }
981
982 a->Draw("colz");
983
984 TFile f(dir+"Scaling.root","RECREATE");
985 a->SetName("FinalCorrections");
986 a->SetTitle("FinalCorrections");
987 a->Write();
988 f.ls();
989 f.Close();
990}
static Double_t a

◆ makeSlicePlots()

void makeSlicePlots ( TH2F * pos,
TH2F * neg,
bool sliceInEta )

Definition at line 774 of file run_EoverP.cxx.

775{
776 std::cout << "INFO::makeSlicePlots()" << std::endl;
777
778 int maxStep(1);
779
780 if(sliceInEta){
781 maxStep = pos->GetNbinsX();
782 } else {
783 maxStep = pos->GetNbinsY();
784 }
785
786 TString name;
787 for (int i(0); i <maxStep; ++i ){
788 TH1D* posProjection;
789 TH1D* negProjection;
790 name = pos->GetName();
791 name += "_Slice";
792
793 if (sliceInEta){
794 posProjection = pos->ProjectionY( "_py", i+1 , i+1);
795 negProjection = neg->ProjectionY( "_py", i+1 , i+1);
796 name+="X";
797 name+=i;
798
799 } else {
800 posProjection = pos->ProjectionX( "_px", i+1 , i+1);
801 negProjection = neg->ProjectionX( "_px", i+1 , i+1);
802 name+="Y";
803 name+=i;
804
805 }
806
807
808
809 makeRatioPlots(posProjection, negProjection, name );
810 delete posProjection;
811 delete negProjection;
812 }
813 std::cout << "INFO::Finished makeSlicePlots()" << std::endl;
814}
void makeRatioPlots(TH1D *h1, TH1D *h2, TString name)

◆ run_EoverP()

void run_EoverP ( TString fileName = "../share/eoverpValidationOut.root",
int refit = 2,
int netabins = 12,
int nphibins = 12 )

Definition at line 93 of file run_EoverP.cxx.

93 {
94
95 // ----------
96 // initialize
97 // ----------
98 initialize();
99
100 // ----------
101 // check validity of input vars
102 // ----------
103 if( !((refit >= 0) && (refit <= 2)) ){
104 std::cout << "ERROR :: Input parameter 'refit' must be equal to 0, 1, or 2!" << std::endl;
105 std::exit(0);
106 }
107 if( (netabins < 1) || (nphibins < 1) ){
108 std::cout << "ERROR :: Can't have less than one bin in eta/phi!" << std::endl;
109 std::exit(0);
110 }
111
112 // ----------
113 // set up our RooFit variables
114 // ----------
115 RooRealVar ClusterEnergy("ClusterEnergy","ClusterEnergy",0,1e10,"MeV") ;
116 RooRealVar ClusterPhi("ClusterPhi","#phi",0);
117 RooRealVar ClusterEta("ClusterEta","#eta",0);
118 RooRealVar charge("charge","charge",0);
119 RooRealVar TrackTheta("TrackTheta","TrackTheta",0);
120 RooRealVar TrackQoverP("QoverP","QoverP",-1e10,1e10,"MeV^{-1}");
121 RooRealVar EoverP("EoverP","E/p",0,5,"");
122 RooRealVar Et("Et","E_{T}",0,1e10,"GeV");
123 RooRealVar Eta("Eta","#eta",-3,3,"");
124
125 RooArgSet arg;
126 arg.add(ClusterEnergy);
127 arg.add(ClusterPhi);
128 arg.add(ClusterEta);
129 arg.add(charge);
130 arg.add(TrackTheta);
131 arg.add(TrackQoverP);
132 arg.add(EoverP);
133 arg.add(Et);
134 arg.add(Eta);
135
136 // ---------
137 // Open our TFile(s) and set up our event variables
138 // (in this format, each "event" is one electron)
139 // ---------
140 TChain *eoverpTree = new TChain("EGrefitterSmall");
141 eoverpTree->Add(fileName);
142
143 Double_t el_ClusterEnergy;
144 Double_t el_ClusterPhi;
145 Double_t el_ClusterEta;
146 Double_t el_charge;
147 Double_t el_TrackTheta;
148 Double_t el_QoverP;
149 Double_t el_QoverP1;
150 Double_t el_QoverP2;
151 eoverpTree->SetBranchAddress("ClusterEnergy", &el_ClusterEnergy);
152 eoverpTree->SetBranchAddress("ClusterPhi", &el_ClusterPhi);
153 eoverpTree->SetBranchAddress("ClusterEta", &el_ClusterEta);
154 eoverpTree->SetBranchAddress("charge", &el_charge);
155 eoverpTree->SetBranchAddress("TrackTheta", &el_TrackTheta);
156 eoverpTree->SetBranchAddress("Default_QoverP", &el_QoverP);
157 eoverpTree->SetBranchAddress("Refitted1_QoverP", &el_QoverP1);
158 eoverpTree->SetBranchAddress("Refitted2_QoverP", &el_QoverP2);
159
160 RooDataSet* dataSet = new RooDataSet("DataSet","DataSet",arg);
161
162 // which refit QoverP do we want? -- Hardcoded for now...
163 //Int_t refit = 2 // 0 = original; 1 = refit1; 2 = refit2
164
165 // ----------
166 // Loop over the events and fill the variables
167 // ----------
168 Int_t nEl = eoverpTree->GetEntries();
169 for (Int_t i=0; i<nEl; i++){
170 if( (i%10000) == 0 )
171 std::cout << "Filling variables for electron #" << i << std::endl;
172 eoverpTree->GetEntry(i);
173
174 charge.setVal(el_charge);
175 Et.setVal(el_ClusterEnergy*sin(el_TrackTheta)*1e-3);
176 Eta.setVal(-log(tan(el_TrackTheta/2)) );
177 ClusterPhi.setVal(el_ClusterPhi);
178 ClusterEnergy.setVal(el_ClusterEnergy);
179 ClusterEta.setVal(el_ClusterEta);
180 //std::cout << "default: " << el_QoverP*el_ClusterEnergy << " refit1: " << el_QoverP1*el_ClusterEnergy << " refit2: " << el_QoverP2*el_ClusterEnergy << std::endl;
181 if(refit == 0){
182 EoverP.setVal(fabs(el_QoverP)*el_ClusterEnergy);
183 //std::cout << "refit = " << refit << " Using " << 1./el_QoverP << std::endl;
184 }
185 else if(refit == 1){
186 EoverP.setVal(fabs(el_QoverP1)*el_ClusterEnergy);
187 //std::cout << "refit = " << refit << " Using " << 1./el_QoverP1 << std::endl;
188 }
189 else{
190 EoverP.setVal(fabs(el_QoverP2)*el_ClusterEnergy);
191 //std::cout << "refit = " << refit << " Using " << 1./el_QoverP2 << std::endl;
192 }
193
194 dataSet->add(arg);
195
196 }
197
198 TCanvas c; // put a blank page at the start of the output. because reasons.
199 c.Print(PATH+"new_eoverp_plots.pdf(");
200
201 // ----------
202 // Pass the data off to the plotting functions
203 // ----------
204 makePlots(dataSet,
205 EoverP,
206 ClusterEta,
207 netabins,
208 ClusterPhi,
209 nphibins,
210 Et);
211
212 c.Print(PATH+"new_eoverp_plots.pdf)"); // put a blank page at the end of the output. yup.
213
215
216 return;
217
218}
@ Eta
Definition RPCdef.h:8
void initialize()
void makePlots(RooAbsData *originalDataSet, RooRealVar &eOverP, RooRealVar &eta, int nBinsEta, RooRealVar &phi, int nBinsPhi, RooRealVar &Et, TString extraCuts="")
void makeScalingHist(TString inputDir)

Variable Documentation

◆ PATH

TString PATH = "./Results/"

Definition at line 91 of file run_EoverP.cxx.