<commit_before>#include <Riostream.h>
#include "TVirtualMCApplication.h"
#include "TGeoMaterial.h"
#include "TGeoManager.h"
#include <TParticle.h>
#include "TFlukaCerenkov.h"

#include "TFluka.h"
#include "TFlukaCodes.h"

#include "Fdimpar.h"  //(DIMPAR) fluka include
#include "Ftrackr.h"  //(TRACKR) fluka common
#include "Fltclcm.h"  //(LTCLCM) fluka common
#include "Fpaprop.h"  //(PAPROP) fluka common

#ifndef WIN32
# define endraw endraw_
#else
# define endraw ENDRAW
#endif
extern "C" {
void endraw(Int_t& icode, Int_t& mreg, Double_t& rull, Double_t& xsco, Double_t& ysco, Double_t& zsco)
{
  TFluka* fluka = (TFluka*) gMC;
  // nothing to do if particle in dummy region
  if (mreg == fluka->GetDummyRegion()) return;
  Int_t verbosityLevel = fluka->GetVerbosityLevel();
  Bool_t debug = (verbosityLevel >= 3)? kTRUE : kFALSE;
  Int_t mlttc = (icode==kKASKADinelarecoil) ? TRACKR.lt2trk : TRACKR.lt1trk; //LTCLCM.mlatm1;
  fluka->SetCaller(kENDRAW);
  fluka->SetRull(rull);
  fluka->SetXsco(xsco);
  fluka->SetYsco(ysco);
  fluka->SetZsco(zsco);
  fluka->SetMreg(mreg, mlttc);

  Float_t edep = rull;
  
  if (TRACKR.jtrack == -1) {
  // Handle quantum efficiency the G3 way
      if (debug) printf("endraw: Cerenkov photon depositing energy: %d %e\n", mreg, rull);
      TGeoMaterial* material = (gGeoManager->GetCurrentVolume())->GetMaterial();
      TFlukaCerenkov*  cerenkov = dynamic_cast<TFlukaCerenkov*> (material->GetCerenkovProperties());
      if (cerenkov) {
          Double_t eff = (cerenkov->GetQuantumEfficiency(rull));
          if (gRandom->Rndm() > eff) {
              edep = 0.;
          }
      }
  }

  TVirtualMCStack* cppstack = fluka->GetStack();

  if (debug) {
     cout << "ENDRAW For icode=" << icode 
          << " track=" << TRACKR.ispusr[mkbmx2-1] << " pdg=" << fluka->PDGFromId(TRACKR.jtrack)
          << " edep="<< edep << " mreg=" << mreg << endl;
  }

    // check region lattice consistency (debug Ernesto)
    // *****************************************************
    Int_t nodeId;
    Int_t volId = fluka->CurrentVolID(nodeId);
    Int_t crtlttc = gGeoManager->GetCurrentNodeId()+1;
    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
            << "               TGeo   volId=" << volId << " crtlttc=" << crtlttc << endl
            << "     common TRACKR   lt1trk=" << TRACKR.lt1trk << " lt2trk=" << TRACKR.lt2trk << endl
            << "     common LTCLCM   newlat=" << LTCLCM.newlat << " mlatld=" <<  LTCLCM.mlatld << endl
            << "                     mlatm1=" << LTCLCM.mlatm1 << " mltsen=" <<  LTCLCM.mltsen << endl
            << "                     mltsm1=" << LTCLCM.mltsm1 << " mlattc=" << LTCLCM.mlattc << endl;
        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
          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 );

  }
} // end of endraw
} // end of extern "C"
<commit_msg>Protection against special particle types.<commit_after>#include <Riostream.h>
#include "TVirtualMCApplication.h"
#include "TGeoMaterial.h"
#include "TGeoManager.h"
#include <TParticle.h>
#include "TFlukaCerenkov.h"

#include "TFluka.h"
#include "TFlukaCodes.h"

#include "Fdimpar.h"  //(DIMPAR) fluka include
#include "Ftrackr.h"  //(TRACKR) fluka common
#include "Fltclcm.h"  //(LTCLCM) fluka common
#include "Fpaprop.h"  //(PAPROP) fluka common

#ifndef WIN32
# define endraw endraw_
#else
# define endraw ENDRAW
#endif
extern "C" {
void endraw(Int_t& icode, Int_t& mreg, Double_t& rull, Double_t& xsco, Double_t& ysco, Double_t& zsco)
{
  TFluka* fluka = (TFluka*) gMC;
  // nothing to do if particle in dummy region
  if (mreg == fluka->GetDummyRegion()) return;
  Int_t verbosityLevel = fluka->GetVerbosityLevel();
  Bool_t debug = (verbosityLevel >= 3)? kTRUE : kFALSE;
  Int_t mlttc = (icode==kKASKADinelarecoil) ? TRACKR.lt2trk : TRACKR.lt1trk; //LTCLCM.mlatm1;
  fluka->SetCaller(kENDRAW);
  fluka->SetRull(rull);
  fluka->SetXsco(xsco);
  fluka->SetYsco(ysco);
  fluka->SetZsco(zsco);
  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
      if (debug) printf("endraw: Cerenkov photon depositing energy: %d %e\n", mreg, rull);
      TGeoMaterial* material = (gGeoManager->GetCurrentVolume())->GetMaterial();
      TFlukaCerenkov*  cerenkov = dynamic_cast<TFlukaCerenkov*> (material->GetCerenkovProperties());
      if (cerenkov) {
          Double_t eff = (cerenkov->GetQuantumEfficiency(rull));
          if (gRandom->Rndm() > eff) {
              edep = 0.;
          }
      }
  }

  TVirtualMCStack* cppstack = fluka->GetStack();

  if (debug) {
     cout << "ENDRAW For icode=" << icode 
          << " track=" << TRACKR.ispusr[mkbmx2-1] << " pdg=" << fluka->PDGFromId(TRACKR.jtrack)
          << " edep="<< edep << " mreg=" << mreg << endl;
  }

    // check region lattice consistency (debug Ernesto)
    // *****************************************************
    Int_t nodeId;
    Int_t volId = fluka->CurrentVolID(nodeId);
    Int_t crtlttc = gGeoManager->GetCurrentNodeId()+1;
    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
            << "               TGeo   volId=" << volId << " crtlttc=" << crtlttc << endl
            << "     common TRACKR   lt1trk=" << TRACKR.lt1trk << " lt2trk=" << TRACKR.lt2trk << endl
            << "     common LTCLCM   newlat=" << LTCLCM.newlat << " mlatld=" <<  LTCLCM.mlatld << endl
            << "                     mlatm1=" << LTCLCM.mlatm1 << " mltsen=" <<  LTCLCM.mltsen << endl
            << "                     mltsm1=" << LTCLCM.mltsm1 << " mlattc=" << LTCLCM.mlattc << endl;
        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] );
      } else {
          cppstack->SetCurrentTrack(TRACKR.ispusr[mkbmx2-1] );
      }

      if (TRACKR.jtrack != 308 && TRACKR.jtrack != 211) (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();
  }
} // end of endraw
} // end of extern "C"

{'fraction_non_alphanumeric': 0.1903114186851211, 'fraction_numerical': 0.00993414443576292, 'mean_word_length': 2.9541041482789057, 'pattern_counts': {'":': 0, '<': 227, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3345520', 'n_tokens_mistral': 3402, 'n_tokens_neox': 3287, 'n_words': 628}