Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions python/rootUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,30 @@ def errorSummary():
print("Summary of recorded incidents:")
for e in _error_log:
print(e, ':', _error_log[e])

def checkFileExists(x):
if x[0:4] == "/eos": f=gSystem.Getenv("EOSSHIP")+x
else: f=x
test = TFile.Open(f)
if not test:
print("input file",f," does not exist. Missing authentication?")
os._exit(1)
if test.FindObjectAny('cbmsim'):
return 'tree'

if isinstance(x, list):
print("I'm a list")
for _f in x:
if _f[0:4] == "/eos": f=gSystem.Getenv("EOSSHIP")+_f
else: f=_f
test = TFile.Open(f)
if not test:
print("input file",f," does not exist. Missing authentication?")
os._exit(1)
if test.FindObjectAny('cbmsim'):
return 'tree'
else:
return 'ntuple'
else:
return 'ntuple'
if x[0:4] == "/eos": f=gSystem.Getenv("EOSSHIP")+x
else: f=x
test = TFile.Open(f)
if not test:
print("input file",f," does not exist. Missing authentication?")
os._exit(1)
if test.FindObjectAny('cbmsim'):
return 'tree'
else:
return 'ntuple'
47 changes: 35 additions & 12 deletions shipgen/MuonBackGenerator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "FairPrimaryGenerator.h"
#include "ShipMCTrack.h"
#include "ShipUnit.h"
#include "TChain.h"
#include "TDatabasePDG.h" // for TDatabasePDG
#include "TFile.h"
#include "TMCProcess.h"
Expand All @@ -38,22 +39,33 @@ MuonBackGenerator::MuonBackGenerator()
Bool_t MuonBackGenerator::Init(const char* fileName) {
return Init(fileName, 0);
}
// ----- Default constructor -------------------------------------------
Bool_t MuonBackGenerator::Init(const char* fileName, const int firstEvent) {
LOG(info) << "Opening input file " << fileName;
fInputFile = TFile::Open(fileName);
if (!fInputFile) {
LOG(fatal) << "Error opening the Signal file: " << fileName;

Bool_t MuonBackGenerator::Init(std::vector<const char*> fileNames) {
return Init(fileNames, 0);
}

Bool_t MuonBackGenerator::Init(std::vector<const char*> fileNames,
const int firstEvent) {
LOG(info) << "Opening input file " << fileNames.at(0);
TFile testFile(fileNames.at(0));
auto testKeys = testFile.GetListOfKeys();
if (testKeys == nullptr) {
LOG(fatal) << "Error opening the Signal file: " << fileNames.at(0);
}
fn = firstEvent;
fPaintBeam = 5 * cm; // default value for painting beam
fSameSeed = 0;
fPhiRandomize = false; // default value for phi randomization
fsmearBeam = 8 * mm; // default value for smearing beam
fdownScaleDiMuon = kFALSE; // only needed for muflux simulation
fTree = fInputFile->Get<TTree>("pythia8-Geant4");
if (fTree) {
if (testKeys->FindObject("pythia8-Geant4")) {
fTree = new TChain("pythia8-Geant4");
for (auto& f : fileNames) {
LOG(info) << "Opening input file " << f;
static_cast<TChain*>(fTree)->Add(f);
}
fNevents = fTree->GetEntries();
LOG(info) << "Reading " << fNevents << " entries";
// count only events with muons
fTree->SetBranchAddress("id", &id); // particle id
fTree->SetBranchAddress("parentid",
Expand Down Expand Up @@ -82,9 +94,14 @@ Bool_t MuonBackGenerator::Init(const char* fileName, const int firstEvent) {
}
} else {
id = -1;
fTree = fInputFile->Get<TTree>("cbmsim");
// fTree = fInputFile->Get<TTree>("cbmsim");
fTree = new TChain("cbmsim");
for (auto& f : fileNames) {
LOG(info) << "Opening input file " << f;
static_cast<TChain*>(fTree)->Add(f);
}
fNevents = fTree->GetEntries();

LOG(info) << "Reading " << fNevents << " entries";
// Detect format by checking branch name:
// STL format uses PlaneHAPoint, TClonesArray uses vetoPoint
TBranch* mcBranch = fTree->GetBranch("MCTrack");
Expand Down Expand Up @@ -122,6 +139,12 @@ Bool_t MuonBackGenerator::Init(const char* fileName, const int firstEvent) {
}
return kTRUE;
}

// ----- Default constructor -------------------------------------------
Bool_t MuonBackGenerator::Init(const char* fileName, const int firstEvent) {
std::vector<const char*> fileNames = {fileName};
return Init(fileNames, firstEvent);
}
// ----- Destructor ----------------------------------------------------
MuonBackGenerator::~MuonBackGenerator() {
if (!fUseSTL) {
Expand Down Expand Up @@ -228,8 +251,8 @@ Bool_t MuonBackGenerator::ReadEvent(FairPrimaryGenerator* cpg) {
}
}
}
if (fn > fNevents - 1) {
LOGF(info, "End of file reached %i", fNevents);
if (fn == fNevents) {
LOGF(info, "End of tree reached %i", fNevents);
return kFALSE;
}
if (fSameSeed) {
Expand Down
11 changes: 7 additions & 4 deletions shipgen/MuonBackGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ class MuonBackGenerator : public FairGenerator {

/** public method ReadEvent **/
Bool_t ReadEvent(FairPrimaryGenerator*);
virtual Bool_t Init(const char*, int); //!
virtual Bool_t Init(const char*); //!
Int_t GetNevents(); //!
void CloseFile(); //!
virtual Bool_t Init(const char*, int); //!
virtual Bool_t Init(const char*); //!
virtual Bool_t Init(std::vector<const char*>, int); //!
virtual Bool_t Init(std::vector<const char*>); //!

Int_t GetNevents(); //!
void CloseFile(); //!
void FollowAllParticles() { followMuons = false; };
void SetSmearBeam(Double_t sb) { fsmearBeam = sb; };
void SetPaintRadius(Double_t r) { fPaintBeam = r; };
Expand Down