Пример #1
0
    static bool CheckAxisCompatibility(const TAxis& a, const TAxis& b)
    {
        static const double delta_max = 0.001;
        static const double rel_delta_max = 0.01;

        if(a.GetNbins() != b.GetNbins()) return false;
        for(Int_t n = 1; n <= a.GetNbins(); ++n) {
            const double c_a = a.GetBinCenter(n);
            const double c_b = b.GetBinCenter(n);
            const double delta = c_a - c_b;
            if( ( c_a && std::abs(delta/c_a) > rel_delta_max ) || ( !c_a && std::abs(delta) > delta_max ) )
                return false;
        }
        return true;
    }
//////////////////////////////////////////////////
// addXAxis - add X axis information
unsigned int addXAxis(SEXP data, SEXP dataNames, unsigned int j, TH1* hist)
{
  int n = hist->GetNbinsX();
  TAxis* axis = hist->GetXaxis();
  
  // Determine breaks--
  // Add to list
  SEXP breaks = addNumericVector(data, dataNames, j++, n+1, "breaks");

  // Get information
  for ( unsigned int i=0; i<n; ++i ) {
    NUMERIC_POINTER(breaks)[i] = axis->GetBinLowEdge(i+1);
  }

  // Add the high edge
  NUMERIC_POINTER(breaks)[n] = axis->GetBinUpEdge(n);

  // Determine mids--
  SEXP mids = addNumericVector(data, dataNames, j++, n, "mids");

  // Get information
  for ( unsigned int i=0; i<n; ++i ) {
    NUMERIC_POINTER(mids)[i] = axis->GetBinCenter(i+1);
  }

  // Get name of axis
  SEXP xname = addCharVector(data, dataNames, j++, 1, "xname");
  SET_STRING_ELT( xname, 0, mkChar( axis->GetTitle() ) );
  
  // Done
  return j;
}
Пример #3
0
TH2F * histo_rebin(TH2F *h, const int nx, const Double_t *xbins, const int ny, const Double_t *ybins){

  // NB: the errors of the rebinned histogram are wrong!

  TH2F * h_new = new TH2F("h_new",h->GetTitle(),nx,xbins,ny,ybins);
  h_new->Sumw2();

  TAxis *xaxis = h->GetXaxis();
  TAxis *yaxis = h->GetYaxis();
  
  for (int jbin=1; jbin<=yaxis->GetNbins(); ++jbin){
    for (int ibin=1; ibin<=xaxis->GetNbins(); ++ibin){
      h_new->Fill(xaxis->GetBinCenter(ibin),yaxis->GetBinCenter(jbin),h->GetBinContent(ibin,jbin));
    }
  }
  
  return (TH2F*) h_new->Clone();
  
}
void dumpHistogram(TH1* histogram)
{
  std::cout << "<dumpHistogram>:" << std::endl;
  std::cout << " histogram: name = " << histogram->GetName() << ", title = " << histogram->GetTitle() << std::endl;
  std::cout << "  fillColor = " << histogram->GetFillColor() << ", fillStyle = " << histogram->GetFillStyle() << ","
	    << " lineColor = " << histogram->GetLineColor() << ", lineStyle = " << histogram->GetLineStyle() << ", lineWidth = " << histogram->GetLineWidth() << "," 
	    << " markerColor = " << histogram->GetMarkerColor() << ", markerStyle = " << histogram->GetMarkerStyle() << ", markerSize = " << histogram->GetMarkerSize() << std::endl;
  TAxis* xAxis = histogram->GetXaxis();
  int numBins = xAxis->GetNbins();
  for ( int iBin = 1; iBin <= numBins; ++iBin ) {
    std::cout << "bin #" << iBin << " (x = " << xAxis->GetBinCenter(iBin) << "): " << histogram->GetBinContent(iBin) << " +/- " << histogram->GetBinError(iBin) << std::endl;
  }
  std::cout << "integral = " << compIntegral(histogram, true, true) << std::endl;
}
Пример #5
0
//TH1D *makeDiffHistWptLog(TH1D* hData, TH1D* hFit, const TString name)
TH1D *makeDiffHistWptLog(TH1D* hData, TH1D* hFit, TH1D* hFitError, const TString name)
{
  //double WptBins[14]={1,7.5,12.5,17.5,24,30,40,50,70,110,150,190,250,600};
  double WptBins[14]={0.68,7.5,12.5,17.5,24,30,40,50,70,110,150,190,250,600};
  TH1D *hDiff = new TH1D(name,"",13,WptBins);
  TAxis *xaxis = hData->GetXaxis();
  for(int ibin=1; ibin<=hData->GetNbinsX(); ibin++) {
    //cout << "Wpt Data: " << hData->GetBinContent(ibin) << "\t sqrt(data): " << sqrt(hData->GetBinContent(ibin)) << "\t Wpt Fit: " << hFit->GetBinContent(ibin) << "\t fit error : " << hFitError->GetBinError(ibin) << endl;
    Double_t diff = (hData->GetBinContent(ibin)-hFit->GetBinContent(ibin)); // data-mc
    //Double_t err = sqrt(hData->GetBinContent(ibin));
    Double_t err = hFitError->GetBinError(ibin); // error from fit
    if(err==0) err= sqrt(hFit->GetBinContent(ibin));
    if(err>0) hDiff->Fill(xaxis->GetBinCenter(ibin),diff/err);
    else      hDiff->Fill(xaxis->GetBinCenter(ibin),0);
    cout << 
      "Wpt Data:\t " <<   hData->GetBinContent(ibin) << 
      "\t sqrt(data):\t " << sqrt(hData->GetBinContent(ibin)) << 
      "\t Wpt Fit:\t " << hFit->GetBinContent(ibin) << 
      "\t error:\t " << hFitError->GetBinError(ibin) <<
      "\t Wpt Data - Wpt Fit:\t " <<   hData->GetBinContent(ibin)-hFit->GetBinContent(ibin) << 
      "\tdiff/err: " << diff/err  <<
      endl;
    //cout << ibin <<  "\tdiff:   " << diff  <<  "\tfab(diff):   " << fab(diff)  << endl;
    //cout << ibin<< "\tdiff/err: " << diff/err  << endl;
  }

  //hDiff->GetYaxis()->SetTitleOffset(0.42);
  hDiff->GetYaxis()->SetTitleOffset(0.55);
  //hDiff->GetYaxis()->SetTitleSize(0.13);
  hDiff->GetYaxis()->SetTitleSize(0.10);
  hDiff->GetYaxis()->SetLabelSize(0.10);
  hDiff->GetYaxis()->SetNdivisions(104);
  hDiff->GetYaxis()->CenterTitle();
  hDiff->GetXaxis()->SetTitleOffset(1.2);
  hDiff->GetXaxis()->SetTitleSize(0.13);
  hDiff->GetXaxis()->SetLabelSize(0.12);
  //hDiff->GetXaxis()->CenterTitle();

  return hDiff;
}
 void fillHistograms(double mvaOutput, double pt, double eta, double Nvtx, double evtWeight)
 {    
   histogramPt_denominator_->Fill(pt, evtWeight);
   histogramEta_denominator_->Fill(eta, evtWeight);
   histogramNvtx_denominator_->Fill(Nvtx, evtWeight);
   bool passesCuts = (mvaOutput > mvaCut_);
   //std::cout << "passesCuts = " << passesCuts << std::endl;
   if ( passesCuts ) {
     histogramPt_numerator_->Fill(pt, evtWeight);
     histogramEta_numerator_->Fill(eta, evtWeight);
     histogramNvtx_numerator_->Fill(Nvtx, evtWeight);
   }
   double y = mvaOutput;
   TAxis* yAxis = histogramMVAoutput_vs_Pt_->GetYaxis();
   int binY = yAxis->FindBin(y);
   int numBinsY = yAxis->GetNbins();
   if ( binY <  1       ) binY = 1;
   if ( binY > numBinsY ) binY = numBinsY;
   double yWithinRange = yAxis->GetBinCenter(binY);
   histogramMVAoutput_vs_Pt_->Fill(pt, y, evtWeight);
   histogramPt_->Fill(pt, evtWeight);
 }
Пример #7
0
void DrawMeasurement( TH1 *h, Int_t nbin, Double_t val, Double_t err )
{
   TAxis *axis   = h->GetYaxis();
   
   Double_t dy;
   Double_t x1,y1,x2,y2, ymin;
   
   Int_t i = nbin;
   
   ymin = axis->GetBinCenter(i)+1;
   dy   = axis->GetBinWidth(i);
   x1   = val - err;
   y1   = ymin - 0.05*dy;
   x2   = val + err;
   y2   = ymin + 0.05*dy;
  
   TLine* line = new TLine;
   TLine* lbar = new TLine;
   TLine* rbar = new TLine;
   TMarker* m2 = new TMarker( val, ymin, 20 );
   Int_t color = 1;
   line->SetLineColor( color );
   line->SetLineWidth( 2 );
   lbar->SetLineColor( color );
   lbar->SetLineWidth( 2 );
   rbar->SetLineColor( color );
   rbar->SetLineWidth( 2 );
   m2->SetMarkerColor( color );
   m2->SetMarkerSize( 1.2 );
   m2->SetMarkerStyle( 21 );
   
   line->DrawLine( x1, ymin, x2, ymin );
   lbar->DrawLine( x1, y1, x1, y2 );
   rbar->DrawLine( x2, y1, x2, y2 );
   m2->Draw();
}
Пример #8
0
void RebinProfile(){

	f = new TFile("../../../rootfiles/MC/EPOS_PbPb_Ntrk_0.root");

	TH2D* h2;
	h2 = (TH2D*)f->Get("demo/scatterHist_effcorr");



	TCanvas* C = new TCanvas("fitscatterplot","EPOS Hydjet Scatterplot",1800,1200);

	C->Divide(3,2);
	C->cd(1);

	double newbins[8] = {-0.3,-0.075,-0.045,-0.015,0.015,0.045,0.075,0.3};
	//double newbins[6] = {-0.3,-0.045,-0.015,0.015,0.045,0.3};
	TH2D* hnew = new TH2D("rebin","rebin",7,newbins,1000,-0.3,0.3); 

	TAxis *xaxis = h2->GetXaxis();
	TAxis *yaxis = h2->GetYaxis();
	for (int k=1; k<=yaxis->GetNbins();k++) {
		for (int l=1; l<=xaxis->GetNbins();l++) {
			hnew->Fill(xaxis->GetBinCenter(l),yaxis->GetBinCenter(k),h2->GetBinContent(l,k));
		}
	}

	TProfile *prof = hnew->ProfileX();

	TF1* fit1 = new TF1("Linear fitting case 1", "[0]+x*[1]", -0.2, 0.2);
	fit1->SetLineColor(kBlue);
	fit1->SetLineStyle(1);
	fit1->SetLineWidth(3);
	prof->Fit(fit1,"RN0");

	TLatex* text2 = makeLatex(Form("slope : %.3f #pm %.3f",fit1->GetParameter(1),fit1->GetParError(1)),0.55,0.25) ;
	prof->Draw();

	text2->Draw("same");
	fit1->Draw("same");


	


/*
	for (Int_t i=0;i<2;i++) {
		for (Int_t j=0;j<3;j++) {


			h = (TH2D*)f->Get("demo/scatterHist_noeffcorr");
			h -> new TH2D(" ");


			corrTable[oc]->SetBinContent(eta+1, pt+1, c);

			

			double c1 = testload.getWeight(ptbins[pt], etabins[eta], ocbin[oc], "eff");
			double c2 = testload.getWeight(ptbins[pt], etabins[eta], ocbin[oc], "fak");
			double c = c1/(1-c2);

			if( oc == 0 && eta == 15 && pt == 20 ) cout << "1: " << c << endl;
			if( oc == 4 && eta == 15 && pt == 20 ) cout << "4: " << c << endl;
				//cout << "corr factor: " << c << endl; 
			corrTable[oc]->SetBinContent(eta+1, pt+1, c);


			c = c1/(1-c2);
			c2 = c3/(1-c1);
			c4 = c2/(1-c3);
			c5 = c6/(1-c7);

*/
		}
//void pi0_mfitpeak(char *FileName, char *HistName, Int_t etapi0flag) 
void pi0_mfitpeak(TH1F *mh1, Int_t etapi0flag, float xmin, float xmax, int npol,float res[],int posFlag, const char *dirName, const char *histName, float text_x, float text_y, const char *texName) 
  
