GEMC  2.3
Geant4 Monte-Carlo Framework
txt_output.cc
Go to the documentation of this file.
1 // gemc headers
2 #include "txt_output.h"
3 #include "utils.h"
4 
5 // C++ headers
6 #include <fstream>
7 
8 // CLHEP units
9 #include "CLHEP/Units/PhysicalConstants.h"
10 using namespace CLHEP;
11 
12 
13 // record the simulation conditions
14 // the format is a string for each variable
15 void txt_output :: recordSimConditions(outputContainer* output, map<string, string> simcons)
16 {
17  ofstream *txtout = output->txtoutput ;
18 
19  *txtout << " Simulation Conditions, TAG " << SIMULATION_CONDITIONS_BANK_TAG << ":" << endl;
20 
21  for(map<string, string>::iterator it = simcons.begin(); it != simcons.end(); it++)
22  *txtout << " > " << it->first << " " << it->second << endl;
23 }
24 
25 
26 
27 
28 // write header bank
29 // initialize insideBank to zero
30 void txt_output :: writeHeader(outputContainer* output, map<string, double> data, gBank bank)
31 {
32  insideBank.clear();
33  ofstream *txtout = output->txtoutput ;
34 
35 
36  *txtout << " --- Header Bank -- " << endl;
37  *txtout << " - (" << HEADER_BANK_TAG << ", " << bank.getVarId("time") << ") " << "time:\t" << timeStamp() << endl;
38 
39  for(map<string, double> :: iterator it = data.begin(); it != data.end(); it++)
40  {
41  int bankId = bank.getVarId(it->first);
42 
43  if(bankId)
44  *txtout << " - (" << HEADER_BANK_TAG << ", " << bankId << ") " << it->first << ":\t" << it->second << endl;
45  }
46  *txtout << " --- End of Header Bank -- " << endl;
47 
48 
49 }
50 
51 void txt_output :: writeGenerated(outputContainer* output, vector<generatedParticle> MGP, map<string, gBank> *banksMap)
52 {
53  double MAXP = output->gemcOpt.optMap["NGENP"].arg;
54  ofstream *txtout = output->txtoutput ;
55 
56  gBank bank = getBankFromMap("generated", banksMap);
57 
58  *txtout << " --- Generated Particles Bank -- " << endl;
59 
60  for(unsigned int i=0; i<MAXP && i<MGP.size(); i++)
61  {
62  *txtout << " - Particle " << i+1 << " pid: "<< MGP[i].PID
63  << " - mom: " << MGP[i].momentum/MeV
64  << " MeV - vert: " << MGP[i].vertex/mm << " mm" << endl;
65 
66  for(unsigned d=0; d<MGP[i].pSum.size(); d++)
67  {
68  *txtout << " - Hit >" << MGP[i].pSum[d].dname
69  << "< Has " << MGP[i].pSum[d].stat << " hit";
70  if(MGP[i].pSum[d].stat>1) *txtout << "s";
71 
72  if(MGP[i].pSum[d].etot > 0)
73  {
74  *txtout << " with etot " << MGP[i].pSum[d].etot/MeV
75  << " MeV and time " << MGP[i].pSum[d].t << " ns" << endl;
76  }
77  else if(MGP[i].pSum[d].nphe > 0)
78  {
79  *txtout << " with nphe " << MGP[i].pSum[d].nphe
80  << " nphe and time " << MGP[i].pSum[d].t << " ns" << endl;
81  }
82  }
83  }
84  *txtout << " --- End of Generated Particles Bank -- " << endl;
85 }
86 
87 void txt_output :: initBank(outputContainer* output, gBank thisHitBank)
88 {
89  if(!insideBank[thisHitBank.bankName])
90  {
91  ofstream *txtout = output->txtoutput ;
92  *txtout << " --- " << thisHitBank.bankName << " (" << thisHitBank.idtag << ", " << DETECTOR_BANK_ID << ") ---- " << endl;
93  insideBank[thisHitBank.bankName] = 1;
94  }
95 }
96 
97 // write out true information. This is common to all banks
98 // and not contained in the banks definitions
99 void txt_output :: writeG4RawIntegrated(outputContainer* output, vector<hitOutput> HO, string hitType, map<string, gBank> *banksMap)
100 {
101  gBank thisHitBank = getBankFromMap(hitType, banksMap);
102  gBank rawBank = getBankFromMap("raws", banksMap);
103 
104  initBank(output, thisHitBank);
105  ofstream *txtout = output->txtoutput ;
106 
107  *txtout << " -- integrated true infos bank (" << thisHitBank.idtag + RAWINT_ID << ", 0) -- " << endl;
108  for(map<int, string>::iterator it = rawBank.orderedNames.begin(); it != rawBank.orderedNames.end(); it++)
109  {
110  int bankId = rawBank.getVarId(it->second);
111  int bankType = rawBank.getVarBankType(it->second);
112 
113  // we only need the first hit to get the definitions
114  map<string, double> raws = HO[0].getRaws();
115 
116  // bankID 0 is hit index
117  if(raws.find(it->second) != raws.end() && bankId >= 0 && bankType == RAWINT_ID)
118  {
119  *txtout << " - (" << rawBank.idtag + thisHitBank.idtag << ", " << bankId << ") " << it->second << ":\t" ;
120  for(unsigned int nh=0; nh<HO.size(); nh++)
121  {
122  map<string, double> theseRaws = HO[nh].getRaws();
123  *txtout << theseRaws[it->second] << "\t" ;
124  }
125  *txtout << endl;
126  }
127  }
128  *txtout << " -- end of integrated raw bank." << endl;
129 }
130 
131 
132 
133 
134 // write out true information step by step. This is common to all banks
135 // and not contained in the banks definitions
136 void txt_output :: writeG4RawAll(outputContainer* output, vector<hitOutput> HO, string hitType, map<string, gBank> *banksMap)
137 {
138  gBank thisHitBank = getBankFromMap(hitType, banksMap);
139  gBank allRawsBank = getBankFromMap("allraws", banksMap);
140 
141  initBank(output, thisHitBank);
142  ofstream *txtout = output->txtoutput ;
143 
144  *txtout << " -- step by step true infos bank (" << thisHitBank.idtag + RAWSTEP_ID << ", 0) -- " << endl;
145  for(map<int, string>::iterator it = allRawsBank.orderedNames.begin(); it != allRawsBank.orderedNames.end(); it++)
146  {
147  int bankId = allRawsBank.getVarId(it->second);
148  int bankType = allRawsBank.getVarBankType(it->second);
149 
150  // we only need the first hit to get the definitions
151  map<string, vector<double> > allRaws = HO[0].getAllRaws();
152 
153  // bankID 0 is hit index
154  if(allRaws.find(it->second) != allRaws.end() && bankId >= 0 && bankType == RAWSTEP_ID)
155  {
156  *txtout << " - (" << allRawsBank.idtag + thisHitBank.idtag << ", " << bankId << ") " << it->second << ":\t" ;
157  for(unsigned int nh=0; nh<HO.size(); nh++)
158  {
159  map<string, vector<double> > theseRaws = HO[nh].getAllRaws();
160 
161  vector<double> theseRawsSteps = theseRaws[it->second];
162 
163  for(unsigned s=0; s<theseRawsSteps.size(); s++)
164  *txtout << theseRawsSteps[s] << "\t" ;
165  }
166  *txtout << endl;
167  }
168  }
169  *txtout << " -- end of integrated raw bank." << endl;
170 }
171 
172 
173 
174 
175 
176 
177 void txt_output :: writeG4DgtIntegrated(outputContainer* output, vector<hitOutput> HO, string hitType, map<string, gBank> *banksMap)
178 {
179  gBank thisHitBank = getBankFromMap(hitType, banksMap);
180  gBank dgtBank = getDgtBankFromMap(hitType, banksMap);
181 
182  initBank(output, thisHitBank);
183  ofstream *txtout = output->txtoutput ;
184 
185  *txtout << " -- integrated digitized bank (" << thisHitBank.idtag + DGTINT_ID << ", 0) -- " << endl;
186 
187  for(map<int, string>::iterator it = dgtBank.orderedNames.begin(); it != dgtBank.orderedNames.end(); it++)
188  {
189  int bankId = dgtBank.getVarId(it->second);
190  int bankType = dgtBank.getVarBankType(it->second);
191 
192  // we only need the first hit to get the definitions
193  map<string, double> dgts = HO[0].getDgtz();
194 
195  // bankID 0 is hit index
196  if(dgts.find(it->second) != dgts.end() && bankId > 0 && bankType == DGTINT_ID)
197  {
198  *txtout << " - (" << dgtBank.idtag + thisHitBank.idtag << ", " << bankId << ") " << it->second << ":\t";
199 
200  for(unsigned int nh=0; nh<HO.size(); nh++)
201  {
202  map<string, double> theseDgts = HO[nh].getDgtz();
203  *txtout << theseDgts[it->second] << "\t" ;
204  }
205  *txtout << endl;
206  }
207  }
208 
209  *txtout << " -- End of integrated digitized bank." << endl;
210 }
211 
213 {
214  if(insideBank.size())
215  {
216  ofstream *txtout = output->txtoutput ;
217  *txtout << " ---- End of Event ---- " << endl;
218 
219  }
220 }
221 
string timeStamp()
Definition: utils.cc:318
void writeEvent(outputContainer *)
Definition: txt_output.cc:212
void writeGenerated(outputContainer *, vector< generatedParticle >, map< string, gBank > *banksMap)
Definition: txt_output.cc:51
void recordSimConditions(outputContainer *, map< string, string >)
Definition: txt_output.cc:15
gBank getDgtBankFromMap(string name, map< string, gBank > *banksMap)
Definition: gbank.cc:438
int idtag
unique id for the bank
Definition: gbank.h:102
int getVarBankType(string)
Definition: gbank.cc:381
#define HEADER_BANK_TAG
Definition: gbank.h:24
ofstream * txtoutput
void initBank(outputContainer *, gBank)
Definition: txt_output.cc:87
gBank getBankFromMap(string name, map< string, gBank > *banksMap)
Definition: gbank.cc:424
map< string, aopt > optMap
Options map.
Definition: options.h:75
#define DETECTOR_BANK_ID
Definition: gbank.h:39
string bankName
name of the bank, it&#39;s also key in the map but we store it here as well
Definition: gbank.h:101
map< int, string > orderedNames
Definition: gbank.h:126
virtual void writeG4RawAll(outputContainer *, vector< hitOutput >, string, map< string, gBank > *)
Definition: txt_output.cc:136
void writeG4DgtIntegrated(outputContainer *, vector< hitOutput >, string, map< string, gBank > *)
Definition: txt_output.cc:177
int getVarId(string)
Definition: gbank.cc:358
#define SIMULATION_CONDITIONS_BANK_TAG
Definition: gbank.h:21
#define RAWSTEP_ID
Definition: gbank.h:65
#define RAWINT_ID
Definition: gbank.h:50
Definition: gbank.h:86
void writeG4RawIntegrated(outputContainer *, vector< hitOutput >, string, map< string, gBank > *)
Definition: txt_output.cc:99
#define DGTINT_ID
Definition: gbank.h:61
void writeHeader(outputContainer *, map< string, double >, gBank)
Definition: txt_output.cc:30