CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATTriggerEventProducer.cc
Go to the documentation of this file.
1 //
2 //
3 
4 
6 
7 #include <cassert>
8 
10 
12 
19 
23 
24 
25 using namespace pat;
26 using namespace edm;
27 
28 
30  nameProcess_( iConfig.getParameter< std::string >( "processName" ) ),
31  autoProcessName_( nameProcess_ == "*" ),
32  tagTriggerProducer_( "patTrigger" ),
33  tagsTriggerMatcher_(),
34  // L1 configuration parameters
35  tagL1Gt_(),
36  // HLTConfigProvider
37  hltConfigInit_( false ),
38  // HLT configuration parameters
39  tagTriggerResults_( "TriggerResults" ),
40  tagTriggerEvent_( "hltTriggerSummaryAOD" ),
41  // Conditions configuration parameters
42  tagCondGt_(),
43  // Conditions
44  condRun_(),
45  condLumi_(),
46  gtCondRunInit_( false ),
47  gtCondLumiInit_( false )
48 {
49 
50  if ( iConfig.exists( "triggerResults" ) ) tagTriggerResults_ = iConfig.getParameter< InputTag >( "triggerResults" );
52  if ( iConfig.exists( "triggerEvent" ) ) tagTriggerEvent_ = iConfig.getParameter< InputTag >( "triggerEvent" );
53  if ( iConfig.exists( "patTriggerProducer" ) ) tagTriggerProducer_ = iConfig.getParameter< InputTag >( "patTriggerProducer" );
54  triggerAlgorithmCollectionToken_ = mayConsume< TriggerAlgorithmCollection >( tagTriggerProducer_ );
55  triggerConditionCollectionToken_ = mayConsume< TriggerConditionCollection >( tagTriggerProducer_ );
56  triggerPathCollectionToken_ = mayConsume< TriggerPathCollection >( tagTriggerProducer_ );
57  triggerFilterCollectionToken_ = mayConsume< TriggerFilterCollection >( tagTriggerProducer_ );
58  triggerObjectCollectionToken_ = mayConsume< TriggerObjectCollection >( tagTriggerProducer_ );
59  if ( iConfig.exists( "condGtTag" ) ) {
60  tagCondGt_ = iConfig.getParameter< InputTag >( "condGtTag" );
61  tagCondGtRunToken_ = mayConsume< ConditionsInRunBlock, InRun >( tagCondGt_ );
62  tagCondGtLumiToken_ = mayConsume< ConditionsInLumiBlock, InLumi >( tagCondGt_ );
63  tagCondGtEventToken_ = mayConsume< ConditionsInEventBlock >( tagCondGt_ );
64  }
65  if ( iConfig.exists( "l1GtTag" ) ) tagL1Gt_ = iConfig.getParameter< InputTag >( "l1GtTag" );
66  l1GtToken_ = mayConsume< L1GlobalTriggerReadoutRecord >( tagL1Gt_ );
67  if ( iConfig.exists( "patTriggerMatches" ) ) tagsTriggerMatcher_ = iConfig.getParameter< std::vector< InputTag > >( "patTriggerMatches" );
68  triggerMatcherTokens_ = vector_transform( tagsTriggerMatcher_, [this](InputTag const & tag) { return mayConsume< TriggerObjectStandAloneMatch >( tag ); } );
69 
70  callWhenNewProductsRegistered( [ this, &iConfig ]( BranchDescription const& bd ) {
72  } );
73 
74  for ( size_t iMatch = 0; iMatch < tagsTriggerMatcher_.size(); ++iMatch ) {
75  produces< TriggerObjectMatch >( tagsTriggerMatcher_.at( iMatch ).label() );
76  }
77  produces< TriggerEvent >();
78 
79 }
80 
81 
82 void PATTriggerEventProducer::beginRun(const Run & iRun, const EventSetup & iSetup )
83 {
84 
85  // Initialize process name
86  if ( autoProcessName_ ) {
87  // reset
88  nameProcess_ = "*";
89  // determine process name from last run TriggerSummaryProducerAOD module in process history of input
90  const ProcessHistory & processHistory( iRun.processHistory() );
92  ParameterSet processPSet;
93  // unbroken loop, which relies on time ordering (accepts the last found entry)
94  for ( ProcessHistory::const_iterator iHist = processHistory.begin(); iHist != processHistory.end(); ++iHist ) {
95  if ( processHistory.getConfigurationForProcess( iHist->processName(), processConfiguration ) &&
96  pset::Registry::instance()->getMapped( processConfiguration.parameterSetID(), processPSet ) &&
97  processPSet.exists( tagTriggerEvent_.label() )
98  ) {
99  nameProcess_ = iHist->processName();
100  LogDebug( "autoProcessName" ) << "HLT process name '" << nameProcess_ << "' discovered";
101  }
102  }
103  // terminate, if nothing is found
104  if ( nameProcess_ == "*" ) {
105  LogError( "autoProcessName" ) << "trigger::TriggerEvent product with label '" << tagTriggerEvent_.label() << "' not produced according to process history of input data\n"
106  << "No trigger information produced.";
107  return;
108  }
109  LogInfo( "autoProcessName" ) << "HLT process name " << nameProcess_ << " used for PAT trigger information";
110  }
111  // adapt configuration of used input tags
112  if ( tagTriggerResults_.process().empty() || tagTriggerResults_.process() == "*" ) {
114  } else if ( tagTriggerEvent_.process() != nameProcess_ ) {
115  LogWarning( "triggerResultsTag" ) << "TriggerResults process name '" << tagTriggerResults_.process() << "' differs from HLT process name '" << nameProcess_ << "'";
116  }
117  if ( tagTriggerEvent_.process().empty() || tagTriggerEvent_.process() == "*" ) {
119  } else if ( tagTriggerEvent_.process() != nameProcess_ ) {
120  LogWarning( "triggerEventTag" ) << "TriggerEvent process name '" << tagTriggerEvent_.process() << "' differs from HLT process name '" << nameProcess_ << "'";
121  }
122 
123  gtCondRunInit_ = false;
124  if ( ! tagCondGt_.label().empty() ) {
125  Handle< ConditionsInRunBlock > condRunBlock;
126  iRun.getByToken( tagCondGtRunToken_, condRunBlock );
127  if ( condRunBlock.isValid() ) {
128  condRun_ = *condRunBlock;
129  gtCondRunInit_ = true;
130  } else {
131  LogError( "conditionsInEdm" ) << "ConditionsInRunBlock product with InputTag '" << tagCondGt_.encode() << "' not in run";
132  }
133  }
134 
135  // Initialize HLTConfigProvider
136  hltConfigInit_ = false;
137  bool changed( true );
138  if ( ! hltConfig_.init( iRun, iSetup, nameProcess_, changed ) ) {
139  LogError( "hltConfigExtraction" ) << "HLT config extraction error with process name '" << nameProcess_ << "'";
140  } else if ( hltConfig_.size() <= 0 ) {
141  LogError( "hltConfigSize" ) << "HLT config size error";
142  } else hltConfigInit_ = true;
143 
144 }
145 
146 void PATTriggerEventProducer::beginLuminosityBlock(const LuminosityBlock & iLuminosityBlock, const EventSetup & iSetup )
147 {
148 
149  // Terminate, if auto process name determination failed
150  if ( nameProcess_ == "*" ) return;
151 
152  gtCondLumiInit_ = false;
153  if ( ! tagCondGt_.label().empty() ) {
154  Handle< ConditionsInLumiBlock > condLumiBlock;
155  iLuminosityBlock.getByToken( tagCondGtLumiToken_, condLumiBlock );
156  if ( condLumiBlock.isValid() ) {
157  condLumi_ = *condLumiBlock;
158  gtCondLumiInit_ = true;
159  } else {
160  LogError( "conditionsInEdm" ) << "ConditionsInLumiBlock product with InputTag '" << tagCondGt_.encode() << "' not in lumi";
161  }
162  }
163 
164 }
165 
166 
168 {
169 
170  // Terminate, if auto process name determination failed
171  if ( nameProcess_ == "*" ) return;
172 
173  if ( ! hltConfigInit_ ) return;
174 
175  ESHandle< L1GtTriggerMenu > handleL1GtTriggerMenu;
176  iSetup.get< L1GtTriggerMenuRcd >().get( handleL1GtTriggerMenu );
177  Handle< TriggerResults > handleTriggerResults;
178  iEvent.getByLabel( tagTriggerResults_, handleTriggerResults );
179 // iEvent.getByToken( triggerResultsToken_, handleTriggerResults );
180  if ( ! handleTriggerResults.isValid() ) {
181  LogError( "triggerResultsValid" ) << "TriggerResults product with InputTag '" << tagTriggerResults_.encode() << "' not in event\n"
182  << "No trigger information produced";
183  return;
184  }
185  Handle< TriggerAlgorithmCollection > handleTriggerAlgorithms;
186  iEvent.getByToken( triggerAlgorithmCollectionToken_, handleTriggerAlgorithms );
187  Handle< TriggerConditionCollection > handleTriggerConditions;
188  iEvent.getByToken( triggerConditionCollectionToken_, handleTriggerConditions );
189  Handle< TriggerPathCollection > handleTriggerPaths;
190  iEvent.getByToken( triggerPathCollectionToken_, handleTriggerPaths );
191  Handle< TriggerFilterCollection > handleTriggerFilters;
192  iEvent.getByToken( triggerFilterCollectionToken_, handleTriggerFilters );
193  Handle< TriggerObjectCollection > handleTriggerObjects;
194  iEvent.getByToken( triggerObjectCollectionToken_, handleTriggerObjects );
195 
196  bool physDecl( false );
197  if ( iEvent.isRealData() && ! tagL1Gt_.label().empty() ) {
198  Handle< L1GlobalTriggerReadoutRecord > handleL1GlobalTriggerReadoutRecord;
199  iEvent.getByToken( l1GtToken_, handleL1GlobalTriggerReadoutRecord );
200  if ( handleL1GlobalTriggerReadoutRecord.isValid() ) {
201  L1GtFdlWord fdlWord = handleL1GlobalTriggerReadoutRecord->gtFdlWord();
202  if ( fdlWord.physicsDeclared() == 1 ) {
203  physDecl = true;
204  }
205  } else {
206  LogError( "l1GlobalTriggerReadoutRecordValid" ) << "L1GlobalTriggerReadoutRecord product with InputTag '" << tagL1Gt_.encode() << "' not in event";
207  }
208  } else {
209  physDecl = true;
210  }
211 
212 
213  // produce trigger event
214 
215  std::auto_ptr< TriggerEvent > triggerEvent( new TriggerEvent( handleL1GtTriggerMenu->gtTriggerMenuName(), std::string( hltConfig_.tableName() ), handleTriggerResults->wasrun(), handleTriggerResults->accept(), handleTriggerResults->error(), physDecl ) );
216  // set product references to trigger collections
217  if ( handleTriggerAlgorithms.isValid() ) {
218  triggerEvent->setAlgorithms( handleTriggerAlgorithms );
219  } else {
220  LogError( "triggerAlgorithmsValid" ) << "pat::TriggerAlgorithmCollection product with InputTag '" << tagTriggerProducer_.encode() << "' not in event";
221  }
222  if ( handleTriggerConditions.isValid() ) {
223  triggerEvent->setConditions( handleTriggerConditions );
224  } else {
225  LogError( "triggerConditionsValid" ) << "pat::TriggerConditionCollection product with InputTag '" << tagTriggerProducer_.encode() << "' not in event";
226  }
227  if ( handleTriggerPaths.isValid() ) {
228  triggerEvent->setPaths( handleTriggerPaths );
229  } else {
230  LogError( "triggerPathsValid" ) << "pat::TriggerPathCollection product with InputTag '" << tagTriggerProducer_.encode() << "' not in event";
231  }
232  if ( handleTriggerFilters.isValid() ) {
233  triggerEvent->setFilters( handleTriggerFilters );
234  } else {
235  LogError( "triggerFiltersValid" ) << "pat::TriggerFilterCollection product with InputTag '" << tagTriggerProducer_.encode() << "' not in event";
236  }
237  if ( handleTriggerObjects.isValid() ) {
238  triggerEvent->setObjects( handleTriggerObjects );
239  } else {
240  LogError( "triggerObjectsValid" ) << "pat::TriggerObjectCollection product with InputTag '" << tagTriggerProducer_.encode() << "' not in event";
241  }
242  if ( gtCondRunInit_ ) {
243  triggerEvent->setLhcFill( condRun_.lhcFillNumber );
244  triggerEvent->setBeamMode( condRun_.beamMode );
245  triggerEvent->setBeamMomentum( condRun_.beamMomentum );
246  triggerEvent->setBCurrentStart( condRun_.BStartCurrent );
247  triggerEvent->setBCurrentStop( condRun_.BStopCurrent );
248  triggerEvent->setBCurrentAvg( condRun_.BAvgCurrent );
249  }
250  if ( gtCondLumiInit_ ) {
251  triggerEvent->setIntensityBeam1( condLumi_.totalIntensityBeam1 );
252  triggerEvent->setIntensityBeam2( condLumi_.totalIntensityBeam2 );
253  }
254  if ( ! tagCondGt_.label().empty() ) {
255  Handle< ConditionsInEventBlock > condEventBlock;
256  iEvent.getByToken( tagCondGtEventToken_, condEventBlock );
257  if ( condEventBlock.isValid() ) {
258  triggerEvent->setBstMasterStatus( condEventBlock->bstMasterStatus );
259  triggerEvent->setTurnCount( condEventBlock->turnCountNumber );
260  } else {
261  LogError( "conditionsInEdm" ) << "ConditionsInEventBlock product with InputTag '" << tagCondGt_.encode() << "' not in event";
262  }
263  }
264 
265  // produce trigger match association and set references
266  if ( handleTriggerObjects.isValid() ) {
267  for ( size_t iMatch = 0; iMatch < tagsTriggerMatcher_.size(); ++iMatch ) {
268  const std::string labelTriggerObjectMatcher( tagsTriggerMatcher_.at( iMatch ).label() );
269  // copy trigger match association using TriggerObjectStandAlone to those using TriggerObject
270  // relying on the fact, that only one candidate collection is present in the association
271  Handle< TriggerObjectStandAloneMatch > handleTriggerObjectStandAloneMatch;
272  iEvent.getByToken( triggerMatcherTokens_.at( iMatch ), handleTriggerObjectStandAloneMatch );
273  if ( ! handleTriggerObjectStandAloneMatch.isValid() ) {
274  LogError( "triggerMatchValid" ) << "pat::TriggerObjectStandAloneMatch product with InputTag '" << labelTriggerObjectMatcher << "' not in event";
275  continue;
276  }
277  AssociativeIterator< reco::CandidateBaseRef, TriggerObjectStandAloneMatch > it( *handleTriggerObjectStandAloneMatch, EdmEventItemGetter< reco::CandidateBaseRef >( iEvent ) ), itEnd( it.end() );
278  Handle< reco::CandidateView > handleCands;
279  if ( it != itEnd ) iEvent.get( it->first.id(), handleCands );
280  std::vector< int > indices;
281  while ( it != itEnd ) {
282  indices.push_back( it->second.key() );
283  ++it;
284  }
285  std::auto_ptr< TriggerObjectMatch > triggerObjectMatch( new TriggerObjectMatch( handleTriggerObjects ) );
286  TriggerObjectMatch::Filler matchFiller( *triggerObjectMatch );
287  if ( handleCands.isValid() ) {
288  matchFiller.insert( handleCands, indices.begin(), indices.end() );
289  }
290  matchFiller.fill();
291  OrphanHandle< TriggerObjectMatch > handleTriggerObjectMatch( iEvent.put( triggerObjectMatch, labelTriggerObjectMatcher ) );
292  // set product reference to trigger match association
293  if ( ! handleTriggerObjectMatch.isValid() ) {
294  LogError( "triggerMatchValid" ) << "pat::TriggerObjectMatch product with InputTag '" << labelTriggerObjectMatcher << "' not in event";
295  continue;
296  }
297  if ( ! ( triggerEvent->addObjectMatchResult( handleTriggerObjectMatch, labelTriggerObjectMatcher ) ) ) {
298  LogWarning( "triggerObjectMatchReplication" ) << "pat::TriggerEvent contains already a pat::TriggerObjectMatch from matcher module '" << labelTriggerObjectMatcher << "'";
299  }
300  }
301  }
302 
303  iEvent.put( triggerEvent );
304 
305 }
306 
307 
#define LogDebug(id)
unsigned int size() const
number of trigger paths in trigger table
collection_type::const_iterator const_iterator
T getParameter(std::string const &) const
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
Definition: ProducerBase.h:51
edm::EDGetTokenT< TriggerConditionCollection > triggerConditionCollectionToken_
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
bool getByToken(EDGetToken token, Handle< PROD > &result) const
edm::Association< TriggerObjectCollection > TriggerObjectMatch
Association of TriggerObjects to store matches to Candidates.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
boost::uint32_t lhcFillNumber
bool exists(std::string const &parameterName) const
checks if a parameter exists
processConfiguration
Definition: Schedule.cc:369
boost::uint32_t totalIntensityBeam1
const std::string & tableName() const
HLT ConfDB table name.
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
edm::EDGetTokenT< edm::ConditionsInLumiBlock > tagCondGtLumiToken_
Produces the central entry point to full PAT trigger information.
bool isRealData() const
Definition: EventBase.h:60
std::string encode() const
Definition: InputTag.cc:164
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:239
boost::uint32_t totalIntensityBeam2
Helper class that fetches some type of Ref given ProductID and index, using the edm::Event.
PATTriggerEventProducer(const edm::ParameterSet &iConfig)
edm::GetterOfProducts< edm::TriggerResults > triggerResultsGetter_
edm::EDGetTokenT< TriggerObjectCollection > triggerObjectCollectionToken_
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:309
ProcessHistory const & processHistory() const
Definition: Run.cc:108
std::vector< edm::EDGetTokenT< TriggerObjectStandAloneMatch > > triggerMatcherTokens_
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
std::vector< edm::InputTag > tagsTriggerMatcher_
Analysis-level trigger event class.
Definition: TriggerEvent.h:42
virtual void beginLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup) override
edm::EDGetTokenT< L1GlobalTriggerReadoutRecord > l1GtToken_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
const T & get() const
Definition: EventSetup.h:55
const cms_uint16_t physicsDeclared() const
get/set &quot;physics declared&quot; bit
Definition: L1GtFdlWord.h:227
edm::ConditionsInRunBlock condRun_
edm::EDGetTokenT< edm::ConditionsInRunBlock > tagCondGtRunToken_
std::string const & label() const
Definition: InputTag.h:42
std::string const & process() const
Definition: InputTag.h:46
edm::EDGetTokenT< edm::ConditionsInEventBlock > tagCondGtEventToken_
edm::ConditionsInLumiBlock condLumi_
boost::uint16_t beamMomentum
volatile std::atomic< bool > shutdown_flag false
std::string const & instance() const
Definition: InputTag.h:43
virtual void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
edm::EDGetTokenT< TriggerFilterCollection > triggerFilterCollectionToken_
Definition: Run.h:41
edm::EDGetTokenT< TriggerPathCollection > triggerPathCollectionToken_
edm::EDGetTokenT< TriggerAlgorithmCollection > triggerAlgorithmCollectionToken_