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


C++ TChain::Fill方法代码示例

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


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

示例1: ntuple_subset

void ntuple_subset(TString inputRootFile, TString baseFilename, bool useCuts = false, int evtsPerFile = -1) {
   TFile* ifile = TFile::Open(inputRootFile);
   ifile->cd("PS");

   //Set up date and Root Chain
   TChain *t1 = (TChain*)gDirectory->Get("jets2p");
   EventNtuple *ntuple = new EventNtuple();
   t1->SetBranchAddress("EvtNtuple", &ntuple);
   int nEventNtuple = static_cast<int>(t1->GetEntries());

   int numFiles = 0;
   if (evtsPerFile==-1)
      numFiles = 1;
   else
      numFiles = std::ceil(double(nEventNtuple)/evtsPerFile);

   for(int f=0; f<numFiles; f++) {
      //Opens the .ROOT file and set it so that new graph will be added, but nothing will be deleted
      TString index = Form("%d",f);
      TFile myfile(TString(baseFilename+index+".root"), "RECREATE");
      myfile.mkdir("PS");
      myfile.cd("PS");
      cout << "File " << f << " of " << numFiles << endl;

      TChain *newntuple = (TChain*)t1->CloneTree(0);
      if(numFiles == 1) evtsPerFile = nEventNtuple;
      for(int i=0; i<evtsPerFile; i++)
      {
         t1->GetEntry((f*evtsPerFile)+i);
         if(!useCuts || (useCuts && cuts(ntuple)))
            newntuple->Fill();
         if (i%10000==0) cout << "\tEntry " << (f*evtsPerFile)+i << " of " << nEventNtuple << endl;
      }
      
      newntuple->AutoSave();
      newntuple->Write();
      myfile.Close();
   }
}
开发者ID:aperloff,项目名称:TAMUWW,代码行数:39,代码来源:ntuple_subset.C

示例2: splitNtupleByGenInfo

