Example #1
0
void draw_reflections(TString infile)
{
	gStyle->SetOptStat(0);
	
	TChain *data = new TChain("data");
	data->Add(infile);

	
	TH2D *direct = new TH2D("d","d",250,-50,200,200,-100,100);
	TH2D *left = new TH2D("l","l",250,-50,200,200,-100,100);
	TH2D *bottom = new TH2D("b","b",250,-50,200,200,-100,100);
   	TH2D *right = new TH2D("r","r",250,-50,200,200,-100,100);
	right->SetTitle(0);
	

	data->Project("r","fHitArray.fGlobalPos.y():fHitArray.fGlobalPos.x()","fHitArray.fPathInPrizm==4");
	data->Project("b","fHitArray.fGlobalPos.y():fHitArray.fGlobalPos.x()","fHitArray.fPathInPrizm==3");
	data->Project("l","fHitArray.fGlobalPos.y():fHitArray.fGlobalPos.x()","fHitArray.fPathInPrizm==2");
	data->Project("d","fHitArray.fGlobalPos.y():fHitArray.fGlobalPos.x()","fHitArray.fPathInPrizm==0");

	direct->SetMarkerColor(kGray+1);
	left->SetMarkerColor(kGreen+2);
	bottom->SetMarkerColor(kBlue);
	right->SetMarkerColor(kMagenta+2);

	TCanvas *canv = new TCanvas();
	right->Draw();
	bottom->Draw("same");
	left->Draw("same");
	direct->Draw("same");
}
Example #2
0
void Draw_KL_Test(){

  TChain* ch = new TChain("Tree");
  TChain* ch1 = new TChain("Tree");
  
  TH1D* his  = new TH1D("Klong6g","Klong6g",20,450,550);
  TH1D* his1 = new TH1D("Klong4g","Klong4g",20,450,550);
  TH1D* his2 = new TH1D("Klong4gAll","Klong4gAll",60,250,550);

  for( int i = 0; i< 68; i++){
    ch->Add(Form("klongRootFile/kl%d.root" ,4162+i));
    ch1->Add(Form("klongRootFile/ks%d.root",4162+i));
  }
  ch->Project(his->GetName()  ,"KlongMass[0]","CutCondition==0");
  ch1->Project(his1->GetName(),"KlongMass[0]","CutCondition==0");
  ch1->Project(his2->GetName(),"KlongMass[0]","CutCondition==0");
  
  TF1* func = new TF1("func","gaus(0)+expo(3)",0,550);
  func->SetParameter(1,498);
  func->SetParameter(2,5);
  TF1* func2 = new TF1("func2","gaus(0)",0,550);
  func2->SetParameter(1,498);
  func2->SetParameter(2,5);



  TCanvas* can = new TCanvas("can","",1200,600);
  can->Divide(2,1);
  can->cd(1);
  his2->Fit(func->GetName(),"","",450,550);
  his2->Draw();
  TF1* func1 = new TF1("Test","gaus",450,550);
  func1->SetParameter(0,func->GetParameter(0));
  func1->SetParameter(1,func->GetParameter(1));
  func1->SetParameter(2,func->GetParameter(2));

  can->cd(2);
  his1->SetLineColor(2);  
  his->Draw();
  his->Fit(func2->GetName(),"","",450,550);
  func->Draw("same");
  his1->Draw("same");

  std::cout<< func2->GetParameter(0) << " " 
	   << func->GetParameter(0)  << " " 
	   << func->GetParameter(0)/func2->GetParameter(0)<< std::endl;
  std::cout<< func2->Integral(450,550) << " " 
	   << func1->Integral(450,550)  << " " 
	   << func1->Integral(450,550)/func2->Integral(450,550)
	   << std::endl;
  //ch->Draw("KlongPt[0]:KlongMass[0]>>(400,200,600,50,0,20)","(CutCondition&(1|2|4|8))==0","colz");
  gPad->SetLogz();
  TText* text = new TText(0.5,0.5,"");
  TText* text1 = new TText(0.5,0.5,"");
  text->DrawTextNDC(0.5,0.5,Form("Integral:%2.3lf",func1->Integral(450,550)));
  text1->DrawTextNDC(0.5,0.6,Form("Integral:%2.3lf",func2->Integral(450,550)));
  
}
Example #3
0
void mc_xyzratio(const char *fname = NULL)
{
	TH1D *hA[3];
	TH1D *hB[3];
	TH1D *hR[3];
	int i;
	char str[256];
	const int Color[] = {kRed, kBlue, kGreen};
	TCut cut;

	TChain *tMC = make_mc_tree(fname);
	if (!tMC) {
		printf("DanssPair tree not found\n");
		return;
	}

	gROOT->cd();
	for (i=0; i<3; i++) {
		sprintf(str, "hMCgt3P%c", 'X'+i);
		hA[i] = new TH1D(str, "MC gt 3 MeV", 25, 0, 100);
		sprintf(str, "hMClt3P%c", 'X'+i);
		hB[i] = new TH1D(str, "MC lt 3 MeV", 25, 0, 100);
		sprintf(str, "PositronX[%d]+%4.1f", i, (i==2) ? 0.5 : 2.0);
		switch (i) {
		case 0:
			cut = cY && "PositronX[0]>=0" && cZ && cR && c20 && cGamma && cGammaMax && cPe && cN;
			break;
		case 1:
			cut = cX && "PositronX[1]>=0" && cZ && cR && c20 && cGamma && cGammaMax && cPe && cN;
			break;
		default:
			cut = cX && cY && cR && c20 && cGamma && cGammaMax && cPe && cN;
		}
		gROOT->cd();
		tMC->Project(hA[i]->GetName(), str, cut && "PositronEnergy > 3");
		tMC->Project(hB[i]->GetName(), str, cut && "PositronEnergy < 3");
		hA[i]->Sumw2();
		hB[i]->Sumw2();
		sprintf(str, "hRatioMCP%c", 'X'+i);
		hR[i] = (TH1D*) hA[i]->Clone(str);
		hR[i]->Divide(hA[i], hB[i]);
		hR[i]->SetTitle("MC Ratio (PE gt 3 MeV) / (PE lt 3 MeV);cm;Ratio");
		hR[i]->SetLineColor(Color[i]);
		hR[i]->SetStats(0);
	}
	TCanvas *cv = new TCanvas("CV", "CV", 1200, 900);
	for (i=0; i<3; i++) hR[i]->Draw((i) ? "same" : "");
	TLegend *lg = new TLegend(0.12, 0.73, 0.2, 0.87);
	for (i=0; i<3; i++) {
		sprintf(str, "%c", 'X'+i);
		lg->AddEntry(hR[i], str, "LE");
	}
	lg->Draw();
	cv->SaveAs("XYZ-ratioMC.pdf");
}
Example #4
0
void sigHist(TChain & EventsVBF, TChain & EventsGF, string variable, string title, int nBins, float min, float max, float GF, float VBF ){

  TCanvas c("");
  TH1F *hVBF = new TH1F("hVBF","hVBF", nBins, min, max);
  TH1F *hGF = new TH1F("hGF","hGF", nBins, min, max);
  EventsVBF.Project("hVBF",variable.c_str() );
  EventsGF.Project("hGF",variable.c_str() );
  //hVBF->Draw();
  EventsVBF.Draw("h.mass()");
  TH1F * h = new TH1F(title.c_str(),title.c_str(), nBins, min,max);

  
  h->Add(hVBF,hGF,VBF,GF);

    h->SetLineColor(kBlue+1);
    h->SetFillColor(kAzure+7);

  //h->SetLineColor(kMagenta+3);
  //h->SetFillColor(kMagenta-3);

  //    h->SetLineColor(kTeal+3);
  //  h->SetFillColor(kTeal+2);

  //  h->SetLineColor(kOrange+7);
  //  h->SetFillColor(kYellow-9);

  h->SetMarkerStyle(0);
  h->SetTitle( ("H350, "+title).c_str() );
  h->SetXTitle("m_{H} (GeV/c^{2})");
  //h->hGF->GetXaxis()->SeXmin();
  //h->Scale(1/h->GetEntries());
  h->Draw("HIST");

  h->Write();
  //c.SaveAs( (title+".eps").c_str() );
  delete hVBF;
  delete hGF;
  delete h;

}
void ecalSpectra()
{
  TH1::SetDefaultSumw2();

  //const Double_t PTBINS[] = {0,2.5,5,7.5,10,12.5,15,17.5, 20,25, 30,35, 40, 50, 60, 80, 120, 300};
  //const Int_t nPTBINS = 5;
  //const Int_t nPTBINS = sizeof(PTBINS)/sizeof(Double_t) -1;

  TChain *ecalTree = new TChain("ecalTree");
  ecalTree->Add("pA_promptRECO/*.root");
  //ecalTree->Add("pA_promptRECO/89.root");
  //TH1D *ecalSpectra = new TH1D("ecalSpectra","ecalSpectra", nPTBINS, PTBINS);
  TH1D *ecalSpectra = new TH1D("ecalSpectra","ecalSpectra",300,0,300);

  // const TCut ecalEtaCut = "abs(ecalTree.eta) < 1.44";
  // const TCut isoCut = "ecalRecHitSumEtConeDR04 < 4.2  &&  hcalTowerSumEtConeDR04 < 2.2  &&  trkSumPtHollowConeDR04 < 2 && hadronicOverEm<0.1";
  // const TCut genCut = "genCalIsoDR04<5 && abs(genMomId)<=22";
  // const TCut sbCut = "(cc4+cr4+ct4PtCut20>10) && (cc4+cr4+ct4PtCut20<20) && hadronicOverEm<0.1";
  // const TCut candidateCut = "sigmaIetaIeta<0.01";
  // const TCut decayCut = "(sigmaIetaIeta>0.011) && (sigmaIetaIeta<0.017)";

  //TCut ecalPtCut = "ecalTree.corrPt>40 && ecalTree.corrPt<300";

  //const TCut triggerCut = "HLT_PAPhoton10_NoCaloIdVL_v1 && HLT_PAPhoton10_NoCaloIdVL_v1_Prescl==1 && L1_SingleEG5_BptxAND_Prescl==1";
  const TCut triggerCut = "HLT_PAPhoton10_NoCaloIdVL_v1";
  const TCut showerCut = "sigmaIetaIeta > 0.011";
  const TCut etaCut = "abs(eta) < 1.44";
  //const TCut trackerIso = "trkSumPtHollowConeDR04 > 2";
  const TCut ecalIso = "ecalRecHitSumEtConeDR04 > 4.2";
  //const TCut hcalIso
  Int_t count = ecalTree->Project(ecalSpectra->GetName(),"pt", triggerCut && showerCut && etaCut && ecalIso);
  printf("Num events: %i\n", count);

  TCanvas *c1 = new TCanvas();
  ecalSpectra->Draw();
  // correctedEcalSpectra->Draw("same");
  c1->SetLogy();

  // TFile *outFile = new TFile("ecalSpectra.root", "RECREATE");
  // outFile->cd();
  // ecalSpectra->Write();
  // correctedEcalSpectra->Write();
  // outFile->Close();
}
Example #6
0
void addTreeToFile( TFile* file, const std::string& treeName, std::vector<ZGSample> samples, const ZGConfig& cfg, int idMin, int idMax ) {


    if( idMin>=0 && idMax<0 ) idMax=idMin;

    TChain* tree = new TChain("mt2");


    for( unsigned i=0; i<samples.size(); ++i ) {
        if( idMin>0 ) {
            int thisId = samples[i].id;
            if( thisId<idMin ) continue;
            if( thisId>idMax ) continue;
        }
        std::string fileName(Form("%s/mt2", samples[i].file.c_str()) );
        tree->Add( fileName.c_str() );
        std::cout << "-> Added: " << fileName << std::endl;
    }



    //TFile* puFile_data = TFile::Open("puData.root");
    //TH1D* h1_nVert_data = (TH1D*)puFile_data->Get("nVert");

    //TFile* puFile_mc = TFile::Open("puMC.root");
    //TH1D* h1_nVert_mc = (TH1D*)puFile_mc->Get("nVert");

    // for pu reweighting:
    TFile* puFile = TFile::Open("DoubleEG_cert_210.root");
    TH1D* h1_pu = (TH1D*)puFile->Get("pileup");


    ZGTree myTree;
    myTree.loadGenStuff = false;
    myTree.Init(tree);


    // compute denominators of efficiency for PDF syst
    std::vector<float> pdf_denom;
    std::vector<float> pdf_num;

    file->cd();
    gDirectory->Delete(Form("%s;*", treeName.c_str()));
    gDirectory->Delete(Form("pdf_%s;*", treeName.c_str()));
    TTree* outTree = new TTree( treeName.c_str(), "" );

    int run;
    outTree->Branch( "run", &run, "run/I");
    int lumi;
    outTree->Branch( "lumi", &lumi, "lumi/I");
    UInt_t event;
    outTree->Branch( "event", &event, "event/i");
    float weight;
    outTree->Branch( "weight", &weight, "weight/F");
    float puWeight;
    outTree->Branch( "puWeight", &puWeight, "puWeight/F");
    int id;
    outTree->Branch( "id", &id, "id/I");
    int leptType;
    outTree->Branch( "leptType", &leptType, "leptType/I");
    float met;
    outTree->Branch( "met", &met, "met/F" );
    int nVert;
    outTree->Branch( "nVert", &nVert, "nVert/I" );
    int nGamma;
    outTree->Branch( "nGamma", &nGamma, "nGamma/I" );
    bool isGolden;
    outTree->Branch( "isGolden", &isGolden, "isGolden/O");
    bool isSilver;
    outTree->Branch( "isSilver", &isSilver, "isSilver/O");

    bool passHLT_old;
    outTree->Branch( "passHLT_old", &passHLT_old, "passHLT_old/O" );
    bool passHLT;
    outTree->Branch( "passHLT", &passHLT, "passHLT/O" );
    bool HLT_Photon165;
    outTree->Branch( "HLT_Photon165", &HLT_Photon165, "HLT_Photon165/O" );
    bool HLT_DoubleEle;
    outTree->Branch( "HLT_DoubleEle", &HLT_DoubleEle, "HLT_DoubleEle/O" );
    bool HLT_DoubleEle33;
    outTree->Branch( "HLT_DoubleEle33", &HLT_DoubleEle33, "HLT_DoubleEle33/O" );
    bool HLT_DoubleMu;
    outTree->Branch( "HLT_DoubleMu", &HLT_DoubleMu, "HLT_DoubleMu/O" );
    bool HLT_Mu30_TkMu11;
    outTree->Branch( "HLT_Mu30_TkMu11", &HLT_Mu30_TkMu11, "HLT_Mu30_TkMu11/O" );
    bool HLT_SingleMu;
    outTree->Branch( "HLT_SingleMu", &HLT_SingleMu, "HLT_SingleMu/O" );
    bool passStandardIso;
    outTree->Branch( "passStandardIso", &passStandardIso, "passStandardIso/O" );

    float weight_scale;
    outTree->Branch( "weight_scale", &weight_scale, "weight_scale/F");
    float weight_pdf;
    outTree->Branch( "weight_pdf", &weight_pdf, "weight_pdf/F");
    float weight_lep;
    outTree->Branch( "weight_lep", &weight_lep, "weight_lep/F");

    float lept0_pt;
    outTree->Branch( "lept0_pt", &lept0_pt, "lept0_pt/F" );
    float lept0_eta;
    outTree->Branch( "lept0_eta", &lept0_eta, "lept0_eta/F" );
    float lept0_phi;
    outTree->Branch( "lept0_phi", &lept0_phi, "lept0_phi/F" );
    float lept0_mass;
    outTree->Branch( "lept0_mass", &lept0_mass, "lept0_mass/F" );
    float lept0_miniRelIso;
    outTree->Branch( "lept0_miniRelIso", &lept0_miniRelIso, "lept0_miniRelIso/F" );
    int lept0_pdgId;
    outTree->Branch( "lept0_pdgId", &lept0_pdgId, "lept0_pdgId/I" );

    float lept1_pt;
    outTree->Branch( "lept1_pt", &lept1_pt, "lept1_pt/F" );
    float lept1_eta;
    outTree->Branch( "lept1_eta", &lept1_eta, "lept1_eta/F" );
    float lept1_phi;
    outTree->Branch( "lept1_phi", &lept1_phi, "lept1_phi/F" );
    float lept1_mass;
    outTree->Branch( "lept1_mass", &lept1_mass, "lept1_mass/F" );
    float lept1_miniRelIso;
    outTree->Branch( "lept1_miniRelIso", &lept1_miniRelIso, "lept1_miniRelIso/F" );
    int lept1_pdgId;
    outTree->Branch( "lept1_pdgId", &lept1_pdgId, "lept1_pdgId/I" );

    float deltaR_lept;
    outTree->Branch( "deltaR_lept", &deltaR_lept, "deltaR_lept/F" );

    float gamma_pt;
    outTree->Branch( "gamma_pt", &gamma_pt, "gamma_pt/F" );
    float gamma_eta;
    outTree->Branch( "gamma_eta", &gamma_eta, "gamma_eta/F" );
    float gamma_phi;
    outTree->Branch( "gamma_phi", &gamma_phi, "gamma_phi/F" );
    float gamma_mass;
    outTree->Branch( "gamma_mass", &gamma_mass, "gamma_mass/F" );
    float gamma_iso;
    outTree->Branch( "gamma_iso", &gamma_iso, "gamma_iso/F" );

    float z_pt;
    outTree->Branch( "z_pt", &z_pt, "z_pt/F" );
    float z_eta;
    outTree->Branch( "z_eta", &z_eta, "z_eta/F" );
    float z_phi;
    outTree->Branch( "z_phi", &z_phi, "z_phi/F" );
    float z_mass;
    outTree->Branch( "z_mass", &z_mass, "z_mass/F" );

    float boss_pt;
    outTree->Branch( "boss_pt", &boss_pt, "boss_pt/F" );
    float boss_eta;
    outTree->Branch( "boss_eta", &boss_eta, "boss_eta/F" );
    float boss_phi;
    outTree->Branch( "boss_phi", &boss_phi, "boss_phi/F" );
    float boss_mass;
    outTree->Branch( "boss_mass", &boss_mass, "boss_mass/F" );

    float boss2_pt;
    outTree->Branch( "boss2_pt", &boss2_pt, "boss2_pt/F" );
    float boss2_eta;
    outTree->Branch( "boss2_eta", &boss2_eta, "boss2_eta/F" );
    float boss2_phi;
    outTree->Branch( "boss2_phi", &boss2_phi, "boss2_phi/F" );
    float boss2_mass;
    outTree->Branch( "boss2_mass", &boss2_mass, "boss2_mass/F" );

    float qgamma_mass;
    outTree->Branch( "qgamma_mass", &qgamma_mass, "qgamma_mass/F" );
    float qZ_mass;
    outTree->Branch( "qZ_mass", &qZ_mass, "qZ_mass/F" );





    // for muon rochester corrections
    rochcor2016 *rmcor = new rochcor2016();


    EnergyScaleCorrection_class egcor("Golden10June_plus_DCS");


    int nentries = tree->GetEntries();

    for( int iEntry=0; iEntry<nentries; ++iEntry ) {

        if( iEntry % 50000 == 0 ) std::cout << "    Entry: " << iEntry << " / " << nentries << std::endl;

        myTree.GetEntry(iEntry);

        run   = myTree.run;
        lumi  = myTree.lumi;
        event = myTree.evt;
        id    = myTree.evt_id;


        if( iEntry==0 ) { // initialize stuff

            if( id<100 ) {
                egcor.doScale=true;
                egcor.doSmearings=false;
            } else {
                egcor.doScale=false;
                egcor.doSmearings=true;
            }

        }



        if( event == DEBUG_EVENT ) {
            std::cout << "++++ STARTING DEBUG COUT FOR: " << std::endl;
            std::cout << "    Run: " << run << std::endl;
            std::cout << "    LS : " << lumi << std::endl;
            std::cout << "    Event : " << event << std::endl;
        }

        bool doSystForThisSample =  doSyst && (id==851 || id==852 || id==4301 || id==4302);

        if( iEntry==0 && doSystForThisSample ) { // allocate all of the PDF stuff

            for( int i=0; i<myTree.nLHEweight; ++i ) {
                pdf_num.push_back(0.);
                std::cout << "[PDF Systematics] Allocating stuff for LHE weight: " << myTree.LHEweight_id[i] << " (" << i << "/" << myTree.nLHEweight << ")" << std::endl;
                bool goodIndex = (myTree.LHEweight_id[i]>=2000 && myTree.LHEweight_id[i]<=3000);
                if( goodIndex ) {
                    TH1D* h1_tmp = new TH1D("pdf_tmp", "", 100, 0., 10000. );
                    h1_tmp->Sumw2();
                    tree->Project( "pdf_tmp", "met_pt", Form("LHEweight_wgt[%d]", i) );
                    pdf_denom.push_back( h1_tmp->Integral() );
                    delete h1_tmp;
                } else {
                    pdf_denom.push_back( 1. );
                }
            }

        } // if first entry


        // remove overlap from DY:
        if( id>=700 && id<710 ) {
            if( myTree.ngamma>0 && myTree.gamma_mcMatchId[0]==22 ) continue;
            //if( myTree.ngamma>0 ) {
            //  bool isFake = myTree.gamma_mcMatchId[0]!=22;
            //  bool okFromDY = isFake || (!isFake && myTree.gamma_drMinParton[0]<0.05);
            //  if( !okFromDY ) continue;
            //}
        }


        if( myTree.nVert==0 ) continue;
        nVert = myTree.nVert;


        // filters
        if( myTree.isData ) {
            if( !myTree.passFilters() ) continue;
        }

        isGolden = myTree.isGolden;
        isSilver = myTree.isSilver;

        HLT_Photon165   = myTree.HLT_Photon165_HE10;
        HLT_DoubleEle   = myTree.HLT_DoubleEl;
        HLT_DoubleMu    = myTree.HLT_DoubleMu;
        HLT_Mu30_TkMu11 = myTree.HLT_Mu30_TkMu11;
        HLT_DoubleEle33 = myTree.HLT_DoubleEle33;
        HLT_SingleMu    = myTree.HLT_SingleMu;

        // hlt on data:
        if( myTree.isData ) {
            if( !myTree.isGolden ) continue;
            //if( !myTree.isSilver ) continue;
            passHLT = false;
            if( id==5 ) passHLT = myTree.HLT_DoubleMu || myTree.HLT_Mu30_TkMu11; //DoubleMu PD
            if( id==8 ) passHLT = myTree.HLT_SingleMu && !myTree.HLT_DoubleMu && !myTree.HLT_Mu30_TkMu11; //SingleMu PD
            if( id==4 ) passHLT = (myTree.HLT_DoubleEl || myTree.HLT_DoubleEle33) && !myTree.HLT_DoubleMu && !myTree.HLT_Mu30_TkMu11 && !myTree.HLT_SingleMu; //DoubleEG PD
            //if( id==7 ) passHLT = myTree.HLT_Photon165_HE10 && !myTree.HLT_DoubleEl && !myTree.HLT_DoubleMu; //SinglePhoton PD
            //if( id==5 ) passHLT = myTree.HLT_DoubleMu; //DoubleMu PD
            //if( id==4 ) passHLT = myTree.HLT_DoubleEl && !myTree.HLT_DoubleMu && !myTree.HLT_SingleMu; //DoubleEG PD
            //if( id==9 ) passHLT = myTree.HLT_SingleEl && !myTree.HLT_DoubleEl && !myTree.HLT_DoubleMu && !myTree.HLT_SingleMu; //SingleElectron PD
        } else {
            // hlt on mc:
            passHLT = true; // no HLT in 80X MC
            //passHLT = ( myTree.HLT_DoubleEl || myTree.HLT_DoubleMu || myTree.HLT_Mu30_TkMu11 || myTree.HLT_DoubleEle33 );
            //passHLT = ( myTree.HLT_DoubleEl || myTree.HLT_DoubleMu || myTree.HLT_Mu30_TkMu11 || myTree.HLT_DoubleEle33 || myTree.HLT_SingleMu );
        }

        if( !passHLT && cfg.additionalStuff()!="noHLT" ) continue;

        if( event == DEBUG_EVENT )  std::cout << " -> passed HLT " << std::endl;

        if( myTree.nlep!=2 ) continue; // two leptons
        if( event == DEBUG_EVENT )  std::cout << " -> passed 2 lepton requirement " << std::endl;
        if( myTree.lep_pdgId[0] != -myTree.lep_pdgId[1] ) continue; // same flavour, opposite sign
        if( event == DEBUG_EVENT )  std::cout << " -> passed same flavor opposite charge requirement " << std::endl;

        leptType = abs(myTree.lep_pdgId[0]);
        if( leptType!=11 && leptType!=13 ) continue; // just in case
        if( event == DEBUG_EVENT )  std::cout << " -> passed electron/muon requirement " << std::endl;




        TLorentzVector lept0;
        lept0.SetPtEtaPhiM( myTree.lep_pt[0], myTree.lep_eta[0], myTree.lep_phi[0], myTree.lep_mass[0] );
        TLorentzVector lept1;
        lept1.SetPtEtaPhiM( myTree.lep_pt[1], myTree.lep_eta[1], myTree.lep_phi[1], myTree.lep_mass[1] );

        if( lept0.Pt()<25. ) continue;
        if( lept1.Pt()<20. ) continue;

        if( leptType==11 ) {
            if( myTree.lep_tightId[0]==0 || myTree.lep_tightId[1]==0 ) continue; // loose electron ID
        } else {
            //if( myTree.lep_tightId[0]==0 || myTree.lep_tightId[1]==0 ) continue; // tight muon ID on both
            if( !( (myTree.lep_tightId[0]==1 && myTree.lep_tightId[0]>=0)
                    || (myTree.lep_tightId[1]==1 && myTree.lep_tightId[1]>=0)) ) continue; // tight muon ID on at least one of the muons
        }


        // apply rochester corrections for muons:
        if( leptType==13 ) {

            // instructions taken from https://twiki.cern.ch/twiki/pub/CMS/RochcorMuon/manual_rochcor_run2.pdf
            // linked from twiki: https://twiki.cern.ch/twiki/bin/viewauth/CMS/RochcorMuon
            float qter = 1.0;

            if( !myTree.isData ) {
                rmcor->momcor_mc(lept0, myTree.lep_pdgId[0]/(abs(myTree.lep_pdgId[0])), 0, qter);
                rmcor->momcor_mc(lept1, myTree.lep_pdgId[1]/(abs(myTree.lep_pdgId[1])), 0, qter);
            } else {
                rmcor->momcor_data(lept0, myTree.lep_pdgId[0]/(abs(myTree.lep_pdgId[0])), 0, qter);
                rmcor->momcor_data(lept1, myTree.lep_pdgId[1]/(abs(myTree.lep_pdgId[1])), 0, qter);
            }

            passStandardIso = (myTree.lep_relIso04[0]<0.25 && myTree.lep_relIso04[1]<0.25);

        } else if( leptType==11 ) {

            if( !myTree.isData ) {
                if( cfg.smearing() ) {
                    smearEmEnergy( egcor, lept0, myTree, myTree.lep_r9[0] );
                    smearEmEnergy( egcor, lept1, myTree, myTree.lep_r9[1] );
                }
            } else {
                if( cfg.smearing() ) {
                    applyEmEnergyScale( egcor, lept0, myTree, myTree.lep_r9[0] );
                    applyEmEnergyScale( egcor, lept1, myTree, myTree.lep_r9[1] );
                }
            }

            bool passStandardIso0 = (fabs(myTree.lep_eta[0])<1.479) ? myTree.lep_relIso03[0]<0.0893 : myTree.lep_relIso03[0]<0.121;
            bool passStandardIso1 = (fabs(myTree.lep_eta[1])<1.479) ? myTree.lep_relIso03[1]<0.0893 : myTree.lep_relIso03[1]<0.121;

            passStandardIso = passStandardIso0 && passStandardIso1;

        }

        lept0_miniRelIso = myTree.lep_miniRelIso[0];
        lept1_miniRelIso = myTree.lep_miniRelIso[1];

        lept0_pdgId = myTree.lep_pdgId[0];
        lept1_pdgId = myTree.lep_pdgId[1];



        weight = 1.;
        puWeight = 1.;
        weight_scale = 1.;
        weight_pdf = 1.;
        weight_lep = 1.;

        if( !myTree.isData ) {

            weight = myTree.evt_scale1fb*cfg.lumi();
            // pu reweighting:
            //puWeight = getPUweight( h1_pu, myTree.nTrueInt );
            puWeight = myTree.puWeight;
            weight *= puWeight;

            // lepton SF:
            float leptonSF = 1.;
            if( leptType==13 ) {
                float isoSF = 0.9997;
                float idSF_loose = 0.997;
                float idSF_tight = 0.983;
                float idSF = idSF_loose*idSF_tight;
                if( myTree.lep_tightId[0]==1 && myTree.lep_tightId[1]==1 )
                    idSF = 2.*idSF_loose*idSF_tight - idSF_tight*idSF_tight;

                leptonSF = isoSF*idSF;
            }
            weight *= leptonSF;



            // trigger SF:

            float hltSF = 1.;

            if( leptType==11 ) { // electrons

                if( lept0.Pt()<35. || lept1.Pt()<35. ) {
                    hltSF = 0.965;
                } else {
                    hltSF = 1.;
                }

            } else { // muons

                hltSF = 0.989;

            }

            weight *= hltSF;

            weight_lep = myTree.weight_lepsf_UP;
            weight_scale = weight; // will compute later
            weight_pdf = weight; // will compute later

        }




        TLorentzVector photon;
        TLorentzVector photon2;
        bool foundSecondPhoton = false;


        if( cfg.selection()!="veryloose" ) {

            if( myTree.ngamma==0 ) continue; // photon
            if( event == DEBUG_EVENT )  std::cout << " -> passed ngamma requirement " << std::endl;

            photon  = selectPhoton(cfg, myTree, 0, lept0, lept1, egcor);

            if( photon.Pt()<1. ) continue;
            if( event == DEBUG_EVENT )  std::cout << " -> passed photon requirement " << std::endl;

            photon2 = selectPhoton(cfg, myTree, 1, lept0, lept1, egcor);

            foundSecondPhoton = photon2.Pt()>10.;

        }


        TLorentzVector zBoson = lept0+lept1;
        if( zBoson.M()<50. ) continue;
        if( cfg.selection()!="presel" && zBoson.M()>130. ) continue;
        if( event == DEBUG_EVENT )  std::cout << " -> passed M(ll) cut " << std::endl;

        TLorentzVector boss = zBoson + photon;
        TLorentzVector boss2;
        if( foundSecondPhoton )
            boss2 = zBoson + photon + photon2;
        else
            boss2.SetPtEtaPhiM( 0.1, 0., 0., 0.);

        if( id==851 && boss.M()>410. ) continue;


        lept0_pt   = lept0.Pt();
        lept0_eta  = lept0.Eta();
        lept0_phi  = lept0.Phi();
        lept0_mass = lept0.M();

        lept1_pt   = lept1.Pt();
        lept1_eta  = lept1.Eta();
        lept1_phi  = lept1.Phi();
        lept1_mass = lept1.M();

        deltaR_lept = lept0.DeltaR(lept1);

        nGamma = myTree.ngamma;

        if( photon.Pt()>0. ) {

            gamma_pt   = photon.Pt();
            gamma_eta  = photon.Eta();
            gamma_phi  = photon.Phi();
            gamma_mass = photon.M();
            gamma_iso = myTree.gamma_chHadIso[0];

        } else {

            gamma_pt   = 0.;
            gamma_eta  = 0.;
            gamma_phi  = 0.;
            gamma_mass = 0.;
            gamma_iso = -1.;

        }

        z_pt   = zBoson.Pt();
        z_eta  = zBoson.Eta();
        z_phi  = zBoson.Phi();
        z_mass = zBoson.M();

        boss_pt   = boss.Pt();
        boss_eta  = boss.Eta();
        boss_phi  = boss.Phi();
        boss_mass = boss.M();

        boss2_pt   = boss2.Pt();
        boss2_eta  = boss2.Eta();
        boss2_phi  = boss2.Phi();
        boss2_mass = boss2.M();

        met = myTree.met_pt;

        if( cfg.selection()=="v0" )
            if( gamma_pt/boss_mass < 40./150. ) continue;

        if( cfg.selection()=="Qv0" ) {
            if( myTree.njet==0 ) continue;
            if( fabs(myTree.jet_eta[0])>2.5 ) continue;
            if( myTree.jet_pt[0]<30. ) continue;
        }

        if( event == DEBUG_EVENT )  std::cout << " -> passed additional cuts" << std::endl;


        qgamma_mass = -1.;
        qZ_mass = -1.;

        if( myTree.njet>0 && myTree.jet_pt[0]>30. ) {

            TLorentzVector jet;
            jet.SetPtEtaPhiM( myTree.jet_pt[0], myTree.jet_eta[0], myTree.jet_phi[0], myTree.jet_mass[0] );

            TLorentzVector qgamma = jet+photon;
            TLorentzVector qZ     = jet+zBoson;

            qgamma_mass = qgamma.M();
            qZ_mass     = qZ.M();

        }


        if( DATABLINDING && myTree.isData && boss_mass>500. ) continue;


        if( doSystForThisSample ) { // systematic uncertainties

            for( int i=0; i<myTree.nLHEweight; ++i ) {
                bool goodIndex = (myTree.LHEweight_id[i]>=2000 && myTree.LHEweight_id[i]<=3000);
                if( goodIndex )
                    pdf_num[i] += myTree.LHEweight_wgt[i];
            } //for pdf sets

        }


        //if( id==851 && doSyst ) { // systematic uncertainties

        //  // first scale
        //  float ref = myTree.LHEweight_original;

        //  float maxScaleDiff = 0.;

        //  TH1D* h1_pdf = new TH1D("pdf", "", 1000, -3000., 3000.);

        //  for( int i=0; i<myTree.nLHEweight; ++i ) {

        //    if( myTree.LHEweight_id[i]>=1000 && myTree.LHEweight_id[i]<1010 ) {
        //      float thisScaleDiff = fabs( (myTree.LHEweight_wgt[i]-ref)/ref );
        //      if( thisScaleDiff>maxScaleDiff)
        //        maxScaleDiff = thisScaleDiff+1.;
        //    }

        //    if( myTree.LHEweight_id[i]>=2000 ) {
        //      if( myTree.LHEweight_wgt[i] > h1_pdf->GetXaxis()->GetXmax() || myTree.LHEweight_wgt[i] < h1_pdf->GetXaxis()->GetXmin() )
        //        std::cout << "WARNING!! PDF weight out of bounds: " << myTree.LHEweight_wgt[i] << std::endl;
        //      h1_pdf->Fill( myTree.LHEweight_wgt[i]/ref );
        //    }

        //  } // for lhe weights

        //  float meanPdfWgt = h1_pdf->GetMean();
        //  float rmsPdfWgt = h1_pdf->GetRMS();
        //  weight_pdf *= (1.+rmsPdfWgt/meanPdfWgt);

        //  weight_scale *= maxScaleDiff;

        //  delete h1_pdf;

        //} // if correct sample

        if( event == DEBUG_EVENT )  std::cout << " -> filling tree" << std::endl;
        outTree->Fill();


    } // for entries


    TH1D* h1_pdf = new TH1D( Form("pdf_%s", treeName.c_str()), "", 2000, 0., 1. );
    for( unsigned i=0; i<pdf_num.size(); ++i ) {
        if( pdf_num[i]!=0. )
            h1_pdf->Fill( pdf_num[i]/pdf_denom[i] );
    }

    if( h1_pdf->GetMean()>0. )
        h1_pdf->Write();

    outTree->Write();

    puFile->Close();

}
void drawQGFraction(){

	const double PI = 3.14159;

	TChain *mix = new TChain("mixing_tree");
	mix->Add("/data/kurtjung/JetTrackCorr_skims/2p76TeV_MC_Pythia6/MergedPythia_withPartonFlavor.root");
	//mix->Add("/data/kurtjung/JetTrackCorr_skims/5TeV_MC_Pythia6/*");

	//double xsecs[11] = {5.335E-01, 3.378E-02, 3.778E-03, 4.412E-04, 6.147E-05, 1.018E-05, 2.477E-06, 6.160E-07, 1.088E-07, 3.216E-08, 0}; //pythia6 5.02 tev weights
    double xsecs[11] = {2.043e-01, 1.075E-02, 1.025E-03, 9.865E-05, 1.129E-05, 1.465E-06, 2.837E-07, 5.323E-08, 5.934e-09, 8.125e-10, 0}; //2.76 tev weights
	int recalculatedEntries[10] = {0,0,0,0,0,0,0,0,0,0};
	double pthatbins[11] = {15,30,50,80,120,170,220,280,370,460,9999};

	TFile *fout = new TFile("QGFrac_pythia6_2p76TeV.root","recreate");

	TH1D *quarkFracIncl = new TH1D("quarkFracIncl","",20,120,500); quarkFracIncl->Sumw2();
	TH1D *glueFracIncl = new TH1D("glueFracIncl","",20,120,500); glueFracIncl->Sumw2();
	TH1D *inclJets = new TH1D("inclJets","",20,120,500); inclJets->Sumw2();

	TH1D *quarkFracLead = new TH1D("quarkFracLead","",20,120,500); quarkFracLead->Sumw2();
	TH1D *glueFracLead = new TH1D("glueFracLead","",20,120,500); glueFracLead->Sumw2();
	TH1D *leadJets = new TH1D("leadJets","",20,120,500); leadJets->Sumw2();


	Int_t HBHENoiseFilterResultRun2Loose, pPAprimaryVertexFilter;
	vector<float> *calo_corrpt=0, *calo_jtphi=0;
	vector<int> *calo_refparton_flavor=0;
	float pthat;

	mix->SetBranchAddress("calo_corrpt",&calo_corrpt);
	mix->SetBranchAddress("calo_jtphi",&calo_jtphi);
	mix->SetBranchAddress("calo_refparton_flavor",&calo_refparton_flavor);
	mix->SetBranchAddress("pthat",&pthat);

	mix->SetBranchAddress("HBHENoiseFilterResultRun2Loose",&HBHENoiseFilterResultRun2Loose);
	mix->SetBranchAddress("pPAprimaryVertexFilter",&pPAprimaryVertexFilter);


	TH1D *pthatHisto = new TH1D("pthatHisto","",10,pthatbins);
	mix->Project("pthatHisto","pthat");
	for(int i=0; i<10; i++){
		recalculatedEntries[i] = pthatHisto->GetBinContent(i+1);
		cout << "entries between pthat " << pthatbins[i] << " and " << pthatbins[i+1] << ": " << recalculatedEntries[i] << endl;
		cout << "weight: " << (xsecs[i]-xsecs[i+1])/recalculatedEntries[i] <<endl;
	}

	int totEntries = mix->GetEntries();
	cout << "entries: "<< totEntries << endl;
	totEntries=100000;
	for(int ievt=0; ievt<totEntries; ievt++){
		mix->GetEntry(ievt);
		if(ievt && ievt%10000==0) cout << "entry: " << ievt << endl;

		//if(!HBHENoiseFilterResultRun2Loose || !pPAprimaryVertexFilter) continue;

		int ibin=0;
		double weight=0.;
		while(pthat>pthatbins[ibin]) ibin++;
		ibin--;
		weight = (xsecs[ibin]-xsecs[ibin+1])/recalculatedEntries[ibin];
		if(weight>1){ 
			cout << "xsec: "<< xsecs[ibin]-xsecs[ibin+1] << " entries: " << recalculatedEntries[ibin] << endl;
			cout << "pthat: "<< pthat << " bin " << ibin << endl;
		}
		
		for(unsigned int ijet=0; ijet<calo_corrpt->size(); ijet++){
			
			if(abs(calo_refparton_flavor->at(ijet))>0 && abs(calo_refparton_flavor->at(ijet))<6) quarkFracIncl->Fill(calo_corrpt->at(ijet), weight);
			if(abs(calo_refparton_flavor->at(ijet))==21){ glueFracIncl->Fill(calo_corrpt->at(ijet), weight); }
			inclJets->Fill(calo_corrpt->at(ijet), weight);

			if(ijet==0 && calo_corrpt->size()>1){
				double dphi = abs(calo_jtphi->at(0) - calo_jtphi->at(1));
				if(dphi>(7*PI/8.) && dphi<(9*PI/8.) && calo_corrpt->at(1)>50) {

					if(abs(calo_refparton_flavor->at(ijet))>0 && abs(calo_refparton_flavor->at(ijet))<6) quarkFracLead->Fill(calo_corrpt->at(ijet), weight);
					if(abs(calo_refparton_flavor->at(ijet))==21) glueFracLead->Fill(calo_corrpt->at(ijet), weight);
					leadJets->Fill(calo_corrpt->at(ijet), weight);

				}
			}
		}
	}

	//quarkFracLead->Divide(leadJets);
	//glueFracLead->Divide(leadJets);

	//quarkFracIncl->Divide(inclJets);
	//glueFracIncl->Divide(inclJets);

	fout->cd();

	formatHisto(quarkFracLead,1);
	formatHisto(glueFracLead,2);
	formatHisto(quarkFracIncl,4);
	formatHisto(glueFracIncl,8);

	quarkFracLead->Write();
	glueFracLead->Write();
	quarkFracIncl->Write();
	glueFracIncl->Write();
	leadJets->Write();
	inclJets->Write();

	fout->Close();

}
void makeSamePhiPlots() 
{
   gSystem->AddIncludePath("-I${EVENT_READER_DIR}");
   gSystem->AddIncludePath("-I${PLOTTER_DIR}");
   //  cout << gSystem->GetIncludePath() <<endl;
   
   gSystem->Load("libMathMore.so");
   gSystem->Load("/usr/lib64/libfftw3.so");
   gSystem->Load("libAnitaEvent.so");
   gSystem->Load("libAnitaCorrelator.so");
   TChain *deltaTTree = new TChain("deltaTTree");
   //   TFile *fp = new TFile("deltaTFile1027.root");
   //   TTree *deltaTTree = (TTree*) fp->Get("deltaTTree");
   deltaTTree->Add("deltaTFileClock*.root");
   
   AnitaGeomTool *fGeomTool = AnitaGeomTool::Instance();



   char plotCond[180];
   char plotTitle[180];
   char histName[180];
   TF1 *fitty = new TF1("fitty","gaus",-1,1);

   TH1F *histMeanDiff = new TH1F("histMeanDiff","histMeanDiff",100,-1,1);
   TH1F *histChiSq = new TH1F("histChiSq","histChiSq",100,0,3);
   TH1F *histSigma = new TH1F("histSigma","histSigma",100,0,10);
   TH1F *histConstant = new TH1F("histConstant","histConstant",100,0,100);

   ofstream Output("diffsDown.txt");

   for(int ant=0;ant<16;ant++) {
      TCanvas *can = new TCanvas();//"can","can");
      can->Divide(2,2);
      int topAnt=ant; 
      int bottomAnt=fGeomTool->getAzimuthPartner(topAnt); 
      for(int chip=0;chip<4;chip++) {
	 fitty->SetParameters(10,0,0.05);
	 //	 fitty->SetParLimits(2,0,0.1);

	 can->cd(chip+1);
	 sprintf(plotCond,"((firstAnt==%d && secondAnt==%d))  && labChip==%d && (corPeak/corRMS)>6",topAnt,bottomAnt,chip);	 
	 sprintf(plotTitle,"Ant %d -  Ant %d (Chip %d)",topAnt,bottomAnt,chip);
	 sprintf(histName,"histDt_%d_%d",ant,chip);
	 TH1F *histDt11 = new TH1F(histName,plotTitle,40,-0.5,0.5);

	 deltaTTree->Project(histName,"deltaT-deltaTExpected",plotCond);
	 //	 cout << plotCond << endl;
	 histDt11->Draw();
	 histDt11->Fit("fitty","Q");
	 Int_t numUnder= histDt11->GetBinContent(0);
	 Int_t numOver =histDt11->GetBinContent(1+histDt11->GetNbinsX());
// 	 cout << topAnt << "\t" << bottomAnt << "\t" << chip << "\t" << histDt11->GetEntries() << "\t"
// 	      << (histDt11->GetEntries()-(numOver+numUnder)) << "\t" << histDt11->GetMean() << "\t" << histDt11->GetRMS() << "\t"
// 	      << fitty->GetParameter(1) << "\t" << fitty->GetParError(1) << "\t" << fitty->GetParameter(2) << "\t"
// 	      << fitty->GetParError(2)  << "\t" << fitty->GetChisquare() << "\t" << fitty->GetNDF() << "\n";
	 histMeanDiff->Fill(fitty->GetParameter(1));
	 histChiSq->Fill(fitty->GetChisquare()/Double_t(fitty->GetNDF()));
	 histSigma->Fill(fitty->GetParameter(2));
	 histConstant->Fill(fitty->GetParameter(0));


	 Double_t constant=histDt11->GetMean();
	 Double_t error=0;
	 if(histDt11->GetEntries())
	    error=histDt11->GetRMS()/TMath::Sqrt(histDt11->GetEntries());
	 Int_t entries=(histDt11->GetEntries()-(numOver+numUnder));

	 if(TMath::Abs(fitty->GetParameter(1)-histDt11->GetMean())<0.01 || (entries>=20 && fitty->GetParError(1)<0.08)) {
	    constant=fitty->GetParameter(1);
	    error=fitty->GetParError(1);
	 }
	 else {
	    cout << topAnt << "\t" << bottomAnt << "\t" << chip << "\n";
	 }
	 Output << topAnt << "\t" << bottomAnt << "\t" << chip << "\t" << constant << "\t" << error << "\t"
		<< entries << "\n";
      }
	 
   }
   TCanvas *canSum = new TCanvas();
   canSum->Divide(2,2);
   canSum->cd(1);
   histChiSq->Draw();
   canSum->cd(2);
   histConstant->Draw();
   canSum->cd(3);
   histMeanDiff->Draw();
   canSum->cd(4);
   histSigma->Draw();    

      
}
Example #9
0
void plotLHCPPZHproj(variables var=km) {

  RooRealVar* costheta1 = new RooRealVar("costheta1","cos#theta_{1}",-1.,1.);
  RooRealVar* costheta2 = new RooRealVar("costheta2","cos#theta_{2}",-1.,1.);
  RooRealVar* phi = new RooRealVar("phi","#Phi",-TMath::Pi(),TMath::Pi());
  RooRealVar* m= new RooRealVar("m","m_{VH} [GeV]", 200, 1000);
  RooRealVar* Y= new RooRealVar("Y","Rapidity (VH)", -4, 4);
  // additional variables
  // event weight
  RooRealVar* wt = new RooRealVar("wt", "wt", 0.0, 50);

  vector<RooRealVar*> meas;
  meas.push_back(costheta1);
  meas.push_back(costheta2);
  meas.push_back(phi);
  meas.push_back(m);
  meas.push_back(Y);
  meas.push_back(wt);

  
  int parameterization = 1; 

  RooRealVar* mH = new RooRealVar("mH","m_{H}",125.);
  ScalarPdfFactoryPPZH SMHiggs(costheta1,costheta2,phi,m,Y,mH,parameterization,false);

  ScalarPdfFactoryPPZH psScalar(costheta1,costheta2,phi,m,Y,mH,parameterization,false);
  psScalar.g1Val->setVal(0.0);
  psScalar.g4Val->setVal(1.0);

  ScalarPdfFactoryPPZH f3p5Scalar(costheta1,costheta2,phi,m,Y,mH,parameterization,false);
  f3p5Scalar.g1Val->setVal(1.0);
  f3p5Scalar.g4Val->setVal(0.144708);

  ScalarPdfFactoryPPZH f3p5_90_Scalar(costheta1,costheta2,phi,m,Y,mH,parameterization,false);
  f3p5_90_Scalar.g1Val->setVal(1.0);
  f3p5_90_Scalar.g4ValIm->setVal(0.144708);


  //
  //  Read datasets
  // 
  TChain* SMHtree = new TChain("SelectedTree");
  SMHtree->Add("samples/pp_ZH/pp_ZH_llbb_g1_1M_false.root");
  RooDataSet dataTMPSMH("dataTMPSMH","dataTMPSMH", SMHtree, RooArgSet(*costheta1,*costheta2,*phi,*m,*Y, *wt));
  RooDataSet SMHdata = RooDataSet("SMHData","SMHData",RooArgList(*costheta1,*costheta2,*phi,*m, *Y, *wt), WeightVar("wt"), Import(dataTMPSMH));

  TChain* PStree = new TChain("SelectedTree");
  PStree->Add("samples/pp_ZH/pp_ZH_llbb_g4_1M_false.root");
  RooDataSet dataTMPPS("dataTMPPS","dataTMPPS", PStree, RooArgSet(*costheta1,*costheta2,*phi,*m,*Y, *wt));
  RooDataSet PSdata = RooDataSet("PSData","PSData",RooArgList(*costheta1,*costheta2,*phi,*m, *Y, *wt), WeightVar("wt"), Import(dataTMPPS));

  TChain* f3p5tree = new TChain("SelectedTree");
  f3p5tree->Add("samples/pp_ZH/pp_ZH_llbb_g1_p_g4_1M_false.root");
  RooDataSet dataTMPf3p5("dataTMPf3p5","dataTMPf3p5", f3p5tree, RooArgSet(*costheta1,*costheta2,*phi,*m,*Y, *wt));
  RooDataSet f3p5data = RooDataSet("f3p5Data","f3p5Data",RooArgList(*costheta1,*costheta2,*phi,*m, *Y, *wt), WeightVar("wt"), Import(dataTMPf3p5));

  TChain* f3p5_90_tree = new TChain("SelectedTree");
  f3p5_90_tree->Add("samples/pp_ZH/pp_ZH_llbb_g1_p_ig4_1M_false.root");
  RooDataSet dataTMPf3p5_90("dataTMPf3p5_90","dataTMPf3p5_90", f3p5_90_tree, RooArgSet(*costheta1,*costheta2,*phi,*m,*Y, *wt));
  RooDataSet f3p5_90_data = RooDataSet("f3p5_90Data","f3p5_90Data",RooArgList(*costheta1,*costheta2,*phi,*m, *Y, *wt), WeightVar("wt"), Import(dataTMPf3p5_90));
  
  TString varName = "costheta1";
  const int nbins = 20;
  double xMin =  -1; 
  double xMax = 1.;
  
  if ( var == kcostheta2 ) {
    varName = "costheta2";
  } else if( var == kphi)  {
    varName = "phi";
    xMin = -TMath::Pi();
    xMax = TMath::Pi();
  } else if ( var == km)   {
    varName = "m";
    xMin = 200;
    xMax = 1000.;
  } else if ( var == kY)  {
    varName = "Y";
    xMin = -4;
    xMax = 4;
  }
  // 
  // Do some gymnastics about the plots
  // normalize to 1
  // 
  
  TH1F *h_0p = new TH1F("h_0p", "h_0p", nbins, xMin, xMax);
  SMHtree->Project("h_0p", varName,"wt");
  double rescale_0p = 1./h_0p->Integral();
  h_0p->Scale(rescale_0p);
  // std::cout << "rescale_0p = " << rescale_0p << "\n";
  double ymax = h_0p->GetMaximum();
  
  TH1F *h_0m = new TH1F("h_0m", "h_0m", nbins, xMin, xMax); 
  PStree->Project("h_0m", varName,"wt");
  double rescale_0m = 1./h_0m->Integral();
  // std::cout << "rescale_0m = " << rescale_0m << "\n";
  h_0m->Scale(rescale_0m);
  ymax = h_0m->GetMaximum() > ymax ? h_0m->GetMaximum() : ymax;

  TH1F *h_0mix = new TH1F("h_0mix", "h_0mix", nbins, xMin, xMax);
  f3p5tree->Project("h_0mix", varName,"wt");
  double rescale_0mix = 1./h_0mix->Integral();
  // std::cout << "rescale_0mix = " << rescale_0mix << "\n";
  h_0mix->Scale(rescale_0mix);
  ymax = h_0mix->GetMaximum() > ymax ? h_0mix->GetMaximum() : ymax;

  TH1F *h_0mixphase = new TH1F("h_0mixphase", "h_0mixphase", nbins, xMin, xMax);
  f3p5_90_tree->Project("h_0mixphase", varName,"wt");
  double rescale_0mixphase = 1./h_0mixphase->Integral();
  // std::cout << "rescale_0mixphase = " << rescale_0mixphase << "\n";
  h_0mixphase->Scale(rescale_0mixphase);
  ymax = h_0mixphase->GetMaximum() > ymax ? h_0mixphase->GetMaximum() : ymax;
  

  // create rooplot and plot data/pdfs
  RooPlot* plot = (meas[var])->frame(nbins);
  
  SMHdata.plotOn(plot,MarkerColor(kRed),MarkerStyle(4),MarkerSize(1.5),XErrorSize(0),DataError(RooAbsData::None), Rescale(rescale_0p));
  SMHiggs.PDF->plotOn(plot,LineColor(kRed),LineWidth(2), Normalization(rescale_0p));

  PSdata.plotOn(plot,MarkerColor(kBlue),MarkerStyle(27),MarkerSize(1.9),XErrorSize(0),DataError(RooAbsData::None), Rescale(rescale_0m));
  psScalar.PDF->plotOn(plot,LineColor(kBlue),LineWidth(2), Normalization(rescale_0m));

  f3p5data.plotOn(plot,MarkerColor(kGreen+3),MarkerStyle(25),MarkerSize(1.5),XErrorSize(0),DataError(RooAbsData::None), Rescale(rescale_0mix));
  f3p5Scalar.PDF->plotOn(plot,LineColor(kGreen+3),LineWidth(2), Normalization(rescale_0mix));

  f3p5_90_data.plotOn(plot,MarkerColor(kMagenta+1),MarkerStyle(20), MarkerSize(1.5),XErrorSize(0),DataError(RooAbsData::None), Rescale(rescale_0mixphase));
  f3p5_90_Scalar.PDF->plotOn(plot,LineColor(kMagenta+1),LineWidth(2), Normalization(rescale_0mixphase));

  //TGaxis::SetMaxDigits(3);
  plot->SetMaximum(ymax*1.1);
  
  if ( var == km ) 
    plot->SetMaximum(ymax*1.3);

  TCanvas* can = new TCanvas("can","can",600,600);
  // plot styles
  // gStyle->SetPadLeftMargin(0.05);
  plot->GetXaxis()->CenterTitle();
  plot->GetYaxis()->CenterTitle();
  plot->GetYaxis()->SetTitle(" ");
  plot->GetXaxis()->SetNdivisions(505);
  plot->Draw();

  TString plotName = "h1";
  if ( var == kcostheta2) plotName = "h2";
  if ( var == kphi) plotName = "phi";
  if ( var == km) plotName = "mvh";
  if ( var == kY) plotName = "Yvh";
  
  can->SaveAs(Form("paperplots/%s_ppzh_pp_ZH_llbb_accfalse.eps", plotName.Data()));
  can->SaveAs(Form("paperplots/%s_ppzh_pp_ZH_llbb_accfalse.png", plotName.Data()));

  delete h_0p;
  delete h_0m;
  delete h_0mix;
  delete h_0mixphase;
  delete plot;
  delete can;
  delete SMHtree;
  delete PStree;
  delete f3p5tree;  
  delete f3p5_90_tree;
}
make_complete_histo(){

	
	TChain* genie = new TChain("MasterTree");
	genie->Add("Level7_genie_ic.1460.0000XX_LowE.root");

	//change these 3 numbers for the amount of bins: Warning, there is a n^2 efficiency so be careful 
	const int nbins_en = 10; 
	const int nbins_cos_theta = 10; 
	const int nbins_phi =4; 

	const int nbins_total = nbins_en*nbins_cos_theta*nbins_phi;
	double binedges_en[nbins_en+1];
	double binedges_cos_theta[nbins_cos_theta+1];
	double binedges_phi[nbins_phi+1];


	//The final matrix histogram
	TH2D* matrix_histo = new TH2D("matrix_histo","matrix_histo",nbins_total,0,nbins_total,nbins_total,0,nbins_total);


	//Initialise the bin edges
	binedges_en[0]=0.0;
	for (int i = 1; i < nbins_en+1; ++i){ binedges_en[i]= binedges_en[i-1] + 200/(double)nbins_en; }
	binedges_cos_theta[0]=-1.0;
	for (int i = 1; i < nbins_cos_theta+1; ++i){ binedges_cos_theta[i]= binedges_cos_theta[i-1] + 2/(double)nbins_cos_theta; }
	binedges_phi[0]=0.0;
	for (int i = 1; i < nbins_phi+1; ++i){ binedges_phi[i]= binedges_phi[i-1] + (2*TMath::Pi())/(double)nbins_phi; }	


	//Fill each bin with the # recon(ij) in true(mn)
	for (int true_e = 0; true_e < nbins_en; ++true_e){ //true energy bin loop
		for (int recon_e = 0; recon_e < nbins_en; ++recon_e){ //recon energy bin loop
			cout << endl<< true_e << " " << recon_e << endl;
			for (int true_theta = 0; true_theta < nbins_cos_theta; ++true_theta){
				for (int recon_theta = 0; recon_theta < nbins_cos_theta; ++recon_theta)
				{
					//create the histogram to read values from, setting energy cuts and theta bins
					TH2D* firstrun = new TH2D("firstrun","firstrun",nbins_phi,binedges_phi,nbins_phi,binedges_phi);
					//create the stupidly long cut 
					char* cut_e = Form("(MCMuon.energy >%8.7f && MultiNest8D_Track.energy >%8.7f && MCMuon.energy <=%8.7f && MultiNest8D_Track.energy <=%8.7f", binedges_en[true_e],binedges_en[recon_e], binedges_en[true_e+1], binedges_en[recon_e+1]);
					char* cut_theta = Form(" && TMath::Cos(MCMuon.zenith) >%8.7f && TMath::Cos(MultiNest8D_Track.zenith) >%8.7f && TMath::Cos(MCMuon.zenith) <=%8.7f && TMath::Cos(MultiNest8D_Track.zenith) <=%8.7f)", binedges_cos_theta[true_theta], binedges_cos_theta[recon_theta], binedges_cos_theta[true_theta+1], binedges_cos_theta[recon_theta+1] );
					char* cut_total[9999];	
					strcpy(cut_total, cut_e);


					//project all azimuth values for this cut
					genie->Project("firstrun","MCMuon.azimuth:MultiNest8D_Track.azimuth",strcat(cut_total, cut_theta));

					//move values into matrix_histo
					for (int t_bin = 0; t_bin < nbins_phi; ++t_bin){	
						for (int r_bin = 0; r_bin < nbins_phi; ++r_bin){
							//read for all azimuth angles for specific energy and zenith
							double tempval = firstrun->GetBinContent(r_bin+1,t_bin+1);
							matrix_histo->SetBinContent((recon_e*nbins_cos_theta*nbins_phi)+(true_theta*nbins_phi)+r_bin+1,(true_e*nbins_cos_theta*nbins_phi)+(recon_theta*nbins_phi)+t_bin+1, tempval);
						}
					}

					//delete histogram to free space for next loop
					delete firstrun;
					cout << true_theta << " " << recon_theta << endl;
				}
			}
		}
	}
	//save the histogram for later use
	matrix_histo->SaveAs(Form("icecube_energy_%d_cos_%d_phi_%d.root",nbins_en,nbins_cos_theta,nbins_phi));

}
Example #11
0
void ootpu_comparison(TString files, TString var, TString title, int nbins, float low, float high, TString comments="") {

  TChain* chain = new TChain("reduced_tree");
  chain->Add(files);

  TH1::SetDefaultSumw2();

  TH1F* hA = new TH1F("hA",title, nbins, low, high);
  TH1F* hB = new TH1F("hB",title, nbins, low, high);
  TH1F* hC = new TH1F("hC",title, nbins, low, high);
  TH1F* hD = new TH1F("hD",title, nbins, low, high);

  TH1F* hA_l = new TH1F("hA_l",title, nbins, low, high);
  TH1F* hB_l = new TH1F("hB_l",title, nbins, low, high);
  TH1F* hC_l = new TH1F("hC_l",title, nbins, low, high);
  TH1F* hD_l = new TH1F("hD_l",title, nbins, low, high);
  hA->SetStats(0);
  hA->GetYaxis()->SetLabelSize(0.04);
  //hA->GetYaxis()->SetTitleOffset(1.3);
  hA->GetXaxis()->SetTitleOffset(1.1);
  hA->GetXaxis()->SetTitleFont(132);
  hA->GetXaxis()->SetTitleSize(0.042);
  hA->GetXaxis()->SetLabelSize(0.04);
  hA->SetLineWidth(2);

  //  hA->StatOverflows(true);
  //  hB->StatOverflows(true);
  //  hC->StatOverflows(true);
  //  hD->StatOverflows(true);

  int n1(0), n2(0), n3(0), n4(0), n5(0);
  if (files.Contains("20bx25")) {
    n1=5;
    n2=17;
    n3=21;
    n4=25;
    n5=40;
  }
  else if (files.Contains("S14")) {
    n1=0;
    n2=25;
    n3=40;
    n4=55;
    n5=120;
  }
  else { // default: 8 TeV scenario
    n1=0;
    n2=15;
    n3=22;
    n4=32;
    n5=70;
  }


  TString mu("num_gen_muons==1&&muon_reco_match>=0");
  //if (files.Contains("PU_S10")) {
  TString cuts = Form("(%s)&&(eoot_pu>=%d&&eoot_pu<%d)",mu.Data(),n1,n2);
  cout << "Cuts: " << cuts.Data() << endl;
  chain->Project("hA", var, cuts);
  cuts = Form("(%s)&&(loot_pu>=%d&&loot_pu<%d)",mu.Data(),n1,n2);
  chain->Project("hA_l", var, cuts);
  cuts = Form("(%s)&&(eoot_pu>=%d&&eoot_pu<%d)",mu.Data(),n2,n3);
  cout << "Cuts: " << cuts.Data() << endl;
  chain->Project("hB", var, cuts);
  cuts = Form("(%s)&&(loot_pu>=%d&&loot_pu<%d)",mu.Data(),n2,n3);
  chain->Project("hB_l", var, cuts);
  cuts = Form("(%s)&&(eoot_pu>=%d&&eoot_pu<%d)",mu.Data(),n3,n4);
  cout << "Cuts: " << cuts.Data() << endl;
  chain->Project("hC", var, cuts);
  cuts = Form("(%s)&&(loot_pu>=%d&&loot_pu<%d)",mu.Data(),n3,n4);
  chain->Project("hC_l", var, cuts);
  cuts = Form("(%s)&&(eoot_pu>=%d)",mu.Data(),n4);
  cout << "Cuts: " << cuts.Data() << endl;
  chain->Project("hD", var, cuts);
  cuts = Form("(%s)&&(loot_pu>=%d)",mu.Data(),n4);
  chain->Project("hD_l", var, cuts);
  // }
  // else {
  //  }
  
  float avg1(hA->GetMean());
  float avg2(hB->GetMean());
  float avg3(hC->GetMean());
  float avg4(hD->GetMean());

  hA->Scale(1/hA->Integral());
  hB->Scale(1/hB->Integral());
  hC->Scale(1/hC->Integral());
  hD->Scale(1/hD->Integral());

  hA->SetLineColor(1);
  hB->SetLineColor(2);
  hC->SetLineColor(3);
  hD->SetLineColor(4);

  hA->SetLineWidth(2);
  hB->SetLineWidth(2);
  hC->SetLineWidth(2);
  hD->SetLineWidth(2);

  float avg1_l(hA_l->GetMean());
  float avg2_l(hB_l->GetMean());
  float avg3_l(hC_l->GetMean());
  float avg4_l(hD_l->GetMean());

  hA_l->Scale(1/hA_l->Integral());
  hB_l->Scale(1/hB_l->Integral());
  hC_l->Scale(1/hC_l->Integral());
  hD_l->Scale(1/hD_l->Integral());

  hA_l->SetLineColor(12);
  hB_l->SetLineColor(46);
  hC_l->SetLineColor(8);
  hD_l->SetLineColor(7);

  hA_l->SetLineWidth(2);
  hB_l->SetLineWidth(2);
  hC_l->SetLineWidth(2);
  hD_l->SetLineWidth(2);

  TCanvas* c1 = new TCanvas();
  float max = TMath::Max(hA->GetMaximum(), hB->GetMaximum());
  if (hC->GetMaximum()>max) max = hC->GetMaximum();
  if (hD->GetMaximum()>max) max = hD->GetMaximum();

  hA->SetMaximum(max*1.1);
  hA->Draw("hist");
  hB->Draw("hist,same");
  hC->Draw("hist,same");
  hD->Draw("hist,same");
  hA_l->Draw("hist,same");
  hB_l->Draw("hist,same");
  hC_l->Draw("hist,same");
  hD_l->Draw("hist,same");

  TLegend* leg = new TLegend(0.42,0.6,0.9,0.9);
  leg->SetFillStyle(0);
  char label[1000];
  sprintf(label,"%d#leqEarly Ints.<%d (#mu=%3.3f)",n1,n2,avg1);
  leg->AddEntry(hA,label,"lp");
  sprintf(label,"%d#leqEarly Ints.<%d (#mu=%3.3f)",n2,n3,avg2);
  leg->AddEntry(hB,label,"lp");
  sprintf(label,"%d#leqEarly Ints.<%d (#mu=%3.3f)",n3,n4,avg3);
  leg->AddEntry(hC,label,"lp");
  sprintf(label,"Early Ints.>%d (#mu=%3.3f)",n4,avg4);
  leg->AddEntry(hD,label,"lp");
  // leg->Draw();

  TString plotTitle ="relIso_vs_early_and_late_OOTPU_"+var+comments+".pdf";
  c1->Print(plotTitle);

  cout << "Rejection rates" << endl;
  Double_t left(0.), lerror(0.), right(0.), rerror(0.);
  left = hA->IntegralAndError(1,12,lerror);
  right = hA->IntegralAndError(13,31,rerror);
  float rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  printf("bin1: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  left = hB->IntegralAndError(1,12,lerror);
  right = hB->IntegralAndError(13,31,rerror);
  rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  printf("bin2: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  left = hC->IntegralAndError(1,12,lerror);
  right = hC->IntegralAndError(13,31,rerror);
  rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  printf("bin3: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  left = hD->IntegralAndError(1,12,lerror);
  right = hD->IntegralAndError(13,31,rerror);
  rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  printf("bin4: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
}
Example #12
0
TGraphAsymmErrors* GetCombinedEfficiency(const TString cut = "min_delta_phi_met_N>4.", const TString preselection="")
{ 
  
  TH1::SetDefaultSumw2();

  const int nbins=16;
  const double varbins[nbins+1]={0,20,40,60,80,100,125,150,175,200,250,300,400,500,600,800,1000};


    
  TCut all(preselection);
  TCut ccut(cut);
  TCut pass(all+ccut);


  TFile *fout = new TFile("macros/qcd_control/output.root", "recreate");
  fout->cd();

  cout << "Denom. cuts: " << (string)all << endl;
  cout << "Num. cuts: " << (string)pass << endl;

  TList* pList=new TList();
  vector<TH1D> v_all, v_pass;

  for (unsigned int sample(0); sample<nSamples; sample++) {
      
    TChain * ch = new TChain();
    ch->Add(qcd_files[sample]+"/reduced_tree");


    TH1D* hMETall = new TH1D(Form("hMETall_%d",sample),"hMETall",nbins,varbins);
    TH1D* hMETpass = new TH1D(Form("hMETpass_%d",sample),"hMETpass",nbins,varbins);

    ch->Project(hMETall->GetName(),"met",all);
    ch->Project(hMETpass->GetName(),"met",pass);

    Double_t e_overflow(0.), i_overflow(0.);
    i_overflow=hMETall->IntegralAndError(nbins,nbins+1,e_overflow);
    hMETall->SetBinContent(nbins, i_overflow);
    hMETall->SetBinError(nbins, e_overflow);
    i_overflow=hMETpass->IntegralAndError(nbins,nbins+1,e_overflow);
    hMETpass->SetBinContent(nbins, i_overflow);
    hMETpass->SetBinError(nbins, e_overflow);

    printf("Sample %d: hMETpass/hMETall=%.1f/%.1f\n",sample, hMETpass->Integral(),hMETall->Integral());

      
    delete ch;

    v_all.push_back(*hMETall);
    v_pass.push_back(*hMETpass);

    delete hMETall;
    delete hMETpass;

  }

  for (unsigned int sample(0); sample<nSamples; sample++) {
    cout << "Found hist " << v_all[sample].GetName() << endl;
    v_all[sample].Write();
    v_pass[sample].Write();
    TEfficiency* pEff = new TEfficiency(v_pass[sample],v_all[sample]);
    pList->Add(pEff);
  }

  TGraphAsymmErrors* gr = TEfficiency::Combine(pList,"v,mode",nSamples,weights);
  return gr;
}
Example #13
0
void TriggerStudy(int initialRunNumber){
  gStyle->SetOptStat("neMRIuo");
  gSystem->Load("../E14_ANA_COSMIC/lib/libtest.so");
  IDHandler* handler = new IDHandler(" ../E14_ANA_COSMIC/Data/crystal.txt");
  CsIImage*  image[4];
  for( int i = 0; i< 4; i++){
    image[i] = new CsIImage(handler);
  }

  const Int_t nRUN     = 4;
  char* name[4]        ={"Double_et","4Cluster_200MeV","4Cluster_160MeV","3Cluster_370MeV"};
  Int_t RunNumber[4]={3969,4089,4094,4097};
  Double_t SECValue[4] ={257727,327229,286614,303859};
  Double_t Spill[4]    ={145,184,162,172}; 
  
  TH1D* hisKLMass[4];
  TH1D* hisKLMom[4];
  TH1D* TextMassEntries[4];
  TH1D* TextMomEntries[4];
  
  TChain* ch[4];
  for( int i =0 ;i< 4; i++){
    ch[i] = new TChain("Tree");
    ch[i]->Add(Form("klongRootFile/kl%04d.root",RunNumber[i]));
  };
  
  TH1D* hisKLMass[3];
  TH1D* hisKLMom[2];
  TText* textMassEntries[3];
  TText* textMomEntries[2];
  


  hisKLMass[0] = new TH1D("hisKLMassWithNOCut",Form("KLMass%06d;Mass[MeV];N/5MeV"          ,initialRunNumber),80,400,800);
  hisKLMass[1] = new TH1D("hisKLMassCutSome"  ,Form("KLMassWithCut%06d;Mass[MeV];N/5MeV"   ,initialRunNumber),80,400,800);
  hisKLMass[2] = new TH1D("hisKLMassCutFull"  ,Form("KLMassWithAllCut%06d;Mass[MeV];N/5MeV",initialRunNumber),80,400,800);
  hisKLMass[0]->SetLineColor(1);
  hisKLMass[1]->SetLineColor(2);
  hisKLMass[2]->SetLineColor(3);
  hisKLMom[0] = new TH1D("hisKLMomWithNOCut","KLMomentum;Momentum[MeV];N/20MeV",300,0,6000);
  hisKLMom[1] = new TH1D("hisKLMomCut0x00F" ,"KLMomentum;Momentum[MeV];N/20MeV",300,0,6000);
  hisKLMom[1]->SetLineColor(2);
  
  TChain* ch  = new TChain("Tree");
  ch->Add(Form("klongRootFile/kl%04d.root",initialRunNumber));
  
  ch->Project(hisKLMass[0]->GetName(),"KlongMass[0]");
  ch->Project(hisKLMass[1]->GetName(),"KlongMass[0]" ,"(CutCondition & (8))==0 && TMath::Abs(KlongMass[0]-498) < 10");
  ch->Project(hisKLMass[2]->GetName(),"KlongMass[0]" ,"(CutCondition & (1+2+4+8))==0 && TMath::Abs(KlongMass[0]-498)<10");
  ch->Project(hisKLMom[0]->GetName() ,"KlongMom[0][2]");
  ch->Project(hisKLMom[1]->GetName() ,"KlongMom[0][2]","(CutCondition & (1+2+4+8))==0");  
  TCanvas* can = new TCanvas("can","",1200,600);
  can->Divide(2,1);

  std::cout << hisKLMass[0]->GetEntries() << std::endl;
  std::cout << hisKLMass[1]->GetEntries() << std::endl;
  
  can->cd(1);
  gPad->SetLogy();
  hisKLMass[0]->Draw();
  hisKLMass[1]->Draw("same");
  hisKLMass[2]->Draw("same");
  textMassEntries[0] = new TText(0.5,0.5,"");
  textMassEntries[1] = new TText(0.5,0.5,"");
  textMassEntries[2] = new TText(0.5,0.5,"");
  textMassEntries[0]->SetTextSize(0.04);
  textMassEntries[1]->SetTextSize(0.04);
  textMassEntries[2]->SetTextSize(0.04);
  textMassEntries[0]->SetTextColor(1);
  textMassEntries[1]->SetTextColor(2);
  textMassEntries[2]->SetTextColor(3);
  textMassEntries[0]->DrawTextNDC(0.5,0.6,Form("#of Klong(NoCut):%d",(int)hisKLMass[0]->GetEntries()));
  textMassEntries[1]->DrawTextNDC(0.5,0.55,Form("#of Klong(SumeCut):%d",(int)hisKLMass[1]->GetEntries()));
  textMassEntries[2]->DrawTextNDC(0.5,0.5,Form("#of Klong(FullCut):%d",(int)hisKLMass[2]->GetEntries()));

  can->cd(2);
  gPad->SetLogy();
  hisKLMom[0]->Draw();
  hisKLMom[1]->Draw("same");
  can->SaveAs(Form("Image/KLong_%06d.gif",initialRunNumber));
}
Example #14
0
void optimize_n_jets(const TString sigName = "reduced_trees/SMS-T1tttt_2J_mGl-1500_mLSP-100*v75*.root", const TString bgName = "all", const TString plotNote="T1tttt_1500_100_met_200_ht40_1000", const TCut cuts="") 
{
  set_plot_style();
  TH1::StatOverflows(true);
  TH1::SetDefaultSumw2(); //trick to turn on Sumw2 for all histos
  //TH1::SetStats(0);

  const unsigned int nbins = 16;

  TH1D* h_n30sig = new TH1D("h_n30sig",";n_{jets};Events after cut (#int L dt = 5 fb^{-1})",nbins,0.,16.);
  TH1D* h_n30bg = new TH1D("h_n30bg","",nbins,0.,16.);
  TH1D* h_n40sig = new TH1D("h_n40sig","",nbins,0.,16.);
  TH1D* h_n40bg = new TH1D("h_n40bg","",nbins,0.,16.);
  TH1D* h_n50sig = new TH1D("h_n50sig","",nbins,0.,16.);
  TH1D* h_n50bg = new TH1D("h_n50bg","",nbins,0.,16.);
  TH1D* h_n70sig = new TH1D("h_n70sig","",nbins,0.,16.);
  TH1D* h_n70bg = new TH1D("h_n70bg","",nbins,0.,16.);
  TH1D* h_n100sig = new TH1D("h_n100sig","",nbins,0.,16.);
  TH1D* h_n100bg = new TH1D("h_n100bg","",nbins,0.,16.);

  // TH1D* h_n30sig_pass = new TH1D("h_n30sig_pass",";n_{jets};EventsPassing cut",nbins,0.,16.);
  // TH1D* h_n40sig_pass = new TH1D("h_n40sig_pass","",nbins,0.,16.);
  // TH1D* h_n50sig_pass = new TH1D("h_n50sig_pass","",nbins,0.,16.);
  // TH1D* h_n70sig_pass = new TH1D("h_n70sig_pass","",nbins,0.,16.);
  // TH1D* h_n100sig_pass = new TH1D("h_n100sig_pass","",nbins,0.,16.);

  TH1D* h_n30s_over_sqrt_b = new TH1D("h_n30s_over_sqrt_b",";n_{jets} cut;S/#sqrt{B}",nbins,0.,16.);
  TH1D* h_n40s_over_sqrt_b = new TH1D("h_n40s_over_sqrt_b","",nbins,0.,16.);
  TH1D* h_n50s_over_sqrt_b = new TH1D("h_n50s_over_sqrt_b","",nbins,0.,16.);
  TH1D* h_n70s_over_sqrt_b = new TH1D("h_n70s_over_sqrt_b","",nbins,0.,16.);
  TH1D* h_n100s_over_sqrt_b = new TH1D("h_n100s_over_sqrt_b","",nbins,0.,16.);

  h_n30sig->SetStats(0);
  h_n30s_over_sqrt_b->SetStats(0);


  TCut start(cuts+"met>200&&ht40>500&&num_csvm_jets30>1&&min_delta_phi_met_N>4&&num_reco_veto_muons==0&&num_reco_veto_electrons==0");
  TCut weighted_selection(start*"(weightppb*5000.)");

  TChain * bg = new TChain("reduced_tree");
  TChain * sig = new TChain("reduced_tree");
  if (!bgName.EqualTo("all")) bg->Add(bgName);// treestring is passed as an argument
  else {
    bg->Add("reduced_trees/skimmed/TTJets*v75*.root");
    bg->Add("reduced_trees/skimmed/QCD*v75*.root");
    bg->Add("reduced_trees/skimmed/WJets*v75*.root");
    bg->Add("reduced_trees/skimmed/ZJets*v75*.root");
    bg->Add("reduced_trees/skimmed/TTo*v75*.root");
    bg->Add("reduced_trees/skimmed/TBarTo*v75*.root");
    bg->Add("reduced_trees/skimmed/*tW*v75*.root");
    bg->Add("reduced_trees/skimmed/*HToBB*v75*.root");
    bg->Add("reduced_trees/skimmed/TTbarH*v75*.root");
  }
  sig->Add(sigName);

  TCanvas * thecanvas= new TCanvas("thecanvas","the canvas",800,1600);
  TPad* pad1 = new TPad("pad1","This is pad1",0.,0.5,1,1);
  TPad* pad2 = new TPad("pad1","This is pad2",0.,0.,1,0.5);
  pad1->Draw();
  pad2->Draw();

  sig->Project("h_n30sig","num_jets_pt30",weighted_selection);
  bg->Project("h_n30bg","num_jets_pt30",weighted_selection);
  sig->Project("h_n40sig","num_jets_pt40",weighted_selection);
  bg->Project("h_n40bg","num_jets_pt40",weighted_selection);
  sig->Project("h_n50sig","num_jets_pt50",weighted_selection);
  bg->Project("h_n50bg","num_jets_pt50",weighted_selection);
  sig->Project("h_n70sig","num_jets_pt70",weighted_selection);
  bg->Project("h_n70bg","num_jets_pt70",weighted_selection);
  sig->Project("h_n100sig","num_jets_pt100",weighted_selection);
  bg->Project("h_n100bg","num_jets_pt100",weighted_selection);

  convert_to_int(h_n30sig);
  convert_to_int(h_n40sig);
  convert_to_int(h_n50sig);
  convert_to_int(h_n70sig);
  convert_to_int(h_n100sig);
  convert_to_int(h_n30bg);
  convert_to_int(h_n40bg);
  convert_to_int(h_n50bg);
  convert_to_int(h_n70bg);
  convert_to_int(h_n100bg);

  for (unsigned int bin(0); bin<nbins+1; bin++) {
    if (h_n30bg->GetBinContent(bin+1)>0) h_n30s_over_sqrt_b->SetBinContent(bin+1, h_n30sig->GetBinContent(bin+1)/sqrt(h_n30bg->GetBinContent(bin+1)));
    else h_n30s_over_sqrt_b->SetBinContent(bin+1,100.);
    if (h_n40bg->GetBinContent(bin+1)>0) h_n40s_over_sqrt_b->SetBinContent(bin+1, h_n40sig->GetBinContent(bin+1)/sqrt(h_n40bg->GetBinContent(bin+1)));
    else h_n40s_over_sqrt_b->SetBinContent(bin+1,100.);
    if (h_n50bg->GetBinContent(bin+1)>0) h_n50s_over_sqrt_b->SetBinContent(bin+1, h_n50sig->GetBinContent(bin+1)/sqrt(h_n50bg->GetBinContent(bin+1)));
    else h_n50s_over_sqrt_b->SetBinContent(bin+1,100.);
    if (h_n70bg->GetBinContent(bin+1)>0) h_n70s_over_sqrt_b->SetBinContent(bin+1, h_n70sig->GetBinContent(bin+1)/sqrt(h_n70bg->GetBinContent(bin+1)));
    else h_n70s_over_sqrt_b->SetBinContent(bin+1,100.);
    if (h_n100bg->GetBinContent(bin+1)>0) h_n100s_over_sqrt_b->SetBinContent(bin+1, h_n100sig->GetBinContent(bin+1)/sqrt(h_n100bg->GetBinContent(bin+1)));
    else h_n100s_over_sqrt_b->SetBinContent(bin+1,100.);
   
    // h_n30sig_pass->SetBinContent(bin+1, h_n30sig->Integral(bin+1,nbins+1));
    // h_n40sig_pass->SetBinContent(bin+1, h_n40sig->Integral(bin+1,nbins+1));
    // h_n50sig_pass->SetBinContent(bin+1, h_n50sig->Integral(bin+1,nbins+1));
    // h_n70sig_pass->SetBinContent(bin+1, h_n70sig->Integral(bin+1,nbins+1));
    // h_n100sig_pass->SetBinContent(bin+1, h_n100sig->Integral(bin+1,nbins+1));
  }

  h_n30s_over_sqrt_b->SetLineColor(1);
  h_n40s_over_sqrt_b->SetLineColor(2);
  h_n50s_over_sqrt_b->SetLineColor(3);
  h_n70s_over_sqrt_b->SetLineColor(kOrange);
  h_n100s_over_sqrt_b->SetLineColor(kCyan);
  h_n30s_over_sqrt_b->SetLineWidth(3);
  h_n40s_over_sqrt_b->SetLineWidth(3);
  h_n50s_over_sqrt_b->SetLineWidth(3);
  h_n70s_over_sqrt_b->SetLineWidth(3);
  h_n100s_over_sqrt_b->SetLineWidth(3);

  h_n30sig->SetLineColor(1);
  h_n40sig->SetLineColor(2);
  h_n50sig->SetLineColor(3);
  h_n70sig->SetLineColor(kOrange);
  h_n100sig->SetLineColor(kCyan);
  h_n30sig->SetLineWidth(3);
  h_n40sig->SetLineWidth(3);
  h_n50sig->SetLineWidth(3);
  h_n70sig->SetLineWidth(3);
  h_n100sig->SetLineWidth(3);
 
  pad1->cd();
  h_n30sig->Draw("hist");
  h_n40sig->Draw("hist,same");
  h_n50sig->Draw("hist,same");
  h_n70sig->Draw("hist,same");
  h_n100sig->Draw("hist,same");

  TLegend* leg = new TLegend(0.7,0.7,0.9,0.9);
  leg->SetFillStyle(0);
  leg->SetLineStyle(0);
  leg->SetTextFont(132);
  leg->AddEntry(h_n30s_over_sqrt_b,"p_{T} > 30 GeV","l");
  leg->AddEntry(h_n40s_over_sqrt_b,"p_{T} > 40 GeV","l");
  leg->AddEntry(h_n50s_over_sqrt_b,"p_{T} > 50 GeV","l");
  leg->AddEntry(h_n70s_over_sqrt_b,"p_{T} > 70 GeV","l");
  leg->AddEntry(h_n100s_over_sqrt_b,"p_{T} > 100 GeV","l");
  leg->Draw();

  pad2->cd();
  h_n30s_over_sqrt_b->SetMinimum(0);
  if (sigName.Contains("tttt")||sigName.Contains("1000")) h_n30s_over_sqrt_b->SetMaximum(5);
  else h_n30s_over_sqrt_b->SetMaximum(2.5);
  h_n30s_over_sqrt_b->Draw("hist");
  h_n40s_over_sqrt_b->Draw("hist,same");
  h_n50s_over_sqrt_b->Draw("hist,same");
  h_n70s_over_sqrt_b->Draw("hist,same");
  h_n100s_over_sqrt_b->Draw("hist,same");



  thecanvas->Print("macros/cutflow/plots/optimize_n_jets/n_jets_optimization_"+plotNote+".pdf");


}
Example #15
0
void plot(){
	gStyle->SetOptStat(0);

	int run_number = 4085; cerr<<"---- Run Number = "; cin >> run_number;
	TString SAMC_File = "";cerr<<"---- SAMC File = "; cin >> SAMC_File;
    TString Target = ""; cerr<<"---- Target = "; cin >> Target;
	TString Kin = ""; cerr<<"---- Kin = "; cin >> Kin;

	/*Ploting EX Data{{{*/
	TString GeneralCut = "L.tr.n==1";//&&abs(L.tr.x)<0.75 && abs(L.tr.y)<0.55 && abs(L.tr.th)<0.15 && abs(L.tr.ph)<0.045";
	TString TriggerCut3 = "((DBB.evtypebits>>3)&1)";
	TString TriggerCut7 = "((DBB.evtypebits>>7)&1)";
	Double_t y_cut = 0.170;
	TString Acc_real = Form("abs(ExTgtL.th)<0.03&&abs(ExTgtL.ph)<0.02&&abs(ExTgtL.y)<%f&&abs(ExTgtL.dp)<0.04&&abs(RctPtL.z)<0.070",y_cut);
	TString Cut_All = GeneralCut+"&&"+TriggerCut3+"&&"+Acc_real
		+"&&L.cer.asum_c>=50.&&L.prl2.e>=100.&&(L.prl1.e+L.prl2.e)/L.tr.p/1000.>=0.5";
	//TString Cut_All ="1";

	double scale;  int norm = 100000;

	TString filename=Form("/work/halla/e08014/disk1/Rootfiles/e08014_%d.root",run_number);
	TChain *T = new TChain("T");
	T->Add(filename);

	/*Focal Plane{{{*/
	//X_fp
	TH1F *h_xfp = new TH1F("h_xfp","", 100, -1.15,1.15);
	h_xfp->SetXTitle("x_{fp}");
	h_xfp->SetLineColor(2); 
	h_xfp->SetLineWidth(1.1);
	h_xfp->GetXaxis()->SetTitleSize(0.08);
	h_xfp->GetXaxis()->SetTitleOffset(0.7);
	h_xfp->GetXaxis()->CenterTitle(1);
	T->Project("h_xfp","L.tr.r_x",Cut_All);
	scale = norm/h_xfp->Integral(); h_xfp->Scale(scale);
	//Y_fp
	TH1F *h_yfp = new TH1F("h_yfp","", 100, -0.05,0.05);
	h_yfp->SetXTitle("y_{fp}");
	h_yfp->SetLineColor(2); 
	h_yfp->SetLineWidth(1.1);
	h_yfp->GetXaxis()->SetTitleSize(0.08);
	h_yfp->GetXaxis()->SetTitleOffset(0.7);
	h_yfp->GetXaxis()->CenterTitle(1);
	T->Project("h_yfp","L.tr.r_y",Cut_All);
	scale = norm/h_yfp->Integral(); h_yfp->Scale(scale);
	//Th_fp
	TH1F *h_tfp = new TH1F("h_tfp","", 100, -0.02,0.02);
	h_tfp->SetXTitle("#theta_{fp}");
	h_tfp->SetLineColor(2); 
	h_tfp->SetLineWidth(1.1);
	h_tfp->GetXaxis()->SetTitleSize(0.08);
	h_tfp->GetXaxis()->SetTitleOffset(0.7);
	h_tfp->GetXaxis()->CenterTitle(1);
	T->Project("h_tfp","L.tr.r_th",Cut_All);
	scale = norm/h_tfp->Integral(); h_tfp->Scale(scale);
	//Ph_fp
	TH1F *h_pfp = new TH1F("h_pfp","", 100, -0.05,0.05);
	h_pfp->SetXTitle("#phi_{fp}");
	h_pfp->SetLineColor(2); 
	h_pfp->SetLineWidth(1.1);
	h_pfp->GetXaxis()->SetTitleSize(0.08);
	h_pfp->GetXaxis()->SetTitleOffset(0.7);
	h_pfp->GetXaxis()->CenterTitle(1);
	T->Project("h_pfp","L.tr.r_ph",Cut_All);
	scale = norm/h_pfp->Integral(); h_pfp->Scale(scale);
	/*}}}*/

	/*Target Plane{{{*/
	//DeltaP
	TH1F *h_dtg = new TH1F("h_dtg","", 100, -0.07,0.07);
	h_dtg->SetXTitle("#delta P");
	h_dtg->SetLineColor(2); 
	h_dtg->SetLineWidth(1.1);
	h_dtg->GetXaxis()->SetTitleSize(0.08);
	h_dtg->GetXaxis()->SetTitleOffset(0.7);
	h_dtg->GetXaxis()->CenterTitle(1);
	T->Project("h_dtg","ExTgtL.dp",Cut_All);
	scale = norm/h_dtg->Integral(); h_dtg->Scale(scale);
	//Y_tg  
	TH1F *h_ytg = new TH1F("h_ytg","", 100, -0.07,0.07);
	h_ytg->SetXTitle("y_{tg}");
	h_ytg->SetLineColor(2); 
	h_ytg->SetLineWidth(1.1);
	h_ytg->GetXaxis()->SetTitleSize(0.08);
	h_ytg->GetXaxis()->SetTitleOffset(0.7);
	h_ytg->GetXaxis()->CenterTitle(1);
	T->Project("h_ytg","ExTgtL.y",Cut_All);
	scale = norm/h_ytg->Integral(); h_ytg->Scale(scale);
	//Z_react
	TH1F *h_ztg = new TH1F("h_ztg","", 100, -0.12,0.12);
	h_ztg->SetXTitle("z_{react}");
	h_ztg->SetLineColor(2); 
	h_ztg->SetLineWidth(1.1);
	h_ztg->GetXaxis()->SetTitleSize(0.08);
	h_ztg->GetXaxis()->SetTitleOffset(0.7);
	h_ztg->GetXaxis()->CenterTitle(1);
	T->Project("h_ztg","RctPtL.z",Cut_All);
	scale = norm/h_ztg->Integral(); h_ztg->Scale(scale);
	//Th_tg  
	TH1F *h_ttg = new TH1F("h_ttg","", 100, -0.05,0.05);
	h_ttg->SetXTitle("#theta_{tg}");
	h_ttg->SetLineColor(2); 
	h_ttg->SetLineWidth(1.1);
	h_ttg->GetXaxis()->SetTitleSize(0.08);
	h_ttg->GetXaxis()->SetTitleOffset(0.7);
	h_ttg->GetXaxis()->CenterTitle(1);
	T->Project("h_ttg","ExTgtL.th",Cut_All);
	scale = norm/h_ttg->Integral(); h_ttg->Scale(scale);
	//Ph_tg  
	TH1F *h_ptg = new TH1F("h_ptg","", 100, -0.03,0.03);
	h_ptg->SetXTitle("#phi_{tg}");
	h_ptg->SetLineColor(2); 
	h_ptg->SetLineWidth(1.1);
	h_ptg->GetXaxis()->SetTitleSize(0.08);
	h_ptg->GetXaxis()->SetTitleOffset(0.7);
	h_ptg->GetXaxis()->CenterTitle(1);
	T->Project("h_ptg","ExTgtL.ph",Cut_All);
	scale = norm/h_ptg->Integral(); h_ptg->Scale(scale);
	/*}}}*/

   	/*}}}*/

	/*Ploting MC Data{{{*/
	 TChain* S = new TChain("SAMC");
	 S->Add(SAMC_File);

	TString Cut_MC = Form("abs(th_tg_rec)<0.03&&abs(ph_tg_rec)<0.02&&abs(y_tg_rec)<%f&&abs(dp_rec)<0.04&&abs(reactz_rec)<0.10",y_cut);

	/*Focal Plane{{{*/
	//X_fp
	TH1F *m_xfp = new TH1F("m_xfp","", 100,-1.15,1.15);
	m_xfp->SetXTitle("x_{fp}");
	m_xfp->SetLineColor(4); 
	m_xfp->SetLineWidth(1.1);
	m_xfp->GetXaxis()->SetTitleSize(0.08);
	m_xfp->GetXaxis()->SetTitleOffset(0.7);
	m_xfp->GetXaxis()->CenterTitle(1);
	//Y_fp
	TH1F *m_yfp = new TH1F("m_yfp","", 100, -0.05,0.05);
	m_yfp->SetXTitle("y_{fp}");
	m_yfp->SetLineColor(4); 
	m_yfp->SetLineWidth(1.1);
	m_yfp->GetXaxis()->SetTitleSize(0.08);
	m_yfp->GetXaxis()->SetTitleOffset(0.7);
	m_yfp->GetXaxis()->CenterTitle(1);
	//Th_fp
	TH1F *m_tfp = new TH1F("m_tfp","", 100, -0.02,0.02);
	m_tfp->SetXTitle("#theta_{fp}");
	m_tfp->SetLineColor(4); 
	m_tfp->SetLineWidth(1.1);
	m_tfp->GetXaxis()->SetTitleSize(0.08);
	m_tfp->GetXaxis()->SetTitleOffset(0.7);
	m_tfp->GetXaxis()->CenterTitle(1);
	//Ph_fp
	TH1F *m_pfp = new TH1F("m_pfp","", 100, -0.05,0.05);
	m_pfp->SetXTitle("#phi_{fp}");
	m_pfp->SetLineColor(4); 
	m_pfp->SetLineWidth(1.1);
	m_pfp->GetXaxis()->SetTitleSize(0.08);
	m_pfp->GetXaxis()->SetTitleOffset(0.7);
	m_pfp->GetXaxis()->CenterTitle(1);
	/*}}}*/

	/*Target Plane{{{*/
	//DeltaP
	TH1F *m_dtg = new TH1F("m_dtg","", 100, -0.07,0.07);
	m_dtg->SetXTitle("#delta P");
	m_dtg->SetLineColor(4); 
	m_dtg->SetLineWidth(1.1);
	m_dtg->GetXaxis()->SetTitleSize(0.08);
	m_dtg->GetXaxis()->SetTitleOffset(0.7);
	m_dtg->GetXaxis()->CenterTitle(1);
	//Y_tg  
	TH1F *m_ytg = new TH1F("m_ytg","", 100, -0.07,0.07);
	m_ytg->SetXTitle("y_{tg}");
	m_ytg->SetLineColor(4); 
	m_ytg->SetLineWidth(1.1);
	m_ytg->GetXaxis()->SetTitleSize(0.08);
	m_ytg->GetXaxis()->SetTitleOffset(0.7);
	m_ytg->GetXaxis()->CenterTitle(1);
	//Z_react
	TH1F *m_ztg = new TH1F("m_ztg","", 100, -0.12,0.12);
	m_ztg->SetXTitle("z_{react}");
	m_ztg->SetLineColor(4); 
	m_ztg->SetLineWidth(1.1);
	m_ztg->GetXaxis()->SetTitleSize(0.08);
	m_ztg->GetXaxis()->SetTitleOffset(0.7);
	m_ztg->GetXaxis()->CenterTitle(1);
	//Th_tg  
	TH1F *m_ttg = new TH1F("m_ttg","", 100, -0.05,0.05);
	m_ttg->SetXTitle("#theta_{tg}");
	m_ttg->SetLineColor(4); 
	m_ttg->SetLineWidth(1.1);
	m_ttg->GetXaxis()->SetTitleSize(0.08);
	m_ttg->GetXaxis()->SetTitleOffset(0.7);
	m_ttg->GetXaxis()->CenterTitle(1);
	//Ph_tg  
	TH1F *m_ptg = new TH1F("m_ptg","", 100, -0.03,0.03);
	m_ptg->SetXTitle("#phi_{tg}");
	m_ptg->SetLineColor(4); 
	m_ptg->SetLineWidth(1.1);
	m_ptg->GetXaxis()->SetTitleSize(0.08);
	m_ptg->GetXaxis()->SetTitleOffset(0.7);
	m_ptg->GetXaxis()->CenterTitle(1);
	/*}}}*/

	/*Fill Histograms{{{*/
	/*Set BranchAddress{{{*/
    int IsPassed,IsQualified;
	double x_fp,y_fp,th_fp,ph_fp,x_tg_rec, y_tg_rec,th_tg_rec,ph_tg_rec,dp_rec,reactz_rec,Angle_rec;
	S->SetBranchAddress("IsPassed",&IsPassed); //if pass through the magnet, 1=true, 0=false(not pass)
	S->SetBranchAddress("IsQualified",&IsQualified); //if rec var is in the range of gen, 1=true, 0=false(not
	S->SetBranchAddress("x_fp",&x_fp    ); //
	S->SetBranchAddress("y_fp",&y_fp    ); //
	S->SetBranchAddress("th_fp",&th_fp    ); //
	S->SetBranchAddress("ph_fp",&ph_fp    ); //
	S->SetBranchAddress("x_tg_rec",&x_tg_rec    ); //cm
	S->SetBranchAddress("y_tg_rec",&y_tg_rec    ); //cm
	S->SetBranchAddress("th_tg_rec",&th_tg_rec    ); //
	S->SetBranchAddress("ph_tg_rec",&ph_tg_rec    ); //
	S->SetBranchAddress("dp_rec",&dp_rec    );
	S->SetBranchAddress("Angle_rec",&Angle_rec    );
	S->SetBranchAddress("reactz_rec",&reactz_rec    );

	double E_s, E_p, Theta,Xbj;
	S->SetBranchAddress("E_s",&E_s);
	S->SetBranchAddress("E_p",&E_p);
	S->SetBranchAddress("Theta",&Theta);
	S->SetBranchAddress("Xbj",&Xbj);
	/*}}}*/
	Int_t Evt = S->GetEntries();

	/*Loop and Fill{{{*/
	//Define XS table
	Get_XS* xs = new Get_XS();
	xs->Load_Table(Target.Data(),Kin.Data());
	double cs_Center = xs->gGet_XS_Center();
	cerr<<"--> XS Center = "<< cs_Center<<endl;
	if(cs_Center<1e-33){
		cs_Center = 1.0;
		cerr<<"---> Reset cs_Centr = 1"<<endl;
	}
	double cs = 0.0;
	double weight=1.0;

	/*Target Density{{{*/
	TString Density_Profile = Form("/work/halla/e08014/disk1/yez/Monte_Calo/SAMC/Generator/%s.rho",Target.Data());
	TString dummy;
	double VZ[52], Rho[52], Rho1[52],Rho2[52],Rho3[52];
	ifstream density(Density_Profile.Data()); 
	density >> dummy >> dummy >> dummy >> dummy >> dummy;
	double Rho_Sum = 0;
	for(int i=0;i<52;i++){
		density >> VZ[i] >> Rho[i] >> Rho1[i] >> Rho2[i] >> Rho3[i];
		Rho_Sum += Rho3[i];
	}
	Rho_Sum /=52;
	const double VZ_Max = 0.1020, VZ_Min = -0.1020;
	const double step = (VZ_Max-VZ_Min)/51.;//0.004
	/*}}}*/

	int VZ_Bin = 0; double Y_Offset = 0.0;
	for(int j=0;j<Evt;j++){
		S->GetEntry(j);
		y_tg_rec += Y_Offset;//Correct the offset
		//    if(IsPassed){
		if(IsPassed
				&&abs(reactz_rec)<0.07
		    	&&abs(y_tg_rec+0.00)<(0.175)
				&&abs(th_tg_rec)<0.03
				&&abs(ph_tg_rec)<0.02
				&&abs(dp_rec)<0.04
				){	
			VZ_Bin = (reactz_rec-VZ_Min)/step;
			cs = xs->gGet_XS(E_s,E_p,abs(Angle_rec*180./3.14));
			weight = cs/cs_Center*Rho3[VZ_Bin]/Rho_Sum; 
   
			m_xfp->Fill(x_fp,weight);
			m_yfp->Fill(y_fp,weight);
			m_tfp->Fill(th_fp,weight);
			m_pfp->Fill(ph_fp,weight);

			m_dtg->Fill(dp_rec,weight);
			m_ytg->Fill(y_tg_rec,weight);
			m_ztg->Fill(reactz_rec,weight);
			m_ttg->Fill(th_tg_rec,weight);
			m_ptg->Fill(ph_tg_rec,weight);
		}

	}
	delete xs;
	/*}}}*/

	scale = norm/m_xfp->Integral(); m_xfp->Scale(scale);
	scale = norm/m_yfp->Integral(); m_yfp->Scale(scale);
	scale = norm/m_tfp->Integral(); m_tfp->Scale(scale);
	scale = norm/m_pfp->Integral(); m_pfp->Scale(scale);

	scale = norm/m_dtg->Integral(); m_dtg->Scale(scale);
	scale = norm/m_ytg->Integral(); m_ytg->Scale(scale);
	scale = norm/m_ztg->Integral(); m_ztg->Scale(scale);
	scale = norm/m_ttg->Integral(); m_ttg->Scale(scale);
	scale = norm/m_ptg->Integral(); m_ptg->Scale(scale);
	/*}}}*/

	/*}}}*/

	/*Plot{{{*/
	TH1F *r_xfp = (TH1F*) h_xfp->Clone("r_xfp"); r_xfp->Divide(m_xfp);
	TH1F *r_yfp = (TH1F*) h_yfp->Clone("r_yfp"); r_yfp->Divide(m_yfp);
	TH1F *r_tfp = (TH1F*) h_tfp->Clone("r_tfp"); r_tfp->Divide(m_tfp);
	TH1F *r_pfp = (TH1F*) h_pfp->Clone("r_pfp"); r_pfp->Divide(m_pfp);
    
	r_xfp->SetTitle("#x_{fp} Ratio (EX/MC)");     r_xfp->SetLineColor(1);
	r_yfp->SetTitle("y_{fp} Ratio (EX/MC)");      r_yfp->SetLineColor(1);
	r_tfp->SetTitle("#theta_{fp} Ratio (EX/MC)"); r_tfp->SetLineColor(1);
	r_pfp->SetTitle("#phi_{fp} Ratio (EX/MC)");   r_pfp->SetLineColor(1);


	TH1F *r_dtg = (TH1F*) h_dtg->Clone("r_dtg"); r_dtg->Divide(m_dtg);
	TH1F *r_ytg = (TH1F*) h_ytg->Clone("r_ytg"); r_ytg->Divide(m_ytg);
	TH1F *r_ztg = (TH1F*) h_ztg->Clone("r_ztg"); r_ztg->Divide(m_ztg);
	TH1F *r_ttg = (TH1F*) h_ttg->Clone("r_ttg"); r_ttg->Divide(m_ttg);
	TH1F *r_ptg = (TH1F*) h_ptg->Clone("r_ptg"); r_ptg->Divide(m_ptg);
    
	r_dtg->SetTitle("#deltaP Ratio (EX/MC)");     r_dtg->SetLineColor(1);
	r_ztg->SetTitle("ReactZ Ratio (EX/MC)");      r_ztg->SetLineColor(1);
	r_ytg->SetTitle("y_{tg} Ratio (EX/MC)");      r_ytg->SetLineColor(1);
	r_ttg->SetTitle("#theta_{tg} Ratio (EX/MC)"); r_ttg->SetLineColor(1);
	r_ptg->SetTitle("#phi_{tg} Ratio (EX/MC)");   r_ptg->SetLineColor(1);

	TCanvas *c1 = new TCanvas("c1","c1 Focal Plane",800,1000);
	c1->Divide(2,4);

	c1->cd(1); h_xfp->Draw();
	c1->cd(3); h_yfp->Draw();
	c1->cd(5); h_tfp->Draw();
	c1->cd(7); h_pfp->Draw();
	c1->cd(1); m_xfp->Draw("same");  
	c1->cd(3); m_yfp->Draw("same"); 
	c1->cd(5); m_tfp->Draw("same"); 
	c1->cd(7); m_pfp->Draw("same"); 

	c1->cd(2); r_xfp->Draw("");  
	c1->cd(4); r_yfp->Draw(""); 
	c1->cd(6); r_tfp->Draw(""); 
	c1->cd(8); r_pfp->Draw(""); 


	TCanvas *c2 = new TCanvas("c2","c2 Target Plane",800,1000);
	c2->Divide(2,4);

	c2->cd(1); h_dtg->Draw();
	c2->cd(3); h_ztg->Draw();
	//c2->cd(5); h_ytg->Draw();
	c2->cd(5); h_ttg->Draw();
	c2->cd(7); h_ptg->Draw();

	c2->cd(1); m_dtg->Draw("same");  
	c2->cd(3); m_ztg->Draw("same"); 
	//c2->cd(3); m_ytg->Draw("same"); 
	c2->cd(5); m_ttg->Draw("same"); 
	c2->cd(7); m_ptg->Draw("same"); 

	c2->cd(2); r_dtg->Draw("");  
	c2->cd(4); r_ztg->Draw("same"); 
	//c2->cd(4); r_ytg->Draw(""); 
	c2->cd(6); r_ttg->Draw(""); 
	c2->cd(8); r_ptg->Draw(""); 


	SAMC_File.ReplaceAll(".root","_");
	TString pic=Target+"_"+SAMC_File+Form("%d_fp_cut.png",run_number);
	c1->Print(pic);
	pic=Target+"_"+SAMC_File+Form("%d_tg_cut.png",run_number);
	c2->Print(pic);
	//TCanvas *c2 = new TCanvas("c2","c2",1200,700);
	//c2->Divide(2,2);
	/*}}}*/
}
Example #16
0
void checkTrkInputs(
    TString infrec="nt_djhp_HyUQ110v0_djcalo.root",
    TString infgen="nt_djhp_HyUQ110v0_djcalo_genp.root",
    TCut evtCut="cent<30")
{
  //TH1::SetDefaultSumw2();
  TChain * trec = new TChain("tjttrk");
  trec->Add(infrec);
  setupAlias(trec);
  TChain * tgen = new TChain("tjttrk");
  tgen->Add(infgen);
  cout << infrec << " cut " << TString(evtCut) << ": " << trec->GetEntries() << endl;
  cout << infgen << " cut " << TString(evtCut) << ": " << tgen->GetEntries() << endl;
   
  // Correction Histograms
  TFile * fTrkCorr = new TFile("djtrkhist_hydjetBassv2_djuq110.root");
  TString corrModule = "hitrkEffAnalyzer";
  TH2F * hrec = (TH2F*)fTrkCorr->Get(Form("%s/hrec",corrModule.Data()));
  TH1D * hrec_pt = (TH1D*)hrec->ProjectionY();
  TH2F * hsim = (TH2F*)fTrkCorr->Get(Form("%s/hsim",corrModule.Data()));
  TH1D * hsim_pt = (TH1D*)hsim->ProjectionY();
  
  // Frag Histograms
  //TH1D * hPPtRecRaw = new TH1D("hPPtRecRaw",";p_{T} (GeV/c); count;");
  TH1D * hPPtRecRaw = (TH1D*)hrec_pt->Clone("hPPtRecRaw");
  hPPtRecRaw->Reset();
  TH1D * hPPtGen = (TH1D*)hrec_pt->Clone("hPPtGen");
  hPPtGen->Reset();
  trec->Project("hPPtRecRaw","ppt","");
  tgen->Project("hPPtGen","ppt","");
  TH1D * hRecSimRat_pt = (TH1D*)hrec_pt->Clone("hRecSimRat_pt");
  hRecSimRat_pt->Sumw2();
  hRecSimRat_pt->Divide(hrec_pt,hsim_pt);
  TH1D * hPPtRat = (TH1D*)hrec_pt->Clone("hPPtRat");
  hPPtRat->Sumw2();
  hPPtRat->Divide(hPPtRecRaw,hPPtGen);

  // Normalize
  normHist(hsim_pt,0,true,1);
  normHist(hrec_pt,0,true,1);
  normHist(hPPtGen,0,true,1);
  normHist(hPPtRecRaw,0,true,1);

  // Plot
  hsim_pt->SetAxisRange(0,100,"X");
  hsim_pt->SetTitle(";p_{T} (GeV/c); count");
  hRecSimRat_pt->SetTitle(";p_{T} (GeV/c); reco/gen ratio");
  hsim_pt->SetLineColor(kRed);
  hPPtGen->SetMarkerColor(kRed);
  hPPtGen->SetLineColor(kRed);
  hRecSimRat_pt->SetAxisRange(0,100,"X");
  hRecSimRat_pt->SetAxisRange(-0.2,1.2,"Y");
  hRecSimRat_pt->SetLineColor(kRed);
  TCanvas *cRec = new TCanvas("cRec","Rec",500,900);
  cRec->Divide(1,2);
  cRec->cd(1);
  cRec->GetPad(1)->SetLogy();
  hsim_pt->Draw("hist");
  hPPtGen->Draw("sameE");
  hrec_pt->Draw("hist same");
  hPPtRecRaw->Draw("sameE");
  cRec->cd(2);
  hRecSimRat_pt->Draw("hist");
  hPPtRat->Draw("sameE");

  // ====================
  TLegend *leg = new TLegend(0.61,0.78,0.91,0.91);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.035);
}
Example #17
0
void plotTrkClosure(
    TString infrec="nt_djhp_HyUQ110v0_djcalo_100_50_offset0.root",
    TString infgen="nt_djhp_HyUQ110v0_djcalo_genp_100_50_offset0.root",
    TCut evtCut="cent<30")
{
  //TH1::SetDefaultSumw2();
  TChain * trec = new TChain("tjttrk");
  trec->Add(infrec);
  setupAlias(trec);
  TChain * tgen = new TChain("tjttrk");
  tgen->Add(infgen);
  cout << infrec << " cut " << TString(evtCut) << ": " << trec->GetEntries() << endl;
  cout << infgen << " cut " << TString(evtCut) << ": " << tgen->GetEntries() << endl;
   
  const Int_t numPPtBins=19;
  Float_t pptBins[numPPtBins+1] = {0.0,0.2,1,2,3,4,6,8,10,14,18,22,26,30,40,50,60,70,80,100};

  vector<TCut> jetCut;
  jetCut.push_back("jtpt[0]>100&&jtpt[0]<200&&abs(jteta[0])<0.8");
  jetCut.push_back("jtpt[1]>50&&jtpt[1]<200&&abs(jteta[1])<0.8");
  vector<TCut> jetTrkCut;
  vector<TCut> jetGenPCut;
  jetGenPCut.push_back("pdr[0]<0.5");
  jetTrkCut.push_back(jetGenPCut[0]&&"trkeff>0&&trkeff<1");
  jetGenPCut.push_back("pdr[1]<0.5");
  jetTrkCut.push_back(jetGenPCut[1]&&"trkeff>0&&trkeff<1");

  TFile * outf = new TFile("closureHists.root","RECREATE");
  vector<Float_t> numJetRec;
  vector<Float_t> numJetGen;
  vector<TH1D*> vhPPtRecCorr;
  vector<TH1D*> vhPPtRecRaw;
  vector<TH1D*> vhPPtGen;
  vector<TH1D*> vhPPtRat;
  for (Int_t i=0; i<jetCut.size(); ++i) {
    numJetRec.push_back(trec->GetEntries(jetCut[i]&&evtCut));
    numJetGen.push_back(tgen->GetEntries(jetCut[i]&&evtCut));
    cout << "numJ" << i << " rec: " << numJetRec[i] << endl;
    cout << "numJ" << i << " gen: " << numJetGen[i] << endl;
    vhPPtRecCorr.push_back(new TH1D(Form("hPPtRecCorr_j%d",i),";In-Cone Trk p_{T} (GeV/c); #frac{1}{N_{Jet}} #frac{dN}{dp_{T}}",numPPtBins,pptBins));
    vhPPtRecRaw.push_back(new TH1D(Form("hPPtRecRaw_j%d",i),";In-Cone Trk p_{T} (GeV/c); #frac{1}{N_{Jet}} #frac{dN}{dp_{T}}",numPPtBins,pptBins));
    vhPPtGen.push_back(new TH1D(Form("hPPtGen_j%d",i),";In-Cone Trk p_{T} (GeV/c); #frac{1}{N_{Jet}} #frac{dN}{dp_{T}}",numPPtBins,pptBins));
    vhPPtRat.push_back(new TH1D(Form("hPPtRat_j%d",i),";In-Cone Trk p_{T} (GeV/c); RecTrk/GenParticle",numPPtBins,pptBins));
  }

  for (Int_t i=0; i<jetCut.size(); ++i) {
    vhPPtRecCorr[i]->Sumw2();
    trec->Project(vhPPtRecCorr[i]->GetName(),"ppt",(evtCut&&jetCut[i]&&jetTrkCut[i])*"trkwt");
    normHist(vhPPtRecCorr[i],0,true,1./numJetRec[i]);

    vhPPtRecRaw[i]->Sumw2();
    trec->Project(vhPPtRecRaw[i]->GetName(),"ppt",(evtCut&&jetCut[i]&&jetTrkCut[i]));
    normHist(vhPPtRecRaw[i],0,true,1./numJetRec[i]);

    vhPPtGen[i]->Sumw2();
    tgen->Project(vhPPtGen[i]->GetName(),"ppt",(evtCut&&jetCut[i]&&jetGenPCut[i]));
    normHist(vhPPtGen[i],0,true,1./numJetGen[i]);

    vhPPtRat[i]->Divide(vhPPtRecCorr[i],vhPPtGen[i]);
  }

  for (Int_t i=0; i<jetCut.size(); ++i) {
    vhPPtGen[i]->SetAxisRange(1,100,"X");
    vhPPtGen[i]->SetAxisRange(1e-3,1e1,"Y");
    vhPPtGen[i]->SetLineColor(kRed);
    vhPPtGen[i]->SetMarkerColor(kRed);
    vhPPtGen[i]->SetMarkerStyle(kOpenCircle);
  }
  TCanvas *c2 = new TCanvas("c2","closure",500,900);
  c2->Divide(1,2);
  c2->cd(1);
  c2->GetPad(1)->SetLogy();
  vhPPtGen[0]->Draw("hist");
  vhPPtRecCorr[0]->Draw("sameE");
  c2->cd(2);
  vhPPtRat[0]->Draw("E");

  // ====================
  TLine *l = new TLine(1,1,100,1);
  l->Draw();

  c2->cd(1);
  TLegend *leg = new TLegend(0.61,0.78,0.91,0.91);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.035);
  leg->AddEntry(vhPPtGen[0],"#DeltaR(jet,trk)<0.5","");
  leg->AddEntry(vhPPtGen[0],"Gen. Particle","pl");
  leg->AddEntry(vhPPtRecCorr[0],"Trk Corr.","pl");
  leg->Draw();

  // ====================
  TCanvas * chk0 = new TCanvas("chk0","check eff",500,500);
  chk0->SetLogz();
  trec->Draw("trkeff:ppt>>hTrkEffProf(50,0,100)",evtCut&&jetCut[0]&&jetTrkCut[0],"prof");
  trec->Draw("trkeff:ppt>>hTrkEff2D(50,0,100,50,-0.2,1.2)",evtCut&&jetCut[0]&&jetTrkCut[0],"colz");
  ((TH1D*)gDirectory->Get("hTrkEffProf"))->Draw("same");

  TCanvas * chk1 = new TCanvas("chk1","check fake",500,500);
  chk1->SetLogz();
  trec->Draw("trkfak:ppt>>hTrkFakProf(50,0,100)",evtCut&&jetCut[0]&&jetTrkCut[0],"prof");
  trec->Draw("trkfak:ppt>>hTrkFak2D(50,0,100,50,-0.2,1.2)",evtCut&&jetCut[0]&&jetTrkCut[0],"colz");
  ((TH1D*)gDirectory->Get("hTrkFakProf"))->Draw("same");
}
Example #18
0
void InConeLeadFrag_AJ(
    //TString algo="akpu3pf"
    TString algo="icpu5"
    )
{
  TH1::SetDefaultSumw2();
  TString infnamedata = Form("histntff_tv1data_%s_cv3.root",algo.Data());
  TString infnamemc = Form("histntff_tv1mc80_%s_cv3.root",algo.Data());
  TCut evtSel;
  if (algo=="akpu3pf")
    evtSel = "cent<20&&jtpt[0]>90&&jtpt[1]>40&&abs(jteta[0])<1.6&&abs(jteta[1])<1.6&&abs(jdphi)>2.09";
  if (algo=="icpu5")
    evtSel = "cent<20&&jtpt[0]>120&&jtpt[1]>50&&abs(jteta[0])<1.6&&abs(jteta[1])<1.6&&abs(jdphi)>2.09";

  TChain * tdata = new TChain("tjfrRec");
  tdata->Add(infnamedata);
  TChain * tmc = new TChain("tjfrRec");
  tmc->Add(infnamemc);

  cout << "Cut: " << TString(evtSel) << endl;
  cout << infnamedata << " " << tdata->GetEntries(evtSel) << endl;
  cout << infnamemc << " " << tmc->GetEntries(evtSel) << endl;

  TProfile * hLFJ1Data = new TProfile("hLFJ1Data","",5,0,0.5);
  TProfile * hLFJ1Mc = new TProfile("hLFJ1Mc","",5,0,0.5);
  TProfile * hLFJ2Data = new TProfile("hLFJ2Data","",5,0,0.5);
  TProfile * hLFJ2Mc = new TProfile("hLFJ2Mc","",5,0,0.5);

  cout << "========== LF ana ==========" << endl;
  TCut jet1Sel = evtSel&&"clppt[0]>0";
  TCut jet2Sel = evtSel&&"clppt[1]>0";
  cout << "Cut: " << TString(jet1Sel) << endl;
  cout << infnamedata << " " << tdata->GetEntries(jet1Sel) << endl;
  cout << infnamemc << " " << tmc->GetEntries(jet1Sel) << endl;
  cout << "Cut: " << TString(jet2Sel) << endl;
  cout << infnamedata << " " << tdata->GetEntries(jet2Sel) << endl;
  cout << infnamemc << " " << tmc->GetEntries(jet2Sel) << endl;

  tdata->Project("hLFJ1Data","clppt[0]/jtpt[0]:Aj",jet1Sel*"cltrkwt","prof");
  tmc->Project("hLFJ1Mc","clppt[0]/jtpt[0]:Aj",jet1Sel*"cltrkwt","prof");
  tdata->Project("hLFJ2Data","clppt[1]/jtpt[1]:Aj",jet2Sel*"cltrkwt","prof");
  tmc->Project("hLFJ2Mc","clppt[1]/jtpt[1]:Aj",jet2Sel*"cltrkwt","prof");

  TCanvas * c2 = new TCanvas("c2","c2",500,500);
  hLFJ1Mc->SetAxisRange(0,0.3,"Y");
  hLFJ1Mc->SetTitle(";A_{J};<z^{lead}>=<p_{T}^{Leading Trk}/p_{T}^{Jet}>;");
  hLFJ1Mc->GetXaxis()->CenterTitle();
  hLFJ1Mc->GetYaxis()->CenterTitle();
  hLFJ1Mc->SetLineColor(kRed);
  hLFJ1Mc->SetLineStyle(2);

  hLFJ2Mc->SetLineColor(kRed);

  hLFJ1Data->SetMarkerStyle(kOpenCircle);

  hLFJ1Mc->Draw("hist");
  hLFJ2Mc->Draw("samehist");
  hLFJ1Data->Draw("sameE");
  hLFJ2Data->Draw("sameE");

  TLegend *leg = new TLegend(0.18,0.18,0.68,0.38);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.035);
  leg->AddEntry(hLFJ1Data,"0-20%, "+algo,"");
  leg->AddEntry(hLFJ1Data,"Data J1","p");
  leg->AddEntry(hLFJ2Data,"Data J2","p");
  leg->AddEntry(hLFJ1Mc,"PYTHIA+HYDJET J1","l");
  leg->AddEntry(hLFJ2Mc,"PYTHIA+HYDJET J2","l");
  leg->Draw();

  c2->Print(Form("InConeLeadingFragment_vs_AJ_%s.gif",algo.Data()));
}
Example #19
0
void draw_Amps(void)
{
	gStyle->SetOptStat("i");
	gStyle->SetOptFit(1);
	gStyle->SetTitleXSize(0.05);
	gStyle->SetTitleYSize(0.05);
	gStyle->SetLabelSize(0.05);
	gStyle->SetPadLeftMargin(0.15);
	gStyle->SetPadBottomMargin(0.15);
	
	TChain *tNa = new TChain("DanssEvent");
	TChain *tCo = new TChain("DanssEvent");
	TChain *tBgnd = new TChain("DanssEvent");
	tNa->AddFile("../digi.v2/danss_root4_3/danss_020243.root");
	tNa->AddFile("../digi.v2/danss_root4_3/danss_020244.root");
	tCo->AddFile("../digi.v2/danss_root4_3/danss_020233.root");
	tCo->AddFile("../digi.v2/danss_root4_3/danss_020234.root");
	tBgnd->AddFile("../digi.v2/danss_root4_3/danss_020252.root");
	tBgnd->AddFile("../digi.v2/danss_root4_3/danss_020253.root");

	TH1D *hNaSiPMA = new TH1D("hNaSiPMA", "SiPM ^{22}Na;ADC units", 50, 0, 1500);
	TH1D *hNaSiPMB = new TH1D("hNaSiPMB", "SiPM ^{22}Na;ADC units", 50, 0, 1500);
	TH1D *hCoSiPMA = new TH1D("hCoSiPMA", "SiPM ^{60}Co;ADC units", 50, 0, 1500);
	TH1D *hCoSiPMB = new TH1D("hCoSiPMB", "SiPM ^{60}Co;ADC units", 50, 0, 1500);
	TH1D *hBgndSiPM = new TH1D("hBgndSiPM", "SiPM ^{60}Co;ADC units", 50, 0, 1500);

	TH1D *hNaPMTA = new TH1D("hNaPMTA", "PMT ^{22}Na;ADC units", 50, 0, 1000);
	TH1D *hNaPMTB = new TH1D("hNaPMTB", "PMT ^{22}Na;ADC units", 50, 0, 1000);
	TH1D *hCoPMTA = new TH1D("hCoPMTA", "PMT ^{60}Co;ADC units", 50, 0, 1000);
	TH1D *hCoPMTB = new TH1D("hCoPMTB", "PMT ^{60}Co;ADC units", 50, 0, 1000);
	TH1D *hBgndPMT = new TH1D("hBgndPMT", "PMT ^{60}Co;ADC units", 50, 0, 1000);
	
	TCut cxyz("NeutronX[0] >= 0 && NeutronX[1] >= 0 && NeutronX[2] >= 0");
	TCut ccc("(NeutronX[0] - 48) * (NeutronX[0] - 48) + (NeutronX[1] - 48) * (NeutronX[1] - 48) + (NeutronX[2] - 49.5) * (NeutronX[2] - 49.5) < 400");
	TCut cVeto("VetoHits < 2 && VetoEnergy < 4");
	
	tNa->Project("hNaSiPMA", "SiPmCleanEnergy", cxyz && ccc && cVeto);
	tCo->Project("hCoSiPMA", "SiPmCleanEnergy", cxyz && ccc && cVeto);
	tBgnd->Project("hBgndSiPM", "SiPmCleanEnergy", cxyz && ccc && cVeto);
	tNa->Project("hNaPMTA", "PmtCleanEnergy", cxyz && ccc && cVeto);
	tCo->Project("hCoPMTA", "PmtCleanEnergy", cxyz && ccc && cVeto);
	tBgnd->Project("hBgndPMT", "PmtCleanEnergy", cxyz && ccc && cVeto);
	
	hNaSiPMA->Sumw2();
	hCoSiPMA->Sumw2();
	hBgndSiPM->Sumw2();
	hNaPMTA->Sumw2();
	hCoPMTA->Sumw2();
	hBgndPMT->Sumw2();

	hNaSiPMB->Add(hNaSiPMA, hBgndSiPM, 1.0, -0.977);
	hCoSiPMB->Add(hCoSiPMA, hBgndSiPM, 1.0, -0.977);
	hNaPMTB->Add(hNaPMTA, hBgndPMT, 1.0, -0.977);
	hCoPMTB->Add(hCoPMTA, hBgndPMT, 1.0, -0.977);

	hNaSiPMB->GetYaxis()->SetLabelSize(0.05);
	hCoSiPMB->GetYaxis()->SetLabelSize(0.05);
	hNaPMTB->GetYaxis()->SetLabelSize(0.05);
	hCoPMTB->GetYaxis()->SetLabelSize(0.05);

	TCanvas *cAmp = new TCanvas("cAmp", "Raw Amplitude", 1200, 800);
	cAmp->Divide(2, 2);
	cAmp->cd(1);
	hNaSiPMB->Fit("gaus", "", "", 200, 800);
	cAmp->cd(2);
	hCoSiPMB->Fit("gaus", "", "", 200, 200);
	cAmp->cd(3);
	hNaPMTB->Fit("gaus", "", "", 150, 600);
	cAmp->cd(4);
	hCoPMTB->Fit("gaus", "", "", 150, 600);
	cAmp->SaveAs("22Na_60Co_raw_ADC_amplitudes.pdf");
}
Example #20
0
void BkgFluctuation(TString infname = "../ntv6_datambv3rand_djcalo_c0to30_offset0.root",
                    TCut myCut = "cent<30", char *title = "",bool drawLegend = false,
                    bool drawSys = true
		    )
{
  gStyle->SetHistLineWidth(2);
  // ===========================================================
  // Get Input
  // ===========================================================
  TChain* t = new TChain("ntjt");
  t->Add(infname);
  t->AddFriend("tcone",infname);
  cout << infname << ": " << t->GetEntries() << endl;
  t->SetAlias("cptsub0Merge0","cpt[0][1]+cpt[0][2]-(cptbg[0][1]+cptbg[0][2])");
  t->SetAlias("cptsub0Merge1","cpt[0][3]-(cptbg[0][3])");
  t->SetAlias("cptsub0Merge2","cpt[0][4]+cpt[0][5]-(cptbg[0][4]+cptbg[0][5])");
  t->SetAlias("cptsub0Merge3","(Sum$(cpt[0])-cpt[0][0])-(Sum$(cptbg[0])-cptbg[0][0])");

  // ===========================================================
  // Analysis Setup
  // ===========================================================
  TH1::SetDefaultSumw2();
   const int nBin = 3;
   double bins[nBin+1] = {1.,4,8,160};  
  TCut evtCut = "nljet>100&&abs(nljetacorr)<1.6&&aljet>50&&abs(aljetacorr)<1.6&&jdphi>2./3*TMath::Pi()&&!maskEvt";
  TCut exclusion = "abs(nljetacorr)>0.8"; //&&abs(aljetacorr)>0.8";
  evtCut = evtCut&&exclusion;
  //Int_t colors[7] = {kBlue, kCyan-3, kYellow+1, kOrange+1, kGreen+2, kMagenta, kRed };
  Int_t colors[7] = {kYellow+2, kGreen+2,kRed };
  
  // ===========================================================
  // Book Histograms
  // ===========================================================
  vector<TH1D*> vhBgSub;
  for (Int_t i=0; i<nBin+1; ++i) {
    vhBgSub.push_back(new TH1D(Form("hBgSub_%d"),";(Sig Cone #Sigma p_{T}) - (Bkg Cone #Sigma p_{T}) (GeV/c);fraction;",50,-300,300));
  }

  Float_t numEvt = t->GetEntries(evtCut&&myCut);
  cout << "Total Sel evt: " << numEvt << endl;
  for (Int_t i=0; i<nBin+1; ++i) {
    TString var(Form("cptsub0Merge%i",i));
    cout << "Sel evt: " << t->GetEntries(evtCut&&myCut&&var) << endl;
    cout << "var: " << t->GetAlias(var) << endl;
    t->Project(vhBgSub[i]->GetName(),var,(evtCut&&myCut&&var)*"weight");
    Float_t mean = vhBgSub[i]->GetMean();
    Float_t rms = vhBgSub[i]->GetRMS();
    cout << "bgsub mean: " << mean << " rms: " << rms << endl;
    vhBgSub[i]->Scale(1./numEvt);
    cout << "Bin " << i << " rms/sqrt(250): " << rms/sqrt(250)
      << " r=0: " << rms/sqrt(250.)*sqrt(fracArea(0))
      << " r=0.8: " << rms/sqrt(250.)*sqrt(fracArea(0.8)) << endl;
  }

  TCanvas * c2 = new TCanvas("c2","c2",600,600);
  c2->SetLogy();
  vhBgSub[nBin]->SetAxisRange(1e-5,5,"Y");
  vhBgSub[nBin]->Draw("E");
  for (Int_t i=0; i<nBin; ++i) {
    vhBgSub[i]->SetLineColor(colors[i]);
    vhBgSub[i]->Draw("same hist");
  }
  vhBgSub[nBin]->Draw("Esame");

  TLegend *leg = new TLegend(0.19,0.70,0.53,0.92);
  leg->SetFillStyle(0);
  leg->SetBorderSize(0);
  leg->SetTextSize(0.035);
  leg->AddEntry(vhBgSub[nBin],"CMS 0-30%","");
  leg->AddEntry(vhBgSub[nBin],"Random Cone (MB Sample)","");
  leg->AddEntry(vhBgSub[nBin],Form("> %.1f GeV/c",bins[0]),"pl");
  for (int i=0;i<nBin;++i) {
    if (i!=nBin-1){
      leg->AddEntry(vhBgSub[i],Form("%.1f - %.1f GeV/c",bins[i],bins[i+1]),"l");
    } else {
      leg->AddEntry(vhBgSub[i],Form("> %.1f GeV/c",bins[i]),"l");
    }
  }
  leg->Draw();
}
void GenerateInputFile_ge4b( double mgl=-1., double mlsp=-1., double target_susy_all0lep=-1. ) {

  TChain* dyTree = new TChain("treeZ") ;
  int nAdded = dyTree->Add("files15fb_8TeV_old1/DY.root") ;
  if ( nAdded <= 0 ) {
     printf("\n\n\n *** No treeZ in files15fb_8TeV_old1/DY.root\n\n\n") ;
     return ;
  }

  double t1bbbbWeight(0.) ;
  TChain chainT1bbbb("tree") ;
  char susycutstring[1000] ;
  sprintf( susycutstring, "&&mgluino==%.0f&&mlsp==%.0f", mgl, mlsp ) ;
  TString susycut( susycutstring ) ;
  if ( mgl>0. && mlsp>0. ) {
     nAdded = chainT1bbbb.Add("files5fb_MT/T1bbbb.root") ;
     if ( nAdded <= 0 ) {
        printf("\n\n\n *** No tree in files5fb_MT/T1bbbb.root\n\n\n") ;
        return ;
     }
     TFile f("referenceXSecs.root") ;
     TH1F* xsechist = (TH1F*) f.Get("gluino8TeV_NLONLL") ;
     if ( xsechist==0x0 ) { printf("\n\n *** can't find reference Xsec histogram in referenceXSecs.root.\n\n") ; return ; }
     int theBin = xsechist->FindBin( mgl ) ;
     if ( theBin <=0 || theBin > xsechist->GetNbinsX() ) {
        printf("\n\n *** can't find bin for mgl=%g.  Returned %d\n\n", mgl, theBin ) ;
        return ;
     }
     double xsec = xsechist->GetBinContent( theBin ) ;
     printf("\n\n T1bbbb xsec for mgl=%g is %g\n\n", mgl, xsec ) ;
     t1bbbbWeight = 1.5*xsec ;  //in pb. scan has 10k events, so nScan*1.5*xsec = events in 15fb-1
     //////  t1bbbbWeight = 0.1*xsec ;  //in pb. T1tttt scan has 50k events, so nScan*0.1*xsec = events in 5fb-1
     printf("\n\n Susy ttree cut: %s\n\n", susycutstring ) ;
  }


  TChain chainQCD("tree") ;
   //--- these have high weight
//chainQCD.Add("files15fb_8TeV/QCD-50to80.root");
//chainQCD.Add("files15fb_8TeV/QCD-80to120.root");
  chainQCD.Add("files15fb_8TeV/QCD-120to170.root");
  chainQCD.Add("files15fb_8TeV/QCD-170to300.root");
   //--- below here, these have weight less than one.
  chainQCD.Add("files15fb_8TeV/QCD-300to470.root");
  chainQCD.Add("files15fb_8TeV/QCD-470to600.root");
  chainQCD.Add("files15fb_8TeV/QCD-600to800.root");
  chainQCD.Add("files15fb_8TeV/QCD-800to1000.root");
  chainQCD.Add("files15fb_8TeV/QCD-1000to1400.root");
  chainQCD.Add("files15fb_8TeV/QCD-1400to1800.root");
  chainQCD.Add("files15fb_8TeV/QCD-1800.root");

  TChain chainTT("tree") ;
  chainTT.Add("files15fb_8TeV/TT.root") ;

  TChain chainZnn("tree") ;
  chainZnn.Add("files15fb_8TeV/Zinv-100to200.root") ;
  chainZnn.Add("files15fb_8TeV/Zinv-200to400.root") ;
  chainZnn.Add("files15fb_8TeV/Zinv-400.root") ;

  TChain chainWJets("tree") ;
  chainWJets.Add("files15fb_8TeV/WJets-250to300.root") ;
  chainWJets.Add("files15fb_8TeV/WJets-300to400.root") ;
  chainWJets.Add("files15fb_8TeV/WJets-400.root") ;
  chainWJets.Add("files15fb_8TeV/T-s.root") ;
  chainWJets.Add("files15fb_8TeV/T-t.root") ;
  chainWJets.Add("files15fb_8TeV/T-tW.root") ;
  chainWJets.Add("files15fb_8TeV/Tbar-s.root") ;
  chainWJets.Add("files15fb_8TeV/Tbar-t.root") ;
  chainWJets.Add("files15fb_8TeV/Tbar-tW.root") ;



      char qcdinputfile[9][1000] = {
        "files15fb_8TeV/QCD-120to170.root"
       ,"files15fb_8TeV/QCD-170to300.root"
       ,"files15fb_8TeV/QCD-300to470.root"
       ,"files15fb_8TeV/QCD-470to600.root"
       ,"files15fb_8TeV/QCD-600to800.root"
       ,"files15fb_8TeV/QCD-800to1000.root"
       ,"files15fb_8TeV/QCD-1000to1400.root"
       ,"files15fb_8TeV/QCD-1400to1800.root"
       ,"files15fb_8TeV/QCD-1800.root"
      } ;

      char qcdsamplename[9][100] = {
        "qcd_0120_to_0170"
       ,"qcd_0170_to_0300"
       ,"qcd_0300_to_0470"
       ,"qcd_0470_to_0600"
       ,"qcd_0600_to_0800"
       ,"qcd_0800_to_1000"
       ,"qcd_1000_to_1400"
       ,"qcd_1400_to_1800"
       ,"qcd_1800_to_9999"
      } ;



  gROOT->Reset();

  const int nBinsBjets = 4 ;
  const int nJetsCut = 3 ;     // #jets >= nJetsCut

//be careful because this is hard coded now in SmallTree::Loop
  double minLeadJetPt = 70. ;
  double min3rdJetPt = 50. ;
  
  bool doPUreweighting = false;

  //-- met2-ht1-v1
//const int nBinsMET   = 2 ;
//const int nBinsHT    = 1 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,250.,99999.};
//float Hbins[nBinsHT+1] = {400.,99999.};

//-- met2-ht2-v1
//const int nBinsMET   = 2 ;
//const int nBinsHT    = 2 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,250.,99999.};
//float Hbins[nBinsHT+1] = {400.,600.,99999.};

////-- met2-ht8-v1
//const int nBinsMET   = 2 ;
//const int nBinsHT    = 8 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,250.,99999.};
//float Hbins[nBinsHT+1] = {400.,500.,600.,700.,800.,900.,1000.,1200.,99999.};

  //-- met3-ht2-v1
//const int nBinsMET   = 3 ;
//const int nBinsHT    = 2 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,250.,350.,99999.};
//float Hbins[nBinsHT+1] = {400.,800.,99999.};

////-- met3-ht3-v1
//const int nBinsMET   = 3 ;
//const int nBinsHT    = 3 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,250.,350.,99999.};
//float Hbins[nBinsHT+1] = {400.,600.,1000.,99999.};

////-- met3-ht3-v5
//    const int nBinsMET = 3 ;
//    const int nBinsHT  = 3 ;
//    const int version = 5;
//    float Mbins[nBinsMET+1] = { 125, 200,  350, 99999. } ;
//    float Hbins[nBinsHT+1]  = { 400, 600, 1000, 99999. } ;

////-- met3-ht3-v2
//const int nBinsMET   = 3 ;
//const int nBinsHT    = 3 ;
//    const int version = 2;
//float Mbins[nBinsMET+1] = {150.,250.,350.,99999.};
//float Hbins[nBinsHT+1] = {300.,500.,1000.,99999.};

////-- met3-ht4-v1
//const int nBinsMET   = 3 ;
//const int nBinsHT    = 4 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,250.,350.,99999.};
//float Hbins[nBinsHT+1] = {200, 300.,500.,1000.,99999.};

////-- met3-ht5-v1
//const int nBinsMET   = 3 ;
//const int nBinsHT    = 5 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,250.,350.,99999.};
//float Hbins[nBinsHT+1] = {400.,500.,600.,800.,1000.,99999.};

////-- met4-ht3-v1
//const int nBinsMET   = 4 ;
//const int nBinsHT    = 3 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,250.,350.,500.,99999.};
//float Hbins[nBinsHT+1] = {400.,600.,1000.,99999.};

////-- met4-ht3-v2
//const int nBinsMET   = 4 ;
//const int nBinsHT    = 3 ;
//    const int version = 2;
//float Mbins[nBinsMET+1] = {125, 150.,250.,350.,99999.};
//float Hbins[nBinsHT+1] = {300.,500.,1000.,99999.};

  //-- met5-ht4-v1
//const int nBinsMET   = 5 ;
//const int nBinsHT    = 4 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,200.,250.,300.,350.,99999.};
//float Hbins[nBinsHT+1] = {400.,600.,800.,1000.,99999.};

////-- met4-ht4-v1
//    const int nBinsMET   = 4 ;
//    const int nBinsHT    = 4 ;
//    const int version = 1;
//    float Mbins[nBinsMET+1] = {150.,200.,250.,300.,99999.};
//    float Hbins[nBinsHT+1] = {400.,500.,600.,800.,99999.};

  //-- met4-ht4-v2
//    const int nBinsMET   = 4 ;
//    const int nBinsHT    = 4 ;
//    const int version = 2;
//    float Mbins[nBinsMET+1] = {150.,250.,350.,450.,99999.};
//    float Hbins[nBinsHT+1] = {400.,500.,600.,800.,99999.};

  //-- met4-ht4-v3
//    const int nBinsMET   = 4 ;
//    const int nBinsHT    = 4 ;
//    const int version = 3;
//    float Mbins[nBinsMET+1] = {150.,200.,250.,300.,99999.};
//    float Hbins[nBinsHT+1] = {400.,600.,800.,1000.,99999.};

  //-- met4-ht4-v4
//    const int nBinsMET   = 4 ;
//    const int nBinsHT    = 4 ;
//    const int version = 4;
//    float Mbins[nBinsMET+1] = {150.,250.,350.,450.,99999.};
//    float Hbins[nBinsHT+1] = {400.,600.,800.,1000.,99999.};

  //-- met4-ht4-v5
//    const int nBinsMET   = 4 ;
//    const int nBinsHT    = 4 ;
//    const int version = 5;
//    float Mbins[nBinsMET+1] = {150.,175.,200.,400.,99999.};
//    float Hbins[nBinsHT+1] = {400.,450.,550.,850.,99999.};

  //-- met4-ht4-v6
//    const int nBinsMET   = 4 ;
//    const int nBinsHT    = 4 ;
//    const int version = 6;
//    float Mbins[nBinsMET+1] = {150.,200.,350.,450.,99999.};
//    float Hbins[nBinsHT+1] = {400.,550.,800.,950.,99999.};

////-- met4-ht4-v7
//const int nBinsMET   = 4 ;
//const int nBinsHT    = 4 ;
//    const int version = 7;
//float Mbins[nBinsMET+1] = {125, 150.,250.,350.,99999.};
//float Hbins[nBinsHT+1] = {200, 300.,500.,1000.,99999.};

  //-- met4-ht4-v15
      const int nBinsMET   = 4 ;
      const int nBinsHT    = 4 ;
      const int version = 15;
      float Mbins[nBinsMET+1] = {125.,150.,250.,350.,99999.};
      float Hbins[nBinsHT+1] = {400.,500.,800.,1000.,99999.};

////-- met4-ht5-v1
//const int nBinsMET   = 4 ;
//const int nBinsHT    = 5 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,200.,300.,400.,99999.};
//float Hbins[nBinsHT+1] = {400.,600.,800.,1000.,1200.,99999.};

////-- met5-ht5-v1
//const int nBinsMET   = 5 ;
//const int nBinsHT    = 5 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,200.,250.,300.,350.,99999.};
//float Hbins[nBinsHT+1] = {400.,500.,600.,800.,1000.,99999.};

////-- met5-ht3-v1
//const int nBinsMET   = 5 ;
//const int nBinsHT    = 3 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,200.,250.,300.,350.,99999.};
//float Hbins[nBinsHT+1] = {400.,600.,1000.,99999.};

////-- met5-ht3-v2
//const int nBinsMET   = 5 ;
//const int nBinsHT    = 3 ;
//    const int version = 2;
//float Mbins[nBinsMET+1] = {150.,175.,200.,350.,450.,99999.};
//float Hbins[nBinsHT+1] = {400.,550.,800.,99999.};

  //-- met6-ht6-v1
//const int nBinsMET   = 6 ;
//const int nBinsHT    = 6 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,200.,250.,300.,350.,400.,99999.};
//float Hbins[nBinsHT+1] = {400.,500.,600.,700.,800.,900.,99999.};

  //-- met7-ht7-v1
//const int nBinsMET   = 7 ;
//const int nBinsHT    = 7 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,200.,250.,300.,350.,400.,500.,99999.};
//float Hbins[nBinsHT+1] = {400.,500.,600.,700.,800.,900.,1000.,99999.};

////-- met8-ht8-v1
//const int nBinsMET   = 8 ;
//const int nBinsHT    = 8 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,200.,250.,300.,350.,400.,450.,600.,99999.};
//float Hbins[nBinsHT+1] = {400.,500.,600.,700.,800.,900.,1000.,1200.,99999.};

////-- met8-ht2-v1
//const int nBinsMET   = 8 ;
//const int nBinsHT    = 2 ;
//    const int version = 1;
//float Mbins[nBinsMET+1] = {150.,200.,250.,300.,350.,400.,450.,600.,99999.};
//float Hbins[nBinsHT+1] = {400.,600.,99999.};



  TString sMbins[nBinsMET];
  TString sHbins[nBinsHT];
  TString sBbins[nBinsBjets] = {"_1b","_2b","_3b","_4b"};

  TString cMbins[nBinsMET];
  TString cHbins[nBinsHT];

  for (int i = 0 ; i < nBinsMET ; i++) {
    TString base = "_M";
    stringstream sbin;
    sbin << i+1;
    base += sbin.str();
    sMbins[i] = base;
    base = "&&MET>";
    stringstream cbin;
    cbin << Mbins[i] << "&&MET<" << Mbins[i+1];
    base += cbin.str();
    cMbins[i] = base;
  }

  for (int j = 0 ; j < nBinsHT ; j++) {
    TString base = "_H";
    stringstream sbin;
    sbin << j+1;
    base += sbin.str();
    sHbins[j] = base;
    base = "&&HT>";
    stringstream cbin;
    cbin << Hbins[j] << "&&HT<" << Hbins[j+1];
    base += cbin.str();
    cHbins[j] = base;
  }

  TString leadJetPtCutString ;
  {
     leadJetPtCutString = "(pt_1st_leadJet>" ;
     stringstream number ;
     number << minLeadJetPt ;
     stringstream number2 ;
     number2 << min3rdJetPt ;
     leadJetPtCutString += number.str() ;
     leadJetPtCutString += "&&pt_2nd_leadJet>" ;
     leadJetPtCutString += number.str() ;
     leadJetPtCutString += "&&pt_3rd_leadJet>" ;
     leadJetPtCutString += number2.str() ;
     leadJetPtCutString += ")" ;
  }

//int dummyInt = 99;
//float dummyFloat = 9.999;
  float dummyZero = 0.;
  float dummyOne = 1.0;
  float dummyPoint999 = 0.999 ;
  float dummyErr = 0.1;

  float sl_frac2b_val[nBinsMET][nBinsHT];
  float sl_frac2b_err[nBinsMET][nBinsHT];
  float sl_frac3b_val[nBinsMET][nBinsHT];
  float sl_frac3b_err[nBinsMET][nBinsHT];
  float sl_frac4b_val[nBinsMET][nBinsHT];
  float sl_frac4b_err[nBinsMET][nBinsHT];


  ofstream inFile;
  char outfile[10000] ;
  if ( mgl > 0. && mlsp > 0. ) {
     if ( target_susy_all0lep > 0. ) {
        sprintf( outfile, "InputWT1bbbb-nb4-mgl%.0f-mlsp%.0f-%.0fevts-met%d-ht%d-v%d.dat", mgl, mlsp, target_susy_all0lep, nBinsMET, nBinsHT, version  ) ;
     } else {
        sprintf( outfile, "InputWT1bbbb-nb4-mgl%.0f-mlsp%.0f-met%d-ht%d-v%d.dat", mgl, mlsp, nBinsMET, nBinsHT, version  ) ;
     }
  } else {
     sprintf( outfile, "Input-nb4-met%d-ht%d-v%d.dat", nBinsMET, nBinsHT, version  ) ;
  }
  inFile.open( outfile );

  // print out header line:

  inFile << "Using HT bins:  " ;
  for (int j = 0 ; j <= nBinsHT ; j++ ) {
    inFile << Hbins[j] ;
    if ( j < nBinsHT ) inFile << "-" ;
  }

  inFile << "\t Using MET bins: " ;
  for (int i = 0 ; i <= nBinsMET ; i++ ) {
    inFile << Mbins[i] ;
    if ( i < nBinsMET ) inFile << "-" ;
  }
  
  inFile << endl ;


   int nSel(3) ;
   char selname[3][100] = { "0lep", "1lep", "ldp" } ;

   char selcuts[3][10000] = {
        "minDelPhiN>4&&nMu==0&&nEl==0&&",
        "minDelPhiN>4&&( (nMu==1&&nEl==0) || (nMu==0&&nEl==1) )&&",
        "minDelPhiN<4&&nMu==0&&nEl==0&&" } ;


  //--- Output histograms.

   TH1F* hmctruth_susy [3][4] ;
   TH1F* hmctruth_ttwj [3][4] ;
   TH1F* hmctruth_ttbar[3][4] ;
   TH1F* hmctruth_wjets[3][4] ;
   TH1F* hmctruth_qcd  [3][4] ;
   TH1F* hmctruth_znn  [3][4] ;
   TH1F* hmctruth_allsm[3][4] ;
   TH1F* hmctruth_all  [3][4] ;

   for ( int si=0; si<nSel; si++ ) {
      for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

         char hname[1000] ;
         char htitle[1000] ;
         sprintf( htitle, "%s, %d btag", selname[si], bbi+1 ) ;

         sprintf( hname, "hmctruth_susy_%s_%db", selname[si], bbi+1 ) ;
         hmctruth_susy[si][bbi] = bookHist( hname, htitle, selname[si], bbi+1, nBinsMET, nBinsHT ) ;

         sprintf( hname, "hmctruth_ttwj_%s_%db", selname[si], bbi+1 ) ;
         hmctruth_ttwj[si][bbi] = bookHist( hname, htitle, selname[si], bbi+1, nBinsMET, nBinsHT ) ;

         sprintf( hname, "hmctruth_ttbar_%s_%db", selname[si], bbi+1 ) ;
         hmctruth_ttbar[si][bbi] = bookHist( hname, htitle, selname[si], bbi+1, nBinsMET, nBinsHT ) ;

         sprintf( hname, "hmctruth_wjets_%s_%db", selname[si], bbi+1 ) ;
         hmctruth_wjets[si][bbi] = bookHist( hname, htitle, selname[si], bbi+1, nBinsMET, nBinsHT ) ;

         sprintf( hname, "hmctruth_qcd_%s_%db", selname[si], bbi+1 ) ;
         hmctruth_qcd[si][bbi] = bookHist( hname, htitle, selname[si], bbi+1, nBinsMET, nBinsHT ) ;

         sprintf( hname, "hmctruth_znn_%s_%db", selname[si], bbi+1 ) ;
         hmctruth_znn[si][bbi] = bookHist( hname, htitle, selname[si], bbi+1, nBinsMET, nBinsHT ) ;

         sprintf( hname, "hmctruth_allsm_%s_%db", selname[si], bbi+1 ) ;
         hmctruth_allsm[si][bbi] = bookHist( hname, htitle, selname[si], bbi+1, nBinsMET, nBinsHT ) ;

         sprintf( hname, "hmctruth_all_%s_%db", selname[si], bbi+1 ) ;
         hmctruth_all[si][bbi] = bookHist( hname, htitle, selname[si], bbi+1, nBinsMET, nBinsHT ) ;


      } // bbi.
   } // si.




     TH1F* hmctruth_fit_zee_1b  = bookHist("hmctruth_fit_zee_1b" , "Zee" , "Zee", 1, nBinsMET, nBinsHT ) ;
     TH1F* hmctruth_fit_zmm_1b  = bookHist("hmctruth_fit_zmm_1b" , "Zmm" , "Zmm", 1, nBinsMET, nBinsHT ) ;






  //--- histograms used in getting the observables.

    TH2F* h_tt[10] ;
    TH2F* h_wjets[10] ;
    TH2F* h_qcd[10] ;
    TH2F* h_znn[10] ;
    TH2F* h_susy[10] ;
    TH2F* h_mc[10] ;

    for ( int bi=0; bi<nBinsBjets; bi++ ) {

       char hname[100] ;

       sprintf( hname, "h_tt_%db", bi+1 ) ;
       h_tt[bi]   = new TH2F( hname, hname , nBinsMET, Mbins, nBinsHT, Hbins ) ;
       h_tt[bi] -> Sumw2() ;

       sprintf( hname, "h_wjets_%db", bi+1 ) ;
       h_wjets[bi]   = new TH2F( hname, hname , nBinsMET, Mbins, nBinsHT, Hbins ) ;
       h_wjets[bi] -> Sumw2() ;

       sprintf( hname, "h_qcd_%db", bi+1 ) ;
       h_qcd[bi]  = new TH2F( hname, hname , nBinsMET, Mbins, nBinsHT, Hbins ) ;
       h_qcd[bi] -> Sumw2() ;

       sprintf( hname, "h_znn_%db", bi+1 ) ;
       h_znn[bi]  = new TH2F( hname, hname , nBinsMET, Mbins, nBinsHT, Hbins ) ;
       h_znn[bi] -> Sumw2() ;

       sprintf( hname, "h_susy_%db", bi+1 ) ;
       h_susy[bi] = new TH2F( hname, hname , nBinsMET, Mbins, nBinsHT, Hbins ) ;
       h_susy[bi] -> Sumw2() ;

       sprintf( hname, "h_mc_%db", bi+1 ) ;
       h_mc[bi]   = new TH2F( hname, hname , nBinsMET, Mbins, nBinsHT, Hbins ) ;
       h_mc[bi] -> Sumw2() ;

    }

  float nSusyTotal = 0;

  for ( int si=0 ; si<nSel ; si++ ) {


  printf("\n\n-----------------------------------------------------------------\n\n") ;

      for (int k = 0 ; k < nBinsBjets ; k++) {

        char allcuts[10000] ;
        char allsusycuts[10000] ;

        if ( k < (nBinsBjets-1) ) {
          sprintf( allcuts, "%snB==%d&&nJets>=%d&&(pt_1st_leadJet>%.0f&&pt_2nd_leadJet>%.0f&&pt_3rd_leadJet>%.0f)", selcuts[si], k+1, nJetsCut, minLeadJetPt, minLeadJetPt, min3rdJetPt ) ;
          sprintf( allsusycuts, "%snB==%d&&nJets>=%d&&(pt_1st_leadJet>%.0f&&pt_2nd_leadJet>%.0f&&pt_3rd_leadJet>%.0f)%s", selcuts[si], k+1, nJetsCut, minLeadJetPt, minLeadJetPt, min3rdJetPt, susycut.Data() ) ;
        } else {
          sprintf( allcuts, "%snB>=%d&&nJets>=%d&&(pt_1st_leadJet>%.0f&&pt_2nd_leadJet>%.0f&&pt_3rd_leadJet>%.0f)", selcuts[si], k+1, nJetsCut, minLeadJetPt, minLeadJetPt, min3rdJetPt ) ;
          sprintf( allsusycuts, "%snB>=%d&&nJets>=%d&&(pt_1st_leadJet>%.0f&&pt_2nd_leadJet>%.0f&&pt_3rd_leadJet>%.0f)%s", selcuts[si], k+1, nJetsCut, minLeadJetPt, minLeadJetPt, min3rdJetPt, susycut.Data() ) ;
        }


        printf("\n\n N_%s -- nbjet bin (%d): cuts=%s\n\n", selname[si], k, allcuts) ; cout << flush ;

        char hname[100] ;
        sprintf( hname, "h_tt_%db", k+1 ) ;
        if(doPUreweighting) FillHTMET(&chainTT, h_tt[k], si, k);
	else chainTT.Project (hname,"HT:MET",allcuts);
	printf("    %12s %9.1f events\n", hname, h_tt[k]->Integral() ) ; cout << flush ;

        sprintf( hname, "h_wjets_%db", k+1 ) ;
        if(doPUreweighting) FillHTMET(&chainWJets, h_wjets[k], si, k);
	else chainWJets.Project(hname,"HT:MET",allcuts);
	printf("    %12s %9.1f events\n", hname, h_wjets[k]->Integral() ) ; cout << flush ;

        sprintf( hname, "h_qcd_%db", k+1 ) ;
        if (doPUreweighting) FillHTMET(&chainQCD, h_qcd[k], si, k);
	else chainQCD.Project(hname,"HT:MET",allcuts);
	printf("    %12s %9.1f events\n", hname, h_qcd[k]->Integral() ) ; cout << flush ;

        sprintf( hname, "h_znn_%db", k+1 ) ;
        if (doPUreweighting) FillHTMET(&chainZnn, h_znn[k], si, k);
	else chainZnn.Project(hname,"HT:MET",allcuts);
	printf("    %12s %9.1f events\n", hname, h_znn[k]->Integral() ) ; cout << flush ;
        if ( mgl > 0. ) {
           sprintf( hname, "h_susy_%db", k+1 ) ;
           chainT1bbbb.Project(hname,"HT:MET",allsusycuts);
           h_susy[k]->Scale( t1bbbbWeight ) ;
           printf("    %12s %9.1f events\n", hname, h_susy[k]->Integral() ) ; cout << flush ;
	   if (si==0) nSusyTotal += h_susy[k]->Integral();
        }
      } // k
      if (si==0) printf("N_Susy_Total = %9.1f events", nSusyTotal); cout << flush;
      printf("\n\n") ;


      for (int i = 0 ; i < nBinsMET ; i++) {
        for (int j = 0 ; j < nBinsHT ; j++) {
          for (int k = 0 ; k < nBinsBjets ; k++) {


             char obsname[1000] ;
             sprintf( obsname, "N_%s_M%d_H%d_%db", selname[si], i+1, j+1, k+1 ) ;


             double ttval = h_tt[k] -> GetBinContent( i+1, j+1 ) ;
             double tterr = h_tt[k] -> GetBinError(   i+1, j+1 ) ;

             double wjetsval = h_wjets[k] -> GetBinContent( i+1, j+1 ) ;
             double wjetserr = h_wjets[k] -> GetBinError(   i+1, j+1 ) ;

             double qcdval = h_qcd[k] -> GetBinContent( i+1, j+1 ) ;
             double qcderr = h_qcd[k] -> GetBinError(   i+1, j+1 ) ;

             double znnval = h_znn[k] -> GetBinContent( i+1, j+1 ) ;
             double znnerr = h_znn[k] -> GetBinError(   i+1, j+1 ) ;

             double susyval = h_susy[k] -> GetBinContent( i+1, j+1 ) ;
             double susyerr = h_susy[k] -> GetBinError(   i+1, j+1 ) ;

             printf(" N_%s, tt     met,ht,nbjet bin (%d,%d,%d)  --  npass=%7.1f +/- %6.1f\n", selname[si], i,j,k, ttval,tterr) ; cout << flush ;
             printf(" N_%s, wjets  met,ht,nbjet bin (%d,%d,%d)  --  npass=%7.1f +/- %6.1f\n", selname[si], i,j,k, wjetsval,wjetserr) ; cout << flush ;
             printf(" N_%s, qcd    met,ht,nbjet bin (%d,%d,%d)  --  npass=%7.1f +/- %6.1f\n", selname[si], i,j,k, qcdval,qcderr) ; cout << flush ;
             printf(" N_%s, znn    met,ht,nbjet bin (%d,%d,%d)  --  npass=%7.1f +/- %6.1f\n", selname[si], i,j,k, znnval,znnerr) ; cout << flush ;
             if ( mgl>0. ) {
                if ( target_susy_all0lep > 0. ) {
                   susyval = susyval * (target_susy_all0lep/nSusyTotal);
                   susyerr = susyerr * (target_susy_all0lep/nSusyTotal);
                }
                printf(" N_%s, susy   met,ht,nbjet bin (%d,%d,%d)  --  npass=%7.1f +/- %6.1f\n", selname[si], i,j,k, susyval,susyerr) ; cout << flush ;
             }
             printf("\n") ;

             double allval = ttval + wjetsval + qcdval + znnval + susyval ;

             //// inFile << obsname << "  \t" << (int)allval << endl;
             inFile << obsname << "  \t" << allval << endl;

             int histbin = 1 + (nBinsHT+1)*i + j + 1 ;

             hmctruth_ttwj[si][k]  -> SetBinContent( histbin, ttval + wjetsval  ) ;
             hmctruth_ttwj[si][k]  -> SetBinError(   histbin, sqrt( pow(tterr,2) + pow(wjetserr,2) )  ) ;
             hmctruth_ttbar[si][k] -> SetBinContent( histbin, ttval ) ;
             hmctruth_ttbar[si][k] -> SetBinError(   histbin, tterr ) ;
             hmctruth_wjets[si][k] -> SetBinContent( histbin, wjetsval  ) ;
             hmctruth_wjets[si][k] -> SetBinError(   histbin, wjetserr  ) ;
             hmctruth_qcd[si][k]   -> SetBinContent( histbin, qcdval ) ;
             hmctruth_qcd[si][k]   -> SetBinError(   histbin, qcderr ) ;
             hmctruth_znn[si][k]   -> SetBinContent( histbin, znnval ) ;
             hmctruth_znn[si][k]   -> SetBinError(   histbin, znnerr ) ;
             hmctruth_susy[si][k]  -> SetBinContent( histbin, susyval  ) ;
             hmctruth_susy[si][k]  -> SetBinError(   histbin, susyerr  ) ;
             hmctruth_allsm[si][k] -> SetBinContent( histbin, ttval+wjetsval+qcdval+znnval ) ;
             hmctruth_allsm[si][k] -> SetBinError(   histbin, sqrt( pow(tterr,2) + pow(wjetserr,2) + pow(qcderr,2) + pow(znnerr,2) ) ) ;
             hmctruth_all[si][k]   -> SetBinContent( histbin, ttval+wjetsval+qcdval+znnval+susyval ) ;
             hmctruth_all[si][k]   -> SetBinError(   histbin, sqrt( pow(tterr,2) + pow(wjetserr,2) + pow(qcderr,2) + pow(znnerr,2) + pow(susyerr,2) ) ) ;


	     // compute fractions of SL 2b/1b and 3b/1b

	     if ( si == 1 && k > 0 ) {

	       double ttval_1b = h_tt[0] -> GetBinContent( i+1, j+1 ) ;
	       double wjetsval_1b = h_wjets[0] -> GetBinContent( i+1, j+1 ) ;

	       double ttwjval = ttval + wjetsval ;
	       double ttwjval_1b = ttval_1b + wjetsval_1b ;

	       if ( k == 1 ) {
		 sl_frac2b_val[i][j] = ( ttwjval ) / ( ttwjval_1b ) ;
		 sl_frac2b_err[i][j] = 0.01 ;   // start with arbitrary errors, first
	       }

	       if ( k == 2 ) {
		 sl_frac3b_val[i][j] = ( ttwjval ) / ( ttwjval_1b ) ;
		 sl_frac3b_err[i][j] = 0.01 ;   // start with arbitrary errors, first
	       }

	       if ( k == 3 ) {
		 sl_frac4b_val[i][j] = ( ttwjval ) / ( ttwjval_1b ) ;
		 sl_frac4b_err[i][j] = 0.01 ;   // start with arbitrary errors, first
	       }

	     }

            } // k
          } // j
        } // i



          for (int k = 0 ; k < nBinsBjets ; k++) {
             h_tt[k] -> Reset() ;
             h_wjets[k] -> Reset() ;
             h_qcd[k] -> Reset() ;
             h_znn[k] -> Reset() ;
             h_susy[k] -> Reset() ;
          }


     } // si.




     //--- Insert dummy R_lsb lines for backwards compatibility.
     for ( int hbi=0; hbi<nBinsHT; hbi++ ) {
        for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {
           char dummyline[1000] ;
           sprintf( dummyline, "R_lsb_H%d_%db       0.1", hbi+1, bbi+1 ) ;
           inFile << dummyline << endl ;
           sprintf( dummyline, "R_lsb_H%d_%db_err   0.01", hbi+1, bbi+1 ) ;
           inFile << dummyline << endl ;
        } // bbi.
     } // hbi.





    printf("\n\n-----------------------------------------------------------------\n\n") ; cout << flush ;

    { //--- scoping bracket for QCD chunk.

    //--- Fill histograms to be used in QCD analysis (done in mcclosure4.c).

      const int nQcdSamples(9) ;

      TCanvas* cqcd = new TCanvas("cqcd","QCD") ;

      TH2F*   h0lep[nQcdSamples][nBinsBjets] ;
      TH2F*   hldp [nQcdSamples][nBinsBjets] ;

      TChain* qcdch[nQcdSamples] ;

      char hname[1000] ;
      char htitle[1000] ;

      TH2F* hdummy = new TH2F("hdummy","",2, Mbins[0], 1500., 2, Hbins[0], 1500. ) ;

         printf("\n\n") ;
         for ( int si=0; si<nQcdSamples; si++ ) {

            qcdch[si] = new TChain("tree") ;
            printf(" %2d : connecting to %s\n", si, qcdinputfile[si] ) ;
            qcdch[si] -> Add( qcdinputfile[si] ) ;

            for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

               sprintf( hname, "h_0lep_%db_%s", bbi+1, qcdsamplename[si] ) ;
               sprintf( htitle, "QCD 0lep yield, nb=%d, %s", bbi+1, qcdsamplename[si] ) ;
               printf("         booking hist %s : %s\n", hname, htitle ) ;
               h0lep[si][bbi] = new TH2F( hname, htitle, nBinsMET, Mbins, nBinsHT, Hbins ) ;
               h0lep[si][bbi] -> Sumw2() ;
               sprintf( hname, "h_ldp_%db_%s", bbi+1, qcdsamplename[si] ) ;
               sprintf( htitle, "QCD  LDP yield, nb=%d, %s", bbi+1, qcdsamplename[si] ) ;
               printf("         booking hist %s  : %s\n", hname, htitle ) ;
               hldp [si][bbi] = new TH2F( hname, htitle, nBinsMET, Mbins, nBinsHT, Hbins ) ;
               hldp [si][bbi] -> Sumw2() ;

            } // bbi.

         } // si.
         printf("\n\n") ;


         char bcut[4][100] = { "nB==1", "nB==2", "nB==3", "nB>=4" } ;

         for ( int si=0; si<nQcdSamples; si++ ) {

            printf(" %2d : %s : 0lep\n", si, qcdsamplename[si] ) ; cout << flush ;
            for ( int bbi=0; bbi<nBinsBjets; bbi++ ) {

               char arg1[1000] ;

               char cuts0lep[10000] ;
               sprintf( cuts0lep, "%s(%s)&&nJets>=%d&&(pt_1st_leadJet>%.0f&&pt_2nd_leadJet>%.0f&&pt_3rd_leadJet>%.0f)", selcuts[0], bcut[bbi], nJetsCut, minLeadJetPt, minLeadJetPt, min3rdJetPt ) ;
               printf("     %db, 0lep cuts : %s\n", bbi+1, cuts0lep ) ;
               sprintf( arg1, "HT:MET>>h_0lep_%db_%s", bbi+1, qcdsamplename[si] ) ;
               qcdch[si] -> Draw( arg1, cuts0lep ) ;
               hdummy->Draw() ;
               h0lep[si][bbi]->Draw("samecolz") ;
               cqcd->Update() ; cqcd->Draw() ;


               char cutsldp[10000] ;
               sprintf( cutsldp, "%s(%s)&&nJets>=%d&&(pt_1st_leadJet>%.0f&&pt_2nd_leadJet>%.0f&&pt_3rd_leadJet>%.0f)", selcuts[2], bcut[bbi], nJetsCut, minLeadJetPt, minLeadJetPt, min3rdJetPt ) ;
               printf("     %db, ldp  cuts : %s\n", bbi+1, cutsldp  ) ;
               sprintf( arg1, "HT:MET>>h_ldp_%db_%s", bbi+1, qcdsamplename[si] ) ;
               qcdch[si] -> Draw( arg1, cutsldp, "colz" ) ;
               hdummy->Draw() ;
               hldp[si][bbi]->Draw("samecolz") ;
               cqcd->Update() ; cqcd->Draw() ;

            } // bbi.

         } // si.

    } //--- scoping bracket for QCD chunk.

    printf("\n\n-----------------------------------------------------------------\n\n") ; cout << flush ;
  
    // Z -> ee observables 
  
    TH1F* ht = new TH1F("ht","ht",10,0,10000);
  
    ht -> Sumw2() ;

    TString cutszee = "cat==2&&minDelPhiNee>4&&nVLB>=1&&nJets>=";
    stringstream njcut ; njcut << nJetsCut ;
    cutszee += njcut.str();
    cutszee += "&&";

    for (int i = 0 ; i < nBinsMET ; i++) {
      for (int j = 0 ; j < nBinsHT ; j++) {
  
        TString obs_Zee = "N_Zee" ;
        obs_Zee = obs_Zee+sMbins[i]+sHbins[j] ;
        
        TString cut = "HT>";  
        cut += Hbins[j];
        cut += "&&HT<";
        cut += Hbins[j+1];
        cut += "&&METee>";
        cut += Mbins[i];
        cut += "&&METee<";
        cut += Mbins[i+1];
  
        TString allcutsZ = cutszee+cut ;
        allcutsZ += "&&" ;
        allcutsZ += leadJetPtCutString ;
  
        dyTree->Project("ht","HT",allcutsZ);
        double allerr(0.) ;
        double allval = ht->IntegralAndError(1,10,allerr) ;
        printf(" N_Zee -- HT,MET bins (%d,%d): events=%7.1f +/- %6.1f, cuts=%s\n", j,i,allval,allerr,allcutsZ.Data() ) ; cout << flush ;
          ht->Reset() ;
  
        ////// inFile << obs_Zee << "  \t" << (int)allval << endl;
        inFile << obs_Zee << "  \t" << allval << endl;

        //Z->ee counts, with 1 VLb and sig selection, so so MET>250, HT>400, mindelphi>4, 2e, 0mu, nJets >= 3
  
        int histbin = 1 + (nBinsHT+1)*i + j + 1 ;
  
        hmctruth_fit_zee_1b -> SetBinContent( histbin, allval ) ;
        hmctruth_fit_zee_1b -> SetBinError(   histbin, allerr ) ;
  
      }
    }
  
    
    printf("\n\n-----------------------------------------------------------------\n\n") ; cout << flush ;
  
    // Z -> mm observables
  
    TString cutszmm = "cat==1&&minDelPhiNmm>4&&nVLB>=1&&nJets>=";
    cutszmm += njcut.str();
    cutszmm += "&&";

    for (int i = 0 ; i < nBinsMET ; i++) {
      for (int j = 0 ; j < nBinsHT ; j++) {
  
        TString obs_Zmm = "N_Zmm" ;
        obs_Zmm = obs_Zmm+sMbins[i]+sHbins[j] ;
        
        TString cut = "HT>";  
        cut += Hbins[j];
        cut += "&&HT<";
        cut += Hbins[j+1];
        cut += "&&METmm>";
        cut += Mbins[i];
        cut += "&&METmm<";
        cut += Mbins[i+1];
        
        TString allcutsZ = cutszmm+cut ;
        allcutsZ += "&&" ;
        allcutsZ += leadJetPtCutString ;
  
        dyTree->Project("ht","HT",allcutsZ);
        double allerr(0.) ;
        double allval = ht->IntegralAndError(1,10,allerr) ;
        printf(" N_Zmm -- HT,MET bins (%d,%d): events=%7.1f +/- %6.1f, cuts=%s\n", j,i,allval,allerr,allcutsZ.Data() ) ; cout << flush ;
          ht->Reset() ;
  
        ////// inFile << obs_Zmm << "  \t" << (int)allval << endl;
        inFile << obs_Zmm << "  \t" << allval << endl;

        //Z->mm counts, with 1 VLb and sig selection, so so MET>250, HT>400, mindelphi>4, 2mu, 0e, nJets >= 3
  
        int histbin = 1 + (nBinsHT+1)*i + j + 1 ;
  
        hmctruth_fit_zmm_1b -> SetBinContent( histbin, allval ) ;
        hmctruth_fit_zmm_1b -> SetBinError(   histbin, allerr ) ;
  
  
      }
    }
  
    //inFile << "Why are all three of these MC categories separate? I've just put them together (only QCD, Zinv, tt)" << endl;
    // Nttbarsingletopzjetsmc_ldp
  
  
    printf("\n\n-----------------------------------------------------------------\n\n") ; cout << flush ;

    //--- Owen : these MC inputs are no longer used.  Insert dummy values for backwards compatibility in format.

    for (int i = 0 ; i < nBinsMET ; i++) {
      for (int j = 0 ; j < nBinsHT ; j++) {
        for (int k = 0 ; k < nBinsBjets ; k++) {

           char obsname[1000] ;
           sprintf( obsname, "N_ttbarsingletopzjetsmc_ldp_M%d_H%d_%db", i+1, j+1, k+1 ) ;

           double val, err ;
           val = 0. ;
           err = 0. ;

           printf(" %s : %7.1f +/- %7.1f\n", obsname, val, err ) ;

           inFile << obsname << "  \t" << val << endl ;

        }
        printf("\n") ;
      }
      printf("\n") ;
    }

    // NWJmc_ldp
  
    for (int i = 0 ; i < nBinsMET ; i++) {
      for (int j = 0 ; j < nBinsHT ; j++) {
        for (int k = 0 ; k < nBinsBjets ; k++) {
  
  	TString obs_WJmc_ldp = "N_WJmc_ldp" ;
  	obs_WJmc_ldp = obs_WJmc_ldp+sMbins[i]+sHbins[j]+sBbins[k] ;
  	
  	inFile << obs_WJmc_ldp << "  \t" << dummyZero << endl;
  // signal selection, but ldp, so MET>250, HT>400, >=1 b, mindelphi<4, 0L, nJets >= 3
        }
      }
    }
  
  
    // NZnnmc_ldp
  
    for (int i = 0 ; i < nBinsMET ; i++) {
      for (int j = 0 ; j < nBinsHT ; j++) {
        for (int k = 0 ; k < nBinsBjets ; k++) {
  
  	TString obs_Znnmc_ldp = "N_Znnmc_ldp" ;
  	obs_Znnmc_ldp = obs_Znnmc_ldp+sMbins[i]+sHbins[j]+sBbins[k] ;
  	
  	inFile << obs_Znnmc_ldp << "  \t" << dummyZero << endl;
  // signal selection, but ldp, so MET>250, HT>400, >=1 b, mindelphi<4, 0L, nJets >= 3
        }
      }
    }
  
    printf("\n\n-----------------------------------------------------------------\n\n") ; cout << flush ;
  
    // various parameters needed for Z -> invis.
  
    // Z -> ee acceptance
  
    for (int i = 0 ; i < nBinsMET ; i++) {
  
      TString Zee_acc = "acc_Zee";
      Zee_acc = Zee_acc+sMbins[i];
  
      inFile << Zee_acc << "  \t" << dummyPoint999 << endl;
  
      Zee_acc = Zee_acc+"_err";
      inFile << Zee_acc << "  \t" << dummyErr << endl;
  
    }
  
  
    // Z -> mm acceptance
  
    for (int i = 0 ; i < nBinsMET ; i++) {
  
      TString Zmm_acc = "acc_Zmm";
      Zmm_acc = Zmm_acc+sMbins[i];
  
      inFile << Zmm_acc << "  \t" << dummyPoint999 << endl;
  
      Zmm_acc = Zmm_acc+"_err";
      inFile << Zmm_acc << "  \t" << dummyErr << endl;
  
    }
  
  
    // Z -> ll efficiencies
  
  // use 2011 values for now.
    inFile << "Z_ee_eff  \t" << 0.6774 << endl;
    inFile << "Z_ee_eff_err  \t" << 0.0580 << endl;
    inFile << "Z_mm_eff  \t" << 0.7217 << endl;
    inFile << "Z_mm_eff_err  \t" << 0.0506 << endl;
  
  
    // Z -> ee VL to nominal scale factors
  // would it make more sense to count events in only the loosest HT and/or MET bin and
  // use the scale factors to translate between the different HT and MET bins?

   //    for (int k = 0 ; k < nBinsBjets ; k++) {
   //    TString knn_ee = "knn_ee" ;
   //    knn_ee = knn_ee+sBbins[k] ;
   //    inFile << knn_ee << "  \t" << dummyOne << endl;
   //    knn_ee = knn_ee+"_err" ;
   //    inFile << knn_ee << "  \t" << dummyErr << endl;
   //  }
   //
   //
   //  // use 2011 values for now.
   //  inFile << "knn_1b     \t" << 0.401 << endl;
   //  inFile << "knn_1b_err \t" << 0.018 << endl;
   //  inFile << "knn_2b     \t" << 0.067 << endl;
   //  inFile << "knn_2b_err \t" << 0.009 << endl;
   //  inFile << "knn_3b     \t" << 0.009 << endl;
   //  inFile << "knn_3b_err \t" << 0.003 << endl;
   //

    // updated SF's to improve MC closure (the errors are the same as before)
    inFile << "knn_1b     \t" << 0.394  << endl;
    inFile << "knn_1b_err \t" << 0.018  << endl;
    inFile << "knn_2b     \t" << 0.0626 << endl;
    inFile << "knn_2b_err \t" << 0.009  << endl;
    inFile << "knn_3b     \t" << 0.0036 << endl;
    inFile << "knn_3b_err \t" << 0.003  << endl;
    inFile << "knn_4b     \t" << 0.00011 << endl;
    inFile << "knn_4b_err \t" << 0.00011  << endl;

    // Z -> ll purity
  
    // use 2011 values for now.
    inFile << "Z_ee_pur  \t" << 0.911 << endl;
    inFile << "Z_ee_pur_err  \t" << 0.079 << endl;
    inFile << "Z_mm_pur  \t" << 0.866 << endl;
    inFile << "Z_mm_pur_err  \t" << 0.079 << endl;
  
  
    // scale factors:
  
    inFile << "sf_mc  \t" << dummyOne << endl ; 
    inFile << "sf_mc_err  \t" << dummyErr << endl; 
  
  
    // sf_qcd
  
    for (int i = 0 ; i < nBinsMET ; i++) {
      for (int j = 0 ; j < nBinsHT ; j++) {
        for (int k = 0 ; k < nBinsBjets ; k++) {
  
  	TString sf_qcd = "sf_qcd" ;
  	sf_qcd = sf_qcd+sMbins[i]+sHbins[j]+sBbins[k] ;
  	
  	inFile << sf_qcd << "  \t" << dummyOne << endl;	
  
  	sf_qcd = sf_qcd+"_err" ;
  	inFile << sf_qcd << "  \t" << dummyErr << endl;	
  
        }
      }
    }
  
  
    // sf_ttwj
  
    for (int i = 0 ; i < nBinsMET ; i++) {
      for (int j = 0 ; j < nBinsHT ; j++) {
        for (int k = 0 ; k < nBinsBjets ; k++) {
  
  	TString sf_ttwj = "sf_ttwj" ;
  	sf_ttwj = sf_ttwj+sMbins[i]+sHbins[j]+sBbins[k] ;
  	
  	inFile << sf_ttwj << "  \t" << dummyOne << endl;	
  
  	sf_ttwj = sf_ttwj+"_err" ;
  	inFile << sf_ttwj << "  \t" << dummyErr << endl;	
  
        }
      }
    }
  
  
    // sf_ee
  
    for (int k = 0 ; k < nBinsBjets ; k++) {
  
      TString sf_ee = "sf_ee" ;
      sf_ee = sf_ee+sBbins[k] ;
  
      inFile << sf_ee << "  \t" << dummyOne << endl;
      
      sf_ee = sf_ee+"_err" ;
      inFile << sf_ee << "  \t" << dummyErr << endl;
  
    }
  
  
    // sf_mm
  
    for (int k = 0 ; k < nBinsBjets ; k++) {
  
      TString sf_mm = "sf_mm" ;
      sf_mm = sf_mm+sBbins[k] ;
  
      inFile << sf_mm << "  \t" << dummyOne << endl;
      
      sf_mm = sf_mm+"_err" ;
      inFile << sf_mm << "  \t" << dummyErr << endl;
  
    }


    // btag eff err (Note: this was missing until Aug 3, 2012, but it's apparently not used.)
    inFile << "btageff_err" << " \t" << dummyErr << endl ;



    //--- Addding ttwj and znn LDP/ZL MC values

    //--- ttwj MC LDP/ZL

    for (int mbi = 0 ; mbi < nBinsMET ; mbi++) {
      for (int hbi = 0 ; hbi < nBinsHT ; hbi++) {
        int hbin = 1 + (nBinsHT+1)*mbi + hbi + 1 ;
        for (int bbi = 0 ; bbi < nBinsBjets ; bbi++) {

            float ldpval = hmctruth_ttwj[2][bbi] -> GetBinContent( hbin ) ;
            float ldperr = hmctruth_ttwj[2][bbi] -> GetBinError(   hbin ) ;
            float zlval  = hmctruth_ttwj[0][bbi] -> GetBinContent( hbin ) ;
            float zlerr  = hmctruth_ttwj[0][bbi] -> GetBinError(   hbin ) ;

            float ldpoverzl = 0. ;
            float ldpoverzlerr = 0. ;

            if ( zlval > 0. && ldpval > 0. ) {
               ldpoverzl = ldpval / zlval ;
               ldpoverzlerr = ldpoverzl * sqrt( pow((zlerr/zlval),2) + pow((ldperr/ldpval),2) ) ;
            }

            char parname[1000] ;

            sprintf( parname, "ttwj_mc_ldpover0lep_ratio_M%d_H%d_%db", mbi+1, hbi+1, bbi+1 ) ;
            printf(" %s  :  %6.3f +/- %5.3f\n", parname, ldpoverzl, ldpoverzlerr ) ;
            inFile << parname << "  \t" << ldpoverzl << endl;

            sprintf( parname, "ttwj_mc_ldpover0lep_ratio_M%d_H%d_%db_err", mbi+1, hbi+1, bbi+1 ) ;
            inFile << parname << "  \t" << ldpoverzlerr << endl;

        } // bbi
      } // hbi
    } // mbi


    //--- Znn MC LDP/ZL
    //--- Note: the 2b and >=3b MC stats are too low.  Use 1b values for all 3.

    for (int mbi = 0 ; mbi < nBinsMET ; mbi++) {
      for (int hbi = 0 ; hbi < nBinsHT ; hbi++) {
        int hbin = 1 + (nBinsHT+1)*mbi + hbi + 1 ;

        float ldpval = hmctruth_znn[2][0] -> GetBinContent( hbin ) ;
        float ldperr = hmctruth_znn[2][0] -> GetBinError(   hbin ) ;
        float zlval  = hmctruth_znn[0][0] -> GetBinContent( hbin ) ;
        float zlerr  = hmctruth_znn[0][0] -> GetBinError(   hbin ) ;

        float ldpoverzl = 0. ;
        float ldpoverzlerr = 0. ;

        if ( zlval > 0. && ldpval > 0. ) {
           ldpoverzl = ldpval / zlval ;
           ldpoverzlerr = ldpoverzl * sqrt( pow((zlerr/zlval),2) + pow((ldperr/ldpval),2) ) ;
        }

        char parname[1000] ;

        for (int bbi = 0 ; bbi < nBinsBjets ; bbi++) {
            sprintf( parname, "znn_mc_ldpover0lep_ratio_M%d_H%d_%db", mbi+1, hbi+1, bbi+1 ) ;
            printf(" %s  :  %6.3f +/- %5.3f\n", parname, ldpoverzl, ldpoverzlerr ) ;
            inFile << parname << "  \t" << ldpoverzl << endl;

            sprintf( parname, "znn_mc_ldpover0lep_ratio_M%d_H%d_%db_err", mbi+1, hbi+1, bbi+1 ) ;
            inFile << parname << "  \t" << ldpoverzlerr << endl;
        } // bbi
      } // hbi
    } // mbi


    // add here the fractions (bin by bin) of 2b/1b and 3b/1b SL events (just for the MC for now)

    for (int mbi = 0 ; mbi < nBinsMET ; mbi++) {
      for (int hbi = 0 ; hbi < nBinsHT ; hbi++) {

	TString Sl2bstring     = "sl_frac_2b_val";
	TString Sl2bstring_err = "sl_frac_2b_err";
	TString Sl3bstring     = "sl_frac_3b_val";
	TString Sl3bstring_err = "sl_frac_3b_err";
	TString Sl4bstring     = "sl_frac_4b_val";
	TString Sl4bstring_err = "sl_frac_4b_err";

	Sl2bstring     += sMbins[mbi]+sHbins[hbi] ;
	Sl2bstring_err += sMbins[mbi]+sHbins[hbi] ;
	Sl3bstring     += sMbins[mbi]+sHbins[hbi] ;
	Sl3bstring_err += sMbins[mbi]+sHbins[hbi] ;
	Sl4bstring     += sMbins[mbi]+sHbins[hbi] ;
	Sl4bstring_err += sMbins[mbi]+sHbins[hbi] ;

	inFile << Sl2bstring     << "   \t" << sl_frac2b_val[mbi][hbi] << endl ;
	inFile << Sl2bstring_err << "   \t" << sl_frac2b_err[mbi][hbi] << endl ;
	inFile << Sl3bstring     << "   \t" << sl_frac3b_val[mbi][hbi] << endl ;
	inFile << Sl3bstring_err << "   \t" << sl_frac3b_err[mbi][hbi] << endl ;
	inFile << Sl4bstring     << "   \t" << sl_frac4b_val[mbi][hbi] << endl ;
	inFile << Sl4bstring_err << "   \t" << sl_frac4b_err[mbi][hbi] << endl ;

      }
    }




    gSystem->Exec("mkdir -p rootfiles") ;
    char outHistName[1000] ;
    if ( mgl>0. && mlsp>0. ) {
       if ( target_susy_all0lep > 0 ) {
          sprintf( outHistName, "rootfiles/gi-plots-nb4-wsusy-mgl%.0f-mlsp%.0f-%.0fevts-met%d-ht%d-v%d.root", mgl, mlsp, target_susy_all0lep, nBinsMET, nBinsHT, version ) ;
       } else {
          sprintf( outHistName, "rootfiles/gi-plots-nb4-wsusy-mgl%.0f-mlsp%.0f-met%d-ht%d-v%d.root", mgl, mlsp, nBinsMET, nBinsHT, version ) ;
       }
    } else {
       sprintf( outHistName, "rootfiles/gi-plots-nb4-met%d-ht%d-v%d.root", nBinsMET, nBinsHT, version ) ;
    }
    saveHist( outHistName, "h*" ) ;


    inFile.close();
    return;
  
  }
