SND@LHC Software
Loading...
Searching...
No Matches
NtupleGenerator_FLUKA.cxx
Go to the documentation of this file.
1
#include <math.h>
2
#include "TROOT.h"
3
#include "TSystem.h"
4
#include "TFile.h"
5
#include "FairPrimaryGenerator.h"
6
#include "
NtupleGenerator_FLUKA.h
"
7
#include "FairLogger.h"
8
#include "FairMCEventHeader.h"
9
10
// read events from ntuples produced by FLUKA
11
12
// ----- Default constructor -------------------------------------------
13
NtupleGenerator_FLUKA::NtupleGenerator_FLUKA
() {}
14
// -------------------------------------------------------------------------
15
// ----- Default constructor -------------------------------------------
16
Bool_t
NtupleGenerator_FLUKA::Init
(
const
char
* fileName) {
17
return
Init
(fileName, 0);
18
}
19
// ----- Default constructor -------------------------------------------
20
Bool_t
NtupleGenerator_FLUKA::Init
(
const
char
* fileName,
const
int
firstEvent) {
21
TString fN =
""
;
22
if
(0 == strncmp(
"/eos"
,fileName,4) ) {
23
fN = gSystem->Getenv(
"EOSSHIP"
);
24
}
25
fN+=fileName;
26
fInputFile
= TFile::Open(fN);
27
if
(
fInputFile
->IsZombie()) {
28
LOG(FATAL) <<
"NtupleGenerator_FLUKA: Error opening the Signal file"
<< fN;
29
return
kFALSE;
30
}
31
LOG(INFO) <<
"NtupleGenerator_FLUKA: Opening input file "
<< fN;
32
33
fTree
= (TTree *)
fInputFile
->Get(
"nt"
);
34
35
fNevents
=
fTree
->GetEntries();
36
fn
= firstEvent;
37
primaries
= 0;
38
// Check the input TTree structure
39
if
(
fTree
->FindLeaf(
"primaries_"
) !=
nullptr
) {
40
fTree
->SetBranchAddress(
"primaries"
,&
primaries
);
41
}
42
else
{
43
fTree
->SetBranchAddress(
"run"
,&
runN
);
// run number
44
fTree
->SetBranchAddress(
"event"
,&
eventN
);
// event number
45
fTree
->SetBranchAddress(
"id"
,&
id
);
// particle id
46
fTree
->SetBranchAddress(
"generation"
,&
generation
);
// origin generation number
47
fTree
->SetBranchAddress(
"t"
,&
t
);
// time of flight
48
fTree
->SetBranchAddress(
"E"
,&
E
);
// incoming muon energy
49
fTree
->SetBranchAddress(
"w"
,&
w
);
// weight of event
50
fTree
->SetBranchAddress(
"x"
,&
x
);
// position
51
fTree
->SetBranchAddress(
"y"
,&
y
);
52
fTree
->SetBranchAddress(
"z"
,&
z
);
53
fTree
->SetBranchAddress(
"px"
,&
px
);
// momentum
54
fTree
->SetBranchAddress(
"py"
,&
py
);
55
fTree
->SetBranchAddress(
"pz"
,&
pz
);
56
}
57
return
kTRUE;
58
}
59
// -------------------------------------------------------------------------
60
61
62
// ----- Destructor ----------------------------------------------------
63
NtupleGenerator_FLUKA::~NtupleGenerator_FLUKA
()
64
{
65
// cout << "destroy Ntuple" << endl;
66
fInputFile
->Close();
67
fInputFile
->Delete();
68
delete
fInputFile
;
69
}
70
// -------------------------------------------------------------------------
71
72
// ----- Passing the event ---------------------------------------------
73
Bool_t
NtupleGenerator_FLUKA::ReadEvent
(FairPrimaryGenerator* cpg)
74
{
75
fTree
->GetEntry(
fn
);
76
fn
++;
77
if
(
fn
%10000==0) {LOG(INFO)<<
"reading event "
<<
fn
;}
78
if
(
fn
>
fNevents
) {
79
LOG(WARNING) <<
"No more input events"
;
80
return
kFALSE; }
81
/* Add all primary tracks in the event. Typically, muon bkg MC has single muon per event.
82
Several muon primaries per event exist in the multi-muon MC.
83
*/
84
if
(
fTree
->FindLeaf(
"primaries_"
) !=
nullptr
) {
85
int
nf =
primaries
->GetEntries();
86
for
(
int
i=0; i<nf; i++){
87
//casting
88
struct
PrimaryTrack
* primary =
dynamic_cast<
struct
PrimaryTrack
*
>
(
primaries
->AddrAt(i));
89
//convert time from ns to sec
90
cpg->AddTrack(
int
(primary->
id
),primary->
px
,primary->
py
,primary->
pz
,
91
primary->
x
,primary->
y
,primary->
z
-
SND_Z
,-1,
true
,primary->
E
,
92
primary->
t
/1E9,primary->
w
,(TMCProcess)primary->
generation
);
93
LOG(DEBUG) <<
"NtupleGenerator_FLUKA: add muon "
<< i <<
","
<< int(primary->
id
)
94
<<
","
<<primary->
px
<<
","
<<primary->
py
<<
","
<<primary->
pz
<<
","
<<primary->
x
95
<<
","
<<primary->
y
<<
","
<<primary->
z
-
SND_Z
<<
","
<<primary->
generation
96
<<
","
<<primary->
E
<<
","
<<primary->
t
<<
"ns,"
<<primary->
w
;
97
}
98
}
99
else
{
100
// convert time from ns to sec
101
cpg->AddTrack(
int
(
id
[0]),
px
[0],
py
[0],
pz
[0],
x
[0],
y
[0],
z
[0]-
SND_Z
,-1,
true
,
E
[0],
t
[0]/1E9,
w
[0],(TMCProcess)
generation
[0]);
102
LOG(DEBUG) <<
"NtupleGenerator_FLUKA: add muon "
<<
id
[0]<<
","
<<
px
[0]<<
","
<<
py
[0]<<
","
<<
pz
[0]<<
","
<<
x
[0]<<
","
<<
y
[0]<<
","
<<
z
[0]-
SND_Z
<<
","
<<
generation
[0]<<
","
<<
E
[0]<<
","
<<
t
[0]<<
"ns,"
<<
w
[0];
103
}
104
105
// Set the generation run and event numbers through the MC event header
106
FairMCEventHeader* header = cpg->GetEvent();
107
header->SetEventID(
int
(
eventN
));
108
header->SetRunID(
int
(
runN
));
109
110
return
kTRUE;
111
}
112
113
// -------------------------------------------------------------------------
114
Int_t
NtupleGenerator_FLUKA::GetNevents
()
115
{
116
return
fNevents
;
117
}
118
119
120
ClassImp
(
NtupleGenerator_FLUKA
)
NtupleGenerator_FLUKA.h
NtupleGenerator_FLUKA
Definition
NtupleGenerator_FLUKA.h:17
NtupleGenerator_FLUKA::pz
Double_t pz[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::py
Double_t py[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::t
Double_t t[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::fInputFile
TFile * fInputFile
Definition
NtupleGenerator_FLUKA.h:36
NtupleGenerator_FLUKA::px
Double_t px[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::w
Double_t w[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::~NtupleGenerator_FLUKA
virtual ~NtupleGenerator_FLUKA()
Definition
NtupleGenerator_FLUKA.cxx:63
NtupleGenerator_FLUKA::y
Double_t y[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::E
Double_t E[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::x
Double_t x[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::fNevents
int fNevents
Definition
NtupleGenerator_FLUKA.h:38
NtupleGenerator_FLUKA::GetNevents
Int_t GetNevents()
Definition
NtupleGenerator_FLUKA.cxx:114
NtupleGenerator_FLUKA::SND_Z
Double_t SND_Z
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::fTree
TTree * fTree
Definition
NtupleGenerator_FLUKA.h:37
NtupleGenerator_FLUKA::primaries
TClonesArray * primaries
Definition
NtupleGenerator_FLUKA.h:40
NtupleGenerator_FLUKA::generation
Double_t generation[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::runN
Double_t runN
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::NtupleGenerator_FLUKA
NtupleGenerator_FLUKA()
Definition
NtupleGenerator_FLUKA.cxx:13
NtupleGenerator_FLUKA::Init
virtual Bool_t Init(const char *, int)
Definition
NtupleGenerator_FLUKA.cxx:20
NtupleGenerator_FLUKA::z
Double_t z[1]
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::eventN
Double_t eventN
Definition
NtupleGenerator_FLUKA.h:35
NtupleGenerator_FLUKA::ReadEvent
Bool_t ReadEvent(FairPrimaryGenerator *)
Definition
NtupleGenerator_FLUKA.cxx:73
NtupleGenerator_FLUKA::fn
int fn
Definition
NtupleGenerator_FLUKA.h:39
ClassImp
ClassImp(ecalContFact) ecalContFact
Definition
ecalContFact.cxx:8
PrimaryTrack
Definition
NtupleGenerator_FLUKA.h:10
PrimaryTrack::px
Double_t px
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::E
Double_t E
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::x
Double_t x
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::pz
Double_t pz
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::id
Double_t id
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::t
Double_t t
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::generation
Double_t generation
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::y
Double_t y
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::py
Double_t py
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::w
Double_t w
Definition
NtupleGenerator_FLUKA.h:11
PrimaryTrack::z
Double_t z
Definition
NtupleGenerator_FLUKA.h:11
shipgen
NtupleGenerator_FLUKA.cxx
Generated by
1.9.8