Exemple #1
0
void spectrum(char *filename = "example.root")
{
   TFile *infile = new TFile(filename);
   TTree *data = (TTree*) infile->FindObjectAny("data");
   
   TH1F *h[10];
   
   TCanvas *c = new TCanvas("c","",960,480);
   TPad *p = new TPad("p","",0,0,1,1);
   p->Divide(4,2,0.01,0.01);
   p->Draw();

   double norm;
   for (int i=0;i<8;i++)
   { 
      p->cd(i+1);
      p->GetPad(i+1)->SetLogy();
      h[i] = new TH1F(Form("h%d",i),Form("Ch %d",i),60,-0.1,1.1);
//      data->Draw(Form("-min[%d]>>h%d",i,i),"min[0]<min[1]&&min[0]<min[2]&&min[0]<min[3]&&min[0]<min[4]&&min[0]<min[5]&&min[0]<min[6]&&min[0]<min[7]");
      data->Draw(Form("-min[%d]/256./0.86>>h%d",i,i));
      if (i==0) norm = h[i]->GetEntries();
      h[i]->SetTitle(Form("Ch %d",i));
      h[i]->SetXTitle("Pulse height (Volt)");
      h[i]->SetYTitle("#");
      h[i]->SetMarkerSize(0.5);
      h[i]->SetMarkerColor(2);
      h[i]->Sumw2();
      h[i]->Scale(1./norm);
      h[i]->SetAxisRange(1e-7,10,"Y");
      h[i]->Draw("e");
   }
}
void RDK2AnalysisPlotter::makeEPGPlot(CoDet detType)
{
     gROOT->cd();
    TCanvas* theCanvas;
    TPad* mainPad;
    TPad* titlePad;
    TPad* gEPad;
    TPad* detPad;
    TPad* gEPadSubs[3];


    int numTitleLines=getTitleBoxLines( detType);
    int canvasNumPixelsYPlot=600;
    int canvasNumPixelsYPlots=2*canvasNumPixelsYPlot;
    int canvasNumPixelsYTitle=40*numTitleLines;
    int canvasNumPixelsY=canvasNumPixelsYPlots+canvasNumPixelsYTitle;

    theCanvas = new TCanvas("EPGExpMCAnalysisComparisonPlot","EPGExpMCAnalysisComparisonPlot",10,10,1200,canvasNumPixelsY);
     mainPad=(TPad*) theCanvas->GetPad(0);


    double ylow,yhigh;

    yhigh=1;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    titlePad=new TPad("titlePad", "titlePad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=ylow;
    ylow=ylow-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    gEPad=new TPad("gEPad", "gEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=ylow;
    ylow=0;
    detPad=new TPad("detPad", "detPad", 0., ylow, 1., yhigh, -1, 1, 1);

    titlePad->Draw();
    gEPad->Draw();
    detPad->Draw();



//    titlePad=(TPad*) theCanvas->GetPad(1);
//    gEPad=(TPad*) theCanvas->GetPad(2);
//    detPad=(TPad*) theCanvas->GetPad(3);
//    egTPad=(TPad*) theCanvas->GetPad(4);

    titlePad->SetMargin(0.05,0.0,0.0,0.0);
    gEPad->SetMargin(0.05,0.0,0.0,0.05);

    if(numExp>1 && numMC>1)
    {
        gEPad->Divide(2);

        gEPadSubs[0]=(TPad*) gEPad->GetPad(1);

        TPad* tempPad;
        tempPad=(TPad*) gEPad->GetPad(2);
        tempPad->Divide(1,2);
        gEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        gEPadSubs[2]=(TPad*) tempPad->GetPad(2);


        TPad* allBasePads[5]={titlePad,gEPadSubs[0],gEPadSubs[1],gEPadSubs[2],detPad};
         for (int i = 1;i< 5;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }

        gEPadSubs[2]->SetLogx();

        gEPadSubs[0]->SetMargin(0.15,0.1,.1,0.1);
        gEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        gEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);

        //Plot gE

        gEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_COMP);
        gEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_RESID);
        gEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_GEVAR,PLOT_NORMRESID);

    }
    else
    {

        TPad* allBasePads[3]={titlePad,gEPad,detPad};
        for (int i = 1;i< 3;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }

        gEPad->SetMargin(0.13,0.1,.1,0.1);


        //Plot gE

        gEPad->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_COMP);
    }
    mainPad->SetFillColor(kGray);

    ///Make Title box
    titlePad->cd();
    titlePad->SetFillColor(kGray);
    TPaveText* titleBox = makeTitleBox( detType);
    titleBox->Draw();

    detPad->SetMargin(0.1,0.05,.1,0.1);

    //Plot det
     detPad->cd(); drawPlot(detType, PLOTVAR_GE,PLOT_DETS);

    TString coTypeString;
    if(detType==DET_EP)
    {
        coTypeString="EP";
    }
    else if(detType==DET_EPG)
    {
        coTypeString="EPG";
    }
    else if(detType==DET_EPBG)
    {
        coTypeString="EPBG";
    }
    TString imagePath=GRAPHS_DIR;
    imagePath+="layouts/PlotLayout";
    if(numMC) imagePath+="_MC";
    for (int i = 0;i< numMC;i++)
    {
        imagePath+=TString("_")+mc[i]->GetName();
    }
    if(numExp) imagePath+="_Exp";
    for (int i = 0;i< numExp;i++)
    {
        imagePath+=TString("_")+exp[i]->GetName();
    }

    imagePath+="_"+coTypeString+"_EPGPlots.pdf";
    theCanvas->SaveAs(imagePath);

    delete theCanvas;
    clearPlotHists();

}
void RDK2AnalysisPlotter::makeEPPlot(CoDet detType)
{
    gROOT->cd();
    TCanvas* theCanvas;
    TPad* mainPad;
    TPad* titlePad;
    TPad* pTPad;
    TPad* eEPad;
    TPad* pEPad;
    TPad* pTPadSubs[3];
    TPad* eEPadSubs[3];
    TPad* pEPadSubs[3];


    int numTitleLines=getTitleBoxLines( detType);
    int canvasNumPixelsYPlot=600;
    int canvasNumPixelsYPlots=3*canvasNumPixelsYPlot;
    int canvasNumPixelsYTitle=40*numTitleLines;
    int canvasNumPixelsY=canvasNumPixelsYPlots+canvasNumPixelsYTitle;

    theCanvas = new TCanvas("EPExpMCAnalysisComparisonPlot","EPExpMCAnalysisComparisonPlot",10,10,1200,canvasNumPixelsY);
     mainPad=(TPad*) theCanvas->GetPad(0);


    double ylow,yhigh;

    yhigh=1;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    titlePad=new TPad("titlePad", "titlePad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    pTPad=new TPad("pTPad", "pTPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    ylow=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY- 2*canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    eEPad=new TPad("eEPad", "eEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    yhigh=1.-canvasNumPixelsYTitle/(double)canvasNumPixelsY-2*canvasNumPixelsYPlot/(double)canvasNumPixelsY;
    ylow=0;
    pEPad=new TPad("pEPad", "pEPad", 0., ylow, 1., yhigh, -1, 1, 1);

    titlePad->Draw();
    pTPad->Draw();
    eEPad->Draw();
    pEPad->Draw();



//    titlePad=(TPad*) theCanvas->GetPad(1);
//    pTPad=(TPad*) theCanvas->GetPad(2);
//    eEPad=(TPad*) theCanvas->GetPad(3);
//    pEPad=(TPad*) theCanvas->GetPad(4);

    titlePad->SetMargin(0.05,0.0,0.0,0.0);
    pTPad->SetMargin(0.05,0.0,0.0,0.05);
    pEPad->SetMargin(0.05,0.0,0.0,0.05);
    eEPad->SetMargin(0.05,0.0,0.0,0.05);


    if(numExp+numMC >1)
    {
        pTPad->Divide(2);
        eEPad->Divide(2);
        pEPad->Divide(2);

        pTPadSubs[0]=(TPad*) pTPad->GetPad(1);
        eEPadSubs[0]=(TPad*) eEPad->GetPad(1);
        pEPadSubs[0]=(TPad*) pEPad->GetPad(1);

        TPad* tempPad;
        tempPad=(TPad*) pTPad->GetPad(2);
        tempPad->Divide(1,2);
        pTPadSubs[1]=(TPad*) tempPad->GetPad(1);
        pTPadSubs[2]=(TPad*) tempPad->GetPad(2);

        tempPad=(TPad*) pEPad->GetPad(2);
        tempPad->Divide(1,2);
        pEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        pEPadSubs[2]=(TPad*) tempPad->GetPad(2);

        tempPad=(TPad*) eEPad->GetPad(2);
        tempPad->Divide(1,2);
        eEPadSubs[1]=(TPad*) tempPad->GetPad(1);
        eEPadSubs[2]=(TPad*) tempPad->GetPad(2);

        TPad* allBasePads[10]={titlePad,pTPadSubs[0],pTPadSubs[1],pTPadSubs[2],eEPadSubs[0],eEPadSubs[1],eEPadSubs[2],pEPadSubs[0],pEPadSubs[1],pEPadSubs[2]};
        for (int i = 1;i< 10;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }
        pTPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);
        pEPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);
        eEPadSubs[0]->SetMargin(0.13,0.1,.1,0.1);

        pTPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        pEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);
        eEPadSubs[1]->SetMargin(0.1,0.1,.1,0.1);

        pTPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        pEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        eEPadSubs[2]->SetMargin(0.1,0.1,.1,0.1);
        //Plot pT

        pTPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_COMP);
        pTPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_RESID);
        pTPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_NORMRESID);


        //Plot eE
        eEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_COMP);
        eEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_RESID);
        eEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_NORMRESID);

        //Plot pE
        pEPadSubs[0]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_COMP);
        pEPadSubs[1]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_RESID);
        pEPadSubs[2]->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_NORMRESID);
    }
    else
    {
        TPad* allBasePads[4]={titlePad,pTPad,eEPad,pEPad};
        for (int i = 1;i< 4;i++)
        {
            allBasePads[i]->SetGrid(1,1);
            allBasePads[i]->SetTickx(1);
            allBasePads[i]->SetTicky(1);
        }
        pTPad->SetMargin(0.13,0.1,.1,0.1);
        pEPad->SetMargin(0.13,0.1,.1,0.1);
        eEPad->SetMargin(0.13,0.1,.1,0.1);
        pTPad->cd(); drawPlot(detType, PLOTVAR_PT,PLOT_COMP);
        eEPad->cd(); drawPlot(detType, PLOTVAR_EE,PLOT_COMP);
        pEPad->cd(); drawPlot(detType, PLOTVAR_PE,PLOT_COMP);

    }
    mainPad->SetFillColor(kGray);

    ///Make Title box
    titlePad->cd();
    titlePad->SetFillColor(kGray);
    TPaveText* titleBox = makeTitleBox( detType);
    titleBox->Draw();





    TString coTypeString;
    if(detType==DET_EP)
    {
        coTypeString="EP";
    }
    else if(detType==DET_EPG)
    {
        coTypeString="EPG";
    }
    else if(detType==DET_EPBG)
    {
        coTypeString="EPBG";
    }
     TString imagePath=GRAPHS_DIR;
    imagePath+="layouts/PlotLayout";
    if(numMC>0) imagePath+="_MC";
    for (int i = 0;i< numMC;i++)
    {
        imagePath+=TString("_")+mc[i]->GetName();
    }
    if(numExp>0) imagePath+="_Exp";
    for (int i = 0;i< numExp;i++)
    {
        imagePath+=TString("_")+exp[i]->GetName();
    }

    imagePath+="_"+coTypeString+"_EPPlots.pdf";
    theCanvas->SaveAs(imagePath);

    delete theCanvas;
    clearPlotHists();

}
void advancedNoiseAnalysis( unsigned int runNumber, unsigned int loop = 1) {
  
  string inputFileName = "./histo/run00" + toString( runNumber ) + "-ped-histo.root";
  string outputFileName = "./histo/run00" + toString( runNumber ) + "-adv-noise.root";
  

  // before opening the input and the output files, try to see if they
  // are not opened yet and in case close them before continue   
  TList * listOfOpenedFile = (TList*) gROOT->GetListOfFiles();
  for ( int i = 0; i < listOfOpenedFile->GetSize() ; ++i ) {
    TFile * file = (TFile*) listOfOpenedFile->At( i ) ;
    TString fileName(file->GetName());
    TString inputFileName1( inputFileName.c_str() );
    TString outputFileName1( outputFileName.c_str() );

    if (  ( fileName.Contains( inputFileName1 ) ) ||
	  ( inputFileName1.Contains( fileName ) ) ||
	  ( fileName.Contains( outputFileName1 ) ) ||
	  ( outputFileName1.Contains( fileName ) ) ) {
      cout << "Closing " << fileName << " before reopen " << endl;
      file->Close();
    }
  }


  // close also all the previously opened canvas
  TList * listOfOpenedCanvas = (TList*) gROOT->GetListOfCanvases();
  for ( int i = 0 ; i < listOfOpenedCanvas->GetSize() ; ++i ) {
    TCanvas * canvas = (TCanvas*) listOfOpenedCanvas->At( i );
    TString canvasName2 = canvas->GetName();
    if ( canvasName2.Contains( "det" ) ) {
      canvas->Close();
    }
  }

	 
  // now safely open the file
  TFile * inputFile = TFile::Open( inputFileName.c_str() ) ;
  TFile * outputFile = TFile::Open( outputFileName.c_str(), "RECREATE") ;
  TList * outputHistoList = new TList;

  // look into the inputFile for a folder named
  string pedeProcessorFolderName = "PedestalAndNoiseCalculator";
  TDirectoryFile * pedeProcessorFolder = (TDirectoryFile*) inputFile->Get( pedeProcessorFolderName.c_str() );
  
  if ( pedeProcessorFolder == 0 ) { 
    cerr << "No pedestal processor folder found in file " << inputFileName << endl;
    return ;
  }

  // this folder should contain one folder for each loop.
  string loopFolderName = "loop-" + toString( loop );
  TDirectoryFile * loopFolder = (TDirectoryFile *) pedeProcessorFolder->Get( loopFolderName.c_str() );
  
  if ( loopFolder == 0 ) {
    cerr << "No " << loopFolderName << " found in file " << inputFileName << endl;
    return ;
  }

  // guess the number of sensors from the number of subfolder in the loopfolder
  size_t nDetector = loopFolder->GetListOfKeys()->GetSize();
  cout << "This file contains " << nDetector << " detectors" << endl;

  // prepare arrays to store the mean and the rms of the noise distribution
  if ( noiseMean == NULL ) {
    delete [] noiseMean;
    noiseMean = NULL;
  }
  if ( noiseRMS == NULL ) {
    delete [] noiseRMS;
    noiseRMS = NULL;
  }
  if ( channel == NULL ) {
    delete [] channel;
    channel = NULL;
  }

  noiseMean = new double[ nDetector * kNChan ];
  noiseRMS  = new double[ nDetector * kNChan ];
  channel   = new double[ kNChan ];

  string canvasName = "comparison";
  string canvasTitle = "Noise comparison";

  TCanvas * comparisonCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  comparisonCanvas->Divide(1,2);
  
  TPad * topPad = (TPad*) comparisonCanvas->cd(1);
  topPad->Divide( nDetector );
  
  TPad * middlePad = (TPad *) comparisonCanvas->cd(2);
  middlePad->Divide( kNChan );


  // for each detector we have to get the noise map and to prepare 4
  // separe histos and maps
  for ( unsigned int iDetector = 0; iDetector < nDetector; iDetector++ ) {

    // get the noise map.
    string noiseMapName = "detector-" + toString( iDetector ) ;
    noiseMapName += "/NoiseMap-d" + toString( iDetector )  ;
    noiseMapName += "-l" + toString( loop ) ;
 
    TH2D * noiseMap = ( TH2D* ) loopFolder->Get( noiseMapName.c_str() ); 
    

    // create a folder in the output file
    TDirectory * subfolder = outputFile->mkdir( string( "detector_" + toString( iDetector ) ).c_str(),
						string( "detector_" + toString( iDetector ) ).c_str()
						);
    subfolder->cd();

    
    string canvasName = "det" + toString( iDetector );
    string canvasTitle = "Detector " + toString( iDetector );
    
    TCanvas * canvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
    canvas->Divide( kNChan, 2 );

    // ok now start the loop on channels
    for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) { 
	
      if ( iDetector == 0 ) channel[iChan] = iChan - 0.5;

      string tempName = "NoiseMap_d" + toString( iDetector ) + "_l" + toString( loop )	+ "_ch" + toString( iChan ) ;
      string tempTitle = "NoiseMap Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ;

      TH2D * noiseMapCh = new TH2D ( tempName.c_str() , tempTitle.c_str(), 
				     kXPixel / kNChan , -0.5 + xLimit[ iChan ] , -0.5 + xLimit[ iChan + 1 ],
				     kYPixel, -0.5, -0.5 + kYPixel );
      noiseMapCh->SetXTitle("X [pixel]");
      noiseMapCh->SetYTitle("Y [pixel]");
      noiseMapCh->SetZTitle("Noise [ADC]");
      noiseMapCh->SetStats( false );
      outputHistoList->Add( noiseMapCh ) ;

      tempName = "NoiseDist_d" + toString( iDetector ) + "_l" + toString( loop )	+ "_ch" + toString( iChan ) ;
      
      tempTitle = "NoiseDist Det. " + toString( iDetector ) + " - Ch. " + toString( iChan ) ; 

      TH1D * noiseDistCh = new TH1D( tempName.c_str(), tempTitle.c_str(), 50, 0., 10. );
      noiseDistCh->SetXTitle("Noise [ADC]");
      noiseDistCh->SetLineColor( kColor[iDetector]  );
      noiseDistCh->SetLineStyle( iChan + 2 );
      noiseDistCh->SetLineWidth( 2 );
      outputHistoList->Add( noiseDistCh );

      // let's start looping on pixels now
      for ( size_t yPixel = 1 ; yPixel <= kYPixel ; ++yPixel ) {
	for ( size_t xPixel = xLimit[ iChan ] + 1; xPixel <= xLimit[ iChan +1 ] ; ++xPixel ) {
	  double noise = noiseMap->GetBinContent( xPixel , yPixel );
	  noiseMapCh->Fill( xPixel - 1 , yPixel - 1, noise );
	  noiseDistCh->Fill( noise );
	  
	}
      }

      canvas->cd( iChan + 1 ) ;
      noiseMapCh->Draw("colz");
      canvas->cd( iChan + kNChan + 1  );
      noiseDistCh->Draw();
      
      topPad->cd( iDetector + 1 );
      if ( iChan == 0 ) {
	noiseDistCh->Draw();
      } else {
	noiseDistCh->Draw("same");
      }

      middlePad->cd( iChan + 1 );
      if ( iDetector == 0 ) {
	noiseDistCh->Draw();
      } else {
	noiseDistCh->Draw("same");
      }


      noiseMean[ kNChan * iDetector + iChan ] = noiseDistCh->GetMean();
      noiseRMS[ kNChan * iDetector  + iChan ] = noiseDistCh->GetRMS();
    }
    canvas->Write();

  }

  canvasName = "summary";
  canvasTitle = "Noise summary";

  TCanvas * summaryCanvas = new TCanvas( canvasName.c_str(), canvasTitle.c_str(), 1000, 500 );
  summaryCanvas->SetGridx(1);
  TLegend * legend = new TLegend(0.5, 4.8, 1.5, 4.3,"","br");;
  

  for ( size_t iDetector = 0 ; iDetector < nDetector ; ++iDetector ) {
    
    TGraphErrors * gr = new TGraphErrors( kNChan, channel, &noiseMean[ iDetector * kNChan ], NULL, &noiseRMS[ iDetector * kNChan ] );
    gr->SetName( string( "NoisePerChannel_d" + toString( iDetector )).c_str());
    gr->SetTitle(string("Detector " + toString( iDetector )).c_str());
    gr->GetXaxis()->SetTitle("Channel #");
    gr->GetYaxis()->SetTitle("Noise [ADC]");
    gr->GetXaxis()->SetNdivisions( 5 );
    gr->GetXaxis()->SetLabelSize( 0 );
    gr->SetMarkerStyle( iDetector + 1 );
    gr->SetMarkerColor( kColor[iDetector] );
    gr->SetLineColor( kColor[iDetector] );
    gr->SetLineWidth( 2 );

    
    legend->AddEntry( gr, string("Detector " + toString( iDetector )).c_str(), "LP");

    if ( iDetector == 0 ) {
      gr->Draw("ALP");
    } else {
      gr->Draw("LP");
    }
    

  }

  
  
  legend->Draw();

  for ( size_t iChan = 0 ; iChan < kNChan ; ++iChan ) {
    
    TPaveLabel * label = new TPaveLabel( iChan - 0.75 , 3.2 , iChan -0.25 , 3, string("Ch " + toString( iChan ) ).c_str());
    label->Draw();
  }


  summaryCanvas->Write();
  comparisonCanvas->Write();

  outputHistoList->Write();

  

 
} 
Exemple #5
0
/*#include "TTree.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TMultiGraph.h"
#include "TRint.h"
#include <time.h>
#include <stdio.h>

const short MaxNN = 6;
*/
void make_scatterplot(TString data_file, TString plot_name, TString header)
{
	//TApplication program = new TRInt(); 
	//pull in data
	TTree *t = new TTree(); 
	t->ReadFile(data_file);
	t->SetName("t");
	
	//TString name = "run2.png";
	TCanvas *BG = new TCanvas("c1", "Read Velocity on Local Disk for CMS3 Files", 1920, 1080);
	BG->cd();
	TPad *c = new TPad("MainPad", "My main pad", 0, 0, 1, 0.9);
	c->Draw();
	c->Divide(2,2);

	//In first slot have Time vs. Buffer for 1 Concurrent Read
	c->cd(1);
	int n1 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==1", "goff");
	TGraph *ghist1 = new TGraph(n1, t->GetV2(), t->GetV1());
	ghist1->SetName("ghist1");
	ghist1->SetMarkerStyle(3);
	ghist1->SetMarkerColor(1);
	ghist1->SetTitle("Single File Read");
	ghist1->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist1->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist1->Draw("ap");
	
	//In second slot have Time vs. Buffer for 3 Concurrent Reads
	c->cd(2);
	int n2 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==3", "goff");
	TGraph *ghist2 = new TGraph(n2, t->GetV2(), t->GetV1());
	Double_t DP2x[n2], DP2y[n2];
	ghist2->SetName("ghist2");
	ghist2->SetMarkerStyle(3);
	ghist2->SetMarkerColor(1);
	ghist2->SetTitle("3 Concurrent Reads");
	ghist2->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist2->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist2->Draw("ap");
	
	//In third slot have Time vs. Buffer for 3 Concurrent Reads
	c->cd(3);
	int n3 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==6", "goff");
	TGraph *ghist3 = new TGraph(n3, t->GetV2(), t->GetV1());
	Double_t DP3x[n3], DP3y[n3];
	ghist3->SetName("ghist3");
	ghist3->SetMarkerStyle(3);
	ghist3->SetMarkerColor(1);
	ghist3->SetTitle("6 Concurrent Reads");
	ghist3->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist3->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist3->Draw("ap");
	
	//In fourth slot have Time vs. Buffer for 10 Concurrent Reads
	c->cd(4);
	int n4 = t->Draw("VelocityMBps:BufferSize", "ConcurrentReads==10", "goff");
	TGraph *ghist4 = new TGraph(n4, t->GetV2(), t->GetV1());
	ghist4->SetMarkerStyle(3);
	ghist4->SetName("ghist4");
	ghist4->SetMarkerColor(1);
	ghist4->SetTitle("10 Concurrent Reads");
	ghist4->GetXaxis()->SetTitle("Buffer Size (Bytes)");
	ghist4->GetYaxis()->SetTitle("Read Velocity (MB/s)");
	ghist4->Draw("ap");
	
	//Draw to screen
	//Initialize Canvas
	
	c->cd(0);
	c->Draw();
	
	BG->cd();
	TText *title = new TText(.5,.95, header);
	title->SetTextAlign(22);
	title->Draw();
	
	gDirectory->Add(ghist1);
	gDirectory->Add(ghist2);
	gDirectory->Add(ghist3);
	gDirectory->Add(ghist4);
	gDirectory->Add(t);
	gPad->SaveAs(plot_name);
}
Exemple #6
0
void compareInDir(TFile* f1, TFile* f2, std::string dirName,unsigned int logmod=0, unsigned int dOpt=1){
  TCanvas* cv = 0;
  TPad* pH = 0;
  TPad* pD = 0;

  TPaveText* pt = 0;

  //  std::cout<<"Start with "<<dirName.c_str()<<std::endl;
  //  cv->Print("diff.ps[");
  
  TDirectory* d1 = f1->GetDirectory(dirName.c_str());
  TDirectory* d2 = f2->GetDirectory(dirName.c_str());

  if (d1==0 || d2 == 0){
    std::cout<<"ERROR: "<<dirName.c_str()<<" not found"<<std::endl;
    return;
  }
  //  std::cout<<"\t\t "<<d1->GetName()<<std::endl;

  TList* list1 = d1->GetListOfKeys();
  
  TIterator* keyIt1 = list1->MakeIterator();

  TObject* obj;  
  while ((obj = keyIt1->Next())){
    TObject* obj1 = d1->Get(obj->GetName());    
    if(obj1 == 0){
      //      std::cout<<"ERROR: failed to read in "<<d1->GetName()<<" / "<<obj->GetName()<<std::endl;
      continue;
    }
    //    std::cout<<d1->GetName()<<"/"<<obj->GetName()<<std::endl;
    if (! obj1->InheritsFrom(TH1::Class())) continue;
    
    TObject* obj2 = d2->Get(obj1->GetName());
    if (obj2 == 0){
      //      std::cout<<"WARNING: failed to get"<<d1->GetName()<<"/"<<obj1->GetName()<<std::endl;
      continue;
    }

    TH1* h1 = (TH1*)obj1;
    TH1* h2 = (TH1*)obj2;
    //    std::cout<<"Will check "<<dirName.c_str()<<"/"<<h1->GetName()<<" dOpt "<<dOpt<<std::endl;
    if(h1->Integral() == 0 && h2->Integral() == 0){
      //      std::cout<<"Integral is 0: "<<d1->GetName()<<"/"<<obj1->GetName()<<std::endl;
      continue;
    }
    //    if (TString(h1->GetTitle()).Index("ffic")<0) continue;
    bool isProf = obj1->InheritsFrom(TProfile::Class());
    bool isH2   = obj1->InheritsFrom(TH2::Class());
    double bDiff = 0;
    if(!isH2){
      unsigned int nX1 = h1->GetNbinsX();
      //      std::cout<<"\t is 1D with nBins "<<nX1<<std::endl;
      for(unsigned int iB=0; iB<=nX1+1; ++iB){
	if(h1->GetBinError(iB)==0 && h1->GetBinContent(iB)!=0) h1->SetBinError(iB,1e-3*fabs(h1->GetBinContent(iB)));
	if(h2->GetBinError(iB)==0 && h2->GetBinContent(iB)!=0) h2->SetBinError(iB,1e-3*fabs(h2->GetBinContent(iB)));
	bDiff +=fabs(h1->GetBinContent(iB) - h2->GetBinContent(iB));
      }
    } else {
      unsigned int nX1 = h1->GetNbinsX();
      unsigned int nY1 = h1->GetNbinsY();
      //      std::cout<<"\t is 2D with nBins "<<nX1<<" : "<<nY1<<std::endl;
      for(unsigned int iB=0; iB<=nX1+1; ++iB){
	for(unsigned int jB=0; jB<=nY1+1; ++jB){
	  if(h1->GetBinError(iB,jB)==0 && h1->GetBinContent(iB,jB)!=0) h1->SetBinError(iB,jB,1e-3*fabs(h1->GetBinContent(iB,jB)));
	  if(h2->GetBinError(iB,jB)==0 && h2->GetBinContent(iB,jB)!=0) h2->SetBinError(iB,jB,1e-3*fabs(h2->GetBinContent(iB,jB)));
	  bDiff +=fabs(h1->GetBinContent(iB,jB) - h2->GetBinContent(iB,jB));
	}
      }
    }

    double ksProb = 0;
    if (bDiff == 0) ksProb = 1;
    else ksProb = h1->KolmogorovTest(h2);
    if (dOpt%10 == 0 && bDiff ==0 ) continue;
    if (dOpt%10 == 1 && (bDiff ==0 || 1.-ksProb <1e-12) ) continue;
    if (dOpt%10 == 2 && (bDiff ==0 || ksProb >0.1 )) continue;
    if (dOpt%10 == 3 && (bDiff ==0 || 1.-ksProb < 0.001 )) continue;
    if (dOpt%10 == 4 && (bDiff ==0 || ksProb >0.9 )) continue;
    if (dOpt%10 == 5 && (bDiff ==0 || ksProb >0.5 )) continue;

    if (cv == 0){
      cv = new TCanvas(dirName.c_str(),dirName.c_str());
      cv->cd();
      pH = new TPad("head","head", 0, 0.93, 1, 1);
      pH->Draw();
      pH->cd();
      pt = new TPaveText(0,0,1,1); pt->SetFillColor(0);
      pt->AddText(dirName.c_str());
      pt->Draw();
      cv->cd();
      pD = new TPad("dis","dis", 0, 0.0, 1, 0.93);
      pD->Draw();
      pD->cd();
    }
    
    pD->Clear();
    pD->cd();
    std::cout<<"Save : "<<dirName.c_str()<<"/"<<h1->GetName()<<std::endl;

    if (! isH2){
      h1->SetLineWidth(2);
      h1->SetLineColor(1);
      h1->SetMarkerColor(1);
      h2->SetLineColor(2);
      h2->SetMarkerColor(2);
      //      if (h1->GetNbinsX() > 25) h1 = h1->Rebin();
 //     if (h2->GetNbinsX() > 25) h2 = h2->Rebin();
      //      if (h1->GetNbinsX() > 50) h1 = h1->Rebin(5);
      //      if (h2->GetNbinsX() > 50) h2 = h2->Rebin(5);
      double max1 = h1->GetMaximum();
      double max2 = h2->GetMaximum();
      double min1 = h1->GetMinimum();
      double min2 = h2->GetMinimum();
      if (max2> max1) h1->SetMaximum(max2+0.15*fabs(max2));
      if (min2 < min1) h1->SetMinimum(min2-0.15*fabs(min2));
      //      pD->SetLogy();
      if ((logmod&1)) pD->SetLogx();
      if ((logmod&2)) pD->SetLogy();
      h1->Draw();
      h2->Draw("sames");   

      if (std::string(h1->GetName())==std::string("reconstruction_step_module_total")
	  || std::string(h1->GetName())==std::string("validation_step_module_total")){
	TPaveText ksPt(0,0, 0.35, 0.04, "NDC"); ksPt.SetBorderSize(0); ksPt.SetFillColor(0);
	ksPt.AddText(Form("P(KS)=%g, diffBins=%g, eblk %g ered %g",ksProb, bDiff, h1->GetEntries(), h2->GetEntries()));
	//	ksPt.AddText(h1->GetName());
	ksPt.Draw();
	cv->Print("diff.ps");

	int nX = h1->GetNbinsX();
	TAxis* h1Ax = h1->GetXaxis();
	int nRanges = nX/20 + 1;
	double h1Int = h1->Integral();
	float curBMargin = pD->GetBottomMargin(); 
	pD->SetBottomMargin(0.3);
	for (int iR = 0; iR < nRanges; iR++){
	  h1Ax->SetRange(iR*20+1, iR*20+20);
	  double bDiffL = 0;
	  double max1L = -1;
	  double max2L = -1;
	  double min1L = h1->GetMaximum();
	  double min2L = h2->GetMaximum();
	  for (int iBL = iR*20+1; iBL<= iR*20+20; ++iBL){
	    double h1L = h1->GetBinContent(iBL);
	    double h2L = h2->GetBinContent(iBL);
	    bDiffL += std::abs(h1L-h2L);
	    if (max1L < h1L) max1L = h1L;
	    if (max2L < h2L) max2L = h2L;
	    if (min1L > h1L) min1L = h1L;
	    if (min2L > h2L) min2L = h2L;
	  }
	  if (max2L> max1L)  h1->SetMaximum(max2L+0.15*std::abs(max2L));
	  else h1->SetMaximum(max1L+0.15*std::abs(max1L));
	  if (min2L < min1L) h1->SetMinimum(min2L-0.15*std::abs(min2L));
	  else h1->SetMinimum(min1L-0.15*std::abs(min1L));
	  h1->Draw();
	  h2->Draw("sames");
	  TPaveText ksPtL(0,0, 0.35, 0.04, "NDC"); ksPtL.SetBorderSize(0); ksPtL.SetFillColor(0);
	  ksPtL.AddText(Form("P(KS)=%g, diffBinsL=%g(%g), eblk %g ered %g",ksProb, bDiffL, bDiffL/h1Int, h1->GetEntries(), h2->GetEntries()));
	  ksPtL.Draw();
	  cv->Print("diff.ps");
	}
	pD->SetBottomMargin(curBMargin);

      }
    }
    if (isH2){
      pD->Divide(2);
      pD->cd(1);
      h1->Draw("colz");
      pD->cd(2);
      h2->Draw("colz");
    }
    TPaveText ksPt(0,0, 0.55, 0.06, "NDC"); ksPt.SetBorderSize(0); ksPt.SetFillColor(0);
    ksPt.AddText(Form("P(KS)=%g, diffBins=%g, eblk %g ered %g",ksProb, bDiff, h1->GetEntries(), h2->GetEntries()));
    ksPt.AddText(h1->GetName());
    ksPt.Draw();
    cv->Print("diff.ps");
    cv->Print("diff.pdf");


  }

  //  std::cout<<"Done in "<<dirName.c_str()<<std::endl;
  //  delete pH; delete pD;
  if (cv) delete cv;
  //  cv->Print("diff.ps]");
}
void PlotFinal(TGraphAsymmErrors* g_data_final, TGraphAsymmErrors* g_mg_final, TGraphAsymmErrors* g_ph_final, TGraphAsymmErrors* g_ratio_phistar, TGraphAsymmErrors* g_ratio_mg_phistar, TGraphAsymmErrors* g_ratio_ph_phistar, bool isPlot2 = 0, TGraphAsymmErrors* g_re_final = 0, TGraphAsymmErrors* g_ratio_re_phistar = 0) {

    vector<TGraphAsymmErrors*> g_data = SplitGraph(g_data_final);
    vector<TGraphAsymmErrors*> g_mg = SplitGraph(g_mg_final);
    vector<TGraphAsymmErrors*> g_ph = SplitGraph(g_ph_final);
    vector<TGraphAsymmErrors*> r_data = SplitGraph(g_ratio_phistar, 1);
    vector<TGraphAsymmErrors*> r_mg = SplitGraph(g_ratio_mg_phistar);
    vector<TGraphAsymmErrors*> r_ph = SplitGraph(g_ratio_ph_phistar);
    vector<TGraphAsymmErrors*> g_re = SplitGraph(g_re_final);
    vector<TGraphAsymmErrors*> r_re = SplitGraph(g_ratio_re_phistar);
    //New Graphs
    TGraphAsymmErrors* g_ANlo_final = ResbosFromRaj(2);
    TGraphAsymmErrors* r_ANlo_Ratio_final = CreateRatio(g_data_final, g_ANlo_final, 0);
    TGraphAsymmErrors* g_PowPyth8_final = ResbosFromRaj(1);
    TGraphAsymmErrors* r_PowPyth8_Ratio_final = CreateRatio(g_data_final, g_PowPyth8_final, 0);

    vector<TGraphAsymmErrors*> g_ANlo = SplitGraph(g_ANlo_final);
    vector<TGraphAsymmErrors*> r_ANlo = SplitGraph(r_ANlo_Ratio_final);
    vector<TGraphAsymmErrors*> g_Pyth8 = SplitGraph(g_PowPyth8_final);
    vector<TGraphAsymmErrors*> r_Pyth8 = SplitGraph(r_PowPyth8_Ratio_final);

    vector<TGraphAsymmErrors*> g_dummy = CreateDummy(g_data);
    OneDYPlot(g_data, g_mg, g_ph, g_re, g_ANlo, g_Pyth8);
    for (uint i = 0; i < ny; i++) {
        //  for (uint i=0; i<5; i++){ 
        std::ostringstream strs;
        strs << i;
        //TO HERE
        std::string Canvasname = "EventEff_Bin" + strs.str();

        TCanvas* FinalPhiTot = new TCanvas(Canvasname.c_str(), Canvasname.c_str(), 800, 900);
        FinalPhiTot->Divide(1, 2);
        FinalPhiTot->cd(1);
        gPad->SetPad("p1", "p1", 0, 2.5 / 9.0, 1, 1, kWhite, 0, 0);
        gPad->SetBottomMargin(0.01);
        gPad->SetTopMargin(0.06);
        gPad->SetLeftMargin(0.15);
        gPad->SetRightMargin(0.06);
        gPad->SetLogx(1);
        gPad->SetLogy(1);
        g_dummy[i]->GetXaxis()->SetRangeUser(0.001, 10.0);
        if (doNorm) g_dummy[i]->GetYaxis()->SetRangeUser(0.00000005, 1000.0);
        else g_dummy[i]->GetYaxis()->SetRangeUser(0.00005, 1000000.0);
        g_dummy[i]->GetXaxis()->CenterTitle();
        g_dummy[i]->GetYaxis()->CenterTitle();
        g_dummy[i]->Draw("A2");
        g_mg[i]->SetMarkerColor(kBlue - 7);
        g_mg[i]->SetLineColor(kBlue - 7);
        g_mg[i]->SetMarkerSize(1);
        g_mg[i]->SetLineWidth(2);
        g_mg[i]->SetMarkerStyle(21);
        g_mg[i]->Draw("PEsame");
        g_ph[i]->SetMarkerColor(kRed);
        g_ph[i]->SetLineColor(kRed);
        g_ph[i]->SetMarkerSize(1);
        g_ph[i]->SetLineWidth(2);
        g_ph[i]->SetMarkerStyle(22);
        g_ph[i]->Draw("PEsame");
        if (!isPlot2 && elec == 1 && g_re_final) {
            g_re[i]->SetMarkerColor(kGreen + 1);
            g_re[i]->SetLineColor(kGreen + 1);
            g_re[i]->SetMarkerSize(1);
            g_re[i]->SetLineWidth(2);
            g_re[i]->SetMarkerStyle(23);
            g_re[i]->Draw("PEsame");
        }
        g_data[i]->SetFillColor(kYellow);
        g_data[i]->SetMarkerSize(1);
        g_data[i]->SetLineWidth(2);
        g_data[i]->SetMarkerStyle(20);
        g_data[i]->Draw("PEsame");
        g_data[i]->SetFillColor(kYellow);

        TLegend* leg;
        if (isPlot2) leg = new TLegend(0.15, 0.06, 0.80, 0.27);
        else leg = new TLegend(0.15, 0.06, 0.80, 0.31); //TLegend(0.45,0.73,0.94,0.93);//.19 0.06
        leg->SetFillStyle(0);
        leg->SetBorderSize(0);
        leg->SetLineWidth(1);
        leg->SetNColumns(1);
        leg->SetTextFont(42);

        if (!isPlot2) {
            leg->AddEntry(g_data[i], "2012 data", "PEF");
            if (Type == "elec") {
                leg->AddEntry(g_mg[i], "#gamma*/Z #rightarrow ee (MadGraph+Pythia6 Z2*)", "P");
                leg->AddEntry(g_ph[i], "#gamma*/Z #rightarrow ee (Powheg+Pythia6 Z2*)", "P");
                //ToDo AMCAt decisions
                //if (elec == 1 && g_re_final) leg->AddEntry(g_re[i], "#gamma*/Z #rightarrow ee (Resbos)", "P");
                if (elec == 1 && g_re_final) leg->AddEntry(g_re[i], "#gamma*/Z #rightarrow ee (POWHEG+Pythia8)", "P");
            }
            if (Type == "muon") {
                leg->AddEntry(g_mg[i], "#gamma*/Z #rightarrow #mu#mu (MadGraph+Pythia6 Z2*)", "P");
                leg->AddEntry(g_ph[i], "#gamma*/Z #rightarrow #mu#mu (Powheg+Pythia6 Z2*)", "P");
                if (elec == 1 && g_re_final) leg->AddEntry(g_re[i], "#gamma*/Z #rightarrow #mu#mu (Resbos)", "P");
                //if (elec == 1 && g_re_final) leg->AddEntry(g_re[i], "#gamma*/Z #rightarrow #mu#mu (POWHEG+Pythia8 CUETP8M1)", "P");
            }
            if (Type == "combined") {
                leg->AddEntry(g_mg[i], "#gamma*/Z #rightarrow ll (MadGraph+Pythia6 Z2*)", "P");
                leg->AddEntry(g_ph[i], "#gamma*/Z #rightarrow ll (Powheg+Pythia6 Z2*)", "P");
                if (elec == 1 && g_re_final) leg->AddEntry(g_re[i], "#gamma*/Z #rightarrow ll (Resbos)", "P");
                //if (elec == 1 && g_re_final) leg->AddEntry(g_re[i], "#gamma*/Z #rightarrow ll (POWHEG+Pythia8 CUETP8M1)", "P");
            }
        } else {
            if (Type == "combined") {
                leg->AddEntry(g_mg[i], "#gamma*/Z #rightarrow ee (2012 data)", "P");
                leg->AddEntry(g_ph[i], "#gamma*/Z #rightarrow #mu#mu (2012 data)", "P");
                if (doMG)leg->AddEntry(g_data[i], "#gamma*/Z #rightarrow ll (MadGraph+Pythia6 Z2*)", "PEF");
                else leg->AddEntry(g_data[i], "#gamma*/Z #rightarrow ll (Powheg+Pythia6 Z2*)", "PEF");
            }
            if (Type == "elec") {
                leg->AddEntry(g_mg[i], "data (unfolded with Powheg)", "P");
                leg->AddEntry(g_ph[i], "data (unfolded with MadGraph)", "P");
                if (doMG)leg->AddEntry(g_data[i], "#gamma*/Z #rightarrow ll (MadGraph+Pythia6 Z2*)", "PEF");
                else leg->AddEntry(g_data[i], "#gamma*/Z #rightarrow ll (Powheg+Pythia6 Z2*)", "PEF");
            }
        }
        leg->Draw();

        TLatex mark3;
        mark3.SetTextSize(0.043);
        mark3.SetTextFont(42);
        mark3.SetNDC(true);
        mark3.DrawLatex(0.71, 0.955, "19.7 fb^{-1} (8 TeV)");
        TLatex mark;
        mark.SetTextSize(0.043);
        mark.SetTextFont(42);
        mark.SetNDC(true);
        if (Type == "elec" && !isPlot2) {
            mark.DrawLatex(0.53, 0.88, "|#eta^{e_{0}}| < 2.1,        |#eta^{e_{1}}| < 2.4");
            mark.DrawLatex(0.53, 0.81, "p_{T}^{e_{0}} > 30 GeV,   p_{T}^{e_{1}} > 20 GeV");
            mark.DrawLatex(0.53, 0.74, "60 GeV < M_{ee} < 120 GeV");
        }
        if (Type == "combined" || isPlot2) {
            mark.DrawLatex(0.53, 0.88, "|#eta^{l_{0}}| < 2.1,        |#eta^{l_{1}}| < 2.4");
            mark.DrawLatex(0.53, 0.81, "p_{T}^{l_{0}} > 30 GeV,  p_{T}^{l_{1}} > 20 GeV");
            mark.DrawLatex(0.53, 0.74, "60 GeV < M_{ll} < 120 GeV");
        }
        if (i == 0) mark.DrawLatex(0.2, 0.88, "0.0 < |y_{ee}| < 0.4");
        if (i == 1) mark.DrawLatex(0.2, 0.88, "0.4 < |y_{ee}| < 0.8");
        if (i == 2) mark.DrawLatex(0.2, 0.88, "0.8 < |y_{ee}| < 1.2");
        if (i == 3) mark.DrawLatex(0.2, 0.88, "1.2 < |y_{ee}| < 1.6");
        if (i == 4) mark.DrawLatex(0.2, 0.88, "1.6 < |y_{ee}| < 2.0");
        if (i == 5) mark.DrawLatex(0.2, 0.88, "2.0 < |y_{ee}| < 2.4");
        FinalPhiTot->cd(2);
        gPad->SetPad("p2", "p2", 0, 0, 1, 2.5 / 9.0, kWhite, 0, 0);
        gPad->SetBottomMargin(0.37);
        gPad->SetTopMargin(0.01);
        gPad->SetLeftMargin(0.15);
        gPad->SetRightMargin(0.06);
        gPad->SetLogx(1);

        r_data[i]->SetLineWidth(2);
        r_data[i]->GetXaxis()->SetRangeUser(0.001, 10);
        r_data[i]->GetXaxis()->SetTitle("#phi*");
        r_data[i]->GetXaxis()->SetTitleOffset(1.05);
        r_data[i]->GetXaxis()->SetTitleSize(0.12);
        r_data[i]->GetXaxis()->SetLabelSize(0.12);
        r_data[i]->GetYaxis()->SetTitle("MC/Data  ");
        //   r_data[i]->GetYaxis()->SetRangeUser(0.8,1.2);
        r_data[i]->GetYaxis()->SetTitleOffset(0.32);
        r_data[i]->GetYaxis()->SetTitleSize(0.12);
        r_data[i]->GetYaxis()->SetLabelSize(0.12);
        r_data[i]->SetTitle(0);
        if (isPlot2) r_data[i]->GetYaxis()->SetTitle("Data/MC  ");
        else r_data[i]->GetYaxis()->SetTitle("MC/Data   ");
        r_data[i]->GetYaxis()->SetRangeUser(0.5, 1.5);
        r_data[i]->GetYaxis()->SetNdivisions(2, 5, 0);
        if (isPlot2) r_data[i]->GetYaxis()->SetRangeUser(0.3, 1.35);
        if (isPlot2 && (!doNorm)) r_data[i]->GetYaxis()->SetRangeUser(0.7, 1.3);
        r_data[i]->GetYaxis()->SetNdivisions(2, 5, 0);
        r_data[i]->GetYaxis()->SetTitleOffset(0.45);
        r_data[i]->SetFillColor(kYellow);
        r_data[i]->GetXaxis()->SetTitleSize(0.15);
        r_data[i]->GetXaxis()->CenterTitle();
        r_data[i]->GetYaxis()->CenterTitle();
        r_data[i]->Draw("APE2");
        r_mg[i]->SetMarkerSize(1);
        r_mg[i]->SetLineWidth(2);
        r_mg[i]->SetMarkerStyle(21);
        r_mg[i]->SetMarkerColor(kBlue - 7);
        r_mg[i]->SetLineColor(kBlue - 7);
        r_mg[i]->Draw("PEsame");
        r_ph[i]->SetMarkerSize(1);
        r_ph[i]->SetLineWidth(2);
        r_ph[i]->SetMarkerStyle(22);
        r_ph[i]->SetMarkerColor(kRed);
        r_ph[i]->SetLineColor(kRed);
        r_ph[i]->Draw("PEsame");
        r_re[i]->SetMarkerSize(1);
        r_re[i]->SetLineWidth(2);
        r_re[i]->SetMarkerStyle(23);
        r_re[i]->SetMarkerColor(kGreen + 1);
        r_re[i]->SetLineColor(kGreen + 1);
        r_re[i]->Draw("PEsame");

        std::string plotname = "Plots/ZShape_2D_";
        plotname += "Bin" + strs.str() + "_";
        plotname += Tag;
        if (isPlot2 && Type == "combined")plotname += "MuEl";
        else if (isPlot2 && Type == "elec")plotname += "PHMG";
        else plotname += Type;
        plotname += "_";
        if ((Type == "elec" || isPlot2) && !doMG) plotname += "PH_";
        if ((Type == "elec" || isPlot2) && doMG) plotname += "MG_";
        if (doNorm) plotname += "Norm_";
        else plotname += "Abs_";
        if (elec == 0)plotname += "Dressed.";
        if (elec == 1)plotname += "Born.";
        if (elec == 2)plotname += "Naked.";
        //FinalPhiTot->SaveAs((plotname + OutType).c_str());
        delete FinalPhiTot;
        //TO HERE ZACH


        TCanvas* FinalPhiRatio = new TCanvas("FinalPhiRatio", "FinalPhiRatio", 800, 900);
        FinalPhiRatio->cd();
        FinalPhiRatio->SetLogx();
        r_data[i]->GetYaxis()->SetTitle("MC/Data");
        r_data[i]->SetFillColor(kYellow);
        r_data[i]->GetYaxis()->SetRangeUser(0.5, 1.5);
        r_data[i]->GetYaxis()->SetTitleOffset(1.2);
        r_data[i]->GetYaxis()->SetTitleSize(0.04);
        r_data[i]->GetYaxis()->SetLabelSize(0.04);
        r_data[i]->GetXaxis()->SetTitleSize(0.04);
        r_data[i]->GetXaxis()->SetLabelSize(0.04);
        r_data[i]->GetXaxis()->SetLabelOffset(-0.01);
        r_data[i]->Draw("AE2");

        r_mg[i]->SetMarkerStyle(kFullTriangleUp);
        r_mg[i]->SetMarkerColor(kBlue - 7);
        r_mg[i]->SetLineColor(kBlue - 7);

        r_ph[i]->SetMarkerSize(1);
        r_ph[i]->SetLineWidth(2);
        r_ph[i]->SetMarkerStyle(kFullSquare);
        r_ph[i]->SetMarkerColor(kRed);
        r_ph[i]->SetLineColor(kRed);
        r_ph[i]->Draw("PEsame");

        r_mg[i]->Draw("PEsame");

        r_re[i]->SetMarkerColor(kGreen + 1);
        r_re[i]->SetLineColor(kGreen + 1);
        r_re[i]->SetMarkerSize(1);
        r_re[i]->SetLineWidth(2);
        r_re[i]->SetMarkerStyle(kStar);
        r_re[i]->Draw("PEsame");

        r_ANlo[i]->SetMarkerSize(1);
        r_ANlo[i]->SetLineWidth(2);
        r_ANlo[i]->SetMarkerStyle(kOpenCircle);
        r_ANlo[i]->SetMarkerColor(kCyan + 2);
        r_ANlo[i]->SetLineColor(kCyan + 2);
        r_ANlo[i]->Draw("PEsame");

        r_Pyth8[i]->SetMarkerSize(1);
        r_Pyth8[i]->SetLineWidth(2);
        r_Pyth8[i]->SetMarkerStyle(kOpenSquare);
        r_Pyth8[i]->SetMarkerColor(kRed);
        r_Pyth8[i]->SetLineColor(kRed);
        r_Pyth8[i]->Draw("PEsame");

        //r_data[i]->Draw("PEsame");

        mark.SetTextSize(0.03);
        mark.DrawLatex(0.7, 0.907, "19.7 fb^{-1} (8 TeV)");
        mark.DrawLatex(0.19, 0.907, "CMS Preliminary");
        if (i == 0) mark.DrawLatex(0.15, 0.3, "0.0 < |y_{ll}| < 0.4");
        if (i == 1) mark.DrawLatex(0.15, 0.3, "0.4 < |y_{ll}| < 0.8");
        if (i == 2) mark.DrawLatex(0.15, 0.3, "0.8 < |y_{ll}| < 1.2");
        if (i == 3) mark.DrawLatex(0.15, 0.3, "1.2 < |y_{ll}| < 1.6");
        if (i == 4) mark.DrawLatex(0.15, 0.3, "1.6 < |y_{ll}| < 2.0");
        if (i == 5) mark.DrawLatex(0.15, 0.35, "2.0 < |y_{ll}| < 2.4");
        if (Type == "elec" && !isPlot2) {
            mark.DrawLatex(0.15, 0.25, "|#eta^{l_{0}}| < 2.1,        |#eta^{l_{1}}| < 2.4");
            mark.DrawLatex(0.15, 0.20, "p_{T}^{l_{0}} > 30 GeV,   p_{T}^{l_{1}} > 20 GeV");
            if (i != 5)mark.DrawLatex(0.15, 0.15, "60 GeV < M_{ll} < 120 GeV");
            else mark.DrawLatex(0.15, 0.30, "60 GeV < M_{ll} < 120 GeV");
        }
        if (Type == "muon" && !isPlot2) {
            mark.DrawLatex(0.15, 0.25, "|#eta^{#mu_{0}}| < 2.1,        |#eta^{#mu_{1}}| < 2.4");
            mark.DrawLatex(0.15, 0.20, "p_{T}^{#mu_{0}} > 30 GeV,   p_{T}^{#mu_{1}} > 20 GeV");
            mark.DrawLatex(0.15, 0.15, "60 GeV < M_{#mu#mu} < 120 GeV");
        }
        if (Type == "combined" || isPlot2) {
            mark.DrawLatex(0.15, 0.25, "|#eta^{l_{0}}| < 2.1,        |#eta^{l_{1}}| < 2.4");
            mark.DrawLatex(0.15, 0.20, "p_{T}^{l_{0}} > 30 GeV,   p_{T}^{l_{1}} > 20 GeV");
            mark.DrawLatex(0.15, 0.15, "60 GeV < M_{ll} < 120 GeV");
        }

        TLegend* leg2 = new TLegend(0.13, 0.72, 0.7, 0.9);
        leg2->SetFillStyle(0);
        leg2->SetBorderSize(0);
        leg2->SetLineWidth(1);
        leg2->SetNColumns(1);
        leg2->SetTextFont(22);

        leg2->AddEntry(r_data[i], "2012 data", "F");
        if (Type == "elec") {
            leg2->AddEntry(r_mg[i], " MadGraph+Pythia6 (Z2*)", "P");
            leg2->AddEntry(r_ph[i], "POWHEG+Pythia6 (Z2*)", "P");
            leg2->AddEntry(r_re[i], "Resbos", "P");
            leg2->AddEntry(r_ANlo[i], "AMC@nlo+Pythia8(CUETP8M1)", "P");
            leg2->AddEntry(r_Pyth8[i], "POWHEG+Pythia8 (CT10)", "P");
        }
        if (Type == "muon") {
            leg2->AddEntry(r_mg[i], "Z #rightarrow #mu#mu MadGraph", "P");
            leg2->AddEntry(r_ph[i], "Z #rightarrow #mu#mu Powheg", "P");
        }
        if (Type == "combined") {
            leg2->AddEntry(r_mg[i], "Z #rightarrow ll MadGraph", "P");
            leg2->AddEntry(r_ph[i], "Z #rightarrow ll Powheg", "P");
        }
        leg2->Draw();
        plotname = "ZShape_Ratio";

        plotname += Tag;
        if (isPlot2)plotname += "MuEl";
        else plotname += Type;
        plotname = "Plots/Ratio_ZShape_2D_";
        plotname += "Bin" + strs.str() + "_";
        plotname += Tag;
        //if (isPlot2 && Type == "combined")plotname += "MuEl";
        //else if (isPlot2 && Type == "elec")plotname += "PHMG";
        plotname += Type;
        plotname += "_";
        if ((Type == "elec" || isPlot2) && !doMG) plotname += "PH_";
        if ((Type == "elec" || isPlot2) && doMG) plotname += "MG_";
        if (doNorm) plotname += "Norm_";
        else plotname += "Abs_";
        if (elec == 0)plotname += "Dressed.";
        if (elec == 1)plotname += "Born.";
        if (elec == 2)plotname += "Naked.";
        FinalPhiRatio->RedrawAxis();
        FinalPhiRatio->SaveAs((plotname + "pdf").c_str());
        FinalPhiRatio->SaveAs((plotname + "png").c_str());
        FinalPhiRatio->SaveAs((plotname + "C").c_str());
    }


    //TOTAL PLOT FROM HERE
    TCanvas* FinalPhiRatio = new TCanvas("FinalPhiRatio", "FinalPhiRatio", 800, 900);
    FinalPhiRatio->SetBottomMargin(0.1);

    TPad* Info = new TPad("p1", "p1", 0, .03, 1, .9);
    Info->Draw();
    Info->cd();
    Info->Divide(1, 6, 0, 0);


    for (uint i = 0; i < ny; i++) {
        Info->cd(i + 1);
        std::ostringstream strs;
        strs << i;
        std::string gPadName = "p" + strs.str();
        //gPad->SetPad(gPadName.c_str(), gPadName.c_str(), 0, i / 6, 1, (1 + i) / 6, kWhite, 0, 0);
        //gPad->SetLeftMargin(0.15);
        //gPad->SetRightMargin(0.06);
        if (i == 5)gPad->SetBottomMargin(0.2);
        gPad->SetLogx(1);

        if (i == 0)r_data[i]->SetTitle("");
        else r_data[i]->SetTitle("");

        if (i == 0)r_data[i]->GetYaxis()->SetTitle("");
        else if (i == 1)r_data[i]->GetYaxis()->SetTitle("");
        else if (i == 2)r_data[i]->GetYaxis()->SetTitle("MC/Data");
        else if (i == 3)r_data[i]->GetYaxis()->SetTitle("");
        else if (i == 4)r_data[i]->GetYaxis()->SetTitle("");
        else if (i == 5)r_data[i]->GetYaxis()->SetTitle("");

        r_data[i]->GetYaxis()->CenterTitle();
        r_data[i]->SetFillColor(kYellow);
        r_data[i]->GetYaxis()->SetNdivisions(503);
        r_data[i]->GetYaxis()->SetRangeUser(0.865, 1.135);
        if (i == 4)r_data[i]->GetYaxis()->SetRangeUser(0.77, 1.23);
        if (i == 5)r_data[i]->GetYaxis()->SetRangeUser(0.4, 1.6);
        r_data[i]->GetYaxis()->SetTitleOffset(0.2); //OFFSET
        r_data[i]->GetYaxis()->SetTitleSize(0.2); //Y TITLE SIZE
        r_data[i]->GetYaxis()->SetLabelSize(0.15);
        r_data[i]->GetXaxis()->SetTitleSize(0);
        r_data[i]->GetXaxis()->SetLabelSize(0);
        r_data[i]->GetXaxis()->SetTitle("");
        r_data[i]->GetXaxis()->CenterTitle();
        if (i == ny - 1) {
            r_data[i]->GetXaxis()->SetTitleOffset(0.42); //OFFSET
            r_data[i]->GetXaxis()->SetTitleSize(0.2); //X TITLE SIZE
            r_data[i]->GetXaxis()->SetLabelSize(0.15);
            r_data[i]->GetXaxis()->SetLabelOffset(-0.01);
            r_data[i]->GetXaxis()->SetTitle("#phi*");
            r_data[i]->GetXaxis()->CenterTitle();
        }
        r_data[i]->GetXaxis()->SetRangeUser(.015, 1.95);
        r_data[i]->Draw("AE2");

        r_mg[i]->SetMarkerStyle(kFullTriangleUp);
        r_mg[i]->SetMarkerColor(kBlue - 7);
        r_mg[i]->SetLineColor(kBlue - 7);

        r_ph[i]->SetMarkerSize(1);
        r_ph[i]->SetLineWidth(2);
        r_ph[i]->SetMarkerStyle(kFullSquare);
        r_ph[i]->SetMarkerColor(kRed);
        r_ph[i]->SetLineColor(kRed);
        r_ph[i]->Draw("PEsame");

        r_mg[i]->Draw("PEsame");

        r_re[i]->SetMarkerColor(kGreen + 1);
        r_re[i]->SetLineColor(kGreen + 1);
        r_re[i]->SetMarkerSize(1);
        r_re[i]->SetLineWidth(2);
        r_re[i]->SetMarkerStyle(kStar);
        r_re[i]->Draw("PEsame");

        r_ANlo[i]->SetMarkerSize(1);
        r_ANlo[i]->SetLineWidth(2);
        r_ANlo[i]->SetMarkerStyle(kOpenCircle);
        r_ANlo[i]->SetMarkerColor(kCyan + 2);
        r_ANlo[i]->SetLineColor(kCyan + 2);
        r_ANlo[i]->Draw("PEsame");

        r_Pyth8[i]->SetMarkerSize(1);
        r_Pyth8[i]->SetLineWidth(2);
        r_Pyth8[i]->SetMarkerStyle(kOpenSquare);
        r_Pyth8[i]->SetMarkerColor(kRed);
        r_Pyth8[i]->SetLineColor(kRed);
        r_Pyth8[i]->Draw("PEsame");
    }
    //r_data_WO->Draw("PEsame");
    FinalPhiRatio->cd(0);
    TLatex mark;
    mark.SetTextSize(0.02);
    mark.SetNDC(kTRUE);
    mark.DrawLatex(.75, .95, "19.7 fb^{-1} (8 TeV)");
    mark.DrawLatex(0.1, .95, "CMS Preliminary");
    TLatex mark2;
    mark2.SetTextSize(0.02);
    mark2.SetNDC(kTRUE);
    mark2.DrawLatex(.12, .84, "0.0 < |y_{ll}| < 0.4");
    mark2.DrawLatex(.12, .7, "0.4 < |y_{ll}| < 0.8");
    mark2.DrawLatex(.12, .55, "0.8 < |y_{ll}| < 1.2");
    mark2.DrawLatex(.12, .42, "1.2 < |y_{ll}| < 1.6");
    mark2.DrawLatex(.12, .28, "1.6 < |y_{ll}| < 2.0");
    mark2.DrawLatex(.12, .15, "2.0 < |y_{ll}| < 2.4");
    //mark.DrawLatex(-0.15, 0.25, "|#eta^{l_{0}}| < 2.1,        |#eta^{l_{1}}| < 2.4");
    //mark.DrawLatex(0.15, 0.20, "p_{T}^{l_{0}} > 30 GeV,   p_{T}^{l_{1}} > 20 GeV");
    //if (i != 5)mark.DrawLatex(0.15, 0.15, "60 GeV < M_{ll} < 120 GeV");
    //else mark.DrawLatex(0.15, 0.30, "60 GeV < M_{ll} < 120 GeV");

    FinalPhiRatio->cd(1);
    TLegend* leg2 = new TLegend(0.09, 0.888, 0.9, 0.94);
    leg2->SetNColumns(3);
    leg2->SetFillStyle(0);
    //leg2->SetBorderSize(1);
    leg2->SetLineWidth(1);
    leg2->SetTextFont(22);

    leg2->AddEntry(r_data[1], "2012 data", "F");
    leg2->AddEntry(r_mg[1], " MadGraph+Pythia6 (Z2*)", "P");
    leg2->AddEntry(r_ph[1], "POWHEG+Pythia6 (Z2*)", "P");
    leg2->AddEntry(r_re[1], "Resbos", "P");
    leg2->AddEntry(r_ANlo[1], "AMC@nlo+Pythia8(CUETP8M1)", "P");
    leg2->AddEntry(r_Pyth8[1], "POWHEG+Pythia8 (CT10)", "P");

    leg2->Draw();
    std::string plotname = "Plots/Ratio_ZShape_2D_ALL";
    plotname += Tag;
    //if (isPlot2 && Type == "combined")plotname += "MuEl";
    //else if (isPlot2 && Type == "elec")plotname += "PHMG";
    plotname += Type;
    plotname += "_";
    if ((Type == "elec" || isPlot2) && !doMG) plotname += "PH_";
    if (doNorm) plotname += "Norm_";
    else plotname += "Abs_";
    if (elec == 0)plotname += "Dressed.";
    if (elec == 1)plotname += "Born.";

    if (elec == 2)plotname += "Naked.";
    FinalPhiRatio->RedrawAxis();
    FinalPhiRatio->SaveAs((plotname + "pdf").c_str());
    FinalPhiRatio->SaveAs((plotname + "png").c_str());
    FinalPhiRatio->SaveAs((plotname + "C").c_str());


    //TO HEREs


}
Exemple #8
0
void simulateResponse() {
  TF1 MyPoisson("MyPoisson", PoissonReal, 0., 20, 1);
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetPadRightMargin(0.05);

  int NEVT = 10000;

  // the mean number of photons from clas6
  // was 9.
  // For pions however, depending on momemntum,
  // this number will change.
  // Taking 9 as the number of photons for pions at 7.5 GeV
  // and calculating the ratio of pi3 for each momentum
  double mean7 = 9;
  double means[MNP];

  double
      pion_ratio_1[MNP]; // no changes: same mirror, same PMT, same wc (so-so)
  double pion_ratio_2[MNP]; // recoated mirror, same PMT, same wc (so-so)
  double pion_ratio_3[MNP]; // recoated mirror, improved PMT, same wc (so-so)
  double pion_ratio_4[MNP]; // recoated mirror, improved PMT, coated wc (good)
  double pion_ratio_5[MNP]; // recoated mirror, improved PMT, bad wc
  double pion_ratio_6[MNP]; // recoated mirror, improved PMT, perfect wc (2
                            // reflections only)

  TH1D* perfec[MNP];
  TH1D* doNoth[MNP];
  TH1D* fixBad[MNP];
  TH1D* fixAll[MNP];

  // assuming show_ration has been run (need to re-run if RECALC is 1)
  ifstream in("pionYield.txt");

  for (int i = 0; i < MNP; i++) {
    in >> pion_ratio_1[i] >> pion_ratio_2[i] >> pion_ratio_3[i] >>
        pion_ratio_4[i] >> pion_ratio_5[i] >> pion_ratio_6[i];
  }

  in.close();

  if (RECALC2 == 0) {

    TFile f("dist.root");

    for (int i = 0; i < MNP; i++) {
      perfec[i] = (TH1D*)f.Get(Form("perfec%d", i));
      doNoth[i] = (TH1D*)f.Get(Form("doNoth%d", i));
      fixBad[i] = (TH1D*)f.Get(Form("fixBad%d", i));
      fixAll[i] = (TH1D*)f.Get(Form("fixAll%d", i));

      perfec[i]->SetDirectory(0);
      doNoth[i]->SetDirectory(0);
      fixBad[i]->SetDirectory(0);
      fixAll[i]->SetDirectory(0);
    }
    f.Close();
  } else {
    for (int i = 0; i < MNP; i++) {
      perfec[i] =
          new TH1D(Form("perfec%d", i), Form("perfec%d", i), 250, 0, 25);
      doNoth[i] =
          new TH1D(Form("doNoth%d", i), Form("doNoth%d", i), 250, 0, 25);
      fixBad[i] =
          new TH1D(Form("fixBad%d", i), Form("fixBad%d", i), 250, 0, 25);
      fixAll[i] =
          new TH1D(Form("fixAll%d", i), Form("fixAll%d", i), 250, 0, 25);
    }

    for (int i = 2; i < MNP; i++) {
      // means[i] = mean7*pion_ratio_2[i]/pion_ratio_2[11];
      means[i] = mean7 * pion_ratio_3[i] / pion_ratio_3[11];

      for (int e = 1; e < NEVT; e++) {
        if (e % 1000 == 0) {
          cout << " Event number " << e << " for momentum: " << i << endl;
        }

        MyPoisson.SetParameter(0, means[i]);

        double r = MyPoisson.GetRandom();
        perfec[i]->Fill(r);

        int nr = calculateNReflection(gRandom->Uniform(0, 1));
        int gr = calculateWCgroup(gRandom->Uniform(0, 1));

        // only 2 reflections
        // wc are "perfect"
        if (nr == 2) {
          doNoth[i]->Fill(r * pion_ratio_4[i]);
          fixBad[i]->Fill(r * pion_ratio_4[i]);
          fixAll[i]->Fill(r * pion_ratio_4[i]);
        }
        if (nr == 3) {
          // bad
          if (gr == 1) {
            doNoth[i]->Fill(r * pion_ratio_5[i]);
            fixBad[i]->Fill(r * pion_ratio_4[i]);
            fixAll[i]->Fill(r * pion_ratio_4[i]);
          }
          // so-so
          if (gr == 2) {
            doNoth[i]->Fill(r * pion_ratio_3[i]);
            fixBad[i]->Fill(r * pion_ratio_3[i]);
            fixAll[i]->Fill(r * pion_ratio_4[i]);
          }
          // good
          if (gr == 3) {
            doNoth[i]->Fill(r * pion_ratio_4[i]);
            fixBad[i]->Fill(r * pion_ratio_4[i]);
            fixAll[i]->Fill(r * pion_ratio_4[i]);
          }
        }
        if (nr == 4) {
          r = r * 0.8;
          // bad
          if (gr == 1) {
            doNoth[i]->Fill(r * pion_ratio_5[i]);
            fixBad[i]->Fill(r * pion_ratio_4[i]);
            fixAll[i]->Fill(r * pion_ratio_4[i]);
          }
          // so-so
          if (gr == 2) {
            doNoth[i]->Fill(r * pion_ratio_3[i]);
            fixBad[i]->Fill(r * pion_ratio_3[i]);
            fixAll[i]->Fill(r * pion_ratio_4[i]);
          }
          // good
          if (gr == 3) {
            doNoth[i]->Fill(r * pion_ratio_4[i]);
            fixBad[i]->Fill(r * pion_ratio_4[i]);
            fixAll[i]->Fill(r * pion_ratio_4[i]);
          }
        }
      }
    }

    // saving histos
    TFile f("dist.root", "RECREATE");
    for (int i = 0; i < MNP; i++) {
      perfec[i]->Write();
      doNoth[i]->Write();
      fixBad[i]->Write();
      fixAll[i]->Write();
    }
    f.Close();
  }

  // histos loaded, now plotting
  for (int i = 0; i < MNP; i++) {
    doNoth[i]->SetLineColor(kRed);
    fixBad[i]->SetLineColor(kBlue);
    fixAll[i]->SetLineColor(kGreen);

    perfec[i]->GetXaxis()->SetLabelSize(0.08);
    perfec[i]->GetYaxis()->SetLabelSize(0.08);
    perfec[i]->GetXaxis()->SetLabelOffset(-0.02);
    perfec[i]->GetYaxis()->SetLabelOffset(0.02);
  }

  double xmom[10];
  double ymomA[10];
  double ymomB[10];
  double ymomC[10];

  TCanvas* res = new TCanvas("res", "Photon Yields", 1500, 1200);

  TPad* pres = new TPad("pres", "pres", 0.01, 0.01, 0.98, 0.9);
  pres->Divide(5, 2);
  pres->Draw();

  TLatex lab;
  lab.SetTextFont(102);
  lab.SetTextColor(kBlue + 2);
  lab.SetTextSize(0.06);
  lab.SetNDC();

  for (int i = 2; i < 12; i++) {
    pres->cd(i - 1);

    perfec[i]->Draw();
    fixAll[i]->Draw("same");
    doNoth[i]->Draw("same");
    fixBad[i]->Draw("same");

    double perfectCounts = perfec[i]->Integral(40, 250);
    double donothCounts = doNoth[i]->Integral(40, 250);
    double fixBadCounts = fixBad[i]->Integral(40, 250);
    double fixAllCounts = fixAll[i]->Integral(40, 250);

    double dmom = (max_m - min_m) / MNP;
    double mom = min_m + i * dmom;

    xmom[i - 2] = mom;
    ymomA[i - 2] = 100 * donothCounts / perfectCounts;
    ymomB[i - 2] = 100 * fixBadCounts / perfectCounts;
    ymomC[i - 2] = 100 * fixAllCounts / perfectCounts;

    cout << " momentum: " << mom << " perfect: " << perfectCounts
         << "   nothing: " << donothCounts << "    fix bad: " << fixBadCounts
         << "   fix all " << fixAllCounts << endl;

    lab.DrawLatex(.5, .82, Form(" mom: %2.1f GeV", mom));
    lab.DrawLatex(.5, .75, Form(" do nothing: %3.1f%%",
                                100 * donothCounts / perfectCounts));
    lab.DrawLatex(
        .5, .68, Form(" fix bad: %3.1f%%", 100 * fixBadCounts / perfectCounts));
    lab.DrawLatex(
        .5, .60, Form(" fix all: %3.1f%%", 100 * fixAllCounts / perfectCounts));
  }

  //	res->Print("allMoms.png");

  TCanvas* res2 = new TCanvas("res2", "Photon Yields", 1000, 1000);
  //	perfec[5]->Draw();
  //	fixAll[5]->Draw("same");
  //	doNoth[5]->Draw("same");
  //	fixBad[5]->Draw("same");
  //
  //	res2->Print("fixAll.png");

  TGraph* mresA = new TGraph(10, xmom, ymomA);
  TGraph* mresB = new TGraph(10, xmom, ymomB);
  TGraph* mresC = new TGraph(10, xmom, ymomC);

  mresA->SetMarkerStyle(8);
  mresB->SetMarkerStyle(21);
  mresC->SetMarkerStyle(8);

  mresA->SetMarkerSize(1.6);
  mresB->SetMarkerSize(1.6);
  mresC->SetMarkerSize(1.6);
  mresA->SetMarkerColor(kBlack);
  mresB->SetMarkerColor(kRed);
  mresC->SetMarkerColor(kBlue);

  mresA->Draw("AP");
  mresB->Draw("Psame");
  mresC->Draw("Psame");

  TLegend* lstudy = new TLegend(0.6, 0.35, 0.95, 0.58);
  lstudy->AddEntry(mresA, "Current Situation", "P");
  lstudy->AddEntry(mresB, "Fix Bad", "P");
  lstudy->AddEntry(mresC, "Fix So-So", "P");
  lstudy->SetBorderSize(0);
  lstudy->SetFillColor(0);
  lstudy->Draw();
}
Exemple #9
0
void plotFinalEnergy()  {

    
    gStyle->SetStatH(0.3);
    gStyle->SetStatY(0.88);
    gStyle->SetStatW(0.3);
    char canTitle[180];
    sprintf(canTitle,"Energy at Terminal Interaction (10000 tries)"); 
    TCanvas *canFinalEnergy = new TCanvas("canFinalEnergy","Final Energy",800,800);
    TPaveLabel *pl = new TPaveLabel(0.1,0.96,0.9,0.99,canTitle,"br NDC");
    pl->SetBorderSize(0);
    pl->SetFillColor(0);
    pl->SetFillStyle(0);
    pl->Draw();
    TPad *subCanFinalEnergy = new TPad("subCanFinalEnergy","",0,0,1,0.95);
    subCanFinalEnergy->Draw();
    subCanFinalEnergy->cd();
    subCanFinalEnergy->Divide(2,4);
    subCanFinalEnergy->Update();
    


//    gStyle->SetOptStat(0);
    char fileName[80];   
    char histTitle[80];

    char theEnergies[4][5]={"1e9","1e10","1e11","1e12"};

    int theColours[2][3]={{50,42,46},{40,30,38}};
    
    for(int isATau=0;isATau<=1;isATau++) {
	for(int i=0;i<4;i++) {		 
	    sprintf(fileName,
		    "newest%sFile%sIce.root",getParticleNameCaps(isATau),theEnergies[i]);
	    sprintf(histTitle,"%s -- %s GeV",getParticleNameCaps(isATau),theEnergies[i]);
	    TFile *fp = new TFile(fileName);
	    TH1F *histEnergy = 
		new TH1F("histEnergy",histTitle,100,7.5,12.5);
	    TH1F *histEnergy2 = 
		new TH1F("histEnergy2","Last Energy",100,7.5,12.5);
	    TH1F *histEnergy3 = 
		new TH1F("histEnergy3","Last Energy",100,7.5,12.5);

	    TTree *theTree = (TTree*) fp->Get("theTree");
	    cout << theTree->GetEntries() << endl;
	    subCanFinalEnergy->cd((2*i)+isATau+1);
	    gPad->SetTopMargin(0.12);
//	gPad->SetBottomMargin(0.2);
	    histEnergy->SetLineWidth(3);
	    histEnergy->SetLineColor(theColours[isATau][0]);
	    histEnergy2->SetLineWidth(3);
	    histEnergy2->SetLineColor(theColours[isATau][1]);
	    histEnergy3->SetLineWidth(3);
	    histEnergy3->SetLineColor(theColours[isATau][2]);
	    theTree->Draw("log10(stepIntEnergy)>>histEnergy","stepIntType>=4");
//	histEnergy->GetXaxis()->SetTitle("IntType (#mus)");
// 	histEnergy->GetXaxis()->SetBinLabel(2,"Bremsstrahlung");
// 	histEnergy->GetXaxis()->SetBinLabel(3,"Pair Production");
// 	histEnergy->GetXaxis()->SetBinLabel(4,"Photonuclear");
// 	histEnergy->GetXaxis()->SetLabelSize(0.09);
// 	histEnergy->GetXaxis()->SetLabelOffset(0.02);
 	    theTree->Draw("log10(stepIntEnergy)>>histEnergy2","stepIntType==4");
 	    theTree->Draw("log10(stepIntEnergy)>>histEnergy3","stepIntType==5");

	    histEnergy->DrawCopy();
	    if(histEnergy2->GetEntries())
		histEnergy2->DrawCopy("same");
	    if(histEnergy3->GetEntries())
		histEnergy3->DrawCopy("same");
	    
	    if(histEnergy->GetEntries())
		gPad->SetLogy();

	    if(i==0) {
		TLegend *leg = new TLegend(0.7,0.2,0.9,0.6);
		leg->SetFillColor(0);
		leg->SetFillStyle(0);
		leg->SetBorderSize(0);
		leg->AddEntry(histEnergy2,"Decay","l");
		leg->AddEntry(histEnergy3,"Weak (CC)","l");
		leg->AddEntry(histEnergy,"Either","l");
		leg->Draw("same");
	    }
	}
    } 
    for(int i=0;i<8;i++) {
//	cout << "Doing title "<< i+1 << endl;
	subCanFinalEnergy->cd(i+1);
	sortOutTitle(0.07);
    }
//    gStyle->SetOptStat(1110);

}
Exemple #10
0
void quarks () {
   TCanvas *c1 = new TCanvas("c1", "c1",10,10,630,760);
   c1->SetFillColor(kBlack);
   Int_t quarkColor  = 50;
   Int_t leptonColor = 16;
   Int_t forceColor  = 38;
   Int_t titleColor  = kYellow;
   Int_t border = 8;

   TLatex *texf = new TLatex(0.90,0.455,"Force Carriers");
   texf->SetTextColor(forceColor);
   texf->SetTextAlign(22); texf->SetTextSize(0.07);
   texf->SetTextAngle(90);
   texf->Draw();

   TLatex *texl = new TLatex(0.11,0.288,"Leptons");
   texl->SetTextColor(leptonColor);
   texl->SetTextAlign(22); texl->SetTextSize(0.07);
   texl->SetTextAngle(90);
   texl->Draw();

   TLatex *texq = new TLatex(0.11,0.624,"Quarks");
   texq->SetTextColor(quarkColor);
   texq->SetTextAlign(22); texq->SetTextSize(0.07);
   texq->SetTextAngle(90);
   texq->Draw();

   TLatex tex(0.5,0.5,"u");
   tex.SetTextColor(titleColor); tex.SetTextFont(32);
   tex.SetTextAlign(22);
   tex.SetTextSize(0.14);
   tex.DrawLatex(0.5,0.93,"Elementary");
   tex.SetTextSize(0.12);
   tex.DrawLatex(0.5,0.84,"Particles");
   tex.SetTextSize(0.05);
   tex.DrawLatex(0.5,0.067,"Three Generations of Matter");

   tex.SetTextColor(kBlack); tex.SetTextSize(0.8);

// ------------>Create main pad and its subdivisions
   TPad *pad = new TPad("pad", "pad",0.15,0.11,0.85,0.79);
   pad->Draw();
   pad->cd();
   pad->Divide(4,4,0.0003,0.0003);

   pad->cd(1); gPad->SetFillColor(quarkColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"u");

   pad->cd(2); gPad->SetFillColor(quarkColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"c");

   pad->cd(3); gPad->SetFillColor(quarkColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"t");

   pad->cd(4); gPad->SetFillColor(forceColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.55,"#gamma");

   pad->cd(5); gPad->SetFillColor(quarkColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"d");

   pad->cd(6); gPad->SetFillColor(quarkColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"s");

   pad->cd(7); gPad->SetFillColor(quarkColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"b");

   pad->cd(8); gPad->SetFillColor(forceColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.55,"g");

   pad->cd(9); gPad->SetFillColor(leptonColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"#nu_{e}");

   pad->cd(10); gPad->SetFillColor(leptonColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"#nu_{#mu}");

   pad->cd(11); gPad->SetFillColor(leptonColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"#nu_{#tau}");

   pad->cd(12); gPad->SetFillColor(forceColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"Z");

   pad->cd(13); gPad->SetFillColor(leptonColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"e");

   pad->cd(14); gPad->SetFillColor(leptonColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.56,"#mu");

   pad->cd(15); gPad->SetFillColor(leptonColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"#tau");

   pad->cd(16); gPad->SetFillColor(forceColor);
   gPad->SetBorderSize(border);
   tex.DrawLatex(.5,.5,"W");

   c1->cd();
}