-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVG_writeVBF.h
442 lines (356 loc) · 14.5 KB
/
VG_writeVBF.h
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
/*! \brief VG_writeVBF class for writing vbf simulation files
Version 1.0
Charlie Duke
Grinnell College
May 5, 2010
This code mirrors the older GrISU_writeVBF class used with the grisudet
detector code in GrISU. However, this code has a generic interface
independent of the grisudet code and can be used with any simulation
detector code.
*/
#ifndef VG_WRITEVBF
#define VG_WRITEVBF
class VBankFileWriter; //!< forward declarations of VBF classes and structure
struct VArrayConfiguration;
class VPixelLocation;
class VATime;
struct VEventType;
class VPacket;
class VArrayEvent;
class VEvent;
class VArrayTrigger;
struct VSimulationData;
class VCorsikaSimulationData;
class TRandom3; //!< forward declaration of random number generator
class VG_writeVBF {
private:
bool fPedFlag; //!< if true, pedestals are generated
std::string fPedFileName; //!< filename for separate peds file, if "" no file
std::vector< std::vector<VPixelLocation> > *fTelPixV; //!< vector containing pixel location vector for each telescope
std::vector<float> fTelSouth; //<! vector containing telescope locations, South direction
std::vector<float> fTelEast; //<! vector containing telescope locations, East direction
std::vector<float> fTelUp; //<! vector containing telescope locations, Up direction
TRandom3 *frand; //<! pointer to random number generator from ROOT
unsigned fnbr_tel; //!< number of telescopes
float fObsAlt; //!< observatory altitude
std::vector<unsigned> fnumPixV; //!< vector of number of pixels in each camera
std::string fVbfFileName; //!< name of vbf file for writing
long fRunNumber; //!< runnumber (from pilot file or default)
bool fpedestalevent; //!< true for pedestal event, false for data event
int fDebugLevel; //!< debug print level; if 0, no debug printing
u_int32_t fEventNumber; //!< current event number
u_int32_t fPedEventCount; //!< current pedestal count
VATime *fEventTime; //!< event time for next event
VATime *fPedEventTime; //!< event time for next pedestal event
u_int8_t fGPSYear; //!< GPS variables used by all VATime classes
u_int16_t fGPSWords[5]; //!< GPS words used by VATime classes
unsigned fnumFADCSamples; //!< number of fadc time bins
unsigned fnumPmts; //!< number of pixels
unsigned fnumTelsWithData; //!< number of telescopes with data
unsigned fnumTrigTels; //!< number of triggered telescopes
bool ftriggered_readout; //!< if true, readout all telescopes
VEventType *fEvType; //!< pointer to eventtype created in make_packet
std::vector<float> aztel; //!< telescope azimuth in degree units
std::vector<float> eltel; //!< telescope elevation in degree units
std::string fConfigMaskPed; //!< config.mask string for ped events
std::string fConfigMaskAll; //!< config.mask string for all telescopes
unsigned short fCMaskPed; //<! vbf config.make for pedestal events
unsigned short fCMaskTrig; //<! vbf config.mask for data, local triggers
unsigned short fCMaskAll; //<! vbf config.mask for all telescopes
unsigned fmaxNumChannels; //!< set by default to 500 (why not 499?)
unsigned fcurrent_tel; //!< current telescope id
unsigned fcurrent_pix; //!< current pixel id
unsigned fnum_vevent; //!< number of VEvent's in shower (for debugging)
bool fmake_pedestal_now_flag; //!< set when event time > ped time
std::string fSimConfigFile; //!< string written to VSimulationHeader
std::string fFirstValidEventTimeStr; //!< string to initialize event times
double fEventRatePerSec; //!< data rate in Hertz
double fMeanTimeBetweenEventsSec; //!< mean time between events in seconds
int fPedTimeInterval; //!< time interval between pedestal events, in seconds (integer)
u_int32_t fCorsikaParticleIDType; //<! Corika style particle type number
bool fFirstArgon; //!< needed for Kascade2Corsika particle type conversion
VBankFileWriter *pfWriter; //!< pointer to vbf bank class
VPacket *packet; //!< pointer to vbf packet class
VArrayEvent *ae; //!< pointer to vbf arrayevent class
VEvent *event; //!< pointer to vbf event class
std::vector<VEvent*> events; //!< vector of pointers to VEvent class
VArrayTrigger *at; //!< pointer to vbf arraytrigger class
VSimulationData *simu_data; //!< pointer to vbf simul.data class
VCorsikaSimulationData * cors_data;
/*! Used internally in converting kascade id to Corsika id
*/
void MassNumber2ChargeAndMass(
int fIAtomicNum,int& fCharge, double& fMass);
/*! Used internally to convert double to nearest integer
*/
int NearestInt(double fX);
/*! Used internally, for initialization
*/
void initialize();
public:
/*! Constructor
\param numTel number of telescopes
\param numPixTel vector of number of pixels per telescope
\param vbfFileName vbf output filename, default "photon.vbf"
\param vbfRunNumber vbf run number, default 99999
\param debugLevel debug level for testing, default 0 (no printing)
*/
VG_writeVBF(const int &numTel,
const std::vector<unsigned> &numPixTel,
const std::string &vbfFileName="photon.vbf",
const long &vbfRunNumber=99999,
const int &debugLevel=0);
/*! Destructor
*/
~VG_writeVBF() {};
/*! set telescope location
\param telId telescope identification number, numbering from zero
\param telSouthLoc relative location south of array origin
\param telEastLoc relative location east of array origin
\param telUpLoc relative location up from array origin
*/
void setTelescopeLocations(const int & telId, const float & telSouthLoc,
const float & telEastLoc,
const float & telUpLoc);
/*! set pixel locations
\param telId telescope identification, numbering from zero
\param pixId pixel number for that telescope, numbering from zero
\param pixEastLocDeg pixel East location in Degrees, telescope in stow
\param pixUpLocDeg pixel Up location in Degrees, telescope in stow
\param pixRadDeg pixel radius in Degrees
*/
void setPixelLocations(const int &telId, const int &pixId,
const float &pixEastLocDeg,
const float &pixUpLocDeg,
const float &pixRadDeg);
/*! Make vbf VSimulationHeader class and put into vbf packet
\param configFilePlus string with user supplied information
\param simulator name of simulator
\param obserAltitudeM observatory altitude in meters above mean sea level
\param simulationPackage see enum SimulationPackageCodes for possible values
\param atmosphericModel use 0, only current value
\return true
*/
bool makeSimulationHeader(std::string &configFilePlus,
const std::string &simulator,
const float &obserAltitudeM,
const u_int32_t &simulationPackage,
const u_int32_t &atmosphericModel=0);
/*! set pedestal parameters
\param makePedsFlag make pedestals if true, default true
\param pedTimeIntervalS time interval (seconds between peds, default 1 sec
\param pedFileName name of separate peds file, default "" (no file)
*/
void setPedestalParameters(const bool &makePedsFlag=true,
const int &pedTimeIntervalS= 1,
const std::string &pedFileName="");
/*! set first event time string
\param firstEventTime, first event time: example format "2006-11-28 02:00:00.000000000 GPS"
\return true
*/
void setFirstEventTimeString(const std::string &firstEventTime);
/*! set shower frequency
\param showerfreq shower frequency in hz, default 100.0
*/
void setShowerFrequencyHz(const double &showerfreq= 100.0);
/*! create VATime classes for showers and peds
\return true
*/
bool makeEventTimeClasses();
/*! set the azimuth(degrees) and elevation(degrees) for each telescope
\param telId telescope number, starting from zero
\param azimDeg azimuth in degrees
\param elevDeg elevation in degrees
\return true
*/
void setAzimElevTelDeg(const unsigned &telId, const float &azimDeg,
const float &elevDeg);
/*! create new vbf VPacket class
\return true
*/
bool makePacket();
/*! store packet in vbf file
\return true
*/
bool storePacket();
/*! make new vbf VEvent class
\return true
*/
bool makeEvent();
/*! store VEvent class in vbf arrayevent
\return true
*/
bool storeEvent();
/*! make new vbf VArrayEvent class
\return true
*/
bool makeArrayEvent();
/*! store VarrayEvent class in vbf packet
\return true
*/
bool storeArrayEvent();
/*! store time bin using event->SetSample method
\param ti time bin index
\param iDC time bin data in digital counts
\param iPC time bin pedestal in digital counts
*/
void storeSample(int &ti,int &iDC);
/*! make a VSimulationData class using default values
and put into the vbf packet. Normally used with pedestal packets
\return true
*/
// NEED TO FIX THIS, USE DEFAULTS BELOW IF POSSIBLE.
bool makeVSimulationData1();
/*! make a VSimulationData class
use no arguments in call for simulation data for pedestals
the vbf packet. Normally used with data packets
\param energyGeV primary energy in GeV
\param primaryZenithAngleDeg primary zenith angle in degrees
\param primaryAzimuthDe primary azimuth in degrees
\param primaryCoreEastM core location East
\param primaryCoreSouthM core location South
\param primaryCoreElevMASL, negative value replaces observatory height
zero value sets Core Elevation to zero
\param corsikaParticleID
\return true
*/
bool makeVSimulationData(const float &energyGeV=0.0,
const float &primaryZenithAngleDeg=0.0,
const float &primaryAzimuthDeg=0.0,
const float &primaryCoreEastM=0.0,
const float &primaryCoreSouthM=0.0,
const float &primaryCoreElevMASL=0.0,
const float &firstInteractionHeight=0.0,
const float &firstInteractionDepth=0.0,
const u_int32_t &corsikaParticleID=1,
const u_int32_t &corsikaRunNumber = 0,
const u_int32_t &fShowerID = 0
);
/*! make a VArrayTrigger class, get triggering information
\param localTriggerV vector of local trigger 0/1 for each telescope
\return true
*/
bool makeArrayTrigger(const std::vector<int> &localTriggerV);
/*! make a VArrayTrigger, used for pedestals only
\return true
*/
bool makeArrayTrigger();
/*! store the VArrayTrigger class in VArrayEvent
\return true
*/
bool storeArrayTrigger();
/*! create vbf file index and write checksum
*/
void finishVBF();
/*! labels event as a pedestal event
\return true
*/
void setPedestalEvent() {fpedestalevent=true;};
/*! labels event as a data event
*/
void setDataEvent() {fpedestalevent=false;};
/*! sets the current telescope number (starting at 0)
\param tel current telescope number
*/
void setTelescope(const int &tel) {fcurrent_tel = tel;};
/*! sets the current pixel number (starting at 0)
\param pix current pixel number
*/
void setPixel(const int &pix) {fcurrent_pix = pix;};
/*! gets the current vbf event number
\return eventnumber
*/
u_int32_t getEventNumber() {return fEventNumber;};
/*! gets the current vbf pedestal event count
\return current pedestal event count
*/
u_int32_t getPedEventCount() {return fPedEventCount; };
/*! prints to cout: event number and pedestal event number
*/
void getStats();
/*! converts kascade particle id to Corsika particle id
\param fKType kascade particle id
\return Corsika particle id
*/
u_int32_t KascadeType2CorsikaType(u_int32_t fKType);
// time management methods (can connect two vbf writers, e.g. for peds)
/*! gets current pedestal event time as pointer to VATime class
\return VATime class pointer for current pedestal event time
*/
VATime *getPedEventTime();
/*! sets pedestal event time
\param eventtime pointer to VATime class
\return true
*/
void setPedEventTime(VATime *eventtime);
/*! sets eventtime
\param eventtime pointer to VAtime class
*/
void setEventTime(VATime *eventtime);
/*! gets current event time as pointer to VATime class
\return true
*/
VATime *getEventTime();
/*! increment event time
*/
bool incrementEventTime();
/*! increment pedestal time
\return true
*/
bool incrementPedTime();
/*! flag that, if true, indicates it's time to make a pedestal event
\return bool
*/
bool makePedestalNow();
/*! print year, month, day, hour, min, sec, nanosec for testing
\param vat VATime class pointer
*/
void testVATime(VATime *vat);
/*! set change and pedestal for the current pixel to zero
*/
void setChargePedHigain();
/*! set high/low gain
\param bhilo if true, set to high gain; false, low gain
*/
void setHiLoGain(const bool &bhilo);
/*! set pixel trigger bit, need to setPixel(int pix) first
/param btrigger set to true if pixel fired
*/
void setTriggerBit(bool btrigger);
/*!
*/
void setTriggeredReadout(const bool &triggered_readout);
/*! set seed for TRandom3, unsigned integer
/param iseed, seed: default = 111
*/
void setSeed(const unsigned &iseed=111);
/*! set particleIDType
\param particleIDType, 0 for kascade, 1 for corsika
*/
void setParticleIDType(const u_int32_t &particleIDType) {
fCorsikaParticleIDType = particleIDType;
};
/*! set debug print level, 0: no printout, 1: print all parameters
\param debugLevel
*/
void setDebugLevel(const int &debugLevel);
/*! setMaxNumberChannels: internally set to 500, set only if !=500. same for all cameras
\param maxNumberChannels
*/
void setMaxNumberChannels(const unsigned &maxNumberChannels) {
fmaxNumChannels = maxNumberChannels;
};
/*! setNumFadcSamples: internally set to 24, set only if !=24, all fadcs have same number of channels
\param numFadcSamples
*/
void setNumFadcSamples(const unsigned &numFadcSamples) {
fnumFADCSamples = numFadcSamples;
};
/*! print error message to stderr, do not exit
*/
int showErrorVbfWriter(const char *msg);
/*! print error message to stderr, exit code
*/
int showXErrorVbfWriter(const char *msg);
};
#endif