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 
36 template <typename T>
38 {
39  public:
40  explicit CaloCleaner(const edm::ParameterSet&);
41  ~CaloCleaner();
42 
43  private:
44  virtual void produce(edm::Event&, const edm::EventSetup&) override;
45 
47 
49 
50  std::map<std::string, edm::EDGetTokenT<RecHitCollection > > inputs_;
51 
54 
56  void fill_correction_map(TrackDetMatchInfo *, std::map<uint32_t, float> *);
57 
58 };
59 
60 template <typename T>
62  mu_input_(consumes<edm::View<pat::Muon> >(iConfig.getParameter<edm::InputTag>("MuonCollection")))
63 {
64  std::vector<edm::InputTag> inCollections = iConfig.getParameter<std::vector<edm::InputTag> >("oldCollection");
65  for (auto inCollection : inCollections){
66  inputs_[inCollection.instance()] = consumes<RecHitCollection >(inCollection);
67  produces<RecHitCollection>(inCollection.instance());
68  }
69 
70  is_preshower_ =iConfig.getUntrackedParameter<bool>("is_preshower", false);
71  edm::ParameterSet parameters = iConfig.getParameter<edm::ParameterSet>("TrackAssociatorParameters");
73  parameters_.loadParameters( parameters, iC );
74  //trackAssociator_.useDefaultPropagator();
75 
76 }
77 
78 template <typename T>
80 {
81 // nothing to be done yet...
82 }
83 
84 
85 template <typename T>
87 {
89  iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny", propagator);
91 
93  iEvent.getByToken(mu_input_, muonHandle);
94  edm::View<pat::Muon> muons = *muonHandle;
95 
96  std::map<uint32_t, float> correction_map;
97 
98  // Fill the correction map
99  for (edm::View<pat::Muon>::const_iterator iMuon = muons.begin(); iMuon != muons.end(); ++iMuon) {
100  // get the basic informaiton like fill reco mouon does
101  // RecoMuon/MuonIdentification/plugins/MuonIdProducer.cc
102  const reco::Track* track = 0;
103  if ( iMuon->track().isNonnull() ) track = iMuon->track().get();
104  else if ( iMuon->standAloneMuon().isNonnull() ) track = iMuon->standAloneMuon().get();
105  else throw cms::Exception("FatalError") << "Failed to fill muon id information for a muon with undefined references to tracks";
107  fill_correction_map(&info,&correction_map);
108  }
109 
110  // Copy the old collection and correct if necessary
111  for (auto input_ : inputs_){
112  std::unique_ptr<RecHitCollection> recHitCollection_output(new RecHitCollection());
113  edm::Handle<RecHitCollection> recHitCollection;
114  // iEvent.getByToken(input_.second[0], recHitCollection);
115  iEvent.getByToken(input_.second, recHitCollection);
116  for ( typename RecHitCollection::const_iterator recHit = recHitCollection->begin(); recHit != recHitCollection->end(); ++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) continue; // Do not save empty Hits
120  T newRecHit(*recHit);
121  newRecHit.setEnergy(new_energy);
122  recHitCollection_output->push_back(newRecHit);
123  }
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 
137 
138 
139  }
140  // Save the new collection
141  recHitCollection_output->sort();
142  iEvent.put(std::move(recHitCollection_output),input_.first);
143  }
144 
145 }
146 #endif
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
static const TGPicture * info(bool iBackgroundIsBlack)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
void fill_correction_map(TrackDetMatchInfo *, std::map< uint32_t, float > *)
Definition: CaloCleaner.cc:25
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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:48
std::map< std::string, edm::EDGetTokenT< RecHitCollection > > inputs_
Definition: CaloCleaner.h:50
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition: HeavyIon.h:7
virtual void produce(edm::Event &, const edm::EventSetup &) override
Definition: CaloCleaner.h:86
edm::SortedCollection< T > RecHitCollection
Definition: CaloCleaner.h:46
int iEvent
Definition: GenABIO.cc:230
const_iterator begin() const
Definition: Muon.py:1
void setPropagator(const Propagator *)
use a user configured propagator
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
const_iterator end() const
bool is_preshower_
Definition: CaloCleaner.h:55
const T & get() const
Definition: EventSetup.h:56
TrackDetectorAssociator trackAssociator_
Definition: CaloCleaner.h:52
CaloCleaner(const edm::ParameterSet &)
Definition: CaloCleaner.h:61
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
TrackAssociatorParameters parameters_
Definition: CaloCleaner.h:53
TrackDetMatchInfo associate(const edm::Event &, const edm::EventSetup &, const FreeTrajectoryState &, const AssociatorParameters &)
const_iterator end() const
long double T
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510
const_iterator begin() const