7 #include "Fdblprc.h" //(DBLPRC) fluka common
8 #include "Fdimpar.h" //(DIMPAR) fluka parameters
9 #include "Fepisor.h" //(EPISOR) fluka common
10 #include "Fstack.h" //(STACK) fluka common
11 #include "Fstars.h" //(STARS) fluka common
12 #include "Fbeam.h" //(BEAM) fluka common
13 #include "Fpaprop.h" //(PAPROP) fluka common
14 #include "Fltclcm.h" //(LTCLCM) fluka common
15 //#include "Fcaslim.h" //(CASLIM) fluka common
21 #include "TFlukaGeo.h"
24 #include "TVirtualMCStack.h"
25 //#include "TVirtualMCApplication.h"
29 #include "TFlukaGeo.h"
32 #include "TParticle.h"
36 #include <Riostream.h>
39 # define source source_
40 # define geocrs geocrs_
41 # define georeg georeg_
42 # define geohsm geohsm_
43 # define soevsv soevsv_
45 # define source SOURCE
46 # define geocrs GEOCRS
47 # define georeg GEOREG
48 # define geohsm GEOHSM
49 # define soevsv SOEVSV
54 // Prototypes for FLUKA functions
56 void type_of_call geocrs(Double_t &, Double_t &, Double_t &);
57 void type_of_call georeg(Double_t &, Double_t &, Double_t &,
59 void type_of_call geohsm(Int_t &, Int_t &, Int_t &, Int_t &);
60 void type_of_call soevsv();
62 *----------------------------------------------------------------------*
64 * Created on 07 january 1990 by Alfredo Ferrari & Paola Sala *
67 * Last change on 21-jun-98 by Alfredo Ferrari *
69 * C++ version on 27-sep-02 by Isidro Gonzalez *
71 * This is just an example of a possible user written source routine. *
72 * note that the beam card still has some meaning - in the scoring the *
73 * maximum momentum used in deciding the binning is taken from the *
74 * beam momentum. Other beam card parameters are obsolete. *
76 *----------------------------------------------------------------------*/
78 void source(Int_t& nomore) {
80 cout << "==> source(" << nomore << ")" << endl;
83 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
85 static Bool_t lfirst = true;
86 static Bool_t particleIsPrimary = true;
87 static Bool_t lastParticleWasPrimary = true;
89 /* +-------------------------------------------------------------------*
90 * First call initializations for FLUKA: */
94 // Get the pointer to the VMC
95 TVirtualMC* fluka = TFluka::GetMC();
97 TVirtualMCStack* cppstack = fluka->GetStack();
100 Int_t nprim = cppstack->GetNprimary();
101 // Get the next particle from the stack
102 particle = cppstack->PopNextTrack(itrack);
103 ((TFluka*)fluka)->SetTrackIsNew(kTRUE);
105 // Is this a secondary not handled by Fluka, i.e. a particle added by user action ?
106 lastParticleWasPrimary = particleIsPrimary;
108 if (itrack >= nprim) {
109 particleIsPrimary = kFALSE;
111 particleIsPrimary = kTRUE;
114 // printf("--->Got Particle %d %d %d\n", itrack, particleIsPrimary, lastParticleWasPrimary);
117 EPISOR.tkesum = zerzer;
119 EPISOR.lussrc = true;
122 // Post-track actions for primary track
124 if (particleIsPrimary) {
125 TVirtualMCApplication::Instance()->PostTrack();
126 TVirtualMCApplication::Instance()->FinishPrimary();
130 //Exit if itrack is negative (-1). Set lsouit to false to mark last track for
135 EPISOR.lsouit = false;
136 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
137 cout << "\t* No more particles. Exiting..." << endl;
139 cout << "<== source(" << nomore << ")" << endl;
144 //Get some info about the particle and print it
147 Int_t pdg = particle->GetPdgCode();
149 TVector3 polarisation;
150 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;
160 /* Lstack is the stack counter: of course any time source is called it
166 /* Wt is the weight of the particle*/
167 STACK.wt[STACK.lstack] = oneone;
168 STARS.weipri += STACK.wt[STACK.lstack];
170 /* Particle type (1=proton.....). Ijbeam is the type set by the BEAM
174 //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
175 if (pdg == 50000050 || pdg == 50000051) {
176 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(22);
178 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(pdg);
184 /* From this point .....
185 * Particle generation (1 for primaries)
187 STACK.lo[STACK.lstack] = 1;
189 /* User dependent flag:*/
190 STACK.louse[STACK.lstack] = 0;
192 /* User dependent spare variables:*/
194 for (ispr = 0; ispr < mkbmx1; ispr++)
195 STACK.sparek[STACK.lstack][ispr] = zerzer;
197 /* User dependent spare flags:*/
198 for (ispr = 0; ispr < mkbmx2; ispr++)
199 STACK.ispark[STACK.lstack][ispr] = 0;
201 /* Save the track number of the stack particle:*/
202 STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
204 STACK.numpar[STACK.lstack] = STACK.nparma;
205 STACK.nevent[STACK.lstack] = 0;
206 STACK.dfnear[STACK.lstack] = +zerzer;
208 /* Particle age (s)*/
209 STACK.agestk[STACK.lstack] = +zerzer;
210 STACK.aknshr[STACK.lstack] = -twotwo;
212 /* Group number for "low" energy neutrons, set to 0 anyway*/
213 STACK.igroup[STACK.lstack] = 0;
216 if (pdg == 50000050 || pdg == 50000051) {
218 // Special case for optical photons
219 STACK.tke[STACK.lstack] = particle->Energy();
221 STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
225 /* Particle momentum*/
226 STACK.pmom [STACK.lstack] = particle->P();
228 /* Cosines (tx,ty,tz)*/
229 Double_t cosx = particle->Px()/particle->P();
230 Double_t cosy = particle->Py()/particle->P();
231 Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
232 if (particle->Pz() < 0.) cosz = -cosz;
233 STACK.tx [STACK.lstack] = cosx;
234 STACK.ty [STACK.lstack] = cosy;
235 STACK.tz [STACK.lstack] = cosz;
237 /* Polarization cosines:*/
238 if (polarisation.Mag()) {
239 Double_t cospolx = polarisation.Px()/polarisation.Mag();
240 Double_t cospoly = polarisation.Py()/polarisation.Mag();
241 Double_t cospolz = sqrt(oneone - cospolx*cospolx - cospoly*cospoly);
242 STACK.tx [STACK.lstack] = cospolx;
243 STACK.ty [STACK.lstack] = cospoly;
244 STACK.tz [STACK.lstack] = cospolz;
247 STACK.txpol [STACK.lstack] = -twotwo;
248 STACK.typol [STACK.lstack] = +zerzer;
249 STACK.tzpol [STACK.lstack] = +zerzer;
252 /* Particle coordinates*/
253 // Vertext coordinates;
254 STACK.xa [STACK.lstack] = particle->Vx();
255 STACK.ya [STACK.lstack] = particle->Vy();
256 STACK.za [STACK.lstack] = particle->Vz();
258 /* Calculate the total kinetic energy of the primaries: don't change*/
259 Int_t st_ilo = STACK.ilo[STACK.lstack];
262 ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
263 * STACK.wt[STACK.lstack]);
265 EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
267 /* Here we ask for the region number of the hitting point.
268 * NREG (LSTACK) = ...
269 * The following line makes the starting region search much more
270 * robust if particles are starting very close to a boundary:
272 geocrs( STACK.tx[STACK.lstack],
273 STACK.ty[STACK.lstack],
274 STACK.tz[STACK.lstack] );
278 georeg ( STACK.xa[STACK.lstack],
279 STACK.ya[STACK.lstack],
280 STACK.za[STACK.lstack],
281 STACK.nreg[STACK.lstack],
282 idisc);//<-- dummy return variable not used
283 /* Do not change these cards:*/
285 Int_t igeohsm2 = -11;
286 geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
287 STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
290 // Pre-track actions at for primary tracks
292 if (particleIsPrimary) {
293 TVirtualMCApplication::Instance()->BeginPrimary();
294 TVirtualMCApplication::Instance()->PreTrack();
300 cout << "<== source(" << nomore << ")" << endl;