CMS 3D CMS Logo

MultiClustersFromTrackstersProducer.cc
Go to the documentation of this file.
1 // user include files
4 
9 
12 
13 #include <algorithm>
14 #include <array>
15 #include <string>
16 #include <vector>
17 
19 public:
22  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
23 
24  void produce(edm::Event&, const edm::EventSetup&) override;
25 
26 private:
29 };
30 
32 
34  : layer_clusters_token_(consumes<std::vector<reco::CaloCluster>>(ps.getParameter<edm::InputTag>("LayerClusters"))),
35  tracksters_token_(consumes<std::vector<ticl::Trackster>>(ps.getParameter<edm::InputTag>("Tracksters"))) {
36  produces<std::vector<reco::HGCalMultiCluster>>();
37 }
38 
40  // hgcalMultiClusters
42  desc.add<edm::InputTag>("Tracksters", edm::InputTag("Tracksters", "TrackstersByCA"));
43  desc.add<edm::InputTag>("LayerClusters", edm::InputTag("hgcalLayerClusters"));
44  desc.addUntracked<unsigned int>("verbosity", 3);
45  descriptions.add("multiClustersFromTrackstersProducer", desc);
46 }
47 
49  auto multiclusters = std::make_unique<std::vector<reco::HGCalMultiCluster>>();
51  evt.getByToken(tracksters_token_, tracksterHandle);
52 
53  edm::Handle<std::vector<reco::CaloCluster>> layer_clustersHandle;
54  evt.getByToken(layer_clusters_token_, layer_clustersHandle);
55 
56  auto const& tracksters = *tracksterHandle;
57  auto const& layerClusters = *layer_clustersHandle;
58 
60  for (unsigned i = 0; i < layerClusters.size(); ++i) {
61  edm::Ptr<reco::BasicCluster> ptr(layer_clustersHandle, i);
62  clusterPtrs.push_back(ptr);
63  }
64 
65  std::for_each(std::begin(tracksters), std::end(tracksters), [&](auto const& trackster) {
66  // Do not create a multicluster if the trackster has no layer clusters.
67  // This could happen when a seed leads to no trackster and a dummy one is produced.
68  if (!trackster.vertices().empty()) {
69  std::array<double, 3> baricenter{{0., 0., 0.}};
70  double total_weight = 0.;
72  int counter = 0;
73  std::for_each(std::begin(trackster.vertices()), std::end(trackster.vertices()), [&](unsigned int idx) {
74  temp.push_back(clusterPtrs[idx]);
75  auto fraction = 1.f / trackster.vertex_multiplicity(counter++);
76  for (auto const& cell : clusterPtrs[idx]->hitsAndFractions()) {
77  temp.addHitAndFraction(cell.first, cell.second * fraction);
78  }
79  auto weight = clusterPtrs[idx]->energy() * fraction;
80  total_weight += weight;
81  baricenter[0] += clusterPtrs[idx]->x() * weight;
82  baricenter[1] += clusterPtrs[idx]->y() * weight;
83  baricenter[2] += clusterPtrs[idx]->z() * weight;
84  });
86  std::begin(baricenter), std::end(baricenter), std::begin(baricenter), [&total_weight](double val) -> double {
87  return val / total_weight;
88  });
89  temp.setEnergy(total_weight);
90  temp.setCorrectedEnergy(total_weight);
91  temp.setPosition(math::XYZPoint(baricenter[0], baricenter[1], baricenter[2]));
93  temp.setTime(trackster.time(), trackster.timeError());
94  multiclusters->push_back(temp);
95  }
96  });
97 
98  evt.put(std::move(multiclusters));
99 }
ConfigurationDescriptions.h
counter
Definition: counter.py:1
MultiClustersFromTrackstersProducer::layer_clusters_token_
edm::EDGetTokenT< std::vector< reco::CaloCluster > > layer_clusters_token_
Definition: MultiClustersFromTrackstersProducer.cc:27
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
Trackster.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
mps_merge.weight
weight
Definition: mps_merge.py:88
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
HGCalMultiCluster.h
EDProducer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ticl
Definition: Common.h:8
edm::Handle
Definition: AssociativeIterator.h:50
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
training_settings.idx
idx
Definition: training_settings.py:16
end
#define end
Definition: vmac.h:39
MakerMacros.h
MultiClustersFromTrackstersProducer::~MultiClustersFromTrackstersProducer
~MultiClustersFromTrackstersProducer() override
Definition: MultiClustersFromTrackstersProducer.cc:21
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
edm::PtrVector
Definition: PtrVector.h:36
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
ParameterSetDescription.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::PtrVector::push_back
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
Event.h
MultiClustersFromTrackstersProducer::tracksters_token_
edm::EDGetTokenT< std::vector< ticl::Trackster > > tracksters_token_
Definition: MultiClustersFromTrackstersProducer.cc:28
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:132
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
MultiClustersFromTrackstersProducer
Definition: MultiClustersFromTrackstersProducer.cc:18
MultiClustersFromTrackstersProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MultiClustersFromTrackstersProducer.cc:48
edm::Ptr
Definition: AssociationVector.h:31
reco::HGCalMultiCluster
Definition: HGCalMultiCluster.h:12
MultiClustersFromTrackstersProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MultiClustersFromTrackstersProducer.cc:39
heppy_batch.val
val
Definition: heppy_batch.py:351
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
MultiClustersFromTrackstersProducer::MultiClustersFromTrackstersProducer
MultiClustersFromTrackstersProducer(const edm::ParameterSet &)
Definition: MultiClustersFromTrackstersProducer.cc:33
reco::CaloCluster::hgcal_em
Definition: CaloCluster.h:40
edm::Event
Definition: Event.h:73
HLT_2018_cff.fraction
fraction
Definition: HLT_2018_cff.py:51317
edm::InputTag
Definition: InputTag.h:15
begin
#define begin
Definition: vmac.h:32
weight
Definition: weight.py:1