InteractionChainData.cpp
Go to the documentation of this file.
1 
2 #include "InteractionChainData.h"
3 #include "Numi2Pdg.h"
4 
5 namespace NeutrinoFluxReweight{
8  const char* tgtcfg,
9  const char* horncfg){
10 
11  // Fill in information about the hadron exiting the target
12  // this information is needed in order to reweight yields
13  // off the target (i.e., MIPP)
14  double tarP[3];
15  tarP[0] = nu->tpx;
16  tarP[1] = nu->tpy;
17  tarP[2] = nu->tpz;
18  double tarV[3];
19  tarV[0] = nu->tvx;
20  tarV[1] = nu->tvy;
21  tarV[2] = nu->tvz;
22 
23  static Numi2Pdg numi2pdg;
24  tar_info = TargetData(tarP,numi2pdg.GetPdg(nu->tptype),tarV,-1);
25 
26  // loop over trajectories, create InteractionData objects,
27  // and add them to the interaction_chain vector
28  //(Note about units: In nudata format, the momentum unit is MeV)
29 
30  Int_t ntraj = nu->ntrajectory;
31  if(ntraj>10)ntraj = 10;
32  for(int itraj=0;itraj<(ntraj-1);itraj++){
33  double incP[3];
34  incP[0] = nu->pprodpx[itraj+1]/1000.;
35  incP[1] = nu->pprodpy[itraj+1]/1000.;
36  incP[2] = nu->pprodpz[itraj+1]/1000.;
37 
38  Int_t itraj_prod = itraj + 1;
39  Int_t pdg_prod = nu->pdg[itraj_prod];
40  std::string this_proc = std::string(nu->proc[itraj_prod]);
41  // skip over etas and other swiftly decaying particles
42  // we are interested in their daughters
43 
44  //It seems that the next while is causing seg fault in gcc 6.3:
45  /* while( is_fast_decay(pdg_prod) ){
46  itraj_prod++;
47  pdg_prod = nu->pdg[itraj_prod];
48  } */
49  if( is_fast_decay(pdg_prod) ){
50  for(int ifast = itraj_prod + 1; ifast < (ntraj-1); ifast++ ){
51  pdg_prod = nu->pdg[ifast];
52  itraj_prod++;
53  pdg_prod = nu->pdg[itraj_prod];
54  if( !is_fast_decay(pdg_prod) ) break;
55  }
56  }
57  double prodP[3];
58  prodP[0] = nu->startpx[itraj_prod]/1000.;
59  prodP[1] = nu->startpy[itraj_prod]/1000.;
60  prodP[2] = nu->startpz[itraj_prod]/1000.;
61 
62  double vtx[3];
63  vtx[0]=nu->startx[itraj_prod];
64  vtx[1]=nu->starty[itraj_prod];
65  vtx[2]=nu->startz[itraj_prod];
66 
67  InteractionData inter(itraj, incP,nu->pdg[itraj],prodP,pdg_prod,std::string(nu->fvol[itraj]),this_proc,vtx);
68  interaction_chain.push_back(inter);
69  }
70 
71  //
72  //nothing to fill for ParticlesThroughVolumesData here. If we are using nudata format
73  //the size of the vector of ParticlesThroughVolumesData objects will be zero.
74  //
75 
76  target_config=tgtcfg;
77  horn_config=horncfg;
78  playlist = -1;
79  }
80 
82  bsim::DkMeta* meta){
83 
84  // Fill in information about the hadron exiting the target
85  // this information is needed in order to reweight yields
86  // off the target (i.e., MIPP)
87  std::string mode(getenv("MODE"));
88  //if(mode=="OPT")std::cout<<"MODE IS OPT interactionchaindata "<<std::endl;
89  //else std::cout<<"MODE not recognized. InteractionChainData "<<std::endl;
90 
91  // std::cout<<" The environment is "<<getenv("MODE")<<std::endl;
92  double tarP[3];
93  tarP[0]=nu->tgtexit.tpx;
94  tarP[1]=nu->tgtexit.tpy;
95  tarP[2]=nu->tgtexit.tpz;
96  double tarV[3];
97  tarV[0]=nu->tgtexit.tvx;
98  tarV[1]=nu->tgtexit.tvy;
99  tarV[2]=nu->tgtexit.tvz;
100  int Nskip = 0;
101  //we will fill tardata after looking into the ancestry for the right index.
102 
103  // loop over trajectories, create InteractionData objects,
104  // and add them to the interaction_chain vector
105  // Note about units: In dk2nu format, the momentum unit is GeV
106 
107  Int_t ntraj = nu->ancestor.size();
108  for(int itraj=0;itraj<(ntraj-1);itraj++){
109 
110  int pdg_inc=nu->ancestor[itraj].pdg;
111  double incP[3];
112  incP[0]=0.0;incP[1]=0.0;incP[2]=0.0;
113  // itraj is the index of the projectile in each interaction.
114  // one can find out what it did by looking at
115  // ancestor[itraj+1].proc
116  // since 'proc' records the process which made the particle.
117  //
118  // Unfortunately, the pprod variables in g4numi v5 are needlessly complicated
119  //
120  // (1) If the particle at itraj *interacts* then pprod seems to hold
121  // the momentum of the particle just before the interaction
122  //
123  // (2) If the particle at itraj *decays* then pprod seems to hold the
124  // momentum of the particle at itraj-1, just before it interacts
125  //
126  // (3) If the particle at itraj is the *result of a decay*, then pprod holds
127  // something that looks like the momentum of the parent.
128  //
129  // Generally for hadron production studies, the second case isn't interesting
130  // if(nu->ancestor[itraj].pprodpz==0)std::cout<<"Found incident proton with 0 GeV Energy"<<std::endl;
131  if( nu->ancestor[itraj].pprodpz != 0){
132  incP[0] = nu->ancestor[itraj].pprodpx;
133  incP[1] = nu->ancestor[itraj].pprodpy;
134  incP[2] = nu->ancestor[itraj].pprodpz;
135 
136  }
137  else{
138  incP[0]=nu->ancestor[itraj].stoppx;
139  incP[1]=nu->ancestor[itraj].stoppy;
140  incP[2]=nu->ancestor[itraj].stoppz;
141  }
142  Int_t itraj_prod = itraj + 1;
143  Int_t pdg_prod = nu->ancestor[itraj_prod].pdg;
144  std::string this_proc = std::string(nu->ancestor[itraj_prod].proc);
145 
146  // skip over etas and other swiftly decaying particles
147  // we are interested in their daughters
148  //It seems that the next while is causing seg fault in gcc 6.3:
149  /*while( is_fast_decay(pdg_prod) ){
150  itraj_prod++;
151  Nskip++;
152  pdg_prod = nu->ancestor[itraj_prod].pdg;
153  }*/
154  if( is_fast_decay(pdg_prod) ){
155  for(int ifast = itraj_prod + 1; ifast < (ntraj-1); ifast++ ){
156  itraj_prod++;
157  Nskip++;
158  pdg_prod = nu->ancestor[itraj_prod].pdg;
159  if( !is_fast_decay(pdg_prod) ) break;
160  }
161  }
162  double prodP[3];
163  prodP[0] = nu->ancestor[itraj_prod].startpx;
164  prodP[1] = nu->ancestor[itraj_prod].startpy;
165  prodP[2] = nu->ancestor[itraj_prod].startpz;
166 
167  double vtx[3];
168  vtx[0]=nu->ancestor[itraj_prod].startx;
169  vtx[1]=nu->ancestor[itraj_prod].starty;
170  vtx[2]=nu->ancestor[itraj_prod].startz;
171  std::string this_vol=nu->ancestor[itraj_prod].ivol;
172 
173  //Get Rid of Hydrogen
174  if(pdg_prod == 1000010020 || pdg_inc == 1000010020|| pdg_inc == 1000020030||pdg_prod==1000020030){
175  // std::cout<<"InteractionChainData::Unusual pdgcode found "<<pdg_prod<<std::endl; //For now just skipping these deuterons
176  continue;
177  }
178 
179  InteractionData inter(itraj, incP,pdg_inc,prodP,pdg_prod,
180  this_vol,this_proc,vtx);
181  interaction_chain.push_back(inter);
182 
183  }// end loop over trajectories
184  /*&int tptype = numi2pdg.GetPdg(nu->tgtexit.tptype);
185  if(mode=="NUMI")tptype = nu->tgtexit.tptype; this was added by DUNE... seems not right (Leo) */
186  // std::cout<<"The tptype::InteractionChainData "<<tptype<<" "<<nu->tgtexit.tptype<<std::endl;
187  if(meta->vintnames.size()==0){
188  tar_info = TargetData(tarP,nu->tgtexit.tptype,tarV,-1);
189  }
190  else{
191  tar_info = TargetData(tarP,nu->tgtexit.tptype,tarV,nu->vint[0]-Nskip);
192  }
193 
194  //Filling here the ParticlesThroughVolumesData info:
195  ptv_info.clear();
196  //Looking IC, DPIP and DVOL:
197  int pdgs[3];
198  double moms[3];
199  double amount_IC[3],amount_DPIP[3],amount_DVOL[3];
200  for(int ii=0;ii<3;ii++){
201  pdgs[ii] = 0; moms[ii] = 0;
202  amount_IC[ii] = 0; amount_DPIP[ii] = 0; amount_DVOL[ii] = 0;
203  }
204 
205  for(int ii=0;ii<3;ii++){
206  if(nu->ancestor.size()==3 && ii==2)continue;
207  pdgs[ii] = nu->ancestor[nu->ancestor.size()-ii-2].pdg;
208  moms[ii] = sqrt(pow(nu->ancestor[nu->ancestor.size()-ii-2].startpx,2)+
209  pow(nu->ancestor[nu->ancestor.size()-ii-2].startpy,2)+
210  pow(nu->ancestor[nu->ancestor.size()-ii-2].startpz,2));
211 
212  //Amounts:
213  //control:
214  if( (nu->vdbl)[ii] <0 || (nu->vdbl)[ii+3] <0 || (nu->vdbl)[ii+6] <0 || (nu->vdbl)[ii+9] <0){
215  std::cout<< "ERROR FILLING AMOUNT OF MATERIAL CROSSED (In InteractionChainData) !!!" <<std::endl;
216  }
217  amount_IC[ii] = (nu->vdbl)[ii] + (nu->vdbl)[ii+3];
218  amount_DPIP[ii] = (nu->vdbl)[ii+6];
219  amount_DVOL[ii] = (nu->vdbl)[ii+9];
220  }
221 
222  ParticlesThroughVolumesData tmp_ptv_IC(pdgs,amount_IC,moms,"IC");
223  ParticlesThroughVolumesData tmp_ptv_DPIP(pdgs,amount_DPIP,moms,"DPIP");
224  ParticlesThroughVolumesData tmp_ptv_DVOL(pdgs,amount_DVOL,moms,"DVOL");
225 
226  ptv_info.push_back(tmp_ptv_IC);
227  ptv_info.push_back(tmp_ptv_DPIP);
228  ptv_info.push_back(tmp_ptv_DVOL);
229  ///
230 
231  target_config=meta->tgtcfg;
232  horn_config=meta->horncfg;
233  if((mode=="REF")||(mode=="OPT"))target_config = "le00zmi";
234  //special tgt configuration for Minerva (exact longitudinal position after survey)
235  //check for other experiments
236  if(meta->vintnames.size()>1){
237  playlist = nu->vint[1];
238  }
239  else{
240  playlist = -1;
241  }
242 
243  }
244 
245  std::ostream& InteractionChainData::print(std::ostream& os) const{
246  using namespace std;
247  os<<"==== InteractionChainData ====\n"
248  <<" *config* "<<target_config<<" "<<horn_config
249  <<"\n *target info*\n ";
250  tar_info.print(os);
251  os<<"\n *ancestors*\n";
252  for(size_t i=0; i<interaction_chain.size(); i++){
253  os<<" ";
254  interaction_chain[i].print(os);
255  }
256  os<<"\n *Particlethrough volumes:*\n";
257  for(size_t i=0; i<ptv_info.size(); i++){
258  os<<" ";
259  ptv_info[i].print(os);
260  }
261  os<<endl;
262  return os;
263  }
264 
266 
267  bool fast_decay = false;
268  if( (pdg==221)||(pdg==331)||(pdg==3212)||(pdg==113)||(pdg==223) )fast_decay = true;
269  return fast_decay;
270  }
271 
272 }
Double_t pprodpx[10]
Definition: nu_g4numi.h:67
TString fvol[10]
Definition: nu_g4numi.h:100
Double_t starty[10]
Definition: nu_g4numi.h:79
std::string string
Definition: nybbler.cc:12
Double_t tpy
Definition: nu_g4numi.h:108
constexpr T pow(T x)
Definition: pow.h:72
std::ostream & print(std::ostream &os=std::cout) const
Double_t startx[10]
Definition: nu_g4numi.h:76
The information about a hadronic interaction needed to calculate weights.
int GetPdg(int numipart)
Definition: Numi2Pdg.cpp:8
std::vector< InteractionData > interaction_chain
vector of neutrino ancestors
STL namespace.
Double_t tvx
Definition: nu_g4numi.h:114
InteractionChainData()
boring old default constructor
std::ostream & print(std::ostream &os) const
Definition: TargetData.cpp:46
Double_t tvy
Definition: nu_g4numi.h:117
Int_t tptype
Definition: nu_g4numi.h:124
std::vector< ParticlesThroughVolumesData > ptv_info
Information about all particles that pass through volumes without interacting.
std::string getenv(std::string const &name)
Definition: getenv.cc:15
Double_t tvz
Definition: nu_g4numi.h:120
std::string horn_config
The horn configuration. Example: 185i.
Double_t startpy[10]
Definition: nu_g4numi.h:52
std::string target_config
The target configuration. Example: le010z.
TString proc[10]
Definition: nu_g4numi.h:94
int playlist
The tgt playlist (exact position of the target after survey)
Double_t pprodpy[10]
Definition: nu_g4numi.h:70
Int_t ntrajectory
Definition: nu_g4numi.h:40
Double_t tpz
Definition: nu_g4numi.h:111
Double_t startpz[10]
Definition: nu_g4numi.h:55
The information about the hadron that exits the target.
Definition: TargetData.h:12
Int_t pdg[10]
Definition: nu_g4numi.h:46
Double_t pprodpz[10]
Definition: nu_g4numi.h:73
Double_t startz[10]
Definition: nu_g4numi.h:82
Double_t tpx
Definition: nu_g4numi.h:105
TargetData tar_info
Information about the hadron which exited the target.
QTextStream & endl(QTextStream &s)
Double_t startpx[10]
Definition: nu_g4numi.h:49