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::stream::EDProducer<>

Public Member Functions

 CaloTowersMerger (const edm::ParameterSet &)
 
CaloTower mergedTower (const CaloTower &t1, const CaloTower &t2)
 
 ~CaloTowersMerger () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Member Functions

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::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 44 of file CaloTowersMerger.cc.

Constructor & Destructor Documentation

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

Definition at line 72 of file CaloTowersMerger.cc.

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

72  {
73  regularTowerTag = iConfig.getParameter<edm::InputTag>("regularTowerTag");
74  extraTowerTag = iConfig.getParameter<edm::InputTag>("extraTowerTag");
75 
76  // register for data access
77  tok_reg_ = consumes<CaloTowerCollection>(regularTowerTag);
78  tok_ext_ = consumes<CaloTowerCollection>(extraTowerTag);
79 
80  //register your products
81  produces<CaloTowerCollection>();
82 }
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 84 of file CaloTowersMerger.cc.

84  {
85  // do anything here that needs to be done at desctruction time
86  // (e.g. close files, deallocate resources etc.)
87 }

Member Function Documentation

CaloTower CaloTowersMerger::mergedTower ( const CaloTower t1,
const CaloTower t2 
)

Definition at line 161 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().

161  {
162  double newOuterE = 0;
163 
164  // HO energies are always saved (even if useHO=false)
165  // make sure there is no double counting
166  // crude test if one has HO energy and the other not (possibly due to bad hit cleanup)
167  // However: for |iEta|>15 E_outer has different meening:
168  // it holds either the energy in the outer depths in HCAL, etc
169 
170  if (rt.ietaAbs() < 16 && (fabs(rt.outerEnergy() - et.outerEnergy()) < 0.00001)) {
171  // there is no differnce in the store HO energies
172  newOuterE = rt.outerEnergy();
173  } else {
174  newOuterE = rt.outerEnergy() + et.outerEnergy();
175  }
176 
177  bool rt_hasEcalConstit = false;
178  bool et_hasEcalConstit = false;
179 
180  bool rt_hasHcalConstit = false;
181  bool et_hasHcalConstit = false;
182 
183  // check if there are HCAL/ECAL constituents in the towers
184 
185  std::vector<DetId>::const_iterator rc_begin = rt.constituents().begin();
186  std::vector<DetId>::const_iterator rc_end = rt.constituents().end();
187  std::vector<DetId>::const_iterator rc_it;
188 
189  for (rc_it = rc_begin; rc_it != rc_end; ++rc_it) {
190  if (rc_it->det() == DetId::Hcal)
191  rt_hasHcalConstit = true;
192  break;
193  }
194  for (rc_it = rc_begin; rc_it != rc_end; ++rc_it) {
195  if (rc_it->det() == DetId::Ecal)
196  rt_hasEcalConstit = true;
197  break;
198  }
199 
200  std::vector<DetId>::const_iterator ec_begin = et.constituents().begin();
201  std::vector<DetId>::const_iterator ec_end = et.constituents().end();
202  std::vector<DetId>::const_iterator ec_it;
203 
204  for (ec_it = ec_begin; ec_it != ec_end; ++ec_it) {
205  if (ec_it->det() == DetId::Hcal)
206  et_hasHcalConstit = true;
207  break;
208  }
209  for (ec_it = ec_begin; ec_it != ec_end; ++ec_it) {
210  if (ec_it->det() == DetId::Ecal)
211  et_hasEcalConstit = true;
212  break;
213  }
214 
215  std::vector<DetId> combinedConstituents = rt.constituents();
216  for (ec_it = ec_begin; ec_it != ec_end; ++ec_it) {
217  // if properly resconstructed, the only possible overlap should be for HO hits that
218  // are always listed as constituents if above thereshold (old JetMET request)
219  if (std::find(combinedConstituents.begin(), combinedConstituents.end(), *ec_it) == combinedConstituents.end())
220  combinedConstituents.push_back(*ec_it);
221  }
222 
223  GlobalPoint newEmPosition(0.0, 0.0, 0.0);
224 
225  // The following assumes the current default
226  // momentum reconstruction method (1) and
227  // accepted rechits with some threshod >0
228 
229  if (rt_hasEcalConstit && et_hasEcalConstit) {
230  if (rt.emEnergy() > 0 && et.emEnergy() > 0) {
231  double sumEmE = rt.emEnergy() + et.emEnergy();
232 
233  double x = rt.emEnergy() * rt.emPosition().x() + et.emEnergy() * et.emPosition().x();
234  double y = rt.emEnergy() * rt.emPosition().y() + et.emEnergy() * et.emPosition().y();
235  double z = rt.emEnergy() * rt.emPosition().z() + et.emEnergy() * et.emPosition().z();
236 
237  GlobalPoint weightedEmdPosition(x / sumEmE, y / sumEmE, z / sumEmE);
238  newEmPosition = weightedEmdPosition;
239  }
240 
241  } else if (rt_hasEcalConstit && !et_hasEcalConstit) {
242  newEmPosition = rt.emPosition();
243  } else if (!rt_hasEcalConstit && et_hasEcalConstit) {
244  newEmPosition = et.emPosition();
245  }
246 
247  GlobalPoint newHadPosition(0.0, 0.0, 0.0);
248  // had positions are the same if there is at least one constituent
249  if (rt_hasHcalConstit) {
250  newHadPosition = rt.hadPosition();
251  } else if (et_hasHcalConstit) {
252  newHadPosition = et.hadPosition();
253  }
254 
255  // MAke the new tower and set all values
256 
257  CaloTower mergedTower(rt.id(),
258  rt.emEnergy() + et.emEnergy(),
259  rt.hadEnergy() + et.hadEnergy(),
260  newOuterE,
261  -1,
262  -1,
263  rt.p4() + et.p4(),
264  newEmPosition,
265  newHadPosition);
266 
267  mergedTower.addConstituents(combinedConstituents);
268 
269  (rt.hottestCellE() > et.hottestCellE()) ? mergedTower.setHottestCellE(rt.hottestCellE())
270  : mergedTower.setHottestCellE(et.hottestCellE());
271 
272  unsigned int numBadHcalChan = rt.numBadHcalCells() - et.numProblematicHcalCells() - rt.numRecoveredHcalCells();
273  unsigned int numBadEcalChan = rt.numBadEcalCells() - et.numProblematicEcalCells() - rt.numRecoveredEcalCells();
274 
275  unsigned int numProbHcalChan = rt.numProblematicHcalCells() + et.numProblematicHcalCells();
276  unsigned int numProbEcalChan = rt.numProblematicEcalCells() + et.numProblematicEcalCells();
277 
278  unsigned int numRecHcalChan = rt.numRecoveredHcalCells() + et.numRecoveredHcalCells();
279  unsigned int numRecEcalChan = rt.numRecoveredEcalCells() + et.numRecoveredEcalCells();
280 
282  numBadHcalChan, numBadEcalChan, numRecHcalChan, numRecEcalChan, numProbHcalChan, numProbEcalChan);
283 
284  // use timing from the good tower only (for now, in default reco we use information from good hits only)
285  // time is saved as integer but returned as float in (ns)
286  mergedTower.setEcalTime(int(rt.ecalTime() * 100.0 + 0.5));
287  mergedTower.setHcalTime(int(rt.hcalTime() * 100.0 + 0.5));
288 
289  return mergedTower;
290 }
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:221
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void setHottestCellE(double e)
Definition: CaloTower.h:124
void addConstituents(const std::vector< DetId > &ids)
Definition: CaloTower.cc:199
void setEcalTime(int t)
Definition: CaloTower.h:87
void setHcalTime(int t)
Definition: CaloTower.h:88
void CaloTowersMerger::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 94 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_.

