CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronSeedTrackRefUpdaterAndMerger.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: ElectronSeedTrackRefUpdaterAndMerger
4 // Class: ElectronSeedTrackRefUpdaterAndMerger
5 //
13 //
14 // Original Author: Tomasz Maciej Frueboes
15 // Created: Fri Apr 9 12:15:56 CEST 2010
16 // $Id: ElectronSeedTrackRefUpdaterAndMerger.cc,v 1.1 2012/03/01 17:03:28 fruboes Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
27 
30 
34 
39 
41 //
42 // class decleration
43 //
44 using namespace reco;
45 
46 
48  public:
51 
52  private:
53  virtual void beginJob() ;
54  virtual void produce(edm::Event&, const edm::EventSetup&);
55  virtual void endJob() ;
60 
62 
65  // ----------member data ---------------------------
66 };
67 
68 //
69 // constants, enums and typedefs
70 //
71 
72 
73 //
74 // static data member definitions
75 //
76 
77 //
78 // constructors and destructor
79 //
81  _inSeeds1(iConfig.getParameter< edm::InputTag > ("inSeeds1")),
82  _inPreId1(iConfig.getParameter< edm::InputTag > ("inPreId1")),
83  _inSeeds2(iConfig.getParameter< edm::InputTag > ("inSeeds2")),
84  _inPreId2(iConfig.getParameter< edm::InputTag > ("inPreId2")),
85  _targetTracks(iConfig.getParameter< edm::InputTag > ("targetTracks"))
86 {
87  preidgsf_ = iConfig.getParameter<std::string>("PreGsfLabel");
88  preidname_= iConfig.getParameter<std::string>("PreIdLabel");
89 
90  produces<ElectronSeedCollection>(preidgsf_);
91  produces<PreIdCollection>(preidname_);
92  //produces<edm::ValueMap<reco::PreIdRef> >(preidname_);
93 
94 }
95 
96 
98 {
99 
100  // do anything here that needs to be done at desctruction time
101  // (e.g. close files, deallocate resources etc.)
102 
103 }
104 
105 
106 //
107 // member functions
108 //
109 
110 // ------------ method called to produce the data ------------
111 void
113 {
114  using namespace edm;
115  using namespace std;
116  using namespace reco;
117 
118  auto_ptr<ElectronSeedCollection> output_preid(new ElectronSeedCollection);
119  auto_ptr<PreIdCollection> output_preidinfo(new PreIdCollection);
120 
122  iEvent.getByLabel( _targetTracks, hTargetTracks);
123 
125  iEvent.getByLabel( _inSeeds1, hSeeds1 );
127  iEvent.getByLabel( _inSeeds2, hSeeds2 );
128 
129  std::vector< edm::Handle< ElectronSeedCollection > > colsSeed;
130  colsSeed.push_back(hSeeds1);
131  colsSeed.push_back(hSeeds2);
132 
133 
135  iEvent.getByLabel( _inPreId1, hPreId1);
137  iEvent.getByLabel( _inPreId2, hPreId2);
138 
139  std::vector< edm::Handle< PreIdCollection > > colsPreId;
140  colsPreId.push_back(hPreId1);
141  colsPreId.push_back(hPreId2);
142 
143 
144  for ( std::vector< edm::Handle< PreIdCollection > >::iterator itCols=colsPreId.begin();
145  itCols!=colsPreId.end();
146  ++itCols )
147  {
148  for (PreIdCollection::const_iterator it = (*itCols)->begin(); it!=(*itCols)->end(); ++ it){
149  PreId newPreId(*it);
150  TrackRef currentTrRef = it->trackRef();
151  if ( currentTrRef.isNull() || !currentTrRef.isAvailable() ) {
152  std::cout << "XXXX whoops! Org track ref empty!!" << std::endl;
153  // keep things as they are;
154  output_preidinfo->push_back(newPreId);
155  continue;
156  }
157  size_t newIndex = -1;
158  bool found = false;
159  for (size_t i=0; i<hTargetTracks->size();++i){
160 
161  if ( deltaR( currentTrRef->momentum(), hTargetTracks->at(i).momentum()) < 0.001){
162  newIndex = i;
163  found = true;
164  break;
165  }
166  }
167  if (found) {
168  TrackRef trackRef(hTargetTracks, newIndex);
169  newPreId.setTrack(trackRef);
170  } else {
171  std::cout << "XXXX whoops! Cannot set track ref!!" << std::endl;
172  }
173  output_preidinfo->push_back(newPreId);
174  }
175  }
176 
177 
178  for ( std::vector< edm::Handle< ElectronSeedCollection > >::iterator itCols=colsSeed.begin();
179  itCols!=colsSeed.end();
180  ++itCols )
181  {
182  for (ElectronSeedCollection::const_iterator it = (*itCols)->begin(); it!=(*itCols)->end(); ++ it){
183  ElectronSeed newSeed(*it);
184  TrackRef currentTrRef = it->ctfTrack ();
185  if ( currentTrRef.isNull() || !currentTrRef.isAvailable() ) {
186  std::cout << "XXXX whoops! Org track ref empty!!" << std::endl;
187  // keep things as they are;
188  output_preid->push_back(newSeed);
189  continue;
190  }
191  size_t newIndex = -1;
192  bool found = false;
193  for (size_t i=0; i<hTargetTracks->size();++i){
194 
195  if ( deltaR( currentTrRef->momentum(), hTargetTracks->at(i).momentum()) < 0.001){
196  newIndex = i;
197  found = true;
198  break;
199  }
200  }
201  if (found) {
202  TrackRef trackRef(hTargetTracks, newIndex);
203  newSeed.setCtfTrack(trackRef);
204  } else {
205  std::cout << "XXXX whoops! Cannot set track ref!!" << std::endl;
206  }
207  output_preid->push_back(newSeed);
208  }
209  }
210 
211 
212  iEvent.put(output_preid,preidgsf_);
213  iEvent.put(output_preidinfo,preidname_);
214 
215  //iEvent.put(newCol);
216 
217 }
218 
219 // ------------ method called once each job just before starting event loop ------------
220 void
222 {
223 }
224 
225 // ------------ method called once each job just after ending the event loop ------------
226 void
228 }
229 
230 //define this as a plug-in
bool isAvailable() const
Definition: Ref.h:576
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< reco::PreId > PreIdCollection
Definition: PreIdFwd.h:6
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void beginJob()
Definition: Breakpoints.cc:15
void setCtfTrack(const CtfTrackRef &)
Set additional info.
Definition: ElectronSeed.cc:64
void setTrack(reco::TrackRef trackref)
Definition: PreId.h:34
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:413
bool isNull() const
Checks for null.
Definition: Ref.h:249
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
virtual void produce(edm::Event &, const edm::EventSetup &)
tuple cout
Definition: gather_cfg.py:121