CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HeavyFlavorValidation.cc
Go to the documentation of this file.
1 
8 // Original Author: Zoltan Gecse
9 
10 #include <memory>
20 
36 
38 
42 
44 
45 #include "TLorentzVector.h"
46 
47 using namespace std;
48 using namespace edm;
49 using namespace reco;
50 using namespace l1extra;
51 using namespace trigger;
52 
54  public:
57  protected:
58  void dqmBeginRun(const edm::Run&, const edm::EventSetup&);
59  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
60  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
61  private:
62  int getMotherId( const Candidate * p );
63  void match( MonitorElement * me, vector<LeafCandidate> & from, vector<LeafCandidate> & to, double deltaRMatchingCut, vector<int> & map );
64  void myBook2D(DQMStore::IBooker & ibooker, TString name, vector<double> &xBins, TString xLabel, vector<double> &yBins, TString yLabel, TString title);
65  void myBook2D(DQMStore::IBooker & ibooker, TString name, vector<double> &xBins, TString xLabel, vector<double> &yBins, TString yLabel){
66  myBook2D(ibooker, name, xBins, xLabel, yBins, yLabel, name);
67  }
68  void myBookProfile2D(DQMStore::IBooker & ibooker, TString name, vector<double> &xBins, TString xLabel, vector<double> &yBins, TString yLabel, TString title);
69  void myBookProfile2D(DQMStore::IBooker & ibooker, TString name, vector<double> &xBins, TString xLabel, vector<double> &yBins, TString yLabel){
70  myBookProfile2D(ibooker, name, xBins, xLabel, yBins, yLabel, name);
71  }
72  void myBook1D(DQMStore::IBooker & ibooker, TString name, vector<double> &xBins, TString label, TString title );
73  void myBook1D(DQMStore::IBooker & ibooker, TString name, vector<double> &xBins, TString label ){
74  myBook1D(ibooker, name, xBins, label, name );
75  }
76  string dqmFolder;
79 
85 
86  vector<int> motherIDs;
91  vector<double> deltaEtaBins;
92  vector<double> deltaPhiBins;
93  vector<double> muonPtBins;
94  vector<double> muonEtaBins;
95  vector<double> muonPhiBins;
96  vector<double> dimuonPtBins;
97  vector<double> dimuonEtaBins;
98  vector<double> dimuonDRBins;
100  map<TString, MonitorElement *> ME;
101  vector<pair<string,int> > filterNamesLevels;
102  const double muonMass;
103 };
104 
106 //get parameters
107  dqmFolder(pset.getUntrackedParameter<string>("DQMFolder")),
108  triggerProcessName(pset.getUntrackedParameter<string>("TriggerProcessName")),
109  triggerPathName(pset.getUntrackedParameter<string>("TriggerPathName")),
110  motherIDs(pset.getUntrackedParameter<vector<int> >("MotherIDs")),
111  genGlobDeltaRMatchingCut(pset.getUntrackedParameter<double>("GenGlobDeltaRMatchingCut")),
112  globL1DeltaRMatchingCut(pset.getUntrackedParameter<double>("GlobL1DeltaRMatchingCut")),
113  globL2DeltaRMatchingCut(pset.getUntrackedParameter<double>("GlobL2DeltaRMatchingCut")),
114  globL3DeltaRMatchingCut(pset.getUntrackedParameter<double>("GlobL3DeltaRMatchingCut")),
115  deltaEtaBins(pset.getUntrackedParameter<vector<double> >("DeltaEtaBins")),
116  deltaPhiBins(pset.getUntrackedParameter<vector<double> >("DeltaPhiBins")),
117  muonPtBins(pset.getUntrackedParameter<vector<double> >("MuonPtBins")),
118  muonEtaBins(pset.getUntrackedParameter<vector<double> >("MuonEtaBins")),
119  muonPhiBins(pset.getUntrackedParameter<vector<double> >("MuonPhiBins")),
120  dimuonPtBins(pset.getUntrackedParameter<vector<double> >("DimuonPtBins")),
121  dimuonEtaBins(pset.getUntrackedParameter<vector<double> >("DimuonEtaBins")),
122  dimuonDRBins(pset.getUntrackedParameter<vector<double> >("DimuonDRBins")),
123  muonMass(0.106)
124 {
125  triggerSummaryRAWTag = consumes<TriggerEventWithRefs>(InputTag( pset.getUntrackedParameter<string>("TriggerSummaryRAW"), "", triggerProcessName));
126  triggerSummaryAODTag = consumes<TriggerEvent>(InputTag( pset.getUntrackedParameter<string>("TriggerSummaryAOD"), "", triggerProcessName));
127  triggerResultsTag = consumes<TriggerResults>(InputTag( pset.getUntrackedParameter<string>("TriggerResults"), "", triggerProcessName));
128  recoMuonsTag = consumes<MuonCollection>(pset.getParameter<InputTag>("RecoMuons"));
129  genParticlesTag = consumes<GenParticleCollection>(pset.getParameter<InputTag>("GenParticles"));
130 }
131 
132 void HeavyFlavorValidation::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup & iSetup ) {
133  //discover HLT configuration
135  bool isChanged;
136  if(hltConfig.init(iRun, iSetup, triggerProcessName, isChanged)){
137  LogDebug("HLTriggerOfflineHeavyFlavor") << "Successfully initialized HLTConfigProvider with process name: "<<triggerProcessName<<endl;
138  }else{
139  LogWarning("HLTriggerOfflineHeavyFlavor") << "Could not initialize HLTConfigProvider with process name: "<<triggerProcessName<<endl;
140  return;
141  }
142  stringstream os;
143  vector<string> triggerNames = hltConfig.triggerNames();
144  for( size_t i = 0; i < triggerNames.size(); i++) {
145  TString triggerName = triggerNames[i];
146  if (triggerName.Contains(triggerPathName)){
147  vector<string> moduleNames = hltConfig.moduleLabels( triggerNames[i] );
148  for( size_t j = 0; j < moduleNames.size(); j++) {
149  TString name = moduleNames[j];
150  if(name.Contains("Filter")){
151  int level = 0;
152  if(name.Contains("L1"))
153  level = 1;
154  else if(name.Contains("L2"))
155  level = 2;
156  else if(name.Contains("L3"))
157  level = 3;
158  else if(name.Contains("mumuFilter") || name.Contains("JpsiTrackMass"))
159  level = 4;
160  filterNamesLevels.push_back( pair<string,int>(moduleNames[j],level) );
161  os<<" "<<moduleNames[j];
162  }
163  }
164  break;
165  }
166  }
167  if(filterNamesLevels.size()==0){
168  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Bad Trigger Path: "<<triggerPathName<<endl;
169  return;
170  }else{
171  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Trigger Path: "<<triggerPathName<<" has filters:"<<os.str();
172  }
173 }
174 
175 
176 
178  edm::Run const & iRun,
179  edm::EventSetup const & iSetup) {
180  ibooker.cd();
182 
183  // create Monitor Elements
184  // Eta Pt Single
185  myBook2D(ibooker, "genMuon_genEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
186  myBook2D(ibooker, "globMuon_genEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
187  myBook2D(ibooker, "globMuon_recoEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
188 
189  for(size_t i=0; i<filterNamesLevels.size(); i++){
190  myBook2D(ibooker, TString::Format("filt%dMuon_recoEtaPt",int(i+1)), muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)", filterNamesLevels[i].first);
191  }
192  myBook2D(ibooker, "pathMuon_recoEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)", triggerPathName);
193  myBook2D(ibooker, "resultMuon_recoEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
194  // Eta Pt Single Resolution
195  myBookProfile2D(ibooker, "resGlobGen_genEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)");
196  for(size_t i=0; i<filterNamesLevels.size(); i++){
197  myBookProfile2D(ibooker, TString::Format("resFilt%dGlob_recoEtaPt",int(i+1)), muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)", filterNamesLevels[i].first);
198  }
199  myBookProfile2D(ibooker, "resPathGlob_recoEtaPt", muonEtaBins, "#mu eta", muonPtBins, " #mu pT (GeV)", triggerPathName);
200  // Eta Pt Double
201  myBook2D(ibooker, "genDimuon_genEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)");
202  myBook2D(ibooker, "globDimuon_genEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)");
203  myBook2D(ibooker, "globDimuon_recoEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)");
204  for(size_t i=0; i<filterNamesLevels.size(); i++){
205  myBook2D(ibooker, TString::Format("filt%dDimuon_recoEtaPt",int(i+1)), dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)", filterNamesLevels[i].first);
206  }
207  myBook2D(ibooker, "pathDimuon_recoEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)", triggerPathName);
208  myBook2D(ibooker, "resultDimuon_recoEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)");
209  for(size_t i=0; i<filterNamesLevels.size(); i++){
210  myBook2D(ibooker, TString::Format("diFilt%dDimuon_recoEtaPt",int(i+1)), dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)", filterNamesLevels[i].first);
211  }
212  myBook2D(ibooker, "diPathDimuon_recoEtaPt", dimuonEtaBins, "#mu#mu eta", dimuonPtBins, " #mu#mu pT (GeV)", triggerPathName);
213  // Eta Phi Single
214  myBook2D(ibooker, "genMuon_genEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi");
215  myBook2D(ibooker, "globMuon_genEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi");
216  myBook2D(ibooker, "globMuon_recoEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi");
217  for(size_t i=0; i<filterNamesLevels.size(); i++){
218  myBook2D(ibooker, TString::Format("filt%dMuon_recoEtaPhi",int(i+1)), muonEtaBins, "#mu eta", muonPhiBins, "#mu phi", filterNamesLevels[i].first);
219  }
220  myBook2D(ibooker, "pathMuon_recoEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi", triggerPathName);
221  myBook2D(ibooker, "resultMuon_recoEtaPhi", muonEtaBins, "#mu eta", muonPhiBins, "#mu phi");
222  // Rap Pt Double
223  myBook2D(ibooker, "genDimuon_genRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)");
224  myBook2D(ibooker, "globDimuon_genRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)");
225  myBook2D(ibooker, "globDimuon_recoRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)");
226  for(size_t i=0; i<filterNamesLevels.size(); i++){
227  myBook2D(ibooker, TString::Format("filt%dDimuon_recoRapPt",int(i+1)), dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)", filterNamesLevels[i].first);
228  }
229  myBook2D(ibooker, "pathDimuon_recoRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)", triggerPathName);
230  myBook2D(ibooker, "resultDimuon_recoRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)");
231  for(size_t i=0; i<filterNamesLevels.size(); i++){
232  myBook2D(ibooker, TString::Format("diFilt%dDimuon_recoRapPt",int(i+1)), dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)", filterNamesLevels[i].first);
233  }
234  myBook2D(ibooker, "diPathDimuon_recoRapPt", dimuonEtaBins, "#mu#mu rapidity", dimuonPtBins, " #mu#mu pT (GeV)", triggerPathName);
235  // Pt DR Double
236  myBook2D(ibooker, "genDimuon_genPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP");
237  myBook2D(ibooker, "globDimuon_genPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP");
238  myBook2D(ibooker, "globDimuon_recoPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP");
239  for(size_t i=0; i<filterNamesLevels.size(); i++){
240  myBook2D(ibooker, TString::Format("filt%dDimuon_recoPtDR",int(i+1)), dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP", filterNamesLevels[i].first);
241  }
242  myBook2D(ibooker, "pathDimuon_recoPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP", triggerPathName);
243  for(size_t i=0; i<filterNamesLevels.size(); i++){
244  myBook2D(ibooker, TString::Format("diFilt%dDimuon_recoPtDR",int(i+1)), dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP", filterNamesLevels[i].first);
245  }
246  myBook2D(ibooker, "diPathDimuon_recoPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP", triggerPathName);
247  myBook2D(ibooker, "resultDimuon_recoPtDR", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R at IP");
248  // Pt DRpos Double
249  myBook2D(ibooker, "globDimuon_recoPtDRpos", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R in MS");
250  for(size_t i=0; i<filterNamesLevels.size(); i++){
251  myBook2D(ibooker, TString::Format("filt%dDimuon_recoPtDRpos",int(i+1)), dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R in MS", filterNamesLevels[i].first);
252  }
253  myBook2D(ibooker, "pathDimuon_recoPtDRpos", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R in MS", triggerPathName);
254  for(size_t i=0; i<filterNamesLevels.size(); i++){
255  myBook2D(ibooker, TString::Format("diFilt%dDimuon_recoPtDRpos",int(i+1)), dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R in MS", filterNamesLevels[i].first);
256  }
257  myBook2D(ibooker, "diPathDimuon_recoPtDRpos", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R in MS", triggerPathName);
258  myBook2D(ibooker, "resultDimuon_recoPtDRpos", dimuonPtBins, " #mu#mu pT (GeV)", dimuonDRBins, "#mu#mu #Delta R in MS");
259 
260  // Matching
261  myBook2D(ibooker, "globGen_deltaEtaDeltaPhi", deltaEtaBins, "#Delta eta", deltaPhiBins, "#Delta phi");
262  for(size_t i=0; i<filterNamesLevels.size(); i++){
263  myBook2D(ibooker, TString::Format("filt%dGlob_deltaEtaDeltaPhi",int(i+1)), deltaEtaBins, "#Delta eta", deltaPhiBins, "#Delta phi", filterNamesLevels[i].first);
264  }
265  myBook2D(ibooker, "pathGlob_deltaEtaDeltaPhi", deltaEtaBins, "#Delta eta", deltaPhiBins, "#Delta phi", triggerPathName);
266  // Size of containers
267  vector<double> sizeBins; sizeBins.push_back(10); sizeBins.push_back(0); sizeBins.push_back(10);
268  myBook1D(ibooker, "genMuon_size", sizeBins, "container size" );
269  myBook1D(ibooker, "globMuon_size", sizeBins, "container size" );
270  for(size_t i=0; i<filterNamesLevels.size(); i++){
271  myBook1D(ibooker, TString::Format("filt%dMuon_size",int(i+1)), sizeBins, "container size", filterNamesLevels[i].first);
272  }
273  myBook1D(ibooker, "pathMuon_size", sizeBins, "container size", triggerPathName );
274 }
275 
277  if(filterNamesLevels.size()==0){
278  return;
279  }
280 //access the containers and create LeafCandidate copies
281  vector<LeafCandidate> genMuons;
283  iEvent.getByToken(genParticlesTag, genParticles);
284  if(genParticles.isValid()){
285  for(GenParticleCollection::const_iterator p=genParticles->begin(); p!= genParticles->end(); ++p){
286  if( p->status() == 1 && std::abs(p->pdgId())==13 &&
287  ( find( motherIDs.begin(), motherIDs.end(), -1 )!=motherIDs.end() || find( motherIDs.begin(), motherIDs.end(), getMotherId(&(*p)) )!=motherIDs.end() ) ){
288  genMuons.push_back( *p );
289  }
290  }
291  }else{
292  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Could not access GenParticleCollection"<<endl;
293  }
294  sort(genMuons.begin(), genMuons.end(), GreaterByPt<LeafCandidate>());
295  ME["genMuon_size"]->Fill(genMuons.size());
296  LogDebug("HLTriggerOfflineHeavyFlavor")<<"GenParticleCollection from "<<genParticlesTag<<" has size: "<<genMuons.size()<<endl;
297 
298  vector<LeafCandidate> globMuons;
299  vector<LeafCandidate> globMuons_position;
300  Handle<MuonCollection> recoMuonsHandle;
301  iEvent.getByToken(recoMuonsTag, recoMuonsHandle);
302  if(recoMuonsHandle.isValid()){
303  for(MuonCollection::const_iterator p=recoMuonsHandle->begin(); p!= recoMuonsHandle->end(); ++p){
304  if(p->isGlobalMuon()){
305  globMuons.push_back(*p);
306  globMuons_position.push_back( LeafCandidate( p->charge(), math::XYZTLorentzVector(p->outerTrack()->innerPosition().x(), p->outerTrack()->innerPosition().y(), p->outerTrack()->innerPosition().z(), 0.) ) );
307  }
308  }
309  }else{
310  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Could not access reco Muons"<<endl;
311  }
312  ME["globMuon_size"]->Fill(globMuons.size());
313  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Global Muons from "<<recoMuonsTag<<" has size: "<<globMuons.size()<<endl;
314 
315 // access RAW trigger event
316  vector<vector<LeafCandidate> > muonsAtFilter;
317  vector<vector<LeafCandidate> > muonPositionsAtFilter;
318  for(size_t i=0; i<filterNamesLevels.size(); i++){
319  muonsAtFilter.push_back(vector<LeafCandidate>());
320  muonPositionsAtFilter.push_back(vector<LeafCandidate>());
321  }
322  Handle<TriggerEventWithRefs> rawTriggerEvent;
323  iEvent.getByToken( triggerSummaryRAWTag, rawTriggerEvent );
324  if( rawTriggerEvent.isValid() ){
325  for(size_t i=0; i<filterNamesLevels.size(); i++){
326  size_t index = rawTriggerEvent->filterIndex(InputTag( filterNamesLevels[i].first, "", triggerProcessName ));
327  if ( index < rawTriggerEvent->size() ){
328  if( filterNamesLevels[i].second==1 ){
329  vector<L1MuonParticleRef> l1Cands;
330  rawTriggerEvent->getObjects( index, TriggerL1Mu, l1Cands );
331  for(size_t j=0; j<l1Cands.size(); j++){
332  muonsAtFilter[i].push_back(*l1Cands[j]);
333  }
334  }else{
335  vector<RecoChargedCandidateRef> hltCands;
336  rawTriggerEvent->getObjects( index, TriggerMuon, hltCands );
337  for(size_t j=0; j<hltCands.size(); j++){
338  muonsAtFilter[i].push_back(*hltCands[j]);
339  if( filterNamesLevels[i].second==2 ){
340  muonPositionsAtFilter[i].push_back( LeafCandidate( hltCands[j]->charge(), math::XYZTLorentzVector(hltCands[j]->track()->innerPosition().x(), hltCands[j]->track()->innerPosition().y(), hltCands[j]->track()->innerPosition().z(), 0.) ) );
341  }
342  }
343  }
344  }
345  ME[TString::Format("filt%dMuon_size",int(i+1))]->Fill(muonsAtFilter[i].size());
346  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Filter \""<<filterNamesLevels[i].first<<"\" has "<<muonsAtFilter[i].size()<<" muons"<<endl;
347  }
348  }else{
349  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Could not access RAWTriggerEvent"<<endl;
350  }
351 
352 // access AOD trigger event
353  vector<LeafCandidate> pathMuons;
354  Handle<TriggerEvent> aodTriggerEvent;
355  iEvent.getByToken(triggerSummaryAODTag,aodTriggerEvent);
356  if(aodTriggerEvent.isValid()){
357  TriggerObjectCollection allObjects = aodTriggerEvent->getObjects();
358  for(int i=0; i<aodTriggerEvent->sizeFilters(); i++){
359  if(aodTriggerEvent->filterTag(i)==InputTag((filterNamesLevels.end()-1)->first,"",triggerProcessName)){
360  Keys keys = aodTriggerEvent->filterKeys(i);
361  for(size_t j=0; j<keys.size(); j++){
362  pathMuons.push_back( LeafCandidate( allObjects[keys[j]].id()>0 ? 1 : -1, math::PtEtaPhiMLorentzVector( allObjects[keys[j]].pt(), allObjects[keys[j]].eta(), allObjects[keys[j]].phi(), muonMass ) ) );
363  }
364  }
365  }
366  ME["pathMuon_size"]->Fill(pathMuons.size());
367  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Path \""<<triggerPathName<<"\" has "<<pathMuons.size()<<" muons at last filter \""<<(filterNamesLevels.end()-1)->first<<"\""<<endl;
368  }else{
369  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Could not access AODTriggerEvent"<<endl;
370  }
371 
372 // access Trigger Results
373  bool triggerFired = false;
375  iEvent.getByToken(triggerResultsTag,triggerResults);
376  if(triggerResults.isValid()){
377  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Successfully initialized "<<triggerResultsTag<<endl;
378  const edm::TriggerNames & triggerNames = iEvent.triggerNames(*triggerResults);
379  bool hlt_exists = false;
380  for ( unsigned int i=0; i!=triggerNames.size(); i++) {
381  TString hlt_name = triggerNames.triggerName(i);
382  if (hlt_name.Contains(triggerPathName)) {
383  triggerFired = triggerResults->accept( i );
384  hlt_exists = true;
385  break;
386  }
387  }
388  if (!hlt_exists) {
389  LogDebug("HLTriggerOfflineHeavyFlavor")<<triggerResultsTag<<" has no trigger: "<<triggerPathName<<endl;
390  }
391  }else{
392  LogDebug("HLTriggerOfflineHeavyFlavor")<<"Could not initialize "<<triggerResultsTag<<endl;
393  }
394 
395 //create matching maps
396  vector<int> glob_gen(genMuons.size(),-1);
397  match( ME["globGen_deltaEtaDeltaPhi"], genMuons, globMuons, genGlobDeltaRMatchingCut, glob_gen );
398  vector<vector<int> > filt_glob;
399  for(size_t i=0; i<filterNamesLevels.size(); i++){
400  filt_glob.push_back( vector<int>(globMuons.size(),-1) );
401  if( filterNamesLevels[i].second == 1 ){
402  match( ME[TString::Format("filt%dGlob_deltaEtaDeltaPhi",int(i+1))], globMuons_position, muonsAtFilter[i] ,globL1DeltaRMatchingCut, filt_glob[i] );
403  }else if( filterNamesLevels[i].second == 2 ){
404  match( ME[TString::Format("filt%dGlob_deltaEtaDeltaPhi",int(i+1))], globMuons_position, muonPositionsAtFilter[i] ,globL2DeltaRMatchingCut, filt_glob[i] );
405  }else if( filterNamesLevels[i].second == 3 || filterNamesLevels[i].second == 4){
406  match( ME[TString::Format("filt%dGlob_deltaEtaDeltaPhi",int(i+1))], globMuons, muonsAtFilter[i] ,globL3DeltaRMatchingCut, filt_glob[i] );
407  }
408  }
409  vector<int> path_glob(globMuons.size(),-1);
410  if( (filterNamesLevels.end()-1)->second == 1 ){
411  match( ME["pathGlob_deltaEtaDeltaPhi"], globMuons_position, pathMuons ,globL1DeltaRMatchingCut, path_glob );
412  }else if( (filterNamesLevels.end()-1)->second == 2 ){
413  match( ME["pathGlob_deltaEtaDeltaPhi"], globMuons, pathMuons ,globL2DeltaRMatchingCut, path_glob );
414  }else if( (filterNamesLevels.end()-1)->second == 3 || (filterNamesLevels.end()-1)->second == 4){
415  match( ME["pathGlob_deltaEtaDeltaPhi"], globMuons, pathMuons ,globL3DeltaRMatchingCut, path_glob );
416  }
417 
418 //fill histos
419  bool first = true;
420  for(size_t i=0; i<genMuons.size(); i++){
421  ME["genMuon_genEtaPt"]->Fill(genMuons[i].eta(), genMuons[i].pt());
422  ME["genMuon_genEtaPhi"]->Fill(genMuons[i].eta(), genMuons[i].phi());
423  if(glob_gen[i] != -1) {
424  ME["resGlobGen_genEtaPt"]->Fill(genMuons[i].eta(), genMuons[i].pt(), (globMuons[glob_gen[i]].pt()-genMuons[i].pt())/genMuons[i].pt() );
425  ME["globMuon_genEtaPt"]->Fill(genMuons[i].eta(), genMuons[i].pt());
426  ME["globMuon_genEtaPhi"]->Fill(genMuons[i].eta(), genMuons[i].phi());
427  ME["globMuon_recoEtaPt"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt());
428  ME["globMuon_recoEtaPhi"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].phi());
429  for(size_t f=0; f<filterNamesLevels.size(); f++) {
430  if(filt_glob[f][glob_gen[i]] != -1) {
431  ME[TString::Format("resFilt%dGlob_recoEtaPt",int(f+1))]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt(), (muonsAtFilter[f][filt_glob[f][glob_gen[i]]].pt()-globMuons[glob_gen[i]].pt())/globMuons[glob_gen[i]].pt() );
432  ME[TString::Format("filt%dMuon_recoEtaPt",int(f+1))]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt());
433  ME[TString::Format("filt%dMuon_recoEtaPhi",int(f+1))]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].phi());
434  }else{
435  break;
436  }
437  }
438  if(path_glob[glob_gen[i]] != -1){
439  ME["resPathGlob_recoEtaPt"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt(), (pathMuons[path_glob[glob_gen[i]]].pt()-globMuons[glob_gen[i]].pt())/globMuons[glob_gen[i]].pt() );
440  ME["pathMuon_recoEtaPt"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt());
441  ME["pathMuon_recoEtaPhi"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].phi());
442  }
443 //highest pt muon
444  if( first ){
445  first = false;
446  if( triggerFired ){
447  ME["resultMuon_recoEtaPt"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].pt());
448  ME["resultMuon_recoEtaPhi"]->Fill(globMuons[glob_gen[i]].eta(), globMuons[glob_gen[i]].phi());
449  }
450  }
451  }
452  }
453 
454 //fill dimuon histograms (highest pT, opposite charge)
455  int secondMuon = 0;
456  for(size_t j=1; j<genMuons.size(); j++){
457  if(genMuons[0].charge()*genMuons[j].charge()==-1){
458  secondMuon = j;
459  break;
460  }
461  }
462  if(secondMuon > 0){
463 //two generated
464  double genDimuonPt = (genMuons[0].p4()+genMuons[secondMuon].p4()).pt();
465  double genDimuonEta = (genMuons[0].p4()+genMuons[secondMuon].p4()).eta();
466  double genDimuonRap = (genMuons[0].p4()+genMuons[secondMuon].p4()).Rapidity();
467  double genDimuonDR = deltaR<LeafCandidate,LeafCandidate>( genMuons[0], genMuons[secondMuon] );
468  bool highPt = genMuons[0].pt()>7. && genMuons[secondMuon].pt()>7;
469  ME["genDimuon_genEtaPt"]->Fill( genDimuonEta, genDimuonPt );
470  ME["genDimuon_genRapPt"]->Fill( genDimuonRap, genDimuonPt );
471  if(highPt) ME["genDimuon_genPtDR"]->Fill( genDimuonPt, genDimuonDR );
472 //two global
473  if(glob_gen[0]!=-1 && glob_gen[secondMuon]!=-1){
474  ME["globDimuon_genEtaPt"]->Fill( genDimuonEta, genDimuonPt );
475  ME["globDimuon_genRapPt"]->Fill( genDimuonRap, genDimuonPt );
476  if(highPt) ME["globDimuon_genPtDR"]->Fill( genDimuonPt, genDimuonDR );
477  double globDimuonPt = (globMuons[glob_gen[0]].p4()+globMuons[glob_gen[secondMuon]].p4()).pt();
478  double globDimuonEta = (globMuons[glob_gen[0]].p4()+globMuons[glob_gen[secondMuon]].p4()).eta();
479  double globDimuonRap = (globMuons[glob_gen[0]].p4()+globMuons[glob_gen[secondMuon]].p4()).Rapidity();
480  double globDimuonDR = deltaR<LeafCandidate,LeafCandidate>( globMuons[glob_gen[0]], globMuons[glob_gen[secondMuon]] );
481  double globDimuonDRpos = deltaR<LeafCandidate,LeafCandidate>( globMuons_position[glob_gen[0]], globMuons_position[glob_gen[secondMuon]] );
482  ME["globDimuon_recoEtaPt"]->Fill( globDimuonEta, globDimuonPt );
483  ME["globDimuon_recoRapPt"]->Fill( globDimuonRap, globDimuonPt );
484  if(highPt) ME["globDimuon_recoPtDR"]->Fill( globDimuonPt, globDimuonDR );
485  if(highPt) ME["globDimuon_recoPtDRpos"]->Fill( globDimuonPt, globDimuonDRpos );
486 //two filter objects
487  for(size_t f=0; f<filterNamesLevels.size(); f++){
488  if(filt_glob[f][glob_gen[0]] != -1 && filt_glob[f][glob_gen[secondMuon]] != -1){
489  ME[TString::Format("diFilt%dDimuon_recoEtaPt",int(f+1))]->Fill( globDimuonEta, globDimuonPt );
490  ME[TString::Format("diFilt%dDimuon_recoRapPt",int(f+1))]->Fill( globDimuonRap, globDimuonPt );
491  if(highPt) ME[TString::Format("diFilt%dDimuon_recoPtDR",int(f+1))]->Fill( globDimuonPt, globDimuonDR );
492  if(highPt) ME[TString::Format("diFilt%dDimuon_recoPtDRpos",int(f+1))]->Fill( globDimuonPt, globDimuonDRpos );
493  }else{
494  break;
495  }
496  }
497 //one filter object
498  for(size_t f=0; f<filterNamesLevels.size(); f++){
499  if(filt_glob[f][glob_gen[0]] != -1 || filt_glob[f][glob_gen[secondMuon]] != -1){
500  ME[TString::Format("filt%dDimuon_recoEtaPt",int(f+1))]->Fill( globDimuonEta, globDimuonPt );
501  ME[TString::Format("filt%dDimuon_recoRapPt",int(f+1))]->Fill( globDimuonRap, globDimuonPt );
502  if(highPt) ME[TString::Format("filt%dDimuon_recoPtDR",int(f+1))]->Fill( globDimuonPt, globDimuonDR );
503  if(highPt) ME[TString::Format("filt%dDimuon_recoPtDRpos",int(f+1))]->Fill( globDimuonPt, globDimuonDRpos );
504  }else{
505  break;
506  }
507  }
508 //two path objects
509  if(path_glob[glob_gen[0]] != -1 && path_glob[glob_gen[secondMuon]] != -1){
510  ME["diPathDimuon_recoEtaPt"]->Fill( globDimuonEta, globDimuonPt );
511  ME["diPathDimuon_recoRapPt"]->Fill( globDimuonRap, globDimuonPt );
512  if(highPt) ME["diPathDimuon_recoPtDR"]->Fill( globDimuonPt, globDimuonDR );
513  if(highPt) ME["diPathDimuon_recoPtDRpos"]->Fill( globDimuonPt, globDimuonDRpos );
514  }
515 //one path object
516  if(path_glob[glob_gen[0]] != -1 || path_glob[glob_gen[secondMuon]] != -1){
517  ME["pathDimuon_recoEtaPt"]->Fill( globDimuonEta, globDimuonPt );
518  ME["pathDimuon_recoRapPt"]->Fill( globDimuonRap, globDimuonPt );
519  if(highPt) ME["pathDimuon_recoPtDR"]->Fill( globDimuonPt, globDimuonDR );
520  if(highPt) ME["pathDimuon_recoPtDRpos"]->Fill( globDimuonPt, globDimuonDRpos );
521  }
522 //trigger result
523  if( triggerFired ){
524  ME["resultDimuon_recoEtaPt"]->Fill( globDimuonEta, globDimuonPt );
525  ME["resultDimuon_recoRapPt"]->Fill( globDimuonRap, globDimuonPt );
526  if(highPt) ME["resultDimuon_recoPtDR"]->Fill( globDimuonPt, globDimuonDR );
527  if(highPt) ME["resultDimuon_recoPtDRpos"]->Fill( globDimuonPt, globDimuonDRpos );
528  }
529  }
530  }
531 }
532 
534  const Candidate* mother = p->mother();
535  if( mother ){
536  if( mother->pdgId() == p->pdgId() ){
537  return getMotherId(mother);
538  }else{
539  return mother->pdgId();
540  }
541  }else{
542  return 0;
543  }
544 }
545 
546 void HeavyFlavorValidation::match( MonitorElement * me, vector<LeafCandidate> & from, vector<LeafCandidate> & to, double dRMatchingCut, vector<int> & map ){
547  vector<double> dR(from.size());
548  for(size_t i=0; i<from.size(); i++){
549  map[i] = -1;
550  dR[i] = 10.;
551  //find closest
552  for(size_t j=0; j<to.size(); j++){
553  double dRtmp = deltaR<double>(from[i].eta(), from[i].phi(), to[j].eta(), to[j].phi());
554  if( dRtmp < dR[i] ){
555  dR[i] = dRtmp;
556  map[i] = j;
557  }
558  }
559  //fill matching histo
560  if( map[i] != -1 ){
561  me->Fill( to[map[i]].eta()-from[i].eta(), deltaPhi<double>(to[map[i]].phi(), from[i].phi()) );
562  }
563  //apply matching cut
564  if( dR[i] > dRMatchingCut ){
565  map[i] = -1;
566  }
567  //remove duplication
568  if( map[i] != -1 ){
569  for(size_t k=0; k<i; k++){
570  if( map[k] != -1 && map[i] == map[k] ){
571  if( dR[i] < dR[k] ){
572  map[k] = -1;
573  }else{
574  map[i] = -1;
575  }
576  break;
577  }
578  }
579  }
580  }
581 }
582 
583 void HeavyFlavorValidation::myBook2D(DQMStore::IBooker & ibooker, TString name, vector<double> &ptBins, TString ptLabel, vector<double> &etaBins, TString etaLabel, TString title )
584 {
585 // dqmStore->setCurrentFolder(dqmFolder+"/"+folder);
586  int ptN = ptBins.size()==3 ? (int)ptBins[0]+1 : ptBins.size();
587  Double_t *pt = new Double_t[ ptN ];
588  for(int i=0; i<ptN; i++){
589  pt[i] = ptBins.size()==3 ? ptBins[1] + i*(ptBins[2]-ptBins[1])/ptBins[0] : ptBins[i] ;
590  }
591  int etaN = etaBins.size()==3 ? (int)etaBins[0]+1 : etaBins.size();
592  Double_t *eta = new Double_t[ etaN ];
593  for(int i=0; i<etaN; i++){
594  eta[i] = etaBins.size()==3 ? etaBins[1] + i*(etaBins[2]-etaBins[1])/etaBins[0] : etaBins[i] ;
595  }
596  TH2F *h = new TH2F( name, name, ptN-1, pt, etaN-1, eta );
597  h->SetXTitle(ptLabel);
598  h->SetYTitle(etaLabel);
599  h->SetTitle(title);
600  ME[name] = ibooker.book2D( name.Data(), h );
601  delete h;
602 }
603 
604 void HeavyFlavorValidation::myBookProfile2D(DQMStore::IBooker & ibooker, TString name, vector<double> &ptBins, TString ptLabel, vector<double> &etaBins, TString etaLabel, TString title )
605 {
606 // dqmStore->setCurrentFolder(dqmFolder+"/"+folder);
607  int ptN = ptBins.size()==3 ? (int)ptBins[0]+1 : ptBins.size();
608  Double_t *pt = new Double_t[ ptN ];
609  for(int i=0; i<ptN; i++){
610  pt[i] = ptBins.size()==3 ? ptBins[1] + i*(ptBins[2]-ptBins[1])/ptBins[0] : ptBins[i] ;
611  }
612  int etaN = etaBins.size()==3 ? (int)etaBins[0]+1 : etaBins.size();
613  Double_t *eta = new Double_t[ etaN ];
614  for(int i=0; i<etaN; i++){
615  eta[i] = etaBins.size()==3 ? etaBins[1] + i*(etaBins[2]-etaBins[1])/etaBins[0] : etaBins[i] ;
616  }
617  TProfile2D *h = new TProfile2D( name, name, ptN-1, pt, etaN-1, eta );
618  h->SetXTitle(ptLabel);
619  h->SetYTitle(etaLabel);
620  h->SetTitle(title);
621  ME[name] = ibooker.bookProfile2D( name.Data(), h );
622  delete h;
623 }
624 
625 void HeavyFlavorValidation::myBook1D(DQMStore::IBooker & ibooker, TString name, vector<double> &bins, TString label, TString title )
626 {
627 // dqmStore->setCurrentFolder(dqmFolder+"/"+folder);
628  int binsN = bins.size()==3 ? (int)bins[0]+1 : bins.size();
629  Double_t *myBins = new Double_t[ binsN ];
630  for(int i=0; i<binsN; i++){
631  myBins[i] = bins.size()==3 ? bins[1] + i*(bins[2]-bins[1])/bins[0] : bins[i] ;
632  }
633  TH1F *h = new TH1F( name, name, binsN-1, myBins );
634  h->SetXTitle(label);
635  h->SetTitle(title);
636  ME[name] = ibooker.book1D( name.Data(), h );
637  delete h;
638 }
639 
641 }
642 
643 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const
Definition: Event.cc:204
void myBook2D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString xLabel, vector< double > &yBins, TString yLabel, TString title)
virtual const Candidate * mother(size_type i=0) const =0
return pointer to mother
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
enum start value shifted to 81 so as to avoid clashes with PDG codes
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void cd(void)
Definition: DQMStore.cc:266
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::vector< std::string > & triggerNames() const
names of trigger paths
vector< pair< string, int > > filterNamesLevels
const double muonMass
Strings::size_type size() const
Definition: TriggerNames.cc:39
T eta() const
vector< double > dimuonEtaBins
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
double charge(const std::vector< uint8_t > &Ampls)
float float float z
void bookHistograms(fwlite::EventContainer &eventCont)
EDGetTokenT< TriggerEvent > triggerSummaryAODTag
EDGetTokenT< GenParticleCollection > genParticlesTag
void Fill(long long x)
U second(std::pair< T, U > const &p)
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
Definition: ME.h:11
void myBookProfile2D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString xLabel, vector< double > &yBins, TString yLabel, TString title)
int getMotherId(const Candidate *p)
int iEvent
Definition: GenABIO.cc:230
void match(MonitorElement *me, vector< LeafCandidate > &from, vector< LeafCandidate > &to, double deltaRMatchingCut, vector< int > &map)
MonitorElement * bookProfile2D(Args &&...args)
Definition: DQMStore.h:161
EDGetTokenT< TriggerEventWithRefs > triggerSummaryRAWTag
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:113
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
void dqmBeginRun(const edm::Run &, const edm::EventSetup &)
double f[11][100]
void myBook1D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString label, TString title)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static std::string const triggerResults
Definition: EdmProvDump.cc:41
bool first
Definition: L1TdeRCT.cc:75
bool isValid() const
Definition: HandleBase.h:76
HeavyFlavorValidation(const edm::ParameterSet &)
int k[5][pyjets_maxn]
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
virtual int pdgId() const =0
PDG identifier.
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
EDGetTokenT< TriggerResults > triggerResultsTag
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:131
void myBook2D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString xLabel, vector< double > &yBins, TString yLabel)
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
std::vector< size_type > Keys
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
void myBookProfile2D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString xLabel, vector< double > &yBins, TString yLabel)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
tuple level
Definition: testEve_cfg.py:34
void myBook1D(DQMStore::IBooker &ibooker, TString name, vector< double > &xBins, TString label)
Definition: DDAxes.h:10
map< TString, MonitorElement * > ME
tuple size
Write out results.
EDGetTokenT< MuonCollection > recoMuonsTag
Definition: Run.h:41
Definition: DDAxes.h:10