MEvent/Counter.cc
Go to the documentation of this file.
1 #include <mevt/Counter.h>
2 
3 #include <sstream>
4 
5 using std::cout;
6 using std::endl;
7 
8 
9 namespace mevt {
10 
11  void
13  {
14  if (fSimData)
15  ERROR("SimData already exists - Not Replacing");
16  else
18  }
19 
20 
21  bool
23  const
24  {
25  if (!fModules.GetNumberOf())
26  return false;
27 
28  // return true
29  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
30  if (im->HasRecData())
31  return true;
32 
33  return false;
34  }
35 
36 
37  size_t
39  const
40  {
41  size_t nCandidateModules = 0;
42 
43  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
44  if (im->IsCandidate())
45  ++nCandidateModules;
46 
47  return nCandidateModules;
48  }
49 
50 
51  size_t
53  const
54  {
55  size_t nSilentModules = 0;
56 
57  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
58  if (im->IsSilent())
59  ++nSilentModules;
60 
61  return nSilentModules;
62  }
63 
64 
65  size_t
67  const
68  {
69  size_t nRejectedModules = 0;
70 
71  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
72  if (im->IsRejected())
73  ++nRejectedModules;
74 
75  return nRejectedModules;
76  }
77 
78 
79  bool
81  const
82  {
83  const size_t nCandidateModules = CountCandidateModules();
84 
85  return nCandidateModules >= 1;
86  }
87 
88 
89  bool
91  const
92  {
93  const size_t nCandidateModules = CountCandidateModules();
94  const size_t nSilentModules = CountSilentModules();
95 
96  return !nCandidateModules && nSilentModules > 0;
97  }
98 
99 
100  bool
102  const
103  {
104  return !CountCandidateModules() &&
105  !CountSilentModules() &&
107  }
108 
109 
110  bool
112  const
113  {
114  // if not candidate return false
115  if (!IsCandidate())
116  return false;
117 
118  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
119  if (im->IsCandidate() && im->HasRecData() && im->GetRecData().IsSaturated())
120  return true;
121 
122  return false;
123  }
124 
125 
126  bool
128  const
129  {
130  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
131  if (im->HasRecData() && im->GetRecData().IsADCCalibratedLG())
132  return true;
133 
134  return false;
135  }
136 
137 
138  bool
140  const
141  {
142  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
143  if (im->HasRecData() && im->GetRecData().IsADCCalibratedHG())
144  return true;
145 
146  return false;
147  }
148 
149 
150  void
151  Counter::SetRejected(const std::string& reason)
152  {
153  for (ModuleIterator im = fModules.Begin(); im != fModules.End(); ++im)
154  im->SetRejected(reason);
155  }
156 
157 
158  void
160  {
161  for (ModuleIterator im = fModules.Begin(); im != fModules.End(); ++im)
162  im->SetSilent();
163  }
164 
165 
166  double
168  const
169  {
170  double estimatedMuons = 0;
171 
172  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im) {
173  // muons can only be estimated for modules with data and unsaturated
174  if (im->IsCandidate() && im->HasRecData()) {
175  if (im->GetRecData().IsSaturated()) {
176  std::ostringstream ss;
177  ss << "Number of muons cannot calculated for saturated counter " << fId;
178  WARNING(ss);
179  return -1;
180  } else {
181  estimatedMuons += im->GetRecData().GetNumberOfEstimatedMuons();
182  }
183  }
184  }
185 
186  return estimatedMuons;
187  }
188 
189 
190  double
192  const
193  {
194  double counterVariance = 0;
195 
196  // muons can only be estimated for modules with data and unsaturated
197  if (IsSaturated()) {
198  std::ostringstream ss;
199  ss << "Number of muons cannot calculated for saturated counter " << fId;
200  WARNING(ss);
201  return -1;
202  }
203 
204  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im) {
205  if (im->IsCandidate() && im->HasRecData()) {
206  const double moduleSigma = im->GetRecData().GetNumberOfMuonsErrorHigh();
207  counterVariance += (moduleSigma*moduleSigma);
208  }
209  }
210 
211  return sqrt(counterVariance);
212  }
213 
214 
215  double
217  const
218  {
219  double counterVariance = 0;
220 
221  // muons can only be estimated for modules with data and unsaturated
222  if (IsSaturated()) {
223  std::ostringstream ss;
224  ss << "Number of muons cannot calculated for saturated counter " << fId;
225  WARNING(ss);
226  return -1;
227  }
228 
229  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im) {
230  if (im->IsCandidate() && im->HasRecData()) {
231  const double moduleSigma = im->GetRecData().GetNumberOfMuonsErrorLow();
232  counterVariance += (moduleSigma*moduleSigma);
233  }
234  }
235 
236  return sqrt(counterVariance);
237  }
238 
239 
240  double
242  const
243  {
244  double limit = 0;
245 
246  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
247  if (im->IsCandidate() && im->HasRecData())
248  limit += im->GetRecData().GetNumberOfMuonsLowLimit();
249 
250  return limit;
251  }
252 
253 
254  double
256  const
257  {
258  double estimatedMuons = 0;
259 
260  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im) {
261  // muons can only be estimated for modules with data and unsaturated
262  if (im->IsCandidate() && im->HasRecData()) {
263  if (im->GetRecData().IsSaturated()) {
264  std::ostringstream ss;
265  ss << "Mean muons cannot calculated for saturated counter " << fId;
266  WARNING(ss);
267  return -1;
268  } else {
269  estimatedMuons += im->GetRecData().GetMeanMuons();
270  }
271  }
272  }
273 
274  return estimatedMuons;
275  }
276 
277 
278  double
280  const
281  {
282  double counterVariance = 0;
283 
284  // muons can only be estimated for modules with data and unsaturated
285  if (IsSaturated()) {
286  std::ostringstream ss;
287  ss << "Mean muons cannot calculated for saturated counter " << fId;
288  WARNING(ss);
289  return -1;
290  }
291 
292  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im) {
293  if (im->IsCandidate() && im->HasRecData()) {
294  const double moduleSigma = im->GetRecData().GetMeanMuonsErrorHigh();
295  counterVariance += (moduleSigma*moduleSigma);
296  }
297  }
298 
299  return sqrt(counterVariance);
300  }
301 
302 
303  double
305  const
306  {
307  double counterVariance = 0;
308 
309  // muons can only be estimated for modules with data and unsaturated
310  if (IsSaturated()) {
311  std::ostringstream ss;
312  ss << "Mean muons cannot calculated for saturated counter " << fId;
313  WARNING(ss);
314  return -1;
315  }
316 
317  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im) {
318  if (im->IsCandidate() && im->HasRecData()) {
319  const double moduleSigma = im->GetRecData().GetMeanMuonsErrorLow();
320  counterVariance += (moduleSigma*moduleSigma);
321  }
322  }
323 
324  return sqrt(counterVariance);
325  }
326 
327 
328  double
330  const
331  {
332  double limit = 0;
333 
334  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
335  if (im->IsCandidate() && im->HasRecData())
336  limit += im->GetRecData().GetMeanMuonsLowLimit();
337 
338  return limit;
339  }
340 
341 
342  double
344  const
345  {
346  double counterArea = 0;
347 
348  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
349  if (im->IsCandidate() && im->HasRecData())
350  counterArea += im->GetRecData().GetActiveArea();
351 
352  return counterArea;
353  }
354 
355 
356  double
358  const
359  {
360  double counterArea = 0;
361 
362  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
363  if (im->HasRecData() && im->GetRecData().IsADCCalibratedLG())
364  counterArea += im->GetRecData().GetActiveArea();
365 
366  return counterArea;
367  }
368 
369 
370  double
372  const
373  {
374  double counterArea = 0;
375 
376  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
377  if (im->HasRecData() && im->GetRecData().IsADCCalibratedHG())
378  counterArea += im->GetRecData().GetActiveArea();
379 
380  return counterArea;
381  }
382 
383 
384  double
386  const
387  {
388  // muons can only be estimated for unsaturated modules
389  if (IsSaturated()) {
390  std::ostringstream ss;
391  ss << "Density of muons cannot calculated for saturated counter " << fId;
392  WARNING(ss);
393  return -1;
394  }
395 
396  const double density = GetNumberOfEstimatedMuons() / GetActiveArea();
397 
398  return density;
399  }
400 
401 
402  double
404  const
405  {
406  // muons can only be estimated for unsaturated modules
407  if (IsSaturated()) {
408  std::ostringstream ss;
409  ss << "Density of muons cannot calculated for saturated counter " << fId;
410  WARNING(ss);
411  return -1;
412  }
413 
414  const double counterSigma = GetNumberOfMuonsErrorHigh() / GetActiveArea();
415 
416  return counterSigma;
417  }
418 
419 
420  double
422  const
423  {
424  // muons can only be estimated for unsaturated modules
425  if (IsSaturated()) {
426  std::ostringstream ss;
427  ss << "Density of muons cannot calculated for saturated counter " << fId;
428  WARNING(ss);
429  return -1;
430  }
431 
432  const double counterSigma = GetNumberOfMuonsErrorLow() / GetActiveArea();
433 
434  return counterSigma;
435  }
436 
437  double
439  const
440  {
441  std::ostringstream ss;
442  // muons can only be estimated for unsaturated modules
443  if (IsSaturated()) {
444  ss << "Mean density of muons cannot calculated for saturated counter " << fId;
445  WARNING(ss);
446  return -1;
447  }
448  const double density = GetMeanMuons() / GetActiveArea();
449  ss << "density = " << GetMeanMuons() << " / " << GetActiveArea() << " = " << density;
450  DEBUGLOG( ss.str() );
451 
452  return density;
453  }
454 
455 
456  double
458  const
459  {
460  // muons can only be estimated for unsaturated modules
461  if (IsSaturated()) {
462  std::ostringstream ss;
463  ss << "Mean density of muons cannot calculated for saturated counter " << fId;
464  WARNING(ss);
465  return -1;
466  }
467 
468  const double counterSigma = GetMeanMuonsErrorHigh() / GetActiveArea();
469 
470  return counterSigma;
471  }
472 
473 
474  double
476  const
477  {
478  // muons can only be estimated for unsaturated modules
479  if (IsSaturated()) {
480  std::ostringstream ss;
481  ss << "Mean density of muons cannot calculated for saturated counter " << fId;
482  WARNING(ss);
483  return -1;
484  }
485 
486  const double counterSigma = GetMeanMuonsErrorLow() / GetActiveArea();
487 
488  return counterSigma;
489  }
490 
491 
492  unsigned int
494  const
495  {
496  double windowsOn = 0;
497 
498  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im) {
499  // windows can only be estimated for modules with data
500  if (im->IsCandidate() && im->HasRecData())
501  windowsOn += im->GetRecData().GetNumberOfChannelsOn();
502  }
503 
504  return windowsOn;
505  }
506 
507 
508  double
510  const
511  {
512  double ldfResidual = 0;
513  unsigned int nModules = 0;
514 
515  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
516  if (im->IsCandidate() && im->HasRecData() && !im->GetRecData().IsSaturated()) {
517  ldfResidual += im->GetRecData().GetLDFResidual();
518  ++nModules;
519  }
520 
521  return ldfResidual / nModules;
522  }
523 
524 
525  /**********************
526  * ADC LG
527  **********************/
528 
529  double
531  const
532  {
533  double estimatedMuons = 0;
534 
535  // muons can only be estimated for modules with data and unsaturated
536  if (!IsADCCalibratedLG()) {
537  std::ostringstream ss;
538  ss << "Number of muons with ADC LG cannot calculated for counter with no calibrated modules " << fId;
539  WARNING(ss);
540  return -1;
541  }
542 
543  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
544  if (im->HasRecData() && im->GetRecData().IsADCCalibratedLG())
545  estimatedMuons += im->GetRecData().GetNumberOfEstimatedMuonsADCLG();
546 
547  return estimatedMuons;
548  }
549 
550 
551  double
553  const
554  {
555  double counterVariance = 0;
556 
557  // muons can only be estimated for modules with data and unsaturated
558  if (!IsADCCalibratedLG()) {
559  std::ostringstream ss;
560  ss << "Number of muons with ADC LG cannot calculated for counter with no calibrated modules " << fId;
561  WARNING(ss);
562  return -1;
563  }
564 
565  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
566  if (im->HasRecData() && im->GetRecData().IsADCCalibratedLG()) {
567  const double moduleSigma = im->GetRecData().GetNumberOfMuonsADCErrorHighLG();
568  counterVariance += (moduleSigma*moduleSigma);
569  }
570 
571  return sqrt(counterVariance);
572  }
573 
574 
575  double
577  const
578  {
579  double counterVariance = 0;
580 
581  // muons can only be estimated for modules with data and unsaturated
582  if (!IsADCCalibratedLG()) {
583  std::ostringstream ss;
584  ss << "Number of muons with ADC LG cannot calculated for counter with no calibrated modules " << fId;
585  WARNING(ss);
586  return -1;
587  }
588 
589  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
590  if (im->HasRecData() && im->GetRecData().IsADCCalibratedLG()) {
591  const double moduleSigma = im->GetRecData().GetNumberOfMuonsADCErrorLowLG();
592  counterVariance += (moduleSigma*moduleSigma);
593  }
594 
595  return sqrt(counterVariance);
596  }
597 
598 
599  double
601  const
602  {
603  // muons can only be estimated for unsaturated modules
604  if (!IsADCCalibratedLG()) {
605  std::ostringstream ss;
606  ss << "Density of muons cannot be calculated with ADC LG for counter with no calibrated modules " << fId;
607  WARNING(ss);
608  return -1;
609  }
610 
611  const double density = GetNumberOfEstimatedMuonsLG() / GetActiveAreaLG();
612 
613  return density;
614  }
615 
616 
617  double
619  const
620  {
621  // muons can only be estimated for unsaturated modules
622  if (!IsADCCalibratedLG()) {
623  std::ostringstream ss;
624  ss << "Density of muons cannot be calculated with ADC LG for counter with no calibrated modules " << fId;
625  WARNING(ss);
626  return -1;
627  }
628 
629  const double counterSigma = GetNumberOfMuonsErrorHighLG() / GetActiveAreaLG();
630 
631  return counterSigma;
632  }
633 
634 
635  double
637  const
638  {
639  // muons can only be estimated for unsaturated modules
640  if (!IsADCCalibratedLG()) {
641  std::ostringstream ss;
642  ss << "Density of muons cannot be calculated with ADC LG for counter with no calibrated modules " << fId;
643  WARNING(ss);
644  return -1;
645  }
646 
647  const double counterSigma = GetNumberOfMuonsErrorLowLG() / GetActiveAreaLG();
648 
649  return counterSigma;
650  }
651 
652 
653  /**********************
654  * ADC HG
655  **********************/
656 
657  double
659  const
660  {
661  double estimatedMuons = 0;
662 
663  // muons can only be estimated for modules with data and unsaturated
664  if (!IsADCCalibratedHG()) {
665  std::ostringstream ss;
666  ss << "Number of muons with ADC HG cannot calculated for counter with no calibrated modules" << fId;
667  WARNING(ss);
668  return -1;
669  }
670 
671  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
672  if (im->HasRecData() && im->GetRecData().IsADCCalibratedHG())
673  estimatedMuons += im->GetRecData().GetNumberOfEstimatedMuonsADCHG();
674 
675  return estimatedMuons;
676  }
677 
678 
679  double
681  const
682  {
683  double counterVariance = 0;
684 
685  // muons can only be estimated for modules with data and unsaturated
686  if (!IsADCCalibratedHG()) {
687  std::ostringstream ss;
688  ss << "Number of muons with ADC HG cannot calculated for counter with no calibrated modules " << fId;
689  WARNING(ss);
690  return -1;
691  }
692 
693  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
694  if (im->HasRecData() && im->GetRecData().IsADCCalibratedHG()) {
695  const double moduleSigma = im->GetRecData().GetNumberOfMuonsADCErrorHighHG();
696  counterVariance += (moduleSigma*moduleSigma);
697  }
698 
699  return sqrt(counterVariance);
700  }
701 
702 
703  double
705  const
706  {
707  double counterVariance = 0;
708 
709  // muons can only be estimated for modules with data and unsaturated
710  if (!IsADCCalibratedHG()) {
711  std::ostringstream ss;
712  ss << "Number of muons with ADC HG cannot calculated for counter with no calibrated modules " << fId;
713  WARNING(ss);
714  return -1;
715  }
716 
717  for (ModuleConstIterator im = fModules.Begin(); im != fModules.End(); ++im)
718  if (im->HasRecData() && im->GetRecData().IsADCCalibratedHG()) {
719  const double moduleSigma = im->GetRecData().GetNumberOfMuonsADCErrorLowHG();
720  counterVariance += (moduleSigma*moduleSigma);
721  }
722 
723  return sqrt(counterVariance);
724  }
725 
726 
727  double
729  const
730  {
731  if (!IsADCCalibratedHG()) {
732  std::ostringstream ss;
733  ss << "Density of muons cannot be calculated with ADC HG for counter with no calibrated modules " << fId;
734  WARNING(ss);
735  return -1;
736  }
737 
738  const double density = GetNumberOfEstimatedMuonsHG() / GetActiveAreaHG();
739 
740  return density;
741  }
742 
743 
744  double
746  const
747  {
748  if (!IsADCCalibratedHG()) {
749  std::ostringstream ss;
750  ss << "Density of muons cannot be calculated with ADC HG for counter with no calibrated modules " << fId;
751  WARNING(ss);
752  return -1;
753  }
754 
755  const double counterSigma = GetNumberOfMuonsErrorHighHG() / GetActiveAreaHG();
756 
757  return counterSigma;
758  }
759 
760 
761  double
763  const
764  {
765  if (!IsADCCalibratedHG()) {
766  std::ostringstream ss;
767  ss << "Density of muons cannot be calculated with ADC HG for counter with no calibrated modules " << fId;
768  WARNING(ss);
769  return -1;
770  }
771 
772  const double counterSigma = GetNumberOfMuonsErrorLowHG() / GetActiveAreaHG();
773 
774  return counterSigma;
775  }
776 
777 }
ComponentIterator Begin()
bool IsCandidate() const
The muon counter status.
double GetNumberOfMuonsErrorHighHG() const
double GetNumberOfMuonsErrorHighLG() const
InternalModuleCollection fModules
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
double GetNumberOfEstimatedMuonsLG() const
The number of estimated muons with the ADC is calculated as the sum of the estimated muons of the ass...
bool HasRecData() const
Counter is flagged has having reconstructed data if at least one of its associated modules has recons...
size_t CountRejectedModules() const
double GetMeanMuonDensityErrorLow() const
double GetMeanMuonDensityErrorHigh() const
bool IsSaturated() const
Check if the counter is &quot;hardware&quot; saturated (limit imposed by detector segmentation) ...
double GetActiveAreaLG() const
double GetNumberOfMuonsErrorHigh() const
bool IsADCCalibratedLG() const
Check if the counter ADC LG channel is calibrated.
bool IsRejected() const
Check if the counter is rejected.
double GetMeanMuonDensity() const
double GetMuonDensityHG() const
bool IsSilent() const
Check if the counter is silent.
double GetMuonDensityErrorLowLG() const
double GetMuonDensityErrorHighLG() const
double GetActiveAreaHG() const
int GetNumberOf() const
Query quantity.
void SetSilent()
Set the status of all modules in this counter to silent. This is used if the associated tank does not...
double GetActiveArea() const
double GetMuonDensity() const
The density measured by a counter is the calculated as the number of estimated muons over the active ...
double GetMeanMuons() const
bool IsADCCalibratedHG() const
Check if the counter ADC HG channel is calibrated.
double GetMuonDensityErrorLowHG() const
double GetNumberOfMuonsLowLimit() const
The lower limit to the number of muons in a counter.
#define DEBUGLOG(message)
Macro for logging debugging messages.
Definition: ErrorLogger.h:157
size_t CountSilentModules() const
double GetMuonDensityErrorHighHG() const
unsigned int GetNumberOfChannelsOn() const
double GetNumberOfMuonsErrorLowHG() const
#define WARNING(message)
Macro for logging warning messages.
Definition: ErrorLogger.h:163
InternalModuleCollection::ComponentIterator ModuleIterator
size_t CountCandidateModules() const
Count the number of modules in the counter by status.
Counter level simulation data.
double GetMuonDensityErrorHigh() const
double GetNumberOfMuonsErrorLow() const
void SetRejected(const std::string &reason="")
Set the status of all modules in this counter to rejected. As described for the muon counter status...
double GetMeanMuonsErrorLow() const
double GetNumberOfEstimatedMuons() const
The number of estimated muons of the counter is calculated as the sum of the estimated muons of the a...
double GetMeanMuonsErrorHigh() const
InternalModuleCollection::ComponentConstIterator ModuleConstIterator
double GetMuonDensityLG() const
double GetMuonDensityErrorLow() const
ComponentIterator End()
#define ERROR(message)
Macro for logging error messages.
Definition: ErrorLogger.h:165
double GetNumberOfEstimatedMuonsHG() const
double GetNumberOfMuonsErrorLowLG() const
utl::ShadowPtr< CounterSimData > fSimData

, generated on Tue Sep 26 2023.