Go to the documentation of this file.00001 #include <iostream>
00002 #include <sstream>
00003 #include <istream>
00004 #include <fstream>
00005 #include <iomanip>
00006 #include <string>
00007 #include <cmath>
00008 #include <functional>
00009 #include <stdlib.h>
00010 #include <string.h>
00011
00012 #include "HLTriggerOffline/Higgs/interface/HLTHiggsTruth.h"
00013
00014 HLTHiggsTruth::HLTHiggsTruth() {
00015
00016
00017 _Monte=false;
00018 _Debug=false;
00019 isvisible=false;
00020
00021
00022
00023
00024
00025
00026
00027 isPhotonDecay_acc=false;
00028 isTauDecay_acc =false;
00029 isMuonDecay_recoacc=false;
00030 isElecDecay_recoacc=false;
00031 isEMuDecay_recoacc=false;
00032 isPhotonDecay_recoacc=false;
00033 isTauDecay_recoacc =false;
00034 isvisible_reco= false;
00035
00036
00037
00038 }
00039
00040
00041 void HLTHiggsTruth::setup(const edm::ParameterSet& pSet, TTree* HltTree) {
00042
00043 edm::ParameterSet myMCParams = pSet.getParameter<edm::ParameterSet>("RunParameters") ;
00044 std::vector<std::string> parameterNames = myMCParams.getParameterNames() ;
00045
00046 for ( std::vector<std::string>::iterator iParam = parameterNames.begin();
00047 iParam != parameterNames.end(); iParam++ ){
00048 if ( (*iParam) == "Monte" ) _Monte = myMCParams.getParameter<bool>( *iParam );
00049 else if ( (*iParam) == "Debug" ) _Debug = myMCParams.getParameter<bool>( *iParam );
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 }
00073
00074
00075
00077
00078 void HLTHiggsTruth::analyzeHWW2l(const reco::CandidateView& mctruth,const reco::CaloMETCollection&
00079 caloMet, const reco::TrackCollection& Tracks, const reco::MuonCollection& muonHandle,
00080 const reco::GsfElectronCollection& electronHandle, TTree* HltTree) {
00081 if (_Monte) {
00082
00083
00084
00085
00086
00087
00092
00093 std::map<double, reco::Muon> muonMap;
00094 std::map<double,reco::GsfElectron> electronMap;
00095
00096
00097 for (size_t i = 0; i < muonHandle.size(); ++ i) {
00098 if ( (muonHandle)[i].isGlobalMuon() && (muonHandle)[i].pt()>10 &&
00099 fabs((muonHandle)[i].eta())<2.4 ){
00100
00101 muonMap[(muonHandle)[i].pt()]= (muonHandle)[i];
00102 }
00103 }
00104
00105
00106 for (size_t ii = 0; ii < electronHandle.size(); ++ ii) {
00107 if ( (electronHandle)[ii].pt()>10 && fabs((electronHandle)[ii].eta())<2.4 &&
00108 (electronHandle)[ii].hadronicOverEm()<0.05 &&
00109 (electronHandle)[ii].eSuperClusterOverP()>0.6 && (electronHandle)[ii].eSuperClusterOverP()<2.5 ){
00110 electronMap[(electronHandle)[ii].pt()]= (electronHandle)[ii];
00111 }
00112 }
00113
00115
00116 std::vector<reco::Muon> selected_muons;
00117 for( std::map<double,reco::Muon>::reverse_iterator rit=muonMap.rbegin(); rit!=muonMap.rend(); ++rit){
00118 selected_muons.push_back( (*rit).second );
00119 }
00120
00121
00122 std::vector<reco::GsfElectron> selected_electrons;
00123 for( std::map<double,reco::GsfElectron>::reverse_iterator rit=electronMap.rbegin(); rit!=electronMap.rend(); ++rit){
00124 selected_electrons.push_back( (*rit).second );
00125 }
00126
00127
00128
00130
00131 reco::Muon muon1, muon2;
00132 reco::GsfElectron electron1, electron2;
00133
00134 if (selected_electrons.size() ==1 ) electron1 = selected_electrons[0];
00135 if (selected_electrons.size() > 1){
00136 electron1 = selected_electrons[0];
00137 electron2 = selected_electrons[1];
00138 }
00139
00140 if (selected_muons.size() ==1 ) muon1 = selected_muons[0];
00141 if (selected_muons.size() > 1){
00142 muon1 = selected_muons[0];
00143 muon2 = selected_muons[1];
00144 }
00145
00146
00147
00148
00149
00150
00151
00152 double ptel1=0.;
00153 double ptel2=0.;
00154 double ptmu1=0.;
00155 double ptmu2=0.;
00156
00157 if (selected_electrons.size()==0) { ptel1 = 0; ptel2 = 0; }
00158 if (selected_electrons.size()==1) { ptel1 = electron1.pt(); ptel2 = 0; }
00159 if (selected_electrons.size()>1) { ptel1 = electron1.pt() ; ptel2 = electron2.pt();}
00160
00161 if (selected_muons.size()==0) { ptmu1 = 0; ptmu2 = 0; }
00162 if (selected_muons.size()==1) { ptmu1 = muon1.pt(); ptmu2 = 0; }
00163 if (selected_muons.size()>1) { ptmu1 = muon1.pt(); ptmu2 =muon2.pt();}
00164
00165
00166
00167 if (selected_muons.size() + selected_electrons.size() > 1){
00168
00169 if (ptel2 > ptmu1){
00170 if (electron1.charge()*electron2.charge()<0 && electron1.pt()>20 ) {
00171
00172 isElecDecay_recoacc=true;
00173 isMuonDecay_recoacc=false;
00174 isEMuDecay_recoacc=false;
00175
00176 Electron1 = selected_electrons[0];
00177 Electron2 = selected_electrons[1];
00178
00179 met_hwwdiel_ = caloMet[0].pt();
00180 }
00181 }
00182
00183 else if (ptmu2 > ptel1){
00184
00185 if (muon1.charge()*muon2.charge()<0 && muon1.pt()>20 ){
00186
00187 isElecDecay_recoacc=false;
00188 isMuonDecay_recoacc=true;
00189 isEMuDecay_recoacc=false;
00190
00191 Muon1 = selected_muons[0];
00192 Muon2 = selected_muons[1];
00193
00194 met_hwwdimu_ = caloMet[0].pt();
00195
00196 }
00197 }
00198
00199 else {
00200
00201
00202 if (muon1.charge()*electron1.charge()<0 && (muon1.pt()>20 || electron1.pt()>20)
00203 ) {
00204
00205 isElecDecay_recoacc=false;
00206 isMuonDecay_recoacc=false;
00207 isEMuDecay_recoacc=true;
00208
00209
00210 Muon1 = selected_muons[0];
00211 Electron1 = selected_electrons[0];
00212
00213 met_hwwemu_ = caloMet[0].pt();
00214 }
00215 }
00216
00217 }
00218 else{
00219
00220
00221 isElecDecay_recoacc=false;
00222 isMuonDecay_recoacc=false;
00223 isEMuDecay_recoacc=false;
00224
00225 }
00226
00227
00228
00229
00230
00231
00232 }
00233
00234 }
00235
00237
00238 void HLTHiggsTruth::analyzeHZZ4l(const reco::CandidateView& mctruth, const reco::MuonCollection& muonHandle,
00239 const reco::GsfElectronCollection& electronHandle, TTree* HltTree) {
00240 if (_Monte) {
00241
00242
00243
00244
00245
00246
00247
00248 std::map<double,reco::Muon> muonMap;
00249
00250
00251 for (size_t i = 0; i < muonHandle.size(); ++ i) {
00252 if ( (muonHandle)[i].isGlobalMuon() && (muonHandle)[i].pt()>10 &&
00253 fabs((muonHandle)[i].eta())<2.4 ){
00254 muonMap[(muonHandle)[i].pt()]= (muonHandle)[i];
00255 }
00256 }
00257
00258 std::map<double,reco::GsfElectron> electronMap;
00259 for (size_t ii = 0; ii < electronHandle.size(); ++ ii) {
00260 if ( (electronHandle)[ii].pt()>10 && fabs((electronHandle)[ii].eta())<2.4 &&
00261 (electronHandle)[ii].hadronicOverEm()<0.05 &&
00262 (electronHandle)[ii].eSuperClusterOverP()>0.6 && (electronHandle)[ii].eSuperClusterOverP()<2.5){
00263 electronMap[(electronHandle)[ii].pt()]= (electronHandle)[ii];
00264
00265 }
00266 }
00267
00269 std::vector<reco::Muon> selected_muons;
00270
00271 for( std::map<double,reco::Muon>::reverse_iterator rit=muonMap.rbegin(); rit!=muonMap.rend(); ++rit){
00272 selected_muons.push_back( (*rit).second );
00273 }
00274
00275
00276 std::vector<reco::GsfElectron> selected_electrons;
00277
00278 for( std::map<double,reco::GsfElectron>::reverse_iterator rit=electronMap.rbegin(); rit!=electronMap.rend(); ++rit){
00279 selected_electrons.push_back( (*rit).second );
00280 }
00281
00282
00284
00285 int posEle=0;
00286 int negEle=0;
00287 int posMu=0;
00288 int negMu=0;
00289
00290
00291 for (size_t k=0; k<selected_muons.size();k++){
00292 if (selected_muons[k].charge()>0) posMu++;
00293 else if (selected_muons[k].charge()<0) negMu++;
00294 }
00295
00296 for (size_t k=0; k<selected_electrons.size();k++){
00297 if (selected_electrons[k].charge()>0) posEle++;
00298 else if (selected_electrons[k].charge()<0) negEle++;
00299 }
00300
00301
00303
00304 int nElectron=0;
00305 int nMuon=0;
00306
00307 bool hzz2e2mu_decay = false;
00308 bool hzz4e_decay =false;
00309 bool hzz4mu_decay=false;
00310
00311
00312 if (selected_muons.size()>=4) hzz4mu_decay=true;
00313 else if (selected_electrons.size()>=4) hzz4e_decay=true;
00314 else if (selected_muons.size()>=2 && selected_electrons.size()>=2) hzz2e2mu_decay=true;
00315
00316
00317 if (hzz2e2mu_decay) {
00318 if ( posEle>=1 && negEle>=1 ) {
00319 nElectron=posEle+negEle;
00320 }
00321 if ( posMu>=1 && negMu>=1 ) {
00322 nMuon=posMu+negMu;
00323 }
00324 }
00325 else if (hzz4e_decay) {
00326 if ( posEle>=2 && negEle>=2 ) {
00327 nElectron=posEle+negEle;
00328 }
00329 }
00330 else if (hzz4mu_decay) {
00331 if ( posMu>=2 && negMu>=2 ) {
00332 nMuon=posMu+negMu;
00333 }
00334 }
00335
00337
00338 if (hzz2e2mu_decay && nElectron>=2 && nMuon>=2 ){
00339
00340 isEMuDecay_recoacc =true;
00341 Muon1 = selected_muons[0];
00342 Electron1 = selected_electrons[0];
00343
00344 }
00345 else if (hzz4e_decay && nElectron>=4){
00346 isElecDecay_recoacc=true;
00347 Electron1 = selected_electrons[0];
00348 Electron2 = selected_electrons[1];
00349
00350 }
00351 else if (hzz4mu_decay && nMuon>=4){
00352 isMuonDecay_recoacc =true;
00353 Muon1 = selected_muons[0];
00354 Muon2 = selected_muons[1];
00355
00356 }
00357 else {
00358
00359 isElecDecay_recoacc=false;
00360 isMuonDecay_recoacc=false;
00361 isEMuDecay_recoacc=false;
00362 }
00363
00364
00365
00366
00367
00368
00369 }
00370 }
00371
00372 void HLTHiggsTruth::analyzeHgg(const reco::CandidateView& mctruth, const reco::PhotonCollection& photonHandle, TTree* HltTree) {
00373 if (_Monte) {
00374
00375 std::map<double,reco::Photon> photonMap;
00376
00377
00378
00379
00380
00381
00382 for (size_t i = 0; i < photonHandle.size(); ++ i) {
00383 if ( (photonHandle)[i].pt()>20 && fabs((photonHandle)[i].eta())<2.4 ){
00384 photonMap[(photonHandle)[i].pt()]= (photonHandle)[i];
00385 }
00386 }
00387
00388
00389 std::vector<reco::Photon> selected_photons;
00390
00391 for( std::map<double,reco::Photon>::reverse_iterator rit=photonMap.rbegin(); rit!=photonMap.rend(); ++rit){
00392 selected_photons.push_back( (*rit).second );
00393 }
00394
00395
00396
00397
00398
00399 if (selected_photons.size()>1){
00400
00401 isPhotonDecay_acc=true;
00402 isvisible_reco= true;
00403
00404 Photon1 = selected_photons[0];
00405 Photon2 = selected_photons[1];
00406 }
00407 else{
00408 isPhotonDecay_acc=false;
00409 isvisible_reco=false;
00410 }
00411
00412
00413
00414
00415 }
00416 }
00417
00418 void HLTHiggsTruth::analyzeA2mu(const reco::CandidateView& mctruth,TTree* HltTree) {
00419 if (_Monte) {
00420 int nmuons=0;
00421 if (&mctruth){
00422 for (size_t i = 0; i < mctruth.size(); ++ i) {
00423 const reco::Candidate & p = (mctruth)[i];
00424 int status = p.status();
00425 if (status==1) {
00426 int pid=p.pdgId();
00427 bool ismuon = std::abs(pid)==13;
00428 bool inacceptance = (std::abs(p.eta()) < 2.4);
00429 bool aboveptcut = (p.pt() > 3.0);
00430 if (inacceptance && aboveptcut && ismuon) {
00431 if (nmuons==0) {
00432 nmuons=int(pid/std::abs(pid));
00433 } else if (pid<0 && nmuons==1) {
00434 nmuons=2;
00435 } else if (pid>0 && nmuons==-1) {
00436 nmuons=2;
00437 }
00438 }
00439 }
00440 }
00441
00442 isvisible = nmuons==2;
00443 }
00444 else {std::cout << "%HLTHiggsTruth -- No MC truth information" << std::endl;}
00445
00446 }
00447 }
00448
00449
00450 void HLTHiggsTruth::analyzeH2tau(const reco::CandidateView& mctruth,TTree* HltTree) {
00451 if (_Monte) {
00452
00453 int ngentau=0;
00454 int itauel=0;
00455 int itauelaccept=0;
00456 int itaumu=0;
00457 int itaumuaccept=0;
00458
00459
00460 std::vector<double> ptMuFromTau_,ptElFromTau_;
00461 std::vector<double> etaMuFromTau_,etaElFromTau_;
00462
00463
00464 if (&mctruth){
00465
00466
00467 for (size_t i = 0; i < mctruth.size(); ++ i) {
00468 const reco::Candidate & p = (mctruth)[i];
00469 int status = p.status();
00470 int pid=p.pdgId();
00471
00472
00473
00474 if (status==3 && fabs(pid)==15) {
00475 ngentau++;
00476 bool elecdec = false, muondec = false;
00477 LeptonicTauDecay(p, elecdec, muondec);
00478
00479 if (elecdec) {
00480 itauel++;
00481 if (PtElFromTau > 15 && fabs(EtaElFromTau)<2.4) {
00482 itauelaccept++;
00483 ptElFromTau_.push_back(PtElFromTau);
00484 etaElFromTau_.push_back(EtaElFromTau);
00485 }
00486 }
00487 if (muondec) {
00488 itaumu++;
00489 if (PtMuFromTau>15 && fabs(EtaMuFromTau)<2.4) {
00490 itaumuaccept++;
00491 ptMuFromTau_.push_back(PtMuFromTau);
00492 etaMuFromTau_.push_back(EtaMuFromTau);
00493 }
00494 }
00495 }
00496
00497 }
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00521
00522 int iTauQ = ngentau - itauel - itaumu;
00523 if (ngentau==2 && itaumu==1 && iTauQ==1 && itaumuaccept==1){
00524
00525 isMuonDecay_recoacc=true;
00526 ptMuMax = ptMuFromTau_[0];
00527
00528 etaMuMax = etaMuFromTau_[0];
00529
00530 }
00531 else {isMuonDecay_recoacc=false;}
00532
00534 if (ngentau==2 && itauel==1 && iTauQ==1 && itauelaccept==1){
00535
00536 isElecDecay_recoacc=true;
00537 ptElMax=ptElFromTau_[0];
00538
00539 etaElMax=etaElFromTau_[0];
00540
00541 }
00542 else { isElecDecay_recoacc=false;}
00543
00544 }
00545 else {std::cout << "%HLTHiggsTruth -- No MC truth information" << std::endl;}
00546
00547 }
00548 }
00549
00550 void HLTHiggsTruth::analyzeHtaunu(const reco::CandidateView& mctruth,TTree* HltTree) {
00551 if (_Monte) {
00552
00553 int ntaus=0;
00554
00555 std::map<double,reco::Particle> tauMap;
00556 if (&mctruth){
00557 for (size_t i = 0; i < mctruth.size(); ++ i) {
00558 const reco::Candidate & p = (mctruth)[i];
00559 int status = p.status();
00560 int pid=p.pdgId();
00561
00562
00563
00564 if (status==1 || status==2) {
00565
00566 bool istau = std::abs(pid)==15;
00567 bool inacceptance = (fabs(p.eta()) < 2.4);
00568 bool aboveptcut = (p.pt() > 100);
00569 if (inacceptance && aboveptcut && istau) {
00570
00571 ntaus++;
00572 }
00573 }
00574 }
00575
00577
00578
00579
00580 isvisible= (ntaus>0);
00581 isTauDecay_acc = isvisible;
00582
00583
00584 }
00585 else {std::cout << "%HLTHiggsTruth -- No MC truth information" << std::endl;}
00586
00587 }
00588 }
00589
00590 void HLTHiggsTruth::analyzeHinv(const reco::CandidateView& mctruth,TTree* HltTree) {
00591 if (_Monte) {
00592 if (&mctruth){
00593 isvisible = true;
00594 } else {
00595 std::cout << "%HLTHiggsTruth -- No MC truth information" << std::endl;
00596 }
00597
00598 }
00599 }
00600
00601 void HLTHiggsTruth::LeptonicTauDecay(const reco::Candidate& tau, bool& elecdec, bool& muondec)
00602
00603 {
00604
00605
00606
00607 for(reco::Candidate::const_iterator daughter=tau.begin();daughter!=tau.end(); ++daughter){
00608
00609
00610
00611 if(daughter->pdgId()==tau.pdgId()) return LeptonicTauDecay(*daughter, elecdec, muondec);
00612
00613 elecdec |= std::abs(daughter->pdgId())==11;
00614 muondec |= std::abs(daughter->pdgId())==13;
00615
00616 if (std::abs(daughter->pdgId())==11) {
00617 PtElFromTau = daughter->pt();
00618 EtaElFromTau = daughter->eta();
00619 }
00620
00621 if (std::abs(daughter->pdgId())==13){
00622 PtMuFromTau = daughter->pt();
00623 EtaMuFromTau = daughter->eta();
00624 }
00625 }
00626
00627 }
00628
00629
00630
00631
00632
00633
00634