FairShip
Loading...
Searching...
No Matches
NtupleGenerator Class Reference

#include <NtupleGenerator.h>

Inheritance diagram for NtupleGenerator:
Collaboration diagram for NtupleGenerator:

Public Member Functions

 NtupleGenerator ()
 
 ~NtupleGenerator () override
 
Bool_t ReadEvent (FairPrimaryGenerator *) override
 
Bool_t Init (const char *, int) override
 
Bool_t Init (const char *) override
 
Int_t GetNevents ()
 
- Public Member Functions inherited from SHiP::Generator
 Generator ()
 
virtual ~Generator ()
 
virtual Bool_t Init (const char *, int)=0
 
virtual Bool_t Init (const char *)=0
 
virtual Bool_t Init (const std::vector< std::string > &inFiles, int startNumber)
 
virtual Bool_t Init (const std::vector< std::string > &inFiles)
 
virtual void UseExternalFile (std::string x, Int_t i)
 
virtual void UseExternalFile (std::vector< std::string > &inFiles, Int_t i)
 

Protected Attributes

Int_t id
 
Int_t Nmeas
 
Int_t volid [500]
 
Int_t procid [500]
 
Int_t parentid
 
Float_t Ezero
 
Float_t tof
 
Double_t w
 
Float_t px [500]
 
Float_t py [500]
 
Float_t pz [500]
 
Float_t vx [500]
 
Float_t vy [500]
 
Float_t vz [500]
 
TFile * fInputFile
 
TTree * fTree
 
FairLogger * fLogger
 
int fNevents
 don't make it persistent, magic ROOT command
 
int fn
 
- Protected Attributes inherited from SHiP::Generator
std::optional< std::string > fextFile
 
Int_t firstEvent = 0
 

Detailed Description

Definition at line 15 of file NtupleGenerator.h.

Constructor & Destructor Documentation

◆ NtupleGenerator()

NtupleGenerator::NtupleGenerator ( )

default constructor

Definition at line 20 of file NtupleGenerator.cxx.

20{}

◆ ~NtupleGenerator()

NtupleGenerator::~NtupleGenerator ( )
override

destructor

Definition at line 58 of file NtupleGenerator.cxx.

58 {
59 // cout << "destroy Ntuple" << endl;
60 fInputFile->Close();
61 fInputFile->Delete();
62 delete fInputFile;
63}

Member Function Documentation

◆ GetNevents()

Int_t NtupleGenerator::GetNevents ( )

Definition at line 106 of file NtupleGenerator.cxx.

106{ return fNevents; }
int fNevents
don't make it persistent, magic ROOT command

◆ Init() [1/2]

Bool_t NtupleGenerator::Init ( const char *  fileName)
overridevirtual

Implements SHiP::Generator.

Definition at line 23 of file NtupleGenerator.cxx.

23{ return Init(fileName, 0); }
Bool_t Init(const char *, int) override

◆ Init() [2/2]

Bool_t NtupleGenerator::Init ( const char *  fileName,
int  startEvent 
)
overridevirtual

Implements SHiP::Generator.

Definition at line 25 of file NtupleGenerator.cxx.

25 {
26 cout << "Info NtupleGenerator: Opening input file " << fileName << endl;
27 fInputFile = new TFile(fileName);
28 if (fInputFile->IsZombie()) {
29 cout << "-E NtupleGenerator: Error opening the Signal file" << fileName
30 << endl;
31 }
32 fTree = dynamic_cast<TTree*>(fInputFile->Get("ntuple"));
33 fNevents = fTree->GetEntries();
34 fn = startEvent;
35 fTree->SetBranchAddress("id", &id); // particle id
36 if (fTree->FindBranch("parentid")) {
37 fTree->SetBranchAddress("parentid", &parentid);
38 } // parent id
39 if (fTree->FindBranch("tof")) {
40 fTree->SetBranchAddress("tof", &tof);
41 } // time of flight
42 fTree->SetBranchAddress("Nmeas", &Nmeas); // number of Geant4 points
43 fTree->SetBranchAddress("Ezero", &Ezero); // incoming muon energy
44 fTree->SetBranchAddress("w", &w); // weight of event
45 fTree->SetBranchAddress("x", &vx); // position
46 fTree->SetBranchAddress("y", &vy);
47 fTree->SetBranchAddress("z", &vz);
48 fTree->SetBranchAddress("px", &px); // momentum
49 fTree->SetBranchAddress("py", &py);
50 fTree->SetBranchAddress("pz", &pz);
51 fTree->SetBranchAddress("volid", &volid); // which volume
52 fTree->SetBranchAddress("procid", &procid); // which process
53 return kTRUE;
54}
Float_t vz[500]
Float_t vy[500]
Float_t vx[500]
Float_t pz[500]
Int_t volid[500]
Int_t procid[500]
Float_t py[500]
Float_t px[500]

