CMS 3D CMS Logo

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