CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
CaloTowersMerger Class Reference

#include <RecoLocalCalo/CaloTowersMerger/src/CaloTowersMerger.cc>

Inheritance diagram for CaloTowersMerger:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 CaloTowersMerger (const edm::ParameterSet &)
 
CaloTower mergedTower (const CaloTower &t1, const CaloTower &t2)
 
 ~CaloTowersMerger () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

void beginJob () override
 
void endJob () override
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

edm::InputTag extraTowerTag
 
edm::InputTag regularTowerTag
 
edm::EDGetTokenT< CaloTowerCollectiontok_ext_
 
edm::EDGetTokenT< CaloTowerCollectiontok_reg_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 46 of file CaloTowersMerger.cc.

Constructor & Destructor Documentation

CaloTowersMerger::CaloTowersMerger ( const edm::ParameterSet iConfig)
explicit

Definition at line 77 of file CaloTowersMerger.cc.

References extraTowerTag, edm::ParameterSet::getParameter(), regularTowerTag, tok_ext_, and tok_reg_.

78 {
79  regularTowerTag=iConfig.getParameter<edm::InputTag>("regularTowerTag");
80  extraTowerTag=iConfig.getParameter<edm::InputTag>("extraTowerTag");
81 
82  // register for data access
83  tok_reg_ = consumes<CaloTowerCollection>(regularTowerTag);
84  tok_ext_ = consumes<CaloTowerCollection>(extraTowerTag);
85 
86  //register your products
87  produces<CaloTowerCollection>();
88 }
edm::EDGetTokenT< CaloTowerCollection > tok_reg_
T getParameter(std::string const &) const
edm::EDGetTokenT< CaloTowerCollection > tok_ext_
edm::InputTag extraTowerTag
edm::InputTag regularTowerTag
CaloTowersMerger::~CaloTowersMerger ( )
override

Definition at line 91 of file CaloTowersMerger.cc.

92 {
93 
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 
97 }

Member Function Documentation

void CaloTowersMerger::beginJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 171 of file CaloTowersMerger.cc.

172 {
173 }
void CaloTowersMerger::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 177 of file CaloTowersMerger.cc.

177  {
178 }
CaloTower CaloTowersMerger::mergedTower ( const CaloTower t1,
const CaloTower t2 
)

Definition at line 190 of file CaloTowersMerger.cc.

References CaloTower::addConstituents(), CaloTower::constituents(), DEFINE_FWK_MODULE, DetId::Ecal, CaloTower::ecalTime(), CaloTower::emEnergy(), CaloTower::emPosition(), spr::find(), CaloTower::hadEnergy(), CaloTower::hadPosition(), DetId::Hcal, CaloTower::hcalTime(), CaloTower::hottestCellE(), CaloTower::id(), CaloTower::ietaAbs(), CaloTower::numBadEcalCells(), CaloTower::numBadHcalCells(), CaloTower::numProblematicEcalCells(), CaloTower::numProblematicHcalCells(), CaloTower::numRecoveredEcalCells(), CaloTower::numRecoveredHcalCells(), CaloTower::outerEnergy(), CaloTower::p4(), CaloTower::setCaloTowerStatus(), CaloTower::setEcalTime(), CaloTower::setHcalTime(), CaloTower::setHottestCellE(), x, PV3DBase< T, PVType, FrameType >::x(), y, PV3DBase< T, PVType, FrameType >::y(), z, and PV3DBase< T, PVType, FrameType >::z().

Referenced by produce().

