-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathoutputFactory.h
More file actions
328 lines (242 loc) · 8.59 KB
/
Copy pathoutputFactory.h
File metadata and controls
328 lines (242 loc) · 8.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/// \file outputFactory.h
/// Defines the gemc output Factory .\n
/// It contains the factory method
/// that returns a pointer to goutputs.\n
/// The virtual method processOutput writes events to
/// the correct stream.\n
/// \author \n Maurizio Ungaro
/// \author mail: ungaro@jlab.org\n\n\n
#ifndef OUTPUT_FACTORY_H
#define OUTPUT_FACTORY_H 1
// gemc
#include "gbank.h"
#include "gemcOptions.h"
#include "MPrimaryGeneratorAction.h"
// mlibrary
#include "frequencySyncSignal.h"
// Hipo
#include "hipo4/writer.h"
#include "hipoSchemas.h"
// geant4
#include "G4ThreeVector.hh"
/// \class hitOutput
/// <b> hitOutput</b>\n\n
/// Contains dynamic output informations
/// - geant4 information, summed over the hit: vector<double> raws
/// - digitized information, from g4 summed: vector<int> dgtz
// This information is relevant to ONE hit only
// TODO: all these quantities should be references.
class hitOutput
{
private:
// geant4 integrated (over the hit) information.
// DISABLED by default
// key is variable name
map<string, double> raws;
// digitized information coming from raws
// ENABLED by default
// key is variable name
map<string, double> dgtz;
// geant4 step by step information.
// DISABLED by default
// key is variable name
map< string, vector <double> > allRaws;
// multi - digitized information from step by step
// DISABLED by default
// key is variable name
map< string, vector <int> > multiDgt;
// quantized signal as a function of time bunch
// DISABLED by default
// the first three entries are crate/slot/channel
map< int, int > quantumS;
// charge ([0]), time([1] info at every step
// DISABLED by default
// index 0: hit number
// index 1: step index
// index 2: charge at electronics
// index 3: time at electronics
// index 4: vector of identifiers - have to match the translation table
// index 5: hardware - it's a vector[3] with crate/slot/channel
map< int, vector <double> > chargeTime;
public:
void setRaws (map<string, double> r) {raws = r;}
void setDgtz (map<string, double> d) {dgtz = d;}
void setAllRaws (map< string, vector <double> > r) {allRaws = r;}
void setMultiDgt (map< string, vector <int> > d) {multiDgt = d;}
void setChargeTime (map< int, vector <double> > d) {chargeTime = d;}
void setOneRaw (string s, double d) {raws[s] = d;}
void setOneRaw (string s, int i) {raws[s] = (double) i;}
void setOneDgt (string s, double d) {dgtz[s] = d;}
void setOneDgt (string s, int i) {dgtz[s] = (double) i;}
void createQuantumS(map< int, int > qs) {quantumS = qs;}
// may want to insert verbosity here?
map<string, double> getRaws() {return raws;}
map<string, double> getDgtz() {return dgtz;}
map< string, vector <double> > getAllRaws() {return allRaws;}
map< string, vector <int> > getMultiDgt() {return multiDgt;}
map< int, vector <double> > getChargeTime() {return chargeTime;}
map< int, int > getQuantumS() {return quantumS;}
double getIntRawVar(string s)
{
if(raws.find(s) != raws.end()) return raws[s];
return -99;
}
double getIntDgtVar(string s)
{
if(dgtz.find(s) != dgtz.end()) return dgtz[s];
return -99;
}
};
/// \class summaryForParticle
/// <b> summaryForParticle </b>\n\n
/// Contains a summary information for each detector, caused
/// by a primary particle and all its descendant
/// - stat (how many hits generated by this track)
/// - total energy
/// - fastest time
/// - nphe
/// - detector name
class summaryForParticle
{
public:
summaryForParticle(string detector)
{
dname = detector;
stat = 0;
etot = 0;
t = -1; // initializing to negative for the first assignment
nphe = 0;
}
~summaryForParticle(){;}
string dname;
int stat;
double etot;
double t;
int nphe;
};
/// \class fastMCForParticle
/// <b> fastMCForParticle </b>\n\n
/// Contains fastMC information for each detector, caused
/// by a primary particle
/// - original track momentum
/// - smeared track momentum
class fastMCForParticle
{
public:
fastMCForParticle(string detector)
{
pOrig = G4ThreeVector(0,0,0);
pSmear = G4ThreeVector(0,0,0);
}
~fastMCForParticle(){;}
/// - stat (how many hits generated by this track)
G4ThreeVector pOrig;
G4ThreeVector pSmear;
};
/// \class generatedParticle
/// <b> generatedParticle </b>\n\n
/// Contains particle informations.
/// The Primary Particles will be written to the output.\n
/// Secondary Particles will be written to the output if option is specified.\n
class generatedParticle
{
public:
generatedParticle()
{
pSum.clear();
fastMC.clear();
}
~generatedParticle(){;}
G4ThreeVector vertex;
G4ThreeVector momentum;
int PID;
double time;
int multiplicity;
// adding summary information for each detector.
vector<summaryForParticle> pSum;
vector<fastMCForParticle> fastMC;
int getVariableFromStringI(string);
double getVariableFromStringD(string);
};
class ancestorInfo
{
public:
ancestorInfo() {};
~ancestorInfo() {};
int pid;
int tid;
int mtid;
double trackE;
G4ThreeVector p;
G4ThreeVector vtx;
int getVariableFromStringI(string);
double getVariableFromStringD(string);
};
/// \class outputContainer
/// <b> outputContainer </b>\n\n
/// Contains all possible outputs.
class outputContainer
{
public:
outputContainer(goptions);
~outputContainer();
goptions gemcOpt;
string outType;
string outFile;
ofstream *txtoutput;
// hipo schema and writer
// The schemas have to be added to the writer before openning
// the file, since they are written into the header of the file.
// Thus the schema has to be declared in this base class
void initializeHipo(bool openFile);
hipo::writer *hipoWriter;
HipoSchema *hipoSchema;
};
/// \class outputFactory
/// <b> outputFactory </b>\n\n
/// outputFactory is registered in a map<string, outputFactory>\n
/// The virtual method processOutput is called at the end of each event.
class outputFactory
{
public:
// prepare event
virtual void prepareEvent(outputContainer* output, map<string, double> *configuration) ;
// record the simulation conditions on the file
virtual void recordSimConditions(outputContainer*, map<string, string>) = 0;
// write event header
virtual void writeHeader(outputContainer*, map<string, double>, gBank) = 0;
// write RF Signal
virtual void writeRFSignal(outputContainer*, FrequencySyncSignal, gBank) = 0;
// write user infos header
virtual void writeUserInfoseHeader(outputContainer*, map<string, double>) = 0;
// write generated particles
virtual void writeGenerated(outputContainer*, vector<generatedParticle>, map<string, gBank> *banksMap, vector<userInforForParticle> userInfo) = 0;
// write ancestors
virtual void writeAncestors (outputContainer*, vector<ancestorInfo>, gBank) = 0;
// write geant4 true integrated info
virtual void writeG4RawIntegrated(outputContainer*, vector<hitOutput>, string, map<string, gBank>*) = 0;
// write geant4 true info for every step
virtual void writeG4RawAll(outputContainer*, vector<hitOutput>, string, map<string, gBank>*) = 0;
// write geant4 raw integrated info
virtual void writeG4DgtIntegrated(outputContainer*, vector<hitOutput>, string, map<string, gBank>*) = 0;
// write geant4 charge / time (as seen by electronic) info
virtual void writeChargeTime(outputContainer*, vector<hitOutput>, string, map<string, gBank>*) = 0;
// write fadc mode 1 (full signal shape) - jlab hybrid banks. This uses the translation table to write the crate/slot/channel
virtual void writeFADCMode1(outputContainer*, vector<hitOutput>, int) = 0;
// write fadc mode 1 (full signal shape) - jlab hybrid banks. This uses the translation table to write the crate/slot/channel
// This method should be called once at the end of event action, and the 1st argument
// is a map<int crate_id, vector<hitoutput> (vector of all hits from that crate) >
virtual void writeFADCMode1( map<int, vector<hitOutput> >, int) = 0;
// write fadc mode 7 (integrated mode) - jlab hybrid banks. This uses the translation table to write the crate/slot/channel
virtual void writeFADCMode7(outputContainer*, vector<hitOutput>, int) = 0;
// write event and close stream if necessary
virtual void writeEvent(outputContainer*) = 0;
string outputType;
virtual ~outputFactory(){;}
};
// Define outputFactory as a pointer to a function that returns a pointer to a outputFactory
typedef outputFactory *(*outputFactoryInMap)();
// Instantiates the outputFactory
outputFactory *getOutputFactory(map<string, outputFactoryInMap>*, string);
map<string, outputFactoryInMap> registerOutputFactories();
#endif