#ifndef __JAANET_JHEADTOOLKIT__ #define __JAANET_JHEADTOOLKIT__ #include #include #include "km3net-dataformat/offline/Vec.hh" #include "km3net-dataformat/offline/Head.hh" #include "km3net-dataformat/definitions/applications.hh" #include "JGeometry3D/JPosition3D.hh" #include "JGeometry3D/JCylinder3D.hh" #include "JAAnet/JHead.hh" /** * \author mdejong */ namespace JAANET { using JGEOMETRY3D::JPosition3D; using JGEOMETRY3D::JCylinder3D; /** * Type definition of test function of header. */ typedef bool (*is_head)(const JHead&); /** * Check for generator. * * \param header header * \return true if this header is produced by genhen; else false */ inline bool is_genhen(const JHead& header) { for (const auto& i : header.simul) { if (i.program == APPLICATION_GENHEN) { return true; } } for (const auto& i : header.physics) { // legacy if (i.buffer.find(APPLICATION_GENHEN) != std::string::npos) { return true; } } return false; } /** * Check for generator. * * \param header header * \return true if this header is produced by gSeaGen; else false */ inline bool is_gseagen(const JHead& header) { for (const auto& i : header.simul) { if (i.program == APPLICATION_GSEAGEN) { return true; } } for (const auto& i : header.physics) { // legacy if (i.buffer.find(APPLICATION_GSEAGEN) != std::string::npos) { return true; } } return false; } /** * Check for generator. * * \param header header * \return true if this header is produced by MUPAGE; else false */ inline bool is_mupage(const JHead& header) { for (const auto& i : header.simul) { if (i.program == APPLICATION_MUPAGE) { return true; } } return false; } /** * Check for generator. * * \param header header * \return true if this header is produced by Corsika; else false */ inline bool is_corsika(const JHead& header) { for (const auto& i : header.simul) { if (i.program == APPLICATION_CORSIKA) { return true; } } return false; } /** * Check for generator. * * \param header header * \return true if this header is produced by km3buu; else false */ inline bool is_km3buu(const JHead& header) { for (const auto& i : header.simul) { if (i.program == APPLICATION_KM3BUU) { return true; } } return false; } /** * Check for detector simulation. * * \param header header * \return true if this header is processed with km3; else false */ inline bool is_km3(const JHead& header) { for (const auto& i : header.simul) { if (i.program == APPLICATION_KM3) { return true; } } return false; } /** * Check for detector simulation. * * \param header header * \return true if this header is processed with KM3Sim; else false */ inline bool is_km3sim(const JHead& header) { for (const auto& i : header.simul) { if (i.program == APPLICATION_KM3SIM) { return true; } } return false; } /** * Check for detector simulation. * * \param header header * \return true if this header is processed with JSirene; else false */ inline bool is_sirene(const JHead& header) { for (const auto& i : header.simul) { if (i.program == APPLICATION_JSIRENE) { return true; } } return false; } /** * Check for generator. * * \param header header * \return true if this header is produced by pure noise; else false */ inline bool is_pure_noise(const JHead& header) { return header.K40.livetime_s > 0.0; } /** * Check for real data. * * \param header header * \return true if this header corresponds to real data; else false */ inline bool is_daq(const JHead& header) { return header.DAQ.livetime_s > 0.0; } /** * Auxiliary map of application to check method. */ struct JHeadHelper : public std::map { /** * Default constructor. */ JHeadHelper() { (*this)[APPLICATION_GENHEN] = is_genhen; (*this)[APPLICATION_GSEAGEN] = is_gseagen; (*this)[APPLICATION_MUPAGE] = is_mupage; (*this)[APPLICATION_CORSIKA] = is_corsika; (*this)[APPLICATION_KM3BUU] = is_km3buu; (*this)[APPLICATION_KM3] = is_km3; (*this)[APPLICATION_KM3SIM] = is_km3sim; (*this)[APPLICATION_JSIRENE] = is_sirene; (*this)["DAQ"] = is_daq; } /** * Get check method for given application. * * \param application application * \return check method */ is_head operator()(const std::string& application) const { return this->at(application); } }; /** * Function object to get check method for given application. */ static JHeadHelper get_is_head; /** * Get offset. * * For consistency with the position of the detector, * a pending offset should be added to the positions of generated tracks (i.e. Evt::mc_trks). * * The main logic can be summarised as follows. * -# if * JHead::fixedcan is defined, the values correspond to an offset that has already been applied, * (0,0,0) is returned; * -# else if * JHead::can is defined, the values correspond to a z-range that has already been applied, * (0,0,-zmin) is returned; * -# else if * JHead::coord_origin is defined, the values correspond to an offset that has not yet been applied, * (x,y,z) is returned; * -# else * (0,0,0) is returned; * * \param header header * \return position */ inline Vec getOffset(const JHead& header) { if (header.is_valid(&JHead::fixedcan)) return Vec(0.0, 0.0, 0.0); else if (header.is_valid(&JHead::can)) return Vec(0.0, 0.0, -header.can.zmin); else if (header.is_valid(&JHead::coord_origin)) return header.coord_origin; else return Vec(0.0, 0.0, 0.0); } /** * Get origin. * * The origin corresponds to the offset that has already been applied to the positions of generated tracks (i.e. Evt::mc_trks). * * The main logic can be summarised as follows. * -# if * JHead::fixedcan is defined, the values correspond to the offset that has already been applied, * (x,y,0) is returned; * -# else if * JHead::can is defined, the values correspond to a z-range that has already been applied, * (0,0,zmin) is returned; * -# else if * JHead::coord_origin is defined, the values correspond to the offset that has not yet been applied, * (0,0,0) is returned; * -# else * (0,0,0) is returned; * * \param header header * \return position */ inline Vec getOrigin(const JHead& header) { if (header.is_valid(&JHead::fixedcan)) return Vec(header.fixedcan.xcenter, header.fixedcan.ycenter, 0.0); else if (header.is_valid(&JHead::can)) return Vec(0.0, 0.0, header.can.zmin); else if (header.is_valid(&JHead::coord_origin)) return Vec(0.0, 0.0, 0.0); else return Vec(0.0, 0.0, 0.0); } /** * Get cylinder corresponding to the positions of generated tracks (i.e. Evt::mc_trks). * * For consistency with the position of the detector, * the pending offset (see method JAANET::getOffset) should be added to the position of cylinder. * * \param header header * \return cylinder */ inline JCylinder3D getCylinder(const JHead& header) { using namespace JPP; if (header.is_valid(&JHead::fixedcan)) { return JCylinder3D(JCircle2D(JVector2D(header.fixedcan.xcenter, header.fixedcan.ycenter), header.fixedcan.radius), header.fixedcan.zmin, header.fixedcan.zmax); } else if (header.is_valid(&JHead::can)) { return JCylinder3D(JCircle2D(JVector2D(), header.can.r), header.can.zmin, header.can.zmax); } else { return JCylinder3D(); } } } #endif