CMS 3D CMS Logo

CaloCleaner.cc
Go to the documentation of this file.
2 
8 
14 
15 template <typename T>
17  : mu_input_(consumes<edm::View<pat::Muon>>(iConfig.getParameter<edm::InputTag>("MuonCollection"))),
18  propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))) {
19  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag>>("oldCollection");
20  for (const auto &inCollection : inCollections) {
21  inputs_[inCollection.instance()] = consumes<RecHitCollection>(inCollection);
22  produces<RecHitCollection>(inCollection.instance());
23  }
24 
25  is_preshower_ = iConfig.getUntrackedParameter<bool>("is_preshower", false);
26  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
27  edm::ConsumesCollector iC = consumesCollector();
29 }
30 
31 template <typename T>
33  // nothing to be done yet...
34 }
35 
36 template <typename T>
38  auto const &propagator = iSetup.getData(propagatorToken_);
39  trackAssociator_.setPropagator(&propagator);
40 
42  iEvent.getByToken(mu_input_, muonHandle);
43  edm::View<pat::Muon> muons = *muonHandle;
44 
45  std::map<uint32_t, float> correction_map;
46 
47  // Fill the correction map
48  for (edm::View<pat::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
49  const reco::Track *track = nullptr;
50  if (iMuon->track().isNonnull())
51  track = iMuon->track().get();
52  else if (iMuon->standAloneMuon().isNonnull())
53  track = iMuon->standAloneMuon().get();
54  else
55  throw cms::Exception("FatalError")
56  << "Failed to fill muon id information for a muon with undefined references to tracks";
58  trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any);
59  fill_correction_map(&info, &correction_map);
60  }
61 
62  // Copy the old collection and correct if necessary
63  for (auto input_ : inputs_) {
64  std::unique_ptr<RecHitCollection> recHitCollection_output(new RecHitCollection());
65  edm::Handle<RecHitCollection> recHitCollection;
66  iEvent.getByToken(input_.second, recHitCollection);
67  for (typename RecHitCollection::const_iterator recHit = recHitCollection->begin();
68  recHit != recHitCollection->end();
69  ++recHit) {
70  if (correction_map[recHit->detid().rawId()] > 0) {
71  float new_energy = recHit->energy() - correction_map[recHit->detid().rawId()];
72  if (new_energy <= 0)
73  continue; // Do not save empty Hits
74  T newRecHit(*recHit);
75  newRecHit.setEnergy(new_energy);
76  recHitCollection_output->push_back(newRecHit);
77  } else {
78  recHitCollection_output->push_back(*recHit);
79  }
80  }
81  // Save the new collection
82  recHitCollection_output->sort();
83  iEvent.put(std::move(recHitCollection_output), input_.first);
84  }
85 }
86 
87 //-------------------------------------------------------------------------------
88 // define 'buildRecHit' functions used for different types of recHits
89 //-------------------------------------------------------------------------------
90 
91 template <typename T>
92 void CaloCleaner<T>::fill_correction_map(TrackDetMatchInfo *, std::map<uint32_t, float> *) {
93  assert(0);
94 }
95 
96 template <>
97 void CaloCleaner<EcalRecHit>::fill_correction_map(TrackDetMatchInfo *info, std::map<uint32_t, float> *cor_map) {
98  if (is_preshower_) {
99  for (std::vector<DetId>::const_iterator detId = info->crossedPreshowerIds.begin();
100  detId != info->crossedPreshowerIds.end();
101  ++detId) {
102  (*cor_map)[detId->rawId()] = 9999999; // just remove all energy (Below 0 is not possible)
103  }
104  } else {
105  for (std::vector<const EcalRecHit *>::const_iterator hit = info->crossedEcalRecHits.begin();
106  hit != info->crossedEcalRecHits.end();
107  hit++) {
108  (*cor_map)[(*hit)->detid().rawId()] = (*hit)->energy();
109  }
110  }
111 }
112 
113 template <>
114 void CaloCleaner<HBHERecHit>::fill_correction_map(TrackDetMatchInfo *info, std::map<uint32_t, float> *cor_map) {
115  for (std::vector<const HBHERecHit *>::const_iterator hit = info->crossedHcalRecHits.begin();
116  hit != info->crossedHcalRecHits.end();
117  hit++) {
118  (*cor_map)[(*hit)->detid().rawId()] = (*hit)->energy();
119  }
120 }
121 
122 template <>
123 void CaloCleaner<HORecHit>::fill_correction_map(TrackDetMatchInfo *info, std::map<uint32_t, float> *cor_map) {
124  for (std::vector<const HORecHit *>::const_iterator hit = info->crossedHORecHits.begin();
125  hit != info->crossedHORecHits.end();
126  hit++) {
127  (*cor_map)[(*hit)->detid().rawId()] = (*hit)->energy();
128  }
129 }
130 
131 template <>
132 void CaloCleaner<HFRecHit>::fill_correction_map(TrackDetMatchInfo *info, std::map<uint32_t, float> *cor_map) {
133  return; // No corrections for HF
134 }
135 
136 template <>
137 void CaloCleaner<ZDCRecHit>::fill_correction_map(TrackDetMatchInfo *info, std::map<uint32_t, float> *cor_map) {
138  return; // No corrections for ZDC
139 }
140 
144 // no need for cleaning outside of tracker, so just a copy of the old collection
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static const TGPicture * info(bool iBackgroundIsBlack)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
void fill_correction_map(TrackDetMatchInfo *, std::map< uint32_t, float > *)
Definition: CaloCleaner.cc:92
CaloCleaner< HORecHit > HORecHitColCleaner
Definition: CaloCleaner.cc:12
std::vector< T >::const_iterator const_iterator
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
CaloCleaner< HBHERecHit > HBHERecHitColCleaner
Definition: CaloCleaner.cc:10
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
Definition: DiMuonV_cfg.py:214
assert(be >=bs)
CaloCleaner< EcalRecHit > EcalRecHitColCleaner
Definition: CaloCleaner.cc:9
CaloCleaner< ZDCRecHit > ZDCRecHitColCleaner
Definition: CaloCleaner.cc:13
Definition: HeavyIon.h:7
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CaloCleaner.cc:37
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
CaloCleaner< HFRecHit > HFRecHitColCleaner
Definition: CaloCleaner.cc:11
Definition: Muon.py:1
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool is_preshower_
Definition: CaloCleaner.h:52
CaloCleaner(const edm::ParameterSet &)
Definition: CaloCleaner.cc:16
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
TrackAssociatorParameters parameters_
Definition: CaloCleaner.h:50
std::map< std::string, edm::EDGetTokenT< RecHitCollection > > inputs_
Definition: CaloCleaner.h:46
~CaloCleaner() override
Definition: CaloCleaner.cc:32
long double T
def move(src, dest)
Definition: eostools.py:511