int main (int argc, char **argv) {
 
 /// Input File MCTruth IC Map , RECO IC map, MC IC set after calibration (Usually set with miscalibration 5%)
 /// and StatPrecision IC coefficient obtained from DrawCalibrationPlotsEE.C

 if(argc != 2){
 std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ;
 return 1;
 }

 parseConfigFile (argv[1]) ;

 std::string inputFile = gConfigParser -> readStringOption("Input::inputFile");  
 std::string inputMomentumScale =  gConfigParser -> readStringOption("Input::inputMomentumScale");
 std::string fileMCTruth = gConfigParser -> readStringOption("Input::fileMCTruth");  
 std::string fileMCRecoIC = gConfigParser -> readStringOption("Input::fileMCRecoIC");  
 std::string fileStatPrecision = gConfigParser -> readStringOption("Input::fileStatPrecision");  
 
 std::string outputFile = gConfigParser -> readStringOption("Output::outputFile");  
 

 TApplication* theApp = new TApplication("Application",&argc, argv);

 TFile *f1 = TFile::Open(fileMCTruth.c_str());
 TFile *f2 = TFile::Open(fileMCRecoIC.c_str());  
 /// L3 result MC endcap
 TFile *f3 = TFile::Open(inputFile.c_str());  
 /// File form momentum scale correction
 TFile* input = new TFile(inputMomentumScale.c_str());
 /// Statistical Precision map 
 TFile *f4 =  TFile::Open(fileStatPrecision.c_str());
 
 if(f1==0 || f2==0 || f3==0 || f4==0) return -1; 


 // Set style options
 gROOT->Reset();
 gROOT->SetStyle("Plain");

 gStyle->SetPadTickX(1);
 gStyle->SetPadTickY(1);
 gStyle->SetOptTitle(0); 
 gStyle->SetOptStat(1110); 
 gStyle->SetOptFit(0); 
 gStyle->SetFitFormat("6.3g"); 
 gStyle->SetPalette(1); 
 
 gStyle->SetTextFont(42);
 gStyle->SetTextSize(0.05);
 gStyle->SetTitleFont(42,"xyz");
 gStyle->SetTitleSize(0.05);
 gStyle->SetLabelFont(42,"xyz");
 gStyle->SetLabelSize(0.05);
 gROOT->ForceStyle();


 /// input coeff map for EEP and EEM

 TH2F *hcmapMcT_EEP = (TH2F*)f1->Get("h_scale_EEP");
 TH2F *hcmapMcT_EEM = (TH2F*)f1->Get("h_scale_EEM");
 TH2F *hcmapMcR_EEP = (TH2F*)f2->Get("h_scale_EEP");
 TH2F *hcmapMcR_EEM = (TH2F*)f2->Get("h_scale_EEM");
 
 TH2F * hcmap_EEP = (TH2F*)hcmapMcT_EEP->Clone("hcmap_EEP");
 TH2F * hcmap_EEM = (TH2F*)hcmapMcT_EEM->Clone("hcmap_EEM");
 
 hcmap_EEP->Reset();
 hcmap_EEM->Reset();

 for (int jbin = 1; jbin < hcmap_EEP-> GetNbinsY(); jbin++){
   for (int ibin = 1; ibin < hcmap_EEM-> GetNbinsX()+1; ibin++){
	
     if(hcmapMcT_EEP->GetBinContent(ibin,jbin)!=0 && hcmapMcR_EEP->GetBinContent(ibin,jbin)!=0)
        hcmap_EEP->SetBinContent(ibin,jbin,hcmapMcT_EEP->GetBinContent(ibin,jbin)/hcmapMcR_EEP->GetBinContent(ibin,jbin));
     if(hcmapMcT_EEM->GetBinContent(ibin,jbin)!=0 && hcmapMcR_EEM->GetBinContent(ibin,jbin)!=0)
	hcmap_EEM->SetBinContent(ibin,jbin,hcmapMcT_EEM->GetBinContent(ibin,jbin)/hcmapMcR_EEM->GetBinContent(ibin,jbin));
      }
  }

 /// Scalib and L3 map Normalized for EE+ and EE-
 
 TH2F * miscalib_map_EEP = (TH2F*) f3 -> Get("h_scalib_EEP");
 TH2F * miscalib_map_EEM = (TH2F*) f3 -> Get("h_scalib_EEM");

 TH2F *hcL3_EEP = (TH2F*)f3->Get("h_scale_map_EEP");
 TH2F *hcL3_EEM = (TH2F*)f3->Get("h_scale_map_EEM");
  
 TH2F *hcmap2_EEP = (TH2F*)hcL3_EEP ->Clone("hcmap2_EEP");
 TH2F *hcmap2_EEM = (TH2F*)hcL3_EEM ->Clone("hcmap2_EEM");
  
 hcmap2_EEP->Reset();
 hcmap2_EEM->Reset();


 /// Momentum scale correction
 
 TGraphErrors* g_EoP_EE = (TGraphErrors*) input->Get("g_EoP_EE_0");
 TGraphErrors* PhiProjectionEEp = new TGraphErrors();
 TGraphErrors* PhiProjectionEEm = new TGraphErrors();
 
 PhiProjectionEEp->SetMarkerStyle(20);
 PhiProjectionEEp->SetMarkerSize(1);
 PhiProjectionEEp->SetMarkerColor(kRed);

 PhiProjectionEEm->SetMarkerStyle(20);
 PhiProjectionEEm->SetMarkerSize(1);
 PhiProjectionEEm->SetMarkerColor(kBlue);
 

 TEndcapRings *eRings = new TEndcapRings();
 std::vector<double> vectSum;
 std::vector<double> vectCounter;
 
 vectCounter.assign(g_EoP_EE->GetN(),0.);
 vectSum.assign(g_EoP_EE->GetN(),0.);

 /// EE+ and EE- projection 

 for(int ix=1; ix<hcL3_EEM->GetNbinsX()+1;ix++){
   for(int iy=1; iy<hcL3_EEM->GetNbinsY()+1;iy++){
    if(hcL3_EEM->GetBinContent(ix,iy)==0) continue;
      int iPhi = int(eRings->GetEndcapIphi(ix,iy,-1)/(360./g_EoP_EE->GetN()));
      vectSum.at(iPhi)=vectSum.at(iPhi)+hcL3_EEM->GetBinContent(ix,iy);
      vectCounter.at(iPhi)=vectCounter.at(iPhi)+1;
  }
 }


 for(unsigned int i=0; i<vectCounter.size();i++)
  PhiProjectionEEm->SetPoint(i,int(i*(360./g_EoP_EE->GetN())),vectSum.at(i)/vectCounter.at(i));

 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }

 for(int ix=1; ix<hcL3_EEP->GetNbinsX()+1;ix++){
   for(int iy=1; iy<hcL3_EEP->GetNbinsY()+1;iy++){
    if(hcL3_EEP->GetBinContent(ix,iy)==0) continue;
     int iPhi = int(eRings->GetEndcapIphi(ix,iy,1)/(360./g_EoP_EE->GetN()));
     vectSum.at(iPhi)=vectSum.at(iPhi)+hcL3_EEP->GetBinContent(ix,iy);
     vectCounter.at(iPhi)=vectCounter.at(iPhi)+1;
  }
 }

 
 for(unsigned int i=0; i<vectCounter.size();i++)
  PhiProjectionEEp->SetPoint(i,int(i*(360./g_EoP_EE->GetN())),vectSum.at(i)/vectCounter.at(i));
 
 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }

 /// Correction EE+ and EE-

 TH2F* mapMomentumCorrected[2];
 mapMomentumCorrected[0] = (TH2F*) hcL3_EEM->Clone("mapMomentumCorrected_EEM");
 mapMomentumCorrected[1] = (TH2F*) hcL3_EEP->Clone("mapMomentumCorrected_EEP");
 mapMomentumCorrected[0]->Reset();
 mapMomentumCorrected[1]->Reset();

 for(int ix=1; ix<hcL3_EEM->GetNbinsX()+1;ix++){
  for(int iy=1; iy<hcL3_EEM->GetNbinsY()+1;iy++){
   if(hcL3_EEM->GetBinContent(ix,iy)==0) continue;
    int iPhi = int(eRings->GetEndcapIphi(ix,iy,-1));
    double xphi,yphi;
    g_EoP_EE->GetPoint(int(iPhi/(360./PhiProjectionEEm->GetN())),xphi,yphi);
    mapMomentumCorrected[0]->SetBinContent(ix,iy,hcL3_EEM->GetBinContent(ix,iy)*yphi);
  }
 }

 for(int ix=1; ix<hcL3_EEP->GetNbinsX()+1;ix++){
  for(int iy=1; iy<hcL3_EEP->GetNbinsY()+1;iy++){
   if(hcL3_EEP->GetBinContent(ix,iy)==0) continue;
    int iPhi = int(eRings->GetEndcapIphi(ix,iy,1));
    double xphi,yphi; 
    g_EoP_EE->GetPoint(int(iPhi/(360./PhiProjectionEEp->GetN())),xphi,yphi);
    mapMomentumCorrected[1]->SetBinContent(ix,iy,hcL3_EEP->GetBinContent(ix,iy)*yphi);
  }
 }

