SND@LHC Software
Loading...
Searching...
No Matches
NtupleGenerator Class Reference

#include <NtupleGenerator.h>

Inheritance diagram for NtupleGenerator:
Collaboration diagram for NtupleGenerator:

Public Member Functions

 NtupleGenerator ()
 
virtual ~NtupleGenerator ()
 
Bool_t ReadEvent (FairPrimaryGenerator *)
 
virtual Bool_t Init (const char *, int)
 
virtual Bool_t Init (const char *)
 
Int_t GetNevents ()
 

Protected Member Functions

 ClassDef (NtupleGenerator, 1)
 

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
 

Detailed Description

Definition at line 11 of file NtupleGenerator.h.

Constructor & Destructor Documentation

◆ NtupleGenerator()

NtupleGenerator::NtupleGenerator ( )

default constructor

Definition at line 14 of file NtupleGenerator.cxx.

14{}

◆ ~NtupleGenerator()

NtupleGenerator::~NtupleGenerator ( )
virtual

destructor

Definition at line 50 of file NtupleGenerator.cxx.

51{
52 // cout << "destroy Ntuple" << endl;
53 fInputFile->Close();
54 fInputFile->Delete();
55 delete fInputFile;
56}

Member Function Documentation

◆ ClassDef()

NtupleGenerator::ClassDef ( NtupleGenerator  ,
 
)
protected

◆ GetNevents()

Int_t NtupleGenerator::GetNevents ( )

Definition at line 92 of file NtupleGenerator.cxx.

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

◆ Init() [1/2]

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

Definition at line 17 of file NtupleGenerator.cxx.

17 {
18 return Init(fileName, 0);
19}
virtual Bool_t Init(const char *, int)

◆ Init() [2/2]

Bool_t NtupleGenerator::Init ( const char *  fileName,
int  firstEvent 
)
virtual

Definition at line 21 of file NtupleGenerator.cxx.

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

◆ ReadEvent()

Bool_t NtupleGenerator::ReadEvent ( FairPrimaryGenerator *  cpg)

public method ReadEvent

Definition at line 60 of file NtupleGenerator.cxx.

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

Member Data Documentation

◆ Ezero

Float_t NtupleGenerator::Ezero
protected

Definition at line 30 of file NtupleGenerator.h.

◆ fInputFile

TFile* NtupleGenerator::fInputFile
protected

Definition at line 33 of file NtupleGenerator.h.

◆ fLogger

FairLogger* NtupleGenerator::fLogger
protected

Definition at line 35 of file NtupleGenerator.h.

◆ fn

int NtupleGenerator::fn
protected

Definition at line 37 of file NtupleGenerator.h.

◆ fNevents

int NtupleGenerator::fNevents
protected

don't make it persistent, magic ROOT command

Definition at line 36 of file NtupleGenerator.h.

◆ fTree

TTree* NtupleGenerator::fTree
protected

Definition at line 34 of file NtupleGenerator.h.

◆ id

Int_t NtupleGenerator::id
protected

Definition at line 29 of file NtupleGenerator.h.

◆ Nmeas

Int_t NtupleGenerator::Nmeas
protected

Definition at line 29 of file NtupleGenerator.h.

◆ parentid

Int_t NtupleGenerator::parentid
protected

Definition at line 29 of file NtupleGenerator.h.

◆ procid

Int_t NtupleGenerator::procid[500]
protected

Definition at line 29 of file NtupleGenerator.h.

◆ px

Float_t NtupleGenerator::px[500]
protected

Definition at line 32 of file NtupleGenerator.h.

◆ py

Float_t NtupleGenerator::py[500]
protected

Definition at line 32 of file NtupleGenerator.h.

◆ pz

Float_t NtupleGenerator::pz[500]
protected

Definition at line 32 of file NtupleGenerator.h.

◆ tof

Float_t NtupleGenerator::tof
protected

Definition at line 30 of file NtupleGenerator.h.

◆ volid

Int_t NtupleGenerator::volid[500]
protected

Definition at line 29 of file NtupleGenerator.h.

◆ vx

Float_t NtupleGenerator::vx[500]
protected

Definition at line 32 of file NtupleGenerator.h.

◆ vy

Float_t NtupleGenerator::vy[500]
protected

Definition at line 32 of file NtupleGenerator.h.

◆ vz

Float_t NtupleGenerator::vz[500]
protected

Definition at line 32 of file NtupleGenerator.h.

◆ w

Double_t NtupleGenerator::w
protected

Definition at line 31 of file NtupleGenerator.h.


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