ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TpcRS.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TpcRS.cc
1 //____________________________________________________________________________..
2 //
3 // This is a template for a Fun4All SubsysReco module with all methods from the
4 // $OFFLINE_MAIN/include/fun4all/SubsysReco.h baseclass
5 // You do not have to implement all of them, you can just remove unused methods
6 // here and in TpcRS.h.
7 //
8 // TpcRS(const std::string &name = "TpcRS")
9 // everything is keyed to TpcRS, duplicate names do work but it makes
10 // e.g. finding culprits in logs difficult or getting a pointer to the module
11 // from the command line
12 //
13 // TpcRS::~TpcRS()
14 // this is called when the Fun4AllServer is deleted at the end of running. Be
15 // mindful what you delete - you do loose ownership of object you put on the node tree
16 //
17 // int TpcRS::Init(PHCompositeNode *topNode)
18 // This method is called when the module is registered with the Fun4AllServer. You
19 // can create historgrams here or put objects on the node tree but be aware that
20 // modules which haven't been registered yet did not put antyhing on the node tree
21 //
22 // int TpcRS::InitRun(PHCompositeNode *topNode)
23 // This method is called when the first event is read (or generated). At
24 // this point the run number is known (which is mainly interesting for raw data
25 // processing). Also all objects are on the node tree in case your module's action
26 // depends on what else is around. Last chance to put nodes under the DST Node
27 // We mix events during readback if branches are added after the first event
28 //
29 // int TpcRS::process_event(PHCompositeNode *topNode)
30 // called for every event. Return codes trigger actions, you find them in
31 // $OFFLINE_MAIN/include/fun4all/Fun4AllReturnCodes.h
32 // everything is good:
33 // return Fun4AllReturnCodes::EVENT_OK
34 // abort event reconstruction, clear everything and process next event:
35 // return Fun4AllReturnCodes::ABORT_EVENT;
36 // proceed but do not save this event in output (needs output manager setting):
37 // return Fun4AllReturnCodes::DISCARD_EVENT;
38 // abort processing:
39 // return Fun4AllReturnCodes::ABORT_RUN
40 // all other integers will lead to an error and abort of processing
41 //
42 // int TpcRS::ResetEvent(PHCompositeNode *topNode)
43 // If you have internal data structures (arrays, stl containers) which needs clearing
44 // after each event, this is the place to do that. The nodes under the DST node are cleared
45 // by the framework
46 //
47 // int TpcRS::EndRun(const int runnumber)
48 // This method is called at the end of a run when an event from a new run is
49 // encountered. Useful when analyzing multiple runs (raw data). Also called at
50 // the end of processing (before the End() method)
51 //
52 // int TpcRS::End(PHCompositeNode *topNode)
53 // This is called at the end of processing. It needs to be called by the macro
54 // by Fun4AllServer::End(), so do not forget this in your macro
55 //
56 // int TpcRS::Reset(PHCompositeNode *topNode)
57 // not really used - it is called before the dtor is called
58 //
59 // void TpcRS::Print(const std::string &what) const
60 // Called from the command line - useful to print information when you need it
61 //
62 //____________________________________________________________________________..
63 
64 #include "TpcRS.h"
65 
66 #include <g4main/PHG4Hit.h>
68 #include <g4main/PHG4Particle.h>
70 
72 
73 #include <phool/PHCompositeNode.h>
74 #include <phool/getClass.h>
75 
76 #include <TSystem.h>
77 
78 //____________________________________________________________________________..
79 TpcRS::TpcRS(const std::string &name)
80  : SubsysReco(name)
81 {
82  std::cout << "TpcRS::TpcRS(const std::string &name) Calling ctor" << std::endl;
83 }
84 
85 //____________________________________________________________________________..
87 {
88  delete simulator;
89  std::cout << "TpcRS::~TpcRS() Calling dtor" << std::endl;
90 }
91 
92 //____________________________________________________________________________..
94 {
95  std::cout << "TpcRS::Init(PHCompositeNode *topNode) Initializing" << std::endl;
97 }
98 
99 //____________________________________________________________________________..
101 {
102  std::cout << "TpcRS::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
104 }
105 
106 //____________________________________________________________________________..
108 {
109  std::cout << "TpcRS::process_event(PHCompositeNode *topNode)" << std::endl;
110  PHG4TruthInfoContainer *TruthInfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
111  if (!TruthInfo)
112  {
113  std::cout << PHWHERE << " ERROR: Can't find G4TruthInfo" << std::endl;
114  gSystem->Exit(-1);
115  }
116 
117  PHG4HitContainer *hits = findNode::getClass<PHG4HitContainer>(topNode, "G4HIT_TPC");
118  if (!hits)
119  {
120  std::cout << "no G4HITS_TPC node" << std::endl;
121  gSystem->Exit(-1);
122  }
123  PHG4HitContainer::ConstRange hit_range = hits->getHits();
124  for (PHG4HitContainer::ConstIterator hit_iter = hit_range.first; hit_iter != hit_range.second; hit_iter++)
125  {
126  PHG4Particle *particle = TruthInfo->GetParticle(hit_iter->second->get_trkid());
127  tpcrs::SimulatedHit simu_hit;
128  if (hit_iter->second->get_trkid() == 0)
129  {
130  std::cout << "trackid=0, x: " << hit_iter->second->get_avg_x() << std::endl;
131  }
132  simu_hit.track_id = hit_iter->second->get_trkid();
133  simu_hit.particle_id = particle->get_pid();
134  simu_hit.x = hit_iter->second->get_avg_x();
135  simu_hit.y = hit_iter->second->get_avg_y();
136  simu_hit.z = hit_iter->second->get_avg_z();
137  simu_hit.px = 0.5 * (hit_iter->second->get_px(0) + hit_iter->second->get_px(1));
138  simu_hit.py = 0.5 * (hit_iter->second->get_py(0) + hit_iter->second->get_py(1));
139  simu_hit.pz = 0.5 * (hit_iter->second->get_pz(0) + hit_iter->second->get_pz(1));
140  simu_hit.de = hit_iter->second->get_edep();
141  simu_hit.ds = hit_iter->second->get_path_length();
142  simu_hit.tof = hit_iter->second->get_avg_t();
143  simu_hits.push_back(simu_hit);
144  }
145  simulator->Distort(begin(simu_hits), end(simu_hits), std::back_inserter(dist_hits));
146 
147  // simulator->Digitize(begin(simu_hits), end(simu_hits), std::back_inserter(digi_hits));
148 
150 }
151 
152 //____________________________________________________________________________..
154 {
155  std::cout << "TpcRS::ResetEvent(PHCompositeNode *topNode) Resetting internal structures, prepare for next event" << std::endl;
156  simu_hits.clear();
157  dist_hits.clear();
158  digi_hits.clear();
160 }
161 
162 //____________________________________________________________________________..
163 int TpcRS::EndRun(const int runnumber)
164 {
165  std::cout << "TpcRS::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
167 }
168 
169 //____________________________________________________________________________..
171 {
172  std::cout << "TpcRS::End(PHCompositeNode *topNode) This is the End..." << std::endl;
174 }
175 
176 //____________________________________________________________________________..
178 {
179  std::cout << "TpcRS::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
181 }
182 
183 //____________________________________________________________________________..
184 void TpcRS::Print(const std::string &what) const
185 {
186  std::cout << "TpcRS::Print(const std::string &what) const Printing info for " << what << std::endl;
187 }
188 
189 void TpcRS::SetupConfigurator(const std::string &filename)
190 {
191  cfg = new tpcrs::Configurator("simple", filename);
192  simulator = new tpcrs::Simulator(*cfg);
193 }