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 (CaloTower t1, CaloTower t2)
 
 ~CaloTowersMerger ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
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 ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

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

Private Attributes

edm::InputTag extraTowerTag
 
edm::InputTag regularTowerTag
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- 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::EDProducer
CurrentProcessingContext const * currentContext () const
 
- 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 47 of file CaloTowersMerger.cc.

Constructor & Destructor Documentation

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

Definition at line 76 of file CaloTowersMerger.cc.

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

77 {
78  regularTowerTag=iConfig.getParameter<edm::InputTag>("regularTowerTag");
79  extraTowerTag=iConfig.getParameter<edm::InputTag>("extraTowerTag");
80 
81  //register your products
82  produces<CaloTowerCollection>();
83 }
T getParameter(std::string const &) const
edm::InputTag extraTowerTag
edm::InputTag regularTowerTag
CaloTowersMerger::~CaloTowersMerger ( )

Definition at line 86 of file CaloTowersMerger.cc.

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

Member Function Documentation

void CaloTowersMerger::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 170 of file CaloTowersMerger.cc.

171 {
172 }
void CaloTowersMerger::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 176 of file CaloTowersMerger.cc.

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

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

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

Implements edm::EDProducer.

Definition at line 101 of file CaloTowersMerger.cc.

References extraTowerTag, spr::find(), edm::Event::getByLabel(), edm::HandleBase::isValid(), mergedTower(), convertSQLitetoXML_cfg::output, edm::Event::put(), and regularTowerTag.

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

Member Data Documentation

edm::InputTag CaloTowersMerger::extraTowerTag
private

Definition at line 61 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().

edm::InputTag CaloTowersMerger::regularTowerTag
private

Definition at line 61 of file CaloTowersMerger.cc.

Referenced by CaloTowersMerger(), and produce().