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