CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZToMuMuSelector.cc
Go to the documentation of this file.
1 /* \class ZToMuMuSelector
2  *
3  * \author Juan Alcaraz, CIEMAT
4  *
5  */
8 
9 class ZToMuMuSelector : public edm::EDFilter {
10 public:
12  virtual bool filter(edm::Event&, const edm::EventSetup&);
13 private:
16  double ptCut_;
17  double etaCut_;
18  double massZMin_;
19  double massZMax_;
20 
25 };
26 
34 
35 using namespace edm;
36 using namespace std;
37 using namespace reco;
38 
40  muonTag_(cfg.getParameter<edm::InputTag> ("MuonTag")),
41  isoTag_(cfg.getParameter<edm::InputTag> ("IsolationTag")),
42  ptCut_(cfg.getParameter<double>("PtCut")),
43  etaCut_(cfg.getParameter<double>("EtaCut")),
44  massZMin_(cfg.getParameter<double>("MassZMin")),
45  massZMax_(cfg.getParameter<double>("MassZMax")),
46 
47  onlyGlobalMuons_(cfg.getParameter<bool>("OnlyGlobalMuons")),
48  trackerTag_(cfg.getUntrackedParameter<edm::InputTag> ("TrackerTag",edm::InputTag("ctfWithMaterialTracks"))),
49  isoTrackerTag_(cfg.getUntrackedParameter<edm::InputTag> ("TrackerIsolationTag",edm::InputTag("zMuMuTrackerIsolations"))),
50  minTrackerHits_(cfg.getUntrackedParameter<int>("MinTrackerHits",7))
51 {
52 }
53 
55 
56  // Note: try/catch sequences should disappear in the future
57  // GetByLabel will return a false bool value
58  // if the collection is not present
59 
60  Handle<TrackCollection> muonCollection;
61 
62  ev.getByLabel(muonTag_, muonCollection);
63  if (!muonCollection.isValid()) {
64  LogTrace("") << ">>> Muon collection does not exist !!!";
65  return false;
66  }
67 
69  ev.getByLabel(isoTag_, isoMap);
70  if (!isoMap.isValid()) {
71  LogTrace("") << ">>> ISO Muon collection does not exist !!!";
72  return false;
73  }
74 
75  Handle<TrackCollection> trackerCollection;
76  Handle<edm::ValueMap<bool> > isoTrackerMap;
77  if (!onlyGlobalMuons_) {
78  ev.getByLabel(trackerTag_, trackerCollection);
79  if (!trackerCollection.isValid()) {
80  LogTrace("") << ">>> Tracker collection does not exist !!!";
81  return false;
82  }
83 
84  ev.getByLabel(isoTrackerTag_, isoTrackerMap);
85  if (!isoTrackerMap.isValid()) {
86  LogTrace("") << ">>> ISO Tracker collection does not exist !!!";
87  return false;
88  }
89  }
90 
91  unsigned int npairs = 0;
92  bool globalCombinationFound = false;
93  for (unsigned int i=0; i<muonCollection->size(); i++) {
94  TrackRef mu(muonCollection,i);
95  LogTrace("") << "> Processing muon number " << i << "...";
96  double pt = mu->pt();
97  LogTrace("") << "\t... pt= " << pt << " GeV";
98  if (pt<ptCut_) continue;
99  double eta = mu->eta();
100  LogTrace("") << "\t... eta= " << eta;
101  if (fabs(eta)>etaCut_) continue;
102  bool iso = (*isoMap)[mu];
103  LogTrace("") << "\t... isolated? " << iso;
104  if (!iso) continue;
105 
106  for (unsigned int j=i+1; j<muonCollection->size(); j++) {
107  TrackRef mu2(muonCollection,j);
108  LogTrace("") << "> Processing second muon number " << j << "...";
109  double pt2 = mu2->pt();
110  LogTrace("") << "\t... pt2= " << pt2 << " GeV";
111  if (pt2<ptCut_) continue;
112  double eta2 = mu2->eta();
113  LogTrace("") << "\t... eta2= " << eta2;
114  if (fabs(eta2)>etaCut_) continue;
115  bool iso2 = (*isoMap)[mu2];
116  LogTrace("") << "\t... isolated2? " << iso2;
117  if (!iso2) continue;
118 
119  double z_en = mu->p() + mu2->p();
120  double z_px = mu->px() + mu2->px();
121  double z_py = mu->py() + mu2->py();
122  double z_pz = mu->pz() + mu2->pz();
123  double massZ = z_en*z_en - z_px*z_px - z_py*z_py - z_pz*z_pz;
124  massZ = (massZ>0) ? sqrt(massZ) : 0;
125  LogTrace("") << "\t... Z_en, Z_px, Z_py, Z_pz= " << z_en << ", " << z_px << ", " << z_py << ", " << z_pz << " GeV";
126  LogTrace("") << "\t... (GM-GM) Invariant reconstructed mass= " << massZ << " GeV";
127  if (massZ<massZMin_) continue;
128  if (massZ>massZMax_) continue;
129  globalCombinationFound = true;
130  npairs++;
131  }
132 
133  if (onlyGlobalMuons_ || globalCombinationFound) continue;
134 
135  for (unsigned int j=0; j<trackerCollection->size(); j++) {
136  TrackRef mu2(trackerCollection,j);
137  LogTrace("") << "> Processing track number " << j << "...";
138  double pt2 = mu2->pt();
139  LogTrace("") << "\t... pt3= " << pt2 << " GeV";
140  if (pt2<ptCut_) continue;
141  double eta2 = mu2->eta();
142  LogTrace("") << "\t... eta3= " << eta2;
143  if (fabs(eta2)>etaCut_) continue;
144  int nhits2 = mu2->numberOfValidHits();
145  LogTrace("") << "\t... nhits3= " << nhits2;
146  if (nhits2<minTrackerHits_) continue;
147  bool iso2 = (*isoTrackerMap)[mu2];
148  LogTrace("") << "\t... isolated3? " << iso2;
149  if (!iso2) continue;
150 
151  double z_en = mu->p() + mu2->p();
152  double z_px = mu->px() + mu2->px();
153  double z_py = mu->py() + mu2->py();
154  double z_pz = mu->pz() + mu2->pz();
155  double massZ = z_en*z_en - z_px*z_px - z_py*z_py - z_pz*z_pz;
156  massZ = (massZ>0) ? sqrt(massZ) : 0;
157  LogTrace("") << "\t... Z_en, Z_px, Z_py, Z_pz= " << z_en << ", " << z_px << ", " << z_py << ", " << z_pz << " GeV";
158  LogTrace("") << "\t... (GM-TK) Invariant reconstructed mass= " << massZ << " GeV";
159  if (massZ<massZMin_) continue;
160  if (massZ>massZMax_) continue;
161  npairs++;
162  }
163  }
164 
165  LogTrace("") << "> Number of Z pairs found= " << npairs;
166  if (npairs<1) {
167  LogTrace("") << ">>>> Event REJECTED";
168  return false;
169  }
170  LogTrace("") << ">>>> Event SELECTED!!!";
171 
172  return true;
173 
174 }
175 
177 
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T eta() const
edm::InputTag isoTag_
T sqrt(T t)
Definition: SSEVec.h:46
int j
Definition: DBlmapReader.cc:9
const int mu
Definition: Constants.h:23
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
#define LogTrace(id)
edm::InputTag trackerTag_
virtual bool filter(edm::Event &, const edm::EventSetup &)
ZToMuMuSelector(const edm::ParameterSet &)
edm::InputTag muonTag_
edm::InputTag isoTrackerTag_