CMS 3D CMS Logo

QuickTrackAssociatorByHitsProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SimTracker/TrackAssociatorProducers
4 // Class: QuickTrackAssociatorByHitsProducer
5 //
13 //
14 // Original Author: Christopher Jones
15 // Created: Mon, 05 Jan 2015 16:33:55 GMT
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
32 
36 
37 //
38 // class declaration
39 //
40 namespace {
41 }
42 
44  public:
47 
48  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
49 
50  private:
51  virtual void beginJob() override;
52  virtual void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
53  virtual void endJob() override;
55 
56  // ----------member data ---------------------------
62  double cutRecoToSim_;
67 
68 };
69 
70 //
71 // constants, enums and typedefs
72 //
73 
74 
75 //
76 // static data member definitions
77 //
78 
79 //
80 // constructors and destructor
81 //
84  qualitySimToReco_( iConfig.getParameter<double>( "Quality_SimToReco" ) ),
85  puritySimToReco_( iConfig.getParameter<double>( "Purity_SimToReco" ) ),
86  pixelHitWeight_( iConfig.getParameter<double>( "PixelHitWeight" ) ),
87  cutRecoToSim_( iConfig.getParameter<double>( "Cut_RecoToSim" ) ),
88  threeHitTracksAreSpecial_( iConfig.getParameter<bool>( "ThreeHitTracksAreSpecial" ) ),
89  useClusterTPAssociation_( iConfig.getParameter<bool>( "useClusterTPAssociation" ) ),
90  absoluteNumberOfHits_( iConfig.getParameter<bool>( "AbsoluteNumberOfHits" ) )
91 {
92 
93  //
94  // Check whether the denominator when working out the percentage of shared hits should
95  // be the number of simulated hits or the number of reconstructed hits.
96  //
97  std::string denominatorString=iConfig.getParameter<std::string>("SimToRecoDenominator");
99  else if( denominatorString=="reco" ) simToRecoDenominator_=QuickTrackAssociatorByHitsImpl::denomreco;
100  else throw cms::Exception( "QuickTrackAssociatorByHitsImpl" ) << "SimToRecoDenominator not specified as sim or reco";
101 
102  //
103  // Do some checks on whether UseGrouped or UseSplitting have been set. They're not used
104  // unlike the standard TrackAssociatorByHits so show a warning.
105  //
106  bool useGrouped, useSplitting;
107  if( iConfig.exists("UseGrouped") ) useGrouped=iConfig.getParameter<bool>("UseGrouped");
108  else useGrouped=true;
109 
110  if( iConfig.exists("UseSplitting") ) useSplitting=iConfig.getParameter<bool>("UseSplitting");
111  else useSplitting=true;
112 
113  // This associator works as though both UseGrouped and UseSplitting were set to true, so show a
114  // warning if this isn't the case.
115  if( !(useGrouped && useSplitting) )
116  {
117  LogDebug("QuickTrackAssociatorByHitsImpl") << "UseGrouped and/or UseSplitting has been set to false, but this associator ignores that setting.";
118  }
119 
120  //register your products
121  produces<reco::TrackToTrackingParticleAssociator>();
122 
124  cluster2TPToken_ = consumes<ClusterTPAssociation>(iConfig.getParameter < edm::InputTag > ("cluster2TPSrc"));
125  }
126 
127 }
128 
129 
131 {
132 
133  // do anything here that needs to be done at desctruction time
134  // (e.g. close files, deallocate resources etc.)
135 
136 }
137 
138 
139 //
140 // member functions
141 //
142 
143 // Set up the parameter set for the hit associator
146  edm::ParameterSet hitAssociatorParameters;
147  hitAssociatorParameters.addParameter<bool>( "associatePixel", iConfig.getParameter<bool>("associatePixel") );
148  hitAssociatorParameters.addParameter<bool>( "associateStrip", iConfig.getParameter<bool>("associateStrip") );
149  // This is the important one, it stops the hit associator searching through the list of sim hits.
150  // I only want to use the hit associator methods that work on the hit IDs (i.e. the uint32_t trackId
151  // and the EncodedEventId eventId) so I'm not interested in matching that to the PSimHit objects.
152  hitAssociatorParameters.addParameter<bool>("associateRecoTracks",true);
153  // add these new ones to allow redirection of inputs:
154  hitAssociatorParameters.addParameter<edm::InputTag>( "pixelSimLinkSrc", iConfig.getParameter<edm::InputTag>("pixelSimLinkSrc") );
155  hitAssociatorParameters.addParameter<edm::InputTag>( "stripSimLinkSrc", iConfig.getParameter<edm::InputTag>("stripSimLinkSrc") );
156 
157  return hitAssociatorParameters;
158 }
159 
160 // ------------ method called to produce the data ------------
161 void
163 {
164  using namespace edm;
165 
166  const ClusterTPAssociation *clusterAssoc = nullptr;
167  std::unique_ptr<TrackerHitAssociator> trackAssoc;
169  edm::Handle<ClusterTPAssociation> clusterAssocHandle;
170  iEvent.getByToken(cluster2TPToken_,clusterAssocHandle);
171  clusterAssoc = clusterAssocHandle.product();
172  }
173  else {
174  // If control got this far then either useClusterTPAssociation_ was false or getting the cluster
175  // to TrackingParticle association from the event failed. Either way I need to create a hit associator.
176  trackAssoc = std::make_unique<TrackerHitAssociator>(iEvent, trackerHitAssociatorConfig_);
177  }
178 
179  auto impl = std::make_unique<QuickTrackAssociatorByHitsImpl>(iEvent.productGetter(),
180  std::move(trackAssoc),
181  clusterAssoc,
189 
190  auto toPut = std::make_unique<reco::TrackToTrackingParticleAssociator>(std::move(impl));
191  iEvent.put(std::move(toPut));
192 }
193 
194 // ------------ method called once each job just before starting event loop ------------
195 void
197 {
198 }
199 
200 // ------------ method called once each job just after ending the event loop ------------
201 void
203 }
204 
205 
206 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
207 void
209  //The following says we do not know what parameters are allowed so do no validation
210  // Please change this to state exactly what you do use, even if it is no parameters
212  desc.setUnknown();
213  descriptions.addDefault(desc);
214 }
215 
216 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
EDProductGetter const & productGetter() const
Definition: Event.cc:56
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::ParameterSet makeHitAssociatorParameters(const edm::ParameterSet &)
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
QuickTrackAssociatorByHitsImpl::SimToRecoDenomType simToRecoDenominator_
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< ClusterTPAssociation > cluster2TPToken_
HLT enums.
def move(src, dest)
Definition: eostools.py:510