ITS tracking analysis macros
authordainese <dainese@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 13 Nov 2009 23:15:39 +0000 (23:15 +0000)
committerdainese <dainese@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 13 Nov 2009 23:15:39 +0000 (23:15 +0000)
PWG1/macros/PlotITSTrackingEff.C [new file with mode: 0644]
PWG1/macros/PlotITSTrackingRes.C [new file with mode: 0644]

diff --git a/PWG1/macros/PlotITSTrackingEff.C b/PWG1/macros/PlotITSTrackingEff.C
new file mode 100644 (file)
index 0000000..51fd4dc
--- /dev/null
@@ -0,0 +1,1178 @@
+void PlotITSTrackingEff(TString filename="ITS.Performance.root",
+                       TString part="Pi",
+                       TString partforgraph="pions",
+                       Int_t pdgcode=211,
+                       Bool_t useAbsPdg=kTRUE,
+                       Bool_t nofakes=kTRUE,
+                       Bool_t askITSrefit=kTRUE,
+                       Int_t minTPCcls=1) 
+{
+  //
+  // Macro to plot ITS tracking efficiency from ITS.Performance.root
+  // A. Dainese
+  //  
+
+  //Open File
+  if(gSystem->AccessPathName(filename.Data())) {
+    printf("file not found!\n");  
+    return;
+  }
+  TFile *file= TFile::Open(filename.Data());
+  cout<<"Open File "<<filename<<endl;   
+
+  TList *list = (TList*)file->Get("cOutputITS");
+  TNtuple *ntTracks = (TNtuple*)list->FindObject("fNtupleESDTracks");
+    
+  //Getting and Addressing  NTuples    
+  Float_t pt,ptmes,eta,phi,pdg,d0True,d0TV,d0zTV,sigmad0zTV,d0All,d0Oth,sigmad0Oth,ITSflag,sigmad0TV,sigmad0All;
+  ntTracks->SetBranchAddress("pt",&ptmes);
+  ntTracks->SetBranchAddress("ptMC",&pt);
+  ntTracks->SetBranchAddress("eta",&eta);
+  ntTracks->SetBranchAddress("phi",&phi);
+  ntTracks->SetBranchAddress("pdgMC",&pdg);
+  ntTracks->SetBranchAddress("d0MC",&d0True);
+  ntTracks->SetBranchAddress("d0MCv",&d0TV);
+  ntTracks->SetBranchAddress("z0MCv",&d0zTV);
+  ntTracks->SetBranchAddress("sigmad0MCv",&sigmad0TV);
+  ntTracks->SetBranchAddress("sigmaz0MCv",&sigmad0zTV);
+  ntTracks->SetBranchAddress("d0",&d0All);
+  ntTracks->SetBranchAddress("sigmad0",&sigmad0All);
+  ntTracks->SetBranchAddress("ITSflag",&ITSflag);
+
+  
+  TString titlegraph1,titlefile;  
+  Int_t  ntracks,nITSsel,nfakes=0;
+  const Int_t nPtBins=10;  
+  Double_t meanpt[nPtBins];
+  ///////////////////////////////////////////////////////////////////////////
+  Double_t nprimgen[nPtBins]; 
+  Float_t nfiles=48.; if(!useAbsPdg) nfiles*=0.5; 
+  for(Int_t j=0; j<nPtBins; j++) nprimgen[j]=nfiles*50.;// *18.;
+  // the factor 50 is for the cut |eta|<0.9
+  // the factor 18 is for the cut 0.9<|eta|<1.4
+  ///////////////////////////////////////////////////////////////////////////
+  Double_t n6ITSclspart[nPtBins],n5ITSclspart[nPtBins],n4ITSclspart[nPtBins],n3ITSclspart[nPtBins],n2ITSclspart[nPtBins],n1ITSclspart[nPtBins];
+  Double_t n6ITSclsparttoTPC[nPtBins],n5ITSclsparttoTPC[nPtBins],n4ITSclsparttoTPC[nPtBins],n3ITSclsparttoTPC[nPtBins],n2ITSclsparttoTPC[nPtBins];
+  Double_t nSPD[nPtBins],n2ITS[nPtBins],n3ITS[nPtBins],n4ITS[nPtBins],n5ITS[nPtBins],n6ITS[nPtBins],n456ITS[nPtBins],ptbinning[2*nPtBins],ntottr[nPtBins];
+  Double_t nTPCnorm6[nPtBins],n1ITSnorm6[nPtBins],n2ITSnorm6[nPtBins],n3ITSnorm6[nPtBins],n4ITSnorm6[nPtBins],n5ITSnorm6[nPtBins],n6ITSnorm6[nPtBins],n456ITSnorm6[nPtBins],n4ITSnorm5[nPtBins],n5ITSnorm5[nPtBins],n3ITSnorm4[nPtBins],n4ITSnorm4[nPtBins],n2ITSnorm3[nPtBins],n3ITSnorm3[nPtBins],n1ITSnorm2[nPtBins],n2ITSnorm2[nPtBins];
+  Double_t nSPDtoGen[nPtBins],n2ITStoGen[nPtBins],n3ITStoGen[nPtBins],n4ITStoGen[nPtBins],n5ITStoGen[nPtBins],n6ITStoGen[nPtBins],n456ITStoGen[nPtBins],nTPCtoGen[nPtBins];
+  Double_t nTPCto6cls[nPtBins],n1ITSto6cls[nPtBins],n2ITSto6cls[nPtBins],n3ITSto6cls[nPtBins],n4ITSto6cls[nPtBins],n5ITSto6cls[nPtBins],n4ITSto5cls[nPtBins],n5ITSto5cls[nPtBins],n3ITSto4cls[nPtBins],n4ITSto4cls[nPtBins],n2ITSto3cls[nPtBins],n3ITSto3cls[nPtBins],n1ITSto2cls[nPtBins],n2ITSto2cls[nPtBins],n6ITSto6cls[nPtBins],n456ITSto6cls[nPtBins];
+  Double_t n330[nPtBins],n331[nPtBins],n332[nPtBins],n313[nPtBins],n323[nPtBins],n133[nPtBins],n233[nPtBins],nOTHERS[nPtBins],nSSD[nPtBins],nSDD[nPtBins];
+
+  Double_t sigmnSPD[nPtBins],sigmn4ITS[nPtBins],sigmn5ITS[nPtBins],sigmn6ITS[nPtBins],sigmn456ITS[nPtBins],ptbinning[2*nPtBins],ntottr[nPtBins];
+  Double_t sigmnSPDtoGen[nPtBins],sigmn2ITStoGen[nPtBins],sigmn3ITStoGen[nPtBins],sigmn4ITStoGen[nPtBins],sigmn5ITStoGen[nPtBins],sigmn6ITStoGen[nPtBins],sigmn456ITStoGen[nPtBins],sigmnTPCtoGen[nPtBins];
+  Double_t sigmnTPCto6cls[nPtBins],sigmn1ITSto6cls[nPtBins],sigmn2ITSto6cls[nPtBins],sigmn3ITSto6cls[nPtBins],sigmn4ITSto6cls[nPtBins],sigmn5ITSto6cls[nPtBins],sigmn6ITSto6cls[nPtBins],sigmn456ITSto6cls[nPtBins],sigmn4ITSto5cls[nPtBins],sigmn5ITSto5cls[nPtBins],sigmn3ITSto4cls[nPtBins],sigmn4ITSto4cls[nPtBins],sigmn2ITSto3cls[nPtBins],sigmn3ITSto3cls[nPtBins],sigmn1ITSto2cls[nPtBins],sigmn2ITSto2cls[nPtBins];
+  Double_t sigmn330[nPtBins],sigmn331[nPtBins],sigmn332[nPtBins],sigmn313[nPtBins],sigmn323[nPtBins],sigmn133[nPtBins],sigmn233[nPtBins],sigmnOTHERS[nPtBins],sigmnSSD[nPtBins],sigmnSDD[nPtBins];
+  Double_t sigmn6ITSclsparttoTPC[nPtBins],sigmn5ITSclsparttoTPC[nPtBins],sigmn4ITSclsparttoTPC[nPtBins],sigmn3ITSclsparttoTPC[nPtBins],sigmn2ITSclsparttoTPC[nPtBins];
+
+  Double_t errx[nPtBins];
+  
+  TGraphErrors *gr4,*gr5,*gr6,*gr456,*grSPDtoGen,*gr2toGen,*gr3toGen,*gr4toGen,*gr5toGen,*gr6toGen,*gr456toGen,*grTPCtoGen,*grTPCto6cls,*gr1to6cls,*gr2to6cls,*gr3to6cls,*gr4to6cls,*gr5to6cls,*gr6to6cls,*gr456to6cls,*gr4to5cls,*gr5to5cls,*gr3to4cls,*gr4to4cls,*gr2to3cls,*gr3to3cls,*gr1to2cls,*gr2to2cls,*gr330,*gr331,*gr332,*gr313,*gr323,*gr133,*gr233,*grOTHERS,*grSSD,*grSPD,*gr6clspart,*gr5clspart,*gr4clspart,*gr2ITSclsparttoTPC,*gr3ITSclsparttoTPC,*gr4ITSclsparttoTPC,*gr5ITSclsparttoTPC,*gr6ITSclsparttoTPC;
+  
+  for(Int_t j=0;j<nPtBins;j++) {
+    n1ITSclspart[j]=0.;
+    n2ITSclspart[j]=0.;
+    n3ITSclspart[j]=0.;
+    n4ITSclspart[j]=0.;
+    n5ITSclspart[j]=0.;
+    n6ITSclspart[j]=0.;
+    nSPD[j]=0.;
+    n2ITS[j]=0.;
+    n3ITS[j]=0.;
+    n4ITS[j]=0.;
+    n5ITS[j]=0.;
+    n6ITS[j]=0.;
+    n456ITS[j]=0.;
+    n1ITSnorm6[j]=0.;
+    n2ITSnorm6[j]=0.;
+    n3ITSnorm6[j]=0.;
+    n4ITSnorm6[j]=0.;
+    n5ITSnorm6[j]=0.;
+    n6ITSnorm6[j]=0.;
+    n456ITSnorm6[j]=0.;
+    n4ITSnorm5[j]=0.;
+    n5ITSnorm5[j]=0.;
+    n3ITSnorm4[j]=0.;
+    n4ITSnorm4[j]=0.;
+    n2ITSnorm3[j]=0.;
+    n3ITSnorm3[j]=0.;
+    n1ITSnorm2[j]=0.;
+    n2ITSnorm2[j]=0.;
+    nSPDtoGen[j]=0.;
+    n2ITStoGen[j]=0.;
+    n3ITStoGen[j]=0.;
+    n4ITStoGen[j]=0.;
+    n5ITStoGen[j]=0.;
+    n6ITStoGen[j]=0.;
+    n456ITStoGen[j]=0.;
+    nTPCtoGen[j]=0.;
+    n1ITSto6cls[j]=0.;
+    n2ITSto6cls[j]=0.;
+    n3ITSto6cls[j]=0.;
+    n4ITSto6cls[j]=0.;
+    n5ITSto6cls[j]=0.;
+    n6ITSto6cls[j]=0.;
+    n4ITSto5cls[j]=0.;
+    n5ITSto5cls[j]=0.;
+    n3ITSto4cls[j]=0.;
+    n4ITSto4cls[j]=0.;
+    n2ITSto3cls[j]=0.;
+    n3ITSto3cls[j]=0.;
+    n1ITSto2cls[j]=0.;
+    n2ITSto2cls[j]=0.;
+    n456ITSto6cls[j]=0.;
+    nTPCto6cls[j]=0.;
+    n330[j]=0;
+    n331[j]=0;
+    n332[j]=0;
+    n313[j]=0;
+    n323[j]=0;
+    n133[j]=0;
+    n233[j]=0;
+    nOTHERS[j]=0;
+    nSDD[j]=0.;
+    nSSD[j]=0.;
+    errx[j]=0.;
+    ntottr[j]=0;
+    meanpt[j]=0;
+  }
+
+  ptbinning[0]=0.15;
+  ptbinning[1]=0.35;
+  ptbinning[2]=0.4;
+  ptbinning[3]=0.6;
+  ptbinning[4]=0.7;
+  ptbinning[5]=0.85;
+  ptbinning[6]=0.85;
+  ptbinning[7]=1.2;
+  ptbinning[8]=1.7;
+  ptbinning[9]=2.3;
+  ptbinning[10]=3.6;
+  ptbinning[11]=4.4;
+  ptbinning[12]=6.5;
+  ptbinning[13]=7.5;
+  ptbinning[14]=8.5;
+  ptbinning[15]=11.5;
+  ptbinning[16]=18.5;
+  ptbinning[17]=21.5;
+  ptbinning[18]=27.5;
+  ptbinning[19]=32.5;
+  
+
+  
+  
+
+  // ------------ Starting Loop on Tracks ----------
+  ntracks=ntTracks->GetEntries();
+  printf("number of Tracks %d \n",ntracks);
+  
+  for (Int_t j=0;j<ntracks;j++) {
+    if(j%10000==0) printf("Reading track %d\n",j);
+    ntTracks->GetEvent(j); 
+    if(TMath::Abs(d0True)>1.) continue; // only primaries
+    if(TMath::Abs(eta)>0.9) continue;   // only tracks with |etapart|<0.9
+    //if(TMath::Abs(eta)<0.9 || TMath::Abs(eta)>1.4) continue;   // only tracks with 0.9<|etapart|<1.4
+    Float_t theta = 2.*TMath::ATan(TMath::Exp(-eta));
+    //if(TMath::Abs(TMath::Abs(phi)-0.5*TMath::Pi())>0.5 || TMath::Abs(theta-0.5*TMath::Pi())>0.5) continue;
+    //if(phi<(.5+0.25)*TMath::Pi() || phi>(.5+0.45)*TMath::Pi()) continue;
+    if(ITSflag<0) nfakes++;
+    //printf("  %d\n",ITSflag);
+    if(nofakes && ITSflag<0) continue;        // reject fakes
+    ITSflag=TMath::Abs(ITSflag); 
+    //printf("%d\n",ITSflag);
+    Int_t ITSflagorig=ITSflag;
+    Int_t nTPCcls =       (Int_t)(ITSflag/100000);
+    ITSflag -= nTPCcls*100000;
+    Int_t nITSclspart =   (Int_t)(ITSflag/10000);
+    ITSflag -= nITSclspart*10000;
+    //printf("%d\n",ITSflag);
+    Int_t nITSclsassign = (Int_t)(ITSflag/1000);
+    ITSflag -= nITSclsassign*1000;
+    //printf("%d\n",ITSflag);
+    //printf("%d\n",ITSflag);
+    nITSsel=ITSnCluster(ITSflag);
+
+
+    if(nTPCcls<=minTPCcls) continue;
+
+    if(useAbsPdg) pdg=TMath::Abs(pdg);
+    if(pdg!=pdgcode) continue;
+
+    for (Int_t k=0; k<nPtBins; k++) {
+      if(ptbinning[2*k]<pt&&pt<ptbinning[2*k+1]) {
+       //if(nITSclspart==3) {nITSclspart=5;}else{nITSclspart=-1;}
+       if(ptmes>0.) {
+         ntottr[k]+=1.;
+         meanpt[k]+=pt;
+         if(nITSclspart==6) n6ITSclspart[k]+=1.;
+         if(nITSclspart==5) n5ITSclspart[k]+=1.;
+         if(nITSclspart==4) n4ITSclspart[k]+=1.;
+         if(nITSclspart==3) n3ITSclspart[k]+=1.;
+         if(nITSclspart==2) n2ITSclspart[k]+=1.;
+       }       
+       if(askITSrefit && sigmad0TV<0.) continue;   
+       if(nITSclsassign!=nITSsel) cout<<" ERROR  "<<ITSflag<<"  "<<nITSclsassign<<"  "<<nITSsel<<"   "<<ITSflagorig<<endl; 
+       
+       if(nITSsel==2) n2ITS[k]+=1.;
+       if(nITSsel==3) n3ITS[k]+=1.;
+       if(nITSsel==4) n4ITS[k]+=1.;
+       if(nITSsel==5) n5ITS[k]+=1.;
+       if(nITSsel==6) n6ITS[k]+=1.;
+       
+       if(((Int_t)ITSflag)%10==3) nSPD[k]+=1.; // both SPD
+       
+       if(nITSclspart==6) {
+         if(nITSsel==1) n1ITSnorm6[k]+=1.;
+         if(nITSsel==2) n2ITSnorm6[k]+=1.;
+         if(nITSsel==3) n3ITSnorm6[k]+=1.;
+         if(nITSsel==4) n4ITSnorm6[k]+=1.;
+         if(nITSsel==5) n5ITSnorm6[k]+=1.;
+         if(nITSsel==6) n6ITSnorm6[k]+=1.;
+       }
+       if(nITSclspart==5) {
+         if(nITSsel==4) n4ITSnorm5[k]+=1.;
+         if(nITSsel==5) n5ITSnorm5[k]+=1.;
+       }
+       if(nITSclspart==4) {
+         if(nITSsel==3) n3ITSnorm4[k]+=1.;
+         if(nITSsel==4) n4ITSnorm4[k]+=1.;
+       }
+       if(nITSclspart==3) {
+         if(nITSsel==2) n2ITSnorm3[k]+=1.;
+         if(nITSsel==3) n3ITSnorm3[k]+=1.;
+       }
+       if(nITSclspart==2) {
+         if(nITSsel==1) n1ITSnorm2[k]+=1.;
+         if(nITSsel==2) n2ITSnorm2[k]+=1.;
+       }
+
+       if(k==nPtBins-1 && nITSclspart==5 && nITSsel==4) printf("nClustersPart %d nClustersTrack %d Map %d\n",nITSclspart,nITSsel,ITSflag);
+       
+       //5 points array
+       if(nITSclspart==5) {
+         if(ITSflag==332) {
+           n332[k]+=1.;
+         } else if(ITSflag==331) {
+           n331[k]+=1.;
+         } else if(ITSflag==323) {
+           n323[k]+=1.;
+         } else if(ITSflag==313) {
+           n313[k]+=1.;
+         } else if(ITSflag==233) {
+           n233[k]+=1.;
+         } else if(ITSflag==133) {
+           n133[k]+=1.;
+         }
+       }
+       if(ITSflag==330) {
+         n330[k]+=1.;
+       } else if(ITSflag!=333) {
+         nOTHERS[k]+=1.;
+       }
+       
+      }
+    }
+
+  } //end loop on tracks
+
+  printf("%d  %d  %d  %d  %d\n",n2ITS[9],n3ITS[9],n4ITS[9],n5ITS[9],n6ITS[9]);
+
+  for(Int_t k=0;k<nPtBins;k++) {
+    if(n6ITSclspart[k]<1) n6ITSclspart[k]=1.;
+    if(n5ITSclspart[k]<1) n5ITSclspart[k]=1.;
+    if(n4ITSclspart[k]<1) n4ITSclspart[k]=1.;
+    if(n3ITSclspart[k]<1) n3ITSclspart[k]=1.;
+    if(n2ITSclspart[k]<1) n2ITSclspart[k]=1.;
+    if(n1ITSclspart[k]<1) n1ITSclspart[k]=1.;
+
+    //cout<<n1ITSclspart[k]<<" "<<n2ITSclspart[k]<<" "<<n3ITSclspart[k]<<" "<<n4ITSclspart[k]<<" "<<n5ITSclspart[k]<<" "<<n6ITSclspart[k]<<endl;
+
+    if(ntottr[k]!=0) {
+      meanpt[k]=meanpt[k]/ntottr[k];
+
+      nSPDtoGen[k]=nSPD[k]/nprimgen[k];
+      n2ITStoGen[k]=n2ITS[k]/nprimgen[k];
+      n3ITStoGen[k]=n3ITS[k]/nprimgen[k];
+      n4ITStoGen[k]=n4ITS[k]/nprimgen[k];
+      n5ITStoGen[k]=n5ITS[k]/nprimgen[k];
+      n6ITStoGen[k]=n6ITS[k]/nprimgen[k];
+      nTPCtoGen[k]=ntottr[k]/nprimgen[k];
+      n456ITStoGen[k]=n4ITStoGen[k]+n5ITStoGen[k]+n6ITStoGen[k];
+      
+      n1ITSto6cls[k]=n1ITSnorm6[k]/n6ITSclspart[k];
+      n2ITSto6cls[k]=n2ITSnorm6[k]/n6ITSclspart[k];
+      n3ITSto6cls[k]=n3ITSnorm6[k]/n6ITSclspart[k];
+      n4ITSto6cls[k]=n4ITSnorm6[k]/n6ITSclspart[k];
+      n5ITSto6cls[k]=n5ITSnorm6[k]/n6ITSclspart[k];
+      n6ITSto6cls[k]=n6ITSnorm6[k]/n6ITSclspart[k];
+      n4ITSto5cls[k]=n4ITSnorm5[k]/n5ITSclspart[k];
+      n5ITSto5cls[k]=n5ITSnorm5[k]/n5ITSclspart[k];
+      n3ITSto4cls[k]=n3ITSnorm4[k]/n4ITSclspart[k];
+      n4ITSto4cls[k]=n4ITSnorm4[k]/n4ITSclspart[k];
+      n2ITSto3cls[k]=n2ITSnorm3[k]/n3ITSclspart[k];
+      n3ITSto3cls[k]=n3ITSnorm3[k]/n3ITSclspart[k];
+      n1ITSto2cls[k]=n1ITSnorm2[k]/n2ITSclspart[k];
+      n2ITSto2cls[k]=n2ITSnorm2[k]/n2ITSclspart[k];
+
+      nTPCto6cls[k]=ntottr[k]/n6ITSclspart[k];
+      n456ITSto6cls[k]=n4ITSto6cls[k]+n5ITSto6cls[k]+n6ITSto6cls[k];
+      //cout<<meanpt[k]<<"  "<<n6ITSnorm6[k]<<"  "<<n6ITSclspart[k]<<endl;
+
+      n6ITSclsparttoTPC[k]=n6ITSclspart[k]/ntottr[k];
+      n5ITSclsparttoTPC[k]=n5ITSclspart[k]/ntottr[k];
+      n4ITSclsparttoTPC[k]=n4ITSclspart[k]/ntottr[k];
+      n3ITSclsparttoTPC[k]=n3ITSclspart[k]/ntottr[k];
+      n2ITSclsparttoTPC[k]=n2ITSclspart[k]/ntottr[k];
+      
+      n4ITS[k]=n4ITS[k]/ntottr[k];
+      n5ITS[k]=n5ITS[k]/ntottr[k];
+      n6ITS[k]=n6ITS[k]/ntottr[k];
+
+      n330[k]=n330[k]/ntottr[k];
+      n331[k]=n331[k]/n5ITSclspart[k];
+      n332[k]=n332[k]/n5ITSclspart[k];
+      n313[k]=n313[k]/n5ITSclspart[k];
+      n323[k]=n323[k]/n5ITSclspart[k];
+      n133[k]=n133[k]/n5ITSclspart[k];
+      n233[k]=n233[k]/n5ITSclspart[k];
+      nOTHERS[k]=nOTHERS[k]/ntottr[k];
+      n456ITS[k]=n4ITS[k]+n5ITS[k]+n6ITS[k];
+      nSSD[k]=n133[k]+n233[k];
+      nSDD[k]=n323[k]+n313[k];
+
+      
+      sigmn4ITS[k]=TMath::Sqrt(n4ITS[k]*(1-n4ITS[k])/ntottr[k]);
+      sigmn5ITS[k]=TMath::Sqrt(n5ITS[k]*(1-n5ITS[k])/ntottr[k]);
+      sigmn6ITS[k]=TMath::Sqrt(n6ITS[k]*(1-n6ITS[k])/ntottr[k]);
+      sigmn456ITS[k]=TMath::Sqrt(n456ITS[k]*(1-n456ITS[k])/ntottr[k]);
+
+      sigmn2ITSclsparttoTPC[k]=TMath::Sqrt(n2ITSclsparttoTPC[k]*(1-n2ITSclsparttoTPC[k])/ntottr[k]);
+      sigmn3ITSclsparttoTPC[k]=TMath::Sqrt(n3ITSclsparttoTPC[k]*(1-n3ITSclsparttoTPC[k])/ntottr[k]);
+      sigmn4ITSclsparttoTPC[k]=TMath::Sqrt(n4ITSclsparttoTPC[k]*(1-n4ITSclsparttoTPC[k])/ntottr[k]);
+      sigmn5ITSclsparttoTPC[k]=TMath::Sqrt(n5ITSclsparttoTPC[k]*(1-n5ITSclsparttoTPC[k])/ntottr[k]);
+      sigmn6ITSclsparttoTPC[k]=TMath::Sqrt(n6ITSclsparttoTPC[k]*(1-n6ITSclsparttoTPC[k])/ntottr[k]);
+
+      sigmnSPDtoGen[k]=TMath::Sqrt(nSPDtoGen[k]*(1-nSPDtoGen[k])/nprimgen[k]);
+      sigmn2ITStoGen[k]=TMath::Sqrt(n2ITStoGen[k]*(1-n2ITStoGen[k])/nprimgen[k]);
+      sigmn3ITStoGen[k]=TMath::Sqrt(n3ITStoGen[k]*(1-n3ITStoGen[k])/nprimgen[k]);
+      sigmn4ITStoGen[k]=TMath::Sqrt(n4ITStoGen[k]*(1-n4ITStoGen[k])/nprimgen[k]);
+      sigmn5ITStoGen[k]=TMath::Sqrt(n5ITStoGen[k]*(1-n5ITStoGen[k])/nprimgen[k]);
+      sigmn6ITStoGen[k]=TMath::Sqrt(n6ITStoGen[k]*(1-n6ITStoGen[k])/nprimgen[k]);
+      sigmn456ITStoGen[k]=TMath::Sqrt(n456ITStoGen[k]*(1-n456ITStoGen[k])/nprimgen[k]);
+      sigmnTPCtoGen[k]=TMath::Sqrt(nTPCtoGen[k]*(1-nTPCtoGen[k])/nprimgen[k]);
+      sigmnTPCto6cls[k]=TMath::Sqrt(nTPCto6cls[k]*(1-nTPCto6cls[k])/n6ITSclspart[k]);
+      
+      sigmn1ITSto6cls[k]=TMath::Sqrt(n1ITSto6cls[k]*(1-n1ITSto6cls[k])/n6ITSclspart[k]);
+      sigmn2ITSto6cls[k]=TMath::Sqrt(n2ITSto6cls[k]*(1-n2ITSto6cls[k])/n6ITSclspart[k]);
+      sigmn3ITSto6cls[k]=TMath::Sqrt(n3ITSto6cls[k]*(1-n3ITSto6cls[k])/n6ITSclspart[k]);
+      sigmn4ITSto6cls[k]=TMath::Sqrt(n4ITSto6cls[k]*(1-n4ITSto6cls[k])/n6ITSclspart[k]);
+      sigmn5ITSto6cls[k]=TMath::Sqrt(n5ITSto6cls[k]*(1-n5ITSto6cls[k])/n6ITSclspart[k]);
+      sigmn6ITSto6cls[k]=TMath::Sqrt(n6ITSto6cls[k]*(1-n6ITSto6cls[k])/n6ITSclspart[k]);
+      sigmn4ITSto5cls[k]=TMath::Sqrt(n4ITSto5cls[k]*(1-n4ITSto5cls[k])/n5ITSclspart[k]);
+      sigmn5ITSto5cls[k]=TMath::Sqrt(n5ITSto5cls[k]*(1-n5ITSto5cls[k])/n5ITSclspart[k]);
+      sigmn3ITSto4cls[k]=TMath::Sqrt(n3ITSto4cls[k]*(1-n3ITSto4cls[k])/n4ITSclspart[k]);
+      sigmn4ITSto4cls[k]=TMath::Sqrt(n4ITSto4cls[k]*(1-n4ITSto4cls[k])/n4ITSclspart[k]);
+      sigmn2ITSto3cls[k]=TMath::Sqrt(n2ITSto3cls[k]*(1-n2ITSto3cls[k])/n3ITSclspart[k]);
+      sigmn3ITSto3cls[k]=TMath::Sqrt(n3ITSto3cls[k]*(1-n3ITSto3cls[k])/n3ITSclspart[k]);
+      sigmn1ITSto2cls[k]=TMath::Sqrt(n1ITSto2cls[k]*(1-n1ITSto2cls[k])/n2ITSclspart[k]);
+      sigmn2ITSto2cls[k]=TMath::Sqrt(n2ITSto2cls[k]*(1-n2ITSto2cls[k])/n2ITSclspart[k]);
+      sigmn456ITSto6cls[k]=TMath::Sqrt(n456ITSto6cls[k]*(1-n456ITSto6cls[k])/n6ITSclspart[k]);
+      
+      sigmn330[k]=TMath::Sqrt(n330[k]*(1-n330[k])/ntottr[k]);
+      sigmn331[k]=TMath::Sqrt(n331[k]*(1-n331[k])/ntottr[k]);
+      sigmn332[k]=TMath::Sqrt(n332[k]*(1-n332[k])/ntottr[k]);
+      sigmn313[k]=TMath::Sqrt(n313[k]*(1-n313[k])/ntottr[k]);
+      sigmn323[k]=TMath::Sqrt(n323[k]*(1-n323[k])/ntottr[k]);
+      sigmn133[k]=TMath::Sqrt(n133[k]*(1-n133[k])/ntottr[k]);
+      sigmn233[k]=TMath::Sqrt(n233[k]*(1-n233[k])/ntottr[k]);
+
+     
+      sigmnOTHERS[k]=TMath::Sqrt(nOTHERS[k]*(1-nOTHERS[k])/ntottr[k]);
+      sigmnSSD[k]=TMath::Sqrt((n133[k]+n233[k])*(1-n133[k]-n233[k])/ntottr[k]);
+      sigmnSDD[k]=TMath::Sqrt((n323[k]+n313[k])*(1-n323[k]-n313[k])/ntottr[k]);
+    } else {
+      meanpt[k]=(ptbinning[2*k+1]+ptbinning[2*k])/2.;
+    }
+    
+  } // end loop on pt bins
+
+  //-------DRAWING  TGRAPH--------  
+  
+  const int cWidth = 500;
+  const int cHeight = (int)(500*(29.7/21.));
+  
+  TCanvas* ceff0 = new TCanvas("ceff0","ceff0",cWidth,cHeight);
+  ceff0->SetLogx();
+  ceff0->SetGridy();
+
+  gr4 = new TGraphErrors(nPtBins,meanpt,n4ITS,errx,sigmn4ITS);
+  gr4->SetName("mygraph04ITS");
+  gr4->SetTitle("ITS tracking efficiency (B=0.5T, no misal.)");
+  gr4->SetLineColor(1);
+  gr4->SetLineWidth(1);
+  gr4->SetMarkerColor(2);
+  gr4->SetMarkerStyle(21);
+  gr4->SetMarkerSize(1);
+  gr4->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr4->GetYaxis()->SetTitle("ITS efficiency (normalized to TPC trks)");
+  gr4->SetMaximum(1.2);
+  gr4->SetMinimum(0.);
+  gr4->Draw("AP");
+  
+  gr5 = new TGraphErrors(nPtBins,meanpt,n5ITS,errx,sigmn5ITS);
+  gr5->SetName("mygraph05ITS");
+  gr5->SetLineColor(1);
+  gr5->SetLineWidth(1);
+  gr5->SetMarkerColor(8);
+  gr5->SetMarkerStyle(21);
+  gr5->SetMarkerSize(1.);
+  gr5->SetTitle(titlegraph1);
+  gr5->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr5->GetYaxis()->SetTitle("");
+  gr5->Draw("P");
+
+  gr6 = new TGraphErrors(nPtBins,meanpt,n6ITS,errx,sigmn6ITS);
+  gr6->SetName("mygraph06ITS");
+  gr6->SetLineColor(1);
+  gr6->SetLineWidth(1);
+  gr6->SetMarkerColor(4);
+  gr6->SetMarkerStyle(21);
+  gr6->SetMarkerSize(1.);
+  gr6->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr6->GetYaxis()->SetTitle("");
+  gr6->Draw("P");
+
+  gr456 = new TGraphErrors(nPtBins,meanpt,n456ITS,errx,sigmn456ITS);
+  gr456->SetName("mygraph456ITS");
+  gr456->SetLineColor(1);
+  gr456->SetLineWidth(1);
+  gr456->SetMarkerColor(1);
+  gr456->SetMarkerStyle(21);
+  gr456->SetMarkerSize(1.);
+  gr456->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr456->GetYaxis()->SetTitle("");
+  gr456->Draw("P");
+
+  TLegend *l0 = new TLegend(0.5,0.5,0.9,0.9);
+  l0->SetFillStyle(0);
+  l0->SetBorderSize(0);
+  l0->AddEntry(gr4,"kTPCin + 4 ITS cls","p");
+  l0->AddEntry(gr5,"kTPCin + 5 ITS cls","p");
+  l0->AddEntry(gr6,"kTPCin + 6 ITS cls","p");
+  l0->AddEntry(gr456,"kTPCin + 4or5or6 ITS cls","p");
+  l0->Draw();
+
+  TCanvas* ceff1 = new TCanvas("ceff1","ceff1",cWidth,cHeight);
+  ceff1->SetLogx();
+  ceff1->SetGridy();
+  
+  gr4toGen = new TGraphErrors(nPtBins,meanpt,n4ITStoGen,errx,sigmn4ITStoGen);
+  gr4toGen->SetName("mygraph04ITStoGen");
+  gr4toGen->SetTitle("Physical tracking efficiency (B=0.5T, no misal.)");
+  gr4toGen->SetLineColor(1);
+  gr4toGen->SetLineWidth(1);
+  gr4toGen->SetMarkerColor(2);
+  gr4toGen->SetMarkerStyle(24);
+  gr4toGen->SetMarkerSize(1.);
+  gr4toGen->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr4toGen->GetYaxis()->SetTitle("Physical efficiency (normalized to generated)");
+  gr4toGen->SetMaximum(1.2);
+  gr4toGen->SetMinimum(0.);
+  gr4toGen->Draw("AP");
+
+  gr2toGen = new TGraphErrors(nPtBins,meanpt,n2ITStoGen,errx,sigmn2ITStoGen);
+  gr2toGen->SetName("mygraph02ITStoGen");
+  gr2toGen->SetLineColor(1);
+  gr2toGen->SetLineWidth(1);
+  gr2toGen->SetMarkerColor(1);
+  gr2toGen->SetMarkerStyle(20);
+  gr2toGen->SetMarkerSize(1.);
+  gr2toGen->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr2toGen->GetYaxis()->SetTitle("");
+  gr2toGen->Draw("P");
+
+  gr3toGen = new TGraphErrors(nPtBins,meanpt,n3ITStoGen,errx,sigmn3ITStoGen);
+  gr3toGen->SetName("mygraph03ITStoGen");
+  gr3toGen->SetLineColor(1);
+  gr3toGen->SetLineWidth(1);
+  gr3toGen->SetMarkerColor(2);
+  gr3toGen->SetMarkerStyle(21);
+  gr3toGen->SetMarkerSize(1.);
+  gr3toGen->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr3toGen->GetYaxis()->SetTitle("");
+  gr3toGen->Draw("P");
+
+  gr5toGen = new TGraphErrors(nPtBins,meanpt,n5ITStoGen,errx,sigmn5ITStoGen);
+  gr5toGen->SetName("mygraph05ITStoGen");
+  gr5toGen->SetLineColor(1);
+  gr5toGen->SetLineWidth(1);
+  gr5toGen->SetMarkerColor(8);
+  gr5toGen->SetMarkerStyle(24);
+  gr5toGen->SetMarkerSize(1.);
+  gr5toGen->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr5toGen->GetYaxis()->SetTitle("");
+  gr5toGen->Draw("P");
+
+  gr6toGen = new TGraphErrors(nPtBins,meanpt,n6ITStoGen,errx,sigmn6ITStoGen);
+  gr6toGen->SetName("mygraph06ITStoGen");
+  gr6toGen->SetLineColor(1);
+  gr6toGen->SetLineWidth(1);
+  gr6toGen->SetMarkerColor(4);
+  gr6toGen->SetMarkerStyle(24);
+  gr6toGen->SetMarkerSize(1.);
+  gr6toGen->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr6toGen->GetYaxis()->SetTitle("");
+  gr6toGen->Draw("P");
+
+  gr456toGen = new TGraphErrors(nPtBins,meanpt,n456ITStoGen,errx,sigmn456ITStoGen);
+  gr456toGen->SetName("mygraph0456ITStoGen");
+  gr456toGen->SetLineColor(1);
+  gr456toGen->SetLineWidth(1);
+  gr456toGen->SetMarkerColor(1);
+  gr456toGen->SetMarkerStyle(24);
+  gr456toGen->SetMarkerSize(1.);
+  gr456toGen->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr456toGen->GetYaxis()->SetTitle("");
+  //gr456toGen->Draw("P");
+
+  
+  grTPCtoGen = new TGraphErrors(nPtBins,meanpt,nTPCtoGen,errx,sigmnTPCtoGen);
+  grTPCtoGen->SetName("mygraph0TPCtoGen");
+  grTPCtoGen->SetLineColor(1);
+  grTPCtoGen->SetLineWidth(1);
+  grTPCtoGen->SetMarkerColor(6);
+  grTPCtoGen->SetMarkerStyle(20);
+  grTPCtoGen->SetMarkerSize(1.);
+  grTPCtoGen->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  grTPCtoGen->GetYaxis()->SetTitle("");
+  grTPCtoGen->Draw("P");
+
+  grSPDtoGen = new TGraphErrors(nPtBins,meanpt,nSPDtoGen,errx,sigmnSPDtoGen);
+  grSPDtoGen->SetName("mygraph0SPDtoGen");
+  grSPDtoGen->SetLineColor(1);
+  grSPDtoGen->SetLineWidth(1);
+  grSPDtoGen->SetMarkerColor(9);
+  grSPDtoGen->SetMarkerStyle(22);
+  grSPDtoGen->SetMarkerSize(1.3);
+  grSPDtoGen->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  grSPDtoGen->GetYaxis()->SetTitle("");
+  grSPDtoGen->Draw("P");
+  
+
+  TLegend *l1 = new TLegend(0.5,0.5,0.9,0.9);
+  l1->SetFillStyle(0);
+  l1->SetBorderSize(0);
+  l1->AddEntry(grTPCtoGen,"kTPCin","p");
+  l1->AddEntry(grSPDtoGen,"kTPCin + 2 SPD cls","p");
+  l1->AddEntry(gr2toGen,"kTPCin + 2 ITS cls","p");
+  l1->AddEntry(gr3toGen,"kTPCin + 3 ITS cls","p");
+  l1->AddEntry(gr4toGen,"kTPCin + 4 ITS cls","p");
+  l1->AddEntry(gr5toGen,"kTPCin + 5 ITS cls","p");
+  l1->AddEntry(gr6toGen,"kTPCin + 6 ITS cls","p");
+  //l1->AddEntry(gr456toGen,"kTPCin + 4or5or6 ITS cls","p");
+  l1->Draw();
+  
+
+
+  TCanvas* ceff2_6 = new TCanvas("ceff2_6","ceff2_6",cWidth,cHeight);
+  ceff2_6->SetLogx();
+  ceff2_6->SetGridy();
+  
+  gr4to6cls = new TGraphErrors(nPtBins,meanpt,n4ITSto6cls,errx,sigmn4ITSto6cls);
+  gr4to6cls->SetName("mygraph04ITSto6cls");
+  gr4to6cls->SetTitle("ITS tracking efficiency (B=0.5T, no misal.)");
+  gr4to6cls->SetLineColor(1);
+  gr4to6cls->SetLineWidth(1);
+  gr4to6cls->SetMarkerColor(2);
+  gr4to6cls->SetMarkerStyle(24);
+  gr4to6cls->SetMarkerSize(1.);
+  gr4to6cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr4to6cls->GetYaxis()->SetTitle("ITS efficiency (normalized to kTPCin with 6 ITS cls)");
+  gr4to6cls->SetMaximum(1.2);
+  gr4to6cls->SetMinimum(0.);
+  gr4to6cls->Draw("AP");
+
+  gr5to6cls = new TGraphErrors(nPtBins,meanpt,n5ITSto6cls,errx,sigmn5ITSto6cls);
+  gr5to6cls->SetName("mygraph05ITSto6cls");
+  gr5to6cls->SetLineColor(1);
+  gr5to6cls->SetLineWidth(1);
+  gr5to6cls->SetMarkerColor(8);
+  gr5to6cls->SetMarkerStyle(25);
+  gr5to6cls->SetMarkerSize(1.);
+  gr5to6cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr5to6cls->GetYaxis()->SetTitle("");
+  gr5to6cls->Draw("P");
+
+  gr6to6cls = new TGraphErrors(nPtBins,meanpt,n6ITSto6cls,errx,sigmn6ITSto6cls);
+  gr6to6cls->SetName("mygraph06ITSto6cls");
+  gr6to6cls->SetLineColor(1);
+  gr6to6cls->SetLineWidth(1);
+  gr6to6cls->SetMarkerColor(4);
+  gr6to6cls->SetMarkerStyle(26);
+  gr6to6cls->SetMarkerSize(1.);
+  gr6to6cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr6to6cls->GetYaxis()->SetTitle("");
+  gr6to6cls->Draw("P");
+
+  gr3to6cls = new TGraphErrors(nPtBins,meanpt,n3ITSto6cls,errx,sigmn3ITSto6cls);
+  gr3to6cls->SetName("mygraph03ITSto6cls");
+  gr3to6cls->SetLineColor(1);
+  gr3to6cls->SetLineWidth(1);
+  gr3to6cls->SetMarkerColor(9);
+  gr3to6cls->SetMarkerStyle(27);
+  gr3to6cls->SetMarkerSize(1.);
+  gr3to6cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr3to6cls->GetYaxis()->SetTitle("");
+  gr3to6cls->Draw("P");
+
+  gr2to6cls = new TGraphErrors(nPtBins,meanpt,n2ITSto6cls,errx,sigmn2ITSto6cls);
+  gr2to6cls->SetName("mygraph02ITSto6cls");
+  gr2to6cls->SetLineColor(1);
+  gr2to6cls->SetLineWidth(1);
+  gr2to6cls->SetMarkerColor(1);
+  gr2to6cls->SetMarkerStyle(28);
+  gr2to6cls->SetMarkerSize(1.);
+  gr2to6cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr2to6cls->GetYaxis()->SetTitle("");
+  gr2to6cls->Draw("P");
+
+  gr1to6cls = new TGraphErrors(nPtBins,meanpt,n1ITSto6cls,errx,sigmn1ITSto6cls);
+  gr1to6cls->SetName("mygraph01ITSto6cls");
+  gr1to6cls->SetLineColor(1);
+  gr1to6cls->SetLineWidth(1);
+  gr1to6cls->SetMarkerColor(6);
+  gr1to6cls->SetMarkerStyle(29);
+  gr1to6cls->SetMarkerSize(1.);
+  gr1to6cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr1to6cls->GetYaxis()->SetTitle("");
+  gr1to6cls->Draw("P");
+
+
+  TLegend *l2_6 = new TLegend(0.5,0.5,0.9,0.9);
+  l2_6->SetFillStyle(0);
+  l2_6->SetBorderSize(0);
+  l2_6->AddEntry(gr6to6cls,"kTPCin + 6 ITS cls","p");
+  l2_6->AddEntry(gr5to6cls,"kTPCin + 5 ITS cls","p");
+  l2_6->AddEntry(gr4to6cls,"kTPCin + 4 ITS cls","p");
+  l2_6->AddEntry(gr3to6cls,"kTPCin + 3 ITS cls","p");
+  l2_6->AddEntry(gr2to6cls,"kTPCin + 2 ITS cls","p");
+  l2_6->AddEntry(gr1to6cls,"kTPCin + 1 ITS cls","p");
+  l2_6->Draw();
+
+  TCanvas* ceff2_5 = new TCanvas("ceff2_5","ceff2_5",cWidth,cHeight);
+  ceff2_5->SetLogx();
+  ceff2_5->SetGridy();
+  
+  gr4to5cls = new TGraphErrors(nPtBins,meanpt,n4ITSto5cls,errx,sigmn4ITSto5cls);
+  gr4to5cls->SetName("mygraph04ITSto5cls");
+  gr4to5cls->SetTitle("ITS tracking efficiency (B=0.5T, no misal.)");
+  gr4to5cls->SetLineColor(1);
+  gr4to5cls->SetLineWidth(1);
+  gr4to5cls->SetMarkerColor(2);
+  gr4to5cls->SetMarkerStyle(24);
+  gr4to5cls->SetMarkerSize(1.);
+  gr4to5cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr4to5cls->GetYaxis()->SetTitle("ITS efficiency (normalized to kTPCin with 5 ITS cls)");
+  gr4to5cls->SetMaximum(1.2);
+  gr4to5cls->SetMinimum(0.);
+  gr4to5cls->Draw("AP");
+
+  gr5to5cls = new TGraphErrors(nPtBins,meanpt,n5ITSto5cls,errx,sigmn5ITSto5cls);
+  gr5to5cls->SetName("mygraph05ITSto5cls");
+  gr5to5cls->SetLineColor(1);
+  gr5to5cls->SetLineWidth(1);
+  gr5to5cls->SetMarkerColor(1);
+  gr5to5cls->SetMarkerStyle(25);
+  gr5to5cls->SetMarkerSize(1.);
+  gr5to5cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr5to5cls->GetYaxis()->SetTitle("");
+  gr5to5cls->Draw("P");
+
+  TLegend *l2_5 = new TLegend(0.5,0.5,0.9,0.9);
+  l2_5->SetFillStyle(0);
+  l2_5->SetBorderSize(0);
+  l2_5->AddEntry(gr5to5cls,"kTPCin + 5 ITS cls","p");
+  l2_5->AddEntry(gr4to5cls,"kTPCin + 4 ITS cls","p");
+  l2_5->Draw();
+
+  TCanvas* ceff2_4 = new TCanvas("ceff2_4","ceff2_4",cWidth,cHeight);
+  ceff2_4->SetLogx();
+  ceff2_4->SetGridy();
+  
+  gr4to4cls = new TGraphErrors(nPtBins,meanpt,n4ITSto4cls,errx,sigmn4ITSto4cls);
+  gr4to4cls->SetName("mygraph04ITSto4cls");
+  gr4to4cls->SetTitle("ITS tracking efficiency (B=0.5T, no misal.)");
+  gr4to4cls->SetLineColor(1);
+  gr4to4cls->SetLineWidth(1);
+  gr4to4cls->SetMarkerColor(2);
+  gr4to4cls->SetMarkerStyle(24);
+  gr4to4cls->SetMarkerSize(1.);
+  gr4to4cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr4to4cls->GetYaxis()->SetTitle("ITS efficiency (normalized to kTPCin with 4 ITS cls)");
+  gr4to4cls->SetMaximum(1.2);
+  gr4to4cls->SetMinimum(0.);
+  gr4to4cls->Draw("AP");
+
+  gr3to4cls = new TGraphErrors(nPtBins,meanpt,n3ITSto4cls,errx,sigmn3ITSto4cls);
+  gr3to4cls->SetName("mygraph03ITSto4cls");
+  gr3to4cls->SetLineColor(1);
+  gr3to4cls->SetLineWidth(1);
+  gr3to4cls->SetMarkerColor(1);
+  gr3to4cls->SetMarkerStyle(25);
+  gr3to4cls->SetMarkerSize(1.);
+  gr3to4cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr3to4cls->GetYaxis()->SetTitle("");
+  gr3to4cls->Draw("P");
+
+  TLegend *l2_4 = new TLegend(0.5,0.5,0.9,0.9);
+  l2_4->SetFillStyle(0);
+  l2_4->SetBorderSize(0);
+  l2_4->AddEntry(gr4to4cls,"kTPCin + 4 ITS cls","p");
+  l2_4->AddEntry(gr3to4cls,"kTPCin + 3 ITS cls","p");
+  l2_4->Draw();
+
+  TCanvas* ceff2_3 = new TCanvas("ceff2_3","ceff2_3",cWidth,cHeight);
+  ceff2_3->SetLogx();
+  ceff2_3->SetGridy();
+  
+  gr3to3cls = new TGraphErrors(nPtBins,meanpt,n3ITSto3cls,errx,sigmn3ITSto3cls);
+  gr3to3cls->SetName("mygraph03ITSto3cls");
+  gr3to3cls->SetTitle("ITS tracking efficiency (B=0.5T, no misal.)");
+  gr3to3cls->SetLineColor(1);
+  gr3to3cls->SetLineWidth(1);
+  gr3to3cls->SetMarkerColor(2);
+  gr3to3cls->SetMarkerStyle(24);
+  gr3to3cls->SetMarkerSize(1.);
+  gr3to3cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr3to3cls->GetYaxis()->SetTitle("ITS efficiency (normalized to kTPCin with 3 ITS cls)");
+  gr3to3cls->SetMaximum(1.2);
+  gr3to3cls->SetMinimum(0.);
+  gr3to3cls->Draw("AP");
+
+  gr2to3cls = new TGraphErrors(nPtBins,meanpt,n2ITSto3cls,errx,sigmn2ITSto3cls);
+  gr2to3cls->SetName("mygraph02ITSto3cls");
+  gr2to3cls->SetLineColor(1);
+  gr2to3cls->SetLineWidth(1);
+  gr2to3cls->SetMarkerColor(1);
+  gr2to3cls->SetMarkerStyle(25);
+  gr2to3cls->SetMarkerSize(1.);
+  gr2to3cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr2to3cls->GetYaxis()->SetTitle("");
+  gr2to3cls->Draw("P");
+
+  TLegend *l2_3 = new TLegend(0.5,0.5,0.9,0.9);
+  l2_3->SetFillStyle(0);
+  l2_3->SetBorderSize(0);
+  l2_3->AddEntry(gr3to3cls,"kTPCin + 3 ITS cls","p");
+  l2_3->AddEntry(gr2to3cls,"kTPCin + 2 ITS cls","p");
+  l2_3->Draw();
+
+  TCanvas* ceff2_2 = new TCanvas("ceff2_2","ceff2_2",cWidth,cHeight);
+  ceff2_2->SetLogx();
+  ceff2_2->SetGridy();
+  
+  gr1to2cls = new TGraphErrors(nPtBins,meanpt,n1ITSto2cls,errx,sigmn1ITSto2cls);
+  gr1to2cls->SetName("mygraph01ITSto2cls");
+  gr1to2cls->SetTitle("ITS tracking efficiency (B=0.5T, no misal.)");
+  gr1to2cls->SetLineColor(1);
+  gr1to2cls->SetLineWidth(1);
+  gr1to2cls->SetMarkerColor(2);
+  gr1to2cls->SetMarkerStyle(24);
+  gr1to2cls->SetMarkerSize(1.);
+  gr1to2cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr1to2cls->GetYaxis()->SetTitle("ITS efficiency (normalized to kTPCin with 2 ITS cls)");
+  gr1to2cls->SetMaximum(1.2);
+  gr1to2cls->SetMinimum(0.);
+  gr1to2cls->Draw("AP");
+
+  gr2to2cls = new TGraphErrors(nPtBins,meanpt,n2ITSto2cls,errx,sigmn2ITSto2cls);
+  gr2to2cls->SetName("mygraph02ITSto2cls");
+  gr2to2cls->SetLineColor(1);
+  gr2to2cls->SetLineWidth(1);
+  gr2to2cls->SetMarkerColor(1);
+  gr2to2cls->SetMarkerStyle(25);
+  gr2to2cls->SetMarkerSize(1.);
+  gr2to2cls->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr2to2cls->GetYaxis()->SetTitle("");
+  gr2to2cls->Draw("P");
+
+  TLegend *l2_2 = new TLegend(0.5,0.5,0.9,0.9);
+  l2_2->SetFillStyle(0);
+  l2_2->SetBorderSize(0);
+  l2_2->AddEntry(gr2to2cls,"kTPCin + 2 ITS cls","p");
+  l2_2->AddEntry(gr1to2cls,"kTPCin + 1 ITS cls","p");
+  l2_2->Draw();
+
+
+  TCanvas* ceff3 = new TCanvas("ceff3","ceff3",cWidth,cHeight);
+  ceff3->SetLogx();
+  ceff3->SetGridy();
+  
+  gr4ITSclsparttoTPC = new TGraphErrors(nPtBins,meanpt,n4ITSclsparttoTPC,errx,sigmn4ITSclsparttoTPC);
+  gr4ITSclsparttoTPC->SetName("mygraph04ITSclsparttoTPC");
+  gr4ITSclsparttoTPC->SetTitle("Number of produced clusters (B=0.5T, no misal.)");
+  gr4ITSclsparttoTPC->SetLineColor(1);
+  gr4ITSclsparttoTPC->SetLineWidth(1);
+  gr4ITSclsparttoTPC->SetMarkerColor(2);
+  gr4ITSclsparttoTPC->SetMarkerStyle(22);
+  gr4ITSclsparttoTPC->SetMarkerSize(1.);
+  gr4ITSclsparttoTPC->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr4ITSclsparttoTPC->GetYaxis()->SetTitle("Fraction of primary kTPCin tracks producing N clusters");
+  gr4ITSclsparttoTPC->SetMaximum(1.2);
+  gr4ITSclsparttoTPC->SetMinimum(0.);
+  gr4ITSclsparttoTPC->Draw("AP");
+
+  gr5ITSclsparttoTPC = new TGraphErrors(nPtBins,meanpt,n5ITSclsparttoTPC,errx,sigmn5ITSclsparttoTPC);
+  gr5ITSclsparttoTPC->SetName("mygraph05ITSclsparttoTPC");
+  gr5ITSclsparttoTPC->SetLineColor(1);
+  gr5ITSclsparttoTPC->SetLineWidth(1);
+  gr5ITSclsparttoTPC->SetMarkerColor(8);
+  gr5ITSclsparttoTPC->SetMarkerStyle(22);
+  gr5ITSclsparttoTPC->SetMarkerSize(1.);
+  gr5ITSclsparttoTPC->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr5ITSclsparttoTPC->GetYaxis()->SetTitle("");
+  gr5ITSclsparttoTPC->Draw("P");
+
+  gr6ITSclsparttoTPC = new TGraphErrors(nPtBins,meanpt,n6ITSclsparttoTPC,errx,sigmn6ITSclsparttoTPC);
+  gr6ITSclsparttoTPC->SetName("mygraph06ITSITSclsparttoTPC");
+  gr6ITSclsparttoTPC->SetLineColor(1);
+  gr6ITSclsparttoTPC->SetLineWidth(1);
+  gr6ITSclsparttoTPC->SetMarkerColor(4);
+  gr6ITSclsparttoTPC->SetMarkerStyle(22);
+  gr6ITSclsparttoTPC->SetMarkerSize(1.);
+  gr6ITSclsparttoTPC->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr6ITSclsparttoTPC->GetYaxis()->SetTitle("");
+  gr6ITSclsparttoTPC->Draw("P");
+
+  gr3ITSclsparttoTPC = new TGraphErrors(nPtBins,meanpt,n3ITSclsparttoTPC,errx,sigmn3ITSclsparttoTPC);
+  gr3ITSclsparttoTPC->SetName("mygraph03ITSITSclsparttoTPC");
+  gr3ITSclsparttoTPC->SetLineColor(1);
+  gr3ITSclsparttoTPC->SetLineWidth(1);
+  gr3ITSclsparttoTPC->SetMarkerColor(6);
+  gr3ITSclsparttoTPC->SetMarkerStyle(22);
+  gr3ITSclsparttoTPC->SetMarkerSize(1.);
+  gr3ITSclsparttoTPC->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr3ITSclsparttoTPC->GetYaxis()->SetTitle("");
+  gr3ITSclsparttoTPC->Draw("P");
+
+  gr2ITSclsparttoTPC = new TGraphErrors(nPtBins,meanpt,n2ITSclsparttoTPC,errx,sigmn2ITSclsparttoTPC);
+  gr2ITSclsparttoTPC->SetName("mygraph06ITSITSclsparttoTPC");
+  gr2ITSclsparttoTPC->SetLineColor(1);
+  gr2ITSclsparttoTPC->SetLineWidth(1);
+  gr2ITSclsparttoTPC->SetMarkerColor(1);
+  gr2ITSclsparttoTPC->SetMarkerStyle(22);
+  gr2ITSclsparttoTPC->SetMarkerSize(1.);
+  gr2ITSclsparttoTPC->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr2ITSclsparttoTPC->GetYaxis()->SetTitle("");
+  gr2ITSclsparttoTPC->Draw("P");
+
+  TLegend *l3 = new TLegend(0.5,0.5,0.9,0.9);
+  l3->SetFillStyle(0);
+  l3->SetBorderSize(0);
+  l3->AddEntry(gr2ITSclsparttoTPC,"2 ITS cls","p");
+  l3->AddEntry(gr3ITSclsparttoTPC,"3 ITS cls","p");
+  l3->AddEntry(gr4ITSclsparttoTPC,"4 ITS cls","p");
+  l3->AddEntry(gr5ITSclsparttoTPC,"5 ITS cls","p");
+  l3->AddEntry(gr6ITSclsparttoTPC,"6 ITS cls","p");
+  l3->Draw();
+  
+
+  ////////////--------------5 POINTS SCENARIO
+  
+  TCanvas* fitting1 = new TCanvas("fitting1","5 Points Scenario tracks analysis",cWidth,cHeight);
+  fitting1->Divide(3,2);
+  fitting1->cd(1);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  gr133 = new TGraphErrors(nPtBins,meanpt,n133,errx,sigmn133);
+  gr133->SetName("mygraph133");
+  gr133->SetLineColor(1);
+  gr133->SetLineWidth(1);
+  gr133->SetMarkerColor(4);
+  gr133->SetMarkerStyle(21);
+  gr133->SetMarkerSize(.5);
+  titlegraph1="NTracks without SSD2 point for ";
+  //titlegraph1="d_{0}(r#phi) Resolution for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using True Vertex");
+  gr133->SetTitle(titlegraph1);
+  gr133->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr133->GetYaxis()->SetTitle("");
+  gr133->Draw("AP");
+  
+  fitting1->cd(4);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  gr233 = new TGraphErrors(nPtBins,meanpt,n233,errx,sigmn233);
+  gr233->SetName("mygraph233");
+  gr233->SetLineColor(1);
+  gr233->SetLineWidth(1);
+  gr233->SetMarkerColor(4);
+  gr233->SetMarkerStyle(21);
+  gr233->SetMarkerSize(.5);
+  //titlegraph1="d_{0}(r#phi) Resolution for  ";
+  titlegraph1="NTracks without SSD1 point for ";
+  titlegraph1.Append(partforgraph);
+  // titlegraph1.Append(" using Reconstructed Vertex");
+  gr233->SetTitle(titlegraph1);
+  gr233->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr233->GetYaxis()->SetTitle("");
+  gr233->Draw("AP");
+  
+  fitting1->cd(2);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  gr313 = new TGraphErrors(nPtBins,meanpt,n313,errx,sigmn313);
+  gr313->SetName("mygraph313");
+  gr313->SetLineColor(1);
+  gr313->SetLineWidth(1);
+  gr313->SetMarkerColor(4);
+  gr313->SetMarkerStyle(21);
+  gr313->SetMarkerSize(.5);
+  titlegraph1="NTracks without SDD2 point for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using Vertex on the Fly");
+  gr313->SetTitle(titlegraph1);
+  gr313->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr313->GetYaxis()->SetTitle("");
+  gr313->Draw("AP");
+
+  fitting1->cd(5);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+ gPad->SetGridx();
+  gPad->SetGridy();  
+  gr323 = new TGraphErrors(nPtBins,meanpt,n323,errx,sigmn323);
+  gr323->SetName("mygraph323");
+  gr323->SetLineColor(1);
+  gr323->SetLineWidth(1);
+  gr323->SetMarkerColor(4);
+  gr323->SetMarkerStyle(21);
+  gr323->SetMarkerSize(.5);
+  titlegraph1="NTracks without SDD1 point for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using Vertex on the Fly");
+  gr323->SetTitle(titlegraph1);
+  gr323->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr323->GetYaxis()->SetTitle("");
+  gr323->Draw("AP");
+
+  fitting1->cd(3);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  gr331 = new TGraphErrors(nPtBins,meanpt,n331,errx,sigmn331);
+  gr331->SetName("mygraph331");
+  gr331->SetLineColor(1);
+  gr331->SetLineWidth(1);
+  gr331->SetMarkerColor(4);
+  gr331->SetMarkerStyle(21);
+  gr331->SetMarkerSize(.5);
+  titlegraph1="NTracks without SPD2 point for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using Vertex on the Fly");
+  gr331->SetTitle(titlegraph1);
+  gr331->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr331->GetYaxis()->SetTitle("");
+  gr331->Draw("AP");
+
+  fitting1->cd(6);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  gr332 = new TGraphErrors(nPtBins,meanpt,n332,errx,sigmn332);
+  gr332->SetName("mygraph332");
+  gr332->SetLineColor(1);
+  gr332->SetLineWidth(1);
+  gr332->SetMarkerColor(4);
+  gr332->SetMarkerStyle(21);
+  gr332->SetMarkerSize(.5);
+  titlegraph1="NTracks without SPD1 point for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using Vertex on the Fly");
+  gr332->SetTitle(titlegraph1);
+  gr332->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr332->GetYaxis()->SetTitle("");
+  gr332->Draw("AP");
+
+
+  TCanvas* fitting2 = new TCanvas("fitting2","SPD Scenario tracks analysis",cWidth,cHeight);
+  fitting2->Divide(3,2);
+  
+  fitting2->cd(1);
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  gr331->Draw("AP");
+
+  fitting2->cd(2);
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  gr332->Draw("AP");
+
+  fitting2->cd(3);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  gr330 = new TGraphErrors(nPtBins,meanpt,n330,errx,sigmn330);
+  gr330->SetName("mygraph330");
+  gr330->SetLineColor(1);
+  gr330->SetLineWidth(1);
+  gr330->SetMarkerColor(4);
+  gr330->SetMarkerStyle(21);
+  gr330->SetMarkerSize(.5);
+  titlegraph1="NTracks without 2 SPD points for ";
+  //titlegraph1="d_{0}(r#phi) Resolution for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using True Vertex");
+  gr330->SetTitle(titlegraph1);
+  gr330->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr330->GetYaxis()->SetTitle("");
+  gr330->Draw("AP");
+
+  fitting2->cd(4);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  grSSD = new TGraphErrors(nPtBins,meanpt,nSSD,errx,sigmnSSD);
+  grSSD->SetName("mygraphSSD");
+  grSSD->SetLineColor(1);
+  grSSD->SetLineWidth(1);
+  grSSD->SetMarkerColor(4);
+  grSSD->SetMarkerStyle(21);
+  grSSD->SetMarkerSize(.5);
+  titlegraph1="NTracks without one SSD point for ";
+  //titlegraph1="d_{0}(r#phi) Resolution for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using True Vertex");
+  grSSD->SetTitle(titlegraph1);
+  grSSD->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  grSSD->GetYaxis()->SetTitle("");
+  grSSD->Draw("AP");
+
+  fitting2->cd(5);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  grSDD = new TGraphErrors(nPtBins,meanpt,nSDD,errx,sigmnSDD);
+  grSDD->SetName("mygraphSDD");
+  grSDD->SetLineColor(1);
+  grSDD->SetLineWidth(1);
+  grSDD->SetMarkerColor(4);
+  grSDD->SetMarkerStyle(21);
+  grSDD->SetMarkerSize(.5);
+  titlegraph1="NTracks without one SDD point for ";
+  //titlegraph1="d_{0}(r#phi) Resolution for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using True Vertex");
+  grSDD->SetTitle(titlegraph1);
+  grSDD->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  grSDD->GetYaxis()->SetTitle("");
+  grSDD->Draw("AP");
+
+  fitting2->cd(6);
+  // gPad->SetLogy();
+  gPad->SetLogx();
+  gPad->SetGridx();
+  gPad->SetGridy();  
+  grOTHERS = new TGraphErrors(nPtBins,meanpt,nOTHERS,errx,sigmnOTHERS);
+  grOTHERS->SetName("mygraphOTHERS");
+  grOTHERS->SetLineColor(1);
+  grOTHERS->SetLineWidth(1);
+  grOTHERS->SetMarkerColor(4);
+  grOTHERS->SetMarkerStyle(21);
+  grOTHERS->SetMarkerSize(.5);
+  titlegraph1="NTracks with 4 points (2 SPD+ ?)for ";
+  //titlegraph1="d_{0}(r#phi) Resolution for ";
+  titlegraph1.Append(partforgraph);
+  //    titlegraph1.Append(" using True Vertex");
+  grOTHERS->SetTitle(titlegraph1);
+  grOTHERS->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  grOTHERS->GetYaxis()->SetTitle("");
+  grOTHERS->Draw("AP");
+
+  ceff0->cd();
+  gr330->Draw("p");
+  gr331->Draw("p");
+  gr332->Draw("p");
+  grSSD->Draw("p");
+  grSDD->Draw("p");
+  //  gr313->Draw("p");
+  // gr323->Draw("p");
+  //gr133->Draw("p");
+  //gr233->Draw("p");
+  
+
+  //---------CLOSE EVRYTHING AND SAVE------------
+  TFile *outfile = new TFile("EfficienciesAnalysis.root","recreate");
+  gr4->Write();
+  gr5->Write();
+  gr6->Write();
+  gr456->Write();
+  gr4toGen->Write();
+  gr5toGen->Write();
+  gr6toGen->Write();
+  gr456toGen->Write();
+  grTPCtoGen->Write();
+  gr4to6cls->Write();
+  gr5to6cls->Write();
+  gr6to6cls->Write();
+  //gr456to6cls->Write();
+  //gr330->Write();
+  //gr331->Write();
+  //gr332->Write();
+  //gr323->Write();
+  //gr313->Write();
+  //gr133->Write();
+  //gr233->Write();
+  //grOTHERS->Write();
+  //grSPD->Write();
+  //grSSD->Write();
+  //grSDD->Write();
+  outfile->Close();
+
+
+  printf("Number of fakes: %d\n",nfakes);
+  return;
+}
+//--------------------------------------------------------------------------
+Int_t ITSnCluster(Int_t ITSf) 
+{
+  Int_t sign,aITSf,n0,n3,aux,ITSsel;//be careful!:working with integer!
+  n0=0;
+  n3=0;
+  aITSf=TMath::Abs(ITSf);
+  if(aITSf==0)sign=0;
+  else if (aITSf==ITSf)sign=1;
+  else if(aITSf==-ITSf)sign=-1;
+  
+  if (aITSf/100<1)n0++;
+  n3=aITSf/300;
+  aux=(aITSf-(aITSf/100)*100);
+  if(aux/10<1)n0++;
+  n3+=aux/30;
+  aux=(aux-(aux/10)*10);
+  if (aux==0)n0++;
+  n3+=aux/3;
+  ITSsel=3+n3-n0;
+  
+  if(ITSsel>6) {
+    cout<<"Wrong ITSflag assignment!"<<endl;
+    return 99;
+  }
+  
+  return ITSsel*sign;
+}
+//----------------------------------------------------------------------------
diff --git a/PWG1/macros/PlotITSTrackingRes.C b/PWG1/macros/PlotITSTrackingRes.C
new file mode 100644 (file)
index 0000000..24e6b06
--- /dev/null
@@ -0,0 +1,1695 @@
+Bool_t gboxbin=kFALSE;
+Int_t  gMarkerColor=2;
+
+void PlotITSTrackingRes(TString filename="ITS.Performance.root",
+                       Int_t pdgcode=211,
+                       Bool_t useAbsPdg=kTRUE,
+                       Bool_t box=kTRUE,
+                       Int_t minITSpoints=6,
+                       Bool_t nofakes=kTRUE,
+                       Bool_t askITSrefit=kTRUE,
+                       Int_t minTPCcls=1) 
+{
+  //
+  // Plot ITS tracking resolutions from ITS.Performance.root
+  // A. Dainese
+  // 
+
+
+  //Open File
+  if(gSystem->AccessPathName(filename.Data())) {
+    printf("file not found!\n");  
+    return;
+  }
+  TFile *file= TFile::Open(filename.Data());
+  cout<<"Opening file "<<filename.Data()<<endl;   
+    
+  TList *list = (TList*)file->Get("cOutputITS");
+  TNtuple *ntTracks = (TNtuple*)list->FindObject("fNtupleESDTracks");
+
+      
+  //Getting and Addressing  NTuples
+    
+  Float_t pt,ptmes,eta,phi,pdg,d0True,d0TV,d0zTV,sigmad0zTV,d0All,d0Oth,sigmad0Oth,ITSflag,sigmad0TV,sigmad0All;
+  
+  ntTracks->SetBranchAddress("pt",&ptmes);
+  ntTracks->SetBranchAddress("ptMC",&pt);
+  ntTracks->SetBranchAddress("eta",&eta);
+  ntTracks->SetBranchAddress("phi",&phi);
+  ntTracks->SetBranchAddress("pdgMC",&pdg);
+  ntTracks->SetBranchAddress("d0MC",&d0True);
+  ntTracks->SetBranchAddress("d0MCv",&d0TV);
+  ntTracks->SetBranchAddress("z0MCv",&d0zTV);
+  ntTracks->SetBranchAddress("sigmad0MCv",&sigmad0TV);
+  ntTracks->SetBranchAddress("sigmaz0MCv",&sigmad0zTV);
+  ntTracks->SetBranchAddress("d0",&d0All);
+  ntTracks->SetBranchAddress("sigmad0",&sigmad0All);
+  ntTracks->SetBranchAddress("ITSflag",&ITSflag);
+
+    
+  //make STANDARD Pt BINNING
+  gboxbin=box;
+  const Int_t nPtBins=10;
+  Double_t ptbinning[2*nPtBins];
+  const Int_t numint=10;
+  Double_t ptmin[numint],lenghtbin[numint],stepbin[numint],interval[numint],steplenght;
+  Int_t nbinning[numint];
+  Int_t runningbin=0;
+
+  for(Int_t i=0;i<nPtBins;i++) nbinning[i]=1;
+  
+  ptbinning[0]=0.2;
+  ptbinning[1]=0.35;
+  ptbinning[2]=0.4;
+  ptbinning[3]=0.6;
+  ptbinning[4]=0.7;
+  ptbinning[5]=0.85;
+  ptbinning[6]=0.85;
+  ptbinning[7]=1.2;
+  ptbinning[8]=1.7;
+  ptbinning[9]=2.3;
+  ptbinning[10]=3.6;
+  ptbinning[11]=4.4;
+  ptbinning[12]=6.5;
+  ptbinning[13]=7.5;
+  ptbinning[14]=9.5;
+  ptbinning[15]=10.5;
+  ptbinning[16]=19.5;
+  ptbinning[17]=20.5;
+  ptbinning[18]=29.5;
+  ptbinning[19]=30.5;
+  interval[0]=600;
+  interval[1]=300;
+  interval[2]=200;
+  interval[3]=150;
+  interval[4]=100;
+  interval[5]=100;
+  interval[6]=100;
+  interval[7]=70;
+  interval[8]=50;
+  interval[9]=50;
+
+  
+  const Int_t dipnbin=10;
+  const Double_t lenghtbindip=0.1;//0.03;
+  const Double_t stepbindip=0.0;
+  const Double_t dipinterval=200;
+  
+  
+  //  Double_t radice=TMath::Sqrt(2.)/2.; // |eta|<0.9
+  Double_t radice=0.; // all eta
+  Int_t ntracks,entries,ntotaltracks=0,nfaketr=0;
+  Double_t bin,sinteta,rms;
+  Double_t ptbin[nPtBins],dipbin[dipnbin],multptbin[nPtBins],multdipbin[dipnbin],ex[nPtBins],exdip[dipnbin];
+  Double_t sigmaResolutionTV[dipnbin][nPtBins],sigmaResolutionPtTV[nPtBins],errsigmResPtTV[nPtBins],meanResolutionPtTV[nPtBins],errmeanResPtTV[nPtBins],sigmaResolutionDipTV[dipnbin],errsigmResDipTV[dipnbin];
+  Double_t binpt,bindip,sigmaResolutionOV[dipnbin][nPtBins],sigmaResolutionPtOV[nPtBins],errsigmResPtOV[nPtBins],sigmaResolutionDipOV[dipnbin],errsigmResDipOV[dipnbin];
+  Double_t sigmaResolutionRV[dipnbin][nPtBins],sigmaResolutionPtRV[nPtBins],errsigmResPtRV[nPtBins],sigmaResolutionDipRV[dipnbin],errsigmResDipRV[dipnbin];
+  Double_t mediumsigmad0rphiPtTV[nPtBins],errmediumsigmad0rphiPtTV[nPtBins],mediumsigmad0rphiPtRV[nPtBins],errmediumsigmad0rphiPtRV[nPtBins],mediumsigmad0rphiPtOV[nPtBins],errmediumsigmad0rphiPtOV[nPtBins];
+  Double_t sigmaPullPtTV[nPtBins],errsigmPullPtTV[nPtBins],sigmaPullPtRV[nPtBins],errsigmPullPtRV[nPtBins],sigmaPullPtOV[nPtBins],errsigmPullPtOV[nPtBins];
+  Double_t sigmad0zResPtTV[nPtBins],errsigmd0zResPtTV[nPtBins];
+  // Double_t sigmad0zResPtRV[nPtBins],errsigmd0zResPtRV[nPtBins],sigmad0zResPtOV[nPtBins],errsigmd0zResPtOV[nPtBins];
+  Double_t sigmad0zPullPtTV[nPtBins],errsigmd0zPullPtTV[nPtBins];
+  Double_t sigmaPtResTV[nPtBins],errsigmPtResTV[nPtBins],meanPtResTV[nPtBins],errmeanPtResTV[nPtBins],sigmaCurvResTV[nPtBins],errsigmCurvResTV[nPtBins];
+  // Double_t sigmad0zPullPtRV[nPtBins],errsigmd0zPullPtRV[nPtBins],sigmad0zPullPtOV[nPtBins],errsigmd0zPullPtOV[nPtBins];
+  
+  Int_t ITSnpoints;
+  
+  Float_t hptbin[nPtBins+1],hdipbin[dipnbin+1];
+  
+  TF1 *gauss = new TF1("gauss","gaus",-10,10); 
+
+  TGraphErrors *gr0TV;
+  TGraphErrors *gr0OV;
+  TGraphErrors *gr0RV; 
+  TGraphErrors *gr1TV;
+  TGraphErrors *gr1OV;
+  TGraphErrors *gr1RV;
+
+  TGraphErrors *grPullTV;
+  TGraphErrors *grPullOV;
+  TGraphErrors *grPullRV; 
+
+  TGraphErrors *grsigmad0rphiTV;
+  TGraphErrors *grsigmad0rphiRV;
+  TGraphErrors *grsigmad0rphiOV;
+
+  TGraphErrors *grd0zResTV;
+  //TGraphErrors *grd0zRes0OV;
+  //TGraphErrors *grd0zRes0RV; 
+  
+  TGraphErrors *grd0zPullTV;
+  //TGraphErrors *grd0zPull0OV;
+  //TGraphErrors *grd0zPull0RV; 
+  TGraphErrors *grPtResTV;
+  TGraphErrors *grPtResMeanTV;
+  TGraphErrors *grCurvResTV;
+
+  TString numerobin,numerobin2,numerobinSigma,numerobinSigma2,numerobinPull,numerobinPull2,numerobind0zRes,numerobind0zPull,numerobind0zRes2,numerobind0zPull2,numerobinCurvRes,numerobinCurvRes2,numerobinPtRes,numerobinPtRes2,numerobin3,titlegraph1,titlegraph2,str=" ";
+  
+
+  
+  //DECLARING AND CONSTRUCTING HISTOGRAMS
+   
+  TH1F **hFitResolutionTV=new TH1F*[dipnbin*nPtBins];
+  TH1F **hFitResolutionOV=new TH1F*[dipnbin*nPtBins];
+  TH1F **hFitResolutionRV=new TH1F*[dipnbin*nPtBins];
+
+  TH1F **hFitResolutionPtTV=new TH1F*[nPtBins];
+  TH1F **hFitResolutionPtRV=new TH1F*[nPtBins];
+  TH1F **hFitResolutionPtOV=new TH1F*[nPtBins];
+
+  TH1F **hFitsigmad0rphiPtTV=new TH1F*[nPtBins];
+  TH1F **hFitsigmad0rphiPtRV=new TH1F*[nPtBins];
+  TH1F **hFitsigmad0rphiPtOV=new TH1F*[nPtBins];
+
+  TH1F **hFitPullPtTV=new TH1F*[nPtBins];
+  TH1F **hFitPullPtRV=new TH1F*[nPtBins];
+  TH1F **hFitPullPtOV=new TH1F*[nPtBins];
+
+  TH1F **hFitd0zResPtTV=new TH1F*[nPtBins];
+  //  TH1F **hFitd0zResPtRV=new TH1F*[nPtBins];
+  //TH1F **hFitd0zResPtOV=new TH1F*[nPtBins];
+
+  TH1F **hFitd0zPullPtTV=new TH1F*[nPtBins];
+  //TH1F **hFitd0zPullPtRV=new TH1F*[nPtBins];
+  //TH1F **hFitd0zPullPtOV=new TH1F*[nPtBins];
+
+  TH1F **hFitResolutionDipTV=new TH1F*[dipnbin];
+  TH1F **hFitResolutionDipRV=new TH1F*[dipnbin];
+  TH1F **hFitResolutionDipOV=new TH1F*[dipnbin];
+  
+  TH1F **hFitPtResTV=new TH1F*[nPtBins];
+  TH1F **hFitCurvResTV=new TH1F*[nPtBins];
+  TH2F *hFitResPtDipTV;
+  TH2F *hFitResPtDipRV;
+  TH2F *hFitResPtDipOV;
+
+  
+  Int_t incycle=0;
+  
+  for(Int_t v=0;v<dipnbin;v++) {
+    incycle=0;
+    for (Int_t nint=0;nint<numint;nint++) {
+      for (Int_t k=0;k<nbinning[nint];k++) { 
+       numerobin ="TranvDipResolution";
+       numerobin+=v;
+       numerobin.Append("_");
+       numerobin+=(k+incycle); 
+       numerobin.Append("bin");
+       
+       numerobin2=numerobin;
+       numerobin.Append("TV");
+       hFitResolutionTV[v*nPtBins+k+incycle]=new TH1F(numerobin,numerobin,3*100,-2*interval[nint],2*interval[nint]);
+       //      numerobin.Replace(24,25,"RV");
+       //      cout<<numerobin<<endl;
+       
+       numerobin=numerobin2;
+       numerobin2.Append("RV");
+       hFitResolutionRV[v*nPtBins+k+incycle]=new TH1F(numerobin2,numerobin2,3*100,-2*interval[nint],2*interval[nint]);
+       //      cout<<numerobin2<<endl;
+       
+       numerobin.Append("OV");
+       hFitResolutionOV[v*nPtBins+k+incycle]=new TH1F(numerobin,numerobin,3*100,-2*interval[nint],2*interval[nint]);
+       //      cout<<numerobin<<endl;
+       
+       //      cout<<(v*nPtBins+k+incycle)<<endl;
+      }
+      incycle+=nbinning[nint];
+    }
+  }
+
+  for(Int_t v=0;v<dipnbin;v++) {
+    numerobin="DipResolution";
+    numerobin+=v;
+    numerobin.Append("bin");
+    
+    numerobin2=numerobin;
+    numerobin.Append("TV");
+    hFitResolutionDipTV[v]=new TH1F(numerobin,numerobin,3*100,-3*dipinterval,3*dipinterval);
+
+    numerobin=numerobin2;
+    numerobin2.Append("RV");
+    hFitResolutionDipRV[v]=new TH1F(numerobin2,numerobin2,3*100,-3*dipinterval,3*dipinterval);
+
+    numerobin.Append("OV");
+    hFitResolutionDipOV[v]=new TH1F(numerobin,numerobin,3*100,-3*dipinterval,3*dipinterval);
+
+    dipbin[v]=0;
+    multdipbin[v]=0;    
+  }
+  incycle=0;
+  
+  for (Int_t nint=0;nint<numint;nint++) {   
+    for(Int_t k=0;k<nbinning[nint];k++) { 
+      numerobin = "d0PtResolution";
+      numerobinSigma="d0rphiPtsigma";
+      numerobinPull="d0PtPull";
+      numerobind0zRes="d0zPtResolution";
+      numerobind0zPull="d0zPtPull";
+      numerobinPtRes="PtResolution";
+      numerobinCurvRes="CurvRes";
+
+
+      numerobin+=k+incycle;
+      numerobinSigma+=k+incycle;
+      numerobinPull+=k+incycle;
+      numerobind0zRes+=k+incycle;
+      numerobind0zPull+=k+incycle;
+      numerobinPtRes+=k+incycle;
+      numerobinCurvRes+=k+incycle;
+
+      numerobin.Append("bin");
+      numerobinSigma.Append("bin");
+      numerobinPull.Append("bin");
+      numerobind0zRes.Append("bin");
+      numerobind0zPull.Append("bin");
+      numerobinPtRes.Append("bin");
+      numerobinCurvRes.Append("bin");
+
+       
+      numerobin2=numerobin;
+      numerobinSigma2=numerobinSigma;
+      numerobinPull2=numerobinPull;
+      numerobind0zRes2=numerobind0zRes;
+      numerobind0zPull2=numerobind0zPull;
+      numerobinPtRes2=numerobinPtRes;
+      numerobinCurvRes2=numerobinCurvRes;
+
+      numerobin.Append("TV");
+      hFitResolutionPtTV[k+incycle]=new TH1F(numerobin,numerobin,100,-2*interval[nint],2*interval[nint]);
+      hFitsigmad0rphiPtTV[k+incycle]=new TH1F(numerobinSigma,numerobinSigma,3*100,0.,4*interval[nint]);
+      numerobinPull.Append("TV");
+      hFitPullPtTV[k+incycle]=new TH1F(numerobinPull,numerobinPull,100,-4.,4.);
+      numerobind0zRes.Append("TV");
+      hFitd0zResPtTV[k+incycle]=new TH1F(numerobind0zRes,numerobind0zRes,3*100,-3*interval[nint],3*interval[nint]);
+      numerobind0zPull.Append("TV");
+      hFitd0zPullPtTV[k+incycle]=new TH1F(numerobind0zPull,numerobind0zPull,100,-4.,4.);
+      numerobinPtRes.Append("TV");
+      hFitPtResTV[k+incycle]=new TH1F(numerobinPtRes,numerobinPtRes,300,-1.,1.);
+      numerobinCurvRes.Append("TV");
+      hFitCurvResTV[k+incycle]=new TH1F(numerobinCurvRes,numerobinCurvRes,300,-1.,1.);
+
+      numerobin=numerobin2;
+      numerobinSigma=numerobinSigma2;
+      numerobin.Append("RV");
+      numerobinSigma.Append("RV");
+      hFitResolutionPtRV[k+incycle]=new TH1F(numerobin,numerobin,3*100,-2*interval[nint],2*interval[nint]);
+      hFitsigmad0rphiPtRV[k+incycle]=new TH1F(numerobinSigma,numerobinSigma,3*100,0.,4*interval[nint]);
+      numerobinPull=numerobinPull2;
+      numerobinPull.Append("RV");
+      hFitPullPtRV[k+incycle]=new TH1F(numerobinPull,numerobinPull,100,-4,4);
+
+      /*      numerobind0zRes=numerobind0zRes2;
+      numerobind0zRes.Append("RV");
+      hFitd0zResPtRV[k+incycle]=new TH1F(numerobind0zRes,numerobind0zRes,3*100,-3*interval[nint],3*interval[nint]);
+      numerobind0zPull=numerobind0zPull2;
+      numerobind0zPull.Append("RV");
+      hFitd0zPullPtRV[k+incycle]=new TH1F(numerobind0zPull,numerobind0zPull,100,-4,4);
+      */
+
+      numerobin=numerobin2;
+      numerobin.Append("OV");
+      hFitResolutionPtOV[k+incycle]=new TH1F(numerobin,numerobin,3*100,-2*interval[nint],2*interval[nint]);
+
+      numerobinSigma=numerobinSigma2;
+      numerobinSigma.Append("OV");
+      hFitsigmad0rphiPtOV[k+incycle]=new TH1F(numerobinSigma,numerobinSigma,3*100,0.,4.*interval[nint]);
+      numerobinPull=numerobinPull2;
+      numerobinPull.Append("OV");
+      hFitPullPtOV[k+incycle]=new TH1F(numerobinPull,numerobinPull,100,-4,4);
+
+      /* numerobind0zRes=numerobind0zRes2;
+      numerobind0zRes.Append("OV");
+      hFitd0zResPtOV[k+incycle]=new TH1F(numerobind0zRes,numerobind0zRes,3*100,-3*interval[nint],3*interval[nint]);
+      numerobind0zPull=numerobind0zPull2;
+      numerobind0zPull.Append("OV");
+      hFitd0zPullPtOV[k+incycle]=new TH1F(numerobind0zPull,numerobind0zPull,100,-4,4);
+      */
+      
+      ptbin[k+incycle]=0;
+      multptbin[k+incycle]=0;
+      hptbin[k+incycle]=0;
+      //      hptbin[(k+incycle)+1]=0;
+      //hptbin[(k+incycle)]=0;
+    }
+    incycle+=nbinning[nint];
+  }
+    
+  //  binpt=lenghtbin+stepbin;
+
+  bindip=lenghtbindip+stepbindip;
+  Int_t np=0;  
+  Int_t kbox=0;
+  if(gboxbin) kbox=1;
+
+
+
+  // ------------ Loop on Tracks ----------
+  ntracks=ntTracks->GetEntries();
+  cout<<"Number of Tracks: "<<ntracks<<endl;  
+  for (Int_t j=0;j<ntracks;j++) {
+    if(j%5000==0) printf("Reading track %d\n",j);
+    ntTracks->GetEvent(j);    
+    d0True*=1.e4;
+    d0TV*=1.e4;
+    d0zTV*=1.e4;
+    sigmad0zTV*=1.e4;
+    d0All*=1.e4;
+    d0Oth*1.e4;
+    sigmad0Oth*=1.e4;
+    sigmad0TV*=1.e4;
+    sigmad0All*=1.e4;
+
+    if(TMath::Abs(eta)>0.9) continue;
+    //if(TMath::Abs(eta)<0.9 || TMath::Abs(eta)>1.4) continue;
+    Float_t theta = 2.*TMath::ATan(TMath::Exp(-eta));
+    //if(TMath::Abs(TMath::Abs(phi)-0.5*TMath::Pi())>0.5 || TMath::Abs(theta-0.5*TMath::Pi())>0.5) continue;
+    Bool_t isFake=kFALSE;
+    if(ITSflag<0) isFake=kTRUE;
+    //printf("  %d\n",ITSflag);
+    ITSflag=TMath::Abs(ITSflag); 
+    //printf("%d\n",ITSflag);
+    Int_t ITSflagorig=ITSflag;
+    Int_t nTPCcls =       (Int_t)(ITSflag/100000);
+    ITSflag -= nTPCcls*100000;
+    Int_t nITSclspart =   (Int_t)(ITSflag/10000);
+    ITSflag -= nITSclspart*10000;
+    //printf("%d\n",ITSflag);
+    Int_t nITSclsassign = (Int_t)(ITSflag/1000);
+    ITSflag -= nITSclsassign*1000;
+    //printf("%d\n",ITSflag);
+    //printf("%d\n",ITSflag);
+    Int_t nITSsel=ITSnCluster(ITSflag);
+
+
+    if(nTPCcls<=minTPCcls) continue;
+
+    if(useAbsPdg) pdg=TMath::Abs(pdg);
+    if(pdg!=pdgcode) continue;
+
+
+    
+    if(TMath::Abs(nITSclsassign)<minITSpoints) continue;
+
+    if(askITSrefit && sigmad0TV<0.) continue;   
+
+    if(TMath::Abs(d0True)>0.5) continue;//skipping secondaries tracks if asked
+    //consider only "part" (if "all" is set to 1 all particles are considered)
+
+    if(isFake) nfaketr++;
+    if(nofakes && isFake) continue;        // reject fakes
+    np++;
+
+    //hPtResolutionOV->Fill(pt-ptmes);
+    //hPtResolutionRV->Fill(ptRV-ptmesRV);
+    //hPzResolutionOV->Fill(pz-pzmes);
+    //hPzResolutionRV->Fill(pzRV-pzmesRV);
+    
+    sinteta=TMath::Sin(2*TMath::ATan(TMath::Exp(-eta)));
+
+    for(Int_t v=0;v<dipnbin;v++) {
+      if (v*bindip+radice<sinteta&&sinteta<=v*bindip+radice+lenghtbindip) { //printf("Prova2 %d \n",v);
+       
+       for (Int_t k=0;k<nPtBins;k=k+1) {
+         
+         hFitResolutionDipTV[v]->Fill(d0TV-d0True);
+         
+         if(sigmad0All>0.) {
+           hFitResolutionDipRV[v]->Fill(d0All-d0True);
+         }
+         //if(sigmad0Oth>0.) {
+         //  hFitResolutionDipOV[v]->Fill(d0Oth-d0True);
+         //}
+         
+         //Transverse Momentum bin
+         if(ptbinning[(1+kbox)*k]<pt&&pt<=ptbinning[(1+kbox)*k+1]) { //printf("Prova3 %d \n",k/2)
+           if(ptmes!=0.&&pt!=0.) {
+             hFitPtResTV[k]->Fill(ptmes/pt-1.);
+             hFitCurvResTV[k]->Fill(1/ptmes-1/pt);
+           }
+           hFitResolutionTV[v*nPtBins+k]->Fill(d0TV-d0True);
+           hFitResolutionPtTV[k]->Fill(d0TV-d0True);
+           //to calculate resolution on d0z we should have d0zTrue but we haven't. So we ask for the track being primary and then d0zTV is equal to the residual
+           if(TMath::Abs(d0True)<0.1) {
+             hFitd0zResPtTV[k]->Fill(d0zTV);
+             if(sigmad0zTV>0)hFitd0zPullPtTV[k]->Fill(d0zTV/sigmad0zTV);
+           }
+           if(sigmad0TV>0) {
+             hFitPullPtTV[k]->Fill((d0TV-d0True)/sigmad0TV);
+             hFitsigmad0rphiPtTV[k]->Fill(sigmad0TV);
+           }
+           if(sigmad0All>=0.) {
+             hFitResolutionRV[v*nPtBins+k]->Fill(d0All-d0True);        
+             hFitResolutionPtRV[k]->Fill(d0All-d0True);
+             if(sigmad0All>0) {
+               hFitPullPtRV[k]->Fill((d0All-d0True)/sigmad0All);
+               hFitsigmad0rphiPtRV[k]->Fill(sigmad0All);
+             }
+           }
+           /*if(sigmad0Oth>=0.) {
+             hFitResolutionOV[v*nPtBins+k]->Fill(d0Oth-d0True);
+             hFitResolutionPtOV[k]->Fill(d0Oth-d0True);
+             if(sigmad0Oth>0) {
+             hFitPullPtOV[k]->Fill((d0Oth-d0True)/sigmad0Oth);
+             hFitsigmad0rphiPtOV[k]->Fill(sigmad0Oth);
+             }
+             }*/
+           
+           ptbin[k]+=pt;
+           multptbin[k]++;  
+           dipbin[v]+=sinteta;
+           multdipbin[v]++;
+         }
+       }
+      }
+    }
+  }
+
+  printf("Loop on ntuple finished \n");
+
+  /*
+    for (Int_t k=0;k<nPtBins;k++) {
+    for (Int_t j=0;j<dipnbin;j++) {
+    hFitResolutionPtTV[k]->Add(hFitResolutionTV[j*nPtBins+k],1.);
+    hFitResolutionPtRV[k]->Add(hFitResolutionRV[j*nPtBins+k],1.);
+    hFitResolutionPtOV[k]->Add(hFitResolutionOV[j*nPtBins+k],1.);
+    
+    hFitResolutionDipTV[j]->Add(hFitResolutionTV[j*nPtBins+k],1.);
+    hFitResolutionDipRV[j]->Add(hFitResolutionRV[j*nPtBins+k],1.);
+    hFitResolutionDipOV[j]->Add(hFitResolutionOV[j*nPtBins+k],1.);
+    }
+    }
+  */
+  //Loop and Fits
+  gauss->SetRange(-dipinterval,dipinterval);
+  
+  // pt and dip angle binning array for TGraphs: it reproduces the mean pt and angle of the intervals
+  for (Int_t v=0;v<dipnbin;v++) {
+    if (multdipbin[v]!=0) {
+      exdip[v]=0;
+      dipbin[v]=(dipbin[v]/multdipbin[v]);
+      
+      hFitResolutionDipTV[v]->Fit("gauss","N,R");
+      sigmaResolutionDipTV[v]=gauss->GetParameter(2);
+      errsigmResDipTV[v]=gauss->GetParError(2);
+      
+      hFitResolutionDipRV[v]->Fit("gauss","N,R");
+      sigmaResolutionDipRV[v]=gauss->GetParameter(2);
+      errsigmResDipRV[v]=gauss->GetParError(2);
+      
+      hFitResolutionDipOV[v]->Fit("gauss","N,R");
+      sigmaResolutionDipOV[v]=gauss->GetParameter(2);
+      errsigmResDipOV[v]=gauss->GetParError(2);
+      
+      hdipbin[v]=(Float_t)radice+v*bindip;
+    } else {
+      dipbin[v]=radice+v*bindip+lenghtbindip/2.;
+      
+      exdip[v]=0;
+      sigmaResolutionDipTV[v]=0;
+      errsigmResDipTV[v]=0;
+      sigmaResolutionDipRV[v]=0;
+      errsigmResDipRV[v]=0;
+      sigmaResolutionDipOV[v]=0;
+      errsigmResDipTV[v]=0;
+      
+      hdipbin[v]=(Float_t)radice+v*bindip;
+    }
+  }
+  
+  hdipbin[dipnbin]=(Float_t)hdipbin[dipnbin-1]+bindip;
+  
+  for (Int_t j=0;j<nPtBins;j++) {
+    if (multptbin[j]!=0) {
+      ptbin[j]=ptbin[j]/multptbin[j];
+    } else {
+      ptbin[j]=(ptbinning[j]+ptbinning[j+1])/2.;
+    }
+    hptbin[j]=(Float_t)ptbinning[j];
+  }
+  hptbin[nPtBins]=ptbinning[nPtBins];
+  
+  incycle=0; 
+  
+  for (Int_t nint=0;nint<numint;nint++) {      
+    gauss->SetRange(-interval[nint],interval[nint]);
+    for (Int_t k=0;k<nbinning[nint];k++) {
+      ex[k+incycle]=0;
+      rms=hFitPtResTV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitPtResTV[k+incycle]->Fit("gauss","N,R");
+      sigmaPtResTV[k+incycle]=gauss->GetParameter(2);
+      errsigmPtResTV[k+incycle]=gauss->GetParError(2);
+      meanPtResTV[k+incycle]=gauss->GetParameter(1);
+      errmeanPtResTV[k+incycle]=gauss->GetParError(1);
+
+      rms=hFitCurvResTV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitCurvResTV[k+incycle]->Fit("gauss","N,R");
+      sigmaCurvResTV[k+incycle]=gauss->GetParameter(2);
+      errsigmCurvResTV[k+incycle]=gauss->GetParError(2);
+
+      rms=hFitResolutionPtTV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitResolutionPtTV[k+incycle]->Fit("gauss","N,R");
+      sigmaResolutionPtTV[k+incycle]=gauss->GetParameter(2);
+      errsigmResPtTV[k+incycle]=gauss->GetParError(2);
+      meanResolutionPtTV[k+incycle]=gauss->GetParameter(1);
+      errmeanResPtTV[k+incycle]=gauss->GetParError(1);
+      
+      rms=hFitResolutionPtRV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitResolutionPtRV[k+incycle]->Fit("gauss","N,R");
+      sigmaResolutionPtRV[k+incycle]=gauss->GetParameter(2);
+      errsigmResPtRV[k+incycle]=gauss->GetParError(2);
+      
+      rms=hFitResolutionPtOV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitResolutionPtOV[k+incycle]->Fit("gauss","N,R");
+      sigmaResolutionPtOV[k+incycle]=gauss->GetParameter(2); 
+      errsigmResPtOV[k+incycle]=gauss->GetParError(2);
+
+      /*
+      rms=hFitsigmad0rphiPtTV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitsigmad0rphiPtTV[k+incycle]->Fit("gauss","N,R");
+      mediumsigmad0rphiPtTV[k+incycle]=gauss->GetParameter(2);
+      errmediumsigmad0rphiPtTV[k+incycle]=gauss->GetParError(2);*/
+      mediumsigmad0rphiPtTV[k+incycle]=hFitsigmad0rphiPtTV[k+incycle]->GetMean();
+      errmediumsigmad0rphiPtTV[k+incycle]=0;
+      
+      /*
+      rms=hFitsigmad0rphiPtRV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitsigmad0rphiPtRV[k+incycle]->Fit("gauss","N,R");
+      mediumsigmad0rphiPtRV[k+incycle]=gauss->GetParameter(2);
+      errmediumsigmad0rphiPtRV[k+incycle]=gauss->GetParError(2);*/
+      mediumsigmad0rphiPtRV[k+incycle]=hFitsigmad0rphiPtRV[k+incycle]->GetMean();
+      errmediumsigmad0rphiPtRV[k+incycle]=0;
+      
+      /*  
+      rms=hFitsigmad0rphiPtOV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitsigmad0rphiPtOV[k+incycle]->Fit("gauss","N,R");
+      mediumsigmad0rphiPtOV[k+incycle]=gauss->GetParameter(2); 
+      errmediumsigmad0rphiPtOV[k+incycle]=gauss->GetParError(2);*/
+      mediumsigmad0rphiPtOV[k+incycle]=hFitsigmad0rphiPtOV[k+incycle]->GetMean();
+      errmediumsigmad0rphiPtOV[k+incycle]=0;
+
+      rms=hFitPullPtTV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitPullPtTV[k+incycle]->Fit("gauss","N,R");
+      sigmaPullPtTV[k+incycle]=gauss->GetParameter(2);
+      errsigmPullPtTV[k+incycle]=gauss->GetParError(2);
+      
+      rms=hFitPullPtRV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitPullPtRV[k+incycle]->Fit("gauss","N,R");
+      sigmaPullPtRV[k+incycle]=gauss->GetParameter(2);
+      errsigmPullPtRV[k+incycle]=gauss->GetParError(2);
+      
+      rms=hFitPullPtOV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitPullPtOV[k+incycle]->Fit("gauss","N,R");
+      sigmaPullPtOV[k+incycle]=gauss->GetParameter(2); 
+      errsigmPullPtOV[k+incycle]=gauss->GetParError(2);
+
+      rms=hFitd0zResPtTV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitd0zResPtTV[k+incycle]->Fit("gauss","N,R");
+      sigmad0zResPtTV[k+incycle]=gauss->GetParameter(2);
+      errsigmd0zResPtTV[k+incycle]=gauss->GetParError(2);
+
+      rms=hFitd0zPullPtTV[k+incycle]->GetRMS();
+      gauss->SetRange(-3*rms,3*rms);
+      hFitd0zPullPtTV[k+incycle]->Fit("gauss","N,R");
+      sigmad0zPullPtTV[k+incycle]=gauss->GetParameter(2);
+      errsigmd0zPullPtTV[k+incycle]=gauss->GetParError(2);      
+    }
+    incycle+=nbinning[nint];
+  }
+  
+  // hptbin[nPtBins]=hptbin[nPtBins-1]+lenghtbin;
+  
+  
+  hFitResPtDipTV=new TH2F("hFitResPtDipTV","The 3D histogram for Resolution in Pt*sin#theta space",nPtBins,hptbin,dipnbin,hdipbin);
+  hFitResPtDipRV=new TH2F("hFitResPtDipRV","The 3D histogram for Resolution in Pt*sin#theta space",nPtBins,hptbin,dipnbin,hdipbin);
+  hFitResPtDipOV=new TH2F("hFitResPtDipOV","The 3D histogram for Resolution in Pt*sin#theta space",nPtBins,hptbin,dipnbin,hdipbin);
+  
+  
+  for (Int_t v=0;v<dipnbin;v++) { 
+    incycle=0;
+    for (Int_t nint=0;nint<numint;nint++) {    
+      gauss->SetRange(-interval[nint],interval[nint]);
+      for (Int_t k=0;k<nbinning[nint];k++) {
+       //gauss->SetRange(-interval,interval);
+       if(hFitResolutionOV[v*nPtBins+k+incycle]->GetEntries()>1.) {
+         // cout<<"v "<<v<<"ptbin"<<k+incycle<<endl;
+         cout<<hFitResolutionTV[v*nPtBins+k+incycle]->GetEntries()<<endl;
+         hFitResolutionTV[v*nPtBins+k+incycle]->Fit("gauss","N,R");
+         sigmaResolutionTV[v][k+incycle]=gauss->GetParameter(2);
+         hFitResPtDipTV->SetBinContent((k+incycle+1),v+1,sigmaResolutionTV[v][k+incycle]);
+         
+         hFitResolutionRV[v*nPtBins+k+incycle]->Fit("gauss","N,R");
+         sigmaResolutionRV[v][k+incycle]=gauss->GetParameter(2);
+         hFitResPtDipRV->SetBinContent((k+incycle+1),v+1,sigmaResolutionRV[v][k+incycle]);
+         
+         hFitResolutionOV[v*nPtBins+k+incycle]->Fit("gauss","N,R");
+         sigmaResolutionOV[v][k+incycle]=gauss->GetParameter(2);
+         hFitResPtDipOV->SetBinContent((k+incycle+1),v+1,sigmaResolutionOV[v][k+incycle]);
+       } else {
+         sigmaResolutionTV[v][k+incycle]=0;
+         sigmaResolutionRV[v][k+incycle]=0;
+         sigmaResolutionOV[v][k+incycle]=0;
+         hFitResPtDipTV->SetBinContent((k+incycle+1),v+1,sigmaResolutionTV[v][k+incycle]);
+         hFitResPtDipRV->SetBinContent((k+incycle+1),v+1,sigmaResolutionRV[v][k+incycle]);
+         hFitResPtDipOV->SetBinContent((k+incycle+1),v+1,sigmaResolutionOV[v][k+incycle]);
+       }
+      }
+      incycle+=nbinning[nint];
+    }
+  }  
+  
+  printf("###########  Number of good tracks: %d  ###########\n",np);
+  printf("###########  Number of fake tracks: %d  ###########\n",nfaketr);
+
+
+  //-------DRAWING  TGRAPH--------  
+  
+  const int cWidth = 1400;
+  const int cHeight = 800;
+  
+  TCanvas* c0 = new TCanvas("c0","c0",cWidth,cHeight);
+  c0->Divide(3,1);
+  c0->cd(1);
+  gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();    
+  gr0TV = new TGraphErrors(nPtBins,ptbin,sigmaResolutionPtTV,ex,errsigmResPtTV);
+  gr0TV->SetName("mygraphd0TV");
+  gr0TV->SetLineColor(1);
+  gr0TV->SetLineWidth(1);
+  gr0TV->SetMarkerColor(gMarkerColor);
+  gr0TV->SetMarkerStyle(21);
+  gr0TV->SetMarkerSize(1);
+  titlegraph1="d_{0}(r#phi) Resolution  (MC vertex)";
+  gr0TV->SetTitle(titlegraph1);
+  gr0TV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr0TV->GetYaxis()->SetTitle("#sigma [#mu m]");
+  gr0TV->GetXaxis()->SetTitleSize(0.05);
+  gr0TV->GetYaxis()->SetTitleSize(0.05);
+  gr0TV->GetXaxis()->SetLabelSize(0.05);
+  gr0TV->GetYaxis()->SetLabelSize(0.05);
+  gr0TV->Draw("AP");
+
+  c0->cd(3);
+  gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();    
+  TGraphErrors *gr0meanTV = new TGraphErrors(nPtBins,ptbin,meanResolutionPtTV,ex,errmeanResPtTV);
+  gr0meanTV->SetName("mygraphmeand0TV");
+  gr0meanTV->SetLineColor(1);
+  gr0meanTV->SetLineWidth(1);
+  gr0meanTV->SetMarkerColor(gMarkerColor);
+  gr0meanTV->SetMarkerStyle(21);
+  gr0meanTV->SetMarkerSize(1);
+  titlegraph1="Mean of d_{0}(r#phi) residuals  (MC vertex)";
+  gr0meanTV->SetTitle(titlegraph1);
+  gr0meanTV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+  gr0meanTV->GetYaxis()->SetTitle("mean of residuals [#mu m]");
+  gr0meanTV->GetXaxis()->SetTitleSize(0.05);
+  gr0meanTV->GetYaxis()->SetTitleSize(0.05);
+  gr0meanTV->GetXaxis()->SetLabelSize(0.05);
+  gr0meanTV->GetYaxis()->SetLabelSize(0.05);
+  gr0meanTV->Draw("AP");
+  
+  /*
+    TCanvas* c1 = new TCanvas("c1","Resolution analysis dip Angle",cWidth,cHeight);
+    c1->Divide(3,1);
+    c1->cd(1);
+    gr1TV = new TGraphErrors(dipnbin,dipbin,sigmaResolutionDipTV,exdip,errsigmResDipTV);
+    gr1TV->SetName("mygraph1TV");
+    gr1TV->SetLineColor(1);
+    gr1TV->SetLineWidth(1);
+    gr1TV->SetMarkerColor(gMarkerColor);
+    gr1TV->SetMarkerStyle(21);
+    gr1TV->SetMarkerSize(1);
+    titlegraph1="d_{0}(z) Resolution for ";
+    titlegraph1.Append(partforgraph);
+    titlegraph1.Append(" using True Vertex");
+    gr1TV->SetTitle(titlegraph1);
+    gr1TV->GetXaxis()->SetTitle("sin#theta ");
+    gr1TV->GetYaxis()->SetTitle("#sigma [#mu m]");
+    gr1TV->GetXaxis()->SetTitleSize(0.05);
+    gr1TV->GetYaxis()->SetTitleSize(0.05);
+    gr1TV->GetXaxis()->SetLabelSize(0.05);
+    gr1TV->GetYaxis()->SetLabelSize(0.05);
+    gr1TV->GetXaxis()->SetRangeUser(0.7,1);
+    gr1TV->GetYaxis()->SetRangeUser(0,100);
+    gr1TV->Draw("AP");
+    c1->Update();
+        
+    c1->cd(2);
+    // gPad->SetLogy();
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    gr1RV = new TGraphErrors(dipnbin,dipbin,sigmaResolutionDipRV,exdip,errsigmResDipRV);
+    gr1RV->SetName("mygraph1RV");
+    gr1RV->SetLineColor(1);
+    gr1RV->SetLineWidth(1);
+    gr1RV->SetMarkerColor(gMarkerColor);
+    gr1RV->SetMarkerStyle(21);
+    gr1RV->SetMarkerSize(1);
+    titlegraph1="d_{0}(z) Resolution for ";
+    titlegraph1.Append(partforgraph);
+    titlegraph1.Append(" using Reconstructed Vertex");
+    gr1RV->SetTitle(titlegraph1);
+    gr1RV->GetXaxis()->SetTitle("sin#theta ");
+    gr1RV->GetYaxis()->SetTitle("#sigma [#mu m]");
+    gr1RV->GetXaxis()->SetTitleSize(0.05);
+    gr1RV->GetYaxis()->SetTitleSize(0.05);
+    gr1RV->GetXaxis()->SetLabelSize(0.05);
+    gr1RV->GetYaxis()->SetLabelSize(0.05);
+    gr1RV->GetXaxis()->SetRangeUser(0.7,1);
+    gr1RV->GetYaxis()->SetRangeUser(0,100);
+    gr1RV->Draw("AP");
+    c1->Update();
+
+
+  
+    c1->cd(3);
+    // gPad->SetLogy();
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    gr1OV = new TGraphErrors(dipnbin,dipbin,sigmaResolutionDipOV,exdip,errsigmResDipOV);
+    gr1OV->SetName("mygraph1OV");
+    gr1OV->SetLineColor(1);
+    gr1OV->SetLineWidth(1);
+    gr1OV->SetMarkerColor(gMarkerColor);
+    gr1OV->SetMarkerStyle(21);
+    gr1OV->SetMarkerSize(1);
+    titlegraph1="d_{0}(z) Resolution for ";
+    titlegraph1.Append(partforgraph);
+    titlegraph1.Append(" using Vertex on the Fly");
+    gr1OV->SetTitle(titlegraph1);
+    gr1OV->GetXaxis()->SetTitle("sin#theta ");
+    gr1OV->GetYaxis()->SetTitle("#sigma [#mu m]");
+    gr1OV->GetXaxis()->SetTitleSize(0.05);
+    gr1OV->GetYaxis()->SetTitleSize(0.05);
+    gr1OV->GetXaxis()->SetLabelSize(0.05);
+    gr1OV->GetYaxis()->SetLabelSize(0.05);
+    gr1OV->GetXaxis()->SetRangeUser(0.7,1);
+    gr1OV->GetYaxis()->SetRangeUser(0,100);
+    gr1OV->Draw("AP");
+    c1->Update();
+    */    
+
+    TCanvas* c2 = new TCanvas("c2","c2",cWidth,cHeight);
+    c2->Divide(3,1);
+    c2->cd(1);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();    
+    grPullTV = new TGraphErrors(nPtBins,ptbin,sigmaPullPtTV,ex,errsigmPullPtTV);
+    grPullTV->SetName("mygraphPullTV");
+    grPullTV->SetMinimum(0);
+    grPullTV->SetMaximum(1.5);
+    grPullTV->SetLineColor(1);
+    grPullTV->SetLineWidth(1);
+    grPullTV->SetMarkerColor(gMarkerColor);
+    grPullTV->SetMarkerStyle(21);
+    grPullTV->SetMarkerSize(1);
+    titlegraph1="d_{0}(r#phi) Pull  (MC vertex)";
+    grPullTV->SetTitle(titlegraph1);
+    grPullTV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grPullTV->GetYaxis()->SetTitle("");
+    grPullTV->GetXaxis()->SetTitleSize(0.05);
+    grPullTV->GetYaxis()->SetTitleSize(0.05);
+    grPullTV->GetXaxis()->SetLabelSize(0.05);
+    grPullTV->GetYaxis()->SetLabelSize(0.05);
+    grPullTV->Draw("AP");
+    c0->cd(2);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grPullTV->Draw("AP");
+
+    c2->cd(2);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grPullRV = new TGraphErrors(nPtBins,ptbin,sigmaPullPtRV,ex,errsigmPullPtRV);
+    grPullRV->SetName("mygraphPullRV");
+    grPullRV->SetMinimum(0);
+    grPullRV->SetMaximum(1.2);
+    grPullRV->SetLineColor(1);
+    grPullRV->SetLineWidth(1);
+    grPullRV->SetMarkerColor(gMarkerColor);
+    grPullRV->SetMarkerStyle(21);
+    grPullRV->SetMarkerSize(1);
+    titlegraph1="d_{0}(r#phi) Pull for using Reconstructed Vertex";
+    grPullRV->SetTitle(titlegraph1);
+    grPullRV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grPullRV->GetYaxis()->SetTitle("");
+    grPullRV->GetXaxis()->SetTitleSize(0.05);
+    grPullRV->GetYaxis()->SetTitleSize(0.05);
+    grPullRV->GetXaxis()->SetLabelSize(0.05);
+    grPullRV->GetYaxis()->SetLabelSize(0.05);
+    grPullRV->Draw("AP");
+
+    c2->cd(3);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grPullOV = new TGraphErrors(nPtBins,ptbin,sigmaPullPtOV,ex,errsigmPullPtOV);
+    grPullOV->SetName("mygraphPullOV");
+    grPullOV->SetMinimum(0);
+    grPullOV->SetMaximum(1.2);
+    grPullOV->SetLineColor(1);
+    grPullOV->SetLineWidth(1);
+    grPullOV->SetMarkerColor(gMarkerColor);
+    grPullOV->SetMarkerStyle(21);
+    grPullOV->SetMarkerSize(1);
+    titlegraph1="d_{0}(r#phi) Pull using Vertex on the Fly";
+    grPullOV->SetTitle(titlegraph1);
+    grPullOV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grPullOV->GetYaxis()->SetTitle("");
+    grPullOV->GetXaxis()->SetTitleSize(0.05);
+    grPullOV->GetYaxis()->SetTitleSize(0.05);
+    grPullOV->GetXaxis()->SetLabelSize(0.05);
+    grPullOV->GetYaxis()->SetLabelSize(0.05);
+    grPullOV->Draw("AP");
+
+
+    TCanvas* c3 = new TCanvas("c3","c3",cWidth,cHeight);
+    c3->Divide(2,1);   
+    c3->cd(1);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grd0zResTV = new TGraphErrors(nPtBins,ptbin,sigmad0zResPtTV,ex,errsigmd0zResPtTV);
+    grd0zResTV->SetName("mygraphd0zResTV");
+    grd0zResTV->SetLineColor(1);
+    grd0zResTV->SetLineWidth(1);
+    grd0zResTV->SetMarkerColor(gMarkerColor);
+    grd0zResTV->SetMarkerStyle(21);
+    grd0zResTV->SetMarkerSize(1);
+    titlegraph1="d_{0}(z) Resolution  (MC vertex)";
+    grd0zResTV->SetTitle(titlegraph1);
+    grd0zResTV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grd0zResTV->GetYaxis()->SetTitle("#sigma [#mu m]");
+    grd0zResTV->GetXaxis()->SetTitleSize(0.05);
+    grd0zResTV->GetYaxis()->SetTitleSize(0.05);
+    grd0zResTV->GetXaxis()->SetLabelSize(0.05);
+    grd0zResTV->GetYaxis()->SetLabelSize(0.05);
+    grd0zResTV->Draw("AP");
+    c3->cd(2);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grd0zPullTV = new TGraphErrors(nPtBins,ptbin,sigmad0zPullPtTV,ex,errsigmd0zPullPtTV);
+    grd0zPullTV->SetName("mygraphd0zPullTV");
+    grd0zPullTV->SetMinimum(0);
+    grd0zPullTV->SetMaximum(1.5);
+    grd0zPullTV->SetLineColor(1);
+    grd0zPullTV->SetLineWidth(1);
+    grd0zPullTV->SetMarkerColor(gMarkerColor);
+    grd0zPullTV->SetMarkerStyle(21);
+    grd0zPullTV->SetMarkerSize(1);
+    titlegraph1="d_{0}(z) Pull  (MC vertex)";
+    grd0zPullTV->SetTitle(titlegraph1);
+    grd0zPullTV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grd0zPullTV->GetYaxis()->SetTitle("");
+    grd0zPullTV->GetXaxis()->SetTitleSize(0.05);
+    grd0zPullTV->GetYaxis()->SetTitleSize(0.05);
+    grd0zPullTV->GetXaxis()->SetLabelSize(0.05);
+    grd0zPullTV->GetYaxis()->SetLabelSize(0.05);
+    grd0zPullTV->Draw("AP");
+
+    TCanvas* c4 = new TCanvas("c4","c4",cWidth,cHeight);
+    c4->Divide(3,1);
+    c4->cd(1);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grPtResTV = new TGraphErrors(nPtBins,ptbin,sigmaPtResTV,ex,errsigmPtResTV);
+    grPtResTV->SetName("mygraphPtResTV");
+    grPtResTV->SetLineColor(1);
+    grPtResTV->SetLineWidth(1);
+    grPtResTV->SetMarkerColor(gMarkerColor);
+    grPtResTV->SetMarkerStyle(21);
+    grPtResTV->SetMarkerSize(1);
+    titlegraph1="p_{t}mes/p_{t}true - 1 ";
+    grPtResTV->SetTitle(titlegraph1);
+    grPtResTV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grPtResTV->GetYaxis()->SetTitle("#sigma(p_{t}mes/p_{t}true- 1 ) ");
+    grPtResTV->GetXaxis()->SetTitleSize(0.05);
+    grPtResTV->GetYaxis()->SetTitleSize(0.05);
+    grPtResTV->GetXaxis()->SetLabelSize(0.05);
+    grPtResTV->GetYaxis()->SetLabelSize(0.05);
+    grPtResTV->GetYaxis()->SetRangeUser(0,0.025);
+    grPtResTV->Draw("AP");
+    c4->cd(2);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grPtResMeanTV = new TGraphErrors(nPtBins,ptbin,meanPtResTV,ex,errmeanPtResTV);
+    grPtResMeanTV->SetName("mygraphPtResMeanTV");
+    grPtResMeanTV->SetLineColor(1);
+    grPtResMeanTV->SetLineWidth(1);
+    grPtResMeanTV->SetMarkerColor(gMarkerColor);
+    grPtResMeanTV->SetMarkerStyle(21);
+    grPtResMeanTV->SetMarkerSize(1);
+    titlegraph1="p_{t}mes/p_{t}true - 1 ";
+    grPtResMeanTV->SetTitle(titlegraph1);
+    grPtResMeanTV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grPtResMeanTV->GetYaxis()->SetTitle("mean(p_{t}mes/p_{t}true - 1) ");
+    grPtResMeanTV->GetXaxis()->SetTitleSize(0.05);
+    grPtResMeanTV->GetYaxis()->SetTitleSize(0.05);
+    grPtResMeanTV->GetXaxis()->SetLabelSize(0.05);
+    grPtResMeanTV->GetYaxis()->SetLabelSize(0.05);
+    grPtResMeanTV->GetYaxis()->SetRangeUser(0,0.025);
+    grPtResMeanTV->Draw("AP");
+    c4->cd(3);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grCurvResTV = new TGraphErrors(nPtBins,ptbin,sigmaCurvResTV,ex,errsigmCurvResTV);
+    grCurvResTV->SetName("mygraphCurvResTV");
+    grCurvResTV->SetLineColor(1);
+    grCurvResTV->SetLineWidth(1);
+    grCurvResTV->SetMarkerColor(gMarkerColor);
+    grCurvResTV->SetMarkerStyle(21);
+    grCurvResTV->SetMarkerSize(1);
+    titlegraph1="1/p_{t} Resolution ";
+    grCurvResTV->SetTitle(titlegraph1);
+    grCurvResTV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grCurvResTV->GetYaxis()->SetTitle("#sigma(1/p_{t}) [1/(GeV/c)]");
+    grCurvResTV->GetXaxis()->SetTitleSize(0.05);
+    grCurvResTV->GetYaxis()->SetTitleSize(0.05);
+    grCurvResTV->GetXaxis()->SetLabelSize(0.05);
+    grCurvResTV->GetYaxis()->SetLabelSize(0.05);
+    grCurvResTV->Draw("AP");
+
+
+    /*
+    TCanvas* c5 = new TCanvas("c5","Resolution analysis 2",cWidth,cHeight);
+    c5->Divide(3,1);
+    c5->cd(1);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();    
+    grsigmad0rphiTV = new TGraphErrors(nPtBins,ptbin,mediumsigmad0rphiPtTV,ex,errmediumsigmad0rphiPtTV);
+    grsigmad0rphiTV->SetName("mygraphsigmad0rphiTV");
+    grsigmad0rphiTV->SetLineColor(1);
+    grsigmad0rphiTV->SetLineWidth(1);
+    grsigmad0rphiTV->SetMarkerColor(gMarkerColor);
+    grsigmad0rphiTV->SetMarkerStyle(21);
+    grsigmad0rphiTV->SetMarkerSize(1);
+    titlegraph1="d_{0}(r#phi) Resolution Estimated from Cov. Matr (RelateToVtx) for ";
+    titlegraph1.Append(" using TV");
+    grsigmad0rphiTV->SetTitle(titlegraph1);
+    grsigmad0rphiTV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grsigmad0rphiTV->GetYaxis()->SetTitle("#sigma [#mu m]");
+    grsigmad0rphiTV->GetXaxis()->SetTitleSize(0.05);
+    grsigmad0rphiTV->GetYaxis()->SetTitleSize(0.05);
+    grsigmad0rphiTV->GetXaxis()->SetLabelSize(0.05);
+    grsigmad0rphiTV->GetYaxis()->SetLabelSize(0.05);
+    grsigmad0rphiTV->Draw("AP");
+    c5->cd(2);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grsigmad0rphiRV = new TGraphErrors(nPtBins,ptbin,mediumsigmad0rphiPtRV,ex,errmediumsigmad0rphiPtRV);
+    grsigmad0rphiRV->SetName("mygraphsigmad0rphiRV");
+    grsigmad0rphiRV->SetLineColor(1);
+    grsigmad0rphiRV->SetLineWidth(1);
+    grsigmad0rphiRV->SetMarkerColor(gMarkerColor);
+    grsigmad0rphiRV->SetMarkerStyle(21);
+    grsigmad0rphiRV->SetMarkerSize(1);
+    titlegraph1="d_{0}(r#phi) Resolution Estimated from Cov. Matr (RelateToVtx) for ";
+    titlegraph1.Append(" using RVtx");
+    grsigmad0rphiRV->SetTitle(titlegraph1);
+    grsigmad0rphiRV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grsigmad0rphiRV->GetYaxis()->SetTitle("#sigma [#mu m]");
+    grsigmad0rphiRV->GetXaxis()->SetTitleSize(0.05);
+    grsigmad0rphiRV->GetYaxis()->SetTitleSize(0.05);
+    grsigmad0rphiRV->GetXaxis()->SetLabelSize(0.05);
+    grsigmad0rphiRV->GetYaxis()->SetLabelSize(0.05);
+    grsigmad0rphiRV->Draw("AP");
+    c5->cd(3);
+    gPad->SetLogx(); gPad->SetGridx(); gPad->SetGridy();
+    grsigmad0rphiOV = new TGraphErrors(nPtBins,ptbin,mediumsigmad0rphiPtOV,ex,errmediumsigmad0rphiPtOV);
+    grsigmad0rphiOV->SetName("mygraphsigmad0rphiOV");
+    grsigmad0rphiOV->SetLineColor(1);
+    grsigmad0rphiOV->SetLineWidth(1);
+    grsigmad0rphiOV->SetMarkerColor(gMarkerColor);
+    grsigmad0rphiOV->SetMarkerStyle(21);
+    grsigmad0rphiOV->SetMarkerSize(1);
+    titlegraph1="d_{0}(r#phi) Resolution Estimated from Cov. Matr (RelateToVtx) for ";
+    titlegraph1.Append(" using VtxOth");
+    grsigmad0rphiOV->SetTitle(titlegraph1);
+    grsigmad0rphiOV->GetXaxis()->SetTitle("p_{t} [GeV/c] ");
+    grsigmad0rphiOV->GetYaxis()->SetTitle("#sigma [#mu m]");
+    grsigmad0rphiOV->GetXaxis()->SetTitleSize(0.05);
+    grsigmad0rphiOV->GetYaxis()->SetTitleSize(0.05);
+    grsigmad0rphiOV->GetXaxis()->SetLabelSize(0.05);
+    grsigmad0rphiOV->GetYaxis()->SetLabelSize(0.05);
+    grsigmad0rphiOV->Draw("AP");
+    */
+
+
+
+    
+    //---------CLOSE EVRYTHING AND SAVE------------
+   TFile *outfile = new TFile("ResolutionsAnalysis.root","recreate");
+    outfile->cd(); 
+    for (Int_t i=0;i<nPtBins;i++) {
+      hFitResolutionPtTV[i]->Write();
+      hFitResolutionPtRV[i]->Write();
+      hFitResolutionPtOV[i]->Write();
+      delete hFitResolutionPtTV[i];//=0;
+      delete   hFitResolutionPtRV[i];//=0;
+      delete   hFitResolutionPtOV[i];
+      hFitsigmad0rphiPtTV[i]->Write();
+      hFitsigmad0rphiPtRV[i]->Write();
+      hFitsigmad0rphiPtOV[i]->Write();
+      delete hFitsigmad0rphiPtTV[i];//=0;
+      delete   hFitsigmad0rphiPtRV[i];//=0;
+      delete   hFitsigmad0rphiPtOV[i];
+      hFitPullPtTV[i]->Write();
+      hFitPullPtRV[i]->Write();
+      hFitPullPtOV[i]->Write();
+      delete hFitPullPtTV[i];//=0;
+      delete   hFitPullPtRV[i];//=0;
+      delete   hFitPullPtOV[i];
+      hFitd0zResPtTV[i]->Write();
+      hFitd0zPullPtTV[i]->Write();
+      delete hFitd0zResPtTV[i];//=0;
+      delete hFitd0zPullPtTV[i];//=0;
+      hFitPtResTV[i]->Write();
+      hFitCurvResTV[i]->Write();
+      delete hFitPtResTV[i];//=0;
+      delete hFitCurvResTV[i];//=0;
+      for(Int_t j=0;j<dipnbin;j++) {
+       hFitResolutionTV[j*nPtBins+i]->Write();
+       hFitResolutionRV[j*nPtBins+i]->Write();
+       hFitResolutionOV[j*nPtBins+i]->Write();
+       delete  hFitResolutionTV[j*nPtBins+i];//=0;
+       delete hFitResolutionRV[j*nPtBins+i];//=0;
+       delete hFitResolutionOV[j*nPtBins+i];
+      }
+    }
+    for (Int_t i=0;i<dipnbin;i++) {
+      hFitResolutionDipTV[i]->Write();
+      hFitResolutionDipRV[i]->Write();
+      hFitResolutionDipOV[i]->Write();
+      delete hFitResolutionDipTV[i];//=0;
+      delete hFitResolutionDipRV[i];//=0;
+      delete hFitResolutionDipOV[i];//=0;
+    }
+  
+    //    delete hFitResolutionPtTV;
+    hFitResPtDipTV->Write();
+    hFitResPtDipRV->Write();
+    hFitResPtDipOV->Write();
+    delete hFitResPtDipOV;
+    delete hFitResPtDipTV;
+    delete hFitResPtDipRV;
+
+    gr0TV->Write();
+    gr0meanTV->Write();
+    //gr0RV->Write();
+    //gr0OV->Write();
+    //gr1TV->Write();
+    //gr1RV->Write();
+    //gr1OV->Write();
+
+    //grsigmad0rphiTV->Write();
+    //grsigmad0rphiRV->Write();
+    //grsigmad0rphiOV->Write();
+  
+    grd0zResTV->Write();
+    grd0zPullTV->Write();
+    grPtResTV->Write();
+    grPtResMeanTV->Write();
+    grCurvResTV->Write();
+    
+
+    grPullTV->Write();
+    grPullRV->Write();
+    //grPullOV->Write();
+    
+    outfile->Close();
+    
+    return; 
+}
+//-----------------------------------------------------------------------------
+Int_t ITSnCluster(Int_t ITSf) {
+
+  Int_t nTPCclusters = (Int_t)(ITSf/1000);
+  ITSf -= nTPCclusters*1000;
+  Int_t sign,aITSf,n0,n3,aux,ITSsel;//be careful!:working with integer!
+  n0=0;
+  n3=0;
+  aITSf=TMath::Abs(ITSf);
+  if(aITSf==0)sign=0;
+  else if (aITSf==ITSf)sign=1;
+  else if(aITSf==-ITSf)sign=-1;
+  
+  if (aITSf/100<1)n0++;
+  n3=aITSf/300;
+  aux=(aITSf-(aITSf/100)*100);
+  if(aux/10<1)n0++;
+  n3+=aux/30;
+  aux=(aux-(aux/10)*10);
+  if (aux==0)n0++;
+  n3+=aux/3;
+  ITSsel=3+n3-n0;
+  
+  if(ITSsel>6) {
+    printf("Wrong ITSflag assignment! \n");
+    return 99;
+  }
+  return ITSsel*sign;
+}
+//-----------------------------------------------------------------------------
+Bool_t kITSrefit(Double_t sigmd0TV) {
+  //return TRUE if track was kITSrefit, FALSE otherwise (see AliTrackProperties.C)
+  Bool_t kITSref=kTRUE;
+  if (sigmd0TV<0.)kITSref=kFALSE;
+  return kITSref;
+}
+//-----------------------------------------------------------------------------
+void PlotResolutions() {
+
+  TCanvas *c1a = new TCanvas("c1a","d0 resolution",0,0,800,800);
+  c1a->SetLogx();
+  c1a->SetGridx();
+  c1a->SetGridy();
+  TCanvas *c1b = new TCanvas("c1b","d0 mean",0,0,800,800);
+  c1b->SetLogx();
+  c1b->SetGridx();
+  c1b->SetGridy();
+  TCanvas *c1c = new TCanvas("c1c","d0 pull",0,0,800,800);
+  c1c->SetLogx();
+  c1c->SetGridx();
+  c1c->SetGridy();
+
+  TCanvas *c2a = new TCanvas("c2a","z0 resolution",0,0,800,800);
+  c2a->SetLogx();
+  c2a->SetGridx();
+  c2a->SetGridy();
+  TCanvas *c2c = new TCanvas("c2c","z0 pull",0,0,800,800);
+  c2c->SetLogx();
+  c2c->SetGridx();
+  c2c->SetGridy();
+
+  TCanvas *c3a = new TCanvas("c3a","pt resolution",0,0,800,800);
+  c3a->SetLogx();
+  c3a->SetGridx();
+  c3a->SetGridy();
+  TCanvas *c3b = new TCanvas("c3b","pt mean",0,0,800,800);
+  c3b->SetLogx();
+  c3b->SetGridx();
+  c3b->SetGridy();
+
+  TCanvas *c4 = new TCanvas("c4","d0 residuals",0,0,800,800);
+  c4->Divide(3,3);
+  c4_1->SetLogy();
+  c4_2->SetLogy();
+  c4_3->SetLogy();
+  c4_4->SetLogy();
+  c4_5->SetLogy();
+  c4_6->SetLogy();
+  c4_7->SetLogy();
+  c4_8->SetLogy();
+  c4_9->SetLogy();
+
+  TCanvas *c5 = new TCanvas("c5","pt residuals",0,0,800,800);
+  c5->Divide(3,3);
+  c5_1->SetLogy();
+  c5_2->SetLogy();
+  c5_3->SetLogy();
+  c5_4->SetLogy();
+  c5_5->SetLogy();
+  c5_6->SetLogy();
+  c5_7->SetLogy();
+  c5_8->SetLogy();
+  c5_9->SetLogy();
+
+
+  TLegend *leg1=new TLegend(0.5,0.5,0.9,0.9);
+  leg1->SetFillStyle(0);
+  leg1->SetBorderSize(0);
+  TLegend *leg2=new TLegend(0.5,0.5,0.9,0.9);
+  leg2->SetFillStyle(0);
+  leg2->SetBorderSize(0);
+  TGraph *mark20=new TGraph();
+  mark20->SetMarkerColor(4);
+  mark20->SetLineColor(4);
+  mark20->SetMarkerStyle(20);
+  leg1->AddEntry(mark20,"pions","p");
+  leg2->AddEntry(mark20,"pions","l");
+  TGraph *mark21=new TGraph();
+  mark21->SetMarkerColor(2);
+  mark21->SetLineColor(2);
+  mark21->SetMarkerStyle(21);
+  leg1->AddEntry(mark21,"electrons","p");
+  leg2->AddEntry(mark21,"electrons","l");
+  TGraph *mark25=new TGraph();
+  mark25->SetMarkerColor(1);
+  mark25->SetLineColor(1);
+  mark25->SetMarkerStyle(25);
+  leg1->AddEntry(mark25,"electrons (no brem)","p");
+  leg2->AddEntry(mark25,"electrons (no brem)","l");
+  TGraph *mark22=new TGraph();
+  mark22->SetMarkerColor(6);
+  mark22->SetLineColor(6);
+  mark22->SetMarkerStyle(22);
+  leg1->AddEntry(mark22,"kaons","p");
+  leg2->AddEntry(mark22,"kaons","l");
+  TGraph *mark23=new TGraph();
+  mark23->SetMarkerColor(8);
+  mark23->SetLineColor(8);
+  mark23->SetMarkerStyle(23);
+  leg1->AddEntry(mark23,"protons","p");
+  leg2->AddEntry(mark23,"protons","l");
+
+  // pions
+  TFile *f1=new TFile("boxPiv416Release_zero/ResolutionsAnalysis_Pi.root");
+  c1a->cd();
+  mygraphd0TV->Draw("a,p");
+  mygraphd0TV->SetMarkerColor(4);
+  mygraphd0TV->SetMarkerStyle(20);
+  leg1->Draw();
+  c1b->cd();
+  mygraphmeand0TV->Draw("a,p");
+  mygraphmeand0TV->SetMarkerColor(4);
+  mygraphmeand0TV->SetMarkerStyle(20);
+  leg1->Draw();
+  c1c->cd();
+  mygraphPullTV->Draw("a,p");
+  mygraphPullTV->SetMarkerColor(4);
+  mygraphPullTV->SetMarkerStyle(20);
+  leg1->Draw();
+  c2a->cd();
+  mygraphd0zResTV->Draw("a,p");
+  mygraphd0zResTV->SetMarkerColor(4);
+  mygraphd0zResTV->SetMarkerStyle(20);
+  leg1->Draw();
+  c2c->cd();
+  mygraphd0zPullTV->Draw("a,p");
+  mygraphd0zPullTV->SetMarkerColor(4);
+  mygraphd0zPullTV->SetMarkerStyle(20);
+  leg1->Draw();
+  c3a->cd();
+  mygraphPtResTV->Draw("a,p");
+  mygraphPtResTV->SetMarkerColor(4);
+  mygraphPtResTV->SetMarkerStyle(20);
+  leg1->Draw();
+  c3b->cd();
+  mygraphPtResMeanTV->Draw("a,p");
+  mygraphPtResMeanTV->SetMarkerColor(4);
+  mygraphPtResMeanTV->SetMarkerStyle(20);
+  leg1->Draw();
+  c4->cd(1);
+  d0PtResolution0binTV->Draw();
+  d0PtResolution0binTV->SetLineColor(4);
+  c4->cd(2);
+  d0PtResolution1binTV->Draw();
+  d0PtResolution1binTV->SetLineColor(4);
+  c4->cd(3);
+  d0PtResolution2binTV->Draw();
+  d0PtResolution2binTV->SetLineColor(4);
+  c4->cd(4);
+  d0PtResolution3binTV->Draw();
+  d0PtResolution3binTV->SetLineColor(4);
+  c4->cd(5);
+  d0PtResolution4binTV->Draw();
+  d0PtResolution4binTV->SetLineColor(4);
+  c4->cd(6);
+  d0PtResolution5binTV->Draw();
+  d0PtResolution5binTV->SetLineColor(4);
+  c4->cd(7);
+  d0PtResolution6binTV->Draw();
+  d0PtResolution6binTV->SetLineColor(4);
+  c4->cd(8);
+  d0PtResolution7binTV->Draw();
+  d0PtResolution7binTV->SetLineColor(4);
+  c4->cd(9);
+  d0PtResolution8binTV->Draw();
+  d0PtResolution8binTV->SetLineColor(4);
+  leg2->Draw();
+  c5->cd(1);
+  PtResolution0binTV->Draw();
+  PtResolution0binTV->SetLineColor(4);
+  c5->cd(2);
+  PtResolution1binTV->Draw();
+  PtResolution1binTV->SetLineColor(4);
+  c5->cd(3);
+  PtResolution2binTV->Draw();
+  PtResolution2binTV->SetLineColor(4);
+  c5->cd(4);
+  PtResolution3binTV->Draw();
+  PtResolution3binTV->SetLineColor(4);
+  c5->cd(5);
+  PtResolution4binTV->Draw();
+  PtResolution4binTV->SetLineColor(4);
+  c5->cd(6);
+  PtResolution5binTV->Draw();
+  PtResolution5binTV->SetLineColor(4);
+  c5->cd(7);
+  PtResolution6binTV->Draw();
+  PtResolution6binTV->SetLineColor(4);
+  c5->cd(8);
+  PtResolution7binTV->Draw();
+  PtResolution7binTV->SetLineColor(4);
+  c5->cd(9);
+  PtResolution8binTV->Draw();
+  PtResolution8binTV->SetLineColor(4);
+  leg2->Draw();
+
+
+
+  // kaons
+  TFile *f3=new TFile("boxKav416Release_zero/ResolutionsAnalysis_Ka.root");
+  c1a->cd();
+  mygraphd0TV->Draw("p");
+  mygraphd0TV->SetMarkerColor(6);
+  mygraphd0TV->SetMarkerStyle(22);
+  c1b->cd();
+  mygraphmeand0TV->Draw("p");
+  mygraphmeand0TV->SetMarkerColor(6);
+  mygraphmeand0TV->SetMarkerStyle(22);
+  c1c->cd();
+  mygraphPullTV->Draw("p");
+  mygraphPullTV->SetMarkerColor(6);
+  mygraphPullTV->SetMarkerStyle(22);
+  c2a->cd();
+  mygraphd0zResTV->Draw("p");
+  mygraphd0zResTV->SetMarkerColor(6);
+  mygraphd0zResTV->SetMarkerStyle(22);
+  c2c->cd();
+  mygraphd0zPullTV->Draw("p");
+  mygraphd0zPullTV->SetMarkerColor(6);
+  mygraphd0zPullTV->SetMarkerStyle(22);
+  c3a->cd();
+  mygraphPtResTV->Draw("p");
+  mygraphPtResTV->SetMarkerColor(6);
+  mygraphPtResTV->SetMarkerStyle(22);
+  c3b->cd();
+  mygraphPtResMeanTV->Draw("p");
+  mygraphPtResMeanTV->SetMarkerColor(6);
+  mygraphPtResMeanTV->SetMarkerStyle(22);
+  c4->cd(1);
+  d0PtResolution0binTV->Draw("same");
+  d0PtResolution0binTV->SetLineColor(6);
+  c4->cd(2);
+  d0PtResolution1binTV->Draw("same");
+  d0PtResolution1binTV->SetLineColor(6);
+  c4->cd(3);
+  d0PtResolution2binTV->Draw("same");
+  d0PtResolution2binTV->SetLineColor(6);
+  c4->cd(4);
+  d0PtResolution3binTV->Draw("same");
+  d0PtResolution3binTV->SetLineColor(6);
+  c4->cd(5);
+  d0PtResolution4binTV->Draw("same");
+  d0PtResolution4binTV->SetLineColor(6);
+  c4->cd(6);
+  d0PtResolution5binTV->Draw("same");
+  d0PtResolution5binTV->SetLineColor(6);
+  c4->cd(7);
+  d0PtResolution6binTV->Draw("same");
+  d0PtResolution6binTV->SetLineColor(6);
+  c4->cd(8);
+  d0PtResolution7binTV->Draw("same");
+  d0PtResolution7binTV->SetLineColor(6);
+  c4->cd(9);
+  d0PtResolution8binTV->Draw("same");
+  d0PtResolution8binTV->SetLineColor(6);
+  c5->cd(1);
+  PtResolution0binTV->Draw("same");
+  PtResolution0binTV->SetLineColor(6);
+  c5->cd(2);
+  PtResolution1binTV->Draw("same");
+  PtResolution1binTV->SetLineColor(6);
+  c5->cd(3);
+  PtResolution2binTV->Draw("same");
+  PtResolution2binTV->SetLineColor(6);
+  c5->cd(4);
+  PtResolution3binTV->Draw("same");
+  PtResolution3binTV->SetLineColor(6);
+  c5->cd(5);
+  PtResolution4binTV->Draw("same");
+  PtResolution4binTV->SetLineColor(6);
+  c5->cd(6);
+  PtResolution5binTV->Draw("same");
+  PtResolution5binTV->SetLineColor(6);
+  c5->cd(7);
+  PtResolution6binTV->Draw("same");
+  PtResolution6binTV->SetLineColor(6);
+  c5->cd(8);
+  PtResolution7binTV->Draw("same");
+  PtResolution7binTV->SetLineColor(6);
+  c5->cd(9);
+  PtResolution8binTV->Draw("same");
+  PtResolution8binTV->SetLineColor(6);
+
+
+  // protons
+  TFile *f4=new TFile("boxPrv416Release_zero/ResolutionsAnalysis_Pr.root");
+  c1a->cd();
+  mygraphd0TV->Draw("p");
+  mygraphd0TV->SetMarkerColor(8);
+  mygraphd0TV->SetMarkerStyle(23);
+  c1b->cd();
+  mygraphmeand0TV->Draw("p");
+  mygraphmeand0TV->SetMarkerColor(8);
+  mygraphmeand0TV->SetMarkerStyle(23);
+  c1c->cd();
+  mygraphPullTV->Draw("p");
+  mygraphPullTV->SetMarkerColor(8);
+  mygraphPullTV->SetMarkerStyle(23);
+  c2a->cd();
+  mygraphd0zResTV->Draw("p");
+  mygraphd0zResTV->SetMarkerColor(8);
+  mygraphd0zResTV->SetMarkerStyle(23);
+  c2c->cd();
+  mygraphd0zPullTV->Draw("p");
+  mygraphd0zPullTV->SetMarkerColor(8);
+  mygraphd0zPullTV->SetMarkerStyle(23);
+  c3a->cd();
+  mygraphPtResTV->Draw("p");
+  mygraphPtResTV->SetMarkerColor(8);
+  mygraphPtResTV->SetMarkerStyle(23);
+  c3b->cd();
+  mygraphPtResMeanTV->Draw("p");
+  mygraphPtResMeanTV->SetMarkerColor(8);
+  mygraphPtResMeanTV->SetMarkerStyle(23);
+  c4->cd(1);
+  d0PtResolution0binTV->Draw("same");
+  d0PtResolution0binTV->SetLineColor(8);
+  c4->cd(2);
+  d0PtResolution1binTV->Draw("same");
+  d0PtResolution1binTV->SetLineColor(8);
+  c4->cd(3);
+  d0PtResolution2binTV->Draw("same");
+  d0PtResolution2binTV->SetLineColor(8);
+  c4->cd(4);
+  d0PtResolution3binTV->Draw("same");
+  d0PtResolution3binTV->SetLineColor(8);
+  c4->cd(5);
+  d0PtResolution4binTV->Draw("same");
+  d0PtResolution4binTV->SetLineColor(8);
+  c4->cd(6);
+  d0PtResolution5binTV->Draw("same");
+  d0PtResolution5binTV->SetLineColor(8);
+  c4->cd(7);
+  d0PtResolution6binTV->Draw("same");
+  d0PtResolution6binTV->SetLineColor(8);
+  c4->cd(8);
+  d0PtResolution7binTV->Draw("same");
+  d0PtResolution7binTV->SetLineColor(8);
+  c4->cd(9);
+  d0PtResolution8binTV->Draw("same");
+  d0PtResolution8binTV->SetLineColor(8);
+  c5->cd(1);
+  PtResolution0binTV->Draw("same");
+  PtResolution0binTV->SetLineColor(8);
+  c5->cd(2);
+  PtResolution1binTV->Draw("same");
+  PtResolution1binTV->SetLineColor(8);
+  c5->cd(3);
+  PtResolution2binTV->Draw("same");
+  PtResolution2binTV->SetLineColor(8);
+  c5->cd(4);
+  PtResolution3binTV->Draw("same");
+  PtResolution3binTV->SetLineColor(8);
+  c5->cd(5);
+  PtResolution4binTV->Draw("same");
+  PtResolution4binTV->SetLineColor(8);
+  c5->cd(6);
+  PtResolution5binTV->Draw("same");
+  PtResolution5binTV->SetLineColor(8);
+  c5->cd(7);
+  PtResolution6binTV->Draw("same");
+  PtResolution6binTV->SetLineColor(8);
+  c5->cd(8);
+  PtResolution7binTV->Draw("same");
+  PtResolution7binTV->SetLineColor(8);
+  c5->cd(9);
+  PtResolution8binTV->Draw("same");
+  PtResolution8binTV->SetLineColor(8);
+
+
+  // electrons
+  TFile *f2=new TFile("boxElv416Release_zero/ResolutionsAnalysis_El.root");
+  c1a->cd();
+  mygraphd0TV->Draw("p");
+  mygraphd0TV->SetMarkerColor(2);
+  mygraphd0TV->SetMarkerStyle(21);
+  c1b->cd();
+  mygraphmeand0TV->Draw("p");
+  mygraphmeand0TV->SetMarkerColor(2);
+  mygraphmeand0TV->SetMarkerStyle(21);
+  c1c->cd();
+  mygraphPullTV->Draw("p");
+  mygraphPullTV->SetMarkerColor(2);
+  mygraphPullTV->SetMarkerStyle(21);
+  c2a->cd();
+  mygraphd0zResTV->Draw("p");
+  mygraphd0zResTV->SetMarkerColor(2);
+  mygraphd0zResTV->SetMarkerStyle(21);
+  c2c->cd();
+  mygraphd0zPullTV->Draw("p");
+  mygraphd0zPullTV->SetMarkerColor(2);
+  mygraphd0zPullTV->SetMarkerStyle(21);
+  c3a->cd();
+  mygraphPtResTV->Draw("p");
+  mygraphPtResTV->SetMarkerColor(2);
+  mygraphPtResTV->SetMarkerStyle(21);
+  c3b->cd();
+  mygraphPtResMeanTV->Draw("p");
+  mygraphPtResMeanTV->SetMarkerColor(2);
+  mygraphPtResMeanTV->SetMarkerStyle(21);
+  c4->cd(1);
+  d0PtResolution0binTV->Draw("same");
+  d0PtResolution0binTV->SetLineColor(2);
+  c4->cd(2);
+  d0PtResolution1binTV->Draw("same");
+  d0PtResolution1binTV->SetLineColor(2);
+  c4->cd(3);
+  d0PtResolution2binTV->Draw("same");
+  d0PtResolution2binTV->SetLineColor(2);
+  c4->cd(4);
+  d0PtResolution3binTV->Draw("same");
+  d0PtResolution3binTV->SetLineColor(2);
+  c4->cd(5);
+  d0PtResolution4binTV->Draw("same");
+  d0PtResolution4binTV->SetLineColor(2);
+  c4->cd(6);
+  d0PtResolution5binTV->Draw("same");
+  d0PtResolution5binTV->SetLineColor(2);
+  c4->cd(7);
+  d0PtResolution6binTV->Draw("same");
+  d0PtResolution6binTV->SetLineColor(2);
+  c4->cd(8);
+  d0PtResolution7binTV->Draw("same");
+  d0PtResolution7binTV->SetLineColor(2);
+  c4->cd(9);
+  d0PtResolution8binTV->Draw("same");
+  d0PtResolution8binTV->SetLineColor(2);
+  c5->cd(1);
+  PtResolution0binTV->Draw("same");
+  PtResolution0binTV->SetLineColor(2);
+  c5->cd(2);
+  PtResolution1binTV->Draw("same");
+  PtResolution1binTV->SetLineColor(2);
+  c5->cd(3);
+  PtResolution2binTV->Draw("same");
+  PtResolution2binTV->SetLineColor(2);
+  c5->cd(4);
+  PtResolution3binTV->Draw("same");
+  PtResolution3binTV->SetLineColor(2);
+  c5->cd(5);
+  PtResolution4binTV->Draw("same");
+  PtResolution4binTV->SetLineColor(2);
+  c5->cd(6);
+  PtResolution5binTV->Draw("same");
+  PtResolution5binTV->SetLineColor(2);
+  c5->cd(7);
+  PtResolution6binTV->Draw("same");
+  PtResolution6binTV->SetLineColor(2);
+  c5->cd(8);
+  PtResolution7binTV->Draw("same");
+  PtResolution7binTV->SetLineColor(2);
+  c5->cd(9);
+  PtResolution8binTV->Draw("same");
+  PtResolution8binTV->SetLineColor(2);
+
+  // electrons, no bremsstrahlung
+  TFile *f2=new TFile("boxElv416Release_zero/ResolutionsAnalysis_ElNoBrem.root");
+  c1a->cd();
+  mygraphd0TV->Draw("p");
+  mygraphd0TV->SetMarkerColor(1);
+  mygraphd0TV->SetMarkerStyle(25);
+  c1b->cd();
+  mygraphmeand0TV->Draw("p");
+  mygraphmeand0TV->SetMarkerColor(1);
+  mygraphmeand0TV->SetMarkerStyle(25);
+  c1c->cd();
+  mygraphPullTV->Draw("p");
+  mygraphPullTV->SetMarkerColor(1);
+  mygraphPullTV->SetMarkerStyle(25);
+  c2a->cd();
+  mygraphd0zResTV->Draw("p");
+  mygraphd0zResTV->SetMarkerColor(1);
+  mygraphd0zResTV->SetMarkerStyle(25);
+  c2c->cd();
+  mygraphd0zPullTV->Draw("p");
+  mygraphd0zPullTV->SetMarkerColor(1);
+  mygraphd0zPullTV->SetMarkerStyle(25);
+  c3a->cd();
+  mygraphPtResTV->Draw("p");
+  mygraphPtResTV->SetMarkerColor(1);
+  mygraphPtResTV->SetMarkerStyle(25);
+  c3b->cd();
+  mygraphPtResMeanTV->Draw("p");
+  mygraphPtResMeanTV->SetMarkerColor(1);
+  mygraphPtResMeanTV->SetMarkerStyle(25);
+  c4->cd(1);
+  d0PtResolution0binTV->Draw("same");
+  d0PtResolution0binTV->SetLineColor(1);
+  c4->cd(2);
+  d0PtResolution1binTV->Draw("same");
+  d0PtResolution1binTV->SetLineColor(1);
+  c4->cd(3);
+  d0PtResolution2binTV->Draw("same");
+  d0PtResolution2binTV->SetLineColor(1);
+  c4->cd(4);
+  d0PtResolution3binTV->Draw("same");
+  d0PtResolution3binTV->SetLineColor(1);
+  c4->cd(5);
+  d0PtResolution4binTV->Draw("same");
+  d0PtResolution4binTV->SetLineColor(1);
+  c4->cd(6);
+  d0PtResolution5binTV->Draw("same");
+  d0PtResolution5binTV->SetLineColor(1);
+  c4->cd(7);
+  d0PtResolution6binTV->Draw("same");
+  d0PtResolution6binTV->SetLineColor(1);
+  c4->cd(8);
+  d0PtResolution7binTV->Draw("same");
+  d0PtResolution7binTV->SetLineColor(1);
+  c4->cd(9);
+  d0PtResolution8binTV->Draw("same");
+  d0PtResolution8binTV->SetLineColor(1);
+  c5->cd(1);
+  PtResolution0binTV->Draw("same");
+  PtResolution0binTV->SetLineColor(1);
+  c5->cd(2);
+  PtResolution1binTV->Draw("same");
+  PtResolution1binTV->SetLineColor(1);
+  c5->cd(3);
+  PtResolution2binTV->Draw("same");
+  PtResolution2binTV->SetLineColor(1);
+  c5->cd(4);
+  PtResolution3binTV->Draw("same");
+  PtResolution3binTV->SetLineColor(1);
+  c5->cd(5);
+  PtResolution4binTV->Draw("same");
+  PtResolution4binTV->SetLineColor(1);
+  c5->cd(6);
+  PtResolution5binTV->Draw("same");
+  PtResolution5binTV->SetLineColor(1);
+  c5->cd(7);
+  PtResolution6binTV->Draw("same");
+  PtResolution6binTV->SetLineColor(1);
+  c5->cd(8);
+  PtResolution7binTV->Draw("same");
+  PtResolution7binTV->SetLineColor(1);
+  c5->cd(9);
+  PtResolution8binTV->Draw("same");
+  PtResolution8binTV->SetLineColor(1);
+
+
+  return;
+}