Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackPoint.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackPoint.cc
1 /* Copyright 2008-2009, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "Track.h"
21 
22 #include "TrackPoint.h"
23 #include "Exception.h"
24 #include "KalmanFitterInfo.h"
25 #include "IO.h"
26 
27 #include <algorithm>
28 #include <TBuffer.h>
29 
30 namespace genfit {
31 
33  sortingParameter_(0), track_(nullptr), thinScatterer_(nullptr)
34 {
35  ;
36 }
37 
39  sortingParameter_(0), track_(track), thinScatterer_(nullptr)
40 {
41  ;
42 }
43 
44 TrackPoint::TrackPoint(const std::vector< genfit::AbsMeasurement* >& rawMeasurements, Track* track) :
45  sortingParameter_(0), track_(track), thinScatterer_(nullptr)
46 {
47  rawMeasurements_.reserve(rawMeasurements.size());
48 
49  for (std::vector<AbsMeasurement*>::const_iterator m = rawMeasurements.begin(); m != rawMeasurements.end(); ++m) {
51  }
52 }
53 
54 TrackPoint::TrackPoint(AbsMeasurement* rawMeasurement, Track* track) :
55  sortingParameter_(0), track_(track), thinScatterer_(nullptr)
56 {
57  addRawMeasurement(rawMeasurement);
58 }
59 
60 
62  TObject(rhs),
63  sortingParameter_(rhs.sortingParameter_), track_(rhs.track_), thinScatterer_(nullptr)
64 {
65  // clone rawMeasurements
66  for (std::vector<AbsMeasurement*>::const_iterator it = rhs.rawMeasurements_.begin(); it != rhs.rawMeasurements_.end(); ++it) {
67  AbsMeasurement* tp = (*it)->clone();
69  }
70 
71  // copy fitterInfos
72  for (std::map<const AbsTrackRep*, AbsFitterInfo* >::const_iterator it = rhs.fitterInfos_.begin(); it != rhs.fitterInfos_.end(); ++it ) {
73  AbsFitterInfo* fi = it->second->clone();
74  fi->setTrackPoint(this);
75  setFitterInfo(fi);
76  }
77 
78  if (rhs.thinScatterer_ != nullptr)
79  thinScatterer_.reset(new ThinScatterer(*(rhs.thinScatterer_)));
80 }
81 
83  const std::map<const AbsTrackRep*, AbsTrackRep*>& map,
84  const std::vector<const genfit::AbsTrackRep*> * repsToIgnore) :
85  sortingParameter_(rhs.sortingParameter_), track_(rhs.track_), thinScatterer_(nullptr)
86 {
87  // clone rawMeasurements
88  for (std::vector<AbsMeasurement*>::const_iterator it = rhs.rawMeasurements_.begin(); it!=rhs.rawMeasurements_.end(); ++it) {
89  AbsMeasurement* m = (*it)->clone();
91  }
92 
93  // copy fitterInfos
94  for (std::map<const AbsTrackRep*, AbsFitterInfo* >::const_iterator it = rhs.fitterInfos_.begin(); it != rhs.fitterInfos_.end(); ++it ) {
95  if (repsToIgnore != nullptr) {
96  if (std::find(repsToIgnore->begin(), repsToIgnore->end(), it->first) != repsToIgnore->end())
97  continue;
98  }
99  AbsFitterInfo* fi = it->second->clone();
100  fi->setRep(map.at(it->first));
101  fi->setTrackPoint(this);
102  setFitterInfo(fi);
103  }
104 
105  if (rhs.thinScatterer_ != nullptr)
106  thinScatterer_.reset(new ThinScatterer(*(rhs.thinScatterer_)));
107 }
108 
109 
111  swap(rhs);
112 
113  for (std::vector<AbsMeasurement*>::const_iterator it = rawMeasurements_.begin(); it!=rawMeasurements_.end(); ++it) {
114  (*it)->setTrackPoint(this);
115  }
116 
117  for (std::map<const AbsTrackRep*, AbsFitterInfo* >::const_iterator it = fitterInfos_.begin(); it != fitterInfos_.end(); ++it ) {
118  it->second->setTrackPoint(this);
119  }
120 
121  return *this;
122 }
123 
124 
127  std::swap(this->track_, other.track_);
129  std::swap(this->fitterInfos_, other.fitterInfos_);
130  this->thinScatterer_.swap(other.thinScatterer_);
131 }
132 
133 
135  // FIXME: We definitely need some smart containers or smart pointers that
136  // take care of this, but so far we haven't found a convincing
137  // option (2013-07-05).
138 
139  for (size_t i = 0; i < rawMeasurements_.size(); ++i)
140  delete rawMeasurements_[i];
141 
142  std::map< const AbsTrackRep*, AbsFitterInfo* >::iterator it;
143  for (it = fitterInfos_.begin(); it != fitterInfos_.end(); ++it)
144  delete it->second;
145 }
146 
147 
149  if (i < 0)
150  i += rawMeasurements_.size();
151 
152  return rawMeasurements_.at(i);
153 }
154 
155 
156 std::vector< AbsFitterInfo* > TrackPoint::getFitterInfos() const {
157  std::vector< AbsFitterInfo* > retVal;
158 
159  if (fitterInfos_.empty())
160  return retVal;
161 
162  for (std::map<const AbsTrackRep*, AbsFitterInfo* >::const_iterator it = fitterInfos_.begin(); it != fitterInfos_.end(); ++it ) {
163  retVal.push_back(it->second);
164  }
165 
166  return retVal;
167 }
168 
169 
171  if (!rep)
172  rep = track_->getCardinalRep();
173  std::map<const AbsTrackRep*, AbsFitterInfo*>::const_iterator it = fitterInfos_.find(rep);
174  if (it == fitterInfos_.end())
175  return nullptr;
176  return fitterInfos_.at(rep);
177 }
178 
179 
181  return dynamic_cast<KalmanFitterInfo*>(getFitterInfo(rep));
182 }
183 
184 
185 
187  for (size_t i = 0; i < rawMeasurements_.size(); ++i)
188  delete rawMeasurements_[i];
189 
190  rawMeasurements_.clear();
191 }
192 
193 
195  assert (fitterInfo != nullptr);
196  if (hasFitterInfo(fitterInfo->getRep()))
197  delete fitterInfos_[fitterInfo->getRep()];
198 
199  fitterInfos_[fitterInfo->getRep()] = fitterInfo;
200 }
201 
202 
203 void TrackPoint::Print(const Option_t*) const {
204  printOut << "genfit::TrackPoint, belonging to Track " << track_ << "; sorting parameter = " << sortingParameter_ << "\n";
205  printOut << "contains " << rawMeasurements_.size() << " rawMeasurements and " << getFitterInfos().size() << " fitterInfos for " << fitterInfos_.size() << " TrackReps.\n";
206 
207  for (unsigned int i=0; i<rawMeasurements_.size(); ++i) {
208  printOut << "RawMeasurement Nr. " << i << "\n";
209  rawMeasurements_[i]->Print();
210  printOut << "............\n";
211  }
212 
213  for (std::map< const AbsTrackRep*, AbsFitterInfo* >::const_iterator it = fitterInfos_.begin(); it != fitterInfos_.end(); ++it ) {
214  printOut << "FitterInfo for TrackRep " << it->first << "\n";
215  it->second->Print();
216  printOut << "............\n";
217  }
218 
219  if (thinScatterer_)
220  thinScatterer_->Print();
221 
222 }
223 
224 
225 //
226 // This is modified from the auto-generated Streamer.
227 //
228 void TrackPoint::Streamer(TBuffer &R__b)
229 {
230  // Stream an object of class genfit::TrackPoint.
231  //This works around a msvc bug and should be harmless on other platforms
232  typedef ::genfit::TrackPoint thisClass;
233  UInt_t R__s, R__c;
234  if (R__b.IsReading()) {
235  Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
236  //TObject::Streamer(R__b);
237  R__b >> sortingParameter_;
238  {
239  std::vector<genfit::AbsMeasurement*,std::allocator<genfit::AbsMeasurement*> > &R__stl = rawMeasurements_;
240  R__stl.clear();
241  TClass *R__tcl1 = TBuffer::GetClass(typeid(genfit::AbsMeasurement));
242  if (R__tcl1==0) {
243  Error("rawMeasurements_ streamer","Missing the TClass object for genfit::AbsMeasurement!");
244  return;
245  }
246  int R__i, R__n;
247  R__b >> R__n;
248  R__stl.reserve(R__n);
249  for (R__i = 0; R__i < R__n; R__i++) {
250  genfit::AbsMeasurement* R__t = 0;
251  R__b >> R__t;
252  R__stl.push_back(R__t);
253  }
254  }
255  track_ = nullptr;
256  size_t nTrackReps;
257  R__b >> nTrackReps;
258  for (size_t i = 0; i < nTrackReps; ++i) {
259  int id;
260  R__b >> id;
261  AbsFitterInfo* p = 0;
262  R__b >> p;
263  vFitterInfos_[id] = p;
264  }
265  thinScatterer_.reset();
266  char flag;
267  R__b >> flag;
268  if (flag) {
269  genfit::ThinScatterer *scatterer = 0;
270  R__b >> scatterer;
271  thinScatterer_.reset(new ThinScatterer(*scatterer));
272  }
273  R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
274 
275 
276  // Fixup ownerships.
277  for (size_t i = 0; i < rawMeasurements_.size(); ++i) {
278  rawMeasurements_[i]->setTrackPoint(this);
279  }
280  for (auto& trackRepIDWithFitterInfo : vFitterInfos_) {
281  AbsFitterInfo* fitterInfo = trackRepIDWithFitterInfo.second;
282  if (fitterInfo)
283  fitterInfo->setTrackPoint(this);
284  }
285  } else {
286  R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
287  //TObject::Streamer(R__b);
288  R__b << sortingParameter_;
289  {
290  std::vector<genfit::AbsMeasurement*,std::allocator<genfit::AbsMeasurement*> > &R__stl = rawMeasurements_;
291  int R__n= int(R__stl.size());
292  R__b << R__n;
293  if(R__n) {
294  std::vector<genfit::AbsMeasurement*,std::allocator<genfit::AbsMeasurement*> >::iterator R__k;
295  for (R__k = R__stl.begin(); R__k != R__stl.end(); ++R__k) {
296  R__b << (*R__k);
297  }
298  }
299  }
300  R__b << fitterInfos_.size();
301  for (std::map<const AbsTrackRep*, AbsFitterInfo*>::const_iterator it = fitterInfos_.begin();
302  it != fitterInfos_.end(); ++it)
303  {
304  int id = track_->getIdForRep(it->first);
305  R__b << id;
306  R__b << it->second;
307  }
308  if (thinScatterer_) {
309  R__b << (char)1;
310  R__b << thinScatterer_.get();
311  } else {
312  R__b << (char)0;
313  }
314  R__b.SetByteCount(R__c, kTRUE);
315  }
316 }
317 
318 
320 {
321  for (auto& trackRepIDWithFitterInfo : vFitterInfos_) {
322  // The map is filled such that i corresponds to the id of the TrackRep.
323  const unsigned int id = trackRepIDWithFitterInfo.first;
324  AbsFitterInfo* fitterInfo = trackRepIDWithFitterInfo.second;
325 
326  // May not have FitterInfos for all reps.
327  if (!fitterInfo)
328  continue;
329  AbsTrackRep* trackRep = track_->getTrackRep(id);
330 
331  fitterInfos_[trackRep] = fitterInfo;
332  fitterInfos_[trackRep]->setRep(trackRep);
333  }
334  vFitterInfos_.clear();
335 }
336 
337 } /* End of namespace genfit */