MCTruth.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 /// \file MCTruth.cxx
3 /// \brief Simple MC truth class, holds a vector of MCParticles
4 ///
5 /// \version $Id: MCTruth.cxx,v 1.8 2012-10-15 20:36:27 brebel Exp $
6 /// \author jpaley@indiana.edu
7 ////////////////////////////////////////////////////////////////////////
11 
13 
14 #include "TDatabasePDG.h"
15 
16 #include <iostream>
17 
18 namespace simb{
19 
20  //......................................................................
22  : fPartList()
23  , fMCNeutrino()
24  , fOrigin(simb::kUnknown)
25  , fNeutrinoSet(false)
26  {
27  }
28 
29  //......................................................................
30  void MCTruth::SetNeutrino(int CCNC,
31  int mode,
32  int interactionType,
33  int target,
34  int nucleon,
35  int quark,
36  double w,
37  double x,
38  double y,
39  double qsqr)
40  {
41  if( !fNeutrinoSet ){
42  fNeutrinoSet = true;
43  // loop over the MCParticle list and get the outgoing lepton
44  // assume this is a neutral current interaction to begin with
45  // which means the outgoing lepton is the incoming neutrino
46  MCParticle nu = fPartList[0];
47  MCParticle lep = fPartList[0];
48 
49  // start at i = 1 because i = 0 is the incoming neutrino
50  for(unsigned int i = 1; i < fPartList.size(); ++i){
51  if(fPartList[i].Mother() == nu.TrackId() &&
52  (fPartList[i].PdgCode() == nu.PdgCode() ||
53  abs(fPartList[i].PdgCode()) == abs(nu.PdgCode())-1) ){
54  lep = fPartList[i];
55  break;
56  }
57  }//done looping over particles
58 
59  fMCNeutrino = simb::MCNeutrino(nu, lep,
60  CCNC, mode, interactionType,
61  target, nucleon, quark,
62  w, x, y, qsqr);
63  } // end if MCNeutrino is not already set
64  else
65  throw art::Exception(art::errors::LogicError) << "MCTruth - attempt to set neutrino when already set";
66  return;
67  }
68 
69  //......................................................................
70  std::ostream& operator<< (std::ostream& o, simb::MCTruth const& a)
71  {
72  if(a.Origin() == kCosmicRay)
73  o << "This is a cosmic ray event" << std::endl;
74  else if(a.Origin() == kBeamNeutrino){
75  o << "This is a beam neutrino event" << std::endl;
76  o << a.GetNeutrino();
77  }
78  else if(a.Origin() == kSuperNovaNeutrino){
79  o << "This is a supernova neutrino event" << std::endl;
80  o << a.GetNeutrino();
81  }
82 
83  for (int i = 0; i < a.NParticles(); ++i)
84  o << i << " " << a.GetParticle(i) << std::endl;
85 
86  return o;
87  }
88 }
89 ////////////////////////////////////////////////////////////////////////
std::vector< simb::MCParticle > fPartList
list of particles in this event
Definition: MCTruth.h:38
int PdgCode() const
Definition: MCParticle.h:212
const simb::MCNeutrino & GetNeutrino() const
Definition: MCTruth.h:77
simb::Origin_t Origin() const
Definition: MCTruth.h:74
int NParticles() const
Definition: MCTruth.h:75
void SetNeutrino(int CCNC, int mode, int interactionType, int target, int nucleon, int quark, double w, double x, double y, double qsqr)
Definition: MCTruth.cxx:30
simb::MCNeutrino fMCNeutrino
reference to neutrino info - null if not a neutrino
Definition: MCTruth.h:39
Particle class.
int TrackId() const
Definition: MCParticle.h:210
T abs(T value)
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code
const double a
Base utilities and modules for event generation and detector simulation.
const simb::MCParticle & GetParticle(int i) const
Definition: MCTruth.h:76
friend std::ostream & operator<<(std::ostream &o, simb::MCTruth const &a)
Definition: MCTruth.cxx:70
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Supernova neutrinos.
Definition: MCTruth.h:25
list x
Definition: train.py:276
Event generator information.
Definition: MCTruth.h:32
bool fNeutrinoSet
flag for whether the neutrino information has been set
Definition: MCTruth.h:42
Event generator information.
Definition: MCNeutrino.h:18
Cosmic rays.
Definition: MCTruth.h:24
QTextStream & endl(QTextStream &s)
Beam neutrinos.
Definition: MCTruth.h:23