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/HLTMuon.h"
00013
00014 HLTMuon::HLTMuon() {
00015 evtCounter=0;
00016
00017
00018 _Monte=false;
00019 _Debug=false;
00020 }
00021
00022
00023 void HLTMuon::setup(const edm::ParameterSet& pSet, TTree* HltTree) {
00024
00025 edm::ParameterSet myEmParams = pSet.getParameter<edm::ParameterSet>("RunParameters") ;
00026 vector<std::string> parameterNames = myEmParams.getParameterNames() ;
00027
00028 for ( vector<std::string>::iterator iParam = parameterNames.begin();
00029 iParam != parameterNames.end(); iParam++ ){
00030 if ( (*iParam) == "Monte" ) _Monte = myEmParams.getParameter<bool>( *iParam );
00031 else if ( (*iParam) == "Debug" ) _Debug = myEmParams.getParameter<bool>( *iParam );
00032 }
00033
00034 const int kMaxMuon = 10000;
00035 muonpt = new float[kMaxMuon];
00036 muonphi = new float[kMaxMuon];
00037 muoneta = new float[kMaxMuon];
00038 muonet = new float[kMaxMuon];
00039 muone = new float[kMaxMuon];
00040 const int kMaxMuonL2 = 500;
00041 muonl2pt = new float[kMaxMuonL2];
00042 muonl2phi = new float[kMaxMuonL2];
00043 muonl2eta = new float[kMaxMuonL2];
00044 muonl2dr = new float[kMaxMuonL2];
00045 muonl2dz = new float[kMaxMuonL2];
00046 muonl2chg = new int[kMaxMuonL2];
00047 muonl2pterr = new float[kMaxMuonL2];
00048 muonl2iso = new int[kMaxMuonL2];
00049 const int kMaxMuonL3 = 500;
00050 muonl3pt = new float[kMaxMuonL3];
00051 muonl3phi = new float[kMaxMuonL3];
00052 muonl3eta = new float[kMaxMuonL3];
00053 muonl3dr = new float[kMaxMuonL3];
00054 muonl3dz = new float[kMaxMuonL3];
00055 muonl3chg = new int[kMaxMuonL3];
00056 muonl3pterr = new float[kMaxMuonL3];
00057 muonl3iso = new int[kMaxMuonL3];
00058 muonl32idx = new int[kMaxMuonL3];
00059
00060
00061 HltTree->Branch("NrecoMuon",&nmuon,"NrecoMuon/I");
00062 HltTree->Branch("recoMuonPt",muonpt,"recoMuonPt[NrecoMuon]/F");
00063 HltTree->Branch("recoMuonPhi",muonphi,"recoMuonPhi[NrecoMuon]/F");
00064 HltTree->Branch("recoMuonEta",muoneta,"recoMuonEta[NrecoMuon]/F");
00065 HltTree->Branch("recoMuonEt",muonet,"recoMuonEt[NrecoMuon]/F");
00066 HltTree->Branch("recoMuonE",muone,"recoMuonE[NrecoMuon]/F");
00067 HltTree->Branch("NohMuL2",&nmu2cand,"NohMuL2/I");
00068 HltTree->Branch("ohMuL2Pt",muonl2pt,"ohMuL2Pt[NohMuL2]/F");
00069 HltTree->Branch("ohMuL2Phi",muonl2phi,"ohMuL2Phi[NohMuL2]/F");
00070 HltTree->Branch("ohMuL2Eta",muonl2eta,"ohMuL2Eta[NohMuL2]/F");
00071 HltTree->Branch("ohMuL2Chg",muonl2chg,"ohMuL2Chg[NohMuL2]/I");
00072 HltTree->Branch("ohMuL2PtErr",muonl2pterr,"ohMuL2PtErr[NohMuL2]/F");
00073 HltTree->Branch("ohMuL2Iso",muonl2iso,"ohMuL2Iso[NohMuL2]/I");
00074 HltTree->Branch("ohMuL2Dr",muonl2dr,"ohMuL2Dr[NohMuL2]/F");
00075 HltTree->Branch("ohMuL2Dz",muonl2dz,"ohMuL2Dz[NohMuL2]/F");
00076 HltTree->Branch("NohMuL3",&nmu3cand,"NohMuL3/I");
00077 HltTree->Branch("ohMuL3Pt",muonl3pt,"ohMuL3Pt[NohMuL3]/F");
00078 HltTree->Branch("ohMuL3Phi",muonl3phi,"ohMuL3Phi[NohMuL3]/F");
00079 HltTree->Branch("ohMuL3Eta",muonl3eta,"ohMuL3Eta[NohMuL3]/F");
00080 HltTree->Branch("ohMuL3Chg",muonl3chg,"ohMuL3Chg[NohMuL3]/I");
00081 HltTree->Branch("ohMuL3PtErr",muonl3pterr,"ohMuL3PtErr[NohMuL3]/F");
00082 HltTree->Branch("ohMuL3Iso",muonl3iso,"ohMuL3Iso[NohMuL3]/I");
00083 HltTree->Branch("ohMuL3Dr",muonl3dr,"ohMuL3Dr[NohMuL3]/F");
00084 HltTree->Branch("ohMuL3Dz",muonl3dz,"ohMuL3Dz[NohMuL3]/F");
00085 HltTree->Branch("ohMuL3L2idx",muonl32idx,"ohMuL3L2idx[NohMuL3]/I");
00086
00087 }
00088
00089
00090 void HLTMuon::analyze(const edm::Handle<MuonCollection> & Muon,
00091 const edm::Handle<RecoChargedCandidateCollection> & MuCands2,
00092 const edm::Handle<edm::ValueMap<bool> > & isoMap2,
00093 const edm::Handle<RecoChargedCandidateCollection> & MuCands3,
00094 const edm::Handle<edm::ValueMap<bool> > & isoMap3,
00095 const edm::Handle<MuonTrackLinksCollection> & mulinks,
00096 TTree* HltTree) {
00097
00098
00099
00100 if (Muon.isValid()) {
00101 MuonCollection mymuons;
00102 mymuons = * Muon;
00103 std::sort(mymuons.begin(),mymuons.end(),PtGreater());
00104 nmuon = mymuons.size();
00105 typedef MuonCollection::const_iterator muiter;
00106 int imu=0;
00107 for (muiter i=mymuons.begin(); i!=mymuons.end(); i++) {
00108 muonpt[imu] = i->pt();
00109 muonphi[imu] = i->phi();
00110 muoneta[imu] = i->eta();
00111 muonet[imu] = i->et();
00112 muone[imu] = i->energy();
00113 imu++;
00114 }
00115 }
00116 else {nmuon = 0;}
00117
00119
00120
00121 RecoChargedCandidateCollection myMucands2;
00122 if (MuCands2.isValid()) {
00123
00124 myMucands2 = * MuCands2;
00125 std::sort(myMucands2.begin(),myMucands2.end(),PtGreater());
00126 nmu2cand = myMucands2.size();
00127 typedef RecoChargedCandidateCollection::const_iterator cand;
00128 int imu2c=0;
00129 for (cand i=myMucands2.begin(); i!=myMucands2.end(); i++) {
00130 TrackRef tk = i->get<TrackRef>();
00131
00132 muonl2pt[imu2c] = tk->pt();
00133
00134 muonl2eta[imu2c] = tk->eta();
00135 muonl2phi[imu2c] = tk->phi();
00136
00137
00138
00139
00140 muonl2dr[imu2c] = fabs(tk->d0());
00141
00142
00143
00144 muonl2dz[imu2c] = fabs(tk->dz());
00145
00146
00147
00148
00149
00150
00151
00152 double l2_err0 = tk->error(0);
00153 double l2_abspar0 = fabs(tk->parameter(0));
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 muonl2pterr[imu2c] = l2_err0/l2_abspar0;
00167 muonl2chg[imu2c] = tk->charge();
00168
00169 if (isoMap2.isValid()){
00170
00171 edm::ValueMap<bool> ::value_type muon1IsIsolated = (*isoMap2)[tk];
00172 muonl2iso[imu2c] = muon1IsIsolated;
00173 }
00174 else {muonl2iso[imu2c] = -999;}
00175
00176 imu2c++;
00177 }
00178 }
00179 else {nmu2cand = 0;}
00180
00181
00182 RecoChargedCandidateCollection myMucands3;
00183 if (MuCands3.isValid()) {
00184 myMucands3 = * MuCands3;
00185 std::sort(myMucands3.begin(),myMucands3.end(),PtGreater());
00186 nmu3cand = myMucands3.size();
00187 typedef RecoChargedCandidateCollection::const_iterator cand;
00188 int imu3c=0;
00189 for (cand i=myMucands3.begin(); i!=myMucands3.end(); i++) {
00190 TrackRef tk = i->get<TrackRef>();
00191
00192 TrackRef staTrack;
00193 typedef MuonTrackLinksCollection::const_iterator l3muon;
00194 int il3 = 0;
00195 for (l3muon j=mulinks->begin(); j!=mulinks->end(); j++){
00196 if (j->globalTrack() == tk) {
00197 staTrack = j->standAloneTrack();
00198 break;
00199 }
00200 il3++;
00201 }
00202 int imu2idx = 0;
00203 if (MuCands2.isValid()) {
00204 typedef RecoChargedCandidateCollection::const_iterator candl2;
00205 for (candl2 i=myMucands2.begin(); i!=myMucands2.end(); i++) {
00206 TrackRef tkl2 = i->get<TrackRef>();
00207 if ( tkl2 == staTrack ) {break;}
00208 imu2idx++;
00209 }
00210 }
00211 else {imu2idx = -999;}
00212 muonl32idx[imu3c] = imu2idx;
00213
00214 muonl3pt[imu3c] = tk->pt();
00215
00216 muonl3eta[imu3c] = tk->eta();
00217 muonl3phi[imu3c] = tk->phi();
00218
00219
00220
00221
00222 muonl3dr[imu3c] = fabs(tk->d0());
00223
00224
00225
00226 muonl3dz[imu3c] = fabs(tk->dz());
00227
00228
00229
00230
00231
00232
00233
00234 double l3_err0 = tk->error(0);
00235 double l3_abspar0 = fabs(tk->parameter(0));
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 muonl3pterr[imu3c] = l3_err0/l3_abspar0;
00249 muonl3chg[imu3c] = tk->charge();
00250
00251 if (isoMap3.isValid()){
00252
00253 edm::ValueMap<bool> ::value_type muon1IsIsolated = (*isoMap3)[tk];
00254 muonl3iso[imu3c] = muon1IsIsolated;
00255 }
00256 else {muonl3iso[imu3c] = -999;}
00257
00258 imu3c++;
00259 }
00260 }
00261 else {nmu3cand = 0;}
00262
00264
00265
00266
00267 }