94  {
95  edm::Handle<CaloTowerCollection> regTower, extraTower;
96 
97  iEvent.getByToken(tok_reg_, regTower);
98  iEvent.getByToken(tok_ext_, extraTower);
99 
100  if (!regTower.isValid() && !extraTower.isValid()) {
101  edm::LogError("CaloTowersMerger") << "both input tag:" << regularTowerTag << " and " << extraTowerTag
102  << " are invalid. empty merged collection";
103  iEvent.put(std::make_unique<CaloTowerCollection>());
104  return;
105  } else if (!regTower.isValid() || !extraTower.isValid()) {
106  if (!regTower.isValid() && extraTower.isValid())
107  regTower = extraTower;
108  iEvent.put(std::make_unique<CaloTowerCollection>(*regTower));
109  return;
110  } else {
111  //both valid input collections: merging
112  auto output = std::make_unique<CaloTowerCollection>();
113  output->reserve(regTower->size() + extraTower->size());
114 
115  CaloTowerCollection::const_iterator rt_begin = regTower->begin();
116  CaloTowerCollection::const_iterator rt_end = regTower->end();
117  CaloTowerCollection::const_iterator rt_it = rt_begin;
118 
119  //vector of overlapping towers
120  std::vector<CaloTowerCollection::const_iterator> overlappingTowers;
121  overlappingTowers.reserve(extraTower->size());
122 
123  for (; rt_it != rt_end; ++rt_it) {
124  CaloTowerCollection::const_iterator et_it = extraTower->find(rt_it->id());
125  if (et_it != extraTower->end()) {
126  //need to merge the components
127  //FIXME
128 
130  //one needs to merge t1 and t2 into mergedTower
131  //end FIXME
132  CaloTower mt = mergedTower(*rt_it, *et_it);
133 
134  output->push_back(mt);
135  overlappingTowers.push_back(et_it);
136 
137  } else {
138  //just copy the regular tower over
139  output->push_back(*rt_it);
140  }
141  }
142  CaloTowerCollection::const_iterator et_begin = extraTower->begin();
143  CaloTowerCollection::const_iterator et_end = extraTower->end();
144  CaloTowerCollection::const_iterator et_it = et_begin;
145  for (; et_it != et_end; ++et_it) {
146  if (std::find(overlappingTowers.begin(), overlappingTowers.end(), et_it) == overlappingTowers.end())
147  //non overlapping tower
148  //copy the extra tower over
149  output->push_back(*et_it);
150  }
151  iEvent.put(std::move(output));
152  }
153 }
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:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
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:19
bool isValid() const
Definition: HandleBase.h:70
const_iterator end() const
edm::InputTag regularTowerTag
iterator find(key_type k)
size_type size() const
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const

Member Data Documentation

edm::InputTag CaloTowersMerger::extraTowerTag
private

Definition at line 56 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

edm::InputTag CaloTowersMerger::regularTowerTag
private

Definition at line 56 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

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

Definition at line 58 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

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

Definition at line 57 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().