MDetector/Module.h
Go to the documentation of this file.
1 #ifndef _mdet_Module_h
2 #define _mdet_Module_h
3 
4 #include <det/VManager.h>
5 #include <det/MPositionable.h>
6 //
7 #include <mdet/MComponentGroup.h>
8 #include <mdet/MDetectorComponent.h>
9 #include <mdet/Scintillator.h>
10 #include <mdet/Fiber.h>
11 #include <mdet/Pixel.h>
12 #include <mdet/PMT.h>
13 #include <mdet/FrontEnd.h>
14 #include <mdet/SiPM.h>
15 #include <mdet/SiPMArray.h>
16 #include <mdet/FrontEndSiPM.h>
17 #include <mdet/BackEndSiPM.h>
18 //
19 #include <utl/Point.h>
20 #include <utl/CoordinateSystemPtr.h>
21 #include <utl/ShadowPtr.h>
22 #include <utl/AugerException.h>
23 #include <utl/ConsecutiveEnumFactory.h>
24 #include <utl/Validated.h>
25 //
26 #include <sstream>
27 #include <string>
28 //
29 #include <boost/utility.hpp>
30 
31 #include <boost/multi_index_container.hpp>
32 #include <boost/multi_index/member.hpp>
33 #include <boost/multi_index/ordered_index.hpp>
34 
35 
36 namespace mdet {
37 
38 class Counter;
39 
40 
57 class Module : public MDetectorComponent<Module>::Type,
58  public det::MPositionable<Module> {
59 
60 private:
63 
66 
67 public:
94  enum AreaKind {
95  eSmall = 0,
96  eLarge = 1,
97  };
98 
100  ePMT = 0,
101  eSiPM = 1,
102  };
103 
105  static const char* const AreaKindTags[];
106 
109 
111  static const char* const PhotoDetectorTags[];
112 
115 
116  static const char* const kComponentName;
117 
118  static const char* const kComponentId;
119 
121 
122  typedef ScintillatorGroup::ConstIterator ScintillatorConstIterator;
124 
127 
130 
132 
134  typedef FiberGroup::ConstIterator FiberConstIterator;
136 
138  FiberConstIterator FibersBegin() const { return fFibers.Begin(); }
139 
141  FiberConstIterator FibersEnd() const { return fFibers.End(); }
143 
175 
181  template<class Component>
182  const Fiber& GetFiberFor(const Component& c) const
183  { const IdTuple ids = GetIdTuple(c); return fFibers.Get(ids.fFiberId); }
184 
190  template<class Component>
191  const Scintillator& GetScintillatorFor(const Component& c) const
192  { const IdTuple ids = GetIdTuple(c); return fScintillators.Get(ids.fScintillatorId); }
193 
200  template<class Component>
201  const Pixel& GetPixelFor(const Component& c) const
202  { const IdTuple ids = GetIdTuple(c); return fPMT->GetPixels().Get(ids.fPixelId); }
203 
210  template<class Component>
211  const SiPM& GetSiPMFor(const Component& c) const
212  { const IdTuple ids = GetIdTuple(c); return fSiPMArray->GetSiPMs().Get(ids.fPixelId); }
213 
220  template<class Component>
221  const ChannelSiPM& GetChannelSiPMFor(const Component& c) const
222  { const IdTuple ids = GetIdTuple(c); return fFrontEndSiPM->GetChannels().Get(ids.fChannelId); }
223 
230  template<class Component>
231  const Channel& GetChannelFor(const Component& c) const
232  { const IdTuple ids = GetIdTuple(c); return fFrontEnd->GetChannels().Get(ids.fChannelId); }
234 
244  const Scintillator& GetScintillator(int sId) const { return fScintillators.Get(sId); }
245 
246  bool ExistsScintillator(const int sId) const { return fScintillators.Exists(sId); }
247 
248  const Channel& GetChannel(int cId) const { return fFrontEnd->GetChannels().Get(cId); }
249 
250  bool ExistsChannel(const int cId) const { return fFrontEnd->GetChannels().Exists(cId); }
251 
252  const ChannelSiPM& GetChannelSiPM(int cId) const { return fFrontEndSiPM->GetChannels().Get(cId); }
253 
254  bool ExistsChannelSiPM(const int cId) const { return fFrontEndSiPM->GetChannels().Exists(cId); }
255 
256  const Fiber& GetFiber(int fId) const { return fFibers.Get(fId); }
257 
258  bool ExistsFiber(const int fId) const { return fFibers.Exists(fId); }
259 
260  const Pixel& GetPixel(int pId) const { return fPMT->GetPixels().Get(pId); }
261 
262  bool ExistsPixel(const int pId) const { return fPMT->GetPixels().Exists(pId); }
263 
264  const SiPM& GetSiPM(const int pId) const { return fSiPMArray->GetSiPMs().Get(pId); }
265 
266  bool ExistsSiPM(const int pId) const { return fSiPMArray->GetSiPMs().Exists(pId); }
267 
268  int ScintillatorToChannelId(const int sId ) const
269  { CheckComponent(); return fIndexByScintillator.find(sId)->fChannelId; }
270 
271  int ScintillatorToPixelId(const int sId) const
272  { CheckComponent(); return fIndexByScintillator.find(sId)->fPixelId; }
273 
274  int ScintillatorToFiberId(const int sId) const
275  { CheckComponent(); return fIndexByScintillator.find(sId)->fFiberId; }
276 
277  int ChannelToScintillatorId(const int cId) const
278  { CheckComponent(); return fIndexByChannel.find(cId)->fScintillatorId; }
279 
280  int ChannelToPixelId(const int cId) const
281  { CheckComponent(); return fIndexByChannel.find(cId)->fPixelId; }
282 
283  int ChannelToFiberId(const int cId) const
284  { CheckComponent(); return fIndexByChannel.find(cId)->fFiberId; }
285 
286  int FiberToChannelId(const int fId) const
287  { CheckComponent(); return fIndexByFiber.find(fId)->fChannelId; }
288 
289  int FiberToScintillatorId(const int fId) const
290  { CheckComponent(); return fIndexByFiber.find(fId)->fScintillatorId; }
291 
292  int FiberToPixelId(const int fId) const
293  { CheckComponent(); return fIndexByFiber.find(fId)->fPixelId; }
294 
295  int PixelToScintillatorId(const int pId) const
296  { CheckComponent(); return fIndexByPixel.find(pId)->fScintillatorId; }
297 
298  int PixelToFiberId(const int pId) const
299  { CheckComponent(); return fIndexByPixel.find(pId)->fFiberId; }
300 
301  int PixelToChannelId(const int pId) const
302  { CheckComponent(); return fIndexByPixel.find(pId)->fChannelId; }
304 
305  // The area of the module in square meters
306  double GetArea() const;
307 
308  // Number of scintillators in the module
309  unsigned int GetNumberOfScintillators() const;
310 
315  double GetDepth() const;
316 
317  // The depth of the given point.
318  double GetDepth(const utl::Point& p) const;
319 
320  // The front-end mask of broken channels.
321  ULong64_t GetMask() const;
322 
324  const Counter& GetCounter() const;
325 
326  // Retrieves the PMT that belongs to the module.
327  const PMT& GetPMT() const;
328 
329  // Retrieves the SiPMArray that belongs to the module.
330  const SiPMArray& GetSiPMArray() const;
331 
332  // Retrieves the electronic FrontEnd that belong to the module.
333  const FrontEnd& GetFrontEnd() const;
334 
335  // Retrieves the electronic FrontEnd that belong to the module.
336  const FrontEndSiPM& GetFrontEndSiPM() const;
337 
338  // Retrieves the electronic FrontEnd that belong to the module.
339  const BackEndSiPM& GetBackEndSiPM() const;
340 
341  // The specific kind of Module.
342  AreaKind GetAreaKind() const;
343 
344  // The photoDetector of Module.
346 
357  double GetBackgroundMuonsFlux() const;
358 
359  double GetPhi0() const;
360 
361  bool IsSiPM() const; //returns true for a module with SiPM array
362 
363  double GetShortestFiber() const;
364 
365 private:
366  // Perform update in this component and forward to subcomponents.
367  void Update(const bool invalidateData, const bool invalidateComponents);
368 
374 
391  Module(const int mId, const det::VManager::IndexMap& parentMap, const Counter& parent);
392 
393  ~Module() { }
394 
395  // Frienship for GetData callback.
396  friend class det::MPositionable<Module>;
397 
402  template<class T>
403  friend void boost::checked_delete(T*) BOOST_NOEXCEPT;
404 
405  // Friendship to allow creation (or call it construction).
406  friend struct det::ParentCreator;
407 
409  friend struct det::ComponentUpdater;
410 
412 
414 
415  utl::ShadowPtr<PMT> fPMT;
416 
417  utl::ShadowPtr<SiPMArray> fSiPMArray;
418 
419  utl::ShadowPtr<FrontEnd> fFrontEnd;
420 
421  utl::ShadowPtr<FrontEndSiPM> fFrontEndSiPM;
422 
423  utl::ShadowPtr<BackEndSiPM> fBackEndSiPM;
424 
426 
427  // Alias for a type considered within the config hierarchy, to be converted to the actual enum
428  typedef std::string AreaKindForConfig;
429 
430  mutable utl::Validated<AreaKindForConfig> fAreaKind;
431 
432  // Alias for a type considered within the config hierarchy, to be converted to the actual enum
433  typedef std::string PhotoDetectorForConfig;
434 
435  mutable utl::Validated<PhotoDetectorForConfig> fPhotoDetector;
436 
437  mutable utl::Validated<double> fBackgroundMuonsFlux;
438 
440  struct IdTuple {
442  int fPixelId;
444  int fFiberId;
445  };
446 
447  //dummies needed to access the different indices of the IndexContainer
448  struct ChannelTag {
449  };
450 
451  struct PixelTag {
452  };
453 
455  };
456 
457  struct FiberTag {
458  };
459 
460  // container for the mapping between different indices (Pixel/Scintillator/Channel/Fiber)
461 
462  typedef boost::multi_index_container<
463  IdTuple,
464  boost::multi_index::indexed_by<
465  boost::multi_index::ordered_unique<
466  boost::multi_index::tag<ChannelTag>, boost::multi_index::member< IdTuple, int, &IdTuple::fChannelId >
467  >,
468  boost::multi_index::ordered_unique<
469  boost::multi_index::tag<PixelTag>, boost::multi_index::member< IdTuple, int, &IdTuple::fPixelId >
470  >,
471  boost::multi_index::ordered_unique<
472  boost::multi_index::tag<ScintillatorTag>, boost::multi_index::member< IdTuple, int, &IdTuple::fScintillatorId >
473  >,
474  boost::multi_index::ordered_unique<
475  boost::multi_index::tag<FiberTag>, boost::multi_index::member< IdTuple, int, &IdTuple::fFiberId >
476  > //close ordered_unique
477  > //close indexed_by
478  > IndexContainer; //close typedef
479 
480  typedef IndexContainer::index<ChannelTag>::type IndexByChannelId;
481  typedef IndexContainer::index<PixelTag>::type IndexByPixelId;
482  typedef IndexContainer::index<ScintillatorTag>::type IndexByScintillatorId;
483  typedef IndexContainer::index<FiberTag>::type IndexByFiberId;
484 
490 
491  /*
492  VERY VERY DIRTY SOLUTION TO IMPLEMENT LAZY INITIALIZATION IN THE IDS OF
493  CHANNELS/SCINTILLATORS AND FIBERS
494  (but in any case implies an improvement of 40 times faster runs!)
495  */
496  void
497  CheckComponent()
498  const
499  {
500 #if 1
501  if (fIndexByChannel.empty()) {
502  if(!IsSiPM()){
503  for (mdet::PMT::PixelConstIterator pixIt = fPMT->PixelsBegin(); pixIt != fPMT->PixelsEnd(); ++pixIt) {
504  const Pixel& pix = *pixIt;
506  if (ids.size() != 3) {
507  FATAL("The information in MModelConfig is corrupt! Number of indeces in "
508  "<channelScintillatorFiberIds> has to be three");
509  }
510  IdTuple newtuple;
511  newtuple.fScintillatorId = ids[1];
512  newtuple.fFiberId = ids[2];
513  newtuple.fPixelId = pixIt->GetId();
514  newtuple.fChannelId = ids[0];
515  fIndexByChannel.insert(newtuple);
516  }
517  }else{
518  for (mdet::SiPMArray::SiPMConstIterator sipmIt = fSiPMArray->SiPMsBegin(); sipmIt != fSiPMArray->SiPMsEnd(); ++sipmIt) {
519  const SiPM& sipm = *sipmIt;
521  if (ids.size() != 3) {
522  FATAL("The information in MModelConfig is corrupt! Number of indeces in "
523  "<channelScintillatorFiberIds> has to be three");
524  }
525  IdTuple newtuple;
526  newtuple.fScintillatorId = ids[1];
527  newtuple.fFiberId = ids[2];
528  newtuple.fPixelId = sipmIt->GetId();
529  newtuple.fChannelId = ids[0];
530  fIndexByChannel.insert(newtuple);
531  }
532  }
533  }
534 #endif
535  }
536 
537  IdTuple GetIdTuple(const Channel& c) const
538  { CheckComponent(); return *fIndexByChannel.find(c.GetId()); }
539 
540  IdTuple GetIdTuple(const Pixel& p) const
541  { CheckComponent(); return *fIndexByPixel.find(p.GetId()); }
542 
543  IdTuple GetIdTuple(const ChannelSiPM& c) const
544  { CheckComponent(); return *fIndexByChannel.find(c.GetId()); }
545 
546  IdTuple GetIdTuple(const SiPM& p) const
547  { CheckComponent(); return *fIndexByPixel.find(p.GetId()); }
548 
549  IdTuple GetIdTuple(const Scintillator& s) const
550  { CheckComponent(); return *fIndexByScintillator.find(s.GetId()); }
551 
552  IdTuple GetIdTuple(const Fiber& f) const
553  { CheckComponent(); return *fIndexByFiber.find(f.GetId()); }
554 
555 };
556 
557 }
558 
559 
560 #endif
561 
int PixelToScintillatorId(const int pId) const
Simple factory to create an enumerator for a given enumeration.
utl::ShadowPtr< FrontEnd > fFrontEnd
utl::ShadowPtr< PMT > fPMT
const BackEndSiPM & GetBackEndSiPM() const
IndexContainer::index< ChannelTag >::type IndexByChannelId
static const char *const PhotoDetectorTags[]
Tags for textual representation.
Defines within it the common (templated) type for muon detector hierarchy components groups...
int fId
Id of the component.
const Pixel & GetPixel(int pId) const
Point object.
Definition: Point.h:32
bool ExistsFiber(const int fId) const
utl::ConsecutiveEnumFactory< AreaKind, eLarge, AreaKindTags > AreaKindCreator
Convenience typedef for creation of AreaKind enumerators.
const Counter & GetCounter() const
The parent counter.
unsigned int GetNumberOfScintillators() const
AreaKind GetAreaKind() const
PixelGroup::ConstIterator PixelConstIterator
Convenience typedef for const iterator over the contained mdet::Pixel instances.
bool ExistsPixel(const int pId) const
Module(const int mId, const det::VManager::IndexMap &parentMap, const Counter &parent)
Constructs the Module (obviously!).
std::string AreaKindForConfig
bool ExistsSiPM(const int pId) const
int ScintillatorToPixelId(const int sId) const
Mixin class to be inherited from objects that have a position.
bool ExistsChannelSiPM(const int cId) const
Defines within it the common (templated) type for muon detector hierarchy components.
const Fiber & GetFiberFor(const Component &c) const
Linking between fibers, scintillators, channels and pixels.
const Channel & GetChannelFor(const Component &c) const
Returns the associated mdet::Channel.
int ChannelToPixelId(const int cId) const
MComponentGroup< Module, Scintillator, det::ParentCreator >::Type ScintillatorGroup
Type for the set of associated mdet::Scintillator.
ScintillatorConstIterator ScintillatorsBegin() const
Begin iterator over the contained scitillators.
Electronic front-end for the modules.
Definition: FrontEnd.h:33
Eletronic channel.
#define FATAL(message)
Macro for logging fatal messages.
Definition: ErrorLogger.h:167
int ScintillatorToChannelId(const int sId) const
const IdsContainer & GetChannelSiPMScintillatorFiberIds() const
Indices for Channel, Scintillator, Fiber of corrresponding Pixel.
Definition: SiPM.cc:49
int FiberToChannelId(const int fId) const
const Channel & GetChannel(int cId) const
IndexByFiberId & fIndexByFiber
utl::Validated< AreaKindForConfig > fAreaKind
Electronic front-end for the modules.
Definition: FrontEndSiPM.h:35
int ChannelToScintillatorId(const int cId) const
Eletronic ChannelSiPM.
Definition: ChannelSiPM.h:33
const ChannelSiPM & GetChannelSiPM(int cId) const
const SiPMArray & GetSiPMArray() const
Actual muon-sensitive objects.
boost::shared_ptr< const CoordinateTransformer > CoordinateSystemPtr
Shared pointer for coordinate systems.
IndexContainer::index< PixelTag >::type IndexByPixelId
const SiPM & GetSiPM(const int pId) const
constexpr double s
Definition: AugerUnits.h:163
const SiPM & GetSiPMFor(const Component &c) const
Returns the associated mdet::SiPM.
64 SiPM Array
Definition: SiPMArray.h:36
friend void boost::checked_delete(T *) BOOST_NOEXCEPT
Friendship for destruction. Depends on det::ComponentGroup innards.
boost::multi_index_container< IdTuple, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< ChannelTag >, boost::multi_index::member< IdTuple, int,&IdTuple::fChannelId > >, boost::multi_index::ordered_unique< boost::multi_index::tag< PixelTag >, boost::multi_index::member< IdTuple, int,&IdTuple::fPixelId > >, boost::multi_index::ordered_unique< boost::multi_index::tag< ScintillatorTag >, boost::multi_index::member< IdTuple, int,&IdTuple::fScintillatorId > >, boost::multi_index::ordered_unique< boost::multi_index::tag< FiberTag >, boost::multi_index::member< IdTuple, int,&IdTuple::fFiberId > > > > IndexContainer
MComponentGroup< Module, Fiber, det::ParentCreator >::Type FiberGroup
Type for the set of associated mdet::Fiber.
PhotoDetector GetPhotoDetector() const
IndexByChannelId & fIndexByChannel
FiberConstIterator FibersBegin() const
Begin iterator over the contained fibers.
static const char *const AreaKindTags[]
Tags for textual representation.
Array of Scintillator.
int FiberToPixelId(const int fId) const
int PixelToChannelId(const int pId) const
double GetArea() const
FiberConstIterator FibersEnd() const
End iterator over the contained fibers.
SiPMGroup::ConstIterator SiPMConstIterator
Definition: SiPMArray.h:50
ScintillatorGroup::ConstIterator ScintillatorConstIterator
Scintillator handling.
std::vector< int > IdsContainer
Typedef for container of corresponding Channel, Scintillator, Fiber indices.
const Scintillator & GetScintillatorFor(const Component &c) const
Returns the associated mdet::Scintillator.
double GetBackgroundMuonsFlux() const
Background muons Flux.
Multiple-pixel photo-multiplier tube.
Definition: MDetector/PMT.h:49
const Pixel & GetPixelFor(const Component &c) const
Returns the associated mdet::Pixel.
IndexContainer fIndexRelations
double GetShortestFiber() const
const FrontEnd & GetFrontEnd() const
ULong64_t GetMask() const
Root detector of the muon detector hierarchy.
IndexContainer::index< ScintillatorTag >::type IndexByScintillatorId
bool ExistsChannel(const int cId) const
utl::Validated< double > fBackgroundMuonsFlux
FiberGroup fFibers
PMT pixel.
int ScintillatorToFiberId(const int sId) const
std::string const
Returns the message that identifies this component.
utl::Validated< PhotoDetectorForConfig > fPhotoDetector
IndexByScintillatorId & fIndexByScintillator
static const char *const kComponentName
int FiberToScintillatorId(const int fId) const
const VManager::Status f
ScintillatorConstIterator ScintillatorsEnd() const
End iterator over the contained scintillators.
const Fiber & GetFiber(int fId) const
FiberGroup::ConstIterator FiberConstIterator
Fiber handling.
std::string PhotoDetectorForConfig
std::map< std::string, std::string > IndexMap
Definition: VManager.h:133
const FrontEndSiPM & GetFrontEndSiPM() const
double GetPhi0() const
double GetDepth() const
The depth of the origin of the module. This quantity is positive for an underground module...
utl::ShadowPtr< FrontEndSiPM > fFrontEndSiPM
Eletronic BackEndSiPM.
Definition: BackEndSiPM.h:37
AreaKind
Kind of module based on its area.
utl::ConsecutiveEnumFactory< PhotoDetector, eSiPM, PhotoDetectorTags > PhotoDetectorCreator
Convenience typedef for creation of PhotoDetector enumerators.
int GetId() const
The id of this component.
utl::ShadowPtr< BackEndSiPM > fBackEndSiPM
bool IsSiPM() const
const IdsContainer & GetChannelScintillatorFiberIds() const
Indices for Channel, Scintillator, Fiber of corrresponding Pixel.
Optical mdet::Fiber used to conect mdet::Scintillator to mdet::Pixel.
Definition: Fiber.h:54
const Counter & fCounter
static const char *const kComponentId
const Scintillator & GetScintillator(int sId) const
Direct accesor by id.
Type
The type of file that we are acutally opening.
Definition: IoCodes.h:33
void Update(const bool invalidateData, const bool invalidateComponents)
utl::ShadowPtr< SiPMArray > fSiPMArray
bool ExistsScintillator(const int sId) const
int ChannelToFiberId(const int cId) const
IndexContainer::index< FiberTag >::type IndexByFiberId
utl::CoordinateSystemPtr GetReferenceCoordinateSystem() const
The reference is the local coordinate system of mdet::Counter.
ScintillatorGroup fScintillators
int PixelToFiberId(const int pId) const
const ChannelSiPM & GetChannelSiPMFor(const Component &c) const
Returns the associated mdet::ChannelSiPM.
const PMT & GetPMT() const
structure that holds the mapping between different Ids
IndexByPixelId & fIndexByPixel

, generated on Tue Sep 26 2023.