]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TFluka/source.cxx
Use FLUKA particle masses !
[u/mrichter/AliRoot.git] / TFluka / source.cxx
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
13 #include "Fopphst.h"  //(OPPHST) fluka common
14 //#include "Fcaslim.h"  //(CASLIM) fluka common
15
16 //Virutal MC
17 #include "TFluka.h"
18
19 #include "TVirtualMCStack.h"
20 //#include "TVirtualMCApplication.h"
21
22 #include "TParticle.h"
23 #include "TVector3.h"
24
25 //Other
26 #include <Riostream.h>
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
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) {
69 // Get the pointer to TFluka
70     TFluka* fluka = (TFluka*)gMC;
71
72     Int_t verbosityLevel = fluka->GetVerbosityLevel();
73     Bool_t debug = (verbosityLevel>=3)?kTRUE:kFALSE;
74     if (debug) {
75       cout << "==> source(" << nomore << ")" << endl;
76       cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
77     }  
78
79     static Bool_t lfirst = true;
80     static Bool_t particleIsPrimary = true;
81     static Bool_t lastParticleWasPrimary = true;
82
83     nomore = 0;
84     
85 //  Get the stack 
86     TVirtualMCStack* cppstack = fluka->GetStack();
87
88     TParticle* particle;
89     Int_t itrack = -1;
90     Int_t  nprim  = cppstack->GetNprimary();
91 //  Get the next particle from the stack
92     particle  = cppstack->PopNextTrack(itrack);
93     fluka->SetTrackIsNew(kTRUE);
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
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();
115             if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack);
116         }
117     }
118
119     // Exit if itrack is negative (-1). Set lsouit to false to mark last track for this event
120
121     if (itrack<0) {
122       nomore = 1;
123       EPISOR.lsouit = false;
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       }   
129       return;
130     }
131     
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
142     //Get some info about the particle and print it
143     //
144     //pdg code
145     Int_t pdg = particle->GetPdgCode();
146     TVector3 polarisation;
147     particle->GetPolarisation(polarisation);
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() << " ) --> "
157             << particle->P() << " GeV " 
158             << particle->Energy() << " GeV "  
159             << particle->GetMass() << " GeV " << endl;
160     }   
161     /* Lstack is the stack counter: of course any time source is called it
162      * must be =0
163      */
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;    
169
170     //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
171     if (pdg != 50000050 &&  pdg !=  50000051) {
172         STACK.lstack++;
173         Int_t ifl =  fluka-> IdFromPDG(pdg);
174         STACK.ilo[STACK.lstack] = ifl;
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;
183
184         /* User dependent spare variables:*/
185         Int_t ispr = 0;
186         for (ispr = 0; ispr < mkbmx1; ispr++)
187             STACK.sparek[STACK.lstack][ispr] = zerzer;
188
189         /* User dependent spare flags:*/
190         for (ispr = 0; ispr < mkbmx2; ispr++)
191             STACK.ispark[STACK.lstack][ispr] = 0;
192
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;
199         
200         /* Particle age (s)*/
201         STACK.agestk[STACK.lstack] = +zerzer;
202         STACK.cmpath[STACK.lstack] = +zerzer;
203         STACK.aknshr[STACK.lstack] = -twotwo;
204
205         /* Group number for "low" energy neutrons, set to 0 anyway*/
206         STACK.igroup[STACK.lstack] = 0;
207         
208         /* Kinetic energy */
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;
212         /* Particle momentum*/
213         STACK.pmom [STACK.lstack] = p;
214
215         STACK.tx [STACK.lstack] = cosx;
216         STACK.ty [STACK.lstack] = cosy;
217         STACK.tz [STACK.lstack] = cosz;
218     
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();
239     
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] );
257     
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 {
272         //
273         // Next particle is optical photon
274         //
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] );
304     
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();      
316         OPPHST.cmpopp [OPPHST.lstopp - 1] = +zerzer;
317         OPPHST.loopph [OPPHST.lstopp - 1] = 0;
318         OPPHST.louopp [OPPHST.lstopp - 1] = itrack;
319     }
320     
321 //
322 //  Pre-track actions at for primary tracks
323 //
324     if (particleIsPrimary) {
325         TVirtualMCApplication::Instance()->BeginPrimary();
326         TVirtualMCApplication::Instance()->PreTrack();
327     }
328     
329 //
330     if (debug) cout << "<== source(" << nomore << ")" << endl;
331   }
332 }