Functions
FillIMapHists.cpp File Reference
#include "FillIMapHists.h"
#include "InteractionChainData.h"
#include "InteractionData.h"
#include "CentralValuesAndUncertainties.h"
#include "MIPPNumiYieldsBins.h"
#include "MIPPNumiMC.h"
#include "ThinTargetBins.h"
#include "TDatabasePDG.h"
#include "TParticlePDG.h"
#include <iostream>
#include <math.h>
#include "MakeReweight.h"

Go to the source code of this file.

Functions

double FillIMapHists (TChain *tdk2nu, TChain *tdkmeta, HistList *hists, const FillIMapHistsOpts *opts)
 
double FillOneEntry (bsim::Dk2Nu *dk2nu, bsim::DkMeta *dkmeta, HistList *hists, const FillIMapHistsOpts *opts, FillIMapHistsReweighters *reweighters)
 
int FindIndexFromVolume (const std::string &wanted)
 
int FindIndexFromParticleName (const std::string &wanted)
 

Function Documentation

double FillIMapHists ( TChain *  tdk2nu,
TChain *  tdkmeta,
HistList hists,
const FillIMapHistsOpts opts 
)

Definition at line 14 of file FillIMapHists.cpp.

14  {
15  using namespace NeutrinoFluxReweight;
16 
17  // setup the event loop, filling Dk2Nu and DkMeta objects
18  bsim::Dk2Nu* dk2nu = new bsim::Dk2Nu;
19  bsim::DkMeta* dkmeta = new bsim::DkMeta;
20  tdk2nu->SetBranchAddress("dk2nu",&dk2nu);
21  Long64_t nentries = tdk2nu->GetEntries();
22  Long64_t ntrees = tdk2nu->GetNtrees();
23  tdkmeta->SetBranchAddress("dkmeta",&dkmeta);
24 
25  ////////////////////// initializing reweighters ///////////////////////////
26  //
27  // here, we need to initialize the reweighers
28  // and pass them into FillOneEntry
29  // so it can use them to determine if a particular interaction
30  // or chain of interactions can be reweighted
31 
32  ///// Some inputs file are needed to ensure correct operation
33  ///// of the reweight drivers and also, some reweigthwers
34  /////(for instance: ThinTargetnCPionReweighter) use other reweighters.
35  ///// The singleton MakeReweight makes this initialization and pass
36  ///// th information between reweighters.
37 
38  const char* ppfxDir = getenv("PPFX_DIR");
40  makerew->SetOptions(Form("%s/scripts/inputs_imap.xml",ppfxDir));
41 
42  FillIMapHistsReweighters reweighters;
43  reweighters.NumiPions = (makerew->cv_rw)->MIPP_NUMI_PION_Universe;
44  reweighters.NumiKaons = (makerew->cv_rw)->MIPP_NUMI_KAON_Universe;
45  reweighters.ThinTargetpCPion = (makerew->cv_rw)->THINTARGET_PC_PION_Universe;
46  reweighters.ThinTargetpCKaon = (makerew->cv_rw)->THINTARGET_PC_KAON_Universe;
47  reweighters.ThinTargetnCPion = (makerew->cv_rw)->THINTARGET_NC_PION_Universe;
48  reweighters.ThinTargetpCNucleon = (makerew->cv_rw)->THINTARGET_PC_NUCLEON_Universe;
49  reweighters.ThinTargetMesonIncident = (makerew->cv_rw)->THINTARGET_MESON_INCIDENT_Universe;
50  reweighters.ThinTargetnucleonA = (makerew->cv_rw)->THINTARGET_NUCLEON_A_Universe;
51 
52  std::cout<<"FillIMapHists looping over "<<ntrees<<" trees with a total of "<<nentries<<" entries."<<std::endl;
53  double total_weight=0.0;
54  for(Long64_t ientry=0;ientry<nentries;ientry++){
55  if(ientry%100000==0)std::cout<<"ientry "<<ientry/1000<<" k evts"<<std::endl;
56  tdk2nu->GetEntry(ientry);
57  tdkmeta->GetEntry(ientry);
58 
59  total_weight+=FillOneEntry(dk2nu,dkmeta,hists,opts,&reweighters);
60  // std::cout<<"tot wgt: "<<total_weight<<" "<<dk2nu->decay.ntype<<std::endl;
61  }
62  //Releasing memory:
63  makerew->resetInstance();
64 
65  return total_weight;
66 }
NeutrinoFluxReweight::MIPPNumiKaonYieldsReweighter * NumiKaons
Definition: FillIMapHists.h:28
A class to make the reweight event by event.
Definition: MakeReweight.h:32
NeutrinoFluxReweight::ThinTargetMesonIncidentReweighter * ThinTargetMesonIncident
Definition: FillIMapHists.h:34
static MakeReweight * getInstance()
NeutrinoFluxReweight::ThinTargetpCPionReweighter * ThinTargetpCPion
Definition: FillIMapHists.h:30
std::string getenv(std::string const &name)
Definition: getenv.cc:15
NeutrinoFluxReweight::MIPPNumiPionYieldsReweighter * NumiPions
Definition: FillIMapHists.h:27
NeutrinoFluxReweight::ThinTargetnucleonAReweighter * ThinTargetnucleonA
Definition: FillIMapHists.h:35
NeutrinoFluxReweight::ThinTargetpCKaonReweighter * ThinTargetpCKaon
Definition: FillIMapHists.h:31
NeutrinoFluxReweight::ThinTargetnCPionReweighter * ThinTargetnCPion
Definition: FillIMapHists.h:32
ReweightDriver * cv_rw
Reweighter Drivers for the central value.
Definition: MakeReweight.h:68
NeutrinoFluxReweight::ThinTargetpCNucleonReweighter * ThinTargetpCNucleon
Definition: FillIMapHists.h:33
QTextStream & endl(QTextStream &s)
void SetOptions(std::string fileIn)
double FillOneEntry(bsim::Dk2Nu *dk2nu, bsim::DkMeta *dkmeta, HistList *hists, const FillIMapHistsOpts *opts, FillIMapHistsReweighters *reweighters)
double FillOneEntry ( bsim::Dk2Nu *  dk2nu,
bsim::DkMeta *  dkmeta,
HistList hists,
const FillIMapHistsOpts opts,
FillIMapHistsReweighters reweighters 
)

