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.
Loading...
Searching...
No Matches
FinalStateParticleProcessor.cxx
Go to the documentation of this file.
1
7#include "utilities.h"
8
12
15
17
18 std::cout << "Configuring FinalStateParticleProcessor" << std::endl;
19 try
20 {
21 debug_ = parameters.getInteger("debug", debug_);
22 fspCollLcio_ = parameters.getString("fspCollLcio", fspCollLcio_);
23 fspCollRoot_ = parameters.getString("fspCollRoot", fspCollRoot_);
24 kinkRelCollLcio_ = parameters.getString("kinkRelCollLcio", kinkRelCollLcio_);
25 trkRelCollLcio_ = parameters.getString("trkRelCollLcio", trkRelCollLcio_);
26 hitFitsCollLcio_ = parameters.getString("hitFitsCollLcio", hitFitsCollLcio_);
27 trkhitCollRoot_ = parameters.getString("trkhitCollRoot",trkhitCollRoot_);
28 rawhitCollRoot_ = parameters.getString("rawhitCollRoot",rawhitCollRoot_);
29 bfield_ = parameters.getDouble("bfield",bfield_); //this will overwrite the momentum; only use for pre-v3 slcio
30 trackStateLocation_ = parameters.getString("trackStateLocation", trackStateLocation_);
31 }
32 catch (std::runtime_error& error)
33 {
34 std::cout << error.what() << std::endl;
35 }
36}
37
39 // Add branches to tree
40
41 if (!trkhitCollRoot_.empty())
42 tree->Branch(trkhitCollRoot_.c_str(), &hits_);
43
44 if (!rawhitCollRoot_.empty())
45 tree->Branch(rawhitCollRoot_.c_str(), &rawhits_);
46 tree->Branch(fspCollRoot_.c_str(), &fsps_);
47}
48
50
51 if (debug_ > 0) std::cout << "FinalStateParticleProcessor: Clear output vector" << std::endl;
52
53 //Clean up
54 if (hits_.size() > 0) {
55 for (std::vector<TrackerHit *>::iterator it = hits_.begin(); it != hits_.end(); ++it) {
56 delete *it;
57 }
58 hits_.clear();
59 }
60
61 if (rawhits_.size() > 0) {
62 for (std::vector<RawSvtHit *>::iterator it = rawhits_.begin(); it != rawhits_.end(); ++it) {
63 delete *it;
64 }
65 rawhits_.clear();
66 }
67
68 for(int i = 0; i < fsps_.size(); i++) delete fsps_.at(i);
69 fsps_.clear();
70
71 Event* event = static_cast<Event*> (ievent);
72
73 // Get the collection of vertices from the LCIO event. If no such collection
74 // exist, a DataNotAvailableException is thrown
75 if (debug_ > 0) std::cout << "FinalStateParticleProcessor: Get LCIO Collection " << fspCollLcio_ << std::endl;
76 EVENT::LCCollection* lc_fsps= nullptr;
77 try
78 {
79 lc_fsps = event->getLCCollection(fspCollLcio_.c_str());
80 }
81 catch (EVENT::DataNotAvailableException e)
82 {
83 std::cout << e.what() << std::endl;
84 return false;
85 }
86
87 // Get the collection of LCRelations between GBL tracks and kink data and track data variables.
88 EVENT::LCCollection* gbl_kink_data{nullptr};
89 EVENT::LCCollection* track_data{nullptr};
90
91 try
92 {
93 if (!kinkRelCollLcio_.empty())
94 gbl_kink_data = static_cast<EVENT::LCCollection*>(event->getLCCollection(kinkRelCollLcio_.c_str()));
95 if (!trkRelCollLcio_.empty())
96 track_data = static_cast<EVENT::LCCollection*>(event->getLCCollection(trkRelCollLcio_.c_str()));
97 }
98 catch (EVENT::DataNotAvailableException e)
99 {
100 std::cout << e.what() << std::endl;
101 if (!gbl_kink_data)
102 std::cout<<"Failed retrieving " << kinkRelCollLcio_ <<std::endl;
103 if (!track_data)
104 std::cout<<"Failed retrieving " << trkRelCollLcio_ <<std::endl;
105
106 }
107
108
109 if (debug_ > 0) std::cout << "FinalStateParticleProcessor: Converting"<< std::endl;
110
111 bool rotateHits = true;
112 int hitType = 0;
113 EVENT::LCCollection* raw_svt_hit_fits = nullptr;
114
115 auto evColls = event->getLCEvent()->getCollectionNames();
116 auto it = std::find (evColls->begin(), evColls->end(), hitFitsCollLcio_.c_str());
117 bool hasFits = true;
118 if(it == evColls->end()) hasFits = false;
119 if(hasFits)
120 {
121 raw_svt_hit_fits = event->getLCCollection(hitFitsCollLcio_.c_str());
122 }
123 for (int ifsp = 0 ; ifsp < lc_fsps->getNumberOfElements(); ++ifsp)
124 {
125 if (debug_ > 0) std::cout << "FinalStateParticleProcessor: Converting FinalStateParticle " << ifsp << std::endl;
126 EVENT::ReconstructedParticle* lc_fsp{nullptr};
127 lc_fsp = static_cast<EVENT::ReconstructedParticle*>(lc_fsps->getElementAt(ifsp));
128 if (debug_ > 0) std::cout << "FinalStateParticleProcessor: Build Particle" << std::endl;
129
130 Particle * fsp = utils::buildParticle(lc_fsp, trackStateLocation_, gbl_kink_data, track_data);
131 EVENT::Track* lc_track = lc_fsp->getTracks().empty() ? nullptr : static_cast<EVENT::Track*>(lc_fsp->getTracks()[0]);
132 Track* track = lc_track ? utils::buildTrack(lc_track, trackStateLocation_, gbl_kink_data, track_data) : nullptr;
133 // buildTrack returns nullptr when the requested track state is missing
134 if (lc_track && !track)
135 std::cout << "[FinalStateParticleProcessor] WARNING: track " << lc_track->id() << " has no '"
136 << trackStateLocation_ << "' track state; particle stored without a track" << std::endl;
137 if (track){
138 if (bfield_ > 0.0) track->setMomentum(bfield_); //this will overwrite the momentum; only use for pre-v3 slcio
139 if (track->isKalmanTrack()) hitType = 1; //SiClusters
140 EVENT::TrackerHitVec lc_tracker_hits = lc_track->getTrackerHits();
141 for (auto lc_tracker_hit : lc_tracker_hits) {
142 TrackerHit* tracker_hit = utils::buildTrackerHit(static_cast<IMPL::TrackerHitImpl*>(lc_tracker_hit),rotateHits,hitType);
143 std::vector<RawSvtHit*> rawSvthitsOn3d;
144 utils::addRawInfoTo3dHit(tracker_hit,static_cast<IMPL::TrackerHitImpl*>(lc_tracker_hit),
145 raw_svt_hit_fits,&rawSvthitsOn3d,hitType);
146 for (auto rhit : rawSvthitsOn3d)
147 rawhits_.push_back(rhit);
148 //rawhits_->addHit(rhit);
149
150 track->addHit(tracker_hit);
151 hits_.push_back(tracker_hit);
152 rawSvthitsOn3d.clear();
153 // loop on j>i tracks
154 }
155 fsp->setTrack(track);
156 delete track;
157 }
158
159 if (debug_ > 0) std::cout << "FinalStateParticleProcessor: Add Particle" << std::endl;
160 fsps_.push_back(fsp);
161 }
162
163 if (debug_ > 0) std::cout << "FinalStateParticleProcessor: End process" << std::endl;
164 return true;
165}
166
169
#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
Insert description here. more details.
virtual bool process(IEvent *ievent)
Process the event and put new data products into it.
std::string trackStateLocation_
track state used to build tracks; "" = AtPerigee
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.
FinalStateParticleProcessor(const std::string &name, Process &process)
Class constructor.
virtual void initialize(TTree *tree)
Callback for the Processor to take any necessary action when the processing of events starts.
std::vector< RawSvtHit * > rawhits_
std::vector< TrackerHit * > hits_
Definition IEvent.h:7
description
Processor(const std::string &name, Process &process)
Class constructor.
Definition Processor.cxx:10
virtual bool process()
Process the histograms and generate analysis output.
Definition Processor.h:95
Definition Track.h:32
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
Track * buildTrack(EVENT::Track *lc_track, std::string trackstate_location, EVENT::LCCollection *gbl_kink_data, EVENT::LCCollection *track_data)
description
TrackerHit * buildTrackerHit(IMPL::TrackerHitImpl *lc_trackerHit, bool rotate=true, int type=0)
description
Particle * buildParticle(EVENT::ReconstructedParticle *lc_particle, std::string trackstate_location, EVENT::LCCollection *gbl_kink_data, EVENT::LCCollection *track_data)
description
Definition utilities.cxx:47