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 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
31 
35 
36 //
37 // class declaration
38 //
39 namespace {}
40 
42 public:
45 
46  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
47 
48 private:
49  void beginJob() override;
50  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
51  void endJob() override;
53 
54  // ----------member data ---------------------------
60  double cutRecoToSim_;
65 };
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 //
72 // static data member definitions
73 //
74 
75 //
76 // constructors and destructor
77 //
79  : qualitySimToReco_(iConfig.getParameter<double>("Quality_SimToReco")),
80  puritySimToReco_(iConfig.getParameter<double>("Purity_SimToReco")),
81  pixelHitWeight_(iConfig.getParameter<double>("PixelHitWeight")),
82  cutRecoToSim_(iConfig.getParameter<double>("Cut_RecoToSim")),
83  threeHitTracksAreSpecial_(iConfig.getParameter<bool>("ThreeHitTracksAreSpecial")),
84  useClusterTPAssociation_(iConfig.getParameter<bool>("useClusterTPAssociation")),
85  absoluteNumberOfHits_(iConfig.getParameter<bool>("AbsoluteNumberOfHits")) {
86  //
87  // Check whether the denominator when working out the percentage of shared hits should
88  // be the number of simulated hits or the number of reconstructed hits.
89  //
90  std::string denominatorString = iConfig.getParameter<std::string>("SimToRecoDenominator");
91  if (denominatorString == "sim")
93  else if (denominatorString == "reco")
95  else
96  throw cms::Exception("QuickTrackAssociatorByHitsImpl") << "SimToRecoDenominator not specified as sim or reco";
97 
98  //
99  // Do some checks on whether UseGrouped or UseSplitting have been set. They're not used
100  // unlike the standard TrackAssociatorByHits so show a warning.
101  //
102  bool useGrouped, useSplitting;
103  if (iConfig.exists("UseGrouped"))
104  useGrouped = iConfig.getParameter<bool>("UseGrouped");
105  else
106  useGrouped = true;
107 
108  if (iConfig.exists("UseSplitting"))
109  useSplitting = iConfig.getParameter<bool>("UseSplitting");
110  else
111  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  LogDebug("QuickTrackAssociatorByHitsImpl")
117  << "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  } else {
128  }
129 }
130 
132  // do anything here that needs to be done at desctruction time
133  // (e.g. close files, deallocate resources etc.)
134 }
135 
136 //
137 // member functions
138 //
139 
140 // Set up the parameter set for the hit associator
142  edm::ParameterSet hitAssociatorParameters;
143  hitAssociatorParameters.addParameter<bool>("associatePixel", iConfig.getParameter<bool>("associatePixel"));
144  hitAssociatorParameters.addParameter<bool>("associateStrip", iConfig.getParameter<bool>("associateStrip"));
145  // This is the important one, it stops the hit associator searching through the list of sim hits.
146  // I only want to use the hit associator methods that work on the hit IDs (i.e. the uint32_t trackId
147  // and the EncodedEventId eventId) so I'm not interested in matching that to the PSimHit objects.
148  hitAssociatorParameters.addParameter<bool>("associateRecoTracks", true);
149  // add these new ones to allow redirection of inputs:
150  hitAssociatorParameters.addParameter<edm::InputTag>("pixelSimLinkSrc",
151  iConfig.getParameter<edm::InputTag>("pixelSimLinkSrc"));
152  hitAssociatorParameters.addParameter<edm::InputTag>("stripSimLinkSrc",
153  iConfig.getParameter<edm::InputTag>("stripSimLinkSrc"));
154 
155  return hitAssociatorParameters;
156 }
157 
158 // ------------ method called to produce the data ------------
161  const edm::EventSetup& iSetup) const {
162  using namespace edm;
163 
164  const ClusterTPAssociation* clusterAssoc = nullptr;
165  std::unique_ptr<TrackerHitAssociator> trackAssoc;
167  edm::Handle<ClusterTPAssociation> clusterAssocHandle;
168  iEvent.getByToken(cluster2TPToken_, clusterAssocHandle);
169  clusterAssoc = clusterAssocHandle.product();
170  } else {
171  // If control got this far then either useClusterTPAssociation_ was false or getting the cluster
172  // to TrackingParticle association from the event failed. Either way I need to create a hit associator.
173  trackAssoc = std::make_unique<TrackerHitAssociator>(iEvent, trackerHitAssociatorConfig_);
174  }
175 
176  auto impl = std::make_unique<QuickTrackAssociatorByHitsImpl>(iEvent.productGetter(),
177  std::move(trackAssoc),
178  clusterAssoc,
186 
187  auto toPut = std::make_unique<reco::TrackToTrackingParticleAssociator>(std::move(impl));
188  iEvent.put(std::move(toPut));
189 }
190 
191 // ------------ method called once each job just before starting event loop ------------
193 
194 // ------------ method called once each job just after ending the event loop ------------
196 
197 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
199  //The following says we do not know what parameters are allowed so do no validation
200  // Please change this to state exactly what you do use, even if it is no parameters
202  desc.setUnknown();
203  descriptions.addDefault(desc);
204 }
205 
206 //define this as a plug-in
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
bool exists(std::string const &parameterName) const
checks if a parameter exists
T const * product() const
Definition: Handle.h:70
edm::ParameterSet makeHitAssociatorParameters(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
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:136
Config
Definition: helper.py:10
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
QuickTrackAssociatorByHitsImpl::SimToRecoDenomType simToRecoDenominator_
edm::EDGetTokenT< ClusterTPAssociation > cluster2TPToken_
HLT enums.
def move(src, dest)
Definition: eostools.py:511
#define LogDebug(id)