CMS 3D CMS Logo

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 
14 #include <string>
15 
16 
17 using namespace edm;
18 using namespace std;
19 using namespace reco;
20 
22  conf_(iConfig)
23 {
24  LogInfo("ElectronSeedMerger")<<"Electron SeedMerger started ";
25 
26  ecalSeedToken_ = consumes<ElectronSeedCollection>(iConfig.getParameter<InputTag>("EcalBasedSeeds"));
27  edm::InputTag tkSeedLabel_ = iConfig.getParameter<InputTag>("TkBasedSeeds");
28  if (!tkSeedLabel_.label().empty())
29  tkSeedToken_ = consumes<ElectronSeedCollection>(tkSeedLabel_);
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 output = std::make_unique<ElectronSeedCollection>();
55 
56  //HANDLE THE INPUT SEED COLLECTIONS
58  iEvent.getByToken(ecalSeedToken_,EcalBasedSeeds);
59  ElectronSeedCollection ESeed = *(EcalBasedSeeds.product());
60 
64  iEvent.getByToken(tkSeedToken_,TkBasedSeeds);
65  TSeed = *(TkBasedSeeds.product());
66  }
67 
68 
69  //VECTOR FOR MATCHED SEEDS
70  vector<bool> TSeedMatched;
71  for (unsigned int it=0;it<TSeed.size();it++){
72  TSeedMatched.push_back(false);
73  }
74 
75 
76  //LOOP OVER THE ECAL SEED COLLECTION
77  ElectronSeedCollection::const_iterator e_beg= ESeed.begin();
78  ElectronSeedCollection::const_iterator e_end= ESeed.end();
79  for (;e_beg!=e_end;++e_beg){
80 
81  ElectronSeed NewSeed=*(e_beg);
82  bool AlreadyMatched =false;
83 
84  //LOOP OVER THE TK SEED COLLECTION
85  for (unsigned int it=0;it<TSeed.size();it++){
86  if (AlreadyMatched) continue;
87 
88  //HITS FOR ECAL SEED
89  TrajectorySeed::const_iterator eh = e_beg->recHits().first;
90  TrajectorySeed::const_iterator eh_end = e_beg->recHits().second;
91 
92  //HITS FOR TK SEED
93  unsigned int hitShared=0;
94  unsigned int hitSeed=0;
95  for (;eh!=eh_end;++eh){
96 
97  if (!eh->isValid()) continue;
98  hitSeed++;
99  bool Shared=false;
100  TrajectorySeed::const_iterator th = TSeed[it].recHits().first;
101  TrajectorySeed::const_iterator th_end = TSeed[it].recHits().second;
102  for (;th!=th_end;++th){
103  if (!th->isValid()) continue;
104  //CHECK THE HIT COMPATIBILITY: put back sharesInput
105  // as soon Egamma solves the bug on the seed collection
106  if (eh->sharesInput(&(*th),TrackingRecHit::all)) Shared = true;
107  // if(eh->geographicalId() == th->geographicalId() &&
108 // (eh->localPosition() - th->localPosition()).mag() < 0.001) Shared=true;
109  }
110  if (Shared) hitShared++;
111  }
112  if (hitShared==hitSeed){
113  AlreadyMatched=true;
114  TSeedMatched[it]=true;
115  NewSeed.setCtfTrack(TSeed[it].ctfTrack());
116  }
117  if ( hitShared == (hitSeed-1)){
118  NewSeed.setCtfTrack(TSeed[it].ctfTrack());
119  }
120  }
121 
122  output->push_back(NewSeed);
123  }
124 
125  //FILL THE COLLECTION WITH UNMATCHED TK-BASED SEED
126  for (unsigned int it=0;it<TSeed.size();it++){
127  if (!TSeedMatched[it]) output->push_back(TSeed[it]);
128  }
129 
130  //PUT THE MERGED COLLECTION IN THE EVENT
131  iEvent.put(std::move(output));
132 
133 }
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
ElectronSeedMerger(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
void setCtfTrack(const CtfTrackRef &)
Set additional info.
Definition: ElectronSeed.cc:35
void produce(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
recHitContainer::const_iterator const_iterator
edm::EDGetTokenT< reco::ElectronSeedCollection > ecalSeedToken_
SEED COLLECTIONS.
std::vector< ElectronSeed > ElectronSeedCollection
collection of ElectronSeed objects
T const * product() const
Definition: Handle.h:81
range recHits() const
std::string const & label() const
Definition: InputTag.h:36
fixed size matrix
HLT enums.
edm::EDGetTokenT< reco::ElectronSeedCollection > tkSeedToken_
bool isUninitialized() const
Definition: EDGetToken.h:73
def move(src, dest)
Definition: eostools.py:510
~ElectronSeedMerger() override