◆ ReadEvent()

Bool_t NtupleGenerator::ReadEvent ( FairPrimaryGenerator *  cpg)
override

Definition at line 67 of file NtupleGenerator.cxx.

67 {
68 while (fn < fNevents) {
69 fTree->GetEntry(fn);
70 fn++;
71 if (fn % 10000 == 0) {
72 cout << "reading event " << fn << endl;
73 }
74 // test if muon survives:
75 Int_t i = Nmeas - 3;
76 Float_t r2 = (vx[i] * vx[i] + vy[i] * vy[i]);
77 if (procid[Nmeas - 1] == 2 && r2 < 9) {
78 break;
79 }
80 }
81 if (fn == fNevents) {
82 cout << "No more input events" << endl;
83 return kFALSE;
84 }
85 TDatabasePDG* pdgBase = TDatabasePDG::Instance();
86 Double_t mass = pdgBase->GetParticle(id)->Mass();
87 Double_t e =
88 TMath::Sqrt(px[0] * px[0] + py[0] * py[0] + pz[0] * pz[0] + mass * mass);
89 tof = 0;
90 // first, original muon
91 cpg->AddTrack(id, px[0], py[0], pz[0], vx[0] * 100., vy[0] * 100.,
92 vz[0] * 100., -1., false, e, tof, w);
93 Int_t i = Nmeas - 1;
94 // second, surviving muon, extrapolate back to end of muon shield, z=20m
95 Double_t zscor = 20.;
96 Double_t lam = (zscor - vz[i]) / pz[i];
97 Double_t xscor = vx[i] + lam * px[i];
98 Double_t yscor = vy[i] + lam * py[i];
99 e = TMath::Sqrt(px[i] * px[i] + py[i] * py[i] + pz[i] * pz[i] + mass * mass);
100 cpg->AddTrack(id, px[i], py[i], pz[i], xscor * 100., yscor * 100.,
101 zscor * 100., 0, true, e, tof, w);
102 return kTRUE;
103}
int i
Definition: ShipAna.py:97
def mass(str|None particle)
Definition: hnl.py:54

Member Data Documentation

◆ Ezero

Float_t NtupleGenerator::Ezero
protected

Definition at line 33 of file NtupleGenerator.h.

◆ fInputFile

TFile* NtupleGenerator::fInputFile
protected

Definition at line 36 of file NtupleGenerator.h.

◆ fLogger

FairLogger* NtupleGenerator::fLogger
protected

Definition at line 38 of file NtupleGenerator.h.

◆ fn

int NtupleGenerator::fn
protected

Definition at line 40 of file NtupleGenerator.h.

◆ fNevents

int NtupleGenerator::fNevents
protected

don't make it persistent, magic ROOT command

Definition at line 39 of file NtupleGenerator.h.

◆ fTree

TTree* NtupleGenerator::fTree
protected

Definition at line 37 of file NtupleGenerator.h.

◆ id

Int_t NtupleGenerator::id
protected

Definition at line 32 of file NtupleGenerator.h.

◆ Nmeas

Int_t NtupleGenerator::Nmeas
protected

Definition at line 32 of file NtupleGenerator.h.

◆ parentid

Int_t NtupleGenerator::parentid
protected

Definition at line 32 of file NtupleGenerator.h.

◆ procid

Int_t NtupleGenerator::procid[500]
protected

Definition at line 32 of file NtupleGenerator.h.

◆ px

Float_t NtupleGenerator::px[500]
protected

Definition at line 35 of file NtupleGenerator.h.

◆ py

Float_t NtupleGenerator::py[500]
protected

Definition at line 35 of file NtupleGenerator.h.

◆ pz

Float_t NtupleGenerator::pz[500]
protected

Definition at line 35 of file NtupleGenerator.h.

◆ tof

Float_t NtupleGenerator::tof
protected

Definition at line 33 of file NtupleGenerator.h.

◆ volid

Int_t NtupleGenerator::volid[500]
protected

Definition at line 32 of file NtupleGenerator.h.

◆ vx

Float_t NtupleGenerator::vx[500]
protected

Definition at line 35 of file NtupleGenerator.h.

◆ vy

Float_t NtupleGenerator::vy[500]
protected

Definition at line 35 of file NtupleGenerator.h.

◆ vz

Float_t NtupleGenerator::vz[500]
protected

Definition at line 35 of file NtupleGenerator.h.

◆ w

Double_t NtupleGenerator::w
protected

Definition at line 34 of file NtupleGenerator.h.


The documentation for this class was generated from the following files: