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