9 #include <fwk/CentralConfig.h>
10 #include <det/VManager.h>
11 #include <mdet/MDetector.h>
12 #include <sdet/SDetector.h>
13 #include <evt/ShowerRecData.h>
14 #include <evt/ShowerSRecData.h>
15 #include <sevt/SEvent.h>
16 #include <mevt/Module.h>
18 #include <utl/ConsecutiveEnumFactory.h>
19 #include <utl/Trace.h>
20 #include <utl/AugerUnits.h>
21 #include <utl/Branch.h>
22 #include <utl/RandomEngine.h>
23 #include <utl/ConfigUtils.h>
24 #include <utl/TimeStamp.h>
25 #include <utl/PhysicalConstants.h>
26 #include <utl/TimeInterval.h>
28 #include <utl/ErrorLogger.h>
29 #include <utl/Verbosity.h>
41 namespace MdMuonEstimatorAG {
43 const char*
const MdMuonEstimator::kCountingStrategyTags[] = {
"OneBin",
"NBin",
"NBinCentered",
"InfiniteWindow" };
49 DEBUGLOG(
"Initiating Muon Estimator");
53 fUnits.SetTimeDefault(
utl::ns,
"ns");
54 fUnits.Configure(config);
55 fLog.Configure(config);
57 LoadConfig(config,
"countingStrategy", tag, kCountingStrategyTags[0]);
58 LoadConfig(config,
"nBinWindowSize", fNBinWindowSize, 12);
72 WARNING(
"\n+++++++++\nEvent without MEvent: nothing to be done. Skipping to next event.\n++++++++++\n");
77 unsigned int traceLength = GetTraceLength(event);
78 double samplingTimeTrace = GetSamplingTime(event);
80 switch (fCountingStrategy) {
82 fEstimator.reset(
new OneBinStrategy(traceLength, samplingTimeTrace));
83 fLog(
"Strategy")(kCountingStrategyTags[ fCountingStrategy ])(
".");
84 fCountingWindowSize = 1;
87 fEstimator.reset(
new NBinStrategy(fNBinWindowSize, traceLength));
88 fLog(
"#NBin Window size", 1)
89 (fNBinWindowSize)(
"-")
90 (
"Strategy")(kCountingStrategyTags[ fCountingStrategy ])(
".");
91 fCountingWindowSize = fNBinWindowSize;
95 fLog(
"#NBin Window size", 1)
96 (fNBinWindowSize)(
"-")
97 (
"Strategy")(kCountingStrategyTags[ fCountingStrategy ])(
".");
98 fCountingWindowSize = fNBinWindowSize;
100 case eInfiniteWindow:
102 fLog(
"Strategy")(kCountingStrategyTags[ fCountingStrategy ])(
".");
103 fCountingWindowSize = traceLength;
106 ERROR(
"Invalid muon estimation strategy!");
111 const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
113 std::ostringstream os;
117 const int counterId = counter.
GetId();
121 os <<
"Skipping the rejected counter " << counterId;
127 os <<
"Processing counter " << counterId;
137 const int moduleId = module.
GetId();
141 os <<
"Processing module " << moduleId;
150 os <<
"Module " << module.
GetId() <<
" of counter " << counterId;
162 const std::vector<std::pair<unsigned int, unsigned int>> vModulePatternMatches = GetModulePatternMatches(module);
163 DEBUGLOG(
"After getting vModulePatternMatches");
166 FillChannelsOn(module, vModulePatternMatches, mdetModule);
167 DEBUGLOG(
"After filling channelsOn");
172 LoadPatternMatchesInModuleRecData(module, vModulePatternMatches, mdetModule);
173 DEBUGLOG(
"After loading pattern matches in the module reconstructed data");
175 SetSegmentationAndArea(module, mdetModule);
176 DEBUGLOG(
"After setting the segmentation and area");
178 EstimateNumberOfMuons(module, vModulePatternMatches);
179 DEBUGLOG(
"After estimating number of muons");
188 MdMuonEstimator::Finish()
198 unsigned int nTraceSamples = 0;
206 const int counterId = counter.
GetId();
212 const int moduleId = module.
GetId();
214 const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
218 nTraceSamples = mdetModule.
IsSiPM() ?
223 if (!nTraceSamples) {
227 if (!nTraceSamples) {
232 return nTraceSamples;
240 double samplingTime = 0;
248 const int counterId = counter.
GetId();
254 const int moduleId = module.
GetId();
256 const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
260 samplingTime = mdetModule.
IsSiPM() ?
278 std::vector<std::pair<unsigned int, unsigned int>>
283 std::vector<std::pair<unsigned int, unsigned int>> vMatchBins;
285 channel != ech; ++channel) {
287 if (channel->HasRecData() && !channel->IsMasked()) {
289 end = channel->GetRecData().PatternMatchBinsEnd(); mut != end; ++mut) {
290 vMatchBins.push_back(std::make_pair(channel->GetId(),*mut));
300 MdMuonEstimator::FillChannelsOn(
mevt::Module& module,
const std::vector<std::pair<unsigned int, unsigned int>>& vModulePatternMatches,
const mdet::Module& mdetModule)
318 const unsigned int traceSize = mdetModule.
IsSiPM() ?
323 std::vector<unsigned int> channelsOnVector(traceSize,0);
324 std::vector<unsigned int> channelsInhibitedVector(traceSize,0);
325 for (std::vector<std::pair<unsigned int, unsigned int>>::const_iterator it = vModulePatternMatches.begin(); it != vModulePatternMatches.end(); ++it) {
326 const unsigned int bin = it->second;
327 ++channelsOnVector[bin];
328 for (
unsigned int i = 1; i < (
unsigned int) mRecData.
GetWindowSize(); ++i){
329 ++channelsInhibitedVector[bin+i];
333 for (std::vector<unsigned int>::const_iterator it = channelsOnVector.begin(); it != channelsOnVector.end(); ++it){
337 for (std::vector<unsigned int>::const_iterator it = channelsInhibitedVector.begin(); it != channelsInhibitedVector.end(); ++it){
338 channelsInhibitedTrace.
PushBack(*it);
342 const double samplingTime = mdetModule.
IsSiPM() ?
345 const double channelsOnBinning = samplingTime * fCountingWindowSize;
346 channelsOnTrace.
SetBinning(channelsOnBinning);
348 std::ostringstream info;
349 info <<
"Counting channels on\n"
350 "Number of bins = " << traceSize <<
"\n"
351 "Binning (ns) = " << channelsOnBinning;
356 MdMuonEstimator::LoadPatternMatchesInModuleRecData(
mevt::Module& module,
const std::vector<std::pair<unsigned int, unsigned int>>& vModulePatternMatches,
const mdet::Module& mdetModule)
359 DEBUGLOG(
"Starting LoadPatternMatchesInModuleRecData");
363 const double samplingTime = mdetModule.
IsSiPM() ?
367 for (std::vector<std::pair<unsigned int, unsigned int>>::const_iterator it = vModulePatternMatches.begin();
368 it != vModulePatternMatches.end(); ++it) {
369 const double matchTime = it->second * samplingTime;
373 DEBUGLOG(
"After filling the pattern match times vector");
384 DEBUGLOG(
"After setting the segmentation");
387 const double scintillatorArea = scintillator.
GetArea();
388 const double moduleArea = scintillatorArea * segmentation;
390 DEBUGLOG(
"After setting the active area");
394 MdMuonEstimator::EstimateNumberOfMuons(
mevt::Module& module, std::vector<std::pair<unsigned int, unsigned int>> vModulePatternMatches)
399 std::ostringstream os;
402 const double numberOfMuons = (*fEstimator)(vModulePatternMatches, mRecData);
404 DEBUGLOG(
"After setting the number of muons");
412 os <<
"module " << module.
GetId() <<
", "
413 << std::fixed << std::setprecision(1)
416 <<
"muons = " << numberOfMuons;
420 os <<
"module " << module.
GetId() <<
" is saturated";
426 DEBUGLOG(
"Finishing EstimateNumberOfMuons");
Module level reconstruction data. This class contains all data required by the muon reconstruction...
bool HasChannelsInhibited() const
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
CounterConstIterator CountersBegin() const
static EnumType Create(const int k)
int version of the overloaded creation method.
**void SetActiveArea(const double area)
Counter level event data.
void SetNumberOfMuonsLowLimit(const double e)
The lower limit to the number of muons in a module.
std::string GetRejectionReason() const
PatternMatchBinContainer::const_iterator PatternMatchBinIterator
double GetActiveArea() const
void AddPatternMatchTime(const double t)
#define INFO(message)
Macro for logging informational messages.
ScintillatorConstIterator ScintillatorsBegin() const
Begin iterator over the contained scitillators.
void Init()
Initialise the registry.
bool IsRejected() const
Check if the counter is rejected.
Detector associated to muon detector hierarchy.
Actual muon-sensitive objects.
utl::TraceUI & GetChannelsInhibited()
Class representing a document branch.
utl::TraceUI & GetChannelsOn()
Number of windows with a signal in a module.
bool HasChannelsOn() const
#define DEBUGLOG(message)
Macro for logging debugging messages.
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
ChannelConstIterator ChannelsBegin() const
void SetNumberOfMuonsErrorHigh(const double e)
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
void SetNumberOfEstimatedMuons(const double m)
Number of estimated muons in a module.
#define WARNING(message)
Macro for logging warning messages.
double GetArea() const
Compute Scintillator's total area in square metres.
unsigned int GetBufferLength() const
Number of bins of the buffer.
const FrontEnd & GetFrontEnd() const
InternalModuleCollection::ComponentIterator ModuleIterator
void MakeChannelsInhibited()
void SetSegmentation(const size_t nm)
ModuleConstIterator ModulesBegin() const
Root detector of the muon detector hierarchy.
Functor implementing a muon counting strategy bin-wise.
void SetBinning(const double binning)
ChannelConstIterator ChannelsEnd() const
ResultFlag
Flag returned by module methods to the RunController.
int GetId() const
The id of the counter.
Functor implementing a muon counting strategy bin-wise.
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.
ModuleRecData & GetRecData()
const FrontEndSiPM & GetFrontEndSiPM() const
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
size_t GetSegmentation() const
CounterConstIterator CountersEnd() const
const Counter & GetCounter(int id) const
Retrieve Counter by id.
void PushBack(const T &value)
Insert a single value at the end.
#define ERROR(message)
Macro for logging error messages.
Root of the Muon event hierarchy.
size_t GetNumberOfActiveChannels() const
void SetNumberOfMuonsErrorLow(const double e)
utl::Branch GetTopBranch(const std::string &id)
Get top branch for moduleConfigLink with given id (XML files)
Functor implementing a muon counting strategy bin-wise.
InternalChannelCollection::ComponentIterator ChannelIterator
Functor implementing a muon counting strategy bin-wise.
unsigned int GetBufferLength() const
Number of bins of the buffer.