<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  Particles stack class                                                    //
//  Implements the TMCVirtualStack of the Virtual Monte Carlo                //
//  Holds the particles transported during simulation                        //
//  Is used to compare results of reconstruction with simulation             //
//  Author A.Morsch                                                          //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

 
#include <TClonesArray.h>
#include <TObjArray.h>
#include <TPDGCode.h>
#include <TMCProcess.h>
#include <TParticle.h>
#include <TParticlePDG.h>
#include <TDatabasePDG.h>
#include <TTree.h>
#include <TDirectory.h>

#include "AliLog.h"
#include "AliStack.h"
#include "AliMiscConstants.h"


ClassImp(AliStack)


const Char_t* AliStack::fgkEmbedPathsKey = "embeddingBKGPaths";

//_______________________________________________________________________
AliStack::AliStack():
  fParticles("TParticle", 1000),
  fParticleMap(),
  fParticleFileMap(0),
  fParticleBuffer(0),
  fCurrentTrack(0),
  fTreeK(0),
  fNtrack(0),
  fNprimary(0),
  fCurrent(-1),
  fCurrentPrimary(-1),
  fHgwmk(0),
  fLoadPoint(0),
  fTrackLabelMap(0),
  fMCEmbeddingFlag(kFALSE)
{
  //
  // Default constructor
  //
}

//_______________________________________________________________________
AliStack::AliStack(Int_t size, const char* /*evfoldname*/):
  fParticles("TParticle",1000),
  fParticleMap(size),
  fParticleFileMap(0),
  fParticleBuffer(0),
  fCurrentTrack(0),
  fTreeK(0),
  fNtrack(0),
  fNprimary(0),
  fNtransported(0),
  fCurrent(-1),
  fCurrentPrimary(-1),
  fHgwmk(0),
  fLoadPoint(0),
  fTrackLabelMap(0),
  fMCEmbeddingFlag(kFALSE)
{
  //
  //  Constructor
  //
}

//_______________________________________________________________________
AliStack::AliStack(const AliStack& st):
    TVirtualMCStack(st),
    fParticles("TParticle",1000),
    fParticleMap(*(st.Particles())),
    fParticleFileMap(st.fParticleFileMap),
    fParticleBuffer(0),
    fCurrentTrack(0),
    fTreeK((TTree*)(st.fTreeK->Clone())),
    fNtrack(st.GetNtrack()),
    fNprimary(st.GetNprimary()),
    fNtransported(st.GetNtransported()),
    fCurrent(-1),
    fCurrentPrimary(-1),
    fHgwmk(0),
    fLoadPoint(0),
    fTrackLabelMap(0),
    fMCEmbeddingFlag(kFALSE)
{
    // Copy constructor
}


//_______________________________________________________________________
void AliStack::Copy(TObject&) const
{
  AliFatal("Not implemented!");
}

//_______________________________________________________________________
AliStack::~AliStack()
{
  //
  // Destructor
  //
  
    fParticles.Clear();
}

//
// public methods
//

//_____________________________________________________________________________
void AliStack::PushTrack(Int_t done, Int_t parent, Int_t pdg, const Float_t *pmom,
                        const Float_t *vpos, const Float_t *polar, Float_t tof,
                        TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
{ 
  //
  // Load a track on the stack
  //
  // done     1 if the track has to be transported
  //          0 if not
  // parent   identifier of the parent track. -1 for a primary
  // pdg    particle code
  // pmom     momentum GeV/c
  // vpos     position 
  // polar    polarisation 
  // tof      time of flight in seconds
  // mecha    production mechanism
  // ntr      on output the number of the track stored
  //

  //  const Float_t tlife=0;
  
  //
  // Here we get the static mass
  // For MC is ok, but a more sophisticated method could be necessary
  // if the calculated mass is required
  // also, this method is potentially dangerous if the mass
  // used in the MC is not the same of the PDG database
  //
    TParticlePDG* pmc =  TDatabasePDG::Instance()->GetParticle(pdg);
    if (pmc) {
	Float_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
	Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
			      pmom[1]*pmom[1]+pmom[2]*pmom[2]);
	
//    printf("Loading  mass %f ene %f No %d ip %d parent %d done %d pos %f %f %f mom %f %f %f kS %d m \n",
//	   mass,e,fNtrack,pdg,parent,done,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS);
  

	PushTrack(done, parent, pdg, pmom[0], pmom[1], pmom[2], e,
		 vpos[0], vpos[1], vpos[2], tof, polar[0], polar[1], polar[2],
		 mech, ntr, weight, is);
    } else {
	AliWarning(Form("Particle type %d not defined in PDG Database !", pdg));
	AliWarning("Particle skipped !");
    }
}

