ConexInterface.cc
Go to the documentation of this file.
1 #include "ConexInterface.h"
2 #include <io/CONEXStructures.h>
3 #include <utl/AugerException.h>
4 #include <utl/ErrorLogger.h>
5 #include <evt/ShowerSimData.h>
6 
7 #include <dlfcn.h>
8 
9 #include <string>
10 #include <cmath>
11 #include <vector>
12 
13 using namespace std;
14 using namespace io;
15 using namespace utl;
16 using namespace ConexShowerGeneratorKG;
17 
18 // namespace evt {
19 // class CONEXLeadingParticles;
20 // class LeadingInteraction;
21 // }
22 
23 namespace io {
25 }
26 
27 ConexInterface::ConexInterface(const EHEModel model,
28  const string& parameterPathName,
29  const int storedGenerations,
30  const int seed) :
31  ConexDynamicInterface(model)
32 {
33  fShower = new CONEXShower(0);
34  fHeader = new CONEXHeader();
35 #if _CONEX2R_VERSION >= 565
36  std::vector<io::CONEXLeadingParticles> fLeadingParticles;
37 #endif
38  fRandomSeeds[0] = seed;
39  fRandomSeeds[1] = 0;
40  fRandomSeeds[2] = 0;
41 
42  int nShower = 1000000; // large to avoid final stats.
43  int maxDetail = storedGenerations;
44 #ifdef CONEX_EXTENSIONS
45  int particleListMode = 0;
46  InitConex(nShower, fRandomSeeds, fModel, maxDetail,
47  particleListMode,
48  parameterPathName.c_str(), parameterPathName.size());
49 #else
50  InitConex(nShower, fRandomSeeds, fModel, maxDetail,
51  parameterPathName.c_str(), parameterPathName.size());
52 #endif
53 }
54 
55 
57 {
58  delete fShower;
59  delete fHeader;
60 }
61 
62 
63 // Comparison function, sorts according to generation, then energy, order of generations is decreasing
64 bool
67 {
68  if (lhs.fnInt==rhs.fnInt)
69  return (lhs.fEnergy<rhs.fEnergy);
70  else
71  return (lhs.fnInt>rhs.fnInt);
72 }
73 
74 
75 
76 void
78  double energyInGeV,
79  double zenith,
80  double azimuth,
81  double altitude,
82  int storedParticles)
83 {
84  // ... simulate a shower ...
85  double impactParameter = altitude;
86 #if _CONEX2R_VERSION >= 436
87  RunConex(fRandomSeeds, energyInGeV, zenith, azimuth, impactParameter, particleType);
88 #else
89  if (impactParameter != 0) {
90  ERROR("CONEX version < 4.36, can not set impact parameter (altitude).");
91  }
92  RunConex(fRandomSeeds, energyInGeV, zenith, azimuth, particleType);
93 #endif
94 
95  // ... fill header ...
96  fHeader->fHighEnergyModel = int(fModel);
98  fHeader->fParticleID = particleType;
99 
100  int icut = 1;
101 #if _CONEX2R_VERSION >= 436
102  int icute = 1;
103  int icutg = 1;
104  int icutm = 2;
105  int icuth = 3;
106  float outputVersion = 2.5;
107  GetHeaderVariables(icut, fHeader->fECutHadrons, fHeader->fECutEM,
108  icutm, fHeader->fECutLongProfMuons,
114  fHeader->fVersion);
115 #else
116  float outputVersion = 2;
117  GetHeaderVariables(icut, fHeader->fECutHadrons, fHeader->fECutEM,
121 #endif
122  fHeader->fROOTVersion = outputVersion;
123 
124  // ... and fill shower
125  int nX = GetNumberOfDepthBins();
127 
128  fShower->fLogE = log10(energyInGeV) + 9;
129  fShower->fZenith = zenith;
130  fShower->fAzimuth = azimuth;
131 
132  int iSec = 0; // all charged particles
133  float height[nX];
134  float distance[nX];
135  float miscParameters[13];
136  GetShowerData(icut, iSec, nX, fShower->fX[0], fShower->fN[0],
137  miscParameters[0], height[0], distance[0]);
138  fShower->fX0 = miscParameters[4];
139  fShower->fXmax = miscParameters[9];
140  fShower->fNmax = miscParameters[3];
141  fShower->fP1 = miscParameters[5];
142  fShower->fP2 = miscParameters[6];
143  fShower->fP3 = miscParameters[7];
144  fShower->fChi2 = miscParameters[8];
145  fShower->fXfirst = miscParameters[2];
146  fShower->fHfirst = miscParameters[12];
147 
148 #if _CONEX2R_VERSION >= 565 // Handling of data related to leading particles
149 
150  std::vector<LeadingInteractionsData> leadingIntData;
151  leadingIntData = GetLeadingInteractionsData();
152 
153  std::vector<LeadingInteractionsParticleData> leadingIntParticleData;
154  leadingIntParticleData = GetLeadingInteractionsParticleData();
155 
156  // sort the particle data vector from CONEX
157  // generation first, energy second, order is descending
158  sort(leadingIntParticleData.begin(),leadingIntParticleData.end(),
159  ParticleSort);
160 
161  int nInt = leadingIntData.size();
162  int nParticleInt = leadingIntParticleData.size();
163 
164  int Ncount = 0; // Counting the total number of particles, for purposes of sorting
165 
166  for (int i=0; i<nInt; ++i) {
167  io::CONEXLeadingParticles fLeadingParticlesTemp;
168  // cout << ""
169  // << "leading interaction " << i << " : "
170  // << " projectile id/E=" << leadingIntData[i].pId
171  // << "/" << leadingIntData[i].pEnergy
172  // << ", depth=" << leadingIntData[i].Depth <<" g/cm^2"
173  // << ", mult=" << leadingIntData[i].mult
174  // << ", kInel=" << leadingIntData[i].kinel
175  // << endl;
176  fLeadingParticlesTemp.SetKinel(leadingIntData[i].kinel);
177  fLeadingParticlesTemp.SetParentId(leadingIntData[i].pId);
178  fLeadingParticlesTemp.SetParentEnergy(leadingIntData[i].pEnergy);
179  fLeadingParticlesTemp.SetMultiplicity(leadingIntData[i].mult);
180  fLeadingParticlesTemp.SetTargetMass(leadingIntData[i].matg);
181  fLeadingParticlesTemp.SetDepth(leadingIntData[i].Depth);
182  fLeadingParticlesTemp.SetHeight(leadingIntData[i].Height);
183 
184  int PartMax = 0;
185  if (storedParticles > leadingIntData[i].mult)
186  PartMax = leadingIntData[i].mult;
187  else
188  PartMax = storedParticles;
189 
190  // Get data about PartMax particles in each interaction
191  for (int k=0; k<PartMax; ++k) {
192 
193  fLeadingParticlesTemp.AddParticleEnergy(
194  leadingIntParticleData[nParticleInt-1-Ncount-k].fEnergy);
195  fLeadingParticlesTemp.AddParticleId(
196  leadingIntParticleData[nParticleInt-1-Ncount-k].fID);
197  fLeadingParticlesTemp.AddInteractionNumber(
198  leadingIntParticleData[nParticleInt-1-Ncount-k].fnInt);
199  }
200  Ncount += leadingIntData[i].mult;
201  fLeadingParticles.push_back(fLeadingParticlesTemp);
202  }
203 
204  leadingIntData.clear();
205  leadingIntParticleData.clear();
206 
207 #endif // end of leading interactions data
208 
209  GetdEdXProfile(icut, nX, fShower->fdEdX[0], fShower->fGroundEnergy[0]);
210 
211 #if _CONEX2R_VERSION >= 436
212  GetMuonProfile(icutm, nX, fShower->fNmu[0], fShower->fMuProd[0]);
213  GetGammaProfile(icutg, nX, fShower->fNgam[0]);
214  GetElectronProfile(icute, nX, fShower->fNele[0]);
215 #else
216  GetMuonProfile(icut, nX, fShower->fNmu[0], fShower->fMuProd[0]);
217  GetGammaProfile(icut, nX, fShower->fNgam[0]);
218  GetElectronProfile(icut, nX, fShower->fNele[0]);
219 #endif
220 }
static bool ParticleSort(const LeadingInteractionsParticleData &lhs, const LeadingInteractionsParticleData &rhs)
Wrapper for CONEX header information.
Wrapper for CONEX header shower profile data.
void AddParticleId(const double pId)
void SetTargetMass(const int targetMass)
void SimulateShower(int particleType, double energyInGeV, double zenith, double azimuth, double altitude, int storedParticles)
void SetKinel(const double kinel)
void SetParentEnergy(const double parentEnergy)
float fECutLongProfPhotons
void SetMultiplicity(const int mult)
void AddInteractionNumber(const int intnumber)
std::vector< io::CONEXLeadingParticles > fLeadingParticles
float fECutLongProfHadrons
void SetHeight(const double height)
void SetVectorLength(const int n)
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
void SetParentId(const int parentId)
float fGroundEnergy[3]
void AddParticleEnergy(const double penergy)
float fECutLongProfElectrons
void SetDepth(const double depth)

, generated on Tue Sep 26 2023.