/// Use momentum map corrected  

 for (int jbin = 1; jbin < mapMomentumCorrected[1]-> GetNbinsY()+1; jbin++){
    for (int ibin = 1; ibin < mapMomentumCorrected[1]-> GetNbinsX()+1; ibin++){
      if(miscalib_map_EEP->GetBinContent(ibin,jbin)!=0 && mapMomentumCorrected[1]->GetBinContent(ibin,jbin)!=0)
      hcmap2_EEP->SetBinContent(ibin,jbin,miscalib_map_EEP->GetBinContent(ibin,jbin)*mapMomentumCorrected[1]->GetBinContent(ibin,jbin));
      if(miscalib_map_EEM->GetBinContent(ibin,jbin)!=0 && mapMomentumCorrected[0]->GetBinContent(ibin,jbin)!=0)
      hcmap2_EEM->SetBinContent(ibin,jbin,miscalib_map_EEM->GetBinContent(ibin,jbin)*mapMomentumCorrected[0]->GetBinContent(ibin,jbin));
      }
    }


 /// output histos

 TH2F * h2_EEP = new TH2F("h2_EEP","h2_EEP",400,0.5,1.5,400,0.5,1.5);
 TH2F * h2_EEM = new TH2F("h2_EEM","h2_EEM",400,0.5,1.5,400,0.5,1.5);

 TH2F * h2diff_EEP = (TH2F*)hcmap_EEP->Clone("h2diff_EEP");
 TH2F * h2diff_EEM = (TH2F*)hcmap_EEM->Clone("h2diff_EEM");

 h2diff_EEP->Reset();
 h2diff_EEM->Reset();
   
 char hname[100];

 TH1F *hspread_EEP[40];
 TH1F *hspread_EEM[40];
 TH1F *hspread_All[40];

 /// ring geometry for the endcap

 TH2F *hrings_EEP;
 TH2F *hrings_EEM;

 hrings_EEP = (TH2F*)hcmap2_EEP->Clone("hringsEEP");
 hrings_EEM = (TH2F*)hcmap2_EEM->Clone("hringsEEM");
 hrings_EEP ->Reset();
 hrings_EEM ->Reset();

 FILE *fRing;
 fRing = fopen("macros/eerings.dat","r");
 int x,y,z,ir;
 while(fscanf(fRing,"(%d,%d,%d) %d \n",&x,&y,&z,&ir) !=EOF ) {
    if(z>0) hrings_EEP->Fill(x,y,ir); 
    if(z<0) hrings_EEM->Fill(x,y,ir);
 }

 /// spread IC histos
 for (int jbin = 0; jbin < 40; jbin++){
    sprintf(hname,"hspread_ring_EEP_%02d",jbin);
    hspread_EEP[jbin]= new TH1F(hname, hname, 75,0.5,1.5);
    sprintf(hname,"hspread_ring_EEM_%02d",jbin);
    hspread_EEM[jbin]= new TH1F(hname, hname, 75,0.5,1.5);
    sprintf(hname,"hspread_ring_All_%02d",jbin);
    hspread_All[jbin]= new TH1F(hname, hname, 75,0.5,1.5);
    
 }
  
 for (int jbin = 1; jbin < hcmap_EEP-> GetNbinsY()+1; jbin++){
   for (int ibin = 1; ibin < hcmap_EEP-> GetNbinsX()+1; ibin++){
      
     int mybin_EEP = hcmap_EEP -> FindBin(ibin,jbin);
     int ring_EEP  = int(hrings_EEP-> GetBinContent(mybin_EEP)); 	
     float c1_EEP = hcmap_EEP->GetBinContent(mybin_EEP);
     float c2_EEP = hcmap2_EEP->GetBinContent(mybin_EEP);
   
     int mybin_EEM = hcmap_EEM -> FindBin(ibin,jbin);
     int ring_EEM  = int(hrings_EEM-> GetBinContent(mybin_EEM)); 
     float c1_EEM = hcmap_EEM->GetBinContent(mybin_EEM);
     float c2_EEM = hcmap2_EEM->GetBinContent(mybin_EEM);
   
     if (c1_EEP!=0 && c2_EEP!=0 ){
        ///Ratio betweem IC and not the difference
 	hspread_EEP[ring_EEP]->Fill(c1_EEP/c2_EEP);
        hspread_All[ring_EEP]->Fill(c1_EEP/c2_EEP);
        
	h2_EEP->Fill(c1_EEP,c2_EEP);
        h2diff_EEP->SetBinContent(ibin,jbin,c1_EEP/c2_EEP); 
     }
     else h2diff_EEP->SetBinContent(ibin,jbin,0);

     if (c1_EEM!=0 && c2_EEM!=0 ){
        hspread_EEM[ring_EEM]->Fill(c1_EEM/c2_EEM);
        hspread_All[ring_EEM]->Fill(c1_EEM/c2_EEM);
        
	h2_EEM->Fill(c1_EEM,c2_EEM);
        h2diff_EEM->SetBinContent(ibin,jbin,c1_EEM/c2_EEM);       
     }
     else h2diff_EEM->SetBinContent(ibin,jbin,0);
    }
  }

 /// TGraphErrors for final plot
 TGraphErrors *sigma_vs_iring_EEP = new TGraphErrors();
 sigma_vs_iring_EEP->SetMarkerStyle(20);
 sigma_vs_iring_EEP->SetMarkerSize(1);
 sigma_vs_iring_EEP->SetMarkerColor(kBlue+2);
  
 TGraphErrors *sigma_vs_iring_EEM = new TGraphErrors();
 sigma_vs_iring_EEM->SetMarkerStyle(20);
 sigma_vs_iring_EEM->SetMarkerSize(1);
 sigma_vs_iring_EEM->SetMarkerColor(kBlue+2);

 TGraphErrors *sigma_vs_iring_All = new TGraphErrors();
 sigma_vs_iring_All->SetMarkerStyle(20);
 sigma_vs_iring_All->SetMarkerSize(1);
 sigma_vs_iring_All->SetMarkerColor(kBlue+2);
  
 TGraphErrors *scale_vs_iring_EEP = new TGraphErrors();
 scale_vs_iring_EEP->SetMarkerStyle(20);
 scale_vs_iring_EEP->SetMarkerSize(1);
 scale_vs_iring_EEP->SetMarkerColor(kBlue+2);

 TGraphErrors *scale_vs_iring_EEM = new TGraphErrors();
 scale_vs_iring_EEM->SetMarkerStyle(20);
 scale_vs_iring_EEM->SetMarkerSize(1);
 scale_vs_iring_EEM->SetMarkerColor(kBlue+2);

 TGraphErrors *scale_vs_iring_All = new TGraphErrors();
 scale_vs_iring_All->SetMarkerStyle(20);
 scale_vs_iring_All->SetMarkerSize(1);
 scale_vs_iring_All->SetMarkerColor(kBlue+2);
 
 /// Gauss function for fit
 TF1 *fgaus_EEP = new TF1("fgaus_EEP","gaus",0.,2.);
 TF1 *fgaus_EEM = new TF1("fgaus_EEM","gaus",0.,2.);
 TF1 *fgaus_All = new TF1("fgaus_All","gaus",0.,2.);
 
 int np_EEP = 0;
 int np_EEM = 0;
 int np_All = 0;
 for (int i = 0; i < 40; i++){
   if ( hspread_EEP[i]->GetEntries() == 0) {sigma_vs_iring_EEP-> SetPoint(np_EEP,i,-100);np_EEP++;continue;}
   if ( hspread_EEM[i]->GetEntries() == 0) {sigma_vs_iring_EEM-> SetPoint(np_EEM,i,-100);np_EEM++;continue;}
   if ( hspread_All[i]->GetEntries() == 0) {sigma_vs_iring_All-> SetPoint(np_All,i,-100);np_All++;continue;}
    
   hspread_EEP[i]->Fit("fgaus_EEP","QRME");
   hspread_EEM[i]->Fit("fgaus_EEM","QRME");
   hspread_All[i]->Fit("fgaus_All","QRME");
   TString Name = Form("c_%d",i);
 
   sigma_vs_iring_EEP-> SetPoint(np_EEP,i,fgaus_EEP->GetParameter(2));
   sigma_vs_iring_EEP-> SetPointError(np_EEP,0,fgaus_EEP->GetParError(2));
  
   scale_vs_iring_EEP-> SetPoint(np_EEP,i,fgaus_EEP->GetParameter(1));
   scale_vs_iring_EEP-> SetPointError(np_EEP,0,fgaus_EEP->GetParError(1));

   np_EEP++;  

   sigma_vs_iring_EEM-> SetPoint(np_EEM,i,fgaus_EEM->GetParameter(2));
   sigma_vs_iring_EEM-> SetPointError(np_EEM,0,fgaus_EEM->GetParError(2));

   scale_vs_iring_EEM-> SetPoint(np_EEM,i,fgaus_EEM->GetParameter(1));
   scale_vs_iring_EEM-> SetPointError(np_EEM,0,fgaus_EEM->GetParError(1));

   np_EEM++;

   sigma_vs_iring_All-> SetPoint(np_All,i,fgaus_All->GetParameter(2));
   sigma_vs_iring_All-> SetPointError(np_All,0,fgaus_All->GetParError(2));

   scale_vs_iring_All-> SetPoint(np_All,i,fgaus_All->GetParameter(1));
   scale_vs_iring_All-> SetPointError(np_All,0,fgaus_All->GetParError(1));

   np_All++;
 }
 
 /// For from statistical precision analysis

 TGraphErrors* gr_stat_prec_EEP = (TGraphErrors*) f4->Get("gr_stat_prec_EEP");
 TGraphErrors* gr_stat_prec_EEM = (TGraphErrors*) f4->Get("gr_stat_prec_EEM");
 TGraphErrors* gr_stat_prec_All = (TGraphErrors*) f4->Get("gr_stat_prec");
 
  /// Residual Plot
 TGraphErrors* residual_EEP = new TGraphErrors();
 TGraphErrors* residual_EEM = new TGraphErrors();
 TGraphErrors* residual_All = new TGraphErrors();

 for(int pp=0; pp< gr_stat_prec_EEP->GetN(); pp++){
    double ring1, ring2,tot, stat, espread, estat,ex,res,eres;
   
    sigma_vs_iring_EEP->GetPoint(pp, ring2, tot);
    espread = sigma_vs_iring_EEP-> GetErrorY(pp);

    gr_stat_prec_EEP->GetPoint(pp,ring1, stat);
    estat = gr_stat_prec_EEP-> GetErrorY(pp);

    ex = gr_stat_prec_EEP-> GetErrorX(pp);  

    if (tot > stat ){res = sqrt( tot*tot - stat*stat );
	             eres = sqrt( pow(tot*espread,2) + pow(stat*estat,2))/res;
	}
     else {res  = -sqrt( fabs(tot*tot - stat*stat) );
	   eres = sqrt( pow(tot*espread,2) + pow(stat*estat,2))/fabs(res);
	  }

    residual_EEP->SetPoint(pp,ring1,res);
    if(eres<0.01) residual_EEP->SetPointError(pp,ex,eres);
    else residual_EEP->SetPointError(pp,ex,0.01);
  }
  
 for(int pp=0; pp< gr_stat_prec_EEM->GetN(); pp++){
    double ring1, ring2,tot, stat, espread, estat,ex,res,eres;
   
    sigma_vs_iring_EEM->GetPoint(pp, ring2, tot);
    espread = sigma_vs_iring_EEM-> GetErrorY(pp);

    gr_stat_prec_EEM->GetPoint(pp,ring1, stat);
    estat = gr_stat_prec_EEM-> GetErrorY(pp);

    ex = gr_stat_prec_EEM-> GetErrorX(pp);  
    if (tot > stat ){res  = sqrt( tot*tot - stat*stat );
	             eres = sqrt( pow(tot*espread,2) + pow(stat*estat,2))/res;
	}
	else {res  = -sqrt( fabs(tot*tot - stat*stat) );
	      eres = sqrt( pow(tot*espread,2) + pow(stat*estat,2))/fabs(res);
	}
    residual_EEM->SetPoint(pp,ring1,res);
    if(eres<0.01) residual_EEM->SetPointError(pp,ex,eres);
    else residual_EEM->SetPointError(pp,ex,0.01);
  }
  
 for(int pp=0; pp< gr_stat_prec_All->GetN(); pp++){
    double ring1, ring2,tot, stat, espread, estat,ex,res,eres;
   
    sigma_vs_iring_All->GetPoint(pp, ring2, tot);
    espread = sigma_vs_iring_All-> GetErrorY(pp);

    gr_stat_prec_All->GetPoint(pp,ring1, stat);
    estat = gr_stat_prec_All-> GetErrorY(pp);

    ex = gr_stat_prec_All-> GetErrorX(pp);  
    if (tot > stat ){ res  = sqrt( tot*tot - stat*stat );
	              eres = sqrt( pow(tot*espread,2) + pow(stat*estat,2))/res;
	}
	else {res  = -sqrt( fabs(tot*tot - stat*stat) );
	      eres = sqrt( pow(tot*espread,2) + pow(stat*estat,2))/fabs(res);
	}

    residual_All->SetPoint(pp,ring1,res);
    if(eres<0.01) residual_All->SetPointError(pp,ex,eres);
    else residual_All->SetPointError(pp,ex,0.01);
  
  }

 /// Final Plot 
 TCanvas *cscale_EEP = new TCanvas("cscale_EEP","cscale_EEP");
 cscale_EEP->SetGridx();
 cscale_EEP->SetGridy();
 scale_vs_iring_EEP->GetHistogram()->GetYaxis()-> SetRangeUser(0.9,1.1);
 scale_vs_iring_EEP->GetHistogram()->GetXaxis()-> SetRangeUser(0,40);
 scale_vs_iring_EEP->GetHistogram()->GetYaxis()-> SetTitle("c_{1}-c_{2}");
 scale_vs_iring_EEP->GetHistogram()->GetXaxis()-> SetTitle("iring");
 scale_vs_iring_EEP->Draw("ap");

 TCanvas *cscale_EEM = new TCanvas("cscale_EEM","cscale_EEM");
 cscale_EEM->SetGridx();
 cscale_EEM->SetGridy();
 scale_vs_iring_EEM->GetHistogram()->GetYaxis()-> SetRangeUser(0.9,1.1);
 scale_vs_iring_EEM->GetHistogram()->GetXaxis()-> SetRangeUser(0,40);
 scale_vs_iring_EEM->GetHistogram()->GetYaxis()-> SetTitle("c_{1}-c_{2}"); 
 scale_vs_iring_EEM->GetHistogram()->GetXaxis()-> SetTitle("iring");
 scale_vs_iring_EEM->Draw("ap");

 TCanvas *cmap2_EEP = new TCanvas("cmap2_EEP","cmap2_EEP",500,500);
 cmap2_EEP->SetGridx();
 cmap2_EEP->SetGridy();
 cmap2_EEP -> cd();
 cmap2_EEP->SetLeftMargin(0.1); 
 cmap2_EEP->SetRightMargin(0.15); 
 h2_EEP->GetXaxis()->SetRangeUser(0.85,1.15);
 h2_EEP->GetYaxis()->SetRangeUser(0.85,1.15);
 h2_EEP->GetXaxis()->SetTitle("C_{1}");
 h2_EEP->GetYaxis()->SetTitle("C_{2}");
 h2_EEP->Draw("colz");
  
 TCanvas *cmap2_EEM = new TCanvas("cmap2_EEM","cmap2_EEM",500,500);
 cmap2_EEM->SetGridx();
 cmap2_EEM->SetGridy();
 cmap2_EEM -> cd();
 cmap2_EEM->SetLeftMargin(0.1); 
 cmap2_EEM->SetRightMargin(0.15); 
 h2_EEM->GetXaxis()->SetRangeUser(0.85,1.15);
 h2_EEM->GetYaxis()->SetRangeUser(0.85,1.15);
 h2_EEM->GetXaxis()->SetTitle("C_{1}");
 h2_EEM->GetYaxis()->SetTitle("C_{2}");
 h2_EEM->Draw("colz");

 TCanvas *cdiff_EEP = new TCanvas("cdiff_EEP","cdiff_EEP",700,500);
 cdiff_EEP->SetGridx();
 cdiff_EEP->SetGridy();
 cdiff_EEP -> cd();
 cdiff_EEP->SetLeftMargin(0.1); 
 cdiff_EEP->SetRightMargin(0.15); 
 h2diff_EEP->GetZaxis()->SetRangeUser(0.5,1.6);
 h2diff_EEP->GetXaxis()->SetTitle("ix");
 h2diff_EEP->GetYaxis()->SetTitle("iy");
 h2diff_EEP->Draw("colz");

 TCanvas *cdiff_EEM = new TCanvas("cdiff_EEM","cdiff_EEM",700,500);
 cdiff_EEM->SetGridx();
 cdiff_EEM->SetGridy();
 cdiff_EEM -> cd();
 cdiff_EEM->SetLeftMargin(0.1); 
 cdiff_EEM->SetRightMargin(0.15); 
 h2diff_EEM->GetZaxis()->SetRangeUser(0.5,1.6);
 h2diff_EEM->GetXaxis()->SetTitle("ix");
 h2diff_EEM->GetYaxis()->SetTitle("iy");
 h2diff_EEM->Draw("colz");

 TCanvas *csigma_EEP = new TCanvas("csigma_EEP","csigma_EEP");
 csigma_EEP->SetGridx();
 csigma_EEP->SetGridy();
 sigma_vs_iring_EEP->GetHistogram()->GetYaxis()-> SetRangeUser(0.00,0.2);
 sigma_vs_iring_EEP->GetHistogram()->GetXaxis()-> SetRangeUser(0,40);
 sigma_vs_iring_EEP->GetHistogram()->GetYaxis()-> SetTitle("#sigma");
 sigma_vs_iring_EEP->GetHistogram()->GetXaxis()-> SetTitle("iring");
 sigma_vs_iring_EEP->Draw("ap");
 gr_stat_prec_EEP->Draw("psame");
    
 TCanvas *csigma_EEM = new TCanvas("csigma_EEM","csigma_EEM");
 csigma_EEM->SetGridx();
 csigma_EEM->SetGridy();
 sigma_vs_iring_EEM->GetHistogram()->GetYaxis()-> SetRangeUser(0.00,0.2);
 sigma_vs_iring_EEM->GetHistogram()->GetXaxis()-> SetRangeUser(0,40);
 sigma_vs_iring_EEM->GetHistogram()->GetYaxis()-> SetTitle("#sigma");
 sigma_vs_iring_EEM->GetHistogram()->GetXaxis()-> SetTitle("iring");
 sigma_vs_iring_EEM->Draw("ap");
 gr_stat_prec_EEM->Draw("psame");
 
 TCanvas *csigma_All= new TCanvas("csigma_All","csigma_Folded");
 csigma_All->SetGridx();
 csigma_All->SetGridy();
 sigma_vs_iring_All->GetHistogram()->GetYaxis()-> SetRangeUser(0.00,0.2);
 sigma_vs_iring_All->GetHistogram()->GetXaxis()-> SetRangeUser(0,40);
 sigma_vs_iring_All->GetHistogram()->GetYaxis()-> SetTitle("#sigma");
 sigma_vs_iring_All->GetHistogram()->GetXaxis()-> SetTitle("iring");
 sigma_vs_iring_All->Draw("ap");
 gr_stat_prec_All->Draw("psame");
 
 TCanvas *cres_EEP = new TCanvas("cres_EEP","cresidual_EEP");
 cres_EEP->SetGridx();
 cres_EEP->SetGridy();
 residual_EEP->GetHistogram()->GetYaxis()-> SetRangeUser(-0.1,0.1);
 residual_EEP->GetHistogram()->GetXaxis()-> SetRangeUser(0,40);
 residual_EEP-> SetTitle("residual EE+");
 residual_EEP-> SetTitle("iring");
 residual_EEP->SetMarkerStyle(20);
 residual_EEP->SetMarkerSize(1);
 residual_EEP->SetMarkerColor(kGreen+2); 
 residual_EEP->Draw("ap");
  
 TCanvas *cres_EEM = new TCanvas("cres_EEM","cresidual_EEM");
 cres_EEM->SetGridx();
 cres_EEM->SetGridy();
 residual_EEM->GetHistogram()->GetYaxis()-> SetRangeUser(-0.1,0.1);
 residual_EEM->GetHistogram()->GetXaxis()-> SetRangeUser(0,40);
 residual_EEM->GetHistogram()->GetYaxis()-> SetTitle("residual EE-");
 residual_EEM->GetHistogram()->GetXaxis()-> SetTitle("iring");
 residual_EEM ->SetMarkerStyle(20);
 residual_EEM->SetMarkerSize(1);
 residual_EEM->SetMarkerColor(kGreen+2); 
 residual_EEM->Draw("ap");

 TCanvas *cres_All = new TCanvas("cres_All","cresidual_Folded");
 cres_All->SetGridx();
 cres_All->SetGridy();
 residual_All->GetHistogram()->GetYaxis()-> SetRangeUser(-0.1,0.1);
 residual_All->GetHistogram()->GetXaxis()-> SetRangeUser(0,40);
 residual_All->GetYaxis()->SetTitle("residual EE Folded");
 residual_All->GetXaxis()->SetTitle("iring");
 residual_All->SetMarkerStyle(20);
 residual_All->SetMarkerSize(1);
 residual_All->SetMarkerColor(kGreen+2); 
 residual_All->Draw("ap");
  
  /// save output result:
  
 TFile* output = new TFile(outputFile.c_str(),"RECREATE");
 output->cd();
 residual_EEM->Write("residual_EEM");
 residual_EEP->Write("residual_EEP");
 residual_All->Write("residual_All");

 output->Close();

 theApp->Run();

 return 0;
  
}
예제 #2
0
int main (int argc, char**argv){

if(argc!=3){
 std::cerr<<" Wrongs input "<<std::endl;
 return -1;
}

std::string inputFile1 = argv[1];
std::string inputFile2 = argv[2];

std::cout<<" InputFile1 = "<<inputFile1<<std::endl;
std::cout<<" InputFile2 = "<<inputFile2<<std::endl;

std::ifstream File1 (inputFile1.c_str());
std::ifstream File2 (inputFile2.c_str());

if(!File1.is_open()){
    std::cerr << "** ERROR: Can't open '" << inputFile1 << "' for input" << std::endl;
    return -1;
}

if(!File2.is_open()){
    std::cerr << "** ERROR: Can't open '" << inputFile2 << "' for input" << std::endl;
    return -1;
}

// Set style options
gROOT->Reset();
gROOT->SetStyle("Plain");

gStyle->SetPadTickX(1);
gStyle->SetPadTickY(1);
gStyle->SetOptTitle(1); 
gStyle->SetOptStat(0); 
gStyle->SetFitFormat("6.3g"); 
gStyle->SetPalette(1); 
gStyle->SetOptTitle(0);
  
gStyle->SetTextFont(42);
gStyle->SetTextSize(0.05);
gStyle->SetTitleFont(42,"xyz");
gStyle->SetTitleSize(0.05);
gStyle->SetLabelFont(42,"xyz");
gStyle->SetLabelSize(0.05);
gStyle->SetTitleXOffset(0.8);
gStyle->SetTitleYOffset(1.1);
gROOT->ForceStyle();



int iPhi, iEta, iz;
double ic, eic;

/// Histo for first ic set
TString Name = Form("mapEB_%s",inputFile1.c_str());
TH2F * map1_EB = new TH2F(Name,Name,360,1, 361, 171, -85, 86);
Name = Form("mapEEp_%s",inputFile1.c_str());
TH2F * map1_EEp = new TH2F(Name,Name,100,1, 101, 100, 1, 101);
Name = Form("mapEEm_%s",inputFile1.c_str());
TH2F * map1_EEm = new TH2F(Name,Name,100,1, 101, 100, 1, 101);

std::cout<<" Opening first file ..... reading "<<std::endl;
while (!File1.eof()){
File1 >> iEta >> iPhi >> iz >> ic >> eic ;
if(iz==0) map1_EB->Fill(iPhi,iEta,ic);
if(iz==1) map1_EEp->Fill(iEta,iPhi,ic);
if(iz==-1)map1_EEm->Fill(iEta,iPhi,ic);
}
std::cout<<" End first file "<<std::endl;
std::cout<<" Opening second file ..... reading "<<std::endl;

/// Histo for first ic set
Name = Form("mapEB_%s",inputFile2.c_str());
TH2F * map2_EB = new TH2F(Name,Name,360,1, 361, 171, -85, 86);
Name = Form("mapEEp_%s",inputFile2.c_str());
TH2F * map2_EEp = new TH2F(Name,Name,100,1, 101, 100, 1, 101);
Name = Form("mapEEm_%s",inputFile2.c_str());
TH2F * map2_EEm = new TH2F(Name,Name,100,1, 101, 100, 1, 101);

while (!File2.eof()){
File2 >> iEta >> iPhi >> iz >> ic >> eic ;
if(iz==0) map2_EB->Fill(iPhi,iEta,ic);
if(iz==1) map2_EEp->Fill(iEta,iPhi,ic);
if(iz==-1) map2_EEm->Fill(iEta,iPhi,ic);
}
std::cout<<" End second file "<<std::endl;

TApplication* theApp = new TApplication("Application",&argc, argv);


/// Set of two ic sets

Name = Form("diffmapEB");
TH2F * diffmap_EB = (TH2F*) map1_EB->Clone("diffmapEB");
diffmap_EB->Reset();

Name = Form("diffmapEEp");
TH2F * diffmap_EEp = (TH2F*) map1_EEp->Clone("diffmapEEp");
diffmap_EEp->Reset();

Name = Form("diffmapEEm");
TH2F * diffmap_EEm = (TH2F*) map1_EEm->Clone("diffmapEEm");
diffmap_EEm->Reset();

Name = Form("ratiomapEB");
TH2F * ratiomap_EB = (TH2F*) map1_EB->Clone("ratiomapEB");
ratiomap_EB->Reset();

Name = Form("ratiomapEEp");
TH2F * ratiomap_EEp = (TH2F*) map1_EEp->Clone("ratiomapEEp");
ratiomap_EEp->Reset();

Name = Form("ratiomapEEm");
TH2F * ratiomap_EEm = (TH2F*) map1_EEm->Clone("ratiomapEEm");
ratiomap_EEm->Reset();

Name = Form("diffHistEB");
TH1F * diffHistEB = new TH1F(Name,Name,100,-0.6,0.6);
diffHistEB->SetLineWidth(2);

Name = Form("diffHistEEp");
TH1F * diffHistEEp = new TH1F(Name,Name,100,-0.6,0.6);
diffHistEEp->SetLineWidth(2);

Name = Form("diffHistEEm");
TH1F * diffHistEEm = new TH1F(Name,Name,100,-0.6,0.6);
diffHistEEm->SetLineWidth(2);

Name = Form("correlationEB");
TH2F * correlationEB = new TH2F(Name,Name,100,0.2,2.,100,0.2,2.);

Name = Form("correlationEEp");
TH2F * correlationEEp= new TH2F(Name,Name,100,0.2,2.,100,0.2,2.);

Name = Form("correlationEEm");
TH2F * correlationEEm= new TH2F(Name,Name,100,0.2,2.,100,0.2,2.);





for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){
 for(int iEta=1; iEta<map1_EB->GetNbinsY()+1; iEta++){

 if(map1_EB->GetBinContent(iPhi,iEta)==-1. || map2_EB->GetBinContent(iPhi,iEta)==-1.){
 diffmap_EB->SetBinContent(iPhi,iEta,-1.);
 ratiomap_EB->SetBinContent(iPhi,iEta,-1.);
 continue;}

 diffmap_EB->SetBinContent(iPhi,iEta,map1_EB->GetBinContent(iPhi,iEta)-map2_EB->GetBinContent(iPhi,iEta));
 diffHistEB->Fill(map1_EB->GetBinContent(iPhi,iEta)-map2_EB->GetBinContent(iPhi,iEta));
 ratiomap_EB->SetBinContent(iPhi,iEta,map1_EB->GetBinContent(iPhi,iEta)/map2_EB->GetBinContent(iPhi,iEta));
 correlationEB->Fill(map1_EB->GetBinContent(iPhi,iEta),map2_EB->GetBinContent(iPhi,iEta));

 }
}

