Corrections for synchronisation of TFluka and FLUKA particle info during transport:
[u/mrichter/AliRoot.git] / TFluka / endraw.cxx
1 #include <Riostream.h>
2 #include "TVirtualMCApplication.h"
3 #include "TGeoMaterial.h"
4 #include "TGeoManager.h"
5 #include <TParticle.h>
6 #include "TFlukaCerenkov.h"
7
8 #include "TFluka.h"
9 #include "TFlukaCodes.h"
10
11 #include "Fdimpar.h"  //(DIMPAR) fluka include
12 #include "Ftrackr.h"  //(TRACKR) fluka common
13 #include "Fltclcm.h"  //(LTCLCM) fluka common
14 #include "Fpaprop.h"  //(PAPROP) fluka common
15
16 #ifndef WIN32
17 # define endraw endraw_
18 #else
19 # define endraw ENDRAW
20 #endif
21 extern "C" {
22 void endraw(Int_t& icode, Int_t& mreg, Double_t& rull, Double_t& xsco, Double_t& ysco, Double_t& zsco)
23 {
24   TFluka* fluka = (TFluka*) gMC;
25   // nothing to do if particle in dummy region
26   if (mreg == fluka->GetDummyRegion()) return;
27   Int_t verbosityLevel = fluka->GetVerbosityLevel();
28   Bool_t debug = (verbosityLevel >= 3)? kTRUE : kFALSE;
29   Int_t mlttc = LTCLCM.mlatm1;
30   fluka->SetCaller(kENDRAW);
31   fluka->SetRull(rull);
32   fluka->SetXsco(xsco);
33   fluka->SetYsco(ysco);
34   fluka->SetZsco(zsco);
35   fluka->SetMreg(mreg, mlttc);
36   
37   Float_t edep = rull;
38   
39   if (TRACKR.jtrack == -1) {
40   // Handle quantum efficiency the G3 way
41       if (debug) printf("endraw: Cerenkov photon depositing energy: %d %e\n", mreg, rull);
42       TGeoMaterial* material = (gGeoManager->GetCurrentVolume())->GetMaterial();
43       TFlukaCerenkov*  cerenkov = dynamic_cast<TFlukaCerenkov*> (material->GetCerenkovProperties());
44       if (cerenkov) {
45           Double_t eff = (cerenkov->GetQuantumEfficiency(rull));
46           if (gRandom->Rndm() > eff) {
47               edep = 0.;
48           }
49       }
50   }
51
52   TVirtualMCStack* cppstack = fluka->GetStack();
53   Int_t saveTrackId = cppstack->GetCurrentTrackNumber();
54
55   if (debug) {
56      cout << "ENDRAW For icode=" << icode << " stacktrack=" << saveTrackId
57           << " track=" << TRACKR.ispusr[mkbmx2-1] << " pdg=" << fluka->PDGFromId(TRACKR.jtrack)
58           << " edep="<< edep <<endl;
59   }
60
61   if (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2) {
62       fluka->SetIcode((FlukaProcessCode_t)icode);
63       fluka->SetRull(edep);
64       if (icode == kKASKADelarecoil && TRACKR.ispusr[mkbmx2-5]) {
65           //  Elastic recoil and in stuprf npprmr > 0,
66           //  the secondary being loaded is actually still the interacting particle
67           cppstack->SetCurrentTrack( TRACKR.ispusr[mkbmx2-4] );
68           //      cout << "endraw elastic recoil track=" << TRACKR.ispusr[mkbmx2-1] << " parent=" << TRACKR.ispusr[mkbmx2-4]
69           //           << endl;
70       }
71       else
72           cppstack->SetCurrentTrack(TRACKR.ispusr[mkbmx2-1] );
73       (TVirtualMCApplication::Instance())->Stepping();
74       
75 //      cppstack->SetCurrentTrack( saveTrackId );
76   } else {
77   //
78   // For icode 21,22 the particle has fallen below thresshold.
79   // This has to be signalled to the StepManager() 
80   //
81       cppstack->SetCurrentTrack( TRACKR.ispusr[mkbmx2-1] );
82       fluka->SetRull(edep);
83       fluka->SetIcode((FlukaProcessCode_t) icode);
84       (TVirtualMCApplication::Instance())->Stepping();
85       fluka->SetTrackIsNew(kFALSE);
86       fluka->SetIcode((FlukaProcessCode_t)icode);
87       fluka->SetRull(0.);
88       (TVirtualMCApplication::Instance())->Stepping();
89 //      cppstack->SetCurrentTrack( saveTrackId );
90
91   }
92 } // end of endraw
93 } // end of extern "C"
94