All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlashGeoBarycenter_tool.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 /// File: FlashGeoBarycenter_tool.cc
3 ///
4 /// Base class: FlashGeoBase.hh
5 ///
6 /// It computes the PMTs barycenter
7 /// weighted by the reconstructed number of PE
8 ///
9 ////////////////////////////////////////////////////////////////////////
10 
11 #include "art/Utilities/ToolMacros.h"
12 #include "art/Utilities/make_tool.h"
13 #include "fhiclcpp/types/Atom.h"
14 #include "art/Utilities/ToolConfigTable.h"
15 
16 #include "FlashGeoBase.hh"
17 
18 namespace lightana{
19 
21  {
22 
23  public:
24 
25  //Configuration parameters
26  struct Config {
27 
28  fhicl::Atom<unsigned int> WeightExp {
29  fhicl::Name("WeightExp"),
30  fhicl::Comment("Weight exponent for YZ barycenters")
31  };
32 
33  };
34 
35 
36  // Default constructor
37  explicit FlashGeoBarycenter(art::ToolConfigTable<Config> const& config);
38 
39  // Method to calculate the OpFlash t0
40  void GetFlashLocation(std::vector<double> pePerOpChannel,
41  double& Ycenter, double& Zcenter,
42  double& Ywidth, double& Zwidth) override;
43 
44  private:
45 
46  unsigned int fWeightExp;
47 
48  };
49 
50 
51  FlashGeoBarycenter::FlashGeoBarycenter(art::ToolConfigTable<Config> const& config)
52  : fWeightExp{ config().WeightExp() }
53  {
54  }
55 
56 
57  void FlashGeoBarycenter::GetFlashLocation(std::vector<double> pePerOpChannel,
58  double& Ycenter, double& Zcenter,
59  double& Ywidth, double& Zwidth)
60  {
61 
62  // Reset variables
63  Ycenter = Zcenter = 0.;
64  Ywidth = Zwidth = -999.;
65  double totalPE = 0.;
66  double sumy = 0., sumz = 0., sumy2 = 0., sumz2 = 0.;
67  double weight =1.;
68  for (unsigned int opch = 0; opch < pePerOpChannel.size(); opch++) {
69  // Get physical detector location for this opChannel
70  double PMTxyz[3];
72 
73  // Get weight for this channel
74  if(fWeightExp==1) weight = pePerOpChannel[opch];
75  else if(fWeightExp==2) weight = pePerOpChannel[opch]*pePerOpChannel[opch];
76  else weight = std::pow(pePerOpChannel[opch], fWeightExp);
77 
78  // Add up the position, weighting with PEs
79  sumy += weight*PMTxyz[1];
80  sumy2 += weight*PMTxyz[1]*PMTxyz[1];
81  sumz += weight*PMTxyz[2];
82  sumz2 += weight*PMTxyz[2]*PMTxyz[2];
83  totalPE += weight;
84  }
85 
86  Ycenter = sumy/totalPE;
87  Zcenter = sumz/totalPE;
88 
89  // This is just sqrt(<x^2> - <x>^2)
90  if ( (sumy2*totalPE - sumy*sumy) > 0. )
91  Ywidth = std::sqrt(sumy2*totalPE - sumy*sumy)/totalPE;
92 
93  if ( (sumz2*totalPE - sumz*sumz) > 0. )
94  Zwidth = std::sqrt(sumz2*totalPE - sumz*sumz)/totalPE;
95  }
96 
97 }
98 
99 DEFINE_ART_CLASS_TOOL(lightana::FlashGeoBarycenter)
BEGIN_PROLOG vertical distance to the surface Name
void GetFlashLocation(std::vector< double > pePerOpChannel, double &Ycenter, double &Zcenter, double &Ywidth, double &Zwidth) override
FlashGeoBarycenter(art::ToolConfigTable< Config > const &config)