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 // $Id: CaloTowersMerger.cc,v 1.2 2010/11/24 19:52:16 anastass Exp $
17 //
18 //
19 
20 // Anton Anastassov (Northwestern):
21 // Add code for actual tower merging, define two distinct inputs of
22 // "regular" and "extra" towers
23 // This functionality is subject to some restrictions
24 // (see notes below)
25 
26 
27 
28 // system include files
29 #include <memory>
30 
31 // user include files
34 
37 
39 
42 
43 //
44 // class declaration
45 //
46 
48  public:
49  explicit CaloTowersMerger(const edm::ParameterSet&);
51 
53 
54  private:
55  virtual void beginJob() ;
56  virtual void produce(edm::Event&, const edm::EventSetup&);
57  virtual void endJob() ;
58 
59  // ----------member data ---------------------------
60 
62 };
63 
64 //
65 // constants, enums and typedefs
66 //
67 
68 
69 //
70 // static data member definitions
71 //
72 
73 //
74 // constructors and destructor
75 //
77 {
78  regularTowerTag=iConfig.getParameter<edm::InputTag>("regularTowerTag");
79  extraTowerTag=iConfig.getParameter<edm::InputTag>("extraTowerTag");
80 
81  //register your products
82  produces<CaloTowerCollection>();
83 }
84 
85 
87 {
88 
89  // do anything here that needs to be done at desctruction time
90  // (e.g. close files, deallocate resources etc.)
91 
92 }
93 
94 
95 //
96 // member functions
97 //
98 
99 // ------------ method called to produce the data ------------
100 void
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 }
167 
168 // ------------ method called once each job just before starting event loop ------------
169 void
171 {
172 }
173 
174 // ------------ method called once each job just after ending the event loop ------------
175 void
177 }
178 
179 
180 
181 
182 
183 // Make a new tower by merging two towers containing exclusive hits
184 // This cannot be done fully consistently and independent of the
185 // creation mechnaism...
186 // This functionlaity it to be used only for testing the effects
187 // of rejected bad hits.
188 
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())?
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 }
328 
329 
330 
331 //define this as a plug-in
unsigned int numRecoveredEcalCells() const
Definition: CaloTower.h:166
T getParameter(std::string const &) const
CaloTower mergedTower(CaloTower t1, CaloTower t2)
math::PtEtaPhiMLorentzVector p4(double vtxZ) const
Definition: CaloTower.cc:105
CaloTowersMerger(const edm::ParameterSet &)
#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:175
float ecalTime() const
Definition: CaloTower.h:150
std::vector< CaloTower >::const_iterator const_iterator
T y() const
Definition: PV3DBase.h:62
edm::InputTag extraTowerTag
unsigned int numRecoveredHcalCells() const
Definition: CaloTower.h:170
unsigned int numBadHcalCells() const
Definition: CaloTower.h:169
double hottestCellE() const
Definition: CaloTower.h:117
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:129
double double double z
void setHottestCellE(double e)
Definition: CaloTower.h:66
virtual void endJob()
virtual void produce(edm::Event &, const edm::EventSetup &)
unsigned int numBadEcalCells() const
Definition: CaloTower.h:165
void addConstituents(const std::vector< DetId > &ids)
Definition: CaloTower.cc:153
int iEvent
Definition: GenABIO.cc:243
double emEnergy() const
Definition: CaloTower.h:79
const GlobalPoint & hadPosition() const
Definition: CaloTower.h:130
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
T z() const
Definition: PV3DBase.h:63
const std::vector< DetId > & constituents() const
Definition: CaloTower.h:73
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
double hadEnergy() const
Definition: CaloTower.h:80
CaloTowerDetId id() const
Definition: CaloTower.h:72
unsigned int numProblematicEcalCells() const
Definition: CaloTower.h:167
edm::InputTag regularTowerTag
float hcalTime() const
Definition: CaloTower.h:151
unsigned int numProblematicHcalCells() const
Definition: CaloTower.h:171
int ietaAbs() const
Definition: CaloTower.h:155
void setEcalTime(int t)
Definition: CaloTower.h:53
edm::SortedCollection< CaloTower > CaloTowerCollection
Definition: CaloTowerFwd.h:15
x
Definition: VDTMath.h:216
void setHcalTime(int t)
Definition: CaloTower.h:54
T x() const
Definition: PV3DBase.h:61
virtual void beginJob()
double outerEnergy() const
Definition: CaloTower.h:81