<commit_before>#include <iostream>

#include "PureGenUtils.hxx"

#include "GeneratorSpecifics.hxx"

//******************************************************************************
//                     Generic
//******************************************************************************

Generator::Generator(){ generator = kInvalid; TreeName = ""; }
Generator::~Generator(){
  if(OutObjectInfo!=nullptr){
    delete OutObjectInfo;
  }
  if(StdHepP4!=nullptr){
    delete [] StdHepP4;
  }
}

void Generator::AddOutputBranches(TTree* tree, bool LiteOutput,
  bool MultiplyByGeVToMeV, Int_t NThresh, Int_t* Threshs_MeV){

  OutObjectInfo = (LiteOutput?
    new TransversityVarsB(MultiplyByGeVToMeV):
    new TransversityVars(MultiplyByGeVToMeV,
      NThresh, Threshs_MeV, GeneratorName));
  OutObjectInfo->AddBranches(tree);
  this->LiteOutput = LiteOutput;
}

void Generator::DoEvent(){
  OutObjectInfo->Reset();
  this->StartEvent();
  for(UInt_t partNum = 0; partNum < UInt_t(*StdHepN); ++partNum){
    this->HandleStdHepParticle(partNum, StdHepPdg[partNum],
      StdHepStatus[partNum], StdHepP4[partNum]);
  }
  this->Finalise();
}

void Generator::HandleStruckNucleon(Double_t *&StdHepP4, Int_t pdg){
  TLorentzVector StdHepPTLV = TLorentzVector(
    StdHepP4[kStdHepIdxPx],
    StdHepP4[kStdHepIdxPy],
    StdHepP4[kStdHepIdxPz],
    StdHepP4[kStdHepIdxE]);
  OutObjectInfo->HandleStruckNucleon(StdHepPTLV,pdg);
}

void Generator::Finalise(){
  OutObjectInfo->Finalise();
  //Fixes broken antineutrino codes.
  if( (OutObjectInfo->IncNeutrino_PDG < 0) &&
             (NeutConventionReactionCode > 0) ) {
    //want antinu codes to be < 0
    OutObjectInfo->NeutConventionReactionCode =
      (-1*NeutConventionReactionCode);
  } else {
    OutObjectInfo->NeutConventionReactionCode = NeutConventionReactionCode;
  }
}

//******************************************************************************
//                     NEUT
//******************************************************************************

void NEUT::Init(TTree* tree){
  StdHepN = &NStdHepN;
  StdHepPdg = NStdHepPdg;
  StdHepP4 = PGUtils::NewPPOf2DArray(NStdHepP4);
  StdHepStatus = NStdHepStatus;

  tree->SetBranchAddress("EvtCode", &NeutReacCode);
  tree->SetBranchAddress("StdHepN", &NStdHepN);
  tree->SetBranchAddress("StdHepPdg", NStdHepPdg);
  tree->SetBranchAddress("StdHepP4", NStdHepP4);
  tree->SetBranchAddress("StdHepStatus", NStdHepStatus);
}

void NEUT::StartEvent(){
  if(PGUtils::str2int(NeutConventionReactionCode, NeutReacCode->String().Data())
    != PGUtils::STRINT_SUCCESS){
    std::cout << "[WARN]: " << "Couldn't parse reaction code: " <<
      NeutReacCode->String() << std::endl;
  }
}

void NEUT::HandleStdHepParticle(
    UInt_t &StdHepPosition,
    Int_t &StdHepPdg,
    Int_t &StdHepStatus,
    Double_t * &StdHepP4){

  OutObjectInfo->HandleStdHepParticle(StdHepPosition,StdHepPdg,StdHepStatus,
    StdHepP4);

  if(StdHepStatus==11){
    Generator::HandleStruckNucleon(StdHepP4, StdHepPdg);
  }

}
//******************************************************************************
//                     GENIE
//******************************************************************************
void GENIE::Init(TTree* tree){
  StdHepN = &GStdHepN;
  StdHepPdg = GStdHepPdg;
  StdHepP4 = PGUtils::NewPPOf2DArray(GStdHepP4);
  StdHepStatus = GStdHepStatus;

  tree->SetBranchAddress("G2NeutEvtCode", &G2NeutEvtCode);
  tree->SetBranchAddress("StdHepN", &GStdHepN);
  tree->SetBranchAddress("StdHepPdg", GStdHepPdg);
  tree->SetBranchAddress("StdHepP4", GStdHepP4);
  tree->SetBranchAddress("StdHepStatus", GStdHepStatus);
  tree->SetBranchAddress("StdHepRescat", GStdHepRescat);
}

