test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

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

Private Attributes

edm::InputTag extraTowerTag
 
edm::InputTag regularTowerTag
 
edm::EDGetTokenT
< CaloTowerCollection
tok_ext_
 
edm::EDGetTokenT
< CaloTowerCollection
tok_reg_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- 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::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- 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 ( )

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 175 of file CaloTowersMerger.cc.

176 {
177 }
void CaloTowersMerger::endJob ( void  )
overrideprivatevirtual

Reimplemented from edm::EDProducer.

Definition at line 181 of file CaloTowersMerger.cc.

181  {
182 }
CaloTower CaloTowersMerger::mergedTower ( const CaloTower t1,
const CaloTower t2 
)

Definition at line 194 of file CaloTowersMerger.cc.

References CaloTower::addConstituents(), CaloTower::constituents(), 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(), detailsBasic3DVector::y, PV3DBase< T, PVType, FrameType >::y(), detailsBasic3DVector::z, and PV3DBase< T, PVType, FrameType >::z().

Referenced by produce().

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

Implements edm::EDProducer.

Definition at line 106 of file CaloTowersMerger.cc.

References extraTowerTag, spr::find(), edm::Event::getByToken(), edm::HandleBase::isValid(), mergedTower(), convertSQLitetoXML_cfg::output, edm::Event::put(), regularTowerTag, 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  std::auto_ptr<CaloTowerCollection> output;
114 
115  if (!regTower.isValid() && !extraTower.isValid()){
116  edm::LogError("CaloTowersMerger")<<"both input tag:"<<regularTowerTag<<" and "<<extraTowerTag<<" are invalid. empty merged collection";
117  output.reset(new CaloTowerCollection());
118  iEvent.put(output);
119  return;
120  }else if (!regTower.isValid() || !extraTower.isValid()){
121  if (!regTower.isValid() && extraTower.isValid())
122  regTower=extraTower;
123  output.reset(new CaloTowerCollection(*regTower));
124  iEvent.put(output);
125  return;
126  }
127  else{
128  //both valid input collections: merging
129  output.reset(new CaloTowerCollection());
130  output->reserve(regTower->size()+extraTower->size());
131 
132  CaloTowerCollection::const_iterator rt_begin = regTower->begin();
133  CaloTowerCollection::const_iterator rt_end = regTower->end();
134  CaloTowerCollection::const_iterator rt_it = rt_begin;
135 
136  //vector of overlapping towers
137  std::vector<CaloTowerCollection::const_iterator> overlappingTowers;
138  overlappingTowers.reserve(extraTower->size());
139 
140  for (;rt_it!=rt_end;++rt_it){
141  CaloTowerCollection::const_iterator et_it = extraTower->find(rt_it->id());
142  if (et_it != extraTower->end()){
143  //need to merge the components
144  //FIXME
145 
147  //one needs to merge t1 and t2 into mergedTower
148  //end FIXME
149  CaloTower mt = mergedTower(*rt_it, *et_it);
150 
151  output->push_back(mt);
152  overlappingTowers.push_back(et_it);
153 
154  }else{
155  //just copy the regular tower over
156  output->push_back(*rt_it);
157  }
158  }
159  CaloTowerCollection::const_iterator et_begin = extraTower->begin();
160  CaloTowerCollection::const_iterator et_end = extraTower->end();
162  for (;et_it!=et_end;++et_it){
163  if (std::find(overlappingTowers.begin(),overlappingTowers.end(),et_it)==overlappingTowers.end())
164  //non overlapping tower
165  //copy the extra tower over
166  output->push_back(*et_it);
167  }
168  iEvent.put(output);
169  }
170 
171 }
edm::EDGetTokenT< CaloTowerCollection > tok_reg_
CaloTower mergedTower(const CaloTower &t1, const CaloTower &t2)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
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:7
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
bool isValid() const
Definition: HandleBase.h:76
edm::InputTag regularTowerTag
edm::SortedCollection< CaloTower > CaloTowerCollection
Definition: CaloTowerFwd.h:15

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().