00001
00002
00003
00004
00005 #include "PhysicsTools/PatAlgos/plugins/PATMHTProducer.h"
00006
00007 pat::PATMHTProducer::PATMHTProducer(const edm::ParameterSet & iConfig){
00008
00009
00010 verbose_ = iConfig.getParameter<double>("verbose");
00011
00012 jetLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("jetTag");
00013 eleLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("electronTag");
00014 muoLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("muonTag");
00015 tauLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("tauTag");
00016 phoLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("photonTag");
00017
00018 uncertaintyScaleFactor_ = iConfig.getParameter<double>( "uncertaintyScaleFactor") ;
00019 controlledUncertainty_ = iConfig.getParameter<bool>( "controlledUncertainty") ;
00020
00021 jetPtMin_ = iConfig.getParameter<double>("jetPtMin");
00022 jetEtaMax_ = iConfig.getParameter<double>("jetEtaMax");
00023 jetEMfracMax_ = iConfig.getParameter<double>("jetEMfracMax");
00024 elePtMin_ = iConfig.getParameter<double>("elePtMin");
00025 eleEtaMax_ = iConfig.getParameter<double>("eleEtaMax");
00026 muonPtMin_ = iConfig.getParameter<double>("muonPtMin");
00027 muonEtaMax_ = iConfig.getParameter<double>("muonEtaMax");
00028
00029 jetEtUncertaintyParameter0_ = iConfig.getParameter<double>( "jetEtUncertaintyParameter0") ;
00030 jetEtUncertaintyParameter1_ = iConfig.getParameter<double>( "jetEtUncertaintyParameter1") ;
00031 jetEtUncertaintyParameter2_ = iConfig.getParameter<double>( "jetEtUncertaintyParameter2") ;
00032 jetPhiUncertaintyParameter0_= iConfig.getParameter<double>( "jetPhiUncertaintyParameter0");
00033 jetPhiUncertaintyParameter1_= iConfig.getParameter<double>( "jetPhiUncertaintyParameter1");
00034 jetPhiUncertaintyParameter2_= iConfig.getParameter<double>( "jetPhiUncertaintyParameter2");
00035
00036 eleEtUncertaintyParameter0_ = iConfig.getParameter<double>( "eleEtUncertaintyParameter0") ;
00037 elePhiUncertaintyParameter0_ = iConfig.getParameter<double>( "elePhiUncertaintyParameter0") ;
00038
00039 muonEtUncertaintyParameter0_ = iConfig.getParameter<double>( "muonEtUncertaintyParameter0") ;
00040 muonPhiUncertaintyParameter0_ = iConfig.getParameter<double>( "muonPhiUncertaintyParameter0") ;
00041
00042 CaloTowerTag_ = iConfig.getParameter<edm::InputTag>("CaloTowerTag");
00043 noHF_ = iConfig.getParameter<bool>( "noHF");
00044
00045
00046 towerEtThreshold_ = iConfig.getParameter<double>( "towerEtThreshold") ;
00047 useHO_ = iConfig.getParameter<bool>("useHO");
00048
00049 produces<pat::MHTCollection>();
00050
00051 }
00052
00053
00054 pat::PATMHTProducer::~PATMHTProducer() {
00055 }
00056
00057 void pat::PATMHTProducer::beginJob() {
00058 setUncertaintyParameters();
00059 }
00060 void pat::PATMHTProducer::beginRun(const edm::EventSetup& iSetup) {
00061 }
00062
00063 void pat::PATMHTProducer::endJob() {
00064 }
00065
00066
00067 void
00068 pat::PATMHTProducer::produce(edm::Event & iEvent, const edm::EventSetup & iSetup)
00069 {
00070
00071 while(physobjvector_.size()>0){
00072 physobjvector_.erase(physobjvector_.begin(),physobjvector_.end());
00073 }
00074
00075
00076 s_clusteredTowers.clear();
00077
00078 double number_of_jets = getJets(iEvent, iSetup);
00079
00080 double number_of_electrons = getElectrons(iEvent, iSetup);
00081
00082 double number_of_muons = getMuons(iEvent, iSetup);
00083
00084 if (verbose_ == 1.) {
00085 std::cout << ">>>---> Number of jets: " << number_of_jets << std::endl;
00086 std::cout << ">>>---> Number of electrons: " << number_of_jets << std::endl;
00087 std::cout << ">>>---> Number of muons: " << number_of_muons << std::endl;
00088 }
00089
00090 double met_x=0;
00091 double met_y=0;
00092 double met_et=0;
00093 double met_phi=0;
00094 double met_set=0;
00095
00096
00097 std::auto_ptr<pat::MHTCollection> themetsigcoll (new pat::MHTCollection);
00098
00099 if(physobjvector_.size() >= 1) {
00100
00101
00102
00103 metsig::significanceAlgo signifAlgo;
00104 signifAlgo.addObjects(physobjvector_);
00105 double significance = signifAlgo.significance(met_et,met_phi,met_set);
00106
00107 met_x=met_et*cos(met_phi);
00108 met_y=met_et*sin(met_phi);
00109
00110 if (verbose_ == 1.) {
00111 std::cout << ">>>----> MHT Sgificance = " << significance << std::endl;
00112 }
00113
00114 pat::MHT themetsigobj(reco::Particle::LorentzVector(met_x,met_y,0,met_et),met_set,significance);
00115
00116
00117
00118 themetsigobj.setNumberOfJets(number_of_jets);
00119 themetsigobj.setNumberOfElectrons(number_of_electrons);
00120 themetsigobj.setNumberOfMuons(number_of_muons);
00121
00122 themetsigcoll->push_back(themetsigobj);
00123
00124 }
00125
00126
00127 iEvent.put( themetsigcoll);
00128
00129
00130 }
00131
00132
00133
00134
00135 double
00136 pat::PATMHTProducer::getJets(edm::Event& iEvent, const edm::EventSetup & iSetup){
00137
00138 std::string objectname="jet";
00139
00140 double number_of_jets_ = 0.0;
00141
00142 edm::Handle<edm::View<pat::Jet> > jetHandle;
00143 iEvent.getByLabel(jetLabel_,jetHandle);
00144 edm::View<pat::Jet> jets = *jetHandle;
00145
00146
00147 for(edm::View<pat::Jet>::const_iterator jet_iter = jets.begin(); jet_iter!=jets.end(); ++jet_iter){
00148
00149 if( (jet_iter->pt() < jetPtMin_) ||
00150 (TMath::Abs(jet_iter->eta()) > jetEtaMax_) ||
00151 (jet_iter->emEnergyFraction() > jetEMfracMax_ ) )
00152 continue;
00153
00154 double jet_et = jet_iter->et();
00155 double jet_phi = jet_iter->phi();
00156
00157 if (verbose_ == 3.) {
00158 std::cout << "jet pt : " << jet_iter->pt() << " eta : " << jet_iter->eta()
00159 << " EMF: " << jet_iter->emEnergyFraction() << std::endl;
00160 }
00161
00162 double sigma_et, sigma_phi ;
00163
00164 if (controlledUncertainty_) {
00165 sigma_et = jetUncertainty.etUncertainty->Eval(jet_et);
00166 sigma_phi = jetUncertainty.phiUncertainty->Eval(jet_et);
00167 }
00168 else {
00169 sigma_et = 0.0 ;
00170 sigma_phi = 0.0 ;
00171 }
00172
00173 if (verbose_ == 3.) {
00174 std::cout << "jet sigma_et : " << sigma_et << ", jet sigma_phi : " << sigma_phi << std::endl;
00175 }
00176
00177 if(sigma_et<=0 || sigma_phi<=0)
00178 edm::LogWarning("PATMHTProducer") <<
00179 " uncertainties for " << objectname <<
00180 " are (et, phi): " << sigma_et << "," << sigma_phi << " (et,phi): " << jet_et << "," << jet_phi;
00181
00182
00183
00184 if (uncertaintyScaleFactor_ != 1.0){
00185 sigma_et = sigma_et * uncertaintyScaleFactor_;
00186 sigma_phi = sigma_phi * uncertaintyScaleFactor_;
00187
00188
00189 }
00190
00191
00192 if (verbose_ == 101.) {
00193
00194 std::cout << "v101> " << number_of_jets_ << " "
00195 << jet_et << " " << sigma_et << " "
00196 << jet_phi << " " << sigma_phi << std::endl;
00197 }
00198
00199
00200 metsig::SigInputObj tmp_jet(objectname,jet_et,jet_phi,sigma_et,sigma_phi);
00201 physobjvector_.push_back(tmp_jet);
00202 number_of_jets_ ++;
00203
00204
00205 std::vector<CaloTowerPtr> v_towers = jet_iter->getCaloConstituents();
00206
00207
00208 for (unsigned int ii=0; ii < v_towers.size(); ii++) {
00209 s_clusteredTowers.insert( (*v_towers.at(ii)).id() );
00210
00211 }
00212
00213 }
00214
00215 if (verbose_ == 101.) {
00216 std::cout << "v101> --------------------------------------------" << std::endl;
00217 }
00218
00219 return number_of_jets_;
00220
00221 }
00222
00223
00224
00225
00226
00227 double
00228 pat::PATMHTProducer::getElectrons(edm::Event& iEvent, const edm::EventSetup & iSetup){
00229
00230 std::string objectname="electron";
00231
00232 double number_of_electrons_ = 0.0;
00233
00234
00235
00236
00237
00238 edm::Handle<edm::View<pat::Electron> > electronHandle;
00239 iEvent.getByLabel(eleLabel_,electronHandle);
00240 edm::View<pat::Electron> electrons = *electronHandle;
00241 DetId nullDetId;
00242
00243
00244 for(edm::View<pat::Electron>::const_iterator electron_iter = electrons.begin(); electron_iter!=electrons.end(); ++electron_iter){
00245
00246
00247 if (electron_iter->et() < elePtMin_ ||
00248 TMath::Abs(electron_iter->eta()) > eleEtaMax_ ) continue;
00249
00250 if (verbose_ == 3.) {
00251 std::cout << "electron pt = " << electron_iter->pt() << " eta : " << electron_iter->eta()
00252 << std::endl;
00253 }
00254
00255 double electron_et = electron_iter->et();
00256 double electron_phi = electron_iter->phi();
00257
00258 double sigma_et, sigma_phi ;
00259
00260 if (controlledUncertainty_) {
00261 sigma_et = eleUncertainty.etUncertainty->Eval(electron_et);
00262 sigma_phi = eleUncertainty.phiUncertainty->Eval(electron_et);
00263 }
00264 else {
00265 sigma_et = 0.0;
00266 sigma_phi = 0.0;
00267 }
00268
00269 if (verbose_ == 3.) {
00270 std::cout << "electron sigma_et : " << sigma_et << ", electron sigma_phi : " << sigma_phi
00271 << std::endl;}
00272
00273 if(sigma_et< 0 || sigma_phi< 0)
00274 edm::LogWarning("PATMHTProducer") << " uncertainties for " << objectname
00275 <<" are (et, phi): " << sigma_et
00276 << "," << sigma_phi << " (et,phi): "
00277 << electron_et << "," << electron_phi;
00278
00279 if (uncertaintyScaleFactor_ != 1.0){
00280 sigma_et = sigma_et * uncertaintyScaleFactor_;
00281 sigma_phi = sigma_phi * uncertaintyScaleFactor_;
00282 }
00283
00284 metsig::SigInputObj tmp_electron(objectname,electron_et,electron_phi,sigma_et,sigma_phi);
00285 physobjvector_.push_back(tmp_electron);
00286 number_of_electrons_ ++;
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310 }
00311
00312 return number_of_electrons_;
00313 }
00314
00315
00316
00317
00318
00319
00320
00321 double pat::PATMHTProducer::getMuons(edm::Event& iEvent, const edm::EventSetup & iSetup){
00322
00323 std::string objectname="muon";
00324 edm::Handle<edm::View<pat::Muon> > muonHandle;
00325 iEvent.getByLabel(muoLabel_,muonHandle);
00326 edm::View<pat::Muon> muons = *muonHandle;
00327
00328 if ( !muonHandle.isValid() ) {
00329 std::cout << ">>> PATMHTSelector not valid muon Handle!" << std::endl;
00330 return 0.0;
00331 }
00332
00333
00334 double number_of_muons_ = 0.0;
00335
00336 for(edm::View<pat::Muon>::const_iterator muon_iter = muons.begin(); muon_iter!=muons.end(); ++muon_iter){
00337
00338 if (muon_iter->pt() < muonPtMin_ || TMath::Abs(muon_iter->eta()) > muonEtaMax_ ) continue;
00339
00340 if (verbose_ == 3.) {
00341 std::cout << "muon pt = " << muon_iter->pt() << " eta : " << muon_iter->eta() << std::endl;
00342 }
00343
00344 double muon_pt = muon_iter->pt();
00345 double muon_phi = muon_iter->phi();
00346
00347 double sigma_et, sigma_phi ;
00348
00349 if (controlledUncertainty_) {
00350 sigma_et = muonUncertainty.etUncertainty->Eval(muon_pt);
00351 sigma_phi = muonUncertainty.phiUncertainty->Eval(muon_pt);
00352 }
00353 else {
00354 sigma_et = 0.0;
00355 sigma_phi = 0.0;
00356 }
00357
00358 if (verbose_ == 3.) {
00359 std::cout << "muon sigma_et : " << sigma_et
00360 << ", muon sigma_phi : " << sigma_phi
00361 << std::endl;}
00362
00363 if(sigma_et< 0 || sigma_phi< 0)
00364 edm::LogWarning("PATMHTProducer") <<
00365 " uncertainties for " << objectname << " are (et, phi): " << sigma_et << "," <<
00366 sigma_phi << " (pt,phi): " << muon_pt << "," << muon_phi;
00367
00368 if (uncertaintyScaleFactor_ != 1.0){
00369 sigma_et = sigma_et * uncertaintyScaleFactor_;
00370 sigma_phi = sigma_phi * uncertaintyScaleFactor_;
00371 }
00372
00373 metsig::SigInputObj tmp_muon(objectname,muon_pt,muon_phi,sigma_et,sigma_phi);
00374 physobjvector_.push_back(tmp_muon);
00375 number_of_muons_ ++;
00376
00377 }
00378
00379 return number_of_muons_;
00380 }
00381
00382
00383
00384 void pat::PATMHTProducer::setUncertaintyParameters(){
00385
00386
00387
00388
00389
00390
00391
00392 ecalEBUncertainty.etUncertainty = new TF1("ecalEBEtFunc","x*sqrt(([0]*[0]/(x*x))+([1]*[1]/x)+([2]*[2]))",3);
00393 ecalEBUncertainty.etUncertainty->SetParameter(0,0.2);
00394 ecalEBUncertainty.etUncertainty->SetParameter(1,0.03);
00395 ecalEBUncertainty.etUncertainty->SetParameter(2,0.005);
00396
00397 ecalEBUncertainty.phiUncertainty = new TF1("ecalEBphiFunc","[0]*x",1);
00398 ecalEBUncertainty.phiUncertainty->SetParameter(0,0.0174);
00399
00400
00401 ecalEEUncertainty.etUncertainty = new TF1("ecalEEEtFunc","x*sqrt(([0]*[0]/(x*x))+([1]*[1]/x)+([2]*[2]))",3);
00402 ecalEEUncertainty.etUncertainty->SetParameter(0,0.2);
00403 ecalEEUncertainty.etUncertainty->SetParameter(1,0.03);
00404 ecalEEUncertainty.etUncertainty->SetParameter(2,0.005);
00405
00406 ecalEEUncertainty.phiUncertainty = new TF1("ecalEEphiFunc","[0]*x",1);
00407 ecalEEUncertainty.phiUncertainty->SetParameter(0,0.087);
00408
00409
00410
00411
00412 hcalHBUncertainty.etUncertainty = new TF1("hcalHBEtFunc","x*sqrt(([0]*[0]/(x*x))+([1]*[1]/x)+([2]*[2]))",3);
00413 hcalHBUncertainty.etUncertainty->SetParameter(0,0.);
00414 hcalHBUncertainty.etUncertainty->SetParameter(1,1.22);
00415 hcalHBUncertainty.etUncertainty->SetParameter(2,0.05);
00416
00417 hcalHBUncertainty.phiUncertainty = new TF1("ecalHBphiFunc","[0]*x",1);
00418 hcalHBUncertainty.phiUncertainty->SetParameter(0,0.087);
00419
00420
00421 hcalHEUncertainty.etUncertainty = new TF1("hcalHEEtFunc","x*sqrt(([0]*[0]/(x*x))+([1]*[1]/x)+([2]*[2]))",3);
00422 hcalHEUncertainty.etUncertainty->SetParameter(0,0.);
00423 hcalHEUncertainty.etUncertainty->SetParameter(1,1.3);
00424 hcalHEUncertainty.etUncertainty->SetParameter(2,0.05);
00425
00426 hcalHEUncertainty.phiUncertainty = new TF1("ecalHEphiFunc","[0]*x",1);
00427 hcalHEUncertainty.phiUncertainty->SetParameter(0,0.087);
00428
00429
00430 hcalHOUncertainty.etUncertainty = new TF1("hcalHOEtFunc","x*sqrt(([0]*[0]/(x*x))+([1]*[1]/x)+([2]*[2]))",3);
00431 hcalHOUncertainty.etUncertainty->SetParameter(0,0.);
00432 hcalHOUncertainty.etUncertainty->SetParameter(1,1.82);
00433 hcalHOUncertainty.etUncertainty->SetParameter(2,0.09);
00434
00435 hcalHOUncertainty.phiUncertainty = new TF1("ecalHOphiFunc","[0]*x",1);
00436 hcalHOUncertainty.phiUncertainty->SetParameter(0,0.087);
00437
00438
00439 hcalHFUncertainty.etUncertainty = new TF1("hcalHFEtFunc","x*sqrt(([0]*[0]/(x*x))+([1]*[1]/x)+([2]*[2]))",3);
00440 hcalHFUncertainty.etUncertainty->SetParameter(0,0.);
00441 hcalHFUncertainty.etUncertainty->SetParameter(1,1.82);
00442 hcalHFUncertainty.etUncertainty->SetParameter(2,0.09);
00443
00444 hcalHFUncertainty.phiUncertainty = new TF1("ecalHFphiFunc","[0]*x",1);
00445 hcalHFUncertainty.phiUncertainty->SetParameter(0,0.174);
00446
00447
00448 jetUncertainty.etUncertainty = new TF1("jetEtFunc","x*sqrt(([0]*[0]/(x*x))+([1]*[1]/x)+([2]*[2]))",3);
00449
00450 jetUncertainty.etUncertainty->SetParameter(0, jetEtUncertaintyParameter0_);
00451 jetUncertainty.etUncertainty->SetParameter(1, jetEtUncertaintyParameter1_);
00452 jetUncertainty.etUncertainty->SetParameter(2, jetEtUncertaintyParameter2_);
00453
00454
00455
00456
00457
00458
00459
00460
00461 jetUncertainty.phiUncertainty = new TF1("jetPhiFunc","x*sqrt(([0]*[0]/(x*x))+([1]*[1]/x)+([2]*[2]))",3);
00462 jetUncertainty.phiUncertainty->SetParameter(0, jetPhiUncertaintyParameter0_);
00463 jetUncertainty.phiUncertainty->SetParameter(1, jetPhiUncertaintyParameter1_);
00464 jetUncertainty.phiUncertainty->SetParameter(2, jetPhiUncertaintyParameter2_);
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 eleUncertainty.etUncertainty = new TF1("eleEtFunc","[0] * x",1);
00482
00483 eleUncertainty.etUncertainty->SetParameter(0, eleEtUncertaintyParameter0_);
00484
00485
00486 eleUncertainty.phiUncertainty = new TF1("elePhiFunc","[0] * x",1);
00487
00488 eleUncertainty.phiUncertainty->SetParameter(0, elePhiUncertaintyParameter0_);
00489
00490
00491
00492
00493 muonUncertainty.etUncertainty = new TF1("muonEtFunc","[0] * x",1);
00494
00495 muonUncertainty.etUncertainty->SetParameter(0, muonEtUncertaintyParameter0_);
00496 muonUncertainty.phiUncertainty = new TF1("muonPhiFunc","[0] * x",1);
00497
00498 muonUncertainty.phiUncertainty->SetParameter(0, muonPhiUncertaintyParameter0_);
00499
00500
00501
00502
00503
00504
00505
00506 }
00507
00508
00509 using namespace pat;
00510 DEFINE_FWK_MODULE(PATMHTProducer);
00511