SND@LHC Software
Loading...
Searching...
No Matches
ALPACAGenerator.cxx
Go to the documentation of this file.
1#include <math.h>
2#include "TROOT.h"
3#include "TFile.h"
4#include "FairPrimaryGenerator.h"
5#include "ALPACAGenerator.h"
6#include "TDatabasePDG.h" // for TDatabasePDG
7#include "TMath.h" // for Sqrt
8
9const Double_t cm = 10.; // pythia units are mm
10const Double_t c_light = 2.99792458e+10; // speed of light in cm/sec (c_light = 2.99792458e+8 * m/s)
11
12using std::cout;
13using std::endl;
14// read events from ntuples produced
15
16// ----- Default constructor -------------------------------------------
18// -------------------------------------------------------------------------
19// ----- Default constructor -------------------------------------------
20Bool_t ALPACAGenerator::Init(const char* fileName) {
21 return Init(fileName, 0);
22}
23// ----- Default constructor -------------------------------------------
24Bool_t ALPACAGenerator::Init(const char* fileName, const int firstEvent) {
25 cout << "Info ALPACAGenerator: Opening input file " << fileName << endl;
26 fInputFile = new TFile(fileName);
27 if (fInputFile->IsZombie()) {
28 cout << "-E ALPACAGenerator: Error opening the Signal file" << fileName << endl;
29 }
30 fTree = (TTree *)fInputFile->Get("MCTrack");
31 fNevents = fTree->GetEntries();
32 fn=firstEvent;
33 fTree->SetBranchAddress("event",&event); //event no.
34 fTree->SetBranchAddress("track",&track); //track no.
35 fTree->SetBranchAddress("pdg",&pdg); // particle pdg
36 fTree->SetBranchAddress("parent",&parent); // parent track number
37 fTree->SetBranchAddress("tof",&tof); // time of flight
38 fTree->SetBranchAddress("e",&e); // incoming muon energy
39 fTree->SetBranchAddress("w",&w); // weight of event
40 fTree->SetBranchAddress("x",&x); // position in x
41 fTree->SetBranchAddress("y",&y); // position in y
42 fTree->SetBranchAddress("z",&z); // position in z
43 fTree->SetBranchAddress("px",&px); // momentum in x
44 fTree->SetBranchAddress("py",&py); // momentum in y
45 fTree->SetBranchAddress("pz",&pz); // momentum in z
46 return kTRUE;
47}
48// -------------------------------------------------------------------------
49
50
51// ----- Destructor ----------------------------------------------------
53{
54 // cout << "destroy Ntuple" << endl;
55 fInputFile->Close();
56 fInputFile->Delete();
57 delete fInputFile;
58}
59// -------------------------------------------------------------------------
60
61// ----- Passing the event ---------------------------------------------
62Bool_t ALPACAGenerator::ReadEvent(FairPrimaryGenerator* cpg)
63{
64 if (fn<fNevents) {
65 fTree->GetEntry(fn); // ALP is getting,
66 if (track==0&&parent==-1) {
67 cpg->AddTrack(pdg,px,py,pz,x,y,z,-1.,false,e,tof,w); // ALP track is added.
68 }
69 fTree->GetEntry(fn+1); // First daughter/photon is getting,
70 if (track==1&&parent==0) {
71 cpg->AddTrack(pdg,px,py,pz,x,y,z,0,true,e,tof,w); // First daughter/photon track is added.
72 }
73 fTree->GetEntry(fn+2); // Second daughter/photon is getting,
74 if (track==2&&parent==0) {
75 cpg->AddTrack(pdg,px,py,pz,x,y,z,0,true,e,tof,w); // Second daughter/photon track is added.
76 }
77 else {
78 return kFALSE;
79 }
80 fn=fn+3; // Goes to next event, more specifically next ALP,
81 cout << "Event Number:"<<fn/3 <<endl; // this division is due to the fact that ntuple is recorded in track based and every event has three tracks.
82 return kTRUE;
83 }
84 else {
85 cout << "No more input events"<<endl;
86 return kFALSE;
87 }
88}
89
90
91// -------------------------------------------------------------------------
93{
94 return fNevents/3;
95}
96
97
const Double_t cm
const Double_t c_light
int fNevents
don't make it persistent, magic ROOT command
virtual Bool_t Init(const char *, int)
virtual ~ALPACAGenerator()
Bool_t ReadEvent(FairPrimaryGenerator *)
ClassImp(ecalContFact) ecalContFact