190  {
191 
192  double newOuterE = 0;
193 
194  // HO energies are always saved (even if useHO=false)
195  // make sure there is no double counting
196  // crude test if one has HO energy and the other not (possibly due to bad hit cleanup)
197  // However: for |iEta|>15 E_outer has different meening:
198  // it holds either the energy in the outer depths in HCAL, etc
199 
200  if (rt.ietaAbs()<16 && (fabs(rt.outerEnergy()-et.outerEnergy())<0.00001 ) ) {
201  // there is no differnce in the store HO energies
202  newOuterE = rt.outerEnergy();
203  }
204  else {
205  newOuterE = rt.outerEnergy()+et.outerEnergy();
206  }
207 
208 
209  bool rt_hasEcalConstit = false;
210  bool et_hasEcalConstit = false;
211 
212  bool rt_hasHcalConstit = false;
213  bool et_hasHcalConstit = false;
214 
215 
216  // check if there are HCAL/ECAL constituents in the towers
217 
218  std::vector<DetId>::const_iterator rc_begin=rt.constituents().begin();
219  std::vector<DetId>::const_iterator rc_end=rt.constituents().end();
220  std::vector<DetId>::const_iterator rc_it;
221 
222 
223  for (rc_it=rc_begin; rc_it!=rc_end; ++rc_it) {
224  if (rc_it->det()==DetId::Hcal) rt_hasHcalConstit=true;
225  break;
226  }
227  for (rc_it=rc_begin; rc_it!=rc_end; ++rc_it) {
228  if (rc_it->det()==DetId::Ecal) rt_hasEcalConstit=true;
229  break;
230  }
231 
232  std::vector<DetId>::const_iterator ec_begin=et.constituents().begin();
233  std::vector<DetId>::const_iterator ec_end=et.constituents().end();
234  std::vector<DetId>::const_iterator ec_it;
235 
236  for (ec_it=ec_begin; ec_it!=ec_end; ++ec_it) {
237  if (ec_it->det()==DetId::Hcal) et_hasHcalConstit=true;
238  break;
239  }
240  for (ec_it=ec_begin; ec_it!=ec_end; ++ec_it) {
241  if (ec_it->det()==DetId::Ecal) et_hasEcalConstit=true;
242  break;
243  }
244 
245 
246  std::vector<DetId> combinedConstituents = rt.constituents();
247  for (ec_it=ec_begin; ec_it!=ec_end; ++ec_it) {
248  // if properly resconstructed, the only possible overlap should be for HO hits that
249  // are always listed as constituents if above thereshold (old JetMET request)
250  if (std::find(combinedConstituents.begin(),combinedConstituents.end(), *ec_it)==combinedConstituents.end())
251  combinedConstituents.push_back(*ec_it);
252  }
253 
254 
255 
256  GlobalPoint newEmPosition(0.0, 0.0, 0.0);
257 
258  // The following assumes the current default
259  // momentum reconstruction method (1) and
260  // accepted rechits with some threshod >0
261 
262 
263  if (rt_hasEcalConstit && et_hasEcalConstit) {
264 
265  if (rt.emEnergy()>0 && et.emEnergy()>0) {
266  double sumEmE = rt.emEnergy()+ et.emEnergy();
267 
268  double x = rt.emEnergy()*rt.emPosition().x() + et.emEnergy()*et.emPosition().x();
269  double y = rt.emEnergy()*rt.emPosition().y() + et.emEnergy()*et.emPosition().y();
270  double z = rt.emEnergy()*rt.emPosition().z() + et.emEnergy()*et.emPosition().z();
271 
272  GlobalPoint weightedEmdPosition(x/sumEmE,y/sumEmE,z/sumEmE);
273  newEmPosition = weightedEmdPosition;
274  }
275 
276 
277  }
278  else if (rt_hasEcalConstit && !et_hasEcalConstit) {
279  newEmPosition = rt.emPosition();
280  }
281  else if (!rt_hasEcalConstit && et_hasEcalConstit) {
282  newEmPosition = et.emPosition();
283  }
284 
285 
286  GlobalPoint newHadPosition(0.0, 0.0, 0.0);
287  // had positions are the same if there is at least one constituent
288  if (rt_hasHcalConstit) {
289  newHadPosition = rt.hadPosition();
290  }
291  else if (et_hasHcalConstit) {
292  newHadPosition = et.hadPosition();
293  }
294 
295 
296  // MAke the new tower and set all values
297 
298  CaloTower mergedTower(rt.id(), rt.emEnergy()+et.emEnergy(), rt.hadEnergy()+et.hadEnergy(), newOuterE, -1, -1,
299  rt.p4()+et.p4(), newEmPosition, newHadPosition);
300 
301  mergedTower.addConstituents(combinedConstituents);
302 
303  (rt.hottestCellE() > et.hottestCellE())?
304  mergedTower.setHottestCellE(rt.hottestCellE()) :
305  mergedTower.setHottestCellE(et.hottestCellE());
306 
307  unsigned int numBadHcalChan = rt.numBadHcalCells() - et.numProblematicHcalCells() - rt.numRecoveredHcalCells();
308  unsigned int numBadEcalChan = rt.numBadEcalCells() - et.numProblematicEcalCells() - rt.numRecoveredEcalCells();
309 
310  unsigned int numProbHcalChan = rt.numProblematicHcalCells() + et.numProblematicHcalCells();
311  unsigned int numProbEcalChan = rt.numProblematicEcalCells() + et.numProblematicEcalCells();
312 
313  unsigned int numRecHcalChan = rt.numRecoveredHcalCells() + et.numRecoveredHcalCells();
314  unsigned int numRecEcalChan = rt.numRecoveredEcalCells() + et.numRecoveredEcalCells();
315 
316  mergedTower.setCaloTowerStatus(numBadHcalChan, numBadEcalChan,
317  numRecHcalChan, numRecEcalChan,
318  numProbHcalChan, numProbEcalChan);
319 
320  // use timing from the good tower only (for now, in default reco we use information from good hits only)
321  // time is saved as integer but returned as float in (ns)
322  mergedTower.setEcalTime( int(rt.ecalTime()*100.0 + 0.5) );
323  mergedTower.setHcalTime( int(rt.hcalTime()*100.0 + 0.5) );
324 
325 
326  return mergedTower;
327 
328 }
CaloTower mergedTower(const CaloTower &t1, const CaloTower &t2)
void setCaloTowerStatus(unsigned int numBadHcalChan, unsigned int numBadEcalChan, unsigned int numRecHcalChan, unsigned int numRecEcalChan, unsigned int numProbHcalChan, unsigned int numProbEcalChan)
Definition: CaloTower.cc:199
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void setHottestCellE(double e)
Definition: CaloTower.h:97
void addConstituents(const std::vector< DetId > &ids)
Definition: CaloTower.cc:177
et
define resolution functions of each parameter
void setEcalTime(int t)
Definition: CaloTower.h:70
void setHcalTime(int t)
Definition: CaloTower.h:71
void CaloTowersMerger::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 106 of file CaloTowersMerger.cc.

