ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtTPCFissionGeneratorV2.cxx
Go to the documentation of this file.
2 
3 #include "AtVertexPropagator.h"
4 
5 #include <FairIon.h>
6 #include <FairPrimaryGenerator.h>
7 #include <FairRunSim.h>
8 
9 #include <TDatabasePDG.h>
10 #include <TFile.h>
11 #include <TObject.h> // for TObject
12 #include <TParticlePDG.h>
13 #include <TTree.h>
14 
15 #include <algorithm>
16 #include <cstdio>
17 #include <cstdlib>
18 #include <iostream>
19 #include <map>
20 #include <utility>
21 
22 constexpr auto cRED = "\033[1;31m";
23 constexpr auto cYELLOW = "\033[1;33m";
24 constexpr auto cNORMAL = "\033[0m";
25 constexpr auto cGREEN = "\033[1;32m";
26 
27 Int_t AtTPCFissionGeneratorV2::fgNIon = 0;
28 
30  : fP1x(0.), fP1y(0.), fP1z(0.), fP2x(0.), fP2y(0.), fP2z(0.), fVx(0.), fVy(0.), fVz(0.)
31 {
32  // cout << "-W- AtTPCIonGenerator: "
33  // << " Please do not use the default constructor! " << endl;
34 }
35 
36 // ----- Default constructor ------------------------------------------
37 AtTPCFissionGeneratorV2::AtTPCFissionGeneratorV2(const char *name, TString simfile)
38  : fP1x(0.), fP1y(0.), fP1z(0.), fP2x(0.), fP2y(0.), fP2z(0.), fVx(0.), fVy(0.), fVz(0.)
39 {
40 
41  TString dir = getenv("VMCWORKDIR");
42  TString fFileNamebase;
43  std::map<TString, FairIon *> fIonMap;
44 
45  fFileNamebase = dir + "/macro/Simulation/database/ionlist.txt";
46  std::cout << " AtTPCFissionGenerator: Opening input file " << fFileNamebase << std::endl;
47  // Open first the file to register all new ions.
48  std::ifstream fInputFilebase(fFileNamebase);
49  if (!fInputFilebase.is_open())
50  Fatal("AtTPCFissionGenerator", "Cannot open input file.");
51 
52  std::cout << "AtTPCFissionGenerator: Looking for ions..." << std::endl;
53 
54  Int_t nIons = 0;
55  Int_t eventId = 1;
56  Double_t pBeam, b;
57 
58  // Define track variables to be read from file
59  Int_t iPid = -1;
60  Int_t A, Z, qq = 0;
61 
62  fIonMap.clear();
63 
64  fInputFilebase >> Z >> A;
65 
66  while (!fInputFilebase.eof()) {
67 
68  if (fInputFilebase.eof())
69  continue;
70 
71  char buffer[40];
72  sprintf(buffer, "Ion_%d_%d", A, Z);
73  TString ionName(buffer);
74 
75  auto *ion = new FairIon(ionName, Z, A, qq); // NOLINT (I think the run takes ownership of this memory?)
76  fIonMap[ionName] = ion;
77  nIons++;
78 
79  fInputFilebase >> Z >> A;
80 
81  }
82 
83  FairRunSim *run = FairRunSim::Instance();
84  std::map<TString, FairIon *>::iterator mapIt;
85  for (mapIt = fIonMap.begin(); mapIt != fIonMap.end(); mapIt++) {
86  FairIon *ion = (*mapIt).second;
87  run->AddNewIon(ion);
88  }
89 
90  std::cout << cYELLOW << "AtTPCFissionGenerator: " << nIons << " ions registered." << cNORMAL << std::endl;
91 
92  TString simfilepath = dir + "/macro/Simulation/data/" + simfile;
93  auto *f = new TFile(simfilepath.Data()); // NOLINT (belongs to ROOT)
94  if (f->IsZombie()) {
95  std::cout << cRED << " AtTPCFissionGenerator: No simulation file found! Check VMCWORKDIR variable. Exiting... "
96  << cNORMAL << std::endl;
97  return;
98  } else
99  std::cout << cGREEN << " AtTPCFissionGenerator : Prototype geometry found in : " << simfilepath.Data() << cNORMAL
100  << std::endl;
101 
102  auto *fTree = dynamic_cast<TTree *>(f->Get("tree101"));
103  Int_t nEvents = fTree->GetEntriesFast();
104  std::cout << " Number of events : " << nEvents << std::endl;
105  fTree->SetBranchAddress("Evnt", &Evnt);
106  fTree->SetBranchAddress("Ntrack", &Ntrack);
107  fTree->SetBranchAddress("Aout", Aout);
108  fTree->SetBranchAddress("Zout", Zout);
109  fTree->SetBranchAddress("fOutPx", fOutPx);
110  fTree->SetBranchAddress("fOutPy", fOutPy);
111  fTree->SetBranchAddress("fOutPz", fOutPz);
112  pTree.push_back(fTree);
113 
114  event = 0;
115 }
116 
117 // ----- Public method ReadEvent --------------------------------------
118 Bool_t AtTPCFissionGeneratorV2::ReadEvent(FairPrimaryGenerator *primGen)
119 {
120 
121  fVx = 0., fVy = 0., fVz = 0.;
122  Double_t uma = 931.494028, mp = 938.272013, c = 29.972458;
123  Double_t px, py, pz;
124 
125  TDatabasePDG *fPDG = TDatabasePDG::Instance();
126 
127  pTree.at(0)->GetEntry(event);
128 
129  // fIsDecay = kFALSE;
130 
131  // fBeamEnergy = gAtVP->GetEnergy();
132  // std::cout<<" -I- AtTPC2Body Residual energy : "<<gAtVP->GetEnergy()<<std::endl;
133 
134  // fPxBeam = gAtVP->GetPx();
135  // fPyBeam = gAtVP->GetPy();
136  // fPzBeam = gAtVP->GetPz();
137 
138  // gAtVP->SetRecoilE(Ene.at(1));
139  // gAtVP->SetRecoilA(Ang.at(1)*180.0/TMath::Pi());
140  // gAtVP->SetScatterE(Ene.at(0));
141  // gAtVP->SetScatterA(Ang.at(0)*180.0/TMath::Pi());
142 
143  // Propagate the vertex of the previous event
144 
145  // fVx = gAtVP->GetVx();
146  // fVy = gAtVP->GetVy();
147  // fVz = gAtVP->GetVz();
148 
149  // if(i>1 && gAtVP->GetDecayEvtCnt() && pdgType!=1000500500 && fPType.at(i)=="Ion" ){// TODO: Dirty way to propagate
150  // only the products (0 and 1 are beam and target respectively)
151 
152  // Define event
153  Int_t I = 0;
154 
155  // Define track variables
156  Int_t iPid = -1;
157  Int_t ia1 = 12;
158  Int_t iz1 = 6;
159  Int_t pdgType = 0;
160 
161  for (Int_t j = 0; j < Ntrack; j++) {
162 
163  ia1 = Aout[j];
164  iz1 = Zout[j];
165 
166  if (ia1 > 2 && iz1 > 2) {
167  if (iPid < 0) {
168  char ionName[40];
169  sprintf(ionName, "Ion_%d_%d", ia1, iz1);
170  TParticlePDG *part = fPDG->GetParticle(ionName);
171  if (!part) {
172  std::cout << "AtTPCFissionGenerator::ReadEvent: Cannot find " << ionName << " in database!" << std::endl;
173  // continue;
174  }
175  if (part)
176  pdgType = part->PdgCode();
177  } else
178  pdgType = ia1; // "normal" particle
179 
180  px = fOutPx[j];
181  py = fOutPy[j];
182  pz = fOutPz[j];
183 
184  primGen->AddTrack(pdgType, px, py, pz, fVx, fVy, fVz);
185  }
186  }
187 
189  ->IncDecayEvtCnt(); // TODO: Okay someone should put a more suitable name but we are on a hurry...
190  std::cout << cRED << " Fission event : " << event << cNORMAL << std::endl;
191  event++;
192 
193  return kTRUE;
194 }
195 
AtTPCFissionGeneratorV2::ReadEvent
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Definition: AtTPCFissionGeneratorV2.cxx:118
f
double(* f)(double t, const double *par)
Definition: lmcurve.cxx:21
ClassImp
ClassImp(AtFindVertex)
cYELLOW
constexpr auto cYELLOW
Definition: AtTPCFissionGeneratorV2.cxx:23
cGREEN
constexpr auto cGREEN
Definition: AtTPCFissionGeneratorV2.cxx:25
AtTPCFissionGeneratorV2
Definition: AtTPCFissionGeneratorV2.h:18
cRED
constexpr auto cRED
Definition: AtTPCFissionGeneratorV2.cxx:22
AtVertexPropagator.h
AtVertexPropagator::Instance
static AtVertexPropagator * Instance()
Definition: AtVertexPropagator.cxx:18
AtTPCFissionGeneratorV2.h
cNORMAL
constexpr auto cNORMAL
Definition: AtTPCFissionGeneratorV2.cxx:24
AtVertexPropagator::IncDecayEvtCnt
void IncDecayEvtCnt()
Definition: AtVertexPropagator.cxx:321
c
constexpr auto c
Definition: AtRadialChargeModel.cxx:20
AtTPCFissionGeneratorV2::AtTPCFissionGeneratorV2
AtTPCFissionGeneratorV2()
Definition: AtTPCFissionGeneratorV2.cxx:29