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


C++ TBranch::GetLeaf方法代码示例

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


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

示例1: main

int main() {
  // Get7 a map of the histograms of the Z Masses
  const std::string file_name = "/data/whybee0a/user/lesko_2/fermi/MadWithInitial/Mad2016_8_25/results/AllMHWithMothers.root";
  // Open the file and load the tree
  const std::string TreeName = "ZFinder/Combined Gen Cuts Reco/Combined Gen Cuts Reco";
  TTree* tree = GetTTree(file_name, TreeName);

  TBranch* reco = tree->GetBranch("reco");
  TLeaf* PhiStar = reco->GetLeaf("z_phistar_born");
  TLeaf* Mom1 = reco->GetLeaf("z_mom1PDG");
  TLeaf* Mom2 = reco->GetLeaf("z_mom2PDG");
  TLeaf* PenUltimateMom1 = reco->GetLeaf("z_penultimate1PDG");
  TLeaf* PenUltimateMom2 = reco->GetLeaf("z_penultimate2PDG");
  TLeaf* Z_YBorn = reco->GetLeaf("z_yBorn");

  ExploreTree(tree, Mom1, PenUltimateMom1, Mom2, PenUltimateMom2);

  TBranch* event_info = tree->GetBranch("event_info");
  //TLeaf* EVNumb = event_info->GetLeaf("event_number");
  // Pack into a hitogram

  for (int w = 0; w < 2; w++) {
    string PlotName;
    TLeaf* MomOrPenUltimateMom1 = w == 0 ? Mom1 : PenUltimateMom1;
    TLeaf* MomOrPenUltimateMom2 = w == 0 ? Mom2 : PenUltimateMom2;

    vector<string> NamesOfPlots;
    NamesOfPlots.push_back("UpQuarkPair"); //0
    NamesOfPlots.push_back("DownQuarkPair"); //1
    NamesOfPlots.push_back("StrangeQuarkPair"); //2
    NamesOfPlots.push_back("CharmQuarkPair"); //3
    NamesOfPlots.push_back("BottomQuarkPair"); //4
    NamesOfPlots.push_back("SingleQuark"); //5
    NamesOfPlots.push_back("Gluon"); //6
    NamesOfPlots.push_back("TwoQuarks"); //7
    NamesOfPlots.push_back("TwoAntiQuarks"); //8
    NamesOfPlots.push_back("QuarkAntiQuarkPair"); //9
    NamesOfPlots.push_back("QuarkAntiQuarkNotPair"); //10
    NamesOfPlots.push_back("Quark Quark And AntiQuark AntiQuark"); //11
    NamesOfPlots.push_back("Broken");

    map<string, TH1*> AllPlots;
    AllPlots[NamesOfPlots[0]] = new TH1D(NamesOfPlots[0].c_str(), NamesOfPlots[0].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[1]] = new TH1D(NamesOfPlots[1].c_str(), NamesOfPlots[1].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[2]] = new TH1D(NamesOfPlots[2].c_str(), NamesOfPlots[2].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[3]] = new TH1D(NamesOfPlots[3].c_str(), NamesOfPlots[3].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[4]] = new TH1D(NamesOfPlots[4].c_str(), NamesOfPlots[4].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[5]] = new TH1D(NamesOfPlots[5].c_str(), NamesOfPlots[5].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[6]] = new TH1D(NamesOfPlots[6].c_str(), NamesOfPlots[6].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[7]] = new TH1D(NamesOfPlots[7].c_str(), NamesOfPlots[7].c_str(), nphistar, phistarBins); //Two quarks
    AllPlots[NamesOfPlots[8]] = new TH1D(NamesOfPlots[8].c_str(), NamesOfPlots[8].c_str(), nphistar, phistarBins); //Two Anti quarks
    AllPlots[NamesOfPlots[9]] = new TH1D(NamesOfPlots[9].c_str(), NamesOfPlots[9].c_str(), nphistar, phistarBins); //
    AllPlots[NamesOfPlots[10]] = new TH1D(NamesOfPlots[10].c_str(), NamesOfPlots[10].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[11]] = new TH1D(NamesOfPlots[11].c_str(), NamesOfPlots[11].c_str(), nphistar, phistarBins);
    AllPlots[NamesOfPlots[12]] = new TH1D(NamesOfPlots[12].c_str(), NamesOfPlots[12].c_str(), nphistar, phistarBins);

    map<string, TH1*> RatioPlots; //using normalized versions of the pairs to see shape changes

    cout << "test 1" << endl;
    //Vector<TH1*> YplotsFromParents;
    //YplotsFromParents.push_back(new TH1D("YSeperatedUpQuarkPair", "UpQuarkPair", nY, yBins));
    //YplotsFromParents.push_back(new TH1D("YSeperatedDownQuarkPair", "DownQuarkPair", nY, yBins));
    //YplotsFromParents.push_back(new TH1D("YSeperatedStrangeQuarkPair", "StrangeQuarkPair", nY, yBins));
    //YplotsFromParents.push_back(new TH1D("YSeperatedCharmQuarkPair", "CharmQuarkPair", nY, yBins));
    //YplotsFromParents.push_back(new TH1D("YSeperatedBottomQuarkPair", "BottomQuarkPair", nY, yBins));
    //YplotsFromParents.push_back(new TH1D("YSeperatedGluonQuarkPair", "GluonQuarkPair", nY, yBins));
    //YplotsFromParents.push_back(new TH1D("YSeperatedGluon", "Gluon", nY, yBins));
    //YplotsFromParents.push_back(new TH1D("YSeperatedUnmatchingQuarks", "UnmatchingQuarks", nY, yBins));

    //TH2D* Parents = new TH2D("ParentsPDGId", "Parents PDGID", 28, -6.5, 21.5, 28, -6.5, 21.5);
    TH2D* ProductionVsY = new TH2D("ProductionVsY", "ProductionVsY", 7, 0, 7, 6, yBins);

    for (int i = 0; i < tree->GetEntries(); i++) {
      tree->GetEntry(i);
      if(PhiStar->GetValue()==-1)continue;
      if (fabs(MomOrPenUltimateMom1->GetValue()) == 1 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) {
        AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue());
        AllPlots["UpQuarkPair"]->Fill(PhiStar->GetValue());
        ProductionVsY->Fill(0.1, Z_YBorn->GetValue()
                );
      } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 2 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) {
        AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue());
        AllPlots["DownQuarkPair"]->Fill(PhiStar->GetValue());
        ProductionVsY->Fill(1.1, Z_YBorn->GetValue());

      } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 3 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) {
        AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue());
        AllPlots["StrangeQuarkPair"]->Fill(PhiStar->GetValue());
        ProductionVsY->Fill(2.1, Z_YBorn->GetValue());
      } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 4 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) {
        AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue());
        AllPlots["CharmQuarkPair"]->Fill(PhiStar->GetValue());
        ProductionVsY->Fill(3.1, Z_YBorn->GetValue());
      } else if (fabs(MomOrPenUltimateMom1->GetValue()) == 5 && -MomOrPenUltimateMom1->GetValue() == MomOrPenUltimateMom2->GetValue()) {
        AllPlots["QuarkAntiQuarkPair"]->Fill(PhiStar->GetValue());
        AllPlots["BottomQuarkPair"]->Fill(PhiStar->GetValue());
        ProductionVsY->Fill(4.1, Z_YBorn->GetValue());
      } else if ((MomOrPenUltimateMom1->GetValue() == 21 && fabs(MomOrPenUltimateMom2->GetValue()) < 7) || (MomOrPenUltimateMom2->GetValue() == 21 && fabs(MomOrPenUltimateMom1->GetValue()) < 7)) {
        AllPlots["SingleQuark"]->Fill(PhiStar->GetValue());
        ProductionVsY->Fill(6.1, Z_YBorn->GetValue());
//.........这里部分代码省略.........
开发者ID:optimisticcynic,项目名称:ZFinder,代码行数:101,代码来源:MomPDFPlots.cpp

示例2: Initialize

bool TreeReader::Initialize(vector <string> br, string opt)
{
	if(!init)
	{
	    if( !fChain )
		{
		        cout << endl;
			cout << "No tree to initialize" << endl;
			cout << endl;
			return false;
		}

		TObjArray *fileElements = fChain->GetListOfFiles();
		if( !fileElements || ( fileElements->GetEntries() == 0 ))
		{
		        cout << endl;
			cout << "No file(s) to initialize" << endl;
			cout << endl;
			return false;
		}
	}

	varList.clear();

	TObjArray* branches = fChain->GetListOfBranches();
	int nBranches = branches->GetEntries();

	for (int i = 0; i < nBranches; ++i)
	{
		TBranch* branch = (TBranch*)branches->At(i);
		string brname = branch->GetName();
		TLeaf* leaf = branch->GetLeaf(branch->GetName());

		if ( leaf == 0 )  // leaf name is different from branch name
		{
			TObjArray* leafs = branch->GetListOfLeaves();
			leaf = (TLeaf*)leafs->At(0);
		}

		string curtype = leaf->GetTypeName();
        int id = TypeDB::getType(curtype.c_str());
		int arreysize = 1;
		string title = leaf->GetTitle();
        //cout << curtype << "   " << title << endl;

		// Find out whether we have array by inspecting leaf title
		if ( title.find("[")!=std::string::npos )
		{
			TLeaf * nelem = leaf->GetLeafCounter(arreysize);
			if(arreysize == 1 && nelem != NULL) arreysize = nelem->GetMaximum() + 1; //search for maximum value of the lenght
		}


		if(id >= 0)
		{
			bool addVar = true;
			if(br.size()>0)
			{
				addVar = false;
				for(unsigned b = 0; b < br.size(); b++)
				{
					if(opt == "names" || opt == "except")
					{
						if(br[b] == brname) { addVar = true; break;}
					}
					else if(opt.find("contains")!=string::npos)
					{
						if((string(brname)).find(br[b])!=string::npos) { addVar = true; break;}
					}
					else if(opt.find("except")==string::npos) cout << "Option " << opt << " not found" << endl;
				}

				if(opt.find("except")!=string::npos) addVar = !addVar;
			}

			if(addVar)
			{
				variable * tmpVar = new variable(id,arreysize);

				tmpVar->name = leaf->GetName();
				tmpVar->bname = branch->GetName();
				tmpVar->title = title;

				varList.push_back(tmpVar);
				fChain->SetBranchAddress(tmpVar->bname,tmpVar->value.address);
			}
		}
		else
		{
			cout << curtype << ": type not found" << endl;
			exit(1);
			return false;
		}
	}

	init = true;
	continueSorting = true;
	if(pmode=="v") cout << endl << "Set up " << varList.size() << " / " << nBranches << " branches" << endl;

	return true;
//.........这里部分代码省略.........
开发者ID:Williams224,项目名称:AnalysisTools,代码行数:101,代码来源:ReadTree_comp.cpp


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