SND@LHC Software
Loading...
Searching...
No Matches
addAuxiliaryToGST.cxx File Reference
#include <vector>
#include <string>
#include <iostream>
#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "Tools/Flux/GSimpleNtpFlux.h"
Include dependency graph for addAuxiliaryToGST.cxx:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 15 of file addAuxiliaryToGST.cxx.

15 {
16
17 if (argc != 3) {
18 std::cout << "Two arguments required: path of ghep file AND path of gst file." << std::endl;
19 return -1;
20 }
21
22 // 500 auxiliary variables should be enough?
23 int this_auxint[500];
24 double this_auxdbl[500];
25
26 std::vector<std::string> * auxname = new std::vector<std::string>();
27
28 TFile * f_ghep = new TFile(argv[1], "READ");
29 TFile * f_gst = new TFile(argv[2], "UPDATE");
30
31 TTree * ghep_meta = (TTree*) f_ghep->Get("meta");
32 genie::flux::GSimpleNtpMeta* meta_entry = new genie::flux::GSimpleNtpMeta;
33 ghep_meta->SetBranchAddress("meta", &meta_entry);
34 ghep_meta->GetEntry(0);
35
36 TTree * gst = (TTree*) f_gst->Get("gst");
37
38 std::vector<TBranch*> * aux_branches = new std::vector<TBranch*>();
39
40 for (int i_aux_var = 0; i_aux_var< meta_entry->auxintname.size(); i_aux_var++){
41 aux_branches->push_back(gst->Branch(meta_entry->auxintname.at(i_aux_var).c_str(), &(this_auxint[i_aux_var]), (meta_entry->auxintname.at(i_aux_var)+"/I").c_str()));
42 std::cout << "Added branch " << meta_entry->auxintname.at(i_aux_var) << std::endl;
43 }
44
45 for (int i_aux_var = 0; i_aux_var< meta_entry->auxdblname.size(); i_aux_var++){
46 aux_branches->push_back(gst->Branch(meta_entry->auxdblname.at(i_aux_var).c_str(), &(this_auxdbl[i_aux_var]), (meta_entry->auxdblname.at(i_aux_var)+"/D").c_str()));
47 std::cout << "Added branch " << meta_entry->auxdblname.at(i_aux_var) << std::endl;
48 }
49
50 TTree * ghep_gtree = (TTree*) f_ghep->Get("gtree");
51 genie::flux::GSimpleNtpAux* aux_entry = new genie::flux::GSimpleNtpAux;
52 ghep_gtree->SetBranchAddress("aux", &aux_entry);
53
54 for (int i_entry = 0; i_entry < ghep_gtree->GetEntries(); i_entry++){
55 aux_entry->Reset();
56
57 ghep_gtree->GetEntry(i_entry);
58
59 for (int i_auxint = 0; i_auxint < meta_entry->auxintname.size(); i_auxint++) this_auxint[i_auxint] = aux_entry->auxint.at(i_auxint);
60 for (int i_auxdbl = 0; i_auxdbl < meta_entry->auxdblname.size(); i_auxdbl++) this_auxdbl[i_auxdbl] = aux_entry->auxdbl.at(i_auxdbl);
61
62 for (int i_branch = 0; i_branch < aux_branches->size(); i_branch++) aux_branches->at(i_branch)->Fill();
63
64 };
65
66 std::cout << "Done copying auxiliary variables. Closing files." << std::endl;
67
68 f_gst->Write();
69 f_gst->Close();
70 f_ghep->Close();
71
72}