CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronSeedMerger.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PFTracking
4 // Class: ElectronSeedMerger
5 //
6 // Original Author: Michele Pioppi
7 
15 #include <string>
16 
17 
18 using namespace edm;
19 using namespace std;
20 using namespace reco;
21 
23  conf_(iConfig)
24 {
25  LogInfo("ElectronSeedMerger")<<"Electron SeedMerger started ";
26 
27 
28  ecalBasedSeeds_=iConfig.getParameter<InputTag>("EcalBasedSeeds");
29  tkBasedSeeds_=iConfig.getParameter<InputTag>("TkBasedSeeds");
30 
31  produces<ElectronSeedCollection>();
32 
33 }
34 
35 
37 {
38 
39  // do anything here that needs to be done at desctruction time
40  // (e.g. close files, deallocate resources etc.)
41 
42 }
43 
44 
45 //
46 // member functions
47 //
48 
49 // ------------ method called to produce the data ------------
50 void
52 {
53  //CREATE OUTPUT COLLECTION
54  auto_ptr<ElectronSeedCollection> output(new ElectronSeedCollection);
55 
56  //HANDLE THE INPUT SEED COLLECTIONS
57  Handle<ElectronSeedCollection> EcalBasedSeeds;
58  iEvent.getByLabel(ecalBasedSeeds_,EcalBasedSeeds);
59  ElectronSeedCollection ESeed = *(EcalBasedSeeds.product());
60 
61  Handle<ElectronSeedCollection> TkBasedSeeds;
62  iEvent.getByLabel(tkBasedSeeds_,TkBasedSeeds);
63  ElectronSeedCollection TSeed = *(TkBasedSeeds.product());
64 
65 
66  //VECTOR FOR MATCHED SEEDS
67  vector<bool> TSeedMatched;
68  for (unsigned int it=0;it<TSeed.size();it++){
69  TSeedMatched.push_back(false);
70  }
71 
72 
73  //LOOP OVER THE ECAL SEED COLLECTION
74  ElectronSeedCollection::const_iterator e_beg= ESeed.begin();
75  ElectronSeedCollection::const_iterator e_end= ESeed.end();
76  for (;e_beg!=e_end;++e_beg){
77 
78  ElectronSeed NewSeed=*(e_beg);
79  bool AlreadyMatched =false;
80 
81  //LOOP OVER THE TK SEED COLLECTION
82  for (unsigned int it=0;it<TSeed.size();it++){
83  if (AlreadyMatched) continue;
84 
85  //HITS FOR ECAL SEED
86  TrajectorySeed::const_iterator eh = e_beg->recHits().first;
87  TrajectorySeed::const_iterator eh_end = e_beg->recHits().second;
88 
89  //HITS FOR TK SEED
90  unsigned int hitShared=0;
91  unsigned int hitSeed=0;
92  for (;eh!=eh_end;++eh){
93 
94  if (!eh->isValid()) continue;
95  hitSeed++;
96  bool Shared=false;
97  TrajectorySeed::const_iterator th = TSeed[it].recHits().first;
98  TrajectorySeed::const_iterator th_end = TSeed[it].recHits().second;
99  for (;th!=th_end;++th){
100  if (!th->isValid()) continue;
101  //CHECK THE HIT COMPATIBILITY: put back sharesInput
102  // as soon Egamma solves the bug on the seed collection
103  if (eh->sharesInput(&(*th),TrackingRecHit::all)) Shared = true;
104  // if(eh->geographicalId() == th->geographicalId() &&
105 // (eh->localPosition() - th->localPosition()).mag() < 0.001) Shared=true;
106  }
107  if (Shared) hitShared++;
108  }
109  if (hitShared==hitSeed){
110  AlreadyMatched=true;
111  TSeedMatched[it]=true;
112  NewSeed.setCtfTrack(TSeed[it].ctfTrack());
113  }
114  if ( hitShared == (hitSeed-1)){
115  NewSeed.setCtfTrack(TSeed[it].ctfTrack());
116  }
117  }
118 
119  output->push_back(NewSeed);
120  }
121 
122  //FILL THE COLLECTION WITH UNMATCHED TK-BASED SEED
123  for (unsigned int it=0;it<TSeed.size();it++){
124  if (!TSeedMatched[it]) output->push_back(TSeed[it]);
125  }
126 
127  //PUT THE MERGED COLLECTION IN THE EVENT
128  iEvent.put(output);
129 
130 }
T getParameter(std::string const &) const
edm::InputTag tkBasedSeeds_
virtual void produce(edm::Event &, const edm::EventSetup &)
ElectronSeedMerger(const edm::ParameterSet &)
edm::InputTag ecalBasedSeeds_
SEED COLLECTIONS.
void setCtfTrack(const CtfTrackRef &)
Set additional info.
Definition: ElectronSeed.cc:64
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
recHitContainer::const_iterator const_iterator
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
range recHits() const
T const * product() const
Definition: Handle.h:81