CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloMuonMerger.cc
Go to the documentation of this file.
1 //
2 // $Id: CaloMuonMerger.cc,v 1.6 2011/01/06 13:26:53 gpetrucc Exp $
3 //
4 
18 
22 
24 
26 public:
27  explicit CaloMuonMerger(const edm::ParameterSet & iConfig);
28  virtual ~CaloMuonMerger() { }
29 
30  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
31 
32 private:
42 };
43 
44 
46  muons_(iConfig.getParameter<edm::InputTag>("muons")),
47  muonsCut_(iConfig.existsAs<std::string>("muonsCut") ? iConfig.getParameter<std::string>("muonsCut") : ""),
48  mergeCaloMuons_(iConfig.existsAs<bool>("mergeCaloMuons") ? iConfig.getParameter<bool>("mergeCaloMuons") : true),
49  caloMuons_(iConfig.getParameter<edm::InputTag>("caloMuons")),
50  caloMuonsCut_(iConfig.existsAs<std::string>("caloMuonsCut") ? iConfig.getParameter<std::string>("caloMuonsCut") : ""),
51  minCaloCompatibility_(mergeCaloMuons_ ? iConfig.getParameter<double>("minCaloCompatibility") : 0),
52  mergeTracks_(iConfig.existsAs<bool>("mergeTracks") ? iConfig.getParameter<bool>("mergeTracks") : false),
53  tracks_(mergeTracks_ ? iConfig.getParameter<edm::InputTag>("tracks") : edm::InputTag()),
54  tracksCut_(iConfig.existsAs<std::string>("tracksCut") ? iConfig.getParameter<std::string>("tracksCut") : "")
55 {
56  produces<std::vector<reco::Muon> >();
57 }
58 
59 void
64 
65  iEvent.getByLabel(muons_, muons);
66  if(mergeCaloMuons_) iEvent.getByLabel(caloMuons_, caloMuons);
67  if(mergeTracks_) iEvent.getByLabel(tracks_, tracks);
68 
69  std::auto_ptr<std::vector<reco::Muon> > out(new std::vector<reco::Muon>());
70  out->reserve(muons->size() + (mergeTracks_?tracks->size():0));
71 
72  // copy reco::Muons, turning on the CaloCompatibility flag if enabled and possible
73  for (std::vector<reco::Muon>::const_iterator it = muons->begin(), ed = muons->end(); it != ed; ++it) {
74  if(!muonsCut_(*it)) continue;
75  out->push_back(*it);
76  reco::Muon & mu = out->back();
77  if (mergeCaloMuons_ && mu.track().isNonnull()) {
78  if (mu.isCaloCompatibilityValid()) {
81  }
82  } else throw cms::Exception("Boh") << "Muon with track and no CaloCompatibility; pt = " << mu.pt() << ", eta = " << mu.eta() << ", type = " << mu.type() << "\n";
83  }
84  }
85 
86  if (mergeCaloMuons_) {
87  // copy reco::CaloMuon
88  for (std::vector<reco::CaloMuon>::const_iterator it = caloMuons->begin(), ed = caloMuons->end(); it != ed; ++it) {
89  if(!caloMuonsCut_(*it)) continue;
90  // make a reco::Muon
91  reco::TrackRef track = it->track();
92  double energy = sqrt(track->p() * track->p() + 0.011163691);
93  math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
94  out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
95  reco::Muon & mu = out->back();
96  // fill info
97  mu.setCalEnergy( it->calEnergy() );
98  mu.setCaloCompatibility( it->caloCompatibility() );
99  mu.setInnerTrack( track );
101  }
102  }
103 
104  // merge reco::Track avoiding duplication of innerTracks
105  if(mergeTracks_){
106  for (size_t i = 0; i < tracks->size(); i++) {
107  reco::TrackRef track(tracks, i);
108  if(!tracksCut_(track)) continue;
109  // check if it is a muon or calomuon
110  bool isMuon = false;
111  for(std::vector<reco::Muon>::const_iterator muon = muons->begin(); muon < muons->end(); muon++){
112  if(muon->innerTrack() == track){
113  isMuon = true;
114  break;
115  }
116  }
117  if(isMuon) continue;
118  if (mergeCaloMuons_) {
119  bool isCaloMuon = false;
120  for(std::vector<reco::CaloMuon>::const_iterator muon = caloMuons->begin(); muon < caloMuons->end(); muon++){
121  if(muon->innerTrack() == track){
122  isCaloMuon = true;
123  break;
124  }
125  }
126  if(isCaloMuon) continue;
127  }
128  // make a reco::Muon
129  double energy = sqrt(track->p() * track->p() + 0.011163691);
130  math::XYZTLorentzVector p4(track->px(), track->py(), track->pz(), energy);
131  out->push_back(reco::Muon(track->charge(), p4, track->vertex()));
132  reco::Muon & mu = out->back();
133  // fill info
134  mu.setInnerTrack( track );
135  }
136  }
137 
138  iEvent.put(out);
139 }
140 
virtual ~CaloMuonMerger()
int i
Definition: DBlmapReader.cc:9
void setType(unsigned int type)
Definition: Muon.h:215
bool isMuon(const Candidate &part)
Definition: pdgIdUtils.h:11
bool isCaloCompatibilityValid() const
Definition: Muon.h:153
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void setInnerTrack(const TrackRef &t)
set reference to Track
Definition: Muon.cc:846
virtual TrackRef track() const
reference to a Track
Definition: Muon.h:50
void setCalEnergy(const MuonEnergy &calEnergy)
set energy deposition information
Definition: Muon.h:114
StringCutObjectSelector< reco::CaloMuon, false > caloMuonsCut_
double minCaloCompatibility_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
int iEvent
Definition: GenABIO.cc:243
StringCutObjectSelector< reco::TrackRef, false > tracksCut_
edm::InputTag tracks_
void setCaloCompatibility(float input)
Definition: Muon.h:152
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
const int mu
Definition: Constants.h:23
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
CaloMuonMerger(const edm::ParameterSet &iConfig)
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
tuple out
Definition: dbtoconf.py:99
edm::InputTag muons_
tuple tracks
Definition: testEve_cfg.py:39
StringCutObjectSelector< reco::Muon, false > muonsCut_
static const unsigned int CaloMuon
Definition: Muon.h:211
Merges reco::CaloMuons, reco::Muons and optionally reco::Tracks avoiding innerTrack duplications in a...
tuple muons
Definition: patZpeak.py:38
edm::InputTag caloMuons_
unsigned int type() const
Definition: Muon.h:216
const reco::PFCandidateRefVector & tracks_
virtual float pt() const GCC11_FINAL
transverse momentum
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
float caloCompatibility() const
Definition: Muon.h:151