Exemple #1
0
TCanvas* drawFish(TTree *&tree, TString selection = "PID>1000",
				  TString digidata = "", int layout = 3,
				  double maxz = -2, double minz = -2)
{   // assign mcpid and pixid from the hits tree
	int mcpid(0), pixid(0);
	tree->SetBranchAddress("mcp",&mcpid);
	tree->SetBranchAddress("pix",&pixid);
    
	// entry by entry selection
	TTreeFormula* tform 
		= new TTreeFormula("tree selection",selection.Data(),tree);

	// initialize pad and color scale from prttools
	initDigi();
	SetRootPalette(1);
	int entries = tree->GetEntries();
	cout << "selection: " << selection << endl;
	cout << "entries in tree: " << entries << endl;
	for (int i_entry=0; i_entry<entries; i_entry++)
	{
		tree->GetEntry(i_entry);
		//cout << "entry " << i_entry << endl;
		//cout << "\tmcp: " << mcpid << endl;
		//cout << "\tpix: " << pixid << endl;

		if(tform->EvalInstance())
			fhDigi[mcpid]->Fill(pixid%8, pixid/8);
	}

	drawDigi("m,p,v\n",3,-2,-2);
	cDigi->cd();
	(new TPaletteAxis(0.90,0.1,0.94,0.90,fhDigi[14]))->Draw();

	return cDigi;
}
void GetBeamInformation(int runNumber) {
 TTree* tree = (TTree*) _file0->Get("t1041");
 
 TTreeFormula* momentum = new TTreeFormula("momentum","tbspill.GetMomentum()",tree);
 
 tree->GetEntry(0);
 float value_momentum = momentum->EvalInstance();

 std::cout << " momentum = " << value_momentum << std::endl;
 
 ofstream myfile;
 myfile.open ("runNumber_momentum.txt",  std::ofstream::app);
 myfile << runNumber << "   " <<  value_momentum << std::endl;
 myfile.close(); 
 
}
Exemple #3
0
void applyenergy() {

  ROOT::Cintex::Cintex::Enable();   

  
  //printf("include: %s\n",gSystem->GetIncludePath());
  //return;
  
  Long64_t maxentries = -1;
  
  


  //TFile *fmc = new TFile("/home/bendavid/cms/hist/hgg-v0-Sept1/local/filefi/merged/hgg-v0_s11-h120gg-gf-v11-pu_noskim.root","READ");
  //TFile *fmc = new TFile("/scratch/bendavid/cms/hist/hgg-v0/merged/hgg-v0_f11--h121gg-gf-v14b-pu_noskim.root","READ");
  TFile *fmc = new TFile("/scratch/bendavid/cms/hist/hgg-v0/merged/hgg-v0_f11-zjets-v14b-pu_noskim.root","READ");  
  //TFile *fmc = new TFile("/scratch/bendavid/cms/hist/hgg-v0/t2mit/filefi/025/f11--h121gg-gf-v14b-pu/hgg-v0_f11--h121gg-gf-v14b-pu_noskim_0000.root","READ");
  TDirectory *dir = (TDirectory*)fmc->FindObjectAny("PhotonTreeWriterPresel");
  TTree *hmcph = (TTree*)dir->Get("hPhotonTree");

  TDirectory *dirsingle = (TDirectory*)fmc->FindObjectAny("PhotonTreeWriterSingle");
  TTree *hmcsingleph = (TTree*)dirsingle->Get("hPhotonTree");

  TFile *fmcele = new TFile("/scratch/bendavid/cms/hist/hgg-v0/merged/hgg-v0_f11-zjets-v14b-pu_noskim.root","READ");  
  TDirectory *direle = (TDirectory*)fmcele->FindObjectAny("PhotonTreeWriterE");
  TTree *hmcele = (TTree*)direle->Get("hPhotonTree");
  TDirectory *direlesingle = (TDirectory*)fmcele->FindObjectAny("PhotonTreeWriterE");
  TTree *hmcelesingle = (TTree*)direlesingle->Get("hPhotonTreeSingle");

  
  TFile *fdele = new TFile("/scratch/bendavid/cms/hist/hgg-v0/MergedDel2011J16.root","READ");  
  TDirectory *dirdele = (TDirectory*)fdele->FindObjectAny("PhotonTreeWriterE");
  TTree *hdele = (TTree*)dirdele->Get("hPhotonTree");  
  TDirectory *dirdelesingle = (TDirectory*)fdele->FindObjectAny("PhotonTreeWriterE");
  TTree *hdelesingle = (TTree*)dirdelesingle->Get("hPhotonTreeSingle");  
  
  TFile *fgbropt = new TFile("fgbrtraintest.root","READ");
  const GBRForest *gbropt = (GBRForest*)fgbropt->Get("gbrtrain");      
  
  std::vector<std::string> *varlist = (std::vector<std::string>*)fgbropt->Get("varlist");

  
  std::vector<std::string> *varlisteb = varlist;
  std::vector<std::string> *varlistee = varlist;
  
  const GBRForest *gbr = 0;
  const GBRForest *gbreb = gbropt;
  const GBRForest *gbree = gbropt;
  
  UInt_t nvarseb = varlisteb->size();
  UInt_t nvarsee = varlistee->size();
  
  Float_t *vals = 0;
  
  Float_t *valseb = new Float_t[nvarseb];
  Float_t *valsee = new Float_t[nvarsee];
 
  
  TFile *fmvacor = new TFile("fmvacor.root","RECREATE");
  
  TTree *hmvacorph = new TTree("hmvacorph","");
  TTree *hmvacorele = new TTree("hmvacorele","");
  TTree *hmvacorelesingle = new TTree("hmvacorelesingle","");

  TTree *hmvacordele = new TTree("hmvacordele","");
  TTree *hmvacordelesingle = new TTree("hmvacordelesingle","");
  
  TTree *hmvacorqcdsingle = new TTree("hmvacorqcdsingle","");
  
  hmvacorele->SetAutoFlush(-1000000000);
  hmvacorelesingle->SetAutoFlush(-1000000000);

  hmvacordele->SetAutoFlush(-1000000000);
  hmvacordelesingle->SetAutoFlush(-1000000000);  
  
  
  Float_t massmvacor=0.;
  Float_t massmvacorerr=0.;
  Float_t massmvacorerrlo=0.;
  Float_t massmvacorerrhi=0.;
  Float_t ph1emvacor=0.;
  Float_t ph1emvacorerr=0.;
  Float_t ph1emvacorerrlo=0.;
  Float_t ph1emvacorerrhi=0.;
  Float_t ph1bdt = 0.;
  Float_t ph1bdtvar = 0.;
  Int_t   ph1dcoridx=0;
  Float_t ph1emvadcor=0.;
  Float_t ph2emvacor=0.;
  Float_t ph2emvacorerr=0.;
  Float_t ph2emvacorerrlo=0.;
  Float_t ph2emvacorerrhi=0.;
  Float_t ph2bdt = 0.;
  Float_t ph2bdtvar = 0.;
  Int_t   ph2dcoridx=0;
  Float_t ph2emvadcor=0.;  
  
  Float_t phemvacor=0.;
  Float_t phemvacorerr=0.;
  Float_t phbdt=0.;
  Float_t phbdtvar=0.;
  Int_t phdcoridx = 0;
  Float_t phemvadcor=0;
  
  Float_t phregtarget = 0.;
 
  for (UInt_t isample=1; isample<3; ++isample) {
    TTree *hmc = 0;
    TTree *hmvacor = 0;
    TTree *hmcsingle = 0;
    TTree *hmvacorsingle = 0;
    if (isample==0) {
      hmc = hmcph;
      hmvacor = hmvacorph;
      //hmcsingle = hmcqcdsingle;
      //hmvacorsingle = hmvacorqcdsingle;
    }
    else if (isample==1) {
      hmc = hmcele;
      hmvacor = hmvacorele;
      hmcsingle = hmcelesingle;
      hmvacorsingle = hmvacorelesingle;
    }    
    else if (isample==2) {
      hmc = hdele;
      hmvacor = hmvacordele;
      
      hmcsingle = hdelesingle;
      hmvacorsingle = hmvacordelesingle;
      
    } 

//     std::vector<TTreeFormula*> forms1;
//     std::vector<TTreeFormula*> forms2;
//     std::vector<TTreeFormula*> formssingle;
    TTreeFormula **formseb1 = new TTreeFormula*[nvarseb];
    TTreeFormula **formseb2 = new TTreeFormula*[nvarseb];
    TTreeFormula **formsebsingle = new TTreeFormula*[nvarseb];
    for (UInt_t ivar=0; ivar<varlisteb->size(); ++ivar) {
      TString expression = varlisteb->at(ivar);      
      expression.ReplaceAll("ph.genz","vtxZ");
      TString expr1(expression);
      expr1.ReplaceAll("ph.","ph1.");
      TString expr2(expression);
      expr2.ReplaceAll("ph.","ph2.");
      printf("expr = %s, expr1 = %s, expr2 = %s\n",expression.Data(),expr1.Data(),expr2.Data());
      formseb1[ivar] = new TTreeFormula(expr1,expr1,hmc);
      formseb2[ivar] = new TTreeFormula(expr2,expr2,hmc);
      if (hmcsingle) formsebsingle[ivar] = new TTreeFormula(expression,expression,hmcsingle);
    }

    TTreeFormula **formsee1 = new TTreeFormula*[nvarsee];
    TTreeFormula **formsee2 = new TTreeFormula*[nvarsee];
    TTreeFormula **formseesingle = new TTreeFormula*[nvarsee];
    for (UInt_t ivar=0; ivar<varlistee->size(); ++ivar) {
      TString expression = varlistee->at(ivar);    
      expression.ReplaceAll("ph.genz","vtxZ");      
      if (expression=="(1.0-(!ismc)*0.072)*ph.scpse/ph.scrawe") expression = "ph.scpse/ph.scrawe";
      TString expr1(expression);
      expr1.ReplaceAll("ph.","ph1.");
      TString expr2(expression);
      expr2.ReplaceAll("ph.","ph2.");
      printf("expr = %s, expr1 = %s, expr2 = %s\n",expression.Data(),expr1.Data(),expr2.Data());
      formsee1[ivar] = new TTreeFormula(expr1,expr1,hmc);
      formsee2[ivar] = new TTreeFormula(expr2,expr2,hmc);
      if (hmcsingle) formseesingle[ivar] = new TTreeFormula(expression,expression,hmcsingle);
    }
    
    TString denebexpr1 = "ph1.scrawe";
    TString denebexpr2 = "ph2.scrawe";
    TString denebexprsingle = "ph.scrawe";
    TTreeFormula *denebform1 = new TTreeFormula(denebexpr1,denebexpr1,hmc);
    TTreeFormula *denebform2 = new TTreeFormula(denebexpr2,denebexpr2,hmc);
    TTreeFormula *denebformsingle = 0;
    if (hmcsingle) denebformsingle = new TTreeFormula(denebexprsingle,denebexprsingle,hmcsingle);

//     TString deneeexpr1 = "ph1.scrawe + (1.0-(!ismc)*0.072)*ph1.scpse";
//     TString deneeexpr2 = "ph2.scrawe + (1.0-(!ismc)*0.072)*ph2.scpse";
   
    TString deneeexpr1 = "ph1.scrawe + ph1.scpse";
    TString deneeexpr2 = "ph2.scrawe + ph2.scpse";   
    
    TString deneeexprsingle = "ph.scrawe + ph.scpse";
    TTreeFormula *deneeform1 = new TTreeFormula(deneeexpr1,deneeexpr1,hmc);
    TTreeFormula *deneeform2 = new TTreeFormula(deneeexpr2,deneeexpr2,hmc);
    TTreeFormula *deneeformsingle = 0;
    if (hmcsingle) deneeformsingle = new TTreeFormula(deneeexprsingle,deneeexprsingle,hmcsingle);    
    
    TTreeFormula *costhetaform = new TTreeFormula("costheta","costheta",hmc);

    TString isbexpr1 = "ph1.isbarrel";
    TString isbexpr2 = "ph2.isbarrel";
    TString isbexprsingle = "ph.isbarrel";
    TTreeFormula *isbform1 = new TTreeFormula(isbexpr1,isbexpr1,hmc);
    TTreeFormula *isbform2 = new TTreeFormula(isbexpr2,isbexpr2,hmc);
    TTreeFormula *isbformsingle = 0;
    if (hmcsingle) isbformsingle = new TTreeFormula(isbexprsingle,isbexprsingle,hmcsingle);    
    
    hmvacor->Branch("massmvacor",&massmvacor,"massmvacor/F");
    hmvacor->Branch("massmvacorerr",&massmvacorerr,"massmvacorerr/F");
    //hmvacor->Branch("massmvacorerrlo",&massmvacorerrlo,"massmvacorerrlo/F");
    //hmvacor->Branch("massmvacorerrhi",&massmvacorerrhi,"massmvacorerrhi/F");
    
    hmvacor->Branch("ph1.emvacor",&ph1emvacor,"ph1.emvacor/F");
    hmvacor->Branch("ph1.emvacorerr",&ph1emvacorerr,"ph1.emvacorerr/F");
    hmvacor->Branch("ph1.bdt",&ph1bdt,"ph1.bdt/F");
    hmvacor->Branch("ph1.bdtvar",&ph1bdtvar,"ph1.bdtvar/F");    
    hmvacor->Branch("ph1.dcoridx",&ph1dcoridx,"ph1.dcoridx/I"); 
    hmvacor->Branch("ph1.emvadcor",&ph1emvadcor,"ph1.emvadcor/F");    
    
    //hmvacor->Branch("ph1.emvacorerrlo",&ph1emvacorerrlo,"ph1.emvacorerrlo/F");
    //hmvacor->Branch("ph1.emvacorerrhi",&ph1emvacorerrhi,"ph1.emvacorerrhi/F");
    hmvacor->Branch("ph2.emvacor",&ph2emvacor,"ph2.emvacor/F");
    hmvacor->Branch("ph2.emvacorerr",&ph2emvacorerr,"ph2.emvacorerr/F");  
    hmvacor->Branch("ph2.bdt",&ph2bdt,"ph2.bdt/F");
    hmvacor->Branch("ph2.bdtvar",&ph2bdtvar,"ph2.bdtvar/F");    
    hmvacor->Branch("ph2.dcoridx",&ph2dcoridx,"ph2.dcoridx/I");    
    hmvacor->Branch("ph2.emvadcor",&ph2emvadcor,"ph2.emvadcor/F");    
    
    
    //hmvacor->Branch("ph2.emvacorerrlo",&ph2emvacorerrlo,"ph2.emvacorerrlo/F");
    //hmvacor->Branch("ph2.emvacorerrhi",&ph2emvacorerrhi,"ph2.emvacorerrhi/F");
    
    if (hmvacorsingle) {
      hmvacorsingle->Branch("ph.emvacor",&phemvacor,"ph.emvacor/F");
      hmvacorsingle->Branch("ph.emvacorerr",&phemvacorerr,"ph.emvacorerr/F");
      hmvacorsingle->Branch("ph.dcoridx",&phdcoridx,"ph.dcoridx/I");    
      hmvacorsingle->Branch("ph.emvadcor",&phemvadcor,"ph.emvadcor/F");            
      //hmvacor->Branch("ph.bdt",&ph1bdt,"ph.bdt/F");
      //hmvacor->Branch("ph.bdtvar",&ph1bdtvar,"ph.bdtvar/F");      
    }
    
    //TString method = "MLP method";
    //TString method = "BDT method";
    TString method = "BDTG method";
    //TString method = "PDEFoam method";
    
    for (Long64_t i=0; i<hmc->GetEntries(); ++i) {
      hmc->LoadTree(i);

      float den1, den2;
      
      bool isb1 = isbform1->EvalInstance();
      bool isb2 = isbform2->EvalInstance();

      if (isb1) {
        gbr = gbreb;
        //gbrvar = gbrvareb;
        //gbrdcor = gbrdcoreb;
        vals = valseb;
        den1 = denebform1->EvalInstance();
        for (UInt_t ivar=0; ivar<nvarseb; ++ivar) {
          valseb[ivar] = formseb1[ivar]->EvalInstance();
        }        
      }
      else {
        gbr = gbree;
        //gbrvar = gbrvaree;
        //gbrdcor = gbrdcoree;
        vals = valsee;
        den1 = deneeform1->EvalInstance();
        for (UInt_t ivar=0; ivar<nvarsee; ++ivar) {
          valsee[ivar] = formsee1[ivar]->EvalInstance();
        }              
      }
      

      phregtarget = gbr->GetResponse(vals);     
      ph1emvacor = phregtarget*den1;

      //printf("phregtarget = %5f, ph1emvacor = %5f\n",phregtarget,ph1emvacor);
      
      
      if (isb2) {
        gbr = gbreb;
        vals = valseb;        
        den2 = denebform2->EvalInstance();
        for (UInt_t ivar=0; ivar<nvarseb; ++ivar) {
          valseb[ivar] = formseb2[ivar]->EvalInstance();
        }        
      }
      else {
        gbr = gbree;
        vals = valsee;        
        den2 = deneeform2->EvalInstance();
        for (UInt_t ivar=0; ivar<nvarsee; ++ivar) {
          valsee[ivar] = formsee2[ivar]->EvalInstance();
        }              
      }

      phregtarget = gbr->GetResponse(vals);      
      ph2emvacor = phregtarget*den2;

      

      
      massmvacor = TMath::Sqrt(2.0*ph1emvacor*ph2emvacor*(1.0-costhetaform->EvalInstance()));
      //massmvacorerr = 0.5*massmvacor*TMath::Sqrt(ph1emvacorerr*ph1emvacorerr/ph1emvacor/ph1emvacor + ph2emvacorerr*ph2emvacorerr/ph2emvacor/ph2emvacor);
      //massmvacorerrlo = 0.5*massmvacor*TMath::Sqrt(ph1emvacorerrlo*ph1emvacorerrlo/ph1emvacor/ph1emvacor + ph2emvacorerrlo*ph2emvacorerrlo/ph2emvacor/ph2emvacor);
      //massmvacorerrhi = 0.5*massmvacor*TMath::Sqrt(ph1emvacorerrhi*ph1emvacorerrhi/ph1emvacor/ph1emvacor + ph2emvacorerrhi*ph2emvacorerrhi/ph2emvacor/ph2emvacor);
        
      hmvacor->Fill();
      
    }
    hmc->AddFriend(hmvacor);
    hmvacor->Write();
    
    if (hmcsingle) {
      for (Long64_t i=0; i<hmcsingle->GetEntries(); ++i) {
        hmcsingle->LoadTree(i);

        float den;
        bool isbsingle = isbformsingle->EvalInstance();

        if (isbsingle) {
          gbr = gbreb;
          vals = valseb;          
          den = denebformsingle->EvalInstance();
          for (UInt_t ivar=0; ivar<nvarseb; ++ivar) {
            valseb[ivar] = formsebsingle[ivar]->EvalInstance();
          }        
        }
        else {
          gbr = gbree;
          vals = valsee;          
          den = deneeformsingle->EvalInstance();
          for (UInt_t ivar=0; ivar<nvarsee; ++ivar) {
            valsee[ivar] = formseesingle[ivar]->EvalInstance();
          }              
        }

        phregtarget = gbr->GetResponse(vals);     
        phemvacor = phregtarget*den;

        
        hmvacorsingle->Fill();
        
      }
      hmcsingle->AddFriend(hmvacorsingle);
      hmvacorsingle->Write();      
      
    }
    
  }
  
  
  
  
  
//   
}
void SkimClassification(TString process="ZnnH125")
{
    gROOT->LoadMacro("HelperFunctions.h" );  // make functions visible to TTreeFormula
    gROOT->SetBatch(1);

    //TChain * chain  = new TChain("tree");
    //TString fname   = "";
    //TString dijet   = "DiJetPt_";
    //TString dirMC   = "dcache:/pnfs/cms/WAX/resilient/jiafu/ZnunuHbb/" + tagMC + "/";
    //TString dirData = "dcache:/pnfs/cms/WAX/resilient/jiafu/ZnunuHbb/" + tagData + "/";
    TString indir   = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Spring15_PU20bx25/skimV12_v2/step3/";
    TString outdir  = "/afs/cern.ch/work/d/degrutto/public/MiniAOD/ZnnHbb_Spring15_PU20bx25/skimV12_v2/step3/skim_ZnnH_classification/";
    TString prefix  = "Step3_";
    TString suffix  = ".root";

    TFile *input = TFile::Open(indir + prefix + process + suffix);
    if (!input) {
        std::cout << "ERROR: Could not open input file." << std::endl;
        exit(1);
    }
    TTree *tree   = (TTree *) input->Get("tree");
    Long64_t entries = tree->GetEntriesFast();
    
    // Make output directory if it doesn't exist
    if (gSystem->AccessPathName(outdir))
        gSystem->mkdir(outdir);
    TString outname = outdir + prefix + Form("%s.root", process.Data());

    TFile* output = TFile::Open(outname, "RECREATE");

    // Get selections
    const std::vector < std::string > & selExpressions = GetSelExpressions("ZnunuHighPt") ;
    //    const UInt_t nsels = 3;  // ZnunuHighPt, ZnunuLowPt, ZnunuLowCSV
    const UInt_t nsels = 1;  // just one now...  ZnunuHighPt, ZnunuLowPt, ZnunuLowCSV

    //    assert(nsels == selExpressions.size()); <-- fixME
    // even-number events for training, odd-number events for testing
    TCut evenselection = "evt  %2 == 0";
    TCut oddselection  = "evt %2 == 1";

    TTreeFormula *ttf = 0;
    std::vector < TTreeFormula * >::const_iterator formIt, formItEnd;

    // Loop over selections
    std::vector<Long64_t> ventries;
    for (unsigned int i = 0; i < nsels; i++) {
        TString selname = "ZnunuHighPt";
        if (i == 1) {
            selname = "ZnunuMedPt";
	    //	    selExpressions = GetSelExpressions("ZnunuMedPt") ;
        } else if (i == 2) {
            selname = "ZnunuLowPt";
	    // selExpressions = GetSelExpressions("ZnunuLowPt") ;
        }

        TTree *t1 = (TTree*) tree->CloneTree(0);
        TTree *t2 = (TTree*) tree->CloneTree(0);
        
        t1->SetName(TString::Format("%s_%s_train", tree->GetName(), selname.Data()));
        t2->SetName(TString::Format("%s_%s", tree->GetName(), selname.Data()));
        
        // The clones should not delete any shared i/o buffers.
        ResetDeleteBranches(t1);
        ResetDeleteBranches(t2);
        
        ttf = new TTreeFormula(Form("ttfsel%i", i), selExpressions.at(i).c_str(), tree);
        ttf->SetQuickLoad(1);
        TTreeFormula *ttf1 = new TTreeFormula(Form("ttfeven%i", i), evenselection, tree);
        ttf1->SetQuickLoad(1);
        TTreeFormula *ttf2 = new TTreeFormula(Form("ttfodd%i", i), oddselection, tree);
        ttf2->SetQuickLoad(1);
        if (!ttf || !ttf->GetNdim()) {
            std::cerr << "ERROR: Failed to find any TTree variable from the selection: " << selExpressions.at(i) << std::endl;
            return;
        }

        
        /// Loop over events
        Int_t curTree = tree->GetTreeNumber();
        const Long64_t nentries = tree->GetEntries();
        for (Long64_t ievt = 0; ievt < nentries; ievt++) {
            Long64_t entryNumber = tree->GetEntryNumber(ievt);
            if (entryNumber < 0)  break;
            Long64_t localEntry = tree->LoadTree(entryNumber);
            if (localEntry < 0)  break;
            if (tree->GetTreeNumber() != curTree) {
                curTree = tree->GetTreeNumber();
                ttf ->UpdateFormulaLeaves();  // if using TChain
                ttf1->UpdateFormulaLeaves();  // if using TChain
                ttf2->UpdateFormulaLeaves();  // if using TChain
            }
            
            const Int_t ndata = ttf->GetNdata();
            Bool_t keep = kFALSE;
            for(Int_t current = 0; current<ndata && !keep; current++) {
                keep |= (bool(ttf->EvalInstance(current)) != 0);
            }
            if (!keep)  continue;


            bool even  = (bool) ttf1->EvalInstance();
            bool odd   = (bool) ttf2->EvalInstance();
            if (even && odd) {
                std::cerr << "ERROR: An event cannot be even and odd at the same time." << std::cout;
                return;
            }

            tree->GetEntry(entryNumber, 1);  // get all branches
            if (even) {
                t1->Fill();
            } else {
                t2->Fill();
            }
        }  // end loop over events

        t1->Write();
        t2->Write();
        
        ventries.push_back(t1->GetEntriesFast() + t2->GetEntriesFast());
        
        delete ttf;
        delete ttf1;
        delete ttf2;
    }
    
    std::clog << process << ": skimmed from " << entries << " to " << ventries[0] << " (ZnunuHighPt), " << ventries[1] << " (ZnunuLowPt), " << ventries[2] << " (ZnunuLowCSV) " << " entries." << std::endl;

    output->Close();
    input->Close();

    delete output;
    delete input;

    return;
}
Exemple #5
0
void GetOptimization() {
  struct path thisPath;
  std::vector<path> paths;
  std::vector<TString> pathNames;
  struct filter thisFilter;
  std::vector<filter> filters;
  std::vector<std::pair<std::vector<TString>,Double_t> > xSections;
  std::vector<TString> filenamesBkg;
  std::vector<TString> filenamesSig;
  /* Parameters */
  Int_t nCuts = 120;
  Bool_t doBandE = true; // if true, do seperate for cuts in barrel and endcap

  Double_t luminosity = 2.0E33; // in cm^-2 s^-1

  // Cross-sections in mb
  filenamesBkg.push_back("../test/QCD-HLTVars-1.root");
  // filenamesBkg.push_back("sameXSection");
  xSections.push_back(make_pair(filenamesBkg, 2.16E-2));
  filenamesBkg.clear();
  // filenamesBkg.push_back("newXSection.root");
  // ...
  // xSections.push_back(make_pair(filenamesBkg, xSection));
  // filenamesBkg.clear();
  filenamesSig.push_back("../test/ZEE-HLTVars.root");
  /* ********** */
  // Filters
  thisFilter.name = "l1Match";
  thisFilter.pathNum = 0;
  thisFilter.direction =  0;
  thisFilter.hltBarrelCut = 0.;
  thisFilter.hltEndcapCut = 0.;
  thisFilter.maxCut = 0.;
  filters.push_back(thisFilter);
  thisFilter.name = "Et";
  thisFilter.pathNum = 0;
  thisFilter.direction = 1;
  thisFilter.hltBarrelCut = 15.;
  thisFilter.hltEndcapCut = 15.;
  thisFilter.maxCut = 60.;
  filters.push_back(thisFilter);
  thisFilter.name = "IHcal";
  thisFilter.pathNum = 0;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 3.;
  thisFilter.hltEndcapCut = 3.;
  thisFilter.maxCut = 6.;
  filters.push_back(thisFilter);
  thisFilter.name = "pixMatch";
  thisFilter.pathNum = 0;
  thisFilter.direction = 1;
  thisFilter.hltBarrelCut = 0;
  thisFilter.hltEndcapCut = 0;
  thisFilter.maxCut = 0;
  filters.push_back(thisFilter);
  thisFilter.name = "Eoverp";
  thisFilter.pathNum = 1;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 1.5;
  thisFilter.hltEndcapCut = 2.45;
  thisFilter.maxCut = 5.;
  filters.push_back(thisFilter);
  thisFilter.name = "Itrack";
  thisFilter.pathNum = 1;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 0.06;
  thisFilter.hltEndcapCut = 0.06;
  thisFilter.maxCut = 0.24;
  filters.push_back(thisFilter);
  pathNames.push_back("SingleElecsPT.");
  pathNames.push_back("SingleElecs.");
  thisPath.names = pathNames;
  thisPath.nCandsCut = 1;
  thisPath.filters = filters;
  paths.push_back(thisPath);
  pathNames.clear(); 
  pathNames.push_back("RelaxedSingleElecsPT.");
  pathNames.push_back("RelaxedSingleElecs.");
  thisPath.names = pathNames;
  thisPath.nCandsCut = 1;
  thisPath.filters = filters;
  paths.push_back(thisPath);
  pathNames.clear();
  filters.clear();

  thisFilter.name = "l1Match";
  thisFilter.pathNum = 0;
  thisFilter.direction =  0;
  thisFilter.hltBarrelCut = 0.;
  thisFilter.hltEndcapCut = 0.;
  thisFilter.maxCut = 0.;
  filters.push_back(thisFilter);
  thisFilter.name = "Et";
  thisFilter.pathNum = 0;
  thisFilter.direction = 1;
  thisFilter.hltBarrelCut = 10.;
  thisFilter.hltEndcapCut = 10.;
  thisFilter.maxCut = 40.;
  filters.push_back(thisFilter);
  thisFilter.name = "IHcal";
  thisFilter.pathNum = 0;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 9.;
  thisFilter.hltEndcapCut = 9.;
  thisFilter.maxCut = 18.;
  filters.push_back(thisFilter);
  thisFilter.name = "pixMatch";
  thisFilter.pathNum = 0;
  thisFilter.direction = 1;
  thisFilter.hltBarrelCut = 0;
  thisFilter.hltEndcapCut = 0;
  thisFilter.maxCut = 0;
  filters.push_back(thisFilter);
  thisFilter.name = "Eoverp";
  thisFilter.pathNum = 1;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 15000;
  thisFilter.hltEndcapCut = 24500;
  thisFilter.maxCut = 5.;
  filters.push_back(thisFilter);
  thisFilter.name = "Itrack";
  thisFilter.pathNum = 1;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 0.4;
  thisFilter.hltEndcapCut = 0.4;
  thisFilter.maxCut = 0.12;
  filters.push_back(thisFilter);
  pathNames.push_back("DoubleElecsPT.");
  pathNames.push_back("DoubleElecs.");
  thisPath.names = pathNames;
  thisPath.nCandsCut = 2;
  thisPath.filters = filters;
  paths.push_back(thisPath);
  pathNames.clear(); 
  pathNames.push_back("RelaxedDoubleElecsPT.");
  pathNames.push_back("RelaxedDoubleElecs.");
  thisPath.names = pathNames;
  thisPath.nCandsCut = 2;
  thisPath.filters = filters;
  paths.push_back(thisPath);
  pathNames.clear();
  filters.clear();

  thisFilter.name = "l1Match";
  thisFilter.pathNum = 0;
  thisFilter.direction =  0;
  thisFilter.hltBarrelCut = 0.;
  thisFilter.hltEndcapCut = 0.;
  thisFilter.maxCut = 0.;
  filters.push_back(thisFilter);
  thisFilter.name = "Et";
  thisFilter.pathNum = 0;
  thisFilter.direction = 1;
  thisFilter.hltBarrelCut = 30.;
  thisFilter.hltEndcapCut = 30.;
  thisFilter.maxCut = 60.;
  filters.push_back(thisFilter);
  thisFilter.name = "IEcal";
  thisFilter.pathNum = 0;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 1.5;
  thisFilter.hltEndcapCut = 1.5;
  thisFilter.maxCut = 6.;
  filters.push_back(thisFilter);
  thisFilter.name = "IHcal";
  thisFilter.pathNum = 0;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 4.;
  thisFilter.hltEndcapCut = 6.;
  thisFilter.maxCut = 12.;
  filters.push_back(thisFilter);
  thisFilter.name = "Itrack";
  thisFilter.pathNum = 0;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 1;
  thisFilter.hltEndcapCut = 1;
  thisFilter.maxCut = 5;
  filters.push_back(thisFilter);
  pathNames.push_back("SinglePhots.");
  thisPath.names = pathNames;
  thisPath.nCandsCut = 1;
  thisPath.filters = filters;
  paths.push_back(thisPath);
  pathNames.clear(); 
  pathNames.push_back("RelaxedSinglePhots.");
  thisPath.names = pathNames;
  thisPath.nCandsCut = 1;
  thisPath.filters = filters;
  paths.push_back(thisPath);
  pathNames.clear();
  filters.clear();

  thisFilter.name = "l1Match";
  thisFilter.pathNum = 0;
  thisFilter.direction =  0;
  thisFilter.hltBarrelCut = 0.;
  thisFilter.hltEndcapCut = 0.;
  thisFilter.maxCut = 0.;
  filters.push_back(thisFilter);
  thisFilter.name = "Et";
  thisFilter.pathNum = 0;
  thisFilter.direction = 1;
  thisFilter.hltBarrelCut = 20.;
  thisFilter.hltEndcapCut = 20.;
  thisFilter.maxCut = 40.;
  filters.push_back(thisFilter);
  thisFilter.name = "IEcal";
  thisFilter.pathNum = 0;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 2.5;
  thisFilter.hltEndcapCut = 2.5;
  thisFilter.maxCut = 5.;
  filters.push_back(thisFilter);
  thisFilter.name = "IHcal";
  thisFilter.pathNum = 0;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 6.;
  thisFilter.hltEndcapCut = 8.;
  thisFilter.maxCut = 24.;
  filters.push_back(thisFilter);
  thisFilter.name = "Itrack";
  thisFilter.pathNum = 0;
  thisFilter.direction = -1;
  thisFilter.hltBarrelCut = 3;
  thisFilter.hltEndcapCut = 3;
  thisFilter.maxCut = 6;
  filters.push_back(thisFilter);
  pathNames.push_back("DoublePhots.");
  thisPath.names = pathNames;
  thisPath.nCandsCut = 2;
  thisPath.filters = filters;
  paths.push_back(thisPath);
  pathNames.clear(); 
  pathNames.push_back("RelaxedDoublePhots.");
  thisPath.names = pathNames;
  thisPath.nCandsCut = 2;
  thisPath.filters = filters;
  paths.push_back(thisPath);
  pathNames.clear();
  filters.clear();

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

  Int_t cutNum = 0, pathNum = 0, filterNum = 0, oldFilterNum = 0, fileNum = 0, xSecNum = 0;
  Double_t cut = 0.;
  Long64_t passSig = 0, totalSig = 0;
  Long64_t passBkg = 0, totalBkg = 0;
  Double_t effSig = 0., errSig = 0.;
  Double_t effBkg = 0., errBkg = 0., rateTotBkg = 0., errTotBkg = 0.;
  Double_t conversion = 1.0E-27;
  std::vector<std::pair<Double_t,Double_t> > sigPass;
  std::vector<std::pair<Double_t,Double_t> > bkgPass;

  TString cutText;
  TString cutTextEcap;
  TString baseCutText;
  TString baseCutTextEcap;
  TString cutBasePT1;
  TString cutBasePT2;
  TString cutBase1;
  TString cutBase2;
  //  cutBasePT1 = "ElecHLTCutVarsPreTracks_hltCutVars_";
  //  cutBasePT2 = "ElecsPT_EGAMMAHLT.obj.";
  //  cutBase1 = "";
  //  cutBase2 = "Elecs_EGAMMAHLT.obj.";

  std::vector<std::vector<TGraphErrors> > EffVBkg;
  std::vector<std::vector<TGraphErrors> > EffVBkgEcap;
  std::vector<TGraphErrors> pathEffVBkgs;
  TGraphErrors filterEffVBkgs(nCuts);
  for (pathNum = 0; pathNum < paths.size(); pathNum++) {
    for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
      //      filterEffVBkgs = new TGraphErrors(nCuts);
      pathEffVBkgs.push_back(filterEffVBkgs);
    }
    EffVBkg.push_back(pathEffVBkgs);
    if (doBandE) {
      EffVBkgEcap.push_back(pathEffVBkgs);
    }
  }

  std::vector<std::pair<TChain*,Double_t> > bkgEvents;
  for (xSecNum = 0; xSecNum < xSections.size(); xSecNum++) {
    TChain *bkgProc = new TChain("Events");
    for (fileNum = 0; fileNum < (xSections[xSecNum].first).size(); fileNum++) {
      bkgProc->Add((xSections[xSecNum].first)[fileNum]);
    }
    bkgEvents.push_back(make_pair(bkgProc,xSections[xSecNum].second));
  }

  TChain *sigEvents = new TChain("Events");
  for (fileNum = 0; fileNum < filenamesSig.size(); fileNum++) {
    sigEvents->Add(filenamesSig[fileNum]);
  }

  Double_t testX, testY, testdX, testdY;
  Double_t thisBCut = 0., thisECut = 0.;
  TString pathName, filterName;
  for (cutNum = 0; cutNum < nCuts; cutNum++) {
    cout<<"Cut "<<cutNum<<endl;
    for (pathNum = 0; pathNum < paths.size(); pathNum++) {
      for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
	if ((paths[pathNum].filters)[filterNum].maxCut != 0.) {
	  cutText = "(Sum$(";
	  for (oldFilterNum = 0; oldFilterNum < filterNum; oldFilterNum++) { 
	    pathName = (paths[pathNum].names)[(paths[pathNum].filters)[filterNum].pathNum];
	    filterName = (paths[pathNum].filters)[oldFilterNum].name;
	    thisBCut = (paths[pathNum].filters)[oldFilterNum].hltBarrelCut;
	    thisECut = (paths[pathNum].filters)[oldFilterNum].hltEndcapCut;
	    if (thisBCut == thisECut) {
  	      cutText += pathName;
	      cutText += filterName;
  	      switch ((paths[pathNum].filters)[oldFilterNum].direction) {
	      case -1:
	        cutText += " < ";
	        cutText += (paths[pathNum].filters)[oldFilterNum].hltBarrelCut;
  	        break;
	      case 0:
	        break;
	      case 1:
	        cutText += " > ";
	        cutText += (paths[pathNum].filters)[oldFilterNum].hltBarrelCut;
	        break;
	      default:
	        cout<<"Invalid value of direction in "<<pathName<<filterName<<endl;
	        break;
	      }
	    }
	    else {
	      cutText += "((";
  	      cutText += pathName;
	      cutText += filterName;
              switch ((paths[pathNum].filters)[oldFilterNum].direction) {
	      case -1:
	        cutText += " < ";
	        cutText += thisBCut;
  	        break;
	      case 0:
	        break;
	      case 1:
	        cutText += " > ";
	        cutText += thisBCut;
	        break;
	      default:
	        cout<<"Invalid value of direction in "<<pathName<<filterName<<endl;
	        break;
	      }
	      cutText += " && abs(";
	      cutText += pathName;
	      cutText += "eta) < 1.5) || (";
	      cutText += pathName;
	      cutText += filterName;
	      switch ((paths[pathNum].filters)[oldFilterNum].direction) {
              case -1:
                cutText += " < ";
                cutText += thisECut;
                break;
              case 0:
                break;
              case 1:
                cutText += " > ";
                cutText += thisECut;
                break;
              default:
                cout<<"Invalid value of direction in "<<pathName<<filterName<<endl;
                break;
              }
	      cutText += " && abs(";
              cutText += pathName;
              cutText += "eta) > 1.5 && abs(";
	      cutText += pathName;
	      cutText += "eta) < 2.5))";
	    }
	    if (oldFilterNum != filterNum - 1) cutText += " && ";
	  }
	  baseCutText = cutText;
	  pathName = paths[pathNum].names[(paths[pathNum].filters)[filterNum].pathNum];
	  filterName = (paths[pathNum].filters)[filterNum].name;
	  cutText += " && ";
	  cutText += pathName;
	  cutText += filterName;
	  cut = (Double_t)cutNum / (Double_t)nCuts * (paths[pathNum].filters)[oldFilterNum].maxCut;
	  switch ((paths[pathNum].filters)[filterNum].direction) {
	  case -1:
	    cutText += " < ";
	    cutText += cut;
	    break;
	  case 0:
	    break;
	  case 1:
	    cutText += " > ";
	    cutText += cut;
	    break;
	  default:
	    cout<<"Invalid value of direction in "<<pathName<<filterName<<endl;
	    break;
	  }
	  if (doBandE) {
	    cutTextEcap = cutText;
	    cutText += " && abs(";
	    cutText += pathName;
	    cutText += "eta) < 1.5";
	    cutTextEcap += " && abs(";
	    cutTextEcap += pathName;
	    cutTextEcap += "eta) > 1.5 && abs(";
	    cutTextEcap += pathName;
	    cutTextEcap += ") < 2.5";
	    baseCutText += " && abs(";
	    baseCutText += pathName;
	    baseCutTextEcap = baseCutText;
	    baseCutText += "eta) < 1.5";
	    baseCutTextEcap += "eta) > 1.5 && abs(";
	    baseCutTextEcap += pathName;
	    baseCutTextEcap += "eta) < 2.5";
	  }
	  cutText += ") >= ";
	  cutText += paths[pathNum].nCandsCut;
	  cutText += ")";
	  cutTextEcap += ") >= ";
	  cutTextEcap += paths[pathNum].nCandsCut;
	  cutTextEcap += ")";
	  baseCutText += ") >= ";
	  baseCutText += paths[pathNum].nCandsCut;
	  baseCutText += ")";
	  baseCutTextEcap += ") >= ";
	  baseCutTextEcap += paths[pathNum].nCandsCut;
	  baseCutTextEcap += ")";
   
	  cout<<cutText<<endl;
	  cout<<cutTextEcap<<endl;
	  //	  cout<<cutText<<endl;
	  //	  cout<<baseCutText<<endl;
	  passSig = sigEvents->Draw("",cutText);
	  totalSig = sigEvents->Draw("",baseCutText);
	  if (totalSig != 0) {
	    effSig = (Double_t)passSig / (Double_t)totalSig;
	    errSig = sqrt(effSig * (1. - effSig) / (Double_t)totalSig);
	  }
	  else {
	    effSig = 0.;
	    errSig = 0.;
	  }
	  rateTotBkg = 0.;
	  errTotBkg = 0.;
	  for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) {
	    passBkg = bkgEvents[xSecNum].first->Draw("",cutText);
	    totalBkg = bkgEvents[xSecNum].first->Draw("","");
	    if (totalBkg != 0) {
	      effBkg = (Double_t)passBkg / (Double_t)totalBkg;
	      errBkg = sqrt(effBkg * (1. - effBkg) / (Double_t)totalBkg);
	    }
	    else {
	      effBkg = 0.;
	      errBkg = 0.;
	    }
	    rateTotBkg += effBkg * bkgEvents[xSecNum].second * luminosity * conversion;
	    errTotBkg = sqrt(errTotBkg * errTotBkg + errBkg * errBkg * bkgEvents[xSecNum].second * luminosity * conversion * bkgEvents[xSecNum].second * luminosity * conversion);
	  }
	    
	  if (cutNum == 6) {
	    cout<<cutText<<endl;
	    cout<<rateTotBkg<<" +- "<<errTotBkg<<", "<<effSig<<" +- "<<errSig<<endl;;
	  }
	  EffVBkg[pathNum][filterNum].SetPoint(cutNum, rateTotBkg, effSig);
	  EffVBkg[pathNum][filterNum].SetPointError(cutNum, errTotBkg, errSig);
	  if (cutNum == 6) {
	    EffVBkg[pathNum][filterNum].GetPoint(cutNum, testX, testY);
	    cout<<testX<<", "<<testY<<endl;
	  }

	  if (doBandE) {
	    passSig = sigEvents->Draw("",cutTextEcap);
	    totalSig = sigEvents->Draw("",baseCutText);
	    if (totalSig != 0) {
	      effSig = (Double_t)passSig / (Double_t)totalSig;
	      errSig = sqrt(effSig * (1. - effSig) / (Double_t)totalSig);
	    }
	    else {
	      effSig = 0.;
	      errSig = 0.;
	    }
	    rateTotBkg = 0.;
	    errTotBkg = 0.;
	    for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) {
	      passBkg = bkgEvents[xSecNum].first->Draw("",cutText);
	      totalBkg = bkgEvents[xSecNum].first->Draw("","");
	      if (totalBkg != 0) {
		effBkg = (Double_t)passBkg / (Double_t)totalBkg;
		errBkg = sqrt(effBkg * (1. - effBkg) / (Double_t)totalBkg);
	      }
	      else {
		effBkg = 0.;
		errBkg = 0.;
	      }
	      rateTotBkg += effBkg * bkgEvents[xSecNum].second * luminosity * conversion;
	      errTotBkg = sqrt(errTotBkg * errTotBkg + errBkg * errBkg * bkgEvents[xSecNum].second * luminosity * conversion * bkgEvents[xSecNum].second * luminosity * conversion);
	    }
	    
	    if (cutNum == 6) {
	      cout<<cutText<<endl;
	      cout<<rateTotBkg<<" +- "<<errTotBkg<<", "<<effSig<<" +- "<<errSig<<endl;;
	    }
	    EffVBkgEcap[pathNum][filterNum].SetPoint(cutNum, rateTotBkg, effSig);
	    EffVBkgEcap[pathNum][filterNum].SetPointError(cutNum, errTotBkg, errSig);
	    if (cutNum == 6) {
	      EffVBkg[pathNum][filterNum].GetPoint(cutNum, testX, testY);
	      cout<<testX<<", "<<testY<<endl;
	    }
	  }
	}
      }
    }
  }
  TCanvas *myCanvas;
  TString tempPathName, canvasTitle, graphTitle, outFilename;
  Int_t n;
  Int_t nGraphs, curGraph;
  for (pathNum = 0; pathNum < paths.size(); pathNum++) {
    canvasTitle = "Efficiency vs. Background for ";
    tempPathName = paths[pathNum].names[paths[pathNum].filters[(paths[pathNum].filters).size()-1].pathNum];
    tempPathName.Resize(tempPathName.Index(".", 1, 0, TString::kExact));
    outFilename = "./images/";
    outFilename += tempPathName;
    outFilename += "EffVBkg.gif";
    n = 0;
    while (tempPathName.Contains(TRegexp("[a-z][A-Z]")) && n < 10) {
      tempPathName.Insert(tempPathName.Index(TRegexp("[a-z][A-Z]"))+1, " ");
      n++;
    }
    canvasTitle += tempPathName;
    nGraphs = 0;
    for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
      if ((paths[pathNum].filters)[filterNum].maxCut != 0) nGraphs++;
    }
    myCanvas = new TCanvas("myCanvas", canvasTitle, 0, 0, 1000, 500*(nGraphs / 2 + 1));
    myCanvas->Divide(2,nGraphs / 2 + 1);
    curGraph = 0;
    for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
      if ((paths[pathNum].filters)[filterNum].maxCut != 0.) {
        myCanvas->cd(curGraph+1);
	curGraph++;
        graphTitle = "Efficiency vs. Background for ";
	graphTitle += (paths[pathNum].filters)[filterNum].name;
	graphTitle += " Filter;Background Rate (Hz);Signal Eff.";
	EffVBkg[pathNum][filterNum].SetTitle(graphTitle);
	EffVBkg[pathNum][filterNum].Draw("AP");
      }
    }
    myCanvas->Print(outFilename);
    if (doBandE) {
      canvasTitle = "Efficiency vs. Background for ";
      tempPathName = paths[pathNum].names[paths[pathNum].filters[(paths[pathNum].filters).size()-1].pathNum];
      tempPathName.Resize(tempPathName.Index(".", 1, 0, TString::kExact));
      tempPathName += "Endcap";
      outFilename = "./images/";
      outFilename += tempPathName;
      outFilename += "EffVBkg.gif";
      n = 0;
      while (tempPathName.Contains(TRegexp("[a-z][A-Z]")) && n < 10) {
	tempPathName.Insert(tempPathName.Index(TRegexp("[a-z][A-Z]"))+1, " ");
	n++;
      }
      canvasTitle += tempPathName;
      nGraphs = 0;
      for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
	if ((paths[pathNum].filters)[filterNum].maxCut != 0) nGraphs++;
      }
      myCanvas = new TCanvas("myCanvas", canvasTitle, 0, 0, 1000, 500*(nGraphs / 2 + 1));
      myCanvas->Divide(2,nGraphs / 2 + 1);
      curGraph = 0;
      for (filterNum = 0; filterNum < (paths[pathNum].filters).size(); filterNum++) {
	if ((paths[pathNum].filters)[filterNum].maxCut != 0.) {
	  myCanvas->cd(curGraph+1);
	  curGraph++;
	  graphTitle = "Efficiency vs. Background for ";
	  graphTitle += (paths[pathNum].filters)[filterNum].name;
	  graphTitle += " Filter in Endcap;Background Rate (Hz);Signal Eff.";
	  EffVBkgEcap[pathNum][filterNum].SetTitle(graphTitle);
	  EffVBkgEcap[pathNum][filterNum].Draw("AP");
	}
      }
      myCanvas->Print(outFilename);
    }
  }

  TH1F *timingSig = new TH1F("timingSig", "Timing of Single Electron Filters in Signal Events", 6, 0, 6);
  timingSig->SetCanExtend(TH1::kAllAxes);
  timingSig->SetStats(0);
  TTreeFormula *l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",sigEvents);
  TTreeFormula *EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",sigEvents);
  TTreeFormula *IHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecIHcal",sigEvents);
  TTreeFormula *pixMatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.pixMatch",sigEvents);
  TTreeFormula *EoverpTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Eoverp",sigEvents);
  TTreeFormula *ItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecItrack",sigEvents);
  Long64_t event = 0;
  Double_t avgL1Match = 0.;
  Double_t avgEt = 0.;
  Double_t avgIHcal = 0.;
  Double_t avgPixMatch = 0.;
  Double_t avgEoverp = 0.;
  Double_t avgItrack = 0.;
  for (event = 0; event < sigEvents->GetEntries(); event++) {
    sigEvents->LoadTree(event);
    avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgIHcal = (event*avgIHcal + IHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgPixMatch = (event*avgPixMatch + pixMatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgEoverp = (event*avgEoverp + EoverpTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgItrack = (event*avgItrack + ItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
  }
  timingSig->Fill("L1 Match", avgL1Match);
  timingSig->Fill("Et", avgEt); 
  timingSig->Fill("IHcal", avgIHcal); 
  timingSig->Fill("Pix Match", avgPixMatch); 
  timingSig->Fill("E/p", avgEoverp); 
  timingSig->Fill("Itrack", avgItrack); 
  timingSig->LabelsDeflate("X");
  timingSig->LabelsOption("v");

  TH1F *timingBkg = new TH1F("timingBkg", "Timing of Single Electron Filters in Background Events", 6, 0, 6);
  timingBkg->SetCanExtend(TH1::kAllAxes);
  timingBkg->SetStats(0);
  avgL1Match = 0.;
  avgEt = 0.;
  avgIHcal = 0.;
  avgPixMatch = 0.;
  avgEoverp = 0.;
  avgItrack = 0.;
  for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) {
    delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",bkgEvents[xSecNum].first);
    delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",bkgEvents[xSecNum].first);
    delete IHcalTiming; IHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecIHcal",bkgEvents[xSecNum].first);
    delete pixMatchTiming; pixMatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.pixMatch",bkgEvents[xSecNum].first);
    delete EoverpTiming; EoverpTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Eoverp",bkgEvents[xSecNum].first);
    delete ItrackTiming; ItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.ElecItrack",bkgEvents[xSecNum].first);
    event = 0;
    for (event = 0; event <  bkgEvents[xSecNum].first->GetEntries(); event++) {
      bkgEvents[xSecNum].first->LoadTree(event);
      avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgIHcal = (event*avgIHcal + IHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgPixMatch = (event*avgPixMatch + pixMatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgEoverp = (event*avgEoverp + EoverpTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgItrack = (event*avgItrack + ItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    }
  }
  timingBkg->Fill("L1 Match", avgL1Match);
  timingBkg->Fill("Et", avgEt); 
  timingBkg->Fill("IHcal", avgIHcal); 
  timingBkg->Fill("Pix Match", avgPixMatch); 
  timingBkg->Fill("E/p", avgEoverp); 
  timingBkg->Fill("Itrack", avgItrack); 
  timingBkg->LabelsDeflate("X");
  timingBkg->LabelsOption("v");

  myCanvas = new TCanvas("myCanvas", "Timing vs. Filter for Isolated Electron Filters", 1000, 500);
  myCanvas->Divide(2,1);
  myCanvas->cd(1);
  timingSig->Draw();
  myCanvas->cd(2);
  timingBkg->Draw();
  myCanvas->Print("images/TimingIso.gif");
  delete myCanvas;
  delete timingSig;
  delete timingBkg;

  timingSig = new TH1F("timingSig", "Timing of Single Photon Filters in Signal Events", 6, 0, 6);
  timingSig->SetCanExtend(TH1::kAllAxes);
  timingSig->SetStats(0);
  delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",sigEvents);
  delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",sigEvents);
  TTreeFormula *IEcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.IEcal",sigEvents);
  TTreeFormula *PhotIHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotIHcal",sigEvents);
  TTreeFormula *PhotItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotItrack",sigEvents);
  event = 0;
  avgL1Match = 0.;
  avgEt = 0.;
  Double_t avgIEcal = 0.;
  Double_t avgPhotIHcal = 0.;
  Double_t avgPhotItrack = 0.;
  for (event = 0; event < sigEvents->GetEntries(); event++) {
    sigEvents->LoadTree(event);
    avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgIEcal = (event*avgIEcal + IEcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgPhotIHcal = (event*avgPhotIHcal + PhotIHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    avgPhotItrack = (event*avgPhotItrack + PhotItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
  }
  timingSig->Fill("L1 Match", avgL1Match);
  timingSig->Fill("Et", avgEt); 
  timingSig->Fill("IEcal", avgIEcal); 
  timingSig->Fill("IHcal", avgPhotIHcal); 
  timingSig->Fill("Itrack", avgPhotItrack); 
  timingSig->LabelsDeflate("X");
  timingSig->LabelsOption("v");

  timingBkg = new TH1F("timingBkg", "Timing of Single Photon Filters in Background Events", 6, 0, 6);
  timingBkg->SetCanExtend(TH1::kAllAxes);
  timingBkg->SetStats(0);
  avgL1Match = 0.;
  avgEt = 0.;
  avgIEcal = 0.;
  avgPhotIHcal = 0.;
  avgPhotItrack = 0.;
  for (xSecNum = 0; xSecNum < bkgEvents.size(); xSecNum++) {
    delete l1MatchTiming; l1MatchTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.l1Match",bkgEvents[xSecNum].first);
    delete EtTiming; EtTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.Et",bkgEvents[xSecNum].first);
    delete IEcalTiming; IEcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.IEcal",bkgEvents[xSecNum].first);
    delete PhotIHcalTiming; PhotIHcalTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotIHcal",bkgEvents[xSecNum].first);
    delete PhotItrackTiming; PhotItrackTiming = new TTreeFormula("Timing","HLTTiming_hltCutVars_IsoTiming_EGAMMAHLT.obj.PhotItrack",bkgEvents[xSecNum].first);
    event = 0;
    for (event = 0; event < bkgEvents[xSecNum].first->GetEntries(); event++) {
      bkgEvents[xSecNum].first->LoadTree(event);
      avgL1Match = (event*avgL1Match + l1MatchTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgEt = (event*avgEt + EtTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgIEcal = (event*avgIEcal + IEcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgPhotIHcal = (event*avgPhotIHcal + PhotIHcalTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
      avgPhotItrack = (event*avgPhotItrack + PhotItrackTiming->EvalInstance(0))/ ((Double_t) (event+1)); 
    }
  }
  timingBkg->Fill("L1 Match", avgL1Match);
  timingBkg->Fill("Et", avgEt); 
  timingBkg->Fill("IEcal", avgIEcal); 
  timingBkg->Fill("IHcal", avgPhotIHcal); 
  timingBkg->Fill("Itrack", avgPhotItrack); 
  timingBkg->LabelsDeflate("X");
  timingBkg->LabelsOption("v");
    
  myCanvas = new TCanvas("myCanvas", "Timing vs. Filter for Isolated Photon Filters", 1000, 500);
  myCanvas->Divide(2,1);
  myCanvas->cd(1);
  timingSig->Draw();
  myCanvas->cd(2);
  timingBkg->Draw();
  myCanvas->Print("images/TimingIsoPhot.gif");
}