RdLDFMultiFitter.cc
Go to the documentation of this file.
1 #include "RdLDFMultiFitter.h"
2 
3 
4 /* ################################################################################################
5 
6  Removed support for this module from framework and adst with revision 34470 (01.11.21)
7 
8 #################################################################################################*/
9 
10 #include <cmath>
11 #include <sstream>
12 
13 #include <fwk/CentralConfig.h>
14 
15 #include <utl/config.h>
16 #include <utl/ErrorLogger.h>
17 #include <utl/Reader.h>
18 
19 #include <utl/Vector.h>
20 #include <utl/Point.h>
21 #include <utl/BasicVector.h>
22 #include <utl/GeometryUtilities.h>
23 #include <utl/RadioGeometryUtilities.h>
24 #include <utl/CoordinateSystemPtr.h>
25 
26 #include <utl/AxialVector.h>
27 
28 #include <evt/Event.h>
29 #include <evt/ShowerRecData.h>
30 #include <evt/ShowerSRecData.h>
31 #include <evt/ShowerRRecData.h>
32 
33 #include <revt/REvent.h>
34 #include <revt/Station.h>
35 #include <revt/Header.h>
36 #include <revt/StationRecData.h>
37 
38 #include <det/Detector.h>
39 #include <rdet/RDetector.h>
40 #include <det/VManager.h>
41 
43 #include "TGraphErrors.h"
44 #include "TF1.h"
45 #include "TVector3.h"
46 #include "TMath.h"
47 #include "TColor.h"
48 #include "TFitResultPtr.h"
49 #include "TFitResult.h"
50 
52 #include <cstddef>
53 #include <string>
54 #include <cstdlib>
55 #include <iostream>
56 #include <sstream>
57 #include <iomanip>
58 #include <stdlib.h>
59 #include <sys/stat.h>
60 
61 using namespace revt;
62 using namespace fwk;
63 using namespace utl;
64 using namespace det;
65 using std::string;
66 using std::vector;
67 
68 namespace RdLDFMultiFitter {
69 
71  fInfoLevel(eNone),
72  fParA200(0),
73  fParA201(0),
74  fParA210(0),
75  fParA211(0),
76  fEnergyEstimatorDist(0),
77  fEnergyEstimatorPower(0),
78  fEnergyEstimatorCoeff(0)
79  {
80  }
81 
82  RdLDFMultiFitter::~RdLDFMultiFitter()
83  {
84  }
85 
87  {
88  INFO("RdLDFMultiFitter::Init()");
89 
91  utl::Branch topBranch = CentralConfig::GetInstance()->GetTopBranch("RdLDFMultiFitter");
92 
93  topBranch.GetChild("InfoLevel").GetData(fInfoLevel);
94  topBranch.GetChild("parA200").GetData(fParA200);
95  topBranch.GetChild("parA201").GetData(fParA201);
96  topBranch.GetChild("parA210").GetData(fParA210);
97  topBranch.GetChild("parA211").GetData(fParA211);
98  topBranch.GetChild("energyEstimatorDist").GetData(fEnergyEstimatorDist);
99  topBranch.GetChild("energyEstimatorPower").GetData(fEnergyEstimatorPower);
100  topBranch.GetChild("energyEstimatorCoeff").GetData(fEnergyEstimatorCoeff);
101 
103  Branch models = topBranch.GetChild("Models");
104 
105  for (Branch curmodel = models.GetFirstChild(); curmodel; curmodel = curmodel.GetNextSibling()) {
106  if (curmodel.GetName() == "Model") {
107  Model modcontainer;
108  modcontainer.name = VManager::FindComponent<string>("name", curmodel.GetAttributes());
109  for(Branch curp = curmodel.GetFirstChild(); curp; curp = curp.GetNextSibling()) {
110  if(curp.GetName() == "formula") {
111  curp.GetData(modcontainer.formula);
112  }
113  if(curp.GetName() == "color") {
114  curp.GetData(modcontainer.color);
115  }
116  if(curp.GetName() == "parameter") {
117  parameter p;
118  p.id = VManager::FindComponent<int>("id", curp.GetAttributes());
119  p.name = VManager::FindComponent<string>("name", curp.GetAttributes());
120  p.minval = VManager::FindComponent<double>("minval", curp.GetAttributes());
121  p.maxval = VManager::FindComponent<double>("maxval", curp.GetAttributes());
122  p.zenithCorrection = VManager::FindComponent<double>("zenithCorrection", curp.GetAttributes());
123  curp.GetData(p.startvalues);
124  modcontainer.parameters.push_back(p);
125  }
126  }
127  fModels.push_back(modcontainer);
128  }
129  }
130 
131 
132  return eSuccess;
133  }
134 
135  VModule::ResultFlag RdLDFMultiFitter::Run(evt::Event& event)
136  {
137 
139  if(!event.HasREvent()) {
140  WARNING("No radio event found!");
141  return eSuccess;
142  }
143 
145  REvent& rEvent = event.GetREvent();
146  evt::ShowerRRecData& showerrrec = event.GetRecShower().GetRRecShower();
147 
149  // Warning / TODO: need functionality for non-radio cores
150  if(!showerrrec.HasCorePosition() || !showerrrec.HasAxis()) {
151  WARNING("No core or axis. LDF Fit can not be performed.");
152  return eSuccess;
153  }
154 
156  const rdet::RDetector& rDetector = det::Detector::GetInstance().GetRDetector();
157 
159  const utl::Vector showerAxis = showerrrec.GetAxis();
160  const utl::Point coordinateOrigin = showerrrec.GetCoordinateOrigin();
161  const utl::Point core = showerrrec.GetCorePosition();
162 
164  int Nant = showerrrec.GetParameter(revt::eNumberOfStationsWithPulseFound);
166  int curAnt = 0;
168  double distance[Nant], fieldStr[Nant], distanceEr[Nant], fieldStrEr[Nant];
169  double distancetoshoweraxis = 0.0;
170 
171  // Warning / TODO: #warning Iterator has to be changed to stations with pulse
172  for(REvent::CandidateStationIterator sIt = rEvent.CandidateStationsBegin(); sIt != rEvent.CandidateStationsEnd(); ++sIt) {
173 
175  Station& station = *sIt;
176 
177  const StationRecData& sRec = station.GetRecData();
178  const utl::Point sPos = rDetector.GetStation(station).GetPosition();
179 
180  if(!sRec.GetPulseFound())
181  continue;
182 
184  distancetoshoweraxis = utl::RadioGeometryUtilities::GetDistanceToAxis(showerAxis, core, sPos);
185  distance[curAnt] = distancetoshoweraxis;
186  distanceEr[curAnt] = 0;
187  // Warning / TODO: #warning need to define error of distance, currently put to zero (case of Tunka-Rex)
188  fieldStr[curAnt] = sRec.GetParameter(revt::eSignal);
189  fieldStrEr[curAnt] = sRec.GetParameterError(revt::eSignal);
190 
192  ++curAnt;
193  }
194 
196  TGraphErrors *LateralDistribution = new TGraphErrors (Nant, distance,fieldStr,distanceEr,fieldStrEr);
197 
199  TF1 *energy_estimator;
200  energy_estimator = new TF1("exp_formula", "[0]*exp(-[1]*(x-[2]))", 0, 5000);
201  // Warning / TODO: #warning domain is fixed to (0, 5000 m)
202  energy_estimator->SetParLimits(0,0.,1.);
203  energy_estimator->SetParameter(0,fieldStr[0]);
204  energy_estimator->FixParameter(2,fEnergyEstimatorDist);
205  LateralDistribution->Fit(energy_estimator, "RS");
206 
208  double estimated_energy = fEnergyEstimatorCoeff * pow(energy_estimator->GetParameter(0), fEnergyEstimatorPower);
209 
211  vector<TF1> ldfResult;
212  vector<TFitResult> ldfFitResult;
213 
215  for (vector<Model>::iterator m_it = fModels.begin() ; m_it != fModels.end(); ++m_it) {
216 
217  TF1 *fitfuncExp;
218 
219  fitfuncExp = new TF1(m_it->name.c_str(),m_it->formula.c_str(), 0, 5000);
220  // Warning / TODO: #warning: domain is fixed to (0, 5000 m)
221  fitfuncExp->SetLineColor(TColor::GetColor(m_it->color.c_str()));
222 
224  for(vector<parameter>::iterator p_it = m_it->parameters.begin(); p_it != m_it->parameters.end(); ++p_it) {
225 
226  fitfuncExp->SetParName(p_it->id,p_it->name.c_str());
227  fitfuncExp->SetParLimits(p_it->id,p_it->minval,p_it->maxval);
228 
230  if(p_it->zenithCorrection) {
231  fitfuncExp->FixParameter(p_it->id,ZenithCorrection(showerrrec.GetZenith(), estimated_energy));
232  }
233 
234  }
235 
237  TFitResultPtr fitresult = LateralDistribution->Fit(fitfuncExp, "RS");
238  ldfResult.push_back(*fitfuncExp);
239  ldfFitResult.push_back(*fitresult);
240 
242  fitfuncExp->Delete();
243  }
244 
246  showerrrec.SetRdLDF(ldfResult);
247  showerrrec.SetRdLDFFitResult(ldfFitResult);
248 
249  return eSuccess;
250  }
251 
252  double RdLDFMultiFitter::ZenithCorrection(double zenith, double energy) {
253  return p0(energy) + p1(energy)*cos(zenith);
254  }
255 
256  double RdLDFMultiFitter::p0(double energy) {
257  return fParA200 + fParA201*energy;
258  }
259 
260  double RdLDFMultiFitter::p1(double energy) {
261  return fParA210 + fParA211*energy;
262  }
263 
264  VModule::ResultFlag RdLDFMultiFitter::Finish()
265  {
266  INFO("RdLDFMultiFitter::Finish()");
267 
268  return eSuccess;
269  }
270 
271 }
Branch GetTopBranch() const
Definition: Branch.cc:63
Class to access station level reconstructed data.
utl::Vector GetAxis() const
Returns vector of the shower axis.
Point object.
Definition: Point.h:32
static double GetDistanceToAxis(const utl::Vector &ShowerAxis, const utl::Point &CorePosition, const utl::Point &AntennaPosition)
computes the distance from the antenna position to the shower &quot;line&quot; defined by the core position and...
boost::filter_iterator< CandidateStationFilter, AllStationIterator > CandidateStationIterator
Iterator over all CandidateStations (i.e., HasSignal, HasNoSignal)
Definition: REvent.h:141
Report success to RunController.
Definition: VModule.h:62
double fEnergyEstimatorDist
xml settings: parameters for energy pre-estimator
StationRecData & GetRecData()
Get station level reconstructed data.
CandidateStationIterator CandidateStationsEnd()
Definition: REvent.h:146
Interface class to access to the Radio part of an event.
Definition: REvent.h:42
std::vector< parameter > parameters
Configuration of parameters (for fitting)
std::string name
Name (displayed in EventBrowser)
Interface class to access to the RD Reconstruction of a Shower.
double GetParameterError(const Parameter i) const
bool HasCorePosition() const
Return true if all 3 core parameter are set.
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
double minval
Lower bound (for fit)
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
double pow(const double x, const unsigned int i)
std::string color
Color (LDF curve in EventBrowser)
bool HasREvent() const
int zenithCorrection
Fix parameter using zenith information and energy pre-estimator (if 1)
Detector description interface for RDetector-related data.
Definition: RDetector.h:46
Branch GetNextSibling() const
Get next sibling of this branch.
Definition: Branch.cc:284
std::string formula
Formula (in TF1 ROOT format)
unsigned int id
ID (corresponds to one in TF1)
int fInfoLevel
xml settings: info level (0 - 5)
Class representing a document branch.
Definition: Branch.h:107
utl::Point GetCoordinateOrigin() const
class to hold data at the radio Station level.
double GetZenith() const
returns the zenith angle (from the wave fit)
bool HasAxis() const
Return true if all 3 axis parameter are set.
CandidateStationIterator CandidateStationsBegin()
Definition: REvent.h:144
double maxval
Upper bound (for fit)
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
void GetData(bool &b) const
Overloads of the GetData member template function.
Definition: Branch.cc:644
double GetParameter(const Parameter i) const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
Configuration of fit parameters.
Model (parametrization) used for fitting.
Vector object.
Definition: Vector.h:30
utl::Point GetCorePosition() const
returns pointer of the position vector of the core in the reference coor system
double GetParameter(const Parameter i) const
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
double fParA200
xml settings: parametrization fro zenith correction
utl::Point GetPosition() const
Tank position in Site Cartesian Coordinates.
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: RDetector.cc:141
double ZenithCorrection(double zenith, double energy)
return value of fixed parameters corresponding to pre-estimated energy and zenith angle of arrival di...
std::string name
Name (displayed in EventBrowser)
std::vector< Model > fModels
xml settings: list of models
std::vector< double > startvalues
Starting fit values.

, generated on Tue Sep 26 2023.