MD2ADST.cc
Go to the documentation of this file.
1 #include <utl/config.h>
2 
3 #include "MD2ADST.h"
4 #include "Config.h"
5 #include "ConversionUtil.h"
6 
7 #include <fwk/CentralConfig.h>
8 #include <fwk/LocalCoordinateSystem.h>
9 #include <fwk/CoordinateSystemRegistry.h>
10 
11 #include <det/Detector.h>
12 
13 #include <mdet/MDetector.h>
14 #include <mdet/Counter.h>
15 #include <mdet/Scintillator.h>
16 
17 #include <evt/Event.h>
18 #include <evt/ShowerSimData.h>
19 #include <evt/ShowerRecData.h>
20 #include <evt/ShowerSRecData.h>
21 
22 #include <mevt/MEvent.h>
23 #include <mevt/Counter.h>
24 #include <mevt/CounterSimData.h>
25 
26 #include <utl/Branch.h>
27 #include <utl/ErrorLogger.h>
28 #include <utl/UTCDateTime.h>
29 #include <utl/TimeStamp.h>
30 #include <utl/CoordinateSystemPtr.h>
31 #include <utl/ReferenceEllipsoid.h>
32 #include <utl/Point.h>
33 #include <utl/Vector.h>
34 #include <utl/UTMPoint.h>
35 #include <utl/Particle.h>
36 #include <utl/AugerUnits.h>
37 #include <utl/MathConstants.h>
38 #include <utl/PhysicalConstants.h>
39 #include <utl/PhysicalFunctions.h>
40 #include <utl/Is.h>
41 
42 #include <iostream>
43 #include <string>
44 
45 using utl::m;
46 using utl::meter;
47 using std::cout;
48 using std::endl;
49 
50 
51 namespace otoa {
52 
53  MD2ADST::MD2ADST(const otoa::Config& config) :
54  fConfig(config),
55  fDetector(&det::Detector::GetInstance()),
56  fMdDetector(&fDetector->GetMDetector()),
57  fReferenceCS(fDetector->GetReferenceCoordinateSystem())
58  { }
59 
60 
61  void
62  MD2ADST::Convert(const evt::Event& inEvent, RecEvent& outEvent)
63  const
64  {
65  const auto& inMdEvent = inEvent.GetMEvent();
66  auto& outMdEvent = outEvent.GetMDEvent();
67 
68  // Fill event level data
69  FillMEvent(inEvent, outMdEvent);
70 
71  // Fill shower data
72  utl::CoordinateSystemPtr recShowerPlaneCS;
73  if (inEvent.HasRecShower() && inEvent.GetRecShower().HasMRecShower()) {
74 
75  const auto& inMdShower = inEvent.GetRecShower().GetMRecShower();
76  auto& outMdShower = outMdEvent.GetMdRecShower();
77 
78  // Fill the reconstruction flags
79  outMdShower.SetLdfReconstructed(inMdShower.IsLdfReconstructed());
80  outMdShower.SetBetaFixed(inMdShower.IsBetaFixed());
81  outMdShower.SetCoreFixedLdf(inMdShower.IsCoreFixedLdf());
82  outMdShower.SetGeometryReconstructed(inMdShower.IsGeometryReconstructed());
83  outMdShower.SetCoreFixedGeo(inMdShower.IsCoreFixedGeo());
84  outMdShower.SetCurvatureFixed(inMdShower.IsCurvatureFixed());
85 
86  FillRecShower(inMdShower, outMdShower);
87  recShowerPlaneCS = GetShowerPlaneCS(inMdShower);
88 
89  } else {
90 
91  WARNING("Distances from the MD counters to the core will not be set because the event was not reconstructed with the MD.");
92 
93  }
94 
95  // Add counters
96  for (auto inCounter = inMdEvent.CountersBegin(); inCounter != inMdEvent.CountersEnd(); ++inCounter)
97  outMdEvent.AddCounter(MakeCounter(*inCounter, recShowerPlaneCS));
98 
99  // Add simulated data
100  if (inEvent.HasSimShower()) {
101  const auto& showerPlaneCS = inEvent.GetSimShower().GetShowerCoordinateSystem();
102  for (auto inCounter = inMdEvent.CountersBegin(); inCounter != inMdEvent.CountersEnd(); ++inCounter) {
103  if (inCounter->HasSimData())
104  outMdEvent.AddSimCounter(MakeSimCounter(*inCounter, showerPlaneCS));
105  }
106  }
107  }
108 
109 
110  void
111  MD2ADST::FillMEvent(const evt::Event& inEvent, MDEvent& outMdEvent)
112  const
113  {
114  // Setting the number of candidate counters
115  const auto& inMdEvent = inEvent.GetMEvent();
116  const unsigned int nCandidates = inMdEvent.GetNumberOfCandidateCounters();
117  outMdEvent.SetNumberOfCandidates(nCandidates);
118 
119  if (inEvent.HasRecShower() && inEvent.GetRecShower().HasMRecShower()) {
120  const auto& inMdShower = inEvent.GetRecShower().GetMRecShower();
121  if (inMdShower.HasMLDF()) {
122  outMdEvent.SetRecLevel(eHasMdLDF);
123  }
124  } else if (nCandidates > 0) {
125  outMdEvent.SetRecLevel(eHasTriggeredMdStations);
126  } else {
127  outMdEvent.SetRecLevel(eNoMdEvent);
128  }
129  }
130 
131 
132  void
133  MD2ADST::FillRecShower(const evt::ShowerMRecData& inMdShower, MdRecShower& outMdShower)
134  const
135  {
136  // Fill the shower axis (in the core coordinate system)
137  const auto& corePosition = inMdShower.GetCorePosition();
138  const auto& coreCS = fwk::LocalCoordinateSystem::Create(corePosition);
139  const auto& axis1 = inMdShower.GetAxis();
140  TVector3 axis2(0,0,1);
141  axis2.SetTheta(axis1.GetTheta(coreCS));
142  axis2.SetPhi(axis1.GetPhi(coreCS));
143  outMdShower.SetAxisCoreCS(axis2);
144  outMdShower.SetMdSdAngle(inMdShower.GetMdSdAngle());
145 
146  // Fill the error info of the geometrical reconstruction
147  outMdShower.SetZenithError(inMdShower.GetThetaError());
148  outMdShower.SetAzimuthError(inMdShower.GetPhiError());
149  outMdShower.SetZenithAzimuthCorrelation(inMdShower.GetThetaPhiCorrelation());
150  outMdShower.SetAngleChi2(inMdShower.GetAngleChi2(), inMdShower.GetAngleNdof());
151  outMdShower.SetTimeResidualMean(inMdShower.GetTimeResidualMean());
152  outMdShower.SetTimeResidualSpread(inMdShower.GetTimeResidualSpread());
153 
154  const double radius = inMdShower.GetCurvature();
155  const double dradius = inMdShower.GetCurvatureError();
156  outMdShower.SetCurvatureRadius(radius, dradius);
157 
158  // Fill the LDF
159  if (inMdShower.HasMLDF()) {
160  const auto& ldfTable = inMdShower.GetMLDF();
161  const auto n = ldfTable.GetNPoints();
162  std::vector<double> rhos;
163  rhos.reserve(n);
164  std::vector<double> values;
165  values.reserve(n);
166  for (size_t i = 0; i < n; i += 2) {
167  const double x = ldfTable[i].X();
168  const double y = ldfTable[i].Y();
169  rhos.push_back(x);
170  values.push_back(y);
171  if (x > 1500)
172  i += 4;
173  }
174  outMdShower.SetTabulatedValues(rhos, values);
175 
176  // Fill LDF parameters
177  outMdShower.SetReferenceDistance(inMdShower.GetReferenceDistance());
178  outMdShower.SetNMuRef(inMdShower.GetNMuRef(), inMdShower.GetNMuRefError());
179  outMdShower.SetNMuRefSystematics(inMdShower.GetNMuRefSystematics());
180  outMdShower.SetBeta(inMdShower.GetBeta(), inMdShower.GetBetaError());
181  outMdShower.SetBetaSystematics(inMdShower.GetBetaSystematics());
182 
183  // Fill goodness of fit parameters
184  outMdShower.SetMLDFNdof(inMdShower.GetMLDFNdof());
185  outMdShower.SetMLDFLikelihood(inMdShower.GetMLDFLikelihood());
186  outMdShower.SetMLDFChi2(inMdShower.GetMLDFChi2());
187 
188  // Fill the core position
189  outMdShower.SetCoreSiteCS(ToTVector3(corePosition, fReferenceCS, meter));
190 
191  //Fill the core times
192  outMdShower.SetCoreTime(inMdShower.GetCoreTime().GetGPSSecond(),
193  inMdShower.GetCoreTime().GetGPSNanoSecond());
194 
195  // Fill the core error
196  const utl::Vector& coreError = inMdShower.GetCoreError();
197  outMdShower.SetCoreNorthingError(coreError.GetY(fReferenceCS));
198  outMdShower.SetCoreEastingError(coreError.GetX(fReferenceCS));
199  outMdShower.SetCoreNorthingEastingCorrelation(inMdShower.GetCorrelationXY());
200  }
201  }
202 
203 
204  MdRecCounter
205  MD2ADST::MakeCounter(const mevt::Counter& inCounter, const utl::CoordinateSystemPtr& recShowerPlaneCS)
206  const
207  {
208  MdRecCounter outCounter;
209 
210  // set ids
211  const unsigned int counterId = inCounter.GetId();
212  outCounter.SetId(counterId);
213 
214  const auto& detCounter = fMdDetector->GetCounter(counterId);
215 
216  // get the counter for future master data lookups
217  outCounter.SetSdPartnerId(detCounter.GetAssociatedTankId());
218 
219  // map the status of counter to outCounter
220  if (inCounter.IsCandidate()) {
221  outCounter.SetCandidate();
222  } else if (inCounter.IsSilent()) {
223  outCounter.SetSilent();
224  } else if (inCounter.IsRejected()) {
225  outCounter.SetRejected();
226  }
227 
228  // set the reconstructed data flag
229  const bool recDataFlag = inCounter.HasRecData();
230  outCounter.SetRecDataFlag(recDataFlag);
231  if (!recDataFlag) { // if not reconstructed data
232  return outCounter;
233  }
234 
235  // set dense flag
236  try {
237  if (detCounter.IsDense())
238  outCounter.SetIsDense();
239  } catch (utl::AugerException& e) {
240  ERROR(e.GetMessage());
241  exit(-1);
242  }
243 
244  outCounter.SetNumberOfChannelsOn(inCounter.GetNumberOfChannelsOn());
245 
246  outCounter.SetNumberOfMuons(inCounter.GetNumberOfEstimatedMuons());
247  outCounter.SetNumberOfMuonsErrorHigh(inCounter.GetNumberOfMuonsErrorHigh());
248  outCounter.SetNumberOfMuonsErrorLow(inCounter.GetNumberOfMuonsErrorLow());
249  outCounter.SetNumberOfMuonsLowLimit(inCounter.GetNumberOfMuonsLowLimit());
250 
251  outCounter.SetMeanMuons(inCounter.GetMeanMuons());
252  outCounter.SetMeanMuonsErrorHigh(inCounter.GetMeanMuonsErrorHigh());
253  outCounter.SetMeanMuonsErrorLow(inCounter.GetMeanMuonsErrorLow());
254  outCounter.SetMeanMuonsLowLimit(inCounter.GetMeanMuonsLowLimit());
255 
256  outCounter.SetActiveArea(inCounter.GetActiveArea());
257 
258  outCounter.SetMuonDensity(inCounter.GetMuonDensity());
259  outCounter.SetMuonDensityErrorHigh(inCounter.GetMuonDensityErrorHigh());
260  outCounter.SetMuonDensityErrorLow(inCounter.GetMuonDensityErrorLow());
261 
262  outCounter.SetMeanMuonDensity(inCounter.GetMeanMuonDensity());
263  outCounter.SetMeanMuonDensityErrorHigh(inCounter.GetMeanMuonDensityErrorHigh());
264  outCounter.SetMeanMuonDensityErrorLow(inCounter.GetMeanMuonDensityErrorLow());
265 
266  outCounter.SetLDFResidual(inCounter.GetLDFResidual());
267  outCounter.SetTimeResidual(inCounter.GetTimeResidual());
268  outCounter.SetPlaneFrontDelay(inCounter.GetPlaneFrontDelay());
269 
270  // ADC LG
271  outCounter.SetADCCalibratedLG(inCounter.IsADCCalibratedLG());
272  if (outCounter.IsADCCalibratedLG()) {
273  outCounter.SetNumberOfMuonsLG(inCounter.GetNumberOfEstimatedMuonsLG());
274  outCounter.SetNumberOfMuonsErrorHighLG(inCounter.GetNumberOfMuonsErrorHighLG());
275  outCounter.SetNumberOfMuonsErrorLowLG(inCounter.GetNumberOfMuonsErrorLowLG());
276  outCounter.SetActiveAreaLG(inCounter.GetActiveAreaLG());
277  outCounter.SetMuonDensityLG(inCounter.GetMuonDensityLG());
278  outCounter.SetMuonDensityErrorHighLG(inCounter.GetMuonDensityErrorHighLG());
279  outCounter.SetMuonDensityErrorLowLG(inCounter.GetMuonDensityErrorLowLG());
280  }
281 
282  // ADC HG
283  outCounter.SetADCCalibratedHG(inCounter.IsADCCalibratedHG());
284  if (outCounter.IsADCCalibratedHG()) {
285  outCounter.SetNumberOfMuonsHG(inCounter.GetNumberOfEstimatedMuonsHG());
286  outCounter.SetNumberOfMuonsErrorHighHG(inCounter.GetNumberOfMuonsErrorHighHG());
287  outCounter.SetNumberOfMuonsErrorLowHG(inCounter.GetNumberOfMuonsErrorLowHG());
288  outCounter.SetActiveAreaHG(inCounter.GetActiveAreaHG());
289  outCounter.SetMuonDensityHG(inCounter.GetMuonDensityHG());
290  outCounter.SetMuonDensityErrorHighHG(inCounter.GetMuonDensityErrorHighHG());
291  outCounter.SetMuonDensityErrorLowHG(inCounter.GetMuonDensityErrorLowHG());
292  }
293 
294  // Fill the counter position
295  const auto& counterPosition = detCounter.GetPosition();
296  outCounter.SetPosition(ToTVector3(counterPosition, fReferenceCS, meter));
297 
298  // Fill the position in the shower plane reference system
299  if (recShowerPlaneCS) { // valid check of a boost::shared_ptr!
300  const double rho = counterPosition.GetRho(recShowerPlaneCS) / m;
301  const double azimuth = counterPosition.GetPhi(recShowerPlaneCS) / utl::deg;
302  const double delta = counterPosition.GetZ(recShowerPlaneCS) / m;
303  outCounter.SetSPDistance(rho, 0); // errors are set to zero...
304  outCounter.SetSPAzimuth(azimuth, 0);
305  outCounter.SetSPDelta(delta, 0);
306  }
307 
308  if (inCounter.HasT50()) {
309  const auto signalT50 = inCounter.GetSignalT50();
310  outCounter.SetT50(signalT50.GetGPSSecond(), signalT50.GetGPSNanoSecond());
311  outCounter.SetT50Error(inCounter.GetT50Error());
312  outCounter.SetT502SdStart(inCounter.GetT502SdStart());
313  }
314 
315  // add the modules
316  for (auto inModule = inCounter.ModulesBegin(); inModule != inCounter.ModulesEnd(); ++inModule) {
317  const unsigned int moduleId = inModule->GetId();
318  const MdRecModule outModule = MakeModule(*inModule, detCounter.GetModule(moduleId), recShowerPlaneCS);
319  outCounter.AddModule(outModule);
320  }
321 
322  return outCounter;
323  }
324 
325 
326  MdRecModule
327  MD2ADST::MakeModule(const mevt::Module& inModule, const mdet::Module& mdetModule, const utl::CoordinateSystemPtr& recShowerPlaneCS)
328  const
329  {
330  MdRecModule outModule;
331  const unsigned int moduleId = inModule.GetId();
332  outModule.SetId(moduleId);
333 
334  // set flags
335  if (inModule.IsCandidate()) {
336  outModule.SetCandidate();
337  } else if (inModule.IsSilent()) {
338  outModule.SetSilent();
339  } else if (inModule.IsRejected()) {
340  outModule.SetRejected();
341  }
342 
343  // return if no reconstructed data
344  if (!inModule.HasRecData())
345  return outModule;
346 
347  // beware some data is at the module and other at the module reconstructed data levels
348  const auto& inRecData = inModule.GetRecData();
349 
350  // Set the master data
351  outModule.SetActiveArea(inRecData.GetActiveArea());
352  outModule.SetSegmentation(inRecData.GetSegmentation());
353 
354  double sampleNanos = 0;
355  int numberOfSamples = 0;
356 
357  if (!mdetModule.IsSiPM()) {
358  sampleNanos = mdetModule.GetFrontEnd().GetMeanSampleRatePeriod();
359  numberOfSamples = mdetModule.GetFrontEnd().GetBufferLength();
360  } else {
361  sampleNanos = mdetModule.GetFrontEndSiPM().GetMeanSampleRatePeriod();
362  numberOfSamples = mdetModule.GetFrontEndSiPM().GetBufferLength();
363  }
364 
365  outModule.SetSampleTime(sampleNanos);
366  outModule.SetNumberOfSamples(numberOfSamples);
367  //outModule.SetSaturationFlag(inRecData.SaturationFlag());
368 
369  // Fill the channelsOn trace
370  if (inRecData.HasChannelsOn()) {
371  const auto& inChannelsOn = inRecData.GetChannelsOn();
372  outModule.GetChannelsOn().assign(inChannelsOn.Begin(), inChannelsOn.End());
373  outModule.SetChannelsOnBinning(inChannelsOn.GetBinning());
374  }
375 
376  if (inRecData.HasChannelsOnStartTime()) {
377  const auto& t = inRecData.GetChannelsOnStartTime();
378  outModule.SetChannelsOnStartTime(t.GetGPSSecond(), t.GetGPSNanoSecond());
379  }
380 
381  // Fill the pattern matches vector
382  outModule.GetPatternMatchTimes() = inRecData.GetPatternMatchTimes();
383 
384  // Fill the nmuVsTime and muVsTime traces
385  if (inRecData.HasMeanMuonsVsTime()) {
386  const auto& inMeanMuonsVsTime = inRecData.GetMeanMuonsVsTime();
387  outModule.SetMeanMuonsVsTime(inMeanMuonsVsTime.Begin(), inMeanMuonsVsTime.End());
388  }
389  if (inRecData.HasNumberOfMuonsVsTime()) {
390  const auto& inNumberOfMuonsVsTime = inRecData.GetNumberOfMuonsVsTime();
391  outModule.SetNumberOfMuonsVsTime(inNumberOfMuonsVsTime.Begin(), inNumberOfMuonsVsTime.End());
392  }
393 
394  // Fill the number of muons data
395  outModule.SetNumberOfEstimatedMuons(inRecData.GetNumberOfEstimatedMuons());
396  outModule.SetNumberOfMuonsErrorHigh(inRecData.GetNumberOfMuonsErrorHigh());
397  outModule.SetNumberOfMuonsErrorLow(inRecData.GetNumberOfMuonsErrorLow());
398  outModule.SetNumberOfMuonsLowLimit(inRecData.GetNumberOfMuonsLowLimit());
399 
400  outModule.SetMeanMuons(inRecData.GetMeanMuons());
401  outModule.SetMeanMuonsErrorHigh(inRecData.GetMeanMuonsErrorHigh());
402  outModule.SetMeanMuonsErrorLow(inRecData.GetMeanMuonsErrorLow());
403  outModule.SetMeanMuonsLowLimit(inRecData.GetMeanMuonsLowLimit());
404 
405  outModule.SetMuonDensity(inRecData.GetMuonDensity());
406  outModule.SetMuonDensityErrorHigh(inRecData.GetMuonDensityErrorHigh());
407  outModule.SetMuonDensityErrorLow(inRecData.GetMuonDensityErrorLow());
408 
409  outModule.SetMeanMuonDensity(inRecData.GetMeanMuonDensity());
410  outModule.SetMeanMuonDensityErrorHigh(inRecData.GetMeanMuonDensityErrorHigh());
411  outModule.SetMeanMuonDensityErrorLow(inRecData.GetMeanMuonDensityErrorLow());
412 
413  outModule.SetLDFResidual(inRecData.GetLDFResidual());
414 
415  // Fill the module position
416  const auto& modulePosition = mdetModule.GetPosition();
417  outModule.SetPosition(ToTVector3(modulePosition, fReferenceCS, meter));
418 
419  // Fill the position in the shower plane reference system
420  if (recShowerPlaneCS) {
421  const double rho = modulePosition.GetRho(recShowerPlaneCS) / m;
422  const double azimuth = modulePosition.GetPhi(recShowerPlaneCS) / utl::deg;
423  const double delta = modulePosition.GetZ(recShowerPlaneCS) / m;
424  outModule.SetSPDistance(rho, 0); // errors are set to zero...
425  outModule.SetSPAzimuth(azimuth, 0);
426  outModule.SetSPDelta(delta, 0);
427  }
428 
429  // Store integrator traces
430  if (fConfig.StoreMDTraces()) { // if config set to save traces
431  if (inModule.HasDynodeTrace()) {
432  const auto& t = inModule.GetDynodeTrace();
433  outModule.SetDynodeTrace(std::vector<unsigned short int>(t.Begin(), t.End()));
434  }
435 
436  // SiPM Integrator
437  if (inModule.HasIntegratorATrace()) { // if has integrator LG trace
438  const auto& t = inModule.GetIntegratorATrace();
439  outModule.SetIntegratorATrace(std::vector<unsigned short int>(t.Begin(), t.End()));
440  }
441 
442  if (inModule.HasIntegratorBTrace()) { // if has integrator HG trace
443  const auto& t = inModule.GetIntegratorBTrace();
444  outModule.SetIntegratorBTrace(std::vector<unsigned short int>(t.Begin(), t.End()));
445  }
446  }
447 
448  // store integrator reconstruction
449 
450  if (inRecData.IsADCCalibratedLG()) {
451  outModule.SetMeanChargeMuonLG(inRecData.GetMeanChargeMuonLG());
452  outModule.SetStdDevChargeMuonLG(inRecData.GetStdDevChargeMuonLG());
453 
454  outModule.SetNumberOfEstimatedMuonsADCLG(inRecData.GetNumberOfEstimatedMuonsADCLG());
455  outModule.SetNumberOfMuonsADCErrorHighLG(inRecData.GetNumberOfMuonsADCErrorHighLG());
456  outModule.SetNumberOfMuonsADCErrorLowLG(inRecData.GetNumberOfMuonsADCErrorLowLG());
457 
458  outModule.SetMuonDensityLG(inRecData.GetMuonDensityLG());
459  outModule.SetMuonDensityErrorHighLG(inRecData.GetMuonDensityErrorHighLG());
460  outModule.SetMuonDensityErrorLowLG(inRecData.GetMuonDensityErrorLowLG());
461  outModule.SetTotalChargeLG(inRecData.GetTotalChargeLG());
462  }
463 
464  if (inRecData.IsADCCalibratedHG()) {
465  outModule.SetMeanChargeMuonHG(inRecData.GetMeanChargeMuonHG());
466  outModule.SetStdDevChargeMuonHG(inRecData.GetStdDevChargeMuonHG());
467 
468  outModule.SetNumberOfEstimatedMuonsADCHG(inRecData.GetNumberOfEstimatedMuonsADCHG());
469  outModule.SetNumberOfMuonsADCErrorHighHG(inRecData.GetNumberOfMuonsADCErrorHighHG());
470  outModule.SetNumberOfMuonsADCErrorLowHG(inRecData.GetNumberOfMuonsADCErrorLowHG());
471 
472  outModule.SetMuonDensityHG(inRecData.GetMuonDensityHG());
473  outModule.SetMuonDensityErrorHighHG(inRecData.GetMuonDensityErrorHighHG());
474  outModule.SetMuonDensityErrorLowHG(inRecData.GetMuonDensityErrorLowHG());
475  outModule.SetTotalChargeHG(inRecData.GetTotalChargeHG());
476  }
477 
478  // add channels
479  for (auto inChannel = inModule.ChannelsBegin(); inChannel != inModule.ChannelsEnd(); ++inChannel) {
480  const auto outChannel = MakeChannel(*inChannel, mdetModule);
481  outModule.AddChannel(outChannel);
482  }
483 
484  return outModule;
485  }
486 
487 
488  MdRecChannel
489  MD2ADST::MakeChannel(const mevt::Channel& inChannel, const mdet::Module& detModule)
490  const
491  {
492  MdRecChannel outChannel;
493 
494  // set ids
495  const unsigned int channelId = inChannel.GetId();
496  outChannel.SetId(channelId);
497  const unsigned int scintillatorId = detModule.ChannelToScintillatorId(channelId);
498  outChannel.SetScintillatorId(scintillatorId);
499  const unsigned int pixelId = detModule.ChannelToPixelId(channelId);
500  outChannel.SetPixelId(pixelId);
501 
502  // set channel mask
503  outChannel.SetMask(inChannel.IsMasked());
504 
505  // set trace info
506  if (inChannel.HasTrace()) {
507  const auto& trace = inChannel.GetTrace();
508  outChannel.SetNumberOfBins(trace.GetSize());
509  outChannel.SetBinning(trace.GetBinning());
510 
511  if (inChannel.HasTraceStartTime()) {
512  const auto& t = inChannel.GetTraceStartTime();
513  outChannel.SetTraceStartTime(t.GetGPSSecond(), t.GetGPSNanoSecond());
514  }
515 
516  if (fConfig.StoreMDTraces()) {
517  // if config set to save traces
518  outChannel.SetTrace(std::vector<char>(trace.Begin(), trace.End()));
519  }
520 
521  }
522 
523  if (inChannel.HasRecData()) {
524  const auto& channelRecData = inChannel.GetRecData();
525  // Fill the pattern matches vector
526  outChannel.GetPatternMatchTimes().assign(channelRecData.PatternMatchBinsBegin(), channelRecData.PatternMatchBinsEnd());
527  }
528 
529  return outChannel;
530  }
531 
532 
533  MdSimCounter
534  MD2ADST::MakeSimCounter(const mevt::Counter& inCounter, const utl::CoordinateSystemPtr& showerPlaneCS)
535  const
536  {
537  MdSimCounter outCounter;
538 
539  const auto& sPos = fMdDetector->GetCounter(inCounter.GetId()).GetPosition();
540  const auto& detCounter = fMdDetector->GetCounter(inCounter.GetId());
541  const utl::CoordinateSystemPtr& counterCS = detCounter.GetLocalCoordinateSystem();
542  const auto& cSimData = inCounter.GetSimData();
543 
544  outCounter.SetId(inCounter.GetId());
545  outCounter.SetSdPartnerId(detCounter.GetAssociatedTankId());
546  outCounter.SetInsideRMinFlag(cSimData.IsInsideMinRadius());
547 
548  outCounter.SetSPDelta(sPos.GetZ(showerPlaneCS) / m);
549  outCounter.SetSPDistance(sPos.GetRho(showerPlaneCS) / m);
550  outCounter.SetSPAzimuth(sPos.GetPhi(showerPlaneCS) / utl::deg);
551 
552  for (auto mIt = inCounter.ModulesBegin(); mIt != inCounter.ModulesEnd(); ++mIt) {
553  const int mId = mIt->GetId();
554  const auto& detModule = detCounter.GetModule(mId);
555 
556  // get area of each module
557  const double areaPerModule = mIt->HasRecData() ?
558  mIt->GetRecData().GetActiveArea() : detModule.GetArea();
559 
560  outCounter.SetAreaByModule(areaPerModule, mIt->GetId());
561 
562  for (auto chIt = mIt->ChannelsBegin(); chIt != mIt->ChannelsEnd(); ++chIt) {
563  const int chId = chIt->GetId();
564  const int scId = detModule.ChannelToScintillatorId(chId);
565  if (mIt->HasScintillator(scId)) {
566  const auto& scintillator = mIt->GetScintillator(scId);
567  if (scintillator.HasSimData()) {
568 
569  MdSimScintillator myscint;
570  const auto& scintSimData = scintillator.GetSimData();
571  const int injmu = scintSimData.GetNumberOfInjectedMuons();
572  const int ccmu = scintSimData.GetNumberOfCornerClippingMuons();
573  const int electrons = scintSimData.GetNumberOfElectrons();
574  myscint.SetNumberOfInjectedMuons(injmu);
575  myscint.SetNumberOfCornerClippingMuons(ccmu);
576  myscint.SetNumberOfElectrons(electrons);
577  myscint.SetId(scId);
578  myscint.SetChannelId(chId);
579  myscint.SetPixelId(detModule.ChannelToPixelId(chId));
580  myscint.SetModuleId(mId);
581 
582  for (auto pIt = scintSimData.SPEPulsesBegin(); pIt != scintSimData.SPEPulsesEnd(); ++pIt) {
583  myscint.AddSPEPulse(pIt->fMu, pIt->fSigma, pIt->fAmplitude, pIt->fDestPixelId);
584  }
585  for (auto pIt = scintSimData.PEPulsesBegin(); pIt != scintSimData.PEPulsesEnd(); ++pIt) {
586  myscint.AddPEPulse(pIt->fT0, pIt->fAmplitude1, pIt->fAmplitude2, pIt->fAmplitude3, pIt->fRiseTime,
587  pIt->fFallTime1, pIt->fFallTime2, pIt->fFallTime3, pIt->fDestPixelId);
588  }
589 
590  double sumKinEnergy = 0;
591  double sumKinEnergyMuons = 0;
592  {
593  const auto& pTypes = fConfig.StoreMDParticleTypes();
594  for (auto pIt = scintSimData.ParticlesBegin(); pIt != scintSimData.ParticlesEnd(); ++pIt) {
595  const double kinEnergy = pIt->GetKineticEnergy();
596  sumKinEnergy += kinEnergy;
597  const auto pType = pIt->GetType();
598  const bool isMuon = (pType == utl::Particle::eMuon || pType == utl::Particle::eAntiMuon);
599  if (isMuon)
600  sumKinEnergyMuons += kinEnergy;
602  (pTypes.empty() || utl::Is(pType).In(pTypes))) {
603  AddParticle(*pIt, detCounter, mId, scId, myscint);
604  }
605  }
606  }
607 
608  myscint.SetKineticEnergy(sumKinEnergy);
609  myscint.SetMuonKineticEnergy(sumKinEnergyMuons);
610 
611  myscint.SetEnergyDeposit(scintSimData.GetEnergyDeposit());
612  myscint.SetEnergyDepositMuons(scintSimData.GetEnergyDepositMuons());
613 
614  outCounter.AddSimScintillator(myscint);
615  }
616  }
617  }
618  }
619 
620  return outCounter;
621  }
622 
623 
626  const
627  {
628  //const auto& rCore = mRecShower.GetCorePosition(); // core from MD rec. If no MD geometry reco, then it is core from SD rec
629  const auto& rCore = mRecShower.GetReferenceCorePosition(); // core from SD reco
630  const auto& coreCS = fwk::LocalCoordinateSystem::Create(rCore);
631 
632  //const utl::Vector& rAxis = mRecShower.GetAxis(); // axis from MD geometry reco. Currently deprecated so it outputs an empty vector
633  const auto& rAxis = mRecShower.GetReferenceAxis(); // axis from SD reco
634  if (!rAxis)
635  throw utl::NonExistentComponentException("No axis is provided to compute shower plane CS.");
636 
637  const double theta = rAxis.GetTheta(coreCS);
638  const double phi = rAxis.GetPhi(coreCS);
639 
640  const auto& recShowerPlaneCS =
642  return recShowerPlaneCS;
643  }
644 
645 
646  void
647  MD2ADST::AddParticle(const utl::Particle& p, const mdet::Counter& detCounter, const int mId, const int scintId, MdSimScintillator& myScint)
648  const
649  {
650  const utl::CoordinateSystemPtr& counterCS = detCounter.GetLocalCoordinateSystem();
651  const auto& detModule = detCounter.GetModule(mId);
652  const utl::CoordinateSystemPtr& moduleCS = detModule.GetLocalCoordinateSystem();
653  const auto& detScint = detModule.GetScintillator(scintId);
654  const utl::CoordinateSystemPtr& scintCS = detScint.GetLocalCoordinateSystem();
655 
656  const utl::Point& pos = p.GetPosition();
657  const auto pc = pos.GetCoordinates(counterCS);
658  const TVector3 positionStationCS(pc.get<0>(), pc.get<1>(), pc.get<2>());
659  const auto pm = pos.GetCoordinates(moduleCS);
660  const TVector3 positionModuleCS(pm.get<0>(), pm.get<1>(), pm.get<2>());
661  const auto ps = pos.GetCoordinates(scintCS);
662  const TVector3 positionScintillatorCS(ps.get<0>(), ps.get<1>(), ps.get<2>());
663  const utl::Vector& direction = p.GetDirection();
664  const double zenithStationCS = direction.GetTheta(counterCS);
665  const double azimuthStationCS = direction.GetPhi(counterCS);
666  const double azimuthModuleCS = direction.GetPhi(moduleCS);
667  const double azimuthScintCS = direction.GetPhi(scintCS);
668 
669  //const utl::Particle::Source source = partIt->GetSource();
670  const short int source = p.GetSource();
671  const double kineticEnergy = p.GetKineticEnergy();
672  const int type = p.GetType();
673 
674  myScint.AddParticle(zenithStationCS, azimuthStationCS,
675  azimuthModuleCS, azimuthScintCS,
676  positionStationCS, positionModuleCS, positionScintillatorCS,
677  kineticEnergy, source, type);
678  }
679 
680 }
double GetTimeResidualSpread() const
double GetReferenceDistance() const
bool IsCandidate() const
The muon counter status.
double GetNumberOfMuonsErrorHighHG() const
double GetNumberOfMuonsErrorHighLG() const
unsigned int GetNPoints() const
void SetLdfReconstructed(bool flag=true)
const utl::TimeStamp & GetCoreTime() const
const Module & GetModule(const int mId) const
Retrieve by id a constant module.
utl::TimeStamp GetTraceStartTime() const
Return the timestamp associated with the start of the trace. The timestamp of the first bin of the tr...
Point object.
Definition: Point.h:32
mevt::MEvent & GetMEvent()
double GetPhi(const CoordinateSystemPtr &coordinateSystem) const
azimuth (phi) angle in spherical and cylindrical coordinates
Definition: BasicVector.h:254
double GetLDFResidual() const
The LDF residual of the counter is calculated as the sum of the estimated muons of the associated mod...
double GetMeanMuonsLowLimit() const
IsProxy< T > Is(const T &x)
Definition: Is.h:46
double GetThetaPhiCorrelation() const
bool HasIntegratorBTrace() const
Base class for all exceptions used in the auger offline code.
double GetNumberOfEstimatedMuonsLG() const
The number of estimated muons with the ADC is calculated as the sum of the estimated muons of the ass...
const utl::Vector & GetReferenceAxis() const
**void SetActiveArea(const double area)
bool HasRecData() const
Counter is flagged has having reconstructed data if at least one of its associated modules has recons...
Counter level event data.
bool HasRecShower() const
bool HasDynodeTrace() const
Describes a particle for Simulation.
Definition: Particle.h:26
double GetAngleChi2() const
double GetTheta(const CoordinateSystemPtr &coordinateSystem) const
zenith (theta) angle in spherical coordinates
Definition: BasicVector.h:248
double GetT50Error() const
double GetMeanMuonDensityErrorLow() const
ShowerRecData & GetRecShower()
double GetPhiError() const
bool HasT50() const
The median of the arrival time of muons in GPS sec, ns All modules associated to the counter are cons...
double GetMeanMuonDensityErrorHigh() const
bool HasSimShower() const
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Local system based on position and configured rotations.
const utl::Point & GetReferenceCorePosition() const
ChannelRecData & GetRecData()
const double meter
Definition: GalacticUnits.h:29
double GetMdSdAngle() const
int ChannelToPixelId(const int cId) const
double GetActiveAreaLG() const
double GetNumberOfMuonsErrorHigh() const
utl::Point GetPosition() const
bool IsADCCalibratedLG() const
Check if the counter ADC LG channel is calibrated.
void AddParticle(const utl::Particle &p, const mdet::Counter &c, const int moduleId, const int scintId, MdSimScintillator &ms) const
Definition: MD2ADST.cc:647
bool IsRejected() const
Check if the counter is rejected.
Base class for exceptions trying to access non-existing components.
int GetId() const
const otoa::Config & fConfig
Definition: MD2ADST.h:35
utl::TraceB & GetTrace()
MD2ADST(const otoa::Config &config)
Definition: MD2ADST.cc:53
double GetMeanMuonDensity() const
int exit
Definition: dump1090.h:237
double GetMuonDensityHG() const
bool IsSilent() const
Check if the counter is silent.
double GetMuonDensityErrorLowLG() const
MdRecChannel MakeChannel(const mevt::Channel &c, const mdet::Module &m) const
Definition: MD2ADST.cc:489
double GetMuonDensityErrorHighLG() const
double GetActiveAreaHG() const
const utl::Vector & GetAxis() const
unsigned int GetAngleNdof() const
int ChannelToScintillatorId(const int cId) const
constexpr double deg
Definition: AugerUnits.h:140
const utl::Vector & GetCoreError() const
double GetActiveArea() const
utl::TraceUSI & GetDynodeTrace()
Definition: MEvent/Module.cc:7
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
double GetNMuRefSystematics() const
double GetMuonDensity() const
The density measured by a counter is the calculated as the number of estimated muons over the active ...
double GetTimeResidual() const
Residual of geometry fit.
double GetMeanMuons() const
bool IsADCCalibratedHG() const
Check if the counter ADC HG channel is calibrated.
Module level event data.
Definition: MEvent/Module.h:41
double GetMLDFNdof() const
double GetTimeResidualMean() const
void FillMEvent(const evt::Event &e, MDEvent &me) const
Definition: MD2ADST.cc:111
double GetMuonDensityErrorLowHG() const
double GetX(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:206
utl::CoordinateSystemPtr GetShowerPlaneCS(const evt::ShowerMRecData &sr) const
Definition: MD2ADST.cc:625
const mdet::MDetector * fMdDetector
Definition: MD2ADST.h:39
double GetNumberOfMuonsLowLimit() const
The lower limit to the number of muons in a counter.
const utl::TabulatedFunctionErrors & GetMLDF() const
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
Definition: FrontEnd.cc:43
Converts an Offline event to ADST.
Definition: Config.h:19
bool HasRecData() const
ChannelConstIterator ChannelsBegin() const
constexpr double meter
Definition: AugerUnits.h:81
void FillRecShower(const evt::ShowerMRecData &sr, MdRecShower &mr) const
Definition: MD2ADST.cc:133
Array of Scintillator.
bool IsSilent() const
ShowerSimData & GetSimShower()
MdSimCounter MakeSimCounter(const mevt::Counter &c, const utl::CoordinateSystemPtr &showerPlaneCS) const
Definition: MD2ADST.cc:534
bool HasTraceStartTime() const
static Policy::type RotationY(const double angle, const CoordinateSystemPtr &theCS)
Construct from rotation about Y axis.
double GetMuonDensityErrorHighHG() const
double GetMeanSampleRatePeriod() const
Mean electronic sample rate period.
Definition: FrontEndSiPM.cc:53
static Policy::type RotationZ(const double angle, const CoordinateSystemPtr &theCS)
Construct from rotation about Z axis.
unsigned int GetNumberOfChannelsOn() const
void Convert(const evt::Event &inEvent, RecEvent &outEvent) const
Definition: MD2ADST.cc:62
double GetNumberOfMuonsErrorLowHG() const
bool StoreMDInjectedParticles() const
Definition: Config.h:111
bool IsMasked() const
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
const utl::Point & GetCorePosition() const
int GetId() const
utl::TraceUSI & GetIntegratorATrace()
bool HasMRecShower() const
bool HasIntegratorATrace() const
double GetCurvature() const
unsigned int GetBufferLength() const
Number of bins of the buffer.
Definition: FrontEnd.h:130
const FrontEnd & GetFrontEnd() const
ModuleConstIterator ModulesBegin() const
Root detector of the muon detector hierarchy.
double GetRho(const CoordinateSystemPtr &coordinateSystem) const
radius r in cylindrical coordinates (distance to z axis)
Definition: BasicVector.h:263
double GetMLDFChi2() const
double GetMuonDensityErrorHigh() const
double GetNumberOfMuonsErrorLow() const
double GetKineticEnergy() const
Get kinetic energy of the particle.
Definition: Particle.h:130
utl::CoordinateSystemPtr fReferenceCS
Definition: MD2ADST.h:40
ShowerMRecData & GetMRecShower()
void SetBinning(const double binning)
Definition: Trace.h:139
double GetY(const CoordinateSystemPtr &coordinateSystem) const
Definition: BasicVector.h:209
ChannelConstIterator ChannelsEnd() const
double GetMeanMuonsErrorLow() const
int GetId() const
The id of the counter.
ModuleConstIterator ModulesEnd() const
unsigned long GetGPSSecond() const
GPS second.
Definition: TimeStamp.h:124
double GetGPSNanoSecond() const
GPS nanosecond.
Definition: TimeStamp.h:127
double GetPlaneFrontDelay() const
Delay of the couner wrt to a plane front oriented with the reconstructed shower axis.
ModuleRecData & GetRecData()
Source GetSource() const
Source of the particle (eg. shower or background)
Definition: Particle.h:107
double GetCurvatureError() const
const FrontEndSiPM & GetFrontEndSiPM() const
double GetNumberOfEstimatedMuons() const
The number of estimated muons of the counter is calculated as the sum of the estimated muons of the a...
bool IsRejected() const
Channel level event data.
bool StoreMDTraces() const
Definition: Config.h:108
utl::TimeStamp GetSignalT50() const
Vector object.
Definition: Vector.h:30
const std::set< int > & StoreMDParticleTypes() const
Definition: Config.h:113
int GetType() const
Definition: Particle.h:101
double GetMeanMuonsErrorHigh() const
const Point & GetPosition() const
Position of the particle.
Definition: Particle.h:110
bool HasMLDF() const
double GetNMuRefError() const
MdRecCounter MakeCounter(const mevt::Counter &c, const utl::CoordinateSystemPtr &cs) const
Definition: MD2ADST.cc:205
MdRecModule MakeModule(const mevt::Module &em, const mdet::Module &dm, const utl::CoordinateSystemPtr &cs) const
Definition: MD2ADST.cc:327
double GetMuonDensityLG() const
double GetNMuRef() const
bool IsSiPM() const
Interface class to access to the Muon Reconstruction of a Shower.
double GetThetaError() const
TVector3 ToTVector3(const T &v, const utl::CoordinateSystemPtr &cs, const double unit=1)
double GetMuonDensityErrorLow() const
utl::TraceUSI & GetIntegratorBTrace()
bool HasTrace() 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.
CounterSimData & GetSimData()
bool HasRecData() const
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
constexpr double m
Definition: AugerUnits.h:121
const Vector & GetDirection() const
Unit vector giving particle direction.
Definition: Particle.h:114
double GetNumberOfEstimatedMuonsHG() const
unsigned int GetNumberOfCandidateCounters() const
Definition: MEvent.cc:43
double GetT502SdStart() const
Nanoseconds between the MD t50 and the SD signal start time (md t50-sd start)
bool IsCandidate() const
const std::string & GetMessage() const
Retrieve the message from the exception.
double GetBetaSystematics() const
double GetNumberOfMuonsErrorLowLG() const
utl::CoordinateSystemPtr GetShowerCoordinateSystem() const
double GetBetaError() const
double GetMLDFLikelihood() const
double GetCorrelationXY() const
double GetBeta() const
unsigned int GetBufferLength() const
Number of bins of the buffer.
Definition: FrontEndSiPM.h:120

, generated on Tue Sep 26 2023.