Example #22
0
void ootpu_fit(TString files, TString comments="") {

  TChain* chain = new TChain("reduced_tree");
  chain->Add(files);

  TH1::SetDefaultSumw2();

  TH1F* hrelIso = new TH1F("hrelIso","", 30, 0, 0.5);
  TH1F* hOOTPU = new TH1F("hOOTPU","", 75, 0, 75);
  TH1F* hOOTPUvsIso = new TH1F("hOOTPUvsIso",";Out-of-time ints.;Isolation cut efficiency", 15, 0, 75);

  hrelIso->StatOverflows(true);
  
  int n1(0), n2(0);
  if (files.Contains("20bx25")) {
    n1=15;
    n2=75;
  }
  else if (files.Contains("S14")) {
    n1=0;
    n2=120;
  }
  else { // default: 8 TeV scenario
    n1=0;
    n2=70;
  }


  TString mu("num_gen_muons==1&&muon_reco_match>=0");
  int low = 15; 
  for (int bin(1); bin<hOOTPUvsIso->GetNbinsX()+1; bin++) {
    if (bin<4) continue;
    if (bin>4) low=low+5;
    if (low>hOOTPUvsIso->GetBinLowEdge(hOOTPUvsIso->GetNbinsX())) break;
    TString cuts = Form("(%s)&&(oot_pu>=%d&&oot_pu<%d)",mu.Data(),low,low+4);
    cout << "Cuts: " << cuts.Data() << endl;
    chain->Project(hrelIso->GetName(), "muon_relIso", cuts);
    chain->Project(hOOTPU->GetName(), "oot_pu", cuts);
    hrelIso->Scale(1/hrelIso->GetEntries());
    Double_t left(0.), lerror(0.), right(0.), rerror(0.);
    left = hrelIso->IntegralAndError(1,12,lerror);
    right = hrelIso->IntegralAndError(13,31,rerror);
    float rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
    printf("bin1: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
    hOOTPUvsIso->SetBinContent(bin,left/(left+right));
    hOOTPUvsIso->SetBinError(bin,rat_error);
  }
  
  hOOTPUvsIso->SetLineColor(1);
  hOOTPUvsIso->SetMarkerColor(1);
  hOOTPUvsIso->SetMarkerStyle(20);

  TCanvas* c1 = new TCanvas();

  hOOTPUvsIso->Draw("e1");

  // do a linear fit
  TF1 *flin = new TF1("flin", "1 ++ x", 15, 75);
  hOOTPUvsIso->Fit(flin);
  flin=hOOTPUvsIso->GetFunction("flin");
  flin->SetLineColor(kBlue);
  flin->SetLineWidth(2);

  TString plotTitle ="OOTPU_fit"+comments+".pdf";
  c1->Print(plotTitle);

  // cout << "Rejection rates" << endl;
  // Double_t left(0.), lerror(0.), right(0.), rerror(0.);
  // left = hA->IntegralAndError(1,12,lerror);
  // right = hA->IntegralAndError(13,31,rerror);
  // float rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  // printf("bin1: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  // left = hB->IntegralAndError(1,12,lerror);
  // right = hB->IntegralAndError(13,31,rerror);
  // rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  // printf("bin2: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  // left = hC->IntegralAndError(1,12,lerror);
  // right = hC->IntegralAndError(13,31,rerror);
  // rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  // printf("bin3: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
  // left = hD->IntegralAndError(1,12,lerror);
  // right = hD->IntegralAndError(13,31,rerror);
  // rat_error=sqrt((left*left*rerror*rerror+right*right*lerror*lerror)/((left+right)*(left+right)));
  // printf("bin4: %3.2f +/- %3.3f\n", left/(left+right),rat_error);
}
Example #23
0
void pv_comparison(TString files, TString comments="") {

  TChain* chain = new TChain("reduced_tree");
  chain->Add(files);

  TH1F* h0to10 = new TH1F("h0to10",";I_{rel}(#mu);(a.u.)", 30, 0., 0.5);
  TH1F* h10to15 = new TH1F("h10to15",";relIso;(a.u.)", 30, 0., 0.5);
  TH1F* h15to20 = new TH1F("h15to20",";relIso;(a.u.)", 30, 0., 0.5);
  TH1F* h20to25 = new TH1F("h20to25",";relIso;(a.u.)", 30, 0., 0.5);
  TH1F* h25to40 = new TH1F("h25to40",";relIso;(a.u.)", 30, 0., 0.5);
  h0to10->SetStats(0);
  h0to10->GetYaxis()->SetLabelSize(0.04);
  //h0to10->GetYaxis()->SetTitleOffset(1.3);
  h0to10->GetXaxis()->SetTitleOffset(1.1);
  h0to10->GetXaxis()->SetTitleFont(132);
  h0to10->GetXaxis()->SetTitleSize(0.042);
  h0to10->GetXaxis()->SetLabelSize(0.04);
  h0to10->SetLineWidth(2);

  TCut mu("num_gen_muons==1&&muon_reco_match>=0");
  /*
  chain->Project("h0to10", "gen_mu1.reco_relIso", mu+"num_primary_vertices<=10");
  chain->Project("h10to15", "gen_mu1.reco_relIso", mu+"num_primary_vertices>10&&num_primary_vertices<=15");
  chain->Project("h15to20", "gen_mu1.reco_relIso", mu+"num_primary_vertices>15&&num_primary_vertices<=20");
  chain->Project("h20to25", "gen_mu1.reco_relIso", mu+"num_primary_vertices>20&&num_primary_vertices<=25");
  chain->Project("h25to40", "muon_relIso", mu+"num_primary_vertices>25");
  */
  
    chain->Project("h0to10", "muon_relIso", mu+"num_primary_vertices<=13");
    chain->Project("h10to15", "muon_relIso", mu+"num_primary_vertices>13&&num_primary_vertices<=17");
    chain->Project("h15to20", "muon_relIso", mu+"num_primary_vertices>17&&num_primary_vertices<=21");
    chain->Project("h25to40", "muon_relIso", mu+"num_primary_vertices>21");
  

  float avg1(h0to10->GetMean());
  float avg2(h10to15->GetMean());
  float avg3(h15to20->GetMean());
  float avg4(h20to25->GetMean());
  float avg5(h25to40->GetMean());

  h0to10->Scale(1/h0to10->Integral());
  h10to15->Scale(1/h10to15->Integral());
  h15to20->Scale(1/h15to20->Integral());
  h20to25->Scale(1/h20to25->Integral());
  h25to40->Scale(1/h25to40->Integral());

  h0to10->SetLineColor(1);
  h10to15->SetLineColor(2);
  h15to20->SetLineColor(3);
  h20to25->SetLineColor(4);
  h25to40->SetLineColor(6);

  h0to10->SetLineWidth(2);
  h10to15->SetLineWidth(2);
  h15to20->SetLineWidth(2);
  h20to25->SetLineWidth(2);
  h25to40->SetLineWidth(2);

  TCanvas* c1 = new TCanvas();
  float max = TMath::Max(h0to10->GetMaximum(), h10to15->GetMaximum());
  if (h15to20->GetMaximum()>max) max = h15to20->GetMaximum();
  if (h20to25->GetMaximum()>max) max = h20to25->GetMaximum();
  if (h25to40->GetMaximum()>max) max = h25to40->GetMaximum();

  h0to10->SetMaximum(max*1.1);
  h0to10->Draw("hist");
  h10to15->Draw("hist,same");
  h15to20->Draw("hist,same");
  h20to25->Draw("hist,same");
  h25to40->Draw("hist,same");

  TLegend* leg = new TLegend(0.50,0.6,0.9,0.9);
  char label[1000];
  sprintf(label,"0>NPV#leq13 (#mu=%3.2f)",avg1);
  leg->AddEntry(h0to10,label,"l");
  sprintf(label,"13<NPV#leq17 (#mu=%3.2f)",avg2);
  leg->AddEntry(h10to15,label,"l");
  sprintf(label,"17<NPV#leq21 (#mu=%3.2f)",avg3);
  leg->AddEntry(h15to20,label,"l");
  //sprintf(label,"20<NPV#leq25 (#mu=%3.2f)",avg4);
  //leg->AddEntry(h20to25,label,"l");
  sprintf(label,"NPV>21 (#mu=%3.2f)",avg5);
  leg->AddEntry(h25to40,label,"l");
  leg->Draw();

  TString plotTitle ="relIso_vs_NPV"+comments+".pdf";
  c1->Print(plotTitle);
}