All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AuxDetSorting.cxx
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Geometry/details/AuxDetSorting.cxx
3  * @brief Functions for sorting ICARUS CRT modules (auxiliary detectors).
4  * @author Chris Hilgenberg, Gianluca Petrillo (refactoring only)
5  * @date August 7, 2018
6  * @see icarusalg/Geometry/details/AuxDetSorting.h
7  */
8 
9 // library header
11 
12 // LArSoft libraries
15 
16 // C/C++ standard libraries
17 #include <string>
18 #include <algorithm> // std::sort()
19 #include <cstdlib> // std::atoi()
20 
21 
22 namespace {
23 
24  //--------------------------------------------------------------------------
25  /// Define sort order for CRT modules in standard configuration.
26  bool AuxDetStandardSortingRule
27  (const geo::AuxDetGeo& ad1, const geo::AuxDetGeo& ad2)
28  {
29 
30  std::string type1 = "", type2 = "";
31  switch (ad1.NSensitiveVolume()) {
32  case 20 : type1 = "MINOS"; break;
33  case 16 : type1 = "CERN"; break;
34  case 64 : type1 = "DC"; break;
35  }
36  switch (ad2.NSensitiveVolume()) {
37  case 20 : type2 = "MINOS"; break;
38  case 16 : type2 = "CERN"; break;
39  case 64 : type2 = "DC"; break;
40  }
41 
42  // sort based off of GDML name, module number
43  std::string ad1name = (ad1.TotalVolume())->GetName();
44  std::string ad2name = (ad2.TotalVolume())->GetName();
45  // assume volume name is "volAuxDet_<type>_module_###_<region>"
46  std::string base1 = "volAuxDet_"+type1+"_module_";
47  std::string base2 = "volAuxDet_"+type2+"_module_";
48 
49  int ad1Num = std::atoi( ad1name.substr( base1.size(), 3).c_str() );
50  int ad2Num = std::atoi( ad2name.substr( base2.size(), 3).c_str() );
51 
52  return ad1Num < ad2Num;
53 
54  } // AuxDetStandardSortingRule()
55 
56 
57  //----------------------------------------------------------------------------
58  /// Define sort order for CRT submodules in standard configuration.
59  bool AuxDetSensitiveStandardSortingRule
60  (const geo::AuxDetSensitiveGeo& ad1, const geo::AuxDetSensitiveGeo& ad2)
61  {
62  std::string type1 = "", type2 = "";
63 
64  // sort based off of GDML name, assuming ordering is encoded
65  std::string ad1name = (ad1.TotalVolume())->GetName();
66  std::string ad2name = (ad2.TotalVolume())->GetName();
67 
68  if ( ad1name.find("MINOS") != std::string::npos ) type1 = "MINOS";
69  if ( ad1name.find("CERN") != std::string::npos ) type1 = "CERN";
70  if ( ad1name.find("DC") != std::string::npos ) type1 = "DC";
71  if ( ad2name.find("MINOS") != std::string::npos ) type2 = "MINOS";
72  if ( ad2name.find("CERN") != std::string::npos ) type2 = "CERN";
73  if ( ad2name.find("DC") != std::string::npos ) type2 = "DC";
74 
75  // assume volume name is "volAuxDetSensitive_<type>_module_###_strip_##"
76  std::string baseMod1 = "volAuxDetSensitive_"+type1+"module_";
77  std::string baseStr1 = "volAuxDetSensitive_"+type1+"module_###_strip_";
78  std::string baseMod2 = "volAuxDetSensitive_"+type2+"module_";
79  std::string baseStr2 = "volAuxDetSensitive_"+type2+"module_###_strip_";
80 
81  int ad1Num = atoi( ad1name.substr( baseMod1.size(), 3).c_str() );
82  int ad2Num = atoi( ad2name.substr( baseMod2.size(), 3).c_str() );
83 
84  if(ad1Num!=ad2Num) return ad1Num < ad2Num;
85 
86  ad1Num = std::atoi( ad1name.substr( baseStr1.size(), 2).c_str() );
87  ad2Num = std::atoi( ad2name.substr( baseStr2.size(), 2).c_str() );
88 
89 
90  return ad1Num < ad2Num;
91 
92  } // AuxDetSensitiveStandardSortingRule()
93 
94 
95  //----------------------------------------------------------------------------
96 
97 } // local namespace
98 
99 
100 //------------------------------------------------------------------------------
101 void icarus::SortAuxDetsStandard(std::vector<geo::AuxDetGeo> & adgeo) {
102  std::sort(adgeo.begin(), adgeo.end(), AuxDetStandardSortingRule);
103 }
104 
105 
106 //------------------------------------------------------------------------------
108  (std::vector<geo::AuxDetSensitiveGeo>& adsgeo)
109 {
110  std::sort(adsgeo.begin(), adsgeo.end(), AuxDetSensitiveStandardSortingRule);
111 }
112 
113 
114 //------------------------------------------------------------------------------
Encapsulate the geometry of the sensitive portion of an auxiliary detector.
Functions for sorting ICARUS CRT modules (auxiliary detectors).
void SortAuxDetsStandard(std::vector< geo::AuxDetGeo > &adgeo)
Sorts ICARUS CRT modules in standard configuration.
const TGeoVolume * TotalVolume() const
size_t NSensitiveVolume() const
Definition: AuxDetGeo.h:172
Encapsulate the geometry of an auxiliary detector.
const TGeoVolume * TotalVolume() const
Definition: AuxDetGeo.h:106
void SortAuxDetSensitiveStandard(std::vector< geo::AuxDetSensitiveGeo > &adsgeo)
Sorts ICARUS CRT submodules in standard configuration.