CMS 3D CMS Logo

Skim_ReduceHcalRecHitCollectionProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ReduceHcalRecHitCollectionProducer
4 // Class: ReduceHcalRecHitCollectionProducer
5 //
6 /*\class ReduceHcalRecHitCollectionProducer ReduceHcalRecHitCollectionProducer.cc
7 
8  Description: [one line class summary]
9 
10  Implementation:
11  [Notes on implementation]
12 */
13 //
14 // Original Author: Jie Chen
15 // Created: Mon Apr 12 16:41:46 CDT 2010
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
31 
32 
37 
41 
50 
54 
58 
59 #include <iostream>
60 
61 //
62 // class declaration
63 //
64 
66  public:
69  void produce(edm::Event&, const edm::EventSetup&) override;
70  private:
76  double ptcut_;
77  // ----------member data ---------------------------
78 };
79 
80 //
81 // constants, enums and typedefs
82 //
83 
84 
85 //
86 // static data member definitions
87 //
88 
89 //
90 // constructors and destructor
91 //
93 {
94  recHitsToken_ = consumes<HBHERecHitCollection>(iConfig.getParameter< edm::InputTag > ("recHitsLabel"));
95 
96  reducedHitsCollection_ = iConfig.getParameter<std::string>("reducedHitsCollection");
97 
98  //register your products
99  produces< HBHERecHitCollection > (reducedHitsCollection_) ;
100 
101  inputCollectionToken_ = consumes<reco::TrackCollection>(iConfig.getParameter< edm::InputTag >("inputCollection"));
102  ptcut_= iConfig.getParameter< double >("TrackPt");
103 
104  produces< DetIdCollection >() ;
105  // TrackAssociator parameters
106  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
108  parameters_.loadParameters( parameters, iC );
110 
111 }
112 
113 
115 {
116 
117  // do anything here that needs to be done at desctruction time
118  // (e.g. close files, deallocate resources etc.)
119 
120 }
121 
122 
123 //
124 // member functions
125 //
126 
127 // ------------ method called to produce the data ------------
128 void
130 {
131  using namespace edm;
132 
133  using namespace std;
134 
135  using reco::TrackCollection;
136 
137  Handle<HBHERecHitCollection> recHitsHandle;
138  iEvent.getByToken(recHitsToken_,recHitsHandle);
139  if( !recHitsHandle.isValid() )
140  {
141  edm::LogError("ReduceHcalRecHitCollectionProducer") << "RecHit collection not found";
142  return;
143  }
144 
145  //Create empty output collections
146  std::unique_ptr< HBHERecHitCollection > miniRecHitCollection (new HBHERecHitCollection) ;
147 
148 //loop through tracks.
149  Handle<TrackCollection> tkTracks;
150  iEvent.getByToken(inputCollectionToken_,tkTracks);
151  std::unique_ptr< DetIdCollection > interestingDetIdCollection( new DetIdCollection() ) ;
152  for(TrackCollection::const_iterator itTrack = tkTracks->begin();
153  itTrack != tkTracks->end();
154  ++itTrack) {
155  if(itTrack->pt()>ptcut_){
156 
158 
159  if(!info.crossedHcalIds.empty()){
160  //loop through hits in the cone
161  for(std::vector<const HBHERecHit*>::const_iterator hit = info.hcalRecHits.begin();
162  hit != info.hcalRecHits.end(); ++hit)
163  {
164  DetId hitid=(*hit)->id();
165  HBHERecHitCollection::const_iterator iRecHit = recHitsHandle->find(hitid);
166  if ( (iRecHit != recHitsHandle->end()) && (miniRecHitCollection->find(hitid) == miniRecHitCollection->end()) )
167  miniRecHitCollection->push_back(*iRecHit);
168  }
169 
170 
171  }
172  }
173  }
174 
175  iEvent.put(std::move(miniRecHitCollection),reducedHitsCollection_ );
176 
177 
178 
179 }
180 //define this as a plug-in
T getParameter(std::string const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
edm::EDGetTokenT< HBHERecHitCollection > recHitsToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void useDefaultPropagator()
use the default propagator
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
std::vector< HBHERecHit >::const_iterator const_iterator
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
std::vector< DetId > crossedHcalIds
int iEvent
Definition: GenABIO.cc:230
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< const HBHERecHit * > hcalRecHits
bool isValid() const
Definition: HandleBase.h:74
const_iterator end() const
Definition: DetId.h:18
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< reco::TrackCollection > inputCollectionToken_
iterator find(key_type k)
HLT enums.
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
edm::EDCollection< DetId > DetIdCollection
def move(src, dest)
Definition: eostools.py:510