MdMuonCounter.cc
Go to the documentation of this file.
1 #include "MdMuonCounter.h"
2 
3 #ifndef DEBUG
4 # define DEBUG 1
5 #endif
6 
8 #include "GapStrategy.h"
11 #include "AmountGlobalStrategy.h"
12 #include "../MdLDFFinderAG/ProfLike.h"
13 
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>
22 
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>
32 
33 #include <utl/ErrorLogger.h>
34 #include <utl/Verbosity.h>
35 
36 #include <sstream>
37 //#include <cassert>
38 
39 #include <TH1I.h>
40 
41 using namespace fwk;
42 using std::cout;
43 using std::endl;
44 
45 
46 namespace MdMuonCounterAG {
47 
48  const char* const MdMuonCounter::kStrategyTags[] = { "Gap", "GapRelax", "AmountInWindow", "Consecutive", "AmountGlobal" };
49 
50 
53  {
54  // Configuration reading.
55  utl::Branch config = fwk::CentralConfig::GetInstance()->GetTopBranch("MdMuonCounter");
56  fUnits.SetTimeDefault(utl::ns, "ns");
57  fUnits.Configure(config);
58  fLog.Configure(config);
59  std::string tag;
60  LoadConfig(config, "strategy", tag, kStrategyTags[0]);
62 
63  // Init according to selected strategy.
64  switch (fStrategy) {
65  case eAmountInWindow:
66  LoadConfig(config, "windowSize", fWindowSize, 8);
67  LoadConfig(config, "nOnes", fNOnes, 2);
68  fCounter.reset(new AmountInWindowStrategy(fWindowSize, fNOnes));
69  fLog("#Window size", 1)
70  (fWindowSize)("-")
71  ("Number of ones")(fNOnes)("-")
72  ("Strategy")(kStrategyTags[ fStrategy ])(".");
73  break;
74  case eConsecutive:
75  LoadConfig(config, "windowSize", fWindowSize, 8);
76  LoadConfig(config, "nOnes", fNOnes, 2);
77  fCounter.reset(new ConsecutiveInWindowStrategy(fWindowSize, fNOnes));
78  fLog("#Window size", 1)
79  (fWindowSize)("-")
80  ("Number of ones")(fNOnes)("-")
81  ("Strategy")(kStrategyTags[ fStrategy ])(".");
82  break;
83  case eGap:
84  LoadConfig(config, "windowSize", fWindowSize, 8);
85  LoadConfig(config, "nOnes", fNOnes, 2);
86  LoadConfig(config, "nGaps", fNGaps, 1);
87  fCounter.reset(new GapStrategy(fWindowSize, fNOnes, fNGaps, "strict"));
88  fLog("#Window size", 1)
89  (fWindowSize)("-")
90  ("Number of ones")(fNOnes)("-")
91  ("Number of gaps")(fNGaps)("-")
92  ("Strategy")(kStrategyTags[ fStrategy ])(".");
93  break;
94  case eGapRelax:
95  LoadConfig(config, "windowSize", fWindowSize, 8);
96  LoadConfig(config, "nOnes", fNOnes, 2);//minumum number of 1s
97  LoadConfig(config, "nGaps", fNGaps, 6);//maximum number of gaps (0s) allowed between two 1s
98  fCounter.reset(new GapStrategy(fWindowSize, fNOnes, fNGaps, "relax"));
99  fLog("#Window size", 1)
100  (fWindowSize)("-")
101  ("Number of ones")(fNOnes)("-")
102  ("Number of gaps")(fNGaps)("-")
103  ("Strategy")(kStrategyTags[ fStrategy ])(".");
104  break;
105  case eAmountGlobal:
106  LoadConfig(config, "nOnesPerPatternMatch", fNOnesPerPatternMatch, 2.0);
107  LoadConfig(config, "nMinOnes", fNMinOnes, 0);
108  fCounter.reset(new AmountGlobalStrategy(fNOnesPerPatternMatch, fNMinOnes));
109  fWindowSize = 0;
110  fLog("#Number of ones", 1)
111  (fNOnesPerPatternMatch)("-")
112  ("Minimum Number of ones in a scintillator")(fNMinOnes)("-")
113  ("Strategy")(kStrategyTags[ fStrategy ])(".");
114  break;
115  }
116 
117  LoadConfig(config, "setTimeStamps", fSetTimeStamps, false);
118  if (fSetTimeStamps)
119  INFO("Setting the MD timestamps");
120  else
121  INFO("Not setting the MD timestamps");
122 
123  //utl::Branch topB_SD = CentralConfig::GetInstance()->GetTopBranch("SdCalibrator");
124  //topB_SD.GetChild("latchBin").GetData(fSdLatchNanos);
125 
126  //LoadConfig( topB, "sdLatchNanos", fSdLatchNanos, 6400.);
127 
128  // Fill the fModuleDelay map from the configuration file
129  if (fSetTimeStamps) {
130  utl::Branch moduleDelays = config.GetChild("moduleDelays");
131  for (utl::Branch b = moduleDelays.GetFirstChild(); b; b = b.GetNextSibling()) {
132  utl::AttributeMap attibutes = b.GetAttributes();
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;
138  }
139  }
140 
141  LoadConfig(config, "syncCountingHisto", fSyncCountingHisto, false);
142  return eSuccess;
143  }
144 
145 
147  MdMuonCounter::Run(evt::Event& event)
148  {
149  //INFO("Starting");
150 
151  if (!event.HasMEvent()) {
152  WARNING("\n+++++++++\nEvent without MEvent: nothing to be done. Skipping to next event.\n++++++++++\n");
153  return eContinueLoop;
154  }
155 
156  mevt::MEvent& me = event.GetMEvent();
157  const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
158 
159  std::ostringstream os;
160  for (mevt::MEvent::CounterIterator ic = me.CountersBegin(), ec = me.CountersEnd(); ic != ec; ++ic) {
161 
162  mevt::Counter& counter = *ic;
163  const int counterId = counter.GetId();
164 
165  if (counter.IsRejected()) {
166  os.str("");
167  os << "Skipping the rejected counter " << counterId;
168  INFO(os);
169  continue;
170  }
171 
172  os.str("");
173  os << "Processing counter " << counterId;
174  INFO(os);
175 
176  const mdet::Counter& mdetCounter = theMdDetector.GetCounter(counterId);
177  int stationId = mdetCounter.GetAssociatedTankId();
178 
179  // GPS time of the partner SD station
180  const utl::TimeStamp sdTraceStartTime = GetSdTraceStartTime(event, stationId);
181  utl::TimeStamp mdTraceStartTime;
182  const bool hasSdTimeStamps = bool(sdTraceStartTime);
183  //cout << "hasSdTimeStamps is " << std::boolalpha << hasSdTimeStamps << endl;
184 
185  for (mevt::Counter::ModuleIterator im = counter.ModulesBegin(), em = counter.ModulesEnd(); im != em; ++im) {
186 
187  DEBUGLOG("Starting module loop");
188  mevt::Module& module = *im;
189  const int moduleId = module.GetId();
190  const int moduleGlobalId = counterId*100 + moduleId;
191 
192  os.str("");
193  os << "Processing module " << moduleId;
194  DEBUGLOG(os);
195 
196  const mdet::Module& mdetModule = mdetCounter.GetModule(moduleId);
197 
198  // Check if module was flagged as rejected (by a selector) or, in the case of real data, if T1 from SD was not matched
199  // this should imply an empty (all "0s" ) module traces
200  if (module.IsRejected()) {
201  os.str("");
202  os << "Module " << module.GetId() << " of counter " << counterId;
203  os << " discarded because flagged as: " << module.GetRejectionReason();
204  WARNING(os);
205  continue;
206  }
207 
208  const bool hasModuleDelay = fModuleDelay.count(moduleGlobalId);
209  //cout << "hasModuleDelay is " << std::boolalpha << hasModuleDelay << endl;
210 
211  // Set timestamps only if the following three conditions are met
212  // 1 - the configuration variable fSetTimeStamps is true
213  // 2 - the partner sd station has a timestamp
214  // 3 - the module is in the fModuleDelay list
215  const bool setTimeStamps = fSetTimeStamps && hasSdTimeStamps && hasModuleDelay;
216  //cout << "setTimeStamps is " << std::boolalpha << setTimeStamps << endl;
217 
218  // Get the start time of the traces
219  if (setTimeStamps)
220  mdTraceStartTime = sdTraceStartTime + GetTraceOffset(module, counterId);
221 
222  //INFO("After setting mdTraceStartTime");
223 
224  for (mevt::Module::ChannelIterator ch = module.ChannelsBegin(), ech = module.ChannelsEnd(); ch != ech; ++ch) {
225  //DEBUGLOG("Starting channel loop");
226  mevt::Channel& channel = *ch;
227 
228  if (setTimeStamps)
229  channel.SetTraceStartTime(mdTraceStartTime);
230 
231  //DEBUGLOG("After setting the channel trace start time");
232 
233  const unsigned int nRecPatternMatches = FillChannelRecData(channel);
234  //DEBUGLOG("After filling the channel reconstructed data");
235 
236  os.str("");
237  os << "counter " << counterId << ": "
238  << "module " << module.GetId() << " "
239  << "channel " << channel.GetId() << " "
240  << "were detected "<< nRecPatternMatches << " muons ";
241  DEBUGLOG(os);
242  if ( nRecPatternMatches ) fLog( os.str(), 3 );
243 
244  }
245 
246  FillModuleRecData(module, mdetModule);
247  DEBUGLOG("After filling the module reconstructed data");
248 
249  // Set the start time of the channelsOn histogram
250  if (setTimeStamps) {
251  const double samplingTime = mdetModule.IsSiPM() ?
253  mdetModule.GetFrontEnd().GetMeanSampleRatePeriod();
254  // adjusting the start time by half sample period. ChannelsOn is a histogram, not a trace!
255  const utl::TimeStamp channelsOnStartTime = mdTraceStartTime - utl::TimeInterval(0.5*samplingTime);
256  module.GetRecData().SetChannelsOnStartTime(channelsOnStartTime);
257  }
258  DEBUGLOG("After setting the module histogram start time");
259 
260  } // end module loop
261 
262  // Setting the counter T50
263 
264  // Skip not candidate and empty counters
265  if (!counter.IsCandidate() || counter.IsEmpty())
266  continue;
267 
268  // The time correction requires the SD geometrical reconstruction
269  if (!event.HasRecShower() || !event.GetRecShower().HasSRecShower())
270  continue;
271 
272  // Skip counter if the SD gps is unavailable
273  if (!sdTraceStartTime)
274  continue;
275 
276  const evt::ShowerSRecData& sRecShower = event.GetRecShower().GetSRecShower();
277  const utl::Vector& rAxis = sRecShower.GetAxis();
278 
279  // Compute the t50 in nanoseconds from the SD trace start
280  // Apply the md syncronization and correct modules times by position
281  const double t50 = ComputeSignalT50(counter, rAxis);
282 
283  // Refer the t50 to the GPS timestamp
284  const utl::TimeStamp t50GpsTime = sdTraceStartTime + utl::TimeInterval(t50);
285 
286  counter.SetSignalT50(t50GpsTime);
287 
288  // Set the offset between the t50 and the start time of the SD signal
289 
290  // Checking that the partner SD station exists
291  if (!event.HasSEvent() || !event.GetSEvent().HasStation(stationId)) {
292  os.str("");
293  os << "SD station " << stationId << " not found.";
294  WARNING(os);
295  continue;
296  }
297 
298  const sevt::Station& station = event.GetSEvent().GetStation(stationId);
299 
300  if (!station.HasRecData()) {
301  os.str("");
302  os << "Reconstructed data of SD station " << stationId << " not found.";
303  WARNING(os);
304  continue;
305  }
306 
307  const utl::TimeStamp sdSignalStartTime = station.GetRecData().GetSignalStartTime();
308 
309  utl::TimeInterval t50ToSdStart = t50GpsTime - sdSignalStartTime;
310  double t50ToSdStartNanos = t50ToSdStart.GetInterval() / utl::nanosecond;
311  counter.SetT502SdStart(t50ToSdStartNanos);
312 
313  os.str("");
314  os << "MD t50 - SD t0 = " << t50ToSdStartNanos << " ns";
315  INFO(os);
316 
317  } // end counter loop
318 
319  return eSuccess;
320  }
321 
322 
324  MdMuonCounter::Finish()
325  {
326  return eSuccess;
327  }
328 
329 
330  // Private methods
331 
332  unsigned int
333  MdMuonCounter::FillChannelRecData(mevt::Channel& channel)
334  {
335  if (!channel.HasTrace())
336  return 0;
337 
338  const utl::TraceB trace = channel.GetTrace();
339 
340  // Set the trace start time
341  //channel.SetTraceStartTime(mdTraceStartTime);
342 
343  if (channel.HasRecData()) {
344  if (channel.GetRecData().GetNumberOfPatternMatchs()) {
345  fLog("Clearing", 2)
347  ("preexisting muons for channel=")(channel.GetId())(':')
348  ("in rec info.");
349  channel.GetRecData().ClearPatternMatchBins();
350  }
351  } else
352  channel.MakeRecData();
353 
354  mevt::ChannelRecData& rData = channel.GetRecData();
355  // reconstructed muons
356  const unsigned int nRecPatternMatches = (*fCounter)(trace, rData);
357 
358  return nRecPatternMatches;
359  }
360 
361 
362  void
363  MdMuonCounter::FillModuleRecData(mevt::Module& module, const mdet::Module& mdetModule)
364  //const
365  {
366  DEBUGLOG("Starting FillModuleRecData");
367 
368  std::ostringstream os;
369 
370  if (!module.HasRecData())
371  module.MakeRecData();
372  mevt::ModuleRecData& mRecData = module.GetRecData();
373  DEBUGLOG("After making mRecData");
374 
375  // Get a vector with the bin numbers of the pattern matches
376  const std::vector<unsigned int>& vPatternMatches = GetPatternMatchBins(module);
377  DEBUGLOG("After getting vPatternMatches");
378 
379  // Fill the channelsOn histogram
380  FillChannelsOn(module, vPatternMatches, mdetModule);
381  DEBUGLOG("After filling channelsOn");
382 
383  // Fill the pattern match times vector
384  const double samplingTime = mdetModule.IsSiPM() ?
386  mdetModule.GetFrontEnd().GetMeanSampleRatePeriod();
387 
388  for (std::vector<unsigned int>::const_iterator it = vPatternMatches.begin();
389  it != vPatternMatches.end(); ++it) {
390  const double matchTime = (*it) * samplingTime;
391  mRecData.AddPatternMatchTime(matchTime);
392  }
393  DEBUGLOG("After filling the pattern match times vector");
394 
395  const size_t segmentation = module.GetNumberOfActiveChannels();
396  mRecData.SetSegmentation(segmentation);
397  DEBUGLOG("After setting the segmentation");
398 
399  const mdet::Scintillator& scintillator = *(mdetModule.ScintillatorsBegin());
400  const double scintillatorArea = scintillator.GetArea();
401  const double moduleArea = scintillatorArea * segmentation;
402  mRecData.SetActiveArea(moduleArea);
403  DEBUGLOG("After setting the active area");
404 
405  //os.str("");
406  //os << "\nchannelsOn ";
407  //for (utl::TraceUI::ConstIterator it=mRecData.GetChannelsOn().Begin(); it!=mRecData.GetChannelsOn().End(); ++it)
408  // os << (*it) << ' ';
409  //os << " (total: " << mRecData.GetNumberOfChannelsOn() << ')';
410  //INFO(os);
411 
412  mRecData.SetWindowSize(fWindowSize);
413  DEBUGLOG("After setting the window size");
414 
415  MdLDFFinderAG::ProfLike modLike(segmentation, mRecData.GetChannelsOn());
416 
417  // Set the number of estimated muons
418  if (!mRecData.IsSaturated()) { // muons can be estimated for unsaturated modules only
419 
420  const double nunmberOfMuons = EstimateNumberOfMuons(mRecData.GetChannelsOn(), segmentation);
421  mRecData.SetNumberOfEstimatedMuons(nunmberOfMuons);
422  DEBUGLOG("After setting the number of muons");
423  // calculate errors with the profile likelihood
424 
425  const double errorHigh = modLike.GetErrorHigh();
426  mRecData.SetNumberOfMuonsErrorHigh(errorHigh);
427  const double errorLow = modLike.GetErrorLow();
428  mRecData.SetNumberOfMuonsErrorLow(errorLow);
429 
430  os.str("");
431  os << "module " << module.GetId() << ", "
432  << std::fixed << std::setprecision(1)
433  << "area = " << moduleArea << " m2, "
434  << "bars = " << segmentation << ", "
435  << "muons = " << nunmberOfMuons << " +" << errorHigh << " -" << errorLow;
436  INFO(os);
437 
438  } else {
439  os.str("");
440  os << "module " << module.GetId() << " is saturated";
441  INFO(os);
442  }
443 
444  // Set the lower limit to the number of muons for both saturated and unsaturated modules
445  const double lowLimit = modLike.GetLowLimit();
446  mRecData.SetNumberOfMuonsLowLimit(lowLimit);
447 
448  DEBUGLOG("Finishing FillModuleRecData");
449  }
450 
451 
452  std::vector<unsigned int>
453  MdMuonCounter::GetPatternMatchBins(mevt::Module& module)
454  //const
455  {
456  // Get pattern match bins
457  std::vector<unsigned int> vMatchBins;
458  for (mevt::Module::ChannelIterator channel = module.ChannelsBegin(), ech = module.ChannelsEnd();
459  channel != ech; ++channel) {
460 
461  if (channel->HasRecData() && !channel->IsMasked()) { // use unmasked channels only
462  for (mevt::ChannelRecData::PatternMatchBinIterator mut = channel->GetRecData().PatternMatchBinsBegin(),
463  end = channel->GetRecData().PatternMatchBinsEnd(); mut != end; ++mut) {
464  vMatchBins.push_back(*mut);
465 
466  fLog("Matched pattern in module", 50)(module.GetId())("- channel")(channel->GetId())
467  ("bin")(*mut);
468  }
469  }
470 
471  }
472 
473  return vMatchBins;
474  }
475 
476 
477  void
478  MdMuonCounter::FillChannelsOn(mevt::Module& module, const std::vector<unsigned int>& vPatternMatches, const mdet::Module& mdetModule)
479  const
480  {
481  // Get the size and binning of the module (they are the same for all channels)
482 
483  const unsigned int nTraceSamples = mdetModule.IsSiPM() ?
484  mdetModule.GetFrontEndSiPM().GetBufferLength() :
485  mdetModule.GetFrontEnd().GetBufferLength();
486 
487  // Intermediate histogram to group pattern matches in time windows
488  unsigned int histogramStartTime = 1;
489  unsigned int histogramSize = nTraceSamples;
490 
491  if (fSyncCountingHisto && vPatternMatches.size() > 0) {
492  histogramStartTime = *min_element(vPatternMatches.begin(), vPatternMatches.end());
493  histogramSize = nTraceSamples-histogramStartTime+1;
494  }
495 
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; // beware shift between vector and TH1 indexes
499  hChannelsOn.Fill(bin); // load the histogram
500  }
501  if (fWindowSize <= histogramSize)
502  hChannelsOn.Rebin(fWindowSize); // group bins according to the window size
503  else
504  hChannelsOn.Rebin(histogramSize);
505 
506  //Create the ChannelsOn histogram
507  mevt::ModuleRecData& mRecData = module.GetRecData();
508  if (!mRecData.HasChannelsOn()) {
509  mRecData.MakeChannelsOn();
510  }
511  utl::TraceUI& channelsOnTrace = mRecData.GetChannelsOn();
512 
513  // Fill the ChannelsOn histogram
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);
518  }
519 
520  // Set the ChannelsOn binning
521  const double samplingTime = mdetModule.IsSiPM() ?
523  mdetModule.GetFrontEnd().GetMeanSampleRatePeriod();
524  const double channelsOnBinning = samplingTime * fWindowSize;
525  channelsOnTrace.SetBinning(channelsOnBinning);
526 
527  std::ostringstream info;
528  info << "Counting channels on\n"
529  "Number of bins = " << nChannelsOnBins << "\n"
530  "Binning (ns) = " << channelsOnBinning;
531  DEBUGLOG(info);
532  }
533 
534 
535  double
536  MdMuonCounter::EstimateNumberOfMuons(const utl::TraceUI& channelsOn, const size_t segmentation)
537  const
538  {
539  double estimatedMuons = 0;
540 
541  for (utl::TraceUI::ConstIterator it = channelsOn.Begin(); it != channelsOn.End(); ++it)
542  if (*it)
543  estimatedMuons -= segmentation * std::log(1 - double(*it)/segmentation);
544 
545  return estimatedMuons;
546  }
547 
548 
550  MdMuonCounter::GetTraceOffset(const mevt::Module& module, const int counterId)
551  const
552  {
553  const int moduleId = module.GetId();
554  const int moduleGlobalId = counterId*100 + moduleId;
555  const double moduleDelay = fModuleDelay.find(moduleGlobalId)->second;
556 
557  const sdet::SDetector& sDetector = det::Detector::GetInstance().GetSDetector();
558 
559  const mdet::MDetector& theMdDetector = det::Detector::GetInstance().GetMDetector();
560  const mdet::Counter& mdetCounter = theMdDetector.GetCounter(counterId);
561  const mdet::Module& mdetModule = mdetCounter.GetModule(moduleId);
562 
563  const unsigned int nLatchBin = mdetModule.IsSiPM() ?
564  mdetModule.GetFrontEndSiPM().GetPreT1BufferLength() :
565  mdetModule.GetFrontEnd().GetPreT1BufferLength();
566 
567  const double samplingTime = mdetModule.IsSiPM() ?
569  mdetModule.GetFrontEnd().GetMeanSampleRatePeriod();
570 
571  const double traceLatchTime = (nLatchBin - 1) * samplingTime;
573  const int stationId = mdetCounter.GetAssociatedTankId();
574  double sdLatchNanos = sDetector.GetStation(stationId).GetLatchBin() * sDetector.GetStation(stationId).GetFADCBinSize();
575  utl::TimeInterval traceOffset(moduleDelay + sdLatchNanos - traceLatchTime);
576 
577  return traceOffset;
578  }
579 
580 
582  MdMuonCounter::GetSdTraceStartTime(const evt::Event& event, const int stationId)
583  const
584  {
585  // Checking that the partner SD station exists
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.";
590  WARNING(os);
591  return utl::TimeStamp();
592  }
593  const sevt::Station& station = event.GetSEvent().GetStation(stationId);
594 
595  // Check that the station has GPS data
596  if (!station.HasGPSData()) {
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.";
600  WARNING(os);
601  return utl::TimeStamp();
602  }
603 
604  // Get the GPS time
605  return utl::TimeStamp(station.GetTraceStartTime());
606  }
607 
608 
609  double
610  MdMuonCounter::ComputeSignalT50(mevt::Counter& counter, const utl::Vector& rAxis)
611  const
612  {
613  const int counterId = counter.GetId();
614 
615  const det::Detector& detector = det::Detector::GetInstance();
616 
617  const mdet::MDetector& theMdDetector = detector.GetMDetector();
618  const mdet::Counter& mdetCounter = theMdDetector.GetCounter(counterId);
619 
620  const int stationId = mdetCounter.GetAssociatedTankId();
621 
622  const sdet::SDetector& sDetector = detector.GetSDetector();
623  const utl::Point& sdPosition = sDetector.GetStation(stationId).GetPosition();
624 
625  std::vector<double> counterPatternMatches;
626 
627  for (mevt::Counter::ModuleIterator im = counter.ModulesBegin(), em = counter.ModulesEnd(); im != em; ++im) {
628 
629  DEBUGLOG("Starting module loop");
630  mevt::Module& module = *im;
631  const int moduleId = module.GetId();
632 
633  // Skip rejected and silent modules
634  if (!module.IsCandidate())
635  continue;
636 
637  const double moduleTraceOffset = GetTraceOffset(module, counterId);
638 
639  // Compute the correction to the muon times due to the position of each module relative to the SD (height included)
640  const utl::Point& modulePosition = mdetCounter.GetModule(moduleId).GetPosition();
641  const utl::Vector& dPosition = modulePosition - sdPosition;
642  const double positionCorrection = GetTimeCorrection(dPosition, rAxis);
643 
644  const std::vector<double> modulePatternMatches = module.GetRecData().GetPatternMatchTimes();
645 
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);
649  }
650 
651  } // end module loop
652 
653  const double t50 = GetMedian(counterPatternMatches);
654 
655  return t50;
656  }
657 
658 
659  double
660  MdMuonCounter::GetMedian(const std::vector<double> v)
661  const
662  {
663 
664  unsigned int ndata = v.size();
665  assert(ndata>0); // at least one datum needed to estimate the median
666 
667  // temporary vector to get rid of the ctness of vdata as required by sort
668  std::vector<double> vtemp(v);
669  std::sort(vtemp.begin(), vtemp.end());
670 
671  double median = 0;
672 
673  if (!(ndata % 2)) { // if number of data is even
674  const unsigned int i = ndata / 2;
675  median = 0.5*(vtemp[i-1] + vtemp[i]); // median is the average of central values
676  } else { // if number of data is odd
677  const unsigned int i = (ndata - 1) / 2;
678  median = vtemp[i]; // usual median
679  }
680 
681  return median;
682  }
683 
684 
685  double
686  MdMuonCounter::GetTimeCorrection(const utl::Vector& dposition, const utl::Vector& axis)
687  const
688  {
689  const double s = dposition * axis;
690  const double timeCorrection = s / utl::kSpeedOfLight;;
691 
692  return timeCorrection;
693  }
694 
695 }
Module level reconstruction data. This class contains all data required by the muon reconstruction...
Definition: ModuleRecData.h:29
bool IsCandidate() const
The muon counter status.
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
bool HasMEvent() 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
Definition: Detector.cc:155
const std::vector< double > & GetPatternMatchTimes() const
Functor implementing a constant sampling window strategy.
std::map< std::string, std::string > AttributeMap
Definition: Branch.h:24
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.
Definition: ErrorLogger.h:161
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.
Definition: FrontEnd.cc:57
int GetId() const
Branch GetChild(const std::string &childName) const
Get child of this Branch by child name.
Definition: Branch.cc:211
utl::TraceB & GetTrace()
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.
Definition: MDetector.h:32
std::vector< T >::const_iterator ConstIterator
Definition: Trace.h:60
A TimeStamp holds GPS second and nanosecond for some event.
Definition: TimeStamp.h:110
utl::Point GetPosition() const
Tank position.
Iterator Begin()
Definition: Trace.h:75
Actual muon-sensitive objects.
Class representing a document branch.
Definition: Branch.h:107
class to hold data at Station level
constexpr double s
Definition: AugerUnits.h:163
Module level event data.
Definition: MEvent/Module.h:41
utl::TraceUI & GetChannelsOn()
Number of windows with a signal in a module.
Definition: ModuleRecData.cc:9
utl::TimeStamp GetSignalStartTime() const
Start time of the signal.
bool HasChannelsOn() const
static int delay
Definition: XbAlgo.cc:20
constexpr double nanosecond
Definition: AugerUnits.h:143
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
Definition: FrontEnd.cc:43
bool HasRecData() const
Top of the hierarchy of the detector description interface.
Definition: Detector.h:81
ChannelConstIterator ChannelsBegin() const
void SetNumberOfMuonsErrorHigh(const double e)
const sdet::SDetector & GetSDetector() const
Definition: Detector.cc:119
Array of Scintillator.
int GetLatchBin() const
int GetAssociatedTankId() const
Retrieve the id of the associated surface tank.
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
Definition: FrontEndSiPM.cc:53
void ClearPatternMatchBins()
Clears pattern match detection times information.
unsigned int GetPreT1BufferLength() const
Number of bins of the (cyclic) pre-T1 buffer.
Definition: FrontEndSiPM.cc:61
const utl::Vector & GetAxis() const
void SetNumberOfEstimatedMuons(const double m)
Number of estimated muons in a module.
Functor implementing a constant sampling window strategy.
Definition: GapStrategy.h:18
unsigned int GetNumberOfPatternMatchs() const
Retrieve the number of pattern matchs that impinged this scintillator.
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
int GetId() const
void SetWindowSize(const unsigned int ws)
bool HasGPSData() const
Check whether GPS data object edists.
double GetArea() const
Compute Scintillator&#39;s total area in square metres.
unsigned int GetBufferLength() const
Number of bins of the buffer.
Definition: FrontEnd.h:130
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)
Definition: TimeInterval.h:69
Root detector of the muon detector hierarchy.
void SetSignalT50(const utl::TimeStamp &time)
void SetBinning(const double binning)
Definition: Trace.h:139
constexpr double kSpeedOfLight
A TimeInterval is used to represent time elapsed between two events.
Definition: TimeInterval.h:43
ChannelConstIterator ChannelsEnd() const
ResultFlag
Flag returned by module methods to the RunController.
Definition: VModule.h:60
double GetFADCBinSize() const
int GetId() const
The id of the counter.
ModuleConstIterator ModulesEnd() const
InternalCounterCollection::ComponentIterator CounterIterator
Definition: MEvent.h:31
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.
Definition: Trace-fwd.h:19
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.
bool IsRejected() const
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.
Definition: ConfigUtils.h:35
Vector object.
Definition: Vector.h:30
Detector description interface for SDetector-related data.
Definition: SDetector.h:42
CounterConstIterator CountersEnd() const
Definition: MEvent.h:52
constexpr double ns
Definition: AugerUnits.h:162
Branch GetFirstChild() const
Get first child of this Branch.
Definition: Branch.cc:98
bool IsSiPM() const
bool HasTrace() const
const Station & GetStation(const int stationId) const
Get station by Station Id.
Definition: SDetector.cc:192
Channel level reconstruction data.
const Counter & GetCounter(int id) const
Retrieve Counter by id.
Definition: MDetector.h:68
bool HasRecData() const
void PushBack(const T &value)
Insert a single value at the end.
Definition: Trace.h:119
Iterator End()
Definition: Trace.h:76
Root of the Muon event hierarchy.
Definition: MEvent.h:25
bool HasSEvent() const
bool IsCandidate() const
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)
bool IsSaturated() const
Definition: ModuleRecData.h:85
Functor implementing a constant window consecutive-rows-of-ones criteria.
void MakeRecData()
InternalChannelCollection::ComponentIterator ChannelIterator
Definition: MEvent/Module.h:68
unsigned int GetBufferLength() const
Number of bins of the buffer.
Definition: FrontEndSiPM.h:120

, generated on Tue Sep 26 2023.