Beispiel #1
0
pair<TH2F*,TH2F*> Bin2DTree::fillWidths()
/*****************************************************************/
{
        if(!m_gridConstraint)
        {
            cerr<<"ERROR: Bin2DLeaf.fillWidths(): Trying to fill histogram, but the binning is unknown. Define first the gridConstraint.\n";
            exit(1);
        }
        TH2F* hWidthX = (TH2F*)m_gridConstraint->Clone("widthXFromTree");
        TH2F* hWidthY = (TH2F*)m_gridConstraint->Clone("widthYFromTree");
        int nbinsx = hWidthX->GetNbinsX();
        int nbinsy = hWidthX->GetNbinsY();
        map<Bin2DLeaf*, vector< pair<int,int> > > binsInLeaf;
        for(int bx=1;bx<nbinsx+1;bx++) 
        {
            for(int by=1;by<nbinsy+1;by++)
            {
                double x = hWidthX->GetXaxis()->GetBinCenter(bx);
                double y = hWidthX->GetYaxis()->GetBinCenter(by);
                Bin2DLeaf* leaf = getLeaf(x, y);
                vector<Bin2DLeaf*> neighborLeaves = findNeighborLeaves(leaf);
                neighborLeaves.push_back(leaf);
                vector<Bin2DLeaf*>::iterator itLeaf = neighborLeaves.begin();
                vector<Bin2DLeaf*>::iterator itELeaf = neighborLeaves.end();
                double sumw = 0.;
                double sumwx = 0.;
                double sumwy = 0.;
                for(;itLeaf!=itELeaf;++itLeaf)
                {
                    double xi = (*itLeaf)->getXCenter();
                    double yi = (*itLeaf)->getYCenter();
                    double dx = xi-x;
                    double dy = yi-y;
                    double wxi = (*itLeaf)->getXWidth();
                    double wyi = (*itLeaf)->getYWidth();
                    if(dx<0.05*wxi) dx = 0.05*wxi;
                    if(dy<0.05*wyi) dy = 0.05*wyi;
                    double dr2 = dx*dx+dy*dy;
                    sumw += 1./dr2;
                    sumwx += wxi/dr2;
                    sumwy += wyi/dr2;
                }
                double widthx = sumwx/sumw;
                double widthy = sumwy/sumw;
                hWidthX->SetBinContent(bx,by,widthx);
                hWidthY->SetBinContent(bx,by,widthy);
                hWidthX->SetBinError(bx,by,0.);
                hWidthY->SetBinError(bx,by,0.);
            }
        }
        return make_pair(hWidthX, hWidthY);
}
Beispiel #2
0
TH2F* Bin2DTree::fillHistogram()
/*****************************************************************/
{
        if(!m_gridConstraint)
        {
            cerr<<"ERROR: Bin2DLeaf.fillHistogram(): Trying to fill histogram, but the binning is unknown. Define first the gridConstraint.\n";
            exit(1);
        }
        TH2F* histo = (TH2F*)m_gridConstraint->Clone("histoFromTree");
        int nbinsx = histo->GetNbinsX();
        int nbinsy = histo->GetNbinsY();
        map<Bin2DLeaf*, vector< pair<int,int> > > binsInLeaf;
        // First find the list of TH2 bins for each Bin2DLeaf bin
        for(int bx=1;bx<nbinsx+1;bx++) 
        {
            for(int by=1;by<nbinsy+1;by++)
            {
                histo->SetBinContent(bx,by,0);
                histo->SetBinError(bx,by,0);
                double x = histo->GetXaxis()->GetBinCenter(bx);
                double y = histo->GetYaxis()->GetBinCenter(by);
                Bin2DLeaf* leaf = getLeaf(x,y);
                if(binsInLeaf.find(leaf)==binsInLeaf.end())
                {
                    vector< pair<int,int> > empty;
                    binsInLeaf[leaf] = empty;
                }
                binsInLeaf[leaf].push_back(make_pair(bx,by));
            }
        }
        // Then all the TH2 bins are filled according to the entries in the Bin2DLeaf bins
        map<Bin2DLeaf*, vector< pair<int,int> > >::iterator it = binsInLeaf.begin();
        map<Bin2DLeaf*, vector< pair<int,int> > >::iterator itE = binsInLeaf.end();
        for(;it!=itE;++it)
        {
            Bin2DLeaf* leaf = it->first;
            vector< pair<int,int> > bins = it->second;
            vector< vector<double> > entries = leaf->getEntries();
            int nbins = bins.size();
            for(int b=0;b<nbins;b++)
            {
                int bx = bins[b].first;
                int by = bins[b].second;
                double x = histo->GetXaxis()->GetBinCenter(bx);
                double y = histo->GetYaxis()->GetBinCenter(by);
                for(unsigned int e=0;e<entries.size();e++)
                {
                    double value = entries[e][2]/(double)nbins;
                    histo->Fill(x,y,value);
                }
            }
        }
        return histo;
}
Beispiel #3
0
 /// generate TH2F from this, for example for saving to a file or doing anything that
 ///  doesn't depend on bin edges or errors
 TH2F* toTH2F(const char* name_)
 {
   TH2F* h = new TH2F(name_, name_, nXBin, 0.5, nXBin+0.5, nYBin, 0.5, nYBin+0.5);
   
   for(int x=0; x<nXBin; x++)
   {
     for(int y=0; y<nYBin; y++)
     {
       h->SetBinContent(x+1, y+1, values[x][y]);
       h->SetBinError(x+1, y+1, getBinError(x,y));
     }
   }
   return h;
 }
Beispiel #4
0
//================================================
void makeHistos()
{
  TH2F *hDzVsModBL;
  TH1F *hDz[30][5];

  // dz vs mod in each BL
  THnSparseF *hn = (THnSparseF*)f->Get(Form("mhTrkDzDy_%s",trigName[kTrigType]));
  Int_t nbins = hn->GetAxis(1)->GetNbins();
  Double_t xmin = hn->GetAxis(1)->GetXmin();
  Double_t xmax = hn->GetAxis(1)->GetXmax();

  hDzVsModBL = new TH2F(Form("hTrkDzVsModBL_%s",trigName[kTrigType]),Form("%s: #Deltaz of matched track-hit pairs;module;#Deltaz (cm)",trigName[kTrigType]),150,0,150,nbins,xmin,xmax);
  for(int i=0; i<30; i++)
    {
      hn->GetAxis(3)->SetRange(i+1,i+1);
      for(int j=0; j<5; j++)
	{
	  hn->GetAxis(4)->SetRange(j+1,j+1);
	  hDz[i][j] = (TH1F*)hn->Projection(1);
	  hDz[i][j]->SetName(Form("hTrkDz_BL%d_Mod%d_%s",i+1,j+1,trigName[kTrigType]));
	  if(hDz[i][j]->GetEntries()<=0) continue;

	  for(int ibin=1; ibin<=hDz[i][j]->GetNbinsX(); ibin++)
	    {
	      hDzVsModBL->SetBinContent(i*5+j+1,ibin,hDz[i][j]->GetBinContent(ibin));
	      hDzVsModBL->SetBinError(i*5+j+1,ibin,hDz[i][j]->GetBinError(ibin));
	    }
	  hn->GetAxis(4)->SetRange(0,-1);
	}
      hn->GetAxis(3)->SetRange(0,-1);
    }
  TFile *fout = TFile::Open(Form("Rootfiles/%s%s.TrkMthResidual.root",run_cfg_name.Data(),run_type),"update");
  hDzVsModBL->Write();
  for(int i=0; i<30; i++)
    {
      for(int j=0; j<5; j++)
	{
	  hDz[i][j]->Write();
	}
    }
  fout->Close();
}
Beispiel #5
0
 /// generate histogram that looks approx. like this MyH2 would if it was plottable
 TH2F* toVisTH2F(const char* name_)
 {
   const double miny = yBinEdges[0][0];
   const double maxy = yBinEdges[0][nYBin];
   
   TH2F* h = new TH2F(name_, name_, nXBin, xBinEdges, 1000, miny, maxy);
   
   for(int x=0; x<nXBin; x++)
   {
     for(int y=0; y<1000; y++)
     {
       const int xbin = x;
       const int ybin = findYBin(xbin, h->GetYaxis()->GetBinCenter(y+1));
       
       
       h->SetBinContent(x+1, y+1, values[xbin][ybin]);
       h->SetBinError(x+1, y+1, getBinError(xbin,ybin));
     }
   }
   return h;
 }
