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 "Fcaslim.h" //(CASLIM) fluka common
19 #include "TFlukaGeo.h"
22 #include "TVirtualMCStack.h"
23 //#include "TVirtualMCApplication.h"
27 #include "TFlukaGeo.h"
30 #include "TParticle.h"
34 #include <Riostream.h>
37 # define source source_
38 # define geocrs geocrs_
39 # define georeg georeg_
40 # define geohsm geohsm_
41 # define soevsv soevsv_
43 # define source SOURCE
44 # define geocrs GEOCRS
45 # define georeg GEOREG
46 # define geohsm GEOHSM
47 # define soevsv SOEVSV
52 // Prototypes for FLUKA functions
54 void type_of_call geocrs(Double_t &, Double_t &, Double_t &);
55 void type_of_call georeg(Double_t &, Double_t &, Double_t &,
57 void type_of_call geohsm(Int_t &, Int_t &, Int_t &, Int_t &);
58 void type_of_call soevsv();
60 *----------------------------------------------------------------------*
62 * Created on 07 january 1990 by Alfredo Ferrari & Paola Sala *
65 * Last change on 21-jun-98 by Alfredo Ferrari *
67 * C++ version on 27-sep-02 by Isidro Gonzalez *
69 * This is just an example of a possible user written source routine. *
70 * note that the beam card still has some meaning - in the scoring the *
71 * maximum momentum used in deciding the binning is taken from the *
72 * beam momentum. Other beam card parameters are obsolete. *
74 *----------------------------------------------------------------------*/
76 void source(Int_t& nomore) {
77 // Get the pointer to TFluka
78 TFluka* fluka = (TFluka*)gMC;
79 Int_t verbosityLevel = fluka->GetVerbosityLevel();
80 Bool_t debug = (verbosityLevel>=3)?kTRUE:kFALSE;
82 cout << "==> source(" << nomore << ")" << endl;
83 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
86 static Bool_t lfirst = true;
87 static Bool_t particleIsPrimary = true;
88 static Bool_t lastParticleWasPrimary = true;
90 /* +-------------------------------------------------------------------*
91 * First call initializations for FLUKA: */
96 TVirtualMCStack* cppstack = fluka->GetStack();
99 Int_t nprim = cppstack->GetNprimary();
100 // Get the next particle from the stack
101 particle = cppstack->PopNextTrack(itrack);
102 fluka->SetTrackIsNew(kTRUE);
104 // Is this a secondary not handled by Fluka, i.e. a particle added by user action ?
105 lastParticleWasPrimary = particleIsPrimary;
107 if (itrack >= nprim) {
108 particleIsPrimary = kFALSE;
110 particleIsPrimary = kTRUE;
113 // printf("--->Got Particle %d %d %d\n", itrack, particleIsPrimary, lastParticleWasPrimary);
116 EPISOR.tkesum = zerzer;
118 EPISOR.lussrc = true;
121 // Post-track actions for primary track
123 if (particleIsPrimary) {
124 TVirtualMCApplication::Instance()->PostTrack();
125 TVirtualMCApplication::Instance()->FinishPrimary();
129 //Exit if itrack is negative (-1). Set lsouit to false to mark last track for
134 EPISOR.lsouit = false;
136 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
137 cout << "\t* No more particles. Exiting..." << endl;
138 cout << "<== source(" << nomore << ")" << endl;
143 //Get some info about the particle and print it
146 Int_t pdg = particle->GetPdgCode();
148 TVector3 polarisation;
149 particle->GetPolarisation(polarisation);
151 cout << "\t* Particle " << itrack << " retrieved..." << endl;
152 cout << "\t\t+ Name = " << particle->GetName() << endl;
153 cout << "\t\t+ PDG/Fluka code = " << pdg
154 << " / " << fluka->IdFromPDG(pdg) << endl;
155 cout << "\t\t+ P = ("
156 << particle->Px() << " , "
157 << particle->Py() << " , "
158 << particle->Pz() << " ) --> "
159 << particle->P() << " GeV" << endl;
161 /* Lstack is the stack counter: of course any time source is called it
167 /* Wt is the weight of the particle*/
168 STACK.wt[STACK.lstack] = oneone;
169 STARS.weipri += STACK.wt[STACK.lstack];
171 /* Particle type (1=proton.....). Ijbeam is the type set by the BEAM
175 //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
176 if (pdg == 50000050 || pdg == 50000051) {
177 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(22);
179 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(pdg);
185 /* From this point .....
186 * Particle generation (1 for primaries)
188 STACK.lo[STACK.lstack] = 1;
190 /* User dependent flag:*/
191 STACK.louse[STACK.lstack] = 0;
193 /* User dependent spare variables:*/
195 for (ispr = 0; ispr < mkbmx1; ispr++)
196 STACK.sparek[STACK.lstack][ispr] = zerzer;
198 /* User dependent spare flags:*/
199 for (ispr = 0; ispr < mkbmx2; ispr++)
200 STACK.ispark[STACK.lstack][ispr] = 0;
202 /* Save the track number of the stack particle:*/
203 STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
205 STACK.numpar[STACK.lstack] = STACK.nparma;
206 STACK.nevent[STACK.lstack] = 0;
207 STACK.dfnear[STACK.lstack] = +zerzer;
209 /* Particle age (s)*/
210 STACK.agestk[STACK.lstack] = +zerzer;
211 STACK.aknshr[STACK.lstack] = -twotwo;
213 /* Group number for "low" energy neutrons, set to 0 anyway*/
214 STACK.igroup[STACK.lstack] = 0;
217 if (pdg == 50000050 || pdg == 50000051) {
219 // Special case for optical photons
220 STACK.tke[STACK.lstack] = particle->Energy();
222 STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
226 /* Particle momentum*/
227 STACK.pmom [STACK.lstack] = particle->P();
229 /* Cosines (tx,ty,tz)*/
230 Double_t cosx = particle->Px()/particle->P();
231 Double_t cosy = particle->Py()/particle->P();
232 Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
233 if (particle->Pz() < 0.) cosz = -cosz;
234 STACK.tx [STACK.lstack] = cosx;
235 STACK.ty [STACK.lstack] = cosy;
236 STACK.tz [STACK.lstack] = cosz;
238 /* Polarization cosines:*/
239 if (polarisation.Mag()) {
240 Double_t cospolx = polarisation.Px()/polarisation.Mag();
241 Double_t cospoly = polarisation.Py()/polarisation.Mag();
242 Double_t cospolz = sqrt(oneone - cospolx*cospolx - cospoly*cospoly);
243 STACK.tx [STACK.lstack] = cospolx;
244 STACK.ty [STACK.lstack] = cospoly;
245 STACK.tz [STACK.lstack] = cospolz;
248 STACK.txpol [STACK.lstack] = -twotwo;
249 STACK.typol [STACK.lstack] = +zerzer;
250 STACK.tzpol [STACK.lstack] = +zerzer;
253 /* Particle coordinates*/
254 // Vertext coordinates;
255 STACK.xa [STACK.lstack] = particle->Vx();
256 STACK.ya [STACK.lstack] = particle->Vy();
257 STACK.za [STACK.lstack] = particle->Vz();
259 /* Calculate the total kinetic energy of the primaries: don't change*/
260 Int_t st_ilo = STACK.ilo[STACK.lstack];
263 ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
264 * STACK.wt[STACK.lstack]);
266 EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
268 /* Here we ask for the region number of the hitting point.
269 * NREG (LSTACK) = ...
270 * The following line makes the starting region search much more
271 * robust if particles are starting very close to a boundary:
273 geocrs( STACK.tx[STACK.lstack],
274 STACK.ty[STACK.lstack],
275 STACK.tz[STACK.lstack] );
279 georeg ( STACK.xa[STACK.lstack],
280 STACK.ya[STACK.lstack],
281 STACK.za[STACK.lstack],
282 STACK.nreg[STACK.lstack],
283 idisc);//<-- dummy return variable not used
284 /* Do not change these cards:*/
286 Int_t igeohsm2 = -11;
287 geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
288 STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
291 // Pre-track actions at for primary tracks
293 if (particleIsPrimary) {
294 TVirtualMCApplication::Instance()->BeginPrimary();
295 TVirtualMCApplication::Instance()->PreTrack();
299 if (debug) cout << "<== source(" << nomore << ")" << endl;