Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-03 04:10:01

0001 #include "Fireworks/Core/interface/FWSimpleProxyBuilderTemplate.h"
0002 #include "Fireworks/Core/interface/FWProxyBuilderBase.h"
0003 #include "Fireworks/Core/interface/Context.h"
0004 #include "Fireworks/Core/interface/FWEventItem.h"
0005 #include "Fireworks/Core/interface/FWGeometry.h"
0006 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
0007 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
0008 #include "SimGeneral/TrackingAnalysis/interface/SimHitTPAssociationProducer.h"
0009 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0010 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0011 
0012 #include "DataFormats/DetId/interface/DetId.h"
0013 
0014 #include "FWCore/Framework/interface/ESHandle.h"
0015 #include "FWCore/Common/interface/EventBase.h"
0016 #include "DataFormats/DetId/interface/DetId.h"
0017 
0018 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0019 #include "Fireworks/Core/interface/FWParameters.h"
0020 
0021 #include "TEveTrack.h"
0022 #include "TEveCompound.h"
0023 #include "TEveManager.h"
0024 #include "TEveBrowser.h"
0025 #include "TEveTrackPropagator.h"
0026 
0027 class FWTrackingParticleProxyBuilderFullFramework : public FWSimpleProxyBuilderTemplate<TrackingParticle> {
0028 public:
0029   FWTrackingParticleProxyBuilderFullFramework(void) : m_assocList(nullptr) {}
0030   ~FWTrackingParticleProxyBuilderFullFramework(void) override {}
0031 
0032   // virtual void setItem(const FWEventItem* iItem) override;
0033 
0034   REGISTER_PROXYBUILDER_METHODS();
0035 
0036   FWTrackingParticleProxyBuilderFullFramework(const FWTrackingParticleProxyBuilderFullFramework&) = delete;
0037   const FWTrackingParticleProxyBuilderFullFramework& operator=(const FWTrackingParticleProxyBuilderFullFramework&) =
0038       delete;
0039 
0040 private:
0041   using FWSimpleProxyBuilderTemplate<TrackingParticle>::build;
0042   void build(const FWEventItem* iItem, TEveElementList* product, const FWViewContext*) override;
0043 
0044   void build(const TrackingParticle& iData,
0045              unsigned int iIndex,
0046              TEveElement& oItemHolder,
0047              const FWViewContext*) override;
0048 
0049   edm::Handle<TrackingParticleCollection> tpch;
0050   const SimHitTPAssociationProducer::SimHitTPAssociationList* m_assocList;
0051 };
0052 
0053 //______________________________________________________________________________
0054 
0055 /*
0056   void FWTrackingParticleProxyBuilderFullFramework::setItem(const FWEventItem* iItem)
0057   {
0058   printf("set item\n");
0059   FWProxyBuilderBase::setItem(iItem);
0060   }
0061 */
0062 //______________________________________________________________________________
0063 void FWTrackingParticleProxyBuilderFullFramework::build(const FWEventItem* iItem,
0064                                                         TEveElementList* product,
0065                                                         const FWViewContext*) {
0066   // setup event handles amd call function from parent class
0067 
0068   const edm::Event* event = (const edm::Event*)item()->getEvent();
0069   if (event) {
0070     // get collection handle
0071     edm::InputTag coltag(item()->moduleLabel(), item()->productInstanceLabel(), item()->processName());
0072     event->getByLabel(coltag, tpch);
0073 
0074     // AMT todo: check if there is any other way getting the list other than this
0075     //           ifnot, set proces name as a configurable parameter
0076     edm::Handle<SimHitTPAssociationProducer::SimHitTPAssociationList> simHitsTPAssoc;
0077     try {
0078       event->getByLabel("xxx", simHitsTPAssoc);
0079       m_assocList = &*simHitsTPAssoc;
0080     } catch (const std::exception& e) {
0081       std::cerr << " FWTrackingParticleProxyBuilderFullFramework::setItem() Can't get hits association list "
0082                 << e.what() << std::endl;
0083     }
0084     /*
0085       // debug propagator
0086       gEve->GetBrowser()->MapWindow();
0087       gEve->AddToListTree(context().getTrackPropagator(), true);
0088       context().getTrackPropagator()->SetRnrReferences(true);
0089       */
0090   }
0091   FWSimpleProxyBuilder::build(iItem, product, nullptr);
0092 }
0093 //______________________________________________________________________________
0094 void FWTrackingParticleProxyBuilderFullFramework::build(const TrackingParticle& iData,
0095                                                         unsigned int tpIdx,
0096                                                         TEveElement& comp,
0097                                                         const FWViewContext*) {
0098   TEveRecTrack t;
0099   t.fBeta = 1.0;
0100   t.fP = TEveVector(iData.px(), iData.py(), iData.pz());
0101   t.fV = TEveVector(iData.vx(), iData.vy(), iData.vz());
0102   t.fSign = iData.charge();
0103 
0104   TEveTrack* track = new TEveTrack(&t, context().getTrackPropagator());
0105   if (t.fSign == 0)
0106     track->SetLineStyle(7);
0107 
0108   track->MakeTrack();
0109   setupAddElement(track, &comp);
0110   // printf("add track %d \n", tpIdx);
0111 
0112   if (m_assocList) {
0113     TEvePointSet* pointSet = new TEvePointSet;
0114     setupAddElement(pointSet, &comp);
0115 
0116     const FWGeometry* geom = item()->getGeom();
0117     float local[3];
0118     float localDir[3];
0119     float global[3] = {0.0, 0.0, 0.0};
0120     float globalDir[3] = {0.0, 0.0, 0.0};
0121 
0122     TrackingParticleRef tpr(tpch, tpIdx);
0123     std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(tpr, TrackPSimHitRef());
0124     auto range = std::equal_range(m_assocList->begin(),
0125                                   m_assocList->end(),
0126                                   clusterTPpairWithDummyTP,
0127                                   SimHitTPAssociationProducer::simHitTPAssociationListGreater);
0128     // printf("TrackingParticle[%d] P(%.1f, %.1f, %.1f) matches %d hits\n", tpIdx,iData.px(), iData.py(), iData.pz() ,(int)(range.second-range.first ));
0129 
0130     std::vector<const PSimHit*> phits;
0131     for (auto ri = range.first; ri != range.second; ++ri)
0132       phits.push_back(ri->second.get());
0133 
0134     std::sort(phits.begin(), phits.end(), [](const PSimHit* a, const PSimHit* b) { return a->tof() < b->tof(); });
0135     for (auto phi = phits.begin(); phi != phits.end(); ++phi) {
0136       const PSimHit* phit = *phi;
0137 
0138       local[0] = phit->localPosition().x();
0139       local[1] = phit->localPosition().y();
0140       local[2] = phit->localPosition().z();
0141 
0142       localDir[0] = phit->momentumAtEntry().x();
0143       localDir[1] = phit->momentumAtEntry().y();
0144       localDir[2] = phit->momentumAtEntry().z();
0145 
0146       geom->localToGlobal(phit->detUnitId(), local, global);
0147       geom->localToGlobal(phit->detUnitId(), localDir, globalDir, false);
0148       pointSet->SetNextPoint(global[0], global[1], global[2]);
0149 
0150       //printf("localP = (%f, %f, %f) globalP = (%f, %f, %f), loss = %f, tof =%f\n", localDir[0], localDir[1], localDir[2],
0151       //       globalDir[0], globalDir[1], globalDir[2],
0152       //       phit->energyLoss(), phit->tof());
0153       track->AddPathMark(TEvePathMark(TEvePathMark::kReference,
0154                                       TEveVector(global[0], global[1], global[2]),
0155                                       TEveVector(globalDir[0], globalDir[1], globalDir[2])));
0156     }
0157   }
0158 }
0159 
0160 REGISTER_FWPROXYBUILDER(FWTrackingParticleProxyBuilderFullFramework,
0161                         TrackingParticle,
0162                         "TrackingParticleWithPSimHits",
0163                         FWViewType::kAll3DBits | FWViewType::kAllRPZBits);