{
  TGaxis::SetMaxDigits(3);


  // TVirtualFitter::SetDefaultFitter("Minuit");
  


  // This script attempts to fit any pi0 peak so that the freaking fit function would converge
  // currently background is fitted to a pol4 function and the peak by a gaussian;
  // results are not very nice
  // usage  .x pi0_mfitpeak.C++ ("pi0calib.root","minv_spb")
  // or eg.  .x pi0_mfitpeak.C ("../pi0anal/pi0ana_punorm.root","minv_spb",0)

  gROOT->Reset();
  //  gStyle->SetOptFit();
  //  gStyle->SetOptFit(0);
  //  gStyle->SetOptStat(0);
  //  gStyle->SetOptTitle(0);
Bool_t NOTE=1;
  if(NOTE) gStyle->SetCanvasBorderMode(0);

  gStyle->SetPadTopMargin(0.08);
  gStyle->SetPadBottomMargin(0.12);
  gStyle->SetPadLeftMargin(0.15);
  gStyle->SetPadRightMargin(0.08);

  mh1->GetXaxis()->SetRangeUser(xmin,xmax);
  
  Int_t highx=500;
  TCanvas *c2 = new TCanvas("c2","",200,10,highx,500);


    // cout<<FileName<<" "<<HistName<<endl;

  //     TFile f(FileName);
  //   TH1F *mh1 = (TH1F*) f.Get(HistName);
      mh1->SetMarkerStyle(20);
      mh1->SetMarkerSize(1.);
      mh1->SetStats(0); // 1/0 to set the stat box

   mh1->GetXaxis()->SetTitle("Invariant Mass of Photon Pairs (GeV/c^{2})");


   float binwidth = mh1->GetBinWidth(1);
   
   char *ytitle = new char[100];

   sprintf(ytitle,"Photon Pairs / %4.3f GeV/c^{2}",binwidth);
   

   mh1->GetYaxis()->SetTitle(ytitle);


   mh1->GetXaxis()->SetTitleSize(0.055);
   mh1->GetYaxis()->SetTitleSize(0.055);
   mh1->GetXaxis()->SetLabelSize(0.045);
   mh1->GetYaxis()->SetLabelSize(0.045);
   mh1->GetXaxis()->SetTitleOffset(0.90);
   mh1->GetXaxis()->CenterTitle();
   mh1->GetYaxis()->SetTitleOffset(1.32);
   

   // First work with the histogram and find the peak and fit ranges
   TAxis *xaxis = mh1->GetXaxis();
   Float_t binsiz= xaxis->GetBinCenter(3) - xaxis->GetBinCenter(2);
   Int_t nbins = xaxis->GetNbins(); 
   Float_t nevtperbin0[10000];
   Float_t errorbin0[10000];
   Float_t nevttot;
   Float_t maxbin=0; Int_t nmaxbin=0, nminbord=0, nmaxbord=nbins;
   
   for (Int_t nn=1; nn <= nbins; nn++)
     {
       nevtperbin0[nn] = mh1->GetBinContent(nn); 
       if(nevtperbin0[nn] > maxbin) { maxbin=nevtperbin0[nn]; nmaxbin=nn; }
       errorbin0[nn] = mh1->GetBinError(nn); 
       nevttot+=nevtperbin0[nn];
       if(nevtperbin0[nn] > 0 && nminbord == 0) nminbord=nn; 
       if(nevtperbin0[nn] == 0 && (nn > nminbord +10) && nmaxbord==0 && nminbord > 0) nmaxbord=nn; 
     }
   cout<<"Minbordl "<<nminbord<<" with events: "<<nevtperbin0[nminbord]<<endl;
   cout<<"Maxbordl "<<nmaxbord<<" with events: "<<nevtperbin0[nmaxbord]<<endl;
   nminbord+=0;
   nmaxbord-=0;
   Int_t nmin0=nminbord;
   while(nevtperbin0[nminbord] < nevtperbin0[nmaxbin]*0.025) nminbord++;
   while(nevtperbin0[nmaxbord] < nevtperbin0[nmaxbin]*0.025) nmaxbord--;
   // the above was just to get the info and low/high bins

   // Set the fit range ! This is for total fit !	 
   Float_t fitl=xmin;
     float fith=xmax;
   //     Float_t fitl=0.07, fith=0.2;// this works better for pileup
   //         Float_t fitl=0.08, fith=0.18;// this works even better for pileup
     //  if(etapi0flag == 1)
     // {
     //  fitl=0.35; fith=0.75;
     //}
     

     //   if(fitl < xaxis->GetBinCenter(nmin0)) fitl = xaxis->GetBinCenter(nmin0);
   //if(fith > xaxis->GetBinCenter(nmaxbord)) fith = xaxis->GetBinCenter(nmaxbord);
 
   


   cout<<" fit range "<<fitl<<" -- "<<fith<<endl;

   cout <<"Bin size "<<binsiz<<endl;
   cout<<"Total events "<<nevttot<<endl;
   cout<<"MaxBin "<<nmaxbin<<" with events: "<<nevtperbin0[nmaxbin]<<endl;
   cout<<"Minbord "<<nminbord<<" with events: "<<nevtperbin0[nminbord]<<endl;
   cout<<"Maxbord "<<nmaxbord<<" with events: "<<nevtperbin0[nmaxbord]<<endl;
      mh1->DrawCopy("sep");

      Float_t lowgauss=0.135-4.*0.010;
      Float_t highgauss=0.135+4.*0.010;
      if(etapi0flag == 1)
	{
	  lowgauss=0.55-5.*0.025;
              highgauss=0.55+5.*0.025;
	}
      Int_t nlowgauss=Int_t((lowgauss-xaxis->GetBinCenter(1))/Float_t(binsiz)+0.5);
      Int_t nhighgauss=Int_t((highgauss-xaxis->GetBinCenter(1))/Float_t(binsiz)+0.5);
      cout <<xaxis->GetBinCenter(nlowgauss)<<" "<<xaxis->GetBinCenter(nhighgauss)<<endl;
   // now make the "background" histogram and fit it with p4
      Float_t lowvalgauss=nevtperbin0[nlowgauss];
      Float_t increm=(nevtperbin0[nhighgauss]-nevtperbin0[nlowgauss])/Float_t(nhighgauss-nlowgauss);
      TH1F *hbkg = (TH1F*)mh1->Clone();
      hbkg->SetName("bkg_clone");
      for (Int_t nn=nlowgauss; nn<=nhighgauss; nn++)
	{
	  hbkg->SetBinContent(nn,Float_t(lowvalgauss+(nn-nlowgauss)*increm));
	  hbkg->SetBinError(nn,sqrt(lowvalgauss+(nn-nlowgauss)*increm));
	}
      hbkg->DrawCopy("samesep");
      //      break;
      // Now define the "gaussian" histogram
      TH1F *hgauss = (TH1F*)mh1->Clone();
      hgauss->SetName("gauss_clone");
      hgauss->Sumw2();
      hgauss->Add(mh1,hbkg,1,-1); // if errors are independent Add needs to be used !
       for (Int_t nn=1; nn <= nbins; nn++)
	 {
	   if(hgauss->GetBinContent(nn) < 0.) hgauss->SetBinContent(nn,0.001*nevtperbin0[nmaxbin]);
	   hgauss->SetBinError(nn,sqrt(hgauss->GetBinContent(nn)));
	 }

   // Declare function with wich to fit
       TF1 *g1 = new TF1("g1","gaus",lowgauss,highgauss);
   hgauss->Fit(g1,"R0");
   hgauss->DrawCopy("sep");
   g1->Draw("same");
   //  break;

   char *polff = new char[20];

   sprintf(polff,"pol%d",npol);
   
   TF1 *p4bkg; 
   if(etapi0flag != 1)
     p4bkg   = new TF1("pm2",polff, xaxis->GetBinCenter(nminbord),xaxis->GetBinCenter(nmaxbord));
   else
     p4bkg   = new TF1("pm2",polff, 0.35,0.75);
   
   

   hbkg->Fit(p4bkg,"R0");
   hbkg->DrawCopy("sep");
   p4bkg->SetLineStyle(kDashed);
   p4bkg->Draw("same");
   // break;
   
   
   Double_t par[20],parf[20],errparf[20];
   g1->GetParameters(&par[0]);
   p4bkg->GetParameters(&par[3]);

   char *totff = new char[20];
   
   sprintf(totff,"gaus(0)+pol%d(3)",npol);
   
   
   TF1 *total = new TF1("total",totff,fitl,fith);
   TF1 *p4bkgfin   = new TF1("pm2",polff,fitl,fith);
   total->SetParameters(par);

   if(etapi0flag==0){
     total->SetParLimits(1,0.10,0.15);
     total->SetParLimits(2,0.135*0.06,0.135*0.3);
     
   }else{
     total->SetParLimits(1,0.35,0.65);
   }
   
   
   //  total->FixParameter(1,1.21340e-01); 
   // total->FixParameter(2,2.69780e-02);
   
   
   

   

   mh1->Fit(total,"R0");
   
   cout<<" yield.. "<< total->GetParameter(0) <<"+/- " << total->GetParError(0)<<endl;
   

     total->GetParameters(parf);


     for( Int_t nn=0; nn < 3+npol+1; nn++) errparf[nn]=total->GetParError(nn);
     g1->SetParameters(&parf[0]);
     p4bkgfin->SetParameters(&parf[3]);
     cout <<" Piz Mass = "<<parf[1]*1000.<<" +- "<<errparf[1]*1000.<<
       " Sigma ="<<parf[2]*1000.<<" +- "<<errparf[2]*1000.<<endl;
      cout << " Sigma Rel. = "<< parf[2]/parf[1]<<" +- "
	   << errparf[2]/parf[1] <<endl;

    Float_t int_min=parf[1]-3.*parf[2];
    Float_t int_max=parf[1]+3.*parf[2];
    Float_t sig_peak=g1->Integral(int_min,int_max)/binsiz;
    Float_t bkgd_peak=p4bkgfin->Integral(int_min,int_max)/binsiz;
    cout<<" In +-3. sigma window: Signal="<<sig_peak<<" Bkgd="<<bkgd_peak<<endl;
    Float_t SB=sig_peak/bkgd_peak; Float_t SBerr=SB*(sqrt(1./sig_peak+1./bkgd_peak));
    cout<<" Signal/Bkgd "<<SB<<" +- "<<SBerr<<endl;   

    int_min=parf[1]-2.*parf[2];
    int_max=parf[1]+2.*parf[2];
    sig_peak=g1->Integral(int_min,int_max)/binsiz;
    bkgd_peak=p4bkgfin->Integral(int_min,int_max)/binsiz;
    cout<<" In +-2.sigma window: Signal="<<sig_peak<<" Bkgd="<<bkgd_peak<<endl;
    SB=sig_peak/bkgd_peak; SBerr=SB*(sqrt(1./sig_peak+1./bkgd_peak));
    cout<<" Signal/Bkgd "<<SB<<" +- "<<SBerr<<endl;   
 			

    float S = sig_peak; 
    float B = bkgd_peak; 
    
    int_min=parf[1]-20.*parf[2];
    int_max=parf[1]+20.*parf[2];
    float S_all = g1->Integral(int_min,int_max)/binsiz;
    
    

    float test_sall =  parf[0] * parf[2] * sqrt(acos(-1)) / binsiz; 
    
    cout<<"signal all: "<< S_all << " "<< test_sall <<endl; 
    
    float Serr_all = errparf[0]/ parf[0] * S_all; 
    


    res[0] = S_all; 
    res[1] = Serr_all; 

    res[2] = parf[1]; 
    res[3] = errparf[1];
    
    res[4] = parf[2]; 
    res[5] = errparf[2];

    res[6] = SB; 
    res[7] = SBerr; 
    


    total->SetLineWidth(3);
    
   total->SetLineColor(kBlue);

   p4bkgfin->SetLineWidth(3);
   
   p4bkgfin->SetLineColor(kRed);
   mh1->DrawCopy("sep");

   //   total->SetRange(0.07,0.185);
   //    p4bkgfin->SetRange(0.07,0.185);
   total->Draw("same");
   p4bkgfin->SetLineStyle(kDashed);
   p4bkgfin->Draw("same");   

   TLatex l;
   
   //   l.SetTextSize(0.06);
   l.SetTextSize(0.05);
   
   
   l.SetTextColor(1);
   l.SetNDC();
   
  
   float sigma = parf[2]/ parf[1]*100; 
   float sigmaerr = errparf[2]/ parf[1]*100; 
   char *sigma_name = new char[50]; 
   if(sigmaerr>0.005)
     sprintf(sigma_name,"#sigma = %3.2f #pm %3.2f %% ",sigma,sigmaerr);
   else sprintf(sigma_name,"#sigma = %3.2f %% ",sigma);
   
   if(posFlag==1){
     l.DrawLatex(0.54,0.75,sigma_name);
   }else if( posFlag==2){
     l.DrawLatex(0.54,0.3,sigma_name);

   }
      
      //  sprintf(sigma_name,"S/B = %3.2f #pm %3.2f ",SB,SBerr);
      //
      sprintf(sigma_name,"S = %2.1f #pm %2.1f",S_all,Serr_all);
	      //
      
      // l.DrawLatex(0.5,0.5,sigma_name);
      
      sprintf(sigma_name,"M = %3.1f #pm %3.1f MeV",parf[1]*1000.,errparf[1]*1000);
      if(posFlag==1){
      l.DrawLatex(0.54,0.82,sigma_name);
      }else if( posFlag==2){
	l.DrawLatex(0.54,0.37,sigma_name);

      }
      ///l.DrawLatex(0.169,470.,"d)");


      c2->Modified();
   c2->Update();
   //   c2->SaveAs("nice_pi0.gif");

   
   
   if( text_x >0 && text_y >0){
    TLatex *   tex = new TLatex(text_x, text_y, texName);
    tex->SetNDC();
    tex->SetTextSize(0.06);
    tex->SetLineWidth(2);
    tex->Draw();
  }
  

   char *filename = new char[1000];

   
   sprintf(filename,"%s/%s.gif",dirName,histName);
   c2->Print(filename);
   sprintf(filename,"%s/%s.C",dirName,histName);
   c2->Print(filename);
   
   // .x pi0_mfitpeak.C ("pi0ana_508030.root","minv_spb",0)
   // .x pi0_mfitpeak.C ("pi0ana_npu.root","minv_bkg",0)  
   // .x pi0_mfitpeak.C ("pi0ana_punormv2.root","minv_spb",0)
}
Пример #10
0
void Drawing()
{
  frodo *fr = frodo::instance();
  fr->Y1.clear();
  fr->X1.clear();
  fr->Y2.clear();
  fr->X2.clear();
  fr->Y3.clear();
  fr->X3.clear();
  fr->Y4.clear();
  fr->X4.clear();
  fr->AllX.clear();
  fr->AllY.clear();
  
  //----------------------------------------------------------------------------------------------------

  TCanvas *HBD = new TCanvas("HBD","HBD Event Display",0,0,700,700);
  HBD->Range(-50000,-50000,50000,50000);

    
   double Qx1,Qx2,Qx3,Qx4,Qy1,Qy2,Qy3,Qy4;

   Qx1=Qx2=Qx3=Qx4=Qy1=Qy2=Qy3=Qy4=0;
  
   for(unsigned int i=0; i<60; i++)
     {
       Qx1 += fr->J1_XStrips[i].Q();
       Qx2 += fr->J2_XStrips[i].Q();
       Qx3 += fr->J3_XStrips[i].Q();
       Qx4 += fr->J4_XStrips[i].Q();
     }

   for(unsigned int i=0; i<60; i++)
     {
       Qy1 += fr->J1_YStrips[i].Q();
       Qy2 += fr->J2_YStrips[i].Q();
       Qy3 += fr->J3_YStrips[i].Q();
       Qy4 += fr->J4_YStrips[i].Q();
     }
  
   double Qtot1 = Qx1+Qy1;
   double Qtot2 = Qx2+Qy2;
  double Qtot3 = Qx3+Qy3;
   double Qtot4 = Qx4+Qy4;
  
  
  //J1 section:-------------------------------------------------------------------
  double X1 = -49100; //left
  double Y1 = -1375; //bottom
  double X2 = -1000; //right
  double Y2 = -1075; //top
  for(unsigned int i=0; i<60; i++)
    {
      double T = fr->J1_YStrips[i].Q();
      //double Qfrac = exp(-T/20)*100;
      double Qfrac = T/Qtot1*100;
      if(Qfrac>0.04 && Qfrac<1)
 	{
 	  fr->J1_YStrips[i].Draw(X1,Y1,X2,Y2,1);
 	  HBD->Update();
	  fr->Y1.push_back(Coordinates(fr->J1_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J1_YStrips[i].YCenter()));
 	}
      
       else if(Qfrac>=1 && Qfrac<50)
 	{
 	  int index = int (Qfrac);
 	  fr->J1_YStrips[i].Draw(X1,Y1,X2,Y2,index);
 	  HBD->Update();
 	  fr->Y1.push_back(Coordinates(fr->J1_YStrips[i].YCenter()));
 	  fr->AllY.push_back(Coordinates(fr->J1_YStrips[i].YCenter()));
 	}
       else if(Qfrac>=50 && Qfrac<99.98)
 	{
 	  //int index = int (Qfrac) - 49;
 	  fr->J1_YStrips[i].Draw(X1,Y1,X2,Y2,2);
 	  HBD->Update();
 	  fr->Y1.push_back(Coordinates(fr->J1_YStrips[i].YCenter()));
 	  fr->AllY.push_back(Coordinates(fr->J1_YStrips[i].YCenter()));
 	}
      	  
	  Y2 = Y1 - 500;
	  Y1 = Y2 - 300; 
    }

  double x1 = -1900;
  double y1 = -48975;
  double x2 = -1200;
  double y2 = -48675;

  for(unsigned int j=0; j<60; j++)
    {
      
      double T = fr->J1_XStrips[j].Q();
      //double Qfrac = exp(-T/20)*100;
      double Qfrac = T/Qtot1*100;
      if(Qfrac>0.04 && Qfrac<1)
	{
 	  fr->J1_XStrips[j].Draw(x1,y1,x2,y2,1);   
 	  HBD->Update();
	  fr->X1.push_back(Coordinates(fr->J1_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J1_XStrips[j].XCenter()));

 	}
	
      else if(Qfrac>=1 && Qfrac<50)
	{
	  int index = int(Qfrac);
	  fr->J1_XStrips[j].Draw(x1,y1,x2,y2,index);   
	  HBD->Update();
	  fr->X1.push_back(Coordinates(fr->J1_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J1_XStrips[j].XCenter()));
	}
      else if(Qfrac>=50 && Qfrac<99.98)
	{
	  //int index = int(Qfrac) - 49;
	  fr->J1_XStrips[j].Draw(x1,y1,x2,y2,2);
	  HBD->Update();
	  fr->X1.push_back(Coordinates(fr->J1_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J1_XStrips[j].XCenter()));
	}
	
      
      x2 = x1 - 100;
      x1 = x2 - 700;
    }

  
  //J2 section:----------------------------------------------------------------
  //cout<<"J2: "<<endl;

  X1 = 900;
  Y1 = -1375;
  X2 = 49000;
  Y2 = -1075;
  for(unsigned int i=0; i<60; i++)
    {
      double T = fr->J2_YStrips[i].Q();
      //double Qfrac = exp(-T/20)*100;
      double Qfrac = T/Qtot2*100;
      if(Qfrac>0.04 && Qfrac<1)
       	{
 	  fr->J2_YStrips[i].Draw(X1,Y1,X2,Y2,1);
 	  HBD->Update();
	  fr->Y2.push_back(Coordinates(fr->J2_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J2_YStrips[i].YCenter()));
	}
      
      else if(Qfrac>=1 && Qfrac<50)
	{
	  int index = int(Qfrac);
	  fr->J2_YStrips[i].Draw(X1,Y1,X2,Y2,index);
	  HBD->Update();
	  fr->Y2.push_back(Coordinates(fr->J2_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J2_YStrips[i].YCenter()));
	  
	}
      else if(Qfrac>=50 && Qfrac<99.98)
	{
	  //int index = int(Qfrac)-49;
	  fr->J2_YStrips[i].Draw(X1,Y1,X2,Y2,2);
	  HBD->Update();
	  fr->Y2.push_back(Coordinates(fr->J2_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J2_YStrips[i].YCenter()));
	}
      

      Y2 = Y1 - 500;
      Y1 = Y2 - 300; 
    }

  x1 = 48100;
  y1 = -48975;
  x2 = 48800;
  y2 = -48675;

  for(unsigned int j=0; j<60; j++)
    {
      double T = fr->J2_XStrips[j].Q();
      //double Qfrac = exp(-T/20)*100;
      double Qfrac = T/Qtot2*100;
      if(Qfrac>0.04 && Qfrac<1)
       	{
 	  fr->J2_XStrips[j].Draw(x1,y1,x2,y2,1);  
 	  HBD->Update();
	  fr->X2.push_back(Coordinates(fr->J2_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J2_XStrips[j].XCenter()));
 	}
      
      else if(Qfrac>=1 && Qfrac<50)
	{
	  int index = int(Qfrac);
	  fr->J2_XStrips[j].Draw(x1,y1,x2,y2,index);  
	  HBD->Update();
	  fr->X2.push_back(Coordinates(fr->J2_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J2_XStrips[j].XCenter()));
	}
      else if(Qfrac>=50 && Qfrac<99.98)
	{
	  //int index = int(Qfrac)-49;
	  fr->J2_XStrips[j].Draw(x1,y1,x2,y2,2);
	  HBD->Update();
	  fr->X2.push_back(Coordinates(fr->J2_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J2_XStrips[j].XCenter()));
	}
      
      x2 = x1 - 100;
      x1 = x2 - 700;
    }
  
  //J3 section:----------------------------------------------------------------
  X1 = -49100;
  Y1 = 1125;
  X2 = -1000;
  Y2 = 1425;
  for(unsigned int i=0; i<60; i++)
    {
      double T = fr->J3_YStrips[i].Q();
      //double Qfrac = exp(-T/20)*100;
      double Qfrac = T/Qtot3*100;
      if(Qfrac>0.04 && Qfrac<1)
       	{
 	  fr->J3_YStrips[i].Draw(X1,Y1,X2,Y2,1);
 	  HBD->Update();
	  fr->Y3.push_back(Coordinates(fr->J3_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J3_YStrips[i].YCenter()));
 	}
       
       else if(Qfrac>=1 && Qfrac<50)
	{
	  int index = int(Qfrac);
	  fr->J3_YStrips[i].Draw(X1,Y1,X2,Y2,index);
	  HBD->Update();
	  fr->Y3.push_back(Coordinates(fr->J3_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J3_YStrips[i].YCenter()));
	}
       else if(Qfrac>=50 && Qfrac<99.98)
	{
	  //int index = int(Qfrac)-49;
	  fr->J3_YStrips[i].Draw(X1,Y1,X2,Y2,2);
	  HBD->Update();
	  fr->Y3.push_back(Coordinates(fr->J3_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J3_YStrips[i].YCenter()));
	}
       
      Y1 = Y2 + 500;
      Y2 = Y1 + 300; 
    }

  x1 = -49100;
  y1 = 1525;
  x2 = -48400;
  y2 = 1825;
  for(unsigned int j=0; j<60; j++)
    {
      double T = fr->J3_XStrips[j].Q();
      //double Qfrac = exp(-T/20)*100;
      double Qfrac = T/Qtot3*100;
      if(Qfrac>0.04 && Qfrac<1)
       	{
 	  fr->J3_XStrips[j].Draw(x1,y1,x2,y2,1);   
 	  HBD->Update();
	  fr->X3.push_back(Coordinates(fr->J3_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J3_XStrips[j].XCenter()));
	}
      
       else if(Qfrac>=1 && Qfrac<50)
	{
	  int index = int(Qfrac);
	  fr->J3_XStrips[j].Draw(x1,y1,x2,y2,index);   
	  HBD->Update();
	  fr->X3.push_back(Coordinates(fr->J3_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J3_XStrips[j].XCenter()));
	}
       else if(Qfrac>=50 && Qfrac<99.98)
	{
	  //int index = int(Qfrac)-49;
	  fr->J3_XStrips[j].Draw(x1,y1,x2,y2,2);
	  HBD->Update();
	  fr->X3.push_back(Coordinates(fr->J3_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J3_XStrips[j].XCenter()));
	}
      
      x1 = x2 + 100;
      x2 = x1 + 700;
    }

  //J4 section:-----------------------------------------------------------------
  X1 = 950;
  Y1 = 1125;
  X2 = 49050;
  Y2 = 1425;
  for(unsigned int i=0; i<60; i++)
    {
      double T = fr->J4_YStrips[i].Q();
      //double Qfrac = exp(-T/20)*100;
      double Qfrac = T/Qtot4*100;
      if(Qfrac>0.04 && Qfrac<1)
       	{
 	  fr->J4_YStrips[i].Draw(X1,Y1,X2,Y2,1);
 	  HBD->Update();
	  fr->Y4.push_back(Coordinates(fr->J4_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J4_YStrips[i].YCenter()));
 	}
       
       else if(Qfrac>=1 && Qfrac<50)
	{
	  int index = int(Qfrac);
	  fr->J4_YStrips[i].Draw(X1,Y1,X2,Y2,index);
	  HBD->Update();
	  fr->Y4.push_back(Coordinates(fr->J4_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J4_YStrips[i].YCenter()));
	  
	}
       else if(Qfrac>=50 && Qfrac<99.98)
	{
	  //int index = int(Qfrac)-49;
	  fr->J4_YStrips[i].Draw(X1,Y1,X2,Y2,2);
	  HBD->Update();
	  fr->Y4.push_back(Coordinates(fr->J4_YStrips[i].YCenter()));
	  fr->AllY.push_back(Coordinates(fr->J4_YStrips[i].YCenter()));
	}
       
      Y1 = Y2 + 500;
      Y2 = Y1 + 300; 
    }

  x1 = 950;
  y1 = 1525;
  x2 = 1650;
  y2 = 1825;
  for(unsigned int j=0; j<60; j++)
    {
      double T = fr->J4_XStrips[j].Q();
      //double Qfrac = exp(-T/20)*100;
      double Qfrac = T/Qtot4*100;
      if(Qfrac>0.04 && Qfrac<1)
       	{
 	  fr->J4_XStrips[j].Draw(x1,y1,x2,y2,1); 
 	  HBD->Update();
	  fr->X4.push_back(Coordinates(fr->J4_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J4_XStrips[j].XCenter()));
 	}
       
       else if(Qfrac>=1 && Qfrac<50)
	{
	  int index = int(Qfrac);
	  fr->J4_XStrips[j].Draw(x1,y1,x2,y2,index); 
	  HBD->Update();
	  fr->X4.push_back(Coordinates(fr->J4_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J4_XStrips[j].XCenter()));
	}
       else if(Qfrac>=50 && Qfrac<99.98)
	{
	  //int index = int(Qfrac)-49;
	  fr->J4_XStrips[j].Draw(x1,y1,x2,y2,2);
	  HBD->Update();
	  fr->X4.push_back(Coordinates(fr->J4_XStrips[j].XCenter()));
	  fr->AllX.push_back(Coordinates(fr->J4_XStrips[j].XCenter()));
	}
       
      x1 = x2 + 100;
      x2 = x1 + 700;
    }

  //Drawing the Central Cross:
  X1 = -49100;
  Y1 = -675;
  X2 = 49050;
  Y2 = 675;
  TBox Hori (X1,Y1, X2,Y2);
  Hori.SetFillColor(15);
  Hori.DrawBox(X1,Y1, X2,Y2);
  HBD->Update();

  X1 = -500;
  Y1 = -48975;
  X2 = 500;
  Y2 = 49025;
  TBox Vert (X1,Y1, X2,Y2);
  Vert.SetFillColor(15);
  Vert.DrawBox(X1,Y1, X2,Y2);
  HBD->Update();

  //Drawing the real positions of the photons:
  for(unsigned int a=0; a<fr->HBDParticles.size(); a++)
    {
      fr->HBDParticles[a].Draw();
      HBD->Update();
    }

  //Finding the ring:----------------------------------------------------------------------------------
  Hough = new TH3D ("Hough","Hough",500,-50000,50000,500,-50000,50000,500,0,50000);
  Houghxy = new TH2D ("Houghxy","Houghxy",100,-50000,50000,100,-50000,50000);
  Houghxr = new TH2D ("Houghxr","Houghxr",100,-50000,50000,100,0,50000);
  Houghyr = new TH2D ("Houghyr","Houghyr",100,-50000,50000,100,0,50000);
  
    
//Forming J1234 PseudoPoints:
  for(unsigned int s=0; s<fr->Y1.size(); s++)
    {
      for(unsigned int ps=0; ps<fr->X1.size(); ps++)
	{
	  fr->J1_PseudoPoints.push_back(TVector3(fr->X1[ps].Cor(),fr->Y1[s].Cor(),0));
	  
	}
    }
  //cout<<"J1 size:"<<fr->J1_PseudoPoints.size()<<endl;

  for(unsigned int s=0; s<fr->Y2.size(); s++)
    {
      for(unsigned int ps=0; ps<fr->X2.size(); ps++)
	{
	  fr->J2_PseudoPoints.push_back(TVector3(fr->X2[ps].Cor(),fr->Y2[s].Cor(),0));
	  
	}
    }
  //cout<<"J2 size:"<<fr->J2_PseudoPoints.size()<<endl;

  for(unsigned int s=0; s<fr->Y3.size(); s++)
    {
      for(unsigned int ps=0; ps<fr->X3.size(); ps++)
	{
	  fr->J3_PseudoPoints.push_back(TVector3(fr->X3[ps].Cor(),fr->Y3[s].Cor(),0));
	 
	}
    }
  //cout<<"J3 size:"<<fr->J3_PseudoPoints.size()<<endl;

  for(unsigned int s=0; s<fr->Y4.size(); s++)
    {
      for(unsigned int ps=0; ps<fr->X4.size(); ps++)
	{
	  fr->J4_PseudoPoints.push_back(TVector3(fr->X4[ps].Cor(),fr->Y4[s].Cor(),0));
	  
	}
    }
 
  //Selecting 3 PseudoPoints in three different quadrants:
  //J1,J2,J3:
  if(fr->J1_PseudoPoints.size() >= 1 && fr->J2_PseudoPoints.size() >= 1 && fr->J3_PseudoPoints.size() >= 1)
    {
      for(unsigned int i=0; i<fr->J1_PseudoPoints.size(); i++)
	{
	  for(unsigned int j=0; j<fr->J2_PseudoPoints.size(); j++)
	    {
	      for(unsigned int k=0; k<fr->J3_PseudoPoints.size(); k++)
		{
		  
		  double Rad  = FindR(fr->J1_PseudoPoints[i],fr->J2_PseudoPoints[j],fr->J3_PseudoPoints[k]);
		  double Xcen = FindX(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J2_PseudoPoints[j].X(),fr->J2_PseudoPoints[j].Y(),fr->J3_PseudoPoints[k].X(),fr->J3_PseudoPoints[k].Y());
		  double Ycen = FindY(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J2_PseudoPoints[j].X(),fr->J2_PseudoPoints[j].Y(),fr->J3_PseudoPoints[k].X(),fr->J3_PseudoPoints[k].Y());
		  Hough->Fill(Xcen,Ycen,Rad);
		  Houghxy->Fill(Xcen,Ycen);
		  Houghyr->Fill(Ycen,Rad);
		  Houghxr->Fill(Xcen,Rad);
		}
	    }
	}
    }
      
  //J1,J2,J4:
  if(fr->J1_PseudoPoints.size() >= 1 && fr->J2_PseudoPoints.size() >= 1 && fr->J4_PseudoPoints.size() >= 1)
    {
      for(unsigned int i=0; i<fr->J1_PseudoPoints.size(); i++)
	{
	  for(unsigned int j=0; j<fr->J2_PseudoPoints.size(); j++)
	    {
	      for(unsigned int k=0; k<fr->J4_PseudoPoints.size(); k++)
		{
		  double Rad  = FindR(fr->J1_PseudoPoints[i],fr->J2_PseudoPoints[j],fr->J4_PseudoPoints[k]);
		  double Xcen = FindX(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J2_PseudoPoints[j].X(),fr->J2_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  double Ycen = FindY(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J2_PseudoPoints[j].X(),fr->J2_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  Hough->Fill(Xcen,Ycen,Rad);
		  Houghxy->Fill(Xcen,Ycen);
		  Houghyr->Fill(Ycen,Rad);
		  Houghxr->Fill(Xcen,Rad);
		}
	    }
	}
    }
  
  //J1,J3,J4:
  if(fr->J1_PseudoPoints.size() >= 1 && fr->J3_PseudoPoints.size() >= 1 && fr->J4_PseudoPoints.size() >= 1)
    {
      for(unsigned int i=0; i<fr->J1_PseudoPoints.size(); i++)
	{
	  for(unsigned int j=0; j<fr->J3_PseudoPoints.size(); j++)
	    {
	      for(unsigned int k=0; k<fr->J4_PseudoPoints.size(); k++)
		{
		  double Rad  = FindR(fr->J1_PseudoPoints[i],fr->J3_PseudoPoints[j],fr->J4_PseudoPoints[k]);
		  double Xcen = FindX(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J3_PseudoPoints[j].X(),fr->J3_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  double Ycen = FindY(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J3_PseudoPoints[j].X(),fr->J3_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  Hough->Fill(Xcen,Ycen,Rad);
		  Houghxy->Fill(Xcen,Ycen);
		  Houghyr->Fill(Ycen,Rad);
		  Houghxr->Fill(Xcen,Rad);
		}
	    }
	}
    }
  
  //J2,J3,J4;
  if(fr->J2_PseudoPoints.size() >= 1 && fr->J3_PseudoPoints.size() >= 1 && fr->J4_PseudoPoints.size() >= 1)
    {
      for(unsigned int i=0; i<fr->J2_PseudoPoints.size(); i++)
	{
	  for(unsigned int j=0; j<fr->J3_PseudoPoints.size(); j++)
	    {
	      for(unsigned int k=0; k<fr->J4_PseudoPoints.size(); k++)
		{
		  double Rad  = FindR(fr->J2_PseudoPoints[i],fr->J3_PseudoPoints[j],fr->J4_PseudoPoints[k]);
		  double Xcen = FindX(fr->J2_PseudoPoints[i].X(),fr->J2_PseudoPoints[i].Y(),fr->J3_PseudoPoints[j].X(),fr->J3_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  double Ycen = FindY(fr->J2_PseudoPoints[i].X(),fr->J2_PseudoPoints[i].Y(),fr->J3_PseudoPoints[j].X(),fr->J3_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  Hough->Fill(Xcen,Ycen,Rad);
		  Houghxy->Fill(Xcen,Ycen);
		  Houghyr->Fill(Ycen,Rad);
		  Houghxr->Fill(Xcen,Rad);
		}
	    }
	}
    }

  /*
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!DO NOT ERASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  //Forming PseudoPoints:
  for(unsigned int ps=0; ps<fr->AllX.size(); ps++)
    {
      for(unsigned int s=0; s<fr->AllY.size(); s++)
	{
	   fr->PseudoPoints.push_back(TVector3(fr->AllX[ps].Cor(),fr->AllY[s].Cor(),0));
	}
    }
    
  //Full Combinatorial:
   for(unsigned int i=0; i<fr->PseudoPoints.size()-2; i++)
     {
       for(unsigned int j=i+1; j<fr->PseudoPoints.size()-1; j++)
 	{
 	  for(unsigned int k=j+1; k<fr->PseudoPoints.size(); k++)
 	    {
 	      double Rad = FindR(fr->PseudoPoints[i],fr->PseudoPoints[j],fr->PseudoPoints[k]);
 	      double Xcen = FindX(fr->PseudoPoints[i].X(),fr->PseudoPoints[i].Y(),fr->PseudoPoints[j].X(),fr->PseudoPoints[j].Y(),fr->PseudoPoints[k].X(),fr->PseudoPoints[k].Y());
 	      double Ycen = FindY(fr->PseudoPoints[i].X(),fr->PseudoPoints[i].Y(),fr->PseudoPoints[j].X(),fr->PseudoPoints[j].Y(),fr->PseudoPoints[k].X(),fr->PseudoPoints[k].Y());
 	      Hough->Fill(Xcen,Ycen,Rad);
 	      Houghxy->Fill(Xcen,Ycen);
 	      Houghyr->Fill(Ycen,Rad);
 	      Houghxr->Fill(Xcen,Rad);
	      }
 	}
     }
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */      
  int xbin, ybin, zbin;
  xbin=0; ybin=0; zbin=0;
  Hough->GetMaximumBin(xbin, ybin, zbin);
  //cout << "xbin= " << xbin << " ybin= " << ybin << " zbin= " << zbin << endl;

  TAxis *xaxis = Hough->GetXaxis();  
  double Xrec=xaxis->GetBinCenter(xbin);
  cout<<"Xrec= "<< Xrec <<endl;

  TAxis *yaxis = Hough->GetYaxis();  
  double Yrec=yaxis->GetBinCenter(ybin);
  cout<<"Yrec= "<< Yrec <<endl;

  TAxis *zaxis = Hough->GetZaxis();  
  double Rrec=zaxis->GetBinCenter(zbin);
  cout<<"Rrec= "<< Rrec <<endl;

  //Drawing the founded ring and its center:
  TEllipse ring (Xrec,Yrec,Rrec,Rrec,1,360,0);
  ring.SetLineColor(2);
  ring.SetFillStyle(0);
  ring.DrawEllipse(Xrec,Yrec,Rrec,Rrec,0,360,0);
  HBD->Update();

  TMarker circumcenter (Xrec,Yrec,8);
  circumcenter.SetMarkerColor(2);
  circumcenter.SetMarkerSize(1);
  circumcenter.DrawMarker(Xrec,Yrec);
  HBD->Update();  
  
}
Пример #11
0
void SinglePionEfficiency::Loop()
{
//   In a ROOT session, you can do:
//      Root > .L SinglePionEfficiency.C
//      Root > SinglePionEfficiency t
//      Root > t.GetEntry(12); // Fill t data members with entry number 12
//      Root > t.Show();       // Show values of entry 12
//      Root > t.Show(16);     // Read and show values of entry 16
//      Root > t.Loop();       // Loop on all entries
//

//     This is the loop skeleton where:
//    jentry is the global entry number in the chain
//    ientry is the entry number in the current Tree
//  Note that the argument to GetEntry must be:
//    jentry for TChain::GetEntry
//    ientry for TTree::GetEntry and TBranch::GetEntry
//
//       To read only selected branches, Insert statements like:
// METHOD1:
//    fChain->SetBranchStatus("*",0);  // disable all branches
//    fChain->SetBranchStatus("branchname",1);  // activate branchname
// METHOD2: replace line
//    fChain->GetEntry(jentry);       //read all branches
//by  b_branchname->GetEntry(ientry); //read only this branch
   if (fChain == 0) return;

   Long64_t nentries = fChain->GetEntriesFast();
 
   Long64_t nbytes = 0, nb = 0;

   // number of pt bins and intervals
   const Int_t nptbins = 12;
   const Int_t nptcuts = nptbins+1;
   //                       0    1   2    3    4     5     6     7     8     9    10   11    
   Double_t pt[nptcuts]={0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 40., 50.0};
   // number of eta bins and intervals
   const Int_t netabins = 12;
   const Int_t netacuts = netabins+1;
   //                         0    1    2    3    4    5    6    7    8    9    10   11
   Double_t eta[netacuts]={0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4};
   cout <<"  Eta bins " << endl;

   // prepare eta points for graph
   Float_t etagr[netabins], eetagr[netabins];
   for(Int_t i = 0; i < netabins; i++) {
     etagr[i]  = 0.5*(eta[i]+eta[i+1]);
     eetagr[i] = 0.5*(eta[i+1]-eta[i]);
     cout <<" i = " << i <<" Eta = " << etagr[i] <<" err Eta = " << eetagr[i] << endl;
   } 
   // prepare for graph
   Float_t ptgr[nptbins], eptgr[nptbins];
   for(Int_t i = 0; i < nptbins; i++) {
     ptgr[i]  = 0.5*(pt[i]+pt[i+1]);
     eptgr[i] = 0.5*(pt[i+1]-pt[i]);
     cout <<" i = " << i <<" pT = " << ptgr[i] <<" err pT = " << eptgr[i] << endl;
   } 


   TH2D* hResp = new TH2D("hResp","Resp",nptbins, pt, netabins, eta);
   // histos for energy losses
   TH1F* hEnTrkNotInter[netabins];
   const char* namesEnTrkNotInter[netabins] = {"hEnTrkNotInter1",
					       "hEnTrkNotInter2",
					       "hEnTrkNotInter3",
					       "hEnTrkNotInter4",
					       "hEnTrkNotInter5",
					       "hEnTrkNotInter6",
					       "hEnTrkNotInter7",
					       "hEnTrkNotInter8",
					       "hEnTrkNotInter9",
					       "hEnTrkNotInter10",
					       "hEnTrkNotInter11",
					       "hEnTrkNotInter12"};

   const char* titleEnTrkNotInter[netabins] = {"EnTrkNotInter1",
					       "EnTrkNotInter2",
					       "EnTrkNotInter3",
					       "EnTrkNotInter4",
					       "EnTrkNotInter5",
					       "EnTrkNotInter6",
					       "EnTrkNotInter7",
					       "EnTrkNotInter8",
					       "EnTrkNotInter9",
					       "EnTrkNotInter10",
					       "EnTrkNotInter11",
					       "EnTrkNotInter12"};

   TH1F* hEnTrkInter[netabins];
   const char* namesEnTrkInter[netabins] = {"hEnTrkInter1",
					    "hEnTrkInter2",
					    "hEnTrkInter3",
					    "hEnTrkInter4",
					    "hEnTrkInter5",
					    "hEnTrkInter6",
					    "hEnTrkInter7",
					    "hEnTrkInter8",
					    "hEnTrkInter9",
					    "hEnTrkInter10",
					    "hEnTrkInter11",
					    "hEnTrkInter12"};

   const char* titleEnTrkInter[netabins] = {"EnTrkInter1",
					    "EnTrkInter2",
					    "EnTrkInter3",
					    "EnTrkInter4",
					    "EnTrkInter5",
					    "EnTrkInter6",
					    "EnTrkInter7",
					    "EnTrkInter8",
					    "EnTrkInter9",
					    "EnTrkInter10",
					    "EnTrkInter11",
					    "EnTrkInter12"};

   for(Int_t ih=0; ih < netabins; ih++) { 
     hEnTrkNotInter[ih] = new TH1F(namesEnTrkNotInter[ih], titleEnTrkNotInter[ih], 40, -1., 3.);
     hEnTrkInter[ih] = new TH1F(namesEnTrkInter[ih], titleEnTrkInter[ih], 40, -1., 3.);
   }
   //
 
   // ===> for pi- and pi+
   // N total and N reco tracks
   // find how to write output in file
   //~/scratch0/CMSSW_TEST/cmssw134gammajet/src/JetMETCorrections/GammaJet/src/GammaJetAnalysis.cc

   // total number of analized MC tracks
   Int_t ntrk[netabins][nptbins] =   {  
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
   };
   // number of found tracks
   Int_t ntrkreco[netabins][nptbins] = {
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
   };
   // number of lost tracks
   Int_t ntrklost[netabins][nptbins] = {
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
   };
   // number of tracks with impact point on calo
   Int_t ntrkrecor[netabins][nptbins] = {
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
   };

   // trk efficiency and error
   Float_t trkeff[netabins][nptbins], etrkeff[netabins][nptbins];
   // response in 11x11 crystals + 5x5 HCAL around IP in ECAL
   Double_t response[netabins][nptbins] = {
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
   };

   // response for found tracks in cone 0.5 around MC track direction at vertex
   Double_t responseFoundTrk[netabins][nptbins] = {
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
   };

   // response for lost tracks in cone 0.5 around MC track direction at vertex
   Double_t responseLostTrk[netabins][nptbins] = {
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
     {0,0,0,0,0,0,0,0,0,0,0,0},
   };

   // average response in 11x11 crystals + 5x5 HCAL around IP in ECAL
   Double_t responseF[netabins][nptbins];
   // average response for found tracks in cone 0.5 around MC track direction at vertex
   Double_t responseFoundTrkF[netabins][nptbins];
   // average response for lost tracks in cone 0.5 around MC track direction at vertex
   Double_t responseLostTrkF[netabins][nptbins];
   // ratio of responses of lost and found tracks
   Double_t leak[netabins][nptbins];

   Double_t drTrkcut = 0.01;
   Double_t purityTrkcut = 0.75;
   // 
   for (Long64_t jentry=0; jentry<nentries;jentry++) {
      Long64_t ientry = LoadTree(jentry);
      if (ientry < 0) break;
      nb = fChain->GetEntry(jentry);   nbytes += nb;
      // if (Cut(ientry) < 0) continue;
      // counting events for efficiency calculation
      for(Int_t ieta = 0; ieta < netabins; ieta++) {
	for(Int_t ipt = 0; ipt < nptbins; ipt++) {
	  // ==> pi+
	  if(fabs(etaSim1) >= eta[ieta] && fabs(etaSim1) < eta[ieta+1]) {
	    // checking leakage
	    if(ptSim1 > 10. && ptSim1 < 10000.)
	      {
		if(drTrk2 < 0.01 && purityTrk2 == 1) 
		  {
		    hEnTrkNotInter[ieta]->Fill(etCalo1/ptSim1);
		  } else {
		    hEnTrkInter[ieta]->Fill(etCalo1/ptSim1);
		  }
	      }
	    // end of checking leakage
	    if(ptSim1 >= pt[ipt] && ptSim1 < pt[ipt+1]) {
	      ntrk[ieta][ipt] = ntrk[ieta][ipt]+1;
	      // number of reco tracks
	      if(drTrk1 < drTrkcut && purityTrk1 >= purityTrkcut) { 
		ntrkreco[ieta][ipt] = ntrkreco[ieta][ipt]+1;
		// response for found tracks
		responseFoundTrk[ieta][ipt] = responseFoundTrk[ieta][ipt] + etCalo1/ptSim1;  
		//
		Double_t theta = 2.*atan(exp(-etaSim1));
		Double_t eSim1 = ptSim1/sin(theta);
		if(e1ECAL11x11 > -1000. && e1HCAL5x5 > -1000. && fabs(etaSim1) < 1000.) { 
		  ntrkrecor[ieta][ipt] = ntrkrecor[ieta][ipt]+1;
		  Double_t e_ecal11 = e1ECAL11x11/eSim1;
		  Double_t e_hcal5  = e1HCAL5x5/eSim1;
		  Double_t e_ecalhcal11x5 = e_ecal11 + e_hcal5;
		  response[ieta][ipt] = response[ieta][ipt] + e_ecalhcal11x5;
		}
	      } else {
		// response for lost tracks
		ntrklost[ieta][ipt] = ntrklost[ieta][ipt]+1;
		responseLostTrk[ieta][ipt] = responseLostTrk[ieta][ipt] + etCalo1/ptSim1;  
		//
	      }
	    }
	  }
	  // ==> pi-
	  if(fabs(etaSim2) >= eta[ieta] && fabs(etaSim2) < eta[ieta+1]) {
	    // checking leakage
	    if(ptSim2 > 10. && ptSim2 < 1000.)
	      {
		if(drTrk2 < 0.01 && purityTrk2 == 1) 
		  {
		    hEnTrkNotInter[ieta]->Fill(etCalo2/ptSim2);
		  } else {
		    hEnTrkInter[ieta]->Fill(etCalo2/ptSim2);
		  }
	      }
	    // end of checking leakage
	    if(ptSim2 >= pt[ipt] && ptSim2 < pt[ipt+1]) {
	      ntrk[ieta][ipt] = ntrk[ieta][ipt]+1;
	      // number of reco tracks
	      if(drTrk2 < drTrkcut && purityTrk2 >= purityTrkcut) { 
		ntrkreco[ieta][ipt] = ntrkreco[ieta][ipt]+1;
		// response for found tracks
		responseFoundTrk[ieta][ipt] = responseFoundTrk[ieta][ipt] + etCalo2/ptSim2;  
		//
		Double_t theta = 2.*atan(exp(-etaSim2));
		Double_t eSim2 = ptSim2/sin(theta);
		if(e2ECAL11x11 > -1000. && e2HCAL5x5 > -1000. && fabs(etaSim2) < 1000.) { 
		  ntrkrecor[ieta][ipt] = ntrkrecor[ieta][ipt]+1;
		  Double_t e_ecal11 = e2ECAL11x11/eSim2;
		  Double_t e_hcal5  = e2HCAL5x5/eSim2;
		  Double_t e_ecalhcal11x5 = e_ecal11 + e_hcal5;
		  response[ieta][ipt] = response[ieta][ipt] + e_ecalhcal11x5;
		}
	      } else {
		// response for lost tracks
		ntrklost[ieta][ipt] = ntrklost[ieta][ipt]+1;
		responseLostTrk[ieta][ipt] = responseLostTrk[ieta][ipt] + etCalo2/ptSim2;  
		//
	      }
	    }
	  }
	}
      }
   }

   // calculate efficiencfy, full graph and write output stream
   ofstream myoutput_eff("CMSSW_167_TrackNonEff.txt");
   ofstream myoutput_eff1("CMSSW_167_TrackNonEff_one.txt");
   ofstream myoutput_leak("CMSSW_167_TrackLeakage.txt");
   ofstream myoutput_leak1("CMSSW_167_TrackLeakage_one.txt");
   ofstream myoutput_resp("CMSSW_167_response.txt");

   // calculate map of leackage
   for(Int_t ieta = 0; ieta < netabins; ieta++) {
     for(Int_t ipt = 0; ipt < nptbins; ipt++) {
       
	 // found tracks
       if(ntrkreco[ieta][ipt] != 0) {
	 
	 responseFoundTrkF[ieta][ipt] = responseFoundTrk[ieta][ipt]/ntrkreco[ieta][ipt]; 
	 
       } else {
	 
	 responseFoundTrkF[ieta][ipt] = responseFoundTrkF[ieta][ipt-1];
       }
       // lost tracks
       if(ntrklost[ieta][ipt] != 0) {
	 
	 responseLostTrkF[ieta][ipt] = responseLostTrk[ieta][ipt]/ntrklost[ieta][ipt]; 
	 
       } else {
	 
	 responseLostTrkF[ieta][ipt] = responseLostTrkF[ieta][ipt-1];

       }
     }
   } 

   for(Int_t ieta = 0; ieta <= netabins; ieta++) {
     for(Int_t ipt = 0; ipt <= nptbins; ipt++) {

       if(ieta < netabins && ipt < nptbins) {

	 leak[ieta][ipt] = responseLostTrkF[ieta][ipt]/responseFoundTrkF[ieta][ipt];
	 
	 cout <<" ieta = " << ieta
	      <<" eta = " << eta[ieta]
	      <<" ipt = " << ipt
	      <<" pt = " << pt[ipt]
	      <<" ntrkreco = " << ntrkreco[ieta][ipt] 
	      <<" ntrklost = " << ntrklost[ieta][ipt] 
	      <<" responseFoundTrk = " << responseFoundTrkF[ieta][ipt] 
	      <<" responseLostTrk = " << responseLostTrkF[ieta][ipt]
	      <<" leak = " << leak[ieta][ipt] <<  endl;

	 myoutput_leak << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << leak[ieta][ipt] << endl;
	 myoutput_leak1 << ieta << " " 
			<< ipt  << " " 
			<< eta[ieta] << " " 
			<< pt[ipt] << " "
			<< " 1. " << endl;
       }
       if(ipt == nptbins && ieta < netabins) {
	 
	 myoutput_leak << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << leak[ieta][ipt-1] << endl;
	 myoutput_leak1 << ieta << " " 
			<< ipt  << " " 
			<< eta[ieta] << " " 
			<< pt[ipt] << " "
			<< " 1. " << endl;
       }
       if(ipt < nptbins && ieta == netabins) {

	 myoutput_leak << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << leak[ieta-1][ipt] << endl;
	 myoutput_leak1 << ieta << " " 
			<< ipt  << " " 
			<< eta[ieta] << " " 
			<< pt[ipt] << " "
			<< " 1. " << endl;

       }
       if(ipt == nptbins && ieta == netabins) {

	 myoutput_leak << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << leak[ieta-1][ipt-1] << endl;
	 myoutput_leak1 << ieta << " " 
			<< ipt  << " " 
			<< eta[ieta] << " " 
			<< pt[ipt] << " "
			<< " 1. " << endl;

       }
     }
   }

   // calculate map of response and tracker efficiency

   cout <<" " << endl;
   cout <<" " << endl;
   cout <<" " << endl;

   for(Int_t ieta = 0; ieta <= netabins; ieta++) {
     for(Int_t ipt = 0; ipt <= nptbins; ipt++) {

       if(ieta < netabins && ipt < nptbins) {

	 if(ntrk[ieta][ipt] != 0 && ntrkrecor[ieta][ipt] != 0) {
	   trkeff[ieta][ipt] = 1.*ntrkreco[ieta][ipt]/ntrk[ieta][ipt];
	   etrkeff[ieta][ipt] = sqrt( trkeff[ieta][ipt]*(1.-trkeff[ieta][ipt])/ntrk[ieta][ipt] );
	   responseF[ieta][ipt] = response[ieta][ipt]/ntrkrecor[ieta][ipt];
	   
	   cout <<" ieta = " << ieta
		<<" eta = " << eta[ieta]
		<<" ipt = " << ipt
		<<" pt = " << pt[ipt]
		<<" ntrkreco = " << ntrkreco[ieta][ipt] 
		<<" ntrkrecor = " << ntrkrecor[ieta][ipt] 
		<<" ntrk = " << ntrk[ieta][ipt]
		<<" eff = " << trkeff[ieta][ipt] 
		<<" +/- " << etrkeff[ieta][ipt] 
		<<" response = " << responseF[ieta][ipt] << endl;
	   hResp->Fill(pt[ipt],eta[ieta],responseF[ieta][ipt]);
	   
	   myoutput_eff << ieta << " " 
			<< ipt  << " " 
			<< eta[ieta] << " " 
			<< pt[ipt] << " "
			<< trkeff[ieta][ipt] << endl;
	   
	   myoutput_resp << ieta << " " 
			 << ipt  << " " 
			 << eta[ieta] << " " 
			 << pt[ipt] << " "
			 << responseF[ieta][ipt] << endl;
	   
	   myoutput_eff1 << ieta << " " 
			 << ipt  << " " 
			 << eta[ieta] << " " 
			 << pt[ipt] << " "
			 << " 1." << endl;
	 } else {

	   trkeff[ieta][ipt] = trkeff[ieta][ipt-1];
	   responseF[ieta][ipt] = responseF[ieta][ipt-1];
	   hResp->Fill(pt[ipt],eta[ieta],responseF[ieta][ipt]);
	   myoutput_eff << ieta << " " 
			<< ipt  << " " 
			<< eta[ieta] << " " 
			<< pt[ipt] << " "
			<< trkeff[ieta][ipt] << endl;
	   
	   myoutput_resp << ieta << " " 
			 << ipt  << " " 
			 << eta[ieta] << " " 
			 << pt[ipt] << " "
			 << responseF[ieta][ipt] << endl;
	   
	   myoutput_eff1 << ieta << " " 
			 << ipt  << " " 
			 << eta[ieta] << " " 
			 << pt[ipt] << " "
			 << " 1." << endl;
	 }
       }

       if(ipt == nptbins && ieta < netabins) {
	 myoutput_eff << ieta << " " 
		      << ipt  << " " 
		      << eta[ieta] << " " 
		      << pt[ipt] << " "
		      << trkeff[ieta][ipt-1] << endl;
	 
	 myoutput_resp << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << responseF[ieta][ipt-1] << endl;
	 
	 myoutput_eff1 << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << " 1." << endl;
       }
       if(ipt < nptbins && ieta == netabins) {
	 myoutput_eff << ieta << " " 
		      << ipt  << " " 
		      << eta[ieta] << " " 
		      << pt[ipt] << " "
		      << trkeff[ieta-1][ipt] << endl;
	 
	 myoutput_resp << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << responseF[ieta-1][ipt] << endl;
	 
	 myoutput_eff1 << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << " 1." << endl;
       }
       if(ipt == nptbins && ieta == netabins) {
	 myoutput_eff << ieta << " " 
		      << ipt  << " " 
		      << eta[ieta] << " " 
		      << pt[ipt] << " "
		      << trkeff[ieta-1][ipt-1] << endl;
	 
	 myoutput_resp << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << responseF[ieta-1][ipt-1] << endl;
	 
	 myoutput_eff1 << ieta << " " 
		       << ipt  << " " 
		       << eta[ieta] << " " 
		       << pt[ipt] << " "
		       << " 1." << endl;
       }
     }
   }
   
   //
   // plot leakage graph
   Float_t leakage[netabins], eleakage[netabins];
   Float_t MeanNotInter[netabins], MeanErrorNotInter[netabins];
   Float_t MeanInter[netabins], MeanErrorInter[netabins];

   for(Int_t ih=0; ih < netabins; ih++) { 
     //     hEnTrkNotInter[ih]->Write();
     //     hEnTrkInter[ih]->Write();

     MeanNotInter[ih]      = hEnTrkNotInter[ih]->GetMean();
     MeanErrorNotInter[ih] = hEnTrkNotInter[ih]->GetMeanError();
     MeanInter[ih]         = hEnTrkInter[ih]->GetMean();
     MeanErrorInter[ih]    = hEnTrkInter[ih]->GetMeanError();
     leakage[ih] = MeanInter[ih]/MeanNotInter[ih];
     eleakage[ih] = leakage[ih] *
       sqrt( (MeanErrorNotInter[ih]/MeanNotInter[ih])*(MeanErrorNotInter[ih]/MeanNotInter[ih]) +
             (MeanErrorInter[ih]/MeanInter[ih])*(MeanErrorInter[ih]/MeanInter[ih]));

     cout <<" ieta = " << ih <<" MeanNotInter = " << MeanNotInter[ih] <<" +/- " << MeanErrorNotInter[ih]
	  <<" MeanInter = " << MeanInter[ih] <<" +/- " << MeanErrorInter[ih]  
	  <<" leakage = " << leakage[ih] <<" +/- " << eleakage[ih] << endl; 
   }

   TGraph *gleak = new TGraphErrors(netabins,etagr,leakage, eetagr,eleakage);
   TGraph *eMeanNotInter = new TGraphErrors(netabins,etagr,MeanNotInter, eetagr,MeanErrorNotInter);
   TGraph *eMeanInter = new TGraphErrors(netabins,etagr,MeanInter, eetagr,MeanErrorInter);
   //  vs Eta
   setTDRStyle(0,0);
   TCanvas* c3 = new TCanvas("X","Y",1);
   c3->Divide(1,2);
   c3->cd(1);
   TAxis* xaxis = eMeanNotInter->GetXaxis();
   eMeanNotInter->GetXaxis()->SetTitle("#eta");
   eMeanNotInter->GetYaxis()->SetTitle("calo E_{T}^{raw reco} in cone 0.5/p_{T}^{MC}");
   xaxis->SetLimits(0.0,2.4);
   eMeanNotInter->SetMarkerStyle(21);
   //   eMeanNotInter->SetMaximum(0.95);
   //   eMeanNotInter->SetMinimum(0.55);
   eMeanNotInter->SetMaximum(1.);
   eMeanNotInter->SetMinimum(0.);
   eMeanNotInter->Draw("AP");
   eMeanInter->SetMarkerStyle(24);
   eMeanInter->Draw("P");
   TLatex *t = new TLatex();
   t->SetTextSize(0.08);
   t->DrawLatex(0.2,0.9,"CMSSW_1_6_9");
   TLegend *leg = new TLegend(0.2,0.2,0.8,0.4,NULL,"brNDC");
   leg->SetFillColor(10);
   leg->AddEntry(eMeanNotInter,"recontructed tracks 2 < p_{T}^{#pi^{#pm}} < 10 GeV","P");
   leg->AddEntry(eMeanInter,"not reconstructed tracks 2 < p_{T}^{#pi^{#pm}} < 10 GeV","P");
   leg->Draw();

   c3->cd(2);
   TAxis* xaxis = gleak->GetXaxis();
   gleak->GetXaxis()->SetTitle("#eta");
   gleak->GetYaxis()->SetTitle("ratio = <E_{T for lost tracks}^{raw reco} / E_{T for found tracks}^{raw reco}>");
   xaxis->SetLimits(0.0,2.4);
   gleak->SetMarkerStyle(21);
   gleak->SetMaximum(1.0);
   //  leak->SetMinimum(0.7);
   gleak->SetMinimum(0.5);
   gleak->Draw("AP");
   TLatex *t = new TLatex();
   t->SetTextSize(0.08);
   //   t->DrawLatex(0.1,0.75,"<E_{T for lost tracks}^{raw reco} / E_{T for found tracks}^{raw reco}> for p_{T}^{#pi^{#pm}} >2 GeV");
   c3->SaveAs("eMean_vs_eta_pt2-10.gif");
   c3->SaveAs("eMean_vs_eta_pt2-10.eps");

   //  original distribtions
   setTDRStyle(0,0);
   gStyle->SetOptFit(0);
   TCanvas* c4 = new TCanvas("X","Y",1);
   hEnTrkNotInter[0]->GetYaxis()->SetTitle("");
   hEnTrkNotInter[0]->GetXaxis()->SetTitle("calo E_{T}^{raw reco} in cone 0.5/p_{T}^{MC}");
   Double_t scale = 1./hEnTrkNotInter[0]->Integral();
   hEnTrkNotInter[0]->Scale(scale);
   hEnTrkNotInter[0]->SetLineWidth(4);
   hEnTrkNotInter[0]->SetMaximum(0.14);
   //   hEnTrkNotInter[0]->SetMinimum(0.55);
   // Fitting
   Int_t binMax = hEnTrkNotInter[0]->GetMaximumBin();
   TAxis* xaxis = hEnTrkNotInter[0]->GetXaxis();
   Double_t binCenter = xaxis->GetBinCenter(binMax);
   Double_t rms = hEnTrkNotInter[0]->GetRMS();
   Double_t rFitMin = binCenter - 1.5 * rms; 
   Double_t rFitMax = binCenter + 1.5 * rms;
   hEnTrkNotInter[0]->Fit("gaus","","",rFitMin,rFitMax);
   TF1 *fit = hEnTrkNotInter[0]->GetFunction("gaus"); 
   fit->SetLineWidth(4);
   fit->SetLineStyle(2);
   fit->Draw("same");
   scale = 1./hEnTrkInter[0]->Integral();
   hEnTrkInter[0]->Scale(scale);
   hEnTrkInter[0]->SetLineWidth(2);
  // Fitting
   Int_t binMax = hEnTrkInter[0]->GetMaximumBin();
   TAxis* xaxis = hEnTrkInter[0]->GetXaxis();
   Double_t binCenter = xaxis->GetBinCenter(binMax);
   Double_t rms = hEnTrkNotInter[0]->GetRMS();
   Double_t rFitMin = binCenter - 1.5 * rms; 
   Double_t rFitMax = binCenter + 1.5 * rms;
   hEnTrkInter[0]->Fit("gaus","","same",rFitMin,rFitMax);
   TF1 *fit = hEnTrkInter[0]->GetFunction("gaus"); 
   fit->SetLineWidth(2);
   fit->SetLineStyle(2);
   fit->Draw("same");
   TLatex *t = new TLatex();
   t->SetTextSize(0.08);
   t->DrawLatex(0.2,0.9,"CMSSW_1_6_9");
   TLegend *leg = new TLegend(0.15,0.7,0.9,0.9,NULL,"brNDC");
   leg->SetFillColor(10);
   leg->AddEntry(hEnTrkNotInter[0],"recontructed tracks 2< p_{T}^{#pi^{#pm}} < 10 GeV, 0<#eta<0.2","L");
   leg->AddEntry(hEnTrkInter[0],"not reconstructed tracks 2< p_{T}^{#pi^{#pm}} < 10 GeV, 0<#eta<0.2","L");
   leg->Draw();

   c4->SaveAs("eMean_at_eta0.gif");
   c4->SaveAs("eMean_at_eta0.eps");

   //  original distribtions
   setTDRStyle(0,0);
   gStyle->SetOptFit(0);
   TCanvas* c5 = new TCanvas("X","Y",1);
   hEnTrkNotInter[9]->GetYaxis()->SetTitle("");
   hEnTrkNotInter[9]->GetXaxis()->SetTitle("calo E_{T}^{raw reco} in cone 0.5/p_{T}^{MC}");
   Double_t scale = 1./hEnTrkNotInter[9]->Integral();
   hEnTrkNotInter[9]->Scale(scale);
   hEnTrkNotInter[9]->SetLineWidth(4);
   hEnTrkNotInter[9]->SetMaximum(0.17);
   //   hEnTrkNotInter[9]->SetMinimum(0.55);
   // Fitting
   Int_t binMax = hEnTrkNotInter[9]->GetMaximumBin();
   TAxis* xaxis = hEnTrkNotInter[9]->GetXaxis();
   Double_t binCenter = xaxis->GetBinCenter(binMax);
   Double_t rms = hEnTrkNotInter[9]->GetRMS();
   Double_t rFitMin = binCenter - 1.5 * rms; 
   Double_t rFitMax = binCenter + 1.5 * rms;
   hEnTrkNotInter[9]->Fit("gaus","","",rFitMin,rFitMax);
   TF1 *fit = hEnTrkNotInter[9]->GetFunction("gaus"); 
   fit->SetLineWidth(4);
   fit->SetLineStyle(2);
   fit->Draw("same");
   scale = 1./hEnTrkInter[9]->Integral();
   hEnTrkInter[9]->Scale(scale);
   hEnTrkInter[9]->SetLineWidth(2);
  // Fitting
   Int_t binMax = hEnTrkInter[9]->GetMaximumBin();
   TAxis* xaxis = hEnTrkInter[9]->GetXaxis();
   Double_t binCenter = xaxis->GetBinCenter(binMax);
   Double_t rms = hEnTrkNotInter[9]->GetRMS();
   Double_t rFitMin = binCenter - 1.2 * rms; 
   Double_t rFitMax = binCenter + 1.5 * rms;
   hEnTrkInter[9]->Fit("gaus","","same",rFitMin,rFitMax);
   TF1 *fit = hEnTrkInter[9]->GetFunction("gaus"); 
   fit->SetLineWidth(2);
   fit->SetLineStyle(2);
   fit->Draw("same");
   TLatex *t = new TLatex();
   t->SetTextSize(0.08);
   t->DrawLatex(0.2,0.9,"CMSSW_1_6_9");
   TLegend *leg = new TLegend(0.15,0.7,0.9,0.9,NULL,"brNDC");
   leg->SetFillColor(10);
   leg->AddEntry(hEnTrkNotInter[9],"recontructed tracks p_{T}^{#pi^{#pm}} > 2 GeV, 1.8<#eta<2.0","L");
   leg->AddEntry(hEnTrkInter[9],"not reconstructed tracks p_{T}^{#pi^{#pm}} > 2 GeV, 1.8<#eta<2.0","L");
   leg->Draw();

   c5->SaveAs("eMean_at_eta1.9.gif");
   c5->SaveAs("eMean_at_eta1.9.eps");

   TFile efile("response.root","recreate");
   hResp->Write();
   efile.Close();
}
void SUSY_m0_vs_m12_all_withBand_cls( TString fname0 = "mudat_list.root",// nominal
                                      TString fname1 = "",               // Up
                                      TString fname2 = "",               // Down  
                                      TString fname3 = "", // external expection
                                      const char* prefix="test",
                                      const float& lumi = 20,
                                      bool showsig = true,
                                      int discexcl = 1,
                                      int showtevatron = 0,
                                      int showcms = 0,
                                      int showOneSigmaExpBand = 0,
                                      int showfixSigXSecBand = 0,
                                      int channel = -1,
                                      TString hname0 = "sigp1clsf",
                                      TString hname1 = "sigp1expclsf",
                                      TString hname3 = "sigclsu1s",
                                      TString hname5 = "sigclsd1s",
                                      TString hname6 = "sigp1ref",
                                      TString fnameMass= "../../../HistFitterUser/common/mSugraGridtanbeta10_gluinoSquarkMasses.root")
{
   // set style and remove existing canvas'
   CombinationGlob::Initialize();
   
   cout << "--- Plotting m0 versus m12 " << endl;
   
   // --- prepare
   // open reference files, and retrieve histogram
   cout << "--- Reading root base file: " << fname0 << endl;
   TFile* f0 = TFile::Open( fname0, "READ" );
   if (!f0) {
      cout << "*** Error: could not retrieve histogram: " << hname0 << " in file: " << f0->GetName() 
           << " ==> abort macro execution" << endl;
      return;
   }
   
   TFile* f1;
   TFile* f2;
   if(showfixSigXSecBand){
      cout << "--- Reading root base file: " << fname1 << endl;
      f1 = TFile::Open( fname1, "READ" );
      cout << "--- Reading root base file: " << fname2 << endl;
      f2 = TFile::Open( fname2, "READ" );

      if(!f1 || !f2){
         cout << "*** Error: could not open in files: " << f1->GetName() <<" or "<< f2->GetName() 
              << " ==> abort macro execution" << endl;
         return;
      }
   }
   
   TH2F* histecls = (TH2F*)f0->Get( "sigp1expclsf" ); 
   TH2F* histocls = (TH2F*)f0->Get( "sigp1clsf" ); 
   if (histecls!=0) histecls->SetDirectory(0);
   if (histocls!=0) histocls->SetDirectory(0);
   
   // in case we use external expectation!
   TFile* f3 = TFile::Open( fname3, "READ" );
   TH2F* histe(0);
   if (f3) { histe = (TH2F*)f3->Get( hname0 ); }
   TH2F* histe_u1s(0);
   if (f3) { histe_u1s = (TH2F*)f3->Get( hname3 ); }
   TH2F* histe_d1s(0);
   if (f3) { histe_d1s = (TH2F*)f3->Get( hname5 ); }
   
   if (f3) {
      if (histecls!=0) { delete histecls; histecls=0; }
      histecls = (TH2F*)f3->Get( "sigp1expcls" );
      if (histecls!=0) histecls->SetDirectory(0);
      else {
        histecls = (TH2F*)f3->Get( "sigp1expclsf" );
        if (histecls!=0) histecls->SetDirectory(0);
      }
   }
   
   bool extExpectation = (f3!=0) ;
   
   TH2F* hist0 = (TH2F*)f0->Get( hname0 );
   TH2F* hist1 = (TH2F*)f0->Get( hname1 );
   TH2F* hist3 = (TH2F*)f0->Get( hname3 );
   TH2F* hist5 = (TH2F*)f0->Get( hname5 );
   TH2F* hist6 = (TH2F*)f0->Get( hname6 );
   
   if (hist0!=0) hist0->SetDirectory(0);
   if (hist1!=0) hist1->SetDirectory(0);
   if (hist3!=0) hist3->SetDirectory(0);
   if (hist5!=0) hist5->SetDirectory(0);
   if (hist6!=0) hist6->SetDirectory(0);
   f0->Close();

   TH2F* histe_esigxsp1s = (TH2F*)f1->Get( hname0 ); 
   TH2F* histe_esigxsm1s = (TH2F*)f2->Get( hname0 ); 

   if (histe_esigxsp1s!=0) histe_esigxsp1s->SetDirectory(0);
   if (histe_esigxsm1s!=0) histe_esigxsm1s->SetDirectory(0);

   TH2F* contour_esigxsp1s
      = ( histe_esigxsp1s!=0 ? FixAndSetBorders( *histe_esigxsp1s, "contour_esigxsp1s", "contour_esigxsp1s", 0 ) : 0);
   TH2F* contour_esigxsm1s
      = ( histe_esigxsm1s!=0 ? FixAndSetBorders( *histe_esigxsm1s, "contour_esigxsm1s", "contour_esigxsm1s", 0 ) : 0);
   
   TH2F* contour         = ( hist1!=0 ? FixAndSetBorders( *hist1, "contour", "contour", 0 ) : 0);
   TH2F* contour_obs     = ( hist0!=0 ? FixAndSetBorders( *hist0, "contour_obs", "contour_obs") : 0 );
   
   TH2F* contour_ep1s    = ( hist3!=0 ? FixAndSetBorders( *hist3, "contour", "contour", 0 ) : 0 );
   TH2F* contour_em1s    = ( hist5!=0 ? FixAndSetBorders( *hist5, "contour", "contour", 0 ) : 0 );

   // For Band
   TGraph* gr_contour_ep1s = ( contour_ep1s!=0 ? ContourGraph( contour_ep1s ) : 0 ); //ContourGraph( contour_ep1s )->Clone(); 
   TGraph* gr_contour_em1s = ( contour_em1s!=0 ? ContourGraph( contour_em1s ) : 0 ); //ContourGraph( contour_em1s )->Clone(); 
   
   TH2F* contour_exp(0);
   if (histe!=0)     { contour_exp     = FixAndSetBorders( *histe, "contour_exp", "contour_exp", 0 ); } 
   TH2F* contour_au1s(0);
   if (histe_u1s!=0) {  contour_au1s   = FixAndSetBorders( *histe_u1s, "contour", "contour", 0 ); }
   TH2F* contour_ad1s(0);
   if (histe_d1s!=0) {  contour_ad1s   = FixAndSetBorders( *histe_d1s, "contour", "contour", 0 ); }
   
   
   TH2F* contour_expcls(0);
   if (histecls!=0)     { contour_expcls     = FixAndSetBorders( *histecls, "contour_expcls", "contour_expcls", 0 ); }
   TH2F* contour_obscls(0);
   if (histocls!=0)     { contour_obscls     = FixAndSetBorders( *histocls, "contour_obscls", "contour_obscls", 0 ); }

   if (contour_obs==0) { 
      cout << "contour is zero" << endl;
      return;
   }


   
   // set text style
   gStyle->SetPaintTextFormat(".2g");
   if (hist1!=0) hist1->SetMarkerStyle(21);
   if (hist1!=0) hist1->SetMarkerSize(1.5);
   Float_t nsigmax(0)
      if (hist1!=0) nsigmax = hist1->GetMaximum();
   
   // --- draw
   
   // create canvas
   TCanvas* c = new TCanvas( "c", "A scan of m_{0} versus m_{12}", 0, 0, 
                             CombinationGlob::StandardCanvas[0], CombinationGlob::StandardCanvas[1] );  
  //c->SetGrayscale();
  
  // create and draw the frame
  //TH2F *frame = new TH2F("frame", "m_{0} vs m_{12} - ATLAS work in progress", 100, 100., 1400., 100, 115., 500. );
  TH2F *frame = new TH2F("frame", "m_{0} vs m_{12} - ATLAS work in progress", 100, 100., 3750., 100, 115., 700. );
  //TH2F *frame = new TH2F("frame", "m_{0} vs m_{12} - ATLAS work in progress", 100, 100., 600., 100, 240., 500. );
  
  // set common frame style
  CombinationGlob::SetFrameStyle2D( frame, 1.0 ); // the size (scale) is 1.0
  
  frame->SetXTitle( "m_{0} [GeV]" );
  frame->SetYTitle( "m_{1/2} [GeV]" );
  frame->GetYaxis()->SetTitleOffset(1.35);

  //frame->SetTextFont( 42 );
  frame->GetXaxis()->SetTitleFont( 42 );
  frame->GetYaxis()->SetTitleFont( 42 );
  frame->GetXaxis()->SetLabelFont( 42 );
  frame->GetYaxis()->SetLabelFont( 42 );

  frame->GetXaxis()->SetTitleSize( 0.04 );
  frame->GetYaxis()->SetTitleSize( 0.04 );
  frame->GetXaxis()->SetLabelSize( 0.04 );
  frame->GetYaxis()->SetLabelSize( 0.04 );

  frame->Draw();
    
  const int nsig(3);
  //TH2F *chist[3];
  // draw contours
  //!instead of printing sigma in 68% 95% 98% levels now printing +1 sigma deviations 
  //for (Int_t nsigma=1; nsigma<=nsig; nsigma++)
  //  DrawContourSameColor( contour, nsigma, "blue", kFALSE, (nsigma==1?inverse:0) ) ;

  TString basecolor="yellow";
  Int_t nsigma=2;

  //  TLegend *leg = new TLegend(0.7,0.77,0.95,0.915);
  TLegend *leg = new TLegend(0.57,0.52,0.85,0.915);//(0.565,0.47,0.925,0.915);//(0.59,0.47,0.92,0.915);

  leg->SetTextSize( CombinationGlob::DescriptionTextSize );
  leg->SetTextSize( 0.03 );
  leg->SetTextFont( 42 );
  leg->SetFillColor( 0 );
  leg->SetFillStyle(1001);
  
  // add squark, gluino mass contour lines HERE (TILL)
  TFile* f4 = TFile::Open( fnameMass, "READ" );
  TH2F* histSq = (TH2F*)f4->Get( "mSugraGrid_squarkMasses" );
  TH2F* histGl = (TH2F*)f4->Get( "mSugraGrid_gluinoMasses" );
  histSq->SetDirectory(0);
  histGl->SetDirectory(0);
  f4->Close();

  TH2F* histSquarkMass   = FixAndSetBorders( *histSq, "SquarkMass", "SquarkMass", 10000 );
  TH2F* histGluinoMass   = FixAndSetBorders( *histGl, "GluinoMass", "GluinoMass", 10000 );
  
//  DrawContourMassLine( histSquarkMass, 400.0 );
//  DrawContourMassLine( histSquarkMass, 500.0 );
  DrawContourMassLine( histSquarkMass, 600.0 );
//  DrawContourMassLine( histSquarkMass, 700.0 );
  DrawContourMassLine( histSquarkMass, 800.0 , 17);
//  DrawContourMassLine( histSquarkMass, 900.0 );
  DrawContourMassLine( histSquarkMass, 1000.0 );  
//  DrawContourMassLine( histSquarkMass, 1100.0 ); 
  DrawContourMassLine( histSquarkMass, 1200.0 , 17);
//  DrawContourMassLine( histSquarkMass, 1300.0 );    
  DrawContourMassLine( histSquarkMass, 1400.0 );
//  DrawContourMassLine( histSquarkMass, 1500.0 );
  DrawContourMassLine( histSquarkMass, 1600.0 , 17);
//  DrawContourMassLine( histSquarkMass, 1700.0 );
  DrawContourMassLine( histSquarkMass, 1800.0 );
//  DrawContourMassLine( histSquarkMass, 1900.0 );
  DrawContourMassLine( histSquarkMass, 2000.0 , 17);  
//  DrawContourMassLine( histSquarkMass, 2100.0 ); 
  DrawContourMassLine( histSquarkMass, 2200.0 );  
//  DrawContourMassLine( histSquarkMass, 2300.0 );     
  DrawContourMassLine( histSquarkMass, 2400.0 , 17);
//  DrawContourMassLine( histSquarkMass, 2500.0 );
  DrawContourMassLine( histSquarkMass, 2600.0 );
//  DrawContourMassLine( histSquarkMass, 2700.0 );
  DrawContourMassLine( histSquarkMass, 2800.0 , 17);
//  DrawContourMassLine( histSquarkMass, 2900.0 );
  DrawContourMassLine( histSquarkMass, 3000.0 );   
//  DrawContourMassLine( histSquarkMass, 3100.0 ); 
  DrawContourMassLine( histSquarkMass, 3200.0 , 17);  
//  DrawContourMassLine( histSquarkMass, 2300.0 );     
  DrawContourMassLine( histSquarkMass, 3400.0 );
//  DrawContourMassLine( histSquarkMass, 3500.0 );
//  DrawContourMassLine( histSquarkMass, 3600.0 , 17);
//  DrawContourMassLine( histSquarkMass, 3700.0 );
//  DrawContourMassLine( histSquarkMass, 3800.0 );
//  DrawContourMassLine( histSquarkMass, 3900.0 );
//  DrawContourMassLine( histSquarkMass, 4000.0 );        

  DrawContourMassLine( histGluinoMass, 400.0 );
  DrawContourMassLine( histGluinoMass, 500.0 , 17);
  DrawContourMassLine( histGluinoMass, 600.0 );
  DrawContourMassLine( histGluinoMass, 700.0 , 17);
  DrawContourMassLine( histGluinoMass, 800.0 );
  DrawContourMassLine( histGluinoMass, 900.0 , 17);
  DrawContourMassLine( histGluinoMass, 1000.0 );  
  DrawContourMassLine( histGluinoMass, 1100.0 , 17);  
  DrawContourMassLine( histGluinoMass, 1200.0 );  
  DrawContourMassLine( histGluinoMass, 1300.0 , 17);      
  DrawContourMassLine( histGluinoMass, 1400.0 );
  DrawContourMassLine( histGluinoMass, 1500.0 , 17);
  DrawContourMassLine( histGluinoMass, 1600.0 );
//  DrawContourMassLine( histGluinoMass, 1700.0 );
//  DrawContourMassLine( histGluinoMass, 1800.0 );
//  DrawContourMassLine( histGluinoMass, 1900.0 );
//  DrawContourMassLine( histGluinoMass, 2000.0 );  
//  DrawContourMassLine( histGluinoMass, 2100.0 ); 

  // find gluino ~ squark mass exclusion limit
  //DrawContourMassLine( histSquarkMass, 820.0 );
  //DrawContourMassLine( histGluinoMass, 820.0 );

/*  TLatex * s400 = new TLatex( 140, 167 , "#tilde{q} (400 GeV)" );
  s400->SetTextAlign( 11 );
  s400->SetTextSize( 0.025 );
  s400->SetTextColor( TColor::GetColor("#dddddd") );
  s400->Draw();*/
/*  TLatex * s500 = new TLatex( 150, 220, "#tilde{q} (500 GeV)" );
  s500->SetTextAlign( 11 );
  s500->SetTextSize( 0.025 );
  s500->SetTextColor( TColor::GetColor("#dddddd") );
  s500->Draw();*/
  TLatex * s600 = new TLatex( 340, 230, "#tilde{q} (600 GeV)" );
  s600->SetTextAlign( 11 );
  s600->SetTextAngle(-60);
  s600->SetTextSize( 0.025 );
  s600->SetTextColor( 16 ); //12
  s600->Draw();
  /*TLatex * s700 = new TLatex( 545, 315, "#tilde{q} (700 GeV)" );
  s700->SetTextAlign( 11 );
  s700->SetTextSize( 0.025 );
  s700->SetTextColor( TColor::GetColor("#dddddd") );
  s700->Draw();*/
  /*TLatex * s800 = new TLatex( 250, 270, "#tilde{q} (800 GeV)" );
  s800->SetTextAlign( 11 );
  s800->SetTextSize( 0.025 );
  s800->SetTextColor( 203 );
  s800->Draw();*/
  /*
  TLatex * s900 = new TLatex( 330, 400, "#tilde{q} (900 GeV)" );
  s900->SetTextAlign( 11 );
  s900->SetTextSize( 0.025 );
  s900->SetTextColor( TColor::GetColor("#dddddd") );
  s900->Draw();*/
   TLatex * s1000 = new TLatex( 550, 408, "#tilde{q} (1000 GeV)" );
  s1000->SetTextAlign( 11 );
  s1000->SetTextAngle(-60);
  s1000->SetTextSize( 0.025 );
  s1000->SetTextColor( 16 );
  s1000->Draw(); 
   TLatex * s1400 = new TLatex( 790, 580, "#tilde{q} (1400 GeV)" );
  s1400->SetTextAlign( 11 );
  s1400->SetTextAngle(-60);
  s1400->SetTextSize( 0.025 );
  s1400->SetTextColor( 16 );
  s1400->Draw();   

  /*TLatex * g400 = new TLatex( 1100, 140, "#tilde{g} (400 GeV)" );
  g400->SetTextAlign( 11 );
  g400->SetTextSize( 0.025 );
  g400->SetTextColor( 203 );
  g400->Draw();*/
  /*TLatex * g500 = new TLatex( 1000, 185, "#tilde{g} (500 GeV)" );
  g500->SetTextAlign( 11 );
  g500->SetTextSize( 0.025 );
  g500->SetTextColor( TColor::GetColor("#dddddd") );
  g500->Draw();*/
  TLatex * g600 = new TLatex( 1100, 225, "#tilde{g} (600 GeV)" );
  g600->SetTextAlign( 11 );
  g600->SetTextAngle(-4);
  g600->SetTextSize( 0.025 );
  g600->SetTextColor( 16 );
  g600->Draw();
  /*TLatex * g900 = new TLatex( 550, 380, "#tilde{g} (900 GeV)" );
  g900->SetTextAlign( 11 );
  g900->SetTextSize( 0.025 );
  g900->SetTextColor( TColor::GetColor("#dddddd") );
  g900->Draw();*/
  TLatex * g800 = new TLatex( 690, 330, "#tilde{g} (800 GeV)" );
  g800->SetTextAlign( 11 );
  g800->SetTextSize( 0.025 );
  g800->SetTextColor( 16 );
  //g800->Draw();
  TLatex * g1000 = new TLatex( 1400, 399, "#tilde{g} (1000 GeV)" );
  g1000->SetTextAlign( 11 );
  g1000->SetTextAngle(-5); 
  g1000->SetTextSize( 0.025 );
  g1000->SetTextColor( 16 );
  g1000->Draw();
  TLatex * g1200 = new TLatex( 1550, 489, "#tilde{g} (1200 GeV)" );
  g1200->SetTextAlign( 11 );
  g1200->SetTextAngle(-6); 
  g1200->SetTextSize( 0.025 );
  g1200->SetTextColor( 16 );
  //g1200->Draw();  
  TLatex * g1400 = new TLatex( 1650, 582, "#tilde{g} (1400 GeV)" );
  g1400->SetTextAlign( 11 );
  g1400->SetTextAngle(-6); 
  g1400->SetTextSize( 0.025 );
  g1400->SetTextColor( 16 );
  g1400->Draw();
  
  // island hacks
  if (true && channel==4) { // muon fixes 
    cout << "removing islands in muon channel ..." << endl;
    // contour line is drawn for values at 1.64485
    TAxis* ax = contour_obs->GetXaxis();
    TAxis* ay = contour_obs->GetYaxis();

    TH2F* contour_fix = contour_em1s;

    for (int xbin = 1; xbin <= contour_fix->GetNbinsX(); xbin++) {
      for (int ybin = 1; ybin <= contour_fix->GetNbinsY(); ybin++) {
	// island 1
	if ( ax->GetBinCenter( xbin) > 1350.  && ax->GetBinCenter( xbin) < 1500. && ay->GetBinCenter( ybin) < 130. && ay->GetBinCenter( ybin) > 89. ) {
	  cout << "Found spot here: " << xbin << " (" << ax->GetBinCenter( xbin)  << "), "
	       << ybin << " (" << ay->GetBinCenter( ybin) << "), "
	       << " value: " << contour_fix->GetBinContent(xbin,ybin) <<   endl;
	  cout << "   HACK : Setting above point by hand to 1.65 (!)" << endl;
	  if (contour_fix->GetBinContent(xbin,ybin)<1.65) contour_fix->SetBinContent(xbin, ybin, 1.66);
	}

      }
    }

  } 
  if (false && channel==1) { // electron

    cout << "removing islands in electron channel ..." << endl;
    // contour line is drawn for values at 1.64485
    TAxis* ax = contour_obs->GetXaxis();
    TAxis* ay = contour_obs->GetYaxis();

    contour_em1s

    for (int xbin = 1; xbin <= contour_obs->GetNbinsX(); xbin++) {
      for (int ybin = 1; ybin <= contour_obs->GetNbinsY(); ybin++) {
	// island 2
	if ( ax->GetBinCenter( xbin) > 420. && ax->GetBinCenter( xbin) < 480. &&
	     ay->GetBinCenter( ybin) > 140. && ay->GetBinCenter( ybin) < 160. ) {
	  cout << "Found spot here: " << xbin << " (" << ax->GetBinCenter( xbin)  << "), "
	       << ybin << " (" << ay->GetBinCenter( ybin) << "), "
	       << " value: " << contour->GetBinContent(xbin,ybin) <<   endl;
	  cout << "   HACK : Setting above point by hand to 1.50 (!)" << endl;
	  contour->SetBinContent(xbin, ybin, 1.50);
	}
      }
    }

  }
///////////////////////
// Begin Main function:
void mkROOTaqgcMuLT0_Para(){


  //////////////////////////////////////
  // Set MC normalization scale factors:
  const double intLUMI = 19297;

  const double WWA_scale     =  2.1*0.01362 * intLUMI/198777;
  const double WWA2_scale    =  2.1*0.01409 * intLUMI/199183;

  const double LT0_p8m5_scale     =  2.1*0.0809985 * intLUMI/184603 ;
  const double LT0_p5m5_scale     =  2.1*0.0443325 * intLUMI/149975;
  const double LT0_p3m5_scale     =  2.1*0.029308 * intLUMI/97015;
  const double LT0_m3m5_scale     =  2.1*0.0290669 * intLUMI/154634;
  const double LT0_m5m5_scale     =  2.1*0.0440545 * intLUMI/199930;
  const double LT0_m8m5_scale     =  2.1*0.0806445 * intLUMI/196613;


  ///////////////////////////////////////////////////////////////////////////////////
  // Specify what kinematical distribution to observe, as well as histogram settings:
  // 
  plotVar_t pv = {"Photon_Et[iPhoton12]",30,450,10,3,"Photon ET (GeV)"};
  if ( !strlen(pv.plotvar) ) break;
  std::cout << TString(pv.plotvar) << "\t"<<pv.MINRange<<"\t" << pv.MAXRange<<"\t" << pv.NBINS<<"\tTHE CUT " << endl;


  ////////////////////////////////
  // Specify event selection cuts:
  TCut the_cutKfac("effwt*puwt*(iPhoton12>-1&&Photon_Et[iPhoton12]>30.&&Photon_dRlep[iPhoton12]>0.5&&i12Jet2>-1&&i12Jet1>-1&&JetPFCor_dRpho12[i12Jet1]>0.5&&JetPFCor_dRpho12[i12Jet2]>0.5&&abs(W_muon_eta)<2.1&&abs(JetPFCor_dphiMET[i12Jet1])>0.4&& abs(JetPFCor_dphiMET[i12Jet2])>0.4&&JetPFCor_bDiscriminatorCSV[i12Jet1]<0.679&&JetPFCor_bDiscriminatorCSV[i12Jet2]<0.679&&abs(JetPFCor_Eta[i12Jet1]-JetPFCor_Eta[i12Jet2])<1.4&&abs(Photon_Eta[iPhoton12])<1.44421&&W_muon_pt>25&&event_met_pfmet>35.&&c2jMass12>70.&&c2jMass12<100.&&W_mt>30.&&abs(W_muon_dz000)<0.02&&abs(W_muon_dzPV)<0.5&&((i12Jet3>-1)? JetPFCor_dRpho12[i12Jet3]>0.5: 1 )&&((i12Jet4>-1)? JetPFCor_dRpho12[i12Jet4]>0.5: 1 ))");
//mva2jWWAmuA1>0.32

  ///////////////////////////
  // Create output ROOT file:
  TFile f("para_mu_LT0_WWA_PhotonEt.root", "RECREATE");


  //////////////////////////////////////////////////
  // Create file pointers for each sample ROOT file:
  TFile *wwaShape_file,*wwa2Shape_file;

  TFile *LT0_m8m5_file,*LT0_m5m5_file,*LT0_m3m5_file,*LT0_p3m5_file,*LT0_p5m5_file,*LT0_p8m5_file;


  //////////////////////////////
  // Open each sample ROOT file:
  wwaShape_file = new TFile("InData_New/RD_mu_qq_wpwma_wp_qq_wm_lvl.root");
  wwa2Shape_file = new TFile("InData_New/RD_mu_qq_wpwma_wp_lvl_wm_qq.root");

  LT0_m8m5_file = new TFile("InData_New/RD_mu_LT0_m8m11MG_CMSSW532.root");
  LT0_m5m5_file = new TFile("InData_New/RD_mu_LT0_m5m11MG_CMSSW532.root");
  LT0_m3m5_file = new TFile("InData_New/RD_mu_LT0_m3m11MG_CMSSW532.root");
  LT0_p3m5_file = new TFile("InData_New/RD_mu_LT0_p3m11MG_CMSSW532.root");
  LT0_p5m5_file = new TFile("InData_New/RD_mu_LT0_p5m11MG_CMSSW532.root");
  LT0_p8m5_file = new TFile("InData_New/RD_mu_LT0_p8m11MG_CMSSW532.root");


  ///////////////////////////////////////////////////
  // Retrieve ROOT tree with kinematic distributions:
  TTree* treewwa    = (TTree*)    wwaShape_file->Get("WJet");
  TTree* treewwa2    = (TTree*)    wwa2Shape_file->Get("WJet");

  TTree* treeLT0_m8m5 = (TTree*) LT0_m8m5_file->Get("WJet");
  TTree* treeLT0_m5m5 = (TTree*) LT0_m5m5_file->Get("WJet");
  TTree* treeLT0_m3m5 = (TTree*) LT0_m3m5_file->Get("WJet");
  TTree* treeLT0_p3m5 = (TTree*) LT0_p3m5_file->Get("WJet");
  TTree* treeLT0_p5m5 = (TTree*) LT0_p5m5_file->Get("WJet");
  TTree* treeLT0_p8m5 = (TTree*) LT0_p8m5_file->Get("WJet");


  ////////////////////////////////////////////////////////////
  // Create kinematic-distribution histograms for each sample:
  TH1* th1wwa = new TH1D("th1wwa", "th1wwa", pv.NBINS, pv.MINRange, pv.MAXRange);
  TH1* th1wwa2 = new TH1D("th1wwa2", "th1wwa2", pv.NBINS, pv.MINRange, pv.MAXRange);

  TH1* signal_lt0_80 = new TH1D("signal_lt0_80","signal_lt0_80",pv.NBINS, pv.MINRange, pv.MAXRange);
  TH1* signal_lt0_50 = new TH1D("signal_lt0_50","signal_lt0_50",pv.NBINS, pv.MINRange, pv.MAXRange);
  TH1* signal_lt0_30 = new TH1D("signal_lt0_30","signal_lt0_30",pv.NBINS, pv.MINRange, pv.MAXRange);
  TH1* signal_lt0_m30 = new TH1D("signal_lt0_m30","signal_lt0_-30",pv.NBINS, pv.MINRange, pv.MAXRange);
  TH1* signal_lt0_m50 = new TH1D("signal_lt0_m50","signal_lt0_-50",pv.NBINS, pv.MINRange, pv.MAXRange);
  TH1* signal_lt0_m80 = new TH1D("signal_lt0_m80","signal_lt0_-80",pv.NBINS, pv.MINRange, pv.MAXRange);


  /////////////////////////////////////////////////////////////////////////
  // Specify histograms to store Sum of Squares of Weights for each sample:
  th1wwa->Sumw2();
  th1wwa2->Sumw2();

  ///////////////////////////////////////////////////////////////////////////////////
  // Fill kinematical distribution for each sample according to event selection cuts:
  std::cout<<"Fill SM WWA Histogram..."<<std::endl;
  treewwa->Draw(TString(pv.plotvar)+TString(">>th1wwa"), the_cutKfac, "goff");
  th1wwa->AddBinContent(pv.NBINS,th1wwa->GetBinContent(pv.NBINS+1));th1wwa->SetBinContent(pv.NBINS+1,0.);
  treewwa2->Draw(TString(pv.plotvar)+TString(">>th1wwa2"), the_cutKfac, "goff");
  th1wwa2->AddBinContent(pv.NBINS,th1wwa2->GetBinContent(pv.NBINS+1));th1wwa2->SetBinContent(pv.NBINS+1,0.);


  std::cout<<"Fill aQGC_1 WWA Histogram..."<<std::endl;
  treeLT0_m8m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_m80"), the_cutKfac, "goff");

  std::cout<<"Fill aQGC_2 WWA Histogram..."<<std::endl;
  treeLT0_m5m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_m50"), the_cutKfac, "goff");

  std::cout<<"Fill aQGC_3 WWA Histogram..."<<std::endl;
  treeLT0_m3m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_m30"), the_cutKfac, "goff");

  std::cout<<"Fill aQGC_4 WWA Histogram..."<<std::endl;
  treeLT0_p3m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_30"), the_cutKfac, "goff");

  std::cout<<"Fill aQGC_5 WWA Histogram..."<<std::endl;
  treeLT0_p5m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_50"), the_cutKfac, "goff");

  std::cout<<"Fill aQGC_6 WWA Histogram..."<<std::endl;
  treeLT0_p8m5->Draw(TString(pv.plotvar)+TString(">>signal_lt0_80"), the_cutKfac, "goff");

  signal_lt0_80->AddBinContent(pv.NBINS,signal_lt0_80->GetBinContent(pv.NBINS+1));signal_lt0_80->SetBinContent(pv.NBINS+1,0.);
  signal_lt0_50->AddBinContent(pv.NBINS,signal_lt0_50->GetBinContent(pv.NBINS+1));signal_lt0_50->SetBinContent(pv.NBINS+1,0.);
  signal_lt0_30->AddBinContent(pv.NBINS,signal_lt0_30->GetBinContent(pv.NBINS+1));signal_lt0_30->SetBinContent(pv.NBINS+1,0.);
  signal_lt0_m30->AddBinContent(pv.NBINS,signal_lt0_m30->GetBinContent(pv.NBINS+1));signal_lt0_m30->SetBinContent(pv.NBINS+1,0.);
  signal_lt0_m50->AddBinContent(pv.NBINS,signal_lt0_m50->GetBinContent(pv.NBINS+1));signal_lt0_m50->SetBinContent(pv.NBINS+1,0.);
  signal_lt0_m80->AddBinContent(pv.NBINS,signal_lt0_m80->GetBinContent(pv.NBINS+1));signal_lt0_m80->SetBinContent(pv.NBINS+1,0.);


  /////////////////////////
  // Normalize each sample:
  std::cout<<"\nScale Histograms..."<<std::endl;
  th1wwa->Scale(WWA_scale);
  th1wwa2->Scale(WWA2_scale);

  signal_lt0_m80->Scale(LT0_m8m5_scale);
  signal_lt0_m50->Scale(LT0_m5m5_scale);
  signal_lt0_m30->Scale(LT0_m3m5_scale);
  signal_lt0_30->Scale(LT0_p3m5_scale);
  signal_lt0_50->Scale(LT0_p5m5_scale);
  signal_lt0_80->Scale(LT0_p8m5_scale);


  ///////////////////////////
  // Combine certain samples:
  th1wwa->Add(th1wwa2,1);

  signal_lt0_80->Divide(th1wwa);
  signal_lt0_50->Divide(th1wwa);
  signal_lt0_30->Divide(th1wwa);
  signal_lt0_m30->Divide(th1wwa);
  signal_lt0_m50->Divide(th1wwa);
  signal_lt0_m80->Divide(th1wwa);

  ///////////////////////////
  //Fill Parabolic Histogram:
  TH1* bin_1 = new TH1D("bin_1","bin_1",17, -8.5E-11, 8.5E-11);
  TH1* bin_2 = new TH1D("bin_2","bin_2",17, -8.5E-11, 8.5E-11);
  TH1* bin_3 = new TH1D("bin_3","bin_3",17, -8.5E-11, 8.5E-11);
  TH1* bin_4 = new TH1D("bin_4","bin_4",17, -8.5E-11, 8.5E-11);
  TH1* bin_5 = new TH1D("bin_5","bin_5",17, -8.5E-11, 8.5E-11);
  TH1* bin_6 = new TH1D("bin_6","bin_6",17, -8.5E-11, 8.5E-11);
  TH1* bin_7 = new TH1D("bin_7","bin_7",17, -8.5E-11, 8.5E-11);
  TH1* bin_8 = new TH1D("bin_8","bin_8",17, -8.5E-11, 8.5E-11);
  TH1* bin_9 = new TH1D("bin_9","bin_9",17, -8.5E-11, 8.5E-11);
  TH1* bin_10 = new TH1D("bin_10","bin_10",17, -8.5E-11, 8.5E-11);


  bin_1->SetBinContent(1,signal_lt0_m80->GetBinContent(1));
  bin_1->SetBinContent(4,signal_lt0_m50->GetBinContent(1));
  bin_1->SetBinContent(6,signal_lt0_m30->GetBinContent(1));
  bin_1->SetBinContent(9,1);
  bin_1->SetBinContent(12,signal_lt0_30->GetBinContent(1));
  bin_1->SetBinContent(14,signal_lt0_50->GetBinContent(1));
  bin_1->SetBinContent(17,signal_lt0_80->GetBinContent(1));

  bin_2->SetBinContent(1,signal_lt0_m80->GetBinContent(2));
  bin_2->SetBinContent(4,signal_lt0_m50->GetBinContent(2));
  bin_2->SetBinContent(6,signal_lt0_m30->GetBinContent(2));
  bin_2->SetBinContent(9,1);
  bin_2->SetBinContent(12,signal_lt0_30->GetBinContent(2));
  bin_2->SetBinContent(14,signal_lt0_50->GetBinContent(2));
  bin_2->SetBinContent(17,signal_lt0_80->GetBinContent(2));

  bin_3->SetBinContent(1,signal_lt0_m80->GetBinContent(3));
  bin_3->SetBinContent(4,signal_lt0_m50->GetBinContent(3));
  bin_3->SetBinContent(6,signal_lt0_m30->GetBinContent(3));
  bin_3->SetBinContent(9,1);
  bin_3->SetBinContent(12,signal_lt0_30->GetBinContent(3));
  bin_3->SetBinContent(14,signal_lt0_50->GetBinContent(3));
  bin_3->SetBinContent(17,signal_lt0_80->GetBinContent(3));

  bin_4->SetBinContent(1,signal_lt0_m80->GetBinContent(4));
  bin_4->SetBinContent(4,signal_lt0_m50->GetBinContent(4));
  bin_4->SetBinContent(6,signal_lt0_m30->GetBinContent(4));
  bin_4->SetBinContent(9,1);
  bin_4->SetBinContent(12,signal_lt0_30->GetBinContent(4));
  bin_4->SetBinContent(14,signal_lt0_50->GetBinContent(4));
  bin_4->SetBinContent(17,signal_lt0_80->GetBinContent(4));

  bin_5->SetBinContent(1,signal_lt0_m80->GetBinContent(5));
  bin_5->SetBinContent(4,signal_lt0_m50->GetBinContent(5));
  bin_5->SetBinContent(6,signal_lt0_m30->GetBinContent(5));
  bin_5->SetBinContent(9,1);
  bin_5->SetBinContent(12,signal_lt0_30->GetBinContent(5));
  bin_5->SetBinContent(14,signal_lt0_50->GetBinContent(5));
  bin_5->SetBinContent(17,signal_lt0_80->GetBinContent(5));

  bin_6->SetBinContent(1,signal_lt0_m80->GetBinContent(6));
  bin_6->SetBinContent(4,signal_lt0_m50->GetBinContent(6));
  bin_6->SetBinContent(6,signal_lt0_m30->GetBinContent(6));
  bin_6->SetBinContent(9,1);
  bin_6->SetBinContent(12,signal_lt0_30->GetBinContent(6));
  bin_6->SetBinContent(14,signal_lt0_50->GetBinContent(6));
  bin_6->SetBinContent(17,signal_lt0_80->GetBinContent(6));

  bin_7->SetBinContent(1,signal_lt0_m80->GetBinContent(7));
  bin_7->SetBinContent(4,signal_lt0_m50->GetBinContent(7));
  bin_7->SetBinContent(6,signal_lt0_m30->GetBinContent(7));
  bin_7->SetBinContent(9,1);
  bin_7->SetBinContent(12,signal_lt0_30->GetBinContent(7));
  bin_7->SetBinContent(14,signal_lt0_50->GetBinContent(7));
  bin_7->SetBinContent(17,signal_lt0_80->GetBinContent(7));

  bin_8->SetBinContent(1,signal_lt0_m80->GetBinContent(8));
  bin_8->SetBinContent(4,signal_lt0_m50->GetBinContent(8));
  bin_8->SetBinContent(6,signal_lt0_m30->GetBinContent(8));
  bin_8->SetBinContent(9,1);
  bin_8->SetBinContent(12,signal_lt0_30->GetBinContent(8));
  bin_8->SetBinContent(14,signal_lt0_50->GetBinContent(8));
  bin_8->SetBinContent(17,signal_lt0_80->GetBinContent(8));

  bin_9->SetBinContent(1,signal_lt0_m80->GetBinContent(9));
  bin_9->SetBinContent(4,signal_lt0_m50->GetBinContent(9));
  bin_9->SetBinContent(6,signal_lt0_m30->GetBinContent(9));
  bin_9->SetBinContent(9,1);
  bin_9->SetBinContent(12,signal_lt0_30->GetBinContent(9));
  bin_9->SetBinContent(14,signal_lt0_50->GetBinContent(9));
  bin_9->SetBinContent(17,signal_lt0_80->GetBinContent(9));

  bin_10->SetBinContent(1,signal_lt0_m80->GetBinContent(10));
  bin_10->SetBinContent(4,signal_lt0_m50->GetBinContent(10));
  bin_10->SetBinContent(6,signal_lt0_m30->GetBinContent(10));
  bin_10->SetBinContent(9,1);
  bin_10->SetBinContent(12,signal_lt0_30->GetBinContent(10));
  bin_10->SetBinContent(14,signal_lt0_50->GetBinContent(10));
  bin_10->SetBinContent(17,signal_lt0_80->GetBinContent(10));


  ////////////////
  // Fit function:
  Char_t para_fit[] = "[0]+[1]*x+[2]*x^2";
  Char_t fitopt[] = "QMR";
  Double_t xmin = -8E-5;
  Double_t xmax = 8E-5;
  Double_t p[3][10];
  TF1 *pfit = new TF1("pfit",para_fit,xmin,xmax);
//  pfit->SetParLimits(1,0.0,1E15);
//  pfit->FixParameter(0,0.0);


  /////////////////
  // Fit histogram:
  bin_1->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][0] = pfit->GetParameter(0);
  p[1][0] = pfit->GetParameter(1);
  p[2][0] = pfit->GetParameter(2);

  bin_2->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][1] = pfit->GetParameter(0);
  p[1][1] = pfit->GetParameter(1);
  p[2][1] = pfit->GetParameter(2);

  bin_3->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][2] = pfit->GetParameter(0);
  p[1][2] = pfit->GetParameter(1);
  p[2][2] = pfit->GetParameter(2);

  bin_4->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][3] = pfit->GetParameter(0);
  p[1][3] = pfit->GetParameter(1);
  p[2][3] = pfit->GetParameter(2);

  bin_5->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][4] = pfit->GetParameter(0);
  p[1][4] = pfit->GetParameter(1);
  p[2][4] = pfit->GetParameter(2);

  bin_6->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][5] = pfit->GetParameter(0);
  p[1][5] = pfit->GetParameter(1);
  p[2][5] = pfit->GetParameter(2);

  bin_7->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][6] = pfit->GetParameter(0);
  p[1][6] = pfit->GetParameter(1);
  p[2][6] = pfit->GetParameter(2);

  bin_8->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][7] = pfit->GetParameter(0);
  p[1][7] = pfit->GetParameter(1);
  p[2][7] = pfit->GetParameter(2);

  bin_9->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][8] = pfit->GetParameter(0);
  p[1][8] = pfit->GetParameter(1);
  p[2][8] = pfit->GetParameter(2);

  bin_10->Fit(pfit,fitopt,"sames",xmin,xmax);
  p[0][9] = pfit->GetParameter(0);
  p[1][9] = pfit->GetParameter(1);
  p[2][9] = pfit->GetParameter(2);


  /////////////////////////////
  // Fill parameter histograms:
  TH1* p0 = new TH1D("p0","Parameter 0",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* p1 = new TH1D("p1","Parameter 1",pv.NBINS,pv.MINRange,pv.MAXRange);

  for(Int_t i=1;i<=pv.NBINS;i++){
     p0->SetBinContent(i,p[0][i-1]);
     p1->SetBinContent(i,p[1][i-1]);
  }

/*
  ///////////////////
  // Fit pT-function:
  Char_t pt_fit[] = "[0]+[1]*x+[2]*x^2";
  Char_t fitopt[] = "QMR";
  Double_t xmin = 150;//45;
  Double_t xmax = 1050;//275;
  Double_t pt[2][3];
  TF1 *ptfit = new TF1("ptfit",pt_fit,xmin,xmax);

  p0->Fit(ptfit,fitopt,"sames",xmin,xmax);
  pt[0][0] = ptfit->GetParameter(0);
  pt[0][1] = ptfit->GetParameter(1);
  pt[0][2] = ptfit->GetParameter(2);

  p1->Fit(ptfit,fitopt,"sames",xmin,xmax);
  pt[1][0] = ptfit->GetParameter(0);
  pt[1][1] = ptfit->GetParameter(1);
  pt[1][2] = ptfit->GetParameter(2);
*/

  ////////////////
  // Closure test:
  // ratio = 1 + (pt[0][0]+pt[0][1]*pt+pt[0][2]*pt^2)*KOW + (pt[1][0]+pt[1][1]*pt+[1][2]*pt^2)*KOW^2
  TH1* test = new TH1D("test","Test aQGC Photon ET",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* test2 = new TH1D("test2","Test aQGC Photon ET",pv.NBINS,pv.MINRange,pv.MAXRange);

  for(Int_t j=1;j<=pv.NBINS;j++){

     Double_t value,bincent;
     TAxis* xaxis = test->GetXaxis();
     bincent = xaxis->GetBinCenter(j);

     value = p[0][j-1]+p[1][j-1]*(8E-11)+p[2][j-1]*pow(8E-11,2);
     test->SetBinContent(j,value);

     test2->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-8E-11)+p[2][j-1]*pow(-8E-11,2));

  }

