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
Tracker2DHitProcessor.cxx
Go to the documentation of this file.
2#include "utilities.h"
3
4Tracker2DHitProcessor::Tracker2DHitProcessor(const std::string& name, Process& process)
5 : Processor(name, process) {
6}
7
10
12
13 std::cout << "Configuring Tracker2DHitProcessor" << 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 hitFitCollLcio_ = parameters.getString("hitFitCollLcio", hitFitCollLcio_);
21 }
22 catch (std::runtime_error& error)
23 {
24 std::cout << error.what() << std::endl;
25 }
26}
27
29 // Add branches to tree
30 tree->Branch(hitCollRoot_.c_str(), &hits_);
31}
32
34
35 for(int i = 0; i < hits_.size(); i++) delete hits_.at(i);
36 hits_.clear();
37
38 Event* event = static_cast<Event*> (ievent);
39 UTIL::LCRelationNavigator* rawTracker_hit_fits_nav;
40 UTIL::LCRelationNavigator* mcPartRel_nav;
41
42 // Get the collection of 2D hits from the LCIO event. If no such collection
43 // exist, a DataNotAvailableException is thrown
44 EVENT::LCCollection* tracker_hits{nullptr};
45 try
46 {
47 tracker_hits = event->getLCCollection(hitCollLcio_.c_str());
48 }
49 catch (EVENT::DataNotAvailableException e)
50 {
51 std::cout << e.what() << std::endl;
52 }
53
54 //Check to see if fits are in the file
55 auto evColls = event->getLCEvent()->getCollectionNames();
56 auto it = std::find (evColls->begin(), evColls->end(), hitFitCollLcio_.c_str());
57 bool hasFits = true;
58 EVENT::LCCollection* raw_svt_hit_fits;
59 if(it == evColls->end()) hasFits = false;
60 if(hasFits)
61 {
62 raw_svt_hit_fits = event->getLCCollection(hitFitCollLcio_.c_str());
63 // Heap an LCRelation navigator which will allow faster access
64 rawTracker_hit_fits_nav = new UTIL::LCRelationNavigator(raw_svt_hit_fits);
65 }
66
67 //Check to see if MC Particles are in the file
68 it = std::find (evColls->begin(), evColls->end(), mcPartRelLcio_.c_str());
69 bool hasMCParts = true;
70 EVENT::LCCollection* mcPartRel;
71 if(it == evColls->end()) hasMCParts = false;
72 if(hasMCParts)
73 {
74 mcPartRel = event->getLCCollection(mcPartRelLcio_.c_str());
75 // Heap an LCRelation navigator which will allow faster access
76 mcPartRel_nav = new UTIL::LCRelationNavigator(mcPartRel);
77
78 }
79
80 // Create a map from an LCIO TrackerHit to a SvtHit. This will be used when
81 // assigning references to a track
82 // TODO: Use an unordered map for faster access
83 std::map<EVENT::TrackerHit*, TrackerHit*> hit_map;
84
85 // Loop over all of the 2D hits in the LCIO event and add them to the
86 // HPS event
87 bool rotateHits = true;
88 int hitType = 1;
89
90 for (int ihit = 0; ihit < tracker_hits->getNumberOfElements(); ++ihit) {
91
92 float rawcharge = 0;
93 int volume = -1;
94 int layer = -1;
95
96 // Get a 2D hit from the list of hits
97 IMPL::TrackerHitImpl* lc_tracker_hit = static_cast<IMPL::TrackerHitImpl*>(tracker_hits->getElementAt(ihit));
98
99 if(debug_ > 0)
100 std::cout << "tracker hit lcio id: " << lc_tracker_hit->id() << std::endl;
101
102 // Build a TrackerHit
103 TrackerHit* tracker_hit = utils::buildTrackerHit(lc_tracker_hit,rotateHits, hitType);
104
105 if(hasFits)
106 utils::addRawInfoTo3dHit(tracker_hit, lc_tracker_hit,raw_svt_hit_fits,nullptr,hitType,false);
107
108 if(hasMCParts){
109 //Get the SvtRawTrackerHits that make up the 2D hit
110 EVENT::LCObjectVec rawHits = lc_tracker_hit->getRawHits();
111 for(int irawhit = 0; irawhit < rawHits.size(); ++irawhit){
112 IMPL::TrackerHitImpl* rawhit = static_cast<IMPL::TrackerHitImpl*>(rawHits.at(irawhit));
113 if(debug_ > 0)
114 std::cout << "rawhit on track has lcio id: " << rawhit->id() << std::endl;
115
116 // Get the list of fit params associated with the raw tracker hit
117 EVENT::LCObjectVec lc_simtrackerhits = mcPartRel_nav->getRelatedToObjects(rawhit);
118
119 //Loop over SimTrackerHits to get MCParticles
120 for(int isimhit = 0; isimhit < lc_simtrackerhits.size(); isimhit++){
121 IMPL::SimTrackerHitImpl* lc_simhit = static_cast<IMPL::SimTrackerHitImpl*>(lc_simtrackerhits.at(isimhit));
122 IMPL::MCParticleImpl* lc_mcp = static_cast<IMPL::MCParticleImpl*>(lc_simhit->getMCParticle());
123 if(lc_mcp == nullptr)
124 std::cout << "mcp is null" << std::endl;
125 tracker_hit->addMCPartID(lc_mcp->id());
126 if(debug_ > 0) {
127 std::cout << "simtrackerhit lcio id: " << lc_simhit->id() << std::endl;
128 std::cout << "mcp lcio id: " << lc_mcp->id() << std::endl;
129 }
130 }
131
132 /*
133 // Get all the MC Particle IDs associated to the hit
134 for(int ipart = 0; ipart < mcPart_list.size(); ipart++)
135 {
136 IMPL::MCParticleImpl* lc_particle
137 = static_cast<IMPL::MCParticleImpl*>(mcPart_list.at(ipart));
138 tracker_hit->addMCPartID(lc_particle->id());
139 if(debug_ > 0) std::cout << "Has Related MC Particle with ID " << lc_particle->id() << std::endl;
140 }
141 */
142 }
143 }
144
145 // Map the TrackerHit object to the corresponding SvtHit object. This
146 // will be used later when setting references for hits on tracks.
147 //hit_map[lc_tracker_hit] = tracker_hit;
148 hits_.push_back(tracker_hit);
149 }
150
151 if(hasMCParts) delete mcPartRel_nav;
152 if(hasFits) delete rawTracker_hit_fits_nav;
153
154 return true;
155}
156
158 std::cout << "finalize()" << std::endl;
159}
160
#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
virtual void configure(const ParameterSet &parameters)
virtual void initialize(TTree *tree)
Tracker2DHitProcessor(const std::string &name, Process &process)
std::vector< TrackerHit * > hits_
void addMCPartID(const int id)
Definition TrackerHit.h:80
bool addRawInfoTo3dHit(TrackerHit *tracker_hit, IMPL::TrackerHitImpl *lc_tracker_hit, EVENT::LCCollection *raw_svt_fits, std::vector< RawSvtHit * > *rawHits=nullptr, int type=0, bool storeRawHit=true)
description
TrackerHit * buildTrackerHit(IMPL::TrackerHitImpl *lc_trackerHit, bool rotate=true, int type=0)
description