test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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&);
50 
51  CaloTower mergedTower(const CaloTower& t1, const CaloTower& t2);
52 
53  private:
54  virtual void beginJob() override ;
55  virtual void produce(edm::Event&, const edm::EventSetup&) override;
56  virtual void endJob() override ;
57 
58  // ----------member data ---------------------------
59 
63 };
64 
65 //
66 // constants, enums and typedefs
67 //
68 
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
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 }
89 
90 
92 {
93 
94  // do anything here that needs to be done at desctruction time
95  // (e.g. close files, deallocate resources etc.)
96 
97 }
98 
99 
100 //
101 // member functions
102 //
103 
104 // ------------ method called to produce the data ------------
105 void
107 {
108  edm::Handle<CaloTowerCollection> regTower,extraTower;
109 
110  iEvent.getByToken(tok_reg_,regTower);
111  iEvent.getByToken(tok_ext_,extraTower);
112 
113  if (!regTower.isValid() && !extraTower.isValid()){
114  edm::LogError("CaloTowersMerger")<<"both input tag:"<<regularTowerTag<<" and "<<extraTowerTag<<" are invalid. empty merged collection";
115  iEvent.put(std::make_unique<CaloTowerCollection>());
116  return;
117  }else if (!regTower.isValid() || !extraTower.isValid()){
118  if (!regTower.isValid() && extraTower.isValid())
119  regTower=extraTower;
120  iEvent.put(std::make_unique<CaloTowerCollection>(*regTower));
121  return;
122  }
123  else{
124  //both valid input collections: merging
125  auto output = std::make_unique<CaloTowerCollection>();
126  output->reserve(regTower->size()+extraTower->size());
127 
128  CaloTowerCollection::const_iterator rt_begin = regTower->begin();
129  CaloTowerCollection::const_iterator rt_end = regTower->end();
130  CaloTowerCollection::const_iterator rt_it = rt_begin;
131 
132  //vector of overlapping towers
133  std::vector<CaloTowerCollection::const_iterator> overlappingTowers;
134  overlappingTowers.reserve(extraTower->size());
135 
136  for (;rt_it!=rt_end;++rt_it){
137  CaloTowerCollection::const_iterator et_it = extraTower->find(rt_it->id());
138  if (et_it != extraTower->end()){
139  //need to merge the components
140  //FIXME
141 
143  //one needs to merge t1 and t2 into mergedTower
144  //end FIXME
145  CaloTower mt = mergedTower(*rt_it, *et_it);
146 
147  output->push_back(mt);
148  overlappingTowers.push_back(et_it);
149 
150  }else{
151  //just copy the regular tower over
152  output->push_back(*rt_it);
153  }
154  }
155  CaloTowerCollection::const_iterator et_begin = extraTower->begin();
156  CaloTowerCollection::const_iterator et_end = extraTower->end();
158  for (;et_it!=et_end;++et_it){
159  if (std::find(overlappingTowers.begin(),overlappingTowers.end(),et_it)==overlappingTowers.end())
160  //non overlapping tower
161  //copy the extra tower over
162  output->push_back(*et_it);
163  }
164  iEvent.put(std::move(output));
165  }
166 
167 }
168 
169 // ------------ method called once each job just before starting event loop ------------
170 void
172 {
173 }
174 
175 // ------------ method called once each job just after ending the event loop ------------
176 void
178 }
179 
180 
181 
182 
183 
184 // Make a new tower by merging two towers containing exclusive hits
185 // This cannot be done fully consistently and independent of the
186 // creation mechnaism...
187 // This functionlaity it to be used only for testing the effects
188 // of rejected bad hits.
189 
191 
192  double newOuterE = 0;
193 
194  // HO energies are always saved (even if useHO=false)
195  // make sure there is no double counting
196  // crude test if one has HO energy and the other not (possibly due to bad hit cleanup)
197  // However: for |iEta|>15 E_outer has different meening:
198  // it holds either the energy in the outer depths in HCAL, etc
199 
200  if (rt.ietaAbs()<16 && (fabs(rt.outerEnergy()-et.outerEnergy())<0.00001 ) ) {
201  // there is no differnce in the store HO energies
202  newOuterE = rt.outerEnergy();
203  }
204  else {
205  newOuterE = rt.outerEnergy()+et.outerEnergy();
206  }
207 
208 
209  bool rt_hasEcalConstit = false;
210  bool et_hasEcalConstit = false;
211 
212  bool rt_hasHcalConstit = false;
213  bool et_hasHcalConstit = false;
214 
215 
216  // check if there are HCAL/ECAL constituents in the towers
217 
218  std::vector<DetId>::const_iterator rc_begin=rt.constituents().begin();
219  std::vector<DetId>::const_iterator rc_end=rt.constituents().end();
220  std::vector<DetId>::const_iterator rc_it;
221 
222 
223  for (rc_it=rc_begin; rc_it!=rc_end; ++rc_it) {
224  if (rc_it->det()==DetId::Hcal) rt_hasHcalConstit=true;
225  break;
226  }
227  for (rc_it=rc_begin; rc_it!=rc_end; ++rc_it) {
228  if (rc_it->det()==DetId::Ecal) rt_hasEcalConstit=true;
229  break;
230  }
231 
232  std::vector<DetId>::const_iterator ec_begin=et.constituents().begin();
233  std::vector<DetId>::const_iterator ec_end=et.constituents().end();
234  std::vector<DetId>::const_iterator ec_it;
235 
236  for (ec_it=ec_begin; ec_it!=ec_end; ++ec_it) {
237  if (ec_it->det()==DetId::Hcal) et_hasHcalConstit=true;
238  break;
239  }
240  for (ec_it=ec_begin; ec_it!=ec_end; ++ec_it) {
241  if (ec_it->det()==DetId::Ecal) et_hasEcalConstit=true;
242  break;
243  }
244 
245 
246  std::vector<DetId> combinedConstituents = rt.constituents();
247  for (ec_it=ec_begin; ec_it!=ec_end; ++ec_it) {
248  // if properly resconstructed, the only possible overlap should be for HO hits that
249  // are always listed as constituents if above thereshold (old JetMET request)
250  if (std::find(combinedConstituents.begin(),combinedConstituents.end(), *ec_it)==combinedConstituents.end())
251  combinedConstituents.push_back(*ec_it);
252  }
253 
254 
255 
256  GlobalPoint newEmPosition(0.0, 0.0, 0.0);
257 
258  // The following assumes the current default
259  // momentum reconstruction method (1) and
260  // accepted rechits with some threshod >0
261 
262 
263  if (rt_hasEcalConstit && et_hasEcalConstit) {
264 
265  if (rt.emEnergy()>0 && et.emEnergy()>0) {
266  double sumEmE = rt.emEnergy()+ et.emEnergy();
267 
268  double x = rt.emEnergy()*rt.emPosition().x() + et.emEnergy()*et.emPosition().x();
269  double y = rt.emEnergy()*rt.emPosition().y() + et.emEnergy()*et.emPosition().y();
270  double z = rt.emEnergy()*rt.emPosition().z() + et.emEnergy()*et.emPosition().z();
271 
272  GlobalPoint weightedEmdPosition(x/sumEmE,y/sumEmE,z/sumEmE);
273  newEmPosition = weightedEmdPosition;
274  }
275 
276 
277  }
278  else if (rt_hasEcalConstit && !et_hasEcalConstit) {
279  newEmPosition = rt.emPosition();
280  }
281  else if (!rt_hasEcalConstit && et_hasEcalConstit) {
282  newEmPosition = et.emPosition();
283  }
284 
285 
286  GlobalPoint newHadPosition(0.0, 0.0, 0.0);
287  // had positions are the same if there is at least one constituent
288  if (rt_hasHcalConstit) {
289  newHadPosition = rt.hadPosition();
290  }
291  else if (et_hasHcalConstit) {
292  newHadPosition = et.hadPosition();
293  }
294 
295 
296  // MAke the new tower and set all values
297 
298  CaloTower mergedTower(rt.id(), rt.emEnergy()+et.emEnergy(), rt.hadEnergy()+et.hadEnergy(), newOuterE, -1, -1,
299  rt.p4()+et.p4(), newEmPosition, newHadPosition);
300 
301  mergedTower.addConstituents(combinedConstituents);
302 
303  (rt.hottestCellE() > et.hottestCellE())?
306 
307  unsigned int numBadHcalChan = rt.numBadHcalCells() - et.numProblematicHcalCells() - rt.numRecoveredHcalCells();
308  unsigned int numBadEcalChan = rt.numBadEcalCells() - et.numProblematicEcalCells() - rt.numRecoveredEcalCells();
309 
310  unsigned int numProbHcalChan = rt.numProblematicHcalCells() + et.numProblematicHcalCells();
311  unsigned int numProbEcalChan = rt.numProblematicEcalCells() + et.numProblematicEcalCells();
312 
313  unsigned int numRecHcalChan = rt.numRecoveredHcalCells() + et.numRecoveredHcalCells();
314  unsigned int numRecEcalChan = rt.numRecoveredEcalCells() + et.numRecoveredEcalCells();
315 
316  mergedTower.setCaloTowerStatus(numBadHcalChan, numBadEcalChan,
317  numRecHcalChan, numRecEcalChan,
318  numProbHcalChan, numProbEcalChan);
319 
320  // use timing from the good tower only (for now, in default reco we use information from good hits only)
321  // time is saved as integer but returned as float in (ns)
322  mergedTower.setEcalTime( int(rt.ecalTime()*100.0 + 0.5) );
323  mergedTower.setHcalTime( int(rt.hcalTime()*100.0 + 0.5) );
324 
325 
326  return mergedTower;
327 
328 }
329 
330 
331 
332 //define this as a plug-in
edm::EDGetTokenT< CaloTowerCollection > tok_reg_
unsigned int numRecoveredEcalCells() const
Definition: CaloTower.h:194
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:122
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:457
virtual void endJob() override
#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:178
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:198
unsigned int numBadHcalCells() const
Definition: CaloTower.h:197
double hottestCellE() const
Definition: CaloTower.h:145
virtual void beginJob() override
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
const GlobalPoint & emPosition() const
Definition: CaloTower.h:157
void setHottestCellE(double e)
Definition: CaloTower.h:94
unsigned int numBadEcalCells() const
Definition: CaloTower.h:193
void addConstituents(const std::vector< DetId > &ids)
Definition: CaloTower.cc:177
int iEvent
Definition: GenABIO.cc:230
double emEnergy() const
Definition: CaloTower.h:107
const GlobalPoint & hadPosition() const
Definition: CaloTower.h:158
auto const T2 &decltype(t1.eta()) t2
Definition: deltaR.h:16
T z() const
Definition: PV3DBase.h:64
def move
Definition: eostools.py:510
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:101
bool isValid() const
Definition: HandleBase.h:75
double hadEnergy() const
Definition: CaloTower.h:108
virtual void produce(edm::Event &, const edm::EventSetup &) override
CaloTowerDetId id() const
Definition: CaloTower.h:100
unsigned int numProblematicEcalCells() const
Definition: CaloTower.h:195
edm::InputTag regularTowerTag
float hcalTime() const
Definition: CaloTower.h:179
unsigned int numProblematicHcalCells() const
Definition: CaloTower.h:199
int ietaAbs() const
Definition: CaloTower.h:183
void setEcalTime(int t)
Definition: CaloTower.h:67
void setHcalTime(int t)
Definition: CaloTower.h:68
T x() const
Definition: PV3DBase.h:62
double outerEnergy() const
Definition: CaloTower.h:109