void GENIE::StartEvent(){
  NeutConventionReactionCode = G2NeutEvtCode;
  ProtonRescat_contains_NoInt = false;
  ProtonRescat_contains_chrgEx = false;
  ProtonRescat_contains_elastic = false;
  ProtonRescat_contains_inelastic = false;
  ProtonRescat_contains_knockout = false;
}

void GENIE::HandleStdHepParticle(
    UInt_t &StdHepPosition,
    Int_t &StdHepPdg,
    Int_t &StdHepStatus,
    Double_t * &StdHepP4){

  OutObjectInfo->HandleStdHepParticle(StdHepPosition,StdHepPdg,StdHepStatus,
    StdHepP4);

  if(StdHepStatus == 14 && !LiteOutput){
    HandleRescat(StdHepPdg, GStdHepRescat[StdHepPosition]);
  }

  if(StdHepStatus==11){
    Generator::HandleStruckNucleon(StdHepP4, StdHepPdg);
  }
}

void GENIE::HandleRescat(Int_t PDG, Int_t RescatCode){
  if(PDG == 2212){
    switch(RescatCode){
      case 1:{
        ProtonRescat_contains_NoInt = true;
        break;
      }
      case 2:{
        ProtonRescat_contains_chrgEx = true;
        break;
      }
      case 3:{
        ProtonRescat_contains_elastic = true;
        break;
      }
      case 4:{
        ProtonRescat_contains_inelastic = true;
        break;
      }
      case 5:{
        ProtonRescat_contains_knockout = true;
        break;
      }
    }
  }
}

