21 doAreaFastjet_ = iConfig.
getParameter<
bool>(
"doAreaFastjet");
22 doRhoFastjet_ = iConfig.
getParameter<
bool>(
"doRhoFastjet");
27 ghostEtaMax = iConfig.
getParameter<
double>(
"Ghost_EtaMax");
28 activeAreaRepeats = iConfig.
getParameter<
int>(
"Active_Area_Repeats");
31 if ( doAreaFastjet_ || doRhoFastjet_ ) {
35 fjRangeDef_ =
RangeDefPtr(
new fastjet::RangeDefinition(ghostEtaMax) );
36 if ( ( ghostEtaMax < 0 ) || ( activeAreaRepeats < 0 ) || ( ghostArea < 0 ) )
37 throw cms::Exception(
"doAreaFastjet or doRhoFastjet") <<
"Parameters ghostEtaMax, activeAreaRepeats or ghostArea for doAreaFastjet/doRhoFastjet are not defined." << std::endl;
43 std::vector<fastjet::PseudoJet>& towers,
44 std::vector<fastjet::PseudoJet>&
output){
49 fjOriginalInputs_ = (*fjInputs_);
50 for (
unsigned int i = 0;
i < fjInputs_->size(); ++
i){
51 fjOriginalInputs_[
i].set_user_index((*fjInputs_)[
i].user_index());
57 fjJetDefinition_ =
JetDefPtr(
new fastjet::JetDefinition( *jetDef ) );
63 LogDebug(
"PileUpSubtractor")<<
"The subtractor setting up geometry...\n";
74 for(std::vector<DetId>::const_iterator did=alldid.begin(); did != alldid.end(); did++){
77 if( (hid).
depth() == 1 ) {
78 allgeomid_.push_back(*did);
80 if((hid).ieta() != ietaold){
81 ietaold = (hid).ieta();
82 geomtowers_[(hid).ieta()] = 1;
83 if((hid).ieta() > ietamax_) ietamax_ = (hid).ieta();
84 if((hid).ieta() < ietamin_) ietamin_ = (hid).ieta();
87 geomtowers_[(hid).ieta()]++;
94 for (
int i = ietamin_;
i<ietamax_+1;
i++) {
95 ntowersWithJets_[
i] = 0;
104 LogDebug(
"PileUpSubtractor")<<
"The subtractor calculating pedestals...\n";
105 map<int,double> emean2;
106 map<int,int> ntowers;
108 int ietaold = -10000;
113 for(
int i = ietamin_;
i < ietamax_+1;
i++)
121 for (vector<fastjet::PseudoJet>::const_iterator input_object = coll.begin (),
122 fjInputsEnd = coll.end();
123 input_object != fjInputsEnd; ++input_object) {
125 ieta0 = ieta( originalTower );
126 double Original_Et = originalTower->et();
127 if( ieta0-ietaold != 0 )
129 emean_[ieta0] = emean_[ieta0]+Original_Et;
130 emean2[ieta0] = emean2[ieta0]+Original_Et*Original_Et;
136 emean_[ieta0] = emean_[ieta0]+Original_Et;
137 emean2[ieta0] = emean2[ieta0]+Original_Et*Original_Et;
142 for(map<int,int>::const_iterator gt = geomtowers_.begin(); gt != geomtowers_.end(); gt++)
144 int it = (*gt).first;
146 double e1 = (*(emean_.find(it))).second;
147 double e2 = (*emean2.find(it)).
second;
148 int nt = (*gt).second - (*(ntowersWithJets_.find(it))).second;
150 LogDebug(
"PileUpSubtractor")<<
" ieta : "<<it<<
" number of towers : "<<nt<<
" e1 : "<<e1<<
" e2 : "<<e2<<
"\n";
153 double eee = e2/nt - e1*e1/(nt*
nt);
155 esigma_[it] = nSigmaPU_*
sqrt(eee);
162 LogDebug(
"PileUpSubtractor")<<
" ieta : "<<it<<
" Pedestals : "<<emean_[it]<<
" "<<esigma_[it]<<
"\n";
173 LogDebug(
"PileUpSubtractor")<<
"The subtractor subtracting pedestals...\n";
176 for (vector<fastjet::PseudoJet>::iterator input_object = coll.begin (),
177 fjInputsEnd = coll.end();
178 input_object != fjInputsEnd; ++input_object) {
184 double etnew = itow->et() - (*(emean_.find(it))).second - (*(esigma_.find(it))).second;
185 float mScale = etnew/input_object->Et();
186 if(etnew < 0.) mScale = 0.;
189 input_object->pz()*mScale, input_object->e()*mScale);
191 int index = input_object->user_index();
192 input_object->reset_momentum ( towP4.px(),
196 input_object->set_user_index(index);
203 LogDebug(
"PileUpSubtractor")<<
"The subtractor calculating orphan input...\n";
205 (*fjInputs_) = fjOriginalInputs_;
207 vector<int> jettowers;
208 vector<pair<int,int> > excludedTowers;
210 vector <fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin (),
211 fjJetsEnd = fjJets_->end();
212 for (; pseudojetTMP != fjJetsEnd ; ++pseudojetTMP) {
213 if(pseudojetTMP->perp() < puPtMin_)
continue;
216 for(vector<HcalDetId>::const_iterator im = allgeomid_.begin(); im != allgeomid_.end(); im++)
219 vector<pair<int,int> >::const_iterator exclude =
find(excludedTowers.begin(),excludedTowers.end(),pair<int,int>(im->ieta(),im->iphi()));
220 if( dr < radiusPU_ && exclude == excludedTowers.end()) {
221 ntowersWithJets_[(*im).ieta()]++;
222 excludedTowers.push_back(pair<int,int>(im->ieta(),im->iphi()));
225 vector<fastjet::PseudoJet>::const_iterator it = fjInputs_->begin(),
226 fjInputsEnd = fjInputs_->end();
228 for (; it != fjInputsEnd; ++it ) {
229 int index = it->user_index();
230 int ie = ieta((*inputs_)[index]);
231 int ip = iphi((*inputs_)[index]);
232 vector<pair<int,int> >::const_iterator exclude =
find(excludedTowers.begin(),excludedTowers.end(),pair<int,int>(ie,ip));
233 if(exclude != excludedTowers.end()) {
234 jettowers.push_back(index);
242 for(vector<fastjet::PseudoJet>::const_iterator it = fjInputs_->begin(),
243 fjInputsEnd = fjInputs_->end(); it != fjInputsEnd; ++it ) {
244 int index = it->user_index();
245 vector<int>::const_iterator itjet =
find(jettowers.begin(),jettowers.end(),
index);
246 if( itjet == jettowers.end() ){
248 fastjet::PseudoJet orphan(originalTower->px(),originalTower->py(),originalTower->pz(),originalTower->energy());
249 orphan.set_user_index(index);
251 orphanInput.push_back(orphan);
259 LogDebug(
"PileUpSubtractor")<<
"The subtractor correcting jets...\n";
261 using namespace reco;
266 jetOffset_.reserve(fjJets_->size());
267 vector<fastjet::PseudoJet>::iterator pseudojetTMP = fjJets_->begin (),
268 jetsEnd = fjJets_->end();
269 for (; pseudojetTMP != jetsEnd; ++pseudojetTMP) {
270 int ijet = pseudojetTMP - fjJets_->begin();
271 jetOffset_[ijet] = 0;
273 std::vector<fastjet::PseudoJet> towers =
274 fastjet::sorted_by_pt( pseudojetTMP->constituents() );
275 double newjetet = 0.;
276 for(vector<fastjet::PseudoJet>::const_iterator ito = towers.begin(),
277 towEnd = towers.end();
282 int it = ieta( originalTower );
283 double Original_Et = originalTower->et();
284 double etnew = Original_Et - (*emean_.find(it)).
second - (*esigma_.find(it)).
second;
285 if(etnew < 0.) etnew = 0;
286 newjetet = newjetet + etnew;
287 jetOffset_[ijet] += Original_Et - etnew;
289 double mScale = newjetet/pseudojetTMP->Et();
290 LogDebug(
"PileUpSubtractor")<<
"pseudojetTMP->Et() : "<<pseudojetTMP->Et()<<
'\n';
291 LogDebug(
"PileUpSubtractor")<<
"newjetet : "<<newjetet<<
'\n';
292 LogDebug(
"PileUpSubtractor")<<
"jetOffset_[ijet] : "<<jetOffset_[ijet]<<
'\n';
293 LogDebug(
"PileUpSubtractor")<<
"pseudojetTMP->Et() - jetOffset_[ijet] : "<<pseudojetTMP->Et() - jetOffset_[ijet]<<
'\n';
294 LogDebug(
"PileUpSubtractor")<<
"Scale is : "<<mScale<<
'\n';
295 int cshist = pseudojetTMP->cluster_hist_index();
296 pseudojetTMP->reset_momentum(pseudojetTMP->px()*mScale, pseudojetTMP->py()*mScale,
297 pseudojetTMP->pz()*mScale, pseudojetTMP->e()*mScale);
298 pseudojetTMP->set_cluster_hist_index(cshist);
306 for(vector<HcalDetId>::const_iterator im = allgeomid_.begin(); im != allgeomid_.end(); im++){
307 if( im->depth() != 1 )
continue;
311 pu += (*emean_.find(im->ieta())).second+(*esigma_.find(im->ieta())).second;
320 return (*emean_.find(it)).
second;
325 return (*esigma_.find(it)).
second;
330 return (*emean_.find(it)).
second + (*esigma_.find(it)).
second;
336 int n = (*(geomtowers_.find(it))).second - (*(ntowersWithJets_.find(it))).second;
343 int n = (*(ntowersWithJets_.find(it))).second;
356 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
368 throw cms::Exception(
"Invalid Constituent") <<
"CaloJet constituent is not of CaloTower type";
std::shared_ptr< fastjet::JetDefinition > JetDefPtr
T getParameter(std::string const &) const
virtual void calculateOrphanInput(std::vector< fastjet::PseudoJet > &orphanInput)
virtual double getMeanAtTower(const reco::CandidatePtr &in) const
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
int getNwithJets(const reco::CandidatePtr &in) const
T const * get() const
Returns C++ pointer to the item.
Geom::Phi< T > phi() const
virtual double getPileUpAtTower(const reco::CandidatePtr &in) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
static std::string const input
int ieta(const reco::CandidatePtr &in) const
U second(std::pair< T, U > const &p)
virtual void offsetCorrectJets()
int iphi() const
get the tower iphi
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
boost::shared_ptr< fastjet::GhostedAreaSpec > ActiveAreaSpecPtr
virtual void subtractPedestal(std::vector< fastjet::PseudoJet > &coll)
#define EDM_REGISTER_PLUGINFACTORY(_factory_, _category_)
int iphi(const reco::CandidatePtr &in) const
CaloTowerDetId id() const
virtual double getSigmaAtTower(const reco::CandidatePtr &in) const
boost::shared_ptr< fastjet::RangeDefinition > RangeDefPtr
virtual void setDefinition(JetDefPtr const &jetDef)
et
define resolution functions of each parameter
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
PileUpSubtractor(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
virtual void calculatePedestal(std::vector< fastjet::PseudoJet > const &coll)
virtual void setupGeometryMap(edm::Event &iEvent, const edm::EventSetup &iSetup)
int ieta() const
get the tower ieta
virtual double getCone(double cone, double eta, double phi, double &et, double &pu)
virtual void reset(std::vector< edm::Ptr< reco::Candidate > > &input, std::vector< fastjet::PseudoJet > &towers, std::vector< fastjet::PseudoJet > &output)
T const * product() const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
int getN(const reco::CandidatePtr &in) const
boost::shared_ptr< fastjet::JetDefinition > JetDefPtr