References edm::SortedCollection< T, SORT >::begin(), edm::SortedCollection< T, SORT >::end(), extraTowerTag, spr::find(), edm::SortedCollection< T, SORT >::find(), edm::Event::getByToken(), edm::HandleBase::isValid(), mergedTower(), eostools::move(), TtSemiLepEvtBuilder_cfi::mt, convertSQLitetoXML_cfg::output, edm::Event::put(), regularTowerTag, edm::SortedCollection< T, SORT >::size(), tok_ext_, and tok_reg_.

107 {
108  edm::Handle<CaloTowerCollection> regTower,extraTower;
109 
110  iEvent.getByToken(tok_reg_,regTower);
111  iEvent.getByToken(tok_ext_,extraTower);
112 
113  if (!regTower.isValid() && !extraTower.isValid()){
114  edm::LogError("CaloTowersMerger")<<"both input tag:"<<regularTowerTag<<" and "<<extraTowerTag<<" are invalid. empty merged collection";
115  iEvent.put(std::make_unique<CaloTowerCollection>());
116  return;
117  }else if (!regTower.isValid() || !extraTower.isValid()){
118  if (!regTower.isValid() && extraTower.isValid())
119  regTower=extraTower;
120  iEvent.put(std::make_unique<CaloTowerCollection>(*regTower));
121  return;
122  }
123  else{
124  //both valid input collections: merging
125  auto output = std::make_unique<CaloTowerCollection>();
126  output->reserve(regTower->size()+extraTower->size());
127 
128  CaloTowerCollection::const_iterator rt_begin = regTower->begin();
129  CaloTowerCollection::const_iterator rt_end = regTower->end();
130  CaloTowerCollection::const_iterator rt_it = rt_begin;
131 
132  //vector of overlapping towers
133  std::vector<CaloTowerCollection::const_iterator> overlappingTowers;
134  overlappingTowers.reserve(extraTower->size());
135 
136  for (;rt_it!=rt_end;++rt_it){
137  CaloTowerCollection::const_iterator et_it = extraTower->find(rt_it->id());
138  if (et_it != extraTower->end()){
139  //need to merge the components
140  //FIXME
141 
143  //one needs to merge t1 and t2 into mergedTower
144  //end FIXME
145  CaloTower mt = mergedTower(*rt_it, *et_it);
146 
147  output->push_back(mt);
148  overlappingTowers.push_back(et_it);
149 
150  }else{
151  //just copy the regular tower over
152  output->push_back(*rt_it);
153  }
154  }
155  CaloTowerCollection::const_iterator et_begin = extraTower->begin();
156  CaloTowerCollection::const_iterator et_end = extraTower->end();
158  for (;et_it!=et_end;++et_it){
159  if (std::find(overlappingTowers.begin(),overlappingTowers.end(),et_it)==overlappingTowers.end())
160  //non overlapping tower
161  //copy the extra tower over
162  output->push_back(*et_it);
163  }
164  iEvent.put(std::move(output));
165  }
166 
167 }
edm::EDGetTokenT< CaloTowerCollection > tok_reg_
CaloTower mergedTower(const CaloTower &t1, const CaloTower &t2)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
edm::EDGetTokenT< CaloTowerCollection > tok_ext_
std::vector< CaloTower >::const_iterator const_iterator
edm::InputTag extraTowerTag
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
bool isValid() const
Definition: HandleBase.h:74
const_iterator end() const
edm::InputTag regularTowerTag
iterator find(key_type k)
size_type size() const
def move(src, dest)
Definition: eostools.py:510
const_iterator begin() const

Member Data Documentation

edm::InputTag CaloTowersMerger::extraTowerTag
private

Definition at line 60 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

edm::InputTag CaloTowersMerger::regularTowerTag
private

Definition at line 60 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

edm::EDGetTokenT<CaloTowerCollection> CaloTowersMerger::tok_ext_
private

Definition at line 62 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

edm::EDGetTokenT<CaloTowerCollection> CaloTowersMerger::tok_reg_
private

Definition at line 61 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().