CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/HLTriggerOffline/SUSYBSM/src/MuonAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    MuonAnalyzerSBSM
00004 // Class:      MuonAnalyzerSBSM
00005 // 
00013 //
00014 // Original Author:  Philip Hebda
00015 //         Created:  Thu Jun 25 09:34:50 CEST 2009
00016 // $Id: MuonAnalyzer.cc,v 1.3 2010/12/14 17:20:35 vlimant Exp $
00017 //
00018 //
00019 #include "HLTriggerOffline/SUSYBSM/interface/MuonAnalyzer.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 
00022 
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 #include "TDirectory.h"
00025 
00026 #include "HLTriggerOffline/SUSYBSM/interface/PtSorter.h"
00027 //
00028 // class decleration
00029 //
00030 
00031 using namespace edm;
00032 using namespace reco;
00033 using namespace std;
00034 using namespace trigger;
00035 
00036 
00037 MuonAnalyzerSBSM::MuonAnalyzerSBSM(edm::InputTag triggerTag_v, edm::InputTag muonTag_v)
00038 {
00039   triggerTag_ = triggerTag_v;
00040   muonTag_ = muonTag_v;
00041 }
00042 
00043 bool MuonAnalyzerSBSM::find(vector<int> vec, int element)
00044 {
00045   for(size_t i=0; i<vec.size(); ++i)
00046     {
00047       if(vec[i]==element)
00048         return true;
00049     }
00050   return false;
00051 }
00052 
00053 //
00054 // member functions
00055 //
00056 
00057 // ------------ method called to for each event  ------------
00058 void
00059 MuonAnalyzerSBSM::FillPlots(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00060 {
00061    Handle<reco::MuonCollection> theMuonCollectionHandle;
00062    iEvent.getByLabel(muonTag_, theMuonCollectionHandle);
00063    Muons = *theMuonCollectionHandle;
00064    
00065    //Find reco muon with highest Pt, fill histos with lead reco muon pt and eta
00066    int indexOfLeadRecoMuon=-1;
00067    double LeadRecoMuonPt=-1, LeadRecoMuonEta=-1, LeadRecoMuonPhi=-1;
00068    for(size_t i=0; i<Muons.size(); ++i)
00069        if(Muons[i].pt() > LeadRecoMuonPt)
00070          {
00071            indexOfLeadRecoMuon = i;
00072            LeadRecoMuonPt = Muons[i].pt();
00073            LeadRecoMuonEta = Muons[i].eta();
00074            LeadRecoMuonPhi = Muons[i].phi();
00075          }
00076    //hLeadMuonPt->Fill(Pt);
00077    //hLeadMuonEta->Fill(Eta);
00078 
00079    //Creating histograms of L3 Muons
00080    Handle<TriggerEvent> theTriggerCollectionHandle;
00081    iEvent.getByLabel(triggerTag_,theTriggerCollectionHandle);
00082    int indexOfCollection=-1, firstMuon=-1, lastMuon=-2, idOfLeadMuon=-1, indexOfFilter=-1;
00083    double LeadL3MuonPt=-1, LeadL3MuonEta=-1, LeadL3MuonPhi=-1;
00084    vector<int> idsOfFilteredMuons;
00085    bool LeadRecoMuonAssociation=false;
00086    const string L3MuonCollection = "hltL3MuonCandidates::HLT";
00087    const string TriggerFilter = "hltSingleMu9L3Filtered9::HLT";
00088    const TriggerObjectCollection& TOC(theTriggerCollectionHandle->getObjects());
00089    if(theTriggerCollectionHandle.isValid())
00090      {
00091        for(int i=0; i<theTriggerCollectionHandle->sizeCollections(); ++i)
00092          {
00093            if(L3MuonCollection.compare(theTriggerCollectionHandle->collectionTag(i).encode())==0)
00094              {
00095                indexOfCollection = i;
00096                break;
00097              }
00098          }
00099        for(int i=0; i<theTriggerCollectionHandle->sizeFilters(); ++i)
00100          {
00101            if(TriggerFilter.compare(theTriggerCollectionHandle->filterTag(i).encode())==0)
00102              {
00103                indexOfFilter=i;
00104                //idsOfFilteredMuons = new int[theTriggerCollectionHandle->filterKeys(i).size()];
00105                const Keys& KEYS(theTriggerCollectionHandle->filterKeys(i));
00106                for(size_t j=0; j<KEYS.size(); ++j)
00107                  idsOfFilteredMuons.push_back(KEYS[j]);
00108                break;
00109              }
00110          }
00111        if(indexOfCollection!=-1 && indexOfFilter!=-1)
00112          {
00113            if(indexOfCollection==0)
00114              firstMuon = 0;
00115            else
00116              firstMuon = theTriggerCollectionHandle->collectionKey(indexOfCollection-1);
00117            lastMuon = theTriggerCollectionHandle->collectionKey(indexOfCollection)-1;     
00118            for(int i=firstMuon; i<=lastMuon; ++i)
00119              {
00120                const TriggerObject& TO(TOC[i]);
00121                  if(TO.pt()>LeadL3MuonPt && find(idsOfFilteredMuons,i))
00122                  {
00123                    LeadL3MuonPt = TO.pt();
00124                    idOfLeadMuon = i;
00125                  }
00126                  if(indexOfLeadRecoMuon!=-1 && find(idsOfFilteredMuons,i) && sqrt(std::pow(LeadRecoMuonEta-TO.eta(),2)+std::pow(LeadRecoMuonPhi-TO.phi(),2))<=0.5)
00127                    LeadRecoMuonAssociation=true;
00128              }
00129            const TriggerObject& TO(TOC[idOfLeadMuon]);
00130            //hL3LeadMuonPt->Fill(L3LeadMuonPt);
00131            //hL3LeadMuonEta->Fill(TO.eta());
00132            //hL3LeadMuonPhi->Fill(TO.phi());
00133            //hL3LeadMuonMass->Fill(TO.mass());
00134            //hNumberL3Muons->Fill(lastMuon-firstMuon+1);
00135            LeadL3MuonPt = TO.pt();
00136            LeadL3MuonEta = TO.eta();
00137            LeadL3MuonPhi = TO.phi();
00138          }
00139        //else
00140        //hNumberL3Muons->Fill(0);
00141      }
00142    //else
00143    //hNumberL3Muons->Fill(0);
00144 
00145    //Fill the histos
00146    if(indexOfLeadRecoMuon!=-1)
00147      {
00148        if(std::abs(LeadRecoMuonEta)<=1.2)
00149          hLeadRecoMuonPt_1_ByEvent->Fill(LeadRecoMuonPt);
00150        else if(std::abs(LeadRecoMuonEta)>1.2 && std::abs(LeadRecoMuonEta)<=2.1)
00151          hLeadRecoMuonPt_2_ByEvent->Fill(LeadRecoMuonPt);
00152        else if(std::abs(LeadRecoMuonEta)>2.1)
00153          hLeadRecoMuonPt_3_ByEvent->Fill(LeadRecoMuonPt);
00154        if(LeadRecoMuonPt>=0)
00155          hLeadRecoMuonEta_1_ByEvent->Fill(LeadRecoMuonEta);
00156        if(LeadRecoMuonPt>=10)
00157          hLeadRecoMuonEta_2_ByEvent->Fill(LeadRecoMuonEta);
00158        if(LeadRecoMuonPt>=20)
00159          hLeadRecoMuonEta_3_ByEvent->Fill(LeadRecoMuonEta);
00160      }
00161    if(LeadRecoMuonAssociation)
00162      {
00163        if(std::abs(LeadRecoMuonEta)<=1.2)
00164          hLeadAssocRecoMuonPt_1_ByEvent->Fill(LeadRecoMuonPt);
00165        else if(std::abs(LeadRecoMuonEta)>1.2 && std::abs(LeadRecoMuonEta)<=2.1)
00166          hLeadAssocRecoMuonPt_2_ByEvent->Fill(LeadRecoMuonPt);
00167        else if(std::abs(LeadRecoMuonEta)>2.1)
00168          hLeadAssocRecoMuonPt_3_ByEvent->Fill(LeadRecoMuonPt);
00169        if(LeadRecoMuonPt>=0)
00170          hLeadAssocRecoMuonEta_1_ByEvent->Fill(LeadRecoMuonEta);
00171        if(LeadRecoMuonPt>=10)
00172          hLeadAssocRecoMuonEta_2_ByEvent->Fill(LeadRecoMuonEta);
00173        if(LeadRecoMuonPt>=20)
00174          hLeadAssocRecoMuonEta_3_ByEvent->Fill(LeadRecoMuonEta);
00175      }
00176 
00177    //Muon by muon
00178 
00179    if(Muons.size()!=0)
00180      {
00181        for(size_t i=0; i<Muons.size(); ++i)
00182          {
00183            double RecoMuonPt=Muons[i].pt(), RecoMuonEta=Muons[i].eta();
00184            if(std::abs(RecoMuonEta)<=1.2)
00185              hRecoMuonPt_1_ByMuon->Fill(RecoMuonPt);
00186            else if(std::abs(RecoMuonEta)>1.2 && std::abs(RecoMuonEta)<=2.1)
00187              hRecoMuonPt_2_ByMuon->Fill(RecoMuonPt);
00188            else if(std::abs(RecoMuonEta)>2.1)
00189              hRecoMuonPt_3_ByMuon->Fill(RecoMuonPt);
00190            if(RecoMuonPt>=0)
00191              hRecoMuonEta_1_ByMuon->Fill(RecoMuonEta);
00192            if(RecoMuonPt>=10)
00193              hRecoMuonEta_2_ByMuon->Fill(RecoMuonEta);
00194            if(RecoMuonPt>=20)
00195              hRecoMuonEta_3_ByMuon->Fill(RecoMuonEta);
00196 
00197            if(lastMuon-firstMuon+1 > 0)
00198              {
00199                for(int j=firstMuon; j<=lastMuon; ++j)
00200                  {
00201                    const TriggerObject& TO(TOC[j]);
00202                    if(find(idsOfFilteredMuons,j) && sqrt(std::pow(TO.eta()-Muons[i].eta(), 2)+std::pow(TO.phi()-Muons[i].phi(), 2)) <= 0.5)
00203                      {
00204                        RecoMuonPt=Muons[i].pt();
00205                        RecoMuonEta=Muons[i].eta();
00206                        if(std::abs(RecoMuonEta)<=1.2)
00207                          hAssocRecoMuonPt_1_ByMuon->Fill(RecoMuonPt);
00208                        else if(std::abs(RecoMuonEta)>1.2 && std::abs(RecoMuonEta)<=2.1)
00209                          hAssocRecoMuonPt_2_ByMuon->Fill(RecoMuonPt);
00210                        else if(std::abs(RecoMuonEta)>2.1)
00211                          hAssocRecoMuonPt_3_ByMuon->Fill(RecoMuonPt);
00212                        if(RecoMuonPt>=0)
00213                          hAssocRecoMuonEta_1_ByMuon->Fill(RecoMuonEta);
00214                        if(RecoMuonPt>=10)
00215                          hAssocRecoMuonEta_2_ByMuon->Fill(RecoMuonEta);
00216                        if(RecoMuonPt>=20)
00217                          hAssocRecoMuonEta_3_ByMuon->Fill(RecoMuonEta);
00218 
00219                        break; 
00220                      }
00221                  }
00222              }
00223          }
00224      }
00225 
00226    //Another approach to Muon by Muon, comparing order in pt
00227 
00228 
00229 
00230    /*for(size_t i=0; i<Muons.size(); ++i)
00231      {
00232        for(int j=0; j<lastMuon-firstMuon+1; ++j)
00233          {
00234            const TriggerObject& TO(TOC[j]);
00235            cout<<(sqrt(std::pow(TO.eta()-Muons[i].eta(),2)+std::pow(TO.phi()-Muons[i].phi(),2))<=0.5)<<'\t';
00236          }
00237        cout<<endl;
00238        }*/
00239    
00240 
00241 
00242 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00243    Handle<ExampleData> pIn;
00244    iEvent.getByLabel("example",pIn);
00245 #endif
00246    
00247 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00248    ESHandle<SetupData> pSetup;
00249    iSetup.get<SetupRecord>().get(pSetup);
00250 #endif
00251 }
00252 
00253 
00254 // ------------ method called once each job just before starting event loop  ------------
00255 void 
00256 MuonAnalyzerSBSM::InitializePlots(DQMStore* dbe_, string subDir)
00257 {
00258    //now do what ever initialization is needed
00259   int pt_bins=100, eta_bins=100;
00260   double pt_floor=0., pt_ceiling = 200., eta_floor=-3.5, eta_ceiling=3.5;
00261 
00262   dbe_->setCurrentFolder(subDir + "/By_Event");
00263   hLeadRecoMuonPt_1_ByEvent = dbe_->book1D("LeadRecoMuonPt_1_ByEvent" , "Lead Reco Muon P_{t}, |Eta|<1.2, By Event", pt_bins, pt_floor, pt_ceiling);
00264   hLeadRecoMuonEta_1_ByEvent= dbe_->book1D("LeadRecoMuonEta_1_ByEvent", "Lead Reco Muon Eta, P_{t}>0, By Event", eta_bins, eta_floor,eta_ceiling);
00265   hLeadRecoMuonPt_2_ByEvent = dbe_->book1D("LeadRecoMuonPt_2_ByEvent" , "Lead Reco Muon P_{t}, 1.2<|Eta|<2.1, By Event", pt_bins, pt_floor, pt_ceiling);
00266   hLeadRecoMuonEta_2_ByEvent= dbe_->book1D("LeadRecoMuonEta_2_ByEvent", "Lead Reco Muon Eta, P_{t}>10, By Event", eta_bins, eta_floor,eta_ceiling);
00267   hLeadRecoMuonPt_3_ByEvent = dbe_->book1D("LeadRecoMuonPt_3_ByEvent" , "Lead Reco Muon P_{t}, |Eta|>2.1, By Event", pt_bins, pt_floor, pt_ceiling);
00268   hLeadRecoMuonEta_3_ByEvent= dbe_->book1D("LeadRecoMuonEta_3_ByEvent", "Lead Reco Muon Eta, P_{t}>20, By Event", eta_bins, eta_floor,eta_ceiling);
00269   hLeadAssocRecoMuonPt_1_ByEvent = dbe_->book1D("LeadAssocRecoMuonPt_1_ByEvent" , "Lead Assoc Reco Muon P_{t}, |Eta|<1.2, By Event", pt_bins, pt_floor, pt_ceiling);
00270   hLeadAssocRecoMuonEta_1_ByEvent= dbe_->book1D("LeadAssocRecoMuonEta_1_ByEvent", "Lead Assoc Muon Eta, P_{t}>0, By Event", eta_bins, eta_floor,eta_ceiling);
00271   hLeadAssocRecoMuonPt_2_ByEvent = dbe_->book1D("LeadAssocRecoMuonPt_2_ByEvent" , "Lead Assoc Reco Muon P_{t}, 1.2<|Eta|<2.1, By Event", pt_bins, pt_floor, pt_ceiling);
00272   hLeadAssocRecoMuonEta_2_ByEvent= dbe_->book1D("LeadAssocRecoMuonEta_2_ByEvent", "Lead Assoc Muon Eta, P_{t}>10, By Event", eta_bins, eta_floor,eta_ceiling);
00273   hLeadAssocRecoMuonPt_3_ByEvent = dbe_->book1D("LeadAssocRecoMuonPt_3_ByEvent" , "Lead Assoc Reco Muon P_{t}, |Eta|>2.1, By Event", pt_bins, pt_floor, pt_ceiling);
00274   hLeadAssocRecoMuonEta_3_ByEvent= dbe_->book1D("LeadAssocRecoMuonEta_3_ByEvent", "Lead Assoc Muon Eta, P_{t}>20, By Event", eta_bins, eta_floor,eta_ceiling);
00275 
00276   dbe_->setCurrentFolder(subDir + "/By_Muon");
00277   hRecoMuonPt_1_ByMuon = dbe_->book1D("RecoMuonPt_1_ByMuon" , "Reco Muon P_{t}, |Eta|<1.2, By Muon", pt_bins, pt_floor, pt_ceiling);
00278   hRecoMuonEta_1_ByMuon= dbe_->book1D("RecoMuonEta_1_ByMuon", "Reco Muon Eta, P_{t}>0, By Muon", eta_bins, eta_floor,eta_ceiling);
00279   hRecoMuonPt_2_ByMuon = dbe_->book1D("RecoMuonPt_2_ByMuon" , "Reco Muon P_{t}, 1.2<|Eta|<2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
00280   hRecoMuonEta_2_ByMuon= dbe_->book1D("RecoMuonEta_2_ByMuon", "Reco Muon Eta, P_{t}>10, By Muon", eta_bins, eta_floor,eta_ceiling);
00281   hRecoMuonPt_3_ByMuon = dbe_->book1D("RecoMuonPt_3_ByMuon" , "Reco Muon P_{t}, |Eta|>2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
00282   hRecoMuonEta_3_ByMuon= dbe_->book1D("RecoMuonEta_3_ByMuon", "Reco Muon Eta, P_{t}>20, By Muon", eta_bins, eta_floor,eta_ceiling);
00283   hAssocRecoMuonPt_1_ByMuon = dbe_->book1D("AssocRecoMuonPt_1_ByMuon" , "Assoc Reco Muon P_{t}, |Eta|<1.2, By Muon", pt_bins, pt_floor, pt_ceiling);
00284   hAssocRecoMuonEta_1_ByMuon= dbe_->book1D("AssocRecoMuonEta_1_ByMuon", "Assoc Muon Eta, P_{t}>0, By Muon", eta_bins, eta_floor,eta_ceiling);
00285   hAssocRecoMuonPt_2_ByMuon = dbe_->book1D("AssocRecoMuonPt_2_ByMuon" , "Assoc Reco Muon P_{t}, 1.2<|Eta|<2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
00286   hAssocRecoMuonEta_2_ByMuon= dbe_->book1D("AssocRecoMuonEta_2_ByMuon", "Assoc Muon Eta, P_{t}>10, By Muon", eta_bins, eta_floor,eta_ceiling);
00287   hAssocRecoMuonPt_3_ByMuon = dbe_->book1D("AssocRecoMuonPt_3_ByMuon" , "Assoc Reco Muon P_{t}, |Eta|>2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
00288   hAssocRecoMuonEta_3_ByMuon= dbe_->book1D("AssocRecoMuonEta_3_ByMuon", "Assoc Muon Eta, P_{t}>20, By Muon", eta_bins, eta_floor,eta_ceiling);
00289 }
00290 //define this as a plug-in
00291 //DEFINE_FWK_MODULE(MuonAnalyzerSBSM);