Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Detector.hh
Go to the documentation of this file.
1 #ifndef __DETECTOR__
2 #define __DETECTOR__
3 
4 
5 #include "JDetector/JDetector.hh"
8 #include "JTools/JQuantile.hh"
9 
10 #include <tuple>
11 
12 using namespace JDETECTOR ;
13 using namespace std;
14 
15 
16 /**
17  * \author rgruiz
18  */
19 
20 
21 
22 /**
23  * Loads the content of a detector file in a JDetector object
24  *
25  * \param detectorFile The name of a .detx
26  * \return a JDetector object with the information of the file name
27  */
28 inline JDetector loadDetector(string detectorFile){
29 
30  JDetector detector;
31 
32  try {
33 
34  load(detectorFile, detector);
35 
36  }
37 
38  catch(const JException& error) {
39 
40  cerr << "FATAL ERROR. Could not open detector file '" << detectorFile << "'." << endl ;
41 
42  exit(1) ;
43 
44  }
45 
46  return detector ;
47 
48 }
49 
50 
51 
52 /**
53  * Loops over the floors in the string chosen by the user. At each
54  * iteration "i" this function calculates:
55  * dt = t0_tgt[i+1] - t0_ref[i]
56  * where t0_tgt is the t0 of the target PMT and t0_ref
57  * is the t0 of the reference PMT (the closest to the nanobeacon).
58  * The result is stored in a vector of dimension nFloors - 1 and this vector is returned.
59  *
60  * \param detector The name of a .detx
61  * \param strNr String number
62  * \param ref_pmt number of reference pmt
63  * \param tgt_pmt number of target pmt
64  * \return a JDetector object with the information of the file name
65  */
66 inline vector<double> getDetFile_t0_differences(int strNr , JDetector detector , int ref_pmt , int tgt_pmt){
67 
68  int nFloors = getNumberOfFloors(detector) ;
69 
70  vector<double> T0_diff (nFloors - 1) ;
71 
72  for (int i=1 ; i< nFloors ; i++) {
73 
74  T0_diff[i-1] = detector.getModule(JModuleLocation(strNr , i+1 )).getPMT(tgt_pmt).getT0() - detector.getModule(JModuleLocation(strNr , i )).getPMT(ref_pmt).getT0() ;
75 
76  }
77 
78  return T0_diff ;
79 
80 }
81 
82 
84 
85  int nFloors = getNumberOfFloors(detector) ;
86 
87  vector< tuple <double , double , double> > t0_vs_depth (nFloors) ;
88 
89  JTOOLS::JQuantile Q ("") ;
90 
91  for (int i = 1 ; i<nFloors+1 ; i++){
92 
93  JModule module = detector.getModule(JModuleLocation(strNr , i)) ;
94 
95  double depth = module.getPosition().getZ() ;
96 
97  JTOOLS::JQuantile q ("") ;
98 
99  for (int j = 0 ; j < getNumberOfPMTs(module) ; j++){
100 
101  JPMT pm = module.getPMT(j) ;
102 
103  q.put(pm.getT0()) ;
104 
105  }
106 
107  tuple < double , double , double > t (depth , q.getMean() , q.getSTDev()) ;
108 
109  t0_vs_depth[i-1] = t ;
110 
111  Q.put(q.getMean()) ;
112 
113  }
114 
115  for (auto & t: t0_vs_depth){
116 
117  get<1>(t) -= Q.getMean() ;
118 
119  }
120 
121  return t0_vs_depth ;
122 
123 }
124 
125 
126 /**
127  * Calculate the distance between two JPMTs in the detector
128  *
129  * \param src_pmt One pmt
130  * \param tgt_pmt Other pmt
131  * \return distance between both JPMTs
132  */
133 inline double get_PMT_distance(JPMT src_pmt , JPMT tgt_pmt){
134 
135  const JPosition3D pmt1_pos = src_pmt.getPosition() ;
136 
137  const JPosition3D pmt2_pos = tgt_pmt.getPosition() ;
138 
139  const JVector3D dist(pmt1_pos - pmt2_pos) ;
140 
141  return dist.getLength() ;
142 
143 }
144 
145 
146 /**
147  * Prints the t0 of all the PMTs in a DU
148  *
149  * \param detector A JDetector
150  * \param strNr The DU number
151  */
152 inline void Print_Detector(JDetector& detector , int strNr){
153 
154  int nFloors = 18 ;
155 
156  int nPMTs = 31 ;
157 
158  JModuleRouter moduleRouter(detector) ;
159 
160  for(int i=1 ; i < nFloors ; i++){
161 
162  JModule dom = detector.getModule(JModuleLocation(strNr , i+1)) ;
163 
164  for(int j=0 ; j < nPMTs ; j++){
165 
166  cout <<dom.getPMT(j).getT0() << endl;
167 
168  }
169 
170  }
171 
172 }
173 
174 #endif
General exception.
Definition: JException.hh:40
vector< tuple< double, double, double > > get_t0_offsets_vs_depth(int strNr, const JDetector &detector)
Definition: Detector.hh:83
Data structure for a composite optical module.
Definition: JModule.hh:47
Detector data structure.
Definition: JDetector.hh:77
void put(const double x, const double w=1.0)
Put value.
Definition: JQuantile.hh:77
Router for direct addressing of module data in detector data structure.
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
Data structure for detector geometry and calibration.
Quantile calculator.
Definition: JQuantile.hh:34
double getSTDev() const
Get standard deviation.
Definition: JQuantile.hh:159
Data structure for vector in three dimensions.
Definition: JVector3D.hh:32
double get_PMT_distance(JPMT src_pmt, JPMT tgt_pmt)
Calculate the distance between two JPMTs in the detector.
Definition: Detector.hh:133
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:52
int getNumberOfFloors(const JDetector &detector)
Get number of floors.
JDetector loadDetector(string detectorFile)
Loads the content of a detector file in a JDetector object.
Definition: Detector.hh:28
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
const JPosition3D & getPosition() const
Get position.
Definition: JPosition3D.hh:129
void Print_Detector(JDetector &detector, int strNr)
Prints the t0 of all the PMTs in a DU.
Definition: Detector.hh:152
double getLength() const
Get length.
Definition: JVector3D.hh:242
const JPMT & getPMT(const int index) const
Get PMT.
Definition: JModule.hh:141
const JModule & getModule(const JModuleAddress &address) const
Get module parameters.
Definition: JDetector.hh:180
double getMean() const
Get mean value.
Definition: JQuantile.hh:131
Direct access to module in detector data structure.
Data structure for position in three dimensions.
Definition: JPosition3D.hh:35
double getZ() const
Get z position.
Definition: JVector3D.hh:113
Logical location of module.
double getT0() const
Get time offset.
vector< double > getDetFile_t0_differences(int strNr, JDetector detector, int ref_pmt, int tgt_pmt)
Loops over the floors in the string chosen by the user.
Definition: Detector.hh:66