1 #ifndef __JDETECTOR__JDETECTORTOOLKIT__ 
    2 #define __JDETECTOR__JDETECTORTOOLKIT__ 
   67   static const char* 
const GDML_SCHEMA                 = getenv(
"GDML_SCHEMA_DIR");  
 
   80     for (JDetector::const_iterator i = detector.begin(); i != detector.end(); ++i) {
 
   81       for (JDetector::const_iterator 
j = detector.begin(); 
j != i; ++
j) {
 
   82         if (i->getDistance(*
j) > dmax) {
 
   83           dmax = i->getDistance(*
j);
 
  100     const double phi = atan2(dir.
getDY(), dir.
getDZ())*(180.0/
PI);
 
  119     return asin(-dir.
getDX())*(180.0/
PI);
 
  137     const JCylinder3D cylinder(detector.begin(), detector.end());
 
  149     const double WorldBoxHeight = 2200.;
 
  152     const double Crust_Z_size = WorldBoxHeight/2;
 
  154     const double Crust_Z_position= -WorldBoxHeight/4;
 
  157     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=\"";
 
  159       std::cout<<
"GDML_SCHEMA_DIR NOT DEFINED! Setting default path"<<std::endl;
 
  160       out<<
"/sps/km3net/users/jmanczak/km3sim/geant4.10.05/source/persistency/gdml/schema/gdml.xsd\">\n\n\n";
 
  166     out<<
"<rotation name=\"identity\"/>\n<position name=\"zero\"/>\n";
 
  169     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  174       out<<
"<position name=\"PosString"<<module->getString()<<
"_Dom"<<module->getID()<<
"\" unit=\"m\" x=\""<<module->
getX()<<
"\" y=\""<<module->getY()<<
"\" z=\""<<module->getZ()<<
"\"/>\n";
 
  176       for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
 
  180         const JVector3D vec = static_cast<JVector3D>(*pmt).
sub(center);
 
  181         out<<
"<position name=\"CathodPosition"<<pmt->getID()<<
"_"<<module->getID()<<
"\" unit=\"m\" x=\""<<vec.
getX()<<
"\" y=\""<<vec.
getY()<<
"\" z=\""<<vec.
getZ()<<
"\"/>\n";
 
  182         out<<
"<rotation name=\"CathodRotation"<<pmt->getID()<<
"_"<<module->getID()<<
"\" unit=\"deg\" x=\""<<
GetXrotationG4(*pmt)<<
"\" y=\""<<
GetYrotationG4(*pmt)<<
"\" z=\"0.000000\"/>\n";
 
  183         out<<
"<constant name=\"CathodID_"<<PMTs_NO<<
"\" value=\""<<pmt->getID()<<
"\"/>\n";
 
  189     out<<
"<position name=\"OMShift\" unit=\"m\" x=\"0\" y=\"0\" z=\"0.0392\"/>\n";
 
  191     out<<
"<!-- end of DU position definitions -->\n<position name=\"CrustPosition\"   unit=\"m\" x=\"0\" y=\"0\" z=\""<<Crust_Z_position<<
"\"/>\n";
 
  194     out<<
"<materials>\n";
 
  195     out<<
"</materials>\n";
 
  197     out<<
"      <box name=\"WorldBox\" lunit=\"m\" x=\"2200\" y=\"2200\" z=\"2200\"/>\n";
 
  198     out<<
"      <box name=\"CrustBox\" lunit=\"m\" x=\"2200\" y=\"2200\" z=\""<<Crust_Z_size<<
"\"/>\n";
 
  199     out<<
"      <box name=\"StoreyBox\" lunit=\"m\" x=\"0.6\" y=\"0.6\" z=\"0.6\"/>\n";
 
  200     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";
 
  201     out<<
"      <tube name=\"CathodTube\" lunit=\"cm\" aunit=\"deg\" rmin=\"0.0\" rmax=\"4.7462\" z=\"0.5\" startphi=\"0.0\" deltaphi=\"360.0\"/>\n";
 
  202     out<<
"</solids>\n\n\n";
 
  204     out<<
"<structure>\n";
 
  205     out<<
"      <volume name=\"CathodVolume\">\n";
 
  206     out<<
"              <materialref ref=\"Cathod\"/>\n";
 
  207     out<<
"              <solidref ref=\"CathodTube\"/>\n";
 
  210     out<<
"<!-- OMVolume(s) construction -->\n";
 
  212     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  214       out<<
"    <volume name=\"OMVolume"<<module->getID()<<
"\">\n";
 
  215       out<<
"            <materialref ref=\"Water\"/>\n";
 
  216       out<<
"            <solidref ref=\"OMSphere\"/>\n";
 
  218       for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
 
  220         out<<
"                  <volumeref ref=\"CathodVolume\"/>\n";
 
  221         out<<
"                  <positionref ref=\"CathodPosition"<<pmt->getID()<<
"_"<<module->getID()<<
"\"/>\n";
 
  222         out<<
"                  <rotationref ref=\"CathodRotation"<<pmt->getID()<<
"_"<<module->getID()<<
"\"/>\n";
 
  223         out<<
"          </physvol>\n";
 
  229     out<<
"<!-- StoreyVolume(s) construction -->\n";
 
  231     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  232       out<<
"    <volume name=\"StoreyVolume"<<module->getID()<<
"\">\n";
 
  233       out<<
"            <materialref ref=\"Water\"/>\n";
 
  234       out<<
"            <solidref ref=\"StoreyBox\"/>\n";
 
  236       out<<
"                    <volumeref ref=\"OMVolume"<<module->getID()<<
"\"/>\n";
 
  237       out<<
"                    <positionref ref=\"OMShift\"/>\n";
 
  239       out<<
"                    <rotationref ref=\"identity\"/>\n";
 
  240       out<<
"            </physvol>\n";
 
  244     out<<
"<!-- Crust Volume construction-->\n";
 
  245     out<<
"<volume name=\"CrustVolume\">\n";
 
  246     out<<
"      <materialref ref=\"Crust\"/>\n";
 
  247     out<<
"      <solidref ref=\"CrustBox\"/>\n";
 
  250     out<<
"<!-- World Volume construction-->\n";
 
  251     out<<
"<volume name=\"WorldVolume\">\n";
 
  252     out<<
"      <materialref ref=\"Water\"/>\n";
 
  253     out<<
"      <solidref ref=\"WorldBox\"/>\n";
 
  256     out<<
"              <volumeref ref=\"CrustVolume\"/>\n";
 
  257     out<<
"              <positionref ref=\"CrustPosition\"/>\n";
 
  258     out<<
"              <rotationref ref=\"identity\"/>\n";
 
  259     out<<
"      </physvol>\n";
 
  261     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  263       out<<
"            <volumeref ref=\"StoreyVolume"<<module->getID()<<
"\"/>\n";
 
  264       out<<
"            <positionref ref=\"PosString"<< module->getString() <<
"_Dom"<< module->getID() <<
"\"/>\n";
 
  266       out<<
"                    <rotationref ref=\"identity\"/>\n";
 
  267       out<<
"    </physvol>\n";  
 
  272     out<<
"</structure>\n";
 
  273     out<<
"<setup name=\"Default\" version=\"1.0\">\n";
 
  274     out<<
"<world ref=\"WorldVolume\"/>\n";
 
  321     if (!module.empty()) {
 
  325       for (JModule::const_iterator pmt = module.begin(); pmt != module.end(); ++pmt) {
 
  329         time_range.include(
putTime(timeRange.getLowerLimit(), calibration));
 
  330         time_range.include(
putTime(timeRange.getUpperLimit(), calibration));
 
  350     return module.size();
 
  362     int number_of_pmts = 0;
 
  364     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  368     return number_of_pmts;
 
  382     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  383       buffer.insert(module->getString());
 
  386     return buffer.size();
 
  400     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  401       buffer.insert(module->getString());
 
  418     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  419       buffer.insert(module->getFloor());
 
  422     return buffer.size();
 
  436     for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
 
  437       buffer.insert(module->getID());
 
  440     return buffer.size();
 
  465       ifstream in(file_name.c_str());
 
  475       detector.swap(buffer);
 
  491       ifstream in(file_name.c_str());
 
  547       std::ofstream out(file_name.c_str());
 
  563       std::ofstream out(file_name.c_str());
 
  595     module.resize(memo.size());
 
  658     if (module.empty()) {
 
  662       const double R  = 0.5;           
 
  664       const double st = sin(0.75*
PI);
 
  665       const double ct = cos(0.75*
PI);
 
  667       for (
int i = 0; i != 3; ++i) {
 
  669         const double phi = (2.0*
PI*i) / 3.0;
 
  670         const double cp  = cos(phi);
 
  671         const double sp  = sin(phi);
 
  694     os << 
"(" << setfill(
'0') << setw(3) << location.
getString() << 
"," << setfill(
'0') << setw(2) << location.
getFloor() << 
")";
 
  707     static const size_t NUMBER_OF_DIMENSIONS = 3;    
 
  721       if (first.size() == second.size()) {
 
  723         const size_t N = first.size();
 
  725         if (N >= NUMBER_OF_DIMENSIONS) {
 
  730           for (
size_t i = 0; i != N; ++i) {
 
  735           for (
size_t i = 0; i != NUMBER_OF_DIMENSIONS; ++i) {
 
  736             if (!orthonormalise(i)) {
 
  741           this->a00 = out[0].getX() * in[0].getX()  +  out[1].getX() * in[1].getX()  +  out[2].getX() * in[2].getX();
 
  742           this->a01 = out[0].getX() * in[0].getY()  +  out[1].getX() * in[1].getY()  +  out[2].getX() * in[2].getY();
 
  743           this->a02 = out[0].getX() * in[0].getZ()  +  out[1].getX() * in[1].getZ()  +  out[2].getX() * in[2].getZ();
 
  745           this->a10 = out[0].getY() * in[0].getX()  +  out[1].getY() * in[1].getX()  +  out[2].getY() * in[2].getX();
 
  746           this->a11 = out[0].getY() * in[0].getY()  +  out[1].getY() * in[1].getY()  +  out[2].getY() * in[2].getY();
 
  747           this->a12 = out[0].getY() * in[0].getZ()  +  out[1].getY() * in[1].getZ()  +  out[2].getY() * in[2].getZ();
 
  749           this->a20 = out[0].getZ() * in[0].getX()  +  out[1].getZ() * in[1].getX()  +  out[2].getZ() * in[2].getX();
 
  750           this->a21 = out[0].getZ() * in[0].getY()  +  out[1].getZ() * in[1].getY()  +  out[2].getZ() * in[2].getY();
 
  751           this->a22 = out[0].getZ() * in[0].getZ()  +  out[1].getZ() * in[1].getZ()  +  out[2].getZ() * in[2].getZ();
 
  755           THROW(
JException, 
"Module size" << N << 
" < " << NUMBER_OF_DIMENSIONS);
 
  760         THROW(
JException, 
"Module size" << first.size() << 
" != " << second.size());
 
  780       for (
size_t i = index + 1; i != in.size(); ++i) {
 
  781         if (in[i].getLengthSquared() > in[pos].getLengthSquared()) {
 
  786       const double u = in[pos].getLength();
 
  794           swap(in [pos], in [index]);
 
  795           swap(out[pos], out[index]);
 
  798         for (
size_t i = index + 1; i != in.size(); ++i) {
 
  800           const double dot = in[index].getDot(in[i]);
 
  802           in [i] -= dot * in [index];
 
  803           out[i] -= dot * out[index];