for(int ix =1; ix<map1_EEp->GetNbinsX()+1; ix++){
 for(int iy=1; iy<map1_EEp->GetNbinsY()+1; iy++){

  if(map1_EEp->GetBinContent(ix,iy)==-1. || map2_EEp->GetBinContent(ix,iy)==-1.){
  diffmap_EEp->SetBinContent(ix,iy,-1.);
  ratiomap_EEp->SetBinContent(ix,iy,-1.);
  continue;}

  diffmap_EEp->SetBinContent(ix,iy,map1_EEp->GetBinContent(ix,iy)-map2_EEp->GetBinContent(ix,iy));
  diffHistEEp->Fill(map1_EEp->GetBinContent(ix,iy)-map2_EEp->GetBinContent(ix,iy));
  ratiomap_EEp->SetBinContent(ix,iy,map1_EEp->GetBinContent(ix,iy)/map2_EEp->GetBinContent(ix,iy));
  correlationEEp->Fill(map1_EEp->GetBinContent(ix,iy),map2_EEp->GetBinContent(ix,iy));

 }
}

for(int ix =1; ix<map1_EEm->GetNbinsX()+1; ix++){
 for(int iy=1; iy<map1_EEm->GetNbinsY()+1; iy++){

 if(map1_EEm->GetBinContent(ix,iy)==-1. || map2_EEm->GetBinContent(ix,iy)==-1.){
 diffmap_EEm->SetBinContent(ix,iy,-1.);
 ratiomap_EEm->SetBinContent(ix,iy,-1.);
 continue;}

 diffmap_EEm->SetBinContent(ix,iy,map1_EEm->GetBinContent(ix,iy)-map2_EEm->GetBinContent(ix,iy));
 diffHistEEm->Fill(map1_EEm->GetBinContent(ix,iy)-map2_EEm->GetBinContent(ix,iy));
 ratiomap_EEm->SetBinContent(ix,iy,map1_EEm->GetBinContent(ix,iy)/map2_EEm->GetBinContent(ix,iy));
 correlationEEm->Fill(map1_EEm->GetBinContent(ix,iy),map2_EEm->GetBinContent(ix,iy));

 }
}



