Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JInterDomCal_utils.hh
Go to the documentation of this file.
1 #ifndef __CALIB_UTIL__
2 #define __CALIB_UTIL__
3 
4 #include "Detector.hh"
5 #include "NBRun.hh"
6 #include "Physics.hh"
7 
8 /**
9  * \author rgruiz
10  */
11 
12 
13 
14 /**
15  * It uses the pmts from a source module and from a target module.
16  * For each possible pair source-target, it computes the a factor that needs to be added to the t0s of all the PMTs in the target module. Finally it computes the median
17  *
18  * \param det detector with old t0s
19  * \param srcs SUPERPMTs of the emitter DOM
20  * \param tgts SUPERPMTs of the receiver DOM
21  * \return Median correction factor
22  */
24 
25  double c_w = c_water_genhen() ;
26 
27  //double c_w = c_water(470 , 3000);
28 
29  vector<double> corrections ;
30 
31  const JPMTRouter pmtRouter(*det);
32 
33  for (auto & src : srcs){
34 
35  JPMT src_pmt = src->getPMT() ;
36 
37  NBPulse* src_pulse = src->getNBPulse() ;
38 
39  for(auto & tgt : tgts){
40 
41  JPMT tgt_pmt = tgt->getPMT() ;
42 
43  NBPulse* tgt_pulse = tgt->getNBPulse() ;
44 
45  double distance = get_PMT_distance(src_pmt , tgt_pmt) ;
46 
47  double t_flight = distance / c_w ;
48 
49  double delta_traw = tgt_pulse->getPeakTime() - src_pulse->getPeakTime() ;
50 
51  double delta_t0 = t_flight - delta_traw ;
52 
53  double delta_t0_old = pmtRouter.getPMT(JObjectID(tgt_pmt.getID())).getT0() - pmtRouter.getPMT(JObjectID(src_pmt.getID())).getT0() ;
54 
55  corrections.push_back(delta_t0 - delta_t0_old) ;
56 
57  }
58 
59  }
60 
61  sort (corrections.begin() , corrections.end()) ;
62 
63  int index = int(0.5*corrections.size()) ;
64 
65  return corrections[index] ;
66 
67 }
68 
69 /**
70  * Produces a new detector file by updating the existing t0s of the PMTs
71  *
72  * \param detector Old detector
73  * \param SuperMods The SuperModules used to calibrate the detector
74  * \return calibrated detector
75  */
76 inline JDetector Update_Detector(JDetector detector , const vector< SuperModule* > & SuperMods){
77 
78  JDetector new_det = detector ;
79 
80  for(auto & sm : SuperMods){
81 
82  JModuleLocation tgt_loc = sm->getDom().getLocation() ;
83 
84  if(sm->get_good_sources().size()>0){
85 
86  pair < SuperModule* , vector < SuperPMT* > > src = sm->get_closest_good_source();
87 
88  vector < SuperPMT* > srcs = src.first->get_ref_pmts() ;
89 
90  vector < SuperPMT* > tgts = src.second ;
91 
92  double correction = computeMedianCorrection(&new_det , srcs , tgts) ;
93 
94  int nPMTs = getNumberOfPMTs(detector)/getNumberOfModules(detector) ;
95 
96  for(int j=0 ; j < nPMTs ; j++){
97 
98  new_det.getModule(tgt_loc).getPMT(j).setT0(new_det.getModule(tgt_loc).getPMT(j).getT0() + correction ) ;
99 
100  }
101 
102  }
103 
104  }
105 
106  return new_det;
107 
108 }
109 
110 
111 #endif
Router for direct addressing of PMT data in detector data structure.
Definition: JPMTRouter.hh:33
const JModuleLocation & getLocation() const
Get location.
Detector data structure.
Definition: JDetector.hh:77
Analyzes the signal of a nanobeacon in a PMT.
Definition: NBPulse.hh:33
JDetector Update_Detector(JDetector detector, const vector< SuperModule * > &SuperMods)
Produces a new detector file by updating the existing t0s of the PMTs.
int getNumberOfPMTs(const JModule &module)
Get number of PMTs.
const JPMT & getPMT(const JPMTAddress &address) const
Get PMT.
Definition: JPMTRouter.hh:90
double get_PMT_distance(JPMT src_pmt, JPMT tgt_pmt)
Calculate the distance between two JPMTs in the detector.
Definition: Detector.hh:133
int getID() const
Get identifier.
Definition: JObjectID.hh:54
Data structure for PMT geometry and calibration.
Definition: JPMT.hh:52
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
void setT0(const double t0)
Set time offset.
Auxiliary class for object identification.
Definition: JObjectID.hh:27
double computeMedianCorrection(JDetector *det, vector< SuperPMT * > srcs, vector< SuperPMT * > tgts)
It uses the pmts from a source module and from a target module.
double getPeakTime()
Get the arrival time of the nanobeacon pulse.
Definition: NBPulse.hh:554
int getNumberOfModules(const JDetector &detector)
Get number of modules.
double c_water_genhen()
Definition: Physics.hh:25
Logical location of module.
double getT0() const
Get time offset.