CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1ExtraParticlesProd.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1ExtraParticlesProd
4 // Class: L1ExtraParticlesProd
5 //
8 //
9 // Original Author: Werner Sun
10 // Created: Mon Oct 2 22:45:32 EDT 2006
11 //
12 //
13 
14 
15 // system include files
16 #include <memory>
17 
18 // user include files
20 
23 
27 
30 
38 
44 
46 
47 // #include "FWCore/Utilities/interface/EDMException.h"
48 
49 //
50 // class decleration
51 //
52 
53 
54 //
55 // constants, enums and typedefs
56 //
57 
58 //
59 // static data member definitions
60 //
61 
62 double const L1ExtraParticlesProd::muonMassGeV_ = 0.105658369 ; // PDG06
63 
64 //
65 // constructors and destructor
66 //
68  : produceMuonParticles_( iConfig.getParameter< bool >(
69  "produceMuonParticles" ) ),
70  muonSource_( iConfig.getParameter< edm::InputTag >(
71  "muonSource" ) ),
72  produceCaloParticles_( iConfig.getParameter< bool >(
73  "produceCaloParticles" ) ),
74  isoEmSource_( iConfig.getParameter< edm::InputTag >(
75  "isolatedEmSource" ) ),
76  nonIsoEmSource_( iConfig.getParameter< edm::InputTag >(
77  "nonIsolatedEmSource" ) ),
78  cenJetSource_( iConfig.getParameter< edm::InputTag >(
79  "centralJetSource" ) ),
80  forJetSource_( iConfig.getParameter< edm::InputTag >(
81  "forwardJetSource" ) ),
82  tauJetSource_( iConfig.getParameter< edm::InputTag >(
83  "tauJetSource" ) ),
84  etTotSource_( iConfig.getParameter< edm::InputTag >(
85  "etTotalSource" ) ),
86  etHadSource_( iConfig.getParameter< edm::InputTag >(
87  "etHadSource" ) ),
88  etMissSource_( iConfig.getParameter< edm::InputTag >(
89  "etMissSource" ) ),
90  htMissSource_( iConfig.getParameter< edm::InputTag >(
91  "htMissSource" ) ),
92  hfRingEtSumsSource_( iConfig.getParameter< edm::InputTag >(
93  "hfRingEtSumsSource" ) ),
94  hfRingBitCountsSource_( iConfig.getParameter< edm::InputTag >(
95  "hfRingBitCountsSource" ) ),
96  centralBxOnly_( iConfig.getParameter< bool >( "centralBxOnly" ) ),
97  ignoreHtMiss_( iConfig.getParameter< bool >( "ignoreHtMiss" ) )
98 {
99  using namespace l1extra ;
100 
101  //register your products
102  produces< L1EmParticleCollection >( "Isolated" ) ;
103  produces< L1EmParticleCollection >( "NonIsolated" ) ;
104  produces< L1JetParticleCollection >( "Central" ) ;
105  produces< L1JetParticleCollection >( "Forward" ) ;
106  produces< L1JetParticleCollection >( "Tau" ) ;
107  produces< L1MuonParticleCollection >() ;
108  produces< L1EtMissParticleCollection >( "MET" ) ;
109  produces< L1EtMissParticleCollection >( "MHT" ) ;
110  produces< L1HFRingsCollection >() ;
111 
112  //now do what ever other initialization is needed
113  consumes<L1MuGMTReadoutCollection>(muonSource_);
114  consumes<L1GctEmCandCollection>(isoEmSource_);
115  consumes<L1GctEmCandCollection>(nonIsoEmSource_);
116  consumes<L1GctJetCandCollection>(cenJetSource_);
117  consumes<L1GctJetCandCollection>(forJetSource_);
118  consumes<L1GctJetCandCollection>(tauJetSource_);
119  consumes<L1GctEtTotalCollection>(etTotSource_);
120  consumes<L1GctEtMissCollection>(etMissSource_);
121  consumes<L1GctEtHadCollection>(etHadSource_);
122  consumes<L1GctHtMissCollection>(htMissSource_);
123  consumes<L1GctHFRingEtSumsCollection>(hfRingEtSumsSource_);
124  consumes<L1GctHFBitCountsCollection>(hfRingBitCountsSource_);
125 }
126 
127 
129 {
130 
131  // do anything here that needs to be done at desctruction time
132  // (e.g. close files, deallocate resources etc.)
133 
134 }
135 
136 
137 //
138 // member functions
139 //
140 
141 // ------------ method called to produce the data ------------
142 void
144  const edm::EventSetup& iSetup)
145 {
146  using namespace edm ;
147  using namespace l1extra ;
148  using namespace std ;
149 
150  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151  // ~~~~~~~~~~~~~~~~~~~~ Muons ~~~~~~~~~~~~~~~~~~~~
152  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
153 
154  auto_ptr< L1MuonParticleCollection > muColl(
156 
158  {
160  iSetup.get< L1MuTriggerScalesRcd >().get( muScales ) ;
161 
163  iSetup.get< L1MuTriggerPtScaleRcd >().get( muPtScale ) ;
164 
165  Handle< L1MuGMTReadoutCollection > hwMuCollection ;
166  iEvent.getByLabel( muonSource_, hwMuCollection ) ;
167 
168  vector< L1MuGMTExtendedCand > hwMuCands ;
169 
170  if( !hwMuCollection.isValid() )
171  {
172  LogDebug("L1ExtraParticlesProd")
173  << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_
174  << "\nrequested in configuration, but not found in the event."
175  << std::endl;
176  }
177  else
178  {
179  if( centralBxOnly_ )
180  {
181  // Get GMT candidates from central bunch crossing only
182  hwMuCands = hwMuCollection->getRecord().getGMTCands() ;
183  }
184  else
185  {
186  // Get GMT candidates from all bunch crossings
187  vector< L1MuGMTReadoutRecord > records = hwMuCollection->getRecords();
188  vector< L1MuGMTReadoutRecord >::const_iterator rItr = records.begin();
189  vector< L1MuGMTReadoutRecord >::const_iterator rEnd = records.end();
190 
191  for( ; rItr != rEnd ; ++rItr )
192  {
193  vector< L1MuGMTExtendedCand > tmpCands = rItr->getGMTCands() ;
194 
195  hwMuCands.insert( hwMuCands.end(),
196  tmpCands.begin(),
197  tmpCands.end() ) ;
198  }
199  }
200 
201 // cout << "HW muons" << endl ;
202  vector< L1MuGMTExtendedCand >::const_iterator muItr = hwMuCands.begin() ;
203  vector< L1MuGMTExtendedCand >::const_iterator muEnd = hwMuCands.end() ;
204  for( int i = 0 ; muItr != muEnd ; ++muItr, ++i )
205  {
206 // cout << "#" << i
207 // << " name " << muItr->name()
208 // << " empty " << muItr->empty()
209 // << " pt " << muItr->ptIndex()
210 // << " eta " << muItr->etaIndex()
211 // << " phi " << muItr->phiIndex()
212 // << " iso " << muItr->isol()
213 // << " mip " << muItr->mip()
214 // << " bx " << muItr->bx()
215 // << endl ;
216 
217  if( !muItr->empty() )
218  {
219  // keep x and y components non-zero and protect against roundoff.
220  double pt =
221  muPtScale->getPtScale()->getLowEdge( muItr->ptIndex() ) + 1.e-6 ;
222 
223 // cout << "L1Extra pt " << pt << endl ;
224 
225  double eta =
226  muScales->getGMTEtaScale()->getCenter( muItr->etaIndex() ) ;
227 
228  double phi =
229  muScales->getPhiScale()->getLowEdge( muItr->phiIndex() ) ;
230 
232  eta,
233  phi,
234  muonMassGeV_ ) ;
235 
236  muColl->push_back(
237  L1MuonParticle( muItr->charge(),
238  p4,
239  *muItr,
240  muItr->bx() )
241  ) ;
242  }
243  }
244  }
245  }
246 
248  iEvent.put( muColl );
249 
250 
251  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
252  // ~~~~~~~~~~~~~~~~~~~~ Calorimeter ~~~~~~~~~~~~~~~~~~~~
253  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
254 
255  auto_ptr< L1EmParticleCollection > isoEmColl(
257 
258  auto_ptr< L1EmParticleCollection > nonIsoEmColl(
260 
261  auto_ptr< L1JetParticleCollection > cenJetColl(
263 
264  auto_ptr< L1JetParticleCollection > forJetColl(
266 
267  auto_ptr< L1JetParticleCollection > tauJetColl(
269 
270  auto_ptr< L1EtMissParticleCollection > etMissColl(
272 
273  auto_ptr< L1EtMissParticleCollection > htMissColl(
275 
276  auto_ptr< L1HFRingsCollection > hfRingsColl( new L1HFRingsCollection );
277 
279  {
280  // ~~~~~~~~~~~~~~~~~~~~ Geometry ~~~~~~~~~~~~~~~~~~~~
281 
282  ESHandle< L1CaloGeometry > caloGeomESH ;
283  iSetup.get< L1CaloGeometryRecord >().get( caloGeomESH ) ;
284  const L1CaloGeometry* caloGeom = &( *caloGeomESH ) ;
285 
286  // ~~~~~~~~~~~~~~~~~~~~ EM ~~~~~~~~~~~~~~~~~~~~
287 
288  ESHandle< L1CaloEtScale > emScale ;
289  iSetup.get< L1EmEtScaleRcd >().get( emScale ) ;
290 
291  // Isolated EM
292  Handle< L1GctEmCandCollection > hwIsoEmCands ;
293  iEvent.getByLabel( isoEmSource_, hwIsoEmCands ) ;
294 
295  if( !hwIsoEmCands.isValid() )
296  {
297  LogDebug("L1ExtraParticlesProd")
298  << "\nWarning: L1GctEmCandCollection with " << isoEmSource_
299  << "\nrequested in configuration, but not found in the event."
300  << std::endl;
301  }
302  else
303  {
304 // cout << "HW iso EM" << endl ;
305 
306  L1GctEmCandCollection::const_iterator emItr = hwIsoEmCands->begin() ;
307  L1GctEmCandCollection::const_iterator emEnd = hwIsoEmCands->end() ;
308  for( int i = 0 ; emItr != emEnd ; ++emItr, ++i )
309  {
310 // cout << "#" << i
311 // << " name " << emItr->name()
312 // << " empty " << emItr->empty()
313 // << " rank " << emItr->rank()
314 // << " eta " << emItr->etaIndex()
315 // << " sign " << emItr->etaSign()
316 // << " phi " << emItr->phiIndex()
317 // << " iso " << emItr->isolated()
318 // << " bx " << emItr->bx()
319 // << endl ;
320 
321  if( !emItr->empty() &&
322  ( !centralBxOnly_ || emItr->bx() == 0 ) )
323  {
324  double et = emScale->et( emItr->rank() ) ;
325 
326 // cout << "L1Extra et " << et << endl ;
327 
328  isoEmColl->push_back(
329  L1EmParticle( gctLorentzVector( et, *emItr, caloGeom, true ),
330  Ref< L1GctEmCandCollection >( hwIsoEmCands,
331  i ),
332  emItr->bx() ) ) ;
333  }
334  }
335  }
336 
337 
338  // Non-isolated EM
339  Handle< L1GctEmCandCollection > hwNonIsoEmCands ;
340  iEvent.getByLabel( nonIsoEmSource_, hwNonIsoEmCands ) ;
341 
342  if( !hwNonIsoEmCands.isValid() )
343  {
344  LogDebug("L1ExtraParticlesProd")
345  << "\nWarning: L1GctEmCandCollection with " << nonIsoEmSource_
346  << "\nrequested in configuration, but not found in the event."
347  << std::endl;
348  }
349  else
350  {
351 // cout << "HW non-iso EM" << endl ;
352  L1GctEmCandCollection::const_iterator emItr = hwNonIsoEmCands->begin() ;
353  L1GctEmCandCollection::const_iterator emEnd = hwNonIsoEmCands->end() ;
354  for( int i = 0 ; emItr != emEnd ; ++emItr, ++i )
355  {
356 // cout << "#" << i
357 // << " name " << emItr->name()
358 // << " empty " << emItr->empty()
359 // << " rank " << emItr->rank()
360 // << " eta " << emItr->etaIndex()
361 // << " sign " << emItr->etaSign()
362 // << " phi " << emItr->phiIndex()
363 // << " iso " << emItr->isolated()
364 // << " bx " << emItr->bx()
365 // << endl ;
366 
367  if( !emItr->empty() &&
368  ( !centralBxOnly_ || emItr->bx() == 0 ) )
369  {
370  double et = emScale->et( emItr->rank() ) ;
371 
372 // cout << "L1Extra et " << et << endl ;
373 
374  nonIsoEmColl->push_back(
375  L1EmParticle( gctLorentzVector( et, *emItr, caloGeom, true ),
376  Ref< L1GctEmCandCollection >( hwNonIsoEmCands,
377  i ),
378  emItr->bx() ) );
379  }
380  }
381  }
382 
383 
384  // ~~~~~~~~~~~~~~~~~~~~ Jets ~~~~~~~~~~~~~~~~~~~~
385 
386  ESHandle< L1CaloEtScale > jetScale ;
387  iSetup.get< L1JetEtScaleRcd >().get( jetScale ) ;
388 
389  // Central jets.
390  Handle< L1GctJetCandCollection > hwCenJetCands ;
391  iEvent.getByLabel( cenJetSource_, hwCenJetCands ) ;
392 
393  if( !hwCenJetCands.isValid() )
394  {
395  LogDebug("L1ExtraParticlesProd")
396  << "\nWarning: L1GctJetCandCollection with " << cenJetSource_
397  << "\nrequested in configuration, but not found in the event."
398  << std::endl;
399  }
400  else
401  {
402 // cout << "HW central jets" << endl ;
403  L1GctJetCandCollection::const_iterator jetItr = hwCenJetCands->begin() ;
404  L1GctJetCandCollection::const_iterator jetEnd = hwCenJetCands->end() ;
405  for( int i = 0 ; jetItr != jetEnd ; ++jetItr, ++i )
406  {
407 // cout << "#" << i
408 // << " name " << jetItr->name()
409 // << " empty " << jetItr->empty()
410 // << " rank " << jetItr->rank()
411 // << " eta " << jetItr->etaIndex()
412 // << " sign " << jetItr->etaSign()
413 // << " phi " << jetItr->phiIndex()
414 // << " cen " << jetItr->isCentral()
415 // << " for " << jetItr->isForward()
416 // << " tau " << jetItr->isTau()
417 // << " bx " << jetItr->bx()
418 // << endl ;
419 
420  if( !jetItr->empty() &&
421  ( !centralBxOnly_ || jetItr->bx() == 0 ) )
422  {
423  double et = jetScale->et( jetItr->rank() ) ;
424 
425 // cout << "L1Extra et " << et << endl ;
426 
427  cenJetColl->push_back(
428  L1JetParticle( gctLorentzVector( et, *jetItr, caloGeom, true ),
429  Ref< L1GctJetCandCollection >( hwCenJetCands,
430  i ),
431  jetItr->bx() ) ) ;
432  }
433  }
434  }
435 
436 
437  // Forward jets.
438  Handle< L1GctJetCandCollection > hwForJetCands ;
439  iEvent.getByLabel( forJetSource_, hwForJetCands ) ;
440 
441  if( !hwForJetCands.isValid() )
442  {
443  LogDebug("L1ExtraParticlesProd")
444  << "\nWarning: L1GctEmCandCollection with " << forJetSource_
445  << "\nrequested in configuration, but not found in the event."
446  << std::endl;
447  }
448  else
449  {
450 // cout << "HW forward jets" << endl ;
451  L1GctJetCandCollection::const_iterator jetItr = hwForJetCands->begin() ;
452  L1GctJetCandCollection::const_iterator jetEnd = hwForJetCands->end() ;
453  for( int i = 0 ; jetItr != jetEnd ; ++jetItr, ++i )
454  {
455 // cout << "#" << i
456 // << " name " << jetItr->name()
457 // << " empty " << jetItr->empty()
458 // << " rank " << jetItr->rank()
459 // << " eta " << jetItr->etaIndex()
460 // << " sign " << jetItr->etaSign()
461 // << " phi " << jetItr->phiIndex()
462 // << " cen " << jetItr->isCentral()
463 // << " for " << jetItr->isForward()
464 // << " tau " << jetItr->isTau()
465 // << " bx " << jetItr->bx()
466 // << endl ;
467 
468  if( !jetItr->empty() &&
469  ( !centralBxOnly_ || jetItr->bx() == 0 ) )
470  {
471  double et = jetScale->et( jetItr->rank() ) ;
472 
473 // cout << "L1Extra et " << et << endl ;
474 
475  forJetColl->push_back(
476  L1JetParticle( gctLorentzVector( et, *jetItr, caloGeom, false ),
477  Ref< L1GctJetCandCollection >( hwForJetCands,
478  i ),
479  jetItr->bx() ) ) ;
480  }
481  }
482  }
483 
484 
485  // Tau jets.
486 // cout << "HW tau jets" << endl ;
487  Handle< L1GctJetCandCollection > hwTauJetCands ;
488  iEvent.getByLabel( tauJetSource_, hwTauJetCands ) ;
489 
490  if( !hwTauJetCands.isValid() )
491  {
492  LogDebug("L1ExtraParticlesProd")
493  << "\nWarning: L1GctJetCandCollection with " << tauJetSource_
494  << "\nrequested in configuration, but not found in the event."
495  << std::endl;
496  }
497  else
498  {
499  L1GctJetCandCollection::const_iterator jetItr = hwTauJetCands->begin() ;
500  L1GctJetCandCollection::const_iterator jetEnd = hwTauJetCands->end() ;
501  for( int i = 0 ; jetItr != jetEnd ; ++jetItr, ++i )
502  {
503 // cout << "#" << i
504 // << " name " << jetItr->name()
505 // << " empty " << jetItr->empty()
506 // << " rank " << jetItr->rank()
507 // << " eta " << jetItr->etaIndex()
508 // << " sign " << jetItr->etaSign()
509 // << " phi " << jetItr->phiIndex()
510 // << " cen " << jetItr->isCentral()
511 // << " for " << jetItr->isForward()
512 // << " tau " << jetItr->isTau()
513 // << " bx " << jetItr->bx()
514 // << endl ;
515 
516  if( !jetItr->empty() &&
517  ( !centralBxOnly_ || jetItr->bx() == 0 ) )
518  {
519  double et = jetScale->et( jetItr->rank() ) ;
520 
521 // cout << "L1Extra et " << et << endl ;
522 
523  tauJetColl->push_back(
524  L1JetParticle( gctLorentzVector( et, *jetItr, caloGeom, true ),
525  Ref< L1GctJetCandCollection >( hwTauJetCands,
526  i ),
527  jetItr->bx() ) ) ;
528  }
529  }
530  }
531 
532  // ~~~~~~~~~~~~~~~~~~~~ ET Sums ~~~~~~~~~~~~~~~~~~~~
533 
534  double etSumLSB = jetScale->linearLsb() ;
535 
537  iEvent.getByLabel( etTotSource_, hwEtTotColl ) ;
538 
539  Handle< L1GctEtMissCollection > hwEtMissColl ;
540  iEvent.getByLabel( etMissSource_, hwEtMissColl ) ;
541 
542  if( !hwEtTotColl.isValid() )
543  {
544  LogDebug("L1ExtraParticlesProd")
545  << "\nWarning: L1GctEtTotalCollection with " << etTotSource_
546  << "\nrequested in configuration, but not found in the event."
547  << std::endl;
548  }
549  else if( !hwEtMissColl.isValid() )
550  {
551  LogDebug("L1ExtraParticlesProd")
552  << "\nWarning: L1GctEtMissCollection with " << etMissSource_
553  << "\nrequested in configuration, but not found in the event."
554  << std::endl;
555  }
556  else
557  {
558  // Make a L1EtMissParticle even if either L1GctEtTotal or L1GctEtMiss
559  // is missing for a given bx. Keep track of which L1GctEtMiss objects
560  // have a corresponding L1GctEtTotal object.
561  std::vector< bool > etMissMatched ;
562 
563  L1GctEtMissCollection::const_iterator hwEtMissItr =
564  hwEtMissColl->begin() ;
565  L1GctEtMissCollection::const_iterator hwEtMissEnd =
566  hwEtMissColl->end() ;
567  for( ; hwEtMissItr != hwEtMissEnd ; ++hwEtMissItr )
568  {
569  etMissMatched.push_back( false ) ;
570  }
571 
572  // Collate energy sums by bx
573  L1GctEtTotalCollection::const_iterator hwEtTotItr =
574  hwEtTotColl->begin() ;
575  L1GctEtTotalCollection::const_iterator hwEtTotEnd =
576  hwEtTotColl->end() ;
577 
578  int iTot = 0 ;
579  for( ; hwEtTotItr != hwEtTotEnd ; ++hwEtTotItr, ++iTot )
580  {
581  int bx = hwEtTotItr->bx() ;
582 
583  if( !centralBxOnly_ || bx == 0 )
584  {
585  // ET bin low edge
586  double etTot =
587  ( hwEtTotItr->overFlow() ?
588  ( double ) L1GctEtTotal::kEtTotalMaxValue :
589  ( double ) hwEtTotItr->et() ) * etSumLSB + 1.e-6 ;
590 
591  int iMiss = 0 ;
592  hwEtMissItr = hwEtMissColl->begin() ;
593  hwEtMissEnd = hwEtMissColl->end() ;
594  for( ; hwEtMissItr != hwEtMissEnd ; ++hwEtMissItr, ++iMiss )
595  {
596  if( hwEtMissItr->bx() == bx )
597  {
598  etMissMatched[ iMiss ] = true ;
599  break ;
600  }
601  }
602 
603  double etMiss = 0. ;
604  double phi = 0. ;
607 
608  // If a L1GctEtMiss with the right bx is not found, itr == end.
609  if( hwEtMissItr != hwEtMissEnd )
610  {
611  // ET bin low edge
612  etMiss =
613  ( hwEtMissItr->overFlow() ?
614  ( double ) L1GctEtMiss::kEtMissMaxValue :
615  ( double ) hwEtMissItr->et() ) * etSumLSB + 1.e-6 ;
616  // keep x and y components non-zero and
617  // protect against roundoff.
618 
619  phi = caloGeom->etSumPhiBinCenter( hwEtMissItr->phi() ) ;
620 
621  p4 = math::PtEtaPhiMLorentzVector( etMiss,
622  0.,
623  phi,
624  0. ) ;
625 
626  metRef = Ref< L1GctEtMissCollection >( hwEtMissColl, iMiss ) ;
627 
628 // cout << "HW ET Sums " << endl
629 // << "MET: phi " << hwEtMissItr->phi() << " = " << phi
630 // << " et " << hwEtMissItr->et() << " = " << etMiss
631 // << " EtTot " << hwEtTotItr->et() << " = " << etTot
632 // << " bx " << bx
633 // << endl ;
634  }
635 // else
636 // {
637 // cout << "HW ET Sums " << endl
638 // << "MET: phi " << phi
639 // << " et "<< etMiss
640 // << " EtTot " << hwEtTotItr->et() << " = " << etTot
641 // << " bx " << bx
642 // << endl ;
643 // }
644 
645  etMissColl->push_back(
647  p4,
648  L1EtMissParticle::kMET,
649  etTot,
650  metRef,
651  Ref< L1GctEtTotalCollection >( hwEtTotColl, iTot ),
654  bx
655  ) ) ;
656  }
657  }
658 
659  if( !centralBxOnly_ )
660  {
661  // Make L1EtMissParticles for those L1GctEtMiss objects without
662  // a matched L1GctEtTotal object.
663 
664  double etTot = 0. ;
665 
666  hwEtMissItr = hwEtMissColl->begin() ;
667  hwEtMissEnd = hwEtMissColl->end() ;
668  int iMiss = 0 ;
669  for( ; hwEtMissItr != hwEtMissEnd ; ++hwEtMissItr, ++iMiss )
670  {
671  if( !etMissMatched[ iMiss ] )
672  {
673  int bx = hwEtMissItr->bx() ;
674 
675  // ET bin low edge
676  double etMiss =
677  ( hwEtMissItr->overFlow() ?
678  ( double ) L1GctEtMiss::kEtMissMaxValue :
679  ( double ) hwEtMissItr->et() ) * etSumLSB + 1.e-6 ;
680  // keep x and y components non-zero and
681  // protect against roundoff.
682 
683  double phi =
684  caloGeom->etSumPhiBinCenter( hwEtMissItr->phi() ) ;
685 
687  0.,
688  phi,
689  0. ) ;
690 
691 // cout << "HW ET Sums " << endl
692 // << "MET: phi " << hwEtMissItr->phi() << " = " << phi
693 // << " et " << hwEtMissItr->et() << " = " << etMiss
694 // << " EtTot " << etTot
695 // << " bx " << bx
696 // << endl ;
697 
698  etMissColl->push_back(
700  p4,
701  L1EtMissParticle::kMET,
702  etTot,
703  Ref< L1GctEtMissCollection >( hwEtMissColl, iMiss ),
707  bx
708  ) ) ;
709  }
710  }
711  }
712  }
713 
714  // ~~~~~~~~~~~~~~~~~~~~ HT Sums ~~~~~~~~~~~~~~~~~~~~
715 
716  Handle< L1GctEtHadCollection > hwEtHadColl ;
717  iEvent.getByLabel( etHadSource_, hwEtHadColl ) ;
718 
719  Handle< L1GctHtMissCollection > hwHtMissColl ;
720  if( !ignoreHtMiss_ )
721  {
722  iEvent.getByLabel( htMissSource_, hwHtMissColl ) ;
723  }
724 
725  ESHandle< L1GctJetFinderParams > jetFinderParams ;
726  iSetup.get< L1GctJetFinderParamsRcd >().get( jetFinderParams ) ;
727  double htSumLSB = jetFinderParams->getHtLsbGeV();
728 
729  ESHandle< L1CaloEtScale > htMissScale ;
730  std::vector< bool > htMissMatched ;
731  if( !ignoreHtMiss_ )
732  {
733  iSetup.get< L1HtMissScaleRcd >().get( htMissScale ) ;
734 
735  if( !hwEtHadColl.isValid() )
736  {
737  LogDebug("L1ExtraParticlesProd")
738  << "\nWarning: L1GctEtHadCollection with " << etHadSource_
739  << "\nrequested in configuration, but not found in the event."
740  << std::endl;
741  }
742  else if( !hwHtMissColl.isValid() )
743  {
744  LogDebug("L1ExtraParticlesProd")
745  << "\nWarning: L1GctHtMissCollection with " << htMissSource_
746  << "\nrequested in configuration, but not found in the event."
747  << std::endl;
748  }
749  else
750  {
751  // Make a L1EtMissParticle even if either L1GctEtHad or L1GctHtMiss
752  // is missing for a given bx. Keep track of which L1GctHtMiss objects
753  // have a corresponding L1GctHtTotal object.
754  L1GctHtMissCollection::const_iterator hwHtMissItr =
755  hwHtMissColl->begin() ;
756  L1GctHtMissCollection::const_iterator hwHtMissEnd =
757  hwHtMissColl->end() ;
758  for( ; hwHtMissItr != hwHtMissEnd ; ++hwHtMissItr )
759  {
760  htMissMatched.push_back( false ) ;
761  }
762  }
763  }
764 
765  if( !hwEtHadColl.isValid() )
766  {
767  LogDebug("L1ExtraParticlesProd")
768  << "\nWarning: L1GctEtHadCollection with " << etHadSource_
769  << "\nrequested in configuration, but not found in the event."
770  << std::endl;
771  }
772  else if( !hwHtMissColl.isValid() )
773  {
774  LogDebug("L1ExtraParticlesProd")
775  << "\nWarning: L1GctHtMissCollection with " << htMissSource_
776  << "\nrequested in configuration, but not found in the event."
777  << std::endl;
778  }
779  else
780  {
781  L1GctEtHadCollection::const_iterator hwEtHadItr =
782  hwEtHadColl->begin() ;
783  L1GctEtHadCollection::const_iterator hwEtHadEnd =
784  hwEtHadColl->end() ;
785 
786  int iHad = 0 ;
787  for( ; hwEtHadItr != hwEtHadEnd ; ++hwEtHadItr, ++iHad )
788  {
789  int bx = hwEtHadItr->bx() ;
790 
791  if( !centralBxOnly_ || bx == 0 )
792  {
793  // HT bin low edge
794  double htTot =
795  ( hwEtHadItr->overFlow() ?
796  ( double ) L1GctEtHad::kEtHadMaxValue :
797  ( double ) hwEtHadItr->et() ) * htSumLSB + 1.e-6 ;
798 
799  double htMiss = 0. ;
800  double phi = 0. ;
803 
804  if( !ignoreHtMiss_ )
805  {
806  L1GctHtMissCollection::const_iterator hwHtMissItr =
807  hwHtMissColl->begin() ;
808  L1GctHtMissCollection::const_iterator hwHtMissEnd =
809  hwHtMissColl->end() ;
810 
811  int iMiss = 0 ;
812  for( ; hwHtMissItr != hwHtMissEnd ; ++hwHtMissItr, ++iMiss )
813  {
814  if( hwHtMissItr->bx() == bx )
815  {
816  htMissMatched[ iMiss ] = true ;
817  break ;
818  }
819  }
820 
821  // If a L1GctHtMiss with the right bx is not found, itr == end.
822  if( hwHtMissItr != hwHtMissEnd )
823  {
824  // HT bin low edge
825  htMiss =
826  htMissScale->et( hwHtMissItr->overFlow() ?
827  htMissScale->rankScaleMax() :
828  hwHtMissItr->et() ) + 1.e-6 ;
829  // keep x and y components non-zero and
830  // protect against roundoff.
831 
832  phi =
833  caloGeom->htSumPhiBinCenter( hwHtMissItr->phi() ) ;
834 
835  p4 = math::PtEtaPhiMLorentzVector( htMiss,
836  0.,
837  phi,
838  0. ) ;
839 
840  mhtRef=Ref< L1GctHtMissCollection >( hwHtMissColl, iMiss );
841 
842 // cout << "HW HT Sums " << endl
843 // << "MHT: phi " << hwHtMissItr->phi() << " = " << phi
844 // << " ht " << hwHtMissItr->et() << " = " << htMiss
845 // << " HtTot " << hwEtHadItr->et() << " = " << htTot
846 // << " bx " << bx
847 // << endl ;
848  }
849 // else
850 // {
851 // cout << "HW HT Sums " << endl
852 // << "MHT: phi " << phi
853 // << " ht " << htMiss
854 // << " HtTot " << hwEtHadItr->et() << " = " << htTot
855 // << " bx " << bx
856 // << endl ;
857 // }
858  }
859 
860  htMissColl->push_back(
862  p4,
863  L1EtMissParticle::kMHT,
864  htTot,
867  mhtRef,
868  Ref< L1GctEtHadCollection >( hwEtHadColl, iHad ),
869  bx
870  ) ) ;
871  }
872  }
873 
874  if( !centralBxOnly_ && !ignoreHtMiss_ )
875  {
876  // Make L1EtMissParticles for those L1GctHtMiss objects without
877  // a matched L1GctHtTotal object.
878  double htTot = 0. ;
879 
880  L1GctHtMissCollection::const_iterator hwHtMissItr =
881  hwHtMissColl->begin() ;
882  L1GctHtMissCollection::const_iterator hwHtMissEnd =
883  hwHtMissColl->end() ;
884 
885  int iMiss = 0 ;
886  for( ; hwHtMissItr != hwHtMissEnd ; ++hwHtMissItr, ++iMiss )
887  {
888  if( !htMissMatched[ iMiss ] )
889  {
890  int bx = hwHtMissItr->bx() ;
891 
892  // HT bin low edge
893  double htMiss =
894  htMissScale->et( hwHtMissItr->overFlow() ?
895  htMissScale->rankScaleMax() :
896  hwHtMissItr->et() ) + 1.e-6 ;
897  // keep x and y components non-zero and
898  // protect against roundoff.
899 
900  double phi =
901  caloGeom->htSumPhiBinCenter( hwHtMissItr->phi() ) ;
902 
904  0.,
905  phi,
906  0. ) ;
907 
908 // cout << "HW HT Sums " << endl
909 // << "MHT: phi " << hwHtMissItr->phi() << " = " << phi
910 // << " ht " << hwHtMissItr->et() << " = " << htMiss
911 // << " HtTot " << htTot
912 // << " bx " << bx
913 // << endl ;
914 
915  htMissColl->push_back(
917  p4,
918  L1EtMissParticle::kMHT,
919  htTot,
922  Ref< L1GctHtMissCollection >( hwHtMissColl, iMiss ),
924  bx
925  ) ) ;
926  }
927  }
928  }
929  }
930 
931  // ~~~~~~~~~~~~~~~~~~~~ HF Rings ~~~~~~~~~~~~~~~~~~~~
932 
934  iEvent.getByLabel( hfRingEtSumsSource_, hwHFEtSumsColl ) ;
935 
936  Handle< L1GctHFBitCountsCollection > hwHFBitCountsColl ;
937  iEvent.getByLabel( hfRingBitCountsSource_, hwHFBitCountsColl ) ;
938 
939  ESHandle< L1CaloEtScale > hfRingEtScale ;
940  iSetup.get< L1HfRingEtScaleRcd >().get( hfRingEtScale ) ;
941 
942  if( !hwHFEtSumsColl.isValid() )
943  {
944  LogDebug("L1ExtraParticlesProd")
945  << "\nWarning: L1GctHFRingEtSumsCollection with " << hfRingEtSumsSource_
946  << "\nrequested in configuration, but not found in the event."
947  << std::endl;
948  }
949  else if( !hwHFBitCountsColl.isValid() )
950  {
951  LogDebug("L1ExtraParticlesProd")
952  << "\nWarning: L1GctHFBitCountsCollection with " << hfRingBitCountsSource_
953  << "\nrequested in configuration, but not found in the event."
954  << std::endl;
955  }
956  else
957  {
958  L1GctHFRingEtSumsCollection::const_iterator hwHFEtSumsItr =
959  hwHFEtSumsColl->begin() ;
960  L1GctHFRingEtSumsCollection::const_iterator hwHFEtSumsEnd =
961  hwHFEtSumsColl->end() ;
962 
963  int iEtSums = 0 ;
964  for( ; hwHFEtSumsItr != hwHFEtSumsEnd ; ++hwHFEtSumsItr, ++iEtSums )
965  {
966  int bx = hwHFEtSumsItr->bx() ;
967 
968  if( !centralBxOnly_ || bx == 0 )
969  {
970  L1GctHFBitCountsCollection::const_iterator hwHFBitCountsItr =
971  hwHFBitCountsColl->begin() ;
972  L1GctHFBitCountsCollection::const_iterator hwHFBitCountsEnd =
973  hwHFBitCountsColl->end() ;
974 
975  int iBitCounts = 0 ;
976  for( ; hwHFBitCountsItr != hwHFBitCountsEnd ;
977  ++hwHFBitCountsItr, ++iBitCounts )
978  {
979  if( hwHFBitCountsItr->bx() == bx )
980  {
981  break ;
982  }
983  }
984 
985  // If a L1GctHFBitCounts with the right bx is not found, itr == end.
986  if( hwHFBitCountsItr != hwHFBitCountsEnd )
987  {
988  // Construct L1HFRings only if both HW objects are present.
989 
990  // cout << "HF Rings " << endl
991 
992  // HF Et sums
993  double etSums[ L1HFRings::kNumRings ] ;
994  etSums[ L1HFRings::kRing1PosEta ] =
995  hfRingEtScale->et( hwHFEtSumsItr->etSum( 0 ) ) + 1.e-6 ;
996  etSums[ L1HFRings::kRing1NegEta ] =
997  hfRingEtScale->et( hwHFEtSumsItr->etSum( 1 ) ) + 1.e-6 ;
998  etSums[ L1HFRings::kRing2PosEta ] =
999  hfRingEtScale->et( hwHFEtSumsItr->etSum( 2 ) ) + 1.e-6 ;
1000  etSums[ L1HFRings::kRing2NegEta ] =
1001  hfRingEtScale->et( hwHFEtSumsItr->etSum( 3 ) ) + 1.e-6 ;
1002  // protect against roundoff.
1003 
1004 // cout << "HF Et Sums "
1005 // << hwHFEtSumsItr->etSum( 0 ) << " = "
1006 // << etSums[ L1HFRings::kRing1PosEta ] << " "
1007 // << hwHFEtSumsItr->etSum( 1 ) << " = "
1008 // << etSums[ L1HFRings::kRing1NegEta ] << " "
1009 // << hwHFEtSumsItr->etSum( 2 ) << " = "
1010 // << etSums[ L1HFRings::kRing2PosEta ] << " "
1011 // << hwHFEtSumsItr->etSum( 3 ) << " = "
1012 // << etSums[ L1HFRings::kRing2NegEta ]
1013 // << endl ;
1014 
1015  // HF bit counts
1016  int bitCounts[ L1HFRings::kNumRings ] ;
1017  bitCounts[ L1HFRings::kRing1PosEta ] =
1018  hwHFBitCountsItr->bitCount( 0 ) ;
1019  bitCounts[ L1HFRings::kRing1NegEta ] =
1020  hwHFBitCountsItr->bitCount( 1 ) ;
1021  bitCounts[ L1HFRings::kRing2PosEta ] =
1022  hwHFBitCountsItr->bitCount( 2 ) ;
1023  bitCounts[ L1HFRings::kRing2NegEta ] =
1024  hwHFBitCountsItr->bitCount( 3 ) ;
1025 
1026 // cout << "HF bit counts "
1027 // << hwHFBitCountsItr->bitCount( 0 ) << " "
1028 // << hwHFBitCountsItr->bitCount( 1 ) << " "
1029 // << hwHFBitCountsItr->bitCount( 2 ) << " "
1030 // << hwHFBitCountsItr->bitCount( 3 ) << " "
1031 // << endl ;
1032 
1033  hfRingsColl->push_back(
1034  L1HFRings( etSums,
1035  bitCounts,
1036  Ref< L1GctHFRingEtSumsCollection >( hwHFEtSumsColl,
1037  iEtSums ),
1038  Ref< L1GctHFBitCountsCollection >( hwHFBitCountsColl,
1039  iBitCounts ),
1040  bx
1041  ) ) ;
1042  }
1043  }
1044  }
1045  }
1046  }
1047 
1049  iEvent.put( isoEmColl, "Isolated" ) ;
1050 
1052  iEvent.put( nonIsoEmColl, "NonIsolated" ) ;
1053 
1055  iEvent.put( cenJetColl, "Central" ) ;
1056 
1058  iEvent.put( forJetColl, "Forward" ) ;
1059 
1061  iEvent.put( tauJetColl, "Tau" ) ;
1062 
1064  iEvent.put( etMissColl, "MET" ) ;
1065 
1067  iEvent.put( htMissColl, "MHT" ) ;
1068 
1069  OrphanHandle< L1HFRingsCollection > hfRingsCollHandle =
1070  iEvent.put( hfRingsColl ) ;
1071 }
1072 
1073 //math::XYZTLorentzVector
1076  const L1GctCand& cand,
1077  const L1CaloGeometry* geom,
1078  bool central )
1079 {
1080  // To keep x and y components non-zero.
1081  double etCorr = et + 1.e-6 ; // protect against roundoff, not only for et=0
1082 
1083  double eta = geom->etaBinCenter( cand.etaIndex(), central ) ;
1084 
1085 // double tanThOver2 = exp( -eta ) ;
1086 // double ez = etCorr * ( 1. - tanThOver2 * tanThOver2 ) / ( 2. * tanThOver2 );
1087 // double e = etCorr * ( 1. + tanThOver2 * tanThOver2 ) / ( 2. * tanThOver2 );
1088 
1089  double phi = geom->emJetPhiBinCenter( cand.phiIndex() ) ;
1090 
1091 // return math::XYZTLorentzVector( etCorr * cos( phi ),
1092 // etCorr * sin( phi ),
1093 // ez,
1094 // e ) ;
1095  return math::PtEtaPhiMLorentzVector( etCorr,
1096  eta,
1097  phi,
1098  0. ) ;
1099 }
1100 
1101 //define this as a plug-in
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
math::PtEtaPhiMLorentzVector gctLorentzVector(const double &et, const L1GctCand &cand, const L1CaloGeometry *geom, bool central)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T eta() const
double etaBinCenter(unsigned int etaIndex, bool central=true) const
static const double muonMassGeV_
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual unsigned etaIndex() const =0
get eta index (bit 3 is sign, 1 for -ve Z, 0 for +ve Z)
double p4[4]
Definition: TauolaWrapper.h:92
double htSumPhiBinCenter(unsigned int phiIndex) const
edm::InputTag hfRingEtSumsSource_
edm::InputTag hfRingBitCountsSource_
virtual void produce(edm::Event &, const edm::EventSetup &) override
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
virtual unsigned phiIndex() const =0
get phi index (0-17)
const T & get() const
Definition: EventSetup.h:55
string bx
Definition: rpc-layouts.py:13
ABC for GCT EM and jet candidates.
Definition: L1GctCand.h:12
double emJetPhiBinCenter(unsigned int phiIndex) const
std::vector< L1EtMissParticle > L1EtMissParticleCollection
L1ExtraParticlesProd(const edm::ParameterSet &)
double etSumPhiBinCenter(unsigned int phiIndex) const
Definition: DDAxes.h:10