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