All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SBNDCRTGeometryTest_module.cc
Go to the documentation of this file.
1 /**
2  * \brief Unit tests for the CRT geometry
3  *
4  * \author Marco Del Tutto
5  */
6 
7 #include "art/Framework/Core/EDAnalyzer.h"
8 #include "art/Framework/Core/ModuleMacros.h"
9 #include "art/Framework/Principal/Event.h"
10 #include "art/Framework/Principal/Handle.h"
11 #include "art/Framework/Principal/Run.h"
12 #include "art/Framework/Principal/SubRun.h"
13 #include "canvas/Utilities/InputTag.h"
14 #include "fhiclcpp/ParameterSet.h"
15 #include "messagefacility/MessageLogger/MessageLogger.h"
16 
18 
19 #include "TGeoManager.h"
20 #include "TGeoNode.h"
21 
22 
24 
25 
26 class SBNDCRTGeometryTest : public art::EDAnalyzer {
27 public:
28  explicit SBNDCRTGeometryTest(fhicl::ParameterSet const& p);
29  // The compiler-generated destructor is fine for non-base
30  // classes without bare pointers or other resource use.
31 
32  // Plugins should not be copied or assigned.
37 
38  // Required functions.
39  void analyze(art::Event const& e) override;
40 
41 private:
42 
43 };
44 
45 
46 SBNDCRTGeometryTest::SBNDCRTGeometryTest(fhicl::ParameterSet const& p)
47  : EDAnalyzer{p}
48 {}
49 
50 void SBNDCRTGeometryTest::analyze(art::Event const& e)
51 {
52  art::ServiceHandle<geo::Geometry const> geoService;
53 
54  std::cout << "Number of CRT AuxDets is " << geoService->NAuxDets() << std::endl;
55 
56  assert(geoService->NAuxDets() > 0);
57 
58 
59  std::vector<int> used_copynumbers_auxdet;
60  std::vector<int> used_copynumbers_sensitiveauxdet;
61 
62  for (size_t i = 0; i < geoService->NAuxDets(); i++) {
63  const geo::AuxDetGeo& adGeo = geoService->AuxDet(i);
64 
65  std::set<std::string> volNames = { adGeo.TotalVolume()->GetName() };
66  std::vector<std::vector<TGeoNode const*> > paths =
67  geoService->FindAllVolumePaths(volNames);
68 
69  std::string path = "";
70  for (size_t inode=0; inode<paths.at(0).size(); inode++) {
71  path += paths.at(0).at(inode)->GetName();
72  if (inode < paths.at(0).size() - 1) {
73  path += "/";
74  }
75  }
76 
77  TGeoManager* manager = geoService->ROOTGeoManager();
78  manager->cd(path.c_str());
79 
80  // We get the array of strips first, which is the AuxDet,
81  // then from the AuxDet, we get the strip by picking the
82  // daughter with the ID of the AuxDetSensitive, and finally
83  // from the AuxDet, we go up and pick the module and tagger
84  TGeoNode* nodeArray = manager->GetCurrentNode();
85  TGeoNode* nodeModule = manager->GetMother(1);
86  TGeoNode* nodeTagger = manager->GetMother(2);
87 
88 
89  // Ensure auxiliary detector ID and its GDML copynumber are the same
90  assert(i == (size_t)nodeModule->GetNumber());
91 
92  // Check every aux det has a different copynumber
93  auto iter = std::find(used_copynumbers_auxdet.begin(), used_copynumbers_auxdet.end(),
94  nodeModule->GetNumber());
95  assert(iter == used_copynumbers_auxdet.end());
96 
97  used_copynumbers_auxdet.push_back(nodeModule->GetNumber());
98 
99 
100  // Ensure there are CRT strips
101  assert(nodeArray->GetNdaughters() > 0);
102 
103 
104  // Ensure that the number of AuxDetSensitive in the geometry service
105  // is the same as the number of daughter nodes
106  assert((int)geoService->NAuxDetSensitive(i) == nodeArray->GetNdaughters());
107 
108  std::cout << "Auxiliary detector ID " << i
109  << " with copynumber " << nodeModule->GetNumber()
110  << "\n\t strip array name: " << nodeArray->GetName()
111  << "\n\t module name: " << nodeModule->GetName()
112  << "\n\t tagger name: " << nodeTagger->GetName() << std::endl;
113 
114  // Loop over the AuxDetSensitive volumes
115  for (int adsid = 0; adsid < nodeArray->GetNdaughters(); adsid++) {
116 
117  TGeoNode* nodeStrip = nodeArray->GetDaughter(adsid);
118 
119  std::cout << "\t\t has sensitive detector (strip) with ID " << adsid
120  << ", name: " << nodeStrip->GetName()
121  << " (copynumber " << nodeStrip->GetNumber() << ")" << std::endl;
122 
123  // Check every sensitive aux det has a different copynumber (this is used by LArG4)
124  auto iter2 = std::find(used_copynumbers_sensitiveauxdet.begin(), used_copynumbers_sensitiveauxdet.end(),
125  nodeStrip->GetNumber());
126  assert(iter2 == used_copynumbers_sensitiveauxdet.end());
127 
128  used_copynumbers_sensitiveauxdet.push_back(nodeStrip->GetNumber());
129  }
130 
131  }
132 
133 
134 }
135 
136 DEFINE_ART_MODULE(SBNDCRTGeometryTest)
137 
138 
139 
pdgs p
Definition: selectors.fcl:22
SBNDCRTGeometryTest & operator=(SBNDCRTGeometryTest const &)=delete
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
SBNDCRTGeometryTest(fhicl::ParameterSet const &p)
void analyze(art::Event const &e) override
const TGeoVolume * TotalVolume() const
Definition: AuxDetGeo.h:106
do i e
art framework interface to geometry description
BEGIN_PROLOG could also be cout