All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TGeant3gu.cxx
Go to the documentation of this file.
1 #include <iostream>
4 #include "TLorentzVector.h"
5 #include "TClonesArray.h"
6 #include "TParticle.h"
7 
8 //#define COLLECT_TRACKS
9 #if defined(COLLECT_TRACKS)
10 #include "TGeoManager.h"
11 #include "TVirtualGeoTrack.h"
12 #endif
13 
14 #ifndef WIN32
15 # define gudigi gudigi_
16 # define guhadr guhadr_
17 # define guout guout_
18 # define guphad guphad_
19 # define gudcay gudcay_
20 # define guiget guiget_
21 # define guinme guinme_
22 # define guinti guinti_
23 # define gunear gunear_
24 # define guskip guskip_
25 # define guview guview_
26 # define gupara gupara_
27 # define gudtim gudtim_
28 # define guplsh guplsh_
29 # define gutrev gutrev_
30 # define gutrak gutrak_
31 # define guswim guswim_
32 # define gufld gufld_
33 # define gustep gustep_
34 # define gukine gukine_
35 
36 # define eustep eustep_
37 
38 # define calsig calsig_
39 # define gcalor gcalor_
40 
41 # define gheish gheish_
42 # define flufin flufin_
43 # define gfmfin gfmfin_
44 # define gpghei gpghei_
45 # define fldist fldist_
46 # define gfmdis gfmdis_
47 # define g3helx3 g3helx3_
48 # define g3helix g3helix_
49 # define g3rkuta g3rkuta_
50 # define g3track g3track_
51 # define gtreveroot gtreveroot_
52 # define g3last g3last_
53 # define g3invol g3invol_
54 # define g3tmedi g3tmedi_
55 # define g3media g3media_
56 # define g3tmany g3tmany_
57 # define g3tnext g3tnext_
58 # define ginvol ginvol_
59 # define gtmedi gtmedi_
60 # define gtmany gtmany_
61 # define gtonly gtonly_
62 # define gmedia gmedia_
63 # define glvolu glvolu_
64 # define gtnext gtnext_
65 
66 #else
67 # define gudigi GUDIGI
68 # define guhadr GUHADR
69 # define guout GUOUT
70 # define guphad GUPHAD
71 # define gudcay GUDCAY
72 # define guiget GUIGET
73 # define guinme GUINME
74 # define guinti GUINTI
75 # define gunear GUNEAR
76 # define guskip GUSKIP
77 # define guview GUVIEW
78 # define gupara GUPARA
79 # define gudtim GUDTIM
80 # define guplsh GUPLSH
81 # define gutrev GUTREV
82 # define gutrak GUTRAK
83 # define guswim GUSWIM
84 # define gufld GUFLD
85 # define gustep GUSTEP
86 # define gukine GUKINE
87 
88 # define calsig CALSIG
89 # define gcalor GCALOR
90 
91 # define gheish GHEISH
92 # define flufin FLUFIN
93 # define gfmfin GFMFIN
94 # define gpghei GPGHEI
95 # define fldist FLDIST
96 # define gfmdis GFMDIS
97 # define g3helx3 G3HELX3
98 # define g3helix G3HELIX
99 # define g3rkuta G3RKUTA
100 # define gtrack GTRACK
101 # define gtreveroot GTREVEROOT
102 # define glast GLAST
103 # define ginvol GINVOL
104 # define gtmedi GTMEDI
105 # define gtmany GTMANY
106 # define gmedia GMEDIA
107 # define glvolu GLVOLU
108 # define gtnext GTNEXT
109 
110 #endif
111 
112 extern TGeant3* geant3;
113 #if defined(COLLECT_TRACKS)
114 extern TGeoManager *gGeoManager;
115 #endif
116 
117 
118 extern "C" type_of_call void calsig();
119 extern "C" type_of_call void gcalor();
120 
121 extern "C" type_of_call void gheish();
122 extern "C" type_of_call void flufin();
123 extern "C" type_of_call void gfmfin();
124 extern "C" type_of_call void gpghei();
125 extern "C" type_of_call void fldist();
126 extern "C" type_of_call void gfmdis();
127 extern "C" type_of_call void g3helx3(Float_t&, Float_t&, Float_t*, Float_t*);
128 extern "C" type_of_call void g3helix(Float_t&, Float_t&, Float_t*, Float_t*);
129 extern "C" type_of_call void g3rkuta(Float_t&, Float_t&, Float_t*, Float_t*);
130 extern "C" type_of_call void g3track();
131 extern "C" type_of_call void gtreveroot();
132 extern "C" type_of_call void g3last();
133 extern "C" type_of_call void g3invol(Float_t*, Int_t&);
134 extern "C" type_of_call void g3tmedi(Float_t*, Int_t&);
135 extern "C" type_of_call void g3tmany(Int_t&);
136 extern "C" type_of_call void g3media(Float_t*, Int_t&, Int_t&);
137 extern "C" type_of_call void g3tnext();
138 extern "C" type_of_call void ginvol(Float_t*, Int_t&);
139 extern "C" type_of_call void gtmedi(Float_t*, Int_t&);
140 extern "C" type_of_call void gtmany(Int_t&);
141 extern "C" type_of_call void gtonly(Int_t&);
142 extern "C" type_of_call void gmedia(Float_t*, Int_t&, Int_t&);
143 extern "C" type_of_call void glvolu(Int_t &nlev, Int_t *lnam,Int_t *lnum, Int_t &ier);
144 extern "C" type_of_call void gtnext();
145 extern "C" type_of_call {
146 
147 //______________________________________________________________________
148 void gudigi()
149 {
150 //
151 // ******************************************************************
152 // * *
153 // * User routine to digitize one event *
154 // * *
155 // * ==>Called by : GTRIG *
156 // * *
157 // ******************************************************************
158 
159 }
160 
161 
162 //______________________________________________________________________
163 void guhadr()
164 {
165 //
166 // ******************************************************************
167 // * *
168 // * User routine to generate one hadronic interaction *
169 // * *
170 // * ==>Called by : GTHADR,GTNEUT *
171 // * *
172 // ******************************************************************
173 //
174 //
175 // ------------------------------------------------------------------
176 //
177  Int_t ihadr = geant3->Gcphys()->ihadr;
178 
179  // printf(" iHadr 1 :%i \n ",ihadr);
180  if (ihadr<4) { gheish();}
181  else if (ihadr==4){ flufin();}
182  else if (ihadr==5){ gcalor();}
183  else { gfmfin();}
184 
185 }
186 
187 //______________________________________________________________________
188 void guout()
189 {
190 //
191 // ******************************************************************
192 // * *
193 // * User routine called at the end of each event *
194 // * *
195 // * ==>Called by : GTRIG *
196 // * *
197 // ******************************************************************
198 //
199 //
200 // ------------------------------------------------------------------
201 //
202  //printf("count_gmedia= %8d\n",count_gmedia);
203  //printf("count_gtmedi= %8d\n",count_gtmedi);
204  //printf("count_ginvol= %8d\n",count_ginvol);
205  //printf("count_gtnext= %8d\n",count_gtnext);
206 }
207 
208 //______________________________________________________________________
209 void guphad()
210 {
211 //
212 // ******************************************************************
213 // * *
214 // * User routine to compute Hadron. inter. probabilities *
215 // * *
216 // * ==>Called by : GTHADR,GTNEUT *
217 // * *
218 // ******************************************************************
219 //
220 //
221 // ------------------------------------------------------------------
222 //
223  Int_t ihadr = geant3->Gcphys()->ihadr;
224  // printf(" iHadr 2 :%i \n ",ihadr);
225  if (ihadr<4){ gpghei();}
226  else if ( ihadr==4 ){ fldist();}
227  else if ( ihadr==5 ){ calsig();}
228  else { gfmdis();}
229 
230 }
231 
232 //______________________________________________________________________
233 void gudcay()
234 {
235 //
236 // ******************************************************************
237 // * *
238 // * User routine to decay particles *
239 // * *
240 // * ==>Called by : G3DECAY *
241 // * *
242 // ******************************************************************
243 //
244 //
245 // ------------------------------------------------------------------
246 //
247 
248  // set decay table
249  if (!gMC->GetDecayer()) return;
250  gMC->GetDecayer()->ForceDecay();
251 
252 // Initialize 4-momentum vector
253  Int_t ipart = geant3->Gckine()->ipart;
254  static TLorentzVector p;
255 
256  Float_t pmom = geant3->Gctrak()->vect[6];
257 
258  p[0] = pmom * (geant3->Gctrak()->vect[3]);
259  p[1] = pmom * (geant3->Gctrak()->vect[4]);
260  p[2] = pmom * (geant3->Gctrak()->vect[5]);
261  p[3] = geant3->Gctrak()->getot;
262 
263 
264 // Convert from geant to lund particle code
265  Int_t iplund=gMC->PDGFromId(ipart);
266 
267 // Particle list
268  static TClonesArray *particles;
269  if(!particles) particles=new TClonesArray("TParticle",1000);
270 // Decay
271  gMC->GetDecayer()->Decay(iplund, &p);
272 
273 // Fetch Particles
274  Int_t np = geant3->GetDecayer()->ImportParticles(particles);
275  if (np <=1) return;
276 
277  TParticle * iparticle = (TParticle *) particles->At(0);
278  Int_t ipF = 0, ipL = 0 ;
279  Int_t i,j;
280 
281 // Array to flag deselected particles
282  Int_t* pFlag = new Int_t[np];
283  for (i=0; i<np; i++) pFlag[i]=0;
284 // Particle loop
285  for (i=1; i < np; i++)
286  {
287  iparticle = (TParticle *) particles->At(i);
288  ipF = iparticle->GetFirstDaughter();
289  ipL = iparticle->GetLastDaughter();
290  Int_t kf = iparticle->GetPdgCode();
291  Int_t ks = iparticle->GetStatusCode();
292 //
293 // Deselect daughters of deselected particles
294 // and jump skip the current particle
295  if (pFlag[i] == 1) {
296  if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
297  continue;
298  } // deselected ??
299 // Particles with long life-time are put on the stack for further tracking
300 // Decay products are deselected
301 //
302  if (ks != 1) {
303  Double_t lifeTime = gMC->GetDecayer()->GetLifetime(kf);
304  if (lifeTime > (Double_t) 1.e-15) {
305  if (ipF > 0) for (j=ipF-1; j<ipL; j++) pFlag[j]=1;
306  } else{
307  continue;
308  }
309  } // ks==1 ?
310 // Skip neutrinos
311  if (geant3->SkipNeutrinos()) {
312  if (kf==12 || kf ==-12) continue;
313  if (kf==14 || kf ==-14) continue;
314  if (kf==16 || kf ==-16) continue;
315  }
316 
317  Int_t index=geant3->Gcking()->ngkine;
318 // Put particle on geant stack
319 // momentum vector
320 
321  (geant3->Gcking()->gkin[index][0]) = iparticle->Px();
322  (geant3->Gcking()->gkin[index][1]) = iparticle->Py();
323  (geant3->Gcking()->gkin[index][2]) = iparticle->Pz();
324  (geant3->Gcking()->gkin[index][3]) = iparticle->Energy();
325  Int_t ilu = gMC->IdFromPDG(kf);
326 
327 // particle type
328  (geant3->Gcking()->gkin[index][4]) = Float_t(ilu);
329 // position
330  (geant3->Gckin3()->gpos[index][0]) = geant3->Gctrak()->vect[0];
331  (geant3->Gckin3()->gpos[index][1]) = geant3->Gctrak()->vect[1];
332  (geant3->Gckin3()->gpos[index][2]) = geant3->Gctrak()->vect[2];
333 // time of flight offset (mm)
334  (geant3->Gcking()->tofd[index]) = 0.;
335 // increase stack counter
336  (geant3->Gcking()->ngkine)=index+1;
337  }
338  delete[] pFlag;
339 }
340 
341 //______________________________________________________________________
342 void guiget(Int_t&, Int_t&, Int_t&)
343 {
344 //
345 // ******************************************************************
346 // * *
347 // * User routine for interactive control of GEANT *
348 // * *
349 // * ==>Called by : <GXINT>, GINCOM *
350 // * *
351 // ******************************************************************
352 //
353 //
354 // ------------------------------------------------------------------
355 //
356 }
357 
358 //______________________________________________________________________
359 void guinme(Float_t*, Int_t&, Float_t*, Int_t& IYES)
360 {
361 //
362 // **********************************************
363 // * *
364 // * USER ROUTINE TO PROVIDE GINME FUNCTION *
365 // * FOR ALL USER SHAPES IDENTIFIED BY THE *
366 // * SHAPE NUMBER SH. POINT IS GIVEN IN X *
367 // * THE PARAMETERS ARE GIVEN IN P. IYES IS *
368 // * RETURNED 1 IF POINT IS IN, 0 IF POINT *
369 // * IS OUT AND LESS THAN ZERO IF SHAPE *
370 // * NUMBER IS NOT SUPPORTED. *
371 // * *
372 // * ==>Called by : GINME *
373 // * *
374 // **********************************************
375 //
376  IYES=-1;
377 }
378 
379 //______________________________________________________________________
380 void guinti()
381 {
382 //
383 // ******************************************************************
384 // * *
385 // * User routine for interactive version *
386 // * *
387 // * ==>Called by : <GXINT>, GINTRI *
388 // * *
389 // ******************************************************************
390 //
391 //
392 // ------------------------------------------------------------------
393 //
394 }
395 
396 //______________________________________________________________________
397 void gunear(Int_t&, Int_t&, Float_t*, Int_t&)
398 {
399 //
400 // ******************************************************************
401 // * *
402 // * User search *
403 // * ISEARC to identify the given volume *
404 // * ICALL to identify the calling routine *
405 // * 1 GMEDIA like *
406 // * 2 GNEXT like *
407 // * X coordinates (+direction for ICALL=2) *
408 // * JNEAR address of default list of neighbours *
409 // * (list to be overwriten by user) *
410 // * *
411 // * Called by : GFTRAC, GINVOL, GTMEDI, GTNEXT, GNEXT, GMEDIA *
412 // * *
413 // ******************************************************************
414 //
415 //
416 // ------------------------------------------------------------------
417 //
418 }
419 
420 //______________________________________________________________________
421 void guskip(Int_t& ISKIP)
422 {
423 //
424 // ******************************************************************
425 // * *
426 // * User routine to skip unwanted tracks *
427 // * *
428 // * Called by : GSSTAK *
429 // * Author : F.Bruyant *
430 // * *
431 // ******************************************************************
432 //
433 //
434 // ------------------------------------------------------------------
435 //
436  ISKIP = 0;
437 }
438 
439 //______________________________________________________________________
440 void guswim(Float_t& CHARGE, Float_t& STEP, Float_t* VECT, Float_t* VOUT)
441 {
442 //
443 // ******************************************************************
444 // * *
445 // * User routine to control tracking of one track *
446 // * in a magnetic field *
447 // * *
448 // * ==>Called by : GTELEC,GTHADR,GTMUON *
449 // * *
450 // ******************************************************************
451 //
452 //
453 // ------------------------------------------------------------------
454 //
455  Int_t ifield = geant3->Gctmed()->ifield;
456  Float_t fieldm = geant3->Gctmed()->fieldm;
457 
458  if (ifield==3) {
459  Float_t fldcharge = fieldm*CHARGE;
460  g3helx3(fldcharge,STEP,VECT,VOUT);
461  }
462  else if (ifield==2) g3helix(CHARGE,STEP,VECT,VOUT);
463  else g3rkuta(CHARGE,STEP,VECT,VOUT);
464 }
465 
466 //______________________________________________________________________
467 void guview(Int_t&, Int_t&, DEFCHARD, Int_t& DEFCHARL)
468 {
469 //
470 // ******************************************************************
471 // * *
472 // * User routine for interactive version *
473 // * *
474 // * ==>Called by : <GXINT>, GINC1 *
475 // * *
476 // ******************************************************************
477 //
478 //
479 // ------------------------------------------------------------------
480 //
481 }
482 
483 //______________________________________________________________________
484 void gupara()
485 {
486 //
487 // ******************************************************************
488 // * *
489 // * User routine called every time a particle falls below *
490 // * parametrization threshold. This routine should create *
491 // * the parametrization stack, and, when this is full, *
492 // * parametrize the shower and track the geantinos. *
493 // * *
494 // * ==>Called by : GTRACK *
495 // * *
496 // ******************************************************************
497 //
498 //
499 // ------------------------------------------------------------------
500 //
501 }
502 
503 //______________________________________________________________________
504 Float_t gudtim(Float_t&, Float_t&, Int_t&, Int_t&)
505 {
506 //
507 // ******************************************************************
508 // * *
509 // * User function called by GCDRIF to return drift time *
510 // * *
511 // * ==>Called by : GCDRIF *
512 // * *
513 // ******************************************************************
514 //
515 //
516 // ------------------------------------------------------------------
517 //
518  return 0;
519 }
520 
521 
522 //______________________________________________________________________
523 Float_t guplsh(Int_t&, Int_t&)
524 {
525 //
526 // ******************************************************************
527 // * *
528 // * *
529 // * ==>Called by : GLISUR *
530 // * *
531 // ******************************************************************
532 //
533 //
534 // ------------------------------------------------------------------
535 //
536 //
537 //*** By default this defines perfect smoothness
538  return 1;
539 }
540 
541 //______________________________________________________________________
542 void gutrak()
543 {
544 //
545 // ******************************************************************
546 // * *
547 // * User routine to control tracking of one track *
548 // * *
549 // * ==>Called by : GTREVE *
550 // * *
551 // ******************************************************************
552 //
553 //
554 // ------------------------------------------------------------------
555 //
556  TVirtualMCApplication::Instance()->PreTrack();
557 
558  g3track();
559 
560  TVirtualMCApplication::Instance()->PostTrack();
561 }
562 
563 //______________________________________________________________________
564 void gutrev()
565 {
566 //
567 // ******************************************************************
568 // * *
569 // * User routine to control tracking of one event *
570 // * *
571 // * ==>Called by : GTRIG *
572 // * *
573 // ******************************************************************
574 //
575 //
576 // ------------------------------------------------------------------
577 //
578  gtreveroot();
579 }
580 
581 //______________________________________________________________________
582 #ifdef SINGLEFIELD
583 void gufld(Float_t *x, Float_t *b)
584 {
585  Double_t xdouble[3];
586  Double_t bdouble[3];
587  for (Int_t i=0; i<3; i++) xdouble[i] = x[i];
588 #else
589 void gufld(Double_t *xdouble, Double_t *bdouble)
590 {
591 #endif
592  if ( gMC->GetMagField() ) {
593  gMC->GetMagField()->Field(xdouble,bdouble);
594  }
595  else {
596  static Bool_t warn = true;
597  if (warn) {
598  Warning("gufld", "Using deprecated function TVirtualMCApplication::Field().");
599  Warning("gufld", "New TVirtualMagField interface should be used instead.");
600  warn = false;
601  }
602 
603  TVirtualMCApplication::Instance()->Field(xdouble,bdouble);
604  }
605 
606 #ifdef SINGLEFIELD
607  for (Int_t j=0; j<3; j++) b[j] = bdouble[j];
608 #endif
609 }
610 //______________________________________________________________________
611 void eustep(){
612 //
613 // ******************************************************************
614 // * *
615 // * User routine called at the end of each tracking step *
616 // * when using GEANE *
617 // ******************************************************************
618 
619  Int_t cflag;
620  static Int_t icc=0;
621  static Int_t icont=0;
622  Float_t dist2;
623  static Float_t prdist2;
624  Float_t d2x,d2y,d2z,amodd;
625 // clear icc when tracking starts
626  if(geant3->Gctrak()->sleng == 0) icc = 0;
627  cflag=geant3->Gcmore()->iclose;
628  if (geant3->Gcflag()->idebug * geant3->Gcflag()->iswit[2] != 0)geant3->Erxyzc();
629  if(cflag==1){
630 // distance between the track point and the point
631  if(icc==0) prdist2=geant3->Gconst()->big;
632  dist2 = (geant3->Gctrak()->vect[0] - geant3->Gcmore()->pfinal[0])*
633  (geant3->Gctrak()->vect[0] - geant3->Gcmore()->pfinal[0])+
634  (geant3->Gctrak()->vect[1] - geant3->Gcmore()->pfinal[1])*
635  (geant3->Gctrak()->vect[1] - geant3->Gcmore()->pfinal[1])+
636  (geant3->Gctrak()->vect[2] - geant3->Gcmore()->pfinal[2])*
637  (geant3->Gctrak()->vect[2] - geant3->Gcmore()->pfinal[2]);
638 
639  if((TMath::Sqrt(dist2)-TMath::Sqrt(prdist2)) < 1.e-3){
640  prdist2 = dist2;
641  icc = 1;
642  icont = 1;
643  geant3->Gcmore()->cleng[0] = geant3->Gcmore()->cleng[1];
644  geant3->Gcmore()->cleng[1] = geant3->Gcmore()->cleng[2];
645  geant3->Gcmore()->cleng[2] = geant3->Gctrak()->sleng;
646  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p1[i] = geant3->Gcmore()->p2[i]; //call ucopy(p2,p1,3)
647  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p2[i] = geant3->Gcmore()->p3[i]; //call ucopy(p3,p2,3)
648  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p3[i] = geant3->Gctrak()->vect[i]; //call ucopy(vect,p3,3)
649  }else{ // store the first point of increasing distance
650  if(icont == 1) {
651  geant3->Gcmore()->cleng[0] = geant3->Gcmore()->cleng[1];
652  geant3->Gcmore()->cleng[1] = geant3->Gcmore()->cleng[2];
653  geant3->Gcmore()->cleng[2] = geant3->Gctrak()->sleng;
654  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p1[i] = geant3->Gcmore()->p2[i]; //call ucopy(p2,p1,3)
655  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p2[i] = geant3->Gcmore()->p3[i]; //call ucopy(p3,p2,3)
656  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p3[i] = geant3->Gctrak()->vect[i]; //call ucopy(vect,p3,3)
657  icont = 0;
658  }
659  }
660  }else if(cflag==2) {
661  // printf("geant3->Gconst()->big = %F" ,geant3->Gconst());
662  if(icc == 0) prdist2=geant3->Gconst()->big;
663  d2x = (geant3->Gcmore()->wire2[1]-geant3->Gcmore()->wire1[1])*
664  (geant3->Gcmore()->wire1[2]-geant3->Gctrak()->vect[2])-
665  (geant3->Gcmore()->wire2[2]-geant3->Gcmore()->wire1[2])*
666  (geant3->Gcmore()->wire1[1]-geant3->Gctrak()->vect[1]);
667 
668  d2y = (geant3->Gcmore()->wire2[2]-geant3->Gcmore()->wire1[2])*
669  (geant3->Gcmore()->wire1[0]-geant3->Gctrak()->vect[0])-
670  (geant3->Gcmore()->wire2[0]-geant3->Gcmore()->wire1[0])*
671  (geant3->Gcmore()->wire1[2]-geant3->Gctrak()->vect[2]);
672 
673  d2z = (geant3->Gcmore()->wire2[0]-geant3->Gcmore()->wire1[0])*
674  (geant3->Gcmore()->wire1[1]-geant3->Gctrak()->vect[1])-
675  (geant3->Gcmore()->wire2[1]-geant3->Gcmore()->wire1[1])*
676  (geant3->Gcmore()->wire1[0]-geant3->Gctrak()->vect[0]);
677 
678  amodd =(geant3->Gcmore()->wire2[0]-geant3->Gcmore()->wire1[0])*
679  (geant3->Gcmore()->wire2[0]-geant3->Gcmore()->wire1[0])+
680  (geant3->Gcmore()->wire2[1]-geant3->Gcmore()->wire1[1])*
681  (geant3->Gcmore()->wire2[1]-geant3->Gcmore()->wire1[1])+
682  (geant3->Gcmore()->wire2[2]-geant3->Gcmore()->wire1[2])*
683  (geant3->Gcmore()->wire2[2]-geant3->Gcmore()->wire1[2]);
684 
685  dist2 = (d2x*d2x + d2y*d2y + d2z*d2z)/amodd;
686 
687 // distance between the track point and the wire
688  if((TMath::Sqrt(dist2)-TMath::Sqrt(prdist2)) < 1.e-3) {
689  prdist2 = dist2;
690  icc=1;
691  icont = 1;
692  geant3->Gcmore()->cleng[0] = geant3->Gcmore()->cleng[1];
693  geant3->Gcmore()->cleng[1] = geant3->Gcmore()->cleng[2];
694  geant3->Gcmore()->cleng[2] = geant3->Gctrak()->sleng;
695  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p1[i] = geant3->Gcmore()->p2[i]; //call ucopy(p2,p1,3)
696  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p2[i] = geant3->Gcmore()->p3[i]; //call ucopy(p3,p2,3)
697  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p3[i] = geant3->Gctrak()->vect[i]; //call ucopy(vect,p3,3)
698  }else{ // store the first point of increasing distance
699  if(icont == 1){
700  geant3->Gcmore()->cleng[0] = geant3->Gcmore()->cleng[1];
701  geant3->Gcmore()->cleng[1] = geant3->Gcmore()->cleng[2];
702  geant3->Gcmore()->cleng[2] = geant3->Gctrak()->sleng;
703  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p1[i] = geant3->Gcmore()->p2[i]; //call ucopy(p2,p1,3)
704  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p2[i] = geant3->Gcmore()->p3[i]; //call ucopy(p3,p2,3)
705  for(Int_t i=0; i<3; i++)geant3->Gcmore()->p3[i] = geant3->Gctrak()->vect[i]; //call ucopy(vect,p3,3)
706  icont = 0;
707  }
708  }
709  }
710 
711  // --- Particle leaving the setup ?
712  if (!gMC->IsTrackOut()) {
713  TVirtualMCApplication *app = TVirtualMCApplication::Instance();
714  app->GeaneStepping();
715  }
716 
717 }
718 //______________________________________________________________________
719 void gustep()
720 {
721 //
722 // ******************************************************************
723 // * *
724 // * User routine called at the end of each tracking step *
725 // * INWVOL is different from 0 when the track has reached *
726 // * a volume boundary *
727 // * ISTOP is different from 0 if the track has stopped *
728 // * *
729 // * ==>Called by : GTRACK *
730 // * *
731 // ******************************************************************
732 //
733  Int_t ipp, jk, nt;
734  Float_t polar[3]={0,0,0};
735  Float_t mom[3];
736  static TMCProcess pProc;
737 
738  TVirtualMCApplication *app = TVirtualMCApplication::Instance();
739  TVirtualMCStack* stack = gMC->GetStack();
740  // Stop particle if outside user defined tracking region
741  Double_t x, y, z, rmax;
742  geant3->TrackPosition(x,y,z);
743 
744 #if defined(COLLECT_TRACKS)
745  if (gMC->IsRootGeometrySupported()) {
746  Int_t nstep = geant3->Gctrak()->nstep;
747  Int_t cpdg = gMC->PDGFromId(geant3->Gckine()->ipart);
748  Bool_t isnew = kFALSE; // gMC->IsNewTrack() returns true just for new used indices
749  if (nstep==0) isnew = kTRUE;
750  Int_t cid = stack->GetCurrentTrackNumber();
751  Int_t mid = stack->GetCurrentParentTrackNumber();
752  Double_t tofg = geant3->Gctrak()->tofg;
753  //printf("id=%i mid=%i pdg=%i nstep=%i (%f,%f,%f)\n",cid,mid,cpdg,nstep,x,y,z);
754 
755  TVirtualGeoTrack *parent = 0;
756  if (mid>=0) {
757  parent = gGeoManager->GetTrackOfId(mid);
758  if (!parent) printf("Error: no parent track with id=%i\n",mid);
759  }
760  TVirtualGeoTrack *track;
761  if (isnew) {
762  if (parent) {
763  //printf("Adding daughter %i of %i\n",cid,mid);
764  track = parent->AddDaughter(cid, cpdg);
765  gGeoManager->SetCurrentTrack(track);
766  } else {
767  Int_t itrack = gGeoManager->AddTrack(cid, cpdg);
768  //printf("Added new primary %i\n",cid);
769  gGeoManager->SetCurrentTrack(itrack);
770  track = gGeoManager->GetCurrentTrack();
771  }
772  TDatabasePDG *pdgdb = TDatabasePDG::Instance();
773  if (pdgdb) {
774  TParticlePDG *part = pdgdb->GetParticle(cpdg);
775  if (part) {
776  track->SetName(part->GetName());
777  track->SetParticle(part);
778  }
779  }
780  } else {
781  track = gGeoManager->GetCurrentTrack();
782  }
783  Double_t xo,yo,zo,to;
784  Bool_t skippoint = kFALSE;
785  if (track->HasPoints()) {
786  track->GetLastPoint(xo,yo,zo,to);
787  Double_t rdist = TMath::Sqrt((xo-x)*(xo-x)+(yo-y)*(yo-y)+(zo-z)*(zo-z));
788  if (rdist<0.01) skippoint=kTRUE;
789  }
790  if (!skippoint) track->AddPoint(x,y,z,tofg);
791  }
792 #endif
793 
794  rmax = app->TrackingRmax();
795  if (x*x+y*y > rmax*rmax ||
796  TMath::Abs(z) > app->TrackingZmax()) {
797  gMC->StopTrack();
798  }
799 
800  // --- Add new created particles
801  if (gMC->NSecondaries() > 0) {
802  pProc=gMC->ProdProcess(0);
803  for (jk = 0; jk < geant3->Gcking()->ngkine; ++jk) {
804  ipp = Int_t (geant3->Gcking()->gkin[jk][4]+0.5);
805  // --- Skip neutrinos!
806  if (ipp != 4 || !(geant3->SkipNeutrinos())) {
807  geant3->SetTrack(1,stack->GetCurrentTrackNumber(),gMC->PDGFromId(ipp), geant3->Gcking()->gkin[jk],
808  geant3->Gckin3()->gpos[jk], polar,geant3->Gctrak()->tofg, pProc, nt, 1., 0);
809  }
810  }
811  }
812  // Cherenkov photons here
813  if ( geant3->Gckin2()->ngphot ) {
814  for (jk = 0; jk < geant3->Gckin2()->ngphot; ++jk) {
815  mom[0]=geant3->Gckin2()->xphot[jk][3]*geant3->Gckin2()->xphot[jk][6];
816  mom[1]=geant3->Gckin2()->xphot[jk][4]*geant3->Gckin2()->xphot[jk][6];
817  mom[2]=geant3->Gckin2()->xphot[jk][5]*geant3->Gckin2()->xphot[jk][6];
818  geant3->SetTrack(1, stack->GetCurrentTrackNumber(), gMC->PDGFromId(50),
819  mom, //momentum
820  geant3->Gckin2()->xphot[jk], //position
821  &geant3->Gckin2()->xphot[jk][7], //polarisation
822  geant3->Gckin2()->xphot[jk][10], //time of flight
823  kPCerenkov, nt, 1., 0);
824  }
825  }
826  // --- Particle leaving the setup ?
827  if (!gMC->IsTrackOut()) app->Stepping();
828 
829  // --- Standard GEANT debug routine
830  //g3pcxyz();
831  if(geant3->Gcflag()->idebug) geant3->Gdebug();
832 }
833 
834 //______________________________________________________________________
835 void gukine ()
836 {
837 //
838 // ******************************************************************
839 // * *
840 // * Read or Generates Kinematics for primary tracks *
841 // * *
842 // * ==>Called by : GTRIG *
843 // * *
844 // ******************************************************************
845 //
846 //
847 // ------------------------------------------------------------------
848 //
849 
850  TVirtualMCApplication::Instance()->GeneratePrimaries();
851 }
852 }
853 // end of extern "C"
Int_t iclose
Definition: TGeant3.h:352
Float_t xphot[MXPHOT][11]
Definition: TGeant3.h:196
void TrackPosition(TLorentzVector &xyz) const
Definition: TGeant3.cxx:2213
Int_t ngphot
Definition: TGeant3.h:195
Float_t pfinal[3]
Definition: TGeant3.h:353
#define gunear
Definition: TGeant3gu.cxx:23
#define DEFCHARD
Definition: TCallf77.h:9
#define g3tmedi
Definition: TGeant3gu.cxx:54
virtual Gctmed_t * Gctmed() const
Definition: TGeant3.h:823
Float_t gpos[MXGKIN][3]
Definition: TGeant3.h:202
#define g3rkuta
Definition: TGeant3gu.cxx:49
Float_t big
Definition: TGeant3.h:48
#define guview
Definition: TGeant3gu.cxx:25
#define g3tmany
Definition: TGeant3gu.cxx:56
#define gutrev
Definition: TGeant3gu.cxx:29
Float_t p2[3]
Definition: TGeant3.h:358
Int_t idebug
Definition: TGeant3.h:144
#define gukine
Definition: TGeant3gu.cxx:34
Float_t p3[3]
Definition: TGeant3.h:359
virtual Gckine_t * Gckine() const
Definition: TGeant3.h:821
Float_t p1[3]
Definition: TGeant3.h:357
#define gfmfin
Definition: TGeant3gu.cxx:43
#define g3tnext
Definition: TGeant3gu.cxx:57
virtual Gckin3_t * Gckin3() const
Definition: TGeant3.h:828
#define g3helx3
Definition: TGeant3gu.cxx:47
#define gutrak
Definition: TGeant3gu.cxx:30
Float_t wire2[3]
Definition: TGeant3.h:356
virtual Gcking_t * Gcking() const
Definition: TGeant3.h:826
#define gupara
Definition: TGeant3gu.cxx:26
#define guinti
Definition: TGeant3gu.cxx:22
#define guout
Definition: TGeant3gu.cxx:17
Int_t ihadr
Definition: TGeant3.h:433
Float_t cleng[3]
Definition: TGeant3.h:360
#define g3last
Definition: TGeant3gu.cxx:52
#define g3track
Definition: TGeant3gu.cxx:50
#define gpghei
Definition: TGeant3gu.cxx:44
#define guskip
Definition: TGeant3gu.cxx:24
Int_t nstep
Definition: TGeant3.h:254
#define g3media
Definition: TGeant3gu.cxx:55
#define gustep
Definition: TGeant3gu.cxx:33
double y
Bool_t SkipNeutrinos()
Definition: TGeant3.h:715
#define gtreveroot
Definition: TGeant3gu.cxx:51
virtual Gcmore_t * Gcmore() const
Definition: TGeant3.h:811
const double e
#define gudtim
Definition: TGeant3gu.cxx:27
Float_t sleng
Definition: TGeant3.h:259
Float_t vect[7]
Definition: TGeant3.h:247
#define guiget
Definition: TGeant3gu.cxx:20
virtual Gckin2_t * Gckin2() const
Definition: TGeant3.h:827
#define DEFCHARL
Definition: TCallf77.h:10
virtual Gconst_t * Gconst() const
Definition: TGeant3.h:841
Int_t ipart
Definition: TGeant3.h:168
#define gmedia
Definition: TGeant3gu.cxx:62
double z
Float_t tofg
Definition: TGeant3.h:263
virtual Gctrak_t * Gctrak() const
Definition: TGeant3.h:829
#define guinme
Definition: TGeant3gu.cxx:21
#define ginvol
Definition: TGeant3gu.cxx:58
#define gtnext
Definition: TGeant3gu.cxx:64
Int_t iswit[10]
Definition: TGeant3.h:153
#define guhadr
Definition: TGeant3gu.cxx:16
#define fldist
Definition: TGeant3gu.cxx:45
#define gheish
Definition: TGeant3gu.cxx:41
#define calsig
Definition: TGeant3gu.cxx:38
#define gfmdis
Definition: TGeant3gu.cxx:46
TGeant3 * geant3
Definition: TGeant3.cxx:1072
void SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom, Float_t *vpos, Float_t *polar, Float_t tof, TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
Definition: TGeant3.cxx:6338
virtual void Erxyzc()
Definition: TGeant3.cxx:5420
virtual Gcphys_t * Gcphys() const
Definition: TGeant3.h:824
#define gtmany
Definition: TGeant3gu.cxx:60
Int_t ifield
Definition: TGeant3.h:224
p
Definition: test.py:223
#define guplsh
Definition: TGeant3gu.cxx:28
Float_t fieldm
Definition: TGeant3.h:225
#define gudcay
Definition: TGeant3gu.cxx:19
#define guswim
Definition: TGeant3gu.cxx:31
virtual void Gdebug()
Definition: TGeant3.cxx:3720
#define gtmedi
Definition: TGeant3gu.cxx:59
#define gcalor
Definition: TGeant3gu.cxx:39
#define type_of_call
Definition: TCallf77.h:8
Float_t getot
Definition: TGeant3.h:248
#define gudigi
Definition: TGeant3gu.cxx:15
#define g3helix
Definition: TGeant3gu.cxx:48
#define gtonly
Definition: TGeant3gu.cxx:61
#define flufin
Definition: TGeant3gu.cxx:42
list x
Definition: train.py:276
Float_t gkin[MXGKIN][5]
Definition: TGeant3.h:186
#define guphad
Definition: TGeant3gu.cxx:18
#define gufld
Definition: TGeant3gu.cxx:32
Float_t wire1[3]
Definition: TGeant3.h:355
Float_t tofd[MXGKIN]
Definition: TGeant3.h:187
#define glvolu
Definition: TGeant3gu.cxx:63
Int_t ngkine
Definition: TGeant3.h:185
#define eustep
Definition: TGeant3gu.cxx:36
virtual Gcflag_t * Gcflag() const
Definition: TGeant3.h:822
#define g3invol
Definition: TGeant3gu.cxx:53