Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:45

0001 // -*- C++ -*-
0002 //
0003 // Package:     Tracks
0004 // Class  :     FWTrackProxyBuilder
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Nov 25 14:42:13 EST 2008
0011 //
0012 
0013 // system include files
0014 #include "TEveManager.h"
0015 #include "TEveBrowser.h"
0016 #include "TEveTrack.h"
0017 #include "TEvePointSet.h"
0018 #include "TEveCompound.h"
0019 
0020 // user include files
0021 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0022 #include "Fireworks/Core/interface/FWEventItem.h"
0023 #include "Fireworks/Core/interface/FWMagField.h"
0024 
0025 #include "DataFormats/TrackReco/interface/Track.h"
0026 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0027 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0028 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0029 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0030 #include "FWCore/Framework/interface/ESHandle.h"
0031 #include "FWCore/Common/interface/EventBase.h"
0032 
0033 class FWTrackProxyBuilderFullFramework : public FWProxyBuilderBase {
0034 public:
0035   FWTrackProxyBuilderFullFramework();
0036   ~FWTrackProxyBuilderFullFramework() override;
0037 
0038   REGISTER_PROXYBUILDER_METHODS();
0039 
0040   void setItem(const FWEventItem* iItem) override;
0041   bool visibilityModelChanges(const FWModelId&, TEveElement*, FWViewType::EType, const FWViewContext*) override;
0042 
0043   FWTrackProxyBuilderFullFramework(const FWTrackProxyBuilderFullFramework&) = delete;                   // stop default
0044   const FWTrackProxyBuilderFullFramework& operator=(const FWTrackProxyBuilderFullFramework&) = delete;  // stop default
0045 
0046 private:
0047   void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
0048   void buildTrack(TrajTrackAssociationCollection::const_iterator it, TEveCompound* comp);
0049 
0050   TEveTrackPropagator* m_trackerPropagator;
0051   const TrajTrackAssociationCollection* m_trajToTrackMap;
0052 };
0053 
0054 FWTrackProxyBuilderFullFramework::FWTrackProxyBuilderFullFramework()
0055     : m_trackerPropagator(nullptr), m_trajToTrackMap(nullptr) {
0056   m_trackerPropagator = new TEveTrackPropagator();
0057   m_trackerPropagator->SetStepper(TEveTrackPropagator::kRungeKutta);
0058   m_trackerPropagator->SetDelta(0.01);
0059   m_trackerPropagator->SetMaxOrbs(0.7);
0060   m_trackerPropagator->IncDenyDestroy();
0061 }
0062 
0063 FWTrackProxyBuilderFullFramework::~FWTrackProxyBuilderFullFramework() { m_trackerPropagator->DecDenyDestroy(); }
0064 
0065 void FWTrackProxyBuilderFullFramework::setItem(const FWEventItem* iItem) {
0066   FWProxyBuilderBase::setItem(iItem);
0067   if (iItem) {
0068     m_trackerPropagator->SetMagFieldObj(context().getField(), false);
0069     iItem->getConfig()->assertParam("Rnr TrajectoryMeasurement", false);
0070   }
0071 }
0072 
0073 void FWTrackProxyBuilderFullFramework::build(const FWEventItem* iItem,
0074                                              TEveElementList* product,
0075                                              const FWViewContext* vc) {
0076   const reco::TrackCollection* tracks = nullptr;
0077   iItem->get(tracks);
0078   if (tracks == nullptr)
0079     return;
0080 
0081   try {
0082     const edm::EventBase* event = item()->getEvent();
0083     edm::InputTag tag(item()->moduleLabel(), item()->productInstanceLabel(), item()->processName());
0084     edm::Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
0085     event->getByLabel(tag, trajTrackAssociationHandle);
0086     m_trajToTrackMap = &*trajTrackAssociationHandle;
0087   } catch (cms::Exception& exception) {
0088     m_trajToTrackMap = nullptr;
0089     std::cout << exception.what() << std::endl;
0090   }
0091 
0092   if (m_trajToTrackMap) {
0093     bool rnrPathMarks = item()->getConfig()->value<bool>("Rnr TrajectoryMeasurement");
0094     if (m_trackerPropagator->GetRnrReferences() != rnrPathMarks)
0095       m_trackerPropagator->SetRnrReferences(rnrPathMarks);
0096 
0097     unsigned track_index = 0;
0098     for (TrajTrackAssociationCollection::const_iterator it = m_trajToTrackMap->begin(); it != m_trajToTrackMap->end();
0099          ++it, ++track_index) {
0100       TEveCompound* comp = createCompound();
0101       setupAddElement(comp, product);
0102 
0103       if (item()->modelInfo(track_index).displayProperties().isVisible())
0104         buildTrack(it, comp);
0105     }
0106   } else {
0107     for (reco::TrackCollection::const_iterator i = tracks->begin(); i != tracks->end(); ++i) {
0108       const reco::Track& track = *i;
0109       TEveRecTrack ts;
0110       ts.fBeta = 1.;
0111       ts.fSign = track.charge();
0112       ts.fP.Set(track.px(), track.py(), track.pz());
0113       ts.fV.Set(track.vx(), track.vy(), track.vz());
0114       TEveTrack* eveTrack = new TEveTrack(&ts, m_trackerPropagator);
0115       eveTrack->MakeTrack();
0116       TEveCompound* comp = createCompound();
0117       setupAddElement(comp, product);
0118       setupAddElement(eveTrack, comp);
0119     }
0120   }
0121 
0122   gEve->GetBrowser()->MapWindow();
0123 }
0124 
0125 void FWTrackProxyBuilderFullFramework::buildTrack(TrajTrackAssociationCollection::const_iterator it,
0126                                                   TEveCompound* comp) {
0127   const reco::Track& track = *it->val;
0128   const Trajectory& traj = *it->key;
0129 
0130   TEveRecTrack ts;
0131   ts.fBeta = 1.;
0132   ts.fSign = track.charge();
0133   ts.fP.Set(track.px(), track.py(), track.pz());
0134   ts.fV.Set(track.vx(), track.vy(), track.vz());
0135   TEveTrack* eveTrack = new TEveTrack(&ts, m_trackerPropagator);
0136 
0137   // path-marks from a trajectory
0138   std::vector<TrajectoryMeasurement> measurements = traj.measurements();
0139   std::vector<TrajectoryMeasurement>::iterator measurements_it = measurements.begin();
0140   std::vector<TrajectoryMeasurement>::reverse_iterator measurements_rit = measurements.rbegin();
0141   for (size_t t = 0; t != measurements.size(); ++t, ++measurements_it, ++measurements_rit) {
0142     TrajectoryStateOnSurface trajState =
0143         (traj.direction() == alongMomentum) ? measurements_it->updatedState() : measurements_rit->updatedState();
0144 
0145     if (!trajState.isValid())
0146       continue;
0147 
0148     eveTrack->AddPathMark(TEvePathMark(
0149         TEvePathMark::kReference,
0150         TEveVector(trajState.globalPosition().x(), trajState.globalPosition().y(), trajState.globalPosition().z()),
0151         TEveVector(trajState.globalMomentum().x(), trajState.globalMomentum().y(), trajState.globalMomentum().z())));
0152   }
0153 
0154   eveTrack->MakeTrack();
0155   setupAddElement(eveTrack, comp);
0156 }
0157 
0158 bool FWTrackProxyBuilderFullFramework::visibilityModelChanges(const FWModelId& iId,
0159                                                               TEveElement* iCompound,
0160                                                               FWViewType::EType viewType,
0161                                                               const FWViewContext* vc) {
0162   const FWEventItem::ModelInfo& info = iId.item()->modelInfo(iId.index());
0163   bool returnValue = false;
0164   if (info.displayProperties().isVisible() && iCompound->NumChildren() == 0 && m_trajToTrackMap) {
0165     TrajTrackAssociationCollection::const_iterator it = m_trajToTrackMap->begin();
0166     std::advance(it, iId.index());
0167     buildTrack(it, (TEveCompound*)iCompound);
0168     returnValue = true;
0169   }
0170   return returnValue;
0171 }
0172 
0173 REGISTER_FWPROXYBUILDER(FWTrackProxyBuilderFullFramework,
0174                         reco::TrackCollection,
0175                         "TracksTrajectory",
0176                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);