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 
15 
18 
22 
25 #include "PatternRecognitionbyCA.h"
27 
29 
30 using namespace ticl;
31 
32 class TrackstersProducer : public edm::stream::EDProducer<edm::GlobalCache<TrackstersCache>> {
33 public:
34  explicit TrackstersProducer(const edm::ParameterSet&, const TrackstersCache*);
35  ~TrackstersProducer() override {}
36  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
37 
38  void produce(edm::Event&, const edm::EventSetup&) override;
39 
40  // static methods for handling the global cache
41  static std::unique_ptr<TrackstersCache> initializeGlobalCache(const edm::ParameterSet&);
42  static void globalEndJob(TrackstersCache*);
43 
44 private:
51 
52  std::unique_ptr<PatternRecognitionAlgoBase> myAlgo_;
53 };
55 
56 std::unique_ptr<TrackstersCache> TrackstersProducer::initializeGlobalCache(const edm::ParameterSet& params) {
57  // this method is supposed to create, initialize and return a TrackstersCache instance
58  std::unique_ptr<TrackstersCache> cache = std::make_unique<TrackstersCache>(params);
59 
60  // load the graph def and save it
61  std::string graphPath = params.getParameter<std::string>("eid_graph_path");
62  if (!graphPath.empty()) {
63  graphPath = edm::FileInPath(graphPath).fullPath();
64  cache->eidGraphDef = tensorflow::loadGraphDef(graphPath);
65  }
66 
67  return cache;
68 }
69 
71  delete cache->eidGraphDef;
72  cache->eidGraphDef = nullptr;
73 }
74 
76  : myAlgo_(std::make_unique<PatternRecognitionbyCA>(ps, cache)) {
77  clusters_token_ = consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_clusters"));
78  filtered_layerclusters_mask_token_ = consumes<std::vector<float>>(ps.getParameter<edm::InputTag>("filtered_mask"));
79  original_layerclusters_mask_token_ = consumes<std::vector<float>>(ps.getParameter<edm::InputTag>("original_mask"));
80  clustersTime_token_ = consumes<edm::ValueMap<float>>(ps.getParameter<edm::InputTag>("time_layerclusters"));
81  layer_clusters_tiles_token_ = consumes<TICLLayerTiles>(ps.getParameter<edm::InputTag>("layer_clusters_tiles"));
82  seeding_regions_token_ = consumes<std::vector<TICLSeedingRegion>>(ps.getParameter<edm::InputTag>("seeding_regions"));
83 
84  produces<std::vector<Trackster>>();
85  produces<std::vector<float>>(); // Mask to be applied at the next iteration
86 }
87 
89  // hgcalMultiClusters
91  desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalLayerClusters"));
92  desc.add<edm::InputTag>("filtered_mask", edm::InputTag("filteredLayerClusters", "iterationLabelGoesHere"));
93  desc.add<edm::InputTag>("original_mask", edm::InputTag("hgcalLayerClusters", "InitialLayerClustersMask"));
94  desc.add<edm::InputTag>("time_layerclusters", edm::InputTag("hgcalLayerClusters", "timeLayerCluster"));
95  desc.add<edm::InputTag>("layer_clusters_tiles", edm::InputTag("ticlLayerTileProducer"));
96  desc.add<edm::InputTag>("seeding_regions", edm::InputTag("ticlSeedingRegionProducer"));
97  desc.add<int>("algo_verbosity", 0);
98  desc.add<double>("min_cos_theta", 0.915);
99  desc.add<double>("min_cos_pointing", -1.);
100  desc.add<int>("missing_layers", 0);
101  desc.add<int>("min_clusters_per_ntuplet", 10);
102  desc.add<double>("max_delta_time", 0.09);
103  desc.add<bool>("out_in_dfs", true);
104  desc.add<int>("max_out_in_hops", 10);
105  desc.add<std::string>("eid_graph_path", "RecoHGCal/TICL/data/tf_models/energy_id_v0.pb");
106  desc.add<std::string>("eid_input_name", "input");
107  desc.add<std::string>("eid_output_name_energy", "output/regressed_energy");
108  desc.add<std::string>("eid_output_name_id", "output/id_probabilities");
109  desc.add<double>("eid_min_cluster_energy", 1.);
110  desc.add<int>("eid_n_layers", 50);
111  desc.add<int>("eid_n_clusters", 10);
112  descriptions.add("trackstersProducer", desc);
113 }
114 
116  auto result = std::make_unique<std::vector<Trackster>>();
117  auto output_mask = std::make_unique<std::vector<float>>();
118 
120  edm::Handle<std::vector<float>> filtered_layerclusters_mask_h;
121  edm::Handle<std::vector<float>> original_layerclusters_mask_h;
122  edm::Handle<edm::ValueMap<float>> time_clusters_h;
123  edm::Handle<TICLLayerTiles> layer_clusters_tiles_h;
125 
126  evt.getByToken(clusters_token_, cluster_h);
127  evt.getByToken(filtered_layerclusters_mask_token_, filtered_layerclusters_mask_h);
128  evt.getByToken(original_layerclusters_mask_token_, original_layerclusters_mask_h);
129  evt.getByToken(clustersTime_token_, time_clusters_h);
130  evt.getByToken(layer_clusters_tiles_token_, layer_clusters_tiles_h);
131  evt.getByToken(seeding_regions_token_, seeding_regions_h);
132 
133  const auto& layerClusters = *cluster_h;
134  const auto& inputClusterMask = *filtered_layerclusters_mask_h;
135  const auto& layerClustersTimes = *time_clusters_h;
136  const auto& layer_clusters_tiles = *layer_clusters_tiles_h;
137  const auto& seeding_regions = *seeding_regions_h;
139  evt, es, layerClusters, inputClusterMask, layerClustersTimes, layer_clusters_tiles, seeding_regions);
140  myAlgo_->makeTracksters(input, *result);
141 
142  // Now update the global mask and put it into the event
143  output_mask->reserve(original_layerclusters_mask_h->size());
144  // Copy over the previous state
145  std::copy(std::begin(*original_layerclusters_mask_h),
146  std::end(*original_layerclusters_mask_h),
147  std::back_inserter(*output_mask));
148  // Mask the used elements, accordingly
149  for (auto const& trackster : *result) {
150  for (auto const v : trackster.vertices) {
151  // TODO(rovere): for the moment we mask the layer cluster completely. In
152  // the future, properly compute the fraction of usage.
153  (*output_mask)[v] = 0.;
154  }
155  }
156 
157  evt.put(std::move(result));
158  evt.put(std::move(output_mask));
159 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
edm::EDGetTokenT< std::vector< TICLSeedingRegion > > seeding_regions_token_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:55
edm::EDGetTokenT< std::vector< float > > filtered_layerclusters_mask_token_
static std::string const input
Definition: EdmProvDump.cc:48
edm::EDGetTokenT< edm::ValueMap< float > > clustersTime_token_
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< TICLLayerTiles > layer_clusters_tiles_token_
edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::atomic< tensorflow::GraphDef * > eidGraphDef
Definition: GlobalCache.h:25
std::unique_ptr< PatternRecognitionAlgoBase > myAlgo_
#define end
Definition: vmac.h:39
ParameterDescriptionBase * add(U const &iLabel, T const &value)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static void globalEndJob(TrackstersCache *)
TrackstersProducer(const edm::ParameterSet &, const TrackstersCache *)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static std::unique_ptr< TrackstersCache > initializeGlobalCache(const edm::ParameterSet &)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
~TrackstersProducer() override
#define begin
Definition: vmac.h:32
def cache(function)
Definition: utilities.py:3
std::string fullPath() const
Definition: FileInPath.cc:163
edm::EDGetTokenT< std::vector< float > > original_layerclusters_mask_token_
def move(src, dest)
Definition: eostools.py:511