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 // system include files
26 #include <memory>
27 
28 // user include files
31 
34 
36 
39 
40 //
41 // class declaration
42 //
43 
45 public:
46  explicit CaloTowersMerger(const edm::ParameterSet&);
47  ~CaloTowersMerger() override;
48 
49  CaloTower mergedTower(const CaloTower& t1, const CaloTower& t2);
50 
51 private:
52  void produce(edm::Event&, const edm::EventSetup&) override;
53 
54  // ----------member data ---------------------------
55 
59 };
60 
61 //
62 // constants, enums and typedefs
63 //
64 
65 //
66 // static data member definitions
67 //
68 
69 //
70 // constructors and destructor
71 //
73  regularTowerTag = iConfig.getParameter<edm::InputTag>("regularTowerTag");
74  extraTowerTag = iConfig.getParameter<edm::InputTag>("extraTowerTag");
75 
76  // register for data access
77  tok_reg_ = consumes<CaloTowerCollection>(regularTowerTag);
78  tok_ext_ = consumes<CaloTowerCollection>(extraTowerTag);
79 
80  //register your products
81  produces<CaloTowerCollection>();
82 }
83 
85  // do anything here that needs to be done at desctruction time
86  // (e.g. close files, deallocate resources etc.)
87 }
88 
89 //
90 // member functions
91 //
92 
93 // ------------ method called to produce the data ------------
95  edm::Handle<CaloTowerCollection> regTower, extraTower;
96 
97  iEvent.getByToken(tok_reg_, regTower);
98  iEvent.getByToken(tok_ext_, extraTower);
99 
100  if (!regTower.isValid() && !extraTower.isValid()) {
101  edm::LogError("CaloTowersMerger") << "both input tag:" << regularTowerTag << " and " << extraTowerTag
102  << " are invalid. empty merged collection";
103  iEvent.put(std::make_unique<CaloTowerCollection>());
104  return;
105  } else if (!regTower.isValid() || !extraTower.isValid()) {
106  if (!regTower.isValid() && extraTower.isValid())
107  regTower = extraTower;
108  iEvent.put(std::make_unique<CaloTowerCollection>(*regTower));
109  return;
110  } else {
111  //both valid input collections: merging
112  auto output = std::make_unique<CaloTowerCollection>();
113  output->reserve(regTower->size() + extraTower->size());
114 
115  CaloTowerCollection::const_iterator rt_begin = regTower->begin();
116  CaloTowerCollection::const_iterator rt_end = regTower->end();
117  CaloTowerCollection::const_iterator rt_it = rt_begin;
118 
119  //vector of overlapping towers
120  std::vector<CaloTowerCollection::const_iterator> overlappingTowers;
121  overlappingTowers.reserve(extraTower->size());
122 
123  for (; rt_it != rt_end; ++rt_it) {
124  CaloTowerCollection::const_iterator et_it = extraTower->find(rt_it->id());
125  if (et_it != extraTower->end()) {
126  //need to merge the components
127  //FIXME
128 
130  //one needs to merge t1 and t2 into mergedTower
131  //end FIXME
132  CaloTower mt = mergedTower(*rt_it, *et_it);
133 
134  output->push_back(mt);
135  overlappingTowers.push_back(et_it);
136 
137  } else {
138  //just copy the regular tower over
139  output->push_back(*rt_it);
140  }
141  }
142  CaloTowerCollection::const_iterator et_begin = extraTower->begin();
143  CaloTowerCollection::const_iterator et_end = extraTower->end();
144  CaloTowerCollection::const_iterator et_it = et_begin;
145  for (; et_it != et_end; ++et_it) {
146  if (std::find(overlappingTowers.begin(), overlappingTowers.end(), et_it) == overlappingTowers.end())
147  //non overlapping tower
148  //copy the extra tower over
149  output->push_back(*et_it);
150  }
151  iEvent.put(std::move(output));
152  }
153 }
154 
155 // Make a new tower by merging two towers containing exclusive hits
156 // This cannot be done fully consistently and independent of the
157 // creation mechnaism...
158 // This functionlaity it to be used only for testing the effects
159 // of rejected bad hits.
160 
162  double newOuterE = 0;
163 
164  // HO energies are always saved (even if useHO=false)
165  // make sure there is no double counting
166  // crude test if one has HO energy and the other not (possibly due to bad hit cleanup)
167  // However: for |iEta|>15 E_outer has different meening:
168  // it holds either the energy in the outer depths in HCAL, etc
169 
170  if (rt.ietaAbs() < 16 && (fabs(rt.outerEnergy() - et.outerEnergy()) < 0.00001)) {
171  // there is no differnce in the store HO energies
172  newOuterE = rt.outerEnergy();
173  } else {
174  newOuterE = rt.outerEnergy() + et.outerEnergy();
175  }
176 
177  bool rt_hasEcalConstit = false;
178  bool et_hasEcalConstit = false;
179 
180  bool rt_hasHcalConstit = false;
181  bool et_hasHcalConstit = false;
182 
183  // check if there are HCAL/ECAL constituents in the towers
184 
185  std::vector<DetId>::const_iterator rc_begin = rt.constituents().begin();
186  std::vector<DetId>::const_iterator rc_end = rt.constituents().end();
187  std::vector<DetId>::const_iterator rc_it;
188 
189  for (rc_it = rc_begin; rc_it != rc_end; ++rc_it) {
190  if (rc_it->det() == DetId::Hcal)
191  rt_hasHcalConstit = true;
192  break;
193  }
194  for (rc_it = rc_begin; rc_it != rc_end; ++rc_it) {
195  if (rc_it->det() == DetId::Ecal)
196  rt_hasEcalConstit = true;
197  break;
198  }
199 
200  std::vector<DetId>::const_iterator ec_begin = et.constituents().begin();
201  std::vector<DetId>::const_iterator ec_end = et.constituents().end();
202  std::vector<DetId>::const_iterator ec_it;
203 
204  for (ec_it = ec_begin; ec_it != ec_end; ++ec_it) {
205  if (ec_it->det() == DetId::Hcal)
206  et_hasHcalConstit = true;
207  break;
208  }
209  for (ec_it = ec_begin; ec_it != ec_end; ++ec_it) {
210  if (ec_it->det() == DetId::Ecal)
211  et_hasEcalConstit = true;
212  break;
213  }
214 
215  std::vector<DetId> combinedConstituents = rt.constituents();
216  for (ec_it = ec_begin; ec_it != ec_end; ++ec_it) {
217  // if properly resconstructed, the only possible overlap should be for HO hits that
218  // are always listed as constituents if above thereshold (old JetMET request)
219  if (std::find(combinedConstituents.begin(), combinedConstituents.end(), *ec_it) == combinedConstituents.end())
220  combinedConstituents.push_back(*ec_it);
221  }
222 
223  GlobalPoint newEmPosition(0.0, 0.0, 0.0);
224 
225  // The following assumes the current default
226  // momentum reconstruction method (1) and
227  // accepted rechits with some threshod >0
228 
229  if (rt_hasEcalConstit && et_hasEcalConstit) {
230  if (rt.emEnergy() > 0 && et.emEnergy() > 0) {
231  double sumEmE = rt.emEnergy() + et.emEnergy();
232 
233  double x = rt.emEnergy() * rt.emPosition().x() + et.emEnergy() * et.emPosition().x();
234  double y = rt.emEnergy() * rt.emPosition().y() + et.emEnergy() * et.emPosition().y();
235  double z = rt.emEnergy() * rt.emPosition().z() + et.emEnergy() * et.emPosition().z();
236 
237  GlobalPoint weightedEmdPosition(x / sumEmE, y / sumEmE, z / sumEmE);
238  newEmPosition = weightedEmdPosition;
239  }
240 
241  } else if (rt_hasEcalConstit && !et_hasEcalConstit) {
242  newEmPosition = rt.emPosition();
243  } else if (!rt_hasEcalConstit && et_hasEcalConstit) {
244  newEmPosition = et.emPosition();
245  }
246 
247  GlobalPoint newHadPosition(0.0, 0.0, 0.0);
248  // had positions are the same if there is at least one constituent
249  if (rt_hasHcalConstit) {
250  newHadPosition = rt.hadPosition();
251  } else if (et_hasHcalConstit) {
252  newHadPosition = et.hadPosition();
253  }
254 
255  // MAke the new tower and set all values
256 
257  CaloTower mergedTower(rt.id(),
258  rt.emEnergy() + et.emEnergy(),
259  rt.hadEnergy() + et.hadEnergy(),
260  newOuterE,
261  -1,
262  -1,
263  rt.p4() + et.p4(),
264  newEmPosition,
265  newHadPosition);
266 
267  mergedTower.addConstituents(combinedConstituents);
268 
269  (rt.hottestCellE() > et.hottestCellE()) ? mergedTower.setHottestCellE(rt.hottestCellE())
270  : mergedTower.setHottestCellE(et.hottestCellE());
271 
272  unsigned int numBadHcalChan = rt.numBadHcalCells() - et.numProblematicHcalCells() - rt.numRecoveredHcalCells();
273  unsigned int numBadEcalChan = rt.numBadEcalCells() - et.numProblematicEcalCells() - rt.numRecoveredEcalCells();
274 
275  unsigned int numProbHcalChan = rt.numProblematicHcalCells() + et.numProblematicHcalCells();
276  unsigned int numProbEcalChan = rt.numProblematicEcalCells() + et.numProblematicEcalCells();
277 
278  unsigned int numRecHcalChan = rt.numRecoveredHcalCells() + et.numRecoveredHcalCells();
279  unsigned int numRecEcalChan = rt.numRecoveredEcalCells() + et.numRecoveredEcalCells();
280 
282  numBadHcalChan, numBadEcalChan, numRecHcalChan, numRecEcalChan, numProbHcalChan, numProbEcalChan);
283 
284  // use timing from the good tower only (for now, in default reco we use information from good hits only)
285  // time is saved as integer but returned as float in (ns)
286  mergedTower.setEcalTime(int(rt.ecalTime() * 100.0 + 0.5));
287  mergedTower.setHcalTime(int(rt.hcalTime() * 100.0 + 0.5));
288 
289  return mergedTower;
290 }
291 
292 //define this as a plug-in
RandomServiceHelper.t2
t2
Definition: RandomServiceHelper.py:257
CaloTower::setHcalTime
void setHcalTime(int t)
Definition: CaloTower.h:84
DDAxes::y
edm::SortedCollection< CaloTower >::const_iterator
std::vector< CaloTower >::const_iterator const_iterator
Definition: SortedCollection.h:80
CaloTower.h
CaloTowersMerger::regularTowerTag
edm::InputTag regularTowerTag
Definition: CaloTowersMerger.cc:56
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
edm::EDGetTokenT
Definition: EDGetToken.h:33
CaloTowersMerger
Definition: CaloTowersMerger.cc:44
hcal_runs.rt
rt
Definition: hcal_runs.py:76
DetId::Hcal
Definition: DetId.h:28
CaloTowersMerger::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CaloTowersMerger.cc:94
CaloTower::setHottestCellE
void setHottestCellE(double e)
Definition: CaloTower.h:120
EDProducer.h
edm::SortedCollection::size
size_type size() const
Definition: SortedCollection.h:215
DDAxes::x
CaloTowersMerger::~CaloTowersMerger
~CaloTowersMerger() override
Definition: CaloTowersMerger.cc:84
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle
Definition: AssociativeIterator.h:50
MakerMacros.h
RandomServiceHelper.t1
t1
Definition: RandomServiceHelper.py:256
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
DDAxes::z
CaloTower::setCaloTowerStatus
void setCaloTowerStatus(unsigned int numBadHcalChan, unsigned int numBadEcalChan, unsigned int numRecHcalChan, unsigned int numRecEcalChan, unsigned int numProbHcalChan, unsigned int numProbEcalChan)
Definition: CaloTower.cc:221
CaloTowersMerger::tok_reg_
edm::EDGetTokenT< CaloTowerCollection > tok_reg_
Definition: CaloTowersMerger.cc:57
CaloTower::setEcalTime
void setEcalTime(int t)
Definition: CaloTower.h:83
Point3DBase< float, GlobalTag >
CaloTowersMerger::CaloTowersMerger
CaloTowersMerger(const edm::ParameterSet &)
Definition: CaloTowersMerger.cc:72
CaloTowersMerger::mergedTower
CaloTower mergedTower(const CaloTower &t1, const CaloTower &t2)
Definition: CaloTowersMerger.cc:161
CaloTowersMerger::tok_ext_
edm::EDGetTokenT< CaloTowerCollection > tok_ext_
Definition: CaloTowersMerger.cc:58
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
iEvent
int iEvent
Definition: GenABIO.cc:224
CaloTower
Definition: CaloTower.h:26
edm::stream::EDProducer
Definition: EDProducer.h:38
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
edm::EventSetup
Definition: EventSetup.h:58
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
DetId::Ecal
Definition: DetId.h:27
CaloTowersCreator.h
edm::SortedCollection::find
iterator find(key_type k)
Definition: SortedCollection.h:240
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
CaloTowersMerger::extraTowerTag
edm::InputTag extraTowerTag
Definition: CaloTowersMerger.cc:56
TtSemiLepEvtBuilder_cfi.mt
mt
Definition: TtSemiLepEvtBuilder_cfi.py:47
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ParameterSet.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
CaloTower::addConstituents
void addConstituents(const std::vector< DetId > &ids)
Definition: CaloTower.cc:199