ROOT logo
void SetStyles(TH1 *histo,int marker, int color, char *name){
  //histo->Sumw2();
  histo->SetMarkerStyle(marker);
  histo->SetMarkerColor(color);
  histo->SetLineColor(color);
  histo->SetName(name);
  //histo->GetXaxis()->SetTitle(xtitle);
  //histo->GetYaxis()->SetTitle(ytitle);
}
Int_t colors[] = {0,TColor::kRed, TColor::kOrange, TColor::kGreen+3, TColor::kBlue, TColor::kBlack, 
		    TColor::kRed, TColor::kOrange, TColor::kGreen+3, TColor::kBlue, TColor::kBlack, 
		    TColor::kRed, TColor::kOrange, TColor::kGreen+3, TColor::kBlue, TColor::kBlack, 
		    TColor::kRed, TColor::kOrange, TColor::kGreen+3, TColor::kBlue, TColor::kBlack};
Int_t markers[] = {20,21,22,23,33, 24,25,26,32,27, 20,21,22,23,33, 24,25,26,32,27};

Float_t nSecondariesTrMultScaledSim[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
Float_t nSecondariesTrMultScaledData[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
Float_t nSecondariesClMultScaledSim[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
Float_t nSecondariesClMultScaledData[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
Float_t nSecondariesShortTrMultScaledSim[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
Float_t nSecondariesShortTrMultScaledData[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
Float_t nSecondariesShortClMultScaledSim[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
Float_t nSecondariesShortClMultScaledData[] = {0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};
void WriteLatex();
Float_t secondaryCorrEmcal[20] = {0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0};
Float_t secondaryCorrPhos[20] = {0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0};
Float_t secondaryErrorEmcal[20] = {0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0};
Float_t secondaryErrorPhos[20] = {0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0, 0.0,0.0,0.0,0.0,0.0};

void PlotSecondariesCorr(TString filename = "rootFiles/LHC11a10a_bis/Et.ESD.simPbPb.EMCal.LHC11a10a_bis.Run139465.root",TString datafilename = "rootFiles/LHC10hPass2/Et.ESD.realPbPb.EMCal.LHC10hPass2.Run139465.root", Bool_t effCorr = kTRUE){
    TString detector = "";
  gStyle->SetOptTitle(0);
  gStyle->SetOptStat(0);
  gStyle->SetOptFit(0);

    if(filename.Contains("EMC")){
      detector = "Emcal";
    }
    else{
      detector = "Phos";
    }
    TString tag = "";
    if(!effCorr) tag = "NoEffCorr";

    TString outname1 = "/tmp/SecondariesVsTrMult"+detector+".eps";
    TString outname3 = "/tmp/SecondariesVsTrMultRatio"+detector+".png";
    TString outname2 = "/tmp/SecondariesVsClMult"+detector+".eps";
    ofstream myfile;
    TString textfilename = "Secondaries"+detector+tag+".dat";
    myfile.open (textfilename.Data());
    ofstream myfile2;
    TString textfilename2 = "Secondaries"+detector+tag+"Short.dat";
    myfile2.open (textfilename2.Data());

    TFile *fdata = TFile::Open(datafilename, "READ");
    TList *ldata = dynamic_cast<TList*>(fdata->Get("out1"));
    TH3F *fHistCentVsNchVsNclData = ldata->FindObject("fHistCentVsNchVsNclReco");
    fHistCentVsNchVsNclData->SetName("fHistCentVsNchVsNclRecoData");

    TFile *f = TFile::Open(filename, "READ");
    TList *l = dynamic_cast<TList*>(f->Get("out1"));
    TH2F *fHistSecondariesVsNch;
    TH2F *fHistSecondariesVsNcl;
    TH2F *fHistSecondariesOutOfAccEffCorrVsNch;
    TH2F *fHistSecondariesDetectorCoverEffCorrVsNch;
    if(effCorr){
      fHistSecondariesVsNch =(TH2F *) l->FindObject("fHistSecondariesEffCorrVsNch");
      fHistSecondariesVsNcl =(TH2F *) l->FindObject("fHistSecondariesEffCorrVsNcl");
      fHistSecondariesOutOfAccEffCorrVsNch =(TH2F *) l->FindObject("fHistSecondariesOutOfAccEffCorrVsNch");
      fHistSecondariesDetectorCoverEffCorrVsNch =(TH2F *) l->FindObject("fHistSecondariesDetectorCoverEffCorrVsNch");
    }
    else{
      fHistSecondariesVsNch =(TH2F *) l->FindObject("fHistSecondariesVsNch");
      fHistSecondariesVsNcl =(TH2F *) l->FindObject("fHistSecondariesVsNcl");
      fHistSecondariesOutOfAccEffCorrVsNch =(TH2F *) l->FindObject("fHistSecondariesOutOfAccEffCorrVsNch");
      fHistSecondariesDetectorCoverEffCorrVsNch =(TH2F *) l->FindObject("fHistSecondariesDetectorCoverEffCorrVsNch");
    }
    TH3F *fHistCentVsNchVsNcl = l->FindObject("fHistCentVsNchVsNcl");

    TCanvas *c1 = new TCanvas("c1","Secondaries vs N_{ch}",600,400);
    c1->SetTopMargin(0.02);
    c1->SetRightMargin(0.02);
    c1->SetBorderSize(0);
    c1->SetFillColor(0);
    c1->SetFillColor(0);
    c1->SetBorderMode(0);
    c1->SetFrameFillColor(0);
    c1->SetFrameBorderMode(0);
    c1->SetLogz();
    //fHistSecondariesVsNch->GetXaxis()->SetRange(1,fHistSecondariesVsNch->GetXaxis()->FindBin(10.0));
    fHistSecondariesVsNch->Draw("colz");
    TH1D *prof1 = fHistSecondariesVsNch->ProfileX("prof1");
    prof1->Draw("same");
    TCanvas *c1a = new TCanvas("c1a","In detector cover and out of acceptance",600,400);
    c1a->SetTopMargin(0.02);
    c1a->SetRightMargin(0.02);
    c1a->SetBottomMargin(0.153226);
    c1a->SetBorderSize(0);
    c1a->SetFillColor(0);
    c1a->SetFillColor(0);
    c1a->SetBorderMode(0);
    c1a->SetFrameFillColor(0);
    c1a->SetFrameBorderMode(0);
    TH1D *profNCh = fHistSecondariesVsNch->ProfileY("profNCh");
    profNCh->Draw("");
    TH1D *profNChOutOfAcc = fHistSecondariesOutOfAccEffCorrVsNch->ProfileY("profNChOutOfAcc");
    TH1D *profNChDetCover = fHistSecondariesDetectorCoverEffCorrVsNch->ProfileY("profNChDetCover");
    //profNChDetCover->Draw("same");
    //profNChOutOfAcc->Draw("same");
    cout<<"Max "<<profNChDetCover->GetMaximum()<<" "<<profNChOutOfAcc->GetMaximum()<<" "<<profNCh->GetMaximum()<<endl;
    profNChDetCover->SetLineColor(TColor::kRed);
    profNChOutOfAcc->SetLineColor(TColor::kGreen+3);
    profNCh->GetXaxis()->SetTitle("N_{Ch}");
    profNCh->GetYaxis()->SetTitle("E_{T}^{Secondaries}");
    profNCh->GetXaxis()->SetLabelSize(0.06);
    profNCh->GetXaxis()->SetTitleSize(0.06);
    profNCh->GetYaxis()->SetLabelSize(0.06);
    profNCh->GetYaxis()->SetTitleSize(0.06);
    profNCh->GetYaxis()->SetTitleOffset(0.6);
    TLatex *texDet = new TLatex(50,6,detector.Data());
    texDet->SetTextSize(0.0752688);
    texDet->Draw();
    c1a->SaveAs(outname1.Data());
    TCanvas *c1b = new TCanvas("c1b","Fraction in detector cover, out of acceptance",600,400);
    c1b->SetTopMargin(0.02);
    c1b->SetRightMargin(0.02);
    c1b->SetBottomMargin(0.153226);
    c1b->SetBorderSize(0);
    c1b->SetFillColor(0);
    c1b->SetFillColor(0);
    c1b->SetBorderMode(0);
    c1b->SetFrameFillColor(0);
    c1b->SetFrameBorderMode(0);
//     profNCh->Draw("");
//     profNChDetCover->Draw("same")
//       profNChOutOfAcc->Draw("same");
    TH1D *profNChDetCoverRatio = profNChDetCover->Clone("profNChDetCoverRatio");
    TH1D *profNChOutOfAccRatio = profNChOutOfAcc->Clone("profNChOutOfAccRatio");
    profNChDetCoverRatio->Divide(profNCh);
    profNChOutOfAccRatio->Divide(profNCh);
    profNChDetCoverRatio->Draw("l");
    profNChOutOfAccRatio->Draw("same l");
    int rebin = 4;
    profNChDetCoverRatio->Rebin(rebin);
    profNChOutOfAccRatio->Rebin(rebin);
    profNChDetCoverRatio->Scale(1.0/rebin);
    profNChOutOfAccRatio->Scale(1.0/rebin);
    profNChDetCoverRatio->SetMaximum(0.2);
    c1b->SaveAs(outname3.Data());

    TCanvas *c2 = new TCanvas("c2","Secondaries vs NCl",600,400);
    c2->SetTopMargin(0.02);
    c2->SetRightMargin(0.02);
    c2->SetBorderSize(0);
    c2->SetFillColor(0);
    c2->SetFillColor(0);
    c2->SetBorderMode(0);
    c2->SetFrameFillColor(0);
    c2->SetFrameBorderMode(0);
    c2->SetLogz();
    fHistSecondariesVsNcl->Draw("colz");
    //fHistSecondariesVsNcl->GetXaxis()->SetRange(1,fHistSecondariesVsNcl->GetXaxis()->FindBin(10.0));
    TH1D *prof1 = fHistSecondariesVsNcl->ProfileX("prof2");
    prof1->Draw("same");
    TCanvas *c2a = new TCanvas("c2a","average secondaries vs NCl",600,400);
    c2a->SetTopMargin(0.02);
    c2a->SetRightMargin(0.02);
    c2a->SetBottomMargin(0.153226);
    c2a->SetBorderSize(0);
    c2a->SetFillColor(0);
    c2a->SetFillColor(0);
    c2a->SetBorderMode(0);
    c2a->SetFrameFillColor(0);
    c2a->SetFrameBorderMode(0);
    TH1D *profNCl = fHistSecondariesVsNcl->ProfileY("profNCl");
    profNCl->Draw("same");
    profNCl->GetXaxis()->SetTitle("N_{Cl}");
    profNCl->GetYaxis()->SetTitle("E_{T}^{Secondaries}");
    profNCl->GetXaxis()->SetLabelSize(0.06);
    profNCl->GetXaxis()->SetTitleSize(0.06);
    profNCl->GetYaxis()->SetLabelSize(0.06);
    profNCl->GetYaxis()->SetTitleSize(0.06);
    profNCl->GetYaxis()->SetTitleOffset(0.6);
    texDet->Draw();
    c2a->SaveAs(outname2.Data());

    TObjArray trackmultiplicity(20);
    TObjArray clustermultiplicity(20);
    TObjArray trackmultiplicityData(20);
    TObjArray clustermultiplicityData(20);
    int nbinsChMult = fHistCentVsNchVsNcl->GetYaxis()->GetNbins();
    int nbinsClMult = fHistCentVsNchVsNcl->GetZaxis()->GetNbins();
    fHistCentVsNchVsNcl->GetXaxis()->SetTitle("Cent Bin");
    fHistCentVsNchVsNcl->GetYaxis()->SetTitle("N_{tr}");
    fHistCentVsNchVsNcl->GetZaxis()->SetTitle("N_{cl}");
    for(int cb=0;cb<20;cb++){
      //x axis is centrality
      //y axis is charged track multiplicity
      //z axis is cluster multiplicity
      fHistCentVsNchVsNcl->GetXaxis()->SetRange(cb+1,cb+1);
      trackmultiplicity[cb] = fHistCentVsNchVsNcl->Project3D("y");
      clustermultiplicity[cb] = fHistCentVsNchVsNcl->Project3D("z");
      SetStyles((TH1*)trackmultiplicity[cb],markers[cb],colors[cb],Form("tr%i",cb));
      SetStyles((TH1*)clustermultiplicity[cb],markers[cb],colors[cb],Form("cl%i",cb));
      fHistCentVsNchVsNclData->GetXaxis()->SetRange(cb+1,cb+1);
      trackmultiplicityData[cb] = fHistCentVsNchVsNclData->Project3D("y");
      clustermultiplicityData[cb] = fHistCentVsNchVsNclData->Project3D("z");
      SetStyles((TH1*)trackmultiplicityData[cb],markers[cb],colors[cb],Form("tr%i",cb));
      SetStyles((TH1*)clustermultiplicityData[cb],markers[cb],colors[cb],Form("cl%i",cb));
    }
    TCanvas *c3 = new TCanvas("c3","<E_{T}> Neutral Removed",600,400);
    c3->SetTopMargin(0.02);
    c3->SetRightMargin(0.02);
    c3->SetBorderSize(0);
    c3->SetFillColor(0);
    c3->SetFillColor(0);
    c3->SetBorderMode(0);
    c3->SetFrameFillColor(0);
    c3->SetFrameBorderMode(0);
    c3->SetLogy();
    ((TH1*)trackmultiplicity[0])->Draw();
    for(int cb=1;cb<20;cb++){
//       cout<<"cb "<<cb<<" tr "<< ((TH1*)trackmultiplicity[cb])->GetMean();
//       cout<<" cluster "<< ((TH1*)clustermultiplicity[cb])->GetMean()<<endl;
      ((TH1*)trackmultiplicity[cb])->Draw("same");
    }
    TCanvas *c4 = new TCanvas("c4","<E_{T}> Neutral Removed",600,400);
    c4->SetTopMargin(0.02);
    c4->SetRightMargin(0.02);
    c4->SetBorderSize(0);
    c4->SetFillColor(0);
    c4->SetFillColor(0);
    c4->SetBorderMode(0);
    c4->SetFrameFillColor(0);
    c4->SetFrameBorderMode(0);
    c4->SetLogy();
    ((TH1*)clustermultiplicity[0])->Draw();
    for(int cb=1;cb<20;cb++){
//       cout<<"cb "<<cb<<" "<< ((TH1*)trackmultiplicity[cb])->GetMean()<<endl;
      ((TH1*)clustermultiplicity[cb])->Draw("same");
    }
    cout<<" Sim cluster track data cluster track "<<endl;
      //for fewer centrality bins
    int currentShortCB = 0;
    Float_t neventsShort[] = {0,0,0,0};
    //profNCh, profNCl
    for(int cb=0;cb<19;cb++){

      int nbins = ((TH1*)clustermultiplicity[cb])->GetNbinsX();
      Float_t nevents = 0.0;
      for(int binn = 1;binn<=nbins;binn++){
	float neventsBinn = ((TH1*)clustermultiplicity[cb])->GetBinContent(binn);
	float mult= ((TH1*)clustermultiplicity[cb])->GetBinCenter(binn);
	float meanet = profNCl->GetBinContent(profNCl->FindBin(mult));
	nSecondariesClMultScaledSim[cb] += neventsBinn*meanet;
	nevents +=neventsBinn;
	nSecondariesShortClMultScaledSim[currentShortCB] += neventsBinn*meanet;
	neventsShort[0] +=neventsBinn;
      }
      if(nevents>0) nSecondariesClMultScaledSim[cb] = nSecondariesClMultScaledSim[cb]/nevents;



      nbins = ((TH1*)trackmultiplicity[cb])->GetNbinsX();
      nevents = 0.0;
      for(int binn = 1;binn<=nbins;binn++){
	float neventsBinn = ((TH1*)trackmultiplicity[cb])->GetBinContent(binn);
	float mult= ((TH1*)trackmultiplicity[cb])->GetBinCenter(binn);
	float meanet = profNCh->GetBinContent(profNCh->FindBin(mult));
	nSecondariesTrMultScaledSim[cb] += neventsBinn*meanet;
	nevents +=neventsBinn;
	nSecondariesShortTrMultScaledSim[currentShortCB] += neventsBinn*meanet;
	neventsShort[1] +=neventsBinn;
      }
      if(nevents>0) nSecondariesTrMultScaledSim[cb] = nSecondariesTrMultScaledSim[cb]/nevents;

      nbins = ((TH1*)clustermultiplicity[cb])->GetNbinsX();
      nevents = 0.0;
      float meanmult = 0.0;
      //cout<<"Data cluster scaled  = (";
      for(int binn = 1;binn<=nbins;binn++){
	float neventsBinn = ((TH1*)clustermultiplicity[cb])->GetBinContent(binn);
	float mult= ((TH1*)clustermultiplicity[cb])->GetBinCenter(binn);
	float meanet = profNCl->GetBinContent(profNCl->FindBin(mult));
	nSecondariesClMultScaledData[cb] += neventsBinn*meanet;
	meanmult += neventsBinn*mult;
	nevents +=neventsBinn;
	//if(neventsBinn>0) cout<<"("<<mult<<") "<<neventsBinn<<"*"<<meanet<<"+";
	nSecondariesShortClMultScaledData[currentShortCB] += neventsBinn*meanet;
 	neventsShort[2] +=neventsBinn;
      }
      if(nevents>0) meanmult = meanmult/nevents;
      //nSecondariesClMultScaledData[cb] = nSecondariesClMultScaledData[cb]/nevents;
      //cout<<")/"<<nevents<<endl;
      //cout<<"cb "<<cb<<" = "<<nSecondariesClMultScaledData[cb]<<"/"<<nevents;
      if(nevents>0) nSecondariesClMultScaledData[cb] = nSecondariesClMultScaledData[cb]/nevents;//<<" = ";
      //cout<<" " << nSecondariesClMultScaledData[cb];
      //cout<<" mean "<<((TH1*)clustermultiplicityData[cb])->GetMean()<<" mean2 "<<meanmult<<" mean method "<< profNCl->GetBinContent(profNCl->FindBin(meanmult));
      //cout<<" mean method "<< profNCl->GetBinContent(profNCl->FindBin(((TH1*)trackmultiplicityData[cb])->GetMean()));
      //cout<<endl;

      nbins = ((TH1*)trackmultiplicity[cb])->GetNbinsX();
      nevents = 0.0;
      for(int binn = 1;binn<=nbins;binn++){
	float neventsBinn = ((TH1*)trackmultiplicityData[cb])->GetBinContent(binn);
	float mult= ((TH1*)trackmultiplicityData[cb])->GetBinCenter(binn);
	float meanet = profNCh->GetBinContent(profNCh->FindBin(mult));
	nSecondariesTrMultScaledData[cb] += neventsBinn*meanet;
	nevents +=neventsBinn;
	nSecondariesShortTrMultScaledData[currentShortCB] += neventsBinn*meanet;
	neventsShort[3] +=neventsBinn;
      }

//       cout<<"cb "<<cb<<" = "<<nSecondariesTrMultScaledData[cb]<<"/"<<nevents;
      if(nevents>0) nSecondariesTrMultScaledData[cb] = nSecondariesTrMultScaledData[cb]/nevents;
//       cout<<" " << nSecondariesTrMultScaledData[cb];
//       cout<<" mean "<<((TH1*)trackmultiplicityData[cb])->GetMean()<<" mean method "<< profNCh->GetBinContent(profNCh->FindBin(((TH1*)trackmultiplicityData[cb])->GetMean()));
//       cout<<endl<<endl;


      float meanSim = ( nSecondariesTrMultScaledSim[cb] +  nSecondariesClMultScaledSim[cb] ) /2.0;
      float errSim =  TMath::Abs( nSecondariesTrMultScaledSim[cb] -  nSecondariesClMultScaledSim[cb] ) /2.0;
      float mean = ( nSecondariesTrMultScaledData[cb] +  nSecondariesClMultScaledData[cb] ) /2.0;
      float err =  TMath::Abs( nSecondariesTrMultScaledData[cb] -  nSecondariesClMultScaledData[cb] ) /2.0;
      myfile<<Form("%2.3f %2.3f",mean,err)<<endl;

      cout<<"cb "<<cb<<" ET from secondaries "<< nSecondariesClMultScaledSim[cb];// <<endl;
      cout<<" "<< nSecondariesTrMultScaledSim[cb];
      cout<<" "<<meanSim << "+/-"<<errSim;
      cout<<" "<< nSecondariesClMultScaledData[cb];
      cout<<" "<< nSecondariesTrMultScaledData[cb];
      cout<<" "<<mean << "+/-"<<err;
      cout<<endl;

      //return;
      if(cb<2 || (cb+1)%2==0){//For combined bins, 
	if(neventsShort[0]>0)nSecondariesShortClMultScaledSim[currentShortCB] = nSecondariesShortClMultScaledSim[currentShortCB]/neventsShort[0];
	if(neventsShort[1]>0)nSecondariesShortTrMultScaledSim[currentShortCB] = nSecondariesShortTrMultScaledSim[currentShortCB]/neventsShort[1];
	if(neventsShort[2]>0)nSecondariesShortClMultScaledData[currentShortCB] = nSecondariesShortClMultScaledData[currentShortCB]/neventsShort[2];
	if(neventsShort[3]>0)nSecondariesShortTrMultScaledData[currentShortCB] = nSecondariesShortTrMultScaledData[currentShortCB]/neventsShort[3];
	cout<<"cb Short "<<currentShortCB<<" ET from secondaries "<< nSecondariesShortClMultScaledSim[currentShortCB];// <<endl;
	cout<<" "<< nSecondariesShortTrMultScaledSim[currentShortCB];

	meanSim = ( nSecondariesShortTrMultScaledSim[currentShortCB] +  nSecondariesShortClMultScaledSim[currentShortCB] ) /2.0;
	errSim =  TMath::Abs( nSecondariesShortTrMultScaledSim[currentShortCB] -  nSecondariesShortClMultScaledSim[currentShortCB] ) /2.0;
	cout<<" "<<meanSim << "+/-"<<errSim;

	cout<<" "<< nSecondariesShortClMultScaledData[currentShortCB];
	cout<<" "<< nSecondariesShortTrMultScaledData[currentShortCB];

	for(int k=0;k<4;k++){neventsShort[k] = 0;}

	mean = ( nSecondariesShortTrMultScaledData[currentShortCB] +  nSecondariesShortClMultScaledData[currentShortCB] ) /2.0;
	err =  TMath::Abs( nSecondariesShortTrMultScaledData[currentShortCB] -  nSecondariesShortClMultScaledData[currentShortCB] ) /2.0;
	myfile2<<Form("%2.3f %2.3f",mean,err)<<endl;
	//myfile2<<mean<<" "<<err<<endl;
	cout<<" "<<mean << "+/-"<<err;
	cout<<endl;

	currentShortCB++;
	cout<<"cb "<<cb<<" incrementing short CB "<<currentShortCB<<endl<<endl;
      }

    }
    myfile.close();
    myfile2.close();

    WriteLatex();
}

void WriteLatex(){
  TString detector = "Emcal";
    string inline;
    TString secondaryInfileName = "Secondaries"+detector+".dat";
    ifstream mysecondaryfile3 (secondaryInfileName.Data());
    Float_t value = 0;
    Float_t error = 0;
    Int_t i=0;
    if (mysecondaryfile3.is_open()){
      while ( mysecondaryfile3.good() )
	{
	  getline (mysecondaryfile3,inline);
	  istringstream tmp(inline);
	  tmp >> value;
	  tmp >> error;
	  if(i<20){
	    secondaryCorrEmcal[i] = value;
	    secondaryErrorEmcal[i] = error;
	  }
	  i++;
	}
        mysecondaryfile3.close();
    }

    detector = "Phos";
    secondaryInfileName = "Secondaries"+detector+".dat";
    ifstream mysecondaryfile4 (secondaryInfileName.Data());
    Float_t value = 0;
    Float_t error = 0;
    Int_t i=0;
    if (mysecondaryfile4.is_open()){
      while ( mysecondaryfile4.good() )
	{
	  getline (mysecondaryfile4,inline);
	  istringstream tmp(inline);
	  tmp >> value;
	  tmp >> error;
	  if(i<20){
	    secondaryCorrPhos[i] = value;
	    secondaryErrorPhos[i] = error;
	  }
	  i++;
	}
        mysecondaryfile4.close();
    }
    ofstream myfile3;
    myfile3.open ("Secondaries.tex");

    for(int i=0;i<20;i++){
      TString line = Form("%i-%i & %2.3f $\\pm$ %2.3f & %2.3f $\\pm$ %2.3f \\\\",i*5,(i+1)*5,secondaryCorrPhos[i],secondaryErrorPhos[i],secondaryCorrEmcal[i],secondaryErrorEmcal[i]);
      myfile3<<line.Data()<<endl;
    }
    myfile3.close();


}
 PlotSecondariesCorr.C:1
 PlotSecondariesCorr.C:2
 PlotSecondariesCorr.C:3
 PlotSecondariesCorr.C:4
 PlotSecondariesCorr.C:5
 PlotSecondariesCorr.C:6
 PlotSecondariesCorr.C:7
 PlotSecondariesCorr.C:8
 PlotSecondariesCorr.C:9
 PlotSecondariesCorr.C:10
 PlotSecondariesCorr.C:11
 PlotSecondariesCorr.C:12
 PlotSecondariesCorr.C:13
 PlotSecondariesCorr.C:14
 PlotSecondariesCorr.C:15
 PlotSecondariesCorr.C:16
 PlotSecondariesCorr.C:17
 PlotSecondariesCorr.C:18
 PlotSecondariesCorr.C:19
 PlotSecondariesCorr.C:20
 PlotSecondariesCorr.C:21
 PlotSecondariesCorr.C:22
 PlotSecondariesCorr.C:23
 PlotSecondariesCorr.C:24
 PlotSecondariesCorr.C:25
 PlotSecondariesCorr.C:26
 PlotSecondariesCorr.C:27
 PlotSecondariesCorr.C:28
 PlotSecondariesCorr.C:29
 PlotSecondariesCorr.C:30
 PlotSecondariesCorr.C:31
 PlotSecondariesCorr.C:32
 PlotSecondariesCorr.C:33
 PlotSecondariesCorr.C:34
 PlotSecondariesCorr.C:35
 PlotSecondariesCorr.C:36
 PlotSecondariesCorr.C:37
 PlotSecondariesCorr.C:38
 PlotSecondariesCorr.C:39
 PlotSecondariesCorr.C:40
 PlotSecondariesCorr.C:41
 PlotSecondariesCorr.C:42
 PlotSecondariesCorr.C:43
 PlotSecondariesCorr.C:44
 PlotSecondariesCorr.C:45
 PlotSecondariesCorr.C:46
 PlotSecondariesCorr.C:47
 PlotSecondariesCorr.C:48
 PlotSecondariesCorr.C:49
 PlotSecondariesCorr.C:50
 PlotSecondariesCorr.C:51
 PlotSecondariesCorr.C:52
 PlotSecondariesCorr.C:53
 PlotSecondariesCorr.C:54
 PlotSecondariesCorr.C:55
 PlotSecondariesCorr.C:56
 PlotSecondariesCorr.C:57
 PlotSecondariesCorr.C:58
 PlotSecondariesCorr.C:59
 PlotSecondariesCorr.C:60
 PlotSecondariesCorr.C:61
 PlotSecondariesCorr.C:62
 PlotSecondariesCorr.C:63
 PlotSecondariesCorr.C:64
 PlotSecondariesCorr.C:65
 PlotSecondariesCorr.C:66
 PlotSecondariesCorr.C:67
 PlotSecondariesCorr.C:68
 PlotSecondariesCorr.C:69
 PlotSecondariesCorr.C:70
 PlotSecondariesCorr.C:71
 PlotSecondariesCorr.C:72
 PlotSecondariesCorr.C:73
 PlotSecondariesCorr.C:74
 PlotSecondariesCorr.C:75
 PlotSecondariesCorr.C:76
 PlotSecondariesCorr.C:77
 PlotSecondariesCorr.C:78
 PlotSecondariesCorr.C:79
 PlotSecondariesCorr.C:80
 PlotSecondariesCorr.C:81
 PlotSecondariesCorr.C:82
 PlotSecondariesCorr.C:83
 PlotSecondariesCorr.C:84
 PlotSecondariesCorr.C:85
 PlotSecondariesCorr.C:86
 PlotSecondariesCorr.C:87
 PlotSecondariesCorr.C:88
 PlotSecondariesCorr.C:89
 PlotSecondariesCorr.C:90
 PlotSecondariesCorr.C:91
 PlotSecondariesCorr.C:92
 PlotSecondariesCorr.C:93
 PlotSecondariesCorr.C:94
 PlotSecondariesCorr.C:95
 PlotSecondariesCorr.C:96
 PlotSecondariesCorr.C:97
 PlotSecondariesCorr.C:98
 PlotSecondariesCorr.C:99
 PlotSecondariesCorr.C:100
 PlotSecondariesCorr.C:101
 PlotSecondariesCorr.C:102
 PlotSecondariesCorr.C:103
 PlotSecondariesCorr.C:104
 PlotSecondariesCorr.C:105
 PlotSecondariesCorr.C:106
 PlotSecondariesCorr.C:107
 PlotSecondariesCorr.C:108
 PlotSecondariesCorr.C:109
 PlotSecondariesCorr.C:110
 PlotSecondariesCorr.C:111
 PlotSecondariesCorr.C:112
 PlotSecondariesCorr.C:113
 PlotSecondariesCorr.C:114
 PlotSecondariesCorr.C:115
 PlotSecondariesCorr.C:116
 PlotSecondariesCorr.C:117
 PlotSecondariesCorr.C:118
 PlotSecondariesCorr.C:119
 PlotSecondariesCorr.C:120
 PlotSecondariesCorr.C:121
 PlotSecondariesCorr.C:122
 PlotSecondariesCorr.C:123
 PlotSecondariesCorr.C:124
 PlotSecondariesCorr.C:125
 PlotSecondariesCorr.C:126
 PlotSecondariesCorr.C:127
 PlotSecondariesCorr.C:128
 PlotSecondariesCorr.C:129
 PlotSecondariesCorr.C:130
 PlotSecondariesCorr.C:131
 PlotSecondariesCorr.C:132
 PlotSecondariesCorr.C:133
 PlotSecondariesCorr.C:134
 PlotSecondariesCorr.C:135
 PlotSecondariesCorr.C:136
 PlotSecondariesCorr.C:137
 PlotSecondariesCorr.C:138
 PlotSecondariesCorr.C:139
 PlotSecondariesCorr.C:140
 PlotSecondariesCorr.C:141
 PlotSecondariesCorr.C:142
 PlotSecondariesCorr.C:143
 PlotSecondariesCorr.C:144
 PlotSecondariesCorr.C:145
 PlotSecondariesCorr.C:146
 PlotSecondariesCorr.C:147
 PlotSecondariesCorr.C:148
 PlotSecondariesCorr.C:149
 PlotSecondariesCorr.C:150
 PlotSecondariesCorr.C:151
 PlotSecondariesCorr.C:152
 PlotSecondariesCorr.C:153
 PlotSecondariesCorr.C:154
 PlotSecondariesCorr.C:155
 PlotSecondariesCorr.C:156
 PlotSecondariesCorr.C:157
 PlotSecondariesCorr.C:158
 PlotSecondariesCorr.C:159
 PlotSecondariesCorr.C:160
 PlotSecondariesCorr.C:161
 PlotSecondariesCorr.C:162
 PlotSecondariesCorr.C:163
 PlotSecondariesCorr.C:164
 PlotSecondariesCorr.C:165
 PlotSecondariesCorr.C:166
 PlotSecondariesCorr.C:167
 PlotSecondariesCorr.C:168
 PlotSecondariesCorr.C:169
 PlotSecondariesCorr.C:170
 PlotSecondariesCorr.C:171
 PlotSecondariesCorr.C:172
 PlotSecondariesCorr.C:173
 PlotSecondariesCorr.C:174
 PlotSecondariesCorr.C:175
 PlotSecondariesCorr.C:176
 PlotSecondariesCorr.C:177
 PlotSecondariesCorr.C:178
 PlotSecondariesCorr.C:179
 PlotSecondariesCorr.C:180
 PlotSecondariesCorr.C:181
 PlotSecondariesCorr.C:182
 PlotSecondariesCorr.C:183
 PlotSecondariesCorr.C:184
 PlotSecondariesCorr.C:185
 PlotSecondariesCorr.C:186
 PlotSecondariesCorr.C:187
 PlotSecondariesCorr.C:188
 PlotSecondariesCorr.C:189
 PlotSecondariesCorr.C:190
 PlotSecondariesCorr.C:191
 PlotSecondariesCorr.C:192
 PlotSecondariesCorr.C:193
 PlotSecondariesCorr.C:194
 PlotSecondariesCorr.C:195
 PlotSecondariesCorr.C:196
 PlotSecondariesCorr.C:197
 PlotSecondariesCorr.C:198
 PlotSecondariesCorr.C:199
 PlotSecondariesCorr.C:200
 PlotSecondariesCorr.C:201
 PlotSecondariesCorr.C:202
 PlotSecondariesCorr.C:203
 PlotSecondariesCorr.C:204
 PlotSecondariesCorr.C:205
 PlotSecondariesCorr.C:206
 PlotSecondariesCorr.C:207
 PlotSecondariesCorr.C:208
 PlotSecondariesCorr.C:209
 PlotSecondariesCorr.C:210
 PlotSecondariesCorr.C:211
 PlotSecondariesCorr.C:212
 PlotSecondariesCorr.C:213
 PlotSecondariesCorr.C:214
 PlotSecondariesCorr.C:215
 PlotSecondariesCorr.C:216
 PlotSecondariesCorr.C:217
 PlotSecondariesCorr.C:218
 PlotSecondariesCorr.C:219
 PlotSecondariesCorr.C:220
 PlotSecondariesCorr.C:221
 PlotSecondariesCorr.C:222
 PlotSecondariesCorr.C:223
 PlotSecondariesCorr.C:224
 PlotSecondariesCorr.C:225
 PlotSecondariesCorr.C:226
 PlotSecondariesCorr.C:227
 PlotSecondariesCorr.C:228
 PlotSecondariesCorr.C:229
 PlotSecondariesCorr.C:230
 PlotSecondariesCorr.C:231
 PlotSecondariesCorr.C:232
 PlotSecondariesCorr.C:233
 PlotSecondariesCorr.C:234
 PlotSecondariesCorr.C:235
 PlotSecondariesCorr.C:236
 PlotSecondariesCorr.C:237
 PlotSecondariesCorr.C:238
 PlotSecondariesCorr.C:239
 PlotSecondariesCorr.C:240
 PlotSecondariesCorr.C:241
 PlotSecondariesCorr.C:242
 PlotSecondariesCorr.C:243
 PlotSecondariesCorr.C:244
 PlotSecondariesCorr.C:245
 PlotSecondariesCorr.C:246
 PlotSecondariesCorr.C:247
 PlotSecondariesCorr.C:248
 PlotSecondariesCorr.C:249
 PlotSecondariesCorr.C:250
 PlotSecondariesCorr.C:251
 PlotSecondariesCorr.C:252
 PlotSecondariesCorr.C:253
 PlotSecondariesCorr.C:254
 PlotSecondariesCorr.C:255
 PlotSecondariesCorr.C:256
 PlotSecondariesCorr.C:257
 PlotSecondariesCorr.C:258
 PlotSecondariesCorr.C:259
 PlotSecondariesCorr.C:260
 PlotSecondariesCorr.C:261
 PlotSecondariesCorr.C:262
 PlotSecondariesCorr.C:263
 PlotSecondariesCorr.C:264
 PlotSecondariesCorr.C:265
 PlotSecondariesCorr.C:266
 PlotSecondariesCorr.C:267
 PlotSecondariesCorr.C:268
 PlotSecondariesCorr.C:269
 PlotSecondariesCorr.C:270
 PlotSecondariesCorr.C:271
 PlotSecondariesCorr.C:272
 PlotSecondariesCorr.C:273
 PlotSecondariesCorr.C:274
 PlotSecondariesCorr.C:275
 PlotSecondariesCorr.C:276
 PlotSecondariesCorr.C:277
 PlotSecondariesCorr.C:278
 PlotSecondariesCorr.C:279
 PlotSecondariesCorr.C:280
 PlotSecondariesCorr.C:281
 PlotSecondariesCorr.C:282
 PlotSecondariesCorr.C:283
 PlotSecondariesCorr.C:284
 PlotSecondariesCorr.C:285
 PlotSecondariesCorr.C:286
 PlotSecondariesCorr.C:287
 PlotSecondariesCorr.C:288
 PlotSecondariesCorr.C:289
 PlotSecondariesCorr.C:290
 PlotSecondariesCorr.C:291
 PlotSecondariesCorr.C:292
 PlotSecondariesCorr.C:293
 PlotSecondariesCorr.C:294
 PlotSecondariesCorr.C:295
 PlotSecondariesCorr.C:296
 PlotSecondariesCorr.C:297
 PlotSecondariesCorr.C:298
 PlotSecondariesCorr.C:299
 PlotSecondariesCorr.C:300
 PlotSecondariesCorr.C:301
 PlotSecondariesCorr.C:302
 PlotSecondariesCorr.C:303
 PlotSecondariesCorr.C:304
 PlotSecondariesCorr.C:305
 PlotSecondariesCorr.C:306
 PlotSecondariesCorr.C:307
 PlotSecondariesCorr.C:308
 PlotSecondariesCorr.C:309
 PlotSecondariesCorr.C:310
 PlotSecondariesCorr.C:311
 PlotSecondariesCorr.C:312
 PlotSecondariesCorr.C:313
 PlotSecondariesCorr.C:314
 PlotSecondariesCorr.C:315
 PlotSecondariesCorr.C:316
 PlotSecondariesCorr.C:317
 PlotSecondariesCorr.C:318
 PlotSecondariesCorr.C:319
 PlotSecondariesCorr.C:320
 PlotSecondariesCorr.C:321
 PlotSecondariesCorr.C:322
 PlotSecondariesCorr.C:323
 PlotSecondariesCorr.C:324
 PlotSecondariesCorr.C:325
 PlotSecondariesCorr.C:326
 PlotSecondariesCorr.C:327
 PlotSecondariesCorr.C:328
 PlotSecondariesCorr.C:329
 PlotSecondariesCorr.C:330
 PlotSecondariesCorr.C:331
 PlotSecondariesCorr.C:332
 PlotSecondariesCorr.C:333
 PlotSecondariesCorr.C:334
 PlotSecondariesCorr.C:335
 PlotSecondariesCorr.C:336
 PlotSecondariesCorr.C:337
 PlotSecondariesCorr.C:338
 PlotSecondariesCorr.C:339
 PlotSecondariesCorr.C:340
 PlotSecondariesCorr.C:341
 PlotSecondariesCorr.C:342
 PlotSecondariesCorr.C:343
 PlotSecondariesCorr.C:344
 PlotSecondariesCorr.C:345
 PlotSecondariesCorr.C:346
 PlotSecondariesCorr.C:347
 PlotSecondariesCorr.C:348
 PlotSecondariesCorr.C:349
 PlotSecondariesCorr.C:350
 PlotSecondariesCorr.C:351
 PlotSecondariesCorr.C:352
 PlotSecondariesCorr.C:353
 PlotSecondariesCorr.C:354
 PlotSecondariesCorr.C:355
 PlotSecondariesCorr.C:356
 PlotSecondariesCorr.C:357
 PlotSecondariesCorr.C:358
 PlotSecondariesCorr.C:359
 PlotSecondariesCorr.C:360
 PlotSecondariesCorr.C:361
 PlotSecondariesCorr.C:362
 PlotSecondariesCorr.C:363
 PlotSecondariesCorr.C:364
 PlotSecondariesCorr.C:365
 PlotSecondariesCorr.C:366
 PlotSecondariesCorr.C:367
 PlotSecondariesCorr.C:368
 PlotSecondariesCorr.C:369
 PlotSecondariesCorr.C:370
 PlotSecondariesCorr.C:371
 PlotSecondariesCorr.C:372
 PlotSecondariesCorr.C:373
 PlotSecondariesCorr.C:374
 PlotSecondariesCorr.C:375
 PlotSecondariesCorr.C:376
 PlotSecondariesCorr.C:377
 PlotSecondariesCorr.C:378
 PlotSecondariesCorr.C:379
 PlotSecondariesCorr.C:380
 PlotSecondariesCorr.C:381
 PlotSecondariesCorr.C:382
 PlotSecondariesCorr.C:383
 PlotSecondariesCorr.C:384
 PlotSecondariesCorr.C:385
 PlotSecondariesCorr.C:386
 PlotSecondariesCorr.C:387
 PlotSecondariesCorr.C:388
 PlotSecondariesCorr.C:389
 PlotSecondariesCorr.C:390
 PlotSecondariesCorr.C:391
 PlotSecondariesCorr.C:392
 PlotSecondariesCorr.C:393
 PlotSecondariesCorr.C:394
 PlotSecondariesCorr.C:395
 PlotSecondariesCorr.C:396
 PlotSecondariesCorr.C:397
 PlotSecondariesCorr.C:398
 PlotSecondariesCorr.C:399
 PlotSecondariesCorr.C:400
 PlotSecondariesCorr.C:401
 PlotSecondariesCorr.C:402
 PlotSecondariesCorr.C:403
 PlotSecondariesCorr.C:404
 PlotSecondariesCorr.C:405
 PlotSecondariesCorr.C:406
 PlotSecondariesCorr.C:407
 PlotSecondariesCorr.C:408
 PlotSecondariesCorr.C:409
 PlotSecondariesCorr.C:410
 PlotSecondariesCorr.C:411
 PlotSecondariesCorr.C:412
 PlotSecondariesCorr.C:413
 PlotSecondariesCorr.C:414
 PlotSecondariesCorr.C:415
 PlotSecondariesCorr.C:416
 PlotSecondariesCorr.C:417
 PlotSecondariesCorr.C:418
 PlotSecondariesCorr.C:419
 PlotSecondariesCorr.C:420
 PlotSecondariesCorr.C:421
 PlotSecondariesCorr.C:422
 PlotSecondariesCorr.C:423
 PlotSecondariesCorr.C:424
 PlotSecondariesCorr.C:425
 PlotSecondariesCorr.C:426
 PlotSecondariesCorr.C:427