CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/ElectroWeakAnalysis/ZMuMu/plugins/ZToMuMuSelector.cc

Go to the documentation of this file.
00001 /* \class ZToMuMuSelector
00002  *
00003  * \author Juan Alcaraz, CIEMAT
00004  *
00005  */
00006 #include "FWCore/Framework/interface/EDFilter.h"
00007 #include "FWCore/Utilities/interface/InputTag.h"
00008 
00009 class ZToMuMuSelector : public edm::EDFilter {
00010 public:
00011   ZToMuMuSelector (const edm::ParameterSet &);
00012   virtual bool filter(edm::Event&, const edm::EventSetup&);
00013 private:
00014   edm::InputTag muonTag_;
00015   edm::InputTag isoTag_;
00016   double ptCut_;
00017   double etaCut_;
00018   double massZMin_;
00019   double massZMax_;
00020 
00021   bool onlyGlobalMuons_;
00022   edm::InputTag trackerTag_;
00023   edm::InputTag isoTrackerTag_;
00024   int minTrackerHits_;
00025 };
00026 
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028 #include "DataFormats/Common/interface/Handle.h"
00029 #include "DataFormats/Common/interface/ValueMap.h"
00030 #include "FWCore/Framework/interface/Event.h"
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "DataFormats/TrackReco/interface/Track.h"
00033 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00034 
00035 using namespace edm;
00036 using namespace std;
00037 using namespace reco;
00038 
00039 ZToMuMuSelector::ZToMuMuSelector( const ParameterSet & cfg ) :
00040       muonTag_(cfg.getParameter<edm::InputTag> ("MuonTag")),
00041       isoTag_(cfg.getParameter<edm::InputTag> ("IsolationTag")),
00042       ptCut_(cfg.getParameter<double>("PtCut")),
00043       etaCut_(cfg.getParameter<double>("EtaCut")),
00044       massZMin_(cfg.getParameter<double>("MassZMin")),
00045       massZMax_(cfg.getParameter<double>("MassZMax")),
00046 
00047       onlyGlobalMuons_(cfg.getParameter<bool>("OnlyGlobalMuons")),
00048       trackerTag_(cfg.getUntrackedParameter<edm::InputTag> ("TrackerTag",edm::InputTag("ctfWithMaterialTracks"))),
00049       isoTrackerTag_(cfg.getUntrackedParameter<edm::InputTag> ("TrackerIsolationTag",edm::InputTag("zMuMuTrackerIsolations"))),
00050       minTrackerHits_(cfg.getUntrackedParameter<int>("MinTrackerHits",7))
00051 {
00052 }
00053 
00054 bool ZToMuMuSelector::filter (Event & ev, const EventSetup &) {
00055 
00056       // Note:    try/catch sequences should disappear in the future
00057       //          GetByLabel will return a false bool value 
00058       //          if the collection is not present
00059 
00060       Handle<TrackCollection> muonCollection;
00061 
00062       ev.getByLabel(muonTag_, muonCollection);
00063       if (!muonCollection.isValid()) {
00064         LogTrace("") << ">>> Muon collection does not exist !!!";
00065         return false;
00066       }
00067 
00068       Handle<edm::ValueMap<bool> > isoMap;
00069       ev.getByLabel(isoTag_, isoMap);
00070       if (!isoMap.isValid()) {
00071         LogTrace("") << ">>> ISO Muon collection does not exist !!!";
00072         return false;
00073       }
00074 
00075       Handle<TrackCollection> trackerCollection;
00076       Handle<edm::ValueMap<bool> > isoTrackerMap;
00077       if (!onlyGlobalMuons_) {
00078         ev.getByLabel(trackerTag_, trackerCollection);
00079         if (!trackerCollection.isValid()) {
00080           LogTrace("") << ">>> Tracker collection does not exist !!!";
00081           return false;
00082         }
00083         
00084         ev.getByLabel(isoTrackerTag_, isoTrackerMap);
00085         if (!isoTrackerMap.isValid()) {
00086           LogTrace("") << ">>> ISO Tracker collection does not exist !!!";
00087           return false;
00088         }
00089       }
00090 
00091       unsigned int npairs = 0;
00092       bool globalCombinationFound = false;
00093       for (unsigned int i=0; i<muonCollection->size(); i++) {
00094             TrackRef mu(muonCollection,i);
00095             LogTrace("") << "> Processing muon number " << i << "...";
00096             double pt = mu->pt();
00097             LogTrace("") << "\t... pt= " << pt << " GeV";
00098             if (pt<ptCut_) continue;
00099             double eta = mu->eta();
00100             LogTrace("") << "\t... eta= " << eta;
00101             if (fabs(eta)>etaCut_) continue;
00102             bool iso = (*isoMap)[mu];
00103             LogTrace("") << "\t... isolated? " << iso;
00104             if (!iso) continue;
00105 
00106             for (unsigned int j=i+1; j<muonCollection->size(); j++) {
00107                   TrackRef mu2(muonCollection,j);
00108                   LogTrace("") << "> Processing second muon number " << j << "...";
00109                   double pt2 = mu2->pt();
00110                   LogTrace("") << "\t... pt2= " << pt2 << " GeV";
00111                   if (pt2<ptCut_) continue;
00112                   double eta2 = mu2->eta();
00113                   LogTrace("") << "\t... eta2= " << eta2;
00114                   if (fabs(eta2)>etaCut_) continue;
00115                   bool iso2 = (*isoMap)[mu2];
00116                   LogTrace("") << "\t... isolated2? " << iso2;
00117                   if (!iso2) continue;
00118 
00119                   double z_en = mu->p() + mu2->p();
00120                   double z_px = mu->px() + mu2->px();
00121                   double z_py = mu->py() + mu2->py();
00122                   double z_pz = mu->pz() + mu2->pz();
00123                   double massZ = z_en*z_en - z_px*z_px - z_py*z_py - z_pz*z_pz;
00124                   massZ = (massZ>0) ? sqrt(massZ) : 0;
00125                   LogTrace("") << "\t... Z_en, Z_px, Z_py, Z_pz= " << z_en << ", " << z_px << ", " << z_py << ", " << z_pz << " GeV";
00126                   LogTrace("") << "\t... (GM-GM) Invariant reconstructed mass= " << massZ << " GeV";
00127                   if (massZ<massZMin_) continue;
00128                   if (massZ>massZMax_) continue;
00129                   globalCombinationFound = true;
00130                   npairs++;
00131             }
00132 
00133             if (onlyGlobalMuons_ || globalCombinationFound) continue;
00134 
00135             for (unsigned int j=0; j<trackerCollection->size(); j++) {
00136                   TrackRef mu2(trackerCollection,j);
00137                   LogTrace("") << "> Processing track number " << j << "...";
00138                   double pt2 = mu2->pt();
00139                   LogTrace("") << "\t... pt3= " << pt2 << " GeV";
00140                   if (pt2<ptCut_) continue;
00141                   double eta2 = mu2->eta();
00142                   LogTrace("") << "\t... eta3= " << eta2;
00143                   if (fabs(eta2)>etaCut_) continue;
00144                   int nhits2 = mu2->numberOfValidHits();
00145                   LogTrace("") << "\t... nhits3= " << nhits2;
00146                   if (nhits2<minTrackerHits_) continue;
00147                   bool iso2 = (*isoTrackerMap)[mu2];
00148                   LogTrace("") << "\t... isolated3? " << iso2;
00149                   if (!iso2) continue;
00150 
00151                   double z_en = mu->p() + mu2->p();
00152                   double z_px = mu->px() + mu2->px();
00153                   double z_py = mu->py() + mu2->py();
00154                   double z_pz = mu->pz() + mu2->pz();
00155                   double massZ = z_en*z_en - z_px*z_px - z_py*z_py - z_pz*z_pz;
00156                   massZ = (massZ>0) ? sqrt(massZ) : 0;
00157                   LogTrace("") << "\t... Z_en, Z_px, Z_py, Z_pz= " << z_en << ", " << z_px << ", " << z_py << ", " << z_pz << " GeV";
00158                   LogTrace("") << "\t... (GM-TK) Invariant reconstructed mass= " << massZ << " GeV";
00159                   if (massZ<massZMin_) continue;
00160                   if (massZ>massZMax_) continue;
00161                   npairs++;
00162             }
00163       }
00164 
00165       LogTrace("") << "> Number of Z pairs found= " << npairs;
00166       if (npairs<1) {
00167             LogTrace("") << ">>>> Event REJECTED";
00168             return false;
00169       }
00170       LogTrace("") << ">>>> Event SELECTED!!!";
00171 
00172       return true;
00173 
00174 }
00175 
00176 #include "FWCore/Framework/interface/MakerMacros.h"
00177 
00178 DEFINE_FWK_MODULE( ZToMuMuSelector );