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 hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () 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 46 of file CaloTowersMerger.cc.

Constructor & Destructor Documentation

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

Definition at line 75 of file CaloTowersMerger.cc.

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

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

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

Member Function Documentation

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

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

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

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

Member Data Documentation

edm::InputTag CaloTowersMerger::extraTowerTag
private

Definition at line 58 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

edm::InputTag CaloTowersMerger::regularTowerTag
private

Definition at line 58 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

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

Definition at line 60 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

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

Definition at line 59 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().