CMS 3D CMS Logo

TrackstersProducer.cc
Go to the documentation of this file.
1 // Author: Felice Pantaleo,Marco Rovere - felice.pantaleo@cern.ch,marco.rovere@cern.ch
2 // Date: 09/2018
3 
4 // user include files
5 #include <vector>
6 
16 
19 
24 
26 
30 
31 using namespace ticl;
32 using namespace cms::Ort;
33 
35 public:
36  explicit TrackstersProducer(const edm::ParameterSet&);
37  ~TrackstersProducer() override {}
38  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
39 
40  void produce(edm::Event&, const edm::EventSetup&) override;
41 
42  // static methods for handling the global cache
43  static std::unique_ptr<TrackstersCache> initializeGlobalCache(const edm::ParameterSet&);
44  static void globalEndJob(TrackstersCache*);
45 
46 private:
48  bool doNose_;
49  std::unique_ptr<PatternRecognitionAlgoBaseT<TICLLayerTiles>> myAlgo_;
50  std::unique_ptr<PatternRecognitionAlgoBaseT<TICLLayerTilesHFNose>> myAlgoHFNose_;
51  std::unique_ptr<TracksterInferenceAlgoBase> inferenceAlgo_;
61 };
63 
65  : detector_(ps.getParameter<std::string>("detector")),
66  doNose_(detector_ == "HFNose"),
67  clusters_token_(consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_clusters"))),
68  filtered_layerclusters_mask_token_(consumes<std::vector<float>>(ps.getParameter<edm::InputTag>("filtered_mask"))),
69  original_layerclusters_mask_token_(consumes<std::vector<float>>(ps.getParameter<edm::InputTag>("original_mask"))),
70  clustersTime_token_(
71  consumes<edm::ValueMap<std::pair<float, float>>>(ps.getParameter<edm::InputTag>("time_layerclusters"))),
72  seeding_regions_token_(
73  consumes<std::vector<TICLSeedingRegion>>(ps.getParameter<edm::InputTag>("seeding_regions"))),
74  itername_(ps.getParameter<std::string>("itername")) {
75  auto plugin = ps.getParameter<std::string>("patternRecognitionBy");
76  auto pluginPSet = ps.getParameter<edm::ParameterSet>("pluginPatternRecognitionBy" + plugin);
77  if (doNose_) {
79  ps.getParameter<std::string>("patternRecognitionBy"), pluginPSet, consumesCollector());
81  consumes<TICLLayerTilesHFNose>(ps.getParameter<edm::InputTag>("layer_clusters_hfnose_tiles"));
82  } else {
84  ps.getParameter<std::string>("patternRecognitionBy"), pluginPSet, consumesCollector());
85  layer_clusters_tiles_token_ = consumes<TICLLayerTiles>(ps.getParameter<edm::InputTag>("layer_clusters_tiles"));
86  }
87 
88  // Initialize inference algorithm using the factory
89  std::string inferencePlugin = ps.getParameter<std::string>("inferenceAlgo");
90  edm::ParameterSet inferencePSet = ps.getParameter<edm::ParameterSet>("pluginInferenceAlgo" + inferencePlugin);
91  inferenceAlgo_ = std::unique_ptr<TracksterInferenceAlgoBase>(
92  TracksterInferenceAlgoFactory::get()->create(inferencePlugin, inferencePSet));
93 
94  if (itername_ == "TrkEM")
96  else if (itername_ == "EM")
98  else if (itername_ == "Trk")
100  else if (itername_ == "HAD")
102  else if (itername_ == "MIP")
104 
105  produces<std::vector<Trackster>>();
106  produces<std::vector<float>>(); // Mask to be applied at the next iteration
107 }
108 
110  // hgcalMultiClusters
112  desc.add<std::string>("detector", "HGCAL");
113  desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalMergeLayerClusters"));
114  desc.add<edm::InputTag>("filtered_mask", edm::InputTag("filteredLayerClusters", "iterationLabelGoesHere"));
115  desc.add<edm::InputTag>("original_mask", edm::InputTag("hgcalMergeLayerClusters", "InitialLayerClustersMask"));
116  desc.add<edm::InputTag>("time_layerclusters", edm::InputTag("hgcalMergeLayerClusters", "timeLayerCluster"));
117  desc.add<edm::InputTag>("layer_clusters_tiles", edm::InputTag("ticlLayerTileProducer"));
118  desc.add<edm::InputTag>("layer_clusters_hfnose_tiles", edm::InputTag("ticlLayerTileHFNose"));
119  desc.add<edm::InputTag>("seeding_regions", edm::InputTag("ticlSeedingRegionProducer"));
120  desc.add<std::string>("patternRecognitionBy", "CA");
121  desc.add<std::string>("itername", "unknown");
122  desc.add<std::string>("inferenceAlgo", "TracksterInferenceByDNN");
123 
124  // CA Plugin
125  edm::ParameterSetDescription pluginDesc;
126  pluginDesc.addNode(edm::PluginDescription<PatternRecognitionFactory>("type", "CA", true));
127  desc.add<edm::ParameterSetDescription>("pluginPatternRecognitionByCA", pluginDesc);
128  //
129  // CLUE3D Plugin
130  edm::ParameterSetDescription pluginDescClue3D;
131  pluginDescClue3D.addNode(edm::PluginDescription<PatternRecognitionFactory>("type", "CLUE3D", true));
132  desc.add<edm::ParameterSetDescription>("pluginPatternRecognitionByCLUE3D", pluginDescClue3D);
133 
134  // FastJet Plugin
135  edm::ParameterSetDescription pluginDescFastJet;
136  pluginDescFastJet.addNode(edm::PluginDescription<PatternRecognitionFactory>("type", "FastJet", true));
137  desc.add<edm::ParameterSetDescription>("pluginPatternRecognitionByFastJet", pluginDescFastJet);
138 
139  // Recovery Plugin
140  edm::ParameterSetDescription pluginDescRecovery;
141  pluginDescRecovery.addNode(edm::PluginDescription<PatternRecognitionFactory>("type", "Recovery", true));
142  desc.add<edm::ParameterSetDescription>("pluginPatternRecognitionByRecovery", pluginDescRecovery);
143 
144  // Inference Plugins
145  edm::ParameterSetDescription inferenceDesc;
146  inferenceDesc.addNode(edm::PluginDescription<TracksterInferenceAlgoFactory>("type", "TracksterInferenceByDNN", true));
147  desc.add<edm::ParameterSetDescription>("pluginInferenceAlgoTracksterInferenceByDNN", inferenceDesc);
148 
149  edm::ParameterSetDescription inferenceDescANN;
150  inferenceDescANN.addNode(
151  edm::PluginDescription<TracksterInferenceAlgoFactory>("type", "TracksterInferenceByANN", true));
152  desc.add<edm::ParameterSetDescription>("pluginInferenceAlgoTracksterInferenceByANN", inferenceDescANN);
153 
154  edm::ParameterSetDescription inferenceDescCNNv4;
155  inferenceDescCNNv4.addNode(
156  edm::PluginDescription<TracksterInferenceAlgoFactory>("type", "TracksterInferenceByCNNv4", true));
157  desc.add<edm::ParameterSetDescription>("pluginInferenceAlgoTracksterInferenceByCNNv4", inferenceDescCNNv4);
158 
159  descriptions.add("trackstersProducer", desc);
160 }
161 
163  auto result = std::make_unique<std::vector<Trackster>>();
164  auto initialResult = std::make_unique<std::vector<Trackster>>();
165  auto output_mask = std::make_unique<std::vector<float>>();
166 
167  const std::vector<float>& original_layerclusters_mask = evt.get(original_layerclusters_mask_token_);
168  const auto& layerClusters = evt.get(clusters_token_);
169  const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_);
170  const auto& layerClustersTimes = evt.get(clustersTime_token_);
171  const auto& seeding_regions = evt.get(seeding_regions_token_);
172 
173  std::unordered_map<int, std::vector<int>> seedToTrackstersAssociation;
174  // if it's regional iteration and there are seeding regions
175  if (!seeding_regions.empty() and seeding_regions[0].index != -1) {
176  auto numberOfSeedingRegions = seeding_regions.size();
177  for (unsigned int i = 0; i < numberOfSeedingRegions; ++i) {
178  seedToTrackstersAssociation.emplace(seeding_regions[i].index, 0);
179  }
180  }
181 
182  if (doNose_) {
185  evt, es, layerClusters, inputClusterMask, layerClustersTimes, layer_clusters_hfnose_tiles, seeding_regions);
186 
187  myAlgoHFNose_->makeTracksters(inputHFNose, *initialResult, seedToTrackstersAssociation);
188  // Run inference algorithm
189  inferenceAlgo_->inputData(layerClusters, *initialResult);
190  inferenceAlgo_->runInference(*initialResult);
191  myAlgoHFNose_->filter(*result, *initialResult, inputHFNose, seedToTrackstersAssociation);
192 
193  } else {
196  evt, es, layerClusters, inputClusterMask, layerClustersTimes, layer_clusters_tiles, seeding_regions);
197 
198  myAlgo_->makeTracksters(input, *initialResult, seedToTrackstersAssociation);
199  // Run inference algorithm
200  inferenceAlgo_->inputData(layerClusters, *initialResult);
201  inferenceAlgo_->runInference(*initialResult);
202  myAlgo_->filter(*result, *initialResult, input, seedToTrackstersAssociation);
203  }
204  // Now update the global mask and put it into the event
205  output_mask->reserve(original_layerclusters_mask.size());
206  // Copy over the previous state
207  std::copy(
208  std::begin(original_layerclusters_mask), std::end(original_layerclusters_mask), std::back_inserter(*output_mask));
209 
210  for (auto& trackster : *result) {
211  trackster.setIteration(iterIndex_);
212  // Mask the used elements, accordingly
213  for (auto const v : trackster.vertices()) {
214  // TODO(rovere): for the moment we mask the layer cluster completely. In
215  // the future, properly compute the fraction of usage.
216  (*output_mask)[v] = 0.;
217  }
218  }
219 
220  evt.put(std::move(result));
221  evt.put(std::move(output_mask));
222 }
ticl::Trackster::IterationIndex iterIndex_
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EDGetTokenT< TICLLayerTilesHFNose > layer_clusters_tiles_hfnose_token_
std::unique_ptr< TracksterInferenceAlgoBase > inferenceAlgo_
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:344
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
const edm::EDGetTokenT< std::vector< float > > original_layerclusters_mask_token_
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
static std::string const input
Definition: EdmProvDump.cc:50
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< TICLLayerTiles > layer_clusters_tiles_token_
const std::string itername_
const edm::EDGetTokenT< std::vector< TICLSeedingRegion > > seeding_regions_token_
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< PatternRecognitionAlgoBaseT< TICLLayerTiles > > myAlgo_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~TrackstersProducer() override
const edm::EDGetTokenT< std::vector< float > > filtered_layerclusters_mask_token_
fixed size matrix
HLT enums.
Definition: Common.h:10
#define get
std::unique_ptr< PatternRecognitionAlgoBaseT< TICLLayerTilesHFNose > > myAlgoHFNose_
TrackstersProducer(const edm::ParameterSet &)
def move(src, dest)
Definition: eostools.py:511