ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtTPCFissionGenerator.cxx
Go to the documentation of this file.
2 
3 #include <TDatabasePDG.h>
4 #include <TFile.h>
5 #include <TObject.h>
6 #include <TTree.h>
7 
8 #include <cstdlib>
9 #include <iostream>
10 
11 constexpr auto cRED = "\033[1;31m";
12 constexpr auto cYELLOW = "\033[1;33m";
13 constexpr auto cNORMAL = "\033[0m";
14 constexpr auto cGREEN = "\033[1;32m";
15 
17  : fP1x(0.), fP1y(0.), fP1z(0.), fP2x(0.), fP2y(0.), fP2z(0.), fVx(0.), fVy(0.), fVz(0.)
18 {
19  // cout << "-W- AtTPCIonGenerator: "
20  // << " Please do not use the default constructor! " << endl;
21 }
22 
23 AtTPCFissionGenerator::AtTPCFissionGenerator(const char *name, TString simfile)
24  : fP1x(0.), fP1y(0.), fP1z(0.), fP2x(0.), fP2y(0.), fP2z(0.), fPDG(TDatabasePDG::Instance()), fVx(0.), fVy(0.),
25  fVz(0.)
26 {
27 
28  // INCL+ABLA file
29  // simfile ="240Cf.root";
30  TString dir = getenv("VMCWORKDIR");
31  TString simfilepath = dir + "/macro/Simulation/data/" + simfile;
32  auto *f = new TFile(simfilepath.Data()); // NOLINT (owned by root)
33  if (f->IsZombie()) {
34  std::cout << cRED << " AtTPCFissionGenerator: No simulation file found! Check VMCWORKDIR variable. Exiting... "
35  << cNORMAL << std::endl;
36  return;
37  } else
38  std::cout << cGREEN << " AtTPCFissionGenerator : Prototype geometry found in : " << simfilepath.Data() << cNORMAL
39  << std::endl;
40 
41  fTree = dynamic_cast<TTree *>(f->Get("tree101"));
42  Int_t nEvents = fTree->GetEntriesFast();
43  std::cout << " Number of events : " << nEvents << std::endl;
44  fTree->SetBranchAddress("Evnt", &Evnt);
45  fTree->SetBranchAddress("Ntrack", &Ntrack);
46  fTree->SetBranchAddress("Aout", Aout);
47  fTree->SetBranchAddress("Zout", Zout);
48  fTree->SetBranchAddress("fOutPx", fOutPx);
49  fTree->SetBranchAddress("fOutPy", fOutPy);
50  fTree->SetBranchAddress("fOutPz", fOutPz);
51 
52  event = 0;
53 
54  /* fFileNamebase = dir+"/macro/Simulation/database/ionlist.txt";
55  std::cout << " AtTPCFissionGenerator: Opening input file " << fFileNamebase << std::endl;
56  // Open first the file to register all new ions.
57  fInputFilebase = new std::ifstream(fFileNamebase);
58  if ( ! fInputFilebase->is_open() )
59  Fatal("AtTPCFissionGenerator","Cannot open input file.");
60 
61  std::cout << "AtTPCFissionGenerator: Looking for ions..." << std::endl;
62 
63  //Int_t nIons = RegisterIons();
64  //std::cout <<cYELLOW<< "AtTPCFissionGenerator: " << nIons << " ions registered."<<cNORMAL<< std::endl;*/
65 }
66 
68 
69 Bool_t AtTPCFissionGenerator::ReadEvent(FairPrimaryGenerator *primGen)
70 {
71 
72  fVx = 0., fVy = 0., fVz = 0.;
73  Double_t uma = 931.494028, mp = 938.272013, c = 29.972458;
74  Double_t px, py, pz;
75 
76  fTree->GetEntry(event);
77 
78  // Define event
79  /* Int_t I = 0;
80 
81  // Define track variables
82  Int_t iPid = -1;
83  Int_t ia1 = 12;
84  Int_t iz1 = 6;
85  Int_t pdgType=0;
86 
87  for(Int_t j=0;j<Ntrack;j++){
88 
89  ia1=Aout[j];
90  iz1=Zout[j];
91 
92  if(ia1>2 && iz1>2){
93  if ( iPid < 0 ) {
94  char ionName[20];
95  sprintf(ionName, "Ion_%d_%d", ia1, iz1);
96  TParticlePDG* part = fPDG->GetParticle(ionName);
97  if ( ! part ) {
98  std::cout << "AtTPCFissionGenerator::ReadEvent: Cannot find "
99  << ionName << " in database!" << std::endl;
100  //continue;
101  }
102  if(part) pdgType = part->PdgCode();
103  }
104  else pdgType = ia1; // "normal" particle
105 
106  px=(double)fOutPx[j];
107  py=(double)fOutPy[j];
108  pz=(double)fOutPz[j];
109 
110  primGen->AddTrack(pdgType, px, py, pz, fVx, fVy, fVz);
111 
112  }
113 
114  }*/
115 
116  std::cout << cRED << " Fission event : " << event << cNORMAL << std::endl;
117  event++;
118  return kTRUE;
119 }
120 
121 /*Int_t AtTPCFissionGenerator::RegisterIons() {
122 
123  Int_t nIons = 0;
124  Int_t eventId=1;
125  Double_t pBeam,b;
126 
127  // Define track variables to be read from file
128  Int_t iPid = -1;
129  Int_t A,Z,qq;
130 
131 
132  fIonMap.clear();
133 
134  *fInputFilebase>> Z >> A;
135 
136  while ( ! fInputFilebase->eof()) {
137 
138 
139  if ( fInputFilebase->eof() ) continue;
140 
141  char buffer[20];
142  sprintf(buffer, "Ion_%d_%d", A, Z);
143  TString ionName(buffer);
144 
145  FairIon* ion = new FairIon(ionName,Z,A,qq);
146  fIonMap[ionName] = ion;
147  nIons++;
148 
149  *fInputFilebase>> Z >> A;
150 
151  }//!
152 
153  FairRunSim* run = FairRunSim::Instance();
154  std::map<TString, FairIon*>::iterator mapIt;
155  for (mapIt=fIonMap.begin(); mapIt!=fIonMap.end(); mapIt++) {
156  FairIon* ion = (*mapIt).second;
157  run->AddNewIon(ion);
158 
159  }
160 
161  return nIons;
162 }*/
163 
cYELLOW
constexpr auto cYELLOW
Definition: AtTPCFissionGenerator.cxx:12
f
double(* f)(double t, const double *par)
Definition: lmcurve.cxx:21
ClassImp
ClassImp(AtFindVertex)
AtTPCFissionGenerator::AtTPCFissionGenerator
AtTPCFissionGenerator()
Definition: AtTPCFissionGenerator.cxx:16
AtTPCFissionGenerator
Definition: AtTPCFissionGenerator.h:21
cGREEN
constexpr auto cGREEN
Definition: AtTPCFissionGenerator.cxx:14
cRED
constexpr auto cRED
Definition: AtTPCFissionGenerator.cxx:11
AtTPCFissionGenerator::ReadEvent
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Definition: AtTPCFissionGenerator.cxx:69
AtTPCFissionGenerator::~AtTPCFissionGenerator
virtual ~AtTPCFissionGenerator()
cNORMAL
constexpr auto cNORMAL
Definition: AtTPCFissionGenerator.cxx:13
c
constexpr auto c
Definition: AtRadialChargeModel.cxx:20
AtTPCFissionGenerator.h