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


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

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


在下文中一共展示了TChain::AutoSave方法的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


//.........这里部分代码省略.........
         }
         else if((nW > 2 && nZ > 0 && nT == 0 && nH > 0) ||
                 (nW > 2 && nZ == 0 && nT > 0 && nH > 0) ||
                 (nW == 2 && nZ > 0 && nT > 0 && nH > 0)){
            nMultiMatch++;
            MultiMatchSampleEvents.push_back(make_pair(ientry,ntuple->event));
         }
         else {
            nUnmatched++;
            UnmatchedSampleEvents.push_back(make_pair(ientry,ntuple->event));
         }
      }
      else if(hTo.CompareTo("ZZ")==0) {
         if(ntuple->event == 201693) {
            ZHEventNtuple->Fill();
            nMatchedToZH++;
         }
         else if(nW == 1 && nZ == 2 && nT < 2 && nH == 1) {
            WHEventNtuple->Fill();
            nMatchedToWH++;
         }
         else if(nW == 0 && nZ >= 3 && nT == 0 && nH == 1) {
            ZHEventNtuple->Fill();
            nMatchedToZH++;
         }
         else if(nW == 0 && nZ == 2 && nT == 2 && nH == 1) {
            TTHEventNtuple->Fill();
            nMatchedToTTH++;
         }
         else if((nW > 0 && nZ > 2 && nT == 0 && nH > 0) ||
                 (nW > 0 && nZ == 2 && nT > 0 && nH > 0) ||
                 (nW == 0 && nZ > 2 && nT > 0 && nH > 0)){
            nMultiMatch++;
            MultiMatchSampleEvents.push_back(make_pair(ientry,ntuple->event));
         }
         else {
            nUnmatched++;
            UnmatchedSampleEvents.push_back(make_pair(ientry,ntuple->event));
         }
      }
   }

   cout << endl << "Printing the matching information ... " << endl;
   cout << "\t" << setw(12) << "Sample"     << setw(12) << "nMatched"    << endl
        << "\t" << setw(12) << "------"     << setw(12) << "--------"    << endl
        << "\t" << setw(12) << "Original"   << setw(12) << nEventNtuple  << endl
        << "\t" << setw(12) << "------"     << setw(12) << "--------"    << endl
        << "\t" << setw(12) << "WH"         << setw(12) << nMatchedToWH  << endl
        << "\t" << setw(12) << "ZH"         << setw(12) << nMatchedToZH  << endl
        << "\t" << setw(12) << "TTH"        << setw(12) << nMatchedToTTH << endl
        << "\t" << setw(12) << "MultiMatch" << setw(12) << nMultiMatch   << endl
        << "\t" << setw(12) << "Unmatched"  << setw(12) << nUnmatched    << endl
        << "\t" << setw(12) << "------"     << setw(12) << "--------"    << endl
        << "\t" << setw(12) << "Total"      << setw(12) << nMatchedToWH+nMatchedToZH+nMatchedToTTH+nMultiMatch+nUnmatched << endl;

   cout << endl << "If MultiMatch or Unmatched events, print the first 10 sample (entry,event) for each ... " << endl;
   cout << "\tMultiMatch: ";
   for(unsigned int i=0; i<MultiMatchSampleEvents.size() && i<10; i++) {
      cout << "(" << MultiMatchSampleEvents[i].first << "," << MultiMatchSampleEvents[i].second << ")";
      if(i==9 || i==MultiMatchSampleEvents.size()-1)
         cout << endl;
      else
         cout << ", ";
   }
   if(MultiMatchSampleEvents.size()==0)
      cout << endl;
   cout << "\tUnmatched: ";
   for(unsigned int i=0; i<UnmatchedSampleEvents.size() && i<10; i++) {
      cout << "(" << UnmatchedSampleEvents[i].first << "," << UnmatchedSampleEvents[i].second << ")";
      if(i==9 || i==UnmatchedSampleEvents.size()-1)
         cout << endl;
      else
         cout << ", ";
   }
   if(UnmatchedSampleEvents.size()==0)
      cout << endl;

   cout << "Write the output TTrees in the appropriate files ... " << flush;
   if(eventNtupleOnly)
      WHFile.cd("PS");
   WHEventNtuple->AutoSave();
   WHEventNtuple->Write();
   if(eventNtupleOnly)
      ZHFile.cd("PS");
   ZHEventNtuple->AutoSave();
   ZHEventNtuple->Write();
   if(eventNtupleOnly)
      TTHFile.cd("PS");
   TTHEventNtuple->AutoSave();
   TTHEventNtuple->Write();
   cout << "DONE" << endl;

   cout << "Close all the files ... " << flush;
   ifile->Close();
   WHFile.Close();
   ZHFile.Close();
   TTHFile.Close();
   cout << "DONE" << endl;

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