/// Profile along phi  for EB:

TGraphErrors *phiProjectionEB1 = new TGraphErrors();
phiProjectionEB1->SetMarkerStyle(20);
phiProjectionEB1->SetMarkerSize(1);
phiProjectionEB1->SetMarkerColor(kBlue);

TGraphErrors *phiProjectionEB2 = new TGraphErrors();
phiProjectionEB2->SetMarkerStyle(20);
phiProjectionEB2->SetMarkerSize(1);
phiProjectionEB2->SetMarkerColor(kRed);


for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){
   double sumEta=0, nEta=0;
  
   for(int iEta =1; iEta<map1_EB->GetNbinsY()+1; iEta++){
    if(map1_EB->GetBinContent(iPhi,iEta)==-1. || map1_EB->GetBinContent(iPhi,iEta)==0.) continue;
    sumEta=sumEta+map1_EB->GetBinContent(iPhi,iEta);
    nEta++;
   }
   phiProjectionEB1->SetPoint(iPhi-1,iPhi-1,sumEta/nEta);
   phiProjectionEB1->SetPointError(iPhi-1,0.,0.002);
  }

for(int iPhi =1; iPhi<map2_EB->GetNbinsX()+1; iPhi++){
   double sumEta=0, nEta=0;
  
   for(int iEta =1; iEta<map2_EB->GetNbinsY()+1; iEta++){
    if(map2_EB->GetBinContent(iPhi,iEta)==-1.||map2_EB->GetBinContent(iPhi,iEta)==0. ) continue;
    sumEta=sumEta+map2_EB->GetBinContent(iPhi,iEta);
    nEta++;
   }
   phiProjectionEB2->SetPoint(iPhi-1,iPhi-1,sumEta/nEta);
   phiProjectionEB2->SetPointError(iPhi-1,0.,0.002);
  }