//_____________________________________________________________________________
void AliStack::PushTrack(Int_t done, Int_t parent, Int_t pdg,
  	              Double_t px, Double_t py, Double_t pz, Double_t e,
  		      Double_t vx, Double_t vy, Double_t vz, Double_t tof,
		      Double_t polx, Double_t poly, Double_t polz,
		      TMCProcess mech, Int_t &ntr, Double_t weight, Int_t is)
{ 
  //
  // Load a track on the stack
  //
  // done        1 if the track has to be transported
  //             0 if not
  // parent      identifier of the parent track. -1 for a primary
  // pdg         particle code
  // kS          generation status code
  // px, py, pz  momentum GeV/c
  // vx, vy, vz  position 
  // polar       polarisation 
  // tof         time of flight in seconds
  // mech        production mechanism
  // ntr         on output the number of the track stored
  //    
  // New method interface: 
  // arguments were changed to be in correspondence with TParticle<commit_msg>Fix: Stack::PushTrack must assign ntr<0 when rejecting particle<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id$ */

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
//  Particles stack class                                                    //
//  Implements the TMCVirtualStack of the Virtual Monte Carlo                //
//  Holds the particles transported during simulation                        //
//  Is used to compare results of reconstruction with simulation             //
//  Author A.Morsch                                                          //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

 
#include <TClonesArray.h>
#include <TObjArray.h>
#include <TPDGCode.h>
#include <TMCProcess.h>
#include <TParticle.h>
#include <TParticlePDG.h>
#include <TDatabasePDG.h>
#include <TTree.h>
#include <TDirectory.h>

#include "AliLog.h"
#include "AliStack.h"
#include "AliMiscConstants.h"


ClassImp(AliStack)


const Char_t* AliStack::fgkEmbedPathsKey = "embeddingBKGPaths";

//_______________________________________________________________________
AliStack::AliStack():
  fParticles("TParticle", 1000),
  fParticleMap(),
  fParticleFileMap(0),
  fParticleBuffer(0),
  fCurrentTrack(0),
  fTreeK(0),
  fNtrack(0),
  fNprimary(0),
  fCurrent(-1),
  fCurrentPrimary(-1),
  fHgwmk(0),
  fLoadPoint(0),
  fTrackLabelMap(0),
  fMCEmbeddingFlag(kFALSE)
{
  //
  // Default constructor
  //
}

//_______________________________________________________________________
AliStack::AliStack(Int_t size, const char* /*evfoldname*/):
  fParticles("TParticle",1000),
  fParticleMap(size),
  fParticleFileMap(0),
  fParticleBuffer(0),
  fCurrentTrack(0),
  fTreeK(0),
  fNtrack(0),
  fNprimary(0),
  fNtransported(0),
  fCurrent(-1),
  fCurrentPrimary(-1),
  fHgwmk(0),
  fLoadPoint(0),
  fTrackLabelMap(0),
  fMCEmbeddingFlag(kFALSE)
{
  //
  //  Constructor
  //
}

//_______________________________________________________________________
AliStack::AliStack(const AliStack& st):
    TVirtualMCStack(st),
    fParticles("TParticle",1000),
    fParticleMap(*(st.Particles())),
    fParticleFileMap(st.fParticleFileMap),
    fParticleBuffer(0),
    fCurrentTrack(0),
    fTreeK((TTree*)(st.fTreeK->Clone())),
    fNtrack(st.GetNtrack()),
    fNprimary(st.GetNprimary()),
    fNtransported(st.GetNtransported()),
    fCurrent(-1),
    fCurrentPrimary(-1),
    fHgwmk(0),
    fLoadPoint(0),
    fTrackLabelMap(0),
    fMCEmbeddingFlag(kFALSE)
{
    // Copy constructor
}


//_______________________________________________________________________
void AliStack::Copy(TObject&) const
{
  AliFatal("Not implemented!");
}

//_______________________________________________________________________
AliStack::~AliStack()
{
  //
  // Destructor
  //
  
    fParticles.Clear();
}

//
// public methods
//

//_____________________________________________________________________________
void AliStack::PushTrack(Int_t done, Int_t parent, Int_t pdg, const Float_t *pmom,
                        const Float_t *vpos, const Float_t *polar, Float_t tof,
                        TMCProcess mech, Int_t &ntr, Float_t weight, Int_t is)
{ 
  //
  // Load a track on the stack
  //
  // done     1 if the track has to be transported
  //          0 if not
  // parent   identifier of the parent track. -1 for a primary
  // pdg    particle code
  // pmom     momentum GeV/c
  // vpos     position 
  // polar    polarisation 
  // tof      time of flight in seconds
  // mecha    production mechanism
  // ntr      on output the number of the track stored
  //

  //  const Float_t tlife=0;
  
  //
  // Here we get the static mass
  // For MC is ok, but a more sophisticated method could be necessary
  // if the calculated mass is required
  // also, this method is potentially dangerous if the mass
  // used in the MC is not the same of the PDG database
  //
    TParticlePDG* pmc =  TDatabasePDG::Instance()->GetParticle(pdg);
    if (pmc) {
	Float_t mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
	Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
			      pmom[1]*pmom[1]+pmom[2]*pmom[2]);
	
//    printf("Loading  mass %f ene %f No %d ip %d parent %d done %d pos %f %f %f mom %f %f %f kS %d m \n",
//	   mass,e,fNtrack,pdg,parent,done,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],kS);
  

	PushTrack(done, parent, pdg, pmom[0], pmom[1], pmom[2], e,
		 vpos[0], vpos[1], vpos[2], tof, polar[0], polar[1], polar[2],
		 mech, ntr, weight, is);
    } else {
	AliWarning(Form("Particle type %d not defined in PDG Database !", pdg));
	AliWarning("Particle skipped !");
	ntr = -1;
    }
}

//_____________________________________________________________________________
void AliStack::PushTrack(Int_t done, Int_t parent, Int_t pdg,
  	              Double_t px, Double_t py, Double_t pz, Double_t e,
  		      Double_t vx, Double_t vy, Double_t vz, Double_t tof,
		      Double_t polx, Double_t poly, Double_t polz,
		      TMCProcess mech, Int_t &ntr, Double_t weight, Int_t is)
{ 
  //
  // Load a track on the stack
  //
  // done        1 if the track has to be transported
  //             0 if not
  // parent      identifier of the parent track. -1 for a primary
  // pdg         particle code
  // kS          generation status code
  // px, py, pz  momentum GeV/c
  // vx, vy, vz  position 
  // polar       polarisation 
  // tof         time of flight in seconds
  // mech        production mechanism
  // ntr         on output the number of the track stored
  //    
  // New method interface: 
  // arguments were changed to be in correspondence with TParticle
{'fraction_non_alphanumeric': 0.14829791927064187, 'fraction_numerical': 0.011616792882876259, 'mean_word_length': 2.2439780586692106, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5753261', 'n_tokens_mistral': 3996, 'n_tokens_neox': 3862, 'n_words': 1070}