test
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  */
11 
13 public:
15  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
16 private:
19  double ptCut_;
20  double etaCut_;
21  double massZMin_;
22  double massZMax_;
23 
28 };
29 
34 
35 using namespace edm;
36 using namespace std;
37 using namespace reco;
38 
40  muonToken_(consumes<TrackCollection>(cfg.getParameter<edm::InputTag> ("MuonTag"))),
41  isoToken_(consumes<edm::ValueMap<bool> >(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  trackerToken_(mayConsume<TrackCollection>(cfg.getUntrackedParameter<edm::InputTag> ("TrackerTag",edm::InputTag("ctfWithMaterialTracks")))),
49  isoTrackerToken_(mayConsume<edm::ValueMap<bool> >(cfg.getUntrackedParameter<edm::InputTag> ("TrackerIsolationTag",edm::InputTag("zMuMuTrackerIsolations")))),
50  minTrackerHits_(cfg.getUntrackedParameter<int>("MinTrackerHits",7))
51 {
52 }
53 
55 
56  Handle<TrackCollection> muonCollection;
57  ev.getByToken(muonToken_, muonCollection);
58  if (!muonCollection.isValid()) {
59  LogTrace("") << ">>> Muon collection does not exist !!!";
60  return false;
61  }
62 
64  ev.getByToken(isoToken_, isoMap);
65  if (!isoMap.isValid()) {
66  LogTrace("") << ">>> ISO Muon collection does not exist !!!";
67  return false;
68  }
69 
70  Handle<TrackCollection> trackerCollection;
71  Handle<edm::ValueMap<bool> > isoTrackerMap;
72  if (!onlyGlobalMuons_) {
73  ev.getByToken(trackerToken_, trackerCollection);
74  if (!trackerCollection.isValid()) {
75  LogTrace("") << ">>> Tracker collection does not exist !!!";
76  return false;
77  }
78 
79  ev.getByToken(isoTrackerToken_, isoTrackerMap);
80  if (!isoTrackerMap.isValid()) {
81  LogTrace("") << ">>> ISO Tracker collection does not exist !!!";
82  return false;
83  }
84  }
85 
86  unsigned int npairs = 0;
87  bool globalCombinationFound = false;
88  for (unsigned int i=0; i<muonCollection->size(); i++) {
89  TrackRef mu(muonCollection,i);
90  LogTrace("") << "> Processing muon number " << i << "...";
91  double pt = mu->pt();
92  LogTrace("") << "\t... pt= " << pt << " GeV";
93  if (pt<ptCut_) continue;
94  double eta = mu->eta();
95  LogTrace("") << "\t... eta= " << eta;
96  if (fabs(eta)>etaCut_) continue;
97  bool iso = (*isoMap)[mu];
98  LogTrace("") << "\t... isolated? " << iso;
99  if (!iso) continue;
100 
101  for (unsigned int j=i+1; j<muonCollection->size(); j++) {
102  TrackRef mu2(muonCollection,j);
103  LogTrace("") << "> Processing second muon number " << j << "...";
104  double pt2 = mu2->pt();
105  LogTrace("") << "\t... pt2= " << pt2 << " GeV";
106  if (pt2<ptCut_) continue;
107  double eta2 = mu2->eta();
108  LogTrace("") << "\t... eta2= " << eta2;
109  if (fabs(eta2)>etaCut_) continue;
110  bool iso2 = (*isoMap)[mu2];
111  LogTrace("") << "\t... isolated2? " << iso2;
112  if (!iso2) continue;
113 
114  double z_en = mu->p() + mu2->p();
115  double z_px = mu->px() + mu2->px();
116  double z_py = mu->py() + mu2->py();
117  double z_pz = mu->pz() + mu2->pz();
118  double massZ = z_en*z_en - z_px*z_px - z_py*z_py - z_pz*z_pz;
119  massZ = (massZ>0) ? sqrt(massZ) : 0;
120  LogTrace("") << "\t... Z_en, Z_px, Z_py, Z_pz= " << z_en << ", " << z_px << ", " << z_py << ", " << z_pz << " GeV";
121  LogTrace("") << "\t... (GM-GM) Invariant reconstructed mass= " << massZ << " GeV";
122  if (massZ<massZMin_) continue;
123  if (massZ>massZMax_) continue;
124  globalCombinationFound = true;
125  npairs++;
126  }
127 
128  if (onlyGlobalMuons_ || globalCombinationFound) continue;
129 
130  for (unsigned int j=0; j<trackerCollection->size(); j++) {
131  TrackRef mu2(trackerCollection,j);
132  LogTrace("") << "> Processing track number " << j << "...";
133  double pt2 = mu2->pt();
134  LogTrace("") << "\t... pt3= " << pt2 << " GeV";
135  if (pt2<ptCut_) continue;
136  double eta2 = mu2->eta();
137  LogTrace("") << "\t... eta3= " << eta2;
138  if (fabs(eta2)>etaCut_) continue;
139  int nhits2 = mu2->numberOfValidHits();
140  LogTrace("") << "\t... nhits3= " << nhits2;
141  if (nhits2<minTrackerHits_) continue;
142  bool iso2 = (*isoTrackerMap)[mu2];
143  LogTrace("") << "\t... isolated3? " << iso2;
144  if (!iso2) continue;
145 
146  double z_en = mu->p() + mu2->p();
147  double z_px = mu->px() + mu2->px();
148  double z_py = mu->py() + mu2->py();
149  double z_pz = mu->pz() + mu2->pz();
150  double massZ = z_en*z_en - z_px*z_px - z_py*z_py - z_pz*z_pz;
151  massZ = (massZ>0) ? sqrt(massZ) : 0;
152  LogTrace("") << "\t... Z_en, Z_px, Z_py, Z_pz= " << z_en << ", " << z_px << ", " << z_py << ", " << z_pz << " GeV";
153  LogTrace("") << "\t... (GM-TK) Invariant reconstructed mass= " << massZ << " GeV";
154  if (massZ<massZMin_) continue;
155  if (massZ>massZMax_) continue;
156  npairs++;
157  }
158  }
159 
160  LogTrace("") << "> Number of Z pairs found= " << npairs;
161  if (npairs<1) {
162  LogTrace("") << ">>>> Event REJECTED";
163  return false;
164  }
165  LogTrace("") << ">>>> Event SELECTED!!!";
166 
167  return true;
168 
169 }
170 
172 
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< reco::TrackCollection > muonToken_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
bool ev
virtual bool filter(edm::Event &, const edm::EventSetup &) override
T sqrt(T t)
Definition: SSEVec.h:18
int j
Definition: DBlmapReader.cc:9
const int mu
Definition: Constants.h:22
bool isValid() const
Definition: HandleBase.h:75
#define LogTrace(id)
edm::EDGetTokenT< reco::TrackCollection > trackerToken_
edm::EDGetTokenT< edm::ValueMap< bool > > isoToken_
ZToMuMuSelector(const edm::ParameterSet &)
edm::EDGetTokenT< edm::ValueMap< bool > > isoTrackerToken_