/// Profile along phi  for EE+:

TEndcapRings *eRings = new TEndcapRings();
std::vector<double> vectSum;
std::vector<double> vectCounter;
 
vectCounter.assign(360,0.);
vectSum.assign(360,0.);


TGraphErrors *phiProjectionEEp1 = new TGraphErrors();
phiProjectionEEp1->SetMarkerStyle(20);
phiProjectionEEp1->SetMarkerSize(1);
phiProjectionEEp1->SetMarkerColor(kBlue);

TGraphErrors *phiProjectionEEp2 = new TGraphErrors();
phiProjectionEEp2->SetMarkerStyle(20);
phiProjectionEEp2->SetMarkerSize(1);
phiProjectionEEp2->SetMarkerColor(kRed);

 for(int ix=1; ix<map1_EEp->GetNbinsX()+1;ix++){
   for(int iy=1; iy<map1_EEp->GetNbinsY()+1;iy++){
    if(map1_EEp->GetBinContent(ix,iy)==-1. || map1_EEp->GetBinContent(ix,iy)==0. ) continue;
      int iPhi = int(eRings->GetEndcapIphi(ix,iy,1));
      vectSum.at(iPhi)=vectSum.at(iPhi)+map1_EEp->GetBinContent(ix,iy);
      vectCounter.at(iPhi)=vectCounter.at(iPhi)+1;
  }
 }

 int j=0;
 for(unsigned int i=0; i<vectCounter.size();i++){
  if(vectCounter.at(i)==0)continue;
  phiProjectionEEp1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i));
  j++;
 }

 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }


 for(int ix=1; ix<map2_EEp->GetNbinsX()+1;ix++){
   for(int iy=1; iy<map2_EEp->GetNbinsY()+1;iy++){
    if(map2_EEp->GetBinContent(ix,iy)==-1. ||map2_EEp->GetBinContent(ix,iy)==0.) continue;
      int iPhi = int(eRings->GetEndcapIphi(ix,iy,1));
       vectSum.at(iPhi)=vectSum.at(iPhi)+map2_EEp->GetBinContent(ix,iy);
      vectCounter.at(iPhi)=vectCounter.at(iPhi)+1;
  }
 }

 j=0;
 for(unsigned int i=0; i<vectCounter.size();i++){
  if(vectCounter.at(i)==0)continue;
  phiProjectionEEp2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i));
  j++;
 }

 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }

/// Profile along phi  for EE-:

TGraphErrors *phiProjectionEEm1 = new TGraphErrors();
phiProjectionEEm1->SetMarkerStyle(20);
phiProjectionEEm1->SetMarkerSize(1);
phiProjectionEEm1->SetMarkerColor(kBlue);

TGraphErrors *phiProjectionEEm2 = new TGraphErrors();
phiProjectionEEm2->SetMarkerStyle(20);
phiProjectionEEm2->SetMarkerSize(1);
phiProjectionEEm2->SetMarkerColor(kRed);

 for(int ix=1; ix<map1_EEm->GetNbinsX()+1;ix++){
   for(int iy=1; iy<map1_EEm->GetNbinsY()+1;iy++){
    if(map1_EEm->GetBinContent(ix,iy)==-1. || map1_EEm->GetBinContent(ix,iy)==0. ) continue;
      int iPhi = int(eRings->GetEndcapIphi(ix,iy,-1));
      vectSum.at(iPhi)=vectSum.at(iPhi)+map1_EEm->GetBinContent(ix,iy);
      vectCounter.at(iPhi)=vectCounter.at(iPhi)+1;
  }
 }

 j=0;
 for(unsigned int i=0; i<vectCounter.size();i++){
  if(vectCounter.at(i)==0)continue;
  phiProjectionEEm1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i));
  j++;
 }
 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }

 for(int ix=1; ix<map2_EEm->GetNbinsX()+1;ix++){
   for(int iy=1; iy<map2_EEm->GetNbinsY()+1;iy++){
    if(map2_EEm->GetBinContent(ix,iy)==-1. ||  map2_EEm->GetBinContent(ix,iy)==0.) continue;
      int iPhi = int(eRings->GetEndcapIphi(ix,iy,-1));
      vectSum.at(iPhi)=vectSum.at(iPhi)+map2_EEm->GetBinContent(ix,iy);
      vectCounter.at(iPhi)=vectCounter.at(iPhi)+1;
  }
 }

 j=0;
 for(unsigned int i=0; i<vectCounter.size();i++){
  if(vectCounter.at(i)==0)continue;
  phiProjectionEEm2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i));
  j++;
}

 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }


/// projection along eta for EB

TGraphErrors *etaProjectionEB1 = new TGraphErrors();
etaProjectionEB1->SetMarkerStyle(20);
etaProjectionEB1->SetMarkerSize(1);
etaProjectionEB1->SetMarkerColor(kBlue);

TGraphErrors *etaProjectionEB2 = new TGraphErrors();
etaProjectionEB2->SetMarkerStyle(20);
etaProjectionEB2->SetMarkerSize(1);
etaProjectionEB2->SetMarkerColor(kRed);


for(int iEta =1; iEta<map1_EB->GetNbinsY()+1; iEta++){
   double sumPhi=0, nPhi=0;
  
   for(int iPhi =1; iPhi<map1_EB->GetNbinsX()+1; iPhi++){
    if(map1_EB->GetBinContent(iPhi,iEta)==-1.) continue;
    sumPhi=sumPhi+map1_EB->GetBinContent(iPhi,iEta);
    nPhi++;
   }
   etaProjectionEB1->SetPoint(iEta-1,iEta-1,sumPhi/nPhi);
   etaProjectionEB1->SetPointError(iEta-1,0.,0.002);
  }

for(int iEta =1; iEta<map2_EB->GetNbinsY()+1; iEta++){
   double sumPhi=0, nPhi=0;
  
   for(int iPhi =1; iPhi<map2_EB->GetNbinsX()+1; iPhi++){
    if(map2_EB->GetBinContent(iPhi,iEta)==-1.) continue;
    sumPhi=sumPhi+map2_EB->GetBinContent(iPhi,iEta);
    nPhi++;
   }
   etaProjectionEB2->SetPoint(iEta-1,iEta-1,sumPhi/nPhi);
   etaProjectionEB2->SetPointError(iEta-1,0.,0.002);
  }

 
/// projection along eta for EE+:

TGraphErrors *etaProjectionEEp1 = new TGraphErrors();
etaProjectionEEp1->SetMarkerStyle(20);
etaProjectionEEp1->SetMarkerSize(1);
etaProjectionEEp1->SetMarkerColor(kBlue);

TGraphErrors *etaProjectionEEp2 = new TGraphErrors();
etaProjectionEEp2->SetMarkerStyle(20);
etaProjectionEEp2->SetMarkerSize(1);
etaProjectionEEp2->SetMarkerColor(kRed);

vectCounter.clear();
vectSum.clear();
vectCounter.assign(360,0.);
vectSum.assign(360,0.);

 for(int ix=1; ix<map1_EEp->GetNbinsX()+1;ix++){
   for(int iy=1; iy<map1_EEp->GetNbinsY()+1;iy++){
    if(map1_EEp->GetBinContent(ix,iy)==-1. || map1_EEp->GetBinContent(ix,iy)==0.) continue;
      int iEta = int(eRings->GetEndcapIeta(ix,iy,1));
      if(iEta<0 || iEta>360)continue;
      vectSum.at(iEta)=vectSum.at(iEta)+map1_EEp->GetBinContent(ix,iy);
      vectCounter.at(iEta)=vectCounter.at(iEta)+1;
  }
 }
 j=0;
 for(unsigned int i=0; i<vectCounter.size();i++){
  if(vectCounter.at(i)==0) continue;
  etaProjectionEEp1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i));
  j++;
 }

 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }

 for(int ix=1; ix<map2_EEp->GetNbinsX()+1;ix++){
   for(int iy=1; iy<map2_EEp->GetNbinsY()+1;iy++){
    if(map2_EEp->GetBinContent(ix,iy)==-1. || map2_EEp->GetBinContent(ix,iy)==0. ) continue;
      int iEta = int(eRings->GetEndcapIeta(ix,iy,1));
      if(iEta<0 || iEta>360)continue;
      vectSum.at(iEta)=vectSum.at(iEta)+map2_EEp->GetBinContent(ix,iy);
      vectCounter.at(iEta)=vectCounter.at(iEta)+1;
  }
 }

 j=0;
 for(unsigned int i=0; i<vectCounter.size();i++){
  if(vectCounter.at(i)==0) continue;
  etaProjectionEEp2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i));
  j++;
 }

 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }

/// projection along eta for EE-:

TGraphErrors *etaProjectionEEm1 = new TGraphErrors();
etaProjectionEEm1->SetMarkerStyle(20);
etaProjectionEEm1->SetMarkerSize(1);
etaProjectionEEm1->SetMarkerColor(kBlue);

