Coding conventions.
[u/mrichter/AliRoot.git] / TFluka / source_bg.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 "../THijing/AliGenHijing.h"
22
23 #include "TVirtualMCStack.h"
24 #include "TParticle.h"
25 #include "TVector3.h"
26 #include "TRandom.h"
27
28 //Other
29 #include <Riostream.h>
30
31 #ifndef WIN32
32 # define source source_
33 # define geocrs geocrs_
34 # define georeg georeg_
35 # define geohsm geohsm_
36 # define soevsv soevsv_
37 # define mcihad mcihad_
38 # define source_bg source_bg__
39 #else
40 # define source SOURCE
41 # define geocrs GEOCRS
42 # define georeg GEOREG
43 # define geohsm GEOHSM
44 # define soevsv SOEVSV
45 # define mcihad MCIHAD
46 # define source_bg SOURCE_BG
47 #endif
48
49 extern "C" {
50   //
51   // Prototypes for FLUKA functions
52   //
53   void type_of_call geocrs(Double_t &, Double_t &, Double_t &);
54   void type_of_call georeg(Double_t &, Double_t &, Double_t &, 
55                            Int_t &, Int_t &);
56   void type_of_call geohsm(Int_t &, Int_t &, Int_t &, Int_t &);
57   void type_of_call soevsv();
58   int  type_of_call mcihad(const int&);
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_bg(Int_t& nomore) {
77
78       static Bool_t lfirst       = true;
79       static AliGenHijing* gener = 0;
80       static AliStack* stack     = 0;   
81
82       nomore = 0;
83       TParticle* particle;
84       Int_t itrack = -1;
85       if (lfirst) {
86           EPISOR.tkesum = zerzer;
87           lfirst = false;
88           EPISOR.lussrc = true;
89 //
90 // The generator
91 //
92           gener  = new AliGenHijing(-1);
93 // beam energy 
94           gener->SetEnergyCMS(7000.);
95 // reference frame
96           gener->SetReferenceFrame("LAB");
97 // projectile
98           gener->SetProjectile("P",  1,  1);
99           gener->SetTarget    ("A", 16,  8);
100           gener->SetBoostLHC(0);
101           
102 // tell hijing to keep the full parent child chain
103           gener->KeepFullEvent();
104 // enable jet quenching
105           gener->SetJetQuenching(0);
106 // enable shadowing
107           gener->SetShadowing(0);
108 // neutral pion and heavy particle decays switched off
109           gener->SetDecaysOff(1);
110 // Don't track spectators
111           gener->SetSpectators(0);
112 // The particle stack
113           stack = new AliStack(1000);
114           gener->SetStack(stack);
115           gener->Init();
116
117       } else {
118           //
119           // Generate event
120           stack->Reset();
121           gener->Generate();
122           Int_t npart = stack->GetNprimary();
123           // Vertex
124           Float_t za   =  4000. * gRandom->Rndm() -2000.;
125           // Direction
126 //        Float_t dir  = (za < 0.) ? 1. : -1.;
127           Float_t dir  = (gRandom->Rndm() < 0.5)? 1. : -1;
128           
129           for (Int_t part=0; part<npart; part++) {
130               particle = stack->Particle(part);
131               Int_t ic = particle->GetFirstDaughter();
132               if (ic != -1) continue;
133               Int_t pdg = particle->GetPdgCode();
134               Int_t intfluka = mcihad(pdg);
135               Int_t ifl = GetFlukaKPTOIP(intfluka);
136               TVector3 polarisation;
137               particle->GetPolarisation(polarisation);
138
139               STACK.lstack++;
140
141               printf("Particle %5d %5d %5d %10s %10.3f %10.3f %10.3f \n", STACK.lstack, pdg, ifl, 
142                      particle->GetName(), particle->Px(), particle->Py(), particle->Pz());
143               
144
145               
146               /* Wt is the weight of the particle*/
147               STACK.wt[STACK.lstack] = oneone;
148               STARS.weipri += STACK.wt[STACK.lstack];
149               
150               STACK.ilo[STACK.lstack] = ifl;
151               /* From this point .....
152                * Particle generation (1 for primaries)
153                */
154               STACK.lo[STACK.lstack] = 1;
155               
156               /* User dependent flag:*/
157               STACK.louse[STACK.lstack] = 0;
158               
159               /* User dependent spare variables:*/
160               Int_t ispr = 0;
161               for (ispr = 0; ispr < mkbmx1; ispr++)
162                   STACK.sparek[STACK.lstack][ispr] = zerzer;
163               
164               /* User dependent spare flags:*/
165               for (ispr = 0; ispr < mkbmx2; ispr++)
166                   STACK.ispark[STACK.lstack][ispr] = 0;
167               
168               /* Save the track number of the stack particle:*/
169               STACK.ispark[STACK.lstack][mkbmx2-1] = itrack;
170               STACK.nparma++;
171               STACK.numpar[STACK.lstack] = STACK.nparma;
172               STACK.nevent[STACK.lstack] = 0;
173               STACK.dfnear[STACK.lstack] = +zerzer;
174               
175               /* Particle age (s)*/
176               STACK.agestk[STACK.lstack] = +zerzer;
177               STACK.aknshr[STACK.lstack] = -twotwo;
178               
179               /* Group number for "low" energy neutrons, set to 0 anyway*/
180               STACK.igroup[STACK.lstack] = 0;
181               
182               /* Kinetic energy */
183               STACK.tke[STACK.lstack] = particle->Energy() - particle->GetMass();
184               
185               
186               /* Particle momentum*/
187               STACK.pmom [STACK.lstack] = particle->P();
188               
189               /* Cosines (tx,ty,tz)*/
190               Double_t cosx = particle->Px()/particle->P();
191               Double_t cosy = particle->Py()/particle->P();
192               Double_t cosz = TMath::Sqrt(oneone - cosx*cosx - cosy*cosy);
193               if (particle->Pz() < 0.)   cosz = -cosz;
194               cosz *= dir;
195               
196               STACK.tx [STACK.lstack] = cosx;
197               STACK.ty [STACK.lstack] = cosy;
198               STACK.tz [STACK.lstack] = cosz;
199               
200               /* Polarization cosines:*/
201               if (polarisation.Mag()) {
202                   Double_t cospolx = polarisation.Px()/polarisation.Mag();
203                   Double_t cospoly = polarisation.Py()/polarisation.Mag();
204                   Double_t cospolz = sqrt(oneone - cospolx*cospolx - cospoly*cospoly);
205                   STACK.tx [STACK.lstack] = cospolx;
206                   STACK.ty [STACK.lstack] = cospoly;
207                   STACK.tz [STACK.lstack] = cospolz;
208               }
209               else {
210                   STACK.txpol [STACK.lstack] = -twotwo;
211                   STACK.typol [STACK.lstack] = +zerzer;
212                   STACK.tzpol [STACK.lstack] = +zerzer;
213               }
214               
215               /* Particle coordinates*/
216               STACK.xa [STACK.lstack] = particle->Vx();
217               STACK.ya [STACK.lstack] = particle->Vy();
218               STACK.za [STACK.lstack] = za;
219               
220               printf("Particle Vertex %10.3f %10.3f %10.3f %10.3f \n",  
221                      STACK.xa [STACK.lstack],  STACK.ya [STACK.lstack],  STACK.za [STACK.lstack], dir);
222               
223               
224               
225               /*  Calculate the total kinetic energy of the primaries: don't change*/
226               Int_t st_ilo =  STACK.ilo[STACK.lstack];
227               if ( st_ilo != 0 )
228                   EPISOR.tkesum += 
229                       ((STACK.tke[STACK.lstack] + PAPROP.amdisc[st_ilo+6])
230                        * STACK.wt[STACK.lstack]);
231               else
232                   EPISOR.tkesum += (STACK.tke[STACK.lstack] * STACK.wt[STACK.lstack]);
233               
234               /*  Here we ask for the region number of the hitting point.
235                *     NREG (LSTACK) = ...
236                *  The following line makes the starting region search much more
237                *  robust if particles are starting very close to a boundary:
238                */
239               geocrs( STACK.tx[STACK.lstack], 
240                       STACK.ty[STACK.lstack], 
241                       STACK.tz[STACK.lstack] );
242               
243               Int_t idisc;
244               
245               georeg ( STACK.xa[STACK.lstack], 
246                        STACK.ya[STACK.lstack], 
247                        STACK.za[STACK.lstack],
248                        STACK.nreg[STACK.lstack], 
249                        idisc);//<-- dummy return variable not used
250               /*  Do not change these cards:*/
251               Int_t igeohsm1 = 1;
252               Int_t igeohsm2 = -11;
253               geohsm ( STACK.nhspnt[STACK.lstack], igeohsm1, igeohsm2, LTCLCM.mlattc );
254               STACK.nlattc[STACK.lstack] = LTCLCM.mlattc;
255               soevsv();
256           }
257       }
258   }
259 }
260
261