Plot_embed

<code>

//First run scan_embed.C to generate root file with all the histograms
// V. May 31 2007 - Cristina

#ifndef __CINT__
#include "TROOT.h"
#include "TSystem.h"
#include <iostream.h>
#include "TH1.h"
#include "TH2.h"
#include "TH3.h"
#include "TFile.h"
#include "TTree.h"
#include "TChain.h"
#include "TTreeHelper.h"
#include "TText.h"
#include "TLatex.h"
#include "TAttLine.h"
#include "TCanvas.h"
#endif

void plot_embed(Int_t id=9) {

  gROOT->LoadMacro("~/macros/Utility.C"); //location of Utility.C


gStyle->SetOptStat(1);
//gStyle->SetOptTitle(0);   
gStyle->SetOptDate(0);
gStyle->SetOptFit(0);
gStyle->SetPalette(1);

 float mass2;

    if (id == 8)  { TString tag = "Piplus";  mass2 = 0.019;}
    if (id == 9)  { TString tag = "Piminus"; mass2 = 0.019;}
    if (id == 11) { TString tag = "Kplus";   mass2 = 0.245;}
    if (id == 12) { TString tag = "Kminus";  mass2 = 0.245;}
    if (id == 14) { TString tag = "Proton";  mass2 = 0.880;}
    if (id == 15) { TString tag = "Pbar";    mass2 = 0.880;}
    if (id == 50) { TString tag = "Phi";     mass2 = 1.020;}
    if (id == 2)  { TString tag = "Eplus";   mass2 = 0.511;}
    if (id == 1)  { TString tag = "Dmeson";  mass2 = 1.864;}


char  text1[80];
sprintf(text1,"P05_CuCu200_01_02_08");//this is going to show in all the histograms
char title[100],
char gif[100];
TString prod = "P05_CuCu200_01_02_08";

 
int nch1 = 0;
int nch2 = 1000;

/////////////////////////////////////////////////
//Cloning Histograms
/////////////////////////////////////////////////


 f1 = new TFile ("~/data/P05_CuCu200_010208.root");

        TH3D *hDca1   = (TH3D*)hDca   -> Clone("hDca1");//DCA
    TH3D *hNfit1  = (TH3D*)hNfit  -> Clone("hNFit1");//Nfit
    TH2D *hPtM_E1 = (TH2D*)hPtM_E -> Clone("hPtM_E1");//Energy Loss


    TH2D *dedx1  = (TH2D*)dedx  -> Clone("dedx1");
    TH2D *dedxG1 = (TH2D*)dedxG -> Clone("dedxG1");

    TH2D *vxy1 = (TH2D*)vxy  -> Clone("vxy1");
    TH1D *vz1  = (TH1D*)vz   -> Clone("vz1");
    TH1D *dvx1 = (TH1D*)dvx  -> Clone("dvx1");
    TH1D *dvy1 = (TH1D*)dvy  -> Clone("dvy1");
    TH1D *dvz1 = (TH1D*)dvz  -> Clone("dvz1");


    TH1D *PhiMc1  = (TH1D*)PhiMc  -> Clone("PhiMc1");
    TH1D *EtaMc1  = (TH1D*)EtaMc  -> Clone("EtaMc1");
    TH1D *PtMc1   = (TH1D*)PtMc   -> Clone("PtMc1");

    TH1D *PhiM1   = (TH1D*)PhiM   -> Clone("PhiM1");
    TH1D *EtaM1   = (TH1D*)EtaM   -> Clone("EtaM1");
    TH1D *PtM1    = (TH1D*)PtM    -> Clone("PtM1");

    TH2D *PtM_eff1 = (TH2D*)hPtM_eff ->Clone("PtM_eff1");//efficiency

//if you have MuDst hist

        TH3D *hDca1r   = (TH3D*)hDcaR   -> Clone("hDca1r");
        TH3D *hNfit1r  = (TH3D*)hNfitR  -> Clone("hNFit1r");
        TH2D *dedx1R = (TH2D*)dedxR  -> Clone("dedx1R");

/*
//use the following if you need to compare

    f2 = new TFile ("~/data/test_P07ib_pi_10percent_10_03_07.root");

    TH2D *PtM_eff2 = (TH2D*)hPtM_eff ->Clone("PtM_eff2");
    TH3D *hNfit2  = (TH3D*)hNfit  -> Clone("hNFit2");//Nfit
    TH1D *PtM2    = (TH1D*)PtM    -> Clone("PtM2");
    TH1D *PtMc2    = (TH1D*)PtMc  -> Clone("PtMc2");
   
   
    f3 = new TFile ("~/data/test_P07ib_pi_10percent_10_12_07.root");

    TH3D *hNfit3  = (TH3D*)hNfit  -> Clone("hNFit3");//Nfit
    TH2D *PtM_eff3 = (TH2D*)hPtM_eff ->Clone("PtM_eff3");
    TH1D *PtM3    = (TH1D*)PtM    -> Clone("PtM3");
    TH1D *PtMc3    = (TH1D*)PtMc    -> Clone("PtMc3");



*/


    int nch1 = 0;
    int nch2 = 1000;
    Double_t pt[4]= {0.3,0.4, 0.5, 0.6};

    ////////////////////////////////////////////////////////////
    //efficiency
    /////////////////////////////////////////////////////////////
    /*
    TCanvas *c10= new TCanvas("c10","Efficiency",500, 500);
   
    c10->SetGridx(0);
    c10->SetGridy(0);
    c10->SetLeftMargin(0.15);
    c10->SetRightMargin(0.05);
    //c10->SetTitleOffSet(0.1, "Y");

    c10->cd;

    PtM1->Rebin(2);
    PtMc1->Rebin(2);
   
    PtM1->Divide(PtMc1);
    PtM1->SetLineColor(1);
    PtM1->SetMarkerStyle(23);
    PtM1->SetMarkerColor(1);
    PtM1->Draw();
    PtM1->SetXTitle ("pT (GeV/c)");
    PtM1->SetAxisRange(0.0, 6.0, "X");
   
    return;
   
    /*
    PtM2->Rebin(2);
    PtMc2->Rebin(2);
   
    PtM2->Divide(PtMc2);
    PtM2->SetLineColor(9);
    PtM2->SetMarkerStyle(21);
    PtM2->SetMarkerColor(9);
    PtM2->Draw("same");
   
    PtM3->Rebin(2);
    PtMc3->Rebin(2);
   
    PtM3->Divide(PtMc2);
    PtM3->SetLineColor(2);
    PtM3->SetMarkerStyle(22);
    PtM3->SetMarkerColor(2);
    PtM3->Draw("same");


     keySymbol(0.08, 1.0,  text1, 1, 23, 0.04);

   

    /////////////////////////////////////////////////////////////
    //Vertex position
    //////////////////////////////////////////////////////////
   
   
    TCanvas *c6= new TCanvas("c6","Vertex position",600, 400);
    c6->Divide(2,1);

    c6_1->cd();
    vz1->Rebin(2);
    vz1->SetXTitle("Vertex Z");
    vz1->Draw();
   
    c6_2->cd();
    vxy1->Draw("colz");
    vxy1->SetAxisRange(-1.5, 1.5, "X");
    vxy1->SetAxisRange(-1.5, 1.5, "Y");

   
    vxy1->SetXTitle ("vertex X");
    vxy1->SetYTitle ("vertex Y");
    keyLine(.2, 1.05,text1,1);
   

    c6->Update();


   
    /////////////////////////////////////////////////////////////////////
    //Dedx
    ////////////////////////////////////////////////////////////////////

   
    TCanvas *c8= new TCanvas("c8","dEdx vs P",500, 500);
   
     c8->SetGridx(0);
    c8->SetGridy(0);
    c8->SetLeftMargin(0.15);
    c8->SetRightMargin(0.05);
    c8->cd;

              
    dedxG1->SetXTitle("Momentum P (GeV/c)");
    dedxG1->SetYTitle("dE/dx");
    dedxG1->SetAxisRange(0, 5., "X");
    dedxG1->SetAxisRange(0, 8., "Y");
    dedxG1->SetMarkerColor(1);
    dedxG1->Draw();//"colz");

    dedx1->SetMarkerStyle(7);
    dedx1->SetMarkerSize(0.3);
    dedx1->SetMarkerColor(2);
    dedx1->Draw("same");
   

    keyLine(.3, 0.87,"Embedded Tracks",2);
    keyLine(.3, 0.82,"Ghost Tracks",1);
    keyLine(.2, 1.05,text1,1);


    c8->Update();

   
    /////////////////////////////////////////////////////
    //MIPS (just for pions)
    /////////////////////////////////////////////////////


      if (id==8 || id==9)
      {

      TCanvas *c9= new TCanvas("c9","MIPS",500, 500);
   
      c9->SetGridx(0);
      c9->SetGridy(0);
      c9->SetLeftMargin(0.15);
      c9->SetRightMargin(0.05);
      c9->cd;

    double pt1 = 0.4;
    double pt2 = 0.6;

    dedxG1 -> ProjectionX("rpx");
   
    int blG = rpx->FindBin(pt1);
    int bhG = rpx->FindBin(pt2);

    cout<<blG<<endl;
    cout<<bhG<<endl;

    dedxG1->ProjectionY("rpy",blG,bhG);
    rpy->SetTitle("MIPS");
    rpy->SetMarkerStyle(22);
    //   rpy->SetMarkerColor(2);
    rpy->SetAxisRange(1.3, 4, "X");
   
    //dedxG1->Draw();

    dedx1->ProjectionX("mpx");

    int blm = mpx->FindBin(pt1);
    int bhm = mpx->FindBin(pt2);

    cout<<blm<<endl;
    cout<<bhm<<endl;

    dedx1->ProjectionY("mpy", blm,bhm);
   
    mpy->SetAxisRange(0.5, 6, "X");
    mpy->SetMarkerStyle(22);
    mpy->SetMarkerColor(2);

    float max_rpy = rpy->GetMaximum();
           max_rpy /= 1.*mpy->GetMaximum();
    mpy->Scale(max_rpy);

    cout<<"max_rpy is: "<<max_rpy<<endl;
    cout<<"mpy is: "<<mpy<<endl;

    rpy->Sumw2();
    mpy->Sumw2();

    rpy->Fit("gaus","","",1,4);
    mpy->Fit("gaus","","", 1, 4);
    mpy->GetFunction("gaus")->SetLineColor(2);
   
    rpy->SetAxisRange(0.5 ,6.0, "X");
    mpy->Draw();
    rpy->Draw("same");

    float mipMc = mpy->GetFunction("gaus")->GetParameter(1);//mean
    float mipGhost  = rpy->GetFunction("gaus")->GetParameter(1);
   
     float sigmaMc = mpy->GetFunction("gaus")->GetParameter(2);//mean
        float sigmaGhost  = rpy->GetFunction("gaus")->GetParameter(2);

    char  label1[80];
    char  label2[80];
    char  label3[80];
        char  label4[80];


    sprintf(label1,"mip MC %.3f",mipMc);
    sprintf(label2,"mip Ghost %.3f",mipGhost);
    sprintf(label3,"sigma MC %.3f",sigmaMc);
        sprintf(label4,"sigma Ghost %.3f",sigmaGhost);
   
    keySymbol(.5, .9, label1,2,1);
        keySymbol(.5, .85, label3,2,1);

        keySymbol(.5, .75, label2,1,1);
        keySymbol(.5, .70, label4,1,1);

    keyLine(.2, 1.05,text1,1);
   
    char name[30];
        sprintf(name,"%.2f GeV/c < Pt < %.2f GeV/c",pt1, pt2);
        keySymbol(0.3, 0.65, name, 1, 1, 0.04);

       
    c9->Update();

    }//close if pion

       
    /////////////////////////////////////////////////////////////////////////
    //Energy loss
    //////////////////////////////////////////////////////////////////////////

    TCanvas *c7= new TCanvas("c7","Energy Loss",400, 400);
   
    c7->SetGridx(0);
    c7->SetGridy(0);
    c7->SetLeftMargin(0.20);
    c7->SetRightMargin(0.05);
    c7->cd;

    hPtM_E->ProfileX("pfx");
    pfx->SetAxisRange(-0.01, 0.01, "Y");
    pfx->SetAxisRange(0, 6, "X");
    pfx->GetYaxis()->SetDecimals();
    pfx->SetMarkerStyle(23);
    pfx->SetMarkerSize(0.038);
    pfx->SetMarkerColor(4);
    pfx->SetLineColor(4);
    pfx->SetXTitle ("Pt-Reco");
    pfx->SetYTitle ("ptM - PtMc");
    pfx->SetTitleOffset(2,"Y");

    pfx->Draw();

    /*hPtM_E1->ProfileX("pfx1");
    pfx1->SetAxisRange(-0.007, 0.007, "Y");
    pfx1->GetYaxis()->SetDecimals();
    pfx1->SetLineColor(2);
    pfx1->SetMarkerStyle(21);
    pfx1->SetMarkerSize(0.035);
    pfx1->SetXTitle ("Pt-Reco");
    pfx1->SetYTitle ("ptM - PtMc");
    pfx1->SetTitleOffset(2,"Y");

    pfx1->Draw("same");
   
    c7->Update();

    //////////////////////////////////////////////////////
    //pt
    //////////////////////////////////////////////////////

    TCanvas *c2= new TCanvas("c2","pt",500, 500);
   
    c2->SetGridx(0);
    c2->SetGridy(0);
    c2->SetTitle(0);

    c2->cd();


    //embedded

     PtMc1->Rebin(2);
     PtMc1->SetLineColor(2);
     PtMc1->SetMarkerStyle(20);
     PtMc1->SetMarkerColor(2);
     PtMc1->Draw();
     
     PtMc1->SetXTitle ("pT (GeV/c)");
     PtMc1->SetAxisRange(0.0, 6.0, "X");
 
     //Reco

     PtM1->Rebin(2);
     PtM1->SetMarkerStyle(20);
     PtM1->SetMarkerColor(1);
     PtM1->Draw("same");
     
   
     keySymbol(.2, 1.05,text1,1);
     keyLine(.3, 0.20,"Embeded-McTracks",2);
     keyLine(.3, 0.16,"Matched Pairs",1);
     // keyLine(.4, 0.82,"Previous Embedding",4);

     c2->Update();
     
   
     //////////////////////////////////////////////////////////////////
     //phi
     /////////////////////////////////////////////////////////////////
   
   
    TCanvas *c5= new TCanvas("c5","pt",500, 500);
    //c5->Divide(2,1);
    c5->SetGridx(0);
    c5->SetGridy(0);
    c5->SetTitle(0);

    c5->cd();


    //embedded

     PhiMc1->Rebin(2);
     PhiMc1->SetLineColor(2);
     PhiMc1->SetMarkerStyle(20);
     PhiMc1->SetMarkerColor(2);
     PhiMc1->Draw();
     PhiMc1->SetXTitle ("Phi");
     PhiMc1->SetAxisRange(-4, 4.0, "X");
 
     //Reco

     PhiM1->Rebin(2);
     PhiM1->SetMarkerStyle(20);
     PhiM1->SetMarkerColor(1);
     PhiM1->Draw("same");
     
     //Previous

     // PhiM ->Rebin(2);
     //  PtM->SetLineColor(4);
     // PtM->SetMarkerColor(4);
     //PtM->Draw("same");
     
     TLatex l;
     l.DrawLatex(7.0, 450.0, prod);

     keySymbol(.2, 1.05,text1,1);
     keyLine(.3, 0.20,"Embeded-McTracks",2);
     keyLine(.3, 0.16,"Reco - Matched Pairs",1);
     // keyLine(.4, 0.82,"Previous Embedding",4);

     c2->Update();
   
     c5->Update();

     /////////////////////////////////////
     //eta
     ///////////////////////////////////////////////////////////////

    TCanvas *c2= new TCanvas("c2","Eta",500, 500);
   
    c2->SetGridx(0);
    c2->SetGridy(0);
    c2->SetTitle(0);

    c2->cd();


    //embedded

     EtaMc1->Rebin(2);
     EtaMc1->SetLineColor(2);
     EtaMc1->SetMarkerStyle(20);
     EtaMc1->SetMarkerColor(2);
     EtaMc1->Draw();
     EtaMc1->SetXTitle ("Eta");
     EtaMc1->SetAxisRange(-1.2, 1.2, "X");
 
     //Reco

     EtaM1->Rebin(2);
     EtaM1->SetMarkerStyle(20);
     EtaM1->SetMarkerColor(1);
     EtaM1->Draw("same");
     
   
     TLatex l;
     l.DrawLatex(7.0, 450.0, prod);

     keySymbol(.2, 1.05,text1,1);
     keyLine(.3, 0.20,"Embeded-McTracks",2);
     keyLine(.3, 0.16,"Reco - Matched Pairs",1);
     // keyLine(.4, 0.82,"Previous Embedding",4);

     c2->Update();

   
     /////////////////////////////////////////////////////////////
     //DCA
     ////////////////////////////////////////////////////////////


    TCanvas *c= new TCanvas("c","DCA",800, 400);
    c->Divide(3,1);
    c->SetGridx(0);
    c->SetGridy(0);

    //Matched  (Bins for Multiplicity)
   
    TH1D *hX1 =  (TH1D*)hDca1->Project3D("X");

    Int_t bin_nch1 = hX1->FindBin(nch1);
    Int_t bin_nch2 = hX1->FindBin(nch2);//this should be the same for both graphs (for 3 graphs)

    //Bins for Pt
   
    TString name1 = "hDca1";
           TString namer1 = "hDcar1";

    TString name = "hDca";


    TH1D *hY1 =  (TH1D*)hDca1->Project3D("Y");
    TH1D *hY1_r = (TH1D*)hDca1r->Project3D("Y");

    TH1D *hY = (TH1D*)hDca->Project3D("Y");
   
    Double_t Sum1_MC;
    Double_t Sum1_Real;

    Double_t Sum_MC;

    for(Int_t i=0; i<3 ; i++)
   
      {
        c->cd(i+1);
        Int_t  bin_ptl_1 = hY1->FindBin(pt[i]);
        Int_t  bin_pth_1 = hY1->FindBin(pt[i+1]);


        TH1D *hDcaNew1= (TH1D*)hDca1->ProjectionZ(name1+i,bin_nch1, bin_nch2, bin_ptl_1, bin_pth_1);
        Sum1_MC =  hDcaNew1 ->GetSum();
        cout<<Sum1_MC<<endl;
     
        hDcaNew1->Scale(1./Sum1_MC);
        hDcaNew1 ->SetLineColor(2);
        hDcaNew1->Draw();
       
        hDcaNew1->SetXTitle("Dca (cm)");
             
        sprintf(title," %.2f GeV < pT < %.2f GeV, %d < nch < %d", pt[i],pt[i+1],nch1,nch2);
        hDcaNew1->SetTitle(title);
       
        //----Now MuDSt
       
        Int_t  bin_ptrl_1r = hY1_r->FindBin(pt[i]);
        Int_t  bin_ptrh_1r = hY1_r->FindBin(pt[i+1]);

        TH1D *hDca_r1= (TH1D*)hDca1r->ProjectionZ(namer1+i,bin_nch1, bin_nch2, bin_ptrl_1r, bin_ptrh_1r);
        Sum1_Real =  hDca_r1 ->GetSum();
        cout<<Sum1_Real<<endl;
        hDca_r1->Scale(1./Sum1_Real);
        hDca_r1->Draw("same");

        //Now Previous Embedding

        Int_t  bin_ptl = hY->FindBin(pt[i]);
        Int_t  bin_pth = hY->FindBin(pt[i+1]);


         TH1D *hDcaNew = (TH1D*)hDca->ProjectionZ(name+i,bin_nch1, bin_nch2, bin_ptl, bin_pth);
        Sum_MC =  hDcaNew ->GetSum();
        cout<<Sum_MC<<endl;
     
        hDcaNew->Scale(1./Sum_MC);
        hDcaNew ->SetLineColor(4);
        hDcaNew->Draw("same");
       
        keySymbol(.4, .95,text1,1,1);
        keyLine(0.4, 0.90,"MC- Matched Pairs",2);
        keyLine(0.4, 0.85,"MuDst",1);
        keyLine(0.4, 0.80,"Previous Embedding P06ib",4);
      }


    c->Update();
   

    ///////////////////////////////////////////////////
    //NFIT
    ////////////////////////////////////////////////////

    TCanvas *c1= new TCanvas("c1","NFIT",800, 400);
    c1->Divide(3,1);
    c1->SetGridx(0);
    c1->SetGridy(0);

    //Bins for Multiplicity -Matched tracks

    TH1D *hX1 =  (TH1D*)hNfit1->Project3D("X");

    Int_t bin_nch1 = hX1->FindBin(nch1);
    Int_t bin_nch2 = hX1->FindBin(nch2);//this should be the same for both graphs (for 3 graphs)

    //Bins for Pt
   
    TString name_nfit1 = "hNfit1";
           TString name_nfitr1 = "hNfitr1";

    TString name_nfit = "hNfit";


    TH1D *hY1 =  (TH1D*)hNfit1->Project3D("Y");
    TH1D *hY1_r = (TH1D*)hNfit1r->Project3D("Y");

    TH1D *hY = (TH1D*)hNfit->Project3D("Y");
   
    Double_t Sum1_Nfit_MC;
    Double_t Sum1_Nfit_Real;

    Double_t Sum__Nfit_MC;

    for(Int_t i=0; i<3 ; i++)
   
      {
        c1->cd(i+1);
        Int_t  bin_ptl_1 = hY1->FindBin(pt[i]);
        Int_t  bin_pth_1 = hY1->FindBin(pt[i+1]);


        TH1D *hNfitNew1= (TH1D*)hNfit1->ProjectionZ(name_nfit1+i,bin_nch1, bin_nch2, bin_ptl_1, bin_pth_1);
        Sum1_Nfit_MC =  hNfitNew1 ->GetSum();
        cout<<Sum1_Nfit_MC<<endl;
     
        hNfitNew1->Scale(1./Sum1_Nfit_MC);
        hNfitNew1 ->SetLineColor(2);
        hNfitNew1->Draw();
       
        hNfitNew1->SetXTitle("Nfit");
             
        sprintf(title," %.2f GeV < pT < %.2f GeV, %d < nch < %d", pt[i],pt[i+1],nch1,nch2);
        hNfitNew1->SetTitle(title);
       
        //----Now MuDSt
       
        Int_t  bin_ptrl_1r = hY1_r->FindBin(pt[i]);
        Int_t  bin_ptrh_1r = hY1_r->FindBin(pt[i+1]);

        TH1D *hNfit_r1= (TH1D*)hNfit1r->ProjectionZ(name_nfitr1+i,bin_nch1, bin_nch2, bin_ptrl_1r, bin_ptrh_1r);
        Sum1_Nfit_Real =  hNfit_r1 ->GetSum();
        cout<<Sum1_Nfit_Real<<endl;
        hNfit_r1->Scale(1./Sum1_Nfit_Real);
        hNfit_r1->Draw("same");

        //Now Previous Embedding

        Int_t  bin_ptl = hY->FindBin(pt[i]);
        Int_t  bin_pth = hY->FindBin(pt[i+1]);


         TH1D *hNfitNew = (TH1D*)hNfit->ProjectionZ(name_nfit+i,bin_nch1, bin_nch2, bin_ptl, bin_pth);
        Sum_Nfit_MC =  hNfitNew ->GetSum();
        cout<<Sum__Nfit_MC<<endl;
     
        hNfitNew->Scale(1./Sum_Nfit_MC);
        hNfitNew ->SetLineColor(4);
        hNfitNew->Draw("same");

        ///*T = new TBox(40, 0, 50, 0.01);
        //T->SetLineColor(2);
        //T->SetLineWidth(2);
        //T->Draw("same");       
        //check this....

        keySymbol(.2, .95,text1,1,1);
        keyLine(0.2, 0.90,"MC- Matched Pairs",2);
        keyLine(0.2, 0.85,"MuDst",1);
        keyLine(0.2, 0.80,"Previous Embedding P06ib",4);
      }
     
return;     
}

</code>