/*############################################################# *# # *# Author: G.Carminati # *# # *############################################################# */ #ifdef _ANTCC_ENABLED__ #include "ReadDetector.hh" ReadDetector::ReadDetector(std::string filename) { if(filename.empty() ) { std::cout << "ReadDetector::ReadDetector = nofilename provided!" << std::endl; } read(filename); } void ReadDetector::read(std::string FileName) { event buffer; int ntags, ierr, i; std::string line; /* open the detector file */ std::ifstream inDet; inDet.open(FileName.c_str()); if (inDet.fail() ) { std::cout << "ReadDetector::read = Cannot open file " << FileName << std::endl; } /* read the header */ ierr = buffer.read(inDet); if (ierr != 0 ) { std::cout << "ReadDetector::read = Error " << ierr << " reading detector file " << std::endl; } if (!buffer.run_header() ) std::cout << "ReadDetector::read = No run header found!" << std::endl; /* read enviroment info */ ntags=buffer.ndat("environment"); if(ntags==0) std::cout << "ReadDetector::read = no environment defined!" << std::endl; line = buffer.next("environment"); std::istringstream iline(line.c_str()); iline >> latitude_ >> longitude_ >> magnetic_declination_ >> surface_z >> ground_z; /* read the detector event */ ierr = buffer.findev(inDet, 1); if(ierr != 0) { if (ierr == 2) { std::cout << "ReadDetector::read = EoF reached on input files!" << std::endl; } else std::cout << "ReadDetector::read = Error reading event" << std::endl; } /* read OM_cluster_data info */ ntags=buffer.ndat("OM_cluster_data"); if(ntags==0) { std::cout << "ReadDetector::read = no OM_cluster_data defined!" << std::endl; } for(i=0; i> id >> x_ >> y_ >> z_ >> phi_ >> theta_ >> psi_; Vec3D pos(x_, y_, z_); OM_clusters_[id] = pos; } inDet.close(); } Vec3D ReadDetector::compute_cg() { Vec3D CG(0., 0., 0.); for(cluster_map::iterator i=OM_clusters_.begin(); i!=OM_clusters_.end();++i) { CG.x += (*i).second.x; CG.y += (*i).second.y; CG.z += (*i).second.z; } CG.x /= OM_clusters_.size(); CG.y /= OM_clusters_.size(); CG.z /= OM_clusters_.size(); return CG; } double ReadDetector::compute_radius(const Vec3D& ref) { double max_radius = 0.; for(cluster_map::iterator i=OM_clusters_.begin(); i!=OM_clusters_.end();++i) { double x0 = (*i).second.x - ref.x; double y0 = (*i).second.y - ref.y; double r = sqrt(x0*x0 + y0*y0); if (r > max_radius) max_radius = r; } return max_radius; } Vec2D ReadDetector::compute_Z(const Vec3D& ref) { double min_Z = 0.; double max_Z = 0.; Vec2D z(0., 0.); for(cluster_map::iterator i=OM_clusters_.begin(); i!=OM_clusters_.end();++i) { double z0 = (*i).second.z - ref.z; if (z0 < min_Z) min_Z = z0; if (z0 > max_Z) max_Z = z0; } z.x = min_Z; z.y = max_Z; return z; } #endif