CMS 3D CMS Logo

FWTrackProxyBuilderFullFramework.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Tracks
4 // Class : FWTrackProxyBuilder
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Nov 25 14:42:13 EST 2008
11 //
12 
13 // system include files
14 #include "TEveManager.h"
15 #include "TEveBrowser.h"
16 #include "TEveTrack.h"
17 #include "TEvePointSet.h"
18 #include "TEveCompound.h"
19 
20 // user include files
24 
32 
34 public:
37 
39 
40  void setItem(const FWEventItem* iItem) override;
41  bool visibilityModelChanges(const FWModelId&, TEveElement*, FWViewType::EType, const FWViewContext*) override;
42 
44  const FWTrackProxyBuilderFullFramework& operator=(const FWTrackProxyBuilderFullFramework&) = delete; // stop default
45 
46 private:
47  void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
49 
50  TEveTrackPropagator* m_trackerPropagator;
52 };
53 
55  : m_trackerPropagator(nullptr), m_trajToTrackMap(nullptr) {
56  m_trackerPropagator = new TEveTrackPropagator();
57  m_trackerPropagator->SetStepper(TEveTrackPropagator::kRungeKutta);
58  m_trackerPropagator->SetDelta(0.01);
59  m_trackerPropagator->SetMaxOrbs(0.7);
60  m_trackerPropagator->IncDenyDestroy();
61 }
62 
64 
67  if (iItem) {
68  m_trackerPropagator->SetMagFieldObj(context().getField(), false);
69  iItem->getConfig()->assertParam("Rnr TrajectoryMeasurement", false);
70  }
71 }
72 
74  TEveElementList* product,
75  const FWViewContext* vc) {
76  const reco::TrackCollection* tracks = nullptr;
77  iItem->get(tracks);
78  if (tracks == nullptr)
79  return;
80 
81  try {
82  const edm::EventBase* event = item()->getEvent();
83  edm::InputTag tag(item()->moduleLabel(), item()->productInstanceLabel(), item()->processName());
84  edm::Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
85  event->getByLabel(tag, trajTrackAssociationHandle);
86  m_trajToTrackMap = &*trajTrackAssociationHandle;
87  } catch (cms::Exception& exception) {
88  m_trajToTrackMap = nullptr;
89  std::cout << exception.what() << std::endl;
90  }
91 
92  if (m_trajToTrackMap) {
93  bool rnrPathMarks = item()->getConfig()->value<bool>("Rnr TrajectoryMeasurement");
94  if (m_trackerPropagator->GetRnrReferences() != rnrPathMarks)
95  m_trackerPropagator->SetRnrReferences(rnrPathMarks);
96 
97  unsigned track_index = 0;
99  ++it, ++track_index) {
100  TEveCompound* comp = createCompound();
101  setupAddElement(comp, product);
102 
103  if (item()->modelInfo(track_index).displayProperties().isVisible())
104  buildTrack(it, comp);
105  }
106  } else {
107  for (reco::TrackCollection::const_iterator i = tracks->begin(); i != tracks->end(); ++i) {
108  const reco::Track& track = *i;
109  TEveRecTrack ts;
110  ts.fBeta = 1.;
111  ts.fSign = track.charge();
112  ts.fP.Set(track.px(), track.py(), track.pz());
113  ts.fV.Set(track.vx(), track.vy(), track.vz());
114  TEveTrack* eveTrack = new TEveTrack(&ts, m_trackerPropagator);
115  eveTrack->MakeTrack();
116  TEveCompound* comp = createCompound();
117  setupAddElement(comp, product);
118  setupAddElement(eveTrack, comp);
119  }
120  }
121 
122  gEve->GetBrowser()->MapWindow();
123 }
124 
126  TEveCompound* comp) {
127  const reco::Track& track = *it->val;
128  const Trajectory& traj = *it->key;
129 
130  TEveRecTrack ts;
131  ts.fBeta = 1.;
132  ts.fSign = track.charge();
133  ts.fP.Set(track.px(), track.py(), track.pz());
134  ts.fV.Set(track.vx(), track.vy(), track.vz());
135  TEveTrack* eveTrack = new TEveTrack(&ts, m_trackerPropagator);
136 
137  // path-marks from a trajectory
138  std::vector<TrajectoryMeasurement> measurements = traj.measurements();
139  std::vector<TrajectoryMeasurement>::iterator measurements_it = measurements.begin();
140  std::vector<TrajectoryMeasurement>::reverse_iterator measurements_rit = measurements.rbegin();
141  for (size_t t = 0; t != measurements.size(); ++t, ++measurements_it, ++measurements_rit) {
142  TrajectoryStateOnSurface trajState =
143  (traj.direction() == alongMomentum) ? measurements_it->updatedState() : measurements_rit->updatedState();
144 
145  if (!trajState.isValid())
146  continue;
147 
148  eveTrack->AddPathMark(TEvePathMark(
149  TEvePathMark::kReference,
150  TEveVector(trajState.globalPosition().x(), trajState.globalPosition().y(), trajState.globalPosition().z()),
151  TEveVector(trajState.globalMomentum().x(), trajState.globalMomentum().y(), trajState.globalMomentum().z())));
152  }
153 
154  eveTrack->MakeTrack();
155  setupAddElement(eveTrack, comp);
156 }
157 
159  TEveElement* iCompound,
160  FWViewType::EType viewType,
161  const FWViewContext* vc) {
162  const FWEventItem::ModelInfo& info = iId.item()->modelInfo(iId.index());
163  bool returnValue = false;
164  if (info.displayProperties().isVisible() && iCompound->NumChildren() == 0 && m_trajToTrackMap) {
166  std::advance(it, iId.index());
167  buildTrack(it, (TEveCompound*)iCompound);
168  returnValue = true;
169  }
170  return returnValue;
171 }
172 
175  "TracksTrajectory",
#define REGISTER_PROXYBUILDER_METHODS()
static const TGPicture * info(bool iBackgroundIsBlack)
#define REGISTER_FWPROXYBUILDER(_name_, _type_, _purpose_, _view_)
void setItem(const FWEventItem *iItem) override
static const int kAllRPZBits
Definition: FWViewType.h:67
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
T z() const
Definition: PV3DBase.h:61
FWProxyBuilderConfiguration * getConfig() const
Definition: FWEventItem.h:150
void buildTrack(TrajTrackAssociationCollection::const_iterator it, TEveCompound *comp)
void get(const T *&oData) const
Definition: FWEventItem.h:78
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
int index() const
Definition: FWModelId.h:41
bool visibilityModelChanges(const FWModelId &, TEveElement *, FWViewType::EType, const FWViewContext *) override
static const int kAll3DBits
Definition: FWViewType.h:68
const fireworks::Context & context() const
const FWTrackProxyBuilderFullFramework & operator=(const FWTrackProxyBuilderFullFramework &)=delete
DataContainer const & measurements() const
Definition: Trajectory.h:178
const_iterator end() const
last iterator over the map (read only)
const TrajTrackAssociationCollection * m_trajToTrackMap
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
GlobalPoint globalPosition() const
PropagationDirection const & direction() const
Definition: Trajectory.cc:133
virtual void setItem(const FWEventItem *iItem)
constexpr unsigned getField(const uint32_t u, const unsigned mask, const unsigned offset)
const edm::EventBase * getEvent() const
Definition: FWEventItem.h:131
const FWEventItem * item() const
Definition: FWModelId.h:39
FWGenericParameter< T > * assertParam(const std::string &name, T def)
auto const & tracks
cannot be loose
TEveCompound * createCompound(bool set_color=true, bool propagate_color_to_all_children=false) const
GlobalVector globalMomentum() const
const_iterator begin() const
first iterator over the map (read only)
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
const FWEventItem * item() const