LBNEQuickPiToNu.hh
Go to the documentation of this file.
1 //
2 // LBNEQuickPitoNu.hh
3 //
4 
5 #ifndef LBNEQuickPitoNu_H
6 #define LBNEQuickPitoNu_H 1
7 #include <fstream>
8 #include <iostream>
9 #include "globals.hh"
10 #include "G4Event.hh"
11 #include "G4EventManager.hh"
12 #include "G4RunManager.hh"
13 #include "G4ExceptionSeverity.hh"
14 
15 class G4EventManager;
16 class LBNEEventAction;
17 class LBNEQuickPitoNu;
18 class LBNERunManager;
19 //
20 // These actions are for either physics studies, or debugging. They are expected to run either in " Proton on target mode",
21 // or on neutrinos. This a singleton class. Means that an implicit global pointer, tough
22 // Hopefull nobody will complain. Takes very little memory if not filled.
23 //
24 
25 
27 {
28 // see below for use and reasons..
29  public:
31  int evtNum;
32  int trNum;
33  int sign;
34  double piEnergy;
35  double nuEnergy;
36  std::vector<double> piMomentumTarget;
37  std::vector<double> piPosAtHangerRing;
38  std::vector<double> piMomentumAtHangerRing;
39  std::vector<double> nuMomentum;
40 };
41 
42 //
43 // Investigating why fixing the Ring Hanger diameter gave no change at 3GeV.
44 // We will try to correlate the pion that crosses the Horn 2 Hanger Ring (Wrong diameter!)
45 // With the direction of the corresponding neutrino.
46 // This version is probably just a protoype: Investigating how much flux is lost by an
47 // intervening volume is likely to be an on-going problem..
48 //
50  private:
52  LBNEQuickPiToNuVect(LBNEQuickPiToNuVect const &); // not implemented
53  LBNEQuickPiToNuVect& operator=(LBNEQuickPiToNuVect const&); // not implemented
56  std::vector<LBNEQuickPiToNu> data;
57  std::ofstream fOut;
58 
59  public:
60  static LBNEQuickPiToNuVect* Instance();
61  inline void YesDoThis() { doItForReal = true;}
62  inline bool doIt() const {return doItForReal;}
63  inline void open(const std::string &prefix) {
64  if (fOut.is_open()) {
65  std::cerr << " From LBNEQuickPiToNuVect, file has been already opened, close it " << std::endl;
66  fOut.close();
67  }
68  std::string fName(prefix); fName += std::string("QuickPitoNu_v1.txt");
69  fOut.open(fName.c_str());
70  fOut << " evtNum trNum sign piEnergy nuEnergy piPxTgt piPyTgt pixH2 piyH2 pizH2 piPxH2 piPyH2 ";
71  fOut << " nuPx nuPy " << std::endl; // P stands for slope ,Px/Pz...
72  }
73  inline void close() {fOut.close();}
74  inline void addPion(int trNum1, int sign1, double e, G4ThreeVector p) {
75  LBNERunManager* pRunManager=(LBNERunManager*)LBNERunManager::GetRunManager();
76  int evtno = pRunManager->GetCurrentEvent()->GetEventID();
77  LBNEQuickPiToNu a; a.evtNum = evtno; a.sign = sign1;
78  a.trNum = trNum1; a.piEnergy=e;
79  for (size_t k=0; k!=3; k++) a.piMomentumTarget[k]= p[k];
80  data.push_back(a);
81  }
82  inline void RingHangerPion(int trNum1, int sign, G4ThreeVector p, G4ThreeVector xPos) {
83  bool foundPion = false;
84  for (std::vector<LBNEQuickPiToNu>::iterator it=data.begin(); it!=data.end(); it++) {
85  if ((it->trNum == -9999) || (it->trNum == -9998)) continue;
86  if (it->trNum != trNum1) continue;
87  for (size_t k=0; k!= 3; k++) {
88  it->piMomentumAtHangerRing[k] = p[k];
89  it->piPosAtHangerRing[k] = xPos[k];
90  }
91  foundPion = true; return;
92  }
93  if (!foundPion) {
94  const double e = std::sqrt((139.58*139.58) + p[0]*p[0] + p[1]*p[1] + p[2]*p[2]);
95  std::cerr << " Found new secondary pion, declare it with a higher track number " << std::endl;
96  addPion(10000+trNum1, sign, e, p);
97  }
98  }
99 
100  inline void blessPion(int trNum1, double e, G4ThreeVector p) {
101  bool foundPion = false;
102  for (std::vector<LBNEQuickPiToNu>::iterator it=data.begin(); it!=data.end(); it++) {
103  if ((it->trNum == -9999) || (it->trNum == -9998)) continue;
104  if ((it->trNum != trNum1) && ((it->trNum-10000) != trNum1)) continue;
105  for (size_t k=0; k!= 3; k++) {
106  it->nuMomentum[k] = p[k];
107  }
108  it->nuEnergy = e;
109  foundPion = true; return;
110  if (!foundPion) {
111  std::ostringstream mStrStr;
112  mStrStr << "Found Unknown pion.. Should not happen.. Stop here. Fatal " << std::endl;
113  G4String mStr(mStrStr.str());
114  G4Exception("LBNERunAction::BeginOfRunAction", " ", RunMustBeAborted, mStr.c_str());
115  }
116  }
117  }
118  inline void reset () { data.clear();}
119 
120  inline void evtOut() {
121  for (std::vector<LBNEQuickPiToNu>::const_iterator it=data.begin(); it!=data.end(); it++) {
122  if ((it->trNum == -9999) || (it->trNum == -9998)) continue;
123  if (std::abs(it->nuEnergy) < 0.001) continue; // gave no neutrino..
124  fOut << " " << it->evtNum << " " << it->trNum << " " << it->sign << " " << it->piEnergy;
125  fOut << " " << it->nuEnergy;
126  fOut << " " << it->piMomentumTarget[0]/it->piMomentumTarget[2] << " "
127  << it->piMomentumTarget[1]/it->piMomentumTarget[2];
128  for (size_t k=0; k != 3; k++) fOut << " " << it->piPosAtHangerRing[k];
129  const double rSq = it->piPosAtHangerRing[0]*it->piPosAtHangerRing[0] +
130  it->piPosAtHangerRing[1]*it->piPosAtHangerRing[1];
131  if (rSq > 1.0e-6)
132  fOut << " " << it->piMomentumAtHangerRing[0]/it->piMomentumAtHangerRing[2] << " "
133  << it->piMomentumAtHangerRing[1]/it->piMomentumAtHangerRing[2];
134  else fOut << " 0. 0. ";
135  fOut << " " << it->nuMomentum[0]/it->nuMomentum[2] << " " << it->nuMomentum[1]/it->nuMomentum[2];
136  fOut << std::endl;
137  }
138  this->reset();
139  }
140 };
141 #endif
142 
intermediate_table::iterator iterator
std::string string
Definition: nybbler.cc:12
std::vector< LBNEQuickPiToNu > data
intermediate_table::const_iterator const_iterator
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:45
void blessPion(int trNum1, double e, G4ThreeVector p)
static LBNEQuickPiToNuVect * m_pInstance
T abs(T value)
QTextStream & reset(QTextStream &s)
std::vector< double > piMomentumTarget
std::vector< double > piPosAtHangerRing
string prefix
Definition: submitScan.py:88
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
p
Definition: test.py:223
void open(const std::string &prefix)
std::vector< double > piMomentumAtHangerRing
if(!yymsg) yymsg
std::vector< double > nuMomentum
void addPion(int trNum1, int sign1, double e, G4ThreeVector p)
QTextStream & endl(QTextStream &s)
void RingHangerPion(int trNum1, int sign, G4ThreeVector p, G4ThreeVector xPos)