]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TFluka/source.cxx
Clean-up. (E. Futo)
[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        if ((itrack%10)==0) printf("=== TRACKING PRIMARY %d ===\n", itrack);
127         }
128     }
129
130     //Exit if itrack is negative (-1). Set lsouit to false to mark last track for
131     //this event
132
133     if (itrack<0) {
134       nomore = 1;
135       EPISOR.lsouit = false;
136       if (debug) {
137          cout << "\t* EPISOR.lsouit = " << (EPISOR.lsouit?'T':'F') << endl;
138          cout << "\t* No more particles. Exiting..." << endl;
139          cout << "<== source(" << nomore << ")" << endl;
140       }   
141       return;
142     }
143     
144     //Get some info about the particle and print it
145     //
146     //pdg code
147     Int_t pdg = particle->GetPdgCode();
148     
149     TVector3 polarisation;
150     particle->GetPolarisation(polarisation);
151     if (debug) {
152        cout << "\t* Particle " << itrack << " retrieved..." << endl;
153        cout << "\t\t+ Name = " << particle->GetName() << endl;
154        cout << "\t\t+ PDG/Fluka code = " << pdg 
155             << " / " << fluka->IdFromPDG(pdg) << endl;
156        cout << "\t\t+ P = (" 
157             << particle->Px() << " , "
158             << particle->Py() << " , "
159             << particle->Pz() << " ) --> "
160             << particle->P() << " GeV" << endl;
161     }   
162     /* Lstack is the stack counter: of course any time source is called it
163      * must be =0
164      */
165     
166     STACK.lstack++;
167
168     /* Wt is the weight of the particle*/
169     STACK.wt[STACK.lstack] = oneone;
170     STARS.weipri += STACK.wt[STACK.lstack];
171
172     /* Particle type (1=proton.....). Ijbeam is the type set by the BEAM
173      * card
174        */
175
176     //STACK.ilo[STACK.lstack] = BEAM.ijbeam;
177     if (pdg == 50000050 ||  pdg ==  50000051) {
178         STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(22);
179     } else {
180         STACK.ilo[STACK.lstack] = fluka-> IdFromPDG(pdg);
181     }
182     
183     
184             
185
186     /* From this point .....
187      * Particle generation (1 for primaries)
188     */
189     STACK.lo[STACK.lstack] = 1;
190
191     /* User dependent flag:*/
192     STACK.louse[STACK.lstack] = 0;
193
194     /* User dependent spare variables:*/
195     Int_t ispr = 0;
196     for (ispr = 0; ispr < mkbmx1; ispr++)
197       STACK.sparek[STACK.lstack][ispr] = zerzer;
198
199     /* User dependent spare flags:*/
200     for (ispr = 0; ispr < mkbmx2; ispr++)
201         STACK.ispark[STACK.lstack][ispr] = 0;
202
203     /* Save the track number of the stack particle:*/
204     STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
205     STACK.nparma++;
206     STACK.numpar[STACK.lstack] = STACK.nparma;
207     STACK.nevent[STACK.lstack] = 0;
208     STACK.dfnear[STACK.lstack] = +zerzer;
209     
210     /* Particle age (s)*/
211     STACK.agestk[STACK.lstack] = +zerzer;
212     STACK.aknshr[STACK.lstack] = -twotwo;
213
214     /* Group number for "low" energy neutrons, set to 0 anyway*/
215     STACK.igroup[STACK.lstack] = 0;
216     
217     /* Kinetic energy */
218     if (pdg == 50000050 ||  pdg ==  50000051) {
219         // 
220         // Special case for optical photons
221         STACK.tke[STACK.lstack] = particle->Energy();
222     } else {
223         STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
224     }
225     
226     
227     /* Particle momentum*/
228     STACK.pmom [STACK.lstack] = particle->P();
229     
230     /* Cosines (tx,ty,tz)*/
231     Double_t cosx = particle->Px()/particle->P();
232     Double_t cosy = particle->Py()/particle->P();
233     Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
234     if (particle->Pz() < 0.) cosz = -cosz;
235     STACK.tx [STACK.lstack] = cosx;
236     STACK.ty [STACK.lstack] = cosy;
237     STACK.tz [STACK.lstack] = cosz;
238     
239     /* Polarization cosines:*/
240     if (polarisation.Mag()) {
241         Double_t cospolx = polarisation.Px()/polarisation.Mag();
242         Double_t cospoly = polarisation.Py()/polarisation.Mag();
243         Double_t cospolz = sqrt(oneone - cospolx*cospolx - cospoly*cospoly);
244         STACK.tx [STACK.lstack] = cospolx;
245         STACK.ty [STACK.lstack] = cospoly;
246         STACK.tz [STACK.lstack] = cospolz;
247     }
248     else {
249         STACK.txpol [STACK.lstack] = -twotwo;
250         STACK.typol [STACK.lstack] = +zerzer;
251         STACK.tzpol [STACK.lstack] = +zerzer;
252     }
253     
254     /* Particle coordinates*/
255     // Vertext coordinates;
256     STACK.xa [STACK.lstack] = particle->Vx();
257     STACK.ya [STACK.lstack] = particle->Vy();
258     STACK.za [STACK.lstack] = particle->Vz();
259     
260     /*  Calculate the total kinetic energy of the primaries: don't change*/
261     Int_t st_ilo =  STACK.ilo[STACK.lstack];
262     if ( st_ilo != 0 )
263         EPISOR.tkesum += 
264             ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
265              * STACK.wt[STACK.lstack]);
266     else
267         EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
268     
269     /*  Here we ask for the region number of the hitting point.
270      *     NREG (LSTACK) = ...
271      *  The following line makes the starting region search much more
272      *  robust if particles are starting very close to a boundary:
273      */
274     geocrs( STACK.tx[STACK.lstack], 
275             STACK.ty[STACK.lstack], 
276             STACK.tz[STACK.lstack] );
277     
278     Int_t idisc;
279
280     georeg ( STACK.xa[STACK.lstack], 
281              STACK.ya[STACK.lstack], 
282              STACK.za[STACK.lstack],
283              STACK.nreg[STACK.lstack], 
284              idisc);//<-- dummy return variable not used
285     /*  Do not change these cards:*/
286     Int_t igeohsm1 = 1;
287     Int_t igeohsm2 = -11;
288     geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
289     STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
290     soevsv();
291 //
292 //  Pre-track actions at for primary tracks
293 //
294     if (particleIsPrimary) {
295         TVirtualMCApplication::Instance()->BeginPrimary();
296         TVirtualMCApplication::Instance()->PreTrack();
297     }
298     
299 //
300     if (debug) cout << "<== source(" << nomore << ")" << endl;
301   }
302 }