void estimateEfficiencyAndPurity(TH1* fraction,double cut,double& efficiency, double& purity, double& efferror, double& purerror, TFitResultPtr fitRes) {
  // efficiency loss is defined as the estimated signal below the cut over the estimated total signal
  double rangeLow, rangeHigh;
  TF1* expo = fraction->GetFunction("expo");
  expo->GetRange(rangeLow, rangeHigh);

  double signalLoss         = expo->Integral(0,cut)/fraction->GetBinWidth(1);
  double signalLossError = expo->IntegralError(0,cut,fitRes->GetParams(),fitRes->GetCovarianceMatrix().GetMatrixArray())/fraction->GetBinWidth(1);
  
  double signal_expopart         = expo->Integral(cut,fraction->GetBinLowEdge(fraction->FindBin(rangeHigh)+1))/fraction->GetBinWidth(1);
  double signal_expopartError = expo->IntegralError(cut, fraction->GetBinLowEdge(fraction->FindBin(rangeHigh)+1),fitRes->GetParams(),fitRes->GetCovarianceMatrix().GetMatrixArray())/fraction->GetBinWidth(1);

  double signal_toppoart = fraction->Integral(fraction->FindBin(rangeHigh)+1,fraction->FindBin(1.)+1);
  
  efficiency = (signal_expopart+signal_toppoart)/(signal_expopart+signal_toppoart+signalLoss);
  efferror = TMath::Sqrt( pow(signalLoss,2)*pow(signal_expopartError,2) + pow(signal_toppoart+signal_expopart,2)*pow(signalLossError,2) )/pow(signal_expopart+signal_toppoart+signalLoss,2);
  
  // purity is defined as the signal above the cut (signal_expopart+signal_toppoart) 
  // over the total data above that cut
  
  double data_kept = fraction->Integral(fraction->FindBin(cut),fraction->FindBin(1.)+1);
  double allBeforeRangeHigh = fraction->Integral(fraction->FindBin(cut),fraction->FindBin(rangeHigh));
  purity = (signal_expopart+signal_toppoart)/data_kept;
  purerror = signal_expopartError/data_kept; 
 
  if(purity > 1.){
    std::cout << "#################################################"<<std::endl;
    std::cout << "cut: "<<cut<<" purity:" << purity <<std::endl;
    std::cout << "signalLoss: " << signalLoss << " signalExtrapolated: " << signal_expopart << " signalTop: " << signal_toppoart << std::endl;
    std::cout << "all b.r.h.: " << allBeforeRangeHigh << std::endl;
    std::cout << "total signal with expo: "<< (signal_expopart+signal_toppoart)<< std::endl;
    std::cout << "total signal integrating: "<< (allBeforeRangeHigh+signal_toppoart)<< std::endl;
    std::cout << "data kept:  " << data_kept  << std::endl;
    std::cout << "ratio:      " << allBeforeRangeHigh/signal_expopart << std::endl;
    std::cout << "#################################################"<<std::endl;
  }
 
  //   std::cout << "estimateEfficiencyAndPurity for cut=" << cut << std::endl;
  //   std::cout << "signal: " << signalLoss << " " << signal_expopart << " " << signal_toppoart << std::endl;
  //   std::cout << "data kept: " << data_kept << std::endl;
  //   std::cout << "eff: " << efficiency << "+/- " << efferror << " pur: " << purity << " +/- " << purerror << std::endl;
}
Exemple #2
0
bool FitPeak(Double_t *par, TH1 *h, Float_t &area, Float_t &darea){

   Double_t binWidth = h->GetXaxis()->GetBinWidth(1000);//Need to find the bin widths so that the integral makes sense
   Int_t rw = binWidth*20;  //This number may change depending on the source used   
   //Set the number of iterations. The code is pretty quick, so having a lot isn't an issue	
   TVirtualFitter::SetMaxIterations(4999);
   Int_t xp = par[1];

   //Define the fit function and the range of the fit
   TF1 *pp = new TF1("photopeak",fitFunction,xp-rw,xp+rw,10);

   //Name the parameters so it is easy to see what the code is doing
   pp->SetParName(0,"Height");
   pp->SetParName(1,"centroid");
   pp->SetParName(2,"sigma");
   pp->SetParName(3,"beta");
   pp->SetParName(4,"R");
   pp->SetParName(5,"step");
   pp->SetParName(6,"A");
   pp->SetParName(7,"B");
   pp->SetParName(8,"C");
   pp->SetParName(9,"bg offset");

   //Set some physical limits for parameters
   pp->SetParLimits(1,xp-rw,xp+rw);
   pp->SetParLimits(3,0,30);
   pp->SetParLimits(4,0,10);
   pp->SetParLimits(5,0.000,1000000);
   pp->SetParLimits(9,xp-20,xp+20);

   //Actually set the parameters in the photopeak function
   pp->SetParameters(par);

//   pp->FixParameter(4,0);
 //  pp->FixParameter(5,0);

   pp->SetNpx(1000); //Draws a nice smooth function on the graph
   TFitResultPtr fitres = h->Fit("photopeak","RFS");
   pp->Draw("same");      

   pp->GetParameters(&par[0]); 
   TF1 *photopeak = new TF1("photopeak",photo_peak,xp-rw,xp+rw,10);
   photopeak->SetParameters(par);

   Double_t integral = photopeak->Integral(xp-rw,xp+rw)/binWidth;

   std::cout << "FIT RESULT CHI2 " << fitres->Chi2() << std::endl;

   std::cout << "FWHM = " << 2.35482*fitres->Parameter(2)/binWidth <<"(" << fitres->ParError(2)/binWidth << ")" << std::endl;
   std::cout << "NDF: " << fitres->Ndf() << std::endl;
   std::cout << "X sq./v = " << fitres->Chi2()/fitres->Ndf() << std::endl;

   TVirtualFitter *fitter = TVirtualFitter::GetFitter();

   assert(fitter != 0); //make sure something was actually fit
   Double_t * covMatrix = fitres->GetCovarianceMatrix(); //This allows us to find the uncertainty in the integral

   Double_t sigma_integral = photopeak->IntegralError(xp-rw,xp+rw)/binWidth;

   std::cout << "Integral = " << integral << " +/- " << sigma_integral << std::endl;

   area = integral;
   darea = sigma_integral;

   if(fitres->Chi2()/fitres->Ndf() > 5.0)
      return false;

   return true;

//   myFitResult.fIntegral = integral;


 //  return photopeak;

}
Exemple #3
0
plot()
{
// DATA
 TFile *f0 = new TFile("../output/QCD_Pt30-80_7TeV_SD_Jet50U_SSVT.root");
// Primary MC sample
 TFile *f1 = new TFile("../output/QCD_Pt30-80_SD_Jet50U_SSVT.root");
// MC with Track History
 TFile *f2 = new TFile("../output/QCD_Pt80-170_7TeV_SSVT.root");

// *****************************************************************************

 char* xtitle = "p_{T}(jet) (GeV)";
 int nbin = 20;
 float binw = 10., bini = 30.;

 float EtaMin = 0., EtaMax = 2.4;
//  float EtaMin = 0., EtaMax = 0.7;
//  float EtaMin = 0.7, EtaMax = 1.4;
//  float EtaMin = 1.4, EtaMax = 2.4;

//  string TaggerName = "jetProbabilityBJetTags";
//  string TaggerName = "trackCountingHighEffBJetTags";
//  string TaggerName = "trackCountingHighPurBJetTags";
 string TaggerName = "simpleSecondaryVertexBJetTags";

//  float wp = 1.90; // TCHEL
//  float wp = 3.99; // TCHEM
//  float wp = 2.17; // TCHPM
//  float wp = 4.31; // TCHPT
//  float wp = .230; // JPL
//  float wp = .495; // JPM
//  float wp = .700; // JPT
//  float wp = 2.02; // SSVM
 float wp = 3.40; // SSVT

// *****************************************************************************

 int stati=0;
 bool  fit=0;
 bool logy=1;

// *****************************************************************************

 TCanvas *c1 = new TCanvas("c1", "plots",200,10,700,730);
 c1->SetFillColor(10);
 c1->SetFillStyle(4000);
 c1->SetBorderSize(2);

// *****************************************************************************

// TPaveLabel *p01 = new TPaveLabel(0.05,0.93,0.95,0.97,
//                   "mistag in QCD 30-120 CMSSW 1.6.0 : IP2 > 4","br");
// //                   "mistag in QCD 30-120 CMSSW 1.6.0 : IP2 > 4, no pos. IP1 > 4","br");
// // p01->SetFillColor(7);
// p01->SetFillColor(0);
// p01->SetFillStyle(3017);
// p01->SetTextSize(0.8);
// p01->Draw();

pad1 = new TPad("pad1","This is pad1",0.04,0.50,0.96,0.93,21);
pad2 = new TPad("pad2","This is pad2",0.04,0.05,0.96,0.48,21);

pad1->SetFillColor(0);
pad1->SetBorderMode(0);
pad1->SetFrameFillColor(10);
pad1->Draw();
pad1->SetLogy(logy);
   pad1->SetTopMargin(0.05);
   pad1->SetBottomMargin(0.15);
   pad1->SetRightMargin(0.05);
   pad1->SetLeftMargin(0.15);

pad2->SetFillColor(0);
pad2->SetBorderMode(0);
pad2->SetFrameFillColor(10);
pad2->Draw();
pad2->SetLogy(0);
   pad2->SetTopMargin(0.05);
   pad2->SetBottomMargin(0.15);
   pad2->SetRightMargin(0.05);
   pad2->SetLeftMargin(0.15);

//$$ gStyle->SetOptDate(1);
gStyle->SetOptDate(0);
gStyle->SetStatColor(0);
gStyle->SetTitleColor(29);
gStyle->SetTitleW(0.2);
gStyle->SetTitleH(0.1);
gStyle->SetOptStat(stati);

if (fit) {
gStyle->SetOptFit(111);
gStyle->SetStatW(0.5);
gStyle->SetStatH(0.2);
} else {
gStyle->SetOptFit(0);
gStyle->SetStatW(0.4);
gStyle->SetStatH(0.3);
}

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Systematics

// Flavour fraction
 float Xbb = 0.5;
 float Xcc = 0.5;
 float Xgg = 0.2;

// IP Sign Flip
 float XipM = 0.011 * TMath::Sqrt(1.1);    // 10 pb-1
//  float XipM = 0.011 * TMath::Sqrt(0.2); // 100 pb-1
//  float XipM = 0.011 * TMath::Sqrt(0.11); // 1000 pb-1
 float XipT = 0.014 * TMath::Sqrt(1.1);    // 10 pb-1
//  float XipT = 0.014 * TMath::Sqrt(0.2); // 100 pb-1
//  float XipT = 0.014 * TMath::Sqrt(0.11); // 1000 pb-1
 float Xip = XipM;

// V0 fraction
 float Xv = 0.2;

// Bad tracks fraction
 float Xbad = 0.3;
 float SFbad = 2; // medium

 float BinMin[30], BinMax[30]; 
 float Leff[30], LeffMin[30], LeffMax[30], LeffErr[30];
 float Lsf[30], LsfMin[30], LsfMax[30], LsfErr[30];

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Initialise Histograms

       f1->cd();
 TH1F* g00 = (TH1F*)gROOT->FindObject("hAllFlav_JetPt");   // all
 TH1F* g01 = (TH1F*)gROOT->FindObject("hUDSFlav_JetPt");   // uds-jet
 TH1F* g02 = (TH1F*)gROOT->FindObject("hCFlav_JetPt");     // c-jet
 TH1F* g03 = (TH1F*)gROOT->FindObject("hBFlav_JetPt");     // b-jet
 TH1F* g04 = (TH1F*)gROOT->FindObject("hGluonFlav_JetPt"); // g-jet
 TH1F* g09 = (TH1F*)gROOT->FindObject("hLightFlav_JetPt"); // udsg-jet
//
 TH1F* g10 = (TH1F*)gROOT->FindObject("hAllFlav_NegTag_JetPt");   // all neg
 TH1F* g19 = (TH1F*)gROOT->FindObject("hLightFlav_NegTag_JetPt"); // udsg neg 
//
 TH1F* h00 = (TH1F*)gROOT->FindObject("hAllFlav_Veto_JetPt");   // all with veto
 TH1F* h01 = (TH1F*)gROOT->FindObject("hUDSFlav_Veto_JetPt");   // uds-jet with veto 
 TH1F* h02 = (TH1F*)gROOT->FindObject("hCFlav_Veto_JetPt");     // c-jet with veto 
 TH1F* h03 = (TH1F*)gROOT->FindObject("hBFlav_Veto_JetPt");     // b-jet with veto
 TH1F* h04 = (TH1F*)gROOT->FindObject("hGluonFlav_Veto_JetPt"); // g-jet with veto
 TH1F* h09 = (TH1F*)gROOT->FindObject("hLightFlav_Veto_JetPt"); // udsg-jet with veto 
//
 TH1F* h10 = (TH1F*)gROOT->FindObject("hAllFlav_Veto_NegTag_JetPt");   // all neg with veto
 TH1F* h11 = (TH1F*)gROOT->FindObject("hUDSFlav_Veto_NegTag_JetPt");   // uds neg with veto 
 TH1F* h12 = (TH1F*)gROOT->FindObject("hCFlav_Veto_NegTag_JetPt");     // c neg with veto
 TH1F* h13 = (TH1F*)gROOT->FindObject("hBFlav_Veto_NegTag_JetPt");     // b neg with veto
 TH1F* h14 = (TH1F*)gROOT->FindObject("hGluonFlav_Veto_NegTag_JetPt"); // g neg with veto
//
 TH1F* h20 = (TH1F*)gROOT->FindObject("hAllFlav_PosTag_JetPt");   // all pos
 TH1F* h21 = (TH1F*)gROOT->FindObject("hUDSFlav_PosTag_JetPt");   // uds pos 
 TH1F* h22 = (TH1F*)gROOT->FindObject("hCFlav_PosTag_JetPt");     // c pos 
 TH1F* h23 = (TH1F*)gROOT->FindObject("hBFlav_PosTag_JetPt");     // b pos
 TH1F* h24 = (TH1F*)gROOT->FindObject("hGluonFlav_PosTag_JetPt"); // g pos
 TH1F* h29 = (TH1F*)gROOT->FindObject("hLightFlav_PosTag_JetPt"); // udsg pos
//
       g00->Sumw2(); 
       g01->Sumw2(); 
       g02->Sumw2(); 
       g03->Sumw2(); 
       g04->Sumw2(); 
       g09->Sumw2(); 
       g10->Sumw2(); 
       g19->Sumw2(); 
       h00->Sumw2(); 
       h01->Sumw2(); 
       h02->Sumw2(); 
       h03->Sumw2(); 
       h04->Sumw2(); 
       h10->Sumw2(); 
       h11->Sumw2(); 
       h12->Sumw2(); 
       h13->Sumw2(); 
       h14->Sumw2(); 
       h20->Sumw2(); 
       h21->Sumw2(); 
       h22->Sumw2(); 
       h23->Sumw2(); 
       h24->Sumw2(); 
       h29->Sumw2(); 

       f2->cd();
 TH1F* i00 = (TH1F*)gROOT->FindObject("hAllFlav_Veto_JetPt");   // all with veto
 TH1F* i10 = (TH1F*)gROOT->FindObject("hAllFlav_Veto_NegTag_JetPt");   // all neg with veto
 TH1F* i09 = (TH1F*)gROOT->FindObject("hLightFlav_Veto_JetPt"); // udsg-jet with veto 
 TH1F* i29 = (TH1F*)gROOT->FindObject("hLightFlav_PosTag_JetPt"); // udsg pos
//
       i00->Sumw2(); 
       i10->Sumw2(); 
       i09->Sumw2(); 
       i29->Sumw2(); 

 TH1F* h100 = (TH1F*)gROOT->FindObject("hAllFlav_K0s_JetPt");
 TH1F* h109 = (TH1F*)gROOT->FindObject("hLightFlav_K0s_JetPt");
 TH1F* h110 = (TH1F*)gROOT->FindObject("hAllFlav_K0s_Veto_NegTag_JetPt");
 TH1F* h129 = (TH1F*)gROOT->FindObject("hLightFlav_K0s_PosTag_JetPt");
//
 TH1F* h200 = (TH1F*)gROOT->FindObject("hAllFlav_Fak_JetPt");
 TH1F* h209 = (TH1F*)gROOT->FindObject("hLightFlav_Fak_JetPt");
 TH1F* h210 = (TH1F*)gROOT->FindObject("hAllFlav_Fak_Veto_NegTag_JetPt");
 TH1F* h229 = (TH1F*)gROOT->FindObject("hLightFlav_Fak_PosTag_JetPt");
//
 TH1F* h300 = (TH1F*)gROOT->FindObject("hAllFlav_Gam_JetPt");
 TH1F* h309 = (TH1F*)gROOT->FindObject("hLightFlav_Gam_JetPt");
 TH1F* h310 = (TH1F*)gROOT->FindObject("hAllFlav_Gam_Veto_NegTag_JetPt");
 TH1F* h329 = (TH1F*)gROOT->FindObject("hLightFlav_Gam_PosTag_JetPt");
//
       h100->Sumw2(); 
       h109->Sumw2(); 
       h110->Sumw2(); 
       h129->Sumw2(); 
       h200->Sumw2(); 
       h209->Sumw2(); 
       h210->Sumw2(); 
       h229->Sumw2(); 
       h300->Sumw2(); 
       h309->Sumw2(); 
       h310->Sumw2(); 
       h329->Sumw2(); 

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Mistags and Negative Tags

 TH1F* h4= new TH1F("h4","",nbin,bini,bini+nbin*binw);  // light pos / light
       h4->Divide(h29,g09,1,1,"B"); 

 TH1F* h5= new TH1F("h5","",nbin,bini,bini+nbin*binw);  // all neg with veto / all with veto
       h5->Divide(h10,h00,1,1,"B");

 TH1F* Rlight= new TH1F("Rlight","",nbin,bini,bini+nbin*binw);  // (light pos/light) / (all neg/all)
       Rlight->Divide(h4,h5,1,1);

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Flavour fraction

 TH1F* k00= new TH1F("k00","",nbin,bini,bini+nbin*binw);  // g/uds ratio
 TH1F* k01= new TH1F("k01","",nbin,bini,bini+nbin*binw);  // uds-fraction
 TH1F* k02= new TH1F("k02","",nbin,bini,bini+nbin*binw);  // c-fraction
 TH1F* k03= new TH1F("k03","",nbin,bini,bini+nbin*binw);  // b-fraction
 TH1F* k04= new TH1F("k04","flavour fraction",nbin,bini,bini+nbin*binw);  // g-fraction
 TH1F* k11= new TH1F("k11","",nbin,bini,bini+nbin*binw);  // uds-fraction neg
 TH1F* k12= new TH1F("k12","flavour fraction",nbin,bini,bini+nbin*binw);  // c-fraction neg
 TH1F* k13= new TH1F("k13","",nbin,bini,bini+nbin*binw);  // b-fraction neg
 TH1F* k14= new TH1F("k14","",nbin,bini,bini+nbin*binw);  // g-fraction neg
 TH1F* k21= new TH1F("k21","",nbin,bini,bini+nbin*binw);  // uds-fraction pos
 TH1F* k24= new TH1F("k24","",nbin,bini,bini+nbin*binw);  // g-fraction pos

       k00->Divide(g04,g01,1,1);
       k01->Divide(g01,g00,1,1,"B");
       k11->Divide(h11,h10,1,1,"B");
       k21->Divide(h21,h29,1,1,"B");
       k02->Divide(g02,g00,1,1,"B");
       k12->Divide(h12,h10,1,1,"B");
       k03->Divide(g03,g00,1,1,"B");
       k13->Divide(h13,h10,1,1,"B");
       k04->Divide(g04,g00,1,1,"B");
       k14->Divide(h14,h10,1,1,"B");
       k24->Divide(h24,h29,1,1,"B");

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Systematics

// systematics due to flavour fraction

 TH1F* bb= new TH1F("bb","",nbin,bini,bini+nbin*binw);
       for (int i=1; i<nbin+1; i++) {
        float yneg = k13->GetBinContent(i);
	float y = k13->GetBinContent(i) - k03->GetBinContent(i);
	y = Xbb * TMath::Abs( y );
	float ey = Xbb * k13->GetBinError(i);
        bb->SetBinContent(i,y);
        bb->SetBinError(i,ey);
       }
 TH1F* cc= new TH1F("cc","",nbin,bini,bini+nbin*binw);
       for (int i=1; i<nbin+1; i++) {
        float yneg = k12->GetBinContent(i);
	float y = k12->GetBinContent(i) - k02->GetBinContent(i);
	y = Xcc * TMath::Abs( y );
	float ey = Xcc * k12->GetBinError(i);
        cc->SetBinContent(i,y);
        cc->SetBinError(i,ey);
       }

 TH1F* gg= new TH1F("gg","",nbin,bini,bini+nbin*binw);
       for (int i=1; i<nbin+1; i++) {
        float frac = k00->GetBinContent(i);
        float lneg = k11->GetBinContent(i);
        float lpos = k21->GetBinContent(i);
        float gneg = k14->GetBinContent(i);
        float gpos = k24->GetBinContent(i);
	float yl = frac * (lpos - lneg);
	float yg = gpos - gneg;
	y = Xgg * TMath::Abs( yg - yl );
        float elneg = k11->GetBinError(i);
        float elpos = k21->GetBinError(i);
        float egneg = k14->GetBinError(i);
        float egpos = k24->GetBinError(i);
	float eyneg = (egneg - frac*elneg) * (egneg - frac*elneg);
	float eypos = (egpos - frac*elpos) * (egpos - frac*elpos);
	float ey = Xgg * TMath::Sqrt( eyneg + eypos );
        gg->SetBinContent(i,y);
        gg->SetBinError(i,ey);
       }

// systematics due to sign flip

 TH1F* h1= new TH1F("h1","",nbin,bini,bini+nbin*binw); // all pos / all neg
       h1->Divide(h20,g10,1,1);
 TH1F* h2= new TH1F("h2","",nbin,bini,bini+nbin*binw); // light neg / light pos
       h2->Divide(g19,h29,1,1);
 TH1F* sf= new TH1F("sf","",nbin,bini,bini+nbin*binw); // sign flip
       sf->Add(h1,h2,Xip,-Xip);

// systematics due to V0

 TH1F* h71= new TH1F("h71","",nbin,bini,bini+nbin*binw); // K0 neg / all neg
       h71->Divide(h110,i10,1,1,"B");
 TH1F* h72= new TH1F("h72","",nbin,bini,bini+nbin*binw); // light K0 pos / light pos
       h72->Divide(h129,i29,1,1,"B");
 TH1F* h73= new TH1F("h73","",nbin,bini,bini+nbin*binw); // light K0 / light
       h73->Divide(h109,i09,1,1,"B");
 TH1F* h74= new TH1F("h74","",nbin,bini,bini+nbin*binw); // K0 / all
       h74->Divide(h100,i00,1,1,"B");

 TH1F* h81= new TH1F("h81","",nbin,bini,bini+nbin*binw); // Bad neg / all neg
       h81->Divide(h210,i10,SFbad,1,"B");
 TH1F* h82= new TH1F("h82","",nbin,bini,bini+nbin*binw); // light Bad pos / light pos
       h82->Divide(h229,i29,SFbad,1,"B");
 TH1F* h83= new TH1F("h83","",nbin,bini,bini+nbin*binw); // light Bad / light
       h83->Divide(h209,i09,SFbad,1,"B");
 TH1F* h84= new TH1F("h84","",nbin,bini,bini+nbin*binw); // Bad / all
       h84->Divide(h200,i00,SFbad,1,"B");

 TH1F* h91= new TH1F("h91","",nbin,bini,bini+nbin*binw); // gamma neg / all neg
       h91->Divide(h310,i10,1,1,"B");
 TH1F* h92= new TH1F("h92","",nbin,bini,bini+nbin*binw); // light gamma pos / light pos
       h92->Divide(h329,i29,1,1,"B");
 TH1F* h93= new TH1F("h93","",nbin,bini,bini+nbin*binw); // light gamma / light
       h93->Divide(h309,i09,1,1,"B");
 TH1F* h94= new TH1F("h94","",nbin,bini,bini+nbin*binw); // gamma / all
       h94->Divide(h300,i00,1,1,"B");

 TH1F* ka = new TH1F("ka","",nbin,bini,bini+nbin*binw);
 TH1F* bad = new TH1F("bad","",nbin,bini,bini+nbin*binw);
 TH1F* ga = new TH1F("ga","",nbin,bini,bini+nbin*binw);
 TH1F* v0 = new TH1F("v0","",nbin,bini,bini+nbin*binw);

       for (int i=1; i<nbin+1; i++) {
	float y    = h72->GetBinContent(i) - h71->GetBinContent(i);
	             - h73->GetBinContent(i) + h74->GetBinContent(i);
	y = Xv * TMath::Abs( y );
	float ey = h71->GetBinError(i)*h71->GetBinError(i) 
	           + h72->GetBinError(i)*h72->GetBinError(i);
	ey = Xv * TMath::Sqrt( ey );
        ka->SetBinContent(i,y);
        ka->SetBinError(i,ey);
       }
       for (int i=1; i<nbin+1; i++) {
	float y    = h82->GetBinContent(i) - h81->GetBinContent(i);
	             - h83->GetBinContent(i) + h84->GetBinContent(i);
	y = Xbad * TMath::Abs( y );
	float ey = h81->GetBinError(i)*h81->GetBinError(i) 
	           + h82->GetBinError(i)*h82->GetBinError(i);
	ey = Xbad * TMath::Sqrt( ey );
        bad->SetBinContent(i,y);
        bad->SetBinError(i,ey);
       }
       for (int i=1; i<nbin+1; i++) {
	float y    = h92->GetBinContent(i) - h91->GetBinContent(i);
	             - h93->GetBinContent(i) + h94->GetBinContent(i);
	y = Xv * TMath::Abs( y );
	float ey = h91->GetBinError(i)*h91->GetBinError(i) 
	           + h92->GetBinError(i)*h92->GetBinError(i);
	ey = Xv * TMath::Sqrt( ey );
        ga->SetBinContent(i,y);
        ga->SetBinError(i,ey);
       }
       for (int i=1; i<nbin+1; i++) {
	float y = ka->GetBinContent(i)*ka->GetBinContent(i) 
	          + ga->GetBinContent(i)*ga->GetBinContent(i);
	y = TMath::Sqrt( y );
	float ey = ka->GetBinError(i)*ka->GetBinError(i) 
	           + ga->GetBinError(i)*ga->GetBinError(i);
	ey = TMath::Sqrt( ey );
        v0->SetBinContent(i,y);
        v0->SetBinError(i,ey);
       }

 TH1F* tot= new TH1F("tot","",nbin,bini,bini+nbin*binw);
       for (int i=1; i<nbin+1; i++) {
        float ybb = bb->GetBinContent(i);
        float ycc = cc->GetBinContent(i);
        float ygg = gg->GetBinContent(i);
        float ysf = sf->GetBinContent(i);
        float yv0 = v0->GetBinContent(i);
        float ybad = bad->GetBinContent(i);
        float y = ybb + ycc;
	y = TMath::Sqrt( y*y + ygg*ygg + ysf*ysf + yv0*yv0 + ybad*ybad );
        float eybb = bb->GetBinError(i);
        float eycc = cc->GetBinError(i);
        float eygg = gg->GetBinError(i);
        float eysf = sf->GetBinError(i);
        float eyv0 = v0->GetBinError(i);
        float eybad = bad->GetBinError(i);
        float ey = eybb + eycc;
	ey = TMath::Sqrt( ey*ey + eygg*eygg + eysf*eysf + eyv0*eyv0 + eybad*eybad );
        tot->SetBinContent(i,y);
        tot->SetBinError(i,ey);
       }

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Mistag in Data = all neg data * Rlight

 TF1 *Fun = new TF1("Fun","[0]+[1]*x+[2]*x*x",bini,bini+nbin*binw);
//  TF1 *Fun = new TF1("Fun","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",bini,bini+nbin*binw);
      Fun->SetLineColor(1);
      Fun->SetLineStyle(1);
 TF1 *Gun = new TF1("Gun","[0]+[1]*x+[2]*x*x",bini,bini+nbin*binw);
//  TF1 *Gun = new TF1("Gun","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",bini,bini+nbin*binw);
      Gun->SetLineColor(1);
      Gun->SetLineStyle(2);
 TF1 *Hun = new TF1("Hun","[0]+[1]*x+[2]*x*x",bini,bini+nbin*binw);
//  TF1 *Hun = new TF1("Hun","[0]+[1]*x+[2]*x*x+[3]*x*x*x+[4]*x*x*x*x",bini,bini+nbin*binw);
      Hun->SetLineColor(1);
      Hun->SetLineStyle(2);

       f0->cd();
 TH1F* H00 = (TH1F*)gROOT->FindObject("hAllFlav_Veto_JetPt");   // all with veto
 TH1F* H10 = (TH1F*)gROOT->FindObject("hAllFlav_Veto_NegTag_JetPt");   // all neg with veto
       H00->Sumw2(); 
       H10->Sumw2(); 

 TH1F* H5= new TH1F("H5","",nbin,bini,bini+nbin*binw);  // all neg with veto / all with veto
       H5->Divide(H10,H00,1,1,"B");
 TH1F* Mistag= new TH1F("Mistag","",nbin,bini,bini+nbin*binw);  // mistag data
       Mistag->Multiply(H5,Rlight,1,1); 
 TH1F* MisMax= new TH1F("MisMax","",nbin,bini,bini+nbin*binw);  // mistag data up
 TH1F* MisMin= new TH1F("MisMin","",nbin,bini,bini+nbin*binw);  // mistag data down

// MC Truth in "Data"

 TH1F* G09 = (TH1F*)gROOT->FindObject("hLightFlav_JetPt"); // udsg-jet
 TH1F* H29 = (TH1F*)gROOT->FindObject("hLightFlav_PosTag_JetPt"); // udsg pos
       G09->Sumw2(); 
       H29->Sumw2(); 
 TH1F* H4= new TH1F("H4","",nbin,bini,bini+nbin*binw);  // light pos / light
       H4->Divide(H29,G09,1,1,"B"); 

     pad1->cd();
       Mistag->Draw("E"); 
       Mistag->SetLineColor(1);
       Mistag->SetMarkerStyle(20);
       Mistag->SetMarkerColor(1);
       Mistag->SetMarkerSize(1.);
       H4->Draw("Esame");
       H4->SetLineColor(6);
       H4->SetMarkerStyle(21);
       H4->SetMarkerColor(6);
       H4->SetMarkerSize(1.1);
       Mistag->GetXaxis()->SetLabelSize(0.06);
       Mistag->GetYaxis()->SetLabelSize(0.06);
       Mistag->GetXaxis()->SetTitleSize(0.06);
       Mistag->GetXaxis()->SetTitle(xtitle);
       Mistag->GetXaxis()->SetTitleColor(1);
//        Mistag->SetMinimum(0.04); Mistag->SetMaximum(0.4); // Loose
//        Mistag->SetMinimum(0.002); Mistag->SetMaximum(0.05); // Medium
       Mistag->SetMinimum(0.0001); Mistag->SetMaximum(0.02); // Tight
//        Mistag->SetMinimum(0.0001); Mistag->SetMaximum(1.00);
       Mistag->GetXaxis()->SetNdivisions(509);
       Mistag->GetYaxis()->SetNdivisions(509);
       Mistag->Draw("Esame"); 
       Mistag->Fit("Fun","rvee"); 
       H4->Draw("Esame"); 
       Mistag->Draw("Esame"); 
       Fun->Draw("same"); 

       for (int i=1; i<nbin+1; i++) {
	float y = Mistag->GetBinContent(i);
	float ey = Mistag->GetBinError(i);
	float syst = y * tot->GetBinContent(i);
        float stat = Fun->IntegralError(bini+(i-1)*binw,bini+i*binw) / binw;
        float eror = TMath::Sqrt( syst*syst + stat*stat);
	MisMax->SetBinContent(i,y + eror);
	MisMax->SetBinError(i,ey);
	MisMin->SetBinContent(i,y - eror);
	MisMin->SetBinError(i,ey);
	if ( y > 0. ) {
	  MisMax->SetBinError(i,ey * (1. + eror/y ));
	  MisMin->SetBinError(i,ey * (1. - eror/y ));
	}
//$$
    cout << i << " Mistag " << y << " syst " << syst << " stat " << stat << endl;
//$$
	BinMin[i] = bini+(i-1)*binw;
	BinMax[i] = bini+i*binw;
	Leff[i] = Fun->Integral(BinMin[i],BinMax[i]) / binw;;
       }

       MisMax->Fit("Gun","rvee0");
       Gun->Draw("same"); 
       for (int i=1; i<nbin+1; i++) {
	LeffMax[i] = Gun->Integral(BinMin[i],BinMax[i]) / binw;
       }

       MisMin->Fit("Hun","rvee0");
       Hun->Draw("same"); 
       for (int i=1; i<nbin+1; i++) {
	LeffMin[i] = Hun->Integral(BinMin[i],BinMax[i]) / binw;
	LeffErr[i] = (LeffMax[i] - LeffMin[i]) / 2.;
//$$
    cout << BinMin[i] << " " << BinMax[i] << " " 
         << " Light Eff " << int(Leff[i]*1e6)/1e6 << " +_ " << int(LeffErr[i]*1e6)/1e6 << endl;
//$$
       }

  TLegend* leg = new TLegend(0.20,0.73,0.50,0.93);
    leg->SetHeader("Mistag");
    leg->AddEntry(Mistag,"DATA","P");
    leg->AddEntry(H4,"MC truth","P");
    leg->Draw();

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Data/MC Scale Factor

 TF1 *FUn = new TF1("FUn","[0]",bini,bini+nbin*binw);
      FUn->SetLineColor(1);
      FUn->SetLineStyle(1);
 TF1 *GUn = new TF1("GUn","[0]+[1]*x+[2]*x*x",bini,bini+nbin*binw);
      GUn->SetLineColor(1);
      GUn->SetLineStyle(2);
 TF1 *HUn = new TF1("HUn","[0]+[1]*x+[2]*x*x",bini,bini+nbin*binw);
      HUn->SetLineColor(1);
      HUn->SetLineStyle(2);

 TH1F* SFlight= new TH1F("SFlight","",nbin,bini,bini+nbin*binw);  // Scale Factor
       SFlight->Divide(H5,h5,1,1); 
 TH1F* SFmax= new TH1F("SFmax","",nbin,bini,bini+nbin*binw);  // SF up
 TH1F* SFmin= new TH1F("SFmin","",nbin,bini,bini+nbin*binw);  // SF down

     pad2->cd();
       SFlight->Draw("E"); 
       SFlight->SetLineColor(1);
       SFlight->SetMarkerStyle(20);
       SFlight->SetMarkerColor(1);
       SFlight->SetMarkerSize(1.);
       SFlight->GetXaxis()->SetLabelSize(0.06);
       SFlight->GetYaxis()->SetLabelSize(0.06);
       SFlight->GetXaxis()->SetTitleSize(0.06);
       SFlight->GetXaxis()->SetTitle(xtitle);
       SFlight->GetXaxis()->SetTitleColor(1);
       SFlight->SetMinimum(0.); 
       SFlight->SetMaximum(2.);
       SFlight->GetXaxis()->SetNdivisions(509);
       SFlight->GetYaxis()->SetNdivisions(509);
       SFlight->Draw("Esame"); 
       SFlight->Fit("FUn","rvee"); 
       FUn->Draw("same"); 

       for (int i=1; i<nbin+1; i++) {
	float y = SFlight->GetBinContent(i);
	float ey = SFlight->GetBinError(i);
	float syst = y * tot->GetBinContent(i);
        float eror = TMath::Sqrt( syst*syst + ey*ey);
        float yfit = FUn->Integral(bini+(i-1)*binw,bini+i*binw) / binw;
	SFmax->SetBinContent(i,yfit + eror);
	SFmax->SetBinError(i,ey);
	SFmin->SetBinContent(i,yfit - eror);
	SFmin->SetBinError(i,ey);
//$$
//$$    cout << i << " SF " << y << " syst " << syst << " stat " << stat << endl;
//$$
	Lsf[i] = FUn->Integral(BinMin[i],BinMax[i]) / binw;
       }

       SFmax->Fit("GUn","rvee0");
       GUn->Draw("same"); 
       for (int i=1; i<nbin+1; i++) {
	LsfMax[i] = GUn->Integral(BinMin[i],BinMax[i]) / binw;
       }

       SFmin->Fit("HUn","rvee0");
       HUn->Draw("same"); 
       for (int i=1; i<nbin+1; i++) {
	LsfMin[i] = HUn->Integral(BinMin[i],BinMax[i]) / binw;
	LsfErr[i] = (LsfMax[i] - LsfMin[i]) / 2.;
//$$
    cout << BinMin[i] << " " << BinMax[i] << " " 
         << " Light SF " << int(Lsf[i]*1e6)/1e6 << " +_ " << int(LsfErr[i]*1e6)/1e6 << endl;
//$$
       }

  TLegend* leg = new TLegend(0.20,0.78,0.50,0.93);
    leg->SetHeader("Scale Factor");
    leg->AddEntry(SFlight,"Neg.Tag Data/MC","P");
    leg->Draw();
    
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Write the ascii file

       string blabla_file = "Mistag.txt";

       ofstream out_txt(blabla_file.c_str(), ios::out);

       out_txt << TaggerName << endl; // < ---the tagger name
       out_txt << wp << endl; // <---- the WP cut on the discriminator
       out_txt << "PerformancePayloadFromTable" << endl;
       out_txt << 4 << endl; // <---- # of results, lighteff and lightefferr
       out_txt << 2 << endl; // <---- # of variables to bin (eta and pt)
       out_txt << "1005 1006 1013 1014" << endl; // <----- results are light eff +_ error, light SF +_ error
       out_txt << "5 2" << endl; // <----- binning is |eta| / pt
       for (int i=1; i<nbin+1; i++) { // <----- eta and Et ranges, light eff +_ error, light SF +_ error
        if (EtaMin == 0 && BinMin[i] < 100 && BinMax[i] < 100) {  
          out_txt << EtaMin    << "       " << EtaMax     << "      " 
                  << BinMin[i] << "      " << BinMax[i]  << "     " 
	          << int(Leff[i]*1e6)/1e6   << "     " << int(LeffErr[i]*1e6)/1e6 << "     " 
	          << int(Lsf[i]*1e6)/1e6    << "     " << int(LsfErr[i]*1e6)/1e6  << endl;
	}
        else if (EtaMin == 0 && BinMin[i] < 100) {  
          out_txt << EtaMin    << "       " << EtaMax     << "      " 
                  << BinMin[i] << "     " << BinMax[i]  << "     " 
	          << int(Leff[i]*1e6)/1e6   << "     " << int(LeffErr[i]*1e6)/1e6 << "     " 
	          << int(Lsf[i]*1e6)/1e6    << "     " << int(LsfErr[i]*1e6)/1e6  << endl;
	}
        else if (EtaMin == 0) {  
          out_txt << EtaMin    << "       " << EtaMax     << "     " 
                  << BinMin[i] << "     " << BinMax[i]  << "     " 
	          << int(Leff[i]*1e6)/1e6   << "     " << int(LeffErr[i]*1e6)/1e6 << "     " 
	          << int(Lsf[i]*1e6)/1e6    << "     " << int(LsfErr[i]*1e6)/1e6  << endl;
	}
        else if (BinMin[i] < 100 && BinMax[i] < 100) {  
          out_txt << EtaMin    << "     " << EtaMax     << "      " 
                  << BinMin[i] << "      " << BinMax[i]  << "     " 
	          << int(Leff[i]*1e6)/1e6   << "     " << int(LeffErr[i]*1e6)/1e6 << "     " 
	          << int(Lsf[i]*1e6)/1e6    << "     " << int(LsfErr[i]*1e6)/1e6  << endl;
	}
        else if (BinMin[i] < 100) {  
          out_txt << EtaMin    << "     " << EtaMax     << "      " 
                  << BinMin[i] << "     " << BinMax[i]  << "     " 
	          << int(Leff[i]*1e6)/1e6   << "     " << int(LeffErr[i]*1e6)/1e6 << "     " 
	          << int(Lsf[i]*1e6)/1e6    << "     " << int(LsfErr[i]*1e6)/1e6  << endl;
	}
        else {  
          out_txt << EtaMin    << "     " << EtaMax     << "     " 
                  << BinMin[i] << "     " << BinMax[i]  << "     " 
	          << int(Leff[i]*1e6)/1e6   << "     " << int(LeffErr[i]*1e6)/1e6 << "     " 
	          << int(Lsf[i]*1e6)/1e6    << "     " << int(LsfErr[i]*1e6)/1e6  << endl;
	}
       }

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

  c1->Update();
}
Exemple #4
0
void MakeMinvMix(Int_t cen=6){

  TFile fout("raw_MBmix.root","update") ;
  TFile * f = new TFile("LHC13bc_MB.root") ; //result of data scan
  

  TH1F * hev = (TH1F*)f->Get("hSelEvents") ;
  TH1F * hCentrality1  = (TH1F*)f->Get("hCentrality") ;
  
  printf("TotSelEvents: %f \n",hev->GetBinContent(7)) ;
  printf("Centrality:   %f \n",hCentrality1->Integral()) ;

   Int_t nbin=33 ;
   Double_t xa[34] ={0.8,1.0,1.2,1.4,1.6, 1.8,2.0,2.2,2.4,2.6, 2.8,3.0,3.2,3.4,3.6, 3.8,4.0,4.5,5.0,5.5, 6.,7.,8.,10.,12.,16.,20.,22.,  24.,26.,28.,30.,35.,  40.};
//    Int_t nbin=26 ;
//    Double_t xa[27] ={0.8,1.0,1.2,1.4,1.6, 1.8,2.0,2.2,2.4,2.6, 2.8,3.0,3.2,3.4,3.6, 3.8,4.0,4.5,5.0,5.5, 6.,7.,8.,10.,12.,16.,20.};
   
  const Int_t nPID=4 ;
  char cPID[14][15] ;
  snprintf(cPID[0],15,"Emin3_All") ;
  snprintf(cPID[1],15,"Emin3_Disp");
  snprintf(cPID[2],15,"Emin3_CPV") ;
  snprintf(cPID[3],15,"Emin3_Both"); 

  TH2F * hRe[20] ;
  TH2F * hMi[20] ;
  TH2F * tmp = 0x0 ;
  if(cen==6){ //6:0-20, 7:0-10
      for(Int_t iPID=0;iPID<nPID;iPID++){
	hRe[iPID] = (TH2F*)f->Get(Form("hInvM_Re_%s_cent0",cPID[iPID])) ;
        tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent1",cPID[iPID])) ;
        hRe[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent2",cPID[iPID])) ;
        hRe[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent3",cPID[iPID])) ;
        hRe[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Re_%s_cent4",cPID[iPID])) ;
        hRe[iPID]->Add(tmp) ;delete tmp ;
        hRe[iPID]->Sumw2() ;	
	
	hMi[iPID] = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent0",cPID[iPID])) ;
        tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent1",cPID[iPID])) ;
        hMi[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent2",cPID[iPID])) ;
        hMi[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent3",cPID[iPID])) ;
        hMi[iPID]->Add(tmp) ;delete tmp ;
        tmp = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent4",cPID[iPID])) ;
        hMi[iPID]->Add(tmp) ;delete tmp ;
        hMi[iPID]->Sumw2() ;	
      }
  }
  else{
      for(Int_t iPID=0;iPID<nPID;iPID++){
	hRe[iPID] = (TH2F*)f->Get(Form("hInvM_Re_%s_cent%d",cPID[iPID],cen)) ;	
        hRe[iPID]->Sumw2() ;	
	hMi[iPID] = (TH2F*)f->Get(Form("hInvM_Mi_%s_cent%d",cPID[iPID],cen)) ;
        hMi[iPID]->Sumw2() ;	
      }    
  }
      
  PPRstyle();
  gStyle->SetPadLeftMargin(0.14);
  gStyle->SetPadRightMargin(0.01);
  gStyle->SetPadTopMargin(0.01);
  gStyle->SetPadBottomMargin(0.08);


  //Gaus
  TH1D *mr1[nPID],*sr1[nPID],*nr1[nPID],*nr1int[nPID] ;
  for(Int_t iPID=0;iPID<nPID;iPID++){
    mr1[iPID] = new TH1D(Form("mass1_GS_%s_cen%d",cPID[iPID],cen),"Mass",nbin,xa) ;
    sr1[iPID] = new TH1D(Form("width1_GS_%s_cen%d",cPID[iPID],cen),"Width",nbin,xa) ;
    nr1[iPID] = new TH1D(Form("yeild1_GS_%s_cen%d",cPID[iPID],cen),"Raw yield",nbin,xa) ;
    nr1int[iPID] = new TH1D(Form("yeild1_int_GS_%s_cen%d",cPID[iPID],cen),"Raw yield, integrated",nbin,xa) ;
  }

  //CB
  TH1D *mr2[nPID],*sr2[nPID],*nr2[nPID],*nr2int[nPID] ;
  for(Int_t iPID=0;iPID<nPID;iPID++){  
    mr2[iPID] = new TH1D(Form("mass2_CB_%s_cen%d",cPID[iPID],cen),"Mass",nbin,xa) ;
    sr2[iPID] = new TH1D(Form("width2_CB_%s_cen%d",cPID[iPID],cen),"Width",nbin,xa) ;
    nr2[iPID] = new TH1D(Form("yeild2_CB_%s_cen%d",cPID[iPID],cen),"Raw yield",nbin,xa) ;
    nr2int[iPID] = new TH1D(Form("yeild2_int_CB_%s_cen%d",cPID[iPID],cen),"Raw yield, integrated",nbin,xa) ;
  }

  TF1 * fun1 = new TF1("ft1",CB1,0.,1.,8) ;
  fun1->SetParName(0,"A") ;
  fun1->SetParName(1,"m_{0}") ;
  fun1->SetParName(2,"#sigma") ;
  fun1->SetParName(3,"n") ;
  fun1->SetParName(4,"#alpha") ;
  fun1->SetParName(5,"a_{0}") ;
  fun1->SetParName(6,"a_{1}") ;
  fun1->SetParName(7,"a_{2}") ;
  fun1->FixParameter(3,3.28) ;
  fun1->FixParameter(4,1.56) ;
  fun1->SetLineWidth(2) ;
  fun1->SetLineColor(4) ;
  fun1->SetLineStyle(2) ;

  TF1 * fun2 = new TF1("ft2",CB2,0.,1.,9) ;
  fun2->SetParName(0,"A") ;
  fun2->SetParName(1,"m_{0}") ;
  fun2->SetParName(2,"#sigma") ;
  fun2->SetParName(3,"n") ;
  fun2->SetParName(4,"#alpha") ;
  fun2->SetParName(5,"a_{0}") ;
  fun2->SetParName(6,"a_{1}") ;
  fun2->SetParName(7,"a_{2}") ;
  fun2->SetParName(8,"a_{3}") ;
  fun2->FixParameter(3,3.28) ;
  fun2->FixParameter(4,1.56) ;
  fun2->SetLineWidth(2) ;
  fun2->SetLineColor(4) ;
  fun2->SetLineStyle(2) ;
  
  TF1 * funGS1 = new TF1("ft1",GS1,0.,1.,6) ;
  funGS1->SetParName(0,"A") ;
  funGS1->SetParName(1,"m_{0}") ;
  funGS1->SetParName(2,"#sigma") ;
  funGS1->SetParName(3,"a_{0}") ;
  funGS1->SetParName(4,"a_{1}") ;
  funGS1->SetParName(5,"a_{2}") ;
  funGS1->SetLineWidth(2) ;
  funGS1->SetLineColor(8) ;
//   funGS1->SetLineStyle(2) ;

  TF1 * funGS2 = new TF1("ft2",GS2,0.,1.,7) ;
  funGS2->SetParName(0,"A") ;
  funGS2->SetParName(1,"m_{0}") ;
  funGS2->SetParName(2,"#sigma") ;
  funGS2->SetParName(3,"a_{0}") ;
  funGS2->SetParName(4,"a_{1}") ;
  funGS2->SetParName(5,"a_{2}") ;
  funGS2->SetParName(6,"a_{3}") ;
  funGS2->SetLineWidth(2) ;
  funGS2->SetLineColor(8) ;
//   funGS2->SetLineStyle(2) ;
  
  
  
  TF1 * fit1=0x0 ;
  TF1 * fit2=0x0 ;
  
  TF1 * fbgP0 = new TF1("bg",BG,0.,1.,2) ;
  TF1 * fbgP1 = new TF1("bg1",BG1,0.,1.,3) ;
  TF1 * fbgP2 = new TF1("bg2",BG2,0.,1.,4) ;
  TF1 * fbg1=0x0 ;
  TF1 * fbg2=0x0 ;
  TF1 * fgs = new TF1("gs",GSs,0.,1.,4) ;
  TF1 * fcb = new TF1("cb",CBs,0.,1.,6) ;
  fgs->SetLineColor(8) ;
  fgs->SetLineWidth(2) ;
  fcb->SetLineColor(4) ;
  fcb->SetLineWidth(2) ;
  fcb->SetLineStyle(2) ;
  fcb->FixParameter(3,3.28) ;
  fcb->FixParameter(4,1.56) ;

  TCanvas * c1[nPID] ;
  TCanvas * c2[nPID] ;
  TCanvas * c1b[nPID] ;
  TCanvas * c2b[nPID] ;
  for(Int_t iPID=0;iPID<nPID;iPID++){
    c1[iPID] = new TCanvas(Form("Ratio_%s",cPID[iPID]),Form("Ratio_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ;
    c1[iPID]->Divide(4,4) ;
    c2[iPID] = new TCanvas(Form("Signal_%s",cPID[iPID]),Form("Signal_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ;
    c2[iPID]->Divide(4,4) ;
    c1b[iPID] = new TCanvas(Form("RatioB_%s",cPID[iPID]),Form("Ratio_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ;
    c1b[iPID]->Divide(4,3) ;
    c2b[iPID] = new TCanvas(Form("SignalB_%s",cPID[iPID]),Form("Signal_%s",cPID[iPID]),10+10*iPID,10,1200+10*iPID,800) ;
    c2b[iPID]->Divide(4,3) ;
  }
  c1[0]->cd(0) ;

  TAxis * pta=hRe[0]->GetYaxis() ;
  TAxis * ma=hRe[0]->GetXaxis() ;
    
  for(Int_t i=1;i<=nbin;i++){
    Int_t imin=pta->FindBin(xa[i-1]+0.0001);
    Int_t imax=pta->FindBin(xa[i]-0.0001) ;
    TH1D *hp;
    Double_t pt=(xa[i]+xa[i-1])/2. ;
        
    for(Int_t iPID=0;iPID<nPID;iPID++){
      if(i<17)
        c1[iPID]->cd(i) ;
      else
        c1b[iPID]->cd(i-16) ;
      hp = hRe[iPID]->ProjectionX(Form("re%d_%d",i,iPID),imin,imax) ;
//      hp->Sumw2() ;
      hpm= hMi[iPID]->ProjectionX(Form("mi%d_%d",i,iPID),imin,imax) ;
//      hpm->Sumw2() ;
      if(pt>12.){
    hp ->Rebin(2) ;
    hpm->Rebin(2) ;
      }
    if(pt<2.){ //2pol,3pol
      fit1=funGS2 ;
      fit2=fun2 ;
      fbg1=fbgP2 ;
      fbg2=fbgP2 ;
      
    }
    else{ //pol1,pol2
      fit1=funGS1 ;
      fit2=fun1 ;
      fbg1=fbgP1 ;
      fbg2=fbgP1 ;
      
    }
    
//      for(Int_t ib=1; ib<=hp->GetNbinsX();ib++){if(hp ->GetBinContent(ib)==0)hp ->SetBinError(ib,1.);}
//      for(Int_t ib=1; ib<=hp->GetNbinsX();ib++){if(hpm->GetBinContent(ib)==0)hpm->SetBinError(ib,1.);}
      TH1D * hpm2   = (TH1D*)hpm->Clone(Form("Bg1_%d",iPID)) ;
      TH1D * hpcopy = (TH1D*)hp ->Clone(Form("hpcopy_%d",iPID)) ;
      TH1D * hp2    = (TH1D*)hp ->Clone(Form("hp2_%d",iPID)) ;
      hpcopy->SetXTitle("M_{#gamma#gamma} (GeV/c^{2})");
      hp2   ->SetXTitle("M_{#gamma#gamma} (GeV/c^{2})");
      hpcopy->Divide(hpm) ;
      hpcopy->SetTitle(Form("%3.1f<p_{T}<%3.1f GeV/c",xa[i-1],xa[i])) ;
      hpcopy->SetMarkerStyle(20) ;
      hpcopy->SetMarkerSize(0.7) ;
      hpcopy->GetXaxis()->SetRangeUser(0.05,0.25) ;
      
//      fit1->SetParameters(0.0002+0.0001*i*i,0.136,0.011,0.0002,-0.002,0.0) ;
      fit1->SetParameters(0.0002+0.0001*i*i,0.136,0.005,0.0002,-0.002,0.0) ;
//      fit1->SetParameters(0.0002,0.136,0.011,0.0002,-0.002,0.0) ;
      if(cen==0)
        fit1->SetParameters(0.001,0.146,0.005,0.12,-0.002,0.0) ;
      fit1->SetParLimits(0,0.000,2.*hpcopy->GetMaximum()) ;
      fit1->SetParLimits(1,0.125,0.145) ;
      fit1->SetParLimits(2,0.0045,0.010) ;

      Double_t rangeMin=0.07 ;//TMath::Max(0.06,0.11-0.01*i) ;
      Double_t rangeMax=0.22; //TMath::Min(0.25,0.18+0.01*i) ;
//       if(pt>10){
//         rangeMax=0.18; 
//         rangeMin=0.10; 
//       }
//      Double_t rangeMin=TMath::Max(0.06,0.12-0.01*i) ;
//      Double_t rangeMax=TMath::Min(0.25,0.16+0.01*i) ;

      hpcopy->Fit(fit1,"Q","",rangeMin,rangeMax) ;
      hpcopy->Fit(fit1,"MQ","",rangeMin,rangeMax) ;

      fit2->SetParameters(fit1->GetParameters()) ;
      fit2->SetParameter(3,3.2) ;
      fit2->SetParameter(4,1.56) ;
      fit2->SetParameter(5,fit1->GetParameter(3)) ;
      fit2->SetParameter(6,fit1->GetParameter(4)) ;
      fit2->SetParameter(7,fit1->GetParameter(5)) ;      
      fit2->SetParLimits(0,0.000,2.*hpcopy->GetMaximum()) ;
      fit2->SetParLimits(1,0.125,0.145) ;
      fit2->SetParLimits(2,0.0045,0.010) ;
      
      hpcopy->Fit(fit2,"+QN","",rangeMin,rangeMax) ;
      hpcopy->Fit(fit2,"+MQ","",rangeMin,rangeMax) ;
      c1[iPID]->cd(i) ;
      hpcopy->Draw() ;
      if(i<17)
        c1[iPID]->Update() ;
      else
        c1b[iPID]->Update() ;

      if(i<17)
        c2[iPID]->cd(i) ;
      else
        c2b[iPID]->cd(i-16) ;
      
      fbg1->SetParameters(fit1->GetParameter(3),fit1->GetParameter(4),fit1->GetParameter(5),fit1->GetParameter(6)); 
      fbg2->SetParameters(fit2->GetParameter(5),fit2->GetParameter(6),fit2->GetParameter(7),fit2->GetParameter(8)); 
      
      Double_t intRangeMin = PeakPosition(pt)-3.*PeakWidth(pt) ;
      Double_t intRangeMax = PeakPosition(pt)+3.*PeakWidth(pt) ;
      Int_t    intBinMin   = hp->GetXaxis()->FindBin(intRangeMin) ;
      Int_t    intBinMax   = hp->GetXaxis()->FindBin(intRangeMax) ;
      Double_t errStat     = hpm->Integral(intBinMin,intBinMax); 

      hpm ->Multiply(fbg1) ;
      hpm2->Multiply(fbg2) ;
      if(pt<10.){
        hp  ->Add(hpm ,-1.) ;
        hp2 ->Add(hpm2,-1.) ;
      }
      
      Int_t binPi0 = hp->FindBin(kMean);
      fgs->SetParameters(hp->Integral(binPi0-1,binPi0+1)/3.,fit1->GetParameter(1),0.006) ;
      fgs->SetParLimits(0,0.000,10.*hp->GetMaximum()) ;
      fgs->SetParLimits(1,0.120,0.175) ;
      fgs->SetParLimits(2,0.0055,0.010) ;
      hp->Fit(fgs,"QL","",rangeMin,rangeMax) ;   
      hp->Fit(fgs,"QML","",rangeMin,rangeMax) ;   
      hp->SetMaximum(hp->GetMaximum()*1.4) ;
      hp->SetMinimum(hp->GetMinimum()*1.1) ;
      hp->SetMarkerStyle(20) ;
      hp->SetMarkerSize(0.7) ;
      mr1[iPID]->SetBinContent(i,fgs->GetParameter(1)) ;
      mr1[iPID]->SetBinError  (i,fgs->GetParError(1) ) ;
      sr1[iPID]->SetBinContent(i,TMath::Abs(fgs->GetParameter(2))) ;
      sr1[iPID]->SetBinError  (i,fgs->GetParError(2) ) ;

      Double_t y=fgs->GetParameter(0)/hp->GetXaxis()->GetBinWidth(1) ;
      nr1[iPID]->SetBinContent(i,y) ;
      Double_t ey=fgs->GetParError(0)/hp->GetXaxis()->GetBinWidth(1) ;
      nr1[iPID]->SetBinError(i,ey) ;

      Double_t npiInt = hp->Integral(intBinMin,intBinMax)-(intBinMax-intBinMin)*fgs->GetParameter(3) ;
      Double_t norm   = fbg1->GetParameter(0) ;
      Double_t normErr= fbg1->GetParError(0) ;
      if(npiInt>0.){
        nr1int[iPID]->SetBinContent(i,npiInt) ;
        nr1int[iPID]->SetBinError(i,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ;
      }
      
//printf(" Nint1 =%f+-%f \n",npiInt,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ;
      hp2->GetXaxis()->SetRangeUser(rangeMin,rangeMax) ;
      hp2->SetMaximum(hp2->GetMaximum()*1.4) ;
      hp2->SetMinimum(hp2->GetMinimum()*1.1) ;
      hp2->SetMarkerStyle(24) ;
      hp2->SetMarkerSize(0.8) ;

      fcb->SetParameters(hp->Integral(binPi0-1,binPi0+1)/3.,fit2->GetParameter(1),0.006,fit2->GetParameter(3),fit2->GetParameter(4)) ;
      fcb->SetParLimits(0,0.000,10.*hp->GetMaximum()) ;
      fcb->SetParLimits(1,0.120,0.175) ;
      fcb->SetParLimits(2,0.005,0.010) ;
      hp2->Fit(fcb,"QL","",rangeMin,rangeMax) ;
      hp2->Fit(fcb,"QML","",rangeMin,rangeMax) ;
      mr2[iPID]->SetBinContent(i,fcb->GetParameter(1)) ;
      mr2[iPID]->SetBinError  (i,fcb->GetParError(1)) ;
      sr2[iPID]->SetBinContent(i,TMath::Abs(fcb->GetParameter(2))) ;
      sr2[iPID]->SetBinError  (i,fcb->GetParError(2)) ;
      
      y=(fcb->Integral(0.05,0.25)-fcb->GetParameter(5)*(0.25-0.05))/hp->GetXaxis()->GetBinWidth(1) ;
      nr2[iPID]->SetBinContent(i,y) ;
      Double_t ey=fcb->IntegralError(0.05,0.25)/hp->GetXaxis()->GetBinWidth(1) ;
      nr2[iPID]->SetBinError(i,ey) ;
   
      npiInt=hp2->Integral(intBinMin,intBinMax)-(intBinMax-intBinMin)*fgs->GetParameter(3) ;
      norm=fbg2->GetParameter(0) ;
      normErr=fbg2->GetParError(0) ;
      if(npiInt>0.){
        nr2int[iPID]->SetBinContent(i,npiInt) ;
        nr2int[iPID]->SetBinError(i,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ;
      } 
//printf(" Nint2 =%f+-%f \n",npiInt,TMath::Sqrt(npiInt + norm*errStat + normErr*normErr*errStat*errStat + norm*norm*errStat)) ;
      hp2->SetTitle(Form("%3.1f<p_{T}<%3.1f GeV/c",xa[i-1],xa[i])) ;
      hp2->Draw() ;
      hp->SetMarkerColor(6) ;
      hp->Draw("same") ;
      hp2->Draw("same") ;
      c2[iPID]->Update() ;

//      delete hp ;
//    delete hp2 ;
//    delete hpcopy ;
      delete hpm ;
//      delete hpm2 ;
      
    }
  }
/*  
  for(Int_t iPID=0; iPID<4; iPID++){
   c1[iPID]->Print(Form("Ratio_%s_cen%d.eps",cPID[iPID],cen)) ;
   c2[iPID]->Print(Form("Signal_%s_cen%d.eps",cPID[iPID],cen)) ;
  }
*/  
  //Normalize by the number of events
  Int_t cMin,cMax;
  if      (cen == 0) {
    cMin=1;
    cMax=20;
  }
  else if (cen == 1) {
    cMin=21;
    cMax=40;
  }
  else if (cen == 2) {
    cMin=41;
    cMax=60;
  }
  else if (cen == 3) {
    cMin=61;
    cMax=80;
  }
  else if (cen == 4) {
    cMin=81;
    cMax=100;
  }
  else if (cen == 5) {
    cMin=61;
    cMax=80;
  }
  else if (cen == 6) {
    cMin=1;
    cMax=100;
  }
  else if (cen == 7) {
    cMin=1;
    cMax=10;
  }
  else if (cen == 8) {
    cMin=41;
    cMax=80;
  }
  else if (cen == 9) {
    cMin=1;
    cMax=40;
  }
  Double_t nevents = hCentrality1->Integral(cMin,cMax);
  printf("Nevents=%f \n",nevents) ;
  for(Int_t iPID=0;iPID<nPID;iPID++){
    nr1[iPID]   ->Scale(1./nevents) ;
    nr1int[iPID]->Scale(1./nevents) ;
    nr2[iPID]   ->Scale(1./nevents) ;
    nr2int[iPID]->Scale(1./nevents) ;
    nr1[iPID]->SetMarkerStyle(20) ;
    nr1[iPID]->SetMarkerColor(2) ;
    nr1[iPID]->SetTitle("#pi^{0} raw yield per event") ;
    nr2[iPID]->SetTitle("#pi^{0} raw yield per event") ;
  }
  
  fout.cd() ;
  for(Int_t iPID=0;iPID<nPID;iPID++){
    nr1[iPID]->Write(0,TObject::kOverwrite) ;
    nr2[iPID]->Write(0,TObject::kOverwrite) ;
    nr1int[iPID]->Write(0,TObject::kOverwrite) ;
    nr2int[iPID]->Write(0,TObject::kOverwrite) ;
    mr1[iPID]->Write(0,TObject::kOverwrite) ;
    mr2[iPID]->Write(0,TObject::kOverwrite) ;
    sr1[iPID]->Write(0,TObject::kOverwrite) ;
    sr2[iPID]->Write(0,TObject::kOverwrite) ;
  }
  fout.Close() ;



}
Exemple #5
0
void fitToys2(){

  int count=0,countNotFail=0;

  gStyle->SetOptStat(0);

  TCanvas *c1 = new TCanvas("c1","c1",800,600);c1->cd();
  //TCanvas *c2 = new TCanvas("c2","c2",800,600);c2->cd();
  //c1->cd();

  TF1* fit = new TF1("fit","[0]*pow(x,[1])",103,163);
  fit->SetParameters(1.28542e+08,-3.90422);
  fit->SetParError(0,1.27534e+09);
  fit->SetParError(1,2.06166);

  TH1F* h_counts = new TH1F("h_counts","",2,0,2);
  TH1F* h_HiggsWindowFit = new TH1F("h_HiggsWindowFit","# events in Higgs window from fit",80,0,40);
  TH1F* h_pull = new TH1F("h_pull","(fit - generated)/(fit error)",160,-8,8);
  TH1F* h_pull_fail = new TH1F("h_pull_fail","(fit - generated)/(fit error)",160,-8,8);
  TH1F* h_pull_lowErr  = new TH1F("h_pull_lowErr","(fit - generated)/(fit error)",160,-8,8);
  TH1F* h_pull_highErr = new TH1F("h_pull_highErr","(fit - generated)/(fit error)",160,-8,8);
  TH1F* h_diff = new TH1F("h_diff","(fit - generated)",160,-40,40);
  TH1F* h_pullU = new TH1F("h_pullU","(fit - generated)/(fit error)",160,-8,8);
  TH1F* h_diffU = new TH1F("h_diffU","(fit - generated)",160,-40,40);
  TH1F* h_pullL = new TH1F("h_pullL","(fit - generated)/(fit error)",160,-8,8);
  TH1F* h_diffL = new TH1F("h_diffL","(fit - generated)",160,-40,40);
  h_pullL->SetLineColor(kRed);h_pullL->SetMarkerColor(kRed);
  h_diffL->SetLineColor(kRed);h_diffL->SetMarkerColor(kRed);
  h_pullU->SetLineColor(kBlue);h_pullU->SetMarkerColor(kBlue);
  h_diffU->SetLineColor(kBlue);h_diffU->SetMarkerColor(kBlue);
  h_pull_fail->SetFillColor(kRed);
  //  TRandom3 rr;

  for(int j=0;j<10;j++){
 
    TH1F* h = new TH1F("h","",60,103,163);
    for(int i=0;i<5200;i++){
      //for(int i=0;i<rr.Poisson(52);i++){
      h->Fill(fit->GetRandom(103,163));
    }
    
    //h->Draw("PE");
    
    reject=true;
    TF1* fitCurve = new TF1("fitCurve",fpow,103,163,2);
    
    Double_t avg_l = h->Integral(h->FindBin(103),h->FindBin(118))/float(118-103),avg_u = h->Integral(h->FindBin(133),h->FindBin(163))/float(163-133),avgX_l=(118-103)/2.,avgX_u=(163-133)/2.;
    cout<<avg_l<<"  "<<avg_u<<"  "<<avgX_l<<"  "<<avgX_u<<endl;
    Double_t param1= (log(avg_l) - log(avg_u))/(log(avgX_l) - log(avgX_u));
    Double_t param0= /*7e14;*/avg_l/pow(avgX_l, param1);
    cout<<"param0: "<<param0<<"  param1: "<<param1<<endl;
    fitCurve->SetParameter(0,param0);
    fitCurve->SetParameter(1,param1);
    int status = h->Fit(fitCurve,"L","",103,163);
    //Then to get the result
    TFitResultPtr fitResult = h->Fit(fitCurve,"SLLMEV0","",103,163);
    TMatrixDSym cov = fitResult->GetCovarianceMatrix();
    fitResult->Print("V");
    h->GetXaxis()->SetRangeUser(100,164.9);
    reject=false;
    float YieldBinWidth=h->GetBinWidth(1);
    Double_t PowYieldSig = h->Integral(h->FindBin(120),h->FindBin(131-.1))/YieldBinWidth;
    Double_t PowYieldSigFit = fitCurve->Integral(120,131)/YieldBinWidth;
    Double_t PowYieldSigFitErr = fitCurve->IntegralError(120,131,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; 
    Double_t PowSBloYield = h->Integral(h->FindBin(103),h->FindBin(118-.1))/YieldBinWidth;
    Double_t PowSBloYieldFit = fitCurve->Integral(103,118)/YieldBinWidth;
    Double_t PowSBloYieldFitErr = fitCurve->IntegralError(103,118,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; 
    Double_t PowSBhiYield = h->Integral(h->FindBin(133),h->FindBin(163-.1))/YieldBinWidth;
    Double_t PowSBhiYieldFit = fitCurve->Integral(133,163)/YieldBinWidth;
    Double_t PowSBhiYieldFitErr = fitCurve->IntegralError(133,163,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; 
    
    cout<<"gMinuit->fStatus : "<< gMinuit->fStatus <<"  gMinuit->fCstatu : "<< gMinuit->fCstatu<<endl;

    cout<<" low sideband yield from histo: "<<PowSBloYield<<"  and from fit: "<<PowSBloYieldFit<<" +- "<<PowSBloYieldFitErr<<endl; 
    cout<<" higgs window yield from histo: "<<PowYieldSig <<"  and from fit: "<<PowYieldSigFit<<" +- "<<PowYieldSigFitErr<<endl; 
    cout<<" high sideband yield from histo: "<<PowSBhiYield<<"  and from fit: "<<PowSBhiYieldFit<<" +- "<<PowSBhiYieldFitErr<<endl;
    reject=true;
    
    TString str = (TString)gMinuit->fCstatu;
    cout<<"str: "<<str;
    h_counts->Fill(0);
    if(str.Contains("FAILURE")){
      double pull_fail = (PowYieldSigFit-9.11)/PowYieldSigFitErr;
      h_pull_fail->Fill(pull_fail);
      //  continue;
    }
    h_counts->Fill(1);
    double pull = (PowYieldSigFit-9.11)/PowYieldSigFitErr;
    double pull_lowErr = (PowYieldSigFit-(9.11-1.6))/PowYieldSigFitErr;
    double pull_highErr = (PowYieldSigFit-(9.11+1.6))/PowYieldSigFitErr;
    double diff = (PowYieldSigFit-9.11);
    double pullL = (PowSBloYieldFit-PowSBloYield)/PowSBloYieldFitErr;
    double diffL = (PowSBloYieldFit-PowSBloYield);
    double pullU = (PowSBhiYieldFit-PowSBhiYield)/PowSBhiYieldFitErr;
    double diffU = (PowSBhiYieldFit-PowSBhiYield);
    h_pull->Fill(pull);
    h_pull_lowErr->Fill(pull_lowErr);
    h_pull_highErr->Fill(pull_highErr);
    h_diff->Fill(diff);
    h_pullU->Fill(pullU);
    h_diffU->Fill(diffU);
    h_pullL->Fill(pullL);
    h_diffL->Fill(diffL);
    h_HiggsWindowFit->Fill(PowYieldSigFit);
  }
  /*
  TFile fout("InvarMassFitToys.root","RECREATE");
  fout.cd();
  h_diff->Write();
  h_diffL->Write();
  h_diffU->Write();
  h_pull->Write();
  h_pull_lowErr->Write();
  h_pull_highErr->Write();
  h_pullL->Write();
  h_pullU->Write();
  h_HiggsWindowFit->Write();
  h_counts->Write();
  fout.Close();
  */
  //h->Draw();
  h_diffU->Draw();h_diff->Draw("SAMES");h_diffL->Draw("SAMES");
  TLegend *legd = new TLegend(.6,.55,.8,.85,"","brNDC");
  legd->SetFillStyle(0);legd->SetBorderSize(0);
  legd->AddEntry(h_diff,"Higgs window","l");
  legd->AddEntry(h_diffL,"lower sideband","l");
  legd->AddEntry(h_diffU,"upper sideband","l");
  legd->Draw();
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff.png");
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff.pdf");


  //c2->cd();
  h_pullU->Draw();h_pull->Draw("SAMES");h_pullL->Draw("SAMES");
  legd->Draw();
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull.png");
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull.pdf");


  h_diff->Fit("gaus");h_diff->SetTitle("Higgs window (fit - generated) with Gaussian fit");
  h_diff->Draw();
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff_gausFit.png");
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff_gausFit.pdf");

  h_pull->Fit("gaus");h_pull->SetTitle("Higgs window pull with Gaussian fit");//h_pull_fail->Fit("gaus");
  h_pull->Draw();//h_pull_fail->Draw("SAMES");
  c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull_gausFit_withFail.png");
  c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull_gausFit_withFail.pdf");

  h_HiggsWindowFit->Fit("gaus");
  h_HiggsWindowFit->Draw();
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__HiggsWindow_gausFit.png");
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__HiggsWindow_gausFit.pdf");
  
  h_counts->Draw();
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__counts.png");
  //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__counts.pdf");

}