CMS 3D CMS Logo

CaloTowersMerger.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CaloTowersMerger
4 // Class: CaloTowersMerger
5 //
13 //
14 // Original Author: Jean-Roch Vlimant,40 3-A28,+41227671209,
15 // Created: Thu Nov 4 16:36:30 CET 2010
16 //
17 //
18 
19 // Anton Anastassov (Northwestern):
20 // Add code for actual tower merging, define two distinct inputs of
21 // "regular" and "extra" towers
22 // This functionality is subject to some restrictions
23 // (see notes below)
24 
25 
26 
27 // system include files
28 #include <memory>
29 
30 // user include files
33 
36 
38 
41 
42 //
43 // class declaration
44 //
45 
47 public:
48  explicit CaloTowersMerger(const edm::ParameterSet&);
49  ~CaloTowersMerger() override;
50 
51  CaloTower mergedTower(const CaloTower& t1, const CaloTower& t2);
52 
53 private:
54  void produce(edm::Event&, const edm::EventSetup&) override;
55 
56  // ----------member data ---------------------------
57 
61 };
62 
63 //
64 // constants, enums and typedefs
65 //
66 
67 
68 //
69 // static data member definitions
70 //
71 
72 //
73 // constructors and destructor
74 //
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 }
87 
88 
90 {
91 
92  // do anything here that needs to be done at desctruction time
93  // (e.g. close files, deallocate resources etc.)
94 
95 }
96 
97 
98 //
99 // member functions
100 //
101 
102 // ------------ method called to produce the data ------------
103 void
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 }
166 
167 
168 // Make a new tower by merging two towers containing exclusive hits
169 // This cannot be done fully consistently and independent of the
170 // creation mechnaism...
171 // This functionlaity it to be used only for testing the effects
172 // of rejected bad hits.
173 
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())?
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 }
313 
314 
315 
316 //define this as a plug-in
edm::EDGetTokenT< CaloTowerCollection > tok_reg_
unsigned int numRecoveredEcalCells() const
Definition: CaloTower.h:197
T getParameter(std::string const &) const
CaloTower mergedTower(const CaloTower &t1, const CaloTower &t2)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
math::PtEtaPhiMLorentzVector p4(double vtxZ) const
Definition: CaloTower.cc:129
CaloTowersMerger(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setCaloTowerStatus(unsigned int numBadHcalChan, unsigned int numBadEcalChan, unsigned int numRecHcalChan, unsigned int numRecEcalChan, unsigned int numProbHcalChan, unsigned int numProbEcalChan)
Definition: CaloTower.cc:199
float ecalTime() const
Definition: CaloTower.h:181
edm::EDGetTokenT< CaloTowerCollection > tok_ext_
std::vector< CaloTower >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:63
edm::InputTag extraTowerTag
unsigned int numRecoveredHcalCells() const
Definition: CaloTower.h:201
unsigned int numBadHcalCells() const
Definition: CaloTower.h:200
double hottestCellE() const
Definition: CaloTower.h:148
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const GlobalPoint & emPosition() const
Definition: CaloTower.h:160
void setHottestCellE(double e)
Definition: CaloTower.h:97
unsigned int numBadEcalCells() const
Definition: CaloTower.h:196
void addConstituents(const std::vector< DetId > &ids)
Definition: CaloTower.cc:177
int iEvent
Definition: GenABIO.cc:230
double emEnergy() const
Definition: CaloTower.h:110
const GlobalPoint & hadPosition() const
Definition: CaloTower.h:161
T z() const
Definition: PV3DBase.h:64
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:104
bool isValid() const
Definition: HandleBase.h:74
double hadEnergy() const
Definition: CaloTower.h:111
const_iterator end() const
void produce(edm::Event &, const edm::EventSetup &) override
CaloTowerDetId id() const
Definition: CaloTower.h:103
unsigned int numProblematicEcalCells() const
Definition: CaloTower.h:198
edm::InputTag regularTowerTag
float hcalTime() const
Definition: CaloTower.h:182
unsigned int numProblematicHcalCells() const
Definition: CaloTower.h:202
~CaloTowersMerger() override
et
define resolution functions of each parameter
int ietaAbs() const
Definition: CaloTower.h:186
void setEcalTime(int t)
Definition: CaloTower.h:70
iterator find(key_type k)
size_type size() const
void setHcalTime(int t)
Definition: CaloTower.h:71
T x() const
Definition: PV3DBase.h:62
def move(src, dest)
Definition: eostools.py:511
double outerEnergy() const
Definition: CaloTower.h:112
const_iterator begin() const