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