void GENIE::AddOutputBranches(TTree* tree, bool LiteOutput,
    bool MultiplyByGeVToMeV, Int_t NThresh, Int_t* Threshs_Mev){
  Generator::AddOutputBranches(tree, LiteOutput, MultiplyByGeVToMeV,
    NThresh,Threshs_Mev);
  if(LiteOutput){
    tree->Branch("ProtonRescat_contains_NoInt",
      &ProtonRescat_contains_NoInt, "ProtonRescat_contains_NoInt/O");
    tree->Branch("ProtonRescat_contains_chrgEx",
      &ProtonRescat_contains_chrgEx, "ProtonRescat_contains_chrgEx/O");
    tree->Branch("ProtonRescat_contains_elastic",<commit_msg>Fixes bug where GENIE branches only added in Lite mode.<commit_after>#include <iostream>

#include "PureGenUtils.hxx"

#include "GeneratorSpecifics.hxx"

//******************************************************************************
//                     Generic
//******************************************************************************

Generator::Generator(){ generator = kInvalid; TreeName = ""; }
Generator::~Generator(){
  if(OutObjectInfo!=nullptr){
    delete OutObjectInfo;
  }
  if(StdHepP4!=nullptr){
    delete [] StdHepP4;
  }
}

void Generator::AddOutputBranches(TTree* tree, bool LiteOutput,
  bool MultiplyByGeVToMeV, Int_t NThresh, Int_t* Threshs_MeV){

  OutObjectInfo = (LiteOutput?
    new TransversityVarsB(MultiplyByGeVToMeV):
    new TransversityVars(MultiplyByGeVToMeV,
      NThresh, Threshs_MeV, GeneratorName));
  OutObjectInfo->AddBranches(tree);
  this->LiteOutput = LiteOutput;
}

void Generator::DoEvent(){
  OutObjectInfo->Reset();
  this->StartEvent();
  for(UInt_t partNum = 0; partNum < UInt_t(*StdHepN); ++partNum){
    this->HandleStdHepParticle(partNum, StdHepPdg[partNum],
      StdHepStatus[partNum], StdHepP4[partNum]);
  }
  this->Finalise();
}

void Generator::HandleStruckNucleon(Double_t *&StdHepP4, Int_t pdg){
  TLorentzVector StdHepPTLV = TLorentzVector(
    StdHepP4[kStdHepIdxPx],
    StdHepP4[kStdHepIdxPy],
    StdHepP4[kStdHepIdxPz],
    StdHepP4[kStdHepIdxE]);
  OutObjectInfo->HandleStruckNucleon(StdHepPTLV,pdg);
}

void Generator::Finalise(){
  OutObjectInfo->Finalise();
  //Fixes broken antineutrino codes.
  if( (OutObjectInfo->IncNeutrino_PDG < 0) &&
             (NeutConventionReactionCode > 0) ) {
    //want antinu codes to be < 0
    OutObjectInfo->NeutConventionReactionCode =
      (-1*NeutConventionReactionCode);
  } else {
    OutObjectInfo->NeutConventionReactionCode = NeutConventionReactionCode;
  }
}

//******************************************************************************
//                     NEUT
//******************************************************************************

void NEUT::Init(TTree* tree){
  StdHepN = &NStdHepN;
  StdHepPdg = NStdHepPdg;
  StdHepP4 = PGUtils::NewPPOf2DArray(NStdHepP4);
  StdHepStatus = NStdHepStatus;

  tree->SetBranchAddress("EvtCode", &NeutReacCode);
  tree->SetBranchAddress("StdHepN", &NStdHepN);
  tree->SetBranchAddress("StdHepPdg", NStdHepPdg);
  tree->SetBranchAddress("StdHepP4", NStdHepP4);
  tree->SetBranchAddress("StdHepStatus", NStdHepStatus);
}

void NEUT::StartEvent(){
  if(PGUtils::str2int(NeutConventionReactionCode, NeutReacCode->String().Data())
    != PGUtils::STRINT_SUCCESS){
    std::cout << "[WARN]: " << "Couldn't parse reaction code: " <<
      NeutReacCode->String() << std::endl;
  }
}

void NEUT::HandleStdHepParticle(
    UInt_t &StdHepPosition,
    Int_t &StdHepPdg,
    Int_t &StdHepStatus,
    Double_t * &StdHepP4){

  OutObjectInfo->HandleStdHepParticle(StdHepPosition,StdHepPdg,StdHepStatus,
    StdHepP4);

  if(StdHepStatus==11){
    Generator::HandleStruckNucleon(StdHepP4, StdHepPdg);
  }

}
//******************************************************************************
//                     GENIE
//******************************************************************************
void GENIE::Init(TTree* tree){
  StdHepN = &GStdHepN;
  StdHepPdg = GStdHepPdg;
  StdHepP4 = PGUtils::NewPPOf2DArray(GStdHepP4);
  StdHepStatus = GStdHepStatus;

  tree->SetBranchAddress("G2NeutEvtCode", &G2NeutEvtCode);
  tree->SetBranchAddress("StdHepN", &GStdHepN);
  tree->SetBranchAddress("StdHepPdg", GStdHepPdg);
  tree->SetBranchAddress("StdHepP4", GStdHepP4);
  tree->SetBranchAddress("StdHepStatus", GStdHepStatus);
  tree->SetBranchAddress("StdHepRescat", GStdHepRescat);
}

void GENIE::StartEvent(){
  NeutConventionReactionCode = G2NeutEvtCode;
  ProtonRescat_contains_NoInt = false;
  ProtonRescat_contains_chrgEx = false;
  ProtonRescat_contains_elastic = false;
  ProtonRescat_contains_inelastic = false;
  ProtonRescat_contains_knockout = false;
}

void GENIE::HandleStdHepParticle(
    UInt_t &StdHepPosition,
    Int_t &StdHepPdg,
    Int_t &StdHepStatus,
    Double_t * &StdHepP4){

  OutObjectInfo->HandleStdHepParticle(StdHepPosition,StdHepPdg,StdHepStatus,
    StdHepP4);

  if(StdHepStatus == 14 && !LiteOutput){
    HandleRescat(StdHepPdg, GStdHepRescat[StdHepPosition]);
  }

  if(StdHepStatus==11){
    Generator::HandleStruckNucleon(StdHepP4, StdHepPdg);
  }
}

void GENIE::HandleRescat(Int_t PDG, Int_t RescatCode){
  if(PDG == 2212){
    switch(RescatCode){
      case 1:{
        ProtonRescat_contains_NoInt = true;
        break;
      }
      case 2:{
        ProtonRescat_contains_chrgEx = true;
        break;
      }
      case 3:{
        ProtonRescat_contains_elastic = true;
        break;
      }
      case 4:{
        ProtonRescat_contains_inelastic = true;
        break;
      }
      case 5:{
        ProtonRescat_contains_knockout = true;
        break;
      }
    }
  }
}

void GENIE::AddOutputBranches(TTree* tree, bool LiteOutput,
    bool MultiplyByGeVToMeV, Int_t NThresh, Int_t* Threshs_Mev){
  Generator::AddOutputBranches(tree, LiteOutput, MultiplyByGeVToMeV,
    NThresh,Threshs_Mev);
  if(!LiteOutput){
    tree->Branch("ProtonRescat_contains_NoInt",
      &ProtonRescat_contains_NoInt, "ProtonRescat_contains_NoInt/O");
    tree->Branch("ProtonRescat_contains_chrgEx",
      &ProtonRescat_contains_chrgEx, "ProtonRescat_contains_chrgEx/O");
    tree->Branch("ProtonRescat_contains_elastic",
{'fraction_non_alphanumeric': 0.19677507515714676, 'fraction_numerical': 0.008745558895873189, 'mean_word_length': 4.880021424745581, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6185120', 'n_tokens_mistral': 4095, 'n_tokens_neox': 3736, 'n_words': 520}