1 #include <utl/ErrorLogger.h>
2 #include <fwk/CentralConfig.h>
5 #include <evt/ShowerRecData.h>
6 #include <evt/ShowerSRecData.h>
7 #include <mevt/MEvent.h>
8 #include <mevt/Counter.h>
9 #include <utl/ConfigUtils.h>
10 #include <fwk/LocalCoordinateSystem.h>
11 #include <utl/CoordinateSystem.h>
12 #include <utl/Branch.h>
24 namespace MdMuonIntegratorAG {
31 LoadConfig(config,
"baseLineLowLimit", fBaseLineLowLimit, 10);
32 LoadConfig(config,
"baseLineHighLimit", fBaseLineHighLimit, 210);
34 LoadConfig(config,
"lowThreshold", fLowThreshold, 2);
35 LoadConfig(config,
"highThreshold", fHighThreshold, 8);
37 LoadConfig(config,
"showerMaxWidth", fShowerMaxWidth, 200);
38 LoadConfig(config,
"delayBinaryADC", fDelayBinaryADC, 24);
48 WARNING(
"\n+++++++++\nEvent without MEvent: nothing to be done. Skipping to next event.\n++++++++++\n");
56 std::ostringstream os;
60 const int counterId = counter.
GetId();
64 os <<
"Skipping the rejected counter " << counterId <<
" .";
70 os <<
"Processing counter " << counterId;
77 const int moduleId = module.
GetId();
80 os <<
"Processing module " << moduleId;
85 os <<
"Module " << module.
GetId() <<
" of counter " << counterId;
91 GetMuonsWithADC(event, module);
110 int leadingMuonBin = 0;
112 GetModuleFirstMuon(leadingMuonBin, lastMuonBin, module);
114 double cosZenith = 1;
115 if (event.
HasRecShower() &&
event.GetRecShower().HasSRecShower()) {
129 GetSignalCharge(charge, leadingMuonBin, lastMuonBin, windowSize, adcTraceLG);
136 double errorHigh = 0;
138 GetUncertainties(errorLow, errorHigh, muons, resolution);
147 std::ostringstream os;
148 os <<
"Number of muons ADC LG = " << muons <<
", "
149 "Error Low = " << errorLow <<
", Error high = " << errorHigh <<
" "
160 GetSignalCharge(charge, leadingMuonBin, lastMuonBin, windowSize, adcTraceHG);
167 double errorHigh = 0;
169 GetUncertainties(errorLow, errorHigh, muons, resolution);
178 std::ostringstream os;
179 os <<
"Number of muons ADC HG = " << muons <<
", "
180 "Error Low = " << errorLow <<
", Error high = " << errorHigh <<
" "
189 MdMuonIntegrator::GetModuleFirstMuon(
int& leadingMuonBin,
int& lastMuonBin,
mevt::Module& module)
193 for (
unsigned int i = 0; i < channelsOn.
GetSize(); ++i) {
194 if (channelsOn.
At(i) > 0) {
195 if (leadingMuonBin == 0) {
205 MdMuonIntegrator::GetSignalCharge(
double& charge,
206 const double leadingMuonBin,
const double lastMuonBin,
207 const unsigned int windowSize,
const utl::TraceUSI& adcTrace)
209 unsigned int minBin = 0;
210 unsigned int maxBin = 0;
211 int start = leadingMuonBin * windowSize / 2;
212 int end = (lastMuonBin + 1) * windowSize / 2;
216 double baseStdDev = 0;
219 for (j = fBaseLineLowLimit; j < fBaseLineHighLimit; ++j)
220 base += adcTrace.
At(j);
222 base /= fBaseLineHighLimit - fBaseLineLowLimit;
224 for (j = fBaseLineLowLimit; j < fBaseLineHighLimit; ++j)
225 baseStdDev +=
pow(adcTrace.
At(j) - base, 2);
227 baseStdDev /= fBaseLineHighLimit - fBaseLineLowLimit;
228 baseStdDev =
sqrt(baseStdDev);
230 if (leadingMuonBin > 0) {
233 double thrhigh = baseStdDev * fHighThreshold;
234 double thrlow = baseStdDev * fLowThreshold;
235 unsigned int thrBin = 0;
239 for (i = start; i < adcTrace.
GetSize(); ++i) {
240 if (thrBin == 0 && adcTrace.
At(i) - base >= thrhigh) {
250 for (
int i = thrBin; i > start+10; --i) {
251 if (adcTrace.
At(i) - base > thrlow) {
253 }
else if (adcTrace.
At(i-1) - base < thrlow && adcTrace.
At(i-2) - base < thrlow)
257 maxBin = minBin + fShowerMaxWidth;
258 if (maxBin > adcTrace.
GetSize() - 1)
259 maxBin = adcTrace.
GetSize() - 10;
262 for (i = minBin; i <= maxBin; ++i) {
265 bool exitLoop =
true;
266 for (
unsigned int j = i+1; j < i+6; ++j) {
267 if (adcTrace.
At(j) - base > thrlow) {
270 for (
unsigned int k = j+1; k < maxBin; ++k) {
271 if (adcTrace.
At(k) - base > thrhigh) {
280 charge += adcTrace.
At(i) - base;
285 minBin = start + fDelayBinaryADC;
286 maxBin = end + windowSize / 2. + fDelayBinaryADC;
288 if (maxBin > adcTrace.
GetSize())
289 maxBin = adcTrace.
GetSize() - 10;
290 for (i = minBin; i <= maxBin; ++i) {
291 if (adcTrace.
At(i) - base) {
292 charge += adcTrace.
At(i) - base;
301 MdMuonIntegrator::GetUncertainties(
double& errorLow,
double& errorHigh,
const double nMu,
const double resolution)
307 double xmin = (nMu -
sqrt(nMu)) / 2;
308 double xmax = nMu * 2;
310 double stepLow = (nMu - xmin) / 100;
311 double stepHigh = (xmax - nMu) / 100;
313 double poissonWeight = 0;
318 while (poissonWeight < s) {
319 pmin = nMu - i*stepLow;
320 poissonWeight = 2*((pmin - nMu) + nMu * log(nMu / pmin));
325 while (poissonWeight < s) {
326 pmax = nMu + i * stepHigh;
327 poissonWeight = 2*((pmax - nMu) + nMu * log(nMu / pmax));
331 errorLow =
sqrt(
pow(nMu - pmin, 2) + nMu *
pow(resolution, 2));
332 errorHigh =
sqrt(
pow(pmax - nMu, 2) + nMu *
pow(resolution, 2));
Module level reconstruction data. This class contains all data required by the muon reconstruction...
T & At(const SizeType i)
trace entry with checked address
CounterConstIterator CountersBegin() const
bool HasIntegratorBTrace() const
void SetNumberOfMuonsADCErrorHighHG(const double e)
Interface class to access to the SD Reconstruction of a Shower.
void SetNumberOfMuonsADCErrorLowHG(const double e)
Counter level event data.
bool HasRecShower() const
double GetCosTheta(const CoordinateSystemPtr &coordinateSystem) const
cos of zenith (theta) angle
std::string GetRejectionReason() const
#define INFO(message)
Macro for logging informational messages.
void SetTotalChargeLG(const double charge)
void Init()
Initialise the registry.
bool IsRejected() const
Check if the counter is rejected.
double pow(const double x, const unsigned int i)
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
Class representing a document branch.
utl::TraceUI & GetChannelsOn()
Number of windows with a signal in a module.
void SetNumberOfMuonsADCErrorLowLG(const double e)
#define DEBUGLOG(message)
Macro for logging debugging messages.
void SetTotalChargeHG(const double charge)
const utl::Vector & GetAxis() const
#define WARNING(message)
Macro for logging warning messages.
void SetNumberOfMuonsADCErrorHighLG(const double e)
utl::TraceUSI & GetIntegratorATrace()
bool HasIntegratorATrace() const
void SetNumberOfEstimatedMuonsADCHG(const double m)
InternalModuleCollection::ComponentIterator ModuleIterator
ModuleConstIterator ModulesBegin() const
void SetNumberOfEstimatedMuonsADCLG(const double m)
Number of estimated muons in a module with ADC channel.
ResultFlag
Flag returned by module methods to the RunController.
int GetId() const
The id of the counter.
unsigned int GetWindowSize() const
ModuleConstIterator ModulesEnd() const
InternalCounterCollection::ComponentIterator CounterIterator
static CentralConfig * GetInstance()
Use this the first time you get an instance of central configuration.
Template class for a FADC data or calibrated data container. Use the typedefs (TraceD, TraceI, etc.) defined in Trace-fwd.h.
bool IsADCCalibratedLG() const
ModuleRecData & GetRecData()
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
CounterConstIterator CountersEnd() const
double GetStdDevChargeMuonHG() const
const utl::Point & GetCorePosition() const
double GetMeanChargeMuonLG() const
Calibration of ADC channel.
utl::TraceUSI & GetIntegratorBTrace()
static Policy::type Create(const utl::Point &theOrigin)
Create the standard local coordinate system for a Point.
double GetMeanChargeMuonHG() const
bool IsADCCalibratedHG() const
Root of the Muon event hierarchy.
double GetStdDevChargeMuonLG() const
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)