CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
VoronoiSubtractor.cc
Go to the documentation of this file.
3 
6 using namespace std;
7 
8 bool VoronoiSubtractor::match(const fastjet::PseudoJet cand1, const fastjet::PseudoJet cand2){
9  return (cand1.delta_R(cand2) < rParam_);
10 }
11 
12 
14  PileUpSubtractor(iConfig),
15  srcCand_(iConfig.getParameter<edm::InputTag>("src")),
16  srcVor_(iConfig.getParameter<edm::InputTag>("bkg")),
17  dropZeroTowers_(iConfig.getParameter<bool>("dropZeros")),
18  addNegativesFromCone_(iConfig.getParameter<bool>("addNegativesFromCone")),
19  infinitesimalPt_(iConfig.getParameter<double>("infinitesimalPt")),
20  rParam_(iConfig.getParameter<double>("rParam"))
21 {
22 
23 }
24 
25 
26 
28 {
29 
30  LogDebug("VoronoiSubtractor")<<"The subtractor retrieving Voronoi background...\n";
31  geo_ = 0;
32  droppedCandidates_.clear();
33  jetOffset_.clear();
34 
37 
38 }
39 
41 {
42 
43  LogDebug("VoronoiSubtractor")<<"finalizing the output...\n";
44 
45  jetOffset_.reserve(fjJets_->size());
46 
47  for (unsigned int ijet = 0;ijet <fjJets_->size();++ijet) {
48  fastjet::PseudoJet& fjJet = (*fjJets_)[ijet];
49 
50  LogDebug("VoronoiSubtractor")<<"fjJets_ "<<ijet<<" pt : "<<fjJet.pt()
51  <<" --- eta : "<<fjJet.eta()<<" --- phi : "<<fjJet.phi()<<endl;
52 
53  fastjet::PseudoJet subtracted;
54  fastjet::PseudoJet unsubtracted;
55  fastjet::PseudoJet unsubtractedDropped;
56  jetOffset_[ijet] = 0;
57 
58  // Loop over constituents to determine the momentum
59  // before and after subtraction
60 
61  std::vector<fastjet::PseudoJet> fjConstituents = fastjet::sorted_by_pt(fjJet.constituents());
62  for (unsigned int i=0;i<fjConstituents.size();++i) {
63  unsigned int index = fjConstituents[i].user_index();
64 
66  const reco::VoronoiBackground& voronoi = (*backgrounds_)[ref];
67 
68  fastjet::PseudoJet candidate(ref->px(),ref->py(),ref->pz(),ref->energy());
69  double orpt = candidate.perp();
70  unsubtracted += candidate;
71  if(voronoi.pt() > 0){
72  candidate.reset_PtYPhiM(voronoi.pt(),ref->rapidity(),ref->phi(),ref->mass());
73  LogDebug("VoronoiSubtractor")<<"candidate "<<index
74  <<" --- original pt : "<<orpt
75  <<" --- voronoi pt : "<<voronoi.pt()
76  <<" --- ref pt : "<<ref->pt()
77  <<" --- constituent "<<index
78  <<" --- pt : "<<fjConstituents[i].perp()
79  <<" --- eta : "<<fjConstituents[i].pseudorapidity()
80  <<" --- phi : "<<fjConstituents[i].phi()
81  <<" --- mass : "<<fjConstituents[i].m()<<endl;
82  subtracted += candidate;
83  }
84  }
85 
86  // Loop over dropped candidates to see whether there is any of them
87  // that would belong to this jet:
89  for(unsigned int i=0; i < droppedCandidates_.size(); ++i){
91  fastjet::PseudoJet dropcand(ref->px(),ref->py(),ref->pz(),ref->energy());
92 
93  if(match(fjJet,dropcand)){
94  unsubtractedDropped += dropcand;
95  unsubtracted += dropcand;
96  }
97  }
98  }
99 
100  fjJet.reset_momentum(subtracted);
101 
102  LogDebug("VoronoiSubtractor")<<"fjJets_ "<<ijet<<" unsubtracted : "<<unsubtracted.pt()<<endl;
103  LogDebug("VoronoiSubtractor")<<"fjJets_ "<<ijet<<" subtracted : "<<subtracted.pt()<<endl;
104  LogDebug("VoronoiSubtractor")<<"fjJets_ "<<ijet<<" dropped : "<<unsubtractedDropped.pt()<<endl;
105  jetOffset_[ijet] = unsubtracted.pt() - fjJet.pt();
106 
107  }
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 }
119 
120 void VoronoiSubtractor::subtractPedestal(vector<fastjet::PseudoJet> & coll)
121 {
122 
123  LogDebug("VoronoiSubtractor")<<"The subtractor subtracting pedestals...\n";
124  vector<fastjet::PseudoJet> newcoll;
125 
126  for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin (),
127  fjInputsEnd = coll.end();
128  input_object != fjInputsEnd; ++input_object) {
129 
130  reco::CandidateViewRef ref(candidates_,input_object->user_index());
131  const reco::VoronoiBackground& voronoi = (*backgrounds_)[ref];
132 
133  double ptold = input_object->pt();
134  double ptnew = voronoi.pt();
135 
136  LogDebug("VoronoiSubtractor")<<"pt old : "<<ptold<<" ; pt new : "<<ptnew
137  <<" E : "<<input_object->e()
138  <<" rap : "<<input_object->rapidity()
139  <<" phi : "<<input_object->phi()
140  <<" MASS : "<<input_object->m()<<endl;
141 
142  // Treatment of candidates with negative pt after subtraction
143  if(ptnew < infinitesimalPt_){
144  if(infinitesimalPt_ > 0){
145  // Low-pt candidate is assigned a very small finite pt
146  // so that the jet clustering includes the candidate
147  // and can associate it to the jet.
148  // The original candidate pt is restored
149  // in the offsetCorrectJets() function.
150  ptnew = infinitesimalPt_;
151  }else{
152  // Low-pt candidate is removed from the input collection,
153  // so that the jet clustering algorithm can function properly.
154  // However, we need to keep track of these candidates
155  // in order to determine how much energy has been subtracted in total.
156  droppedCandidates_.push_back(input_object->user_index());
157  continue;
158  }
159  }
160 
161  int index = input_object->user_index();
162 
163  fastjet::PseudoJet ps(input_object->four_mom());
164  ps.reset_PtYPhiM(ptnew,input_object->rapidity(),input_object->phi(),input_object->m());
165  ps.set_user_index(index);
166 
167  LogDebug("VoronoiSubtractor")<<"New momentum : "<<ps.pt()
168  <<" rap : "<<ps.rap()
169  <<" phi : "<<ps.phi()
170  <<" MASS : "<<ps.m()<<endl;
171 
172  newcoll.push_back(ps);
173  }
174  coll = newcoll;
175 }
176 
177 void VoronoiSubtractor::calculatePedestal( vector<fastjet::PseudoJet> const & coll )
178 {
179  LogDebug("VoronoiSubtractor")<<"do nothing...\n";
180 }
181 
182 
183 void VoronoiSubtractor::calculateOrphanInput(vector<fastjet::PseudoJet> & orphanInput)
184 {
185  LogDebug("VoronoiSubtractor")<<"do nothing...\n";
186 }
187 
188 /*
189 void VoronoiSubtractor::reset(std::vector<edm::Ptr<reco::Candidate> >& input,
190  std::vector<fastjet::PseudoJet>& towers,
191  std::vector<fastjet::PseudoJet>& output){
192 
193 
194 }
195 
196 */
197 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
std::vector< double > jetOffset_
virtual void subtractPedestal(std::vector< fastjet::PseudoJet > &coll)
VoronoiSubtractor(const edm::ParameterSet &iConfig)
virtual void offsetCorrectJets()
std::vector< fastjet::PseudoJet > * fjJets_
edm::Handle< reco::VoronoiMap > backgrounds_
virtual void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput)
std::vector< int > droppedCandidates_
virtual void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll)
bool match(fastjet::PseudoJet, fastjet::PseudoJet)
edm::InputTag srcVor_
int iEvent
Definition: GenABIO.cc:243
virtual void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::InputTag srcCand_
JetCorrectorParametersCollection coll
Definition: classes.h:14
CaloGeometry const * geo_
edm::Handle< reco::CandidateView > candidates_