GEMC  1.8
Geant4 Monte-Carlo Framework
evio_output.cc
Go to the documentation of this file.
1 // %%%%%%%%%%%%%
2 // gemc headers
3 // %%%%%%%%%%%%%
4 #include "evio_output.h"
5 
6 #include <fstream>
7 
9 {
10  // Need to reorganize the vectors.
11  // First index must be variable index
12  // Second index must be hit number index
13 
14  vector<vector<double> > rawinfv;
15  vector<vector<int> > dgtinfv;
16 
17  unsigned int NHITS = rawinfos.size();
18  if(NHITS)
19  {
20  int NVARSR = rawinfos[0].size();
21  int NVARSD = dgtinfos[0].size();
22 
23  // cout << NHITS << " " << NVARSR << " " << NVARSD << endl;
24 
25  rawinfv.resize(NVARSR);
26  dgtinfv.resize(NVARSD);
27 
28  for(int i=0; i<NVARSR; i++) rawinfv[i].resize(NHITS);
29  for(int i=0; i<NVARSD; i++) dgtinfv[i].resize(NHITS);
30 
31 
32  for(unsigned int nh=0; nh<NHITS; nh++)
33  for(int iv=0; iv<NVARSR; iv++)
34  rawinfv[iv][nh] = rawinfos[nh][iv];
35 
36  for(unsigned int nh=0; nh<NHITS; nh++)
37  for(int iv=0; iv<NVARSD; iv++)
38  dgtinfv[iv][nh] = dgtinfos[nh][iv];
39 
40  // creating dgthitbank, inserting it in bankevent >> TAG=bankID NUM=100 <<
41  if(NVARSD)
42  {
43  evioDOMNodeP dgtbankhit = evioDOMNode::createEvioDOMNode(bankID, 100);
44  *bankevent << dgtbankhit;
45 
46  for(int d=0; d<NVARSD; d++)
47  *dgtbankhit << evioDOMNode::createEvioDOMNode(bankID, mbank.id[d+NVARSR], dgtinfv[d]);
48  }
49 
50  // creating rawhitbank, inserting it in bankevent >> TAG=bankID NUM=200 <<
51  if(NVARSR)
52  {
53  evioDOMNodeP rawbankhit = evioDOMNode::createEvioDOMNode(bankID, 200);
54  *bankevent << rawbankhit;
55 
56  for(int r=0; r<NVARSR; r++)
57  *rawbankhit << evioDOMNode::createEvioDOMNode(bankID, mbank.id[r], rawinfv[r]);
58  }
59  }
60 
61  rawinfos.clear();
62  dgtinfos.clear();
63 }
64 
66 {
67  output->pchan->write(*event);
68  delete event;
69 }
70 
72 {
73  event = new evioDOMTree(1, 0);
74 
75  // creating and inserting head bank >> TAG=1 NUM=1 <<
76  // evioDOMNodeP head = evioDOMNode::createEvioDOMNode(1, 1);
77  //evioDOMNode::createEvioDOMNode(1, 1);
78  *event << evioDOMNode::createEvioDOMNode(1, 1, &head.evn, 1);
79  *event << evioDOMNode::createEvioDOMNode(1, 2, &head.type, 1);
80  *event << evioDOMNode::createEvioDOMNode(1, 3, &head.beamPol, 1);
81  *event << evioDOMNode::createEvioDOMNode(1, 4, &head.targetPol, 1);
82 }
83 
84 
85 
86 void evio_output :: WriteGenerated(MOutputs* output, vector<MGeneratedParticle> MGP)
87 {
88  double MAXP = output->gemcOpt.args["NGENP"].arg;
89 
90  vector<double> pid;
91  vector<double> px;
92  vector<double> py;
93  vector<double> pz;
94  vector<double> vx;
95  vector<double> vy;
96  vector<double> vz;
97 
98  for(unsigned int i=0; i<MAXP && i<MGP.size(); i++)
99  {
100  pid.push_back((double) MGP[i].PID);
101  px.push_back(MGP[i].momentum.getX()/MeV);
102  py.push_back(MGP[i].momentum.getY()/MeV);
103  pz.push_back(MGP[i].momentum.getZ()/MeV);
104  vx.push_back(MGP[i].vertex.getX()/cm);
105  vy.push_back(MGP[i].vertex.getY()/cm);
106  vz.push_back(MGP[i].vertex.getZ()/cm);
107  }
108 
109  // creating and inserting generated particles bank >> TAG=10 NUM=0 <<
110  generatedp = evioDOMNode::createEvioDOMNode(10, 0);
111  evioDOMNodeP rawbankhit = evioDOMNode::createEvioDOMNode(10, 200);
112  *generatedp << rawbankhit;
113 
114 
115  // tag, num hardcoded here, should not be
116  *rawbankhit << evioDOMNode::createEvioDOMNode(10, 10, pid);
117  *rawbankhit << evioDOMNode::createEvioDOMNode(10, 20, px);
118  *rawbankhit << evioDOMNode::createEvioDOMNode(10, 30, py);
119  *rawbankhit << evioDOMNode::createEvioDOMNode(10, 40, pz);
120  *rawbankhit << evioDOMNode::createEvioDOMNode(10, 50, vx);
121  *rawbankhit << evioDOMNode::createEvioDOMNode(10, 60, vy);
122  *rawbankhit << evioDOMNode::createEvioDOMNode(10, 70, vz);
123 
124 
125  *event << generatedp;
126 
127 }
128 
129 
130 
131 void evio_output :: SetBankHeader(int bankid, string SDName, MOutputs* output)
132 {
133  bankID = bankid;
134  bankevent = evioDOMNode::createEvioDOMNode(bankID, 0);
135  *event << bankevent ;
136 }
137 
138 
139 
141 {
142  // check for double/int sizes consistency
143  unsigned int nraws, ndigit;
144  nraws=ndigit=0;
145  for(unsigned int i=0; i<mbank.name.size(); i++)
146  {
147  if(mbank.type[i] == 0) ndigit++;
148  if(mbank.type[i] == 1) nraws++;
149  }
150  if(PHout.raws.size() != nraws || PHout.dgtz.size() != ndigit)
151  {
152  cout << " Output does not match bank definition. This hit won't be written in the output stream." << endl;
153  cout << " nraws size: " << nraws << " Output nraws: " << PHout.raws.size() << endl;
154  cout << " ndgtz size: " << ndigit << " Output ndgt: " << PHout.dgtz.size() << endl;
155  return;
156  }
157 
158  vector<double> rawinf;
159  vector<int> dgtinf;
160 
161  for(unsigned int r=0; r<nraws; r++)
162  rawinf.push_back(PHout.raws[r]);
163 
164  for(unsigned int d=0; d<ndigit; d++)
165  dgtinf.push_back(PHout.dgtz[d]);
166 
167  rawinfos.push_back(rawinf);
168  dgtinfos.push_back(dgtinf);
169 }
170 
171 
172 void evio_output :: SaveSimConditions(MOutputs* output, map<string, string> sims)
173 {
174  vector<string> data;
175 
176  // for better formatting, writing both key and argument as one string
177  for(map<string, string>::iterator it=sims.begin(); it!=sims.end(); it++)
178  {
179  data.push_back(it->first + ": " + it->second + " ");
180  }
181 
182  event = new evioDOMTree(1, 0);
183 
184  *event << evioDOMNode::createEvioDOMNode(5, 1, data);
185 
186  output->pchan->write(*event);
187  delete event;
188 }
189 
190 
191 
192 
193 
vector< vector< int > > dgtinfos
Definition: evio_output.h:40
void WriteGenerated(MOutputs *, vector< MGeneratedParticle >)
Pure Virtual Method to write generated particles infos.
Definition: evio_output.cc:86
vector< double > raws
Raw information.
Definition: MPHBaseClass.h:26
evioDOMNodeP generatedp
Definition: evio_output.h:36
evioDOMTree * event
Definition: evio_output.h:34
double beamPol
Beam Polarization.
void RecordAndClear(MOutputs *, MBank)
Pure Virtual Method to record hits in event / then clear hits objects on heap.
Definition: evio_output.cc:8
void SaveSimConditions(MOutputs *, map< string, string >)
Pure Virtual Method to save the simulation conditions on the file.
Definition: evio_output.cc:172
vector< int > id
Output variable identifier.
Definition: MBankdefs.h:36
vector< string > name
Variable name.
Definition: MBankdefs.h:35
void SetBankHeader(int, string, MOutputs *)
Pure Virtual Method to set the bank header.
Definition: evio_output.cc:131
vector< int > type
Type of variable: 0=int, 1=double.
Definition: MBankdefs.h:37
evioDOMNodeP bankevent
Definition: evio_output.h:35
double d[nslayers]
Definition: dc12geom.h:45
map< string, opts > args
Options map.
Definition: usage.h:68
double targetPol
Target Polarization.
void WriteEvent(MOutputs *)
Pure Virtual Method to write event on disk.
Definition: evio_output.cc:65
gemc_opts gemcOpt
void SetOutpHeader(header, MOutputs *)
Pure Virtual Method to set the output header. MOutputs needed for some output (txt) ...
Definition: evio_output.cc:71
evioFileChannel * pchan
double r
Definition: dc12geom.h:54
vector< int > dgtz
Digitized information.
Definition: MPHBaseClass.h:27
vector< vector< double > > rawinfos
Definition: evio_output.h:39
int evn
Event number.
void ProcessOutput(PH_output, MOutputs *, MBank)
Pure Virtual Method to process the output.
Definition: evio_output.cc:140