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:
46  bool doNose_;
47  std::unique_ptr<PatternRecognitionAlgoBaseT<TICLLayerTiles>> myAlgo_;
48  std::unique_ptr<PatternRecognitionAlgoBaseT<TICLLayerTilesHFNose>> myAlgoHFNose_;
49 
58 };
60 
61 std::unique_ptr<TrackstersCache> TrackstersProducer::initializeGlobalCache(const edm::ParameterSet& params) {
62  // this method is supposed to create, initialize and return a TrackstersCache instance
63  std::unique_ptr<TrackstersCache> cache = std::make_unique<TrackstersCache>(params);
64 
65  // load the graph def and save it
66  std::string graphPath = params.getParameter<std::string>("eid_graph_path");
67  if (!graphPath.empty()) {
68  graphPath = edm::FileInPath(graphPath).fullPath();
69  cache->eidGraphDef = tensorflow::loadGraphDef(graphPath);
70  }
71 
72  return cache;
73 }
74 
76  delete cache->eidGraphDef;
77  cache->eidGraphDef = nullptr;
78 }
79 
81  : detector_(ps.getParameter<std::string>("detector")),
82  doNose_(detector_ == "HFNose"),
83  myAlgo_(std::make_unique<PatternRecognitionbyCA<TICLLayerTiles>>(ps, cache)),
84  myAlgoHFNose_(std::make_unique<PatternRecognitionbyCA<TICLLayerTilesHFNose>>(ps, cache)),
85  clusters_token_(consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("layer_clusters"))),
86  filtered_layerclusters_mask_token_(consumes<std::vector<float>>(ps.getParameter<edm::InputTag>("filtered_mask"))),
87  original_layerclusters_mask_token_(consumes<std::vector<float>>(ps.getParameter<edm::InputTag>("original_mask"))),
88  clustersTime_token_(
89  consumes<edm::ValueMap<std::pair<float, float>>>(ps.getParameter<edm::InputTag>("time_layerclusters"))),
90  seeding_regions_token_(
91  consumes<std::vector<TICLSeedingRegion>>(ps.getParameter<edm::InputTag>("seeding_regions"))),
92  itername_(ps.getParameter<std::string>("itername")) {
93  if (doNose_) {
95  consumes<TICLLayerTilesHFNose>(ps.getParameter<edm::InputTag>("layer_clusters_hfnose_tiles"));
96  } else {
97  layer_clusters_tiles_token_ = consumes<TICLLayerTiles>(ps.getParameter<edm::InputTag>("layer_clusters_tiles"));
98  }
99  produces<std::vector<Trackster>>();
100  produces<std::vector<float>>(); // Mask to be applied at the next iteration
101 }
102 
104  // hgcalMultiClusters
106  desc.add<std::string>("detector", "HGCAL");
107  desc.add<edm::InputTag>("layer_clusters", edm::InputTag("hgcalLayerClusters"));
108  desc.add<edm::InputTag>("filtered_mask", edm::InputTag("filteredLayerClusters", "iterationLabelGoesHere"));
109  desc.add<edm::InputTag>("original_mask", edm::InputTag("hgcalLayerClusters", "InitialLayerClustersMask"));
110  desc.add<edm::InputTag>("time_layerclusters", edm::InputTag("hgcalLayerClusters", "timeLayerCluster"));
111  desc.add<edm::InputTag>("layer_clusters_tiles", edm::InputTag("ticlLayerTileProducer"));
112  desc.add<edm::InputTag>("layer_clusters_hfnose_tiles", edm::InputTag("ticlLayerTileHFNose"));
113  desc.add<edm::InputTag>("seeding_regions", edm::InputTag("ticlSeedingRegionProducer"));
114  desc.add<std::vector<int>>("filter_on_categories", {0});
115  desc.add<double>("pid_threshold", 0.); // make default such that no filtering is applied
116  desc.add<double>("energy_em_over_total_threshold", -1.); // make default such that no filtering is applied
117  desc.add<double>("max_longitudinal_sigmaPCA", 9999);
118  desc.add<int>("shower_start_max_layer", 9999); // make default such that no filtering is applied
119  desc.add<int>("algo_verbosity", 0);
120  desc.add<double>("min_cos_theta", 0.915);
121  desc.add<double>("root_doublet_max_distance_from_seed_squared", 9999);
122  desc.add<double>("min_cos_pointing", -1.);
123  desc.add<int>("skip_layers", 0);
124  desc.add<int>("max_missing_layers_in_trackster", 9999);
125  desc.add<double>("etaLimitIncreaseWindow", 2.1);
126  desc.add<int>("min_layers_per_trackster", 10);
127  desc.add<double>("max_delta_time", 3.); //nsigma
128  desc.add<bool>("out_in_dfs", true);
129  desc.add<int>("max_out_in_hops", 10);
130  desc.add<bool>("oneTracksterPerTrackSeed", false);
131  desc.add<bool>("promoteEmptyRegionToTrackster", false);
132  desc.add<std::string>("eid_graph_path", "RecoHGCal/TICL/data/tf_models/energy_id_v0.pb");
133  desc.add<std::string>("eid_input_name", "input");
134  desc.add<std::string>("eid_output_name_energy", "output/regressed_energy");
135  desc.add<std::string>("eid_output_name_id", "output/id_probabilities");
136  desc.add<std::string>("itername", "unknown");
137  desc.add<double>("eid_min_cluster_energy", 1.);
138  desc.add<int>("eid_n_layers", 50);
139  desc.add<int>("eid_n_clusters", 10);
140  descriptions.add("trackstersProducer", desc);
141 }
142 
144  auto result = std::make_unique<std::vector<Trackster>>();
145  auto output_mask = std::make_unique<std::vector<float>>();
146 
147  const std::vector<float>& original_layerclusters_mask = evt.get(original_layerclusters_mask_token_);
148  const auto& layerClusters = evt.get(clusters_token_);
149  const auto& inputClusterMask = evt.get(filtered_layerclusters_mask_token_);
150  const auto& layerClustersTimes = evt.get(clustersTime_token_);
151  const auto& seeding_regions = evt.get(seeding_regions_token_);
152 
153  std::unordered_map<int, std::vector<int>> seedToTrackstersAssociation;
154  // if it's regional iteration and there are seeding regions
155  if (!seeding_regions.empty() and seeding_regions[0].index != -1) {
156  auto numberOfSeedingRegions = seeding_regions.size();
157  for (unsigned int i = 0; i < numberOfSeedingRegions; ++i) {
158  seedToTrackstersAssociation.emplace(seeding_regions[i].index, 0);
159  }
160  }
161 
162  if (doNose_) {
165  evt, es, layerClusters, inputClusterMask, layerClustersTimes, layer_clusters_hfnose_tiles, seeding_regions);
166 
167  myAlgoHFNose_->makeTracksters(inputHFNose, *result, seedToTrackstersAssociation);
168 
169  } else {
172  evt, es, layerClusters, inputClusterMask, layerClustersTimes, layer_clusters_tiles, seeding_regions);
173 
174  myAlgo_->makeTracksters(input, *result, seedToTrackstersAssociation);
175  }
176  // Now update the global mask and put it into the event
177  output_mask->reserve(original_layerclusters_mask.size());
178  // Copy over the previous state
179  std::copy(
180  std::begin(original_layerclusters_mask), std::end(original_layerclusters_mask), std::back_inserter(*output_mask));
181 
182  // Mask the used elements, accordingly
183  for (auto const& trackster : *result) {
184  for (auto const v : trackster.vertices()) {
185  // TODO(rovere): for the moment we mask the layer cluster completely. In
186  // the future, properly compute the fraction of usage.
187  (*output_mask)[v] = 0.;
188  }
189  }
190 
191  evt.put(std::move(result));
192  evt.put(std::move(output_mask));
193 }
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
HLTEgPhaseIITestSequence_cff.seeding_regions
seeding_regions
Definition: HLTEgPhaseIITestSequence_cff.py:2218
TensorFlow.h
MessageLogger.h
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
Trackster.h
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
ESHandle.h
TrackstersProducer::detector_
std::string detector_
Definition: TrackstersProducer.cc:45
TrackstersProducer::myAlgo_
std::unique_ptr< PatternRecognitionAlgoBaseT< TICLLayerTiles > > myAlgo_
Definition: TrackstersProducer.cc:47
TrackstersProducer::globalEndJob
static void globalEndJob(TrackstersCache *)
Definition: TrackstersProducer.cc:75
HLTEgPhaseIITestSequence_cff.layer_clusters_tiles
layer_clusters_tiles
Definition: HLTEgPhaseIITestSequence_cff.py:2203
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:72
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
EDProducer.h
TrackstersProducer::layer_clusters_tiles_token_
edm::EDGetTokenT< TICLLayerTiles > layer_clusters_tiles_token_
Definition: TrackstersProducer.cc:54
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
ticl
Definition: Common.h:8
end
#define end
Definition: vmac.h:39
TrackstersProducer::clustersTime_token_
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
Definition: TrackstersProducer.cc:53
TrackstersProducer::seeding_regions_token_
const edm::EDGetTokenT< std::vector< TICLSeedingRegion > > seeding_regions_token_
Definition: TrackstersProducer.cc:56
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:103
PFCluster.h
ParameterSetDescription.h
HLTEgPhaseIITestSequence_cff.layerClusters
layerClusters
Definition: HLTEgPhaseIITestSequence_cff.py:2506
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:143
TrackstersProducer::doNose_
bool doNose_
Definition: TrackstersProducer.cc:46
TrackstersProducer::clusters_token_
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
Definition: TrackstersProducer.cc:50
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:57
TrackstersProducer::filtered_layerclusters_mask_token_
const edm::EDGetTokenT< std::vector< float > > filtered_layerclusters_mask_token_
Definition: TrackstersProducer.cc:51
HLTEgPhaseIITestSequence_cff.layer_clusters_hfnose_tiles
layer_clusters_hfnose_tiles
Definition: HLTEgPhaseIITestSequence_cff.py:2202
edm::stream::EDProducer
Definition: EDProducer.h:38
ticl::PatternRecognitionAlgoBaseT::Inputs
Definition: PatternRecognitionAlgoBase.h:30
edm::EventSetup
Definition: EventSetup.h:57
TICLSeedingRegion
Definition: TICLSeedingRegion.h:14
PatternRecognitionbyCA.h
tensorflow::loadGraphDef
GraphDef * loadGraphDef(const std::string &pbFile)
Definition: TensorFlow.cc:68
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
TICLSeedingRegion.h
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TrackstersProducer::myAlgoHFNose_
std::unique_ptr< PatternRecognitionAlgoBaseT< TICLLayerTilesHFNose > > myAlgoHFNose_
Definition: TrackstersProducer.cc:48
Frameworkfwd.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
TrackstersProducer::TrackstersProducer
TrackstersProducer(const edm::ParameterSet &, const TrackstersCache *)
Definition: TrackstersProducer.cc:80
TrackstersProducer::initializeGlobalCache
static std::unique_ptr< TrackstersCache > initializeGlobalCache(const edm::ParameterSet &)
Definition: TrackstersProducer.cc:61
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_hfnose_token_
edm::EDGetTokenT< TICLLayerTilesHFNose > layer_clusters_tiles_hfnose_token_
Definition: TrackstersProducer.cc:55
edm::Event::get
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:337
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163
CaloCluster.h
TrackstersProducer::original_layerclusters_mask_token_
const edm::EDGetTokenT< std::vector< float > > original_layerclusters_mask_token_
Definition: TrackstersProducer.cc:52