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:
44 
48 
50 
51  std::unique_ptr<HGCalClusteringAlgoBase> algo;
52  bool doSharing;
54 
56  double timeOffset;
57 };
58 
60 
62  algoId(reco::CaloCluster::undefined),
63  doSharing(ps.getParameter<bool>("doSharing")),
64  detector(ps.getParameter<std::string >("detector")), // one of EE, FH, BH or "all"
65  timeClname(ps.getParameter<std::string >("timeClname")),
66  timeOffset(ps.getParameter<double>("timeOffset")) {
67 
68  if(detector=="all") {
69  hits_ee_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCEEInput"));
70  hits_fh_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCFHInput"));
71  hits_bh_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCBHInput"));
73  }else if(detector=="EE") {
74  hits_ee_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCEEInput"));
76  }else if(detector=="FH") {
77  hits_fh_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCFHInput"));
79  } else {
80  hits_bh_token = consumes<HGCRecHitCollection>(ps.getParameter<edm::InputTag>("HGCBHInput"));
82  }
83 
84 
85  auto pluginPSet = ps.getParameter<edm::ParameterSet>("plugin");
86  algo.reset(HGCalLayerClusterAlgoFactory::get()->create(pluginPSet.getParameter<std::string>("type"), pluginPSet));
87  algo->setAlgoId(algoId);
88 
89  produces<std::vector<reco::BasicCluster> >();
90  produces<std::vector<reco::BasicCluster> >("sharing");
91  //density
92  produces< Density >();
93  //time for layer clusters
94  produces<edm::ValueMap<float> > (timeClname);
95 
96 }
97 
98 
100  // hgcalLayerClusters
102  edm::ParameterSetDescription pluginDesc;
103  pluginDesc.addNode(edm::PluginDescription<HGCalLayerClusterAlgoFactory>("type", "CLUE", true));
104 
105  desc.add<edm::ParameterSetDescription>("plugin", pluginDesc);
106  desc.add<std::string>("detector", "all");
107  desc.add<bool>("doSharing", false);
108  desc.add<edm::InputTag>("HGCEEInput", edm::InputTag("HGCalRecHit","HGCEERecHits"));
109  desc.add<edm::InputTag>("HGCFHInput", edm::InputTag("HGCalRecHit","HGCHEFRecHits"));
110  desc.add<edm::InputTag>("HGCBHInput", edm::InputTag("HGCalRecHit","HGCHEBRecHits"));
111  desc.add<std::string>("timeClname", "timeLayerCluster");
112  desc.add<double>("timeOffset", 0.0);
113  descriptions.add("hgcalLayerClusters", desc);
114 }
115 
117  const edm::EventSetup& es) {
118 
122 
123 
124  std::unique_ptr<std::vector<reco::BasicCluster> > clusters( new std::vector<reco::BasicCluster> ),
125  clusters_sharing( new std::vector<reco::BasicCluster> );
126  auto density = std::make_unique<Density>();
127 
128  algo->reset();
129 
130  algo->getEventSetup(es);
131 
132  //make a map detid-rechit
133  // NB for the moment just host EE and FH hits
134  // timing in digi for BH not implemented for now
135  std::unordered_map<uint32_t, float> hitmap;
136 
137  switch(algoId){
139  evt.getByToken(hits_ee_token,ee_hits);
140  algo->populate(*ee_hits);
141  for(auto const& it: *ee_hits) hitmap[it.detid().rawId()] = it.time();
142  break;
144  evt.getByToken(hits_fh_token,fh_hits);
145  evt.getByToken(hits_bh_token,bh_hits);
146  if( fh_hits.isValid() ) {
147  algo->populate(*fh_hits);
148  for(auto const& it: *fh_hits) hitmap[it.detid().rawId()] = it.time();
149  } else if ( bh_hits.isValid() ) {
150  algo->populate(*bh_hits);
151  }
152  break;
154  evt.getByToken(hits_ee_token,ee_hits);
155  algo->populate(*ee_hits);
156  for(auto const& it: *ee_hits){
157  hitmap[it.detid().rawId()] = it.time();
158  }
159  evt.getByToken(hits_fh_token,fh_hits);
160  algo->populate(*fh_hits);
161  for(auto const& it: *fh_hits){
162  hitmap[it.detid().rawId()] = it.time();
163  }
164  evt.getByToken(hits_bh_token,bh_hits);
165  algo->populate(*bh_hits);
166  break;
167  default:
168  break;
169  }
170  algo->makeClusters();
171  *clusters = algo->getClusters(false);
172  if(doSharing)
173  *clusters_sharing = algo->getClusters(true);
174 
175  auto clusterHandle = evt.put(std::move(clusters));
176  auto clusterHandleSharing = evt.put(std::move(clusters_sharing),"sharing");
177 
178  //Keep the density
179  *density = algo->getDensity();
180  evt.put(std::move(density));
181 
182  edm::PtrVector<reco::BasicCluster> clusterPtrs, clusterPtrsSharing;
183 
184  std::vector<float> times;
185  times.reserve(clusterHandle->size());
186 
187  for( unsigned i = 0; i < clusterHandle->size(); ++i ) {
188  edm::Ptr<reco::BasicCluster> ptr(clusterHandle,i);
189  clusterPtrs.push_back(ptr);
190 
191  float timeCl = -99.;
192  const reco::CaloCluster &sCl = (*clusterHandle)[i];
193  if(sCl.size() >= 3){
194  std::vector<float> timeClhits;
195 
196  for(auto const& hit : sCl.hitsAndFractions()){
197  auto finder = hitmap.find(hit.first);
198  if(finder == hitmap.end()) continue;
199 
200  //time is computed wrt 0-25ns + offset and set to -1 if no time
201  float rhTime = finder->second;
202  if(rhTime < 0.) continue;
203  timeClhits.push_back(rhTime - timeOffset);
204  }
205  if(timeClhits.size() >= 3) timeCl = hgcalsimclustertime::fixSizeHighestDensity(timeClhits);
206  }
207  times.push_back(timeCl);
208  }
209 
210  auto timeCl = std::make_unique<edm::ValueMap<float>>();
212  filler.insert(clusterHandle, times.begin(), times.end());
213  filler.fill();
214  evt.put(std::move(timeCl), timeClname);
215 
216  if(doSharing){
217  for( unsigned i = 0; i < clusterHandleSharing->size(); ++i ) {
218  edm::Ptr<reco::BasicCluster> ptr(clusterHandleSharing,i);
219  clusterPtrsSharing.push_back(ptr);
220  }
221  }
222 }
223 
224 #endif
float fixSizeHighestDensity(std::vector< float > &t, float deltaT=0.210, float timeWidthBy=0.5)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
void produce(edm::Event &, const edm::EventSetup &) override
def create(alignables, pedeDump, additionalData, outputFile, config)
reco::CaloCluster::AlgoId algoId
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::map< DetId, float > Density
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
Definition: CaloCluster.h:197
std::unique_ptr< HGCalClusteringAlgoBase > algo
edm::EDGetTokenT< HGCRecHitCollection > hits_bh_token
hgcal_clustering::Density Density
Definition: HGCalCLUEAlgo.h:29
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< HGCRecHitCollection > hits_ee_token
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HGCalLayerClusterProducer(const edm::ParameterSet &)
fixed size matrix
size_t size() const
size in number of hits (e.g. in crystals for ECAL)
Definition: CaloCluster.h:174
edm::EDGetTokenT< HGCRecHitCollection > hits_fh_token
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55