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


C++ TClonesArray::Write方法代码示例

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


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

示例1: evtFile

bool
convertEvtToTree(const string&  evtFileName              = "testEvents.evt",
                 const string&  outFileName              = "testEvents.root",
                 const long int maxNmbEvents             = -1,
                 const string&  outTreeName              = "rootPwaEvtTree",
                 const string&  prodKinPartNamesObjName  = "prodKinParticles",
                 const string&  prodKinMomentaLeafName   = "prodKinMomenta",
                 const string&  decayKinPartNamesObjName = "decayKinParticles",
                 const string&  decayKinMomentaLeafName  = "decayKinMomenta",
                 const bool     debug                    = false)
{
	// open input file
	printInfo << "opening input file '" << evtFileName << "'" << endl;
	ifstream evtFile(evtFileName.c_str());
	if (not evtFile or not evtFile.good()) {
		printWarn << "cannot open input file '" << evtFileName << "'" << endl;
		return false;
	}

	// create output file
	printInfo << "creating output file '" << outFileName << "'" << endl;
	TFile* outFile = TFile::Open(outFileName.c_str(), "RECREATE");
	if (not outFile) {
		printErr << "cannot open output file '" << outFileName << "'" << endl;
		return false;
	}

	// create tree
	TTree* tree = new TTree(outTreeName.c_str(), outTreeName.c_str());
	if (not tree) {
		printErr << "problems creating tree '" << outTreeName << "' "
		         << "in file '" << outFileName << "'" << endl;
		return false;
	}

	// doit
	TClonesArray* prodKinPartNames  = new TClonesArray("TObjString");
	TClonesArray* decayKinPartNames = new TClonesArray("TObjString");
	const bool    success           = fillTreeFromEvt(evtFile, *tree,
	                                                  *prodKinPartNames, *decayKinPartNames,
	                                                  maxNmbEvents,
	                                                  prodKinMomentaLeafName, decayKinMomentaLeafName,
	                                                  debug);
	tree->Write();
	prodKinPartNames->Write (prodKinPartNamesObjName.c_str (), TObject::kSingleKey);
	decayKinPartNames->Write(decayKinPartNamesObjName.c_str(), TObject::kSingleKey);

	outFile->Close();
	if (success)
		printSucc << "wrote events to file '" << outFileName << "'" << endl;
	else
		printWarn << "problems processing events" << endl;
	return success;
}
开发者ID:armingensler,项目名称:ROOTPWA,代码行数:54,代码来源:convertEvtToTree.C

示例2: uDstChain