TGraphErrors *etaProjectionEEm2 = new TGraphErrors();
etaProjectionEEm2->SetMarkerStyle(20);
etaProjectionEEm2->SetMarkerSize(1);
etaProjectionEEm2->SetMarkerColor(kRed);

 for(int ix=1; ix<map1_EEm->GetNbinsX()+1;ix++){
   for(int iy=1; iy<map1_EEm->GetNbinsY()+1;iy++){
    if(map1_EEm->GetBinContent(ix,iy)==-1.||map1_EEm->GetBinContent(ix,iy)==0.) continue;
      int iEta = int(eRings->GetEndcapIeta(ix,iy,1));
      if(iEta<0 || iEta>360)continue;
      vectSum.at(iEta)=vectSum.at(iEta)+map1_EEm->GetBinContent(ix,iy);
      vectCounter.at(iEta)=vectCounter.at(iEta)+1;
   }
 }

 j=0;
 for(unsigned int i=0; i<vectCounter.size();i++){
  if(vectCounter.at(i)==0)continue;
  etaProjectionEEm1->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i));
  j++;
 }

 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }

 for(int ix=1; ix<map2_EEm->GetNbinsX()+1;ix++){
   for(int iy=1; iy<map2_EEm->GetNbinsY()+1;iy++){
    if(map2_EEm->GetBinContent(ix,iy)==-1. || map2_EEm->GetBinContent(ix,iy)==0.) continue;
      int iEta = int(eRings->GetEndcapIeta(ix,iy,1));
      if(iEta<0 || iEta>171)continue;
      vectSum.at(iEta)=vectSum.at(iEta)+map2_EEm->GetBinContent(ix,iy);
      vectCounter.at(iEta)=vectCounter.at(iEta)+1;
  }
 }

 j=0;
 for(unsigned int i=0; i<vectCounter.size();i++){
  if(vectCounter.at(i)==0)continue; 
  etaProjectionEEm2->SetPoint(j,i,vectSum.at(i)/vectCounter.at(i));
  j++;
 }

 for(unsigned int i=0; i<vectSum.size(); i++){
  vectSum.at(i)=0; vectCounter.at(i)=0;
 }


 ///  phi Profile Histos EB

 cout<<" Phi Profile Histos "<<endl;

 TH1F* phiProfileEB1 = new TH1F ("phiProfileEB1","phiProfileEB1",60,0.7,1.3);
 TH1F* phiProfileEB2 = new TH1F ("phiProfileEB2","phiProfileEB2",60,0.7,1.3);
 
 for(int i=0; i<phiProjectionEB1->GetN() ; i++){
      double x=0,y=0;
      phiProjectionEB1->GetPoint(i,x,y);
      phiProfileEB1->Fill(y);
  }
 
for(int i=0; i<phiProjectionEB2->GetN() ; i++){
      double x=0,y=0;
      phiProjectionEB2->GetPoint(i,x,y);
      phiProfileEB2->Fill(y);
  }
 
TF1 *fgaus = new TF1("fgaus","gaus",-10,10);
 
fgaus->SetParameter(1,1);
fgaus->SetParameter(2,phiProfileEB1->GetRMS());
fgaus->SetRange(1-5*phiProfileEB1->GetRMS(),1+5*phiProfileEB1->GetRMS());
fgaus->SetLineColor(kBlue);
phiProfileEB1->Fit("fgaus","QRME");
cout<<" First Set :  Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" First Set : Mean dist = "<<phiProfileEB1->GetMean()<<" RMS dist "<<phiProfileEB1->GetRMS()<<endl;

fgaus->SetParameter(1,1);
fgaus->SetParameter(2,phiProfileEB2->GetRMS());
fgaus->SetRange(1-5*phiProfileEB2->GetRMS(),1+5*phiProfileEB2->GetRMS());
fgaus->SetLineColor(kRed);
phiProfileEB2->Fit("fgaus","QRME");
cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" Second Set : Mean dist = "<<phiProfileEB2->GetMean()<<" RMS dist "<<phiProfileEB2->GetRMS()<<endl;

 /// phi Profile Histos EE+

 TH1F* phiProfileEEp1 = new TH1F ("phiProfileEEp1","phiProfileEEp1",60,0.6,1.6);
 TH1F* phiProfileEEp2 = new TH1F ("phiProfileEEp2","phiProfileEEp2",60,0.6,1.6);
 
 for(int i=0; i<phiProjectionEEp1->GetN() ; i++){
      double x=0,y=0;
      phiProjectionEEp1->GetPoint(i,x,y);
      phiProfileEEp1->Fill(y);
  }
 
for(int i=0; i<phiProjectionEEp2->GetN() ; i++){
      double x=0,y=0;
      phiProjectionEEp2->GetPoint(i,x,y);
      phiProfileEEp2->Fill(y);
  }
  
fgaus->SetParameter(1,1);
fgaus->SetParameter(2,phiProfileEEp1->GetRMS());
fgaus->SetRange(1-5*phiProfileEEp1->GetRMS(),1+5*phiProfileEEp1->GetRMS());
fgaus->SetLineColor(kBlue);
phiProfileEEp1->Fit("fgaus","QRME");
cout<<" First Set :  Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" First Set : Mean dist = "<<phiProfileEEp1->GetMean()<<" RMS dist "<<phiProfileEEp1->GetRMS()<<endl;

fgaus->SetParameter(1,1);
fgaus->SetParameter(2,phiProfileEEp2->GetRMS());
fgaus->SetRange(1-5*phiProfileEEp2->GetRMS(),1+5*phiProfileEEp2->GetRMS());
fgaus->SetLineColor(kRed);
phiProfileEEp2->Fit("fgaus","QRME");
cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" Second Set : Mean dist = "<<phiProfileEEp2->GetMean()<<" RMS dist "<<phiProfileEEp2->GetRMS()<<endl;

 /// phi Profile Histos EE-

 TH1F* phiProfileEEm1 = new TH1F ("phiProfileEEm1","phiProfileEEm1",60,0.6,1.6);
 TH1F* phiProfileEEm2 = new TH1F ("phiProfileEEm2","phiProfileEEm2",60,0.6,1.6);
 
 for(int i=0; i<phiProjectionEEm1->GetN() ; i++){
      double x=0,y=0;
      phiProjectionEEm1->GetPoint(i,x,y);
      phiProfileEEm1->Fill(y);
  }
 
for(int i=0; i<phiProjectionEEm2->GetN() ; i++){
      double x=0,y=0;
      phiProjectionEEm2->GetPoint(i,x,y);
      phiProfileEEm2->Fill(y);
  }
  
fgaus->SetParameter(1,1);
fgaus->SetParameter(2,phiProfileEEm1->GetRMS());
fgaus->SetRange(1-5*phiProfileEEm1->GetRMS(),1+5*phiProfileEEm1->GetRMS());
fgaus->SetLineColor(kBlue);
phiProfileEEm1->Fit("fgaus","QRME");
cout<<" First Set :  Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" First Set : Mean dist = "<<phiProfileEEm1->GetMean()<<" RMS dist "<<phiProfileEEm1->GetRMS()<<endl;

fgaus->SetParameter(1,1);
fgaus->SetParameter(2,phiProfileEEm2->GetRMS());
fgaus->SetRange(1-5*phiProfileEEm2->GetRMS(),1+5*phiProfileEEm2->GetRMS());
fgaus->SetLineColor(kRed);
phiProfileEEm2->Fit("fgaus","QRME");
cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" Second Set : Mean dist = "<<phiProfileEEm2->GetMean()<<" RMS dist "<<phiProfileEEm2->GetRMS()<<endl;

 /// eta Profile Histos EB

 cout<<" Eta Profile Histos "<<endl;

 TH1F* etaProfileEB1 = new TH1F ("etaProfileEB1","etaProfileEB1",60,0.85,1.15);
 TH1F* etaProfileEB2 = new TH1F ("etaProfileEB2","etaProfileEB2",60,0.85,1.15);
 
 for(int i=0; i<etaProjectionEB1->GetN() ; i++){
      double x=0,y=0;
      etaProjectionEB1->GetPoint(i,x,y);
      etaProfileEB1->Fill(y);
  }
 
for(int i=0; i<etaProjectionEB2->GetN() ; i++){
      double x=0,y=0;
      etaProjectionEB2->GetPoint(i,x,y);
      etaProfileEB2->Fill(y);
  }
  
fgaus->SetParameter(1,1);
fgaus->SetParameter(2,etaProfileEB1->GetRMS());
fgaus->SetRange(1-5*etaProfileEB1->GetRMS(),1+5*etaProfileEB1->GetRMS());
fgaus->SetLineColor(kBlue);
etaProfileEB1->Fit("fgaus","QRME");
cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" First Set : Mean dist = "<<etaProfileEB1->GetMean()<<" RMS dist "<<etaProfileEB1->GetRMS()<<endl;

fgaus->SetParameter(1,1);
fgaus->SetParameter(2,etaProfileEB2->GetRMS());
fgaus->SetRange(1-5*etaProfileEB2->GetRMS(),1+5*etaProfileEB2->GetRMS());
fgaus->SetLineColor(kRed);
etaProfileEB2->Fit("fgaus","QRME");
cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" Second Set : Mean dist = "<<etaProfileEB2->GetMean()<<" RMS dist "<<etaProfileEB2->GetRMS()<<endl;

 /// eta Profile Histos EE+

 TH1F* etaProfileEEp1 = new TH1F ("etaProfileEEp1","etaProfileEEp1",35,0.,2.5);
 TH1F* etaProfileEEp2 = new TH1F ("etaProfileEEp2","etaProfileEEp2",35,0.,2.5);
 
 for(int i=0; i<etaProjectionEEp1->GetN() ; i++){
      double x=0,y=0;
      etaProjectionEEp1->GetPoint(i,x,y);
      etaProfileEEp1->Fill(y);
  }
 
for(int i=0; i<etaProjectionEEp2->GetN() ; i++){
      double x=0,y=0;
      etaProjectionEEp2->GetPoint(i,x,y);
      etaProfileEEp2->Fill(y);
  }
  
fgaus->SetParameter(1,1);
fgaus->SetParameter(2,etaProfileEEp1->GetRMS());
fgaus->SetRange(1-5*etaProfileEEp1->GetRMS(),1+5*etaProfileEEp1->GetRMS());
fgaus->SetLineColor(kBlue);
etaProfileEEp1->Fit("fgaus","QRME");
cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" First Set : Mean dist = "<<etaProfileEEp1->GetMean()<<" RMS dist "<<etaProfileEEp1->GetRMS()<<endl;

