MdBiasCorrecter.cc
Go to the documentation of this file.
1 #include <utl/ErrorLogger.h>
2 #include <fwk/CentralConfig.h>
3 
4 #include <det/Detector.h>
5 #include <mdet/MDetector.h>
6 #include <mdet/Counter.h>
7 #include <mdet/Module.h>
8 
9 #include <evt/Event.h>
10 #include <mevt/MEvent.h>
11 #include <mevt/Counter.h>
12 #include <sevt/SEvent.h>
13 
14 #include <evt/ShowerRecData.h>
15 #include <evt/ShowerSRecData.h>
16 #include <evt/ShowerMRecData.h>
17 #include <mevt/Scintillator.h>
18 
19 #include <utl/Branch.h>
20 #include <utl/ConfigUtils.h>
21 
22 #include <fwk/LocalCoordinateSystem.h>
23 
24 #include "MdBiasCorrecter.h"
25 
26 #include <sstream>
27 
28 using namespace fwk;
29 using namespace utl;
30 using namespace MdBiasCorrecterAG;
31 
32 
33 namespace MdBiasCorrecterAG {
34 
37  {
38  // Configuration reading
39  utl::Branch config = fwk::CentralConfig::GetInstance()->GetTopBranch("MdBiasCorrecter");
40  LoadConfig(config, "biasCorrection", fBiasCorrection, false);
41  LoadConfig(config, "par0", fPar0, 0);
42  LoadConfig(config, "par1", fPar1, 0);
43  LoadConfig(config, "par2", fPar2, 0);
44  LoadConfig(config, "par3", fPar3, 0);
45  LoadConfig(config, "par4", fPar4, 0);
46 
47  return eSuccess;
48  }
49 
50 
52  MdBiasCorrecter::Run(evt::Event& event)
53  {
54  if (!fBiasCorrection) {
55  INFO("No bias correction applied.");
56  return eSuccess;
57  }
58 
59  if (!event.HasMEvent()) {
60  WARNING("Event without MEvent: nothing to be done. Skipping to next event.");
61  return eSuccess;
62  }
63 
64  INFO("Starting");
65 
66  mevt::MEvent& me = event.GetMEvent();
67  const mdet::MDetector& md = det::Detector::GetInstance().GetMDetector();
68 
69  std::ostringstream os;
70  for (auto cIt = me.CountersBegin(), cEnd = me.CountersEnd(); cIt != cEnd; ++cIt) {
71 
72  mevt::Counter& counter = *cIt;
73  const int counterId = counter.GetId();
74 
75  if (counter.IsRejected()) {
76  os.str("");
77  os << "No bias correction for the rejected counter " << counterId << ".";
78  INFO(os);
79  continue;
80  }
81 
82  if (counter.IsSilent()) {
83  os.str("");
84  os << "No bias correction for the silent counter " << counterId << ".";
85  INFO(os);
86  continue;
87  }
88 
89  os.str("");
90  os << "Processing counter " << counterId;
91  INFO(os);
92 
93  const mdet::Counter& mdc = md.GetCounter(counterId);
94 
95  for (auto mIt = counter.ModulesBegin(), mEnd = counter.ModulesEnd(); mIt != mEnd; ++mIt) {
96 
97  DEBUGLOG("Starting module loop");
98  mevt::Module& module = *mIt;
99  const int moduleId = module.GetId();
100 
101  os.str("");
102  os << "Processing module " << moduleId;
103  DEBUGLOG(os);
104 
105  const mdet::Module& mdm = mdc.GetModule(moduleId);
106 
107  if (module.IsRejected()) {
108  os.str("");
109  os << "Module " << module.GetId() << " of counter " << counterId
110  << " discarded because flagged as: " << module.GetRejectionReason();
111  WARNING(os);
112  continue;
113  }
114 
115  CorrectBias(event, module, mdm);
116 
117  }
118 
119  }
120 
121  return eSuccess;
122  }
123 
124 
125  // Private methods
126 
127  double
128  MdBiasCorrecter::CorrectionFactor(const double phi, const double theta)
129  {
130  const double a = fPar0 + fPar1*(1 + fPar2*std::cos(theta)) * std::sin(theta);
131  const double b = fPar3*(1 + fPar4*std::cos(theta)) * std::sin(theta);
132  return 1 / (1 + a + b*fabs(std::sin(phi)));
133  }
134 
135 
136  void
137  MdBiasCorrecter::CorrectBias(const evt::Event& event, mevt::Module& module, const mdet::Module& mdetModule)
138  {
139  // Shower geometry
140  const evt::ShowerSRecData& sRecShower = event.GetRecShower().GetSRecShower();
141  const utl::Point& rCore = sRecShower.GetCorePosition();
142  const utl::Vector& rAxis = sRecShower.GetAxis();
143  const utl::CoordinateSystemPtr& coreLocalCS = LocalCoordinateSystem::Create(rCore);
144  const double theta = rAxis.GetTheta(coreLocalCS);
145  const double phi = rAxis.GetPhi(coreLocalCS);
146 
147  // Orientation of module
148  const double phi0 = mdetModule.GetPhi0();
149 
150  // Apply correction to numberOfMuons and errors
151  mevt::ModuleRecData& mRecData = module.GetRecData();
152  const double numberOfMuons = mRecData.GetNumberOfEstimatedMuons();
153  const double corrfac = CorrectionFactor(phi-phi0, theta);
154  const double numberOfMuonsCor = numberOfMuons * corrfac;
155  mRecData.SetNumberOfEstimatedMuons(numberOfMuonsCor);
156  // currently no error estimate for bias corrected number of muons
157  mRecData.SetNumberOfMuonsErrorHigh(0);
158  mRecData.SetNumberOfMuonsErrorLow(0);
159 
160  std::ostringstream os;
161  os << "Uncorrected number of muons = " << numberOfMuons << ", "
162  "corrected = " << numberOfMuonsCor << ", "
163  "correction factor = " << corrfac << ", "
164  "for theta = " << theta << ", "
165  "phi = " << phi << ", "
166  "phi0 = " << phi0;
167  INFO(os);
168  }
169 
170 }
Module level reconstruction data. This class contains all data required by the muon reconstruction...
Definition: ModuleRecData.h:29
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
CounterConstIterator CountersBegin() const
Definition: MEvent.h:49
Point object.
Definition: Point.h:32
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Definition: BasicVector.h:254
bool HasMEvent() const
Interface class to access to the SD Reconstruction of a Shower.
Counter level event data.
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
std::string GetRejectionReason() const
double GetNumberOfEstimatedMuons() const
#define INFO(message)
Macro for logging informational messages.
Definition: ErrorLogger.h:161
void Init()
Initialise the registry.
bool IsRejected() const
Check if the counter is rejected.
int GetId() const
bool IsSilent() const
Check if the counter is silent.
Detector associated to muon detector hierarchy.
Definition: MDetector.h:32
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
Definition: Branch.h:107
Module level event data.
Definition: MEvent/Module.h:41
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
void SetNumberOfMuonsErrorHigh(const double e)
Array of Scintillator.
const utl::Vector & GetAxis() const
void SetNumberOfEstimatedMuons(const double m)
Number of estimated muons in a module.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
ModuleConstIterator ModulesBegin() const
Root detector of the muon detector hierarchy.
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
int GetId() const
The id of the counter.
ModuleConstIterator ModulesEnd() const
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
ModuleRecData & GetRecData()
bool IsRejected() const
double GetPhi0() const
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
Definition: ConfigUtils.h:35
Vector object.
Definition: Vector.h:30
CounterConstIterator CountersEnd() const
Definition: MEvent.h:52
const utl::Point & GetCorePosition() const
const Counter & GetCounter(int id) const
Retrieve Counter by id.
Definition: MDetector.h:68
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
Root of the Muon event hierarchy.
Definition: MEvent.h:25
void SetNumberOfMuonsErrorLow(const double e)
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)

, generated on Tue Sep 26 2023.