test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackMixerBase.cc
Go to the documentation of this file.
2 
4  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
5 {
6  edm::VParameterSet todoList = cfg.getParameter<edm::VParameterSet>("todo");
7  if ( todoList.size() == 0 ) {
8  throw cms::Exception("Configuration")
9  << "Empty to-do list !!\n";
10  }
11 
12  for ( edm::VParameterSet::const_iterator todoItem = todoList.begin();
13  todoItem != todoList.end(); ++todoItem ) {
14  todoListEntryType todoListEntry;
15  todoListEntry.srcTrackCollection1_ = todoItem->getParameter<edm::InputTag>("collection1");
16  todoListEntry.srcTrackCollection2_ = todoItem->getParameter<edm::InputTag>("collection2");
17 
18  std::string instanceLabel1 = todoListEntry.srcTrackCollection1_.instance();
19  std::string instanceLabel2 = todoListEntry.srcTrackCollection2_.instance();
20  if ( instanceLabel1 != instanceLabel2 ) {
21  throw cms::Exception("Configuration")
22  << "Mismatch in Instance labels for collection 1 = " << instanceLabel1 << " and 2 = " << instanceLabel2 << " !!\n";
23  }
24 
25  todoList_.push_back(todoListEntry);
26 
27  produces<reco::TrackCollection>(instanceLabel1);
28  }
29 
30  verbosity_ = ( cfg.exists("verbosity") ) ?
31  cfg.getParameter<int>("verbosity") : 0;
32 }
33 
35 {
36  produceTracks(evt, es);
37  produceTrackExtras(evt, es);
38 }
39 
41 {
42  if ( verbosity_ ) std::cout << "<TrackMixerBase::produce (" << moduleLabel_ << ")>:" << std::endl;
43 
44  for ( typename std::vector<todoListEntryType>::const_iterator todoItem = todoList_.begin();
45  todoItem != todoList_.end(); ++todoItem ) {
46  todoItem->trackRefMap_.clear();
47 
48  edm::Handle<reco::TrackCollection> trackCollection1;
49  evt.getByLabel(todoItem->srcTrackCollection1_, trackCollection1);
50 
51  edm::Handle<reco::TrackCollection> trackCollection2;
52  evt.getByLabel(todoItem->srcTrackCollection2_, trackCollection2);
53 
54  if ( verbosity_ ) {
55  std::cout << "trackCollection(input1 = " << todoItem->srcTrackCollection1_.label() << ":" << todoItem->srcTrackCollection1_.instance() << ":" << todoItem->srcTrackCollection1_.process() << "):"
56  << " #entries = " << trackCollection1->size() << std::endl;
57  std::cout << "trackCollection(input2 = " << todoItem->srcTrackCollection2_.label() << ":" << todoItem->srcTrackCollection2_.instance() << ":" << todoItem->srcTrackCollection2_.process() << "):"
58  << " #entries = " << trackCollection2->size() << std::endl;
59  }
60 
61  std::auto_ptr<reco::TrackCollection> trackCollection_output(new reco::TrackCollection());
62 
63  reco::TrackRefProd trackCollectionRefProd_output = evt.getRefBeforePut<reco::TrackCollection>(todoItem->srcTrackCollection1_.instance());
64  size_t idxTrack_output = 0;
65 
66  size_t numTracks1 = trackCollection1->size();
67  for ( size_t idxTrack1 = 0; idxTrack1 < numTracks1; ++idxTrack1 ) {
68  reco::TrackRef track1(trackCollection1, idxTrack1);
69  trackCollection_output->push_back(*track1);
70  todoItem->trackRefMap_[reco::TrackRef(trackCollectionRefProd_output, idxTrack_output)] = track1;
71  ++idxTrack_output;
72  }
73 
74  size_t numTracks2 = trackCollection2->size();
75  for ( size_t idxTrack2 = 0; idxTrack2 < numTracks2; ++idxTrack2 ) {
76  reco::TrackRef track2(trackCollection2, idxTrack2);
77  trackCollection_output->push_back(*track2);
78  todoItem->trackRefMap_[reco::TrackRef(trackCollectionRefProd_output, idxTrack_output)] = track2;
79  ++idxTrack_output;
80  }
81 
82  if ( verbosity_ ) {
83  std::cout << "trackCollection(output = " << moduleLabel_ << ":" << todoItem->srcTrackCollection1_.instance() << "): #entries = " << trackCollection_output->size() << std::endl;
84  int idx = 0;
85  for ( reco::TrackCollection::const_iterator track = trackCollection_output->begin();
86  track != trackCollection_output->end(); ++track ) {
87  if ( track->pt() > 5. ) {
88  std::cout << "track #" << idx << ": Pt = " << track->pt() << ", eta = " << track->eta() << ", phi = " << track->phi() << std::endl;
89  ++idx;
90  }
91  }
92  }
93 
94  evt.put(trackCollection_output, todoItem->srcTrackCollection1_.instance());
95  }
96 }
T getParameter(std::string const &) const
std::vector< todoListEntryType > todoList_
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual void produce(edm::Event &, const edm::EventSetup &)
TrackMixerBase(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void produceTracks(edm::Event &, const edm::EventSetup &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
RefProd< PROD > getRefBeforePut()
Definition: Event.h:128
virtual void produceTrackExtras(edm::Event &, const edm::EventSetup &)=0
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
tuple cout
Definition: gather_cfg.py:121
std::string moduleLabel_
moduleLabel_(iConfig.getParameter< string >("@module_label"))
std::string const & instance() const
Definition: InputTag.h:43