5 #include "Fdblprc.h" //(DBLPRC) fluka common
6 #include "Fdimpar.h" //(DIMPAR) fluka parameters
7 #include "Fepisor.h" //(EPISOR) fluka common
8 #include "Fstack.h" //(STACK) fluka common
9 #include "Fstars.h" //(STARS) fluka common
10 #include "Fbeam.h" //(BEAM) fluka common
11 #include "Fpaprop.h" //(PAPROP) fluka common
12 #include "Fltclcm.h" //(LTCLCM) fluka common
13 #include "Fopphst.h" //(OPPHST) fluka common
14 //#include "Fcaslim.h" //(CASLIM) fluka common
19 #include "TVirtualMCStack.h"
20 //#include "TVirtualMCApplication.h"
22 #include "TParticle.h"
26 #include <Riostream.h>
29 # define source source_
30 # define geocrs geocrs_
31 # define georeg georeg_
32 # define geohsm geohsm_
33 # define soevsv soevsv_
35 # define source SOURCE
36 # define geocrs GEOCRS
37 # define georeg GEOREG
38 # define geohsm GEOHSM
39 # define soevsv SOEVSV
44 // Prototypes for FLUKA functions
46 void type_of_call geocrs(Double_t &, Double_t &, Double_t &);
47 void type_of_call georeg(Double_t &, Double_t &, Double_t &,
49 void type_of_call geohsm(Int_t &, Int_t &, Int_t &, Int_t &);
50 void type_of_call soevsv();
52 *----------------------------------------------------------------------*
54 * Created on 07 january 1990 by Alfredo Ferrari & Paola Sala *
57 * Last change on 21-jun-98 by Alfredo Ferrari *
59 * C++ version on 27-sep-02 by Isidro Gonzalez *
61 * This is just an example of a possible user written source routine. *
62 * note that the beam card still has some meaning - in the scoring the *
63 * maximum momentum used in deciding the binning is taken from the *
64 * beam momentum. Other beam card parameters are obsolete. *
66 *----------------------------------------------------------------------*/
68 void source(Int_t& nomore) {
69 // Get the pointer to TFluka
70 TFluka* fluka = (TFluka*)gMC;
72 Int_t verbosityLevel = fluka->GetVerbosityLevel();
73 Bool_t debug = (verbosityLevel>=3)?kTRUE:kFALSE;
75 cout << "==> source(" << nomore << ")" << endl;
76 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
79 static Bool_t lfirst = true;
80 static Bool_t particleIsPrimary = true;
81 static Bool_t lastParticleWasPrimary = true;
86 TVirtualMCStack* cppstack = fluka->GetStack();
90 Int_t nprim = cppstack->GetNprimary();
91 // Get the next particle from the stack
92 particle = cppstack->PopNextTrack(itrack);
93 fluka->SetTrackIsNew(kTRUE);
95 // Is this a secondary not handled by Fluka, i.e. a particle added by user action ?
96 lastParticleWasPrimary = particleIsPrimary;
98 if (itrack >= nprim) {
99 particleIsPrimary = kFALSE;
101 particleIsPrimary = kTRUE;
105 EPISOR.tkesum = zerzer;
107 EPISOR.lussrc = true;
110 // Post-track actions for primary track
112 if (particleIsPrimary) {
113 TVirtualMCApplication::Instance()->PostTrack();
114 TVirtualMCApplication::Instance()->FinishPrimary();
115 if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack);
119 // Exit if itrack is negative (-1). Set lsouit to false to mark last track for this event
123 EPISOR.lsouit = false;
125 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
126 cout << "\t* No more particles. Exiting..." << endl;
127 cout << "<== source(" << nomore << ")" << endl;
133 // Handle user event abortion
134 if (fluka->EventIsStopped()) {
135 printf("Event has been stopped by user !");
136 fluka->SetStopEvent(kFALSE);
138 EPISOR.lsouit = false;
142 //Get some info about the particle and print it
145 Int_t pdg = particle->GetPdgCode();
146 TVector3 polarisation;
147 particle->GetPolarisation(polarisation);
149 cout << "\t* Particle " << itrack << " retrieved..." << endl;
150 cout << "\t\t+ Name = " << particle->GetName() << endl;
151 cout << "\t\t+ PDG/Fluka code = " << pdg
152 << " / " << fluka->IdFromPDG(pdg) << endl;
153 cout << "\t\t+ P = ("
154 << particle->Px() << " , "
155 << particle->Py() << " , "
156 << particle->Pz() << " ) --> "
157 << particle->P() << " GeV" << endl;
159 /* Lstack is the stack counter: of course any time source is called it
162 /* Cosines (tx,ty,tz)*/
163 Double_t cosx = particle->Px()/particle->P();
164 Double_t cosy = particle->Py()/particle->P();
165 Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
166 if (particle->Pz() < 0.) cosz = -cosz;
168 //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
169 if (pdg != 50000050 && pdg != 50000051) {
171 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(pdg);
173 /* Wt is the weight of the particle*/
174 STACK.wt[STACK.lstack] = oneone;
175 STARS.weipri += STACK.wt[STACK.lstack];
177 STACK.lo[STACK.lstack] = 1;
179 /* User dependent flag:*/
180 STACK.louse[STACK.lstack] = 0;
182 /* User dependent spare variables:*/
184 for (ispr = 0; ispr < mkbmx1; ispr++)
185 STACK.sparek[STACK.lstack][ispr] = zerzer;
187 /* User dependent spare flags:*/
188 for (ispr = 0; ispr < mkbmx2; ispr++)
189 STACK.ispark[STACK.lstack][ispr] = 0;
191 /* Save the track number of the stack particle:*/
192 STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
194 STACK.numpar[STACK.lstack] = STACK.nparma;
195 STACK.nevent[STACK.lstack] = 0;
196 STACK.dfnear[STACK.lstack] = +zerzer;
198 /* Particle age (s)*/
199 STACK.agestk[STACK.lstack] = +zerzer;
200 STACK.cmpath[STACK.lstack] = +zerzer;
201 STACK.aknshr[STACK.lstack] = -twotwo;
203 /* Group number for "low" energy neutrons, set to 0 anyway*/
204 STACK.igroup[STACK.lstack] = 0;
207 STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
208 /* Particle momentum*/
209 STACK.pmom [STACK.lstack] = particle->P();
212 STACK.tx [STACK.lstack] = cosx;
213 STACK.ty [STACK.lstack] = cosy;
214 STACK.tz [STACK.lstack] = cosz;
216 /* Polarization cosines:*/
217 if (polarisation.Mag()) {
218 Double_t cospolx = polarisation.Px() / polarisation.Mag();
219 Double_t cospoly = polarisation.Py() / polarisation.Mag();
220 Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly);
221 STACK.txpol [STACK.lstack] = cospolx;
222 STACK.typol [STACK.lstack] = cospoly;
223 STACK.tzpol [STACK.lstack] = cospolz;
226 STACK.txpol [STACK.lstack] = -twotwo;
227 STACK.typol [STACK.lstack] = +zerzer;
228 STACK.tzpol [STACK.lstack] = +zerzer;
231 /* Particle coordinates*/
232 // Vertext coordinates;
233 STACK.xa [STACK.lstack] = particle->Vx();
234 STACK.ya [STACK.lstack] = particle->Vy();
235 STACK.za [STACK.lstack] = particle->Vz();
237 /* Calculate the total kinetic energy of the primaries: don't change*/
238 Int_t st_ilo = STACK.ilo[STACK.lstack];
241 ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
242 * STACK.wt[STACK.lstack]);
244 EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
246 /* Here we ask for the region number of the hitting point.
247 * NREG (LSTACK) = ...
248 * The following line makes the starting region search much more
249 * robust if particles are starting very close to a boundary:
251 geocrs( STACK.tx[STACK.lstack],
252 STACK.ty[STACK.lstack],
253 STACK.tz[STACK.lstack] );
257 georeg ( STACK.xa[STACK.lstack],
258 STACK.ya[STACK.lstack],
259 STACK.za[STACK.lstack],
260 STACK.nreg[STACK.lstack],
261 idisc);//<-- dummy return variable not used
262 /* Do not change these cards:*/
264 Int_t igeohsm2 = -11;
265 geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
266 STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
270 // Next particle is optical photon
273 OPPHST.donear [OPPHST.lstopp - 1] = 0.;
275 OPPHST.xoptph [OPPHST.lstopp - 1] = particle->Vx();
276 OPPHST.yoptph [OPPHST.lstopp - 1] = particle->Vy();
277 OPPHST.zoptph [OPPHST.lstopp - 1] = particle->Vz();
279 OPPHST.txopph [OPPHST.lstopp - 1] = cosx;
280 OPPHST.tyopph [OPPHST.lstopp - 1] = cosy;
281 OPPHST.tzopph [OPPHST.lstopp - 1] = cosz;
284 if (polarisation.Mag()) {
285 Double_t cospolx = polarisation.Px() / polarisation.Mag();
286 Double_t cospoly = polarisation.Py() / polarisation.Mag();
287 Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly);
288 OPPHST.txpopp [OPPHST.lstopp - 1] = cospolx;
289 OPPHST.typopp [OPPHST.lstopp - 1] = cospoly;
290 OPPHST.tzpopp [OPPHST.lstopp - 1] = cospolz;
293 OPPHST.txpopp [OPPHST.lstopp - 1] = -twotwo;
294 OPPHST.typopp [OPPHST.lstopp - 1] = +zerzer;
295 OPPHST.tzpopp [OPPHST.lstopp - 1] = +zerzer;
298 geocrs( OPPHST.txopph[OPPHST.lstopp - 1],
299 OPPHST.tyopph[OPPHST.lstopp - 1],
300 OPPHST.tzopph[OPPHST.lstopp - 1] );
304 georeg ( OPPHST.xoptph[OPPHST.lstopp - 1],
305 OPPHST.yoptph[OPPHST.lstopp - 1],
306 OPPHST.zoptph[OPPHST.lstopp - 1],
307 OPPHST.nregop[OPPHST.lstopp - 1],
308 idisc);//<-- dummy return variable not used
310 OPPHST.wtopph [OPPHST.lstopp - 1] = particle->GetWeight();
311 OPPHST.poptph [OPPHST.lstopp - 1] = particle->P();
312 OPPHST.agopph [OPPHST.lstopp - 1] = particle->T();
313 OPPHST.cmpopp [OPPHST.lstopp - 1] = +zerzer;
314 OPPHST.loopph [OPPHST.lstopp - 1] = 0;
315 OPPHST.louopp [OPPHST.lstopp - 1] = itrack;
319 // Pre-track actions at for primary tracks
321 if (particleIsPrimary) {
322 TVirtualMCApplication::Instance()->BeginPrimary();
323 TVirtualMCApplication::Instance()->PreTrack();
327 if (debug) cout << "<== source(" << nomore << ")" << endl;