star-travex
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StiVolumeFilter.cxx
Go to the documentation of this file.
2 #include "TError.h"
3 #include "Sti/StiKalmanTrack.h"
4 #include "Sti/StiKalmanTrackNode.h"
5 
6 
11 StiVolumeFilter::StiVolumeFilter() : fgDetGroupId(kMaxDetectorId), fgDetActiveOnly(false),
12  fgVolumeSelectPatterns()
13 {
14  std::string patternFileName("save_sti_detectors.txt");
15  std::ifstream volumePatternFile(patternFileName);
16  std::string pattern;
17 
18  while ( std::getline(volumePatternFile, pattern) )
19  {
20  try {
21  boost::regex volNameRegex(pattern);
22  fgVolumeSelectPatterns.insert(volNameRegex);
23  }
24  catch (boost::regex_error& e) {
25  Warning(__FUNCTION__, "Regex [%s] found in [%s] is not valid", pattern.c_str(), patternFileName.c_str());
26  }
27  }
28 }
29 
30 
32 {
33  static StiVolumeFilter instance;
34  return instance;
35 }
36 
37 
38 bool StiVolumeFilter::AcceptTrack(const StiKalmanTrack& track) const
39 {
40  return HasAcceptedNode(track);
41 }
42 
43 
44 bool StiVolumeFilter::AcceptTrackNode(const StiKalmanTrackNode& node) const
45 {
46  // Always accept DCA nodes
47  if ( node.isDca() ) return true;
48 
49  // Continue with a non-DCA node
50  // Always reject nodes without a proper detector
51  if ( !node.getDetector() ) return false;
52 
53  // Non-DCA node with detector defined
54  std::string volumeName( node.getDetector()->getName() );
55 
56  // Always reject nodes without a proper detector name
57  if ( volumeName.empty() ) return false;
58 
59  // If no patterns defined check detectorGroupId and active det is not used but should be at some
60  // point...
61  if (fgVolumeSelectPatterns.empty())
62  {
63  StDetectorId stiNodeDetId = static_cast<StDetectorId>( node.getDetector()->getGroupId() );
64 
65  if ( ( fgDetGroupId == stiNodeDetId || fgDetGroupId == kMaxDetectorId ) &&
66  ( (fgDetActiveOnly && node.getDetector()->isActive()) || !fgDetActiveOnly )
67  )
68  {
69  return true;
70  }
71 
72  return false;
73  }
74 
75  for (const auto& volNamePattern : fgVolumeSelectPatterns)
76  {
77  if ( boost::regex_match(volumeName, volNamePattern) ) return true;
78  }
79 
80  return false;
81 }
82 
83 
84 bool StiVolumeFilter::HasAcceptedNode(const StiKalmanTrack& track) const
85 {
86  // By convention return true if no patterns defined
87  if (fgVolumeSelectPatterns.empty()) return true;
88 
89  // Loop over track nodes
90  for (const StiKalmanTrackNode& node : track)
91  {
92  // The decision to accept does not take into account DCA nodes
93  if ( node.isDca() ) continue;
94 
95  if ( AcceptTrackNode(node) ) return true;
96  }
97 
98  return false;
99 }
StDetectorId fgDetGroupId
Detector group id used in this study.
bool AcceptTrack(const StiKalmanTrack &track) const
bool fgDetActiveOnly
Another selection criteria to save nodes.
std::set< boost::regex > fgVolumeSelectPatterns
A set of regex patterns to select and save track nodes passing through volumes with matching names...
static StiVolumeFilter & GetInstance()
A singleton to manage constraints on save Sti objects such as tracks and track nodes.
StiVolumeFilter()
By default, we set no constraints on tracks w.r.t.
bool AcceptTrackNode(const StiKalmanTrackNode &node) const
bool HasAcceptedNode(const StiKalmanTrack &track) const