Beispiel #6
0
TH2F *plotEff2D(RooDataSet *a, TString b) {
    const RooArgSet *set = a->get();
    RooRealVar *yAx = (RooRealVar*)set->find("pt");
    RooRealVar *xAx = (RooRealVar*)set->find("eta");
    RooRealVar *eff = (RooRealVar*)set->find("efficiency");

//    const int xnbins = xAx->getBinning().numBins();
//    const int ynbins = yAx->getBinning().numBins();

    //double xbins[] = {-2.4, -1.6, -0.8, 0.0, 0.8, 1.6, 2.4};
    //double ybins[] = {0, 2, 3, 5, 8, 10, 20};

    const double *xvbins = xAx->getBinning().array();
    const double *yvbins = yAx->getBinning().array();

    TH2F* h = new TH2F(b, "", xAx->getBinning().numBins(), xvbins, yAx->getBinning().numBins(), yvbins);

    gStyle->SetPaintTextFormat("5.2f");
    gStyle->SetPadRightMargin(0.12);
    gStyle->SetPalette(1);
    h->SetOption("colztexte");
    h->GetZaxis()->SetRangeUser(-0.001,1.001);
    h->SetStats(kFALSE);
    h->GetYaxis()->SetTitle("p_{T} [GeV/c]");
    h->GetXaxis()->SetTitle("#eta");
    h->GetXaxis()->CenterTitle();
    h->GetYaxis()->CenterTitle();
    h->GetXaxis()->SetTitleSize(0.05);
    h->GetYaxis()->SetTitleSize(0.05);
    h->GetYaxis()->SetTitleOffset(0.8);
    h->GetXaxis()->SetTitleOffset(0.9);
    for(int i=0; i<a->numEntries(); i++) {
        a->get(i);
        h->SetBinContent(h->FindBin(xAx->getVal(), yAx->getVal()), eff->getVal());
        h->SetBinError(h->FindBin(xAx->getVal(), yAx->getVal()), (eff->getErrorHi()-eff->getErrorLo())/2.);
    }

    return h;

}
void cetaflatHFP12(int nIterN=1, double Ethr1=10, double Ethr2=150) {
  
  gStyle->SetOptLogz(0);
  gStyle->SetMarkerSize(0.7);
  gStyle->SetMarkerStyle(20);
  gStyle->SetPadGridX(0);
  gStyle->SetPadGridY(0);
  gStyle->SetTitleOffset(1.7,"Y");
  gStyle->SetTitleOffset(0.9,"X");
  //gStyle->SetPadRightMargin(0.12);
  gStyle->SetPadRightMargin(0.03);
  gStyle->SetPadLeftMargin(0.18);
  //gStyle->SetNdivisions(516);
  gStyle->SetStatH(0.025);
  gStyle->SetStatW(0.3);
  gStyle->SetTitleW(0.4);
  gStyle->SetTitleX(0.28);
  gStyle->SetOptStat(0);
  gROOT->ForceStyle();

  char ctit[245],ftit[245];
  float etaBounds[14] = {2.853,2.964,3.139,3.314,3.489,3.664,3.839,4.013,4.191,4.363,4.538,4.716,4.889,5.205};

  // ------Histos input: spectra of all channels-----------------------------------

  //sprintf(ftit,"%s","phi43val2012A");
  //sprintf(ftit,"%s","phi2012A_May");
  //sprintf(ftit,"%s","phiSym524_2012AB");
  //sprintf(ftit,"%s","phiSym524newGain_2012AB");
  //sprintf(ftit,"%s","phiSym524newGain_2012ABC");
  //sprintf(ftit,"%s","phisymNewCond2012Cval");
  //sprintf(ftit,"%s","phisymOldCond2012Cval");
  //sprintf(ftit,"%s","phiSym533Gain507_2012D");
  sprintf(ftit,"%s","phiSym533Corr45Gain507_2012D");

  sprintf(ctit,"/home/vodib/beam12/intercal/%s.root",ftit);
  TFile *fila = new TFile (ctit);
  cout<<"File= "<<ctit<<endl;

  TH1F *hcounter =   new TH1F(*((TH1F*)fila->Get("phaseHF/hcounter")));
  cout<<"Stat= "<<hcounter->GetBinContent(2)<<endl;
  cout<<"E within: "<<Ethr1<<" - "<<Ethr2<<endl;

  TH2F* hLmapP = new TH2F("hLmapP","E L HFP;i#eta;i#phi",13,28.5,41.5,36,0,72);
  TH2F* hSmapP = new TH2F("hSmapP","E S HFP;i#eta;i#phi",13,28.5,41.5,36,0,72);
  TH2F* hLmapP0 = new TH2F("hLmapP0","E0 L HFP;i#eta;i#phi",13,28.5,41.5,36,0,72);
  TH2F* hSmapP0 = new TH2F("hSmapP0","E0 S HFP;i#eta;i#phi",13,28.5,41.5,36,0,72);
  TH2F* hLmapPc = new TH2F("hLmapPc","corr L HFP;i#eta;i#phi",13,28.5,41.5,36,0,72);
  TH2F* hSmapPc = new TH2F("hSmapPc","corr S HFP;i#eta;i#phi",13,28.5,41.5,36,0,72);
  hLmapPc->Sumw2(); hSmapPc->Sumw2();
  //TH1F *hLcorr1D = new TH1F("hLcorr1D","Corr L",300,0.5,2);
  //TH1F *hScorr1D = new TH1F("hScorr1D","Corr S",300,0.5,2);
  TH1F *hLcorr1D = new TH1F("hLcorr1D","Corr L",180,0.7,1.5);
  TH1F *hScorr1D = new TH1F("hScorr1D","Corr S",180,0.7,1.5);
  TH1F *hLdatP[13][36], *hSdatP[13][36], *hLdatPx[13][36], *hSdatPx[13][36];
  for (int ii=0;ii<13;ii++) for (int jj=0;jj<36;jj++) {
    sprintf(ctit,"hL%d_%d",ii+29,2*jj+1);
    hLdatP[ii][jj] = new TH1F(ctit,ctit,8000,0,250);
    sprintf(ctit,"hS%d_%d",ii+29,2*jj+1);
    hSdatP[ii][jj] = new TH1F(ctit,ctit,8000,0,250);
  }
  TH1F *htL = new TH1F("htL","htL",20000,0,7e8/3.);
  TH1F *htS = new TH1F("htS","htS",20000,0,5e8/3.);
  //TH1F *htL = new TH1F("htL","htL",20000,0,4e8/40);
  //TH1F *htS = new TH1F("htS","htS",20000,0,2e8/40);
  TH1F *hLdatPx[13][36], *hSdatPx[13][36];

  TCanvas *cLx[200],*cSx[200];
  TSpline5 *ttL,*ttS;

  Double_t x,y,rPL,rPS,drPL,drPS,mLE,mSE,ermean,rms;
  Double_t xxL[1000],yyL[1000];
  Double_t xxS[1000],yyS[1000];
  Int_t nELP, nESP, nIter=0;
  Double_t mcorrL,scorrL,mcorrS,scorrS,erLP,erSP,rLP,drLP,rSP,drSP,corrL,corrS,dcorrL,dcorrS;
  double mLEphi[13],mSEphi[13],dmLEphi[13],dmSEphi[13];

  TCanvas *ccxx = new TCanvas("ccxx","ccxx",100,300,900,500);
  ccxx->Divide(2,1);

  for (int ii=0;ii<13;ii++) {
  //for (int ii=1;ii<2;ii++) {
    int ieta=ii+29;

    mLE=mSE=0;   // ------------------for initial condition
    int nmLE=0, nmSE=0;
    htL->Reset(); htS->Reset();
    for (int ll=1;ll<=72;ll+=2) {
      int iphi=ll;
      if (abs(ieta)>39 && (iphi-1)%4==0) continue;
      hSmapPc->SetBinContent(ii+1,ll/2+1,1);
      hLmapPc->SetBinContent(ii+1,ll/2+1,1);
      hSmapPc->SetBinError(ii+1,ll/2+1,1.e-6);
      hLmapPc->SetBinError(ii+1,ll/2+1,1.e-6);
      sprintf(ctit,"phaseHF/espec/E_+%d_%d_1",ieta,iphi);
      hLdatPx[ii][ll/2]  =   new TH1F(*((TH1F*)fila->Get(ctit)));
      hLdatPx[ii][ll/2]->SetAxisRange(Ethr1,Ethr2);
      rLP = hLdatPx[ii][ll/2]->Integral()*hLdatPx[ii][ll/2]->GetMean();
      hLmapP0->SetBinContent(ii+1,ll/2+1,rLP);
      sprintf(ctit,"phaseHF/espec/E_+%d_%d_2",ieta,iphi);
      hSdatPx[ii][ll/2]  =   new TH1F(*((TH1F*)fila->Get(ctit)));
      hSdatPx[ii][ll/2]->SetAxisRange(Ethr1,Ethr2);
      rSP = hSdatPx[ii][ll/2]->Integral()*hSdatPx[ii][ll/2]->GetMean();
      hSmapP0->SetBinContent(ii+1,ll/2+1,rSP);
      if (ieta<=32 && iphi==67) continue;
      if (rLP>0) {
	htL->Fill(rLP);
	mLE += rLP;
	nmLE++;
      }
      if (rSP>0) {
	htS->Fill(rSP);
	mSE += rSP;
	nmSE++;
      }
    }
    if (nmLE>0) mLE /= nmLE; 
    else continue;
    if (nmSE>0) mSE /= nmSE; 
    else continue;
    ccxx->cd(1); htL->Draw("hist");
    ccxx->cd(2); htS->Draw("hist");
    ccxx->Update();
    //histspec(htL,mLE,ermean,rms,4,3);
    //histspec(htS,mSE,ermean,rms,4,3);
    mLEphi[ii]=mLE;
    mSEphi[ii]=mSE;
    dmLEphi[ii]=htL->GetRMS();
    dmSEphi[ii]=htS->GetRMS();
    printf("ieta %2d :  <E>L= %8.1f (%6.1f) x %d    <E>S= %8.1f (%6.1f) x %d \n",
	   ieta,mLE,dmLEphi[ii],nmLE,mSE,dmSEphi[ii],nmSE);
    
    for (int jj=1;jj<=72;jj+=2) {
      int iphi=jj;
      if (abs(ieta)>39 && (iphi-1)%4==0) continue;
      if (ieta<=32 && iphi==67) {
	hLmapP->SetBinContent(ii+1,jj/2+1,hLmapP0->GetBinContent(ii+1,jj/2+1));
	hSmapP->SetBinContent(ii+1,jj/2+1,hSmapP0->GetBinContent(ii+1,jj/2+1));
	continue;
      }

      for (nIter=1;nIter<nIterN;nIter++) { //cout<<nIter<<" |  ";
	corrL=hLmapPc->GetBinContent(ii+1,jj/2+1);
	hLdatP[ii][jj/2]->Reset();

	for (int kk=1;kk<=hLdatPx[ii][jj/2]->GetNbinsX();kk++) {
	  xxL[kk-1]=hLdatPx[ii][jj/2]->GetBinCenter(kk);
	  yyL[kk-1]=hLdatPx[ii][jj/2]->GetBinContent(kk);
	}
	ttL = new TSpline5("tt",xxL,yyL,1000,"",10,20);

	for (int kk=1;kk<=hLdatP[ii][jj/2]->GetNbinsX();kk++) {
	  x=hLdatP[ii][jj/2]->GetBinCenter(kk);
	  y=hLdatP[ii][jj/2]->GetBinContent(kk);
	  hLdatP[ii][jj/2]->Fill(x*corrL,ttL->Eval(x)/8.0);
	}
	ttL->Delete();

	hLdatP[ii][jj/2]->SetAxisRange(Ethr1,Ethr2);
	rLP = hLdatP[ii][jj/2]->Integral()*hLdatP[ii][jj/2]->GetMean();
	dcorrL=(rLP-mLE)/mLE;
	if (rLP>0) drLP=
	      sqrt(pow(hLdatP[ii][jj/2]->GetMeanError()/hLdatP[ii][jj/2]->GetMean(),2)+
		   1.f/hLdatP[ii][jj/2]->Integral()+
		   pow(dcorrL/(1.0+sqrt((float) nIter)),2));
	else drLP=1.e-6;
	if (fabs(dcorrL)>0.001) { 
	  corrL*=1-dcorrL/(1.0+sqrt((float) nIter));
	  //printf("%2d : %2d / %2d / 1 %7.3f %7.3f\n",nIter,ieta,iphi,dcorrL,corrL);
	  hLmapPc->SetBinContent(ii+1,jj/2+1,corrL);
	  hLmapPc->SetBinError(ii+1,jj/2+1,corrL*drLP);
	  hLmapP->SetBinContent(ii+1,jj/2+1,rLP);
	}
	else {
	  printf("%2d : %2d / %2d / 1 %7.3f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrL,corrL,corrL*drLP);
	  hLmapP->SetBinContent(ii+1,jj/2+1,rLP);
	  hLmapPc->SetBinError(ii+1,jj/2+1,corrL*drLP);
	  break;
	}
	if (nIter==nIterN-1) {
	  printf("%2d : %2d / %2d / 1 %7.3f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrL,corrL,corrL*drLP);
	}
      }

      for (nIter=1;nIter<nIterN;nIter++) { //cout<<nIter<<" |  ";
	corrS=hSmapPc->GetBinContent(ii+1,jj/2+1);
	hSdatP[ii][jj/2]->Reset();

	for (int kk=1;kk<=hSdatPx[ii][jj/2]->GetNbinsX();kk++) {
	  xxS[kk-1]=hSdatPx[ii][jj/2]->GetBinCenter(kk);
	  yyS[kk-1]=hSdatPx[ii][jj/2]->GetBinContent(kk);
	}
	ttS = new TSpline5("tt",xxS,yyS,1000,"",10,20);

	for (int kk=1;kk<=hSdatP[ii][jj/2]->GetNbinsX();kk++) {
	  x=hSdatP[ii][jj/2]->GetBinCenter(kk);
	  y=hSdatP[ii][jj/2]->GetBinContent(kk);
	  hSdatP[ii][jj/2]->Fill(x*corrS,ttS->Eval(x)/8.0);
	}
	ttS->Delete();

	hSdatP[ii][jj/2]->SetAxisRange(Ethr1,Ethr2);
	rSP = hSdatP[ii][jj/2]->Integral()*hSdatP[ii][jj/2]->GetMean();
	dcorrS=(rSP-mSE)/mSE;
	if (rSP>0) drSP=sqrt(pow(hSdatP[ii][jj/2]->GetMeanError()/hSdatP[ii][jj/2]->GetMean(),2)+
			     1.f/hSdatP[ii][jj/2]->Integral()+
			     pow(dcorrS/(1.0+sqrt((float) nIter)),2));
	else drSP=1.e-6;
	if (fabs(dcorrS)>0.001) { 
	  corrS*=1-dcorrS/(1.0+sqrt((float) nIter));
	  //printf("%2d : %2d / %2d / 1 %7.3f %7.3f\n",nIter,ieta,iphi,dcorrS,corrS);
	  hSmapPc->SetBinContent(ii+1,jj/2+1,corrS);
	  hSmapPc->SetBinError(ii+1,jj/2+1,corrS*drSP);
	  hSmapP->SetBinContent(ii+1,jj/2+1,rSP);
	}
	else {
	  printf("%2d : %2d / %2d / 2 %7.3f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrS,corrS,corrS*drSP);
	  hSmapP->SetBinContent(ii+1,jj/2+1,rSP);
	  hSmapPc->SetBinError(ii+1,jj/2+1,corrS*drSP);
	  break;
	}
	if (nIter==nIterN-1) {
	  printf("%2d : %2d / %2d / 2 %7.3f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrS,corrS,corrS*drSP);
	}
      }
    }
  }
  //fila->Close();

  cout<<endl<<"Rings :  "<<endl;
  cout<<"       E L        "<<"E S        "<<"eta     "<<"delta eta"<<endl;
  double xeta[13], weta[13], reta[13];
  for (int i=29;i<=41;i++) {
    xeta[i-29]=(etaBounds[i-28]+etaBounds[i-29])/2;
    weta[i-29]=(etaBounds[i-28]-etaBounds[i-29]);
    mLEphi[i-29]=mLEphi[i-29]*36/weta[i-29];
    mSEphi[i-29]=mSEphi[i-29]*36/weta[i-29];
    dmLEphi[i-29]=dmLEphi[i-29]*36/weta[i-29];
    dmSEphi[i-29]=dmSEphi[i-29]*36/weta[i-29];
    if (i>39) {  mLEphi[i-29]/=2; mSEphi[i-29]/=2; dmLEphi[i-29]/=2; dmSEphi[i-29]/=2; }
    reta[i-29] = mSEphi[i-29]/mLEphi[i-29];
    cout<<i<<" :  "<<mLEphi[i-29]<<"    "<<mSEphi[i-29]<<"    "<<xeta[i-29]<<"   "<<weta[i-29]<<endl;
  }
  TCanvas *cgL = new TCanvas("cgL","cgL",300,300,600,600);
  TGraphErrors *grL = new TGraphErrors(13,xeta,mLEphi,0,dmLEphi);
  grL->SetTitle("HFP L;#eta;E_{Ring} / #Delta#eta_{Ring} ,  GeV");
  grL->SetMinimum(0);
  grL->SetMarkerStyle(20);
  grL->Draw("1+PAl");
  cgL->Print("pictHFplot/etaProfHFPL.gif");
  mSEphi[12]/=2; mSEphi[11]/=2;
  TCanvas *cgS = new TCanvas("cgS","cgS",300,300,600,600);
  TGraphErrors *grS = new TGraphErrors(13,xeta,mSEphi,0,dmSEphi);
  grS->SetTitle("HFP S;#eta;E_{Ring} / #Delta#eta_{Ring} ,  GeV");
  grS->SetMinimum(0);
  grS->SetMarkerStyle(20);
  grS->Draw("1+PAl");
  cgS->Print("pictHFplot/etaProfHFPS.gif");
  TCanvas *crg = new TCanvas("crg","crg",300,300,600,600);
  TGraphErrors *rg = new TGraphErrors(13,xeta,reta,0,0);
  rg->SetTitle("HFP;#eta;E(S) / E(L)");
  rg->SetMinimum(0);
  rg->Draw("1+PAl");
  crg->Print("pictHFplot/SoverLetaHFP.gif");

  TCanvas *cL0 = new TCanvas("cL0","cL0",0,0,650,600);
  hLmapP0->Draw("colz");
  cL0->Update();
  TCanvas *cS = new TCanvas("cS0","cS0",1000,0,650,600);
  hSmapP0->Draw("colz");
  cS0->Update();

  //TFile *histf = new TFile("HFPmc.root","RECREATE");

  FILE *ft1;
  //sprintf(ctit,"corrHFPmc_%d_%d.txt",((int) Ethr1),((int) Ethr2));
  sprintf(ctit,"corrHFP_%s_%d_%d.txt",ftit,((int) Ethr1),((int) Ethr2));
  if ((ft1 = fopen(ctit,"w"))==NULL){               // Open new file
    printf("\nNo file %s open => EXIT\n\n",file);
    return;
  }
  printf("\n\n File '%s' open \n\n",ctit);

  TH1D *hprL[13],*hprS[13],*hprL0[13],*hprS0[13];
  TH1D *hprcL[13],*hprcS[13];
  TCanvas *cpr[13],*ccc[13];
  TLine *lin1 = new TLine(0,1,71,1); lin1->SetLineWidth(1);

  int noff=0;
  for (int ii=0;ii<13;ii++) {

    sprintf(ctit,"HFPcorr_%d_L",ii+29);  // draw corrections
    hprcL[ii] = hLmapPc->ProjectionY(ctit,ii+1,ii+1);
    hprcL[ii]->SetTitle(ctit);
    sprintf(ctit,"HFPcorr_%d_S",ii+29);
    hprcS[ii] = hSmapPc->ProjectionY(ctit,ii+1,ii+1);
    hprcS[ii]->SetTitle(ctit);
    ccc[ii] = new TCanvas(ctit,ctit,800,100,500,900);
    ccc[ii]->Divide(1,2);
    ccc[ii]->cd(1);
    if (ii+29>39) {
      hprcL[ii]->Rebin(2);
      hprcS[ii]->Rebin(2);
    }
    hprcL[ii]->SetMinimum(0);
    hprcL[ii]->SetTitleOffset(0.9,"X");
    hprcL[ii]->Draw("e");
    lin1->Draw();
    ccc[ii]->cd(2);
    hprcS[ii]->SetMinimum(0);
    hprcS[ii]->SetTitleOffset(0.9,"X");
    hprcS[ii]->Draw("e");
    lin1->Draw();
    sprintf(ctit,"pictHFplot/HFPcorr_%d.gif",ii+29);
    ccc[ii]->Update();
    ccc[ii]->Print(ctit);
    //hprcL[ii]->Write();
    //hprcS[ii]->Write();

    sprintf(ctit,"HFP_%d_L",ii+29);  //  draw E depositions
    hprL0[ii] = hLmapP0->ProjectionY(ctit,ii+1,ii+1);
    sprintf(ctit,"HFP_%d_L;i#phi;GeV;",29+ii);  //  draw E depositions
    hprL0[ii]->SetTitle(ctit);
    sprintf(ctit,"HFP_L_%d",ii+29);
    hprL[ii] = hLmapP->ProjectionY(ctit,ii+1,ii+1);
    sprintf(ctit,"HFP_%d_S",ii+29);
    hprS0[ii] = hSmapP0->ProjectionY(ctit,ii+1,ii+1);
    sprintf(ctit,"HFP_%d_S;i#phi;GeV;",29+ii);  //  draw E depositions
    hprS0[ii]->SetTitle(ctit);
    sprintf(ctit,"HFP_S_%d",ii+29);
    hprS[ii] = hSmapP->ProjectionY(ctit,ii+1,ii+1);

    cpr[ii] = new TCanvas(ctit,ctit,800,100,500,900);
    cpr[ii]->Divide(1,2);
    cpr[ii]->cd(1);
    if (ii+29>39) {
      hprL0[ii]->Rebin(2);
      hprL[ii]->Rebin(2);
      hprS0[ii]->Rebin(2);
      hprS[ii]->Rebin(2);
    }
    hprL0[ii]->SetFillColor(3);hprL0[ii]->SetLineColor(3);hprL0[ii]->SetLineWidth(3);
    hprL0[ii]->SetMinimum(0);
    hprL0[ii]->SetTitleOffset(0.9,"X");
    hprL0[ii]->Draw("hist");
    hprL[ii]->Draw("samehist");
    cpr[ii]->cd(2);
    hprS0[ii]->SetMinimum(0);
    hprS0[ii]->SetTitleOffset(0.9,"X");
    hprS0[ii]->SetFillColor(3);hprS0[ii]->SetLineColor(3);hprS0[ii]->SetLineWidth(3);
    hprS0[ii]->Draw("hist");
    hprS[ii]->Draw("samehist");
    sprintf(ctit,"pictHFplot/HFP_%d.gif",ii+29);
    cpr[ii]->Print(ctit);
    //hprS0[ii]->Write();
    //hprL0[ii]->Write();

    cout<<"Results : "<<endl;
    for (int jj=1;jj<=72;jj+=2) {
      int ieta=ii+29;
      int iphi=jj;
      if (abs(ieta)>39 && (iphi-1)%4==0) continue;
      //if (ieta==29 && iphi==67) continue;
      corrL=hLmapPc->GetBinContent(ii+1,jj/2+1);
      corrS=hSmapPc->GetBinContent(ii+1,jj/2+1);
      dcorrL=hLmapPc->GetBinError(ii+1,jj/2+1);
      dcorrS=hSmapPc->GetBinError(ii+1,jj/2+1);
      hLcorr1D->Fill(corrL); hScorr1D->Fill(corrS);
      noff++;
      //printf("%2d : %2d / %2d / 1 %9.4f %9.4f\n",noff,ieta,iphi,corrL,dcorrL);
      fprintf(ft1,"%2d   %2d   1 %9.4f %9.4f\n",ieta,iphi,corrL,dcorrL);
      noff++;
      //printf("%2d : %2d / %2d / 2 %9.4f %9.4f\n",noff,ieta,iphi,corrS,dcorrS);
      fprintf(ft1,"%2d   %2d   2 %9.4f %9.4f\n",ieta,iphi,corrS,dcorrS);
    }
  }
  fclose(ft1);

  for (int ii=0;ii<13;ii++) for (int jj=1;jj<=72;jj+=2) {
      int ieta=ii+29;
      int iphi=jj;
      if (abs(ieta)>39 && (iphi-1)%4==0) continue;
      if (ieta==29 && iphi==67) continue;
      corrL=hLmapPc->GetBinContent(ii+1,jj/2+1);
      if (fabs(corrL-1)>0.16) printf("%2d / %2d / 1 %9.4f %9.4f\n",ieta,iphi,corrL,dcorrL);
      corrS=hSmapPc->GetBinContent(ii+1,jj/2+1);
      if (fabs(corrS-1)>0.16) printf("%2d / %2d / 2 %9.4f %9.4f\n",ieta,iphi,corrS,dcorrS);
  }

  TCanvas *cLcorr =new TCanvas("cLcorr","cLcorr",30,30,600,600);
  cLcorr->SetRightMargin(0.12);
  hLmapPc->SetAxisRange(0.6,1.6,"Z");
  hLmapPc->Draw("colz");
  TCanvas *cScorr =new TCanvas("cScorr","cScorr",30,300,600,600);
  cScorr->SetRightMargin(0.12);
  hSmapPc->SetAxisRange(0.6,1.6,"Z");
  hSmapPc->Draw("colz");

  TCanvas *cL = new TCanvas("cL","cL",0,0,650,600);
  hLmapP->Draw("colz");
  cL->Update();
  TCanvas *cS = new TCanvas("cS","cS",1000,0,650,600);
  hSmapP->Draw("colz");
  cS->Update();

  TCanvas *c1corr =new TCanvas("c1corr","c1corr",30,30,900,500);
  c1corr->Divide(2,1);
  c1corr->cd(1);  hLcorr1D->Draw("hist");  histStat(hLcorr1D,1);
  c1corr->cd(2);  hScorr1D->Draw("hist");  histStat(hScorr1D,1);
  //hLcorr1D->Write(); hScorr1D->Write();  

  c1corr->Print("pictHFplot/corrHFP.gif");
  //c1corr->Print("pictHFmc/corrHFP.gif");
  c1corr->Update();
  
  //fila->Close();
  //histf->Close();

  sprintf(ctit,"HFPo_%s_%d_%d.root",ftit,((int) Ethr1),((int) Ethr2));
  TFile *histf = new TFile(ctit,"RECREATE");
  hLcorr1D->Write(); 
  hScorr1D->Write();  
  hLmapP->Write(); 
  hLmapP0->Write(); 
  hLmapPc->Write(); 
  hSmapP->Write(); 
  hSmapP0->Write(); 
  hSmapPc->Write(); 
  grL->Write();
  grS->Write();
  histf->Close();
}
Beispiel #8
0
void plotsEff() {

  /*
  // hardcoded: efficiency on data, mva 005 - no R9 weights
  Float_t dataEffPtEB[4];
  dataEffPtEB[0] = 0.787321;
  dataEffPtEB[1] = 0.865828;
  dataEffPtEB[2] = 0.907563;
  dataEffPtEB[3] = 0.934763;

  Float_t dataErrPtEB[4];
  dataErrPtEB[0] = 0.00147372;
  dataErrPtEB[1] = 0.000507673;
  dataErrPtEB[2] = 0.000371044;
  dataErrPtEB[3] = 0.00104934;
  
  Float_t dataEffPtEE[4];
  dataEffPtEE[0] = 0.717205;
  dataEffPtEE[1] = 0.833808;
  dataEffPtEE[2] = 0.902595;
  dataEffPtEE[3] = 0.947531;

  Float_t dataErrPtEE[4];
  dataErrPtEE[0] = 0.00215698;
  dataErrPtEE[1] = 0.000966102;
  dataErrPtEE[2] = 0.00031378;
  dataErrPtEE[3] = 0.000974099;
  */

  // hardcoded: efficiency on data, mva 005 - with R9 weights
  Float_t dataEffPtEB[4];
  dataEffPtEB[0] = 0.851094;
  dataEffPtEB[1] = 0.911409;
  dataEffPtEB[2] = 0.942177;
  dataEffPtEB[3] = 0.960729;

  Float_t dataErrPtEB[4];
  dataErrPtEB[0] = 0.000877588;
  dataErrPtEB[1] = 0.000284711;
  dataErrPtEB[2] = 0.000193678;
  dataErrPtEB[3] = 0.000351052;
  
  Float_t dataEffPtEE[4];
  dataEffPtEE[0] = 0.823633;
  dataEffPtEE[1] = 0.904294;
  dataEffPtEE[2] = 0.945122;
  dataEffPtEE[3] = 0.972123;

  Float_t dataErrPtEE[4];
  dataErrPtEE[0] = 0.00137336;
  dataErrPtEE[1] = 0.000541285;
  dataErrPtEE[2] = 0.000332841;
  dataErrPtEE[3] = 0.000471213;

  /*
  // hardcoded: efficiency on mc, mva 005  - no R9weights
  Float_t mcEffPtEB[4];
  mcEffPtEB[0] = 0.809073;
  mcEffPtEB[1] = 0.884915;
  mcEffPtEB[2] = 0.921544;
  mcEffPtEB[3] = 0.944102;

  Float_t mcErrPtEB[4];
  mcErrPtEB[0] = 0.00107234;
  mcErrPtEB[1] = 0.000362482;
  mcErrPtEB[2] = 0.000269083;
  mcErrPtEB[3] = 0.000583753;
  
  Float_t mcEffPtEE[4];
  mcEffPtEE[0] = 0.745734;
  mcEffPtEE[1] = 0.869638;
  mcEffPtEE[2] = 0.92426;
  mcEffPtEE[3] = 0.957486;

  Float_t mcErrPtEE[4];
  mcErrPtEE[0] = 0.00181754;
  mcErrPtEE[1] = 0.000661643;
  mcErrPtEE[2] = 0.0000115311;
  mcErrPtEE[3] = 0.000633697;
  */

  // hardcoded: efficiency on mc, mva 005  - with R9weights
  Float_t mcEffPtEB[4];
  mcEffPtEB[0] = 0.869367;
  mcEffPtEB[1] = 0.925948;
  mcEffPtEB[2] = 0.951753;
  mcEffPtEB[3] = 0.967678;

  Float_t mcErrPtEB[4];
  mcErrPtEB[0] = 0.000681269;
  mcErrPtEB[1] = 0.000197075;
  mcErrPtEB[2] = 0.000132988;
  mcErrPtEB[3] = 0.000269974;
  
  Float_t mcEffPtEE[4];
  mcEffPtEE[0] = 0.843007;
  mcEffPtEE[1] = 0.926918;
  mcEffPtEE[2] = 0.958852;
  mcEffPtEE[3] = 0.977944;

  Float_t mcErrPtEE[4];
  mcErrPtEE[0] = 0.00111903;
  mcErrPtEE[1] = 0.00017719;
  mcErrPtEE[2] = 0.000208054;
  mcErrPtEE[3] = 0.0111678;


  // -------------------------------------
  // histograms: 2D plots
  Float_t LowerEta[3];
  LowerEta[0]=0.0;
  LowerEta[1]=1.5;
  LowerEta[2]=2.5;

  Float_t LowerPt[5];
  LowerPt[0]=20.0;
  LowerPt[1]=30.0;
  LowerPt[2]=40.0;
  LowerPt[3]=50.0;
  LowerPt[4]=200.0;

  TH2F *DataEffMap = new TH2F( "DataEffMap",  "data efficiency map", 2, LowerEta, 4, LowerPt);
  TH2F *MCEffMap   = new TH2F( "MCEffMap",    "MC efficiency map",   2, LowerEta, 4, LowerPt);
  
  for (int jj=1; jj<5; jj++) {
    int theindex = jj-1;
    DataEffMap->SetBinContent(1,jj,dataEffPtEB[theindex]);
    DataEffMap->SetBinContent(2,jj,dataEffPtEE[theindex]);
    DataEffMap->SetBinError(1,jj,dataErrPtEB[theindex]);
    DataEffMap->SetBinError(2,jj,dataErrPtEE[theindex]);

    MCEffMap->SetBinContent(1,jj,mcEffPtEB[theindex]);
    MCEffMap->SetBinContent(2,jj,mcEffPtEE[theindex]);
    MCEffMap->SetBinError(1,jj,mcErrPtEB[theindex]);
    MCEffMap->SetBinError(2,jj,mcErrPtEE[theindex]);
  }

  DataEffMap->SetTitle("data");
  DataEffMap->GetXaxis()->SetTitle("probe #eta");
  DataEffMap->GetYaxis()->SetTitle("probe pT [GeV]");

  MCEffMap->SetTitle("MC");
  MCEffMap->GetXaxis()->SetTitle("probe #eta");
  MCEffMap->GetYaxis()->SetTitle("probe pT [GeV]");
  

  // -------------------------------------
  // data: eff vs pT
  TH1F *DataEffVsPt_barrel = new TH1F( "DataEffVsPt_barrel" , "DataEffVsPt_barrel", 4, LowerPt);
  TH1F *DataEffVsPt_endcap = new TH1F( "DataEffVsPt_endcap" , "DataEffVsPt_endcap", 4, LowerPt);
  for (int jj=1; jj<5; jj++) {
    int theindex = jj-1;
    DataEffVsPt_barrel->SetBinContent(jj,dataEffPtEB[theindex]);
    DataEffVsPt_barrel->SetBinError(jj,dataErrPtEB[theindex]);
    DataEffVsPt_endcap->SetBinContent(jj,dataEffPtEE[theindex]);
    DataEffVsPt_endcap->SetBinError(jj,dataErrPtEE[theindex]);
  }
  DataEffVsPt_barrel->SetMarkerColor(4);
  DataEffVsPt_barrel->SetLineColor(4);
  DataEffVsPt_barrel->SetMarkerStyle(20);
  DataEffVsPt_barrel->SetMarkerSize(0.9);
  DataEffVsPt_barrel->GetXaxis()->SetTitle("probe pT [GeV]");
  DataEffVsPt_barrel->SetTitle("photonID efficiency");

  DataEffVsPt_endcap->SetLineColor(4);
  DataEffVsPt_endcap->SetMarkerColor(4);
  DataEffVsPt_endcap->SetMarkerStyle(20);
  DataEffVsPt_endcap->SetMarkerSize(0.9);
  DataEffVsPt_endcap->GetXaxis()->SetTitle("probe pT [GeV]");
  DataEffVsPt_endcap->SetTitle("photonID efficiency");


  // ---------------------------------------
  // mc: eff vs pT
  TH1F *McEffVsPt_barrel = new TH1F( "McEffVsPt_barrel" , "McEffVsPt_barrel", 4, LowerPt);
  TH1F *McEffVsPt_endcap = new TH1F( "McEffVsPt_endcap" , "McEffVsPt_endcap", 4, LowerPt);
  for (int jj=1; jj<5; jj++) {
    int theindex = jj-1;
    McEffVsPt_barrel->SetBinContent(jj,mcEffPtEB[theindex]);
    McEffVsPt_barrel->SetBinError(jj,mcErrPtEB[theindex]);
    McEffVsPt_endcap->SetBinContent(jj,mcEffPtEE[theindex]);
    McEffVsPt_endcap->SetBinError(jj,mcErrPtEE[theindex]);
  }
  McEffVsPt_barrel->SetMarkerColor(2);
  McEffVsPt_barrel->SetLineColor(2);
  McEffVsPt_barrel->SetMarkerStyle(21);
  McEffVsPt_barrel->SetMarkerSize(0.9);
  McEffVsPt_barrel->SetTitle("photonID efficiency");
  McEffVsPt_barrel->GetXaxis()->SetTitle("probe pT [GeV]");

  McEffVsPt_endcap->SetMarkerColor(2);
  McEffVsPt_endcap->SetLineColor(2);
  McEffVsPt_endcap->SetMarkerStyle(21);
  McEffVsPt_endcap->SetMarkerSize(0.9);
  McEffVsPt_endcap->SetTitle("photonID efficiency");
  McEffVsPt_endcap->GetXaxis()->SetTitle("probe pT [GeV]");


  // plots
  gStyle->SetOptStat(0);

  TLegend *leg;
  leg = new TLegend(0.4,0.4,0.65,0.65);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.05);
  leg->SetFillColor(0);
  // leg->AddEntry(DataEffVsPt_endcap, "MC, highR9", "lp");
  // leg->AddEntry(McEffVsPt_endcap,   "MC, low R9", "lp");
  leg->AddEntry(DataEffVsPt_endcap, "data", "lp");
  leg->AddEntry(McEffVsPt_endcap,   "MC",   "lp");

  TCanvas myC1("c1", "c1", 1);
  DataEffMap->Draw("colz");
  DataEffMap->Draw("textsame");
  myC1.SaveAs("dataMap.png");

  TCanvas myC1b("c1b", "c1b", 1);
  MCEffMap->Draw("colz");
  MCEffMap->Draw("textsame");
  myC1b.SaveAs("mcMap.png");

  TCanvas myC2("c2", "c2", 1);
  DataEffVsPt_barrel->SetMinimum(0.5);
  DataEffVsPt_barrel->SetMaximum(1.);
  DataEffVsPt_barrel->Draw();
  myC2.SaveAs("dataEffVsPt_barrel.png");

  TCanvas myC3("c3", "c3", 1);
  DataEffVsPt_endcap->SetMinimum(0.5);
  DataEffVsPt_endcap->SetMaximum(1.);
  DataEffVsPt_endcap->Draw();
  myC3.SaveAs("dataEffVsPt_endcap.png");

  TCanvas myC4("c4", "c4", 1);
  McEffVsPt_barrel->SetMinimum(0.5);
  McEffVsPt_barrel->SetMaximum(1.);
  McEffVsPt_barrel->Draw();
  myC4.SaveAs("mcEffVsPt_barrel.png");

  TCanvas myC5("c5", "c5", 1);
  McEffVsPt_endcap->SetMinimum(0.5);
  McEffVsPt_endcap->SetMaximum(1.);
  McEffVsPt_endcap->Draw();
  myC5.SaveAs("mcEffVsPt_endcap.png");

  TCanvas myC6("c6", "c6", 1);
  DataEffVsPt_barrel->Draw();
  McEffVsPt_barrel->Draw("same");
  leg->Draw();
  myC6.SaveAs("compEffVsPt_barrel.png");

  TCanvas myC7("c7", "c7", 1);
  DataEffVsPt_endcap->Draw();
  McEffVsPt_endcap->Draw("same");
  leg->Draw();
  myC7.SaveAs("compEffVsPt_endcap.png");
}
Beispiel #9
0
void plotsEff() {
  
  // -------------------------------------
  // hardcoded: efficiency on data (95%)
  /*
  Float_t dataEffPtEB[4];
  dataEffPtEB[0] = 0.788216;
  dataEffPtEB[1] = 0.868873;
  dataEffPtEB[2] = 0.909119;
  dataEffPtEB[3] = 0.937142;

  Float_t dataErrPtEB[4];
  dataErrPtEB[0] = 0.0022248;
  dataErrPtEB[1] = 0.00557281;
  dataErrPtEB[2] = 0.000410552;
  dataErrPtEB[3] = 0.0317504;
  
  Float_t dataEffPtEE[4];
  dataEffPtEE[0] = 0.667278;
  dataEffPtEE[1] = 0.789731;
  dataEffPtEE[2] = 0.861867;
  dataEffPtEE[3] = 0.91869;

  Float_t dataErrPtEE[4];
  dataErrPtEE[0] = 0.00288854;
  dataErrPtEE[1] = 0.00113707;
  dataErrPtEE[2] = 0.0008856;
  dataErrPtEE[3] = 0.00125012;
  */

  // hardcoded: efficiency on data (90%)
  Float_t dataEffPtEB[4];
  dataEffPtEB[0] = 0.6809;
  dataEffPtEB[1] = 0.774901;
  dataEffPtEB[2] = 0.826641;
  dataEffPtEB[3] = 0.87309;

  Float_t dataErrPtEB[4];
  dataErrPtEB[0] = 0.002289;
  dataErrPtEB[1] = 0.0006833;
  dataErrPtEB[2] = 0.085946;
  dataErrPtEB[3] = 0.0004758;
  
  Float_t dataEffPtEE[4];
  dataEffPtEE[0] = 0.547962;
  dataEffPtEE[1] = 0.670435;
  dataEffPtEE[2] = 0.753952;
  dataEffPtEE[3] = 0.83594;

  Float_t dataErrPtEE[4];
  dataErrPtEE[0] = 0.003029;
  dataErrPtEE[1] = 0.0012858;
  dataErrPtEE[2] = 0.001035;
  dataErrPtEE[3] = 0.001670;

  // -------------------------------------
  // hardcoded: efficiency on mc (95%)
  /*
  Float_t mcEffPtEB[4];
  mcEffPtEB[0] = 0.806962;
  mcEffPtEB[1] = 0.884942;
  mcEffPtEB[2] = 0.921844;
  mcEffPtEB[3] = 0.946614;

  Float_t mcErrPtEB[4];
  mcErrPtEB[0] = 0.00183663;
  mcErrPtEB[1] = 0.000726529;
  mcErrPtEB[2] = 0.0005429;
  mcErrPtEB[3] = 0.0008690;
  
  Float_t mcEffPtEE[4];
  mcEffPtEE[0] = 0.740969;
  mcEffPtEE[1] = 0.86685;
  mcEffPtEE[2] = 0.924042;
  mcEffPtEE[3] = 0.961009;

  Float_t mcErrPtEE[4];
  mcErrPtEE[0] = 0.00258916;
  mcErrPtEE[1] = 0.00123024;
  mcErrPtEE[2] = 0.000874;
  mcErrPtEE[3] = 0.00113995;
  */

  // hardcoded: efficiency on mc (90%)
  Float_t mcEffPtEB[4];
  mcEffPtEB[0] = 0.70395;
  mcEffPtEB[1] = 0.796202;
  mcEffPtEB[2] = 0.845931;
  mcEffPtEB[3] = 0.886863;

  Float_t mcErrPtEB[4];
  mcErrPtEB[0] = 0.00204;
  mcErrPtEB[1] = 0.000917;
  mcErrPtEB[2] = 0.000730;
  mcErrPtEB[3] = 0.00119625;
  
  Float_t mcEffPtEE[4];
  mcEffPtEE[0] = 0.626057;
  mcEffPtEE[1] = 0.770266;
  mcEffPtEE[2] = 0.846824;
  mcEffPtEE[3] = 0.909447;

  Float_t mcErrPtEE[4];
  mcErrPtEE[0] = 0.002778;
  mcErrPtEE[1] = 0.001529;
  mcErrPtEE[2] = 0.07719;
  mcErrPtEE[3] = 0.001755;

  // -------------------------------------
  // hardcoded: efficiency on MC (90%), high R9 (nome misleading...)
  /*
  Float_t dataEffPtEB[4];
  dataEffPtEB[0] = 0.933638;
  dataEffPtEB[1] = 0.954063;
  dataEffPtEB[2] = 0.964888;
  dataEffPtEB[3] = 0.97694;

  Float_t dataErrPtEB[4];
  dataErrPtEB[0] = 0.002329;
  dataErrPtEB[1] = 0.0009391;
  dataErrPtEB[2] = 0.0006698;
  dataErrPtEB[3] = 0.0120207;
  
  Float_t dataEffPtEE[4];
  dataEffPtEE[0] = 0.930876;
  dataEffPtEE[1] = 0.96969;
  dataEffPtEE[2] = 0.980841;
  dataEffPtEE[3] = 0.987945;

  Float_t dataErrPtEE[4];
  dataErrPtEE[0] = 0.002852;
  dataErrPtEE[1] = 0.001196;
  dataErrPtEE[2] = 0.0007996;
  dataErrPtEE[3] = 0.00111779;
  */

  // hardcoded: efficiency on MC (90%), low R9 (nome misleading...)
  /*
  Float_t mcEffPtEB[4];
  mcEffPtEB[0] = 0.64763;
  mcEffPtEB[1] = 0.741015;
  mcEffPtEB[2] = 0.792764;
  mcEffPtEB[3] = 0.835521;

  Float_t mcErrPtEB[4];
  mcErrPtEB[0] = 0.002352;
  mcErrPtEB[1] = 0.001158;
  mcErrPtEB[2] = 0.000986;
  mcErrPtEB[3] = 0.001738;
  
  Float_t mcEffPtEE[4];
  mcEffPtEE[0] = 0.540286;
  mcEffPtEE[1] = 0.694782;
  mcEffPtEE[2] = 0.783672;
  mcEffPtEE[3] = 0.861586;

  Float_t mcErrPtEE[4];
  mcErrPtEE[0] = 0.23148;
  mcErrPtEE[1] = 0.001958;
  mcErrPtEE[2] = 0.001649;
  mcErrPtEE[3] = 0.002647;
  */

  // -------------------------------------
  // histograms: 2D plots
  Float_t LowerEta[3];
  LowerEta[0]=0.0;
  LowerEta[1]=1.5;
  LowerEta[2]=2.5;

  Float_t LowerPt[5];
  LowerPt[0]=20.0;
  LowerPt[1]=30.0;
  LowerPt[2]=40.0;
  LowerPt[3]=50.0;
  LowerPt[4]=200.0;

  TH2F *DataEffMap = new TH2F( "DataEffMap",  "data efficiency map", 2, LowerEta, 4, LowerPt);
  TH2F *MCEffMap   = new TH2F( "MCEffMap",    "MC efficiency map",   2, LowerEta, 4, LowerPt);
  
  for (int jj=1; jj<5; jj++) {
    int theindex = jj-1;
    DataEffMap->SetBinContent(1,jj,dataEffPtEB[theindex]);
    DataEffMap->SetBinContent(2,jj,dataEffPtEE[theindex]);
    DataEffMap->SetBinError(1,jj,dataErrPtEB[theindex]);
    DataEffMap->SetBinError(2,jj,dataErrPtEE[theindex]);

    MCEffMap->SetBinContent(1,jj,mcEffPtEB[theindex]);
    MCEffMap->SetBinContent(2,jj,mcEffPtEE[theindex]);
    MCEffMap->SetBinError(1,jj,mcErrPtEB[theindex]);
    MCEffMap->SetBinError(2,jj,mcErrPtEE[theindex]);
  }

  DataEffMap->SetTitle("data");
  DataEffMap->GetXaxis()->SetTitle("probe #eta");
  DataEffMap->GetYaxis()->SetTitle("probe pT [GeV]");

  MCEffMap->SetTitle("MC");
  MCEffMap->GetXaxis()->SetTitle("probe #eta");
  MCEffMap->GetYaxis()->SetTitle("probe pT [GeV]");
  

  // -------------------------------------
  // data: eff vs pT
  TH1F *DataEffVsPt_barrel = new TH1F( "DataEffVsPt_barrel" , "DataEffVsPt_barrel", 4, LowerPt);
  TH1F *DataEffVsPt_endcap = new TH1F( "DataEffVsPt_endcap" , "DataEffVsPt_endcap", 4, LowerPt);
  for (int jj=1; jj<5; jj++) {
    int theindex = jj-1;
    DataEffVsPt_barrel->SetBinContent(jj,dataEffPtEB[theindex]);
    DataEffVsPt_barrel->SetBinError(jj,dataErrPtEB[theindex]);
    DataEffVsPt_endcap->SetBinContent(jj,dataEffPtEE[theindex]);
    DataEffVsPt_endcap->SetBinError(jj,dataErrPtEE[theindex]);
  }
  DataEffVsPt_barrel->SetMarkerColor(4);
  DataEffVsPt_barrel->SetLineColor(4);
  DataEffVsPt_barrel->SetMarkerStyle(20);
  DataEffVsPt_barrel->SetMarkerSize(0.9);
  DataEffVsPt_barrel->GetXaxis()->SetTitle("probe pT [GeV]");
  DataEffVsPt_barrel->SetTitle("photonID efficiency");

  DataEffVsPt_endcap->SetLineColor(4);
  DataEffVsPt_endcap->SetMarkerColor(4);
  DataEffVsPt_endcap->SetMarkerStyle(20);
  DataEffVsPt_endcap->SetMarkerSize(0.9);
  DataEffVsPt_endcap->GetXaxis()->SetTitle("probe pT [GeV]");
  DataEffVsPt_endcap->SetTitle("photonID efficiency");


  // ---------------------------------------
  // mc: eff vs pT
  TH1F *McEffVsPt_barrel = new TH1F( "McEffVsPt_barrel" , "McEffVsPt_barrel", 4, LowerPt);
  TH1F *McEffVsPt_endcap = new TH1F( "McEffVsPt_endcap" , "McEffVsPt_endcap", 4, LowerPt);
  for (int jj=1; jj<5; jj++) {
    int theindex = jj-1;
    McEffVsPt_barrel->SetBinContent(jj,mcEffPtEB[theindex]);
    McEffVsPt_barrel->SetBinError(jj,mcErrPtEB[theindex]);
    McEffVsPt_endcap->SetBinContent(jj,mcEffPtEE[theindex]);
    McEffVsPt_endcap->SetBinError(jj,mcErrPtEE[theindex]);
  }
  McEffVsPt_barrel->SetMarkerColor(2);
  McEffVsPt_barrel->SetLineColor(2);
  McEffVsPt_barrel->SetMarkerStyle(21);
  McEffVsPt_barrel->SetMarkerSize(0.9);
  McEffVsPt_barrel->SetTitle("photonID efficiency");
  McEffVsPt_barrel->GetXaxis()->SetTitle("probe pT [GeV]");

  McEffVsPt_endcap->SetMarkerColor(2);
  McEffVsPt_endcap->SetLineColor(2);
  McEffVsPt_endcap->SetMarkerStyle(21);
  McEffVsPt_endcap->SetMarkerSize(0.9);
  McEffVsPt_endcap->SetTitle("photonID efficiency");
  McEffVsPt_endcap->GetXaxis()->SetTitle("probe pT [GeV]");


  // plots
  gStyle->SetOptStat(0);

  TLegend *leg;
  leg = new TLegend(0.4,0.4,0.65,0.65);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.05);
  leg->SetFillColor(0);
  // leg->AddEntry(DataEffVsPt_endcap, "MC, highR9", "lp");
  // leg->AddEntry(McEffVsPt_endcap,   "MC, low R9", "lp");
  leg->AddEntry(DataEffVsPt_endcap, "data", "lp");
  leg->AddEntry(McEffVsPt_endcap,   "MC",   "lp");

  TCanvas myC1("c1", "c1", 1);
  DataEffMap->Draw("colz");
  DataEffMap->Draw("textsame");
  myC1.SaveAs("dataMap.png");

  TCanvas myC1b("c1b", "c1b", 1);
  MCEffMap->Draw("colz");
  MCEffMap->Draw("textsame");
  myC1b.SaveAs("mcMap.png");

  TCanvas myC2("c2", "c2", 1);
  DataEffVsPt_barrel->SetMinimum(0.5);
  DataEffVsPt_barrel->SetMaximum(1.);
  DataEffVsPt_barrel->Draw();
  myC2.SaveAs("dataEffVsPt_barrel.png");

  TCanvas myC3("c3", "c3", 1);
  DataEffVsPt_endcap->SetMinimum(0.5);
  DataEffVsPt_endcap->SetMaximum(1.);
  DataEffVsPt_endcap->Draw();
  myC3.SaveAs("dataEffVsPt_endcap.png");

  TCanvas myC4("c4", "c4", 1);
  McEffVsPt_barrel->SetMinimum(0.5);
  McEffVsPt_barrel->SetMaximum(1.);
  McEffVsPt_barrel->Draw();
  myC4.SaveAs("mcEffVsPt_barrel.png");

  TCanvas myC5("c5", "c5", 1);
  McEffVsPt_endcap->SetMinimum(0.5);
  McEffVsPt_endcap->SetMaximum(1.);
  McEffVsPt_endcap->Draw();
  myC5.SaveAs("mcEffVsPt_endcap.png");

  TCanvas myC6("c6", "c6", 1);
  DataEffVsPt_barrel->Draw();
  McEffVsPt_barrel->Draw("same");
  leg->Draw();
  myC6.SaveAs("compEffVsPt_barrel.png");

  TCanvas myC7("c7", "c7", 1);
  DataEffVsPt_endcap->Draw();
  McEffVsPt_endcap->Draw("same");
  leg->Draw();
  myC7.SaveAs("compEffVsPt_endcap.png");
}
Beispiel #10
0
TH2F* fixrange(TH2F* old, int numB) {

  float x1, x2;
  string name = old->GetName();

  if (name.find("Ht")!=string::npos) {
    x1 = 30.;
    x2 = 500.;
    if (numB==2) x2 = 400.;
  } else if (name.find("jet_pt")!=string::npos) {
    x1 = 30.;
    x2 = 300.;
    if (numB==2) {
      if (name.find("first")!=string::npos) x2 = 200.;
      if (name.find("second")!=string::npos) x2 = 120.;
    }
  } else if (name.find("pt_Z")!=string::npos) {
    x1 = 0.;
    x2 = 300.;
    if (numB==2) x2 = 230.;
  } else {
    x1 = old->GetXaxis()->GetBinCenter(1);
    x2 = old->GetXaxis()->GetBinCenter(old->GetNbinsX());
  }

  float y1=x1;
  float y2=x2;

  int nx = old->GetXaxis()->FindBin(x2)-old->GetXaxis()->FindBin(x1)+1;
  int ny = old->GetYaxis()->FindBin(y2)-old->GetYaxis()->FindBin(y1)+1;

  x1 = old->GetXaxis()->GetBinLowEdge(old->GetXaxis()->FindBin(x1));
  x2 = old->GetXaxis()->GetBinUpEdge(old->GetXaxis()->FindBin(x2));
  y1 = old->GetYaxis()->GetBinLowEdge(old->GetYaxis()->FindBin(y1));
  y2 = old->GetYaxis()->GetBinUpEdge(old->GetYaxis()->FindBin(y2));

  TH2F* tmp = new TH2F("tmp",old->GetTitle(),nx,x1,x2,ny,y1,y2);
  tmp->Sumw2();

  tmp->GetXaxis()->SetTitle(old->GetXaxis()->GetTitle());
  tmp->GetYaxis()->SetTitle(old->GetYaxis()->GetTitle());

  for (int i=0;i<=old->GetNbinsX()+1;i++) {
    for (int j=0;j<=old->GetNbinsY()+1;j++) {
      int ii = tmp->GetXaxis()->FindBin(old->GetXaxis()->GetBinCenter(i));
      int jj = tmp->GetYaxis()->FindBin(old->GetYaxis()->GetBinCenter(j));
      float c1 = tmp->GetBinContent(ii,jj);
      float e1 = tmp->GetBinError(ii,jj);
      float c2 = old->GetBinContent(i,j);
      float e2 = old->GetBinError(i,j);
//
// underflows and overflows *must* be discarded before the unfolding:
// inefficiencies and fakes/background are taken from the additional entries
// in the 'reco' and 'truth' histograms, respectively
//
      if (ii==0) continue;
      if (ii==tmp->GetNbinsX()+1) continue;
      if (jj==0) continue;
      if (jj==tmp->GetNbinsY()+1) continue;

      tmp->SetBinContent(ii,jj,c1+c2);
      tmp->SetBinError(ii,jj,TMath::Sqrt(e1*e1+e2*e2));
    }
  }

  tmp->SetEntries(old->GetEntries());

  old->Delete();
  tmp->SetName(name.c_str());

  return tmp;
}
Beispiel #11
0
TH2F* Smooth(TH2F* thish, Int_t ntimes, Option_t *option, Int_t offset) {

   // Smooth bin contents of this 2-d histogram using kernel algorithms
   // similar to the ones used in the raster graphics community.
   // Bin contents in the active range are replaced by their smooth values.
   // If Errors are defined via Sumw2, they are scaled.
   // 3 kernels are proposed k5a, k5b and k3a.
   // k5a and k5b act on 5x5 cells (i-2,i-1,i,i+1,i+2, and same for j)
   // k5b is a bit more stronger in smoothing
   // k3a acts only on 3x3 cells (i-1,i,i+1, and same for j).
   // By default the kernel "k5a" is used. You can select the kernels "k5b" or "k3a"
   // via the option argument.
   // If TAxis::SetRange has been called on the x or/and y axis, only the bins
   // in the specified range are smoothed.
   // In the current implementation if the first argument is not used (default value=1).
   //
   // implementation by David McKee ([email protected]). Extended by Rene Brun

   Double_t k5a[5][5] =  { { 0, 0, 1, 0, 0 },
                           { 0, 2, 2, 2, 0 },
                           { 1, 2, 5, 2, 1 },
                           { 0, 2, 2, 2, 0 },
                           { 0, 0, 1, 0, 0 } };
   Double_t k5b[5][5] =  { { 0, 1, 2, 1, 0 },
                           { 1, 2, 4, 2, 1 },
                           { 2, 4, 8, 4, 2 },
                           { 1, 2, 4, 2, 1 },
                           { 0, 1, 2, 1, 0 } };
   Double_t k3a[3][3] =  { { 0, 1, 0 },
                           { 1, 2, 1 },
                           { 0, 1, 0 } };

   if (ntimes > 1) {
      Warning("Smooth","Currently only ntimes=1 is supported");
   }
   TString opt = option;
   opt.ToLower();
   Int_t ksize_x=5;
   Int_t ksize_y=5;
   Double_t *kernel = &k5a[0][0];
   if (opt.Contains("k5b")) kernel = &k5b[0][0];
   if (opt.Contains("k3a")) {
      kernel = &k3a[0][0];
      ksize_x=3;
      ksize_y=3;
   }

   TH2F* hworking = (TH2F*)thish->Clone();

   // find i,j ranges
   Int_t ifirst = thish->GetXaxis()->GetFirst();
   Int_t ilast  = thish->GetXaxis()->GetLast();
   Int_t jfirst = thish->GetYaxis()->GetFirst();
   Int_t jlast  = thish->GetYaxis()->GetLast();

   // Determine the size of the bin buffer(s) needed
   Int_t nx = thish->GetNbinsX();
   Int_t ny = thish->GetNbinsY();
  cout << nx << " " << ny << endl; 
   Int_t bufSize  = (nx+2)*(ny+2);
   Double_t *buf  = new Double_t[bufSize];
   Double_t *ebuf = new Double_t[bufSize];

   // Copy all the data to the temporary buffers
   Int_t i,j,bin;
   for (i=ifirst; i<=ilast; i++){
      for (j=jfirst; j<=jlast; j++){
         Int_t bin = thish->GetBin(i,j);
         buf[bin] =thish->GetBinContent(bin);
         ebuf[bin]=thish->GetBinError(bin);
      }
   }

   // Kernel tail sizes (kernel sizes must be odd for this to work!)
   Int_t x_push = (ksize_x-1)/2;
   Int_t y_push = (ksize_y-1)/2;

   // main work loop
   for (int i=ifirst; i<=ilast; i++){
      for (int j=jfirst; j<=jlast; j++) {
         if (i-j<offset) continue;

         Double_t content = 0.0;
         Double_t error = 0.0;
         Double_t norm = 0.0;

         for (Int_t n=0; n<ksize_x; n++) {
            for (Int_t m=0; m<ksize_y; m++) {
               Int_t xb = i+(n-x_push);
               Int_t yb = j+(m-y_push);
               if ( (xb >= 1) && (xb <= nx) && (yb >= 1) && (yb <= ny) ) {
                  Int_t bin = thish->GetBin(xb,yb);
                  Double_t k = kernel[n*ksize_y +m];
                  //if ( (k != 0.0 ) && (buf[bin] != 0.0) ) { // General version probably does not want the second condition
                  if ( k != 0.0 ) {
                     norm    += k;
                     content += k*buf[bin];
                     error   += k*k*buf[bin]*buf[bin];
                  }
               }
            }
         }

         if ( norm != 0.0 ) {
            hworking->SetBinContent(i,j,content/norm);
            error /= (norm*norm);
            hworking->SetBinError(i,j,sqrt(error));
         }
      }
   }

   delete [] buf;
   delete [] ebuf;
   return hworking;
}
void cetaflatHEM3t(int nIterN=1, double Ethr1=4, double Ethr2=150) {

    gStyle->SetOptLogz(0);
    gStyle->SetMarkerSize(0.7);
    gStyle->SetMarkerStyle(20);
    gStyle->SetPadGridX(0);
    gStyle->SetPadGridY(0);
    gStyle->SetTitleOffset(1.7,"Y");
    gStyle->SetTitleOffset(0.9,"X");
    //gStyle->SetPadRightMargin(0.12);
    gStyle->SetPadTopMargin(0.06);
    gStyle->SetPadRightMargin(0.03);
    gStyle->SetPadLeftMargin(0.2);
    //gStyle->SetNdivisions(516);
    gStyle->SetStatH(0.09);
    gStyle->SetStatW(0.3);
    gStyle->SetTitleW(0.4);
    gStyle->SetTitleX(0.3);
    gStyle->SetOptStat(0);
    //gStyle->SetOptStat(1111111);
    gROOT->ForceStyle();

    char ctit[145];

    static const double theHBHEEtaBounds[] = { 0.000, 0.087, 0.087*2, 0.087*3, 0.087*4,
                                               0.087*5, 0.087*6, 0.087*7, 0.087*8, 0.087*9,
                                               0.087*10, 0.087*11, 0.087*12, 0.087*13, 0.087*14,
                                               0.087*15, 0.087*16, 0.087*17, 0.087*18, 0.087*19,
                                               1.74, 1.83, 1.93, 2.043, 2.172,
                                               2.332, 2.5, 2.65, 2.868, 3.000
                                             };

    static const double theHFEtaBounds[] = { 2.853, 2.964, 3.139, 3.314, 3.489, 3.664, 3.839,
                                             4.013, 4.191, 4.363, 4.538, 4.716, 4.889, 5.191
                                           };

    // ---------------- Histos input --------------------------------------

    char ftit[145];
    //sprintf(ftit,"%s","phi43val2012A");
    //sprintf(ftit,"%s","phi2012A_May");
    //sprintf(ftit,"%s","phiSym524_2012AB");
    //sprintf(ftit,"%s","phiSym524newGain_2012AB");
    //sprintf(ftit,"%s","phiSym524newGain_2012ABC");
    sprintf(ftit,"%s","phiSym533Corr45Gain507_2012D");

    sprintf(ctit,"/home/vodib/beam12/intercal/%s.root",ftit);
    TFile *fila = new TFile (ctit);
    cout<<"File= "<<ctit<<endl;

    TH1F *hcounter =   new TH1F(*((TH1F*)fila->Get("phaseHF/hcounter")));
    cout<<"Stat= "<<hcounter->GetBinContent(2)<<endl;
    cout<<"E within: "<<Ethr1<<" - "<<Ethr2<<endl;

    TH2F* hmapP = new TH2F("hmapP","E  HEM;i#eta;i#phi",14,-29.5,-15.5,72,0,72);
    TH2F* hmapP0 = new TH2F("hmapP0","E0  HEM;i#eta;i#phi",14,-29.5,-15.5,72,0,72);
    TH2F* hmapPc = new TH2F("hmapPc","corr  HEM;i#eta;i#phi",14,-29.5,-15.5,72,0,72);
    hmapPc->Sumw2();
    TH1F *hcorr1D = new TH1F("hcorr1D","Corr",150,0.5,2);
    TH1F *ht = new TH1F("ht","ht",20000,0,5e7);
    TH1F *htx = new TH1F("htx","htx",20000,0,5e5);
    TH1F *htr = new TH1F("htr","htr",5000,0,3);

    /*  HE mapping:
    if (ieta==16 && depth<3) continue;
    if (ieta==17 && depth>1) continue;
    if (ieta>17 && ieta<27 && depth==3) continue;
    if (ieta==29 && depth==3) continue;
    if (ieta>20 && iphi%2==0) continue;  */


    TH1F *hdatP[14][72], *hdatPx[14][72];
    for (int ii=0; ii<14; ii++) for (int jj=0; jj<72; jj++) {
            sprintf(ctit,"h%d_%d",ii+16,jj+1);
            hdatP[ii][jj] = new TH1F(ctit,ctit,10000,0,250);
        }

    TCanvas *cx[400];
    TSpline5 *tt;

    Double_t x,y,rPL,rPS,mLE,mSE,ermean,rms;
    Double_t xx[4000],yy[4000];
    Int_t nELP, nESP, nIter=0;
    Double_t mcorrL,scorrL,mcorrS,scorrS,erLP,erSP,rLP,drLP,rSP,corrL,corrS,dcorrL,dcorrS;
    double mLEphi[14];

    TCanvas *ccxx = new TCanvas("ccxx","ccxx",0,400,800,400);
    ccxx->Divide(2,1);
    for (int ii=0; ii<14; ii++) {
        int ieta=-(ii+16);

        mLE=mSE=0;   // ------------------for initial condition
        int nmLE=0, nmSE=0;
        ht->Reset();
        htx->Reset();
        for (int ll=0; ll<72; ll++) {
            int iphi=ll+1;

            if (abs(ieta)!=16 && abs(ieta)!=27 && abs(ieta)!=28) continue;
            if (abs(ieta)>20 && iphi%2==0) continue;

            hmapPc->SetBinContent(14-ii,ll+1,1);
            hmapPc->SetBinError(14-ii,ll+1,1.e-6);
            sprintf(ctit,"phaseHF/eHEspec/E_-%d_%d_3",abs(ieta),iphi);
            hdatPx[ii][ll]  =   new TH1F(*((TH1F*)fila->Get(ctit)));
            hdatPx[ii][ll]->SetAxisRange(Ethr1,Ethr2);
            rLP = hdatPx[ii][ll]->Integral()*hdatPx[ii][ll]->GetMean();
            hmapP0->SetBinContent(14-ii,ll+1,rLP);
            if (skipHEChannel(iphi,ieta)) continue;
            if (rLP>0) {
                ht->Fill(rLP);
                htx->Fill(rLP);
                mLE += rLP;
                nmLE++;
                drLP=rLP*sqrt(pow(1./hdatPx[ii][ll]->Integral(),2)+
                              pow(hdatPx[ii][ll]->GetMeanError()/hdatPx[ii][ll]->GetMean(),2));
                hmapP0->SetBinError(14-ii,ll+1,drLP);
            }
            else hmapP0->SetBinError(14-ii,ll+1,0);
        }
        if (nmLE>0) mLE /= nmLE;
        else mLE=0;
        ccxx->cd(1);
        ht->Draw("hist");
        ccxx->cd(2);
        htx->Draw("hist");
        ccxx->Update();
        if (htx->GetBinContent(20001)>1) histspec(ht,mLE,ermean,rms,4,-5);
        else histspec(htx,mLE,ermean,rms,4,-5);
        //histspec(ht,mLE,ermean,rms);
        mLEphi[ii]=mLE;
        printf("ieta %2d :  <E>= %8.1f \n",ieta,mLE);
        if (ht->GetMean()>0) htr->Fill(ht->GetRMS()/ht->GetMean());

        for (int jj=0; jj<72; jj++) {
            int iphi=jj+1;

            if (abs(ieta)!=16 && abs(ieta)!=27 && abs(ieta)!=28) continue;
            if (abs(ieta)>20 && iphi%2==0) continue;
            if (skipHEChannel(iphi,ieta)) {
                hmapP->SetBinContent(14-ii,jj+1,hmapP0->GetBinContent(14-ii,jj+1,rLP));
                continue;
            }

            for (nIter=1; nIter<nIterN; nIter++) { //cout<<nIter<<" |  ";
                if (hmapP0->GetBinContent(14-ii,jj+1)<=0) continue;
                corrL=hmapPc->GetBinContent(14-ii,jj+1);
                hdatP[ii][jj]->Reset();

                for (int kk=1; kk<=hdatPx[ii][jj]->GetNbinsX(); kk++) {
                    xx[kk-1]=hdatPx[ii][jj]->GetBinCenter(kk);
                    yy[kk-1]=hdatPx[ii][jj]->GetBinContent(kk);
                }
                tt = new TSpline5("tt",xx,yy,1000,"",10,20);

                for (int kk=1; kk<=hdatP[ii][jj]->GetNbinsX(); kk++) {
                    x=hdatP[ii][jj]->GetBinCenter(kk);
                    y=hdatP[ii][jj]->GetBinContent(kk);
                    hdatP[ii][jj]->Fill(x*corrL,tt->Eval(x)/10.0);
                }
                tt->Delete();

                hdatP[ii][jj]->SetAxisRange(Ethr1,Ethr2);
                rLP = hdatP[ii][jj]->Integral()*hdatP[ii][jj]->GetMean();
                dcorrL=(rLP-mLE)/mLE;
                if (fabs(dcorrL)>0.5) dcorrL=0.5*dcorrL/fabs(dcorrL);
                if (rLP>0) drLP=
                        sqrt(pow(hdatP[ii][jj]->GetMeanError()/hdatP[ii][jj]->GetMean(),2)+
                             1.f/hdatP[ii][jj]->Integral()+
                             pow(dcorrL/(1.0+sqrt((float) nIter)),2));
                else drLP=1.e-6;
                if (fabs(dcorrL)>0.001) {
                    //corrL*=1-20*dcorrL/(40+nIter*nIter);
                    //corrL*=1-dcorrL/(2+nIter);
                    corrL*=1-dcorrL/(1.0+sqrt((float) nIter));
                    //printf("%2d : %2d / %2d / 1 %7.3f %7.3f\n",nIter,ieta,iphi,dcorrL,corrL);
                    hmapPc->SetBinContent(14-ii,jj+1,corrL);
                    hmapPc->SetBinError(14-ii,jj+1,corrL*drLP);
                    hmapP->SetBinContent(14-ii,jj+1,rLP);
                }
                else {
                    printf("%2d : %2d / %2d / 3 %7.3f %8.4f %8.4f\n",
                           nIter,ieta,iphi,dcorrL,corrL,corrL*drLP);
                    hmapP->SetBinContent(14-ii,jj+1,rLP);
                    hmapPc->SetBinError(14-ii,jj+1,corrL*drLP);
                    break;
                }
                if (nIter==nIterN-1)
                    printf("%2d : %2d / %2d / 3 %8.4f %8.4f %8.4f\n",nIter,ieta,iphi,dcorrL,corrL,corrL*drLP);
            }
        }
    }

    printf("\nieta      eta  width  dE/dPhidEta\n");
    double xeta[14], weta[14], yield[14];
    int ind=0;
    for (int i=0; i<14; i++) {
        int ieta=-(i+16);
        if (abs(ieta)!=16 && abs(ieta)!=27 && abs(ieta)!=28) continue;
        xeta[ind]=-(theHBHEEtaBounds[i+15]+theHBHEEtaBounds[i+16])/2;
        weta[ind]=(theHBHEEtaBounds[i+16]-theHBHEEtaBounds[i+15]);
        yield[ind]=mLEphi[i];
        if (abs(ieta)<21) yield[ind]*=72/weta[ind];
        else yield[ind]*=36/weta[ind];
        printf("%3d   3 %7.3f%7.3f   %g\n",ieta,xeta[ind],weta[ind],yield[ind]);
        ind++;
    }
    TCanvas *cgL = new TCanvas("cgL","cgL",300,300,600,600);
    TGraphErrors *grL = new TGraphErrors(ind,xeta,yield,0,0);
    grL->SetTitle("HEM ;#eta;E / #Delta#eta ,  GeV");
    grL->Draw("1+PAl");
    cgL->Print("pictHEplot/phiProfHEM3.gif");
    //cgL->Print("HEmc/phiProfM3.gif");


    //TFile *histf = new TFile("HEM3mc.root","RECREATE");

    FILE *ft1;
    sprintf(ctit,"corrHEM3_%s_%d_%d.txt",ftit,((int) Ethr1),((int) Ethr2));
    //sprintf(ctit,"corrHEM3_MC_%d_%d.txt",((int) Ethr1),((int) Ethr2));
    if ((ft1 = fopen(ctit,"w"))==NULL) {              // Open new file
        printf("\nNo file %s open => EXIT\n\n",file);
        return;
    }
    printf("\n\n File '%s' open \n\n",ctit);

    TH1D *hprL[14],*hprL0[14],*hprcL[16];
    TCanvas *cpr[14],*ccc[16];
    TLine *lin1 = new TLine(0,1,71,1);
    lin1->SetLineWidth(1);

    int noff=0;
    for (int ii=0; ii<14; ii++) {

        int ieta=-(ii+16);
        if (abs(ieta)!=16 && abs(ieta)!=27 && abs(ieta)!=28) continue;

        sprintf(ctit,"HEMcorr_%d_3",ieta);  // draw corrections
        hprcL[ii] = hmapPc->ProjectionY(ctit,14-ii,14-ii);
        hprcL[ii]->SetTitle(ctit);
        ccc[ii] = new TCanvas(ctit,ctit,800,100,500,500);
        hprcL[ii]->SetMinimum(0.41);
        hprcL[ii]->SetMaximum(hprcL[ii]->GetMaximum()*1.1);
        hprcL[ii]->SetTitleOffset(0.9,"X");
        hprcL[ii]->Draw("e");
        lin1->Draw();
        sprintf(ctit,"pictHEplot/HEM3corr_%d.gif",ieta);
        //sprintf(ctit,"HEmc/HEM3c_4_100G_%d.gif",ieta);
        ccc[ii]->Print(ctit);
        //hprcL[ii]->Write();

        sprintf(ctit,"HEM_E_%d_3;i#phi;GeV",ieta);
        hprL0[ii] = hmapP0->ProjectionY(ctit,14-ii,14-ii);
        hprL0[ii]->SetTitle(ctit);
        sprintf(ctit,"HEM__%d",ieta);
        hprL[ii] = hmapP->ProjectionY(ctit,14-ii,14-ii);
        if (abs(ieta)>20) {
            hprL[ii]->Rebin();
            hprL0[ii]->Rebin();
        }
        cpr[ii] = new TCanvas(ctit,ctit,800,100,500,500);
        hprL0[ii]->SetFillColor(3);
        hprL0[ii]->SetLineColor(3);
        hprL0[ii]->SetLineWidth(1);
        hprL0[ii]->SetTitleOffset(0.9,"X");
        hprL0[ii]->SetMinimum(0);
        hprL0[ii]->Draw("hist");
        hprL[ii]->Draw("samehist");
        sprintf(ctit,"pictHEplot/HEM_E_%d_3.gif",ieta);
        //sprintf(ctit,"HEmc/HEM_E_%d_3.gif",ieta);
        cpr[ii]->Print(ctit);
        //hprL0[ii]->Write();

        for (int jj=0; jj<72; jj++) {
            int ieta=-(ii+16);
            int iphi=jj+1;

            if (abs(ieta)>20 && iphi%2==0) continue;

            corrL=hmapPc->GetBinContent(14-ii,jj+1);
            dcorrL=hmapPc->GetBinError(14-ii,jj+1);
            hcorr1D->Fill(corrL);
            noff++;
            //printf("%2d : %2d / %2d / 3 %8.4f %8.4f\n",noff,ieta,iphi,corrL,dcorrL);
            fprintf(ft1,"%2d   %2d   3 %8.4f %8.4f\n",ieta,iphi,corrL,dcorrL);
        }
    }
    fclose(ft1);

    TCanvas *c1corr =new TCanvas("c1corr","c1corr",30,30,600,600);
    hcorr1D->Draw("hist");
    histStat(hcorr1D,1);
    c1corr->Print("pictHEplot/corrHEM3.gif");
    //c1corr->Print("HEmc/corrHEM3.gif");

    TCanvas *ctr = new TCanvas("ctr","ctr",0,0,650,600);
    htr->Draw("hist");
    ctr->Update();

    TCanvas *chmapP = new TCanvas("chmapP","chmapP",0,0,650,600);
    chmapP->cd();
    chmapP->SetRightMargin(0.12);
    chmapP->SetLogz();
    hmapP->SetAxisRange(hmapP->GetBinContent(14,1)/2,-1111,"Z");
    hmapP->Draw("colz");
    chmapP->Print("pictHEplot/hmapHEM3.gif");
    chmapP->Update();

    TCanvas *chmapP0 = new TCanvas("chmapP0","chmapP0",0,0,650,600);
    chmapP0->cd();
    chmapP0->SetRightMargin(0.12);
    chmapP0->SetLogz();
    hmapP0->SetAxisRange(hmapP0->GetBinContent(14,1)/2,-1111,"Z");
    hmapP0->Draw("colz");
    chmapP0->Print("pictHEplot/hmap0HEM3.gif");
    chmapP0->Update();

    TCanvas *chmapPc = new TCanvas("chmapPc","chmapPc",0,0,650,600);
    chmapPc->cd();
    chmapPc->SetRightMargin(0.12);
    hmapPc->SetAxisRange(0.6,2,"Z");
    hmapPc->Draw("colz");
    chmapPc->Print("pictHEplot/hmapcHEM3.gif");
    chmapPc->Update();

    sprintf(ctit,"HEM3o_%s_%d_%d.root",ftit,((int) Ethr1),((int) Ethr2));
    TFile *histf = new TFile(ctit,"RECREATE");
    hmapP->Write();
    hmapP0->Write();
    hmapPc->Write();
    histf->Close();

}
Beispiel #13
0
void ana_Run11_eff()
{

  const int rebin = 1;

  TFile *f = TFile::Open("Rootfiles/Run11_eff.root","read");

  // Run with weigth
  TH2F *hMcPtVsEta = (TH2F*)f->Get("mcJpsiPtY");
  TH2F *hRcPtVsEta = (TH2F*)f->Get("hHt2JpsiPE");

  draw2D(hMcPtVsEta);
  draw2D(hRcPtVsEta);

  hMcPtVsEta->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6);
  TH1F *hMcPt = (TH1F*)hMcPtVsEta->ProjectionY("hMcPt");
  hMcPt->Rebin(rebin);
  hMcPt->SetMarkerStyle(20);
  draw1D(hMcPt,"",kTRUE);

  hRcPtVsEta->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6);
  TH1F *hRcPt = (TH1F*)hRcPtVsEta->ProjectionY("hRcPt");
  hRcPt->Rebin(rebin);
  hRcPt->SetMarkerStyle(21);
  hRcPt->SetMarkerColor(2);
  hRcPt->SetLineColor(2);
  hRcPt->Draw("sames P");

  TH1F *hRatio = (TH1F*)hRcPt->Clone("hRatio_fromRunning");
  hRatio->Rebin(100);
  hMcPt->Rebin(100);
  hRatio->Divide(hMcPt);
  cEff = draw1D(hRatio,"");

  // Run without weight
  TH2F *hMcPtVsEtaNoWeight = (TH2F*)f->Get("mcJpsiPtY_Or");
  draw2D(hMcPtVsEtaNoWeight);  

  TH2F *hMcPtVsRcNoWeight = (TH2F*)f->Get("hJpsiRcvsMC_Cut1");
  hMcPtVsRcNoWeight->RebinX(rebin);
  hMcPtVsRcNoWeight->RebinY(rebin);
  draw2D(hMcPtVsRcNoWeight);

  hMcPtVsEtaNoWeight->GetXaxis()->SetRangeUser(-1+1e-6,1-1e-6);
  TH1F *hMcPtNoWeight = (TH1F*)hMcPtVsEtaNoWeight->ProjectionY("hMcPtNoWeight");
  hMcPtNoWeight->Rebin(rebin);
  hMcPtNoWeight->SetMarkerStyle(20);
  hMcPtNoWeight->SetMinimum(1);
  draw1D(hMcPtNoWeight,"",kTRUE);

  TH1F *hRcPtNoWeight = (TH1F*)hMcPtVsRcNoWeight->ProjectionX("hRcPtNoWeight");
  hRcPtNoWeight->SetMarkerStyle(21);
  hRcPtNoWeight->SetMarkerColor(2);
  hRcPtNoWeight->SetLineColor(2);
  hRcPtNoWeight->Draw("sames P");

  TH1F *hRatioNoWeight = (TH1F*)hRcPtNoWeight->Clone("hRatioNoWeight");
  hRatioNoWeight->Divide(hMcPtNoWeight);
  cEff->cd();
  hRatioNoWeight->SetMarkerColor(4);
  hRatioNoWeight->Draw("samesP");

  // weight with input histogram
  TH1F *hMcPtWeight = (TH1F*)hMcPtNoWeight->Clone("hMcPtWeight");
  TH2F *hMcPtVsRcWeight = (TH2F*)hMcPtVsRcNoWeight->Clone("hMcPtVsRcWeight");
  for(int ibin=1; ibin<=hMcPtVsRcNoWeight->GetNbinsX(); ibin++)
    {
      double scale = hMcPt->GetBinContent(ibin);
      hMcPtWeight->SetBinContent(ibin,hMcPtWeight->GetBinContent(ibin)*scale);
      hMcPtWeight->SetBinError(ibin,hMcPtWeight->GetBinError(ibin)*scale);
      for(int jbin=1; jbin<=hMcPtVsRcNoWeight->GetNbinsY(); jbin++)
	{
	  hMcPtVsRcWeight->SetBinContent(ibin,jbin,hMcPtVsRcWeight->GetBinContent(ibin,jbin)*scale);
	  hMcPtVsRcWeight->SetBinError(ibin,jbin,hMcPtVsRcWeight->GetBinError(ibin,jbin)*scale);
	}
    }
  TH1F *hRcPtWeight = (TH1F*)hMcPtVsRcWeight->ProjectionY("hRcPtWeight");
  hRcPtWeight->SetMarkerStyle(21);
  hRcPtWeight->SetMarkerColor(2);
  hRcPtWeight->SetLineColor(2);

  draw2D(hMcPtVsRcWeight);
  draw1D(hMcPtWeight,"",kTRUE);
  hRcPtWeight->Draw("sames P");
  
  TH1F *hRatioWeight = (TH1F*)hRcPtWeight->Clone("hRatioWeight");
  hRatioWeight->Divide(hMcPtWeight);
  cEff->cd();
  hRatioWeight->SetMarkerColor(6);
  hRatioWeight->Draw("samesP");

  TH1F *hCheck = (TH1F*)hRatioWeight->Clone("check");
  hCheck->Divide(hRatio);
  draw1D(hCheck);

  // weight with fitted function
  TCanvas *c = new TCanvas("Fit","Fit",800,600);
  SetPadMargin(gPad,0.15,0.15);
  gPad->SetLogy();
  TH1F *h = new TH1F("histogram",";;;",7,0,30);
  h->GetYaxis()->SetRangeUser(1e-7,100);
  h->Draw();

  TFile *fdata = TFile::Open("Rootfiles/Spectrum_in_bin.root","read");
  TGraphErrors	*gr = (TGraphErrors*)fdata->Get("gall");
  gr->SetMarkerColor(1);
  gr->SetLineColor(1);
  gr->GetXaxis()->SetRangeUser(0,30);
  gr->Draw("sames PE");
  TF1 *func = new TF1("func",InvPt,0,30,4);
  func->SetParameters(0.4,-0.4796,4.229,-7.54);
  gr->Fit(func,"RL");

  TH1F *hMcPtFunc = (TH1F*)hMcPtNoWeight->Clone("hMcPtFunc");
  TH2F *hMcPtVsRcFunc = (TH2F*)hMcPtVsRcNoWeight->Clone("hMcPtVsRcFunc");
  for(int ibin=1; ibin<=hMcPtVsRcFunc->GetNbinsX(); ibin++)
    {
      double scale = func->Eval(hMcPtFunc->GetBinCenter(ibin));
      hMcPtFunc->SetBinContent(ibin,hMcPtFunc->GetBinContent(ibin)*scale);
      hMcPtFunc->SetBinError(ibin,hMcPtFunc->GetBinError(ibin)*scale);
      for(int jbin=1; jbin<=hMcPtVsRcNoWeight->GetNbinsY(); jbin++)
	{
	  hMcPtVsRcFunc->SetBinContent(ibin,jbin,hMcPtVsRcFunc->GetBinContent(ibin,jbin)*scale);
	  hMcPtVsRcFunc->SetBinError(ibin,jbin,hMcPtVsRcFunc->GetBinError(ibin,jbin)*scale);
	}
    }
  TH1F *hRcPtFunc = (TH1F*)hMcPtVsRcFunc->ProjectionY("hRcPtFunc");
  hRcPtFunc->SetMarkerStyle(21);
  hRcPtFunc->SetMarkerColor(2);
  hRcPtFunc->SetLineColor(2);
  hMcPtVsRcFunc->GetZaxis()->SetRangeUser(1e-4,1e2);
  draw2D(hMcPtVsRcFunc);
  hMcPtFunc->GetYaxis()->SetRangeUser(1e-4,5e4);
  draw1D(hMcPtFunc,"",kTRUE);
  hRcPtFunc->Draw("sames P");

  TH1F *hRatioFunc = (TH1F*)hRcPtFunc->Clone("hRatioFunc");
  hRatioFunc->Rebin(100);
  hMcPtFunc->Rebin(100);
  hRatioFunc->Divide(hMcPtFunc);
  cEff->cd();
  hRatioFunc->SetMarkerColor(5);
  hRatioFunc->Draw("samesP");
  
  TH1F *hCheck2 = (TH1F*)hRatioFunc->Clone("check2");
  hCheck2->Divide(hRatio);
  draw1D(hCheck2);

}
void makeScaleFactorFile()
{
	gROOT->SetBatch(kTRUE);
	gStyle->SetOptStat(0);
	
	TString Type = "SIP";
	
	Int_t bineta;
	TString Period = "Moriond_2016";
	
	enum NameEfficiencyNumber_t {datamc = 0, datamc_error = 1};
	
//	TFile *outputFile = new TFile( "ScaleFactors_ID_2015.root", "RECREATE", "", 0 );
	TFile *outputFile = new TFile(Period + "/" + Type + ".root", "RECREATE", "", 0 );
	
	std::cout << "[INFO] Creating scale factors TH2F..." << endl;
	
//	Float_t localPtBinEdges[] = { 7., 20., 30., 200. }; // Slices in pT
	Float_t localPtBinEdges[] = { 7., 10., 20., 30., 40., 50., 200. }; // Slices in pT

	Int_t nbinspt = sizeof(localPtBinEdges)/sizeof(Float_t) - 1 ;
	
//	Float_t localEtaBinEdges[] = { -2.5, 0., 2.5 }; // Slices in eta
	Float_t localEtaBinEdges[] = { -2.5, -2.0, -1.479, -0.8, 0., 0.8, 1.479, 2.0, 2.5 }; // Slices in eta

	Int_t nbinseta = sizeof(localEtaBinEdges)/sizeof(Float_t) - 1;
	
	std::cout << "Bins pt / Eta : "<< nbinspt <<" / " << nbinseta << std::endl;
		
//	TH2F *hScaleFactors = new TH2F( "hScaleFactors_ID", "; p_{T}; #eta", nbinspt, localPtBinEdges, nbinseta, localEtaBinEdges );
	TH2F *hScaleFactors = new TH2F( "hScaleFactors_" + Type, "; p_{T}; #eta", nbinspt, localPtBinEdges, nbinseta, localEtaBinEdges );

//	TH2F *hScaleFactors_Reco = new TH2F( "hScaleFactors_Reco", "Scale factors for electron Reconstruction; p_{T}; #eta", nbinspt, localPtBinEdges, nbinseta, localEtaBinEdges );
	
				   
	for ( int ipt = 0; ipt < nbinspt; ipt++ )
	{
		for ( int ieta = 0; ieta < nbinseta; ieta++ )
		{			
			if (ieta <= 3)
				bineta = (Int_t)fabs( 3 - ieta );
			else if (ieta == 4)
				bineta = 0;
			else
				bineta = (Int_t)fabs( 4 - ieta );
			
			cout << eff_num[bineta][ipt][datamc] << "   " << eff_num[bineta][ipt][datamc_error] << endl;
//			cout << sf_reco[bineta][ipt][datamc] << "   " << sf_reco[bineta][ipt][datamc_error] << endl;
			
			hScaleFactors->SetBinContent( ipt + 1, ieta + 1, eff_num[bineta][ipt][datamc] );
			hScaleFactors->SetBinError( ipt + 1, ieta + 1, eff_num[bineta][ipt][datamc_error] );
			
			// For 2012 Reconstruction
//			hScaleFactors_Reco->SetBinContent( ipt + 1, ieta + 1, sf_reco[ipt][bineta][datamc] );
//			hScaleFactors_Reco->SetBinError( ipt + 1, ieta + 1, sf_reco[ipt][bineta][datamc_error] );
//			hScaleFactors_Reco->SetBinContent( ipt + 1, ieta + 1, sf_reco[bineta][ipt][datamc] );
//			hScaleFactors_Reco->SetBinError( ipt + 1, ieta + 1, sf_reco[bineta][ipt][datamc_error] );
		}
	}
	
	TCanvas *c = new TCanvas( "canvas", "canvas", 800, 600 );
	   c->SetRightMargin(0.13);
		hScaleFactors->Draw("COLZ");
	c->SaveAs(Period + "/" + Type + ".pdf");
	c->SaveAs(Period + "/" + Type + ".png");
	c->SaveAs(Period + "/" + Type + ".eps");
//	c->SaveAs(Period + "/" + Type + ".root");
	c->SaveAs(Period + "/" + Type + ".C");

	
//	TCanvas *cReco = new TCanvas( "cReco", "cReco", 800, 600 );
//		cReco->SetRightMargin(0.13);
//		hScaleFactors_Reco->Draw("COLZ");
//		cReco->SaveAs("Plots_2D/" + Period + "/RecoSF.pdf");
//		cReco->SaveAs("Plots_2D/" + Period + "/RecoSF.png");
//		cReco->SaveAs("Plots_2D/" + Period + "/RecoSF.eps");
//		cReco->SaveAs("Plots_2D/" + Period + "/RecoSF.root");
//		cReco->SaveAs("Plots_2D/" + Period + "/RecoSF.C");

	
	hScaleFactors->Write();
//	hScaleFactors_Reco->Write();
	
	outputFile->Close();	
} // end plot_eff