123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /**
- * @file
- * @author Caleb Fangmeier <caleb@fangmeier.tech>
- * @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 <iostream>
- #include <vector>
- #include <TSystem.h>
- #include <dataset.hpp>
- #include <TROOT.h>
- #include <TChain.h>
- #include <filval.hpp>
- #include <root_filval.hpp>
- 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<float> *trk_px;
- vector<float> *trk_py;
- vector<float> *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<TrackingNtuple> tds(output_filename, file_list, "trackingNtuple/tree");
- auto& px = *tds.track_branch_obj<vector<float>>("trk_py");
- auto& cont = *tds.register_container<ContainerTH1<int>>("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;
- }
|