Cerenkov photon update.
[u/mrichter/AliRoot.git] / TFluka / endraw.cxx
index 593c122..5c68002 100644 (file)
@@ -12,6 +12,7 @@
 #include "Ftrackr.h"  //(TRACKR) fluka common
 #include "Fltclcm.h"  //(LTCLCM) fluka common
 #include "Fpaprop.h"  //(PAPROP) fluka common
+#include "Fopphst.h"  //(OPPHST) fluka common
 
 #ifndef WIN32
 # define endraw endraw_
@@ -35,6 +36,11 @@ void endraw(Int_t& icode, Int_t& mreg, Double_t& rull, Double_t& xsco, Double_t&
   fluka->SetMreg(mreg, mlttc);
 
   Float_t edep = rull;
+  Int_t ipt = fluka->PDGFromId(TRACKR.jtrack);
+  if (ipt == -1) {
+      if (debug) printf("Unknown particle %5d %5d \n", TRACKR.jtrack, icode);
+      return;
+  }
   
   if (TRACKR.jtrack == -1) {
   // Handle quantum efficiency the G3 way
@@ -62,7 +68,7 @@ void endraw(Int_t& icode, Int_t& mreg, Double_t& rull, Double_t& xsco, Double_t&
     Int_t nodeId;
     Int_t volId = fluka->CurrentVolID(nodeId);
     Int_t crtlttc = gGeoManager->GetCurrentNodeId()+1;
-    if( mreg != volId  && !gGeoManager->IsOutside() ) {
+    if(debug && mreg != volId  && !gGeoManager->IsOutside() ) {
        cout << "  endraw:   track=" << TRACKR.ispusr[mkbmx2-1] << " pdg=" << fluka->PDGFromId(TRACKR.jtrack)
             << " icode=" << icode << " gNstep=" << fluka->GetNstep() << endl
             << "               fluka   mreg=" << mreg << " mlttc=" << mlttc << endl
@@ -74,36 +80,35 @@ void endraw(Int_t& icode, Int_t& mreg, Double_t& rull, Double_t& xsco, Double_t&
         if( mlttc == crtlttc ) cout << "   *************************************************************" << endl;
     }
     // *****************************************************
-
-
   if (icode != kEMFSCOstopping1 && icode != kEMFSCOstopping2) {
       fluka->SetIcode((FlukaProcessCode_t)icode);
       fluka->SetRull(edep);
       if (icode == kKASKADelarecoil && TRACKR.ispusr[mkbmx2-5]) {
-         //  Elastic recoil and in stuprf npprmr > 0,
-         //  the secondary being loaded is actually still the interacting particle
-         cppstack->SetCurrentTrack( TRACKR.ispusr[mkbmx2-4] );
-         //      cout << "endraw elastic recoil track=" << TRACKR.ispusr[mkbmx2-1] << " parent=" << TRACKR.ispusr[mkbmx2-4]
-         //           << endl;
-      }
-      else
+         //  Elastic recoil and in stuprf npprmr > 0,
+         //  the secondary being loaded is actually still the interacting particle
+         cppstack->SetCurrentTrack( TRACKR.ispusr[mkbmx2-4] );
+      } else if (TRACKR.jtrack == -1) {
+         cppstack->SetCurrentTrack(OPPHST.louopp[OPPHST.lstopp]);
+      } else {
           cppstack->SetCurrentTrack(TRACKR.ispusr[mkbmx2-1] );
+      }
+
       (TVirtualMCApplication::Instance())->Stepping();
+      
   } else {
   //
   // For icode 21,22 the particle has fallen below thresshold.
   // This has to be signalled to the StepManager() 
   //
       cppstack->SetCurrentTrack( TRACKR.ispusr[mkbmx2-1] );
+      
       fluka->SetRull(edep);
       fluka->SetIcode((FlukaProcessCode_t) icode);
       (TVirtualMCApplication::Instance())->Stepping();
       fluka->SetTrackIsNew(kFALSE);
-      fluka->SetIcode((FlukaProcessCode_t)icode);
-      fluka->SetRull(0.);
-      (TVirtualMCApplication::Instance())->Stepping();
-//      cppstack->SetCurrentTrack( saveTrackId );
-
+//      fluka->SetIcode((FlukaProcessCode_t)icode);
+//      fluka->SetRull(0.);
+//      (TVirtualMCApplication::Instance())->Stepping();
   }
 } // end of endraw
 } // end of extern "C"