Pluto v6.3.0
Loading...
Searching...
No Matches
PHGeantOutput.cc
Go to the documentation of this file.
1
2// File output interface implementation file
3//
4// This class serves as ASCII file output class.
5// This IO class supports all standard ascii io formats
6// of PReaction plus additional formats exclusivly used
7// by HGeant of HADES. The output flags getVERTEX and writeINDEX
8// are transported from the settings of PReaction.
9// Below the coding of the header flag for the Geant IO are listed.
10//
11// getVERTEX -> write out the vertex coordinates of the particles
12// writeINDEX -> write out parent index
13// writeSEQNUMBER -> write out event sequence number for each particle (used for embedding)
14//
15// //----------------------------------------------
16// // construct the header flag : normal flag + 10
17// Int_t shift = 0;
18// if(writeSEQNUMBER) shift = 10;
19// if(!getVERTEX && writeINDEX == 0) flag = (2 + shift);
20// if(!getVERTEX && writeINDEX != 0) flag = - (2 + shift);
21// if( getVERTEX && writeINDEX == 0) flag = (4 + shift);
22// if( getVERTEX && writeINDEX != 0) flag = - (4 + shift);
23// //----------------------------------------------
24//
25// The above header flags are analyzed by HGeant during ascii file io
26// to set the input mode.
27//
28//
29//----------------------------------------------
30// USAGE:
31//
32// {
33// PReaction my_reaction(..settings...); // create reaction
34//
35// ... // add all channels , bulk etc
36//
37// PHGeantOutput* output = new PHGeantOutput(); // created output
38// output->OpenFile("filename"); // open file
39// my_reaction.AddFileOutput(output); // connect output to raection
40//
41// ... // do all other actions
42//
43// my_reaction.Loop(nEvents); // run event loop
44// output->CloseFile(); // close output
45// }
46//
47// Author: Jochen Markert
48// Written: 05/12/2007
49// Revised:
50//
52
53#include "PHGeantOutput.h"
54#include "PReaction.h"
55#include "PData.h"
56#include "TString.h"
57
58
59
61
62 // init variables
63 asciiFile = NULL;
64 ctEvt = 0;
65 writeSEQNUMBER = kTRUE;
66
67 //globals from data base
68 event_impact_param = makeStaticData()->GetBatchValue("_event_impact_param");
69 seqnr = makeStaticData()->GetBatchValue("_event_seqnr");
70}
71
72bool PHGeantOutput::OpenFile(const char *_filename) {
73 // open the ascii output file. returns kFALSE
74 // if not successful.
75
76 if(_filename){
77 filename = _filename;
78 TString name = _filename;
79 if(name.CompareTo("") != 0){
80 asciiFile = fopen(name.Data(),"w");
81 if(!asciiFile){
82 Error("PHGeantOutput::OpenFile()", "NULL pointer retrieved for output!");
83 return kFALSE;
84 } else {
85 Info("PHGeantOutput::OpenFile()", "Opened ascii file IO = %s!", name.Data());
86 return kTRUE;
87 }
88 } else {
89 Error("PHGeantOutput::OpenFile()", "No File name set for output!");
90 return kFALSE;
91 }
92 }
93 return kFALSE;
94}
95
96
98 // close ascii output file and put the
99 // pointer to Null.
100 if(asciiFile){
101 fclose(asciiFile);
102 asciiFile = NULL;
103 return kTRUE;
104 }
105
106 return kFALSE;
107}
108
110 // Write the event header. The io flag is coded
111 // by the diffent switches. The blast parameter
112 // is taken from the first channel (if it exists)
113 // otherwise blast will be 0.
114
115 Int_t flag = 0;
116 Float_t blast = 0;
117
118 if(channel) {
119 blast = channel[0]->GetBT();
120 }
121
122 //----------------------------------------------
123 // construct the header flag : normal flag + 10
124 Int_t shift = 0;
125 if(writeSEQNUMBER) shift = 10;
126 if(!getVERTEX && writeINDEX == 0) flag = (2 + shift);
127 if(!getVERTEX && writeINDEX != 0) flag = - (2 + shift);
128 if( getVERTEX && writeINDEX == 0) flag = (4 + shift);
129 if( getVERTEX && writeINDEX != 0) flag = - (4 + shift);
130 //----------------------------------------------
131
132
133 if(asciiFile){
134 fprintf(asciiFile, " %i %i %f %f %i\n", ctEvt, cnt, blast, *event_impact_param, flag);
135
136 ctEvt ++;
137 return kTRUE;
138 }
139
140 return kFALSE;
141}
142
143
145 // write one particle to the ascii output file.
146 // the format of the line depends on the settings of
147 // different switches.
148 if(!par->IsActive()) return kTRUE;
149
150 if(branchNum) return kTRUE; //skip additional particle for the time being
151
152 if(asciiFile ) {
153 if (!getVERTEX) {
154 if(writeINDEX == 0) {
155 if(!writeSEQNUMBER){
156 fprintf(asciiFile," %e %e %e %e %i %i %i %e\n", // 8 vars
157 par->E() , par->Px(), par->Py(), par->Pz(),
158 par->ID(), par->GetSourceId() , par->GetParentId(),
159 par->W());
160 return kTRUE;
161 } else {
162 fprintf(asciiFile," %e %e %e %e %i %i %i %e %i\n", // 9 vars
163 par->E() , par->Px(), par->Py(), par->Pz(),
164 par->ID(), par->GetSourceId() , par->GetParentId(),
165 par->W(), (Int_t) *seqnr );
166 return kTRUE;
167 }
168 } else {
169 if(!writeSEQNUMBER){
170 fprintf(asciiFile," %e %e %e %e %i %i %i %i %e\n", // 9 vars
171 par->E() , par->Px() , par->Py() , par->Pz(),
172 par->ID(), par->GetSourceId(), par->GetParentId(), par->GetParentIndex(),
173 par->W());
174 return kTRUE;
175 } else {
176 fprintf(asciiFile," %e %e %e %e %i %i %i %i %e %i\n", // 10 vars
177 par->E() , par->Px() , par->Py() , par->Pz(),
178 par->ID(), par->GetSourceId(), par->GetParentId(), par->GetParentIndex(),
179 par->W(), (Int_t)*seqnr);
180 return kTRUE;
181 }
182 }
183 } else {
184
185 if (writeINDEX == 0) {
186 if(!writeSEQNUMBER){
187 fprintf(asciiFile," %e %e %e %e %e %e %e %e %i %i %i %e\n", // 12 vars
188 par->E() , par->Px() , par->Py() , par->Pz(),
189 par->T()/300., par->X() , par->Y() , par->Z(),
190 par->ID() , par->GetSourceId(), par->GetParentId(), par->W());
191 return kTRUE;
192 } else {
193 fprintf(asciiFile," %e %e %e %e %e %e %e %e %i %i %i %e %i\n", // 13 vars
194 par->E() , par->Px() , par->Py() , par->Pz(),
195 par->T()/300., par->X() , par->Y() , par->Z(),
196 par->ID() , par->GetSourceId(), par->GetParentId(), par->W(),
197 (Int_t)*seqnr);
198 return kTRUE;
199 }
200 } else {
201 if(!writeSEQNUMBER){
202 fprintf(asciiFile," %e %e %e %e %e %e %e %e %i %i %i %i %e\n", // 13 vars
203 par->E() , par->Px() , par->Py() , par->Pz(),
204 par->T()/300., par->X() , par->Y() , par->Z(),
205 par->ID() , par->GetSourceId(), par->GetParentId(),
206 par->GetParentIndex(), par->W());
207 return kTRUE;
208 } else {
209 fprintf(asciiFile," %e %e %e %e %e %e %e %e %i %i %i %i %e %i\n", // 14 vars
210 par->E() , par->Px() , par->Py() , par->Pz(),
211 par->T()/300., par->X() , par->Y() , par->Z(),
212 par->ID() , par->GetSourceId(), par->GetParentId(),
213 par->GetParentIndex(), par->W(), (Int_t)*seqnr);
214 return kTRUE;
215 }
216 }
217 }
218 }
219 return kFALSE;
220}
221
222
Float_t blast
Definition NiNi_2AGeV.C:8
ClassImp(PBeamLineSimulation) PBeamLineSimulation
PStaticData * makeStaticData()
PParticle * par[11]
Int_t writeINDEX
transport getVERTEX switch from PReaction
Definition PFileOutput.h:22
Int_t getVERTEX
number of particles in branch
Definition PFileOutput.h:21
Int_t branchNum
transport number of channels in array
Definition PFileOutput.h:28
const char * filename
Branch name.
Definition PFileOutput.h:31
PChannel ** channel
transport asciiOUTPUT switch from PReaction
Definition PFileOutput.h:25
bool WriteEventHeader(void)
bool OpenFile(const char *_filename)
bool CloseFile(void)
Bool_t writeSEQNUMBER
bool WriteParticle(PParticle *par)
Double_t * GetBatchValue(const char *name, Int_t make_val=1)