All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GSimpleInterface.cxx
Go to the documentation of this file.
1 #include "GSimpleInterface.h"
2 #include "TFile.h"
3 #include "TTree.h"
4 
5 namespace fluxr {
7  {
8  }
9 
11  {
12  }
13 
14  void GSimpleInterface::SetRootFile(TFile* fluxInputFile)
15  {
16  fFluxTree=dynamic_cast<TTree*>(fluxInputFile->Get("flux"));
17  fMetaTree=dynamic_cast<TTree*>(fluxInputFile->Get("meta"));
18  fGSimpleEntry = new genie::flux::GSimpleNtpEntry;
19  fGSimpleNuMI = new genie::flux::GSimpleNtpNuMI;
20  fGSimpleAux = new genie::flux::GSimpleNtpAux;
21  fGSimpleMeta = new genie::flux::GSimpleNtpMeta;
22  fFluxTree->SetBranchAddress("entry",&fGSimpleEntry);
23  fFluxTree->SetBranchAddress("numi" ,&fGSimpleNuMI);
24  fFluxTree->SetBranchAddress("aux" ,&fGSimpleAux);
25  fMetaTree->SetBranchAddress("meta" ,&fGSimpleMeta);
26 
27  fNEntries=fFluxTree->GetEntries();
28  fFluxTree->GetEntry(0);
29  fRun=fGSimpleNuMI->run;
30  fMetaTree->GetEntry(0);
31  fPOT=fGSimpleMeta->protons;
32 
33  Double_t* window_base = fGSimpleMeta->windowBase;
34  Double_t* window_dir_1 = fGSimpleMeta->windowDir1;
35  Double_t* window_dir_2 = fGSimpleMeta->windowDir2;
36  std::cout << "GSimple Window:" << std::endl;
37  std::cout << "\tBase: " << window_base[0] << ", " << window_base[1] << ", " << window_base[2] << std::endl;
38  std::cout << "\tDir 1: " << window_dir_1[0] << ", " << window_dir_1[1] << ", " << window_dir_1[2] << std::endl;
39  std::cout << "\tDir 2: " << window_dir_2[0] << ", " << window_dir_2[1] << ", " << window_dir_2[2] << std::endl;
40  }
41 
42  bool GSimpleInterface::FillMCFlux(Long64_t ientry, simb::MCFlux& flux)
43  {
44  if (!fFluxTree->GetEntry(ientry))
45  return false;
46 
47  fNuPos=TLorentzVector(fGSimpleEntry->vtxx*100,fGSimpleEntry->vtxy*100,fGSimpleEntry->vtxz*100,0);
48  fNuMom=TLorentzVector(fGSimpleEntry->px ,fGSimpleEntry->py ,fGSimpleEntry->pz ,fGSimpleEntry->E);
49 
50  //stealing code from GenieHelper (nutools/EventGeneratorBase/GENIE/GENIEHelper.cxx)
51  flux.fntype = fGSimpleEntry->pdg;
52  flux.fnimpwt = fGSimpleEntry->wgt;
53  flux.fdk2gen = fGSimpleEntry->dist;
54  flux.fnenergyn = flux.fnenergyf = fGSimpleEntry->E;
55 
56  if ( fGSimpleNuMI ) {
57  flux.frun = fGSimpleNuMI->run;
58  flux.fevtno = fGSimpleNuMI->evtno;
59  flux.ftpx = fGSimpleNuMI->tpx;
60  flux.ftpy = fGSimpleNuMI->tpy;
61  flux.ftpz = fGSimpleNuMI->tpz;
62  flux.ftptype = fGSimpleNuMI->tptype; // converted to PDG
63  flux.fvx = fGSimpleNuMI->vx;
64  flux.fvy = fGSimpleNuMI->vy;
65  flux.fvz = fGSimpleNuMI->vz;
66 
67  flux.fndecay = fGSimpleNuMI->ndecay;
68  flux.fppmedium = fGSimpleNuMI->ppmedium;
69 
70  flux.fpdpx = fGSimpleNuMI->pdpx;
71  flux.fpdpy = fGSimpleNuMI->pdpy;
72  flux.fpdpz = fGSimpleNuMI->pdpz;
73 
74  double apppz = fGSimpleNuMI->pppz;
75  if ( TMath::Abs(fGSimpleNuMI->pppz) < 1.0e-30 ) apppz = 1.0e-30;
76  flux.fppdxdz = fGSimpleNuMI->pppx / apppz;
77  flux.fppdydz = fGSimpleNuMI->pppy / apppz;
78  flux.fpppz = fGSimpleNuMI->pppz;
79 
80  flux.fptype = fGSimpleNuMI->ptype;
81  }
82 
83  // anything useful stuffed into vdbl or vint?
84  // need to check the metadata auxintname, auxdblname
85  if ( fGSimpleAux && fGSimpleMeta ) {
86  // references just for reducing complexity
87  const std::vector<std::string>& auxdblname = fGSimpleMeta->auxdblname;
88  const std::vector<std::string>& auxintname = fGSimpleMeta->auxintname;
89  const std::vector<int>& auxint = fGSimpleAux->auxint;
90  const std::vector<double>& auxdbl = fGSimpleAux->auxdbl;
91 
92  for (size_t id=0; id<auxdblname.size(); ++id) {
93  if ("muparpx" == auxdblname[id]) flux.fmuparpx = auxdbl[id];
94  if ("muparpy" == auxdblname[id]) flux.fmuparpy = auxdbl[id];
95  if ("muparpz" == auxdblname[id]) flux.fmuparpz = auxdbl[id];
96  if ("mupare" == auxdblname[id]) flux.fmupare = auxdbl[id];
97  if ("necm" == auxdblname[id]) flux.fnecm = auxdbl[id];
98  if ("nimpwt" == auxdblname[id]) flux.fnimpwt = auxdbl[id];
99  if ("fgXYWgt" == auxdblname[id]) {
100  flux.fnwtnear = flux.fnwtfar = auxdbl[id];
101  }
102  }
103  for (size_t ii=0; ii<auxintname.size(); ++ii) {
104  if ("tgen" == auxintname[ii]) flux.ftgen = auxint[ii];
105  if ("tgptype" == auxintname[ii]) flux.ftgptype = auxint[ii];
106  }
107  }
108  return true;
109  }
110 }
genie::flux::GSimpleNtpEntry * fGSimpleEntry
genie::flux::GSimpleNtpNuMI * fGSimpleNuMI
void SetRootFile(TFile *rootFileName)
genie::flux::GSimpleNtpMeta * fGSimpleMeta
genie::flux::GSimpleNtpAux * fGSimpleAux
bool FillMCFlux(Long64_t ientry, simb::MCFlux &mcflux)
BEGIN_PROLOG could also be cout