CMS 3D CMS Logo

CaloMuonMerger.cc
Go to the documentation of this file.
1 //
2 //
3 
16 
20 
22 
24 public:
25  explicit CaloMuonMerger(const edm::ParameterSet & iConfig);
26  ~CaloMuonMerger() override { }
27 
28  void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
29 
30 private:
40 
44 
45 
46 
47 };
48 
49 
51  muons_(iConfig.getParameter<edm::InputTag>("muons")),
52  muonsCut_(iConfig.existsAs<std::string>("muonsCut") ? iConfig.getParameter<std::string>("muonsCut") : ""),
53  mergeCaloMuons_(iConfig.existsAs<bool>("mergeCaloMuons") ? iConfig.getParameter<bool>("mergeCaloMuons") : true),
54  caloMuons_(iConfig.getParameter<edm::InputTag>("caloMuons")),
55  caloMuonsCut_(iConfig.existsAs<std::string>("caloMuonsCut") ? iConfig.getParameter<std::string>("caloMuonsCut") : ""),
56  minCaloCompatibility_(mergeCaloMuons_ ? iConfig.getParameter<double>("minCaloCompatibility") : 0),
57  mergeTracks_(iConfig.existsAs<bool>("mergeTracks") ? iConfig.getParameter<bool>("mergeTracks") : false),
58  tracks_(mergeTracks_ ? iConfig.getParameter<edm::InputTag>("tracks") : edm::InputTag()),
59  tracksCut_(iConfig.existsAs<std::string>("tracksCut") ? iConfig.getParameter<std::string>("tracksCut") : "")
60 {
61  muonToken_ = consumes<std::vector<reco::Muon> >(muons_);
62  caloMuonToken_=consumes<std::vector<reco::CaloMuon> >(caloMuons_);
63  trackToken_ = consumes<std::vector<reco::Track> > (tracks_);
64  produces<std::vector<reco::Muon> >();
65 }
66 
67 void
72 
73  iEvent.getByToken(muonToken_,muons);
74  if(mergeCaloMuons_) iEvent.getByToken(caloMuonToken_,caloMuons);
75  if(mergeTracks_) iEvent.getByToken(trackToken_,tracks);
76 
77  auto out = std::make_unique<std::vector<reco::Muon>>();
78  out->reserve(muons->size() + (mergeTracks_?tracks->size():0));
79 
80  // copy reco::Muons, turning on the CaloCompatibility flag if enabled and possible
81  for (std::vector<reco::Muon>::const_iterator it = muons->begin(), ed = muons->end(); it != ed; ++it) {
82  if(!muonsCut_(*it)) continue;
83  out->push_back(*it);
84  reco::Muon & mu = out->back();
85  if (mergeCaloMuons_ && mu.track().isNonnull()) {
86  if (mu.isCaloCompatibilityValid()) {
89  }
90  } else throw cms::Exception("Boh") << "Muon with track and no CaloCompatibility; pt = " << mu.pt() << ", eta = " << mu.eta() << ", type = " << mu.type() << "\n";
91  }
92  }
93 
94  if (mergeCaloMuons_) {
95  // copy reco::CaloMuon
96  for (std::vector<reco::CaloMuon>::const_iterator it = caloMuons->begin(), ed = caloMuons->end(); it != ed; ++it) {
97  if(!caloMuonsCut_(*it)) continue;
98  // make a reco::Muon
99  reco::TrackRef track = it->track();
100  double energy = sqrt(track->p() * track->p() + 0.011163691);
101  math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
102  out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
103  reco::Muon & mu = out->back();
104  // fill info
105  mu.setCalEnergy( it->calEnergy() );
106  mu.setCaloCompatibility( it->caloCompatibility() );
107  mu.setInnerTrack( track );
109  }
110  }
111 
112  // merge reco::Track avoiding duplication of innerTracks
113  if(mergeTracks_){
114  for (size_t i = 0; i < tracks->size(); i++) {
115  reco::TrackRef track(tracks, i);
116  if(!tracksCut_(track)) continue;
117  // check if it is a muon or calomuon
118  bool isMuon = false;
119  for(std::vector<reco::Muon>::const_iterator muon = muons->begin(); muon < muons->end(); muon++){
120  if(muon->innerTrack() == track){
121  isMuon = true;
122  break;
123  }
124  }
125  if(isMuon) continue;
126  if (mergeCaloMuons_) {
127  bool isCaloMuon = false;
128  for(std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon < caloMuons->end(); muon++){
129  if(muon->innerTrack() == track){
130  isCaloMuon = true;
131  break;
132  }
133  }
134  if(isCaloMuon) continue;
135  }
136  // make a reco::Muon
137  double energy = sqrt(track->p() * track->p() + 0.011163691);
138  math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
139  out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
140  reco::Muon & mu = out->back();
141  // fill info
142  mu.setInnerTrack( track );
143  }
144  }
145 
146  iEvent.put(std::move(out));
147 }
148 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
TrackRef track() const override
reference to a Track
Definition: Muon.h:49
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
double eta() const final
momentum pseudorapidity
void setType(unsigned int type)
Definition: Muon.h:268
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:11
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
bool isCaloCompatibilityValid() const
Definition: Muon.h:156
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
double pt() const final
transverse momentum
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: Muon.h:113
StringCutObjectSelector< reco::CaloMuon, false > caloMuonsCut_
double minCaloCompatibility_
edm::EDGetTokenT< std::vector< reco::Track > > trackToken_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
int iEvent
Definition: GenABIO.cc:230
StringCutObjectSelector< reco::TrackRef, false > tracksCut_
edm::InputTag tracks_
void setCaloCompatibility(float input)
Definition: Muon.h:155
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
const int mu
Definition: Constants.h:22
edm::EDGetTokenT< std::vector< reco::Muon > > muonToken_
CaloMuonMerger(const edm::ParameterSet &iConfig)
edm::InputTag muons_
~CaloMuonMerger() override
StringCutObjectSelector< reco::Muon, false > muonsCut_
edm::EDGetTokenT< std::vector< reco::CaloMuon > > caloMuonToken_
static const unsigned int CaloMuon
Definition: Muon.h:262
Merges reco::CaloMuons, reco::Muons and optionally reco::Tracks avoiding innerTrack duplications in a...
HLT enums.
edm::InputTag caloMuons_
unsigned int type() const
Definition: Muon.h:269
float caloCompatibility() const
Definition: Muon.h:154
def move(src, dest)
Definition: eostools.py:510
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override