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