d7215413012ccd211f9fe5050502c33b010cc43d
[u/mrichter/AliRoot.git] / TFluka / source_ff.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 "Fpart.h"  
16 //#include "Fcaslim.h"  //(CASLIM) fluka common
17
18 //Virutal MC
19 #include "AliGenerator.h"
20 #include "AliStack.h"
21 #include "../PYTHIA6/AliGenPythia.h"
22
23 #include "TVirtualMCStack.h"
24 #include "TParticle.h"
25 #include "TVector3.h"
26
27 //Other
28 #include <Riostream.h>
29
30 #ifndef WIN32
31 # define source source_
32 # define geocrs geocrs_
33 # define georeg georeg_
34 # define geohsm geohsm_
35 # define soevsv soevsv_
36 # define mcihad mcihad_
37 # define source_f source_f__
38 #else
39 # define source SOURCE
40 # define geocrs GEOCRS
41 # define georeg GEOREG
42 # define geohsm GEOHSM
43 # define soevsv SOEVSV
44 # define mcihad MCIHAD
45 # define source_f SOURCE_F
46 #endif
47
48 extern "C" {
49   //
50   // Prototypes for FLUKA functions
51   //
52   void type_of_call geocrs(Double_t &, Double_t &, Double_t &);
53   void type_of_call georeg(Double_t &, Double_t &, Double_t &, 
54                            Int_t &, Int_t &);
55   void type_of_call geohsm(Int_t &, Int_t &, Int_t &, Int_t &);
56   void type_of_call soevsv();
57   int  type_of_call mcihad(const int&);
58  /*
59    *----------------------------------------------------------------------*
60    *                                                                      *
61    *     Created on 07 january 1990   by    Alfredo Ferrari & Paola Sala  *
62    *                                                   Infn - Milan       *
63    *                                                                      *
64    *     Last change on 21-jun-98     by    Alfredo Ferrari               *
65    *                                                                      *
66    *     C++ version on 27-sep-02     by    Isidro Gonzalez               *
67    *                                                                      *
68    *  This is just an example of a possible user written source routine.  *
69    *  note that the beam card still has some meaning - in the scoring the *
70    *  maximum momentum used in deciding the binning is taken from the     *
71    *  beam momentum.  Other beam card parameters are obsolete.            *
72    *                                                                      *
73    *----------------------------------------------------------------------*/
74
75   void source_f(Int_t& nomore) {
76
77       static Bool_t lfirst       = true;
78       static AliGenPythia* gener = 0;
79       static AliStack* stack     = 0;   
80
81       nomore = 0;
82       TParticle* particle;
83       Int_t itrack = -1;
84       if (lfirst) {
85           printf("source_f first call \n");
86           EPISOR.tkesum = zerzer;
87           lfirst = false;
88           EPISOR.lussrc = true;
89           gener  = new AliGenPythia(1);
90           gener->SetEnergyCMS(14000.);
91           gener->SetProcess(kPyMb);
92           stack = new AliStack(1000);
93           gener->SetStack(stack);
94           gener->Init();
95
96       } else {
97           //
98           // Generate event
99           printf("Calling Generate() %p \n", gener);
100           stack->Reset();
101           gener->Generate();
102           Int_t npart = stack->GetNprimary();
103           printf("%d Particles on the stack \n", npart);
104           for (Int_t part=0; part<npart; part++) {
105               particle = stack->Particle(part);
106               Int_t st = particle->GetStatusCode();
107               if (st != 1) continue;
108               Int_t pdg = particle->GetPdgCode();
109               Int_t intfluka = mcihad(pdg);
110               Int_t ifl = GetFlukaKPTOIP(intfluka);
111               TVector3 polarisation;
112               particle->GetPolarisation(polarisation);
113
114               STACK.lstack++;
115
116               printf("Particle %5d %5d %5d %10s %10.3f %10.3f %10.3f \n", STACK.lstack, pdg, ifl, 
117                      particle->GetName(), particle->Px(), particle->Py(), particle->Pz());
118               
119
120               
121               /* Wt is the weight of the particle*/
122               STACK.wt[STACK.lstack] = oneone;
123               STARS.weipri += STACK.wt[STACK.lstack];
124               
125               STACK.ilo[STACK.lstack] = ifl;
126               /* From this point .....
127                * Particle generation (1 for primaries)
128                */
129               STACK.lo[STACK.lstack] = 1;
130               
131               /* User dependent flag:*/
132               STACK.louse[STACK.lstack] = 0;
133               
134               /* User dependent spare variables:*/
135               Int_t ispr = 0;
136               for (ispr = 0; ispr < mkbmx1; ispr++)
137                   STACK.sparek[STACK.lstack][ispr] = zerzer;
138               
139               /* User dependent spare flags:*/
140               for (ispr = 0; ispr < mkbmx2; ispr++)
141                   STACK.ispark[STACK.lstack][ispr] = 0;
142               
143               /* Save the track number of the stack particle:*/
144               STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
145               STACK.nparma++;
146               STACK.numpar[STACK.lstack] = STACK.nparma;
147               STACK.nevent[STACK.lstack] = 0;
148               STACK.dfnear[STACK.lstack] = +zerzer;
149               
150               /* Particle age (s)*/
151               STACK.agestk[STACK.lstack] = +zerzer;
152               STACK.aknshr[STACK.lstack] = -twotwo;
153               
154               /* Group number for "low" energy neutrons, set to 0 anyway*/
155               STACK.igroup[STACK.lstack] = 0;
156               
157               /* Kinetic energy */
158               STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
159               
160               
161               /* Particle momentum*/
162               STACK.pmom [STACK.lstack] = particle->P();
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               STACK.tx [STACK.lstack] = cosx;
170               STACK.ty [STACK.lstack] = cosy;
171               STACK.tz [STACK.lstack] = cosz;
172               
173               /* Polarization cosines:*/
174               if (polarisation.Mag()) {
175                   Double_t cospolx = polarisation.Px()/polarisation.Mag();
176                   Double_t cospoly = polarisation.Py()/polarisation.Mag();
177                   Double_t cospolz = sqrt(oneone - cospolx*cospolx - cospoly*cospoly);
178                   STACK.tx [STACK.lstack] = cospolx;
179                   STACK.ty [STACK.lstack] = cospoly;
180                   STACK.tz [STACK.lstack] = cospolz;
181               }
182               else {
183                   STACK.txpol [STACK.lstack] = -twotwo;
184                   STACK.typol [STACK.lstack] = +zerzer;
185                   STACK.tzpol [STACK.lstack] = +zerzer;
186               }
187               
188               /* Particle coordinates*/
189               // Vertext coordinates;
190               STACK.xa [STACK.lstack] = particle->Vx();
191               STACK.ya [STACK.lstack] = particle->Vy();
192               STACK.za [STACK.lstack] = particle->Vz();
193               
194               /*  Calculate the total kinetic energy of the primaries: don't change*/
195               Int_t st_ilo =  STACK.ilo[STACK.lstack];
196               if ( st_ilo != 0 )
197                   EPISOR.tkesum += 
198                       ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
199                        * STACK.wt[STACK.lstack]);
200               else
201                   EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
202               
203               /*  Here we ask for the region number of the hitting point.
204                *     NREG (LSTACK) = ...
205                *  The following line makes the starting region search much more
206                *  robust if particles are starting very close to a boundary:
207                */
208               geocrs( STACK.tx[STACK.lstack], 
209                       STACK.ty[STACK.lstack], 
210                       STACK.tz[STACK.lstack] );
211               
212               Int_t idisc;
213               
214               georeg ( STACK.xa[STACK.lstack], 
215                        STACK.ya[STACK.lstack], 
216                        STACK.za[STACK.lstack],
217                        STACK.nreg[STACK.lstack], 
218                        idisc);//<-- dummy return variable not used
219               /*  Do not change these cards:*/
220               Int_t igeohsm1 = 1;
221               Int_t igeohsm2 = -11;
222               geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
223               STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
224               soevsv();
225 //
226 //  Pre-track actions at for primary tracks
227 //
228           }
229       }
230   }
231 }
232
233