12 #include "../MdLDFFinderAG/ProfLike.h"
14 #include <fwk/CentralConfig.h>
15 #include <det/VManager.h>
16 #include <mdet/MDetector.h>
17 #include <sdet/SDetector.h>
18 #include <evt/ShowerRecData.h>
19 #include <evt/ShowerSRecData.h>
20 #include <sevt/SEvent.h>
21 #include <mevt/Module.h>
23 #include <utl/ConsecutiveEnumFactory.h>
24 #include <utl/Trace.h>
25 #include <utl/AugerUnits.h>
26 #include <utl/Branch.h>
27 #include <utl/RandomEngine.h>
28 #include <utl/ConfigUtils.h>
29 #include <utl/TimeStamp.h>
30 #include <utl/PhysicalConstants.h>
31 #include <utl/TimeInterval.h>
33 #include <utl/ErrorLogger.h>
34 #include <utl/Verbosity.h>
46 namespace MdMuonCounterAG {
48 const char*
const MdMuonCounter::kStrategyTags[] = {
"Gap",
"GapRelax",
"AmountInWindow",
"Consecutive",
"AmountGlobal" };
56 fUnits.SetTimeDefault(
utl::ns,
"ns");
57 fUnits.Configure(config);
58 fLog.Configure(config);
60 LoadConfig(config,
"strategy", tag, kStrategyTags[0]);
66 LoadConfig(config,
"windowSize", fWindowSize, 8);
69 fLog(
"#Window size", 1)
71 (
"Number of ones")(fNOnes)(
"-")
72 (
"Strategy")(kStrategyTags[ fStrategy ])(
".");
75 LoadConfig(config,
"windowSize", fWindowSize, 8);
78 fLog(
"#Window size", 1)
80 (
"Number of ones")(fNOnes)(
"-")
81 (
"Strategy")(kStrategyTags[ fStrategy ])(
".");
84 LoadConfig(config,
"windowSize", fWindowSize, 8);
87 fCounter.reset(
new GapStrategy(fWindowSize, fNOnes, fNGaps,
"strict"));
88 fLog(
"#Window size", 1)
90 (
"Number of ones")(fNOnes)(
"-")
91 (
"Number of gaps")(fNGaps)(
"-")
92 (
"Strategy")(kStrategyTags[ fStrategy ])(
".");
95 LoadConfig(config,
"windowSize", fWindowSize, 8);
98 fCounter.reset(
new GapStrategy(fWindowSize, fNOnes, fNGaps,
"relax"));
99 fLog(
"#Window size", 1)
101 (
"Number of ones")(fNOnes)(
"-")
102 (
"Number of gaps")(fNGaps)(
"-")
103 (
"Strategy")(kStrategyTags[ fStrategy ])(
".");
106 LoadConfig(config,
"nOnesPerPatternMatch", fNOnesPerPatternMatch, 2.0);
110 fLog(
"#Number of ones", 1)
111 (fNOnesPerPatternMatch)(
"-")
112 (
"Minimum Number of ones in a scintillator")(fNMinOnes)(
"-")
113 (
"Strategy")(kStrategyTags[ fStrategy ])(
".");
117 LoadConfig(config,
"setTimeStamps", fSetTimeStamps,
false);
119 INFO(
"Setting the MD timestamps");
121 INFO(
"Not setting the MD timestamps");
129 if (fSetTimeStamps) {
133 const int counterId = det::VManager::FindComponent<unsigned int>(
"counterId", attibutes);
134 const int moduleId = det::VManager::FindComponent<unsigned int>(
"moduleId", attibutes);
135 const int globalModuleId = counterId*100 + moduleId;
136 const double delay =
b.Get<
double>();
137 fModuleDelay[globalModuleId] =
delay;
141 LoadConfig(config,
"syncCountingHisto", fSyncCountingHisto,
false);
152 WARNING(
"\n+++++++++\nEvent without MEvent: nothing to be done. Skipping to next event.\n++++++++++\n");
153 return eContinueLoop;
157 const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
159 std::ostringstream os;
163 const int counterId = counter.
GetId();
167 os <<
"Skipping the rejected counter " << counterId;
173 os <<
"Processing counter " << counterId;
180 const utl::TimeStamp sdTraceStartTime = GetSdTraceStartTime(event, stationId);
182 const bool hasSdTimeStamps = bool(sdTraceStartTime);
189 const int moduleId = module.
GetId();
190 const int moduleGlobalId = counterId*100 + moduleId;
193 os <<
"Processing module " << moduleId;
202 os <<
"Module " << module.
GetId() <<
" of counter " << counterId;
208 const bool hasModuleDelay = fModuleDelay.count(moduleGlobalId);
215 const bool setTimeStamps = fSetTimeStamps && hasSdTimeStamps && hasModuleDelay;
220 mdTraceStartTime = sdTraceStartTime + GetTraceOffset(module, counterId);
233 const unsigned int nRecPatternMatches = FillChannelRecData(channel);
237 os <<
"counter " << counterId <<
": "
238 <<
"module " << module.
GetId() <<
" "
239 <<
"channel " << channel.
GetId() <<
" "
240 <<
"were detected "<< nRecPatternMatches <<
" muons ";
242 if ( nRecPatternMatches ) fLog( os.str(), 3 );
246 FillModuleRecData(module, mdetModule);
247 DEBUGLOG(
"After filling the module reconstructed data");
251 const double samplingTime = mdetModule.
IsSiPM() ?
258 DEBUGLOG(
"After setting the module histogram start time");
269 if (!event.
HasRecShower() || !
event.GetRecShower().HasSRecShower())
273 if (!sdTraceStartTime)
281 const double t50 = ComputeSignalT50(counter, rAxis);
291 if (!event.
HasSEvent() || !
event.GetSEvent().HasStation(stationId)) {
293 os <<
"SD station " << stationId <<
" not found.";
298 const sevt::Station& station =
event.GetSEvent().GetStation(stationId);
302 os <<
"Reconstructed data of SD station " << stationId <<
" not found.";
309 utl::TimeInterval t50ToSdStart = t50GpsTime - sdSignalStartTime;
314 os <<
"MD t50 - SD t0 = " << t50ToSdStartNanos <<
" ns";
324 MdMuonCounter::Finish()
347 (
"preexisting muons for channel=")(channel.
GetId())(
':')
356 const unsigned int nRecPatternMatches = (*fCounter)(trace, rData);
358 return nRecPatternMatches;
366 DEBUGLOG(
"Starting FillModuleRecData");
368 std::ostringstream os;
376 const std::vector<unsigned int>& vPatternMatches = GetPatternMatchBins(module);
377 DEBUGLOG(
"After getting vPatternMatches");
380 FillChannelsOn(module, vPatternMatches, mdetModule);
381 DEBUGLOG(
"After filling channelsOn");
384 const double samplingTime = mdetModule.
IsSiPM() ?
388 for (std::vector<unsigned int>::const_iterator it = vPatternMatches.begin();
389 it != vPatternMatches.end(); ++it) {
390 const double matchTime = (*it) * samplingTime;
393 DEBUGLOG(
"After filling the pattern match times vector");
397 DEBUGLOG(
"After setting the segmentation");
400 const double scintillatorArea = scintillator.
GetArea();
401 const double moduleArea = scintillatorArea * segmentation;
403 DEBUGLOG(
"After setting the active area");
413 DEBUGLOG(
"After setting the window size");
420 const double nunmberOfMuons = EstimateNumberOfMuons(mRecData.
GetChannelsOn(), segmentation);
422 DEBUGLOG(
"After setting the number of muons");
425 const double errorHigh = modLike.GetErrorHigh();
427 const double errorLow = modLike.GetErrorLow();
431 os <<
"module " << module.
GetId() <<
", "
432 << std::fixed << std::setprecision(1)
433 <<
"area = " << moduleArea <<
" m2, "
434 <<
"bars = " << segmentation <<
", "
435 <<
"muons = " << nunmberOfMuons <<
" +" << errorHigh <<
" -" << errorLow;
440 os <<
"module " << module.
GetId() <<
" is saturated";
445 const double lowLimit = modLike.GetLowLimit();
448 DEBUGLOG(
"Finishing FillModuleRecData");
452 std::vector<unsigned int>
457 std::vector<unsigned int> vMatchBins;
459 channel != ech; ++channel) {
461 if (channel->HasRecData() && !channel->IsMasked()) {
463 end = channel->GetRecData().PatternMatchBinsEnd(); mut != end; ++mut) {
464 vMatchBins.push_back(*mut);
466 fLog(
"Matched pattern in module", 50)(module.
GetId())(
"- channel")(channel->GetId())
478 MdMuonCounter::FillChannelsOn(
mevt::Module& module,
const std::vector<unsigned int>& vPatternMatches,
const mdet::Module& mdetModule)
483 const unsigned int nTraceSamples = mdetModule.
IsSiPM() ?
488 unsigned int histogramStartTime = 1;
489 unsigned int histogramSize = nTraceSamples;
491 if (fSyncCountingHisto && vPatternMatches.size() > 0) {
492 histogramStartTime = *min_element(vPatternMatches.begin(), vPatternMatches.end());
493 histogramSize = nTraceSamples-histogramStartTime+1;
496 TH1I hChannelsOn(
"h1",
"Pattern matches", histogramSize, histogramStartTime, nTraceSamples);
497 for (std::vector<unsigned int>::const_iterator it = vPatternMatches.begin(); it != vPatternMatches.end(); ++it) {
498 const unsigned int bin = *it + 1;
499 hChannelsOn.Fill(bin);
501 if (fWindowSize <= histogramSize)
502 hChannelsOn.Rebin(fWindowSize);
504 hChannelsOn.Rebin(histogramSize);
514 const unsigned int nChannelsOnBins = hChannelsOn.GetNbinsX();
515 for (
unsigned int bin = 1; bin <= nChannelsOnBins; ++bin) {
516 const unsigned int nChannelsOn = hChannelsOn.GetBinContent(bin);
517 channelsOnTrace.
PushBack(nChannelsOn);
521 const double samplingTime = mdetModule.
IsSiPM() ?
524 const double channelsOnBinning = samplingTime * fWindowSize;
525 channelsOnTrace.
SetBinning(channelsOnBinning);
527 std::ostringstream info;
528 info <<
"Counting channels on\n"
529 "Number of bins = " << nChannelsOnBins <<
"\n"
530 "Binning (ns) = " << channelsOnBinning;
536 MdMuonCounter::EstimateNumberOfMuons(
const utl::TraceUI& channelsOn,
const size_t segmentation)
539 double estimatedMuons = 0;
543 estimatedMuons -= segmentation * std::log(1 -
double(*it)/segmentation);
545 return estimatedMuons;
550 MdMuonCounter::GetTraceOffset(
const mevt::Module& module,
const int counterId)
553 const int moduleId = module.
GetId();
554 const int moduleGlobalId = counterId*100 + moduleId;
555 const double moduleDelay = fModuleDelay.find(moduleGlobalId)->second;
557 const sdet::SDetector& sDetector = det::Detector::GetInstance().GetSDetector();
559 const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
563 const unsigned int nLatchBin = mdetModule.
IsSiPM() ?
567 const double samplingTime = mdetModule.
IsSiPM() ?
571 const double traceLatchTime = (nLatchBin - 1) * samplingTime;
582 MdMuonCounter::GetSdTraceStartTime(
const evt::Event& event,
const int stationId)
586 if (!event.
HasSEvent() || !
event.GetSEvent().HasStation(stationId)) {
587 std::ostringstream os;
588 os <<
"Not setting the timestamps for the MD counter " << stationId <<
". "
589 "Cannot find the associated SD station.";
593 const sevt::Station& station =
event.GetSEvent().GetStation(stationId);
597 std::ostringstream os;
598 os <<
"Not setting the timestamps for the MD counter " << stationId <<
". "
599 "Cannot find the gps time of associated SD station.";
613 const int counterId = counter.
GetId();
615 const det::Detector& detector = det::Detector::GetInstance();
625 std::vector<double> counterPatternMatches;
631 const int moduleId = module.
GetId();
637 const double moduleTraceOffset = GetTraceOffset(module, counterId);
641 const utl::Vector& dPosition = modulePosition - sdPosition;
642 const double positionCorrection = GetTimeCorrection(dPosition, rAxis);
646 for (std::vector<double>::const_iterator ip = modulePatternMatches.begin(), ep = modulePatternMatches.end(); ip != ep; ++ip) {
647 const double correctedPatternMatchTime = *ip + moduleTraceOffset + positionCorrection;
648 counterPatternMatches.push_back(correctedPatternMatchTime);
653 const double t50 = GetMedian(counterPatternMatches);
660 MdMuonCounter::GetMedian(
const std::vector<double> v)
664 unsigned int ndata = v.size();
668 std::vector<double> vtemp(v);
669 std::sort(vtemp.begin(), vtemp.end());
674 const unsigned int i = ndata / 2;
675 median = 0.5*(vtemp[i-1] + vtemp[i]);
677 const unsigned int i = (ndata - 1) / 2;
689 const double s = dposition * axis;
692 return timeCorrection;
Module level reconstruction data. This class contains all data required by the muon reconstruction...
bool IsCandidate() const
The muon counter status.
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.
Interface class to access to the SD Reconstruction of a Shower.
**void SetActiveArea(const double area)
Counter level event data.
bool HasRecShower() const
void SetNumberOfMuonsLowLimit(const double e)
The lower limit to the number of muons in a module.
const mdet::MDetector & GetMDetector() const
const std::vector< double > & GetPatternMatchTimes() const
Functor implementing a constant sampling window strategy.
std::map< std::string, std::string > AttributeMap
std::string GetRejectionReason() const
PatternMatchBinContainer::const_iterator PatternMatchBinIterator
ChannelRecData & GetRecData()
sevt::StationRecData & GetRecData()
Get station level reconstructed data.
void AddPatternMatchTime(const double t)
#define INFO(message)
Macro for logging informational messages.
ScintillatorConstIterator ScintillatorsBegin() const
Begin iterator over the contained scitillators.
utl::Point GetPosition() const
void Init()
Initialise the registry.
bool IsRejected() const
Check if the counter is rejected.
unsigned int GetPreT1BufferLength() const
Number of bins of the (cyclic) pre-T1 buffer.
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
void SetT502SdStart(const double c)
bool IsEmpty() const
Checks if there are muons in the counter.
void SetTraceStartTime(const utl::TimeStamp &t)
Stablish the timestamp associated with the start of the trace.
Detector associated to muon detector hierarchy.
std::vector< T >::const_iterator ConstIterator
A TimeStamp holds GPS second and nanosecond for some event.
utl::Point GetPosition() const
Tank position.
Actual muon-sensitive objects.
Class representing a document branch.
class to hold data at Station level
utl::TraceUI & GetChannelsOn()
Number of windows with a signal in a module.
utl::TimeStamp GetSignalStartTime() const
Start time of the signal.
bool HasChannelsOn() const
constexpr double nanosecond
#define DEBUGLOG(message)
Macro for logging debugging messages.
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
Top of the hierarchy of the detector description interface.
ChannelConstIterator ChannelsBegin() const
void SetNumberOfMuonsErrorHigh(const double e)
const sdet::SDetector & GetSDetector() const
int GetAssociatedTankId() const
Retrieve the id of the associated surface tank.
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
void ClearPatternMatchBins()
Clears pattern match detection times information.
unsigned int GetPreT1BufferLength() const
Number of bins of the (cyclic) pre-T1 buffer.
const utl::Vector & GetAxis() const
void SetNumberOfEstimatedMuons(const double m)
Number of estimated muons in a module.
Functor implementing a constant sampling window strategy.
unsigned int GetNumberOfPatternMatchs() const
Retrieve the number of pattern matchs that impinged this scintillator.
#define WARNING(message)
Macro for logging warning messages.
void SetWindowSize(const unsigned int ws)
bool HasGPSData() const
Check whether GPS data object edists.
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 SetSegmentation(const size_t nm)
ModuleConstIterator ModulesBegin() const
double GetInterval() const
Get the time interval as a double (in Auger base units)
Root detector of the muon detector hierarchy.
void SetSignalT50(const utl::TimeStamp &time)
void SetBinning(const double binning)
constexpr double kSpeedOfLight
A TimeInterval is used to represent time elapsed between two events.
ChannelConstIterator ChannelsEnd() const
ResultFlag
Flag returned by module methods to the RunController.
double GetFADCBinSize() const
int GetId() const
The id of the counter.
ModuleConstIterator ModulesEnd() const
InternalCounterCollection::ComponentIterator CounterIterator
bool HasRecData() const
Check whether station reconstructed data exists.
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
Functor implementing a counting strategy based only on the number of positive samples.
void SetChannelsOnStartTime(const utl::TimeStamp &t)
Sets the timestamp associated with the start of the ChannelsOn trace.
utl::TimeStamp GetTraceStartTime() const
Get absolute start time of the VEM trace.
Channel level event data.
void LoadConfig(const utl::Branch &b, const std::string &tag, T1 &var, const T2 &defaultValue)
Helper method to load a particular configuration parameter.
Detector description interface for SDetector-related data.
CounterConstIterator CountersEnd() const
Branch GetFirstChild() const
Get first child of this Branch.
const Station & GetStation(const int stationId) const
Get station by Station Id.
Channel level reconstruction data.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
void PushBack(const T &value)
Insert a single value at the end.
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 constant window consecutive-rows-of-ones criteria.
InternalChannelCollection::ComponentIterator ChannelIterator
unsigned int GetBufferLength() const
Number of bins of the buffer.