//  test->SetBinContent(8,1+p[0][7]*(8E-11)+p[1][7]*pow(8E-11,2));
//  test2->SetBinContent(8,1+p[0][7]*(-8E-11)+p[1][7]*pow(-8E-11,2));

  TH1D* test_r = (TH1D*)test->Clone("test_r");
  TH1D* test2_r = (TH1D*)test2->Clone("test2_r");

  test_r->Divide(signal_lt0_80);
  test2_r->Divide(signal_lt0_m80);

  test->Multiply(th1wwa);
  test2->Multiply(th1wwa);
  test->Add(th1wwa,-1);
  test2->Add(th1wwa,-1);


  /////////////////////
  // Simulate new aQGC:
  TH1* signal_lt0_18 = new TH1D("signal_lt0_18","signal_lt0_1p8",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_20 = new TH1D("signal_lt0_20","signal_lt0_2p0",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_22 = new TH1D("signal_lt0_22","signal_lt0_2p2",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_24 = new TH1D("signal_lt0_24","signal_lt0_2p4",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_26 = new TH1D("signal_lt0_26","signal_lt0_2p6",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_28 = new TH1D("signal_lt0_28","signal_lt0_2p8",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_32 = new TH1D("signal_lt0_32","signal_lt0_3p2",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_34 = new TH1D("signal_lt0_34","signal_lt0_3p4",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_36 = new TH1D("signal_lt0_36","signal_lt0_3p6",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_38 = new TH1D("signal_lt0_38","signal_lt0_3p8",pv.NBINS,pv.MINRange,pv.MAXRange);

  TH1* signal_lt0_m18 = new TH1D("signal_lt0_m18","signal_lt0_-1p8",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m20 = new TH1D("signal_lt0_m20","signal_lt0_-2p0",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m22 = new TH1D("signal_lt0_m22","signal_lt0_-2p2",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m24 = new TH1D("signal_lt0_m24","signal_lt0_-2p4",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m26 = new TH1D("signal_lt0_m26","signal_lt0_-2p6",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m28 = new TH1D("signal_lt0_m28","signal_lt0_-2p8",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m32 = new TH1D("signal_lt0_m32","signal_lt0_-3p2",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m34 = new TH1D("signal_lt0_m34","signal_lt0_-3p4",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m36 = new TH1D("signal_lt0_m36","signal_lt0_-3p6",pv.NBINS,pv.MINRange,pv.MAXRange);
  TH1* signal_lt0_m38 = new TH1D("signal_lt0_m38","signal_lt0_-3p8",pv.NBINS,pv.MINRange,pv.MAXRange);


  signal_lt0_18->Sumw2();
  signal_lt0_20->Sumw2();
  signal_lt0_22->Sumw2();
  signal_lt0_24->Sumw2();
  signal_lt0_26->Sumw2();
  signal_lt0_28->Sumw2();
  signal_lt0_32->Sumw2();
  signal_lt0_34->Sumw2();
  signal_lt0_36->Sumw2();
  signal_lt0_38->Sumw2();
  signal_lt0_m18->Sumw2();
  signal_lt0_m20->Sumw2();
  signal_lt0_m22->Sumw2();
  signal_lt0_m24->Sumw2();
  signal_lt0_m26->Sumw2();
  signal_lt0_m28->Sumw2();
  signal_lt0_m32->Sumw2();
  signal_lt0_m34->Sumw2();
  signal_lt0_m36->Sumw2();
  signal_lt0_m38->Sumw2();

  for(Int_t j=1;j<=pv.NBINS;j++){

     Double_t bincent;
     TAxis* xaxis = test->GetXaxis();
     bincent = xaxis->GetBinCenter(j);

     signal_lt0_m50->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-5.E-11)+p[2][j-1]*pow(-5.E-11,2));
     signal_lt0_m30->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.E-11)+p[2][j-1]*pow(-3.E-11,2));
     signal_lt0_m80->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-8.E-11)+p[2][j-1]*pow(-8.E-11,2));

     signal_lt0_m28->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.8E-11)+p[2][j-1]*pow(-2.8E-11,2));
     signal_lt0_m26->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.6E-11)+p[2][j-1]*pow(-2.6E-11,2));
     signal_lt0_m24->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.4E-11)+p[2][j-1]*pow(-2.4E-11,2));
     signal_lt0_m22->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.2E-11)+p[2][j-1]*pow(-2.2E-11,2));
     signal_lt0_m20->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-2.E-11)+p[2][j-1]*pow(-2.E-11,2));
     signal_lt0_m18->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-1.8E-11)+p[2][j-1]*pow(-1.8E-11,2));
     signal_lt0_m32->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.2E-11)+p[2][j-1]*pow(-3.2E-11,2));
     signal_lt0_m34->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.4E-11)+p[2][j-1]*pow(-3.4E-11,2));
     signal_lt0_m36->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.6E-11)+p[2][j-1]*pow(-3.6E-11,2));
     signal_lt0_m38->SetBinContent(j,p[0][j-1]+p[1][j-1]*(-3.8E-11)+p[2][j-1]*pow(-3.8E-11,2));

     signal_lt0_50->SetBinContent(j,p[0][j-1]+p[1][j-1]*(5.E-11)+p[2][j-1]*pow(5.E-11,2));
     signal_lt0_30->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.E-11)+p[2][j-1]*pow(3.E-11,2));
     signal_lt0_80->SetBinContent(j,p[0][j-1]+p[1][j-1]*(8.E-11)+p[2][j-1]*pow(8.E-11,2));

     signal_lt0_28->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.8E-11)+p[2][j-1]*pow(2.8E-11,2));
     signal_lt0_26->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.6E-11)+p[2][j-1]*pow(2.6E-11,2));
     signal_lt0_24->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.4E-11)+p[2][j-1]*pow(2.4E-11,2));
     signal_lt0_22->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.2E-11)+p[2][j-1]*pow(2.2E-11,2));
     signal_lt0_20->SetBinContent(j,p[0][j-1]+p[1][j-1]*(2.E-11)+p[2][j-1]*pow(2.E-11,2));
     signal_lt0_18->SetBinContent(j,p[0][j-1]+p[1][j-1]*(1.8E-11)+p[2][j-1]*pow(1.8E-11,2));
     signal_lt0_32->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.2E-11)+p[2][j-1]*pow(3.2E-11,2));
     signal_lt0_34->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.4E-11)+p[2][j-1]*pow(3.4E-11,2));
     signal_lt0_36->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.6E-11)+p[2][j-1]*pow(3.6E-11,2));
     signal_lt0_38->SetBinContent(j,p[0][j-1]+p[1][j-1]*(3.8E-11)+p[2][j-1]*pow(3.8E-11,2));

  }