fgaus->SetParameter(1,1);
fgaus->SetParameter(2,etaProfileEEp2->GetRMS());
fgaus->SetRange(1-5*etaProfileEEp2->GetRMS(),1+5*etaProfileEEp2->GetRMS());
fgaus->SetLineColor(kRed);
etaProfileEEp2->Fit("fgaus","QRME");
cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" Second Set : Mean dist = "<<etaProfileEEp2->GetMean()<<" RMS dist "<<etaProfileEEp2->GetRMS()<<endl;


 /// eta Profile Histos EB

 TH1F* etaProfileEEm1 = new TH1F ("etaProfileEEm1","etaProfileEEm1",35,0.,2.5);
 TH1F* etaProfileEEm2 = new TH1F ("etaProfileEEm2","etaProfileEEm2",35,0.,2.5);
 
 for(int i=0; i<etaProjectionEEm1->GetN() ; i++){
      double x=0,y=0;
      etaProjectionEEm1->GetPoint(i,x,y);
      etaProfileEEm1->Fill(y);
  }
 
for(int i=0; i<etaProjectionEEm2->GetN() ; i++){
      double x=0,y=0;
      etaProjectionEEm2->GetPoint(i,x,y);
      etaProfileEEm2->Fill(y);
  }
  
fgaus->SetParameter(1,1);
fgaus->SetParameter(2,etaProfileEEm1->GetRMS());
fgaus->SetRange(1-5*etaProfileEEm1->GetRMS(),1+5*etaProfileEEm1->GetRMS());
fgaus->SetLineColor(kBlue);
etaProfileEEm1->Fit("fgaus","QRME");
cout<<" First Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" First Set : Mean dist = "<<etaProfileEEm1->GetMean()<<" RMS dist "<<etaProfileEEm1->GetRMS()<<endl;

