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;
71 Int_t verbosityLevel = fluka->GetVerbosityLevel();
72 Bool_t debug = (verbosityLevel>=3)?kTRUE:kFALSE;
74 cout << "==> source(" << nomore << ")" << endl;
75 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
78 static Bool_t lfirst = true;
79 static Bool_t particleIsPrimary = true;
80 static Bool_t lastParticleWasPrimary = true;
82 /* +-------------------------------------------------------------------*
83 * First call initializations for FLUKA: */
88 TVirtualMCStack* cppstack = fluka->GetStack();
91 Int_t nprim = cppstack->GetNprimary();
92 // Get the next particle from the stack
93 particle = cppstack->PopNextTrack(itrack);
94 fluka->SetTrackIsNew(kTRUE);
96 // Is this a secondary not handled by Fluka, i.e. a particle added by user action ?
97 lastParticleWasPrimary = particleIsPrimary;
99 if (itrack >= nprim) {
100 particleIsPrimary = kFALSE;
102 particleIsPrimary = kTRUE;
105 // printf("--->Got Particle %d %d %d\n", itrack, particleIsPrimary, lastParticleWasPrimary);
108 EPISOR.tkesum = zerzer;
110 EPISOR.lussrc = true;
113 // Post-track actions for primary track
115 if (particleIsPrimary) {
116 TVirtualMCApplication::Instance()->PostTrack();
117 TVirtualMCApplication::Instance()->FinishPrimary();
118 if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack);
122 //Exit if itrack is negative (-1). Set lsouit to false to mark last track for
127 EPISOR.lsouit = false;
129 cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
130 cout << "\t* No more particles. Exiting..." << endl;
131 cout << "<== source(" << nomore << ")" << endl;
136 //Get some info about the particle and print it
139 Int_t pdg = particle->GetPdgCode();
141 TVector3 polarisation;
142 particle->GetPolarisation(polarisation);
144 cout << "\t* Particle " << itrack << " retrieved..." << endl;
145 cout << "\t\t+ Name = " << particle->GetName() << endl;
146 cout << "\t\t+ PDG/Fluka code = " << pdg
147 << " / " << fluka->IdFromPDG(pdg) << endl;
148 cout << "\t\t+ P = ("
149 << particle->Px() << " , "
150 << particle->Py() << " , "
151 << particle->Pz() << " ) --> "
152 << particle->P() << " GeV" << endl;
154 /* Lstack is the stack counter: of course any time source is called it
157 /* Cosines (tx,ty,tz)*/
158 Double_t cosx = particle->Px()/particle->P();
159 Double_t cosy = particle->Py()/particle->P();
160 Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
161 if (particle->Pz() < 0.) cosz = -cosz;
163 //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
164 if (pdg != 50000050 && pdg != 50000051) {
167 STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(pdg);
169 /* Wt is the weight of the particle*/
170 STACK.wt[STACK.lstack] = oneone;
171 STARS.weipri += STACK.wt[STACK.lstack];
173 STACK.lo[STACK.lstack] = 1;
175 /* User dependent flag:*/
176 STACK.louse[STACK.lstack] = 0;
178 /* User dependent spare variables:*/
180 for (ispr = 0; ispr < mkbmx1; ispr++)
181 STACK.sparek[STACK.lstack][ispr] = zerzer;
183 /* User dependent spare flags:*/
184 for (ispr = 0; ispr < mkbmx2; ispr++)
185 STACK.ispark[STACK.lstack][ispr] = 0;
187 /* Save the track number of the stack particle:*/
188 STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
190 STACK.numpar[STACK.lstack] = STACK.nparma;
191 STACK.nevent[STACK.lstack] = 0;
192 STACK.dfnear[STACK.lstack] = +zerzer;
194 /* Particle age (s)*/
195 STACK.agestk[STACK.lstack] = +zerzer;
196 STACK.cmpath[STACK.lstack] = +zerzer;
197 STACK.aknshr[STACK.lstack] = -twotwo;
199 /* Group number for "low" energy neutrons, set to 0 anyway*/
200 STACK.igroup[STACK.lstack] = 0;
203 STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
204 /* Particle momentum*/
205 STACK.pmom [STACK.lstack] = particle->P();
208 STACK.tx [STACK.lstack] = cosx;
209 STACK.ty [STACK.lstack] = cosy;
210 STACK.tz [STACK.lstack] = cosz;
212 /* Polarization cosines:*/
213 if (polarisation.Mag()) {
214 Double_t cospolx = polarisation.Px() / polarisation.Mag();
215 Double_t cospoly = polarisation.Py() / polarisation.Mag();
216 Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly);
217 STACK.txpol [STACK.lstack] = cospolx;
218 STACK.typol [STACK.lstack] = cospoly;
219 STACK.tzpol [STACK.lstack] = cospolz;
222 STACK.txpol [STACK.lstack] = -twotwo;
223 STACK.typol [STACK.lstack] = +zerzer;
224 STACK.tzpol [STACK.lstack] = +zerzer;
227 /* Particle coordinates*/
228 // Vertext coordinates;
229 STACK.xa [STACK.lstack] = particle->Vx();
230 STACK.ya [STACK.lstack] = particle->Vy();
231 STACK.za [STACK.lstack] = particle->Vz();
233 /* Calculate the total kinetic energy of the primaries: don't change*/
234 Int_t st_ilo = STACK.ilo[STACK.lstack];
237 ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
238 * STACK.wt[STACK.lstack]);
240 EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
242 /* Here we ask for the region number of the hitting point.
243 * NREG (LSTACK) = ...
244 * The following line makes the starting region search much more
245 * robust if particles are starting very close to a boundary:
247 geocrs( STACK.tx[STACK.lstack],
248 STACK.ty[STACK.lstack],
249 STACK.tz[STACK.lstack] );
253 georeg ( STACK.xa[STACK.lstack],
254 STACK.ya[STACK.lstack],
255 STACK.za[STACK.lstack],
256 STACK.nreg[STACK.lstack],
257 idisc);//<-- dummy return variable not used
258 /* Do not change these cards:*/
260 Int_t igeohsm2 = -11;
261 geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
262 STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
265 // Next particle is optical photon
267 OPPHST.donear [OPPHST.lstopp - 1] = 0.;
269 OPPHST.xoptph [OPPHST.lstopp - 1] = particle->Vx();
270 OPPHST.yoptph [OPPHST.lstopp - 1] = particle->Vy();
271 OPPHST.zoptph [OPPHST.lstopp - 1] = particle->Vz();
273 OPPHST.txopph [OPPHST.lstopp - 1] = cosx;
274 OPPHST.tyopph [OPPHST.lstopp - 1] = cosy;
275 OPPHST.tzopph [OPPHST.lstopp - 1] = cosz;
278 if (polarisation.Mag()) {
279 Double_t cospolx = polarisation.Px() / polarisation.Mag();
280 Double_t cospoly = polarisation.Py() / polarisation.Mag();
281 Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly);
282 OPPHST.txpopp [OPPHST.lstopp - 1] = cospolx;
283 OPPHST.typopp [OPPHST.lstopp - 1] = cospoly;
284 OPPHST.tzpopp [OPPHST.lstopp - 1] = cospolz;
287 OPPHST.txpopp [OPPHST.lstopp - 1] = -twotwo;
288 OPPHST.typopp [OPPHST.lstopp - 1] = +zerzer;
289 OPPHST.tzpopp [OPPHST.lstopp - 1] = +zerzer;
292 geocrs( OPPHST.txopph[OPPHST.lstopp - 1],
293 OPPHST.tyopph[OPPHST.lstopp - 1],
294 OPPHST.tzopph[OPPHST.lstopp - 1] );
298 georeg ( OPPHST.xoptph[OPPHST.lstopp - 1],
299 OPPHST.yoptph[OPPHST.lstopp - 1],
300 OPPHST.zoptph[OPPHST.lstopp - 1],
301 OPPHST.nregop[OPPHST.lstopp - 1],
302 idisc);//<-- dummy return variable not used
304 OPPHST.wtopph [OPPHST.lstopp - 1] = particle->GetWeight();
305 OPPHST.poptph [OPPHST.lstopp - 1] = particle->P();
306 OPPHST.agopph [OPPHST.lstopp - 1] = particle->T();
307 OPPHST.cmpopp [OPPHST.lstopp - 1] = +zerzer;
308 OPPHST.loopph [OPPHST.lstopp - 1] = 0;
309 // Int_t mother = particle->GetFirstMother();
310 OPPHST.louopp [OPPHST.lstopp - 1] = itrack;
313 TParticle* mparticle = cppstack->Particle(mother);
314 OPPHST.apropp [OPPHST.lstopp - 1] = mparticle->T();
315 Int_t mpdg = mparticle->GetPdgCode();
316 if (mpdg == 50000050 || mpdg 50000051) {
317 OPPHST.ipropp [OPPHST.lstopp - 1] = -1;
318 OPPHST.tpropp [OPPHST.lstopp - 1] = mparticle->Energy();
320 OPPHST.ipropp [OPPHST.lstopp - 1] = mpdg;
321 OPPHST.tpropp [OPPHST.lstopp - 1] = mparticle->Energy() - mparticle->GetMass();
329 // Pre-track actions at for primary tracks
331 if (particleIsPrimary) {
332 TVirtualMCApplication::Instance()->BeginPrimary();
333 TVirtualMCApplication::Instance()->PreTrack();
337 if (debug) cout << "<== source(" << nomore << ")" << endl;