/*
  signal_lt0_m50->SetBinContent(8,1+p[0][7]*(-5.E-11)+p[1][7]*pow(-5.E-11,2));
  signal_lt0_m30->SetBinContent(8,1+p[0][7]*(-3.E-11)+p[1][7]*pow(-3.E-11,2));
  signal_lt0_m80->SetBinContent(8,1+p[0][7]*(-8.E-11)+p[1][7]*pow(-8.E-11,2));

  signal_lt0_m28->SetBinContent(8,1+p[0][7]*(-2.8E-11)+p[1][7]*pow(-2.8E-11,2));
  signal_lt0_m26->SetBinContent(8,1+p[0][7]*(-2.6E-11)+p[1][7]*pow(-2.6E-11,2));
  signal_lt0_m24->SetBinContent(8,1+p[0][7]*(-2.4E-11)+p[1][7]*pow(-2.4E-11,2));
  signal_lt0_m22->SetBinContent(8,1+p[0][7]*(-2.2E-11)+p[1][7]*pow(-2.2E-11,2));
  signal_lt0_m20->SetBinContent(8,1+p[0][7]*(-2.E-11)+p[1][7]*pow(-2.E-11,2));
  signal_lt0_m18->SetBinContent(8,1+p[0][7]*(-1.8E-11)+p[1][7]*pow(-1.8E-11,2));
  signal_lt0_m32->SetBinContent(8,1+p[0][7]*(-3.2E-11)+p[1][7]*pow(-3.2E-11,2));
  signal_lt0_m34->SetBinContent(8,1+p[0][7]*(-3.4E-11)+p[1][7]*pow(-3.4E-11,2));
  signal_lt0_m36->SetBinContent(8,1+p[0][7]*(-3.6E-11)+p[1][7]*pow(-3.6E-11,2));
  signal_lt0_m38->SetBinContent(8,1+p[0][7]*(-3.8E-11)+p[1][7]*pow(-3.8E-11,2));

  signal_lt0_50->SetBinContent(8,1+p[0][7]*(5.E-11)+p[1][7]*pow(5.E-11,2));
  signal_lt0_30->SetBinContent(8,1+p[0][7]*(3.E-11)+p[1][7]*pow(3.E-11,2));
  signal_lt0_80->SetBinContent(8,1+p[0][7]*(8.E-11)+p[1][7]*pow(8.E-11,2));

  signal_lt0_28->SetBinContent(8,1+p[0][7]*(2.8E-11)+p[1][7]*pow(2.8E-11,2));
  signal_lt0_26->SetBinContent(8,1+p[0][7]*(2.6E-11)+p[1][7]*pow(2.6E-11,2));
  signal_lt0_24->SetBinContent(8,1+p[0][7]*(2.4E-11)+p[1][7]*pow(2.4E-11,2));
  signal_lt0_22->SetBinContent(8,1+p[0][7]*(2.2E-11)+p[1][7]*pow(2.2E-11,2));
  signal_lt0_20->SetBinContent(8,1+p[0][7]*(2.E-11)+p[1][7]*pow(2.E-11,2));
  signal_lt0_18->SetBinContent(8,1+p[0][7]*(1.8E-11)+p[1][7]*pow(1.8E-11,2));
  signal_lt0_32->SetBinContent(8,1+p[0][7]*(3.2E-11)+p[1][7]*pow(3.2E-11,2));
  signal_lt0_34->SetBinContent(8,1+p[0][7]*(3.4E-11)+p[1][7]*pow(3.4E-11,2));
  signal_lt0_36->SetBinContent(8,1+p[0][7]*(3.6E-11)+p[1][7]*pow(3.6E-11,2));
  signal_lt0_38->SetBinContent(8,1+p[0][7]*(3.8E-11)+p[1][7]*pow(3.8E-11,2));
*/
  signal_lt0_m50->Multiply(th1wwa);
  signal_lt0_m30->Multiply(th1wwa);
  signal_lt0_m80->Multiply(th1wwa);

  signal_lt0_m28->Multiply(th1wwa);
  signal_lt0_m26->Multiply(th1wwa);
  signal_lt0_m24->Multiply(th1wwa);
  signal_lt0_m22->Multiply(th1wwa);
  signal_lt0_m20->Multiply(th1wwa);
  signal_lt0_m18->Multiply(th1wwa);
  signal_lt0_m32->Multiply(th1wwa);
  signal_lt0_m34->Multiply(th1wwa);
  signal_lt0_m36->Multiply(th1wwa);
  signal_lt0_m38->Multiply(th1wwa);

  signal_lt0_50->Multiply(th1wwa);
  signal_lt0_30->Multiply(th1wwa);
  signal_lt0_80->Multiply(th1wwa);

  signal_lt0_28->Multiply(th1wwa);
  signal_lt0_26->Multiply(th1wwa);
  signal_lt0_24->Multiply(th1wwa);
  signal_lt0_22->Multiply(th1wwa);
  signal_lt0_20->Multiply(th1wwa);
  signal_lt0_18->Multiply(th1wwa);
  signal_lt0_32->Multiply(th1wwa);
  signal_lt0_34->Multiply(th1wwa);
  signal_lt0_36->Multiply(th1wwa);
  signal_lt0_38->Multiply(th1wwa);

  signal_lt0_m50->Add(th1wwa,-1);
  signal_lt0_m30->Add(th1wwa,-1);
  signal_lt0_m80->Add(th1wwa,-1);

  signal_lt0_m28->Add(th1wwa,-1);
  signal_lt0_m26->Add(th1wwa,-1);
  signal_lt0_m24->Add(th1wwa,-1);
  signal_lt0_m22->Add(th1wwa,-1);
  signal_lt0_m20->Add(th1wwa,-1);
  signal_lt0_m18->Add(th1wwa,-1);
  signal_lt0_m32->Add(th1wwa,-1);
  signal_lt0_m34->Add(th1wwa,-1);
  signal_lt0_m36->Add(th1wwa,-1);
  signal_lt0_m38->Add(th1wwa,-1);

  signal_lt0_50->Add(th1wwa,-1);
  signal_lt0_30->Add(th1wwa,-1);
  signal_lt0_80->Add(th1wwa,-1);

  signal_lt0_28->Add(th1wwa,-1);
  signal_lt0_26->Add(th1wwa,-1);
  signal_lt0_24->Add(th1wwa,-1);
  signal_lt0_22->Add(th1wwa,-1);
  signal_lt0_20->Add(th1wwa,-1);
  signal_lt0_18->Add(th1wwa,-1);
  signal_lt0_32->Add(th1wwa,-1);
  signal_lt0_34->Add(th1wwa,-1);
  signal_lt0_36->Add(th1wwa,-1);
  signal_lt0_38->Add(th1wwa,-1);


  signal_lt0_m50->Scale(1.185/2.1);
  signal_lt0_m30->Scale(1.185/2.1);
  signal_lt0_m80->Scale(1.185/2.1);

  signal_lt0_m28->Scale(1.185/2.1);
  signal_lt0_m26->Scale(1.185/2.1);
  signal_lt0_m24->Scale(1.185/2.1);
  signal_lt0_m22->Scale(1.185/2.1);
  signal_lt0_m20->Scale(1.185/2.1);
  signal_lt0_m18->Scale(1.185/2.1);
  signal_lt0_m32->Scale(1.185/2.1);
  signal_lt0_m34->Scale(1.185/2.1);
  signal_lt0_m36->Scale(1.185/2.1);
  signal_lt0_m38->Scale(1.185/2.1);

  signal_lt0_50->Scale(1.185/2.1);
  signal_lt0_30->Scale(1.185/2.1);
  signal_lt0_80->Scale(1.185/2.1);

  signal_lt0_28->Scale(1.185/2.1);
  signal_lt0_26->Scale(1.185/2.1);
  signal_lt0_24->Scale(1.185/2.1);
  signal_lt0_22->Scale(1.185/2.1);
  signal_lt0_20->Scale(1.185/2.1);
  signal_lt0_18->Scale(1.185/2.1);
  signal_lt0_32->Scale(1.185/2.1);
  signal_lt0_34->Scale(1.185/2.1);
  signal_lt0_36->Scale(1.185/2.1);
  signal_lt0_38->Scale(1.185/2.1);

