コード例 #1
0
void ProduceTree(const char* filename, const char* treename, 
                 Int_t numentries, Int_t compression,
                 int numbranches, int branchsize, int buffersize) {
   TFile f(filename,"RECREATE");
   f.SetCompressionLevel(compression);
   
   TTree* t = new TTree(treename, treename);
   t->SetMaxTreeSize(19000000000.);
   
   Float_t* data = new Float_t[numbranches * branchsize];
   for (int i=0;i<numbranches * branchsize;i++)
      data[i] = 1.2837645786 * i;
      
   for (int nbr=0;nbr<numbranches;nbr++) {
      TString brname = "Branch";
      brname+=nbr;
      
      TString format = brname;
      format+="[";
      format+=branchsize;
      format+="]/F";
      
      t->Branch(brname.Data(),&(data[nbr*branchsize]),format.Data(), buffersize*branchsize*sizeof(Float_t));
   }   
   
   for (int n=0;n<numentries;n++)
     t->Fill();
   
   t->Write();
   
   delete t;
   
   delete[] data;
}
コード例 #2
0
ファイル: root_mem_test.C プロジェクト: SamLR/MuSIC5_detector
void root_mem_test(){
  TFile* file = new TFile("mem_test.root", "RECREATE");
  TTree* tree = new TTree("t", "t");
  Long64_t to_write; // 64b integer, i.e. 8B
  
  tree->Branch("Filler", &to_write);
  
  tree->SetMaxTreeSize(64L); // in bytes, i.e. can store 8 values
  
  for(Long64_t i = 0; i < 16; ++i) {
    to_write = i;
    tree->Fill();
  }
}
void forest2yskim_jetSkim_forestV3_noEleRejection(TString inputFile_="forestFiles/pA/pA_photonSkimForest_v85_skimPhotonPt50_eta1.5.root",
		std::string MinbiasFname = "skim_trackJet_minbiasTrackJet_mc.root",
		float cutphotonPt  = 35,  // default value dropped to 35GeV  for later photon energy smearing/scaling
		std::string outname = "testPhotonSkim.root",
		sampleType colli=kPADATA,
		bool doMix = false,
		bool doJetResCorrection = 1,  // = L2L3 * MC nonclosure correction  jet energy correction is done by default from Oct 19th (YS)
		int smearingCentBin = -1, //0=0-10%, 1=10-30%, 2=30-50%, 3=50-100%, 4=0-30%, 5=30-100%  : Jet pT and phi smearing!
		float jetEnergyScale = 1.0, 
		float addFlatJetEnergyRes = 0.0, 
		bool useGenJetColl = 0
		)
{
	bool isMC=true;
	if ((colli==kPPDATA)||(colli==kPADATA)||(colli==kHIDATA))
		isMC=false;

	int seconds = time(NULL);         cout << " time = " <<seconds%10000<< endl;
	TRandom3 rand(seconds%10000);
	TString datafname  = "";
	float cutphotonEta = 1.44;
	float preCutPhotonEt = 30;

	const int nMaxPho = 100;


	HiForest *c;
	if((colli==kPADATA)||(colli==kPAMC)) {
		c = new HiForest(inputFile_.Data(), "forest", cPPb, isMC );
	}
	else if  ((colli==kPPDATA)||(colli==kPPMC)) {
		c = new HiForest(inputFile_.Data(), "forest", cPP, isMC );
	}
	else if  ((colli==kHIDATA)||(colli==kHIMC)) {
		c = new HiForest(inputFile_.Data(), "forest", cPbPb, isMC );
		c->GetEnergyScaleTable("../photonEnergyScaleTable_lowPt_v6.root");
	}
	else {
		cout << " Error!  No such collision type" << endl;
		return;
	}

	c->InitTree();


	// vertex and centrality vtxCentWeighting
	TFile* fWeight = new TFile("../vertexReweightingHistogram_pthatweighted.root");

	TH1D* hWeight_vtx_data_pp = (TH1D*)fWeight->Get("vertexHistoData_pp");
	TH1D* hWeight_vtx_mc_pp = (TH1D*)fWeight->Get("vertexHistoMC_pp");

	TH1D* hWeight_vtx_data_ppb = (TH1D*)fWeight->Get("vertexHistoData_ppb");
	TH1D* hWeight_vtx_mc_ppb = (TH1D*)fWeight->Get("vertexHistoMC_ppb");

	TH1D* hWeight_vtx_data_pbpb = (TH1D*)fWeight->Get("vertexHistoData_pbpb");
	TH1D* hWeight_vtx_mc_pbpb = (TH1D*)fWeight->Get("vertexHistoMC_pbpb");
	TH1D* hWeight_cent_data_pbpb = (TH1D*)fWeight->Get("centBinHistoData_pbpb");
	TH1D* hWeight_cent_mc_pbpb = (TH1D*)fWeight->Get("centBinHistoMC_pbpb");




	// L2L3 correction
	TFile* fL2L3pp = new TFile("../corrL2L3/Casym_pp_double_hcalbins_algo_ak3PF_pt100_140_jet80_alphahigh_20_phicut250.root");
	TH1D * c_etapp=(TH1D*)fL2L3pp->Get("C_asym");
	TF1* fptpp = new TF1("fptpp","1-[0]/pow(x,[1])",20,300);
	fptpp->SetParameters(0.06971,0.8167);

	TFile* fL2L3pA = new TFile("../corrL2L3/Casym_pPb_double_hcalbins_algo_akPu3PF_pt100_140_jet80_alphahigh_20_phicut250.root");
	TH1D * c_etapA=(TH1D*)fL2L3pA->Get("C_asym");
	TF1* fptpA = new TF1("fptpA","1-[0]/pow(x,[1])",20,300);
	fptpA->SetParameters(0.3015, 0.8913);

	TFile* fL2L3Ap = new TFile("../corrL2L3/Casym_Pbp_double_hcalbins_algo_akPu3PF_pt100_140_jet80_alphahigh_20_phicut250.root");
	TH1D * c_etaAp=(TH1D*)fL2L3Ap->Get("C_asym");
	TF1* fptAp = new TF1("fptAp","1-[0]/pow(x,[1])",20,300);
	fptAp->SetParameters(0.3015, 0.8913);

	// pA MC
	TF1 * fgaus=new TF1("fgaus_pA","gaus(0)",-20,20);
	fgaus->SetParameters(1,0,1);
	TF1 * fsmear_pA = new TF1("fsmear_pA","[0]/pow(x,[1])",50,300);
	fsmear_pA->SetParameters(1.052,0.5261);


	/*
	   TCanvas* c11 = new TCanvas("c11","",1200,400);   // valiation of smearing factors
	   c11->Divide(3,1);
	   c11->cd(1);
	   c_etapp->Draw();
	   c11->cd(2);
	   c_etaAp->Draw();
	   c11->cd(3);
	   c_etapA->Draw();
	   c11->SaveAs("f1.gif");
	   */


	// Create a new root file
	TFile* newfile_data = new TFile(outname.data(),"recreate");

	TTree* newtreePhoton;
	float newPt[nMaxPho];  // <<= temporary space
	int order[nMaxPho];
	float corrPt[nMaxPho];
	newtreePhoton = c->photonTree->CloneTree(0);
	newtreePhoton->SetName("yPhotonTree");
	newtreePhoton->SetMaxTreeSize(MAXTREESIZE);
	newtreePhoton->Branch("order",  order, "order[nPhotons]/I");
	newtreePhoton->Branch("corrPt", corrPt,"corrPt[nPhotons]/F");

	TTree* treeFullJet;
	if (   (colli==kPPDATA) || (colli==kPPMC) ) {
		//treeFullJet = c->ak3jetTree->CloneTree(0);
		treeFullJet = c->ak3PFJetTree->CloneTree(0);
		cout << "pp collision.  Using ak3PF Jet Algo" << endl<<endl;
	}
	else {
		//treeFullJet = c->akPu3jetTree->CloneTree(0);
		treeFullJet = c->akPu3PFJetTree->CloneTree(0);
		cout << "PbPb or pPb collision. Using akPu3PF Jet Algo" << endl<<endl;
	}
	treeFullJet->SetName("fullJet");
	treeFullJet->SetMaxTreeSize(MAXTREESIZE);
#if 1
	TTree* treeGenp;
	if (   (colli==kHIMC ) || (colli==kPPMC) || (colli==kPAMC) ) {
		treeGenp =  c->genParticleTree->CloneTree(0);
		treeGenp->SetName("genparTree");
		//treeGenp =  c->genpTree->CloneTree(0);
		//treeGenp->SetName("genparTree");
		treeGenp->SetMaxTreeSize(MAXTREESIZE);
	}
#endif


	// jet tree!
	int nJet;
	const int MAXJET = 50000; // to accomodate 100 smeared jets, need to be careful with ram
	float jetPt[MAXJET];
	float jetEta[MAXJET];
	float jetPhi[MAXJET];
	float jetDphi[MAXJET];
	int jetSubid[MAXJET];
	float jetRefPt[MAXJET];
	float jetRefEta[MAXJET];
	float jetRefPhi[MAXJET];
	float jetRefDphi[MAXJET];
	float jetRefPartonPt[MAXJET];
	int  jetRefPartonFlv[MAXJET];

	TTree *newtreeJet = new TTree("yJet","jets");
	newtreeJet->SetMaxTreeSize(MAXTREESIZE);
	newtreeJet->Branch("nJet",&nJet,"nJet/I");
	newtreeJet->Branch("pt",jetPt,"pt[nJet]/F");
	newtreeJet->Branch("eta",jetEta,"eta[nJet]/F");
	newtreeJet->Branch("phi",jetPhi,"phi[nJet]/F");
	newtreeJet->Branch("dphi",jetDphi,"dphi[nJet]/F");
	if ( isMC )  {
		newtreeJet->Branch("subid",jetSubid,"subid[nJet]/I");
		newtreeJet->Branch("refPt",jetRefPt,"refPt[nJet]/F");
		newtreeJet->Branch("refEta",jetRefEta,"refEta[nJet]/F");
		newtreeJet->Branch("refPhi",jetRefPhi,"refPhi[nJet]/F");
		newtreeJet->Branch("refDphi",jetRefDphi,"refDphi[nJet]/F");
		newtreeJet->Branch("refPartonPt",jetRefPartonPt,"refPartonPt[nJet]/F");
		newtreeJet->Branch("refPartonFlv",jetRefPartonFlv,"refPartonFlv[nJet]/I");
	}



	int nMjet;
	float mJetPt[MAXMJET];
	float mJetEta[MAXMJET];
	float mJetPhi[MAXMJET];
	float mJetDphi[MAXMJET];

	TTree * tmixJet = new TTree("mJet","Jet from minbias events");
	tmixJet->SetMaxTreeSize(MAXTREESIZE);
	tmixJet->Branch("nJet",&nMjet,"nJet/I");
	tmixJet->Branch("pt",mJetPt,"pt[nJet]/F");
	tmixJet->Branch("eta",mJetEta,"eta[nJet]/F");
	tmixJet->Branch("phi",mJetPhi,"phi[nJet]/F");
	tmixJet->Branch("dphi", mJetDphi, "dphi[nJet]/F");



	// Imb = Input MinBias events
	EvtSel          evtImb;
	Int_t           nJetImb;
	Float_t         jetPtImb[100];
	Float_t         jetEtaImb[100];
	Float_t         jetPhiImb[100];
	TBranch        *b_evt;
	TBranch        *b_nJetImb;
	TBranch        *b_jetPtImb;
	TBranch        *b_jetEtaImb;
	TBranch        *b_jetPhiImb;


	int nCentBins =  nCentBinSkim;
	if ((colli==kPADATA)||(colli==kPAMC)) {
		nCentBins = nCentBinSkimPA;
	}

	TChain   *tjmb[100][nVtxBin+1];
	int nMB[100][nVtxBin+1] ; //= 199109;
	int mbItr[100][nVtxBin+1];
	if ( doMix ) {
		cout <<"  Tree initialization for MinBias mixing" << endl;
		for( int icent = 0 ; icent< nCentBins ; icent++) {
			for( int ivz = 1 ; ivz<=nVtxBin ; ivz++) {

				tjmb[icent][ivz] = new TChain(Form("trkAndJets_first_cBin2icent%d_ivz%d",icent,ivz));
				tjmb[icent][ivz]->Add(MinbiasFname.data());
				tjmb[icent][ivz]->SetBranchAddress("evt", &evtImb,&b_evt);
				tjmb[icent][ivz]->SetBranchAddress("nJet",   &nJetImb,   &b_nJetImb);
				tjmb[icent][ivz]->SetBranchAddress("jetPt",  &jetPtImb,  &b_jetPtImb);
				tjmb[icent][ivz]->SetBranchAddress("jetEta", &jetEtaImb, &b_jetEtaImb);
				tjmb[icent][ivz]->SetBranchAddress("jetPhi", &jetPhiImb, &b_jetPhiImb);


				nMB[icent][ivz] = tjmb[icent][ivz]->GetEntries();
				cout << "number of evetns in (icent = " << icent << ", ivtxZ = "<< ivz << ")  = " << nMB[icent][ivz] << endl;
				int primeSeed = rand.Integer(37324);
				mbItr[icent][ivz] = primeSeed%(nMB[icent][ivz]);
				cout <<" initial itr = " << mbItr[icent][ivz] << endl;
			}
		}
	}
	else
		cout << endl << endl << "  Mixing process is skipped" << endl << endl << endl ;


	// reweighting factor should go here
	int eTot(0), eSel(0);
	EvtSel evt;
	GammaJet gj;
	Isolation isol;
	TTree *tgj;
	tgj = new TTree("tgj","gamma jet tree");
	tgj->SetMaxTreeSize(MAXTREESIZE);
	tgj->Branch("evt",&evt.run,"run/I:evt:cBin:pBin:trig/O:offlSel:noiseFilt:anaEvtSel:vz/F:vtxCentWeight/F:hf4Pos:hf4Neg:hf4Sum:ptHat:ptHatWeight");
	tgj->Branch("lpho",&gj.photonEt,"photonEt/F:photonRawEt:photonEta:photonPhi:hovere:r9:sigmaIetaIeta:sumIso:genIso:genPhotonEt:genMomId/I:lJetPt/F:lJetEta:lJetPhi:lJetDphi:lJetSubid/I");
	tgj->Branch("isolation",&isol.cc1,"cc1:cc2:cc3:cc4:cc5:cr1:cr2:cr3:cr4:cr5:ct1PtCut20:ct2PtCut20:ct3PtCut20:ct4PtCut20:ct5PtCut20:ecalIso:hcalIso:trackIso");  // ecalIso,hcalIso,trackIso are the pp style isolation


	float vzCut = vtxCutPhotonAna;
	TH1F* hvz = new TH1F("hvz","",nVtxBin,-vzCut,vzCut);
	// event plane hitogram
	TH1F* hEvtPlnBin = new TH1F("hEvtPlnBin", "", nPlnBin, -PI/2., PI/2.);
	// jet algos
	Jets* theJet;
	Jets* genJetTree;
	if (   (colli==kPPDATA) || (colli==kPPMC) ) {
		theJet = &(c->ak3PF) ;
		cout << "pp collision.  Using ak3PF Jet Algo" << endl<<endl;
	}
	else {
		theJet = &(c->akPu3PF) ;
		cout << "PbPb or pPb collision. Using akPu3PF Jet Algo" << endl<<endl;
	}
	genJetTree = &(c->akPu3PF);

	//////// Kaya's modificiation ////////
	EventMatchingCMS* eventMatcher=new EventMatchingCMS();
	bool eventAdded;
	Long64_t duplicateEvents = 0;
	//////// Kaya's modificiation - END ////////

	// Loop starts.
	int nentries = c->GetEntries();
	cout << "number of entries = " << nentries << endl;
	for (Long64_t jentry = 0 ; jentry < nentries; jentry++) {
		eTot++;
		if (jentry% 2000 == 0)  {
			cout <<jentry<<" / "<<nentries<<" "<<setprecision(2)<<(double)jentry/nentries*100<<endl;
		}

		c->GetEntry(jentry);

		//////// Kaya's modificiation ////////
		eventAdded = eventMatcher->addEvent(c->evt.evt, c->evt.lumi, c->evt.run, jentry);
		if(!eventAdded) // this event is duplicate, skip this one.
		{
			duplicateEvents++;
			continue;
		}
		//////// Kaya's modificiation - END ////////

		// Select events with a generated photon in mid-rapidity
		bool genPhotonFlag=false;
		if ( !isMC )   // fixed the most stupid error
			genPhotonFlag = true;
		else {
#if 0 // there is no genp tree, but is higentree
			for ( int g=0 ; g< c->genp.nPar ; g++)
				if ( c->genp.id[g] != 22 )
					continue;
			if ( fabs( c->genp.momId[g] ) > 22 )
				continue;
			if ( fabs( c->genp.status[g] ) != 1 )
				continue;
			if ( fabs( c->genp.eta[g] ) > cutphotonEta )
				continue;
			if ( c->genp.et[g] < 35 )
				continue;
#endif
			for ( int g=0 ; g< c->genparticle.mult ; g++) {
				if ( c->genparticle.pdg[g] != 22 )
					continue;
				//	if ( fabs( c->genparticle.momId[g] ) > 22 )
				//	  continue;
				//	if ( fabs( c->genparticle.status[g] ) != 1 )
				//	  continue;
				if ( fabs( c->genparticle.eta[g] ) > cutphotonEta )
					continue;
				if ( c->genparticle.pt[g] < cutphotonPt )
					continue;
				genPhotonFlag = true;
			}
		}
		if ( !genPhotonFlag)
			continue;

		evt.clear();
		evt.run   = c->evt.run;
		evt.evt = c->evt.evt;
		evt.hf4Pos = c->evt.hiHFplusEta4;
		evt.hf4Neg = c->evt.hiHFminusEta4;
		evt.hf4Sum = evt.hf4Pos + evt.hf4Neg;
		evt.cBin = -99;
		evt.pBin   = -99 ;
		if ((colli==kHIDATA)||(colli==kHIMC))   {
			evt.cBin = c->evt.hiBin;
			evt.pBin   = hEvtPlnBin->FindBin( c->evt.hiEvtPlanes[theEvtPlNumber] ) ;
		}
		else if ((colli==kPADATA)||(colli==kPAMC))   {
			evt.cBin =  getHfBin(evt.hf4Sum);
			// if (  ((evt.cBin) < 0) || (evt.cBin) > 18 )
			//   cout << " Check the pA centrality..  cbin = " << evt.cBin << endl;
		}

		evt.trig = 0;
		evt.offlSel = (c->skim.pcollisionEventSelection > 0);
		evt.noiseFilt = (c->skim.pHBHENoiseFilter > 0);
		evt.anaEvtSel = c->selectEvent() && evt.trig;
		evt.vz = c->evt.vz;

		int cBin = evt.cBin;
		int vzBin = hvz->FindBin(evt.vz)  ;
		hvz->Fill(evt.vz) ;

		// this was the problem!!! all c->selectEvent() are 0
		//if ( ( (colli==kHIDATA)||(colli==kHIMC)||(colli==kPADATA)||(colli==kPAMC) || (colli==kPPMC) ) && ( c->selectEvent() == 0 ))
		if ( ( (colli==kHIDATA)||(colli==kHIMC) ) && ( c->skim.pcollisionEventSelection == 0 ))
			continue;
		if ( ( (colli==kPADATA)||(colli==kPAMC)||(colli==kPPDATA)||(colli==kPPMC)) && ( c->skim.pPAcollisionEventSelectionPA == 0 )) // yeonju included pp data and pp mc
			continue;
	//	if ( ( (colli==kPPMC) ) && ( c->skim.pcollisionEventSelection == 0 ))
	//		continue;
	//	if ( ( (colli==kPADATA)||(colli==kPPDATA) ) && ( c->skim.pVertexFilterCutGplus ==0 ) ) // No Pile up events
	//		continue;
		if ( (vzBin<1) || ( vzBin > nVtxBin) )
			continue;

		eSel++;      // OK.  This event is a collisional and no-noise event.


		// Reweight for vertex and centrality of MC
		evt.vtxCentWeight = 1;
		double wVtx=1;
		double wCent=1;
		if (colli ==kHIMC) {
			int vBin =  hWeight_vtx_data_pbpb->FindBin(evt.vz);
			wVtx =   hWeight_vtx_data_pbpb->GetBinContent(vBin) / hWeight_vtx_mc_pbpb->GetBinContent(vBin) ;
			wCent =  hWeight_cent_data_pbpb->GetBinContent(evt.cBin+1) / hWeight_cent_mc_pbpb->GetBinContent(evt.cBin+1) ;
		}
		else if ( colli ==kPPMC) {
			int vBin =  hWeight_vtx_data_pp->FindBin(evt.vz);
			wVtx =   hWeight_vtx_data_pp->GetBinContent(vBin) / hWeight_vtx_mc_pp->GetBinContent(vBin) ;
		}
		else if ( colli ==kPAMC) {
			int vBin =  hWeight_vtx_data_ppb->FindBin(evt.vz);
			wVtx =   hWeight_vtx_data_ppb->GetBinContent(vBin) / hWeight_vtx_mc_ppb->GetBinContent(vBin) ;
		}
		evt.vtxCentWeight = wVtx * wCent;

		evt.ptHat = -1;
		evt.ptHatWeight = 1;
		evt.ptHat = c->photon.ptHat;

		// if( colli == kPAMC && evt.ptHat > maxpthat ) // pA samples don't use ptHatCutter.C.
		//	continue;
		if (colli ==kHIMC) {
			if ( evt.ptHat < 50  )       evt.ptHatWeight = 9008/16237. ;
			else if ( evt.ptHat < 80  )       evt.ptHatWeight = 3750/85438. ;
			else   evt.ptHatWeight =  1191/140432. ;
		}
        else if ( colli == kPPMC) { // pp has only 4 pthat samples
            if ( evt.ptHat > 30 && evt.ptHat < 50  )       evt.ptHatWeight = 156861/156861. ;
            else if ( evt.ptHat > 50 && evt.ptHat < 80  )       evt.ptHatWeight = 33610/193462. ;
            else if ( evt.ptHat > 80 && evt.ptHat < 120  )       evt.ptHatWeight = 5757/195174. ;
            else   evt.ptHatWeight = 1272/236703. ;
            //  if ( evt.ptHat < 50  )       evt.ptHatWeight = 9008/9008. ;
            //  else if ( evt.ptHat < 80  )       evt.ptHatWeight = 3750/40109. ;
            //  else   evt.ptHatWeight = 1191/66934. ;
    	}
		else if ( colli == kPAMC) { 
			if ( evt.ptHat > 30 && evt.ptHat < 50  )       evt.ptHatWeight = 62744/62744. ;
			else if ( evt.ptHat > 50 && evt.ptHat < 80  )       evt.ptHatWeight = 29499/107309. ;
			else if ( evt.ptHat > 80 && evt.ptHat < 120  )       evt.ptHatWeight = 7640/106817. ;
			else if ( evt.ptHat > 120 && evt.ptHat < 170  )       evt.ptHatWeight = 1868/104443. ;
			else   evt.ptHatWeight = 649/139647. ;
		}



		for (int j=0;j< c->photon.nPhotons;j++) {

			if (  ( c->photon.pt[j] > preCutPhotonEt ) && ( fabs( c->photon.eta[j] ) < cutphotonEta ) ) {
				newPt[j] = c->getCorrEt(j);
			}
			else
				newPt[j] = c->photon.pt[j] - 10000;

		//	if ( (c->isSpike(j)) || (c->photon.hadronicOverEm[j]>0.2) || (c->photon.isEle[j]))  // Electron Rejection should be default.
			if ( (c->isSpike(j)) || (c->photon.hadronicOverEm[j]>0.2) ) //||  (c->photon.isEle[j])  // This is for no Electron Rejection case.
				newPt[j] = newPt[j] - 20000;
			if (c->photon.seedTime[j] ==0 )   // clustering bug
				newPt[j] = newPt[j] - 30000;

			corrPt[j] = newPt[j];
		}

		TMath::Sort(c->photon.nPhotons, newPt, order);


		// Select the leading photon
		gj.clear();
		int leadingIndex=-1;
		for (int j=0;j<c->photon.nPhotons;j++) {
			if ( c->photon.pt[j]  < preCutPhotonEt ) continue;
			if ( fabs(c->photon.eta[j]) > cutphotonEta ) continue;
			if (c->isSpike(j)) continue;
			//   if (!(c->isLoosePhoton(j))) continue;
			if (c->photon.hadronicOverEm[j]>0.1) continue;
			if ((c->photon.rawEnergy[j]/c->photon.energy[j])<0.5) continue;



			// sort using corrected photon pt
			float theCorrPt= corrPt[j];
			if ( theCorrPt > gj.photonEt) {
				gj.photonEt = theCorrPt;
				leadingIndex = j;
			}
		}
		//    if ( (gj.photonEt < cutphotonPt) )    <== This cut ruins the ptHat weighting factor
		//  continue;


		/// Save leading photons
		if (leadingIndex!=-1) {
			gj.photonRawEt=c->photon.pt[leadingIndex];
			gj.photonEta=c->photon.eta[leadingIndex];
			gj.photonPhi=c->photon.phi[leadingIndex];
			gj.hovere=c->photon.hadronicOverEm[leadingIndex];
			gj.r9=c->photon.r9[leadingIndex];
			gj.sigmaIetaIeta=c->photon.sigmaIetaIeta[leadingIndex];
			gj.sumIsol = (c->photon.cr4[leadingIndex]+c->photon.cc4[leadingIndex]+c->photon.ct4PtCut20[leadingIndex]) / 0.9;
			gj.genIso   = c->photon.genCalIsoDR04[leadingIndex];
			gj.genPhotonEt = c->photon.genMatchedPt[leadingIndex];
			gj.genMomId = c->photon.genMomId[leadingIndex];
			isol.Set(c,leadingIndex);
		}
		else {
			gj.clear();
		}
		if ( (colli==kPADATA) && ( evt.run > 211256 ) )  {
			gj.photonEta = - gj.photonEta;
		}



		///////////////////// Skimmed Jet tree ///////////////////////////////////
		nJet = 0 ;

		int jetEntries = 0;
		if (useGenJetColl )    jetEntries = theJet->ngen;
		else                   jetEntries = theJet->nref;

		int nSmear = 1;
		if(smearingCentBin != -1)
			nSmear = 100;

		for(int iSmear =0; iSmear < nSmear; iSmear++){ // iSmear loop have to be here, before Jet loop. mis-ordered for loops ruins jetrefpt values.
			for (int ij=0; ij< jetEntries ; ij++) {
				if ( gj.photonEt < 0 )    continue ;    // If there is no photon in this event
				if (  useGenJetColl )   {
					jetPt[nJet] = theJet->genpt[ij];
					jetEta[nJet] = theJet->geneta[ij];
					jetPhi[nJet] = theJet->genphi[ij];
				}
				else  {
					jetPt[nJet] = theJet->jtpt[ij];
					jetEta[nJet] = theJet->jteta[ij];
					jetPhi[nJet] = theJet->jtphi[ij];
				}

				// Smear phi
				Double_t newPhi = jetPhi[nJet] ;
				if( smearingCentBin != -1 )
				{
					Double_t phiSmear  = TMath::Sqrt((cphi_pbpb[smearingCentBin]*cphi_pbpb[smearingCentBin] - cphi_pp*cphi_pp)
							+ (sphi_pbpb[smearingCentBin]*sphi_pbpb[smearingCentBin] - sphi_pp*sphi_pp)/jetPt[nJet]
							+ (nphi_pbpb[smearingCentBin]*nphi_pbpb[smearingCentBin] - nphi_pp*nphi_pp)/(jetPt[nJet]*jetPt[nJet]));
					newPhi  =  jetPhi[nJet] +   rand.Gaus(0, phiSmear);
					while ( fabs(newPhi) > PI )  {
						if ( newPhi > PI )  newPhi = newPhi - 2*PI;
						if ( newPhi < -PI )  newPhi = newPhi + 2*PI;
					}
				}
				jetPhi[nJet] = newPhi;


				// smear the jet pT
				//float smeared = jetPt[nJet] * rand.Gaus(1,addJetEnergyRes/jetPt[nJet])   *  rand.Gaus(1, addFlatJetEnergyRes) ;
				Double_t smeared = jetPt[nJet] * rand.Gaus(1, addFlatJetEnergyRes);
				if( smearingCentBin != -1 )
				{
					Double_t smearSigma = TMath::Sqrt((c_pbpb[smearingCentBin]*c_pbpb[smearingCentBin] - c_pp*c_pp)
							+ (s_pbpb[smearingCentBin]*s_pbpb[smearingCentBin] - s_pp*s_pp)/jetPt[nJet]
							+ (n_pbpb[smearingCentBin]*n_pbpb[smearingCentBin] - n_pp*n_pp)/(jetPt[nJet]*jetPt[nJet]));
					smeared = jetPt[nJet] * rand.Gaus(1, smearSigma);
				}
				// then multiply jet energy sclae

				// resCorrection
				float resCorrection =1. ;
				float l2l3Corr =1 ;

				if  (doJetResCorrection)   {
					// L2L3 correction!
					if ( colli == kPPDATA)   {
						l2l3Corr = c_etapp->GetBinContent(c_etapp->FindBin(jetEta[nJet])) * fptpp->Eval( jetPt[nJet]);
					}
					else if ( colli == kPADATA)   {
						if ( evt.run > 211256 )
							l2l3Corr = c_etapA->GetBinContent(c_etapA->FindBin(jetEta[nJet]))  * fptpA->Eval( jetPt[nJet]);
						else
							l2l3Corr = c_etaAp->GetBinContent(c_etaAp->FindBin(jetEta[nJet]))  * fptAp->Eval( jetPt[nJet]);
					}
					else if ( colli == kPAMC)
						l2l3Corr = 1 + (fsmear_pA->Eval( jetPt[nJet] )) * fgaus->GetRandom()  ;

					// do the residual correction
					if ((colli==kHIDATA)||(colli==kHIMC))  { 
						if ( evt.cBin  < 12 )   // central
							resCorrection  =  1.04503 -1.6122  /(sqrt(jetPt[nJet])) + 9.27212 / (jetPt[nJet]);  //1.04503    -1.6122    9.27212
						else                  // peripheral
							resCorrection  =  1.00596 -0.653191/(sqrt(jetPt[nJet])) + 4.35373 / (jetPt[nJet]);  //1.00596     -0.653191  4.35373
					}
					else if ((colli==kPPDATA)||(colli==kPPMC)){  // do the residual correction
						resCorrection  = 0.993609  +0.158418/(sqrt(jetPt[nJet])) + 0.335479 / (jetPt[nJet]);//	  0.993609   0.158418   0.335479
					}
					else if ((colli==kPADATA)||(colli==kPAMC)){
						resCorrection = 0.997738 + 0.0221806/(sqrt(jetPt[nJet])) - 0.877999/ (jetPt[nJet]); //C : 0.997738, S : 0.0221806, N : -0.877999 //function derived as a function of gen pt 
						//resCorrection = 0.981365 + 0.342746/(sqrt(jetPt[nJet])) - 2.63018 / (jetPt[nJet]); //C : 0.981365, S : 0.342746, N : -2.63018 //function derived as a function of gen pt //derived from l2l3 corrected sample. 
						//resCorrection = 0.745753 + 6.91646/(sqrt(jetPt[nJet])) - 33.0167 / (jetPt[nJet]); //C : 0.745753, S : 6.91646, N : -33.0167 //function derived as a function of reco pt 
					}

				} // doJetResCorrection

				// reflect eta!
				if ( (colli==kPADATA) && ( evt.run > 211256 ) )  {
					jetEta[nJet] = -jetEta[nJet];
				}

				jetPt[nJet] = smeared * l2l3Corr /resCorrection *jetEnergyScale;



				if ( jetPt[nJet] < cutjetPtSkim)  // double cutjetPtSkim = 15; Oct 19th
					continue;
				if ( fabs( jetEta[nJet] ) > cutjetEtaSkim )     // double cutjetEtaSkim = 3.0; Oct 19th
					continue;
				if ( getDR( jetEta[nJet], jetPhi[nJet], gj.photonEta, gj.photonPhi) < 0.5 )
					continue;


				if (jetPt[nJet] >0)
					jetDphi[nJet] = getAbsDphi( jetPhi[nJet], gj.photonPhi) ;
				else
					jetDphi[nJet] = -1;


				if (  useGenJetColl )   {
					jetSubid[nJet] = -9999;
					jetRefPt[nJet] = -9999;
					jetRefEta[nJet] = -9999;
					jetRefPhi[nJet] = -9999;
					jetRefPt[nJet] =  -9999;
					jetRefPartonPt[nJet] = -9999;
					jetRefPartonFlv[nJet] = -9999;
				}
				else {
					jetRefPt[nJet] = theJet->refpt[ij];
					jetRefEta[nJet] = theJet->refeta[ij];
					jetRefPhi[nJet] = theJet->refphi[ij];
					if (jetRefPt[nJet] >0)
						jetRefDphi[nJet] = getAbsDphi( jetRefPhi[nJet] , gj.photonPhi) ;
					else
						jetRefDphi[nJet] = -1;
					jetRefPartonPt[nJet] = theJet->refparton_pt[ij];
					jetRefPartonFlv[nJet] = theJet->refparton_flavor[ij];

					jetSubid[nJet] = -9999;
					if (jetRefPt[nJet] >0)  {   // Find the collisional subid of this gen jet!!
						for ( int igen=0; igen < genJetTree->ngen ; igen++) {
							if ( jetRefPt[nJet] == genJetTree->genpt[igen] )
								jetSubid[nJet] = genJetTree->gensubid[igen] ;
						}

						if ( jetSubid[nJet] == -9999 ) // No genJet matched!
							cout << " WARNING!  This reco jet was not matched to anyone in the gen jet collection!!! " << endl;

					}
				}

				nJet++ ;
			}// ij for loop
		}// iSmear for loop


		//////// Leading jet kinematics in dphi>7pi/8
		float maxJpt = 0;
		int jetLeadingIndex = -1;

		for (int ij=0; ij< nJet ; ij++) {
			if ( jetDphi[ij] < awayRange )  // const float awayRange= PI * 7./8.;
			continue;
			if ( fabs( jetEta[ij] ) > cutjetEta )  // double cutjetEta = 1.6;
			continue;
			if ( jetPt[ij] > maxJpt) {
				maxJpt = jetPt[ij] ;
				jetLeadingIndex = ij;
			}
		}
		if ( jetLeadingIndex > -1 ) {
			gj.lJetPt = jetPt[jetLeadingIndex];
			gj.lJetEta = jetEta[jetLeadingIndex];
			gj.lJetPhi = jetPhi[jetLeadingIndex];
			gj.lJetDphi =  jetDphi[jetLeadingIndex];
			gj.lJetSubid=  jetSubid[jetLeadingIndex];
		}
		else {
			gj.lJetPt = -1;
			gj.lJetEta = 999;
			gj.lJetPhi = 999;
			gj.lJetDphi = 0;
			gj.lJetSubid=  -99;
		}


		int nMixing = nMixing1;
		nMjet = 0;
		bool noSuchEvent = false;
		int iMix=0;
		int loopCounter=0;

		if ( !doMix )
			iMix = nMixing+1;   // Mixing step will be skipped

		while (iMix<nMixing)  {
			loopCounter++;
			if ( loopCounter > nMB[cBin][vzBin]+1) {
				iMix = 999999 ;
				noSuchEvent = true;
				cout << " no such event!! :  icent = " << cBin << ",  vzBin = " << vzBin << ",  pBin = " << evt.pBin << endl;
				continue;
			}

			mbItr[cBin][vzBin] = mbItr[cBin][vzBin] + 1;
			if ( mbItr[cBin][vzBin] == nMB[cBin][vzBin] )
				mbItr[cBin][vzBin] =  mbItr[cBin][vzBin] - nMB[cBin][vzBin];

			/// Load the minbias tracks!!
			tjmb[cBin][vzBin]->GetEntry(mbItr[cBin][vzBin]);



			// ok found the event!! ///////////
			loopCounter =0;  // Re-initiate loopCounter
			// Jet mixing
			for (int it = 0 ; it < nJetImb ; it++) {
				if ( gj.photonEt < 0 )  continue;
				// Smear phi
				Double_t newPhi = jetPhiImb[it];
				if( smearingCentBin != -1 )
				{
					Double_t phiSmear  = TMath::Sqrt((cphi_pbpb[smearingCentBin]*cphi_pbpb[smearingCentBin] - cphi_pp*cphi_pp)
							+ (sphi_pbpb[smearingCentBin]*sphi_pbpb[smearingCentBin] - sphi_pp*sphi_pp)/jetPtImb[it]
							+ (nphi_pbpb[smearingCentBin]*nphi_pbpb[smearingCentBin] - nphi_pp*nphi_pp)/(jetPtImb[it]*jetPtImb[it]));
					newPhi  =  jetPhiImb[it] +   rand.Gaus(0, phiSmear);
					while ( fabs(newPhi) > PI )  {
						if ( newPhi > PI )  newPhi = newPhi - 2*PI;
						if ( newPhi < -PI )  newPhi = newPhi + 2*PI;
					}
				}
				jetPhiImb[it] = newPhi;


				// smear the jet pT
				//float smeared = jetPtImb[it] * rand.Gaus(1,addJetEnergyRes/jetPtImb[it]) *  rand.Gaus(1, addFlatJetEnergyRes) ;
				Double_t smeared = jetPtImb[it] *  rand.Gaus(1, addFlatJetEnergyRes);
				if( smearingCentBin != -1 )
				{
					Double_t smearSigma = TMath::Sqrt((c_pbpb[smearingCentBin]*c_pbpb[smearingCentBin] - c_pp*c_pp)
							+ (s_pbpb[smearingCentBin]*s_pbpb[smearingCentBin] - s_pp*s_pp)/jetPtImb[it]
							+ (n_pbpb[smearingCentBin]*n_pbpb[smearingCentBin] - n_pp*n_pp)/(jetPtImb[it]*jetPtImb[it]));
					smeared = jetPtImb[it] * rand.Gaus(1, smearSigma);
				}
				float resCorrection =1. ;
				float l2l3Corr =1 ;

				if  (doJetResCorrection)   {
					// L2L3
					if ( colli == kPPDATA)   {
						l2l3Corr = c_etapp->GetBinContent(c_etapp->FindBin(jetEtaImb[it])) * fptpp->Eval( jetPtImb[it]);
					}
					else if ( colli == kPADATA)   {
						if ( evt.run > 211256 )
							l2l3Corr = c_etapA->GetBinContent(c_etapA->FindBin(jetEtaImb[it]))  * fptpA->Eval( jetPtImb[it]);
						else
							l2l3Corr = c_etaAp->GetBinContent(c_etaAp->FindBin(jetEtaImb[it]))  * fptAp->Eval( jetPtImb[it]);
					}
					else if ( colli == kPAMC)
						l2l3Corr = 1 + (fsmear_pA->Eval( jetPtImb[it] )) * fgaus->GetRandom()  ;

					// Correction from MC closure
					if ((colli==kHIDATA)||(colli==kHIMC))  { // do the residual correction
						if ( evt.cBin  < 12 )   // central
							resCorrection  =  1.04503 -1.6122  /(sqrt(jetPtImb[it])) + 9.27212 / (jetPtImb[it]);  //1.04503    -1.6122    9.27212
						else                  // peripheral
							resCorrection  =  1.00596 -0.653191/(sqrt(jetPtImb[it])) + 4.35373 / (jetPtImb[it]);  //1.00596     -0.653191  4.35373
					}
					else if ((colli==kPPDATA)||(colli==kPPMC)){  // do the residual correction
						resCorrection  = 0.993609  +0.158418/(sqrt(jetPtImb[it])) + 0.335479 / (jetPtImb[it]);//          0.993609   0.158418   0.335479
					}
					else if ((colli==kPADATA)||(colli==kPAMC)){
						resCorrection = 0.997738 + 0.0221806/(sqrt(jetPtImb[it])) - 0.877999 / (jetPtImb[it]); //C : 0.997738, S : 0.0221806, N : -0.877999 //function derived as a function of gen pt
						//resCorrection = 0.981365 + 0.342746/(sqrt(jetPtImb[it])) - 2.63018 / (jetPtImb[it]); //C : 0.981365, S : 0.342746, N : -2.63018 //function derived as a function of gen pt//derived from l2l3 corrected sample.
						//resCorrection = 0.745753 + 6.91646/(sqrt(jetPtImb[it])) - 33.0167 / (jetPtImb[it]); //C : 0.745753, S : 6.91646, N : -33.0167//function derived as a function of reco pt
					}

				}


				float smearedCorrected  = smeared *l2l3Corr / resCorrection *jetEnergyScale; // residual correction

				if ( smearedCorrected < cutjetPtSkim )  // double cutjetPtSkim = 15; Oct 19th
					continue;
				if ( fabs( jetEtaImb[it] ) > cutjetEtaSkim )   // double cutjetEtaSkim = 3.0; Oct 19th
					continue;
				if ( getDR( jetEtaImb[it], jetPhiImb[it], gj.photonEta, gj.photonPhi) < 0.5 )  // This cut added for consistency ; Oct 19th
					continue;

				mJetPt[nMjet]    = smearedCorrected;
				mJetEta[nMjet]   = jetEtaImb[it];
				mJetPhi[nMjet]   = jetPhiImb[it];
				if  ( mJetPt[nMjet]>0 )
					mJetDphi[nMjet]  =   getAbsDphi(mJetPhi[nMjet], gj.photonPhi) ;
				else
					mJetDphi[nMjet]=-1;

				nMjet++; // < == Important!
			}

			iMix++;
		}
		if ( noSuchEvent )
			continue;

		tgj->Fill();
		newtreeJet->Fill();
		tmixJet->Fill();
		newtreePhoton->Fill();
		treeFullJet->Fill();
		if (   (colli==kHIMC ) || (colli==kPPMC) || (colli==kPAMC) )
			treeGenp->Fill();
	}

	newfile_data->Write();
	//   newfile_data->Close();   // <<=== If there is close() function. writing stucks in the middle of looping.. I don't know why!!
	cout << " Done! "<< endl;
	cout << "    " << eSel<<" out of total "<<eTot<<" events were analyzed."<<endl;
	cout << "Duplicate events  = " << duplicateEvents << endl;
}
コード例 #4
0
int main( int argc, char* argv[] ) {

  if( argc!=4 && argc!=5 && argc!=6 ) {
    std::cout << "USAGE: ./merge_and_setWeights_PhotonJet [dataset] [recoType] [jetAlgo] [analyzerType=\"PhotonJet\"] [flags=\"\"]" << std::endl;
    exit(917);
  }

  std::string dataset = argv[1];
  std::string recoType = argv[2];
  std::string jetAlgo = argv[3];

  std::string analyzerType="PhotonJet";
  if( argc==5 ) {
    std::string analyzerType_str(argv[4]);
    analyzerType = analyzerType_str;
  }

  std::string flags="";
  if( argc==6 ) {
    std::string flags_str(argv[5]);
    flags = flags_str;
  }

  std::string algoName = recoType+jetAlgo;
  if( recoType=="calo") algoName=jetAlgo;
  if( recoType=="jpt" && jetAlgo=="akt5" ) algoName="jptak5";
  if( recoType=="jpt" && jetAlgo=="akt7" ) algoName="jptak7";
  
  tree = new TChain("jetTree");

  EventsAndLumi evlu;
  evlu = addInput( analyzerType, dataset, algoName, flags );

  float weight = getWeight( dataset, evlu.nTotalEvents );

  // and now set the weights
  tree->SetBranchStatus( "eventWeight", 0 );

  Float_t ptPhotReco;
  tree->SetBranchAddress( "ptPhotReco", &ptPhotReco );

  std::string outfilename;
  if( flags!="" )
    outfilename = analyzerType + "_2ndLevelTreeW_"+dataset+"_"+algoName+"_"+flags+".root";
  else
    outfilename = analyzerType + "_2ndLevelTreeW_"+dataset+"_"+algoName+".root";

  TFile* outfile = new TFile(outfilename.c_str(), "recreate");
  outfile->cd();

  TH1F* h1_lumi = new TH1F("lumi", "", 1, 0., 1.);
  h1_lumi->SetBinContent(1, evlu.totalLumi);

  TTree* newTree = tree->CloneTree(0);
  newTree->SetMaxTreeSize(100000000000ULL); //setting max tree size to 100 GB
  Float_t newWeight;
  newTree->Branch( "eventWeight", &newWeight, "newWeight/F" );

  int nentries = tree->GetEntries();
  for( unsigned ientry = 0; ientry<nentries; ++ientry ) {

    tree->GetEntry(ientry);

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

    newWeight = weight;

    if( flags=="GENJETS" && h1_eff_vs_pt!=0 ) {
      Int_t iBin = h1_eff_vs_pt->FindBin( ptPhotReco );
      newWeight *= h1_eff_vs_pt->GetBinContent(iBin);
    }

    newTree->Fill();

  } //for entries

  h1_lumi->Write();
  newTree->Write();
  outfile->Write();
  if( h1_eff_vs_pt!= 0 )
    h1_eff_vs_pt->Write();

  outfile->Close();

  return 0;

}
コード例 #5
0
/*****************************************************************
* root macro to skim MT2trees                                    *
* -> sample and path to shlib given as arguments                 *
*                                                                *
* Pascal Nef                             September 18th, 2011    *  
*****************************************************************/
void MT2treeSkimming(string sample, string shlib, string prefix) {
  	gSystem->Load("libPhysics");
  	gSystem->Load(shlib.c_str());

	string LABEL  = "";
	string file   = sample;
	string outfile = prefix+"/"+sample;

	// log file 
	TString log =sample+".skim.log";
	TString cuts="cuts.skim.log";
	string line="";
	ofstream f_log;
	ofstream f_cuts;
	f_log .open(log.Data(),ios::app);
	f_cuts.open(cuts.Data());
	if(!f_log.is_open()||!f_cuts.is_open()) {cout << "ERROR: cannot open file. " << endl; exit(-1);}

	// cuts --------------------------------------------
  	std::ostringstream cutStream;
	cutStream       << " " 	  
//	  << "misc.MT2 >=50"                                     << "&&" 
//	  << "misc.MET>=30"                                      << "&&"
//	  << "misc.HT > 750 "                                    << "&&"
//	  << "misc.Jet0Pass ==1"                                 << "&&"
//	  << "misc.Jet1Pass ==1"                                 << "&&"
//	  << "misc.SecondJPt  >100"                              << "&&"
//	  << "misc.PassJetID ==1"                                << "&&"
//	  << "misc.Vectorsumpt < 70"                             << "&&"
//	  << "((misc.MinMetJetDPhi >0.3&&NBJets==0)||NBJets>=1)" << "&&"
// Lepton Veto
//	  << "(NEles==0 || ele[0].lv.Pt()<10)"                   << "&&"
//	  << "(NMuons==0 || muo[0].lv.Pt()<10)"                  << "&&"
// Lepton Skim
//	  << "(ele[0].lv.Pt()>10 || muo[0].lv.Pt()>10)"          << "&&"
// LowMT2 ----------------------------
//	  << "misc.LeadingJPt >150"                              << "&&"
//	  << "NBJets >0"                                         << "&&"
//	  << "NJetsIDLoose >=4"                                  << "&&"
// -----------------------------------
//	  << "NJetsIDLoose40 >=3"                                << "&&"
// Photons
	  << "(GenDiLeptPt(0,10,0,1000,false)>=100||GenPhoton[0].Pt()>=100)"  << "&&"
//	  << "(RecoOSDiLeptPt(10,10,0,10000)>=100 ||photon[0].lv.Pt()>=100)"  << "&&"
//	  << "NPhotons >0"  
// Noise
//	  << "misc.HBHENoiseFlag == 0"                           << "&&"
//	  << "misc.CSCTightHaloID==0"                            << "&&"
	  << "misc.CrazyHCAL==0";

	
	TString basecut = cutStream.str();
	string  SEL= "("+basecut+")";
	cout << "Skimming with sel: " << SEL << endl;
	TString cuts_log = basecut.ReplaceAll("&&", "\n");
	f_cuts << "Cuts applied: " <<  cuts_log << endl;
	//  --------------------------------------------


	// files ---------------------------------------
	f_log << "Skimming file: " << file;
	TFile *_file0 = TFile::Open( (file).c_str()); 
	TTree * t = (TTree*) _file0->Get("MassTree");
	TH1F*   h_PUWeights = (TH1F*) _file0->Get("h_PUWeights");
	TH1F*   h_Events    = (TH1F*) _file0->Get("h_Events");
	t->SetMaxTreeSize(19000000000);
	TFile*out = TFile::Open( (outfile).c_str(),"RECREATE");
	TTree *tc = t->CopyTree(SEL.c_str());   
	int nentries = tc->GetEntries();
	f_log << " -> skimmed tree has " << nentries << " entries." <<endl;
	f_log.close();
	f_cuts.close();
	out->Write();
	if(h_PUWeights!=0){
		cout << "writing TH1F h_PUWeights" << endl;
		h_PUWeights->Write();
	}
	if(h_Events!=0){
		cout << "writing TH1F h_Events" << endl;
		h_Events->Write();
	}
	out->Close();
	_file0->Close();
	cout << "Result file: " << outfile << endl;
	// -------------------------------------------------

}
コード例 #6
0
ファイル: skimTree1.C プロジェクト: syuvivida/xtozh_common
void skimTree1::Loop()
{
   if (fChain == 0) return;
  std::string remword=".root";
  size_t pos = inputFile_.find(remword);
  std::string forOutput = inputFile_;  
  if(pos!= std::string::npos)
    forOutput.swap(forOutput.erase(pos,remword.length()));   
  std::string endfix = "_filtered.root";
  std::string outputFile = forOutput + endfix;
   // now open new root file
  TFile* newfile_data = new TFile(outputFile.data(),"recreate");

  // clone tree
  TTree* newtree = fChain->CloneTree(0);
  newtree->SetMaxTreeSize(5000000000);
  cout << "Saving "  << outputFile       << " tree" << endl;

  ofstream fout;
  fout.open("wrong.dat");
  Long64_t nentries = fChain->GetEntriesFast();
  Long64_t nPassEvt=0;
  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if (jentry%100==0)
      printf("%4.1f%% done.\r",(float)jentry/(float)nentries*100.);		

    // require events have CA8jet pt >200

    bool hasCA8jet=false;

    for(int i=0; i < CA8nJet; i++){

	double jet_pt = CA8jetPt->at(i);
      	
	if(jet_pt >200)
	{
		hasCA8jet=true;
		cout<<"ev: "<< jentry << " jet pt: "<<jet_pt<<endl;
		break;
        }


    } // end of loop over ca8 jet




/*
    // require events have two electrons or two muons
    // with mass = 60-120 GeV, pt > 60 GeV

    if(nEle < 2 && nMu < 2)continue;

    bool hasDoubleEle=false;

    for(int i=0; i < nEle; i++){
      
      TLorentzVector i_l4(0,0,0,0);
      i_l4.SetPtEtaPhiM(
			elePt->at(i),
			eleEta->at(i),
			elePhi->at(i),
			eleM->at(i)
			);
      for(int j=0; j< i; j++){
	
	TLorentzVector j_l4(0,0,0,0);
	j_l4.SetPtEtaPhiM(
			  elePt->at(j),
			  eleEta->at(j),
			  elePhi->at(j),
			  eleM->at(j)
			  );
	double Zpt = (i_l4+j_l4).Pt();
	double ZM = (i_l4+j_l4).M();

	if(Zpt > 60 && ZM > 60 && ZM < 120)
	  {
	    hasDoubleEle=true;
	    break;
	  }

      }
    } // end of double loop over electrons

    bool hasDoubleMuo=false;
    for(int i=0; i < nMu; i++){
      
      TLorentzVector i_l4(0,0,0,0);
      i_l4.SetPtEtaPhiM(
			muPt->at(i),
			muEta->at(i),
			muPhi->at(i),
			muM->at(i)
			);
      for(int j=0; j< i; j++){
	
	TLorentzVector j_l4(0,0,0,0);
	j_l4.SetPtEtaPhiM(
			  muPt->at(j),
			  muEta->at(j),
			  muPhi->at(j),
			  muM->at(j)
			  );
	double Zpt = (i_l4+j_l4).Pt();
	double ZM = (i_l4+j_l4).M();

	if(Zpt > 60 && ZM > 60 && ZM < 120)
	  {
	    hasDoubleMuo=true;
	    break;
	  }

      }
    } // end of double loop over double muons

    if(!hasDoubleEle && !hasDoubleMuo)continue;   
*/
    if(!hasCA8jet)continue;
    newtree->Fill();
    nPassEvt++;
  }
  
  // newtree->Print();
  newtree->AutoSave();
  delete newfile_data;
  fout.close();


 cout << "nentries = " << nentries << endl;
 cout << "Number of passed events = " << nPassEvt << endl;
 cout << "Reduction rate = " << (double)nPassEvt/(double)nentries << endl;

}
コード例 #7
0
void skimTree1_2ndSkim::Loop()
{
   if (fChain == 0) return;
  std::string remword=".root";
  size_t pos = inputFile_.find(remword);
  std::string forOutput = inputFile_;  
  if(pos!= std::string::npos)
    forOutput.swap(forOutput.erase(pos,remword.length()));   
  std::string endfix = "_filtered.root";
  std::string outputFile = forOutput + endfix;
   // now open new root file
  TFile* newfile_data = new TFile(outputFile.data(),"recreate");

  // clone tree
  TTree* newtree = fChain->CloneTree(0);
  newtree->SetMaxTreeSize(5000000000);
  cout << "Saving "  << outputFile       << " tree" << endl;

  ofstream fout;
  fout.open("wrong.dat");
  Long64_t nentries = fChain->GetEntriesFast();
  Long64_t nPassEvt=0;
  Long64_t nbytes = 0, nb = 0;
  for (Long64_t jentry=0; jentry<nentries;jentry++) {
    Long64_t ientry = LoadTree(jentry);
    if (ientry < 0) break;
    nb = fChain->GetEntry(jentry);   nbytes += nb;
    if (jentry%100==0)
      printf("%4.1f%% done.\r",(float)jentry/(float)nentries*100.);		

    // require events have CA8jet pt >200
/*
    bool hasCA8jet=false;

    for(int i=0; i < CA8nJet; i++){

	double jet_pt = CA8jetPt->at(i);
      	
	if(jet_pt >200)
	{
		hasCA8jet=true;
		cout<<"ev: "<< jentry << " jet pt: "<<jet_pt<<endl;
		break;
        }


    } // end of loop over ca8 jet
*/
    // require gen muon (status=3) <- W <- top

    //           cout<<"ev: "<< jentry <<endl;

    bool hasGenMuon=false;

    for(int i=0; i < nGenPar; i++){

	if(genParId->at(i) !=13 && genParId->at(i) != -13  ){continue;}
	if(genParSt->at(i)!=3){continue;}

	       //cout<<"ev: "<< jentry <<endl;
               //cout<<" ID : "<< genParId->at(i)<<" status: " <<genParSt->at(i)<<endl;

	int mother_index = genMo1->at(i);
        if(genParId->at(mother_index) !=24 && genParId->at(mother_index) != -24  ){continue;}

              //cout<<" mother ID : "<< genParId->at(mother_index)<<endl;

        int grandmother_index = genMo1->at(mother_index);
        if(genParId->at(grandmother_index) !=6 && genParId->at(grandmother_index) != -6  ){continue;}

              //cout<<" grand mother ID : "<< genParId->at(grandmother_index)<<endl;
    
                hasGenMuon=true;
//                cout<<"ev: "<< jentry << " jet pt: "<<jet_pt<<endl;
                break;


    } // end of loop over gen




    if(!hasGenMuon)continue;
    newtree->Fill();
    nPassEvt++;
  }
  
  // newtree->Print();
  newtree->AutoSave();
  delete newfile_data;
  fout.close();


 cout << "nentries = " << nentries << endl;
 cout << "Number of passed events = " << nPassEvt << endl;
 cout << "Reduction rate = " << (double)nPassEvt/(double)nentries << endl;

}
コード例 #8
0
void dimuonSkim(const TString configFile, const TString inputFile, const TString outputFile)
{
       std::cout<<"running dimuonSkim()"   <<std::endl;
       std::cout<<"configFile  = "<< configFile.Data() <<std::endl;
       std::cout<<"inputFile   = "<< inputFile.Data() <<std::endl;
       std::cout<<"outputFile  = "<< outputFile.Data() <<std::endl;

       InputConfiguration configInput = InputConfigurationParser::Parse(configFile.Data());
       CutConfiguration configCuts = CutConfigurationParser::Parse(configFile.Data());

       if (!configInput.isValid) {
           std::cout << "Input configuration is invalid." << std::endl;
           std::cout << "exiting" << std::endl;
           return;
       }
       if (!configCuts.isValid) {
           std::cout << "Cut configuration is invalid." << std::endl;
           std::cout << "exiting" << std::endl;
           return;
       }

       // input configuration
       int collisionType = configInput.proc[INPUT::kSKIM].i[INPUT::k_collisionType];
       std::string treePath = configInput.proc[INPUT::kSKIM].s[INPUT::k_treePath];

       // set default values
       if (treePath.size() == 0)  treePath = "ggHiNtuplizer/EventTree";

       // verbose about input configuration
       std::cout<<"Input Configuration :"<<std::endl;
       std::cout << "collisionType = " << collisionType << std::endl;
       const char* collisionName =  getCollisionTypeName((COLL::TYPE)collisionType).c_str();
       std::cout << "collision = " << collisionName << std::endl;
       std::cout << "treePath = " << treePath.c_str() << std::endl;

       // cut configuration
       float cut_vz = configCuts.proc[CUTS::kSKIM].obj[CUTS::kEVENT].f[CUTS::EVT::k_vz];
       int cut_pcollisionEventSelection = configCuts.proc[CUTS::kSKIM].obj[CUTS::kEVENT].i[CUTS::EVT::k_pcollisionEventSelection];
       int cut_pPAprimaryVertexFilter = configCuts.proc[CUTS::kSKIM].obj[CUTS::kEVENT].i[CUTS::EVT::k_pPAprimaryVertexFilter];
       int cut_pBeamScrapingFilter = configCuts.proc[CUTS::kSKIM].obj[CUTS::kEVENT].i[CUTS::EVT::k_pBeamScrapingFilter];

       int cut_nMu = configCuts.proc[CUTS::kSKIM].obj[CUTS::kMUON].i[CUTS::MUO::k_nMu];

       // bool isMC = collisionIsMC((COLL::TYPE)collisionType);
       bool isHI = collisionIsHI((COLL::TYPE)collisionType);
       bool isPP = collisionIsPP((COLL::TYPE)collisionType);

       // verbose about cut configuration
       std::cout<<"Cut Configuration :"<<std::endl;
       std::cout<<"cut_vz = "<< cut_vz <<std::endl;
       if (isHI) {
           std::cout<<"cut_pcollisionEventSelection = "<< cut_pcollisionEventSelection <<std::endl;
       }
       else {   // PP
           std::cout<<"cut_pPAprimaryVertexFilter = "<< cut_pPAprimaryVertexFilter <<std::endl;
           std::cout<<"cut_pBeamScrapingFilter = "<< cut_pBeamScrapingFilter <<std::endl;
       }

       std::cout<<"cut_nMu = "<<cut_nMu<<std::endl;

       std::vector<std::string> inputFiles = InputConfigurationParser::ParseFiles(inputFile.Data());

       std::cout<<"input ROOT files : num = "<<inputFiles.size()<< std::endl;
       std::cout<<"#####"<< std::endl;
       for (std::vector<std::string>::iterator it = inputFiles.begin() ; it != inputFiles.end(); ++it) {
           std::cout<<(*it).c_str()<< std::endl;
       }
       std::cout<<"##### END #####"<< std::endl;

       TChain* treeHLT   = new TChain("hltanalysis/HltTree");
       TChain* treeggHiNtuplizer  = new TChain("ggHiNtuplizer/EventTree");
       TChain* treeHiEvt = new TChain("hiEvtAnalyzer/HiTree");
       TChain* treeSkim  = new TChain("skimanalysis/HltTree");
       TChain* treeHiForestInfo = new TChain("HiForest/HiForestInfo");

       for (std::vector<std::string>::iterator it = inputFiles.begin() ; it != inputFiles.end(); ++it) {
          treeHLT->Add((*it).c_str());
          treeggHiNtuplizer->Add((*it).c_str());
          treeHiEvt->Add((*it).c_str());
          treeSkim->Add((*it).c_str());
          treeHiForestInfo->Add((*it).c_str());
       }

       HiForestInfoController hfic(treeHiForestInfo);
       std::cout<<"### HiForestInfo Tree ###"<< std::endl;
       hfic.printHiForestInfo();
       std::cout<<"###"<< std::endl;

       treeHLT->SetBranchStatus("*",0);     // disable all branches
       treeHLT->SetBranchStatus("HLT_HI*SinglePhoton*Eta*",1);     // enable photon branches
       treeHLT->SetBranchStatus("HLT_HI*DoublePhoton*Eta*",1);     // enable photon branches
       treeHLT->SetBranchStatus("*DoubleMu*",1);                      // enable muon branches
       treeHLT->SetBranchStatus("HLT_HIL1Mu*",1);                     // enable muon branches
       treeHLT->SetBranchStatus("HLT_HIL2Mu*",1);                     // enable muon branches
       treeHLT->SetBranchStatus("HLT_HIL3Mu*",1);                     // enable muon branches
       
       // specify explicitly which branches to store, do not use wildcard
       treeHiEvt->SetBranchStatus("*",1);

       // specify explicitly which branches to store, do not use wildcard
       treeSkim->SetBranchStatus("*",0);

       Int_t pcollisionEventSelection;  // this filter is used for HI.
       if (isHI) {
           treeSkim->SetBranchStatus("pcollisionEventSelection",1);
           if (treeSkim->GetBranch("pcollisionEventSelection")) {
               treeSkim->SetBranchAddress("pcollisionEventSelection",&pcollisionEventSelection);
           }
           else {   // overwrite to default
               pcollisionEventSelection = 1;
               std::cout<<"could not get branch : pcollisionEventSelection"<<std::endl;
               std::cout<<"set to default value : pcollisionEventSelection = "<<pcollisionEventSelection<<std::endl;
           }
       }
       else {
           pcollisionEventSelection = 0;    // default value if the collision is not HI, will not be used anyway.
       }
       Int_t pPAprimaryVertexFilter;    // this filter is used for PP.
       if (isPP) {
           treeSkim->SetBranchStatus("pPAprimaryVertexFilter",1);
           if (treeSkim->GetBranch("pPAprimaryVertexFilter")) {
               treeSkim->SetBranchAddress("pPAprimaryVertexFilter",&pPAprimaryVertexFilter);
           }
           else {   // overwrite to default
               pPAprimaryVertexFilter = 1;
               std::cout<<"could not get branch : pPAprimaryVertexFilter"<<std::endl;
               std::cout<<"set to default value : pPAprimaryVertexFilter = "<<pPAprimaryVertexFilter<<std::endl;
           }
       }
       else {
           pPAprimaryVertexFilter = 0;      // default value if the collision is not PP, will not be used anyway.
       }
       Int_t pBeamScrapingFilter;   // this filter is used for PP.
       if (isPP) {
           treeSkim->SetBranchStatus("pBeamScrapingFilter",1);
           if (treeSkim->GetBranch("pBeamScrapingFilter")) {
               treeSkim->SetBranchAddress("pBeamScrapingFilter",&pBeamScrapingFilter);
           }
           else {   // overwrite to default
               pBeamScrapingFilter = 1;
               std::cout<<"could not get branch : pBeamScrapingFilter"<<std::endl;
               std::cout<<"set to default value : pBeamScrapingFilter = "<<pBeamScrapingFilter<<std::endl;
           }
       }
       else {
           pBeamScrapingFilter = 0;     // default value if the collision is not PP, will not be used anyway.
       }

       ggHiNtuplizer ggHi;
       ggHi.setupTreeForReading(treeggHiNtuplizer);
       
       hiEvt hiEvt;
       hiEvt.setupTreeForReading(treeHiEvt);

       TFile* output = new TFile(outputFile,"RECREATE");
       TTree *configTree = setupConfigurationTreeForWriting(configCuts);

       // output tree variables
       TTree *outputTreeHLT           = treeHLT->CloneTree(0);
       outputTreeHLT->SetName("hltTree");
       outputTreeHLT->SetTitle("subbranches of hltanalysis/HltTree");
       TTree *outputTreeggHiNtuplizer = treeggHiNtuplizer->CloneTree(0);
       TTree *outputTreeHiEvt = treeHiEvt->CloneTree(0);
       outputTreeHiEvt->SetName("HiEvt");
       outputTreeHiEvt->SetTitle("subbranches of hiEvtAnalyzer/HiTree");
       TTree* outputTreeSkim  = treeSkim->CloneTree(0);
       outputTreeSkim->SetName("skim");
       outputTreeSkim->SetTitle("subbranches of skimanalysis/HltTree");
       TTree* outputTreeHiForestInfo = treeHiForestInfo->CloneTree(0);
       outputTreeHiForestInfo->SetName("HiForestInfo");
       outputTreeHiForestInfo->SetTitle("first entry of HiForest/HiForestInfo");
       
       outputTreeHLT->SetMaxTreeSize(MAXTREESIZE);
       outputTreeggHiNtuplizer->SetMaxTreeSize(MAXTREESIZE);
       outputTreeHiEvt->SetMaxTreeSize(MAXTREESIZE);
       outputTreeHiForestInfo->SetMaxTreeSize(MAXTREESIZE);

       // write HiForestInfo
       treeHiForestInfo->GetEntry(0);
       outputTreeHiForestInfo->Fill();

       TTree *diMuonTree = new TTree("dimuon","muon pairs");
       diMuonTree->SetMaxTreeSize(MAXTREESIZE);

       dimuon diMu;
       diMu.branchDiMuonTree(diMuonTree);

       EventMatcher* em = new EventMatcher();
       Long64_t duplicateEntries = 0;

       Long64_t entries = treeggHiNtuplizer->GetEntries();
       Long64_t entriesPassedEventSelection = 0;
       Long64_t entriesAnalyzed = 0;
       std::cout << "entries = " << entries << std::endl;
       std::cout<< "Loop : " << treePath.c_str() <<std::endl;
       for (Long64_t j_entry=0; j_entry<entries; ++j_entry)
       {
           if (j_entry % 20000 == 0)  {
             std::cout << "current entry = " <<j_entry<<" out of "<<entries<<" : "<<std::setprecision(2)<<(double)j_entry/entries*100<<" %"<<std::endl;
           }

           treeHLT->GetEntry(j_entry);
           treeggHiNtuplizer->GetEntry(j_entry);
           treeHiEvt->GetEntry(j_entry);
           treeSkim->GetEntry(j_entry);

           bool eventAdded = em->addEvent(ggHi.run,ggHi.lumis,ggHi.event,j_entry);
           if(!eventAdded) // this event is duplicate, skip this one.
           {
               duplicateEntries++;
               continue;
           }

           // event selection
           if (!(TMath::Abs(hiEvt.vz) < cut_vz))  continue;
           if (isHI) {
               if ((pcollisionEventSelection < cut_pcollisionEventSelection))  continue;
           }
           else {
               if (pPAprimaryVertexFilter < cut_pPAprimaryVertexFilter || pBeamScrapingFilter < cut_pBeamScrapingFilter)  continue;
           }
           entriesPassedEventSelection++;

           // skip if there are no muon pairs to study
           if(ggHi.nMu < cut_nMu)  continue;
           entriesAnalyzed++;

           diMu.makeDiMuonPairs(ggHi);

           outputTreeHLT->Fill();
           outputTreeggHiNtuplizer->Fill();
           outputTreeHiEvt->Fill();
           outputTreeSkim->Fill();
           diMuonTree->Fill();
       }
       std::cout<< "Loop ENDED : " << treePath.c_str() <<std::endl;
       std::cout << "entries            = " << entries << std::endl;
       std::cout << "duplicateEntries   = " << duplicateEntries << std::endl;
       std::cout << "entriesPassedEventSelection   = " << entriesPassedEventSelection << std::endl;
       std::cout << "entriesAnalyzed    = " << entriesAnalyzed << std::endl;
       std::cout << "outputTreeHLT->GetEntries()           = " << outputTreeHLT->GetEntries() << std::endl;
       std::cout << "outputTreeggHiNtuplizer->GetEntries() = " << outputTreeggHiNtuplizer->GetEntries() << std::endl;
       std::cout << "outputTreeHiEvt->GetEntries() = " << outputTreeHiEvt->GetEntries() << std::endl;
       std::cout << "outputTreeSkim->GetEntries()  = " << outputTreeSkim->GetEntries() << std::endl;
       std::cout << "diMuonTree->GetEntries()          = " << diMuonTree->GetEntries() << std::endl;

       // overwrite existing trees
       outputTreeHLT->Write("", TObject::kOverwrite);
       outputTreeggHiNtuplizer->Write("", TObject::kOverwrite);
       outputTreeHiEvt->Write("", TObject::kOverwrite);
       diMuonTree->Write("", TObject::kOverwrite);

       configTree->Write("", TObject::kOverwrite);

       output->Write("", TObject::kOverwrite);
       output->Close();

       std::cout<<"dimuonSkim() - END"   <<std::endl;
}
コード例 #9
0
ファイル: skimTree.C プロジェクト: ramankhurana/usercode
void skimTree(std::string inputFile_)
{

  
  TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(inputFile_.data());
  if (!f) {
    f = new TFile(inputFile_.data());
    f->cd(Form("%s:/tree",inputFile_.data()));
  }
  TTree* fChain = (TTree*)gDirectory->Get("tree");
  cout << "Input file is " << inputFile_ << endl;

  // rename the output file
  std::string remword=".root";
  size_t pos = inputFile_.find(remword);
  std::string forOutput = inputFile_;  
  if(pos!= std::string::npos)
    forOutput.swap(forOutput.erase(pos,remword.length()));   
  std::string endfix = "_filteredtree.root";
  std::string outputFile = forOutput + endfix;
  // now open new root file
  TFile* newfile_data = new TFile(outputFile.data(),"recreate");
  cout << "Output file " << outputFile << endl;

  // clone tree
  TTree* newtree = fChain->CloneTree(0);
  newtree->SetMaxTreeSize(4000000000);
  cout << "Saving "  << endfix << " tree" << endl;

  Long64_t nentries = fChain->GetEntries();
  cout << "nentries = " << nentries << endl;

  Int_t           eventNo=-1;
  Int_t           runNo=-1;

  vector<int>*     trigResults;
  vector<string>*  trigName;


  bool isData=false;
  if(forOutput.find("DoubleElectron")!= std::string::npos || forOutput.find("DoubleMu")!= std::string::npos)
    isData=true;


  fChain->SetBranchAddress("EvtInfo_EventNum",&eventNo);
  fChain->SetBranchAddress("EvtInfo_RunNum",&runNo);
  if(isData){
    fChain->SetBranchAddress("trigResults", &trigResults);
    fChain->SetBranchAddress("trigName", &trigName);
  }

  Long64_t nlines=0;

  vector<runInfo> myList;

  ifstream fin;

  if(forOutput.find("DoubleElectron")!= std::string::npos)
    fin.open("/data4/syu/52X_533_validation/DoubleElectron_common.txt");
  else if(forOutput.find("DoubleMu")!= std::string::npos)
    fin.open("/data4/syu/52X_533_validation/DoubleMu_common.txt");
  else if(forOutput.find("GluGlu")!= std::string::npos)
    fin.open("/data4/syu/52X_533_validation/MC_common.txt");
  runInfo tempInfo;
  fin >> tempInfo.run >> tempInfo.evt;
  while(!fin.eof())
    {
      nlines++;
      myList.push_back(tempInfo);
      fin >> tempInfo.run >> tempInfo.evt;
    }
  fin.close();

  cout << "There are " << nlines << " lines" << endl;

  ofstream fout;
  fout.open(Form("%s_updated",forOutput.data()));

  Long64_t nPassEvt=0;

  for (Long64_t jentry=0; jentry<nentries;jentry++) {

    
    eventNo = -1;
    runNo = -1;
    trigName = 0;
    trigResults = 0;
    
    fChain->GetEntry(jentry);


    bool passTrigger=false;
    if(isData){

      for(int it=0; it< trigName->size(); it++)
	{
	  std::string thisTrig= trigName->at(it);
	  int results = trigResults->at(it);
//   	  cout << thisTrig << "\t" << results << endl;

	  if(forOutput.find("DoubleElectron")!= std::string::npos && 
	     thisTrig.find("HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL")
	     != std::string::npos && results==1)
	    {
	      passTrigger=true;
// 	      cout << "Find HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL" << endl;
	      break;
	    }	  

	  if(forOutput.find("DoubleMu")!= std::string::npos && thisTrig.find("HLT_Mu17_Mu8")!= std::string::npos && results==1)
	    {
	      passTrigger=true;
// 	      cout << "Find HLT_Mu17_Mu8" << endl;
	      break;
	    }

	  if(forOutput.find("DoubleMu")!= std::string::npos && thisTrig.find("HLT_Mu17_TkMu8")!= std::string::npos && results==1)
	    {
	      passTrigger=true;
// 	      cout << "Find HLT_Mu17_TkMu8" << endl;
	      break;
	    }

	}

    }
    if(!passTrigger && isData)continue;

    bool pass=false;

    runInfo thisInfo;
    thisInfo.run = runNo;
    thisInfo.evt = eventNo;

    vector<runInfo>::const_iterator location = std::find(myList.begin(), myList.end(), thisInfo);
    if(location != myList.end()) pass=true;

    if(!pass)continue;
    newtree->Fill();
    nPassEvt++;
    fout << runNo << "\t" << eventNo << endl;

    if (jentry%100==0)
      printf("%4.1f%% done.\r",(float)jentry/(float)nentries*100.);		

  }
 
  newtree->Print();
  newtree->AutoSave();
  delete newfile_data;

  fout.close();

  cout << "Number of passed events = " << nPassEvt << endl;
}