test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
L1Muon2RecoTreeProducer Class Reference
Inheritance diagram for L1Muon2RecoTreeProducer:
edm::EDAnalyzer edm::EDConsumerBase

Public Member Functions

void empty_hlt ()
 
 L1Muon2RecoTreeProducer (const edm::ParameterSet &)
 
double match_trigger (std::vector< int > &trigIndices, const trigger::TriggerObjectCollection &trigObjs, edm::Handle< trigger::TriggerEvent > &triggerEvent, const reco::Muon &mu)
 
 ~L1Muon2RecoTreeProducer ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Public Attributes

L1Analysis::L1AnalysisRecoMuon2muon
 
L1Analysis::L1AnalysisRecoMuon2DataFormatmuon_data
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob (void)
 
virtual void beginRun (const edm::Run &, const edm::EventSetup &)
 
virtual void endJob ()
 

Private Attributes

edm::Service< TFileServicefs_
 
HLTConfigProvider hltConfig_
 
std::vector< int > isoTriggerIndices_
 
std::vector< std::string > isoTriggerNames_
 
unsigned int maxMuon_
 
edm::EDGetTokenT
< reco::MuonCollection
MuonToken_
 
TTree * tree_
 
std::vector< int > triggerIndices_
 
bool triggerMatching_
 
double triggerMaxDeltaR_
 
std::vector< std::string > triggerNames_
 
std::string triggerProcessLabel_
 
edm::EDGetTokenT
< edm::TriggerResults
TriggerResultsToken_
 
edm::EDGetTokenT
< trigger::TriggerEvent
triggerSummaryLabelToken_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 78 of file L1Muon2RecoTreeProducer.cc.

Constructor & Destructor Documentation

L1Muon2RecoTreeProducer::L1Muon2RecoTreeProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 137 of file L1Muon2RecoTreeProducer.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), metsig::muon, and AlCaHLTBitMon_QueryRunRegistry::string.

138 {
139 
140  maxMuon_ = iConfig.getParameter<unsigned int>("maxMuon");
141  // isoTriggerToken_ = iConfig.getParameter<std::vector<std::string>>("isoTriggerNames");
142  // TriggerToken_ = iConfig.getParameter<std::vector<std::string>>("triggerNames");
143  MuonToken_ = consumes<reco::MuonCollection>(iConfig.getUntrackedParameter("MuonToken",edm::InputTag("muons")));
144 
145  TriggerResultsToken_ = consumes<edm::TriggerResults>(iConfig.getUntrackedParameter("TriggerResultsToken",edm::InputTag("TriggerResults")));
146  triggerSummaryLabelToken_ = consumes<trigger::TriggerEvent>(iConfig.getUntrackedParameter("triggerSummaryLabelToken",edm::InputTag("hltTriggerSummaryAOD","","HLT")));
147  // TriggerResultsToken_ = consumes<edm::TriggerResults>(iConfig.getUntrackedParameter("TriggerResultsToken",edm::InputTag("triggerSummaryLabel")));
148  // triggerSummaryLabelToken_ = consumes<trigger::TriggerEvent>(iConfig.getUntrackedParameter("triggerSummaryLabelToken",edm::InputTag("triggerSummaryLabel")));
149  //iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
150 
152  muon_data = muon->getData();
153 
154  tree_=fs_->make<TTree>("Muon2RecoTree", "Muon2RecoTree");
155  tree_->Branch("Muon", "L1Analysis::L1AnalysisRecoMuon2DataFormat", &muon_data, 32000, 3);
156 
157  triggerMaxDeltaR_ = iConfig.getParameter<double>("triggerMaxDeltaR");
158  triggerMatching_ = iConfig.getUntrackedParameter<bool>("triggerMatching");
159  triggerProcessLabel_ = iConfig.getUntrackedParameter<std::string>("triggerProcessLabel");
160  isoTriggerNames_ = iConfig.getParameter<std::vector<std::string>>("isoTriggerNames");
161  triggerNames_ = iConfig.getParameter<std::vector<std::string>>("triggerNames");
162 
163  // triggerMatching_ = iConfig.getUntrackedParameter<bool>("triggerMatching");
164  // _ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
165  // triggerProcessLabel_ = iConfig.getUntrackedParameter<std::string>("triggerProcessLabel");
166  // triggerNames_ = iConfig.getParameter<std::vector<std::string> > ("triggerNames");
167  // isoTriggerNames_ = iConfig.getParameter<std::vector<std::string> > ("isoTriggerNames");
168  // triggerMaxDeltaR_ = iConfig.getParameter<double> ("triggerMaxDeltaR");
169 
170 }
L1Analysis::L1AnalysisRecoMuon2DataFormat * muon_data
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
edm::EDGetTokenT< reco::MuonCollection > MuonToken_
edm::Service< TFileService > fs_
edm::EDGetTokenT< edm::TriggerResults > TriggerResultsToken_
L1Analysis::L1AnalysisRecoMuon2 * muon
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryLabelToken_
std::vector< std::string > triggerNames_
std::vector< std::string > isoTriggerNames_
L1Muon2RecoTreeProducer::~L1Muon2RecoTreeProducer ( )

