Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "TEveManager.h"
00016 #include "TEveBrowser.h"
00017 #include "TEveTrack.h"
00018 #include "TEvePointSet.h"
00019 #include "TEveCompound.h"
00020
00021
00022 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
00023 #include "Fireworks/Core/interface/FWEventItem.h"
00024 #include "Fireworks/Core/interface/FWMagField.h"
00025
00026
00027 #include "DataFormats/TrackReco/interface/Track.h"
00028 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00029 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
00030 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00031 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
00032 #include "FWCore/Framework/interface/ESHandle.h"
00033 #include "FWCore/Common/interface/EventBase.h"
00034
00035 class FWTrackProxyBuilderFF : public FWProxyBuilderBase {
00036
00037 public:
00038 FWTrackProxyBuilderFF();
00039 virtual ~FWTrackProxyBuilderFF();
00040
00041 REGISTER_PROXYBUILDER_METHODS();
00042
00043 virtual void setItem(const FWEventItem* iItem);
00044 virtual bool visibilityModelChanges(const FWModelId&, TEveElement*, FWViewType::EType, const FWViewContext*);
00045
00046 private:
00047 FWTrackProxyBuilderFF(const FWTrackProxyBuilderFF&);
00048 const FWTrackProxyBuilderFF& operator=(const FWTrackProxyBuilderFF&);
00049
00050 void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*);
00051 void buildTrack(TrajTrackAssociationCollection::const_iterator it, TEveCompound* comp);
00052
00053
00054 TEveTrackPropagator* m_trackerPropagator;
00055 const TrajTrackAssociationCollection* m_trajToTrackMap;
00056 };
00057
00058 FWTrackProxyBuilderFF::FWTrackProxyBuilderFF():
00059 m_trackerPropagator(0),
00060 m_trajToTrackMap(0)
00061 {
00062 m_trackerPropagator = new TEveTrackPropagator();
00063 m_trackerPropagator->SetStepper( TEveTrackPropagator::kRungeKutta );
00064 m_trackerPropagator->SetDelta(0.01);
00065 m_trackerPropagator->SetMaxOrbs(0.7);
00066 m_trackerPropagator->IncDenyDestroy();
00067 }
00068
00069 FWTrackProxyBuilderFF::~FWTrackProxyBuilderFF()
00070 {
00071 m_trackerPropagator->DecDenyDestroy();
00072 }
00073
00074 void FWTrackProxyBuilderFF::setItem(const FWEventItem* iItem)
00075 {
00076 FWProxyBuilderBase::setItem(iItem);
00077 if (iItem)
00078 {
00079 m_trackerPropagator->SetMagFieldObj(context().getField(), false);
00080 iItem->getConfig()->assertParam("Rnr TrajectoryMeasurement", false);
00081 }
00082 }
00083
00084 void
00085 FWTrackProxyBuilderFF::build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext* vc)
00086 {
00087 const reco::TrackCollection * tracks = 0;
00088 iItem->get( tracks );
00089 if( tracks == 0 ) return;
00090
00091 try {
00092 const edm::EventBase* event = item()->getEvent();
00093 edm::InputTag tag(item()->moduleLabel(), item()->productInstanceLabel(), item()->processName());
00094 edm::Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
00095 event->getByLabel(tag, trajTrackAssociationHandle);
00096 m_trajToTrackMap = &*trajTrackAssociationHandle;
00097 }
00098 catch (cms::Exception &exception)
00099 {
00100 m_trajToTrackMap =0;
00101 std::cout << exception.what() << std::endl;
00102 return;
00103 }
00104
00105
00106 bool rnrPathMarks = item()->getConfig()->value<bool>("Rnr TrajectoryMeasurement");
00107 if (m_trackerPropagator->GetRnrReferences() != rnrPathMarks ) m_trackerPropagator->SetRnrReferences(rnrPathMarks);
00108
00109 unsigned track_index = 0;
00110 for(TrajTrackAssociationCollection::const_iterator it = m_trajToTrackMap->begin(); it!=m_trajToTrackMap->end(); ++it, ++track_index)
00111 {
00112 TEveCompound* comp = createCompound();
00113 setupAddElement( comp, product );
00114
00115 if (item()->modelInfo(track_index).displayProperties().isVisible())
00116 buildTrack(it, comp);
00117 }
00118
00119 gEve->GetBrowser()->MapWindow();
00120 }
00121
00122 void FWTrackProxyBuilderFF::buildTrack(TrajTrackAssociationCollection::const_iterator it, TEveCompound* comp)
00123 {
00124 const reco::Track track = *it->val;
00125 const Trajectory traj = *it->key;
00126
00127 TEveRecTrack ts;
00128 ts.fBeta = 1.;
00129 ts.fSign = track.charge();
00130 ts.fP.Set(track.px(), track.py(), track.pz());
00131 ts.fV.Set(track.vx(), track.vy(), track.vz());
00132 TEveTrack* eveTrack = new TEveTrack( &ts, m_trackerPropagator);
00133
00134
00135 std::vector<TrajectoryMeasurement> measurements = traj.measurements();
00136 std::vector<TrajectoryMeasurement>::iterator measurements_it = measurements.begin();
00137 std::vector<TrajectoryMeasurement>::reverse_iterator measurements_rit = measurements.rbegin();
00138 for (size_t t=0; t != measurements.size(); ++t, ++measurements_it, ++measurements_rit)
00139 {
00140 TrajectoryStateOnSurface trajState = (traj.direction() == alongMomentum) ? measurements_it->updatedState() : measurements_rit->updatedState() ;
00141
00142 if( !trajState.isValid() ) continue;
00143
00144 eveTrack->AddPathMark( TEvePathMark( TEvePathMark::kReference,
00145 TEveVector(trajState.globalPosition().x(),trajState.globalPosition().y(), trajState.globalPosition().z()),
00146 TEveVector(trajState.globalMomentum().x(),trajState.globalMomentum().y(), trajState.globalMomentum().z())));
00147 }
00148
00149 eveTrack->MakeTrack();
00150 setupAddElement(eveTrack, comp);
00151 }
00152
00153 bool FWTrackProxyBuilderFF::visibilityModelChanges(const FWModelId& iId, TEveElement* iCompound,
00154 FWViewType::EType viewType, const FWViewContext* vc)
00155 {
00156 const FWEventItem::ModelInfo& info = iId.item()->modelInfo(iId.index());
00157 bool returnValue = false;
00158 if (info.displayProperties().isVisible() && iCompound->NumChildren()==0 && m_trajToTrackMap)
00159 {
00160 TrajTrackAssociationCollection::const_iterator it = m_trajToTrackMap->begin();
00161 std::advance(it, iId.index());
00162 buildTrack(it, (TEveCompound*)iCompound);
00163 returnValue=true;
00164 }
00165 return returnValue;
00166 }
00167
00168 REGISTER_FWPROXYBUILDER(FWTrackProxyBuilderFF, reco::TrackCollection, "TracksFF", FWViewType::kAll3DBits | FWViewType::kAllRPZBits);
00169
00170