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
edm::StreamID
Definition: StreamID.h:30
electrons_cff.bool
bool
Definition: electrons_cff.py:372
edm::Handle::product
T const * product() const
Definition: Handle.h:70
QuickTrackAssociatorByHitsImpl.h
edm::EDGetTokenT< ClusterTPAssociation >
edm
HLT enums.
Definition: AlignableModifier.h:19
QuickTrackAssociatorByHitsProducer::absoluteNumberOfHits_
bool absoluteNumberOfHits_
Definition: QuickTrackAssociatorByHitsProducer.cc:64
QuickTrackAssociatorByHitsProducer::useClusterTPAssociation_
bool useClusterTPAssociation_
Definition: QuickTrackAssociatorByHitsProducer.cc:63
ClusterTPAssociation
Definition: ClusterTPAssociation.h:21
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
QuickTrackAssociatorByHitsProducer::makeHitAssociatorParameters
edm::ParameterSet makeHitAssociatorParameters(const edm::ParameterSet &)
Definition: QuickTrackAssociatorByHitsProducer.cc:141
edm::EDConsumerBase::consumesCollector
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
Definition: EDConsumerBase.cc:71
TrackerHitAssociator.h
TrackerHitAssociator::Config
Definition: TrackerHitAssociator.h:57
QuickTrackAssociatorByHitsProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: QuickTrackAssociatorByHitsProducer.cc:198
edm::Handle
Definition: AssociativeIterator.h:50
QuickTrackAssociatorByHitsProducer::QuickTrackAssociatorByHitsProducer
QuickTrackAssociatorByHitsProducer(const edm::ParameterSet &)
Definition: QuickTrackAssociatorByHitsProducer.cc:78
MakerMacros.h
QuickTrackAssociatorByHitsProducer::threeHitTracksAreSpecial_
bool threeHitTracksAreSpecial_
Definition: QuickTrackAssociatorByHitsProducer.cc:62
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
QuickTrackAssociatorByHitsImpl::SimToRecoDenomType
SimToRecoDenomType
Definition: QuickTrackAssociatorByHitsImpl.h:68
QuickTrackAssociatorByHitsProducer::endJob
void endJob() override
Definition: QuickTrackAssociatorByHitsProducer.cc:195
QuickTrackAssociatorByHitsImpl::denomsim
Definition: QuickTrackAssociatorByHitsImpl.h:68
QuickTrackAssociatorByHitsProducer::puritySimToReco_
double puritySimToReco_
Definition: QuickTrackAssociatorByHitsProducer.cc:58
EDGetToken.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
QuickTrackAssociatorByHitsProducer::cutRecoToSim_
double cutRecoToSim_
Definition: QuickTrackAssociatorByHitsProducer.cc:60
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:674
TrackToTrackingParticleAssociator.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
QuickTrackAssociatorByHitsImpl::denomreco
Definition: QuickTrackAssociatorByHitsImpl.h:68
Event.h
edm::ParameterSet::addParameter
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:124
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::ParameterSetDescription::setUnknown
void setUnknown()
Definition: ParameterSetDescription.cc:39
QuickTrackAssociatorByHitsProducer::beginJob
void beginJob() override
Definition: QuickTrackAssociatorByHitsProducer.cc:192
edm::EventSetup
Definition: EventSetup.h:57
DBConfiguration_cff.toPut
toPut
Definition: DBConfiguration_cff.py:25
QuickTrackAssociatorByHitsProducer
Definition: QuickTrackAssociatorByHitsProducer.cc:41
QuickTrackAssociatorByHitsProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: QuickTrackAssociatorByHitsProducer.cc:159
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
QuickTrackAssociatorByHitsProducer::trackerHitAssociatorConfig_
TrackerHitAssociator::Config trackerHitAssociatorConfig_
Definition: QuickTrackAssociatorByHitsProducer.cc:55
impl
Definition: trackAlgoPriorityOrder.h:18
eostools.move
def move(src, dest)
Definition: eostools.py:511
QuickTrackAssociatorByHitsProducer::~QuickTrackAssociatorByHitsProducer
~QuickTrackAssociatorByHitsProducer() override
Definition: QuickTrackAssociatorByHitsProducer.cc:131
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
QuickTrackAssociatorByHitsProducer::simToRecoDenominator_
QuickTrackAssociatorByHitsImpl::SimToRecoDenomType simToRecoDenominator_
Definition: QuickTrackAssociatorByHitsProducer.cc:61
QuickTrackAssociatorByHitsProducer::cluster2TPToken_
edm::EDGetTokenT< ClusterTPAssociation > cluster2TPToken_
Definition: QuickTrackAssociatorByHitsProducer.cc:56
ParameterSet.h
EDProducer.h
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
edm::InputTag
Definition: InputTag.h:15
QuickTrackAssociatorByHitsProducer::pixelHitWeight_
double pixelHitWeight_
Definition: QuickTrackAssociatorByHitsProducer.cc:59
helper.Config
Config
Definition: helper.py:10
QuickTrackAssociatorByHitsProducer::qualitySimToReco_
double qualitySimToReco_
Definition: QuickTrackAssociatorByHitsProducer.cc:57