Skip to content

Commit

Permalink
Bunch of files for LF production with trigger on nuclei after trasport
Browse files Browse the repository at this point in the history
  • Loading branch information
fprino committed May 31, 2021
1 parent 0fc3224 commit 78fd624
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 3 deletions.
63 changes: 63 additions & 0 deletions MC/CustomGenerators/PWGLF/ReadKine.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#if !defined(__CINT__) || defined(__MAKECINT__)
#include <Riostream.h>
#include <AliRun.h>
#include <TParticle.h>
#include <TString.h>
#include <TTree.h>
#include <TArrayF.h>
#include <AliStack.h>
#include <AliRunLoader.h>
#include <TMath.h>
#include <AliHeader.h>
#include <AliGenEventHeader.h>
#include <TH1F.h>
#include <TNtuple.h>
#include <TFile.h>
#include <AliESD.h>
#include <AliESDVertex.h>
#endif

void ReadKine()
{
if (gAlice)
{
delete gAlice;
gAlice = 0x0;
}

AliRunLoader *rl = AliRunLoader::Open("galice.root");
if (rl == 0x0)
{
std::cerr << "Can not open session" << std::endl;
return;
}

rl->LoadHeader();
rl->LoadKinematics();
Int_t nev = rl->GetNumberOfEvents();
int codes[4] = {AliPID::ParticleCode(AliPID::kDeuteron), AliPID::ParticleCode(AliPID::kTriton), AliPID::ParticleCode(AliPID::kHe3), AliPID::ParticleCode(AliPID::kAlpha)};
for (Int_t iev = 0; iev < nev; iev++)
{
rl->GetEvent(iev);
AliStack *stack = rl->Stack();
TArrayF mcVertex(3);
rl->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
TTree *treek = (TTree *)rl->TreeK();
Int_t entries = (Int_t)treek->GetEntries();
printf("Number of particles = %d\n", entries);
for (Int_t i = 0; i < entries; i++)
{
TParticle *part = (TParticle *)stack->Particle(i);
Int_t pdgCode = part->GetPdgCode();
for (int iC = 0; iC < 4; ++iC) {
if (pdgCode == codes[iC]) {
if (stack->IsSecondaryFromMaterial(i)) {
printf("Particle with pdg=%d FOUND IN KINE TREE\n",pdgCode);
exit(EXIT_SUCCESS);
}
}
}
}
}
exit(EXIT_FAILURE);
}
94 changes: 94 additions & 0 deletions MC/Digitize.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* AliDPG - ALICE Experiment Data Preparation Group
* Simulation steering script
*
*/

/*****************************************************************/
/*****************************************************************/
/*****************************************************************/

#if (!defined(__CLING__) && !defined(__CINT__)) || defined(__ROOTCLING__) || defined(__ROOTCINT__)
#include "TSystem.h"
#include "TROOT.h"
#include "AliSimulation.h"
#endif

#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
#include "SimulationConfig.C"
#endif

