コード例 #1
0
ファイル: extractFlowVZERO.C プロジェクト: ktf/AliPhysics
void compareTPCTOF(Int_t icentr,Int_t spec,Int_t arm,Float_t pTh,Int_t addbin){
  LoadLib();
  Float_t ptMaxFit[8] = {20,0.7,0.55,1.2,2,2,2,2};

  TProfile *pTPC = extractFlowVZEROsingle(icentr,spec,arm,0,pTh,addbin,"TPC",0,0,-1,-1+2*(spec!=3)); // TPC && !TOF (TPC PID)
  TProfile *pTPC2 = extractFlowVZEROsingle(icentr,spec,arm,0,pTh,addbin,"TPCextra",2,2,-1,-1+2*(spec!=3)); //TPC && TOF (TPC PID)

  TProfile *pTOF = extractFlowVZEROsingle(icentr,spec,arm,0,pTh,addbin,"TOF",1,1,-1,-1+2*(spec!=3)); //TPC && TOF (TPC&TOF PID)

  if(spec > 0) pTPC->Add(pTPC2);
  else pTPC->Add(pTOF);

  char name[100];
  snprintf(name,100,"NUO_%i",spec);

  hNUO[spec] = pTPC->ProjectionX(name);
  hNUO[spec]->Add(pTOF,-1);

  if(spec && hNUO[0]) hNUO[spec]->Add(hNUO[0],-1);

  if(! kCleanMemory){
    new TCanvas();
    pTPC->Draw();
    pTOF->Draw("SAME");

    new TCanvas();  
    pTPC->SetLineColor(1);
    pTOF->SetLineColor(2);
  }

  hNUO[spec]->Draw();

  if(kCleanMemory){
    if(pTPC) delete pTPC;
    if(pTPC2) delete pTPC2;
    if(pTOF) delete pTOF;
  }
}
コード例 #2
0
ファイル: Getvn.C プロジェクト: XuQiao/phenix
void Getvn(int iangle1, int iangle2, bool usingCNTEP=0){
    TString str;
    int nrun = GetTotalRun();
    std::cout<<"Totally we have "<<nrun<<" runs/segments!"<<std::endl;
    FillGoodRun();
    std::cout<<"Filling Good run finished!"<<std::endl;

    if(nrun<0) exit(1);

     ofstream fout, foutraw, fout1, fout2;
     int iharE=0;
     if(nhar==1) iharE=1;
     TFile *fin;

    cout<<"iangle1 = "<<iangle1<<" iangle2 = "<<iangle2<<endl;

     for(int icent=0;icent<ncent;icent++){
      for(int ihar=0;ihar<nhar;ihar++){
       for(int isub=0;isub<nsub;isub++){
        int n = ihar+1.0+iharE;
        str = choosesub(isub);
        TString UseCNTEP;
        if(str=="ABORT") continue;
        if(usingCNTEP)
         UseCNTEP = "UseCNTEP";
        else
         UseCNTEP = "NoUseCNTEP";
        std::cout<<UseCNTEP<<std::endl;
        std::cout<<"starting doing "<<str<<" v"<<n<<" analysis!"<<std::endl;
         fout1.open(Form("Result/%s/res_%d%d_%d_%d_%s.dat",UseCNTEP.Data(),iangle1,iangle2,n,icent,str.Data())); //using str as event plane detector
         fout2.open(Form("Result/%s/psi_%d%d_%d_%d_%s.dat",UseCNTEP.Data(),iangle1,iangle2,n,icent,str.Data())); //using str as event plane detector
         float reso = GetReso(iangle1, iangle2, icent,ihar,isub,usingCNTEP);
         fout1<<reso<<std::endl;
         if(reso<=0) {std::cout<<"resolution is wrong!"<<std::endl; reso = 1.0;}
        for(int irun=0;irun<nrun;irun++){
         fout2<<GetRun(irun)<<" "<<GoodRunFit[icent][ihar][isub][irun]<<std::endl;
        }
         TH1D* hvobsall = new TH1D(Form("hvobsall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobsall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6);
         TH1D* hvobsallsq = new TH1D(Form("hvobsallsq_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobsallsq_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6);
         TH1D* hvobs2all = new TH1D(Form("hvobs2all_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobs2all_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6);

        for(int iphi=0;iphi<nphi+1;iphi++){
         TH1D* hvobs = new TH1D(Form("hvobs_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobs_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6);
         TH1D* hvobssq = new TH1D(Form("hvobssq_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobssq_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6);
         TH1D* hvobs2 = new TH1D(Form("hvobs2_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobs2_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6);
         string phistr = (iphi==0)?"_east":"_west";
         if(iphi==nphi) phistr = "";
         cout<<"open v2 file"<<endl;
         fout.open(Form("Result/%s/v%d_%d%d_%d%s_%s.dat",UseCNTEP.Data(),n,iangle1,iangle2,icent,phistr.c_str(),str.Data())); //using str as event plane detector
         cout<<"open v2raw file"<<endl;
         foutraw.open(Form("Result/%s/v%draw_%d%d_%d%s_%s.dat",UseCNTEP.Data(),n,iangle1,iangle2,icent,phistr.c_str(),str.Data())); //using str as event plane detector
         if(iphi<nphi){
        for(int irun=0;irun<nrun;irun++){
         //std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<irun<<" "<<phistr<<std::endl;
         fin = TFile::Open(Form("/phenix/plhf/xuq/taxi/%s%s/%d/data/%s.root",dataset.Data(),pro.Data(),taxi,GetRun(irun).Data()));
         if(!(GoodRunFit[icent][ihar][isub][irun]>0.2 && GoodRunFit[icent][ihar][isub][irun]<3.0)){
         std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<GetRun(irun)<<" is bad run!"<<std::endl;
         fin->Close();
        continue;
         }
         TProfile* hvobstemp = (TProfile*)fin->Get(Form("vobs%s_%d_%d_%d_%d_%d",str.Data(),iangle1,iangle2,icent,ihar,iphi));
         TProfile* hvobssqtemp = (TProfile*)fin->Get(Form("vobs%ssq_%d_%d_%d_%d_%d",str.Data(),iangle1,iangle2,icent,ihar,iphi));
         TH1D* hvobssumtemp = (TH1D*)hvobstemp->ProjectionX(Form("vobssum%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"W");
         TH1D* hvobssqsumtemp = (TH1D*)hvobssqtemp->ProjectionX(Form("vobssqsum%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"W"); //Add weighted v2
         TH1D* hvobssum2temp = (TH1D*)hvobstemp->ProjectionX(Form("vobssum2%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"B");//Add Entries
         hvobs->Add(hvobssumtemp);
         hvobssq->Add(hvobssqsumtemp);
         hvobs2->Add(hvobssum2temp);
         fin->Close();
        }
         }
        hvobsall->Add(hvobs);
        hvobsallsq->Add(hvobssq);
        hvobs2all->Add(hvobs2);
        if(iphi==nphi){
        hvobs = hvobsall;
        hvobssq = hvobsallsq;
        hvobs2 = hvobs2all;
        }
         for(int ipt=0;ipt<npt-1;ipt++){
             int xbinmin = hvobs->GetXaxis()->FindBin(ptbin[ipt]+eps);
             int xbinmax = hvobs->GetXaxis()->FindBin(ptbin[ipt+1]-eps);
           //  std::cout<<xbinmin<<" "<<xbinmax<<std::endl;
           //  std::cout<<ptbin[ipt]<<" "<<ptbin[ipt+1]<<std::endl;
           // TH1F* hvobsProj = (TH1F*)hvobs->ProjectionY(Form("hvobsProj_%d",ipt),xbinmin,xbinmax);
           // TH1F* hvobssqProj = (TH1F*)hvobssq->ProjectionY(Form("hvobssqProj_%d",ipt),xbinmin,xbinmax);
            float Ntracks = hvobs2->Integral(xbinmin,xbinmax);
            float vobs = hvobs->Integral(xbinmin,xbinmax)/Ntracks;
            float vobssq = hvobssq->Integral(xbinmin,xbinmax)/Ntracks;
           // float vobssq = hvobssqProj->GetMean();
            float v = vobs/reso;
//            float verr = hvobsProj->GetRMS()/reso/sqrt(Ntracks);
            float verr = sqrt(vobssq-vobs*vobs)/reso/sqrt(Ntracks);
            TH1D* hvobsclone = (TH1D*)hvobs2->Clone("hvobsclone");
            hvobsclone->GetXaxis()->SetRangeUser(ptbin[ipt],ptbin[ipt+1]);
            float pt = hvobsclone->GetMean();
            fout<<pt<<" "<<v<<" "<<verr<<" "<<std::endl;
            foutraw<<pt<<" "<<vobs<<" "<<verr*reso<<" "<<std::endl;
         }
        fout.close();
        foutraw.close();
         }
        fout1.close();
        fout2.close();
        }
        }
     }

}
コード例 #3
0
ファイル: extractFlowVZERO.C プロジェクト: ktf/AliPhysics
TProfile *extractFlowVZEROsingle(Int_t icentr,Int_t spec,Int_t arm,Bool_t isMC,Float_t pTh,Int_t addbin,const char *nameSp,Float_t detMin,Float_t detMax,Int_t chMin,Int_t chMax){
  LoadLib();

  pTh += 0.00001;

  // NUA correction currently are missing
  char name[100];
  char stringa[200];

  snprintf(name,100,"AnalysisResults.root");
  if(!fo) fo = new TFile(name);
  snprintf(name,100,"contVZEROv%i",arm);
  TList *cont = (TList *) fo->Get(name);

  cont->ls();

  Float_t xMin[5] = {icentr/*centrality bin*/,chMin/*charge*/,pTh/*prob*/,-TMath::Pi()/arm/*Psi*/,detMin/*PID mask*/};
  Float_t xMax[5] = {icentr+addbin,chMax,1.0,TMath::Pi()/arm,detMax};

  cont->ls();

  TProfile *p1 = cont->At(2);
  TProfile *p2 = cont->At(3);
  TProfile *p3 = cont->At(4);

  TH2F *hPsi2DA = cont->At(5);
  TH2F *hPsi2DC = cont->At(6);

  TH1D *hPsiA = hPsi2DA->ProjectionY("PsiA",icentr+1,icentr+addbin+1);
  TH1D *hPsiC = hPsi2DC->ProjectionY("PsiC",icentr+1,icentr+addbin+1);

  if(!fPsi) fPsi = new TF1("fPsi","pol0",-TMath::Pi()/arm,TMath::Pi()/arm);
  hPsiA->Fit(fPsi,"0");
  Float_t offsetA = fPsi->GetParameter(0);
  hPsiC->Fit(fPsi,"0");
  Float_t offsetC = fPsi->GetParameter(0);

  Int_t nbinPsi = hPsiA->GetNbinsX();

  Float_t *NUAcorrA = new Float_t[nbinPsi];
  Float_t *NUAcorrC = new Float_t[nbinPsi];

  for(Int_t i=0;i < nbinPsi;i++){
    NUAcorrA[i] = offsetA/(hPsiA->GetBinContent(i+1));
    NUAcorrC[i] = offsetC/(hPsiC->GetBinContent(i+1));
  }

  Float_t res1=0,res2=0,res3=0; 
  Float_t eres1=0,eres2=0,eres3=0; 

  for(Int_t i = icentr; i <= icentr+addbin;i++){
    if(p1->GetBinError(i+1)){
      eres1 += 1./p1->GetBinError(i+1)/p1->GetBinError(i+1);
      res1 += p1->GetBinContent(i+1)/p1->GetBinError(i+1)/p1->GetBinError(i+1);      
    }
    if(p2->GetBinError(i+1)){
      eres2 += 1./p2->GetBinError(i+1)/p2->GetBinError(i+1);
      res2 += p2->GetBinContent(i+1)/p2->GetBinError(i+1)/p2->GetBinError(i+1);      
    }
    if(p3->GetBinError(i+1)){
      eres3 += 1./p3->GetBinError(i+1)/p3->GetBinError(i+1);
      res3 += p3->GetBinContent(i+1)/p3->GetBinError(i+1)/p3->GetBinError(i+1);      
    }
  }

  res1 /= eres1;
  res2 /= eres2;
  res3 /= eres3;
  
  eres1 = sqrt(1./eres1);
  eres2 = sqrt(1./eres2);
  eres3 = sqrt(1./eres3);

  AliFlowVZEROResults *a = (AliFlowVZEROResults *) cont->At(0);
  AliFlowVZEROResults *b = (AliFlowVZEROResults *) cont->At(1);
  TProfile *pp,*pp2;
  if(kNUAcorr){ // with NUA corrections
    pp = a->GetV2reweight(spec,xMin,xMax,3,NUAcorrA);
    pp2 = b->GetV2reweight(spec,xMin,xMax,3,NUAcorrC);
  }
  else{
    pp = a->GetV2(spec,xMin,xMax);
    pp2 = b->GetV2(spec,xMin,xMax);
  }
  
  Float_t scaling = sqrt(res1*res3/res2);
  if(kVZEROrescorr){
    pp->Scale(1./scaling);
  }

  Float_t err1_2 = eres1*eres1/res1/res1/4 +
    eres2*eres2/res2/res2/4 +
    eres3*eres3/res3/res3/4;
  Float_t err2_2 = err1_2;
  err1_2 /= scaling*scaling;
  printf("resolution V0A = %f +/- %f\n",scaling,err1_2);
  scaling = sqrt(res2*res3/res1);
  err2_2 /= scaling*scaling;
  if(kVZEROrescorr){
    pp2->Scale(1./scaling);
  }
  printf("resolution V0C =%f +/- %f\n",scaling,err2_2);

  pp->SetName("V0A");
  pp2->SetName("V0C");

  if(! kCleanMemory){
    new TCanvas();  
    pp->Draw();
    pp2->Draw("SAME");
  }

  TProfile *pData = new TProfile(*pp);
  pData->Add(pp2);
  snprintf(stringa,100,"%sData",nameSp);
  pData->SetName(stringa);

  TProfile *pMc = NULL;
  
  TProfile *ppMC;
  TProfile *ppMC2;
  
  if(isMC){
    snprintf(name,100,"contVZEROmc");
    cont = (TList *) fo->Get(name);
    cont->ls();
    if(arm == 2){
      AliFlowVZEROResults *c = (AliFlowVZEROResults *) cont->At(0);
      if(! kCleanMemory) c->GetV2(spec,xMin,xMax)->Draw("SAME");
    }
    AliFlowVZEROResults *cA;
    if(fo->Get("contVZEROv2")) cA = (AliFlowVZEROResults *) cont->At(1+2*(arm==3));
    else cA = (AliFlowVZEROResults *) cont->At(0);
    AliFlowVZEROResults *cC;
    if(fo->Get("contVZEROv2")) cC = (AliFlowVZEROResults *) cont->At(2+2*(arm==3));
    else cC = (AliFlowVZEROResults *) cont->At(1);

    TProfile *p1mc = cont->At(5+3*(arm==3));
    TProfile *p2mc = cont->At(6+3*(arm==3));
    TProfile *p3mc = cont->At(7+3*(arm==3));

    Float_t resMC1=0,resMC2=0,resMC3=0; 
    Float_t eresMC1=0,eresMC2=0,eresMC3=0; 

    for(Int_t i = icentr; i <= icentr+addbin;i++){
      if(p1mc->GetBinError(i+1)){
	eresMC1 += 1./p1mc->GetBinError(i+1)/p1mc->GetBinError(i+1);
	resMC1 += p1mc->GetBinContent(i+1)/p1mc->GetBinError(i+1)/p1mc->GetBinError(i+1);      
      }
      if(p2mc->GetBinError(i+1)){
	eresMC2 += 1./p2mc->GetBinError(i+1)/p2mc->GetBinError(i+1);
	resMC2 += p2mc->GetBinContent(i+1)/p2mc->GetBinError(i+1)/p2mc->GetBinError(i+1);      
      }
      if(p3mc->GetBinError(i+1)){
	eresMC3 += 1./p3mc->GetBinError(i+1)/p3mc->GetBinError(i+1);
	resMC3 += p3mc->GetBinContent(i+1)/p3mc->GetBinError(i+1)/p3mc->GetBinError(i+1);      
      }
    }
    
    resMC1 /= eresMC1;
    resMC2 /= eresMC2;
    resMC3 /= eresMC3;
    
    eresMC1 = sqrt(1./eresMC1);
    eresMC2 = sqrt(1./eresMC2);
    eresMC3 = sqrt(1./eresMC3);

    ppMC = cA->GetV2(spec,xMin,xMax);
    ppMC2 = cC->GetV2(spec,xMin,xMax);
    
    scaling = sqrt(resMC1*resMC3/resMC2);
    ppMC->Scale(1./scaling);
  
    err1_2 = eresMC1*eresMC1/resMC1/resMC1/4 +
      eresMC2*eresMC2/resMC2/resMC2/4 +
      eresMC3*eresMC3/resMC3/resMC3/4;
    err2_2 = err1_2;
    err1_2 /= scaling*scaling;
    printf("resolution V0A (MC) = %f +/- %f\n",scaling,err1_2);
    scaling = sqrt(resMC2*resMC3/resMC1);
    err2_2 /= scaling*scaling;
    ppMC2->Scale(1./scaling);
    printf("resolution V0C (MC) =%f +/- %f\n",scaling,err2_2);

    ppMC->SetName("V0Amc");
    ppMC2->SetName("V0Cmc");

    if(! kCleanMemory){
      ppMC->Draw("SAME");
      ppMC2->Draw("SAME");
    }

    pMc = new TProfile(*ppMC);
    pMc->Add(ppMC2);
    snprintf(stringa,100,"%sMC",nameSp);
    pMc->SetName(stringa);
    pMc->SetLineColor(2);
  }

  if(! kCleanMemory){
    new TCanvas();  
    pData->Draw();
  }
  if(pMc && !kCleanMemory){
    pMc->Draw("SAME");
    TH1D *hData = pData->ProjectionX();
    TH1D *hMc = pMc->ProjectionX();
    hData->Divide(hMc);
    new TCanvas();  
    hData->Draw();
  }

  delete[] NUAcorrA;
  delete[] NUAcorrC;

  if(kCleanMemory){
    if(pp) delete pp;
    if(pp2) delete pp2;
    if(ppMC) delete ppMC;
    if(ppMC2) delete ppMC2;
  }

  delete cont;

  if(isMC) return pMc;
  return pData;
}
コード例 #4
0
ファイル: extractFlowVZERO.C プロジェクト: ktf/AliPhysics
void extractFlowVZERO(Int_t icentr,const char *type,Int_t arm,Float_t pTh,Bool_t isMC,Int_t addbin){
  LoadLib();

  char name[100];
  snprintf(name,100,"AnalysisResults%s.root",type);
  if(!fo) fo = new TFile(name);

  new TCanvas();

  Int_t cMin[] = {0,5,10,20,30,40,50,60,70};
  Int_t cMax[] = {5,10,20,30,40,50,60,70,80};

  if(kNUOcorr){ // Compute correction for NUO in TOF
    compareTPCTOF(icentr,0,arm,pTh,addbin);
//     compareTPCTOF(icentr,1,arm,pTh,addbin);
//     compareTPCTOF(icentr,2,arm,pTh,addbin);
//     compareTPCTOF(icentr,3,arm,pTh,addbin);
//     compareTPCTOF(icentr,4,arm,pTh,addbin);
  }

  TProfile *pAll;
  pAll=extractFlowVZEROsingle(icentr,0,arm,0,pTh,addbin,"all",0,1);
  pAll->SetMarkerStyle(24);
  TProfile *pPiTOF,*pPiTPC,*pPiTPC2;
  pPiTOF=extractFlowVZEROsingle(icentr,1,arm,0,pTh,addbin,"piTOF",1,1);
  pPiTPC=extractFlowVZEROsingle(icentr,1,arm,0,pTh,addbin,"piTPC",0,0);
  pPiTPC2=extractFlowVZEROsingle(icentr,1,arm,0,pTh,addbin,"piTPC2",2,2);
  pPiTPC->Add(pPiTPC2);

  TH1D *hPi = pPiTOF->ProjectionX("hPi");
  hPi->SetLineColor(4);
  hPi->SetMarkerColor(4);
  hPi->SetMarkerStyle(20);
  for(Int_t i=1;i <=hPi->GetNbinsX();i++){
    Float_t x = hPi->GetBinCenter(i);
    if(x < 0.2){
      hPi->SetBinContent(i,0);
      hPi->SetBinError(i,0);
    }
    else if(x < 0.5){
      hPi->SetBinContent(i,pPiTPC->GetBinContent(i));
      hPi->SetBinError(i,pPiTPC->GetBinError(i));      
    }
    else{
      if(kNUOcorr){
	hPi->SetBinContent(i,pPiTOF->GetBinContent(i) + hNUO[0]->GetBinContent(i));
	hPi->SetBinError(i,pPiTOF->GetBinError(i));      
      }
      else{
	hPi->SetBinContent(i,pPiTOF->GetBinContent(i));
	hPi->SetBinError(i,pPiTOF->GetBinError(i));      
      }
    }
  }

  TProfile *pElTOF,*pElTPC,*pElTPC2;
  pElTOF=extractFlowVZEROsingle(icentr,4,arm,0,pTh,addbin,"piTOF",1,1);
  pElTPC=extractFlowVZEROsingle(icentr,4,arm,0,pTh,addbin,"piTPC",0,0);
  pElTPC2=extractFlowVZEROsingle(icentr,4,arm,0,pTh,addbin,"piTPC2",2,2);
  pElTPC->Add(pElTPC2);

  TH1D *hEl = pElTOF->ProjectionX("hEl");
  hEl->SetLineColor(6);
  hEl->SetMarkerColor(6);
  hEl->SetMarkerStyle(20);
  for(Int_t i=1;i <=hEl->GetNbinsX();i++){
    Float_t x = hEl->GetBinCenter(i);
    if(x < 0.2){
      hEl->SetBinContent(i,0);
      hEl->SetBinError(i,0);
    }
    else if(x < 0.3){
      hEl->SetBinContent(i,pElTPC->GetBinContent(i));
      hEl->SetBinError(i,pElTPC->GetBinError(i));      
    }
    else{
      if(kNUOcorr){
	hEl->SetBinContent(i,pElTOF->GetBinContent(i) + hNUO[0]->GetBinContent(i));
	hEl->SetBinError(i,pElTOF->GetBinError(i));      
      }
      else{
	hEl->SetBinContent(i,pElTOF->GetBinContent(i));
	hEl->SetBinError(i,pElTOF->GetBinError(i));      
      }
    }
  }

  TProfile *pKTOF,*pKTPC,*pKTPC2;
  pKTOF=extractFlowVZEROsingle(icentr,2,arm,0,pTh,addbin,"kaTOF",1,1);
  pKTPC=extractFlowVZEROsingle(icentr,2,arm,0,pTh,addbin,"kaTPC",0,0);
  pKTPC2=extractFlowVZEROsingle(icentr,2,arm,0,pTh,addbin,"kaTPC2",2,2);
  pKTPC->Add(pKTPC2);

  TH1D *hK = pKTOF->ProjectionX("hKa");
  hK->SetLineColor(1);
  hK->SetMarkerColor(1);
  hK->SetMarkerStyle(21);
  for(Int_t i=1;i <=hK->GetNbinsX();i++){
    Float_t x = hK->GetBinCenter(i);
    if(x < 0.25){
      hK->SetBinContent(i,0);
      hK->SetBinError(i,0);
    }
    else if(x < 0.45){
      hK->SetBinContent(i,pKTPC->GetBinContent(i));
      hK->SetBinError(i,pKTPC->GetBinError(i));      
    }
    else{
      if(kNUOcorr){
	hK->SetBinContent(i,pKTOF->GetBinContent(i) + hNUO[0]->GetBinContent(i));
	hK->SetBinError(i,pKTOF->GetBinError(i));      
      }
      else{
	hK->SetBinContent(i,pKTOF->GetBinContent(i));
	hK->SetBinError(i,pKTOF->GetBinError(i));      
      }
    }
  }

  TProfile *pPrTOF,*pPrTOF2,*pPrTPC,*pPrTPC2;
  pPrTOF=extractFlowVZEROsingle(icentr,3,arm,0,pTh,addbin,"prTOF",1,1,-1,-1);
  pPrTOF2=extractFlowVZEROsingle(icentr,3,arm,0,pTh,addbin,"prTOF2",1,1,-1,1);
  pPrTPC=extractFlowVZEROsingle(icentr,3,arm,0,pTh,addbin,"prTPC",0,0,-1,-1);
  pPrTPC2=extractFlowVZEROsingle(icentr,3,arm,0,pTh,addbin,"prTPC2",2,2,-1,-1);
  pPrTPC->Add(pPrTPC2);

  TH1D *hPr = pPrTOF->ProjectionX("hPr");
  hPr->SetLineColor(2);
  hPr->SetMarkerColor(2);
  hPr->SetMarkerStyle(22);
  for(Int_t i=1;i <=hPr->GetNbinsX();i++){
    Float_t x = hPr->GetBinCenter(i);
    if(x < 0.3){
      hPr->SetBinContent(i,0);
      hPr->SetBinError(i,0);
    }
    else if(x < 1.0){
      hPr->SetBinContent(i,pPrTPC->GetBinContent(i));
      hPr->SetBinError(i,pPrTPC->GetBinError(i));      
    }
    else{
      if(x < 3){
	if(kNUOcorr){
	  hPr->SetBinContent(i,pPrTOF->GetBinContent(i) + hNUO[0]->GetBinContent(i));
	  hPr->SetBinError(i,pPrTOF->GetBinError(i));      
	}
	else{
	  hPr->SetBinContent(i,pPrTOF->GetBinContent(i));
	  hPr->SetBinError(i,pPrTOF->GetBinError(i));      
	}
      }
      else{
	if(kNUOcorr){
	  hPr->SetBinContent(i,pPrTOF2->GetBinContent(i) + hNUO[0]->GetBinContent(i));
	  hPr->SetBinError(i,pPrTOF2->GetBinError(i));      
	}
	else{
	  hPr->SetBinContent(i,pPrTOF2->GetBinContent(i));
	  hPr->SetBinError(i,pPrTOF2->GetBinError(i));      
	}
      }
    }
  }
  
  pAll->Draw();
  hPi->Draw("SAME");
  hK->Draw("SAME");
  hPr->Draw("SAME");


  char name[100];


  // PID correction
  if(kPIDcorr){
    TFile *fPidTOF = new TFile("$ALICE_ROOT/PWGCF/FLOW/other/BayesianPIDcontTPCTOF.root");
    TFile *fPidTPC = new TFile("$ALICE_ROOT/PWGCF/FLOW/other/BayesianPIDcontTPC.root");
    // pi histos
    sprintf(name,"Pi_IDas_Picentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPiPi=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Pi_IDas_Elcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPiEl=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Pi_IDas_Kacentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPiKa=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Pi_IDas_Prcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPiPr=(TH1D *) fPidTOF->Get(name);
    TH1D *hPidAll = new TH1D(*hPidPiPi);
    hPidAll->Add(hPidPiKa);
    hPidAll->Add(hPidPiPr);
    hPidAll->Add(hPidPiEl);
    hPidPiPi->Divide(hPidAll);
    hPidPiKa->Divide(hPidAll);
    hPidPiPr->Divide(hPidAll);
    hPidPiEl->Divide(hPidAll);

    sprintf(name,"Pi_IDas_Picentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPiPiTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Pi_IDas_Elcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPiElTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Pi_IDas_Kacentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPiKaTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Pi_IDas_Prcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPiPrTPC=(TH1D *) fPidTPC->Get(name);
    hPidAll->Reset();
    hPidAll->Add(hPidPiPiTPC);
    hPidAll->Add(hPidPiKaTPC);
    hPidAll->Add(hPidPiPrTPC);
    hPidAll->Add(hPidPiElTPC);
    hPidPiPiTPC->Divide(hPidAll);
    hPidPiKaTPC->Divide(hPidAll);
    hPidPiPrTPC->Divide(hPidAll);
    hPidPiElTPC->Divide(hPidAll);

    // K histos
    sprintf(name,"Ka_IDas_Picentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidKaPi=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Ka_IDas_Elcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidKaEl=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Ka_IDas_Kacentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidKaKa=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Ka_IDas_Prcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidKaPr=(TH1D *) fPidTOF->Get(name);
    hPidAll->Reset();
    hPidAll->Add(hPidKaPi);
    hPidAll->Add(hPidKaKa);
    hPidAll->Add(hPidKaPr);
    hPidAll->Add(hPidKaEl);
    hPidKaPi->Divide(hPidAll);
    hPidKaKa->Divide(hPidAll);
    hPidKaPr->Divide(hPidAll);
    hPidKaEl->Divide(hPidAll);

    sprintf(name,"Ka_IDas_Picentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidKaPiTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Ka_IDas_Elcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidKaElTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Ka_IDas_Kacentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidKaKaTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Ka_IDas_Prcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidKaPrTPC=(TH1D *) fPidTPC->Get(name);
    hPidAll->Reset();
    hPidAll->Add(hPidKaPiTPC);
    hPidAll->Add(hPidKaKaTPC);
    hPidAll->Add(hPidKaPrTPC);
    hPidAll->Add(hPidKaElTPC);
    hPidKaPiTPC->Divide(hPidAll);
    hPidKaKaTPC->Divide(hPidAll);
    hPidKaPrTPC->Divide(hPidAll);
    hPidKaElTPC->Divide(hPidAll);

    // pr histos
    sprintf(name,"Pr_IDas_Picentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPrPi=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Pr_IDas_Elcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPrEl=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Pr_IDas_Kacentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPrKa=(TH1D *) fPidTOF->Get(name);
    sprintf(name,"Pr_IDas_Prcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPrPr=(TH1D *) fPidTOF->Get(name);
    hPidAll->Reset();
    hPidAll->Add(hPidPrPi);
    hPidAll->Add(hPidPrKa);
    hPidAll->Add(hPidPrPr);
    hPidAll->Add(hPidPrEl);
    hPidPrPi->Divide(hPidAll);
    hPidPrKa->Divide(hPidAll);
    hPidPrPr->Divide(hPidAll);
    hPidPrEl->Divide(hPidAll);

    sprintf(name,"Pr_IDas_Picentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPrPiTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Pr_IDas_Elcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPrElTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Pr_IDas_Kacentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPrKaTPC=(TH1D *) fPidTPC->Get(name);
    sprintf(name,"Pr_IDas_Prcentr%i_pth%4.2f",icentr,pTh);
    TH1D *hPidPrPrTPC=(TH1D *) fPidTPC->Get(name);
    hPidAll->Reset();
    hPidAll->Add(hPidPrPiTPC);
    hPidAll->Add(hPidPrKaTPC);
    hPidAll->Add(hPidPrPrTPC);
    hPidAll->Add(hPidPrElTPC);
    hPidPrPiTPC->Divide(hPidAll);
    hPidPrKaTPC->Divide(hPidAll);
    hPidPrPrTPC->Divide(hPidAll);
    hPidPrElTPC->Divide(hPidAll);
 
    for(Int_t k=1;k <=hPi->GetNbinsX();k++){
      Float_t pt = hPi->GetBinCenter(k);
      Float_t xPi=hPi->GetBinContent(k)*hPidPiPi->Interpolate(pt) + hK->GetBinContent(k)*hPidPiKa->Interpolate(pt) + hPr->GetBinContent(k)*hPidPiPr->Interpolate(pt) + hEl->GetBinContent(k)*hPidPiEl->Interpolate(pt);
      if(pt < 0.5)
	xPi=hPi->GetBinContent(k)*hPidPiPiTPC->Interpolate(pt) + hK->GetBinContent(k)*hPidPiKaTPC->Interpolate(pt) + hPr->GetBinContent(k)*hPidPiPrTPC->Interpolate(pt) + hEl->GetBinContent(k)*hPidPiElTPC->Interpolate(pt);
      Float_t xKa=hPi->GetBinContent(k)*hPidKaPi->Interpolate(pt) + hK->GetBinContent(k)*hPidKaKa->Interpolate(pt) + hPr->GetBinContent(k)*hPidKaPr->Interpolate(pt) + hEl->GetBinContent(k)*hPidKaEl->Interpolate(pt);
      if(pt < 0.45)
	xKa=hPi->GetBinContent(k)*hPidKaPiTPC->Interpolate(pt) + hK->GetBinContent(k)*hPidKaKaTPC->Interpolate(pt) + hPr->GetBinContent(k)*hPidKaPrTPC->Interpolate(pt) + hEl->GetBinContent(k)*hPidKaElTPC->Interpolate(pt);
      Float_t xPr=hPi->GetBinContent(k)*hPidPrPi->Interpolate(pt) + hK->GetBinContent(k)*hPidPrKa->Interpolate(pt) + hPr->GetBinContent(k)*hPidPrPr->Interpolate(pt) + hEl->GetBinContent(k)*hPidPrEl->Interpolate(pt);
      if(pt < 1)
	xPr=hPi->GetBinContent(k)*hPidPrPiTPC->Interpolate(pt) + hK->GetBinContent(k)*hPidPrKaTPC->Interpolate(pt) + hPr->GetBinContent(k)*hPidPrPrTPC->Interpolate(pt) + hEl->GetBinContent(k)*hPidPrElTPC->Interpolate(pt);

      hPi->SetBinContent(k,hPi->GetBinContent(k)*2 - xPi);
      hK->SetBinContent(k,hK->GetBinContent(k)*2 - xKa);
      hPr->SetBinContent(k,hPr->GetBinContent(k)*2 - xPr);    
    }
  }


  // antiproton Feed down
  TProfile *pFromLambda = extractFlowVZEROsingle(icentr,11,arm,0,pTh,addbin,"pFromLambda",1,1);
  TProfile *piFromK = extractFlowVZEROsingle(icentr,12,arm,0,pTh,addbin,"piFromK",1,1,1,1);
  TProfile *pFromLambda2 = extractFlowVZEROsingle(icentr,11,arm,0,0.6,addbin,"pFromLambdanoPID",0,1);
  TProfile *piFromK2 = extractFlowVZEROsingle(icentr,12,arm,0,0.6,addbin,"piFromKnoPID",0,1);
  TProfile *piFromK3 = extractFlowVZEROsingle(icentr,12,arm,0,0.6,addbin,"piFromKnoPIDtof",1,1);

  TH1D *hFeedSyst = NULL;

  if(kFEEDcorr){
    hFeedSyst = new TH1D(*hPr);
    hFeedSyst->SetName("hFeedSyst");
    hFeedSyst->Reset();
    for(Int_t k=1;k <=hPr->GetNbinsX();k++){
      Float_t contam = 3.23174e-01 * TMath::Exp(- 9.46743e-01 *  hPr->GetBinCenter(k));
      Float_t corr = contam * pFromLambda->GetBinContent(k)/(1-contam);
      Float_t corrErr = contam * pFromLambda->GetBinError(k)/(1-contam);
      Float_t value = hPr->GetBinContent(k)/(1-contam) - corr;
      Float_t valueErr = hPr->GetBinError(k)/(1-contam);

      hFeedSyst->SetBinContent(k,hPr->GetBinContent(k) - value);
      hFeedSyst->SetBinContent(k,sqrt(corrErr*corrErr + valueErr*valueErr - hPr->GetBinError(k)*hPr->GetBinError(k)));

      hPr->SetBinContent(k,value);
      hPr->SetBinError(k,sqrt(corrErr*corrErr + valueErr*valueErr));

    }
    hFeedSyst->Divide(hPr);
  }
    
  // write output
  snprintf(name,100,"results%03i-%03iv%i_pTh%3.1f%s.root",cMin[icentr],cMax[icentr+addbin],arm,pTh,type);
  TFile *fout = new TFile(name,"RECREATE");
  pAll->ProjectionX()->Write();
  hPi->Write();
  hK->Write();
  hPr->Write();
  if(isMC){
    TH1D *pTmp = extractFlowVZEROsingle(icentr,0,arm,1,pTh,addbin,"allMC",1,1,-1,1)->ProjectionX();
    pTmp->SetLineColor(6);
    pTmp->SetMarkerColor(6);
    pTmp->SetMarkerStyle(24);
    pTmp->Write();
    pTmp = extractFlowVZEROsingle(icentr,1,arm,1,pTh,addbin,"piMC",1,1,-1,1)->ProjectionX();
    pTmp->SetLineColor(4);
    pTmp->SetMarkerColor(4);
    pTmp->SetMarkerStyle(24);
    pTmp->Write();
    pTmp = extractFlowVZEROsingle(icentr,2,arm,1,pTh,addbin,"kaMC",1,1,-1,1)->ProjectionX();
    pTmp->SetLineColor(1);
    pTmp->SetMarkerColor(1);
    pTmp->SetMarkerStyle(25);
    pTmp->Write();
    pTmp = extractFlowVZEROsingle(icentr,3,arm,1,pTh,addbin,"prMC",1,1,-1,-1)->ProjectionX();
    pTmp->SetLineColor(2);
    pTmp->SetMarkerColor(2);
    pTmp->SetMarkerStyle(26);
    pTmp->Write();
  }
  extractFlowVZEROsingle(icentr,2,arm,0,pTh,addbin,"kProf")->Write();
  extractFlowVZEROsingle(icentr,9,arm,0,pTh,addbin,"ks",0,1,1,1)->Write();
  extractFlowVZEROsingle(icentr,9,arm,0,pTh,addbin,"ksMy",0,1,-1,-1)->Write();
  extractFlowVZEROsingle(icentr,10,arm,0,pTh,addbin,"lambda")->Write();
  pFromLambda->Write();
  piFromK->Write();
  pFromLambda2->Write();
  piFromK2->Write();
  piFromK3->Write();
  if(hFeedSyst) hFeedSyst->Write();
  fout->Close();
}
コード例 #5
0
ファイル: normalizeHistos.C プロジェクト: miquork/jetphys
void recurseFile(TDirectory *indir, TDirectory *outdir,
                 double etawid, double etamid) {

  TDirectory *curdir = gDirectory;

  // Automatically go through the list of keys (directories)
  TList *keys = indir->GetListOfKeys();
  TListIter itkey(keys);
  TObject *key, *obj;
  TDirectory *dir;

  while ( (key = itkey.Next()) ) {

    if (_debug) cout << key->GetName() << endl << flush;
    obj = ((TKey*)key)->ReadObj(); assert(obj);
    dir = indir;

    // Found a subdirectory: copy it to output and go deeper
    if (obj->InheritsFrom("TDirectory")) {

      //assert(outdir->mkdir(obj->GetName()));
      outdir->mkdir(obj->GetName());
      assert(outdir->cd(obj->GetName()));
      TDirectory *outdir2 = outdir->GetDirectory(obj->GetName()); assert(outdir2);
      outdir2->cd();

      assert(indir->cd(obj->GetName()));
      TDirectory *indir2 = indir->GetDirectory(obj->GetName());
      indir2->cd();

      // Check if directory name contains information on eta bin width
      float etamin, etamax;
      if ( (sscanf(indir->GetName(),"Eta_%f-%f",&etamin,&etamax)==2)
           && (etamax>etamin) ) {
        etawid = 2.*(etamax-etamin);
        etamid = 0.5*(etamax+etamin);
        //cout << "Eta bin width: " << etawid << flush << endl;
      }

      recurseFile(indir2, outdir2, etawid, etamid);
      //outdir2->Write(); // does this speedup or slow down?
    } // inherits from TDirectory

    // Found a plot: normalize if hpt, then copy to output
    if (obj->InheritsFrom("TH1")) {

      outdir->cd();
      TObject *obj2 = obj->Clone(obj->GetName());

      // Normalize hpt and hselpt histograms
      // Same for hbpt
      if (string(obj2->GetName())=="hpt" ||
          string(obj2->GetName())=="hpt_evt" ||
          string(obj2->GetName())=="hpt_jet" ||
          string(obj2->GetName())=="hpt_pre" ||
          string(obj2->GetName())=="hpt0" ||
          string(obj2->GetName())=="hpt1" ||
          string(obj2->GetName())=="hpt2" ||
          string(obj2->GetName())=="hpt3" ||
          string(obj2->GetName())=="hpt_jk1" ||
          string(obj2->GetName())=="hpt_jk2" ||
          string(obj2->GetName())=="hpt_jk3" ||
          string(obj2->GetName())=="hpt_jk4" ||
          string(obj2->GetName())=="hpt_jk5" ||
          string(obj2->GetName())=="hpt_jk6" ||
          string(obj2->GetName())=="hpt_jk7" ||
          string(obj2->GetName())=="hpt_jk8" ||
          string(obj2->GetName())=="hpt_jk9" ||
          string(obj2->GetName())=="hpt_jk10" ||
          string(obj2->GetName())=="hpt_l1off" ||
          string(obj2->GetName())=="hpt_l1fast" ||
          string(obj2->GetName())=="hpt_plus" ||
          string(obj2->GetName())=="hpt_minus" ||
          string(obj2->GetName())=="hpt0_plus" ||
          string(obj2->GetName())=="hpt0_minus" ||
          string(obj2->GetName())=="hpt_noid" ||
          string(obj2->GetName())=="hpt_noevtid" ||
          string(obj2->GetName())=="hpt_nojetid" ||
          string(obj2->GetName())=="hpt_ak5calo" ||
          string(obj2->GetName())=="hpt_ak5pf" ||
          string(obj2->GetName())=="hpt_evt_ak5pf" ||
          string(obj2->GetName())=="hpt_jet_ak5pf" ||
          string(obj2->GetName())=="hselpt" ||
          string(obj2->GetName())=="hpt_r" ||
          string(obj2->GetName())=="hpt_g" ||
          string(obj2->GetName())=="hpt_gg" ||
          string(obj2->GetName())=="hpt_g0" ||
          string(obj2->GetName())=="hpt_g0tw" ||
          string(obj2->GetName())=="hdjmass" ||
          string(obj2->GetName())=="hdjmass0" ||
          string(obj2->GetName())=="hdjmass0_hgg") {

          cout << "." << flush;

        TH1D *hpt = (TH1D*)obj2;
        bool isgen = TString(obj2->GetName()).Contains("pt_g");
        bool isoth = (TString(obj2->GetName()).Contains("pt_no") ||
                      TString(obj2->GetName()).Contains("djmass") ||
                      TString(obj2->GetName()).Contains("hpt0") ||
                      TString(obj2->GetName()).Contains("l1off") ||
                      TString(obj2->GetName()).Contains("l1fast"));
        bool iscalo = (TString(obj2->GetName()).Contains("_ak5calo"));
        bool ispf5 = (TString(obj2->GetName()).Contains("_ak5pf"));
        bool ispre = (TString(obj2->GetName()).Contains("_pre"));
        bool isjk = (TString(obj2->GetName()).Contains("hpt_jk"));
        bool isjet = (TString(obj2->GetName()).Contains("hpt_jet"));

        TProfile *peff = (TProfile*)dir->Get("peff"); assert(peff);

        TH1D *hlumi = (TH1D*)dir->Get("hlumi"); assert(hlumi);
        TH1D *hlumi0 = (TH1D*)dir->Get("../jt450/hlumi"); assert(hlumi0);
        if (_jp_usetriglumi) {

          TH1D *hlumi_orig = (TH1D*)outdir->FindObject("hlumi_orig");
          if (!hlumi_orig) hlumi_orig = (TH1D*)hlumi->Clone("hlumi_orig");

          // regular prescaled luminosity
          TH1D *hlumi_new = (TH1D*)outdir->FindObject("hlumi");
          if (hlumi_new) hlumi = hlumi_new;
          string strg = dir->GetName();
          double lumi = triglumi[strg];
          for (int i = 1; i != hlumi->GetNbinsX()+1; ++i) {
            hlumi->SetBinContent(i, lumi);
          }

          // unprescaled luminosity
          double lumi0 = triglumi["jt450"];
          for (int i = 1; i != hlumi0->GetNbinsX()+1; ++i) {
            hlumi0->SetBinContent(i, lumi0);
          }
        } // _jp_usetriglumi

        // Test MC-based normalization for trigger efficiency
        bool dotrigeff = ((string(obj2->GetName())=="hpt") || isjk || isjet);
        TH1D *htrigeff = (TH1D*)outdir->FindObject("htrigeff");
        TH1D *htrigeffmc = (TH1D*)outdir->FindObject("htrigeffmc");
        TH1D *htrigeffsf = (TH1D*)outdir->FindObject("htrigeffsf");
        TH1D *hpt_notrigeff = 0;

        if (!htrigeff && _jp_dotrigeff) {

          TFile *fmc = new TFile("output-MC-1.root","READ");
          assert(fmc && !fmc->IsZombie());
          assert(fmc->cd("Standard"));
          fmc->cd("Standard");
          TDirectory *dmc0 = fmc->GetDirectory("Standard");
          //assert(gDirectory->cd(Form("Eta_%1.1f-%1.1f",
          //                 etamid-0.25*etawid,etamid+0.25*etawid)));
          //TDirectory *dmc = gDirectory;
          TDirectory *dmc = dmc0->GetDirectory(Form("Eta_%1.1f-%1.1f",
                                                    etamid-0.25*etawid,etamid+0.25*etawid));
          assert(dmc);
          dmc->cd();

          // Add MC truth based trigger efficiency
          if(!htrigeffmc && dmc->cd(dir->GetName())) {

            TDirectory *dir1 = dmc->GetDirectory(dir->GetName()); assert(dir1);
            TH1D *hpty = (TH1D*)dir1->Get("hpt"); assert(hpty);
            assert(dmc->cd("mc"));
            dmc->cd("mc");
            TDirectory *dir2 = dmc->GetDirectory("mc"); assert(dir2);
            TH1D *hptx = (TH1D*)dir2->Get(Form("hpt_%s",dir->GetName()));

            outdir->cd();
            if (hpty && hptx) htrigeffmc = (TH1D*)hpty->Clone("htrigeffmc");
            if (hpty && hptx) htrigeffmc->Divide(hpty,hptx,1,1,"B");
          }

          // Add data/MC scale factor for trigger efficiency
          if (_nh_dt && !htrigeffsf) {

            assert(dmc->cd(dir->GetName()));
            dmc->cd(dir->GetName());
            TDirectory *dirmc = dmc->GetDirectory(dir->GetName()); assert(dirmc);
            TProfile *pm = (TProfile*)dirmc->Get("ptrigefftp");
            TProfile *pd = (TProfile*)dir->Get("ptrigefftp");

            outdir->cd();
            if (pm && pd) htrigeffsf = pm->ProjectionX("htrigeffsf");
            if (pm && pd) htrigeffsf->Divide(pd,pm,1);
          }

          // Combine MC trigger efficiency and scalefactor
          if (htrigeffmc) { // not available for 'mc' directory
            outdir->cd();
            htrigeff = (TH1D*)htrigeffmc->Clone("htrigeff");
            assert(!_nh_dt || htrigeffsf);
            if (_nh_dt) htrigeff->Multiply(htrigeffsf);

            TH1D *h = (TH1D*)dir->Get("hpt");
            assert(outdir->FindObject("hpt_notrigeff")==0);
            outdir->cd();
            hpt_notrigeff = (TH1D*)h->Clone("hpt_notrigeff");
          }

          fmc->Close();
        } // dotrigeff


        // Scale data to account for time dependence
        bool dotimedep = ((string(obj2->GetName())=="hpt") || isjk || isjet);
        TH1D *htimedep = (TH1D*)outdir->FindObject("htimedep");
        TH1D *htimefit = (TH1D*)outdir->FindObject("htimefit");
        TH1D *hpt_notimedep = 0, *hpt_withtimedep = 0;
        double ktime = 1.;

        if (!htimedep) {

          TH1D *h = (TH1D*)dir->Get("hpt");
          TH1D *hsel = (TH1D*)dir->Get("hselpt");
          TH1D *hpre = (TH1D*)dir->Get("hpt_pre");
          //TH1D *hlumi0 = (TH1D*)dir->Get("../jt450/hlumi");

          // Fix luminosity for unprescaled trigger
          //string strg = dir->GetName();
          //double lum0 = triglumi["jt450"];
          //for (int i = 1; i != hlumi0->GetNbinsX()+1; ++i) {
          //hlumi0->SetBinContent(i, lum0);
          //}

          outdir->cd();
          if (h) hpt_notimedep = (TH1D*)h->Clone("hpt_notimedep");
          if (hpre && h) htimedep = (TH1D*)hpre->Clone("htimedep");
          if (hpre && h) htimedep->Divide(hpre,h);//,1,1,"B");

          // Figure out trigger luminosities
          double lumi = 0;
          if (hlumi) lumi = hlumi->GetBinContent(1);
          double lumi0 = 0;
          if (hlumi0) lumi0 = hlumi0->GetBinContent(1);
          if (htimedep && lumi && lumi0) {
            htimedep->Scale(lumi / lumi0);
          }

          // Find proper pT range and fit
          double minpt = 0.;
          double maxpt = 6500.;
          if (hsel) {
            for (int i = 1; i != hsel->GetNbinsX()+1; ++i) {
              if (hsel->GetBinContent(i)!=0 &&
                  hsel->GetBinLowEdge(i)>=_jp_xmin57) {
                if (minpt<20) minpt = hsel->GetBinLowEdge(i);
                maxpt = hsel->GetBinLowEdge(i+1);
              }
            }
          }
          TF1 *ftmp = new TF1("ftmp","[0]",minpt,maxpt);
          ftmp->SetParameter(0,1);
          if (htimedep && htimedep->Integral()>0) htimedep->Fit(ftmp,"QRN");

          if (htimedep && ftmp->GetParameter(0)>0)
            ktime = 1./ftmp->GetParameter(0);

          if (htimedep) {
            outdir->cd();
            htimefit = (TH1D*)hsel->Clone("htimefit");
            hpt_withtimedep = (TH1D*)h->Clone("hpt_withtimedep");

            for (int i = 1; i != htimefit->GetNbinsX()+1; ++i) {

              if (hsel->GetBinContent(i)!=0) {
                htimefit->SetBinContent(i, ftmp->GetParameter(0));
                htimefit->SetBinError(i, ftmp->GetParError(0));
              }

              // Calculate with time dependence here to add ktime fit error
              hpt_withtimedep->SetBinContent(i, hpt_notimedep->GetBinContent(i)
                                             * htimefit->GetBinContent(i));
              double err1 = hpt_notimedep->GetBinError(i)
                / hpt_notimedep->GetBinContent(i);
              double err2 = htimefit->GetBinError(i)
                / htimefit->GetBinContent(i);
              hpt_withtimedep->SetBinError(i, hpt_notimedep->GetBinContent(i)
                                           * sqrt(pow(err1,2) + pow(err2,2)));
            }
          }
        } // dotimedep


        if (!(hpt->GetNbinsX()==peff->GetNbinsX() || isoth || isgen) ||
            !(hpt->GetNbinsX()==hlumi->GetNbinsX() || isoth || isgen)) {
          cerr << "Hist " << hpt->GetName() << " " << dir->GetName()
               << " Nbins=" << hpt->GetNbinsX() << endl << flush;
          assert(hpt->GetNbinsX()==peff->GetNbinsX() || isoth);
          assert(hpt->GetNbinsX()==hlumi->GetNbinsX() || isoth);
        }

        for (int i = 1; i != hpt->GetNbinsX()+1; ++i) {

          // Normalization for bin width in y, pT
          double norm = hpt->GetBinWidth(i) * etawid;
          double trigeff = 1.;
          double pt = hpt->GetBinCenter(i);
          // Normalization for all the common efficiencies
          if (peff->GetBinContent(i)!=0 && !isgen)
            norm *= peff->GetBinContent(i);
          // Test MC-based normalization for trigger efficiency
          if (dotrigeff && htrigeff && _jp_dotrigeff) {
            if (htrigeff->GetBinContent(i)!=0) {
              trigeff = min(1.,max(0.,htrigeff->GetBinContent(i)));
              if (_jp_dotrigefflowptonly && pt>=114) trigeff = 1;
              norm *= trigeff;
            }
          }

          // Normalization for luminosity
          if (hlumi->GetBinContent(i)!=0 && !isoth && !isgen && !ispre)
            norm *= hlumi->GetBinContent(i);
          if (hlumi->GetBinContent(1)!=0 && isoth && !isgen && !ispre)
            norm *= hlumi->GetBinContent(1);
          if (hlumi0->GetBinContent(1)!=0 && !isoth && !isgen && ispre)
            norm *= hlumi0->GetBinContent(1);

          // Fix luminosity from .csv VTX to lumiCalc vdM
          if (!_nh_mc) norm *= _lumiscale;
          // Scale normalization for jackknife
          if (isjk) norm *= 0.9;

          if (_nh_mc && _jp_pthatbins) norm *= 1.;
          if (_nh_mc && !_jp_pthatbins) {
            norm /= 2500.; //(xsecw / (sumw * adhocw) ); // equals 2551.;
          }

          // Correct data for time-dependence
          double norm_notime = norm;
          if (dotimedep && htimedep && _jp_dotimedep) {
            norm *= ktime;
          }

          if (!(peff->GetBinContent(i)!=0||hpt->GetBinContent(i)==0 || isgen ||
                iscalo || ispf5 || isoth || hpt->GetBinCenter(i)<_jp_recopt
                || hpt->GetBinCenter(i)*cosh(etamid)>3500.)) {
            cerr << "Hist " << hpt->GetName() << " " << dir->GetName()
                 << " pt=" << hpt->GetBinCenter(i)
                 << " etamid = " << etamid << endl << flush;
            assert(peff->GetBinContent(i)!=0||hpt->GetBinContent(i)==0||isgen||
                   hpt->GetBinCenter(i)<_jp_recopt);
          }
          /*
          if (!(hlumi->GetBinContent(i)!=0 || hpt->GetBinContent(i)==0
                || isoth || isgen || hpt->GetBinCenter(i)<_jp_recopt)) {
            cerr << "Hist " << hpt->GetName() << " " << dir->GetName()
                 << " pt=" << hpt->GetBinCenter(i) << endl << flush;
            assert(hlumi->GetBinContent(i)!=0 || hpt->GetBinContent(i)==0
                   || isoth || hpt->GetBinCenter(i)<_jp_recopt);
          }
          */

          assert(norm!=0);
          hpt->SetBinContent(i, hpt->GetBinContent(i) / norm);
          hpt->SetBinError(i, hpt->GetBinError(i) / norm);
          if (hpt_notrigeff) {
            hpt_notrigeff->SetBinContent(i, hpt_notrigeff->GetBinContent(i)
                                         / norm * trigeff);
            hpt_notrigeff->SetBinError(i, hpt_notrigeff->GetBinError(i)
                                       / norm * trigeff);
          }
          if (hpt_notimedep) {
            hpt_notimedep->SetBinContent(i, hpt_notimedep->GetBinContent(i)
                                         / norm_notime);
            hpt_notimedep->SetBinError(i, hpt_notimedep->GetBinError(i)
                                       / norm_notime);
          }
          if (hpt_withtimedep) { // ktime already applied => use norm_notime
            hpt_withtimedep->SetBinContent(i, hpt_withtimedep->GetBinContent(i)
                                           / norm_notime);
            hpt_withtimedep->SetBinError(i, hpt_withtimedep->GetBinError(i)
                                         / norm_notime);
          }
        } // for i

      } // hpt

      dir->cd();
    } // inherits from TH1

  } // while key

  curdir->cd();
} // recurseFile
コード例 #6
0
ファイル: Getvn.C プロジェクト: XuQiao/phenix
void Getvn(int iangle1, int iangle2, bool usingCNTEP=0){
    TString str;
    int nrun = GetTotalRun();
    std::cout<<"Totally we have "<<nrun<<" runs/segments!"<<std::endl;
    FillGoodRun();
    std::cout<<"Filling Good run finished!"<<std::endl;

    if(nrun<0) exit(1);

     ofstream fout, foutraw, fout1, fout2;
     int iharE=0;
     if(nhar==1) iharE=1;
     TFile *fin;

    cout<<"iangle1 = "<<iangle1<<" iangle2 = "<<iangle2<<endl;
    TH1D* hvobs[nphi+np*5+2+2+1];
    TH1D* hvobssq[nphi+np*5+2+2+1];
    TH1D* hvobs2[nphi+np*5+2+2+1];
     for(int icent=0;icent<ncent;icent++){
      for(int ihar=0;ihar<nhar;ihar++){
//          if(ihar!=1) continue;
       for(int isub=0;isub<nsub;isub++){
           if(isub!=7) continue;
        int n = ihar+1.0+iharE;
        str = choosesub(isub);
        TString UseCNTEP;
        if(str=="ABORT") continue;
        if(usingCNTEP)
         UseCNTEP = "UseCNTEP";
        else
         UseCNTEP = "NoUseCNTEP";
        std::cout<<UseCNTEP<<std::endl;
        std::cout<<"starting doing "<<str<<" v"<<n<<" analysis!"<<std::endl;
         fout1.open(Form("Resultfinept/%s/res_%d%d_%d_%d_%s.dat",UseCNTEP.Data(),iangle1,iangle2,n,icent,str.Data())); //using str as event plane detector
         fout2.open(Form("Resultfinept/%s/psi_%d%d_%d_%d_%s.dat",UseCNTEP.Data(),iangle1,iangle2,n,icent,str.Data())); //using str as event plane detector
         float reso = GetReso(iangle1, iangle2, icent,ihar,isub,usingCNTEP);
         fout1<<reso<<std::endl;
         if(reso<=0) {std::cout<<"resolution is wrong!"<<std::endl; reso = 1.0;}
        for(int irun=0;irun<nrun;irun++){
         fout2<<GetRun(irun)<<" "<<GoodRunFit[icent][ihar][isub][irun]<<std::endl;
        }
        // TH1D* hvobsall = new TH1D(Form("hvobsall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobsall_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6);
        // TH1D* hvobsallsq = new TH1D(Form("hvobsallsq_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobsallsq_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6);
        // TH1D* hvobs2all = new TH1D(Form("hvobs2all_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),Form("hvobs2all_%d%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub),60,0,6);

        for(int iphi=0;iphi<nphi+np*5+2+2+1;iphi++){
         hvobs[iphi] = new TH1D(Form("hvobs_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobs_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6);
         hvobssq[iphi] = new TH1D(Form("hvobssq_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobssq_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6);
         hvobs2[iphi] = new TH1D(Form("hvobs2_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),Form("hvobs2_%d%d_%d_%d_%d_%d",iangle1,iangle2,icent,ihar,isub,iphi),60,0,6);
         string pidstr, chstr, phistr, armstr;
         if(iphi % np == 1) pidstr = "_pion";
         if(iphi % np == 2) pidstr = "_kaon";
         if(iphi % np == 3) pidstr = "_proton";
         if(iphi % np == 4) pidstr = "_pionkaon";
         if(iphi % np == 0) pidstr = "_other";
         chstr = ((iphi % (2*np)) < np)?"_neg":"_pos";
         armstr = (iphi < (2*np))?"_east":"_west";
         if(iphi>=nphi && iphi<nphi+np) { chstr = ""; armstr = "east";}
         if(iphi>=nphi+np && iphi<nphi+np*2) { chstr = ""; armstr = "west";}
         if(iphi>=nphi+np*2 && iphi<nphi+np*3) { chstr = "neg"; armstr = "";}
         if(iphi>=nphi+np*3 && iphi<nphi+np*4) { chstr = "pos"; armstr = "";}
         if(iphi>=nphi+np*4 && iphi<nphi+np*5) { chstr = ""; armstr = "";}
         if(iphi>=nphi+np*5 && iphi<nphi+np*5+2) { if(iphi==nphi+np*5) chstr = "_negc"; else chstr = "_posc"; pidstr = "";armstr = "";}
         if(iphi>=nphi+np*5+2 && iphi<nphi+np*5+2+2) { if(iphi==nphi+np*5+2) armstr = "_east"; else armstr = "_west"; pidstr = ""; chstr = "";}
         if(iphi==nphi+np*5+2+2) {chstr = "";pidstr = "";armstr = "";}
         phistr += armstr;
         phistr += chstr;
         phistr += pidstr;
         cout<<"open v2 file"<<endl;
         fout.open(Form("Resultfinept/%s/v%d_%d%d_%d%s_%s.dat",UseCNTEP.Data(),n,iangle1,iangle2,icent,phistr.c_str(),str.Data())); //using str as event plane detector
         cout<<"open v2raw file"<<endl;
         foutraw.open(Form("Resultfinept/%s/v%draw_%d%d_%d%s_%s.dat",UseCNTEP.Data(),n,iangle1,iangle2,icent,phistr.c_str(),str.Data())); //using str as event plane detector
         if(iphi<nphi){
        for(int irun=0;irun<nrun;irun++){
         //std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<irun<<" "<<phistr<<std::endl;
         fin = TFile::Open(Form("/phenix/plhf/xuq/taxi/%s%s/%d/data/%s",dataset.Data(),pro.Data(),taxi,GetRun(irun).Data()));
         if(!(GoodRunFit[icent][ihar][isub][irun]>0.2 && GoodRunFit[icent][ihar][isub][irun]<3.0)){
         std::cout<<"cent = "<<icent<<"; n = "<<n<<" ;isub = "<<str<<" ;run = "<<GetRun(irun)<<" is bad run!"<<std::endl;
         fin->Close();
        continue;
         }
         TProfile *hvobstemp;
         TProfile *hvobssqtemp;
         hvobstemp = (TProfile*)fin->Get(Form("vobs%s_%d_%d_%d_%d_%d",str.Data(),iangle1,iangle2,icent,ihar,iphi));
         hvobssqtemp = (TProfile*)fin->Get(Form("vobs%ssq_%d_%d_%d_%d_%d",str.Data(),iangle1,iangle2,icent,ihar,iphi));
         TH1D* hvobssumtemp = (TH1D*)hvobstemp->ProjectionX(Form("vobssum%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"W");
         TH1D* hvobssqsumtemp = (TH1D*)hvobssqtemp->ProjectionX(Form("vobssqsum%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"W"); //Add weighted v2
         TH1D* hvobssum2temp = (TH1D*)hvobstemp->ProjectionX(Form("vobssum2%s_%d_%d_%d",str.Data(),icent,ihar,iphi),"B");//Add Entries
         hvobs[iphi]->Add(hvobssumtemp);
         hvobssq[iphi]->Add(hvobssqsumtemp);
         hvobs2[iphi]->Add(hvobssum2temp);
         fin->Close();
        }
             if(iphi%np==1 && iphi%np==2){ //pion or Kaon
             hvobs[iphi]->Add(hvobs[4+iphi/np*np]);
             hvobssq[iphi]->Add(hvobssq[4+iphi/np*np]);
             hvobs2[iphi]->Add(hvobs2[4+iphi/np*np]);
             }
         }

         if(iphi>=nphi && iphi<nphi+np){
             hvobs[iphi]->Add(hvobs[iphi-nphi]);
             hvobs[iphi]->Add(hvobs[iphi-nphi+np]);
             hvobssq[iphi]->Add(hvobssq[iphi-nphi]);
             hvobssq[iphi]->Add(hvobssq[iphi-nphi+np]);
             hvobs2[iphi]->Add(hvobs2[iphi-nphi]);
             hvobs2[iphi]->Add(hvobs2[iphi-nphi+np]);
             if(iphi%np==1 && iphi%np==2){ //pion or Kaon
             hvobs[iphi]->Add(hvobs[4]);
             hvobs[iphi]->Add(hvobs[4+np]);
             hvobssq[iphi]->Add(hvobssq[4]);
             hvobssq[iphi]->Add(hvobssq[4+np]);
             hvobs2[iphi]->Add(hvobs2[4]);
             hvobs2[iphi]->Add(hvobs2[4+np]);
             }
         }
         if(iphi>=nphi+np && iphi<nphi+np*2){
             hvobs[iphi]->Add(hvobs[iphi-nphi+np*1]);
             hvobs[iphi]->Add(hvobs[iphi-nphi+np*2]);
             hvobssq[iphi]->Add(hvobssq[iphi-nphi+np*1]);
             hvobssq[iphi]->Add(hvobssq[iphi-nphi+np*2]);
             hvobs2[iphi]->Add(hvobs2[iphi-nphi+np*1]);
             hvobs2[iphi]->Add(hvobs2[iphi-nphi+np*2]);
             if(iphi%np==1 && iphi%np==2){ //pion or Kaon
             hvobs[iphi]->Add(hvobs[14]);
             hvobs[iphi]->Add(hvobs[14+np]);
             hvobssq[iphi]->Add(hvobssq[14]);
             hvobssq[iphi]->Add(hvobssq[14+np]);
             hvobs2[iphi]->Add(hvobs2[14]);
             hvobs2[iphi]->Add(hvobs2[14+np]);
             }
         }

         if(iphi>=nphi+np*2 && iphi<nphi+np*3){
             hvobs[iphi]->Add(hvobs[iphi-nphi-np*2]);
             hvobs[iphi]->Add(hvobs[iphi-nphi]);
             hvobssq[iphi]->Add(hvobssq[iphi-nphi-np*2]);
             hvobssq[iphi]->Add(hvobssq[iphi-nphi]);
             hvobs2[iphi]->Add(hvobs2[iphi-nphi-np*2]);
             hvobs2[iphi]->Add(hvobs2[iphi-nphi]);
             if(iphi%np==1 && iphi%np==2){ //pion or Kaon
             hvobs[iphi]->Add(hvobs[4]);
             hvobs[iphi]->Add(hvobs[4+np*2]);
             hvobssq[iphi]->Add(hvobssq[4]);
             hvobssq[iphi]->Add(hvobssq[4+np*2]);
             hvobs2[iphi]->Add(hvobs2[4]);
             hvobs2[iphi]->Add(hvobs2[4+np*2]);
             }
         }
         if(iphi>=nphi+np*3 && iphi<nphi+np*4){
             hvobs[iphi]->Add(hvobs[iphi-nphi-np*2]);
             hvobs[iphi]->Add(hvobs[iphi-nphi]);
             hvobssq[iphi]->Add(hvobssq[iphi-nphi-np*2]);
             hvobssq[iphi]->Add(hvobssq[iphi-nphi]);
             hvobs2[iphi]->Add(hvobs2[iphi-nphi-np*2]);
             hvobs2[iphi]->Add(hvobs2[iphi-nphi]);
             if(iphi%np==1 && iphi%np==2){ //pion or Kaon
             hvobs[iphi]->Add(hvobs[9]);
             hvobs[iphi]->Add(hvobs[9+np*2]);
             hvobssq[iphi]->Add(hvobssq[9]);
             hvobssq[iphi]->Add(hvobssq[9+np*2]);
             hvobs2[iphi]->Add(hvobs2[9]);
             hvobs2[iphi]->Add(hvobs2[9+np*2]);
             }
         }

         if(iphi>=nphi+np*4 && iphi<nphi+np*5){
             hvobs[iphi]->Add(hvobs[iphi-np]);
             hvobs[iphi]->Add(hvobs[iphi-np*2]);
             hvobssq[iphi]->Add(hvobssq[iphi-np]);
             hvobssq[iphi]->Add(hvobssq[iphi-np*2]);
             hvobs2[iphi]->Add(hvobs2[iphi-np]);
             hvobs2[iphi]->Add(hvobs2[iphi-np*2]);
         }
         if(iphi>=nphi+np*5 && iphi<nphi+np*5+2) { //inclusive neg/pos
             hvobs[iphi]->Add(hvobs[(iphi%np)*np+1]);
             hvobs[iphi]->Add(hvobs[(iphi%np)*np+2]);
             hvobs[iphi]->Add(hvobs[(iphi%np)*np+3]);
             hvobs[iphi]->Add(hvobs[(iphi%np)*np+4]);
             hvobs[iphi]->Add(hvobs[(iphi%np)*np+np*2+1]);
             hvobs[iphi]->Add(hvobs[(iphi%np)*np+np*2+2]);
             hvobs[iphi]->Add(hvobs[(iphi%np)*np+np*2+3]);
             hvobs[iphi]->Add(hvobs[(iphi%np)*np+np*2+4]);
             hvobssq[iphi]->Add(hvobssq[(iphi%np)*np+1]);
             hvobssq[iphi]->Add(hvobssq[(iphi%np)*np+2]);
             hvobssq[iphi]->Add(hvobssq[(iphi%np)*np+3]);
             hvobssq[iphi]->Add(hvobssq[(iphi%np)*np+4]);
             hvobssq[iphi]->Add(hvobssq[(iphi%np)*np+np*2+1]);
             hvobssq[iphi]->Add(hvobssq[(iphi%np)*np+np*2+2]);
             hvobssq[iphi]->Add(hvobssq[(iphi%np)*np+np*2+3]);
             hvobssq[iphi]->Add(hvobssq[(iphi%np)*np+np*2+4]);
             hvobs2[iphi]->Add(hvobs2[(iphi%np)*np+1]);
             hvobs2[iphi]->Add(hvobs2[(iphi%np)*np+2]);
             hvobs2[iphi]->Add(hvobs2[(iphi%np)*np+3]);
             hvobs2[iphi]->Add(hvobs2[(iphi%np)*np+4]);
             hvobs2[iphi]->Add(hvobs2[(iphi%np)*np+np*2+1]);
             hvobs2[iphi]->Add(hvobs2[(iphi%np)*np+np*2+2]);
             hvobs2[iphi]->Add(hvobs2[(iphi%np)*np+np*2+3]);
             hvobs2[iphi]->Add(hvobs2[(iphi%np)*np+np*2+4]);
         }
         if(iphi>=nphi+np*5+2 && iphi<nphi+np*5+2+2) { //inclusive E/W
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+0]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+1]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+2]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+3]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+4]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+np+0]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+np+1]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+np+2]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+np+3]);
             hvobs[iphi]->Add(hvobs[iphi%(nphi+np*5+2)*np*2+np+4]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np+0]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np+1]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np+2]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np+3]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np+4]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np*2+np+0]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np*2+np+1]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np*2+np+2]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np*2+np+3]);
             hvobssq[iphi]->Add(hvobssq[iphi%(nphi+np*5+2)*np*2+np+4]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+0]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+1]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+2]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+3]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+4]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+np+0]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+np+1]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+np+2]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+np+3]);
             hvobs2[iphi]->Add(hvobs2[iphi%(nphi+np*5+2)*np*2+np+4]);
         }
         if(iphi==nphi+np*5+2+2) {
             hvobs[iphi]->Add(hvobs[nphi+np*5+2]);
             hvobs[iphi]->Add(hvobs[nphi+np*5+2+1]);
             hvobssq[iphi]->Add(hvobssq[nphi+np*5+2]);
             hvobssq[iphi]->Add(hvobssq[nphi+np*5+2+1]);
             hvobs2[iphi]->Add(hvobs2[nphi+np*5+2]);
             hvobs2[iphi]->Add(hvobs2[nphi+np*5+2+1]);
         }
         for(int ipt=0;ipt<npt-1;ipt++){
             int xbinmin = hvobs[iphi]->GetXaxis()->FindBin(ptbin[ipt]+eps);
             int xbinmax = hvobs[iphi]->GetXaxis()->FindBin(ptbin[ipt+1]-eps);
           //  std::cout<<xbinmin<<" "<<xbinmax<<std::endl;
           //  std::cout<<ptbin[ipt]<<" "<<ptbin[ipt+1]<<std::endl;
           // TH1F* hvobsProj = (TH1F*)hvobs->ProjectionY(Form("hvobsProj_%d",ipt),xbinmin,xbinmax);
           // TH1F* hvobssqProj = (TH1F*)hvobssq->ProjectionY(Form("hvobssqProj_%d",ipt),xbinmin,xbinmax);
            float Ntracks = hvobs2[iphi]->Integral(xbinmin,xbinmax);
            float vobs = hvobs[iphi]->Integral(xbinmin,xbinmax)/Ntracks;
            float vobssq = hvobssq[iphi]->Integral(xbinmin,xbinmax)/Ntracks;
           // float vobssq = hvobssqProj->GetMean();
            float v = vobs/reso;
//            float verr = hvobsProj->GetRMS()/reso/sqrt(Ntracks);
            TH1D* hvobsclone = (TH1D*)hvobs2[iphi]->Clone("hvobsclone");
            hvobsclone->GetXaxis()->SetRangeUser(ptbin[ipt]+eps,ptbin[ipt+1]-eps);
            float pt = hvobsclone->GetMean();
            if(Ntracks<=0){
            fout<<pt<<" "<<-9999<<" "<<-9999<<" "<<std::endl;
            foutraw<<pt<<" "<<-9999<<" "<<-9999<<" "<<std::endl;
            }
            else{
            float verr = sqrt(vobssq-vobs*vobs)/reso/sqrt(Ntracks);
            fout<<pt<<" "<<v<<" "<<verr<<" "<<std::endl;
            foutraw<<pt<<" "<<vobs<<" "<<verr*reso<<" "<<std::endl;
            }
         }
        fout.close();
        foutraw.close();
         }
        fout1.close();
        fout2.close();
        }
        }
     }

}