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_;
50 
53 
55  void fill_correction_map(TrackDetMatchInfo*, std::map<uint32_t, float>*);
56 };
57 
58 template <typename T>
60  : mu_input_(consumes<edm::View<pat::Muon> >(iConfig.getParameter<edm::InputTag>("MuonCollection"))),
61  propagatorToken_(esConsumes(edm::ESInputTag("", "SteppingHelixPropagatorAny"))) {
62  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("oldCollection");
63  for (const auto& inCollection : inCollections) {
64  inputs_[inCollection.instance()] = consumes<RecHitCollection>(inCollection);
65  produces<RecHitCollection>(inCollection.instance());
66  }
67 
68  is_preshower_ = iConfig.getUntrackedParameter<bool>("is_preshower", false);
69  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
70  edm::ConsumesCollector iC = consumesCollector();
72  //trackAssociator_.useDefaultPropagator();
73 }
74 
75 template <typename T>
77  // nothing to be done yet...
78 }
79 
80 template <typename T>
82  auto const& propagator = iSetup.getData(propagatorToken_);
83  trackAssociator_.setPropagator(&propagator);
84 
86  iEvent.getByToken(mu_input_, muonHandle);
87  edm::View<pat::Muon> muons = *muonHandle;
88 
89  std::map<uint32_t, float> correction_map;
90 
91  // Fill the correction map
92  for (edm::View<pat::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
93  // get the basic informaiton like fill reco mouon does
94  // RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc
95  const reco::Track* track = nullptr;
96  if (iMuon->track().isNonnull())
97  track = iMuon->track().get();
98  else if (iMuon->standAloneMuon().isNonnull())
99  track = iMuon->standAloneMuon().get();
100  else
101  throw cms::Exception("FatalError")
102  << "Failed to fill muon id information for a muon with undefined references to tracks";
104  trackAssociator_.associate(iEvent, iSetup, *track, parameters_, TrackDetectorAssociator::Any);
105  fill_correction_map(&info, &correction_map);
106  }
107 
108  // Copy the old collection and correct if necessary
109  for (auto input_ : inputs_) {
110  std::unique_ptr<RecHitCollection> recHitCollection_output(new RecHitCollection());
111  edm::Handle<RecHitCollection> recHitCollection;
112  // iEvent.getByToken(input_.second[0], recHitCollection);
113  iEvent.getByToken(input_.second, recHitCollection);
114  for (typename RecHitCollection::const_iterator recHit = recHitCollection->begin();
115  recHit != recHitCollection->end();
116  ++recHit) {
117  if (correction_map[recHit->detid().rawId()] > 0) {
118  float new_energy = recHit->energy() - correction_map[recHit->detid().rawId()];
119  if (new_energy <= 0)
120  continue; // Do not save empty Hits
121  T newRecHit(*recHit);
122  newRecHit.setEnergy(new_energy);
123  recHitCollection_output->push_back(newRecHit);
124  } else {
125  recHitCollection_output->push_back(*recHit);
126  }
127  /* For the inveted collection
128  if (correction_map[recHit->detid().rawId()] > 0){
129  float new_energy = correction_map[recHit->detid().rawId()];
130  if (new_energy < 0) new_energy =0;
131  T newRecHit(*recHit);
132  newRecHit.setEnergy(new_energy);
133  recHitCollection_output->push_back(newRecHit);
134  }*/
135  }
136  // Save the new collection
137  recHitCollection_output->sort();
138  iEvent.put(std::move(recHitCollection_output), input_.first);
139  }
140 }
141 #endif
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)
void fill_correction_map(TrackDetMatchInfo *, std::map< uint32_t, float > *)
Definition: CaloCleaner.cc:22
std::vector< T >::const_iterator const_iterator
void loadParameters(const edm::ParameterSet &, edm::ConsumesCollector &)
const edm::EDGetTokenT< edm::View< pat::Muon > > mu_input_
Definition: CaloCleaner.h:46
Definition: HeavyIon.h:7
void produce(edm::Event &, const edm::EventSetup &) override
Definition: CaloCleaner.h:81
T getUntrackedParameter(std::string const &, T const &) const
edm::SortedCollection< T > RecHitCollection
Definition: CaloCleaner.h:44
int iEvent
Definition: GenABIO.cc:224
Definition: Muon.py:1
bool getData(T &iHolder) const
Definition: EventSetup.h:122
bool is_preshower_
Definition: CaloCleaner.h:54
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorToken_
Definition: CaloCleaner.h:49
TrackDetectorAssociator trackAssociator_
Definition: CaloCleaner.h:51
CaloCleaner(const edm::ParameterSet &)
Definition: CaloCleaner.h:59
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
TrackAssociatorParameters parameters_
Definition: CaloCleaner.h:52
std::map< std::string, edm::EDGetTokenT< RecHitCollection > > inputs_
Definition: CaloCleaner.h:48
~CaloCleaner() override
Definition: CaloCleaner.h:76
long double T
def move(src, dest)
Definition: eostools.py:511