1 #ifndef __JDETECTOR__JDETECTORTOOLKIT__
2 #define __JDETECTOR__JDETECTORTOOLKIT__
38 namespace JDETECTOR {}
39 namespace JPP {
using namespace JDETECTOR; }
70 static const char*
const GDML_SCHEMA = getenv(
"GDML_SCHEMA_DIR");
71 static const char*
const CAN_MARGIN = getenv(
"CAN_MARGIN");
85 for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
86 for (JDetector::const_iterator
j = detector.begin();
j != i; ++
j) {
87 if (i->getDistance(*
j) > dmax) {
88 dmax = i->getDistance(*
j);
105 const double phi = atan2(dir.
getDY(), dir.
getDZ())*(180.0/
PI);
124 return asin(-dir.
getDX())*(180.0/
PI);
142 const JCylinder3D cylinder(detector.begin(), detector.end());
146 std::cout<<
"CAN_MARGIN not defined! Setting standard CAN_MARGIN = 350 m"<<std::endl;
161 const double WorldCylinderHeight = 2*(cylinder.getZmax() - cylinder.getZmin() + can_margin + 50);
162 const double WorldRadius = cylinder.getRadius() + can_margin + 50;
164 std::cout<<WorldCylinderHeight/2<<std::endl;
165 std::cout<<WorldRadius<<std::endl;
175 const double Crust_Z_size = WorldCylinderHeight/2;
176 const double Crust_Z_position= -WorldCylinderHeight/4;
178 out<<
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<gdml xmlns:gdml=\"http://cern.ch/2001/Schemas/GDML\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"";
180 std::cout<<
"GDML_SCHEMA_DIR NOT DEFINED! Setting default path"<<std::endl;
188 out<<
"<rotation name=\"identity\"/>\n<position name=\"zero\"/>\n";
191 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
196 out<<
"<position name=\"PosString"<<module->getString()<<
"_Dom"<<module->getID()<<
"\" unit=\"m\" x=\""<<module->
getX()<<
"\" y=\""<<module->getY()<<
"\" z=\""<<module->getZ()<<
"\"/>\n";
198 for (JModule::const_iterator
pmt = module->begin();
pmt != module->end(); ++
pmt) {
203 out<<
"<position name=\"CathodPosition"<<
pmt->
getID()<<
"_"<<module->getID()<<
"\" unit=\"m\" x=\""<<vec.
getX()<<
"\" y=\""<<vec.
getY()<<
"\" z=\""<<vec.
getZ()<<
"\"/>\n";
205 out<<
"<constant name=\"CathodID_"<<PMTs_NO<<
"\" value=\""<<
pmt->
getID()<<
"\"/>\n";
211 out<<
"<position name=\"OMShift\" unit=\"m\" x=\"0\" y=\"0\" z=\"0.0392\"/>\n";
213 out<<
"<!-- end of DU position definitions -->\n<position name=\"CrustPosition\" unit=\"m\" x=\"0\" y=\"0\" z=\""<<Crust_Z_position<<
"\"/>\n";
216 out<<
"<materials>\n";
217 out<<
"</materials>\n";
220 out<<
" <box name=\"CrustBox\" lunit=\"m\" x=\"2200\" y=\"2200\" z=\""<<Crust_Z_size<<
"\"/>\n";
221 out<<
" <box name=\"StoreyBox\" lunit=\"m\" x=\"0.6\" y=\"0.6\" z=\"0.6\"/>\n";
222 out<<
" <sphere name=\"OMSphere\" lunit=\"cm\" aunit=\"deg\" rmin=\"0.0\" rmax=\"21.6\" startphi=\"0.0\" deltaphi=\"360.0\" starttheta=\"0.0\" deltatheta=\"180.0\"/>\n";
223 out<<
" <tube name=\"CathodTube\" lunit=\"cm\" aunit=\"deg\" rmin=\"0.0\" rmax=\"4.7462\" z=\"0.5\" startphi=\"0.0\" deltaphi=\"360.0\"/>\n";
224 out<<
" <tube name=\"WorldTube\" lunit=\"m\" aunit=\"deg\" rmin=\"0.0\" rmax=\""<<WorldRadius<<
"\" z=\""<<WorldCylinderHeight<<
"\" startphi=\"0.0\" deltaphi=\"360.0\"/>\n";
225 out<<
"</solids>\n\n\n";
227 out<<
"<structure>\n";
228 out<<
" <volume name=\"CathodVolume\">\n";
229 out<<
" <materialref ref=\"Cathod\"/>\n";
230 out<<
" <solidref ref=\"CathodTube\"/>\n";
233 out<<
"<!-- OMVolume(s) construction -->\n";
235 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
237 out<<
" <volume name=\"OMVolume"<<module->getID()<<
"\">\n";
238 out<<
" <materialref ref=\"Water\"/>\n";
239 out<<
" <solidref ref=\"OMSphere\"/>\n";
241 for (JModule::const_iterator
pmt = module->begin();
pmt != module->end(); ++
pmt) {
243 out<<
" <volumeref ref=\"CathodVolume\"/>\n";
244 out<<
" <positionref ref=\"CathodPosition"<<
pmt->
getID()<<
"_"<<module->getID()<<
"\"/>\n";
245 out<<
" <rotationref ref=\"CathodRotation"<<
pmt->
getID()<<
"_"<<module->getID()<<
"\"/>\n";
246 out<<
" </physvol>\n";
252 out<<
"<!-- StoreyVolume(s) construction -->\n";
254 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
255 out<<
" <volume name=\"StoreyVolume"<<module->getID()<<
"\">\n";
256 out<<
" <materialref ref=\"Water\"/>\n";
257 out<<
" <solidref ref=\"StoreyBox\"/>\n";
259 out<<
" <volumeref ref=\"OMVolume"<<module->getID()<<
"\"/>\n";
260 out<<
" <positionref ref=\"OMShift\"/>\n";
262 out<<
" <rotationref ref=\"identity\"/>\n";
263 out<<
" </physvol>\n";
267 out<<
"<!-- Crust Volume construction-->\n";
268 out<<
"<volume name=\"CrustVolume\">\n";
269 out<<
" <materialref ref=\"Crust\"/>\n";
270 out<<
" <solidref ref=\"CrustBox\"/>\n";
273 out<<
"<!-- World Volume construction-->\n";
274 out<<
"<volume name=\"WorldVolume\">\n";
275 out<<
" <materialref ref=\"Water\"/>\n";
277 out<<
" <solidref ref=\"WorldTube\"/>\n";
280 out<<
" <volumeref ref=\"CrustVolume\"/>\n";
281 out<<
" <positionref ref=\"CrustPosition\"/>\n";
282 out<<
" <rotationref ref=\"identity\"/>\n";
283 out<<
" </physvol>\n";
285 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
287 out<<
" <volumeref ref=\"StoreyVolume"<<module->getID()<<
"\"/>\n";
288 out<<
" <positionref ref=\"PosString"<< module->getString() <<
"_Dom"<< module->getID() <<
"\"/>\n";
290 out<<
" <rotationref ref=\"identity\"/>\n";
291 out<<
" </physvol>\n";
296 out<<
"</structure>\n";
297 out<<
"<setup name=\"Default\" version=\"1.0\">\n";
298 out<<
"<world ref=\"WorldVolume\"/>\n";
345 if (!module.empty()) {
349 for (JModule::const_iterator
pmt = module.begin();
pmt != module.end(); ++
pmt) {
353 time_range.
include(
putTime(timeRange.getLowerLimit(), calibration));
354 time_range.
include(
putTime(timeRange.getUpperLimit(), calibration));
374 return module.size();
386 int number_of_pmts = 0;
388 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
392 return number_of_pmts;
406 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
407 buffer.insert(module->getString());
424 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
425 buffer.insert(module->getFloor());
428 return buffer.size();
442 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
443 buffer.insert(module->getID());
446 return buffer.size();
471 ifstream
in(file_name.c_str());
481 detector.swap(buffer);
497 ifstream
in(file_name.c_str());
553 std::ofstream out(file_name.c_str());
569 std::ofstream out(file_name.c_str());
601 module.resize(memo.size());
664 if (module.empty()) {
668 const double R = 0.5;
670 const double st = sin(0.75*
PI);
671 const double ct = cos(0.75*
PI);
673 for (
int i = 0; i != 3; ++i) {
675 const double phi = (2.0*
PI*i) / 3.0;
676 const double cp = cos(phi);
677 const double sp = sin(phi);
694 static const size_t NUMBER_OF_DIMENSIONS = 3;
708 if (first.size() == second.size()) {
710 const size_t N = first.size();
712 if (N >= NUMBER_OF_DIMENSIONS) {
717 for (
size_t i = 0; i !=
N; ++i) {
722 for (
size_t i = 0; i != NUMBER_OF_DIMENSIONS; ++i) {
723 if (!orthonormalise(i)) {
728 this->a00 = out[0].getX() *
in[0].getX() + out[1].getX() *
in[1].getX() + out[2].getX() *
in[2].getX();
729 this->a01 = out[0].getX() *
in[0].getY() + out[1].getX() *
in[1].getY() + out[2].getX() *
in[2].getY();
730 this->a02 = out[0].getX() *
in[0].getZ() + out[1].getX() *
in[1].getZ() + out[2].getX() *
in[2].getZ();
732 this->a10 = out[0].getY() *
in[0].getX() + out[1].getY() *
in[1].getX() + out[2].getY() *
in[2].getX();
733 this->a11 = out[0].getY() *
in[0].getY() + out[1].getY() *
in[1].getY() + out[2].getY() *
in[2].getY();
734 this->a12 = out[0].getY() *
in[0].getZ() + out[1].getY() *
in[1].getZ() + out[2].getY() *
in[2].getZ();
736 this->a20 = out[0].getZ() *
in[0].getX() + out[1].getZ() *
in[1].getX() + out[2].getZ() *
in[2].getX();
737 this->a21 = out[0].getZ() *
in[0].getY() + out[1].getZ() *
in[1].getY() + out[2].getZ() *
in[2].getY();
738 this->a22 = out[0].getZ() *
in[0].getZ() + out[1].getZ() *
in[1].getZ() + out[2].getZ() *
in[2].getZ();
742 THROW(
JException,
"Module size" << N <<
" < " << NUMBER_OF_DIMENSIONS);
747 THROW(
JException,
"Module size" << first.size() <<
" != " << second.size());
767 for (
size_t i = index + 1; i !=
in.size(); ++i) {
768 if (
in[i].getLengthSquared() >
in[pos].getLengthSquared()) {
773 const double u =
in[pos].getLength();
781 swap(
in [pos],
in [index]);
782 swap(out[pos], out[index]);
785 for (
size_t i = index + 1; i !=
in.size(); ++i) {
787 const double dot =
in[index].getDot(
in[i]);
789 in [i] -= dot *
in [index];
790 out[i] -= dot * out[index];
Exception for opening of file.
double GetYrotationG4(const JVersor3D dir)
Get rotation over Y axis in Geant4 coordinate system.
Wrapper class around STL string class.
Data structure for a composite optical module.
void setLocation(const JLocation &location)
Set location.
const JDirection3D & getDirection() const
Get direction.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
std::set< int > getStringIDs(const JDetector &detector)
Get list of strings IDs.
virtual JWriter & write(JWriter &out) const
Write to output.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
static JRotation getRotation
Function object to get rotation matrix to go from first to second module.
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
virtual JReader & read(JReader &in)
Read from input.
Data structure for PMT calibration.
static const char *const GDML_SCHEMA
directory necessary for correct GDML header output
static const JModuleCounter getNumberOfModules
Function object to count unique modules.
Data structure for detector geometry and calibration.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
Data structure for position fit.
bool endsWith(const std::string &suffix) const
Test if this string ends with the specified suffix.
esac $JPP_DIR examples JDetector JTransitTime o $OUTPUT_FILE n N $NPE T $TTS_NS d $DEBUG for HISTOGRAM in tts tt2 pmt
JTimeRange getTimeRange(const Evt &event)
Get time range (i.e. time between earliest and latest hit) of Monte Carlo event.
Monte Carlo detector (i.e. so-called .det file).
Lookup table for PMT addresses in optical module.
double putTime(const T &t1, const JCalibration &cal)
Get de-calibrated time.
JVector3D & sub(const JVector3D &vector)
Subtract vector.
double getMaximalDistance(const JDetector &detector)
Get maximal distance between modules in detector.
I/O formatting auxiliaries.
Data structure for vector in three dimensions.
Logical location of module.
double getDY() const
Get y direction.
Auxiliary class to get rotation matrix between two optical modules.
double getDX() const
Get x direction.
int getID() const
Get identifier.
Data structure for PMT geometry and calibration.
void compile()
Compile position of module from the positions and directions of the PMTs.
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
double getY() const
Get y position.
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
const JPosition3D & getPosition() const
Get position.
static const char *const CAN_MARGIN
extension of the detector size to comply with the can definition
double getMaximalTime(const double R_Hz)
Get maximal time for given rate.
const JPMT & getPMT(const int index) const
Get PMT.
then usage $script[distance] fi case set_variable R
Logical location of module.
const JRotation3D & operator()(const JModule &first, const JModule &second)
Get rotation matrix to go from first to second module.
std::vector< JVector3D > in
static const char *const KM3NET_DETECTOR_FILE_FORMAT
KM3NeT standard ASCII format.
static const char *const ZIPPED_DETECTOR_FILE_FORMAT
zipped KM3NeT standard ASCII format
Linear fit of JFIT::JPoint3D.
static const char *const GENDET_DETECTOR_FILE_FORMAT
File name extensions.
static const char *const BINARY_DETECTOR_FILE_FORMAT
JIO binary file format.
void setID(const int id)
Set identifier.
double getX() const
Get x position.
static const char *const G4GDML_DEFAULT_SCHEMALOCATION
void store(const JString &file_name, const JDetector &detector)
Store detector to output file.
Data structure for position in three dimensions.
Data structure for normalised vector in three dimensions.
void read_gdml(std::istream &, const JDetector &)
Binary buffered file output.
Linear fit of crossing point (position) between axes (objects with position and direction).
then usage $script[input file[working directory[option]]] nWhere option can be N
double GetXrotationG4(const JVersor3D dir)
Get rotation over X axis in Geant4 coordinate system.
static const char *const GDML_DETECTOR_FILE_FORMAT
KM3Sim input format.
double getZ() const
Get z position.
Binary buffered file input.
bool has(const int index) const
Test whether index is available.
double getDZ() const
Get z direction.
std::vector< JVector3D > out
const JModule & getModule(const JDetector &detector, const JModuleLocation &location)
find module with a given string and floor number
void write_gdml(std::ostream &out, const JDetector &detector)
Writes KM3Sim GDML input file from detector.
JPosition3D getPosition(const Vec &v)
Get position.
double getT0() const
Get time offset.
bool orthonormalise(const size_t index)
Put normalised primary direction at specified index and orthoganilise others.