Belle II Software  release-05-02-19
SegmentNetworkAnalyzerModule.cc
1 /*************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2016 - Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Thomas Madlener *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 
11 #include <vector>
12 
13 #include <tracking/modules/vxdtfRedesign/SegmentNetworkAnalyzerModule.h>
14 #include <tracking/spacePointCreation/SpacePoint.h>
15 #include <tracking/spacePointCreation/PurityCalculatorTools.h>
16 
17 
18 using namespace Belle2;
19 using namespace std;
20 
21 REG_MODULE(SegmentNetworkAnalyzer);
22 
24  Module(),
25  m_rFilePtr(nullptr),
26  m_treePtr(nullptr)
27 {
28  setDescription("Module for analyzing the SegmentNetwork.");
29 
30  addParam("networkInputName", m_PARAMnetworkName, "name of the StoreObjPtr to the DNN Container");
31  addParam("rootFileName", m_PARAMrootFileName, "name of the output root file name",
32  std::string("SegmentNetworkAnalyzer_output.root"));
33 
34 }
35 
37 {
38  B2INFO("SegmentNetworkAnalyzer::initialize() ------------------------------");
39  m_network.isRequired(m_PARAMnetworkName);
41  m_mcParticles.isRequired();
42 
43  m_rFilePtr = new TFile(m_PARAMrootFileName.c_str(), "recreate");
44  m_treePtr = new TTree("SegmentNetworkAnalyzer", "segment network analysis output");
45 
46  makeBranches();
47 }
48 
50 {
51  m_rootVariables = RootVariables(); // clear rootVariables
52 
53  auto& hitNetwork = m_network->accessHitNetwork();
54  auto& segmentNetwork = m_network->accessSegmentNetwork();
55  m_rootVariables.networkSize = segmentNetwork.size();
57 
58  for (const auto& outerHit : hitNetwork.getNodes()) {
59  for (const auto& centerHit : outerHit->getInnerNodes()) {
60  for (const auto& innerHit : centerHit->getInnerNodes()) {
61 
62  Segment<TrackNode>* innerSegment = new Segment<TrackNode>(centerHit->getEntry().m_sector->getFullSecID(),
63  innerHit->getEntry().m_sector->getFullSecID(),
64  &centerHit->getEntry(),
65  &innerHit->getEntry());
66  Segment<TrackNode>* outerSegment = new Segment<TrackNode>(outerHit->getEntry().m_sector->getFullSecID(),
67  centerHit->getEntry().m_sector->getFullSecID(),
68  &outerHit->getEntry(),
69  &centerHit->getEntry());
70 
71  bool passed = false;
72  // check if the outerSegment is in the network and then look if the inner is connected to it
73  if (auto outerNode = segmentNetwork.getNode(outerSegment->getID())) {
74  for (const auto& connectedNode : outerNode->getInnerNodes()) {
75  if (connectedNode->getEntry() == *innerSegment) {
76  passed = true;
77  break;
78  }
79  }
80  }
81  analyzeCombination(*innerSegment, *outerSegment, passed);
82 
83  } // end inner loop
84  } // end center loop
85  } // end outer loop
86 
87  m_treePtr->Fill();
88 }
89 
91 {
92  // write and close root file
93  if (m_rFilePtr && m_treePtr) {
94  m_rFilePtr->cd();
95  m_rFilePtr->Write();
96  m_rFilePtr->Close();
97  }
98 }
99 
101 {
102  m_treePtr->Branch("phi", &m_rootVariables.phi);
103  m_treePtr->Branch("theta", &m_rootVariables.theta);
104  m_treePtr->Branch("pT", &m_rootVariables.pT);
105  m_treePtr->Branch("signal", &m_rootVariables.signal);
106  m_treePtr->Branch("passed", &m_rootVariables.passed);
107  m_treePtr->Branch("pdg", &m_rootVariables.pdg);
108  m_treePtr->Branch("virtualIP", &m_rootVariables.virtualIP);
109  m_treePtr->Branch("networkSize", &m_rootVariables.networkSize);
110  m_treePtr->Branch("networkConns", &m_rootVariables.networkConnections);
111 }
112 
115  bool passed)
116 {
117  m_rootVariables.passed.push_back(passed);
118 
119  std::vector<const Belle2::SpacePoint*> combinationSPs; // order in which they are stored does not really matter
120  combinationSPs.push_back(outer.getOuterHit()->m_spacePoint);
121  combinationSPs.push_back(outer.getInnerHit()->m_spacePoint);
122  combinationSPs.push_back(inner.getInnerHit()->m_spacePoint);
123 
124  const vector<MCVXDPurityInfo> purityInfo = createPurityInfosVec(combinationSPs);
125  auto mcId = purityInfo[0].getPurity();
126  bool signal = mcId.first >= 0 && mcId.second == 1;
127  m_rootVariables.signal.push_back((int) signal);
128 
129  // define some default values for non-signal combinations
130  int pdg = 0;
131  double pT = -999;
132 
133  if (signal) {
134  const MCParticle* part = m_mcParticles[mcId.first];
135  pdg = part->getPDG();
136  pT = part->getMomentum().Pt();
137  }
138 
139  m_rootVariables.pdg.push_back(pdg);
140  m_rootVariables.pT.push_back(pT);
141 
142  // check if the innermost hit is virtualIP, if so get the outer hit to retrieve the position information from it
143  auto spacePoint = inner.getInnerHit()->m_spacePoint;
144  if (spacePoint->getType() == VXD::SensorInfoBase::VXD) {
145  m_rootVariables.virtualIP.push_back(1);
146  spacePoint = inner.getOuterHit()->m_spacePoint;
147  } else m_rootVariables.virtualIP.push_back(0);
148 
149  // angles are determined from inner most (accessible) hit in combination
150  auto position = spacePoint->getPosition();
151  m_rootVariables.phi.push_back(position.Phi());
152  m_rootVariables.theta.push_back(position.Theta());
153 
154  B2DEBUG(100, "Collected combination with: phi " << position.Phi() << ", theta " << position.Theta() <<
155  ", pdg " << pdg << ", pT " << pT << ", signal " << signal << ", passed " << passed << ", mcId " << mcId.first);
156 }
157 
158 template<typename EntryType, typename MetaInfoType >
160 {
161  size_t nLinks{};
162  for (const auto& outerNodes : network) {
163  nLinks += outerNodes->getInnerNodes().size();
164  }
165  return nLinks;
166 }
Belle2::SegmentNetworkAnalyzerModule::initialize
void initialize() override
set up root file and check required Store Arrays
Definition: SegmentNetworkAnalyzerModule.cc:36
Belle2::SegmentNetworkAnalyzerModule::RootVariables::phi
std::vector< double > phi
phi of the innermost hit (that is not the virtual IP)
Definition: SegmentNetworkAnalyzerModule.h:47
Belle2::SegmentNetworkAnalyzerModule::RootVariables::passed
std::vector< int > passed
did segment combination pass the three hit filters
Definition: SegmentNetworkAnalyzerModule.h:51
Belle2::SegmentNetworkAnalyzerModule::RootVariables::theta
std::vector< double > theta
theta of the innermost hit (that is not the virtual IP)
Definition: SegmentNetworkAnalyzerModule.h:48
Belle2::Module::setDescription
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:216
Belle2::SegmentNetworkAnalyzerModule::RootVariables::networkConnections
unsigned networkConnections
number of connections in network
Definition: SegmentNetworkAnalyzerModule.h:55
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Segment::getOuterHit
const HitType * getOuterHit() const
returns outer hit of current Segment
Definition: Segment.h:110
Belle2::SegmentNetworkAnalyzerModule::event
void event() override
collect necessary data and put into TTree
Definition: SegmentNetworkAnalyzerModule.cc:49
Belle2::SegmentNetworkAnalyzerModule::RootVariables::pT
std::vector< double > pT
pT of the related MCParticle
Definition: SegmentNetworkAnalyzerModule.h:49
Belle2::TrackNode::m_spacePoint
SpacePoint * m_spacePoint
Pointer to spacePoint.
Definition: TrackNode.h:52
Belle2::SegmentNetworkAnalyzerModule::RootVariables::networkSize
unsigned networkSize
segmentNetwork size
Definition: SegmentNetworkAnalyzerModule.h:54
Belle2::VXD::SensorInfoBase::VXD
@ VXD
Any type of VXD Sensor.
Definition: SensorInfoBase.h:47
Belle2::Segment
The Segment class This class represents segments of track candidates needed for TrackFinderVXD-Module...
Definition: Segment.h:35
Belle2::DirectedNodeNetwork
Network of directed nodes of the type EntryType.
Definition: DirectedNodeNetwork.h:38
Belle2::SegmentNetworkAnalyzerModule::m_rFilePtr
TFile * m_rFilePtr
ptr to root file
Definition: SegmentNetworkAnalyzerModule.h:85
Belle2::SegmentNetworkAnalyzerModule::m_network
Belle2::StoreObjPtr< Belle2::DirectedNodeNetworkContainer > m_network
StoreObjPtr to the SegmentNetwork and TrackNode Network container.
Definition: SegmentNetworkAnalyzerModule.h:79
Belle2::SegmentNetworkAnalyzerModule::SegmentNetworkAnalyzerModule
SegmentNetworkAnalyzerModule()
constructor
Definition: SegmentNetworkAnalyzerModule.cc:23
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::SegmentNetworkAnalyzerModule::terminate
void terminate() override
write and close root file
Definition: SegmentNetworkAnalyzerModule.cc:90
Belle2::Segment::getID
std::int64_t getID() const
************************* PUBLIC MEMBER FUNCTIONS *************************
Definition: Segment.h:94
Belle2::SegmentNetworkAnalyzerModule::m_PARAMrootFileName
std::string m_PARAMrootFileName
file name of the produced root file
Definition: SegmentNetworkAnalyzerModule.h:76
Belle2::SegmentNetworkAnalyzerModule::RootVariables::virtualIP
std::vector< int > virtualIP
did the segment contain the virtual IP
Definition: SegmentNetworkAnalyzerModule.h:53
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SegmentNetworkAnalyzerModule::m_treePtr
TTree * m_treePtr
ptr to TTree
Definition: SegmentNetworkAnalyzerModule.h:88
Belle2::SegmentNetworkAnalyzerModule::getNConnections
size_t getNConnections(Belle2::DirectedNodeNetwork< EntryType, MetaInfoType > &network) const
get the number of connections between the nodes of a network
Definition: SegmentNetworkAnalyzerModule.cc:159
Belle2::SegmentNetworkAnalyzerModule::RootVariables
keep all the variables for rootoutput in one struct
Definition: SegmentNetworkAnalyzerModule.h:46
Belle2::SegmentNetworkAnalyzerModule::makeBranches
void makeBranches()
setup the Branches in the output TTree
Definition: SegmentNetworkAnalyzerModule.cc:100
Belle2::createPurityInfosVec
static std::vector< Belle2::MCVXDPurityInfo > createPurityInfosVec(const std::vector< const Belle2::SpacePoint * > &spacePoints)
create a vector of MCVXDPurityInfos objects for a std::vector<Belle2::SpacePoints>.
Definition: PurityCalculatorTools.h:159
Belle2::Module::addParam
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:562
Belle2::SegmentNetworkAnalyzerModule::RootVariables::signal
std::vector< int > signal
was segment combination signal
Definition: SegmentNetworkAnalyzerModule.h:50
Belle2::Segment::getInnerHit
const HitType * getInnerHit() const
returns inner hit of current Segment
Definition: Segment.h:106
Belle2::SegmentNetworkAnalyzerModule::RootVariables::pdg
std::vector< int > pdg
pdg of the related MCParticle
Definition: SegmentNetworkAnalyzerModule.h:52
Belle2::SegmentNetworkAnalyzerModule::m_mcParticles
Belle2::StoreArray< Belle2::MCParticle > m_mcParticles
MCParticles StoreArray for obtaining MC Information.
Definition: SegmentNetworkAnalyzerModule.h:82
Belle2::SegmentNetworkAnalyzerModule::m_PARAMnetworkName
std::string m_PARAMnetworkName
StoreArray name of the DirectedNodeNetworkContainer.
Definition: SegmentNetworkAnalyzerModule.h:73
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::StoreArray< MCParticle >
Belle2::SegmentNetworkAnalyzerModule::m_rootVariables
RootVariables m_rootVariables
handle to collect all data for one event
Definition: SegmentNetworkAnalyzerModule.h:91
Belle2::SegmentNetworkAnalyzerModule::analyzeCombination
void analyzeCombination(const Belle2::Segment< Belle2::TrackNode > &outer, const Belle2::Segment< Belle2::TrackNode > &inner, bool passed)
get necessary data from three hit combination and put them into the root variables
Definition: SegmentNetworkAnalyzerModule.cc:113