Definition at line 173 of file L1Muon2RecoTreeProducer.cc.

174 {
175 
176  // do anything here that needs to be done at desctruction time
177  // (e.g. close files, deallocate resources etc.)
178 
179 }

Member Function Documentation

void L1Muon2RecoTreeProducer::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDAnalyzer.

Definition at line 187 of file L1Muon2RecoTreeProducer.cc.

References edm::Event::getByToken(), edm::HandleBase::isValid(), metsig::muon, and triggerResults.

188 {
189 
190  muon->Reset();
192  iEvent.getByToken(MuonToken_, recoMuons);
193 
195  iEvent.getByToken(TriggerResultsToken_, triggerResults);
196 
197  edm::Handle<trigger::TriggerEvent> triggerSummaryLabel_;
198  iEvent.getByToken(triggerSummaryLabelToken_, triggerSummaryLabel_);
199 
200  if (recoMuons.isValid()) {
201  muon->SetMuon(iEvent, iSetup, recoMuons, maxMuon_);
202  }
203  else {
204 
205  }
206 
207  int counter_mu = 0;
208 
209  for(reco::MuonCollection::const_iterator imu = recoMuons->begin();
210  imu != recoMuons->end() && (unsigned) counter_mu < maxMuon_; imu++) {
211 
212  //---------------------------------------------------------------------
213  // TRIGGER MATCHING:
214  // if specified the reconstructed muons are matched to a trigger
215  //---------------------------------------------------------------------
216  if (triggerMatching_) {
217  double isoMatchDeltaR = 9999.;
218  double matchDeltaR = 9999.;
219  int hasIsoTriggered = 0;
220  int hasTriggered = 0;
221 
222 
223  // first check if the trigger results are valid:
224  if (triggerResults.isValid()) {
225 
226  if (triggerSummaryLabel_.isValid()) {
227  // get trigger objects:
228  const trigger::TriggerObjectCollection triggerObjects = triggerSummaryLabel_->getObjects();
229 
230  matchDeltaR = match_trigger(triggerIndices_, triggerObjects, triggerSummaryLabel_, (*imu));
231  if (matchDeltaR < triggerMaxDeltaR_)
232  hasTriggered = 1;
233 
234  // cout<<"isoTriggerIndices_.size() = "<<isoTriggerIndices_.size()<<endl;
235  // cout<<"triggerObjects.size() = "<<triggerObjects.size()<<endl;
236  // cout<<"imu->eta() = "<<imu->eta()<<endl;
237 
238  isoMatchDeltaR = match_trigger(isoTriggerIndices_, triggerObjects, triggerSummaryLabel_, (*imu));
239  if (isoMatchDeltaR < triggerMaxDeltaR_)
240  hasIsoTriggered = 1;
241 
242  } // end if (triggerEvent.isValid())
243 
244  } // end if (triggerResults.isValid())
245 
246  // fill trigger matching variables:
247  muon_data->hlt_isomu.push_back(hasIsoTriggered);
248  muon_data->hlt_mu.push_back(hasTriggered);
249  muon_data->hlt_isoDeltaR.push_back(isoMatchDeltaR);
250  muon_data->hlt_deltaR.push_back(matchDeltaR);
251 
252  } else {
253  empty_hlt();
254  } // end if (triggerMatching_)
255  }
256 
257 
258  tree_->Fill();
259 
260 }
L1Analysis::L1AnalysisRecoMuon2DataFormat * muon_data
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
double match_trigger(std::vector< int > &trigIndices, const trigger::TriggerObjectCollection &trigObjs, edm::Handle< trigger::TriggerEvent > &triggerEvent, const reco::Muon &mu)
edm::EDGetTokenT< reco::MuonCollection > MuonToken_
static std::string const triggerResults
Definition: EdmProvDump.cc:41
bool isValid() const
Definition: HandleBase.h:75
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:81
void SetMuon(const edm::Event &event, const edm::EventSetup &setup, const edm::Handle< reco::MuonCollection > muons, unsigned maxMuon)
edm::EDGetTokenT< edm::TriggerResults > TriggerResultsToken_
L1Analysis::L1AnalysisRecoMuon2 * muon
std::vector< int > isoTriggerIndices_
edm::EDGetTokenT< trigger::TriggerEvent > triggerSummaryLabelToken_
void L1Muon2RecoTreeProducer::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 264 of file L1Muon2RecoTreeProducer.cc.

