CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ---------------------------
61  double cutRecoToSim_;
66 
67 };
68 
69 //
70 // constants, enums and typedefs
71 //
72 
73 
74 //
75 // static data member definitions
76 //
77 
78 //
79 // constructors and destructor
80 //
82  trackerHitAssociatorConfig_(makeHitAssociatorParameters(iConfig), consumesCollector()),
83  qualitySimToReco_( iConfig.getParameter<double>( "Quality_SimToReco" ) ),
84  puritySimToReco_( iConfig.getParameter<double>( "Purity_SimToReco" ) ),
85  cutRecoToSim_( iConfig.getParameter<double>( "Cut_RecoToSim" ) ),
86  threeHitTracksAreSpecial_( iConfig.getParameter<bool>( "ThreeHitTracksAreSpecial" ) ),
87  useClusterTPAssociation_( iConfig.getParameter<bool>( "useClusterTPAssociation" ) ),
88  absoluteNumberOfHits_( iConfig.getParameter<bool>( "AbsoluteNumberOfHits" ) )
89 {
90 
91  //
92  // Check whether the denominator when working out the percentage of shared hits should
93  // be the number of simulated hits or the number of reconstructed hits.
94  //
95  std::string denominatorString=iConfig.getParameter<std::string>("SimToRecoDenominator");
97  else if( denominatorString=="reco" ) simToRecoDenominator_=QuickTrackAssociatorByHitsImpl::denomreco;
98  else throw cms::Exception( "QuickTrackAssociatorByHitsImpl" ) << "SimToRecoDenominator not specified as sim or reco";
99 
100  //
101  // Do some checks on whether UseGrouped or UseSplitting have been set. They're not used
102  // unlike the standard TrackAssociatorByHits so show a warning.
103  //
104  bool useGrouped, useSplitting;
105  if( iConfig.exists("UseGrouped") ) useGrouped=iConfig.getParameter<bool>("UseGrouped");
106  else useGrouped=true;
107 
108  if( iConfig.exists("UseSplitting") ) useSplitting=iConfig.getParameter<bool>("UseSplitting");
109  else useSplitting=true;
110 
111  // This associator works as though both UseGrouped and UseSplitting were set to true, so show a
112  // warning if this isn't the case.
113  if( !(useGrouped && useSplitting) )
114  {
115  LogDebug("QuickTrackAssociatorByHitsImpl") << "UseGrouped and/or UseSplitting has been set to false, but this associator ignores that setting.";
116  }
117 
118  //register your products
119  produces<reco::TrackToTrackingParticleAssociator>();
120 
122  cluster2TPToken_ = consumes<ClusterTPAssociationList>(iConfig.getParameter < edm::InputTag > ("cluster2TPSrc"));
123  }
124 
125 }
126 
127 
129 {
130 
131  // do anything here that needs to be done at desctruction time
132  // (e.g. close files, deallocate resources etc.)
133 
134 }
135 
136 
137 //
138 // member functions
139 //
140 
141 // Set up the parameter set for the hit associator
144  edm::ParameterSet hitAssociatorParameters;
145  hitAssociatorParameters.addParameter<bool>( "associatePixel", iConfig.getParameter<bool>("associatePixel") );
146  hitAssociatorParameters.addParameter<bool>( "associateStrip", iConfig.getParameter<bool>("associateStrip") );
147  // This is the important one, it stops the hit associator searching through the list of sim hits.
148  // I only want to use the hit associator methods that work on the hit IDs (i.e. the uint32_t trackId
149  // and the EncodedEventId eventId) so I'm not interested in matching that to the PSimHit objects.
150  hitAssociatorParameters.addParameter<bool>("associateRecoTracks",true);
151  // add these new ones to allow redirection of inputs:
152  hitAssociatorParameters.addParameter<edm::InputTag>( "pixelSimLinkSrc", iConfig.getParameter<edm::InputTag>("pixelSimLinkSrc") );
153  hitAssociatorParameters.addParameter<edm::InputTag>( "stripSimLinkSrc", iConfig.getParameter<edm::InputTag>("stripSimLinkSrc") );
154 
155  return hitAssociatorParameters;
156 }
157 
158 // ------------ method called to produce the data ------------
159 void
161 {
162  using namespace edm;
163 
164  const ClusterTPAssociationList *clusterAssoc = nullptr;
165  std::unique_ptr<TrackerHitAssociator> trackAssoc;
167  edm::Handle<ClusterTPAssociationList> clusterAssocHandle;
168  iEvent.getByToken(cluster2TPToken_,clusterAssocHandle);
169 
170  if(clusterAssocHandle.isValid()) {
171  clusterAssoc = clusterAssocHandle.product();
172  } else {
173  edm::LogInfo( "TrackAssociator" ) << "ClusterTPAssociationList not found. Using DigiSimLink based associator";
174  }
175  }
176  if(not clusterAssoc) {
177  // If control got this far then either useClusterTPAssociation_ was false or getting the cluster
178  // to TrackingParticle association from the event failed. Either way I need to create a hit associator.
179  trackAssoc = std::make_unique<TrackerHitAssociator>(iEvent, trackerHitAssociatorConfig_);
180  }
181 
182  auto impl = std::make_unique<QuickTrackAssociatorByHitsImpl>(iEvent.productGetter(),
183  std::move(trackAssoc),
184  clusterAssoc,
191 
192  auto toPut = std::make_unique<reco::TrackToTrackingParticleAssociator>(std::move(impl));
193  iEvent.put(std::move(toPut));
194 }
195 
196 // ------------ method called once each job just before starting event loop ------------
197 void
199 {
200 }
201 
202 // ------------ method called once each job just after ending the event loop ------------
203 void
205 }
206 
207 
208 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
209 void
211  //The following says we do not know what parameters are allowed so do no validation
212  // Please change this to state exactly what you do use, even if it is no parameters
214  desc.setUnknown();
215  descriptions.addDefault(desc);
216 }
217 
218 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
EDProductGetter const & productGetter() const
Definition: Event.cc:60
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::ParameterSet makeHitAssociatorParameters(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
void addParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:144
def move
Definition: eostools.py:510
edm::EDGetTokenT< ClusterTPAssociationList > cluster2TPToken_
bool isValid() const
Definition: HandleBase.h:75
virtual void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
QuickTrackAssociatorByHitsImpl::SimToRecoDenomType simToRecoDenominator_
std::vector< std::pair< OmniClusterRef, TrackingParticleRef > > ClusterTPAssociationList
T const * product() const
Definition: Handle.h:81