CMS 3D CMS Logo

HGCalLayerClusterProducer.cc
Go to the documentation of this file.
1 #ifndef __RecoLocalCalo_HGCRecProducers_HGCalLayerClusterProducer_H__
2 #define __RecoLocalCalo_HGCRecProducers_HGCalLayerClusterProducer_H__
3 
4 // user include files
8 
15 
23 
26 
29 
32 
34 
36 public:
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41  void produce(edm::Event&, const edm::EventSetup&) override;
42 
43 private:
48 
50 
51  std::unique_ptr<HGCalClusteringAlgoBase> algo;
52  bool doSharing;
54 
56  double timeOffset;
57  unsigned int nHitsTime;
58 };
59 
61 
63  : algoId(reco::CaloCluster::undefined),
64  doSharing(ps.getParameter<bool>("doSharing")),
65  detector(ps.getParameter<std::string>("detector")), // one of EE, FH, BH or "all"
66  timeClname(ps.getParameter<std::string>("timeClname")),
67  timeOffset(ps.getParameter<double>("timeOffset")),
68  nHitsTime(ps.getParameter<unsigned int>("nHitsTime")) {
69  if (detector == "HFNose") {
70  hits_hfnose_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HFNoseInput"));
72  } else if (detector == "all") {
73  hits_ee_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCEEInput"));
74  hits_fh_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCFHInput"));
75  hits_bh_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCBHInput"));
77  } else if (detector == "EE") {
78  hits_ee_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCEEInput"));
80  } else if (detector == "FH") {
81  hits_fh_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCFHInput"));
83  } else {
84  hits_bh_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCBHInput"));
86  }
87 
88  auto pluginPSet = ps.getParameter<edm::ParameterSet>("plugin");
89  if (detector == "HFNose") {
90  algo = HGCalLayerClusterAlgoFactory::get()->create("HFNoseCLUE", pluginPSet);
91  algo->setAlgoId(algoId, true);
92  } else {
93  algo = HGCalLayerClusterAlgoFactory::get()->create(pluginPSet.getParameter<std::string>("type"), pluginPSet);
94  algo->setAlgoId(algoId);
95  }
96 
97  produces<std::vector<float>>("InitialLayerClustersMask");
98  produces<std::vector<reco::BasicCluster>>();
99  produces<std::vector<reco::BasicCluster>>("sharing");
100  //density
101  produces<Density>();
102  //time for layer clusters
103  produces<edm::ValueMap<std::pair<float, float>>>(timeClname);
104 }
105 
107  // hgcalLayerClusters
109  edm::ParameterSetDescription pluginDesc;
110  pluginDesc.addNode(edm::PluginDescription<HGCalLayerClusterAlgoFactory>("type", "CLUE", true));
111 
112  desc.add<edm::ParameterSetDescription>("plugin", pluginDesc);
113  desc.add<std::string>("detector", "all")
114  ->setComment("all (does not include HFNose); other options: EE, FH, HFNose; other value defaults to BH");
115  desc.add<bool>("doSharing", false);
116  desc.add<edm::InputTag>("HFNoseInput", edm::InputTag("HGCalRecHit", "HGCHFNoseRecHits"));
117  desc.add<edm::InputTag>("HGCEEInput", edm::InputTag("HGCalRecHit", "HGCEERecHits"));
118  desc.add<edm::InputTag>("HGCFHInput", edm::InputTag("HGCalRecHit", "HGCHEFRecHits"));
119  desc.add<edm::InputTag>("HGCBHInput", edm::InputTag("HGCalRecHit", "HGCHEBRecHits"));
120  desc.add<std::string>("timeClname", "timeLayerCluster");
121  desc.add<double>("timeOffset", 0.0);
122  desc.add<unsigned int>("nHitsTime", 3);
123  descriptions.add("hgcalLayerClusters", desc);
124 }
125 
131 
132  std::unique_ptr<std::vector<reco::BasicCluster>> clusters(new std::vector<reco::BasicCluster>),
133  clusters_sharing(new std::vector<reco::BasicCluster>);
134  auto density = std::make_unique<Density>();
135 
136  algo->reset();
137 
138  algo->getEventSetup(es);
139 
140  //make a map detid-rechit
141  // NB for the moment just host EE and FH hits
142  // timing in digi for BH not implemented for now
143  std::unordered_map<uint32_t, const HGCRecHit*> hitmap;
144 
145  switch (algoId) {
147  evt.getByToken(hits_hfnose_token, hfnose_hits);
148  algo->populate(*hfnose_hits);
149  for (auto const& it : *hfnose_hits)
150  hitmap[it.detid().rawId()] = &(it);
151  break;
153  evt.getByToken(hits_ee_token, ee_hits);
154  algo->populate(*ee_hits);
155  for (auto const& it : *ee_hits)
156  hitmap[it.detid().rawId()] = &(it);
157  break;
159  evt.getByToken(hits_fh_token, fh_hits);
160  evt.getByToken(hits_bh_token, bh_hits);
161  if (fh_hits.isValid()) {
162  algo->populate(*fh_hits);
163  for (auto const& it : *fh_hits)
164  hitmap[it.detid().rawId()] = &(it);
165  } else if (bh_hits.isValid()) {
166  algo->populate(*bh_hits);
167  }
168  break;
170  evt.getByToken(hits_ee_token, ee_hits);
171  algo->populate(*ee_hits);
172  for (auto const& it : *ee_hits) {
173  hitmap[it.detid().rawId()] = &(it);
174  }
175  evt.getByToken(hits_fh_token, fh_hits);
176  algo->populate(*fh_hits);
177  for (auto const& it : *fh_hits) {
178  hitmap[it.detid().rawId()] = &(it);
179  }
180  evt.getByToken(hits_bh_token, bh_hits);
181  algo->populate(*bh_hits);
182  break;
183  default:
184  break;
185  }
186  algo->makeClusters();
187  *clusters = algo->getClusters(false);
188  if (doSharing)
189  *clusters_sharing = algo->getClusters(true);
190 
191  auto clusterHandle = evt.put(std::move(clusters));
192  auto clusterHandleSharing = evt.put(std::move(clusters_sharing), "sharing");
193 
194  //Keep the density
195  *density = algo->getDensity();
196  evt.put(std::move(density));
197 
198  edm::PtrVector<reco::BasicCluster> clusterPtrs, clusterPtrsSharing;
199 
200  std::vector<std::pair<float, float>> times;
201  times.reserve(clusterHandle->size());
202 
203  for (unsigned i = 0; i < clusterHandle->size(); ++i) {
204  edm::Ptr<reco::BasicCluster> ptr(clusterHandle, i);
205  clusterPtrs.push_back(ptr);
206 
207  std::pair<float, float> timeCl(-99., -1.);
208 
209  const reco::CaloCluster& sCl = (*clusterHandle)[i];
210  if (sCl.size() >= nHitsTime) {
211  std::vector<float> timeClhits;
212  std::vector<float> timeErrorClhits;
213 
214  for (auto const& hit : sCl.hitsAndFractions()) {
215  auto finder = hitmap.find(hit.first);
216  if (finder == hitmap.end())
217  continue;
218 
219  //time is computed wrt 0-25ns + offset and set to -1 if no time
220  const HGCRecHit* rechit = finder->second;
221  float rhTimeE = rechit->timeError();
222  //check on timeError to exclude scintillator
223  if (rhTimeE < 0.)
224  continue;
225  timeClhits.push_back(rechit->time() - timeOffset);
226  timeErrorClhits.push_back(1. / (rhTimeE * rhTimeE));
227  }
229  timeCl = timeEstimator.fixSizeHighestDensity(timeClhits, timeErrorClhits, nHitsTime);
230  }
231  times.push_back(timeCl);
232  }
233  std::unique_ptr<std::vector<float>> layerClustersMask(new std::vector<float>);
234  layerClustersMask->resize(clusterHandle->size(), 1.0);
235  evt.put(std::move(layerClustersMask), "InitialLayerClustersMask");
236 
237  auto timeCl = std::make_unique<edm::ValueMap<std::pair<float, float>>>();
239  filler.insert(clusterHandle, times.begin(), times.end());
240  filler.fill();
241  evt.put(std::move(timeCl), timeClname);
242 
243  if (doSharing) {
244  for (unsigned i = 0; i < clusterHandleSharing->size(); ++i) {
245  edm::Ptr<reco::BasicCluster> ptr(clusterHandleSharing, i);
246  clusterPtrsSharing.push_back(ptr);
247  }
248  }
249 }
250 
251 #endif
ConfigurationDescriptions.h
reco::CaloCluster::size
size_t size() const
size in number of hits (e.g. in crystals for ECAL)
Definition: CaloCluster.h:187
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
InitialClusteringStepBase.h
MessageLogger.h
SeedFinderBase.h
TICLSeedingRegions_cff.algoId
algoId
Definition: TICLSeedingRegions_cff.py:8
HGCalLayerClusterProducer::doSharing
bool doSharing
Definition: HGCalLayerClusterProducer.cc:52
ESHandle.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
HGCalDepthPreClusterer.h
HGCalLayerClusterProducer::algoId
reco::CaloCluster::AlgoId algoId
Definition: HGCalLayerClusterProducer.cc:49
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::PluginDescription
Definition: PluginDescription.h:98
EDProducer.h
HGCalLayerClusterProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HGCalLayerClusterProducer.cc:126
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HGCalLayerClusterProducer::timeClname
std::string timeClname
Definition: HGCalLayerClusterProducer.cc:55
edm::Handle
Definition: AssociativeIterator.h:50
HGCRecHit::timeError
float timeError() const
Definition: HGCRecHit.cc:78
HGCalLayerClusterProducer::~HGCalLayerClusterProducer
~HGCalLayerClusterProducer() override
Definition: HGCalLayerClusterProducer.cc:38
HGCalLayerClusterProducer::hits_bh_token
edm::EDGetTokenT< HGCRecHitCollection > hits_bh_token
Definition: HGCalLayerClusterProducer.cc:46
hgcalsimclustertime::ComputeClusterTime::fixSizeHighestDensity
std::pair< float, float > fixSizeHighestDensity(std::vector< float > &time, std::vector< float > weight=std::vector< float >(), unsigned int minNhits=3, float deltaT=0.210, float timeWidthBy=0.5)
Definition: ComputeClusterTime.cc:64
MakerMacros.h
HGCalLayerClusterProducer::hits_hfnose_token
edm::EDGetTokenT< HGCRecHitCollection > hits_hfnose_token
Definition: HGCalLayerClusterProducer.cc:47
PFClusterEnergyCorrectorBase.h
HGCalLayerClusterProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HGCalLayerClusterProducer.cc:106
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DDAxes::undefined
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
edm::PtrVector
Definition: PtrVector.h:36
hgcal_clustering::Density
std::map< DetId, float > Density
Definition: HGCalClusteringAlgoBase.h:43
hgcalLayerClusters_cff.nHitsTime
nHitsTime
Definition: hgcalLayerClusters_cff.py:25
reco::CaloCluster
Definition: CaloCluster.h:31
PFClusterBuilderBase.h
PFCluster.h
reco::CaloCluster::AlgoId
AlgoId
Definition: CaloCluster.h:33
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
HGCalLayerClusterAlgoFactory.h
ParameterSetDescription.h
PFCPositionCalculatorBase.h
HGCalLayerClusterProducer::timeOffset
double timeOffset
Definition: HGCalLayerClusterProducer.cc:56
reco::CaloCluster::hfnose
Definition: CaloCluster.h:43
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
CaloRecHit::time
constexpr float time() const
Definition: CaloRecHit.h:31
HGCRecHit
Definition: HGCRecHit.h:14
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
edm::PtrVector::push_back
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:149
RecHitTopologicalCleanerBase.h
ComputeClusterTime.h
PluginDescription.h
HGCalLayerClusterProducer::hits_ee_token
edm::EDGetTokenT< HGCRecHitCollection > hits_ee_token
Definition: HGCalLayerClusterProducer.cc:44
HGCalLayerClusterProducer::algo
std::unique_ptr< HGCalClusteringAlgoBase > algo
Definition: HGCalLayerClusterProducer.cc:51
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
HGCalGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
HGCalLayerClusterProducer::hits_fh_token
edm::EDGetTokenT< HGCRecHitCollection > hits_fh_token
Definition: HGCalLayerClusterProducer.cc:45
reco::CaloCluster::hitsAndFractions
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:210
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
HGCalLayerClusterProducer::detector
std::string detector
Definition: HGCalLayerClusterProducer.cc:53
createfilelist.int
int
Definition: createfilelist.py:10
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
IdealGeometryRecord.h
edm::EventSetup
Definition: EventSetup.h:57
edm::ParameterSetDescription::addNode
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
Definition: ParameterSetDescription.cc:41
get
#define get
reco::CaloCluster::hgcal_had
Definition: CaloCluster.h:41
edm::Ptr
Definition: AssociationVector.h:31
ValueMap.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
HLT_2018_cff.finder
finder
Definition: HLT_2018_cff.py:50398
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
CalibratedDigis_cfi.timeOffset
timeOffset
Definition: CalibratedDigis_cfi.py:22
reco::CaloCluster::hgcal_mixed
Definition: CaloCluster.h:42
Frameworkfwd.h
edm::ValueMap
Definition: ValueMap.h:107
HGCalLayerClusterProducer::nHitsTime
unsigned int nHitsTime
Definition: HGCalLayerClusterProducer.cc:57
hgcalsimclustertime::ComputeClusterTime
Definition: ComputeClusterTime.h:23
HGCalLayerClusterProducer::HGCalLayerClusterProducer
HGCalLayerClusterProducer(const edm::ParameterSet &)
Definition: HGCalLayerClusterProducer.cc:62
HGCalLayerClusterProducer
Definition: HGCalLayerClusterProducer.cc:35
hgcalTestNeighbor_cfi.detector
detector
Definition: hgcalTestNeighbor_cfi.py:6
reco::CaloCluster::hgcal_em
Definition: CaloCluster.h:40
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
hit
Definition: SiStripHitEffFromCalibTree.cc:88
fastSimProducer_cff.density
density
Definition: fastSimProducer_cff.py:61
Density
hgcal_clustering::Density Density
Definition: HGCalImagingAlgo.h:29
edm::PtrVectorBase::reserve
void reserve(size_type n)
Reserve space for RefVector.
Definition: PtrVectorBase.h:93