1+ /*
2+ Scouting Muon DQM for L1 seeds. This code does the following:
3+ 1) Reads pat muon and scouting muon collections, and writes an array of scouting muon
4+ triggers (selected in python/ScoutingMuonTriggerAnalyzer_cfi.py)
5+ 2) For each event, if the event passes a logical OR of HLTriggers it is added to
6+ the denominator, and if it passes any of the scouting muon triggers it is
7+ added to the numerator of that specific trigger.
8+ 3) Fills histograms for both leading and subleading muon in the event.
9+ Author: Javier Garcia de Castro, email:[email protected] 10+ */
11+
12+ // Files to include
13+ #include " ScoutingMuonTriggerAnalyzer.h"
14+ #include " FWCore/MessageLogger/interface/MessageLogger.h"
15+ #include < iostream>
16+ #include < cmath>
17+
18+ // Read the collections and triggers
19+ ScoutingMuonTriggerAnalyzer::ScoutingMuonTriggerAnalyzer (const edm::ParameterSet& iConfig) :
20+ outputInternalPath_(iConfig.getParameter<std::string>(" OutputInternalPath" )),
21+ triggerCache_(triggerExpression::Data(iConfig.getParameterSet(" triggerConfiguration" ), consumesCollector())),
22+ vtriggerSelection_(iConfig.getParameter<vector<string>>(" triggerSelection" ))
23+ {
24+ scoutingMuonCollection_ = consumes<std::vector<Run3ScoutingMuon>>(iConfig.getParameter <edm::InputTag>(" ScoutingMuonCollection" ));
25+ vtriggerSelector_.reserve (vtriggerSelection_.size ());
26+ for (auto const & vt:vtriggerSelection_) vtriggerSelector_.push_back (triggerExpression::parse (vt));
27+ algToken_ = consumes<BXVector<GlobalAlgBlk>>(iConfig.getParameter <edm::InputTag>(" AlgInputTag" ));
28+ l1GtUtils_ = std::make_shared<l1t::L1TGlobalUtil>(iConfig, consumesCollector (), l1t::UseEventSetupIn::RunAndEvent);
29+ l1Seeds_ = iConfig.getParameter <std::vector<std::string> >(" l1Seeds" );
30+ for (unsigned int i = 0 ; i < l1Seeds_.size (); i++){
31+ const auto & l1seed (l1Seeds_.at (i));
32+ l1Names[i] = TString (l1seed);
33+ }
34+ }
35+
36+ ScoutingMuonTriggerAnalyzer::~ScoutingMuonTriggerAnalyzer (){
37+ }
38+
39+ // Core of the implementation
40+ void ScoutingMuonTriggerAnalyzer::analyze (edm::Event const & iEvent, edm::EventSetup const & iSetup) {
41+ edm::Handle<std::vector<Run3ScoutingMuon> > sctMuons;
42+ iEvent.getByToken (scoutingMuonCollection_, sctMuons);
43+ if (sctMuons.failedToGet ()) {
44+ edm::LogWarning (" ScoutingMonitoring" )
45+ << " Run3ScoutingMuon collection not found." ;
46+ return ;
47+ }
48+
49+ // Check whether events pass any of the HLTriggers to add to the denominator
50+ bool passHLTDenominator = false ;
51+ if (triggerCache_.setEvent (iEvent, iSetup)){
52+ for (unsigned int i = 0 ; i < vtriggerSelector_.size (); i++){
53+ auto & vts (vtriggerSelector_.at (i));
54+ bool result = false ;
55+ if (vts){
56+ if (triggerCache_.configurationUpdated ()) vts->init (triggerCache_);
57+ result = (*vts)(triggerCache_);
58+ }
59+ if (result)
60+ passHLTDenominator = true ;
61+ }
62+ }
63+
64+ // Find leading and subleading muon from the event
65+ if (sctMuons->size () > 0 ) {
66+ Run3ScoutingMuon leading_mu;
67+ Run3ScoutingMuon subleading_mu;
68+
69+ std::vector<Run3ScoutingMuon> sorted_mu;
70+ for (const auto & muon : *sctMuons) {
71+ sorted_mu.push_back (muon);
72+ }
73+ std::sort (std::begin (sorted_mu),std::end (sorted_mu), [&](Run3ScoutingMuon mu1, Run3ScoutingMuon mu2){return mu1.pt () > mu2.pt ();});
74+ leading_mu = sorted_mu.at (0 );
75+ if (sorted_mu.size () > 1 )
76+ subleading_mu = sorted_mu.at (1 );
77+
78+ l1GtUtils_->retrieveL1 (iEvent, iSetup, algToken_);
79+
80+ math::PtEtaPhiMLorentzVector mu1 (leading_mu.pt (), leading_mu.eta (), leading_mu.phi (), leading_mu.m ());
81+ math::PtEtaPhiMLorentzVector mu2 (subleading_mu.pt (), subleading_mu.eta (), subleading_mu.phi (), subleading_mu.m ());
82+ float invMass = (mu1 + mu2).mass ();
83+ // If event passed and of the HLTs, add to denominator
84+ if (passHLTDenominator){
85+ h_invMass_denominator->Fill (invMass);
86+ h_pt1_l1_denominator->Fill (leading_mu.pt ());
87+ h_eta1_l1_denominator->Fill (leading_mu.eta ());
88+ h_phi1_l1_denominator->Fill (leading_mu.phi ());
89+ h_dxy1_l1_denominator->Fill (leading_mu.trk_dxy ());
90+ if (sorted_mu.size () > 1 ){
91+ h_pt2_l1_denominator->Fill (subleading_mu.pt ());
92+ h_eta2_l1_denominator->Fill (subleading_mu.eta ());
93+ h_phi2_l1_denominator->Fill (subleading_mu.phi ());
94+ h_dxy2_l1_denominator->Fill (subleading_mu.trk_dxy ());
95+ }
96+ // For each L1 seed, if the event passes the trigger plot distributions in the numerator
97+ for (unsigned int i = 0 ; i < l1Seeds_.size (); i++){
98+ const auto & l1seed (l1Seeds_.at (i));
99+ bool l1htbit = 0 ;
100+ double prescale = -1 ;
101+ l1GtUtils_->getFinalDecisionByName (l1seed, l1htbit);
102+ l1GtUtils_->getPrescaleByName (l1seed, prescale);
103+ l1Result[i] = l1htbit;
104+ if (l1Result[i] == 1 ) {
105+ h_invMass_numerators[i]->Fill (invMass);
106+ h_pt1_l1_numerators[i]->Fill (leading_mu.pt ());
107+ h_eta1_l1_numerators[i]->Fill (leading_mu.eta ());
108+ h_phi1_l1_numerators[i]->Fill (leading_mu.phi ());
109+ h_dxy1_l1_numerators[i]->Fill (leading_mu.trk_dxy ());
110+ if (sorted_mu.size () > 1 ){
111+ h_pt2_l1_numerators[i]->Fill (subleading_mu.pt ());
112+ h_eta2_l1_numerators[i]->Fill (subleading_mu.eta ());
113+ h_phi2_l1_numerators[i]->Fill (subleading_mu.phi ());
114+ h_dxy2_l1_numerators[i]->Fill (subleading_mu.trk_dxy ());
115+ }
116+ }
117+ }
118+ }
119+ }
120+ }
121+
122+ // Histogram axes labels, bin number and range
123+ void ScoutingMuonTriggerAnalyzer::bookHistograms (DQMStore::IBooker& ibook, edm::Run const & run, edm::EventSetup const & iSetup) {
124+ ibook.setCurrentFolder (outputInternalPath_);
125+ h_invMass_denominator = ibook.book1D (" h_invMass_denominator" , " ;Invariant Mass (GeV); Muons" , 100 , 0.0 , 20.0 );
126+ h_pt1_l1_denominator = ibook.book1D (" h_pt1_denominator" , " ;Leading muon pt (GeV); Muons" , 100 , 0 , 50.0 );
127+ h_eta1_l1_denominator = ibook.book1D (" h_eta1_denominator" , " ;Leading muon eta; Muons" , 100 , -5.0 , 5.0 );
128+ h_phi1_l1_denominator = ibook.book1D (" h_phi1_denominator" , " ;Leading muon phi; Muons" , 100 , -3.3 , 3.3 );
129+ h_dxy1_l1_denominator = ibook.book1D (" h_dxy1_denominator" , " ;Leading muon dxy; Muons" , 100 , 0 , 5.0 );
130+ h_pt2_l1_denominator = ibook.book1D (" h_pt2_denominator" , " ;Subleading muon pt (GeV); Muons" , 100 , 0 , 50.0 );
131+ h_eta2_l1_denominator = ibook.book1D (" h_eta2_denominator" , " ;Subleading muon eta; Muons" , 100 , -5.0 , 5.0 );
132+ h_phi2_l1_denominator = ibook.book1D (" h_phi2_denominator" , " ;Subleading muon phi; Muons" , 100 , -3.3 , 3.3 );
133+ h_dxy2_l1_denominator = ibook.book1D (" h_dxy2_denominator" , " ;Subleaing muon dxy; Muons" , 100 , 0 , 5.0 );
134+
135+ for (unsigned int i = 0 ; i < l1Seeds_.size (); i++) {
136+ const auto & l1seed = l1Seeds_.at (i);
137+ h_invMass_numerators.push_back (ibook.book1D (Form (" h_invMass_numerator_%s" , l1seed.c_str ()), " ;Invariant mass (GeV); Muons" , 100 , 0.0 , 20.0 ));
138+ h_pt1_l1_numerators.push_back (ibook.book1D (Form (" h_pt1_numerator_%s" , l1seed.c_str ()), " ;Leading muon pt (GeV); Muons" , 100 , 0 , 50.0 ));
139+ h_eta1_l1_numerators.push_back (ibook.book1D (Form (" h_eta1_numerator_%s" , l1seed.c_str ())," ;Leading muon eta; Muons" , 100 , -5.0 , 5.0 ));
140+ h_phi1_l1_numerators.push_back (ibook.book1D (Form (" h_phi1_numerator_%s" , l1seed.c_str ()), " ;Leading muon phi; Muons" , 100 , 3.3 , -3.3 ));
141+ h_dxy1_l1_numerators.push_back (ibook.book1D (Form (" h_dxy1_numerator_%s" , l1seed.c_str ()), " ;Leading muon dxy; Muons" , 100 , 0 , 5.0 ));
142+ h_pt2_l1_numerators.push_back (ibook.book1D (Form (" h_pt2_numerator_%s" , l1seed.c_str ()), " ;Subleading muon pt (GeV); Muons" , 100 , 0 , 50.0 ));
143+ h_eta2_l1_numerators.push_back (ibook.book1D (Form (" h_eta2_numerator_%s" , l1seed.c_str ())," ;Subleading muon eta; Muons" , 100 , -5.0 , 5.0 ));
144+ h_phi2_l1_numerators.push_back (ibook.book1D (Form (" h_phi2_numerator_%s" , l1seed.c_str ()), " ;Subleading muon phi; Muons" , 100 , 3.3 , -3.3 ));
145+ h_dxy2_l1_numerators.push_back (ibook.book1D (Form (" h_dxy2_numerator_%s" , l1seed.c_str ()), " ;Subleading muon dxy; Muons" , 100 , 0 , 5.0 ));
146+ }
147+ }
148+
149+ // Input tags to read collections and L1 seeds
150+ void ScoutingMuonTriggerAnalyzer::fillDescriptions (
151+ edm::ConfigurationDescriptions& descriptions) {
152+ edm::ParameterSetDescription desc;
153+ desc.add <std::string>(" OutputInternalPath" , " MY_FOLDER" );
154+ desc.add <edm::InputTag>(" AlgInputTag" , edm::InputTag (" gtStage2Digis" ));
155+ desc.add <edm::InputTag>(" l1tAlgBlkInputTag" , edm::InputTag (" gtStage2Digis" ));
156+ desc.add <edm::InputTag>(" l1tExtBlkInputTag" , edm::InputTag (" gtStage2Digis" ));
157+ desc.setUnknown ();
158+ descriptions.addDefault (desc);
159+ descriptions.add (" ScoutingMuonTriggerAnalyzer" , desc);
160+ }
161+
162+ DEFINE_FWK_MODULE (ScoutingMuonTriggerAnalyzer);
0 commit comments