/*
  signal_lt0_18->Sumw2();
  signal_lt0_20->Sumw2();
  signal_lt0_22->Sumw2();
  signal_lt0_24->Sumw2();
  signal_lt0_26->Sumw2();
  signal_lt0_28->Sumw2();
  signal_lt0_30->Sumw2();
  signal_lt0_32->Sumw2();
  signal_lt0_34->Sumw2();
  signal_lt0_36->Sumw2();
  signal_lt0_38->Sumw2();
  signal_lt0_50->Sumw2();
  signal_lt0_80->Sumw2();

  signal_lt0_m18->Sumw2();
  signal_lt0_m20->Sumw2();
  signal_lt0_m22->Sumw2();
  signal_lt0_m24->Sumw2();
  signal_lt0_m26->Sumw2();
  signal_lt0_m28->Sumw2();
  signal_lt0_m30->Sumw2();
  signal_lt0_m32->Sumw2();
  signal_lt0_m34->Sumw2();
  signal_lt0_m36->Sumw2();
  signal_lt0_m38->Sumw2();
  signal_lt0_m50->Sumw2();
  signal_lt0_m80->Sumw2();
*/

/*  // Adding 35% Signal K-factor Systematic uncertainty
  for(int hi=1;hi<=pv.NBINS;hi++){

     fperr = pow(signal_lt0_m18->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m18->GetBinContent(hi),2);
     signal_lt0_m18->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m20->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m20->GetBinContent(hi),2);
     signal_lt0_m20->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m22->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m22->GetBinContent(hi),2);
     signal_lt0_m22->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m24->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m24->GetBinContent(hi),2);
     signal_lt0_m24->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m26->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m26->GetBinContent(hi),2);
     signal_lt0_m26->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m28->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m28->GetBinContent(hi),2);
     signal_lt0_m28->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m30->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m30->GetBinContent(hi),2);
     signal_lt0_m30->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m32->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m32->GetBinContent(hi),2);
     signal_lt0_m32->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m34->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m34->GetBinContent(hi),2);
     signal_lt0_m34->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m36->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m36->GetBinContent(hi),2);
     signal_lt0_m36->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m38->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m38->GetBinContent(hi),2);
     signal_lt0_m38->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m50->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m50->GetBinContent(hi),2);
     signal_lt0_m50->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_m80->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_m80->GetBinContent(hi),2);
     signal_lt0_m80->SetBinError(hi,sqrt(fperr));


     fperr = pow(signal_lt0_18->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_18->GetBinContent(hi),2);
     signal_lt0_18->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_20->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_20->GetBinContent(hi),2);
     signal_lt0_20->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_22->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_22->GetBinContent(hi),2);
     signal_lt0_22->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_24->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_24->GetBinContent(hi),2);
     signal_lt0_24->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_26->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_26->GetBinContent(hi),2);
     signal_lt0_26->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_28->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_28->GetBinContent(hi),2);
     signal_lt0_28->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_30->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_30->GetBinContent(hi),2);
     signal_lt0_30->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_32->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_32->GetBinContent(hi),2);
     signal_lt0_32->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_34->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_34->GetBinContent(hi),2);
     signal_lt0_34->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_36->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_36->GetBinContent(hi),2);
     signal_lt0_36->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_38->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_38->GetBinContent(hi),2);
     signal_lt0_38->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_50->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_50->GetBinContent(hi),2);
     signal_lt0_50->SetBinError(hi,sqrt(fperr));

     fperr = pow(signal_lt0_80->GetBinError(hi),2);
     fperr += pow(0.28,2)*pow(signal_lt0_80->GetBinContent(hi),2);
     signal_lt0_80->SetBinError(hi,sqrt(fperr));

  }
*/

  ////////////////////////
  // Set histogram labels:
  const double BINWIDTH = ((pv.MAXRange-pv.MINRange)/pv.NBINS);
  char tmpc[100];    sprintf(tmpc,"Events / %.1f GeV",BINWIDTH);
  if (pv.slog==1)    sprintf(tmpc,"Events / %.1f",BINWIDTH);
  if (pv.slog==2)    sprintf(tmpc,"Events / %.2f",BINWIDTH);
  if (pv.slog==3)    sprintf(tmpc,"Events / %.0f GeV",BINWIDTH);
  if (pv.slog==6)    sprintf(tmpc,"Events / %.2f rad",BINWIDTH);

  signal_lt0_80->SetYTitle(tmpc);
  signal_lt0_80->GetXaxis()->SetTitle(pv.xlabel);
  signal_lt0_80->GetYaxis()->CenterTitle(true);

  signal_lt0_50->SetYTitle(tmpc);
  signal_lt0_50->GetXaxis()->SetTitle(pv.xlabel);
  signal_lt0_50->GetYaxis()->CenterTitle(true);

  signal_lt0_30->SetYTitle(tmpc);
  signal_lt0_30->GetXaxis()->SetTitle(pv.xlabel);
  signal_lt0_30->GetYaxis()->CenterTitle(true);

  signal_lt0_m30->SetYTitle(tmpc);
  signal_lt0_m30->GetXaxis()->SetTitle(pv.xlabel);
  signal_lt0_m30->GetYaxis()->CenterTitle(true);

  signal_lt0_m50->SetYTitle(tmpc);
  signal_lt0_m50->GetXaxis()->SetTitle(pv.xlabel);
  signal_lt0_m50->GetYaxis()->CenterTitle(true);

  signal_lt0_m80->SetYTitle(tmpc);
  signal_lt0_m80->GetXaxis()->SetTitle(pv.xlabel);
  signal_lt0_m80->GetYaxis()->CenterTitle(true);


  //////////////////////////////////////////////////////////
  // Save Observed Data, Background (+ SM WWA), Background +
  // Uncertainty, Background - Uncertainty, Anomalous Signal
  // histograms to output ROOT file:
  std::cout<<"Save Histograms..."<<std::endl;
  f.cd();
  signal_lt0_80->Write();
  signal_lt0_50->Write();
  signal_lt0_30->Write();
  signal_lt0_m30->Write();
  signal_lt0_m50->Write();
  signal_lt0_m80->Write();

  bin_1->Write();
  bin_2->Write();
  bin_3->Write();
  bin_4->Write();
  bin_5->Write();
  bin_6->Write();
  bin_7->Write();
  bin_8->Write();
  bin_9->Write();
  bin_10->Write();

  p0->Write();
  p1->Write();
  test->Write();
  test2->Write();
  test_r->Write();
  test2_r->Write();

  signal_lt0_m28->Write();
  signal_lt0_m26->Write();
  signal_lt0_m24->Write();
  signal_lt0_m22->Write();
  signal_lt0_m20->Write();
  signal_lt0_m18->Write();
  signal_lt0_m32->Write();
  signal_lt0_m34->Write();
  signal_lt0_m36->Write();
  signal_lt0_m38->Write();

  signal_lt0_28->Write();
  signal_lt0_26->Write();
  signal_lt0_24->Write();
  signal_lt0_22->Write();
  signal_lt0_20->Write();
  signal_lt0_18->Write();
  signal_lt0_32->Write();
  signal_lt0_34->Write();
  signal_lt0_36->Write();
  signal_lt0_38->Write();

  //For conveners