void splitNtupleByGenInfo(TString inputFilepath = "/eos/uscms/store/user/aperloff/MatrixElement/Summer12ME8TeV/MEInput/", TString outputDir = "./", TString hTo = "WW", bool eventNtupleOnly = true, TString postfix = "") {

   TString folderName = "";
   if(eventNtupleOnly)
      folderName = "PS/";
   TString inputTreeName = "";
   if(eventNtupleOnly)
      inputTreeName = "jets2p";
   else
      inputTreeName = "METree";

   cout << "Opening input files ... ";
   TFile* ifile;
   TString ifilename;
   if(eventNtupleOnly) {
      ifilename = inputFilepath+"WH_ZH_TTH_HTo"+hTo+"_M125"+postfix+".root";
      ifile = new TFile(ifilename.Data(),"READ");
   }
   else {
      ifilename = inputFilepath+"microWH_ZH_TTH_HTo"+hTo+"_M125"+postfix+"_BaseCuts.root";
      ifile = new TFile(ifilename.Data(),"READ");
   }
   cout << "DONE" << endl;
   cout << "\t" << ifilename << endl;

   cout << "Making all of the input ntuples ... ";
   EventNtuple *ntuple      = new EventNtuple();
   METree *metree           = new METree();
   MicroNtuple *mnt         = new MicroNtuple();
   cout << "DONE" << endl;

   cout << "Setting up EventNtuple ... " << flush;
   TTree *t1 = (TTree*)gDirectory->Get(folderName+inputTreeName);
   if(eventNtupleOnly)
      t1->SetBranchAddress("EvtNtuple", &ntuple);
   else
      t1->SetBranchAddress("EvtTree", &ntuple);
   int nEventNtuple = static_cast<int>(t1->GetEntries());
   cout << "DONE" << endl;

   cout << endl << "Setting up the output file and chain ... " << flush;
   TString prefix = "";
   if(!eventNtupleOnly) {
      prefix = "micro";
      postfix += "_BaseCuts";
   }
   TFile WHFile(outputDir+prefix+"WH_HTo"+hTo+"_M125"+postfix+".root", "RECREATE");
   if(eventNtupleOnly) {
      WHFile.mkdir("PS");
      WHFile.cd("PS");
   }
   TChain *WHEventNtuple = (TChain*)t1->CloneTree(0);

   TFile ZHFile(outputDir+prefix+"ZH_HTo"+hTo+"_M125"+postfix+".root", "RECREATE");
   if(eventNtupleOnly) {
      ZHFile.mkdir("PS");
      ZHFile.cd("PS");
   }
   TChain *ZHEventNtuple = (TChain*)t1->CloneTree(0);

   TFile TTHFile(outputDir+prefix+"TTH_HTo"+hTo+"_M125"+postfix+".root", "RECREATE");
   if(eventNtupleOnly) {
      TTHFile.mkdir("PS");
      TTHFile.cd("PS");
   }
   TChain *TTHEventNtuple = (TChain*)t1->CloneTree(0);
   cout << "DONE" << endl;

   cout << endl << "Looping through the input EventNtuple/MicroNtuple ... " << endl;
   int nMatchedToWH = 0, nMatchedToZH = 0, nMatchedToTTH = 0, nUnmatched = 0, nMultiMatch = 0;
   vector<pair<int,int> > MultiMatchSampleEvents, UnmatchedSampleEvents;
   for(int ientry=0; ientry<nEventNtuple; ientry++) {
      t1->GetEntry(ientry);
      loadbar(ientry+1,nEventNtuple);

      int nW = 0, nZ = 0, nT = 0, nH = 0;
      for (unsigned int i=0; i<ntuple->genParticleCollection.size() && i< 30; i++) {
         if(abs(ntuple->genParticleCollection[i].pdgId)==24) {
            nW++;
            for (int j=0; j<ntuple->genParticleCollection[i].numberOfMothers; j++) {
               if (abs(ntuple->genParticleCollection[ntuple->genParticleCollection[i].motherPositions[j]].pdgId)==6)
                  nW--;
            }
         }
         if(abs(ntuple->genParticleCollection[i].pdgId)==23)
            nZ++;
         if(abs(ntuple->genParticleCollection[i].pdgId)==6)
            nT++;
         if(abs(ntuple->genParticleCollection[i].pdgId)==25)
            nH++;
      }

      if(hTo.CompareTo("WW")==0) {
         if(nW >= 3 && nZ == 0 && nT < 2 && nH == 1) {
            WHEventNtuple->Fill();
            nMatchedToWH++;
         }
         else if(nW == 2 && nZ == 1 && nT == 0 && nH == 1) {
            ZHEventNtuple->Fill();
            nMatchedToZH++;
//.........这里部分代码省略.........
开发者ID:aperloff,项目名称:TAMUWW,代码行数:101,代码来源:ntuple_subset.C

示例3: microNtuple_subtraction

void microNtuple_subtraction(TString inputRootFile, TString compareTo, TString baseFilename) {

   cout << "Opening files ... ";
   TFile* ifile = TFile::Open(inputRootFile);
   TFile* compareToFile = TFile::Open(compareTo);
   cout << "DONE" << endl;

   //Set up the EventNtuple
   cout << "Setting up EventNtuple ... " << flush;
   compareToFile->cd("PS");
   TChain *t1 = (TChain*)gDirectory->Get("jets2p");
   EventNtuple *ntuple = new EventNtuple();
   t1->SetBranchAddress("EvtNtuple", &ntuple);
   t1->SetBranchStatus("*",0);
   t1->SetBranchStatus("event",1);
   int nEventNtuple = static_cast<int>(t1->GetEntries());
   cout << "DONE" << endl;

   //Set up the MicroNtuple
   cout << "Setting up original MicroNtuple ... " << flush;
   ifile->cd();
   TChain *t2 = (TChain*)gDirectory->Get("METree");
   MicroNtuple *mnt = new MicroNtuple();
   t2->SetBranchAddress("mnt", &mnt);
   t2->GetTree()->BuildIndex("m_event");
   TTreeIndex* microNtupleIndex = new TTreeIndex();
   microNtupleIndex->Append((TTreeIndex*)t2->GetTree()->GetTreeIndex());
   //int nMicroNtuple = static_cast<int>(t2->GetEntries());
   cout << "DONE" << endl;

   cout << "Building the eventIndex ... " << endl;
   Long64_t local = -1;
   t2->SetBranchStatus("*",0);
   t2->SetBranchStatus("event*",1);
   map<int,int> eventIndex;
   map<int,int> duplicateIndex;
   int nIndex = microNtupleIndex->GetN();
   for( int i = 0; i < nIndex ; ++i ) {
      loadbar(i+1,nIndex);
      local = microNtupleIndex->GetIndex()[i];
      if(eventIndex.find(microNtupleIndex->GetIndexValues()[i]>>31)!=eventIndex.end()) {
         duplicateIndex[local] = microNtupleIndex->GetIndexValues()[i]>>31;
         cout << "WARNING::makeMicroNtuple::There could be duplicate events in the chain" << endl;
      }
      if(local>t2->GetEntries()) {
         cout << "WARNING::makeMicroNtuple::The local index is greater than the number of entries in the chain" << endl;
      }
      eventIndex[microNtupleIndex->GetIndexValues()[i]>>31] = local;
   }
   t2->SetBranchStatus("*",1);

   //Opens the .ROOT file and set it so that new graph will be added, but nothing will be deleted
   cout << endl << "Setting up the output file and chain ... ";
   TFile myfile(TString(baseFilename+".root"), "RECREATE");   
   TChain *newntuple = (TChain*)t2->CloneTree(0);
   cout << "DONE" << endl;

   //counters
   int eventsRemoved = 0;
   int duplicates = 0;
   // Holds the list of events to avoid duplication
   RunEventSet runEventSet;

   cout << "Looping through the EventNtuple and filling subtracted MicroNtuple ... " << endl;
   for(int ientry=0; ientry<nEventNtuple; ientry++)
   {
      t1->GetEntry(ientry);
      loadbar(ientry+1,nEventNtuple);
      if (runEventSet.alreadySeen(ntuple->run, ntuple->event)) {
         cout << "WARNING, event Run = " << ntuple->run << ", Event = " << ntuple->event
              <<" is duplicated" << endl << "We will skip this event." << endl;
         duplicates++;
         eventsRemoved++;
      }
      else if(eventIndex.find(ntuple->event)!=eventIndex.end()) {
         t2->GetEntry(eventIndex[ntuple->event]);
         newntuple->Fill();
      }
      else
         eventsRemoved++;
   }
   
   cout << endl << "Events Removed: " << eventsRemoved << endl;
   cout << "Events Remaining: " << newntuple->GetEntries() << endl;
   cout << "Duplicate Events: " << duplicateIndex.size() << " (" << duplicates << ")" << endl;

   newntuple->AutoSave();
   newntuple->Write();
   myfile.Close();
}
开发者ID:aperloff,项目名称:TAMUWW,代码行数:90,代码来源:ntuple_subset.C


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