当前位置: 首页>>代码示例>>C++>>正文


C++ TTree::GetEntryWithIndex方法代码示例

本文整理汇总了C++中TTree::GetEntryWithIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::GetEntryWithIndex方法的具体用法?C++ TTree::GetEntryWithIndex怎么用?C++ TTree::GetEntryWithIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TTree的用法示例。


在下文中一共展示了TTree::GetEntryWithIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CompareTrees

void CompareTrees() {
   // The two TTrees created above are compared.
   // The subset of entries in the small TTree must be identical
   // to the entries in the original TTree.
   
   TFile *f = new TFile("treeparent.root");
   TTree *T  = (TTree*)f->Get("T");
   TFile *ff = new TFile("treefriend.root");
   TTree *TF = (TTree*)ff->Get("TF");
   Int_t fRun,fEvent;
   Float_t fx,fy,fz;
   T->SetBranchAddress("Run",&Run);
   T->SetBranchAddress("Event",&Event);
   T->SetBranchAddress("x",&x);
   T->SetBranchAddress("y",&y);
   T->SetBranchAddress("z",&z);
   TF->SetBranchAddress("Run",&fRun);
   TF->SetBranchAddress("Event",&fEvent);
   TF->SetBranchAddress("x",&fx);
   TF->SetBranchAddress("y",&fy);
   TF->SetBranchAddress("z",&fz);
   T->AddFriend(TF);
   
   Long64_t nentries = T->GetEntries();
   Int_t nok = 0;
   for (Long64_t i=0;i<nentries;i++) {
      T->GetEntry(i);
      if (fRun == Run && fEvent==Event && x==fx && y==fy &&z==fz) {
         nok++;
      } else {
         if (TF->GetEntryWithIndex(Run,Event) > 0) {
            if (i <100) printf("i=%lld, Run=%d, Event=%d, x=%g, y=%g, z=%g,  : fRun=%d, fEvent=%d, fx=%g, fy=%g, fz=%g\n",i,Run,Event,x,y,z,fRun,fEvent,fx,fy,fz);
         } 
      } 
   }
   printf("nok = %d, fentries=%lld\n",nok,TF->GetEntries());

   delete f;
   delete ff;
}
开发者ID:adevress,项目名称:root-1,代码行数:40,代码来源:treefriend.C

示例2: calculateEff

