Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RequireParticlesInAcc.cc
Go to the documentation of this file.
1 #include <iomanip>
2 #include <algorithm>
4 #include <g4main/PHG4Hit.h>
6 #include <phool/PHNodeIterator.h>
7 #include <phool/PHIODataNode.h>
8 #include <phool/getClass.h>
10 using namespace std;
11 
13  : SubsysReco(name)
14  , m_npl_per_par(4)
15  , m_npar_per_evt(2)
16 {
17  ;
18 }
19 
21 {
22  ;
23 }
24 
26 {
28 }
29 
31 {
32  int ret = GetNodes(topNode);
33  if (ret != Fun4AllReturnCodes::EVENT_OK) return ret;
35 }
36 
38 {
40  vector<int> vec_id_h1 = ExtractParticleID(g4hc_h1t, g4hc_h1b);
41  vector<int> vec_id_h2 = ExtractParticleID(g4hc_h2t, g4hc_h2b);
42  vector<int> vec_id_h3 = ExtractParticleID(g4hc_h3t, g4hc_h3b);
43  vector<int> vec_id_h4 = ExtractParticleID(g4hc_h4t, g4hc_h4b);
44 
46  map<int, int> map_nhit; // [particle ID] -> N of hit planes
47  CountHitPlanesPerParticle(vec_id_h1, map_nhit);
48  CountHitPlanesPerParticle(vec_id_h2, map_nhit);
49  CountHitPlanesPerParticle(vec_id_h3, map_nhit);
50  CountHitPlanesPerParticle(vec_id_h4, map_nhit);
51 
53  int n_par_ok = 0;
54  for (map<int, int>::iterator it = map_nhit.begin(); it != map_nhit.end(); it++) {
55  if (it->second >= m_npl_per_par) n_par_ok++;
56  }
57 
58  return n_par_ok >= m_npar_per_evt ? Fun4AllReturnCodes::EVENT_OK : Fun4AllReturnCodes::ABORTEVENT;
59 }
60 
62 {
64 }
65 
66 int RequireParticlesInAcc::GetNodes(PHCompositeNode* topNode)
67 {
68  g4hc_h1t = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_H1T");
69  g4hc_h1b = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_H1B");
70  g4hc_h2t = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_H2T");
71  g4hc_h2b = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_H2B");
72  g4hc_h3t = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_H3T");
73  g4hc_h3b = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_H3B");
74  g4hc_h4t = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_H4T");
75  g4hc_h4b = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_H4B");
76 
77  if (!g4hc_h1t || !g4hc_h1b || !g4hc_h2t || !g4hc_h2b ||
78  !g4hc_h3t || !g4hc_h3b || !g4hc_h4t || !g4hc_h4b ) {
80  }
82 }
83 
84 void RequireParticlesInAcc::ExtractParticleID(const PHG4HitContainer* g4hc, vector<int>& vec_par_id)
85 {
86  PHG4HitContainer::ConstRange range = g4hc->getHits();
87  for (PHG4HitContainer::ConstIterator it = range.first; it != range.second; it++) {
88  PHG4Hit* hit = it->second;
89  vec_par_id.push_back(hit->get_trkid());
90  }
91 }
92 
93 vector<int> RequireParticlesInAcc::ExtractParticleID(const PHG4HitContainer* g4hc_t, const PHG4HitContainer* g4hc_b)
94 {
95  vector<int> vec;
96  ExtractParticleID(g4hc_t, vec);
97  ExtractParticleID(g4hc_b, vec);
98  sort(vec.begin(), vec.end());
99  vec.erase(unique(vec.begin(), vec.end()), vec.end());
100  return vec;
101 }
102 
103 void RequireParticlesInAcc::CountHitPlanesPerParticle(const vector<int> vec_id, map<int, int>& map_nhit)
104 {
105  for (vector<int>::const_iterator it = vec_id.begin(); it != vec_id.end(); it++) {
106  int id = *it;
107  if (map_nhit.find(id) == map_nhit.end()) map_nhit[id] = 1;
108  else map_nhit[id]++;
109  }
110 }
virtual int get_trkid() const
Definition: PHG4Hit.h:41
ConstRange getHits(const unsigned int detid) const
return all hits matching a given detid
RequireParticlesInAcc(const std::string &name="ACCEPTANCE")
std::pair< ConstIterator, ConstIterator > ConstRange
Definition: PHG4Hit.h:9
Map::const_iterator ConstIterator
int InitRun(PHCompositeNode *topNode)
int Init(PHCompositeNode *topNode)
int End(PHCompositeNode *topNode)
Called at the end of all processing.
int process_event(PHCompositeNode *topNode)