/** * @file * @author Caleb Fangmeier * @version 0.1 * * @section LICENSE * * * MIT License * * Copyright (c) 2017 Caleb Fangmeier * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * @section DESCRIPTION * A short example demonstrating some of the basic functionality of the FilVal * Value system. */ #include #include #include #include #include #include #include #include using namespace std; class TrackingNtuple { public : TTree *fChain; //!pointer to the analyzed TTree or TChain Int_t fCurrent; //!current Tree number in a TChain vector *trk_px; vector *trk_py; vector *trk_pz; // List of branches TBranch *b_trk_px; //! TBranch *b_trk_py; //! TBranch *b_trk_pz; //! TrackingNtuple(TTree *tree=0); virtual ~TrackingNtuple(); virtual Int_t GetEntry(Long64_t entry); virtual Long64_t LoadTree(Long64_t entry); virtual void Init(TTree *tree); }; TrackingNtuple::TrackingNtuple(TTree *tree) : fChain(0) { // if parameter tree is not specified (or zero), connect the file // used to generate this class and read the Tree. if (tree == 0) { TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject("trackingNtuple_1.root"); if (!f || !f->IsOpen()) { f = new TFile("trackingNtuple_1.root"); } TDirectory * dir = (TDirectory*)f->Get("trackingNtuple_1.root:/trackingNtuple"); dir->GetObject("tree",tree); } Init(tree); } TrackingNtuple::~TrackingNtuple() { if (!fChain) return; delete fChain->GetCurrentFile(); } Int_t TrackingNtuple::GetEntry(Long64_t entry) { // Read contents of entry. if (!fChain) return 0; return fChain->GetEntry(entry); } Long64_t TrackingNtuple::LoadTree(Long64_t entry) { // Set the environment to read one entry if (!fChain) return -5; Long64_t centry = fChain->LoadTree(entry); if (centry < 0) return centry; if (fChain->GetTreeNumber() != fCurrent) { fCurrent = fChain->GetTreeNumber(); } return centry; } void TrackingNtuple::Init(TTree *tree) { // Set object pointer trk_px = 0; trk_py = 0; trk_pz = 0; // Set branch addresses and branch pointers if (!tree) return; fChain = tree; fCurrent = -1; fChain->SetMakeClass(1); fChain->SetBranchAddress("trk_px", &trk_px, &b_trk_px); fChain->SetBranchAddress("trk_py", &trk_py, &b_trk_py); fChain->SetBranchAddress("trk_pz", &trk_pz, &b_trk_pz); } void run(bool silent) { using namespace fv; using namespace fv_root; auto file_list = the_config->get_source_files(); string output_filename = the_config->get_output_filename(); TreeDataSet tds(output_filename, file_list, "trackingNtuple/tree"); auto& px = *tds.track_branch_obj>("trk_py"); auto& cont = *tds.register_container>("trk_py", "Track Px", TH1Params::lookup("track_px")); while(tds.next(silent)) { for (const float& p : px()) { cont.fill(p); } } tds.save_all(); } int main(int argc, char* argv[]){ using namespace fv_util; ArgParser args(argc, argv); bool silent = args.cmdOptionExists("-s"); if(args.cmdOptionExists("-c")) { init_config(args.getCmdOption("-c")); init_log(fv_util::LogPriority::kLogInfo); // gSystem->Load("libfilval.so"); run(silent); } else { cout << "Usage: ./" << argv[0] << " (-s) -c config_file.yaml" << endl; } return 0; }