hpstr
The Heavy Photon Search Toolkit for Reconstruction (hpstr) provides an interface to physics data from the HPS experiment saved in the LCIO format and converts it into an ROOT based format.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tracker3DHitProcessor.cxx
Go to the documentation of this file.
2#include "utilities.h"
3
4Tracker3DHitProcessor::Tracker3DHitProcessor(const std::string& name, Process& process)
5 : Processor(name, process) {
6}
7
10
12
13 std::cout << "Configuring Tracker3DHitProcessor" << std::endl;
14 try
15 {
16 debug_ = parameters.getInteger("debug", debug_);
17 hitCollLcio_ = parameters.getString("hitCollLcio", hitCollLcio_);
18 hitCollRoot_ = parameters.getString("hitCollRoot", hitCollRoot_);
19 mcPartRelLcio_ = parameters.getString("mcPartRelLcio", mcPartRelLcio_);
20 }
21 catch (std::runtime_error& error)
22 {
23 std::cout << error.what() << std::endl;
24 }
25}
26
28 // Add branches to tree
29 tree->Branch(hitCollRoot_.c_str(), &hits_);
30}
31
33
34 for(int i = 0; i < hits_.size(); i++) delete hits_.at(i);
35 hits_.clear();
36
37 Event* event = static_cast<Event*> (ievent);
38 UTIL::LCRelationNavigator* mcPartRel_nav;
39
40 // Get the collection of 3D hits from the LCIO event. If no such collection
41 // exist, a DataNotAvailableException is thrown
42 EVENT::LCCollection* tracker_hits{nullptr};
43 try
44 {
45 tracker_hits = event->getLCCollection(hitCollLcio_.c_str());
46 }
47 catch (EVENT::DataNotAvailableException e)
48 {
49 std::cout << e.what() << std::endl;
50 }
51
52 //Check to see if MC Particles are in the file
53 auto evColls = event->getLCEvent()->getCollectionNames();
54 auto it = std::find (evColls->begin(), evColls->end(), mcPartRelLcio_.c_str());
55 bool hasMCParts = true;
56 EVENT::LCCollection* mcPartRel;
57 if(it == evColls->end()) hasMCParts = false;
58 if(hasMCParts)
59 {
60 mcPartRel = event->getLCCollection(mcPartRelLcio_.c_str());
61 // Heap an LCRelation navigator which will allow faster access
62 mcPartRel_nav = new UTIL::LCRelationNavigator(mcPartRel);
63
64 }
65
66 // Create a map from an LCIO TrackerHit to a SvtHit. This will be used when
67 // assigning references to a track
68 // TODO: Use an unordered map for faster access
69 std::map<EVENT::TrackerHit*, TrackerHit*> hit_map;
70
71 // Loop over all of the 3D hits in the LCIO event and add them to the
72 // HPS event
73 for (int ihit = 0; ihit < tracker_hits->getNumberOfElements(); ++ihit) {
74
75 // Get a 3D hit from the list of hits
76 IMPL::TrackerHitImpl* lc_tracker_hit = static_cast<IMPL::TrackerHitImpl*>(tracker_hits->getElementAt(ihit));
77
78 // Build a TrackerHit
79 TrackerHit* tracker_hit = utils::buildTrackerHit(lc_tracker_hit);
80
81 if(hasMCParts)
82 {
83 // Get the list of fit params associated with the raw tracker hit
84 EVENT::LCObjectVec mcPart_list
85 = mcPartRel_nav->getRelatedToObjects(lc_tracker_hit);
86
87 if(debug_ > 0) std::cout << "Has " << mcPart_list.size() << " Related MC Particles" << std::endl;
88 // Get all the MC Particle IDs associated to the hit
89 for(int ipart = 0; ipart < mcPart_list.size(); ipart++)
90 {
91 IMPL::MCParticleImpl* lc_particle
92 = static_cast<IMPL::MCParticleImpl*>(mcPart_list.at(ipart));
93 tracker_hit->addMCPartID(lc_particle->id());
94 if(debug_ > 0) std::cout << "Has Related MC Particle with ID " << lc_particle->id() << std::endl;
95 }
96 }
97
98 // Map the TrackerHit object to the corresponding SvtHit object. This
99 // will be used later when setting references for hits on tracks.
100 hit_map[lc_tracker_hit] = tracker_hit;
101 hits_.push_back(tracker_hit);
102
103 }
104
105 if(hasMCParts) delete mcPartRel_nav;
106
107 return true;
108}
109
112
#define DECLARE_PROCESSOR(CLASS)
Macro which allows the framework to construct a producer given its name during configuration.
Definition Processor.h:139
Definition Event.h:35
EVENT::LCCollection * getLCCollection(std::string name)
Definition Event.h:102
Definition IEvent.h:7
description
Base class for all event processing components.
Definition Processor.h:34
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95
Insert description here. more details.
Tracker3DHitProcessor(const std::string &name, Process &process)
Class constructor.
std::string mcPartRelLcio_
description
virtual void configure(const ParameterSet &parameters)
Callback for the Processor to configure itself from the given set of parameters.
virtual void finalize()
Callback for the Processor to take any necessary action when the processing of events finishes.
virtual void initialize(TTree *tree)
Callback for the Processor to take any necessary action when the processing of events starts.
std::vector< TrackerHit * > hits_
std::string hitCollRoot_
description
std::string hitCollLcio_
description
void addMCPartID(const int id)
Definition TrackerHit.h:80
TrackerHit * buildTrackerHit(IMPL::TrackerHitImpl *lc_trackerHit, bool rotate=true, int type=0)
description