GEMC  1.8
Geant4 Monte-Carlo Framework
txt_output.cc
Go to the documentation of this file.
1 // %%%%%%%%%%%%%
2 // gemc headers
3 // %%%%%%%%%%%%%
4 #include "txt_output.h"
5 
6 #include <fstream>
7 
9 {
10  ofstream *txtout = output->txtoutput ;
11 
12  *txtout << " > Event number: " << head.evn << endl;
13  *txtout << " > Event type: " << head.type << endl;
14  *txtout << " > Event Beam Pol: " << head.beamPol ;
15  *txtout << ", Target Pol: " << head.targetPol << endl;
16 }
17 
18 void txt_output :: SetBankHeader(int bankid, string SDName, MOutputs* output)
19 {
20  ofstream *txtout = output->txtoutput ;
21 
22  *txtout << " > Bank: " << SDName << " - id: " << bankid << endl;
23 }
24 
25 
26 
27 void txt_output :: WriteGenerated(MOutputs* output, vector<MGeneratedParticle> MGP)
28 {
29  double MAXP = output->gemcOpt.args["NGENP"].arg;
30  ofstream *txtout = output->txtoutput ;
31  for(unsigned int i=0; i<MAXP && i<MGP.size(); i++)
32  {
33  *txtout << " Gen. Particle id: " << MGP[i].PID
34  << " - mom: " << MGP[i].momentum/MeV
35  << " MeV - vert: " << MGP[i].vertex/cm << " cm" << endl;
36  }
37 }
38 
39 
41 {
42  ofstream *txtout = output->txtoutput ;
43 
44  // check for double/int sizes consistency
45  unsigned int nraws, ndigit;
46  nraws=ndigit=0;
47  for(unsigned int i=0; i<mbank.name.size(); i++)
48  {
49  if(mbank.type[i] == 0) ndigit++;
50  if(mbank.type[i] == 1) nraws++;
51  }
52 
53  if(PHout.raws.size() != nraws || PHout.dgtz.size() != ndigit)
54  {
55  cout << " Output does not match bank definition. This hit won't be written in the output stream." << endl;
56  cout << " nraws size: " << nraws << " Output nraws: " << PHout.raws.size() << endl;
57  cout << " ndgtz size: " << ndigit << " Output ndgt: " << PHout.dgtz.size() << endl;
58  return;
59  }
60 
61  // digitized informations, if any
62  if(ndigit)
63  {
64  *txtout << " " ;
65  for(unsigned int d=0; d<ndigit; d++)
66  *txtout << mbank.name[d+nraws] << ": " << PHout.dgtz[d] << " " ;
67  *txtout << endl;
68  }
69 
70  // raw informations, if any
71  if(nraws)
72  {
73  *txtout << " " ;
74  for(unsigned int r=0; r<nraws; r++)
75  *txtout << mbank.name[r] << ": " << PHout.raws[r] << " " ;
76  *txtout << endl;
77  }
78 }
79 
80 
81 void txt_output :: SaveSimConditions(MOutputs* output, map<string, string> simcons)
82 {
83  ofstream *txtout = output->txtoutput ;
84 
85  *txtout << " Simulation Conditions: " << endl;
86 
87  for(map<string, string>::iterator it = simcons.begin(); it != simcons.end(); it++)
88  *txtout << " > " << it->first << " " << it->second << endl;
89 
90  *txtout << " End of Simulation Conditions" ;
91 
92 }
93 
void ProcessOutput(PH_output, MOutputs *, MBank)
Pure Virtual Method to process the output.
Definition: txt_output.cc:40
void WriteGenerated(MOutputs *, vector< MGeneratedParticle >)
Pure Virtual Method to write generated particles infos.
Definition: txt_output.cc:27
vector< double > raws
Raw information.
Definition: MPHBaseClass.h:26
double beamPol
Beam Polarization.
void SetBankHeader(int, string, MOutputs *)
Pure Virtual Method to set the bank header.
Definition: txt_output.cc:18
void SetOutpHeader(header, MOutputs *)
Pure Virtual Method to set the output header. MOutputs needed for some output (txt) ...
Definition: txt_output.cc:8
void SaveSimConditions(MOutputs *, map< string, string >)
Pure Virtual Method to save the simulation conditions on the file.
Definition: txt_output.cc:81
vector< string > name
Variable name.
Definition: MBankdefs.h:35
ofstream * txtoutput
vector< int > type
Type of variable: 0=int, 1=double.
Definition: MBankdefs.h:37
double d[nslayers]
Definition: dc12geom.h:45
map< string, opts > args
Options map.
Definition: usage.h:68
double targetPol
Target Polarization.
gemc_opts gemcOpt
double r
Definition: dc12geom.h:54
vector< int > dgtz
Digitized information.
Definition: MPHBaseClass.h:27
int evn
Event number.