fgaus->SetParameter(1,1);
fgaus->SetParameter(2,etaProfileEEm2->GetRMS());
fgaus->SetRange(1-5*etaProfileEEm2->GetRMS(),1+5*etaProfileEEm2->GetRMS());
fgaus->SetLineColor(kRed);
etaProfileEEm2->Fit("fgaus","QRME");
cout<<" Second Set : Mean Fit = "<<fgaus->GetParameter(1)<<" RMS Fit = "<<fgaus->GetParameter(2)<<" chi2/ndf = "<<fgaus->GetChisquare()/fgaus->GetNDF()<<endl;
cout<<" Second Set : Mean dist = "<<etaProfileEEm2->GetMean()<<" RMS dist "<<etaProfileEEm2->GetRMS()<<endl;


  
 


 ///------------------------------------------------------------------------
 ///-----------------------------------------------------------------
 ///--- Draw plots
 ///-----------------------------------------------------------------
 
 TCanvas *c[30];

 c[0] = new TCanvas("hdiffEB","hdiffEB");
 c[0]->SetLeftMargin(0.1); 
 c[0]->SetRightMargin(0.13); 
 c[0]->SetGridx();
  
 diffmap_EB->GetXaxis()->SetNdivisions(1020);
 diffmap_EB->GetXaxis() -> SetLabelSize(0.03);
 diffmap_EB->GetXaxis() ->SetTitle("i#phi");
 diffmap_EB->GetYaxis() ->SetTitle("i#eta");
 diffmap_EB->GetZaxis() ->SetRangeUser(-0.1,0.1);
 diffmap_EB->Draw("COLZ");

 c[1] = new TCanvas("histdiffEB","histdiffEB");
 c[1]->SetLeftMargin(0.1); 
 c[1]->SetRightMargin(0.13); 
 c[1]->SetLogy();

 diffHistEB->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); 
 diffHistEB->Draw();

 
 c[2] = new TCanvas("hratioEB","hratioEB");
 c[2]->SetLeftMargin(0.1); 
 c[2]->SetRightMargin(0.13); 
 c[2]->SetGridx();
  
 ratiomap_EB->GetXaxis()->SetNdivisions(1020);
 ratiomap_EB->GetXaxis() -> SetLabelSize(0.03);
 ratiomap_EB->GetXaxis() ->SetTitle("i#phi");
 ratiomap_EB->GetYaxis() ->SetTitle("i#eta");
 ratiomap_EB->GetZaxis() ->SetRangeUser(0.95,1.05);
 ratiomap_EB->Draw("COLZ");

 c[3] = new TCanvas("correlationEB","correlationEB");
 c[3]->SetLeftMargin(0.1); 
 c[3]->SetRightMargin(0.13); 
 c[3]->SetGridx();
 c[3]->SetGridy();

 correlationEB->GetXaxis()->SetNdivisions(1020);
 correlationEB->GetXaxis() -> SetLabelSize(0.03);
 correlationEB->GetXaxis() ->SetTitle("c_{#pi}");
 correlationEB->GetYaxis() ->SetTitle("c_{ele}");
 correlationEB->Draw("COLZ");

 
 c[4] = new TCanvas("hdiffEEp","hdiffEEp");
 c[4]->SetLeftMargin(0.1); 
 c[4]->SetRightMargin(0.13); 
 c[4]->SetGridx();
  
 diffmap_EEp->GetXaxis()->SetNdivisions(1020);
 diffmap_EEp->GetXaxis() -> SetLabelSize(0.03);
 diffmap_EEp->GetXaxis() ->SetTitle("ix");
 diffmap_EEp->GetYaxis() ->SetTitle("iy");
 diffmap_EEp->GetZaxis() ->SetRangeUser(-0.15,0.15);
 diffmap_EEp->Draw("COLZ");

 c[5] = new TCanvas("histdiffEEp","histdiffEEp");
 c[5]->SetLeftMargin(0.1); 
 c[5]->SetRightMargin(0.13); 
 c[5]->SetLogy();

 diffHistEEp->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); 
 diffHistEEp->Draw();
 
 c[6] = new TCanvas("hratioEEp","hratioEEp");
 c[6]->SetLeftMargin(0.1); 
 c[6]->SetRightMargin(0.13); 
 c[6]->SetGridx();
  
 ratiomap_EEp->GetXaxis()->SetNdivisions(1020);
 ratiomap_EEp->GetXaxis() -> SetLabelSize(0.03);
 ratiomap_EEp->GetXaxis() ->SetTitle("ix");
 ratiomap_EEp->GetYaxis() ->SetTitle("iy");
 ratiomap_EEp->GetZaxis() ->SetRangeUser(0.9,1.1);
 ratiomap_EEp->Draw("COLZ");

 c[7] = new TCanvas("correlationEEp","correlationEEp");
 c[7]->SetLeftMargin(0.1); 
 c[7]->SetRightMargin(0.13); 
 c[7]->SetGridx();
 c[7]->SetGridy();
  
 correlationEEp->GetXaxis()->SetNdivisions(1020);
 correlationEEp->GetXaxis() -> SetLabelSize(0.03);
 correlationEEp->GetXaxis() ->SetTitle("c_{#pi}");
 correlationEEp->GetYaxis() ->SetTitle("c_{ele}");
 correlationEEp->Draw("COLZ");

 c[8] = new TCanvas("hdiffEEm","hdiffEEm");
 c[8]->SetLeftMargin(0.1); 
 c[8]->SetRightMargin(0.13); 
 c[8]->SetGridx();
  
 diffmap_EEm->GetXaxis()->SetNdivisions(1020);
 diffmap_EEm->GetXaxis() -> SetLabelSize(0.03);
 diffmap_EEm->GetXaxis() ->SetTitle("ix");
 diffmap_EEm->GetYaxis() ->SetTitle("iy");
 diffmap_EEm->GetZaxis() ->SetRangeUser(-0.15,0.15);
 diffmap_EEm->Draw("COLZ");

 c[9] = new TCanvas("histdiffEEm","histdiffEEm");
 c[9]->SetLeftMargin(0.1); 
 c[9]->SetRightMargin(0.13); 
 c[9]->SetLogy();

 diffHistEEm->GetXaxis()->SetTitle("c_{#pi}-c_{ele}"); 
 diffHistEEm->Draw();
 


 c[10] = new TCanvas("hratioEEm","hratioEEm");
 c[10]->SetLeftMargin(0.1); 
 c[10]->SetRightMargin(0.13); 
 c[10]->SetGridx();
  
 ratiomap_EEm->GetXaxis()->SetNdivisions(1020);
 ratiomap_EEm->GetXaxis() -> SetLabelSize(0.03);
 ratiomap_EEm->GetXaxis() ->SetTitle("ix");
 ratiomap_EEm->GetYaxis() ->SetTitle("iy");
 ratiomap_EEm->GetZaxis() ->SetRangeUser(0.9,1.1);
 ratiomap_EEm->Draw("COLZ");
 
 c[11] = new TCanvas("correlationEEm","correlationEEm");
 c[11]->SetLeftMargin(0.1); 
 c[11]->SetRightMargin(0.13); 
 c[11]->SetGridx();
 c[11]->SetGridy();
  
 correlationEEm->GetXaxis()->SetNdivisions(1020);
 correlationEEm->GetXaxis() -> SetLabelSize(0.03);
 correlationEEm->GetXaxis() ->SetTitle("c_{#pi}");
 correlationEEm->GetYaxis() ->SetTitle("c_{ele}");
 correlationEEm->Draw("COLZ");


 c[12] = new TCanvas("phiProjectionEB","phiProjectionEB");
 c[12]->SetGridx();
 c[12]->SetGridy();
 phiProjectionEB1->GetHistogram()->GetYaxis()-> SetRangeUser(0.85,1.1);
 phiProjectionEB1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361);
 phiProjectionEB1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC");
 phiProjectionEB1->GetHistogram()->GetXaxis()-> SetTitle("i#phi");
 phiProjectionEB1->Draw("apl");
 phiProjectionEB2->Draw("plsame");
 
 TLegend * leg1 = new TLegend(0.75,0.75,0.89, 0.89);
 leg1->AddEntry(phiProjectionEB1,"IC set 1","LP");
 leg1->AddEntry(phiProjectionEB2,"IC set 2","LP");
 leg1->SetFillColor(0);
 leg1->Draw("same");

 c[13] = new TCanvas("phiProjectionEEp","phiProjectionEEp");
 c[13]->SetGridx();
 c[13]->SetGridy();
 phiProjectionEEp1->GetHistogram()->GetYaxis()-> SetRangeUser(0.7,1.4);
 phiProjectionEEp1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361);
 phiProjectionEEp1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC");
 phiProjectionEEp1->GetHistogram()->GetXaxis()-> SetTitle("i#phi");
 phiProjectionEEp1->Draw("apl");
 phiProjectionEEp2->Draw("plsame");
 
 TLegend * leg2 = new TLegend(0.75,0.75,0.89, 0.89);
 leg2->AddEntry(phiProjectionEEp1,"IC set 1","LP");
 leg2->AddEntry(phiProjectionEEp2,"IC set 2","LP");
 leg2->SetFillColor(0);
 leg2->Draw("same");


 c[14] = new TCanvas("phiProjectionEEm","phiProjectionEEm");
 c[14]->SetGridx();
 c[14]->SetGridy();
 phiProjectionEEm1->GetHistogram()->GetYaxis()-> SetRangeUser(0.7,1.4);
 phiProjectionEEm1->GetHistogram()->GetXaxis()-> SetRangeUser(1,361);
 phiProjectionEEm1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC");
 phiProjectionEEm1->GetHistogram()->GetXaxis()-> SetTitle("i#phi");
 phiProjectionEEm1->Draw("apl");
 phiProjectionEEm2->Draw("plsame");
 
 TLegend * leg3 = new TLegend(0.75,0.75,0.89, 0.89);
 leg3->AddEntry(phiProjectionEEm1,"IC set 1","LP");
 leg3->AddEntry(phiProjectionEEm2,"IC set 2","LP");
 leg3->SetFillColor(0);
 leg3->Draw("same");

 c[15] = new TCanvas("etaProjectionEB","etaProjectionEB");
 c[15]->SetGridx();
 c[15]->SetGridy();
 etaProjectionEB1->GetHistogram()->GetYaxis()-> SetRangeUser(0.9,1.1);
 etaProjectionEB1->GetHistogram()->GetXaxis()-> SetRangeUser(0,171);
 etaProjectionEB1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC");
 etaProjectionEB1->GetHistogram()->GetXaxis()-> SetTitle("i#eta");
 etaProjectionEB1->Draw("apl");
 etaProjectionEB2->Draw("plsame");
 
 TLegend * leg4 = new TLegend(0.75,0.75,0.89, 0.89);
 leg4->AddEntry(etaProjectionEB1,"IC set 1","LP");
 leg4->AddEntry(etaProjectionEB2,"IC set 2","LP");
 leg4->SetFillColor(0);
 leg1->Draw("same");

 c[16] = new TCanvas("etaProjectionEEp","etaProjectionEEp");
 c[16]->SetGridx();
 c[16]->SetGridy();
 etaProjectionEEp1->GetHistogram()->GetYaxis()-> SetRangeUser(0.55,1.5);
 etaProjectionEEp1->GetHistogram()->GetXaxis()-> SetRangeUser(85,125);
 etaProjectionEEp1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC");
 etaProjectionEEp1->GetHistogram()->GetXaxis()-> SetTitle("i#eta");
 etaProjectionEEp1->Draw("apl");
 etaProjectionEEp2->Draw("plsame");
 
 TLegend * leg5 = new TLegend(0.75,0.75,0.89, 0.89);
 leg5->AddEntry(etaProjectionEEp1,"IC set 1","LP");
 leg5->AddEntry(etaProjectionEEp2,"IC set 2","LP");
 leg5->SetFillColor(0);
 leg5->Draw("same");


 c[17] = new TCanvas("etaProjectionEEm","etaProjectionEEm");
 c[17]->SetGridx();
 c[17]->SetGridy();
 etaProjectionEEm1->GetHistogram()->GetYaxis()-> SetRangeUser(0.55,1.5);
 etaProjectionEEm1->GetHistogram()->GetXaxis()-> SetRangeUser(85,125);
 etaProjectionEEm1->GetHistogram()->GetYaxis()-> SetTitle("Mean IC");
 etaProjectionEEm1->GetHistogram()->GetXaxis()-> SetTitle("i#eta");
 etaProjectionEEm1->Draw("apl");
 etaProjectionEEm2->Draw("plsame");
 
 TLegend * leg6 = new TLegend(0.75,0.75,0.89, 0.89);
 leg6->AddEntry(etaProjectionEEm1,"IC set 1","LP");
 leg6->AddEntry(etaProjectionEEm2,"IC set 2","LP");
 leg6->SetFillColor(0);
 leg6->Draw("same");

 c[18] = new TCanvas("phiProfileEB","phiProfileEB");
 c[18]->SetGridx();
 c[18]->SetGridy();
 phiProfileEB1->GetXaxis()->SetTitle("#bar{IC}");
 phiProfileEB1->SetLineColor(kBlue);
 phiProfileEB1->SetMarkerSize(0.8);
 phiProfileEB1->SetLineWidth(2);
 phiProfileEB2->SetLineColor(kRed);
 phiProfileEB2->SetMarkerSize(0.8);
 phiProfileEB2->SetLineWidth(2);
 phiProfileEB1->Draw();
 phiProfileEB2->Draw("same");
  
 TLegend * leg7 = new TLegend(0.6,0.7,0.89, 0.89);
 leg7->SetFillColor(0);
 leg7->AddEntry(phiProfileEB1,"EB Projection I set ", "LP");
 leg7->AddEntry(phiProfileEB2,"EB Projection II set ", "LP");
 leg7->Draw("same");

 c[19] = new TCanvas("phiProfileEEp","phiProfileEEp");
 c[19]->SetGridx();
 c[19]->SetGridy();
 phiProfileEEp1->GetXaxis()->SetTitle("#bar{IC}");
 phiProfileEEp1->SetLineColor(kBlue);
 phiProfileEEp1->SetMarkerSize(0.8);
 phiProfileEEp1->SetLineWidth(2);
 phiProfileEEp2->SetLineColor(kRed);
 phiProfileEEp2->SetMarkerSize(0.8);
 phiProfileEEp2->SetLineWidth(2);
 phiProfileEEp1->Draw();
 phiProfileEEp2->Draw("same");
  
 TLegend * leg8 = new TLegend(0.6,0.7,0.89, 0.89);
 leg8->SetFillColor(0);
 leg8->AddEntry(phiProfileEEp1,"EE+ Projection I set ", "LP");
 leg8->AddEntry(phiProfileEEp2,"EE+ Projection II set ", "LP");
 leg8->Draw("same");

 c[20] = new TCanvas("phiProfileEEm","phiProfileEEm");
 c[20]->SetGridx();
 c[20]->SetGridy();
 phiProfileEEm1->GetXaxis()->SetTitle("#bar{IC}");
 phiProfileEEm1->SetLineColor(kBlue);
 phiProfileEEm1->SetMarkerSize(0.8);
 phiProfileEEm1->SetLineWidth(2);
 phiProfileEEm2->SetLineColor(kRed);
 phiProfileEEm2->SetMarkerSize(0.8);
 phiProfileEEm2->SetLineWidth(2);
 phiProfileEEm1->Draw();
 phiProfileEEm2->Draw("same");
  
 TLegend * leg9 = new TLegend(0.6,0.7,0.89, 0.89);
 leg9->SetFillColor(0);
 leg9->AddEntry(phiProfileEEm1,"EE- Projection I set ", "LP");
 leg9->AddEntry(phiProfileEEm2,"EE- Projection II set ", "LP");
 leg9->Draw("same");

 c[21] = new TCanvas("etaProfileEB","etaProfileEB");
 c[21]->SetGridx();
 c[21]->SetGridy();
 etaProfileEB1->GetXaxis()->SetTitle("#bar{IC}");
 etaProfileEB1->SetLineColor(kBlue);
 etaProfileEB1->SetMarkerSize(0.8);
 etaProfileEB1->SetLineWidth(2);
 etaProfileEB2->SetLineColor(kRed);
 etaProfileEB2->SetMarkerSize(0.8);
 etaProfileEB2->SetLineWidth(2);
 etaProfileEB1->Draw();
 etaProfileEB2->Draw("same");
  
 TLegend * leg10 = new TLegend(0.6,0.7,0.89, 0.89);
 leg10->SetFillColor(0);
 leg10->AddEntry(etaProfileEB1,"EB Projection I set ", "LP");
 leg10->AddEntry(etaProfileEB2,"EB Projection II set ", "LP");
 leg10->Draw("same");

 c[22] = new TCanvas("etaProfileEEp","etaProfileEEp");
 c[22]->SetGridx();
 c[22]->SetGridy();
 etaProfileEEp1->GetXaxis()->SetTitle("#bar{IC}");
 etaProfileEEp1->SetLineColor(kBlue);
 etaProfileEEp1->SetMarkerSize(0.8);
 etaProfileEEp1->SetLineWidth(2);
 etaProfileEEp2->SetLineColor(kRed);
 etaProfileEEp2->SetMarkerSize(0.8);
 etaProfileEEp2->SetLineWidth(2);
 etaProfileEEp1->Draw();
 etaProfileEEp2->Draw("same");
  
 TLegend * leg11 = new TLegend(0.6,0.7,0.89, 0.89);
 leg11->SetFillColor(0);
 leg11->AddEntry(phiProfileEEp1,"EE+ Projection I set ", "LP");
 leg11->AddEntry(phiProfileEEp2,"EE+ Projection II set ", "LP");
 leg11->Draw("same");

 c[23] = new TCanvas("etaProfileEEm","etaProfileEEm");
 c[23]->SetGridx();
 c[23]->SetGridy();
 etaProfileEEm1->GetXaxis()->SetTitle("#bar{IC}");
 etaProfileEEm1->SetLineColor(kBlue);
 etaProfileEEm1->SetMarkerSize(0.8);
 etaProfileEEm1->SetLineWidth(2);
 etaProfileEEm2->SetLineColor(kRed);
 etaProfileEEm2->SetMarkerSize(0.8);
 etaProfileEEm2->SetLineWidth(2);
 etaProfileEEm1->Draw();
 etaProfileEEm2->Draw("same");
  
 TLegend * leg12 = new TLegend(0.6,0.7,0.89, 0.89);
 leg12->SetFillColor(0);
 leg12->AddEntry(phiProfileEEm1,"EE- Projection I set ", "LP");
 leg12->AddEntry(phiProfileEEm2,"EE- Projection II set ", "LP");
 leg12->Draw("same");

theApp->Run();

return 0;

}