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();
126 if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack);
130 //Exit if itrack is negative (-1). Set lsouit to false to mark last track for
135 EPISOR.lsouit = false;
137 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
138 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);
152 cout << "\t* Particle " << itrack << " retrieved..." << endl;
153 cout << "\t\t+ Name = " << particle->GetName() << endl;
154 cout << "\t\t+ PDG/Fluka code = " << pdg
155 << " / " << fluka->IdFromPDG(pdg) << endl;
156 cout << "\t\t+ P = ("
157 << particle->Px() << " , "
158 << particle->Py() << " , "
159 << particle->Pz() << " ) --> "
160 << particle->P() << " GeV" << endl;
162 /* Lstack is the stack counter: of course any time source is called it
168 /* Wt is the weight of the particle*/
169 STACK.wt[STACK.lstack] = oneone;
170 STARS.weipri += STACK.wt[STACK.lstack];
172 /* Particle type (1=proton.....). Ijbeam is the type set by the BEAM
176 //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
177 if (pdg == 50000050 || pdg == 50000051) {
178 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(22);
180 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(pdg);
186 /* From this point .....
187 * Particle generation (1 for primaries)
189 STACK.lo[STACK.lstack] = 1;
191 /* User dependent flag:*/
192 STACK.louse[STACK.lstack] = 0;
194 /* User dependent spare variables:*/
196 for (ispr = 0; ispr < mkbmx1; ispr++)
197 STACK.sparek[STACK.lstack][ispr] = zerzer;
199 /* User dependent spare flags:*/
200 for (ispr = 0; ispr < mkbmx2; ispr++)
201 STACK.ispark[STACK.lstack][ispr] = 0;
203 /* Save the track number of the stack particle:*/
204 STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
206 STACK.numpar[STACK.lstack] = STACK.nparma;
207 STACK.nevent[STACK.lstack] = 0;
208 STACK.dfnear[STACK.lstack] = +zerzer;
210 /* Particle age (s)*/
211 STACK.agestk[STACK.lstack] = +zerzer;
212 STACK.aknshr[STACK.lstack] = -twotwo;
214 /* Group number for "low" energy neutrons, set to 0 anyway*/
215 STACK.igroup[STACK.lstack] = 0;
218 if (pdg == 50000050 || pdg == 50000051) {
220 // Special case for optical photons
221 STACK.tke[STACK.lstack] = particle->Energy();
223 STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
227 /* Particle momentum*/
228 STACK.pmom [STACK.lstack] = particle->P();
230 /* Cosines (tx,ty,tz)*/
231 Double_t cosx = particle->Px()/particle->P();
232 Double_t cosy = particle->Py()/particle->P();
233 Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
234 if (particle->Pz() < 0.) cosz = -cosz;
235 STACK.tx [STACK.lstack] = cosx;
236 STACK.ty [STACK.lstack] = cosy;
237 STACK.tz [STACK.lstack] = cosz;
239 /* Polarization cosines:*/
240 if (polarisation.Mag()) {
241 Double_t cospolx = polarisation.Px()/polarisation.Mag();
242 Double_t cospoly = polarisation.Py()/polarisation.Mag();
243 Double_t cospolz = sqrt(oneone - cospolx*cospolx - cospoly*cospoly);
244 STACK.tx [STACK.lstack] = cospolx;
245 STACK.ty [STACK.lstack] = cospoly;
246 STACK.tz [STACK.lstack] = cospolz;
249 STACK.txpol [STACK.lstack] = -twotwo;
250 STACK.typol [STACK.lstack] = +zerzer;
251 STACK.tzpol [STACK.lstack] = +zerzer;
254 /* Particle coordinates*/
255 // Vertext coordinates;
256 STACK.xa [STACK.lstack] = particle->Vx();
257 STACK.ya [STACK.lstack] = particle->Vy();
258 STACK.za [STACK.lstack] = particle->Vz();
260 /* Calculate the total kinetic energy of the primaries: don't change*/
261 Int_t st_ilo = STACK.ilo[STACK.lstack];
264 ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
265 * STACK.wt[STACK.lstack]);
267 EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
269 /* Here we ask for the region number of the hitting point.
270 * NREG (LSTACK) = ...
271 * The following line makes the starting region search much more
272 * robust if particles are starting very close to a boundary:
274 geocrs( STACK.tx[STACK.lstack],
275 STACK.ty[STACK.lstack],
276 STACK.tz[STACK.lstack] );
280 georeg ( STACK.xa[STACK.lstack],
281 STACK.ya[STACK.lstack],
282 STACK.za[STACK.lstack],
283 STACK.nreg[STACK.lstack],
284 idisc);//<-- dummy return variable not used
285 /* Do not change these cards:*/
287 Int_t igeohsm2 = -11;
288 geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
289 STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
292 // Pre-track actions at for primary tracks
294 if (particleIsPrimary) {
295 TVirtualMCApplication::Instance()->BeginPrimary();
296 TVirtualMCApplication::Instance()->PreTrack();
300 if (debug) cout << "<== source(" << nomore << ")" << endl;