Definition at line 70 of file FillIMapHists.cpp.

70  {
71  double weight=0.0;
72  TDatabasePDG* pdg = TDatabasePDG::Instance();
73  // check that the neutrino is of the requested type and that
74  // the energy is within range
75  const int nu_type=dk2nu->decay.ntype;
76  const int nuray_idx=1; // this corresponds to the location of minerva
77  const double enu=dk2nu->nuray[nuray_idx].E; // energy at MINOS ND
78 
79 #ifdef DEBUG
80  std::cout<<"FillOneEntry() for nu_type= "<<nu_type
81  <<" and energy "<<enu<<std::endl;
82 #endif
83  // setting opts.nuid=0 will result in all neutrino species being plotted
84  if( (opts->nuid!=0 && nu_type!= opts->nuid)
85  || (enu<opts->elow || enu>opts->ehigh) ){
86 #ifdef DEBUG
87  std::cout<<"Fails cut on nu_type or energy"<<std::endl;
88 #endif
89  return 0;
90  }
91  const double nwtnear=dk2nu->nuray[nuray_idx].wgt;
92  const double nimpwt=dk2nu->decay.nimpwt;
93  weight=nwtnear*nimpwt;
94 
95  hists->_h_nuflux->Fill(enu,weight/pival);
96 
97  /*
98  if(isnan(weight)){
99  std::cout<<"Encountered a NaN weight, dk2nu follows"<<std::endl;
100  std::cout<<(*dk2nu)<<std::endl;
101  }
102  */
104  const int ninter=icd.interaction_chain.size();
105  std::vector<bool> numi_pion_nodes=reweighters->NumiPions->canReweight(icd);
106  std::vector<bool> numi_kaon_nodes=reweighters->NumiKaons->canReweight(icd);
107 
108 #ifdef DEBUG
109  std::cout<<"Passes energy cut and has a weight of "<<weight
110  <<" with "<<ninter<<" entries in ancestry chain"<<std::endl;
111 #endif
112 
113  int ninter_all=0; // a variable to count all non-Decay interactions
114  int ninter_cuts=0;// ... and only those passing the MIPP/NA49/etc cuts
115 
116  for(int iinter=0; iinter<ninter; iinter++){
117 
119  =icd.interaction_chain[iinter];
120 #ifdef DEBUG
121  std::cout<<"Processing interaction "<<iinter<<endl;
122  interdata.print(std::cout);
123 #endif
124  // check to see if this entry is a decay
125  if(interdata.Proc=="Decay"){
126 #ifdef DEBUG
127  std::cout<<" This is a decay, skip it"<<std::endl;
128 #endif
129  continue; // if so, don't histogram
130  }
131  ninter_all++;
132  /////////////////////////////////////////////////////////////////////
133  // check here if this interaction is covered by NA49, MIPP, etc
134  /////////////////////////////////////////////////////////////////////
135 
136  if(opts->cut_mipp && numi_pion_nodes[iinter]) continue;
137  if(opts->cut_mipp && numi_kaon_nodes[iinter]) continue;
138  // Thin target reweighters are based on data and theoretical motivated data extensions.
139  bool covered_by_thintarget = false;
140  if(reweighters->ThinTargetpCPion->canReweight(interdata)){
141  covered_by_thintarget = true;
142  if(! opts->cut_thintarget) hists->_h_aveint_vs_enu_thin_pCpion->Fill(enu,weight);
143  if(interdata.Prod_pdg==211){
144  hists->_h_occ_xfpt_pc_pip->Fill(interdata.xF,interdata.Pt,weight);
145  double hpweight=reweighters->ThinTargetpCPion->calculateWeight(interdata);
146  hists->_h_hpwgt_xfpt_pc_pip->Fill(interdata.xF,interdata.Pt,weight*hpweight);
147  }
148  }
149  else if(reweighters->ThinTargetpCKaon->canReweight(interdata)){
150  covered_by_thintarget = true;
151  if(! opts->cut_thintarget) hists->_h_aveint_vs_enu_thin_pCkaon->Fill(enu,weight);
152  if(interdata.Prod_pdg==321){
153  hists->_h_occ_xfpt_pc_kp->Fill(interdata.xF,interdata.Pt,weight);
154  double hpweight=reweighters->ThinTargetpCKaon->calculateWeight(interdata);
155  hists->_h_hpwgt_xfpt_pc_kp->Fill(interdata.xF,interdata.Pt,weight*hpweight);
156  }
157 
158  }
159  else if(reweighters->ThinTargetnCPion->canReweight(interdata)){
160  covered_by_thintarget = true;
161  if(! opts->cut_thintarget) hists->_h_aveint_vs_enu_thin_nCpion->Fill(enu,weight);
162  }
163  else if(reweighters->ThinTargetpCNucleon->canReweight(interdata)){
164  covered_by_thintarget = true;
165  if(! opts->cut_thintarget) hists->_h_aveint_vs_enu_thin_pCnucleon->Fill(enu,weight);
166  }
167  else if(reweighters->ThinTargetMesonIncident->canReweight(interdata)){
168  covered_by_thintarget = true;
169  if(! opts->cut_thintarget) hists->_h_aveint_vs_enu_thin_mesoninc->Fill(enu,weight);
170  }
171  else if(reweighters->ThinTargetnucleonA->canReweight(interdata)){
172  covered_by_thintarget = true; //Amit Changed this...default was true.
173  if(! opts->cut_thintarget) hists->_h_aveint_vs_enu_thin_nucleona->Fill(enu,weight);
174  }
175  else{
176  covered_by_thintarget = false;
177  hists->_h_aveint_vs_enu_others->Fill(enu,weight);
178  }
179 
180  if(! opts->cut_thintarget)hists->_h_aveint_vs_enu_tot->Fill(enu,weight);
181  else{
182  if(!covered_by_thintarget)hists->_h_aveint_vs_enu_tot->Fill(enu,weight);
183  }
184 
185  if(opts->cut_mipp && covered_by_thintarget) continue;
186 
187 
188  ninter_cuts++;
189  // get an index into the large arrays listing the volume names
190  // and the material of each volume.
191  int mv_idx=FindIndexFromVolume(interdata.Vol);
192  std::string mode = getenv("MODE");
195 
196  if(mode=="REF"||mode=="OPT"){
197  volume_name = IMap::volumedune[mv_idx];
198  material_name = IMap::materialsdune[mv_idx];
199  }
200 
201  if(mv_idx==-1){
202  std::cout<<"Skipping unknown volume "<< interdata.Vol
203  <<" for interaction "<<iinter<<std::endl;
204  }
205 
206  // fill a 2D histogram of projectile vs. material
207  const string proj_name=pdg->GetParticle(interdata.Inc_pdg)->GetName();
208  const string prod_name=pdg->GetParticle(interdata.Prod_pdg)->GetName();
209  //if(covered_by_thintarget) //Uncomment this to get the thin target coverage after turning off the nucleonA reweighter off above.
210  hists->_h_in_vs_mat->Fill(material_name.c_str(),proj_name.c_str(),weight);
211  // figure out if the produced particle is one that we want
212  // to record in histograms
213  // The list of such particles is in IMap::popparticle
214  // the strange name is apparently a contraction: "popular particles"
215  const int prod_pop_idx=FindIndexFromParticleName(prod_name);
216  const int proj_pop_idx=FindIndexFromParticleName(proj_name);
217 #ifdef DEBUG
218  std::cout<<" Projectile: "<<proj_name<<" with popidx "<<proj_pop_idx<<std::endl;
219  std::cout<<" Produced : "<<prod_name<<" with popidx "<<prod_pop_idx<<std::endl;
220 #endif
221 
222 
223  // look at things from the produced particles standpoint
224  if(prod_pop_idx!=-1){ // for each of the commonly produced particles.
225 
226  // histogram kinetic energy, 3-momentum, and xF,pT
227  const double produced_KE=interdata.Prod_P4[3]-interdata.Prod_Mass;
228  hists->_hkepop_tot[prod_pop_idx]->Fill(produced_KE,weight);
229  hists->_htmpop_tot[prod_pop_idx]->Fill(interdata.Prod_P,weight);
230  hists->_hxfpt_tot[prod_pop_idx]->Fill(interdata.xF,interdata.Pt,weight);
231 
232  // histogram the material that the interaction occured in
233  // along with the projectile that made the particle in question
234  hists->_hmatbkw[prod_pop_idx]->Fill(material_name.c_str(),proj_name.c_str(),weight);
235 
236  // now, dig deeper
237  if(proj_pop_idx!=-1){ // for each of the common *projectiles*
238  // histogram kinetic energy, 3-momentum, and xF,pT
239  // of the produced particle
240  hists->_hkepop[prod_pop_idx][proj_pop_idx]->Fill(produced_KE,weight);
241  hists->_htmpop[prod_pop_idx][proj_pop_idx]->Fill(interdata.Prod_P,weight);
242  hists->_hxfpt[prod_pop_idx][proj_pop_idx]->Fill(interdata.xF,interdata.Pt,weight);
243  }
244  }
245 
246  // now look at things from the projectile's standpoint
247  if(proj_pop_idx!=-1){ // for each of the common projectiles
248  // histogram the kinetic energy of the projectile
249  const double projectile_KE=interdata.Inc_P4[3]-interdata.Inc_Mass;
250  hists->_henergytotal[proj_pop_idx]->Fill(projectile_KE,weight);
251  // histogram the volume/material and the produced particle
252  hists->_hmat[proj_pop_idx]->Fill(material_name.c_str(),prod_name.c_str(),weight);
253  hists->_hvol[proj_pop_idx]->Fill(volume_name.c_str(),prod_name.c_str(),weight);
254  // histogram the energy of the projectile for each volume
255  // This may be overkill!
256  if(mv_idx!=-1) hists->_henergyvolume[mv_idx][proj_pop_idx]->Fill(projectile_KE,weight);
257  if(projectile_KE>118 and proj_pop_idx==1){
258  std::cout<<"Oh noes!"<<std::endl;
259  }
260  }
261 
262  }
263 
264  // now fill the # of interactions vs enu
265  hists->_h_nint_vs_enu->Fill(enu,ninter_all,weight);
266  hists->_h_nint_vs_enu_cuts->Fill(enu,ninter_cuts,weight);
267 
268  // the end
269  return weight;
270 }
TH2D * _h_hpwgt_xfpt_pc_kp
NeutrinoFluxReweight::MIPPNumiKaonYieldsReweighter * NumiKaons
Definition: FillIMapHists.h:28
virtual double calculateWeight(const InteractionData &aa)
calculate a weight for this interaction given the central value parameters and the parameters for thi...
TH2D * _h_in_vs_mat
static const std::string materials[nvol]
NeutrinoFluxReweight::ThinTargetMesonIncidentReweighter * ThinTargetMesonIncident
Definition: FillIMapHists.h:34
std::string string
Definition: nybbler.cc:12
vector< TH1F * > _hkepop_tot
virtual std::vector< bool > canReweight(const InteractionChainData &aa)
Look through the InteractionChainData input and identify those Interactions that can be reweighted as...
TH1D * _h_aveint_vs_enu_thin_nucleona
Information about the chain of interactions leading to a neutrino.
int FindIndexFromVolume(const std::string &wanted)
int Prod_pdg
pdg code of the produced particle
vector< vector< TH1F * > > _hkepop
double Pt
Transversal momentum (GeV/c) of the produced particle.
static const std::string volume[nvol]
TH1D * _h_aveint_vs_enu_tot
The information about a hadronic interaction needed to calculate weights.
std::ostream & print(std::ostream &os) const
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
double Inc_P4[4]
Momentum 4 vector of the incident particle, E=p[3].
double Prod_P
Momentum magnitude of the produced particle.
TH1D * _h_aveint_vs_enu_thin_pCpion
vector< vector< TH2D * > > _hxfpt
weight
Definition: test.py:257
vector< vector< TH1F * > > _henergyvolume
double xF
Feynmann-x of the produced particle: .
vector< TH2D * > _hxfpt_tot
TH1D * _h_aveint_vs_enu_thin_nCpion
vector< TH1F * > _htmpop_tot
TH1D * _h_nuflux
virtual double calculateWeight(const InteractionData &inter_data)
calculate a weight for this interaction given the central value parameters and the parameters for thi...
NeutrinoFluxReweight::ThinTargetpCPionReweighter * ThinTargetpCPion
Definition: FillIMapHists.h:30
double Prod_P4[4]
Momentum 4 vector of the produced particle, E=p[3].
std::string getenv(std::string const &name)
Definition: getenv.cc:15
TH2D * _h_occ_xfpt_pc_kp
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
vector< TH2D * > _hmat
const double pival
std::string Proc
Interaction process.
TH2D * _h_occ_xfpt_pc_pip
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
NeutrinoFluxReweight::MIPPNumiPionYieldsReweighter * NumiPions
Definition: FillIMapHists.h:27
std::string Vol
Interaction volume.
TH2D * _h_nint_vs_enu
double Inc_Mass
Mass of the incident particle.
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
vector< vector< TH1F * > > _htmpop
NeutrinoFluxReweight::ThinTargetnucleonAReweighter * ThinTargetnucleonA
Definition: FillIMapHists.h:35
virtual std::vector< bool > canReweight(const InteractionChainData &aa)
Look through the InteractionChainData input and identify those Interactions that can be reweighted as...
int Inc_pdg
pdg code of the incident particle
TH1D * _h_aveint_vs_enu_others
vector< TH2D * > _hvol
vector< TH2D * > _hmatbkw
vector< TH1F * > _henergytotal
NeutrinoFluxReweight::ThinTargetpCKaonReweighter * ThinTargetpCKaon
Definition: FillIMapHists.h:31
int FindIndexFromParticleName(const std::string &wanted)
TH1D * _h_aveint_vs_enu_thin_mesoninc
static const std::string materialsdune[nvoldune]
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
NeutrinoFluxReweight::ThinTargetnCPionReweighter * ThinTargetnCPion
Definition: FillIMapHists.h:32
TH2D * _h_nint_vs_enu_cuts
TH1D * _h_aveint_vs_enu_thin_pCnucleon
static const std::string volumedune[nvoldune]
TH1D * _h_aveint_vs_enu_thin_pCkaon
TH2D * _h_hpwgt_xfpt_pc_pip
NeutrinoFluxReweight::ThinTargetpCNucleonReweighter * ThinTargetpCNucleon
Definition: FillIMapHists.h:33
QTextStream & endl(QTextStream &s)
double Prod_Mass
Mass of the produced particle.
virtual bool canReweight(const InteractionData &aa)
can the particular instance of this class reweight this interaction?
int FindIndexFromParticleName ( const std::string wanted)

Definition at line 288 of file FillIMapHists.cpp.

288  {
289  for(int i=0; i<IMap::npop; i++){
290  if(wanted== std::string(IMap::popparticle[i])) return i;
291  }
292  return -1;
293 }
std::string string
Definition: nybbler.cc:12
static const int npop
static const std::string popparticle[npop]
int FindIndexFromVolume ( const std::string wanted)

Definition at line 273 of file FillIMapHists.cpp.

273  {
274  std::string mode(getenv("MODE"));
275  if((mode=="REF"||mode=="OPT")){
276  for(int i=0; i<IMap::nvoldune; i++){
277  if(wanted== std::string(IMap::volumedune[i])) return i;
278  }
279  }
280  else{
281  for(int i=0; i<IMap::nvol; i++){
282  if(wanted== std::string(IMap::volume[i])) return i;
283  }
284  }
285  return -1;
286 }
std::string string
Definition: nybbler.cc:12
static const std::string volume[nvol]
static const int nvoldune
static const int nvol
std::string getenv(std::string const &name)
Definition: getenv.cc:15
static const std::string volumedune[nvoldune]