5 #include "Fdblprc.h" //(DBLPRC) fluka common
6 #include "Fdimpar.h" //(DIMPAR) fluka parameters
7 #include "Fsourcm.h" //(EPISOR) fluka common
8 #include "Fflkstk.h" //(FLKSTK) fluka common
9 #include "Fsumcou.h" //(SUMCOU) fluka common
10 #include "Fpaprop.h" //(PAPROP) fluka common
11 #include "Fltclcm.h" //(LTCLCM) fluka common
12 #include "Fopphst.h" //(OPPHST) fluka common
17 #include "TVirtualMCStack.h"
18 //#include "TVirtualMCApplication.h"
20 #include "TParticle.h"
24 #include <Riostream.h>
27 # define source source_
28 # define geocrs geocrs_
29 # define georeg georeg_
30 # define geohsm geohsm_
31 # define soevsv soevsv_
33 # define source SOURCE
34 # define geocrs GEOCRS
35 # define georeg GEOREG
36 # define geohsm GEOHSM
37 # define soevsv SOEVSV
42 // Prototypes for FLUKA functions
44 void type_of_call geocrs(Double_t &, Double_t &, Double_t &);
45 void type_of_call georeg(Double_t &, Double_t &, Double_t &,
47 void type_of_call geohsm(Int_t &, Int_t &, Int_t &, Int_t &);
48 void type_of_call soevsv();
50 *----------------------------------------------------------------------*
52 * Created on 07 january 1990 by Alfredo Ferrari & Paola Sala *
55 * Last change on 21-jun-98 by Alfredo Ferrari *
57 * C++ version on 27-sep-02 by Isidro Gonzalez *
59 * This is just an example of a possible user written source routine. *
60 * note that the beam card still has some meaning - in the scoring the *
61 * maximum momentum used in deciding the binning is taken from the *
62 * beam momentum. Other beam card parameters are obsolete. *
64 *----------------------------------------------------------------------*/
66 void source(Int_t& nomore) {
67 // Get the pointer to TFluka
68 TFluka* fluka = (TFluka*)gMC;
70 Int_t verbosityLevel = fluka->GetVerbosityLevel();
71 Bool_t debug = (verbosityLevel>=3)?kTRUE:kFALSE;
73 cout << "==> source(" << nomore << ")" << endl;
74 cout << "\t* SOURCM.lsouit = " << (SOURCM.lsouit?'T':'F') << endl;
77 static Bool_t lfirst = true;
78 static Bool_t particleIsPrimary = true;
79 static Bool_t lastParticleWasPrimary = true;
84 TVirtualMCStack* cppstack = fluka->GetStack();
88 Int_t nprim = cppstack->GetNprimary();
89 // Get the next particle from the stack
90 particle = cppstack->PopNextTrack(itrack);
91 fluka->SetTrackIsNew(kTRUE);
93 // Is this a secondary not handled by Fluka, i.e. a particle added by user action ?
94 lastParticleWasPrimary = particleIsPrimary;
96 if (itrack >= nprim) {
97 particleIsPrimary = kFALSE;
99 particleIsPrimary = kTRUE;
103 SOURCM.tkesum = zerzer;
105 SOURCM.lussrc = true;
108 // Post-track actions for primary track
110 if (particleIsPrimary) {
111 TVirtualMCApplication::Instance()->PostTrack();
112 TVirtualMCApplication::Instance()->FinishPrimary();
113 if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack);
117 // Exit if itrack is negative (-1). Set lsouit to false to mark last track for this event
121 SOURCM.lsouit = false;
123 cout << "\t* SOURCM.lsouit = " << (SOURCM.lsouit?'T':'F') << endl;
124 cout << "\t* No more particles. Exiting..." << endl;
125 cout << "<== source(" << nomore << ")" << endl;
131 // Handle user event abortion
132 if (fluka->EventIsStopped()) {
133 printf("Event has been stopped by user !");
134 fluka->SetStopEvent(kFALSE);
136 SOURCM.lsouit = false;
140 //Get some info about the particle and print it
143 Int_t pdg = particle->GetPdgCode();
144 TVector3 polarisation;
145 particle->GetPolarisation(polarisation);
147 cout << "\t* Particle " << itrack << " retrieved..." << endl;
148 cout << "\t\t+ Name = " << particle->GetName() << endl;
149 cout << "\t\t+ PDG/Fluka code = " << pdg
150 << " / " << fluka->IdFromPDG(pdg) << endl;
151 cout << "\t\t+ P = ("
152 << particle->Px() << " , "
153 << particle->Py() << " , "
154 << particle->Pz() << " ) --> "
155 << particle->P() << " GeV "
156 << particle->Energy() << " GeV "
157 << particle->GetMass() << " GeV " << endl;
159 /* Npflka 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 if (pdg != 50000050 && pdg != 50000051) {
170 Int_t ifl = fluka-> IdFromPDG(pdg);
171 FLKSTK.iloflk[FLKSTK.npflka] = ifl;
172 /* Wtflk is the weight of the particle*/
173 FLKSTK.wtflk[FLKSTK.npflka] = oneone;
174 SUMCOU.weipri += FLKSTK.wtflk[FLKSTK.npflka];
176 FLKSTK.loflk[FLKSTK.npflka] = 1;
178 /* User dependent flag:*/
179 FLKSTK.louse[FLKSTK.npflka] = 0;
181 /* User dependent spare variables:*/
183 for (ispr = 0; ispr < mkbmx1; ispr++)
184 FLKSTK.sparek[FLKSTK.npflka][ispr] = zerzer;
186 /* User dependent spare flags:*/
187 for (ispr = 0; ispr < mkbmx2; ispr++)
188 FLKSTK.ispark[FLKSTK.npflka][ispr] = 0;
190 /* Save the track number of the stack particle:*/
191 FLKSTK.ispark[FLKSTK.npflka][mkbmx2-1] = itrack;
193 FLKSTK.numpar[FLKSTK.npflka] = FLKSTK.nparma;
194 FLKSTK.nevent[FLKSTK.npflka] = 0;
195 FLKSTK.dfnear[FLKSTK.npflka] = +zerzer;
197 /* Particle age (s)*/
198 FLKSTK.agestk[FLKSTK.npflka] = +zerzer;
199 FLKSTK.cmpath[FLKSTK.npflka] = +zerzer;
200 FLKSTK.aknshr[FLKSTK.npflka] = -twotwo;
202 /* Group number for "low" energy neutrons, set to 0 anyway*/
203 FLKSTK.igroup[FLKSTK.npflka] = 0;
206 Double_t p = particle->P();
207 Double_t mass = PAPROP.am[ifl + 6];
208 FLKSTK.tkeflk[FLKSTK.npflka] = TMath::Sqrt( p * p + mass * mass) - mass;
209 /* Particle momentum*/
210 FLKSTK.pmoflk [FLKSTK.npflka] = p;
212 FLKSTK.txflk [FLKSTK.npflka] = cosx;
213 FLKSTK.tyflk [FLKSTK.npflka] = cosy;
214 FLKSTK.tzflk [FLKSTK.npflka] = 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 FLKSTK.txpol [FLKSTK.npflka] = cospolx;
222 FLKSTK.typol [FLKSTK.npflka] = cospoly;
223 FLKSTK.tzpol [FLKSTK.npflka] = cospolz;
226 FLKSTK.txpol [FLKSTK.npflka] = -twotwo;
227 FLKSTK.typol [FLKSTK.npflka] = +zerzer;
228 FLKSTK.tzpol [FLKSTK.npflka] = +zerzer;
231 /* Particle coordinates*/
232 // Vertext coordinates;
233 FLKSTK.xflk [FLKSTK.npflka] = particle->Vx();
234 FLKSTK.yflk [FLKSTK.npflka] = particle->Vy();
235 FLKSTK.zflk [FLKSTK.npflka] = particle->Vz();
237 /* Calculate the total kinetic energy of the primaries: don't change*/
238 Int_t st_ilo = FLKSTK.iloflk[FLKSTK.npflka];
241 ((FLKSTK.tkeflk[FLKSTK.npflka] + PAPROP.amdisc[st_ilo+6])
242 * FLKSTK.wtflk[FLKSTK.npflka]);
244 SOURCM.tkesum += (FLKSTK.tkeflk[FLKSTK.npflka] * FLKSTK.wtflk[FLKSTK.npflka]);
246 /* Here we ask for the region number of the hitting point.
247 * NRGFLK (LFLKSTK) = ...
248 * The following line makes the starting region search much more
249 * robust if particles are starting very close to a boundary:
251 geocrs( FLKSTK.txflk[FLKSTK.npflka],
252 FLKSTK.tyflk[FLKSTK.npflka],
253 FLKSTK.tzflk[FLKSTK.npflka] );
257 georeg ( FLKSTK.xflk[FLKSTK.npflka],
258 FLKSTK.yflk[FLKSTK.npflka],
259 FLKSTK.zflk[FLKSTK.npflka],
260 FLKSTK.nrgflk[FLKSTK.npflka],
261 idisc);//<-- dummy return variable not used
262 /* Do not change these cards:*/
264 Int_t igeohsm2 = -11;
265 geohsm ( FLKSTK.nhspnt[FLKSTK.npflka], igeohsm1, igeohsm2, LTCLCM.mlattc );
266 FLKSTK.nlattc[FLKSTK.npflka] = 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;