8 #include <io/AiresShowerFile.h>
9 #include <io/AiresUtilities.h>
10 #include <io/AiresWrapper.h>
11 #include <io/AiresShowerFileParticleIterator.h>
12 #include <evt/Event.h>
13 #include <evt/DefaultShowerGeometryProducer.h>
14 #include <evt/ShowerSimData.h>
15 #include <evt/GaisserHillas2Parameter.h>
16 #include <evt/GaisserHillas4Parameter.h>
17 #include <evt/GaisserHillasTypes.h>
18 #include <utl/AugerUnits.h>
19 #include <utl/AugerCoordinateSystem.h>
20 #include <utl/CoordinateSystem.h>
21 #include <utl/ErrorLogger.h>
22 #include <utl/Point.h>
23 #include <utl/TabulatedFunction.h>
24 #include <utl/Vector.h>
25 #include <utl/Particle.h>
26 #include <boost/tuple/tuple.hpp>
27 #include <boost/tuple/tuple_io.hpp>
28 #include <boost/filesystem/operations.hpp>
29 #include <boost/filesystem/path.hpp>
40 namespace fs = boost::filesystem;
43 AiresShowerFile::AiresShowerFile() :
76 if (theMode !=
eRead) {
77 FATAL(
"AIRES data file can only be opened in read-only mode!");
86 #if BOOST_FILESYSTEM_VERSION < 3
87 fs::path fullPath(
fFilename.c_str(), fs::native);
88 string theDirectory = fullPath.branch_path().native_file_string();
89 string theFile = fullPath.leaf();
92 string theDirectory = fullPath.branch_path().c_str();
93 string theFile = fullPath.leaf().c_str();
114 int intData[15], showerPrimaryCode;
115 double doubleData[37], showerPrimaryWeight;
117 fill(intData, intData + 15, 0);
118 fill(doubleData, doubleData + 37, 0);
121 &showerPrimaryCode, &showerPrimaryWeight);
182 ERROR(
"Attempt to write AIRES data file!");
207 ERROR(
"Error in positioning with AIRES data file.");
212 int headerIntData[99];
213 double headerDoubleData[99];
215 fill(headerIntData, headerIntData + 99, 0);
216 fill(headerDoubleData, headerDoubleData + 99, 0);
222 ERROR(
"Error attempting to retrieve header for "
223 "shower from AIRES data file.");
235 ERROR(
"Error in positioning with AIRES data file.");
239 int trailerIntData[99];
240 double trailerDoubleData[99];
242 fill(trailerIntData, trailerIntData + 99, 0);
243 fill(trailerDoubleData, trailerDoubleData + 99, 0);
249 ERROR(
"Error attempting to retrieve header for "
250 "shower from AIRES data file.");
267 char taskNameChar[999];
268 int taskNameCharLength;
272 &taskNameVersion, taskDate);
273 string taskName(taskNameChar, taskNameCharLength);
282 #if BOOST_FILESYSTEM_VERSION < 3
283 fs::path fullPath(
fFilename.c_str(), fs::native);
284 const string theDirectory = fullPath.branch_path().native_file_string();
285 const string theFile =
286 fullPath.leaf().substr(0, fullPath.leaf().find(
string(
".")));
289 const string theDirectory = fullPath.branch_path().c_str();
290 const string tmpPath = fullPath.leaf().c_str();
291 const string theFile =
292 tmpPath.substr(0,
string(fullPath.leaf().c_str()).find(
string(
".")));
296 filename << theDirectory <<
'/' << theFile;
302 stringstream showerNumberAppendixMultipleShowers;
303 showerNumberAppendixMultipleShowers <<
"_s";
304 if (showerNumber < 10000)
305 showerNumberAppendixMultipleShowers.width(4);
307 showerNumberAppendixMultipleShowers.width(6);
308 showerNumberAppendixMultipleShowers.fill(
'0');
309 showerNumberAppendixMultipleShowers << showerNumber;
312 const string totalFilenameMultiple = filename.str() + showerNumberAppendixMultipleShowers.str();
314 double depth,
data, dummy;
325 ifstream longitudinalDataFile;
331 bool singleShower =
true;
335 ostringstream infoOpeningLongProf;
336 infoOpeningLongProf <<
"Reading profile from: ";
340 singleShower =
false;
341 infoOpeningLongProf << totalFilenameMultiple;
345 infoOpeningLongProf << filename.str();
349 INFO(infoOpeningLongProf);
351 if (longitudinalDataFile.is_open()) {
354 longitudinalDataFile.get(onechar);
358 if (onechar !=
'#') {
360 longitudinalDataFile.unget();
365 longitudinalDataFile >> index >> depth >> data >> dummy >> dummy >> dummy >> dummy;
367 longitudinalDataFile >> index >> depth >>
data;
382 longitudinalDataFile.getline(line, 128);
383 longitudinalDataFile.get(onechar);
396 double depth1[2000], nch[2000], weight[2000];
401 for (
int i = 0; i < index; ++i) {
403 depth1[i] = profile[i].X()/(
g/
cm2);
404 nch[i] = profile[i].
Y();
409 int bodata = 1, eodata = index - 1, ws = 2;
410 double minmax = 0.0, nminratio = 100.0;
413 int bodataeff, eodataeff;
414 double nmax, xmax, x0, lambda, sq;
418 &ws, &minmax, &nminratio, &bodataeff, &eodataeff,
419 &nmax, &xmax, &x0, &lambda, &sq, &irc);
427 ostringstream message;
428 message <<
"Aires fit for the Gaisser-Hillas function failed! \n"
429 <<
"GHParameters object from simulated shower will \n"
437 unsigned ndof = eodataeff - bodataeff - 4;
452 longitudinalDataFile.close();
456 ostringstream message;
457 message <<
"Unable to find Aires charge profile file ( neither "
458 << totalFilenameMultiple << fChargeTableAppendix <<
" nor "
459 << filename.str() << fChargeTableAppendix
469 ostringstream infoOpeningEnergyDep;
470 infoOpeningEnergyDep <<
"Reading energy deposit from: ";
472 ifstream energyDepositDataFile;
476 infoOpeningEnergyDep << totalFilenameMultiple;
480 infoOpeningEnergyDep << filename.str();
484 INFO(infoOpeningEnergyDep);
486 if (energyDepositDataFile.is_open()) {
489 energyDepositDataFile.get(onechar);
493 if (onechar !=
'#') {
495 energyDepositDataFile.unget();
500 energyDepositDataFile >> index >> depth >> data >> dummy >> dummy >> dummy >> dummy;
502 energyDepositDataFile >> index >> depth >>
data;
520 energyDepositDataFile.getline(line, 128);
521 energyDepositDataFile.get(onechar);
529 energyDepositDataFile.close();
532 ostringstream message;
533 message <<
"Unable to find Aires energy deposit profile file (neither "
534 << totalFilenameMultiple << fdEdXTableAppendix <<
" nor "
535 << filename.str() << fdEdXTableAppendix
546 ostringstream infoOpeningGammaProf;
547 infoOpeningGammaProf <<
"Reading gamma profile from: ";
549 ifstream gammaProfileDataFile;
553 infoOpeningGammaProf << totalFilenameMultiple;
557 infoOpeningGammaProf << filename.str();
561 INFO(infoOpeningGammaProf);
563 if (gammaProfileDataFile.is_open()) {
566 gammaProfileDataFile.get(onechar);
570 if (onechar !=
'#') {
572 gammaProfileDataFile.unget();
577 gammaProfileDataFile >> index >> depth >> data >> dummy >> dummy >> dummy >> dummy;
579 gammaProfileDataFile >> index >> depth >>
data;
590 gammaProfileDataFile.getline(line, 128);
591 gammaProfileDataFile.get(onechar);
599 gammaProfileDataFile.close();
611 ostringstream infoOpeningElectronProf;
612 infoOpeningElectronProf <<
"Reading electron profile from: ";
614 ifstream electronProfileDataFile;
618 infoOpeningElectronProf << totalFilenameMultiple;
622 infoOpeningElectronProf << filename.str();
626 INFO(infoOpeningElectronProf);
628 if (electronProfileDataFile.is_open()) {
631 electronProfileDataFile.get(onechar);
635 if (onechar !=
'#') {
637 electronProfileDataFile.unget();
642 electronProfileDataFile >> index >> depth >> data >> dummy >> dummy >> dummy >> dummy;
644 electronProfileDataFile >> index >> depth >>
data;
655 electronProfileDataFile.getline(line, 128);
656 electronProfileDataFile.get(onechar);
664 electronProfileDataFile.close();
676 ostringstream infoOpeningMuonProf;
677 infoOpeningMuonProf <<
"Reading muon profile from: ";
679 ifstream muonProfileDataFile;
683 infoOpeningMuonProf << totalFilenameMultiple;
687 infoOpeningMuonProf << filename.str();
691 INFO(infoOpeningMuonProf);
693 if (muonProfileDataFile.is_open()) {
696 muonProfileDataFile.get(onechar);
700 if (onechar !=
'#') {
702 muonProfileDataFile.unget();
707 muonProfileDataFile >> index >> depth >> data >> dummy >> dummy >> dummy >> dummy;
709 muonProfileDataFile >> index >> depth >>
data;
720 muonProfileDataFile.getline(line, 128);
721 muonProfileDataFile.get(onechar);
729 muonProfileDataFile.close();
774 <<
" m is small [max: 1 meter]:"
775 " computing total number of muons at ground level";
782 double muonWeight = 0;
809 if (dataIt->first ==
int(eventId)) {
915 for (
int i = 0; i < 5; ++i)
1021 int currentRecordNumber;
1024 double doubleData[99];
1026 fill(intData, intData + 99, 0);
1027 fill(doubleData, doubleData + 99, 0);
1032 currentRecordNumber =
1039 ERROR(
"Invalid read from AIRES data file.");
int AiresToPDG(int theAiresCode)
Convert AIRES particle code to PDG.
int fTotalParticlesInShowerIndex
Status FindEvent(const unsigned int n)
seek Event id set cursor there
int fNumberGroundParticlesIndex
void SetMuonNumber(const double nmuon)
Set the number of muons which reach ground level.
static void opencrofilec(const char *wdir, const char *filename, int *header1, int *logbase, int *vrb, int *channel, int *irc)
std::string fChargeTableAppendix
int fLongFitReturnCodeIndex
static int crorecnumber(int *channel, int *vrb, int *irc)
Describes a particle for Simulation.
std::string fElectronTableAppendix
Class to hold collection (x,y) points and provide interpolation between them.
bool HasGroundParticles() const
bool HasSimShower() const
void SetMaxRadiusCut(const double maxR)
double fGeomagneticFieldDeclination
std::string fGammaTableAppendix
Mode
Available open modes.
void SetXMax(const double xMax, const double error)
void SetGroundParticleCoordinateSystemAzimuth(const double azimuth)
Set the azimuth angle of the shower. Angle in x-y plane wrt. to the x axis (0 is from east)...
#define INFO(message)
Macro for logging informational messages.
DataLocationsType::iterator fCurrentShowerLocation
#define FATAL(message)
Macro for logging fatal messages.
std::string fMuonTableAppendix
void MakeGHParameters(const evt::VGaisserHillasParameter &ghPar)
Make the Gaisser-Hillas parameters of the shower.
void SetShapeParameter(const gh::EShapeParameter par, const double value, const double error)
Setters.
void PushBack(const double x, const double y)
virtual void Rewind()
Rewind the particle list in the shower file to the beginning.
double pow(const double x, const unsigned int i)
int fGroundParticleCodeIndex
void MakedEdX(const utl::TabulatedFunction &dEdX)
Make the energy deposit of the shower.
static void cioclose1(int *channel)
static void crorewind(int *channel, int *vrb, int *irc)
void SetRecordInformation()
Base class to report exceptions in IO.
void SetFileInterface(VShowerFileParticleIterator *const interface)
Interface class to access Shower Simulated parameters.
double fInjectionAltitude
int DefaultOpen(const std::string &filename, const Mode mode=eRead)
std::string fdEdXTableAppendix
Class representing a document branch.
void MakeLongitudinalProfile(const utl::TabulatedFunction &lp, const ProfileType type=eCharged)
Make the longitudinal charge profile of the shower.
Status
Return code for seek operation.
int fPrimaryThinningIndex
double abs(const SVector< n, T > &v)
void Write(const evt::Event &event)
ShowerSimData & GetSimShower()
static void fitghf(int *bodata0, int *eodata0, double *depths, double *nallch, double *weights, int *ws, double *minnmax, double *nminratio, int *bodataeff, int *eodataeff, double *nmax, double *xmax, double *x0, double *lambda, double *sqsum, int *irc)
static void ciorshutdown()
virtual ~AiresShowerFile()
void SetEnergy(const double theEnergy)
Set the energy of the shower primary particle.
utl::ShowerParticleList & GetGroundParticles()
Get particle list Proxy.
Status Read(evt::Event &event)
read current event advance cursor by 1
#define WARNING(message)
Macro for logging warning messages.
static int crofieldindex(int *channel, int *rectype, const char *fieldname, int *vrb, int *datype, int *irc)
friend class AiresShowerFileParticleIterator
void SetChiSquare(const double chi, const unsigned int ndof)
void MakeGroundParticles()
Gaisser Hillas with 4 parameters.
void SetXFirst(const double xFirst)
Set depth of first interaction.
static void croinputdata0(int *intdata, double *realdata, int *shprimcode, double *shprimwt)
static bool crorecfind(int *channel, int *intype, int *vrb, int *infield1, int *rectype)
static void croreccount(int *channel, int *vrb, int *nrtype, int *nrec, int *irc)
void SetNMax(const double nMax, const double error, const bool isEnergyDeposit=false)
bool HasdEdX() const
Check initialization of the energy deposit.
int fTotalChargedParticlesIndex
static bool crogotorec(int *channel, int *recnumber, int *vrb, int *irc)
int fGlobalTimeShiftIndex
virtual utl::Particle * GetOneParticle(const utl::CoordinateSystemPtr &cs)
Member function to fetch the next particle.
int fFirstInteractionDepthIndex
void SetPrimaryParticle(const int type)
Set the type of the shower primary particle.
double GetWeight() const
Particle weight (assigned by shower generator thinning algorithms)
double fThinningParameter
Status GotoPosition(const unsigned int n)
goto by position in the file
void SetGroundParticleCoordinateSystemZenith(const double zenith)
Set the zenith angle of the shower. Room angle between z-axis and direction from where the shower is ...
double fGeomagneticFieldStrength
Implementation of the VShowerFileParticleIterator for an Aires generated shower file.
void SetShowerNumber(const int sid)
bool HasGHParameters() const
Check initialization of the Gaisser-Hillas parameters.
void SetMinRadiusCut(const double minR)
Set the minimum radius cut.
void MakeSimShower(const evt::VShowerGeometryProducer &p)
AiresShowerFileParticleIterator * fParticleIterator
double fShowerPrimaryWeight
int fInjectionAltitudeIndex
static double kMagneticFieldDeclination
Gaisser Hillas with 4 parameters.
DataLocationsType fDataLocations
double Y(const double x) const
Get or interpolate the Y value that corresponds to parameter x.
void SetShowerRunId(const std::string srid)
static void ciorinit(int *inilevel, int *codsys, int *vrb, int *irc)
#define ERROR(message)
Macro for logging error messages.
bool HasLongitudinalProfile(const ProfileType type=eCharged) const
Check initialization of the longitudinal profile.
static void crotaskidc(char *taskname, int *namelen, int *taskversion, char *startdate)
static bool regetcrorecord(int *channel, int *intfields, double *realfields, bool *altrec, int *vrb, int *irc)
static bool getcrorecord(int *channel, int *intfields, double *realfields, bool *altrec, int *vrb, int *irc)
double fGeomagneticFieldInclination
void Open(const std::string &theFileName, const Mode theMode=eRead, const utl::Branch *b=nullptr)