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:
45  std::unique_ptr<PatternRecognitionAlgoBase> myAlgo_;
46 
53  const std::vector<int> filter_on_categories_;
54  const double pid_threshold_;
56 };
58 
59 std::unique_ptr<TrackstersCache> TrackstersProducer::initializeGlobalCache(const edm::ParameterSet& params) {
60  // this method is supposed to create, initialize and return a TrackstersCache instance
61  std::unique_ptr<TrackstersCache> cache = std::make_unique<TrackstersCache>(params);
62 
63  // load the graph def and save it
64  std::string graphPath = params.getParameter<std::string>("eid_graph_path");
65  if (!graphPath.empty()) {
66  graphPath = edm::FileInPath(graphPath).fullPath();
67  cache->eidGraphDef = tensorflow::loadGraphDef(graphPath);
68  }
69 
70  return cache;
71 }
72 
74  delete cache->eidGraphDef;
75  cache->eidGraphDef = nullptr;
76 }
77 
79  : myAlgo_(std::make_unique<PatternRecognitionbyCA>(ps, cache)),
80  clusters_token_(consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_clusters"))),
81  filtered_layerclusters_mask_token_(consumes<std::vector<float>>(ps.getParameter<edm::InputTag>("filtered_mask"))),
82  original_layerclusters_mask_token_(consumes<std::vector<float>>(ps.getParameter<edm::InputTag>("original_mask"))),
83  clustersTime_token_(
84  consumes<edm::ValueMap<std::pair<float, float>>>(ps.getParameter<edm::InputTag>("time_layerclusters"))),
85  layer_clusters_tiles_token_(consumes<TICLLayerTiles>(ps.getParameter<edm::InputTag>("layer_clusters_tiles"))),
86  seeding_regions_token_(
87  consumes<std::vector<TICLSeedingRegion>>(ps.getParameter<edm::InputTag>("seeding_regions"))),
88  filter_on_categories_(ps.getParameter<std::vector<int>>("filter_on_categories")),
89  pid_threshold_(ps.getParameter<double>("pid_threshold")),
90  itername_(ps.getParameter<std::string>("itername")) {
91  produces<std::vector<Trackster>>();
92  produces<std::vector<float>>(); // Mask to be applied at the next iteration
93 }
94 
96  // hgcalMultiClusters
98  desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalLayerClusters"));
99  desc.add<edm::InputTag>("filtered_mask", edm::InputTag("filteredLayerClusters", "iterationLabelGoesHere"));
100  desc.add<edm::InputTag>("original_mask", edm::InputTag("hgcalLayerClusters", "InitialLayerClustersMask"));
101  desc.add<edm::InputTag>("time_layerclusters", edm::InputTag("hgcalLayerClusters", "timeLayerCluster"));
102  desc.add<edm::InputTag>("layer_clusters_tiles", edm::InputTag("ticlLayerTileProducer"));
103  desc.add<edm::InputTag>("seeding_regions", edm::InputTag("ticlSeedingRegionProducer"));
104  desc.add<std::vector<int>>("filter_on_categories", {0});
105  desc.add<double>("pid_threshold", 0.); // make default such that no filtering is applied
106  desc.add<int>("algo_verbosity", 0);
107  desc.add<double>("min_cos_theta", 0.915);
108  desc.add<double>("min_cos_pointing", -1.);
109  desc.add<int>("missing_layers", 0);
110  desc.add<double>("etaLimitIncreaseWindow", 2.1);
111  desc.add<int>("min_clusters_per_ntuplet", 10);
112  desc.add<double>("max_delta_time", 3.); //nsigma
113  desc.add<bool>("out_in_dfs", true);
114  desc.add<int>("max_out_in_hops", 10);
115  desc.add<bool>("oneTracksterPerTrackSeed", false);
116  desc.add<bool>("promoteEmptyRegionToTrackster", false);
117  desc.add<std::string>("eid_graph_path", "RecoHGCal/TICL/data/tf_models/energy_id_v0.pb");
118  desc.add<std::string>("eid_input_name", "input");
119  desc.add<std::string>("eid_output_name_energy", "output/regressed_energy");
120  desc.add<std::string>("eid_output_name_id", "output/id_probabilities");
121  desc.add<std::string>("itername", "unknown");
122  desc.add<double>("eid_min_cluster_energy", 1.);
123  desc.add<int>("eid_n_layers", 50);
124  desc.add<int>("eid_n_clusters", 10);
125  descriptions.add("trackstersProducer", desc);
126 }
127 
129  auto result = std::make_unique<std::vector<Trackster>>();
130  auto output_mask = std::make_unique<std::vector<float>>();
131 
133  edm::Handle<std::vector<float>> filtered_layerclusters_mask_h;
134  edm::Handle<std::vector<float>> original_layerclusters_mask_h;
136  edm::Handle<TICLLayerTiles> layer_clusters_tiles_h;
138 
139  evt.getByToken(clusters_token_, cluster_h);
140  evt.getByToken(filtered_layerclusters_mask_token_, filtered_layerclusters_mask_h);
141  evt.getByToken(original_layerclusters_mask_token_, original_layerclusters_mask_h);
142  evt.getByToken(clustersTime_token_, time_clusters_h);
143  evt.getByToken(layer_clusters_tiles_token_, layer_clusters_tiles_h);
144  evt.getByToken(seeding_regions_token_, seeding_regions_h);
145 
146  const auto& layerClusters = *cluster_h;
147  const auto& inputClusterMask = *filtered_layerclusters_mask_h;
148  const auto& layerClustersTimes = *time_clusters_h;
149  const auto& layer_clusters_tiles = *layer_clusters_tiles_h;
150  const auto& seeding_regions = *seeding_regions_h;
152  evt, es, layerClusters, inputClusterMask, layerClustersTimes, layer_clusters_tiles, seeding_regions);
153 
154  std::unordered_map<int, std::vector<int>> seedToTrackstersAssociation;
155  // if it's regional iteration and there are seeding regions
156  if (!seeding_regions.empty() and seeding_regions[0].index != -1) {
157  auto numberOfSeedingRegions = seeding_regions.size();
158  for (unsigned int i = 0; i < numberOfSeedingRegions; ++i) {
159  seedToTrackstersAssociation.emplace(seeding_regions[i].index, 0);
160  }
161  }
162  myAlgo_->makeTracksters(input, *result, seedToTrackstersAssociation);
163 
164  // Now update the global mask and put it into the event
165  output_mask->reserve(original_layerclusters_mask_h->size());
166  // Copy over the previous state
167  std::copy(std::begin(*original_layerclusters_mask_h),
168  std::end(*original_layerclusters_mask_h),
169  std::back_inserter(*output_mask));
170 
171  // Filter results based on PID criteria.
172  // We want to **keep** tracksters whose cumulative
173  // probability summed up over the selected categories
174  // is greater than the chosen threshold. Therefore
175  // the filtering function should **discard** all
176  // tracksters **below** the threshold.
177  auto filter_on_pids = [&](Trackster& t) -> bool {
178  auto cumulative_prob = 0.;
179  for (auto index : filter_on_categories_) {
180  cumulative_prob += t.id_probabilities(index);
181  }
182  return cumulative_prob <= pid_threshold_;
183  };
184 
185  // Actually filter results and shrink size to fit
186  result->erase(std::remove_if(result->begin(), result->end(), filter_on_pids), result->end());
187 
188  // Mask the used elements, accordingly
189  for (auto const& trackster : *result) {
190  for (auto const v : trackster.vertices()) {
191  // TODO(rovere): for the moment we mask the layer cluster completely. In
192  // the future, properly compute the fraction of usage.
193  (*output_mask)[v] = 0.;
194  }
195  }
196 
197  evt.put(std::move(result));
198  evt.put(std::move(output_mask));
199 }
ConfigurationDescriptions.h
TrackstersProducer
Definition: TrackstersProducer.cc:32
PatternRecognitionAlgoBase.h
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
input
static const std::string input
Definition: EdmProvDump.cc:48
TensorFlow.h
MessageLogger.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
Trackster.h
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
ESHandle.h
TrackstersProducer::globalEndJob
static void globalEndJob(TrackstersCache *)
Definition: TrackstersProducer.cc:73
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
TICLGenericTile
Definition: TICLLayerTile.h:57
TrackstersProducer::pid_threshold_
const double pid_threshold_
Definition: TrackstersProducer.cc:54
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
ticl::PatternRecognitionAlgoBase::Inputs
Definition: PatternRecognitionAlgoBase.h:30
EDProducer.h
EMStep_cff.seeding_regions
seeding_regions
Definition: EMStep_cff.py:24
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
ticl
Definition: Common.h:8
edm::Handle
Definition: AssociativeIterator.h:50
end
#define end
Definition: vmac.h:39
TrackstersProducer::clustersTime_token_
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
Definition: TrackstersProducer.cc:50
TrackstersProducer::seeding_regions_token_
const edm::EDGetTokenT< std::vector< TICLSeedingRegion > > seeding_regions_token_
Definition: TrackstersProducer.cc:52
TICLLayerTile.h
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
ticl::TrackstersCache
Definition: GlobalCache.h:19
fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TrackstersProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TrackstersProducer.cc:95
PFCluster.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
ParameterSetDescription.h
OrderedSet.t
t
Definition: OrderedSet.py:90
utilities.cache
def cache(function)
Definition: utilities.py:3
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GlobalCache.h
PatternRecognitionbyMultiClusters.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
TrackstersProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: TrackstersProducer.cc:128
TrackstersProducer::filter_on_categories_
const std::vector< int > filter_on_categories_
Definition: TrackstersProducer.cc:53
createfilelist.int
int
Definition: createfilelist.py:10
TrackstersProducer::clusters_token_
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
Definition: TrackstersProducer.cc:47
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:132
TrackstersProducer::itername_
const std::string itername_
Definition: TrackstersProducer.cc:55
TrackstersProducer::filtered_layerclusters_mask_token_
const edm::EDGetTokenT< std::vector< float > > filtered_layerclusters_mask_token_
Definition: TrackstersProducer.cc:48
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
TrackstersProducer::myAlgo_
std::unique_ptr< PatternRecognitionAlgoBase > myAlgo_
Definition: TrackstersProducer.cc:45
TICLSeedingRegion
Definition: TICLSeedingRegion.h:14
PatternRecognitionbyCA.h
tensorflow::loadGraphDef
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
TICLSeedingRegion.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
TrackstersProducer::TrackstersProducer
TrackstersProducer(const edm::ParameterSet &, const TrackstersCache *)
Definition: TrackstersProducer.cc:78
TrackstersProducer::initializeGlobalCache
static std::unique_ptr< TrackstersCache > initializeGlobalCache(const edm::ParameterSet &)
Definition: TrackstersProducer.cc:59
mps_fire.result
result
Definition: mps_fire.py:303
TrackstersProducer::~TrackstersProducer
~TrackstersProducer() override
Definition: TrackstersProducer.cc:35
ticl::PatternRecognitionbyCA
Definition: PatternRecognitionbyCA.h:14
edm::Event
Definition: Event.h:73
TrackstersProducer::layer_clusters_tiles_token_
const edm::EDGetTokenT< TICLLayerTiles > layer_clusters_tiles_token_
Definition: TrackstersProducer.cc:51
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
ticl::Trackster
Definition: Trackster.h:19
CaloCluster.h
TrackstersProducer::original_layerclusters_mask_token_
const edm::EDGetTokenT< std::vector< float > > original_layerclusters_mask_token_
Definition: TrackstersProducer.cc:49