265 {
266 }
void L1Muon2RecoTreeProducer::beginRun ( const edm::Run run,
const edm::EventSetup eventSetup 
)
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 319 of file L1Muon2RecoTreeProducer.cc.

References assert(), and gather_cfg::cout.

319  {
320  // Prepare for trigger matching for each new run:
321  // Look up triggetIndices in the HLT config for the different paths
322  if (triggerMatching_) {
323  bool changed = true;
324  if (!hltConfig_.init(run, eventSetup, triggerProcessLabel_, changed)) {
325  // if you can't initialize hlt configuration, crash!
326  std::cout << "Error: didn't find process" << triggerProcessLabel_ << std::endl;
327  assert(false);
328  }
329 
330  bool enableWildcard = true;
331  for (size_t iTrig = 0; iTrig < triggerNames_.size(); ++iTrig) {
332  // prepare for regular expression (with wildcards) functionality:
333  TString tNameTmp = TString(triggerNames_[iTrig]);
334  TRegexp tNamePattern = TRegexp(tNameTmp, enableWildcard);
335  int tIndex = -1;
336  // find the trigger index:
337  for (unsigned ipath = 0; ipath < hltConfig_.size(); ++ipath) {
338  // use TString since it provides reg exp functionality:
339  TString tmpName = TString(hltConfig_.triggerName(ipath));
340  if (tmpName.Contains(tNamePattern)) {
341  tIndex = int(ipath);
342  triggerIndices_.push_back(tIndex);
343  }
344  }
345  if (tIndex < 0) { // if can't find trigger path at all, give warning:
346  std::cout << "Warning: Could not find trigger" << triggerNames_[iTrig] << std::endl;
347  //assert(false);
348  }
349  } // end for triggerNames
350  for (size_t iTrig = 0; iTrig < isoTriggerNames_.size(); ++iTrig) {
351 
352  // prepare for regular expression functionality:
353  TString tNameTmp = TString(isoTriggerNames_[iTrig]);
354  TRegexp tNamePattern = TRegexp(tNameTmp, enableWildcard);
355  int tIndex = -1;
356  // find the trigger index:
357  for (unsigned ipath = 0; ipath < hltConfig_.size(); ++ipath) {
358  // use TString since it provides reg exp functionality:
359  TString tmpName = TString(hltConfig_.triggerName(ipath));
360  if (tmpName.Contains(tNamePattern)) {
361  tIndex = int(ipath);
362  isoTriggerIndices_.push_back(tIndex);
363  }
364  }
365  if (tIndex < 0) { // if can't find trigger path at all, give warning:
366  std::cout << "Warning: Could not find trigger" << isoTriggerNames_[iTrig] << std::endl;
367  //assert(false);
368  }
369  } // end for isoTriggerNames
370  } // end if (triggerMatching_)
371 }
unsigned int size() const
number of trigger paths in trigger table
const std::string & triggerName(unsigned int triggerIndex) const
assert(m_qm.get())
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
tuple cout
Definition: gather_cfg.py:145
std::vector< int > isoTriggerIndices_
std::vector< std::string > triggerNames_
std::vector< std::string > isoTriggerNames_
void L1Muon2RecoTreeProducer::empty_hlt ( )

Definition at line 273 of file L1Muon2RecoTreeProducer.cc.

273  {
274 
275  muon_data->hlt_isomu.push_back(-9999);
276  muon_data->hlt_mu.push_back(-9999);
277  muon_data->hlt_isoDeltaR.push_back(-9999);
278  muon_data->hlt_deltaR.push_back(-9999);
279 
280 }
L1Analysis::L1AnalysisRecoMuon2DataFormat * muon_data
void L1Muon2RecoTreeProducer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 270 of file L1Muon2RecoTreeProducer.cc.

270  {
271 }
double L1Muon2RecoTreeProducer::match_trigger ( std::vector< int > &  trigIndices,
const trigger::TriggerObjectCollection trigObjs,
edm::Handle< trigger::TriggerEvent > &  triggerEvent,
const reco::Muon mu 
)