void Digitize()
{

// number of events configuration
Int_t nev = 200;
if (gSystem->Getenv("CONFIG_NEVENTS"))
nev = atoi(gSystem->Getenv("CONFIG_NEVENTS"));

#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
// in root5 the ROOT_VERSION_CODE is defined only in ACLic mode
#else
gROOT->LoadMacro("$ALIDPG_ROOT/MC/SimulationConfig.C");
#endif

// simulation configuration
ESimulation_t simulationConfig = kSimulationDefault;
if (gSystem->Getenv("CONFIG_SIMULATION")) {
Bool_t valid = kFALSE;
for (Int_t isim = 0; isim < kNSimulations; isim++)
if (strcmp(gSystem->Getenv("CONFIG_SIMULATION"), SimulationName[isim]) == 0) {
simulationConfig = (ESimulation_t) isim;
valid = kTRUE;
break;
}
if (!valid) {
printf(">>>>> Unknown simulation configuration: %s \n", gSystem->Getenv("CONFIG_SIMULATION"));
abort();
}
}

/* initialisation */
Int_t error;
TString config_macro = "$ALIDPG_ROOT/MC/Config.C";
if (gROOT->LoadMacro(Form("%s/Config.C", gSystem->pwd()), &error, kTRUE) == 0) {
printf(">>>>> Config.C macro detected in CWD, using that one \n");
config_macro = Form("%s/Config.C", gSystem->pwd());
}
gROOT->LoadMacro("$ALIDPG_ROOT/MC/Config_LoadLibraries.C");
gROOT->ProcessLine("Config_LoadLibraries();");

AliGeomManager::LoadGeometry("geometry.root");
AliRunLoader* rl = AliRunLoader::Open("galice.root");
rl->LoadgAlice();
AliRunLoader::Instance()->CdGAFile();
gAlice->InitLoaders();
AliRunLoader::Instance()->LoadKinematics();
AliRunLoader::Instance()->LoadTrackRefs();
AliRunLoader::Instance()->LoadHits();


AliSimulation sim(config_macro.Data());
/* configuration */
SimulationConfig(sim, simulationConfig);

AliCDBManager::Instance()->SetSnapshotMode("OCDBsim.root");
AliCDBManager::Instance()->SetRun(atoi(gSystem->Getenv("CONFIG_RUN")));
AliGRPManager grpM;
grpM.ReadGRPEntry();
grpM.SetMagField();

sim.SetRunGeneration(false);
sim.SetRunSimulation(false);
sim.Run(nev);


// TString sdig = "TRD TOF PHOS HMPID EMCAL MUON ZDC PMD T0 VZERO FMD AD";
// TString h2dig = "ITS TPC";
// sim.RunSDigitization(sdig.Data());
// sim.RunDigitization("ALL", h2dig.Data());
// sim.RunHitsDigitization(h2dig.Data());
// sim.RunTrigger();
// sim.RunHLT();
}

74 changes: 74 additions & 0 deletions MC/Generate.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* AliDPG - ALICE Experiment Data Preparation Group
* Simulation steering script
*
*/

/*****************************************************************/
/*****************************************************************/
/*****************************************************************/

#if (!defined(__CLING__) && !defined(__CINT__)) || defined(__ROOTCLING__) || defined(__ROOTCINT__)
#include "TSystem.h"
#include "TROOT.h"
#include "AliSimulation.h"
#endif

#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
#include "SimulationConfig.C"
#endif

void Generate()
{

// number of events configuration
Int_t nev = 200;
if (gSystem->Getenv("CONFIG_NEVENTS"))
nev = atoi(gSystem->Getenv("CONFIG_NEVENTS"));

#if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
// in root5 the ROOT_VERSION_CODE is defined only in ACLic mode
#else
gROOT->LoadMacro("$ALIDPG_ROOT/MC/SimulationConfig.C");
#endif

// simulation configuration
ESimulation_t simulationConfig = kSimulationDefault;
if (gSystem->Getenv("CONFIG_SIMULATION")) {
Bool_t valid = kFALSE;
for (Int_t isim = 0; isim < kNSimulations; isim++)
if (strcmp(gSystem->Getenv("CONFIG_SIMULATION"), SimulationName[isim]) == 0) {
simulationConfig = (ESimulation_t) isim;
valid = kTRUE;
break;
}
if (!valid) {
printf(">>>>> Unknown simulation configuration: %s \n", gSystem->Getenv("CONFIG_SIMULATION"));
abort();
}
}

/* initialisation */
Int_t error;
TString config_macro = "$ALIDPG_ROOT/MC/Config.C";
if (gROOT->LoadMacro(Form("%s/Config.C", gSystem->pwd()), &error, kTRUE) == 0) {
printf(">>>>> Config.C macro detected in CWD, using that one \n");
config_macro = Form("%s/Config.C", gSystem->pwd());
}
gROOT->LoadMacro("$ALIDPG_ROOT/MC/Config_LoadLibraries.C");
gROOT->ProcessLine("Config_LoadLibraries();");
AliSimulation sim(config_macro.Data());

/* configuration */
SimulationConfig(sim, simulationConfig);

/* run generation */
sim.SetMakeSDigits("");
sim.SetMakeDigits("");
sim.SetMakeDigitsFromHits("");
sim.SetWriteRawData("");
sim.SetRunHLT("");
sim.Run(nev);

}

