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 "HLTrigger/HLTanalyzers/interface/HLTMCtruth.h"
00013 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00014
00015 HLTMCtruth::HLTMCtruth() {
00016
00017
00018 _Monte=false;
00019 _Debug=false;
00020 }
00021
00022
00023 void HLTMCtruth::setup(const edm::ParameterSet& pSet, TTree* HltTree) {
00024
00025 edm::ParameterSet myMCParams = pSet.getParameter<edm::ParameterSet>("RunParameters") ;
00026 vector<std::string> parameterNames = myMCParams.getParameterNames() ;
00027
00028 for ( vector<std::string>::iterator iParam = parameterNames.begin();
00029 iParam != parameterNames.end(); iParam++ ){
00030 if ( (*iParam) == "Monte" ) _Monte = myMCParams.getParameter<bool>( *iParam );
00031 else if ( (*iParam) == "Debug" ) _Debug = myMCParams.getParameter<bool>( *iParam );
00032 }
00033
00034 const int kMaxMcTruth = 10000;
00035 mcpid = new int[kMaxMcTruth];
00036 mcvx = new float[kMaxMcTruth];
00037 mcvy = new float[kMaxMcTruth];
00038 mcvz = new float[kMaxMcTruth];
00039 mcpt = new float[kMaxMcTruth];
00040 mceta = new float[kMaxMcTruth];
00041 mcphi = new float[kMaxMcTruth];
00042
00043
00044 HltTree->Branch("NMCpart",&nmcpart,"NMCpart/I");
00045 HltTree->Branch("MCpid",mcpid,"MCpid[NMCpart]/I");
00046 HltTree->Branch("MCvtxX",mcvx,"MCvtxX[NMCpart]/F");
00047 HltTree->Branch("MCvtxY",mcvy,"MCvtxY[NMCpart]/F");
00048 HltTree->Branch("MCvtxZ",mcvz,"MCvtxZ[NMCpart]/F");
00049 HltTree->Branch("MCpt",mcpt,"MCpt[NMCpart]/F");
00050 HltTree->Branch("MCeta",mceta,"MCeta[NMCpart]/F");
00051 HltTree->Branch("MCphi",mcphi,"MCphi[NMCpart]/F");
00052 HltTree->Branch("MCPtHat",&pthatf,"MCPtHat/F");
00053 HltTree->Branch("MCmu3",&nmu3,"MCmu3/I");
00054 HltTree->Branch("MCel3",&nel3,"MCel3/I");
00055 HltTree->Branch("MCbb",&nbb,"MCbb/I");
00056 HltTree->Branch("MCab",&nab,"MCab/I");
00057 HltTree->Branch("MCWenu",&nwenu,"MCWenu/I");
00058 HltTree->Branch("MCWmunu",&nwmunu,"MCmunu/I");
00059 HltTree->Branch("MCZee",&nzee,"MCZee/I");
00060 HltTree->Branch("MCZmumu",&nzmumu,"MCZmumu/I");
00061 HltTree->Branch("MCptEleMax",&ptEleMax,"MCptEleMax/F");
00062 HltTree->Branch("MCptMuMax",&ptMuMax,"MCptMuMax/F");
00063
00064 }
00065
00066
00067 void HLTMCtruth::analyze(const edm::Handle<CandidateView> & mctruth,
00068 const edm::Handle<double> & pthat,
00069 TTree* HltTree) {
00070
00071
00072
00073 if (_Monte) {
00074 int nmc = 0;
00075 int mu3 = 0;
00076 int el3 = 0;
00077 int mab = 0;
00078 int mbb = 0;
00079 int wel = 0;
00080 int wmu = 0;
00081 int zee = 0;
00082 int zmumu = 0;
00083
00084 ptEleMax = -999.0;
00085 ptMuMax = -999.0;
00086 pthatf = pthat.isValid() ? * pthat : 0.0;
00087
00088 if (mctruth.isValid()){
00089
00090 for (size_t i = 0; i < mctruth->size(); ++ i) {
00091 const Candidate & p = (*mctruth)[i];
00092
00093 mcpid[nmc] = p.pdgId();
00094 mcpt[nmc] = p.pt();
00095 mceta[nmc] = p.eta();
00096 mcphi[nmc] = p.phi();
00097 mcvx[nmc] = p.vx();
00098 mcvy[nmc] = p.vy();
00099 mcvz[nmc] = p.vz();
00100
00101 if ((mcpid[nmc]==24)||(mcpid[nmc]==-24)) {
00102 size_t idg = p.numberOfDaughters();
00103 for (size_t j=0; j != idg; ++j){
00104 const Candidate & d = *p.daughter(j);
00105 if ((d.pdgId()==11)||(d.pdgId()==-11)){wel += 1;}
00106 if ((d.pdgId()==13)||(d.pdgId()==-13)){wmu += 1;}
00107
00108
00109 }
00110 }
00111 if (mcpid[nmc]==23) {
00112 size_t idg = p.numberOfDaughters();
00113 for (size_t j=0; j != idg; ++j){
00114 const Candidate & d = *p.daughter(j);
00115 if (d.pdgId()==11){zee += 1;}
00116 if (d.pdgId()==-11){zee += 2;}
00117 if (d.pdgId()==13){zmumu += 1;}
00118 if (d.pdgId()==-13){zmumu += 2;}
00119 }
00120 }
00121
00122 if (((mcpid[nmc]==13)||(mcpid[nmc]==-13))&&(mcpt[nmc]>2.5)) {mu3 += 1;}
00123 if (((mcpid[nmc]==11)||(mcpid[nmc]==-11))&&(mcpt[nmc]>2.5)) {el3 += 1;}
00124
00125 if (mcpid[nmc]==-5) {mab += 1;}
00126 if (mcpid[nmc]==5) {mbb += 1;}
00127
00128 if ((mcpid[nmc]==13)||(mcpid[nmc]==-13))
00129 {if (p.pt()>ptMuMax) {ptMuMax=p.pt();} }
00130 if ((mcpid[nmc]==11)||(mcpid[nmc]==-11))
00131 {if (p.pt() > ptEleMax) ptEleMax=p.pt();}
00132
00133 nmc++;
00134 }
00135
00136 }
00137 else {std::cout << "%HLTMCtruth -- No MC truth information" << std::endl;}
00138
00139 nmcpart = nmc;
00140 nmu3 = mu3;
00141 nel3 = el3;
00142 nbb = mbb;
00143 nab = mab;
00144 nwenu = wel;
00145 nwmunu = wmu;
00146 if((zee%3)==0){nzee = zee/3;}
00147
00148 if ((zmumu%3)==0){nzmumu = zmumu/3;}
00149
00150
00151 }
00152
00153 }