void
fillUdstDataIntoMassBins_example(const string&      inFileNamePattern = "fillUdstDataIntoMassBins_example.root",
                                 const string&      dirName           = "./test",
                                 const long int     maxNmbEvents      = -1,
                                 const unsigned int nmbMassBins       = 50,
                                 const double       massBinWidth      = 40,   // [MeV/c^2]
                                 const double       massRangeMin      = 500,  // [MeV/c^2]
                                 const string&      uDstTreeName      = "pwaDataTree",
                                 const string&      pwaTreeName       = "rootPwaEvtTree",
                                 const long int     treeCacheSize     = 25000000,  // 25 MByte ROOT tree read cache
                                 const bool         debug             = false)
{
	const string prodKinPartNamesObjName  = "prodKinParticles";
	const string prodKinMomentaLeafName   = "prodKinMomenta";
	const string decayKinPartNamesObjName = "decayKinParticles";
	const string decayKinMomentaLeafName  = "decayKinMomenta";

	TStopwatch timer;
	timer.Start();

	printInfo << "reading uDST file(s) '" << inFileNamePattern << "'" << endl
	          << "    writing " << nmbMassBins << " mass bins in mass interval "
	          << "[" << massRangeMin << ", " << massRangeMin + nmbMassBins * massBinWidth << "] "
	          << "MeV/c^2 to '" << dirName << "'" << endl
	          << "    reading uDST data from tree '" << uDstTreeName << "'" << endl
	          << "    writing PWA data to tree '" << pwaTreeName << "'" << endl;

	// create chain and connect tree leaf variables to branches
	TChain uDstChain(uDstTreeName.c_str());
	if (uDstChain.Add(inFileNamePattern.c_str()) < 1)
		printWarn << "no events in uDST input file(s) '" << inFileNamePattern << "'" << endl;
	const long int nmbEventsUdstChain = uDstChain.GetEntries();
	uDstChain.GetListOfFiles()->ls();

	// !!! <channel-dependent part> !!!
	// connect tree leafs
	TLorentzVector* photons[4] = {0, 0, 0, 0};
	TLorentzVector* piMinus    = 0;
	TLorentzVector* beam       = 0;
	TLorentzVector* recoil     = 0;
	uDstChain.SetBranchAddress("gamma1", &(photons[0]));
	uDstChain.SetBranchAddress("gamma2", &(photons[1]));
	uDstChain.SetBranchAddress("gamma3", &(photons[2]));
	uDstChain.SetBranchAddress("gamma4", &(photons[3]));
	uDstChain.SetBranchAddress("pi_out", &piMinus);
	uDstChain.SetBranchAddress("pi_in",  &beam);
	uDstChain.SetBranchAddress("proton", &recoil);
	uDstChain.SetCacheSize(treeCacheSize);
	uDstChain.AddBranchToCache("gamma1", true);
	uDstChain.AddBranchToCache("gamma2", true);
	uDstChain.AddBranchToCache("gamma3", true);
	uDstChain.AddBranchToCache("gamma4", true);
	uDstChain.AddBranchToCache("pi_out", true);
	uDstChain.AddBranchToCache("pi_in",  true);
	uDstChain.AddBranchToCache("proton", true);
	uDstChain.StopCacheLearningPhase();
	// !!! </channel-dependent part> !!!

	// create directories and .root files
	vector<TFile*> pwaDataFiles;
	vector<TTree*> pwaDataTrees;
	if (not createMassBinFiles(pwaDataFiles, pwaDataTrees, dirName, nmbMassBins, massBinWidth,
	                           massRangeMin, pwaTreeName)) {
		printErr << "there were problems creating the mass bin directories/files. aborting." << endl;
		return;
	}
	printSucc << "created " << pwaDataFiles.size() << " directories/files" << endl;

	// write arrays with production and decay particle names to root files
	{
		TClonesArray prodKinPartNames ("TObjString", 1);
		TClonesArray decayKinPartNames("TObjString", 3);

		// !!! <channel-dependent part> !!!
		new (prodKinPartNames [0]) TObjString("pi-"); // beam particle
		new (decayKinPartNames[0]) TObjString("pi0");
		new (decayKinPartNames[1]) TObjString("pi0");
		new (decayKinPartNames[2]) TObjString("pi-");
		// !!! </channel-dependent part> !!!

		for (unsigned int i = 0; i < pwaDataFiles.size(); ++i) {
			pwaDataFiles[i]->cd();
			prodKinPartNames.Write (prodKinPartNamesObjName.c_str (), TObject::kSingleKey);
			decayKinPartNames.Write(decayKinPartNamesObjName.c_str(), TObject::kSingleKey);
		}
		printSucc << "wrote particle name arrays to all files. "
		          << "beam = 'pi-', decay = {'pi0', 'pi0', 'pi-'}." << endl;
	}

	// create tree leafs
	{
		TClonesArray* prodKinMomenta  = new TClonesArray("TVector3");
		TClonesArray* decayKinMomenta = new TClonesArray("TVector3");
		const int     splitLevel      = 99;
		const int     bufSize         = 256000;
		for (unsigned int i = 0; i < pwaDataTrees.size(); ++i) {
			pwaDataTrees[i]->Branch(prodKinMomentaLeafName.c_str(),  "TClonesArray", &prodKinMomenta,
			                        bufSize, splitLevel);
			pwaDataTrees[i]->Branch(decayKinMomentaLeafName.c_str(), "TClonesArray", &decayKinMomenta,
			                        bufSize, splitLevel);
//.........这里部分代码省略.........
开发者ID:armingensler,项目名称:ROOTPWA,代码行数:101,代码来源:fillUdstDataIntoMassBins_example.C


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