CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MuonAnalyzerSBSM
4 // Class: MuonAnalyzerSBSM
5 //
13 //
14 // Original Author: Philip Hebda
15 // Created: Thu Jun 25 09:34:50 CEST 2009
16 //
17 //
20 
21 
23 #include "TDirectory.h"
24 
26 //
27 // class decleration
28 //
29 
30 using namespace edm;
31 using namespace reco;
32 using namespace std;
33 using namespace trigger;
34 
35 
37 {
38  triggerTag_ = iC.consumes<trigger::TriggerEvent>(edm::InputTag(triggerTag_v));
39  muonTag_ = iC.consumes<reco::MuonCollection>(edm::InputTag(muonTag_v));
40 }
41 
42 bool MuonAnalyzerSBSM::find(const std::vector<int>& vec, int element)
43 {
44  for(size_t i=0; i<vec.size(); ++i)
45  {
46  if(vec[i]==element)
47  return true;
48  }
49  return false;
50 }
51 
52 //
53 // member functions
54 //
55 
56 // ------------ method called to for each event ------------
57 void
59 {
60  Handle<reco::MuonCollection> theMuonCollectionHandle;
61  iEvent.getByToken(muonTag_, theMuonCollectionHandle);
62  Muons = *theMuonCollectionHandle;
63 
64  //Find reco muon with highest Pt, fill histos with lead reco muon pt and eta
65  int indexOfLeadRecoMuon=-1;
66  double LeadRecoMuonPt=-1, LeadRecoMuonEta=-1, LeadRecoMuonPhi=-1;
67  for(size_t i=0; i<Muons.size(); ++i)
68  if(Muons[i].pt() > LeadRecoMuonPt)
69  {
70  indexOfLeadRecoMuon = i;
71  LeadRecoMuonPt = Muons[i].pt();
72  LeadRecoMuonEta = Muons[i].eta();
73  LeadRecoMuonPhi = Muons[i].phi();
74  }
75  //hLeadMuonPt->Fill(Pt);
76  //hLeadMuonEta->Fill(Eta);
77 
78  //Creating histograms of L3 Muons
79  Handle<TriggerEvent> theTriggerCollectionHandle;
80  iEvent.getByToken(triggerTag_,theTriggerCollectionHandle);
81  trigger::size_type firstMuon=-1, lastMuon=-2;
82  int indexOfCollection=-1, idOfLeadMuon=-1, indexOfFilter=-1;
83  double LeadL3MuonPt=-1; // , LeadL3MuonEta=-1, LeadL3MuonPhi=-1; // UNUSED
84  vector<int> idsOfFilteredMuons;
85  bool LeadRecoMuonAssociation=false;
86  const string L3MuonCollection = "hltL3MuonCandidates::HLT";
87  const string TriggerFilter = "hltSingleMu9L3Filtered9::HLT";
88  const TriggerObjectCollection& TOC(theTriggerCollectionHandle->getObjects());
89  if(theTriggerCollectionHandle.isValid())
90  {
91  for(int i=0; i<theTriggerCollectionHandle->sizeCollections(); ++i)
92  {
93  if(L3MuonCollection.compare(theTriggerCollectionHandle->collectionTag(i).encode())==0)
94  {
95  indexOfCollection = i;
96  break;
97  }
98  }
99  for(int i=0; i<theTriggerCollectionHandle->sizeFilters(); ++i)
100  {
101  if(TriggerFilter.compare(theTriggerCollectionHandle->filterTag(i).encode())==0)
102  {
103  indexOfFilter=i;
104  //idsOfFilteredMuons = new int[theTriggerCollectionHandle->filterKeys(i).size()];
105  const Keys& KEYS(theTriggerCollectionHandle->filterKeys(i));
106  for(size_t j=0; j<KEYS.size(); ++j)
107  idsOfFilteredMuons.push_back(KEYS[j]);
108  break;
109  }
110  }
111  if(indexOfCollection!=-1 && indexOfFilter!=-1)
112  {
113  if(indexOfCollection==0)
114  firstMuon = 0;
115  else
116  firstMuon = theTriggerCollectionHandle->collectionKey(indexOfCollection-1);
117  lastMuon = theTriggerCollectionHandle->collectionKey(indexOfCollection)-1;
118  for(int i=firstMuon; i<=lastMuon; ++i)
119  {
120  const TriggerObject& TO(TOC[i]);
121  if(TO.pt()>LeadL3MuonPt && find(idsOfFilteredMuons,i))
122  {
123  LeadL3MuonPt = TO.pt();
124  idOfLeadMuon = i;
125  }
126  if(indexOfLeadRecoMuon!=-1 && find(idsOfFilteredMuons,i) && sqrt(std::pow(LeadRecoMuonEta-TO.eta(),2)+std::pow(LeadRecoMuonPhi-TO.phi(),2))<=0.5)
127  LeadRecoMuonAssociation=true;
128  }
129  const TriggerObject& TO(TOC[idOfLeadMuon]);
130  //hL3LeadMuonPt->Fill(L3LeadMuonPt);
131  //hL3LeadMuonEta->Fill(TO.eta());
132  //hL3LeadMuonPhi->Fill(TO.phi());
133  //hL3LeadMuonMass->Fill(TO.mass());
134  //hNumberL3Muons->Fill(lastMuon-firstMuon+1);
135  LeadL3MuonPt = TO.pt();
136  // LeadL3MuonEta = TO.eta(); // UNUSED
137  // LeadL3MuonPhi = TO.phi(); // UNUSED
138  }
139  //else
140  //hNumberL3Muons->Fill(0);
141  }
142  //else
143  //hNumberL3Muons->Fill(0);
144 
145  //Fill the histos
146  if(indexOfLeadRecoMuon!=-1)
147  {
148  if(std::abs(LeadRecoMuonEta)<=1.2)
149  hLeadRecoMuonPt_1_ByEvent->Fill(LeadRecoMuonPt);
150  else if(std::abs(LeadRecoMuonEta)>1.2 && std::abs(LeadRecoMuonEta)<=2.1)
151  hLeadRecoMuonPt_2_ByEvent->Fill(LeadRecoMuonPt);
152  else if(std::abs(LeadRecoMuonEta)>2.1)
153  hLeadRecoMuonPt_3_ByEvent->Fill(LeadRecoMuonPt);
154  if(LeadRecoMuonPt>=0)
155  hLeadRecoMuonEta_1_ByEvent->Fill(LeadRecoMuonEta);
156  if(LeadRecoMuonPt>=10)
157  hLeadRecoMuonEta_2_ByEvent->Fill(LeadRecoMuonEta);
158  if(LeadRecoMuonPt>=20)
159  hLeadRecoMuonEta_3_ByEvent->Fill(LeadRecoMuonEta);
160  }
161  if(LeadRecoMuonAssociation)
162  {
163  if(std::abs(LeadRecoMuonEta)<=1.2)
164  hLeadAssocRecoMuonPt_1_ByEvent->Fill(LeadRecoMuonPt);
165  else if(std::abs(LeadRecoMuonEta)>1.2 && std::abs(LeadRecoMuonEta)<=2.1)
166  hLeadAssocRecoMuonPt_2_ByEvent->Fill(LeadRecoMuonPt);
167  else if(std::abs(LeadRecoMuonEta)>2.1)
168  hLeadAssocRecoMuonPt_3_ByEvent->Fill(LeadRecoMuonPt);
169  if(LeadRecoMuonPt>=0)
170  hLeadAssocRecoMuonEta_1_ByEvent->Fill(LeadRecoMuonEta);
171  if(LeadRecoMuonPt>=10)
172  hLeadAssocRecoMuonEta_2_ByEvent->Fill(LeadRecoMuonEta);
173  if(LeadRecoMuonPt>=20)
174  hLeadAssocRecoMuonEta_3_ByEvent->Fill(LeadRecoMuonEta);
175  }
176 
177  //Muon by muon
178 
179  if(Muons.size()!=0)
180  {
181  for(size_t i=0; i<Muons.size(); ++i)
182  {
183  double RecoMuonPt=Muons[i].pt(), RecoMuonEta=Muons[i].eta();
184  if(std::abs(RecoMuonEta)<=1.2)
185  hRecoMuonPt_1_ByMuon->Fill(RecoMuonPt);
186  else if(std::abs(RecoMuonEta)>1.2 && std::abs(RecoMuonEta)<=2.1)
187  hRecoMuonPt_2_ByMuon->Fill(RecoMuonPt);
188  else if(std::abs(RecoMuonEta)>2.1)
189  hRecoMuonPt_3_ByMuon->Fill(RecoMuonPt);
190  if(RecoMuonPt>=0)
191  hRecoMuonEta_1_ByMuon->Fill(RecoMuonEta);
192  if(RecoMuonPt>=10)
193  hRecoMuonEta_2_ByMuon->Fill(RecoMuonEta);
194  if(RecoMuonPt>=20)
195  hRecoMuonEta_3_ByMuon->Fill(RecoMuonEta);
196 
197  if(lastMuon-firstMuon+1 > 0)
198  {
199  for(int j=firstMuon; j<=lastMuon; ++j)
200  {
201  const TriggerObject& TO(TOC[j]);
202  if(find(idsOfFilteredMuons,j) && sqrt(std::pow(TO.eta()-Muons[i].eta(), 2)+std::pow(TO.phi()-Muons[i].phi(), 2)) <= 0.5)
203  {
204  RecoMuonPt=Muons[i].pt();
205  RecoMuonEta=Muons[i].eta();
206  if(std::abs(RecoMuonEta)<=1.2)
207  hAssocRecoMuonPt_1_ByMuon->Fill(RecoMuonPt);
208  else if(std::abs(RecoMuonEta)>1.2 && std::abs(RecoMuonEta)<=2.1)
209  hAssocRecoMuonPt_2_ByMuon->Fill(RecoMuonPt);
210  else if(std::abs(RecoMuonEta)>2.1)
211  hAssocRecoMuonPt_3_ByMuon->Fill(RecoMuonPt);
212  if(RecoMuonPt>=0)
213  hAssocRecoMuonEta_1_ByMuon->Fill(RecoMuonEta);
214  if(RecoMuonPt>=10)
215  hAssocRecoMuonEta_2_ByMuon->Fill(RecoMuonEta);
216  if(RecoMuonPt>=20)
217  hAssocRecoMuonEta_3_ByMuon->Fill(RecoMuonEta);
218 
219  break;
220  }
221  }
222  }
223  }
224  }
225 
226  //Another approach to Muon by Muon, comparing order in pt
227 
228 
229 
230  /*for(size_t i=0; i<Muons.size(); ++i)
231  {
232  for(int j=0; j<lastMuon-firstMuon+1; ++j)
233  {
234  const TriggerObject& TO(TOC[j]);
235  cout<<(sqrt(std::pow(TO.eta()-Muons[i].eta(),2)+std::pow(TO.phi()-Muons[i].phi(),2))<=0.5)<<'\t';
236  }
237  cout<<endl;
238  }*/
239 
240 
241 }
242 
243 
244 // ------------ method called once each job just before starting event loop ------------
245 void
247 {
248  //now do what ever initialization is needed
249  int pt_bins=100, eta_bins=100;
250  double pt_floor=0., pt_ceiling = 200., eta_floor=-3.5, eta_ceiling=3.5;
251 
252  dbe_->setCurrentFolder(subDir + "/By_Event");
253  hLeadRecoMuonPt_1_ByEvent = dbe_->book1D("LeadRecoMuonPt_1_ByEvent" , "Lead Reco Muon P_{t}, |Eta|<1.2, By Event", pt_bins, pt_floor, pt_ceiling);
254  hLeadRecoMuonEta_1_ByEvent= dbe_->book1D("LeadRecoMuonEta_1_ByEvent", "Lead Reco Muon Eta, P_{t}>0, By Event", eta_bins, eta_floor,eta_ceiling);
255  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);
256  hLeadRecoMuonEta_2_ByEvent= dbe_->book1D("LeadRecoMuonEta_2_ByEvent", "Lead Reco Muon Eta, P_{t}>10, By Event", eta_bins, eta_floor,eta_ceiling);
257  hLeadRecoMuonPt_3_ByEvent = dbe_->book1D("LeadRecoMuonPt_3_ByEvent" , "Lead Reco Muon P_{t}, |Eta|>2.1, By Event", pt_bins, pt_floor, pt_ceiling);
258  hLeadRecoMuonEta_3_ByEvent= dbe_->book1D("LeadRecoMuonEta_3_ByEvent", "Lead Reco Muon Eta, P_{t}>20, By Event", eta_bins, eta_floor,eta_ceiling);
259  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);
260  hLeadAssocRecoMuonEta_1_ByEvent= dbe_->book1D("LeadAssocRecoMuonEta_1_ByEvent", "Lead Assoc Muon Eta, P_{t}>0, By Event", eta_bins, eta_floor,eta_ceiling);
261  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);
262  hLeadAssocRecoMuonEta_2_ByEvent= dbe_->book1D("LeadAssocRecoMuonEta_2_ByEvent", "Lead Assoc Muon Eta, P_{t}>10, By Event", eta_bins, eta_floor,eta_ceiling);
263  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);
264  hLeadAssocRecoMuonEta_3_ByEvent= dbe_->book1D("LeadAssocRecoMuonEta_3_ByEvent", "Lead Assoc Muon Eta, P_{t}>20, By Event", eta_bins, eta_floor,eta_ceiling);
265 
266  dbe_->setCurrentFolder(subDir + "/By_Muon");
267  hRecoMuonPt_1_ByMuon = dbe_->book1D("RecoMuonPt_1_ByMuon" , "Reco Muon P_{t}, |Eta|<1.2, By Muon", pt_bins, pt_floor, pt_ceiling);
268  hRecoMuonEta_1_ByMuon= dbe_->book1D("RecoMuonEta_1_ByMuon", "Reco Muon Eta, P_{t}>0, By Muon", eta_bins, eta_floor,eta_ceiling);
269  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);
270  hRecoMuonEta_2_ByMuon= dbe_->book1D("RecoMuonEta_2_ByMuon", "Reco Muon Eta, P_{t}>10, By Muon", eta_bins, eta_floor,eta_ceiling);
271  hRecoMuonPt_3_ByMuon = dbe_->book1D("RecoMuonPt_3_ByMuon" , "Reco Muon P_{t}, |Eta|>2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
272  hRecoMuonEta_3_ByMuon= dbe_->book1D("RecoMuonEta_3_ByMuon", "Reco Muon Eta, P_{t}>20, By Muon", eta_bins, eta_floor,eta_ceiling);
273  hAssocRecoMuonPt_1_ByMuon = dbe_->book1D("AssocRecoMuonPt_1_ByMuon" , "Assoc Reco Muon P_{t}, |Eta|<1.2, By Muon", pt_bins, pt_floor, pt_ceiling);
274  hAssocRecoMuonEta_1_ByMuon= dbe_->book1D("AssocRecoMuonEta_1_ByMuon", "Assoc Muon Eta, P_{t}>0, By Muon", eta_bins, eta_floor,eta_ceiling);
275  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);
276  hAssocRecoMuonEta_2_ByMuon= dbe_->book1D("AssocRecoMuonEta_2_ByMuon", "Assoc Muon Eta, P_{t}>10, By Muon", eta_bins, eta_floor,eta_ceiling);
277  hAssocRecoMuonPt_3_ByMuon = dbe_->book1D("AssocRecoMuonPt_3_ByMuon" , "Assoc Reco Muon P_{t}, |Eta|>2.1, By Muon", pt_bins, pt_floor, pt_ceiling);
278  hAssocRecoMuonEta_3_ByMuon= dbe_->book1D("AssocRecoMuonEta_3_ByMuon", "Assoc Muon Eta, P_{t}>20, By Muon", eta_bins, eta_floor,eta_ceiling);
279 }
280 //define this as a plug-in
281 //DEFINE_FWK_MODULE(MuonAnalyzerSBSM);
int i
Definition: DBlmapReader.cc:9
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
float phi() const
Definition: TriggerObject.h:58
bool find(const std::vector< int > &, int)
Definition: MuonAnalyzer.cc:42
float eta() const
Definition: TriggerObject.h:57
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void FillPlots(const edm::Event &, const edm::EventSetup &)
Definition: MuonAnalyzer.cc:58
uint16_t size_type
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
int iEvent
Definition: GenABIO.cc:230
T sqrt(T t)
Definition: SSEVec.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:75
DQMStore * dbe_
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
std::vector< size_type > Keys
MuonAnalyzerSBSM(const edm::InputTag &, const edm::InputTag &, edm::ConsumesCollector &&iC)
Definition: MuonAnalyzer.cc:36
void InitializePlots(DQMStore *, const std::string)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40