void calculateEff(int nArguments) {
	string configSysName = Form("share/file.txt");
	ifstream configSystematic(configSysName.c_str());
	vector<string> fileNames;
	vector<string> treeNames;
	string fileName, treeName;
	while (!configSystematic.eof()) {
		configSystematic >> fileName >> treeName;
		if ((fileName.compare(0, 1, "#") == 0))
			continue;

		if (!configSystematic.good())
			break;

		fileNames.push_back(fileName);
		treeNames.push_back(treeName);
	}
	ofstream fout;
	fout.open("share/table.txt");
	fout << left << setw(60) << "#Systematics" << "\t\t" << setw(25) << "purity(corr,rec)(B/A+B)" << "\t\t" << setw(25) << "accept(corr,fid)(B/B'+C)" << "\t\t" << setw(25) << "eff_{fid}=a/p"
			<< setw(25) << "N_{fid}" << setw(25) << "N_{gen}" << endl;
	for (int iSys = 0; iSys < fileNames.size(); ++iSys) {
		bool c_debug(false);

		if (nArguments > 2) {
			cerr << "\n\t[INFO]\t" << "* * * main applyFiducialCut starts * * *" << endl;
			applyFiducialCut(fileNames.at(iSys).c_str());
			cerr << "\n\t[INFO]\t" << "* * * main applyFiducialCut finishes * * *" << endl;
		} else {
			cerr << "\n\t[INFO]\t" << "* * * main SKIP applyFiducialCut * * *" << endl;
		}

		/* nominal Trees */
		TFile* nominalFile = new TFile("../data/2016-04-05/reprocess/reprocess_1j1b_v11_20160405.root");
		TTree *nominalTree = (TTree*) nominalFile->Get(treeNames.at(iSys).c_str());
		cerr << "\t[INFO]\t" << "Reco  Tree " << nominalTree->GetName() << " " << nominalTree->GetEntries() << endl;
		TFile* particleFile = new TFile(Form("root/fiducialRegion_%s.root", fileNames.at(iSys).c_str()));
		TTree* particleTree = (TTree*) particleFile->Get("particleLevel");
		cerr << "\t[INFO]\t" << "Truth Tree " << particleTree->GetName() << " " << particleTree->GetEntries() << endl;

		Int_t runRecNominal;
		Int_t eventRecNominal;
		Float_t EventWeight, EventWeight_noPU, weight_leptonSF, weight_bTagSF_77, mc_weight;

		nominalTree->SetBranchAddress("mcChannelNumber", &runRecNominal);
		nominalTree->SetBranchAddress("EventNumber", &eventRecNominal);
		nominalTree->SetBranchAddress("EventWeight_noPU", &EventWeight_noPU);
		nominalTree->SetBranchAddress("EventWeight", &EventWeight);
		nominalTree->SetBranchAddress("weight_leptonSF", &weight_leptonSF);
		nominalTree->SetBranchAddress("weight_bTagSF_77", &weight_bTagSF_77);
		nominalTree->SetBranchAddress("weight_mc", &mc_weight);

		UInt_t runParticle;
		ULong64_t eventParticle;
		Float_t weight_mc;
		particleTree->SetBranchAddress("mcChannelNumber", &runParticle);
		particleTree->SetBranchAddress("eventNumber", &eventParticle);
		particleTree->SetBranchAddress("weight_mc", &weight_mc);

		/************/
		/* counting */
		/************/

		/* build particleTree index */
		particleTree->BuildIndex("mcChannelNumber", "eventNumber");
		nominalTree->BuildIndex("mcChannelNumber", "EventNumber");

		double totalEventWeight(0.), totalOverlapEventWeight(0.), totalOverlapweight_mc(0.), totalweight_mc(0.), totalOverlapmc_weight(0.);
		double ExperimentalWeight(0.);
		ofstream bugstr;
		if (c_debug)
			bugstr.open("share/bug.log");
		bool useWeight(true);
		for (Long64_t ievt = 0; ievt < (c_debug ? 10 : nominalTree->GetEntries()); ievt++) {
			nominalTree->GetEntry(ievt);
			ExperimentalWeight = (EventWeight_noPU == 0) ? 0 : (EventWeight / EventWeight_noPU) * weight_leptonSF * weight_bTagSF_77 * mc_weight;
			totalEventWeight += useWeight ? ExperimentalWeight : 1; // A+B
			if (particleTree->GetEntryWithIndex(runRecNominal, eventRecNominal) > 0) {
				totalOverlapEventWeight += useWeight ? ExperimentalWeight : 1; // B
				totalOverlapmc_weight += useWeight ? mc_weight : 1;
				if (c_debug)
					bugstr << "recon matched " << runRecNominal << " " << eventRecNominal << " totalOverlapmc_weight=" << totalOverlapmc_weight << endl;
			} else {
				if (c_debug)
					bugstr << "recon notmatc " << runRecNominal << " " << eventRecNominal << " totalOverlapmc_weight=" << totalOverlapmc_weight << endl;
			}
		}
		int dupl(0);
		vector<int> duplevts;
		ifstream ifile(Form("share/%s.overlap.dupEvt", fileNames.at(iSys).c_str()));
		if (ifile) {
			int evt;
			while (!ifile.eof()) {
				ifile >> evt;
				if (!ifile.good())
					break;
				duplevts.push_back(evt);
			}
		}
		for (Long64_t ievt = 0; ievt < (c_debug ? 10 : particleTree->GetEntries()); ievt++) {
//.........这里部分代码省略.........
开发者ID:chnzhangrui,项目名称:WtAna,代码行数:101,代码来源:main.C


注:本文中的TTree::GetEntryWithIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。