Definition at line 282 of file L1Muon2RecoTreeProducer.cc.

References deltaR().

286 {
287  double matchDeltaR = 9999;
288 
289  for(size_t iTrigIndex = 0; iTrigIndex < trigIndices.size(); ++iTrigIndex) {
290  int triggerIndex = trigIndices[iTrigIndex];
291  const std::vector<std::string> moduleLabels(hltConfig_.moduleLabels(triggerIndex));
292  // find index of the last module:
293  const unsigned moduleIndex = hltConfig_.size(triggerIndex)-2;
294  // find index of HLT trigger name:
295  const unsigned hltFilterIndex = triggerEvent->filterIndex( edm::InputTag ( moduleLabels[moduleIndex], "", triggerProcessLabel_ ) );
296 
297  if (hltFilterIndex < triggerEvent->sizeFilters()) {
298  const trigger::Keys triggerKeys(triggerEvent->filterKeys(hltFilterIndex));
299  const trigger::Vids triggerVids(triggerEvent->filterIds(hltFilterIndex));
300 
301  const unsigned nTriggers = triggerVids.size();
302  for (size_t iTrig = 0; iTrig < nTriggers; ++iTrig) {
303  // loop over all trigger objects:
304  const trigger::TriggerObject trigObject = trigObjs[triggerKeys[iTrig]];
305 
306  double dRtmp = deltaR( mu, trigObject );
307 
308  if ( dRtmp < matchDeltaR ) {
309  matchDeltaR = dRtmp;
310  }
311 
312  } // loop over different trigger objects
313  } // if trigger is in event (should apply hltFilter with used trigger...)
314  } // loop over muon candidates
315 
316  return matchDeltaR;
317 }
unsigned int size() const
number of trigger paths in trigger table
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
std::vector< size_type > Keys
std::vector< int > Vids

Member Data Documentation

edm::Service<TFileService> L1Muon2RecoTreeProducer::fs_
private

Definition at line 102 of file L1Muon2RecoTreeProducer.cc.

HLTConfigProvider L1Muon2RecoTreeProducer::hltConfig_
private

Definition at line 121 of file L1Muon2RecoTreeProducer.cc.

std::vector<int> L1Muon2RecoTreeProducer::isoTriggerIndices_
private

Definition at line 130 of file L1Muon2RecoTreeProducer.cc.

std::vector<std::string> L1Muon2RecoTreeProducer::isoTriggerNames_
private

Definition at line 128 of file L1Muon2RecoTreeProducer.cc.

unsigned int L1Muon2RecoTreeProducer::maxMuon_
private

Definition at line 124 of file L1Muon2RecoTreeProducer.cc.

L1Analysis::L1AnalysisRecoMuon2* L1Muon2RecoTreeProducer::muon

Definition at line 91 of file L1Muon2RecoTreeProducer.cc.

L1Analysis::L1AnalysisRecoMuon2DataFormat* L1Muon2RecoTreeProducer::muon_data

Definition at line 93 of file L1Muon2RecoTreeProducer.cc.

edm::EDGetTokenT<reco::MuonCollection> L1Muon2RecoTreeProducer::MuonToken_
private

Definition at line 108 of file L1Muon2RecoTreeProducer.cc.

TTree* L1Muon2RecoTreeProducer::tree_
private

Definition at line 105 of file L1Muon2RecoTreeProducer.cc.

std::vector<int> L1Muon2RecoTreeProducer::triggerIndices_
private

Definition at line 131 of file L1Muon2RecoTreeProducer.cc.

bool L1Muon2RecoTreeProducer::triggerMatching_
private

Definition at line 126 of file L1Muon2RecoTreeProducer.cc.

double L1Muon2RecoTreeProducer::triggerMaxDeltaR_
private

Definition at line 125 of file L1Muon2RecoTreeProducer.cc.

std::vector<std::string> L1Muon2RecoTreeProducer::triggerNames_
private

Definition at line 129 of file L1Muon2RecoTreeProducer.cc.

std::string L1Muon2RecoTreeProducer::triggerProcessLabel_
private

Definition at line 127 of file L1Muon2RecoTreeProducer.cc.

edm::EDGetTokenT<edm::TriggerResults> L1Muon2RecoTreeProducer::TriggerResultsToken_
private

Definition at line 109 of file L1Muon2RecoTreeProducer.cc.

edm::EDGetTokenT<trigger::TriggerEvent> L1Muon2RecoTreeProducer::triggerSummaryLabelToken_
private

Definition at line 110 of file L1Muon2RecoTreeProducer.cc.