11/* * \class CaloCleaner
22 *
33 * Clean collections of calorimeter recHits
4- * (detectors supported at the moment : EB/EE, HB/HE and HO)
5- *
4+ * (detectors supported: EB/EE, HB/HE and HO)
5+ *
66 * \author Tomasz Maciej Frueboes;
77 * Christian Veelken, LLR
8- *
9- *
10- *
118 * Clean Up from STefan Wayand, KIT
9+ * Clean Up from Christian Winter & Sebastian Brommer, KIT
1210 */
1311#ifndef TauAnalysis_MCEmbeddingTools_CaloCleaner_H
1412#define TauAnalysis_MCEmbeddingTools_CaloCleaner_H
1513
16- #include " FWCore/Framework/interface/stream/EDProducer.h"
17- #include " FWCore/Framework/interface/Event.h"
18- #include " FWCore/ParameterSet/interface/ParameterSet.h"
1914#include " DataFormats/Common/interface/Handle.h"
20- #include " DataFormats/PatCandidates/interface/Muon.h"
2115#include " DataFormats/MuonReco/interface/MuonEnergy.h"
16+ #include " DataFormats/PatCandidates/interface/Muon.h"
17+ #include " FWCore/Framework/interface/Event.h"
2218#include " FWCore/Framework/interface/MakerMacros.h"
19+ #include " FWCore/Framework/interface/stream/EDProducer.h"
20+ #include " FWCore/ParameterSet/interface/ParameterSet.h"
2321
22+ #include " TrackingTools/Records/interface/TrackingComponentsRecord.h"
2423#include " TrackingTools/TrackAssociator/interface/TrackAssociatorParameters.h"
2524#include " TrackingTools/TrackAssociator/interface/TrackDetectorAssociator.h"
26- #include " TrackingTools/Records/interface/TrackingComponentsRecord.h"
2725
2826#include " DataFormats/Common/interface/SortedCollection.h"
2927#include " DataFormats/EcalRecHit/interface/EcalRecHit.h"
3028
31- #include < string>
3229#include < iostream>
3330#include < map>
31+ #include < string>
3432
3533template <typename T>
3634class CaloCleaner : public edm ::stream::EDProducer<> {
3735public:
38- explicit CaloCleaner (const edm::ParameterSet&);
36+ explicit CaloCleaner (const edm::ParameterSet &);
3937 ~CaloCleaner () override ;
4038
4139private:
42- void produce (edm::Event&, const edm::EventSetup&) override ;
40+ void produce (edm::Event &, const edm::EventSetup &) override ;
4341
4442 typedef edm::SortedCollection<T> RecHitCollection;
4543
46- const edm::EDGetTokenT<edm::View<pat::Muon> > mu_input_;
44+ const edm::EDGetTokenT<edm::View<pat::Muon>> mu_input_;
4745
48- std::map<std::string, edm::EDGetTokenT<RecHitCollection> > inputs_;
46+ std::map<std::string, edm::EDGetTokenT<RecHitCollection>> inputs_;
4947 edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorToken_;
5048
5149 TrackDetectorAssociator trackAssociator_;
5250 TrackAssociatorParameters parameters_;
5351
5452 bool is_preshower_;
55- void fill_correction_map (TrackDetMatchInfo*, std::map<uint32_t , float >*);
53+ void fill_correction_map (TrackDetMatchInfo *, std::map<uint32_t , float > *);
5654};
57-
58- template <typename T>
59- CaloCleaner<T>::CaloCleaner(const edm::ParameterSet& iConfig)
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 ();
71- parameters_.loadParameters (parameters, iC);
72- // trackAssociator_.useDefaultPropagator();
73- }
74-
75- template <typename T>
76- CaloCleaner<T>::~CaloCleaner () {
77- // nothing to be done yet...
78- }
79-
80- template <typename T>
81- void CaloCleaner<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
82- auto const & propagator = iSetup.getData (propagatorToken_);
83- trackAssociator_.setPropagator (&propagator);
84-
85- edm::Handle<edm::View<pat::Muon> > muonHandle;
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" ;
103- TrackDetMatchInfo info =
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
55+ #endif
0 commit comments