//  th1wwa->Write();

  //
}// End Main function
Пример #14
0
void Wpt_PASformat_withRatio(const TString  outputDir,   // output directory
           const TString  filetype,		// Select input root files for Nominal, Up, Down and Before Recoil Correction
           const Double_t lumi,        // integrated luminosity (/fb)
	   const Double_t nsigma=0     // vary MET corrections by n-sigmas (nsigma=0 means nominal correction)
)
{
  gBenchmark->Start("Wpt_PASformat_withRatio");

  //==================   
  // Settings 
  //==================   
  
  //const TString format("png"); 
  const TString format("pdf"); 
  //const TString format("root"); 

  // input ntuple file names
  TString fname = "MuonFitResultsModRayleighSimultNominal/RstMuon/SigYields_Nominal.root";
  if (filetype == "Electron")
    fname = "ElectronFitResultsModRayleighSimultNominal/RstElectron/SigYields_Nominal.root";

  TFile* infile = new TFile(fname);

  //-------------------------
  // Main analysis code 
  //=========================  
  
  // Create output directory
  gSystem->mkdir(outputDir,kTRUE);
  CPlot::sOutDir = outputDir;  
  cout << "check 1" << endl; 
  //
  // Declare MET histograms
  // 0 is for total

  TH1D *hdataWPpt;
  TH1D *hdataWMpt;
  TH1D *hSigWPpt;
  TH1D *hSigWMpt;
  TH1D *hQCDWPpt;
  TH1D *hQCDWMpt;
  TH1D *hDYToMuMuP;
  TH1D *hDYToMuMuM;
  TH1D *hWToTauNuP;
  TH1D *hWToTauNuM;
  TH1D *hTTJetsP;
  TH1D *hTTJetsM;
  TH1D *hDYToTauTauP;
  TH1D *hDYToTauTauM;

  // To get error from fit
  TH1D *hFitErrorP;
  TH1D *hFitErrorM;


  char histName[30],histName_org[30];

  cout << "check 2" << endl; 
  hdataWPpt    = (TH1D*)infile->Get("hdataWPpt")    -> Clone("hdataWPpt");
  cout << "check 3" << endl; 
  hdataWMpt    = (TH1D*)infile->Get("hdataWMpt")    -> Clone("hdataWMpt");
  hSigWPpt     = (TH1D*)infile->Get("hSigWPpt")     -> Clone("hSigWPpt");
  hSigWMpt     = (TH1D*)infile->Get("hSigWMpt")     -> Clone("hSigWMpt");
  hQCDWPpt     = (TH1D*)infile->Get("hQCDWPpt")     -> Clone("hQCDWPpt");
  hQCDWMpt     = (TH1D*)infile->Get("hQCDWMpt")     -> Clone("hQCDWMpt");
  hDYToMuMuP   = (TH1D*)infile->Get("hDYToMuMuP")   -> Clone("hDYToMuMuP");
  hDYToMuMuM   = (TH1D*)infile->Get("hDYToMuMuM")   -> Clone("hDYToMuMuM");
  hWToTauNuP   = (TH1D*)infile->Get("hWToTauNuP")   -> Clone("hWToTauNuP");
  hWToTauNuM   = (TH1D*)infile->Get("hWToTauNuM")   -> Clone("hWToTauNuM");
  hTTJetsP     = (TH1D*)infile->Get("hTTJetsP")     -> Clone("hTTJetsP");
  hTTJetsM     = (TH1D*)infile->Get("hTTJetsM")     -> Clone("hTTJetsM");
  hDYToTauTauP = (TH1D*)infile->Get("hDYToTauTauP") -> Clone("hDYToTauTauP");
  hDYToTauTauM = (TH1D*)infile->Get("hDYToTauTauM") -> Clone("hDYToTauTauM");

  //To get error from fit
  hFitErrorP      = (TH1D*)infile->Get("hWPptMCLog")   -> Clone("hFitErrorP");
  hFitErrorM      = (TH1D*)infile->Get("hWMptMCLog")   -> Clone("hFitErrorM");


  TCanvas *c;
  c = MakeCanvas("c","c",800,800);
  c->Divide(1,2,0,0);
  c->cd(1)->SetPad(0,0.3,1.0,1.0);
  c->cd(1)->SetTopMargin(0.1);
  //c->cd(1)->SetBottomMargin(0.01);
  c->cd(1)->SetBottomMargin(0.02);
  c->cd(1)->SetLeftMargin(0.15);
  c->cd(1)->SetRightMargin(0.07);
  c->cd(1)->SetTickx(1);
  c->cd(1)->SetTicky(1);
  c->cd(2)->SetPad(0,0,1.0,0.3);
  //c->cd(2)->SetTopMargin(0.05);
  c->cd(2)->SetTopMargin(0.07);
  c->cd(2)->SetBottomMargin(0.45);
  c->cd(2)->SetLeftMargin(0.15);
  c->cd(2)->SetRightMargin(0.07);
  c->cd(2)->SetTickx(1);
  c->cd(2)->SetTicky(1); 
  
//  c->SetPad(0,0,1.0,1.0);
//  c->SetTopMargin(0.1);
//  c->SetBottomMargin(0.15);
//  c->SetLeftMargin(0.15);  
//  c->SetRightMargin(0.07);  
//  c->SetTickx(1);
//  c->SetTicky(1);  
  gStyle->SetTitleOffset(1.400,"Y");
  TGaxis::SetMaxDigits(3);
  char ylabel[100];  // string buffer for y-axis label
  // label for lumi
  char lumitext[100];
  if(lumi<0.1) sprintf(lumitext,"%.1f pb^{-1} (8 TeV)",lumi*1000.);
  else         sprintf(lumitext,"%.2f fb^{-1}  at  #sqrt{s} = 8 TeV",lumi);
  char CMStext[100];
  sprintf(CMStext,"#font[61]{CMS}");
  char Preliminarytext[100];
  sprintf(Preliminarytext,"#font[52]{Preliminary}");
  char binlabel[50];
  
  // plot colors
  Int_t linecolorW   = kOrange-3;
  Int_t fillcolorW   = kOrange-2;
  Int_t linecolorEWK = kOrange+10;
  Int_t fillcolorEWK = kOrange+7;
  Int_t linecolorQCD = kViolet+2;
  Int_t fillcolorQCD = kViolet-5;

  //
  // Dummy histograms for TLegend
  // (I can't figure out how to properly pass RooFit objects...)
  //
  TH1D *hDummyData = new TH1D("hDummyData","",0,0,10);
  hDummyData->SetMarkerStyle(kFullCircle);
  hDummyData->SetMarkerSize(0.9);
  
  TH1D *hDummyW = new TH1D("hDummyW","",0,0,10);
  hDummyW->SetLineColor(linecolorW);
  hDummyW->SetFillColor(fillcolorW);
  hDummyW->SetFillStyle(1001);
  
  TH1D *hDummyEWK = new TH1D("hDummyEWK","",0,0,10);
  hDummyEWK->SetLineColor(linecolorEWK);
  hDummyEWK->SetFillColor(fillcolorEWK);
  hDummyEWK->SetFillStyle(1001);
  
  TH1D *hDummyQCD = new TH1D("hDummyQCD","",0,0,10);
  hDummyQCD->SetLineColor(linecolorQCD);
  hDummyQCD->SetFillColor(fillcolorQCD);
  hDummyQCD->SetFillStyle(1001);

// Wpt distribution=========================
  CPlot* plotWPptLog;
  CPlot* plotWPptDiffLog;
  CPlot* plotWMptLog;
  CPlot* plotWMptDiffLog;

//W plus pt distribution
  TH1D* hWptMC_p = (TH1D*)hDYToTauTauP->Clone("hWptMC_p");
  hWptMC_p->Add(hTTJetsP);
  hWptMC_p->Add(hWToTauNuP);
  hWptMC_p->Add(hDYToMuMuP);
  hWptMC_p->Add(hQCDWPpt);
  hWptMC_p->Add(hSigWPpt);
 
  TH1D* hWPptDiffLog;
  TH1D* hWMptDiffLog;

  //double WptBinsLog[14]={1,7.5,12.5,17.5,24,30,40,50,70,110,150,190,250,600};
  double WptBinsLog[14]={0.68,7.5,12.5,17.5,24,30,40,50,70,110,150,190,250,600};
  double x1,x2,x3,x4,x5,x6,x7,err;
  TH1D *hDYToTauTauLogP = new TH1D("hDYToTauTauLogP","",13,WptBinsLog);
  TH1D *hTTJetsLogP     = new TH1D("hTTJetsLogP","",13,WptBinsLog);
  TH1D *hWToTauNuLogP   = new TH1D("hWToTauNuLogP","",13,WptBinsLog);
  TH1D *hDYToMuMuLogP   = new TH1D("hDYToMuMuLogP","",13,WptBinsLog);
  TH1D *hQCDWptLogP     = new TH1D("hQCDWptLogP","",13,WptBinsLog);
  TH1D *hSigWptLogP     = new TH1D("hSigWptLogP","",13,WptBinsLog);
  TH1D *hdataWptLogP    = new TH1D("hdataWptLogP","",13,WptBinsLog);
  TAxis *xaxis = hSigWPpt->GetXaxis();
  for (int i=1; i<=hSigWPpt->GetNbinsX(); i++){
    x1=hDYToTauTauP->GetBinContent(i);
    x2=hTTJetsP->GetBinContent(i);
    x3=hWToTauNuP->GetBinContent(i);
    x4=hDYToMuMuP->GetBinContent(i);
    x5=hQCDWPpt->GetBinContent(i);
    x6=hSigWPpt->GetBinContent(i);
    x7=hdataWPpt->GetBinContent(i);
    err = hdataWPpt->GetBinError(i);
    hDYToTauTauLogP->Fill(xaxis->GetBinCenter(i),x1);
    hTTJetsLogP->Fill(xaxis->GetBinCenter(i),x2);
    hWToTauNuLogP->Fill(xaxis->GetBinCenter(i),x3);
    hDYToMuMuLogP->Fill(xaxis->GetBinCenter(i),x4);
    hQCDWptLogP->Fill(xaxis->GetBinCenter(i),x5);
    hSigWptLogP->Fill(xaxis->GetBinCenter(i),x6);
    hdataWptLogP->Fill(xaxis->GetBinCenter(i),x7);
    hdataWptLogP->SetBinError(i,err);
  }
  
  TH1D* hEwkWPptLog = (TH1D*)hDYToTauTauLogP->Clone("hEwkWPptLog");
  hEwkWPptLog->Add(hTTJetsLogP);
  hEwkWPptLog->Add(hWToTauNuLogP);
  hEwkWPptLog->Add(hDYToMuMuLogP);
  
  TString plotName = "FitWDistribution_MuonPLog";
  if (filetype == "Electron")
    plotName = "FitWDistribution_ElePLog";
  plotWPptLog=new CPlot(plotName,"","p_{T}^{W} [GeV]","Events");
  plotWPptLog->setOutDir(CPlot::sOutDir);
  plotWPptLog->AddHist1D(hdataWptLogP,"#font[42]{Data}","E");
  plotWPptLog->AddToStack(hEwkWPptLog,"#font[42]{EW+t#bar{t}}",fillcolorEWK,linecolorEWK);
  plotWPptLog->AddToStack(hQCDWptLogP,"#font[42]{QCD}",fillcolorQCD,linecolorQCD);
  if(filetype == "Muon")
    plotWPptLog->AddToStack(hSigWptLogP,"#font[42]{W^{+}#rightarrow #mu^{+}#nu}",fillcolorW,linecolorW);
  if(filetype == "Electron")
    plotWPptLog->AddToStack(hSigWptLogP,"#font[42]{W^{+}#rightarrow e^{+}#nu}",fillcolorW,linecolorW);
  plotWPptLog->SetLegend(0.67,0.70,.98,0.88);
  //plotWPptLog->SetYRange(0.25,1.4*(hWptMC_p->GetMaximum()));
  plotWPptLog->SetYRange(1,50*(hWptMC_p->GetMaximum()));
  plotWPptLog->SetLogx();
  plotWPptLog->SetLogy();
  plotWPptLog->AddTextBox(CMStext,0.14,0.90,0.24,0.97,0);
  plotWPptLog->AddTextBox(lumitext,0.65,0.90,0.95,0.97,0);
  plotWPptLog->Draw(c,kFALSE,format,1);
  gPad->RedrawAxis();

  // Pull distribution (Ratio)
  TH1D* hWPptMCLog = (TH1D*)hEwkWPptLog->Clone("hWPptMCLog");
  hWPptMCLog->Add(hQCDWptLogP);
  hWPptMCLog->Add(hSigWptLogP);

  //hWPptDiffLog = makeDiffHistWptLog(hdataWptLogP,hWPptMCLog,"hWPptDiffLog");
  hWPptDiffLog = makeDiffHistWptLog(hdataWptLogP,hWPptMCLog,hFitErrorP,"hWPptDiffLog"); // added histogram for fit error
  hWPptDiffLog->SetMarkerStyle(kFullCircle);
  hWPptDiffLog->SetMarkerSize(0.9);

  //plotWPptDiffLog=new CPlot(histName,"","p_{T}^{W} [GeV]","(data-mc)/#sigma_{data}");
  plotWPptDiffLog=new CPlot(histName,"","p_{T}^{W} [GeV]","(data-sum)/#sigma_{sum}");
  plotWPptDiffLog->setOutDir(CPlot::sOutDir);
  plotWPptDiffLog->AddHist1D(hWPptDiffLog,"",kAzure+1,1,1001);
  //plotWPptDiffLog->SetYRange(-0.15,0.15);
  plotWPptDiffLog->SetYRange(-1.3,1.3);
  plotWPptDiffLog->AddLine(0.68, 0,600, 0,kBlack,1);
  plotWPptDiffLog->SetLogx();
  plotWPptDiffLog->Draw(c,kFALSE,format,2);
  gPad->RedrawAxis();

  plotName = "Wpt_plots/FitWDistribution_MuonPLog_withRatio." + format;
  if (filetype == "Electron")
    plotName = "Wpt_plots/FitWDistribution_ElePLog_withRatio." + format;
  c->SaveAs(plotName);


//W minus pt distribution
  TH1D* hWptMC_m = (TH1D*)hDYToTauTauM->Clone("hWptMC_m");
  hWptMC_m->Add(hTTJetsM);
  hWptMC_m->Add(hWToTauNuM);
  hWptMC_m->Add(hDYToMuMuM);
  hWptMC_m->Add(hQCDWMpt);
  hWptMC_m->Add(hSigWMpt);
  
  TH1D *hDYToTauTauLogM = new TH1D("hDYToTauTauLogM","",13,WptBinsLog);
  TH1D *hTTJetsLogM = new TH1D("hTTJetsLogM","",13,WptBinsLog);
  TH1D *hWToTauNuLogM = new TH1D("hWToTauNuLogM","",13,WptBinsLog);
  TH1D *hDYToMuMuLogM = new TH1D("hDYToMuMuLogM","",13,WptBinsLog);
  TH1D *hQCDWptLogM = new TH1D("hQCDWptLogM","",13,WptBinsLog);
  TH1D *hSigWptLogM = new TH1D("hSigWptLogM","",13,WptBinsLog);
  TH1D *hdataWptLogM = new TH1D("hdataWptLogM","",13,WptBinsLog);
  for (int i=1; i<=hSigWMpt->GetNbinsX(); i++){
    x1=hDYToTauTauM->GetBinContent(i);
    x2=hTTJetsM->GetBinContent(i);
    x3=hWToTauNuM->GetBinContent(i);
    x4=hDYToMuMuM->GetBinContent(i);
    x5=hQCDWMpt->GetBinContent(i);
    x6=hSigWMpt->GetBinContent(i);
    x7=hdataWMpt->GetBinContent(i);
    err = hdataWMpt->GetBinError(i);
    hDYToTauTauLogM->Fill(xaxis->GetBinCenter(i),x1);
    hTTJetsLogM->Fill(xaxis->GetBinCenter(i),x2);
    hWToTauNuLogM->Fill(xaxis->GetBinCenter(i),x3);
    hDYToMuMuLogM->Fill(xaxis->GetBinCenter(i),x4);
    hQCDWptLogM->Fill(xaxis->GetBinCenter(i),x5);
    hSigWptLogM->Fill(xaxis->GetBinCenter(i),x6);
    hdataWptLogM->Fill(xaxis->GetBinCenter(i),x7);
    hdataWptLogM->SetBinError(i,err);
  }
  
  TH1D* hEwkWMptLog = (TH1D*)hDYToTauTauLogM->Clone("hEwkWMptLog");
  hEwkWMptLog->Add(hTTJetsLogM);
  hEwkWMptLog->Add(hWToTauNuLogM);
  hEwkWMptLog->Add(hDYToMuMuLogM);
  
  plotName = "FitWDistribution_MuonMLog";
  if (filetype == "Electron")
    plotName = "FitWDistribution_EleMLog";
  plotWMptLog=new CPlot(plotName,"","p_{T}^{W} [GeV]","Events");
  plotWMptLog->setOutDir(CPlot::sOutDir);
  plotWMptLog->AddHist1D(hdataWptLogM,"#font[42]{Data}","E");
  plotWMptLog->AddToStack(hEwkWMptLog,"#font[42]{EW+t#bar{t}}",fillcolorEWK,linecolorEWK);
  plotWMptLog->AddToStack(hQCDWptLogM,"#font[42]{QCD}",fillcolorQCD,linecolorQCD);
  if(filetype == "Muon")
    //plotWMptLog->AddToStack(hSigWptLogM,"#font[42]{W^{-}#rightarrow #mu^{-} #bar{#nu}}",fillcolorW,linecolorW);
    plotWMptLog->AddToStack(hSigWptLogM,"#font[42]{W^{#font[122]{-}}#rightarrow #mu^{#font[122]{-}} #bar{#nu}}",fillcolorW,linecolorW);
  if(filetype == "Electron")
    //plotWMptLog->AddToStack(hSigWptLogM,"#font[42]{W^{-}#rightarrow e^{-} #bar{#nu}}",fillcolorW,linecolorW);
    plotWMptLog->AddToStack(hSigWptLogM,"#font[42]{W^{#font[122]{-}}#rightarrow e^{#font[122]{-}} #bar{#nu}}",fillcolorW,linecolorW);
  //plotWMptLog->SetLegend(0.75,0.78,.98,0.88);
  plotWMptLog->SetLegend(0.67,0.70,.98,0.88);
  //plotWMptLog->SetYRange(0.25,1.4*(hWptMC_m->GetMaximum()));
  plotWMptLog->SetYRange(1,50*(hWptMC_m->GetMaximum()));
  plotWMptLog->SetLogx();
  plotWMptLog->SetLogy();
  plotWMptLog->AddTextBox(CMStext,0.14,0.90,0.24,0.97,0);
  plotWMptLog->AddTextBox(lumitext,0.65,0.90,0.95,0.97,0);
  plotWMptLog->Draw(c,kFALSE,format,1);
  gPad->RedrawAxis();
  
  // Pull distribution (Ratio)
  TH1D* hWMptMCLog = (TH1D*)hEwkWMptLog->Clone("hWMptMCLog");
  hWMptMCLog->Add(hQCDWptLogM);
  hWMptMCLog->Add(hSigWptLogM);

  //hWMptDiffLog = makeDiffHistWptLog(hdataWptLogM,hWMptMCLog,"hWMptDiffLog");
  hWMptDiffLog = makeDiffHistWptLog(hdataWptLogM,hWMptMCLog,hFitErrorM,"hWMptDiffLog"); // added histogram for fit error
  hWMptDiffLog->SetMarkerStyle(kFullCircle);
  hWMptDiffLog->SetMarkerSize(0.9);

  //plotWMptDiffLog=new CPlot(histName,"","p_{T}^{W} [GeV]","(data-mc)/#sigma_{data}");
  plotWMptDiffLog=new CPlot(histName,"","p_{T}^{W} [GeV]","(data-sum)/#sigma_{sum}");
  plotWMptDiffLog->setOutDir(CPlot::sOutDir);
  plotWMptDiffLog->AddHist1D(hWMptDiffLog,"",kAzure+1,1,1001);
  //plotWMptDiffLog->SetYRange(-0.15,0.15);
  plotWMptDiffLog->SetYRange(-1.3,1.3);
  plotWMptDiffLog->AddLine(0.68, 0,600, 0,kBlack,1);
  plotWMptDiffLog->SetLogx();
  plotWMptDiffLog->Draw(c,kFALSE,format,2);
  gPad->RedrawAxis();


  plotName = "Wpt_plots/FitWDistribution_MuonMLog_withRatio." + format;
  if (filetype == "Electron")
    plotName = "Wpt_plots/FitWDistribution_EleMLog_withRatio." + format;
  c->SaveAs(plotName);

  gBenchmark->Show("Wpt_PASformat_withRatio");
}
Пример #15
0
void Ringfinder()
{
     static int first=1;
     if (first)
       {
         first = 0;      
	 xerr = new TH1D ("xerr","xerr",200,-5000,5000);
         yerr = new TH1D ("yerr","yerr",200,-5000,5000);
         rerr = new TH1D ("rerr","rerr",200,-3000,3000);
       }
  
  HoughF->Reset();
  
  frodo *fr = frodo::instance();
  fr->Y1.clear();
  fr->X1.clear();
  fr->Y2.clear();
  fr->X2.clear();
  fr->Y3.clear();
  fr->X3.clear();
  fr->Y4.clear();
  fr->X4.clear();
  fr->AllX.clear();
  fr->AllY.clear();
  fr->PseudoPoints.clear();
  fr->J1_PseudoPoints.clear();
  fr->J2_PseudoPoints.clear();
  fr->J3_PseudoPoints.clear();
  fr->J4_PseudoPoints.clear();
  fr->CX.clear();
  fr->CY.clear();
  
//   double Qx1,Qx2,Qx3,Qx4,Qy1,Qy2,Qy3,Qy4;
  
//   Qx1=Qx2=Qx3=Qx4=Qy1=Qy2=Qy3=Qy4=0;
  
//   for(unsigned int i=0; i<60; i++)
//     {
//       Qx1 += fr->J1_XStrips[i].Q();
//       Qx2 += fr->J2_XStrips[i].Q();
//       Qx3 += fr->J3_XStrips[i].Q();
//       Qx4 += fr->J4_XStrips[i].Q();
//     }
//   for(unsigned int i=0; i<60; i++)
//     {
//       Qy1 += fr->J1_YStrips[i].Q();
//       Qy2 += fr->J2_YStrips[i].Q();
//       Qy3 += fr->J3_YStrips[i].Q();
//       Qy4 += fr->J4_YStrips[i].Q();
//     }
  
//   double Qtot1 = Qx1+Qy1;
//   double Qtot2 = Qx2+Qy2;
//   double Qtot3 = Qx3+Qy3;
//   double Qtot4 = Qx4+Qy4;

  //J1 section:-------------------------------------------------------------------
  for(unsigned int i=0; i<60; i++)
    {
      double T = fr->J1_YStrips[i].Q();
      //double Qfrac = T/Qtot1*100;
            
      if(T>=4000)
 	{
	  fr->Y1.push_back(Coordinates(fr->J1_YStrips[i].YCenter()));
	  //fr->AllY.push_back(Coordinates(fr->J1_YStrips[i].YCenter()));
 	}
    }

  for(unsigned int j=0; j<60; j++)
    {
      double T = fr->J1_XStrips[j].Q();
      //double Qfrac = T/Qtot1*100;
      //double Qfrac = exp(-T/20)*100;
      
      if(T>=4000)
 	{
	  fr->X1.push_back(Coordinates(fr->J1_XStrips[j].XCenter()));
	  //fr->AllX.push_back(Coordinates(fr->J1_XStrips[j].XCenter()));
 	}
      
    }

  
  //J2 section:----------------------------------------------------------------
  //cout<<"J2: "<<endl;

  for(unsigned int i=0; i<60; i++)
    {
      double T = fr->J2_YStrips[i].Q();
      //double Qfrac = T/Qtot2*100;
      //double Qfrac = exp(-T/20)*100;

      if(T>=4000)
 	{
	  fr->Y2.push_back(Coordinates(fr->J2_YStrips[i].YCenter()));
	  //fr->AllY.push_back(Coordinates(fr->J2_YStrips[i].YCenter()));
	}
    }

  for(unsigned int j=0; j<60; j++)
    {
      double T = fr->J2_XStrips[j].Q();
      //double Qfrac = T/Qtot2*100;
      //double Qfrac = exp(-T/20)*100;
      
      if(T>=4000)
 	{
	  fr->X2.push_back(Coordinates(fr->J2_XStrips[j].XCenter()));
	  //fr->AllX.push_back(Coordinates(fr->J2_XStrips[j].XCenter()));
 	}
    }
  
  //J3 section:----------------------------------------------------------------

  for(unsigned int i=0; i<60; i++)
    {  
      double T = fr->J3_YStrips[i].Q();
      //double Qfrac = T/Qtot3*100;
      //double Qfrac = exp(-T/20)*100;
      
      if(T>=4000)
 	{
	  fr->Y3.push_back(Coordinates(fr->J3_YStrips[i].YCenter()));
	  //fr->AllY.push_back(Coordinates(fr->J3_YStrips[i].YCenter()));
 	}
    }

  for(unsigned int j=0; j<60; j++)
    {      
      double T = fr->J3_XStrips[j].Q();
      //double Qfrac = T/Qtot3*100;
      //double Qfrac = exp(-T/20)*100;
      
      if(T>=4000)
 	{
	  fr->X3.push_back(Coordinates(fr->J3_XStrips[j].XCenter()));
	  //fr->AllX.push_back(Coordinates(fr->J3_XStrips[j].XCenter()));
	}
    }

  //J4 section:-----------------------------------------------------------------
  for(unsigned int i=0; i<60; i++)
    {      
      double T = fr->J4_YStrips[i].Q();
      //double Qfrac = T/Qtot4*100;
      //double Qfrac = exp(-T/20)*100;
      
      if(T>=4000)
 	{
	  fr->Y4.push_back(Coordinates(fr->J4_YStrips[i].YCenter()));
	  //fr->AllY.push_back(Coordinates(fr->J4_YStrips[i].YCenter()));
 	}
    }

  for(unsigned int j=0; j<60; j++)
    {    
      double T = fr->J4_XStrips[j].Q();
      //double Qfrac = T/Qtot4*100;
      //double Qfrac = exp(-T/20)*100;
      
      if(T>=4000)
 	{
	  fr->X4.push_back(Coordinates(fr->J4_XStrips[j].XCenter()));
	}
    }

  //Finding the ring:----------------------------------------------------------------------------------
  
    
//Forming J1234 PseudoPoints:
  for(unsigned int s=0; s<fr->Y1.size(); s++)
    {
      for(unsigned int ps=0; ps<fr->X1.size(); ps++)
	{
	  fr->J1_PseudoPoints.push_back(TVector3(fr->X1[ps].Cor(),fr->Y1[s].Cor(),0));
	}
    }
 
  for(unsigned int s=0; s<fr->Y2.size(); s++)
    {
      for(unsigned int ps=0; ps<fr->X2.size(); ps++)
	{
	  fr->J2_PseudoPoints.push_back(TVector3(fr->X2[ps].Cor(),fr->Y2[s].Cor(),0));
	}
    }

  for(unsigned int s=0; s<fr->Y3.size(); s++)
    {
      for(unsigned int ps=0; ps<fr->X3.size(); ps++)
	{
	  fr->J3_PseudoPoints.push_back(TVector3(fr->X3[ps].Cor(),fr->Y3[s].Cor(),0));
	}
    }

  for(unsigned int s=0; s<fr->Y4.size(); s++)
    {
      for(unsigned int ps=0; ps<fr->X4.size(); ps++)
	{
	  fr->J4_PseudoPoints.push_back(TVector3(fr->X4[ps].Cor(),fr->Y4[s].Cor(),0));
	}
    }
 
  //Selecting 3 PseudoPoints in three different quadrants:
  //J1,J2,J3:
  if(fr->J1_PseudoPoints.size() >= 1 && fr->J2_PseudoPoints.size() >= 1 && fr->J3_PseudoPoints.size() >= 1)
    {
      for(unsigned int i=0; i<fr->J1_PseudoPoints.size(); i++)
	{
	  for(unsigned int j=0; j<fr->J2_PseudoPoints.size(); j++)
	    {
	      for(unsigned int k=0; k<fr->J3_PseudoPoints.size(); k++)
		{
		  
		  double Rad  = RFindR(fr->J1_PseudoPoints[i],fr->J2_PseudoPoints[j],fr->J3_PseudoPoints[k]);
		  double Xcen = RFindX(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J2_PseudoPoints[j].X(),fr->J2_PseudoPoints[j].Y(),fr->J3_PseudoPoints[k].X(),fr->J3_PseudoPoints[k].Y());
		  double Ycen = RFindY(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J2_PseudoPoints[j].X(),fr->J2_PseudoPoints[j].Y(),fr->J3_PseudoPoints[k].X(),fr->J3_PseudoPoints[k].Y());
		  HoughF->Fill(Xcen,Ycen,Rad);
		}
	    }
	}
    }
      
  //J1,J2,J4:
  if(fr->J1_PseudoPoints.size() >= 1 && fr->J2_PseudoPoints.size() >= 1 && fr->J4_PseudoPoints.size() >= 1)
    {
      for(unsigned int i=0; i<fr->J1_PseudoPoints.size(); i++)
	{
	  for(unsigned int j=0; j<fr->J2_PseudoPoints.size(); j++)
	    {
	      for(unsigned int k=0; k<fr->J4_PseudoPoints.size(); k++)
		{
		  double Rad  = RFindR(fr->J1_PseudoPoints[i],fr->J2_PseudoPoints[j],fr->J4_PseudoPoints[k]);
		  double Xcen = RFindX(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J2_PseudoPoints[j].X(),fr->J2_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  double Ycen = RFindY(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J2_PseudoPoints[j].X(),fr->J2_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  HoughF->Fill(Xcen,Ycen,Rad);
		}
	    }
	}
    }
  
  //J1,J3,J4:
  if(fr->J1_PseudoPoints.size() >= 1 && fr->J3_PseudoPoints.size() >= 1 && fr->J4_PseudoPoints.size() >= 1)
    {
      for(unsigned int i=0; i<fr->J1_PseudoPoints.size(); i++)
	{
	  for(unsigned int j=0; j<fr->J3_PseudoPoints.size(); j++)
	    {
	      for(unsigned int k=0; k<fr->J4_PseudoPoints.size(); k++)
		{
		  double Rad  = RFindR(fr->J1_PseudoPoints[i],fr->J3_PseudoPoints[j],fr->J4_PseudoPoints[k]);
		  double Xcen = RFindX(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J3_PseudoPoints[j].X(),fr->J3_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  double Ycen = RFindY(fr->J1_PseudoPoints[i].X(),fr->J1_PseudoPoints[i].Y(),fr->J3_PseudoPoints[j].X(),fr->J3_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  HoughF->Fill(Xcen,Ycen,Rad);
		}
	    }
	}
    }
  
  //J2,J3,J4;
  if(fr->J2_PseudoPoints.size() >= 1 && fr->J3_PseudoPoints.size() >= 1 && fr->J4_PseudoPoints.size() >= 1)
    {
      for(unsigned int i=0; i<fr->J2_PseudoPoints.size(); i++)
	{
	  for(unsigned int j=0; j<fr->J3_PseudoPoints.size(); j++)
	    {
	      for(unsigned int k=0; k<fr->J4_PseudoPoints.size(); k++)
		{
		  double Rad  = RFindR(fr->J2_PseudoPoints[i],fr->J3_PseudoPoints[j],fr->J4_PseudoPoints[k]);
		  double Xcen = RFindX(fr->J2_PseudoPoints[i].X(),fr->J2_PseudoPoints[i].Y(),fr->J3_PseudoPoints[j].X(),fr->J3_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  double Ycen = RFindY(fr->J2_PseudoPoints[i].X(),fr->J2_PseudoPoints[i].Y(),fr->J3_PseudoPoints[j].X(),fr->J3_PseudoPoints[j].Y(),fr->J4_PseudoPoints[k].X(),fr->J4_PseudoPoints[k].Y());
		  HoughF->Fill(Xcen,Ycen,Rad);
		}
	    }
	}
    }

  /*
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!DO NOT ERASE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  //Forming PseudoPoints:
  for(unsigned int ps=0; ps<fr->AllX.size(); ps++)
    {
      for(unsigned int s=0; s<fr->AllY.size(); s++)
	{
	   fr->PseudoPoints.push_back(TVector3(fr->AllX[ps].Cor(),fr->AllY[s].Cor(),0));
	}
    }
    
  //Full Combinatorial:
   for(unsigned int i=0; i<fr->PseudoPoints.size()-2; i++)
     {
       for(unsigned int j=i+1; j<fr->PseudoPoints.size()-1; j++)
 	{
 	  for(unsigned int k=j+1; k<fr->PseudoPoints.size(); k++)
 	    {
 	      double Rad = RFindR(fr->PseudoPoints[i],fr->PseudoPoints[j],fr->PseudoPoints[k]);
 	      double Xcen = RFindX(fr->PseudoPoints[i].X(),fr->PseudoPoints[i].Y(),fr->PseudoPoints[j].X(),fr->PseudoPoints[j].Y(),fr->PseudoPoints[k].X(),fr->PseudoPoints[k].Y());
 	      double Ycen = RFindY(fr->PseudoPoints[i].X(),fr->PseudoPoints[i].Y(),fr->PseudoPoints[j].X(),fr->PseudoPoints[j].Y(),fr->PseudoPoints[k].X(),fr->PseudoPoints[k].Y());
 	      HoughF->Fill(Xcen,Ycen,Rad);
 	      HoughFxy->Fill(Xcen,Ycen);
 	      HoughFyr->Fill(Ycen,Rad);
 	      HoughFxr->Fill(Xcen,Rad);
	      }
 	}
     }
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  */      
  int xbin, ybin, zbin;
  xbin=0; ybin=0; zbin=0;
  HoughF->GetMaximumBin(xbin, ybin, zbin);
  // cout << "xbin= " << xbin << " ybin= " << ybin << " zbin= " << zbin << endl;

  TAxis *xaxis = HoughF->GetXaxis();  
  double Xrec=xaxis->GetBinCenter(xbin);
  //cout<<"Xrec= "<< Xrec <<endl;

  TAxis *yaxis = HoughF->GetYaxis();  
  double Yrec=yaxis->GetBinCenter(ybin);
  //cout<<"Yrec= "<< Yrec <<endl;

  TAxis *zaxis = HoughF->GetZaxis();  
  double Rrec=zaxis->GetBinCenter(zbin);
  //cout<<"Rrec= "<< Rrec <<endl;

   double Xerr = fr->CX[0].Cor()-Xrec;  
   double Yerr = fr->CY[0].Cor()-Yrec;  
   double Rerr = fr->Ring[0].R()-Rrec;  

//  if(fabs(Xerr) < 3*fr->Ring[0].SigmaX() && fabs(Yerr) < 3*fr->Ring[0].SigmaY() && fabs(Rerr) < 3*fr->Ring[0].SigmaR()) fr->Nsuc.push_back(1);
       
//    double Xdif = fabs(fr->Ring[0].Xmean())-fabs(Xerr); //cout<<"Xdif= " <<Xdif<<endl;
//    double Ydif = fabs(fr->Ring[0].Ymean())-fabs(Yerr); //cout<<"Ydif= " <<Ydif<<endl;
//    double Rdif = fabs(fr->Ring[0].Rmean())-fabs(Rerr); //cout<<"Rdif= " <<Rdif<<endl;

//    if(fabs(Xdif) < 3*fr->Ring[0].SigmaX() && fabs(Ydif) < 3*fr->Ring[0].SigmaY() && fabs(Rdif) < 3*fr->Ring[0].SigmaR()) fr->Nsuc_off.push_back(1);

   xerr->Fill(Xerr);
   yerr->Fill(Yerr);
   rerr->Fill(Rerr);
   
}
void MiniTreeSignalProducerVV13TeV(int samplemin, int samplemax){

 string dir = "/usr/users/dschaefer/CMSSW_7_4_7/src/DijetCombineLimitCode/";
  double mgg, mjj,evWeight, mtot, normWeight;
 int categories;

 evWeight = 1.0;
 normWeight = 1;

 for (int iSample = samplemin; iSample < samplemax; iSample++){
   
   string inFile("WprimeToWZ");
   if (iSample == 1) inFile = string("RS1WW");
   if (iSample == 2) inFile = string("RS1ZZ"); // Fake ZZ signal
   if (iSample == 3) inFile = string("QstarQW");
   if (iSample == 4) inFile = string("QstarQZ");
   if (iSample == 5) inFile = string("BulkWW");
   if (iSample == 6) inFile = string("BulkZZ");
   if (iSample == 7) inFile = string("ZprimeWW");
   if (iSample == 8) inFile = string("WprimeWZ");

   string outFile("dijetVV_13TeV_WZ");
   if (iSample == 1) outFile = string("dijetVV_13TeV_RS1WW");
   if (iSample == 2) outFile = string("dijetVV_13TeV_RS1ZZ");
   if (iSample == 3) outFile = string("dijetVV_13TeV_QstarQW");
   if (iSample == 4) outFile = string("dijetVV_13TeV_QstarQZ");
   if (iSample == 5) outFile = string("dijetVV_13TeV_BulkWW");
   if (iSample == 6) outFile = string("dijetVV_13TeV_BulkZZ");
   if (iSample == 7) outFile = string("dijetVV_13TeV_ZprimeWW");
   if (iSample == 8) outFile = string("dijetVV_13TeV_WZ");
   
   int massrange=36;

   for (int iMass = 0; iMass<massrange; iMass++){

     string sInFile = dir+"input/" + inFile + "_13TeV_" + Form("10k_OUT%dGeV.root", 1000+iMass*100);
     cout << sInFile.c_str() << endl;
     TFile file0(sInFile.c_str(), "read");

     string sOutFile = dir+"MiniTrees/Signal_VV_13TeV/" + outFile + Form("OUT%d_miniTree.root", 1000+iMass*100);
     TFile f1(sOutFile.c_str(), "recreate");
     f1.cd();

     TTree *TCVARS = new TTree("TCVARS", "VV selection");
     TCVARS->Branch("mgg13TeV",&mgg,"mgg/D");

     TCVARS->Branch("evWeight",&evWeight,"evWeight/D");
     TCVARS->Branch("normWeight",&normWeight,"normWeight/D");
     
     TCVARS->Branch("categories",&categories,"categories/I");

  
     double dMass = 1000.+iMass*100.;

     
     for (int iCat = 2; iCat < 8; iCat++){
       TH1D* hMass = (TH1D*) file0.Get("DijetMassHighPuriVV;1");
       if (iCat == 1) hMass = (TH1D*) file0.Get("DijetMassLowPuriVV;1");
       
       if (iCat == 2) hMass = (TH1D*) file0.Get("DijetMassHighPuriWW;1");
       if (iCat == 3) hMass = (TH1D*) file0.Get("DijetMassLowPuriWW;1");
       
       if (iCat == 4) hMass = (TH1D*) file0.Get("DijetMassHighPuriWZ;1");
       if (iCat == 5) hMass = (TH1D*) file0.Get("DijetMassLowPuriWZ;1");
       
       if (iCat == 6) hMass = (TH1D*) file0.Get("DijetMassHighPuriZZ;1");
       if (iCat == 7) hMass = (TH1D*) file0.Get("DijetMassLowPuriZZ;1");
    
       if (iCat == 8) hMass = (TH1D*) file0.Get("DijetMassHighPuriqV;1");
       if (iCat == 9) hMass = (TH1D*) file0.Get("DijetMassLowPuriqV;1");

       if (iCat == 10) hMass = (TH1D*) file0.Get("DijetMassHighPuriqW;1");
       if (iCat == 11) hMass = (TH1D*) file0.Get("DijetMassLowPuriqW;1");

       if (iCat == 12) hMass = (TH1D*) file0.Get("DijetMassHighPuriqZ;1");
       if (iCat == 13) hMass = (TH1D*) file0.Get("DijetMassLowPuriqZ;1");

       if (iCat == 14) hMass = (TH1D*) file0.Get("DijetMassNoPuriVV;1");
       if (iCat == 15) hMass = (TH1D*) file0.Get("DijetMassNoPuriWW;1");
       if (iCat == 16) hMass = (TH1D*) file0.Get("DijetMassNoPuriWZ;1");
       if (iCat == 17) hMass = (TH1D*) file0.Get("DijetMassNoPuriZZ;1");
       if (iCat == 18) hMass = (TH1D*) file0.Get("DijetMassNoPuriqV;1");
       if (iCat == 19) hMass = (TH1D*) file0.Get("DijetMassNoPuriqW;1");
       if (iCat == 20) hMass = (TH1D*) file0.Get("DijetMassNoPuriqZ;1");
       // TH1D* hMass = (TH1D*) file0.Get("DijetMassHighPuriVV"); // WW high purity
//        if (iCat == 1) hMass = (TH1D*) file0.Get("DijetMassLowPuriVV"); // WW low purity
//        if (iCat == 2) hMass = (TH1D*) file0.Get("DijetMassHighPuriWW"); // WW high purity
//        if (iCat == 3) hMass = (TH1D*) file0.Get("DijetMassLowPuriWW"); // WW low purity
//        if (iCat == 4) hMass = (TH1D*) file0.Get("DijetMassHighPuriWZ"); // WZ high purity
//        if (iCat == 5) hMass = (TH1D*) file0.Get("DijetMassLowPuriWZ"); // WZ low purity
//        if (iCat == 6) hMass = (TH1D*) file0.Get("DijetMassHighPuriZZ"); // ZZ high purity
//        if (iCat == 7) hMass = (TH1D*) file0.Get("DijetMassLowPuriZZ"); // ZZ low purity
       
       if(!hMass) continue;
       
       TAxis* Axis =   hMass->GetXaxis();
       for (int i = 1 ; i < hMass->GetNbinsX()+1; i++){
	 //if (hMass->GetBinCenter(i) < dMass*0.75 || hMass->GetBinCenter(i) > dMass*1.25) continue;
	 int N = abs(hMass->GetBinContent(i));
	 if (i%1000 == 0) cout << "i = " << i << " N = " << N << endl;
	 
	 mgg = Axis->GetBinCenter(i);
	 
         categories = iCat;
	 for (int k = 0; k < N; k++) {
	   TCVARS->Fill();
	 }
       }
     }
		 TCVARS->Write();
     f1.Close();
     file0.Close();
     
   }

 }


}
Пример #17
0
void Find_JPsiPt()
{
  double pt_bound[200] = {0.0};
  double PT[200], DelPT[200];
  double YPT[200], DelYPT[200];
  
  int Nptbin = 120;
  //int Nptbin = 70;
  
  double step =0.1;
  
  cout<<" pT Bins "<<endl;
  for (Int_t ih = 0; ih < Nptbin; ih++) {
    pt_bound[ih] = 0 + step*ih;
    pt_bound[ih+1] = 0 + step*(ih+1);
    
    PT[ih] = (pt_bound[ih] + pt_bound[ih+1])/2.0;
    DelPT[ih] = (pt_bound[ih+1] - pt_bound[ih])/2.0;
    
    cout<<PT[ih]<<"    "<<DelPT[ih]<<endl;

  }
  

  char namePt[500];
  
  //TFile *fpT = new TFile("Psi2s5M_pythia.root");
  //TH2D *JPt_BPt = (TH2D*)fpT->Get("Psi2SVsJPsi_Pt");
  //TH2D *JPt_BPt = (TH2D*)fpT->Get("Psi2SVsChic0_Pt");

  TFile *fpT = new TFile("Psi2S1M_pythia.root");
  //TH2D *JPt_BPt = (TH2D*)fpT->Get("Psi2SVsChic1_Pt");
  TH2D *JPt_BPt = (TH2D*)fpT->Get("Psi2SVsChic2_Pt");
  
  new TCanvas;
  JPt_BPt->Draw("colz");

  TH1D *service = (TH1D*)JPt_BPt->ProjectionX("service");
  TAxis *xaxis = service->GetXaxis();

  for(int i=0;i<service->GetSize();i++)
    {
      Double_t binCenter = xaxis->GetBinCenter(i);
      cout<<binCenter<<endl;

    }

  
  //return;

  //service->Draw();
  cout<<" service  "<<service<<endl;

  int pt_bin_bound[200];

  TH1D *ProfY_BPt[200];

  
  for (Int_t ih = 0; ih < Nptbin; ih++) {
  
    pt_bin_bound[ih] = service->FindBin(pt_bound[ih]);
    pt_bin_bound[ih+1] = service->FindBin(pt_bound[ih+1]);
    
    sprintf(namePt,"BPt_%d",ih);
    
    //ProfY_BPt[ih] = (TH1D*)JPt_BPt->ProjectionY(namePt, pt_bin_bound[ih], pt_bin_bound[ih+1]-1,"e");
    
    ProfY_BPt[ih] = (TH1D*)JPt_BPt->ProjectionY(namePt, pt_bin_bound[ih], pt_bin_bound[ih+1],"e");
    YPT[ih] = ProfY_BPt[ih]->GetMean();
    DelYPT[ih] = ProfY_BPt[ih]->GetRMS();
    
    cout<< YPT[ih] <<" /pm "<<  DelYPT[ih]<< endl<<endl;

  }
  
  TGraphErrors *gr_BpTvsJpT = new TGraphErrors(Nptbin, PT, YPT, DelPT, DelYPT);
  TF1 *func_BpTvsJpT = new TF1("pol1", pol1, 0, 20, 2); 
  func_BpTvsJpT->SetLineColor(2);
  gr_BpTvsJpT->Fit("pol1","","",0,20);
  gr_BpTvsJpT->GetXaxis()->SetRangeUser(0,20);
  gr_BpTvsJpT->GetXaxis()->SetTitle("J/#psi p_{T}");
  gr_BpTvsJpT->GetYaxis()->SetTitle("#psi(2S) p_{T}");
  new TCanvas;
  gr_BpTvsJpT->Draw("ap");
  func_BpTvsJpT->Draw("same");
}