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