Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:07

0001 // -*- C++ -*-
0002 //
0003 // Package:    TrackCandidateTopBottomHitFilter
0004 // Class:      TrackCandidateTopBottomHitFilter
0005 //
0006 /**\class TrackCandidateTopBottomHitFilter TrackCandidateTopBottomHitFilter.cc Cruzet/TrackCandidateTopBottomHitFilter/src/TrackCandidateTopBottomHitFilter.cc
0007 
0008 Description: <one line class summary>
0009 
0010 Implementation:
0011 <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Giuseppe Cerati
0015 //         Created:  Tue Sep  9 09:47:01 CEST 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 #include "FWCore/Framework/interface/ESHandle.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "FWCore/Utilities/interface/InputTag.h"
0032 #include "FWCore/Utilities/interface/ESGetToken.h"
0033 
0034 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
0035 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0036 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0037 
0038 //
0039 // class decleration
0040 //
0041 
0042 class dso_hidden TrackCandidateTopBottomHitFilter final : public edm::stream::EDProducer<> {
0043 public:
0044   explicit TrackCandidateTopBottomHitFilter(const edm::ParameterSet&);
0045   ~TrackCandidateTopBottomHitFilter() override;
0046 
0047 private:
0048   void beginRun(edm::Run const& run, const edm::EventSetup&) override;
0049   void produce(edm::Event&, const edm::EventSetup&) override;
0050   edm::EDGetTokenT<TrackCandidateCollection> label;
0051   edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0052   edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> trackBuilderToken;
0053   std::string builderName;
0054   double seedY;
0055 };
0056 
0057 TrackCandidateTopBottomHitFilter::TrackCandidateTopBottomHitFilter(const edm::ParameterSet& iConfig) {
0058   builderName = iConfig.getParameter<std::string>("TTRHBuilder");
0059   label = consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("Input"));
0060   seedY = iConfig.getParameter<double>("SeedY");
0061   trackBuilderToken = esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord, edm::Transition::BeginRun>(
0062       edm::ESInputTag("", builderName));
0063 
0064   produces<TrackCandidateCollection>();
0065 }
0066 
0067 TrackCandidateTopBottomHitFilter::~TrackCandidateTopBottomHitFilter() {}
0068 
0069 //
0070 // member functions
0071 //
0072 
0073 // ------------ method called to produce the data  ------------
0074 void TrackCandidateTopBottomHitFilter::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0075   using namespace edm;
0076   using namespace std;
0077 
0078   Handle<TrackCandidateCollection> pIn;
0079   iEvent.getByToken(label, pIn);
0080   auto pOut = std::make_unique<TrackCandidateCollection>();
0081   for (TrackCandidateCollection::const_iterator it = pIn->begin(); it != pIn->end(); ++it) {
0082     PTrajectoryStateOnDet state = it->trajectoryStateOnDet();
0083     TrajectorySeed seed = it->seed();
0084     TrackCandidate::RecHitContainer hits;
0085     for (auto const& hit : it->recHits()) {
0086       if (hit.isValid()) {
0087         double hitY = theBuilder->build(&hit)->globalPosition().y();
0088         if (seedY * hitY > 0)
0089           hits.push_back(hit.clone());
0090         else
0091           break;
0092       } else
0093         hits.push_back(hit.clone());
0094     }
0095     if (hits.size() >= 3) {
0096       TrackCandidate newTC(hits, seed, state);
0097       pOut->push_back(newTC);
0098     }
0099   }
0100   iEvent.put(std::move(pOut));
0101 }
0102 
0103 void TrackCandidateTopBottomHitFilter::beginRun(edm::Run const& run, const edm::EventSetup& iSetup) {
0104   theBuilder = iSetup.getHandle(trackBuilderToken);
0105 }
0106 
0107 //define this as a plug-in
0108 DEFINE_FWK_MODULE(TrackCandidateTopBottomHitFilter);