62 changes: 59 additions & 3 deletions MC/dpgsim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function COMMAND_HELP(){
echo "--nbkg <numberOfEvents> Number of background events to be generated in the simulation stag in MC-to-MC embedding mode"
echo "--quenching <quenching> Switch on quenching for Pythia: --quenching 1"
echo "--qhat <qhat> Modify qhat for Pythia: --quenching qhat (default = 1.7)"
echo "--selectevents <macro> Macro to select events after generation+transport"
echo ""
echo "Detector, simulation, reconstruction and other settings:"
echo "--detector <detectorConfig> tag name of the detector configuration, as defined in MC/DetectorConfig.C"
Expand Down Expand Up @@ -221,6 +222,7 @@ CONFIG_PTTRIGMIN=""
CONFIG_PTTRIGMAX=""
CONFIG_QUENCHING=""
CONFIG_QHAT=""
CONFIG_SELEVMACRO=""
CONFIG_RUN=""
CONFIG_UID="1"
CONFIG_SIMULATION=""
Expand Down Expand Up @@ -420,6 +422,10 @@ while [ ! -z "$1" ]; do
CONFIG_QHAT="$1"
export CONFIG_QHAT
shift
elif [ "$option" = "--selectevents" ]; then
CONFIG_SELEVMACRO="$1"
export CONFIG_SELEVMACRO
shift
elif [ "$option" = "--nevents" ]; then
CONFIG_NEVENTS="$1"
export CONFIG_NEVENTS
Expand Down Expand Up @@ -930,6 +936,7 @@ echo "pT-trigger min... $CONFIG_PTTRIGMIN"
echo "pT-trigger max... $CONFIG_PTTRIGMAX"
echo "quenching........ $CONFIG_QUENCHING"
echo "q-hat............ $CONFIG_QHAT"
echo "select events ... $CONFIG_SELEVMACRO"
echo "============================================"
echo "Debug mode....... $CONFIG_DEBUG"
echo "============================================"
Expand Down Expand Up @@ -969,6 +976,14 @@ if [[ $CONFIG_MODE == *"sim"* ]] || [[ $CONFIG_MODE == *"full"* ]]; then
if [ -f sim.C ]; then
SIMC=sim.C
fi
GENC=$ALIDPG_ROOT/MC/Generate.C
if [ -f Generate.C ]; then
GENC=Generate.C
fi
DIGC=$ALIDPG_ROOT/MC/Digitize.C
if [ -f Digitize.C ]; then
DIGC=Digitize.C
fi

# embedding using already generated background
if [[ $CONFIG_BACKGROUND == *galice.root ]]; then
Expand Down Expand Up @@ -1014,13 +1029,54 @@ if [[ $CONFIG_MODE == *"sim"* ]] || [[ $CONFIG_MODE == *"full"* ]]; then

fi

runcommand "SIMULATION" $SIMC sim.log 5
mv -f syswatch.log simwatch.log

if [[ $CONFIG_SELEVMACRO != "" ]]; then
# case in which we use a trigger macro to select events after generation+propagation
jtry=0
while true
do
echo "TRIAL" $jtry
runcommand "SIMULATION" $GENC sim.log 5
mv -f syswatch.log simwatch.log


echo -e "\n"
echo -e "\n" >&2

echo "* EVENT SELECTION : $CONFIG_SELEVMACRO"
echo "* EVENT SELECTION : output log in tag.log"
echo "* EVENT SELECTION : $CONFIG_SELEVMACRO" >&2
echo "* EVENT SELECTION : output log in tag.log" >&2

time aliroot -b -q -x $CONFIG_SELEVMACRO > tag.log 2>&1
exitcode=$?
isthere="$(grep "FOUND IN KINE TREE" tag.log)"
echo $isthere
echo "exitcode" $exitcode
if [ $exitcode -eq 0 ]; then
echo "Requested particle found -> run digitization"
break
else
echo "Requested particle not found -> generate another event"
rm *.Hits.root galice.root Kinematics.root TrackRefs.root geometry.root sim.log
jtry=$((jtry+1))
CONFIG_SEED=$(($CONFIG_SEED+1))
echo "New seed" $CONFIG_SEED
fi
done

runcommand "DIGITIZATION" $DIGC dig.log 5
mv -f syswatch.log digwatch.log

else
runcommand "SIMULATION" $SIMC sim.log 5
mv -f syswatch.log simwatch.log
fi

runBenchmark

fi


### rec.C

if [[ $CONFIG_MODE == *"rec"* ]] || [[ $CONFIG_MODE == *"full"* ]]; then
Expand Down

0 comments on commit 78fd624

Please sign in to comment.