]>
Commit | Line | Data |
---|---|---|
b9d0a01d | 1 | // Fortran |
2 | #include "TCallf77.h" | |
3 | ||
4 | // Fluka commons | |
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 | |
cfd35035 | 13 | #include "Fopphst.h" //(OPPHST) fluka common |
b9d0a01d | 14 | //#include "Fcaslim.h" //(CASLIM) fluka common |
15 | ||
16 | //Virutal MC | |
17 | #include "TFluka.h" | |
a7bb59a2 | 18 | |
b9d0a01d | 19 | #include "TVirtualMCStack.h" |
fbf08100 | 20 | //#include "TVirtualMCApplication.h" |
fbf08100 | 21 | |
b9d0a01d | 22 | #include "TParticle.h" |
23 | #include "TVector3.h" | |
24 | ||
25 | //Other | |
eae0fe66 | 26 | #include <Riostream.h> |
b9d0a01d | 27 | |
28 | #ifndef WIN32 | |
29 | # define source source_ | |
30 | # define geocrs geocrs_ | |
31 | # define georeg georeg_ | |
32 | # define geohsm geohsm_ | |
33 | # define soevsv soevsv_ | |
34 | #else | |
35 | # define source SOURCE | |
36 | # define geocrs GEOCRS | |
37 | # define georeg GEOREG | |
38 | # define geohsm GEOHSM | |
39 | # define soevsv SOEVSV | |
40 | #endif | |
41 | ||
b9d0a01d | 42 | extern "C" { |
43 | // | |
44 | // Prototypes for FLUKA functions | |
45 | // | |
46 | void type_of_call geocrs(Double_t &, Double_t &, Double_t &); | |
47 | void type_of_call georeg(Double_t &, Double_t &, Double_t &, | |
48 | Int_t &, Int_t &); | |
49 | void type_of_call geohsm(Int_t &, Int_t &, Int_t &, Int_t &); | |
50 | void type_of_call soevsv(); | |
51 | /* | |
52 | *----------------------------------------------------------------------* | |
53 | * * | |
54 | * Created on 07 january 1990 by Alfredo Ferrari & Paola Sala * | |
55 | * Infn - Milan * | |
56 | * * | |
57 | * Last change on 21-jun-98 by Alfredo Ferrari * | |
58 | * * | |
59 | * C++ version on 27-sep-02 by Isidro Gonzalez * | |
60 | * * | |
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. * | |
65 | * * | |
66 | *----------------------------------------------------------------------*/ | |
67 | ||
68 | void source(Int_t& nomore) { | |
b496f27c | 69 | // Get the pointer to TFluka |
2bc4c610 | 70 | TFluka* fluka = (TFluka*)gMC; |
b496f27c | 71 | |
2bc4c610 | 72 | Int_t verbosityLevel = fluka->GetVerbosityLevel(); |
73 | Bool_t debug = (verbosityLevel>=3)?kTRUE:kFALSE; | |
74 | if (debug) { | |
ce60a136 | 75 | cout << "==> source(" << nomore << ")" << endl; |
ce60a136 | 76 | cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl; |
2bc4c610 | 77 | } |
b9d0a01d | 78 | |
2bc4c610 | 79 | static Bool_t lfirst = true; |
80 | static Bool_t particleIsPrimary = true; | |
81 | static Bool_t lastParticleWasPrimary = true; | |
b9d0a01d | 82 | |
ce60a136 | 83 | nomore = 0; |
b496f27c | 84 | |
85 | // Get the stack | |
b9d0a01d | 86 | TVirtualMCStack* cppstack = fluka->GetStack(); |
b496f27c | 87 | |
ce60a136 | 88 | TParticle* particle; |
b9d0a01d | 89 | Int_t itrack = -1; |
ce60a136 | 90 | Int_t nprim = cppstack->GetNprimary(); |
91 | // Get the next particle from the stack | |
92 | particle = cppstack->PopNextTrack(itrack); | |
2bc4c610 | 93 | fluka->SetTrackIsNew(kTRUE); |
ce60a136 | 94 | |
95 | // Is this a secondary not handled by Fluka, i.e. a particle added by user action ? | |
96 | lastParticleWasPrimary = particleIsPrimary; | |
97 | ||
98 | if (itrack >= nprim) { | |
99 | particleIsPrimary = kFALSE; | |
100 | } else { | |
101 | particleIsPrimary = kTRUE; | |
102 | } | |
103 | ||
ce60a136 | 104 | if (lfirst) { |
105 | EPISOR.tkesum = zerzer; | |
106 | lfirst = false; | |
107 | EPISOR.lussrc = true; | |
108 | } else { | |
109 | // | |
110 | // Post-track actions for primary track | |
111 | // | |
112 | if (particleIsPrimary) { | |
113 | TVirtualMCApplication::Instance()->PostTrack(); | |
114 | TVirtualMCApplication::Instance()->FinishPrimary(); | |
b496f27c | 115 | if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack); |
ce60a136 | 116 | } |
117 | } | |
b9d0a01d | 118 | |
b496f27c | 119 | // Exit if itrack is negative (-1). Set lsouit to false to mark last track for this event |
ce60a136 | 120 | |
b9d0a01d | 121 | if (itrack<0) { |
122 | nomore = 1; | |
123 | EPISOR.lsouit = false; | |
2bc4c610 | 124 | if (debug) { |
125 | cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl; | |
126 | cout << "\t* No more particles. Exiting..." << endl; | |
127 | cout << "<== source(" << nomore << ")" << endl; | |
128 | } | |
b9d0a01d | 129 | return; |
130 | } | |
ce60a136 | 131 | |
b496f27c | 132 | // |
133 | // Handle user event abortion | |
134 | if (fluka->EventIsStopped()) { | |
135 | printf("Event has been stopped by user !"); | |
136 | fluka->SetStopEvent(kFALSE); | |
137 | nomore = 1; | |
138 | EPISOR.lsouit = false; | |
139 | return; | |
140 | } | |
141 | ||
b9d0a01d | 142 | //Get some info about the particle and print it |
ce60a136 | 143 | // |
144 | //pdg code | |
145 | Int_t pdg = particle->GetPdgCode(); | |
b9d0a01d | 146 | TVector3 polarisation; |
147 | particle->GetPolarisation(polarisation); | |
2bc4c610 | 148 | if (debug) { |
149 | cout << "\t* Particle " << itrack << " retrieved..." << endl; | |
150 | cout << "\t\t+ Name = " << particle->GetName() << endl; | |
151 | cout << "\t\t+ PDG/Fluka code = " << pdg | |
152 | << " / " << fluka->IdFromPDG(pdg) << endl; | |
153 | cout << "\t\t+ P = (" | |
154 | << particle->Px() << " , " | |
155 | << particle->Py() << " , " | |
156 | << particle->Pz() << " ) --> " | |
6b51799c | 157 | << particle->P() << " GeV " |
158 | << particle->Energy() << " GeV " | |
159 | << particle->GetMass() << " GeV " << endl; | |
2bc4c610 | 160 | } |
b9d0a01d | 161 | /* Lstack is the stack counter: of course any time source is called it |
162 | * must be =0 | |
163 | */ | |
cfd35035 | 164 | /* Cosines (tx,ty,tz)*/ |
165 | Double_t cosx = particle->Px()/particle->P(); | |
166 | Double_t cosy = particle->Py()/particle->P(); | |
167 | Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy); | |
168 | if (particle->Pz() < 0.) cosz = -cosz; | |
ce60a136 | 169 | |
b9d0a01d | 170 | //STACK.ilo[STACK.lstack] = BEAM.ijbeam; |
cfd35035 | 171 | if (pdg != 50000050 && pdg != 50000051) { |
172 | STACK.lstack++; | |
6b51799c | 173 | Int_t ifl = fluka-> IdFromPDG(pdg); |
174 | STACK.ilo[STACK.lstack] = ifl; | |
cfd35035 | 175 | /* Wt is the weight of the particle*/ |
176 | STACK.wt[STACK.lstack] = oneone; | |
177 | STARS.weipri += STACK.wt[STACK.lstack]; | |
178 | ||
179 | STACK.lo[STACK.lstack] = 1; | |
180 | ||
181 | /* User dependent flag:*/ | |
182 | STACK.louse[STACK.lstack] = 0; | |
ce60a136 | 183 | |
cfd35035 | 184 | /* User dependent spare variables:*/ |
185 | Int_t ispr = 0; | |
186 | for (ispr = 0; ispr < mkbmx1; ispr++) | |
187 | STACK.sparek[STACK.lstack][ispr] = zerzer; | |
ce60a136 | 188 | |
cfd35035 | 189 | /* User dependent spare flags:*/ |
190 | for (ispr = 0; ispr < mkbmx2; ispr++) | |
191 | STACK.ispark[STACK.lstack][ispr] = 0; | |
ce60a136 | 192 | |
cfd35035 | 193 | /* Save the track number of the stack particle:*/ |
194 | STACK.ispark[STACK.lstack][mkbmx2-1] = itrack; | |
195 | STACK.nparma++; | |
196 | STACK.numpar[STACK.lstack] = STACK.nparma; | |
197 | STACK.nevent[STACK.lstack] = 0; | |
198 | STACK.dfnear[STACK.lstack] = +zerzer; | |
e5e3c7b1 | 199 | |
cfd35035 | 200 | /* Particle age (s)*/ |
201 | STACK.agestk[STACK.lstack] = +zerzer; | |
e5e3c7b1 | 202 | STACK.cmpath[STACK.lstack] = +zerzer; |
cfd35035 | 203 | STACK.aknshr[STACK.lstack] = -twotwo; |
ce60a136 | 204 | |
cfd35035 | 205 | /* Group number for "low" energy neutrons, set to 0 anyway*/ |
206 | STACK.igroup[STACK.lstack] = 0; | |
207 | ||
208 | /* Kinetic energy */ | |
6b51799c | 209 | Double_t p = particle->P(); |
210 | Double_t mass = PAPROP.am[ifl + 6]; | |
211 | STACK.tke[STACK.lstack] = TMath::Sqrt( p * p + mass * mass) - mass; | |
cfd35035 | 212 | /* Particle momentum*/ |
6b51799c | 213 | STACK.pmom [STACK.lstack] = p; |
cfd35035 | 214 | |
215 | STACK.tx [STACK.lstack] = cosx; | |
216 | STACK.ty [STACK.lstack] = cosy; | |
217 | STACK.tz [STACK.lstack] = cosz; | |
b9d0a01d | 218 | |
cfd35035 | 219 | /* Polarization cosines:*/ |
220 | if (polarisation.Mag()) { | |
221 | Double_t cospolx = polarisation.Px() / polarisation.Mag(); | |
222 | Double_t cospoly = polarisation.Py() / polarisation.Mag(); | |
223 | Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly); | |
224 | STACK.txpol [STACK.lstack] = cospolx; | |
225 | STACK.typol [STACK.lstack] = cospoly; | |
226 | STACK.tzpol [STACK.lstack] = cospolz; | |
227 | } | |
228 | else { | |
229 | STACK.txpol [STACK.lstack] = -twotwo; | |
230 | STACK.typol [STACK.lstack] = +zerzer; | |
231 | STACK.tzpol [STACK.lstack] = +zerzer; | |
232 | } | |
233 | ||
234 | /* Particle coordinates*/ | |
235 | // Vertext coordinates; | |
236 | STACK.xa [STACK.lstack] = particle->Vx(); | |
237 | STACK.ya [STACK.lstack] = particle->Vy(); | |
238 | STACK.za [STACK.lstack] = particle->Vz(); | |
b9d0a01d | 239 | |
cfd35035 | 240 | /* Calculate the total kinetic energy of the primaries: don't change*/ |
241 | Int_t st_ilo = STACK.ilo[STACK.lstack]; | |
242 | if ( st_ilo != 0 ) | |
243 | EPISOR.tkesum += | |
244 | ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6]) | |
245 | * STACK.wt[STACK.lstack]); | |
246 | else | |
247 | EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]); | |
248 | ||
249 | /* Here we ask for the region number of the hitting point. | |
250 | * NREG (LSTACK) = ... | |
251 | * The following line makes the starting region search much more | |
252 | * robust if particles are starting very close to a boundary: | |
253 | */ | |
254 | geocrs( STACK.tx[STACK.lstack], | |
255 | STACK.ty[STACK.lstack], | |
256 | STACK.tz[STACK.lstack] ); | |
b9d0a01d | 257 | |
cfd35035 | 258 | Int_t idisc; |
259 | ||
260 | georeg ( STACK.xa[STACK.lstack], | |
261 | STACK.ya[STACK.lstack], | |
262 | STACK.za[STACK.lstack], | |
263 | STACK.nreg[STACK.lstack], | |
264 | idisc);//<-- dummy return variable not used | |
265 | /* Do not change these cards:*/ | |
266 | Int_t igeohsm1 = 1; | |
267 | Int_t igeohsm2 = -11; | |
268 | geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc ); | |
269 | STACK.nlattc[STACK.lstack] = LTCLCM.mlattc; | |
270 | soevsv(); | |
271 | } else { | |
b496f27c | 272 | // |
cfd35035 | 273 | // Next particle is optical photon |
b496f27c | 274 | // |
cfd35035 | 275 | OPPHST.lstopp++; |
276 | OPPHST.donear [OPPHST.lstopp - 1] = 0.; | |
277 | ||
278 | OPPHST.xoptph [OPPHST.lstopp - 1] = particle->Vx(); | |
279 | OPPHST.yoptph [OPPHST.lstopp - 1] = particle->Vy(); | |
280 | OPPHST.zoptph [OPPHST.lstopp - 1] = particle->Vz(); | |
281 | ||
282 | OPPHST.txopph [OPPHST.lstopp - 1] = cosx; | |
283 | OPPHST.tyopph [OPPHST.lstopp - 1] = cosy; | |
284 | OPPHST.tzopph [OPPHST.lstopp - 1] = cosz; | |
285 | ||
286 | ||
287 | if (polarisation.Mag()) { | |
288 | Double_t cospolx = polarisation.Px() / polarisation.Mag(); | |
289 | Double_t cospoly = polarisation.Py() / polarisation.Mag(); | |
290 | Double_t cospolz = sqrt(oneone - cospolx * cospolx - cospoly * cospoly); | |
291 | OPPHST.txpopp [OPPHST.lstopp - 1] = cospolx; | |
292 | OPPHST.typopp [OPPHST.lstopp - 1] = cospoly; | |
293 | OPPHST.tzpopp [OPPHST.lstopp - 1] = cospolz; | |
294 | } | |
295 | else { | |
296 | OPPHST.txpopp [OPPHST.lstopp - 1] = -twotwo; | |
297 | OPPHST.typopp [OPPHST.lstopp - 1] = +zerzer; | |
298 | OPPHST.tzpopp [OPPHST.lstopp - 1] = +zerzer; | |
299 | } | |
300 | ||
301 | geocrs( OPPHST.txopph[OPPHST.lstopp - 1], | |
302 | OPPHST.tyopph[OPPHST.lstopp - 1], | |
303 | OPPHST.tzopph[OPPHST.lstopp - 1] ); | |
ce60a136 | 304 | |
cfd35035 | 305 | Int_t idisc; |
306 | ||
307 | georeg ( OPPHST.xoptph[OPPHST.lstopp - 1], | |
308 | OPPHST.yoptph[OPPHST.lstopp - 1], | |
309 | OPPHST.zoptph[OPPHST.lstopp - 1], | |
310 | OPPHST.nregop[OPPHST.lstopp - 1], | |
311 | idisc);//<-- dummy return variable not used | |
312 | ||
313 | OPPHST.wtopph [OPPHST.lstopp - 1] = particle->GetWeight(); | |
314 | OPPHST.poptph [OPPHST.lstopp - 1] = particle->P(); | |
315 | OPPHST.agopph [OPPHST.lstopp - 1] = particle->T(); | |
e5e3c7b1 | 316 | OPPHST.cmpopp [OPPHST.lstopp - 1] = +zerzer; |
cfd35035 | 317 | OPPHST.loopph [OPPHST.lstopp - 1] = 0; |
cfd35035 | 318 | OPPHST.louopp [OPPHST.lstopp - 1] = itrack; |
cfd35035 | 319 | } |
320 | ||
ce60a136 | 321 | // |
322 | // Pre-track actions at for primary tracks | |
323 | // | |
324 | if (particleIsPrimary) { | |
325 | TVirtualMCApplication::Instance()->BeginPrimary(); | |
326 | TVirtualMCApplication::Instance()->PreTrack(); | |
327 | } | |
328 | ||
329 | // | |
2bc4c610 | 330 | if (debug) cout << "<== source(" << nomore << ")" << endl; |
b9d0a01d | 331 | } |
332 | } |