CMS 3D CMS Logo

CaloCleaner.h
Go to the documentation of this file.
1 
13 #ifndef TauAnalysis_MCEmbeddingTools_CaloCleaner_H
14 #define TauAnalysis_MCEmbeddingTools_CaloCleaner_H
15 
23 
27 
30 
31 #include <string>
32 #include <iostream>
33 #include <map>
34 
35 template <typename T>
37 public:
38  explicit CaloCleaner(const edm::ParameterSet&);
39  ~CaloCleaner() override;
40 
41 private:
42  void produce(edm::Event&, const edm::EventSetup&) override;
43 
45 
47 
48  std::map<std::string, edm::EDGetTokenT<RecHitCollection> > inputs_;
49 
52 
54  void fill_correction_map(TrackDetMatchInfo*, std::map<uint32_t, float>*);
55 };
56 
57 template <typename T>
59  : mu_input_(consumes<edm::View<pat::Muon> >(iConfig.getParameter<edm::InputTag>("MuonCollection"))) {
60  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("oldCollection");
61  for (auto inCollection : inCollections) {
62  inputs_[inCollection.instance()] = consumes<RecHitCollection>(inCollection);
63  produces<RecHitCollection>(inCollection.instance());
64  }
65 
66  is_preshower_ = iConfig.getUntrackedParameter<bool>("is_preshower", false);
67  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
68  edm::ConsumesCollector iC = consumesCollector();
70  //trackAssociator_.useDefaultPropagator();
71 }
72 
73 template <typename T>
75  // nothing to be done yet...
76 }
77 
78 template <typename T>
81  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
82  trackAssociator_.setPropagator(propagator.product());
83 
85  iEvent.getByToken(mu_input_, muonHandle);
86  edm::View<pat::Muon> muons = *muonHandle;
87 
88  std::map<uint32_t, float> correction_map;
89 
90  // Fill the correction map
91  for (edm::View<pat::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
92  // get the basic informaiton like fill reco mouon does
93  // RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc
94  const reco::Track* track = nullptr;
95  if (iMuon->track().isNonnull())
96  track = iMuon->track().get();
97  else if (iMuon->standAloneMuon().isNonnull())
98  track = iMuon->standAloneMuon().get();
99  else
100  throw cms::Exception("FatalError")
101  << "Failed to fill muon id information for a muon with undefined references to tracks";
103  trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any);
104  fill_correction_map(&info, &correction_map);
105  }
106 
107  // Copy the old collection and correct if necessary
108  for (auto input_ : inputs_) {
109  std::unique_ptr<RecHitCollection> recHitCollection_output(new RecHitCollection());
110  edm::Handle<RecHitCollection> recHitCollection;
111  // iEvent.getByToken(input_.second[0], recHitCollection);
112  iEvent.getByToken(input_.second, recHitCollection);
113  for (typename RecHitCollection::const_iterator recHit = recHitCollection->begin();
114  recHit != recHitCollection->end();
115  ++recHit) {
116  if (correction_map[recHit->detid().rawId()] > 0) {
117  float new_energy = recHit->energy() - correction_map[recHit->detid().rawId()];
118  if (new_energy <= 0)
119  continue; // Do not save empty Hits
120  T newRecHit(*recHit);
121  newRecHit.setEnergy(new_energy);
122  recHitCollection_output->push_back(newRecHit);
123  } else {
124  recHitCollection_output->push_back(*recHit);
125  }
126  /* For the inveted collection
127  if (correction_map[recHit->detid().rawId()] > 0){
128  float new_energy = correction_map[recHit->detid().rawId()];
129  if (new_energy < 0) new_energy =0;
130  T newRecHit(*recHit);
131  newRecHit.setEnergy(new_energy);
132  recHitCollection_output->push_back(newRecHit);
133  }*/
134  }
135  // Save the new collection
136  recHitCollection_output->sort();
137  iEvent.put(std::move(recHitCollection_output), input_.first);
138  }
139 }
140 #endif
PDWG_BPHSkim_cff.muons
muons
Definition: PDWG_BPHSkim_cff.py:47
Handle.h
TrackDetectorAssociator::Any
Definition: TrackDetectorAssociator.h:55
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
sistrip::View
View
Definition: ConstantsForView.h:26
TrackDetectorAssociator.h
CaloCleaner::mu_input_
const edm::EDGetTokenT< edm::View< pat::Muon > > mu_input_
Definition: CaloCleaner.h:46
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
CaloCleaner::fill_correction_map
void fill_correction_map(TrackDetMatchInfo *, std::map< uint32_t, float > *)
Definition: CaloCleaner.cc:22
EDProducer.h
edm::SortedCollection
Definition: SortedCollection.h:49
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::Handle
Definition: AssociativeIterator.h:50
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
Muon
Definition: Muon.py:1
CaloCleaner::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CaloCleaner.h:79
parameters
parameters
Definition: BeamSpot_PayloadInspector.cc:14
CaloCleaner::RecHitCollection
edm::SortedCollection< T > RecHitCollection
Definition: CaloCleaner.h:44
MakerMacros.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
CaloCleaner
Definition: CaloCleaner.h:36
reco::Track
Definition: Track.h:27
edm::ESHandle< Propagator >
TrackAssociatorParameters::loadParameters
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
Definition: TrackAssociatorParameters.cc:18
edm::View
Definition: CaloClusterFwd.h:14
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
TrackDetectorAssociator
Definition: TrackDetectorAssociator.h:49
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
get
#define get
CaloCleaner::inputs_
std::map< std::string, edm::EDGetTokenT< RecHitCollection > > inputs_
Definition: CaloCleaner.h:48
EcalRecHit.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
TrackDetMatchInfo
Definition: TrackDetMatchInfo.h:14
CaloCleaner::~CaloCleaner
~CaloCleaner() override
Definition: CaloCleaner.h:74
eostools.move
def move(src, dest)
Definition: eostools.py:511
T
long double T
Definition: Basic3DVectorLD.h:48
CaloCleaner::trackAssociator_
TrackDetectorAssociator trackAssociator_
Definition: CaloCleaner.h:50
TrackingComponentsRecord.h
SortedCollection.h
Exception
Definition: hltDiff.cc:246
CaloCleaner::is_preshower_
bool is_preshower_
Definition: CaloCleaner.h:53
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
HLT_2018_cff.track
track
Definition: HLT_2018_cff.py:10352
ParameterSet.h
CaloCleaner::CaloCleaner
CaloCleaner(const edm::ParameterSet &)
Definition: CaloCleaner.h:58
edm::Event
Definition: Event.h:73
MuonEnergy.h
TrackAssociatorParameters.h
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
CaloCleaner::parameters_
TrackAssociatorParameters parameters_
Definition: CaloCleaner.h:51
TrackAssociatorParameters
Definition: TrackAssociatorParameters.h:34
TrackingComponentsRecord
Definition: TrackingComponentsRecord.h:12