00001 #ifndef MuonTrackValidatorBase_h
00002 #define MuonTrackValidatorBase_h
00003
00011 #include <memory>
00012
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/ESHandle.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016
00017 #include "MagneticField/Engine/interface/MagneticField.h"
00018 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00019
00020 #include "SimTracker/TrackAssociation/interface/TrackAssociatorByChi2.h"
00021
00022 #include "DQMServices/Core/interface/DQMStore.h"
00023 #include "DQMServices/Core/interface/MonitorElement.h"
00024 #include "FWCore/ServiceRegistry/interface/Service.h"
00025
00026 #include "CommonTools/RecoAlgos/interface/RecoTrackSelector.h"
00027 #include "CommonTools/RecoAlgos/interface/TrackingParticleSelector.h"
00028 #include "CommonTools/RecoAlgos/interface/CosmicTrackingParticleSelector.h"
00029
00030 #include <iostream>
00031 #include <sstream>
00032 #include <string>
00033 #include <TH1F.h>
00034 #include <TH2F.h>
00035
00036 class MuonTrackValidatorBase {
00037 public:
00039 MuonTrackValidatorBase(const edm::ParameterSet& pset):
00040 label(pset.getParameter< std::vector<edm::InputTag> >("label")),
00041 usetracker(pset.getParameter<bool>("usetracker")),
00042 usemuon(pset.getParameter<bool>("usemuon")),
00043 bsSrc(pset.getParameter< edm::InputTag >("beamSpot")),
00044 label_tp_effic(pset.getParameter< edm::InputTag >("label_tp_effic")),
00045 label_tp_fake(pset.getParameter< edm::InputTag >("label_tp_fake")),
00046 associators(pset.getParameter< std::vector<std::string> >("associators")),
00047 out(pset.getParameter<std::string>("outputFile")),
00048 parametersDefiner(pset.getParameter<std::string>("parametersDefiner")),
00049 min(pset.getParameter<double>("min")),
00050 max(pset.getParameter<double>("max")),
00051 nint(pset.getParameter<int>("nint")),
00052 useFabs(pset.getParameter<bool>("useFabsEta")),
00053 minpT(pset.getParameter<double>("minpT")),
00054 maxpT(pset.getParameter<double>("maxpT")),
00055 nintpT(pset.getParameter<int>("nintpT")),
00056 minHit(pset.getParameter<double>("minHit")),
00057 maxHit(pset.getParameter<double>("maxHit")),
00058 nintHit(pset.getParameter<int>("nintHit")),
00059 minPhi(pset.getParameter<double>("minPhi")),
00060 maxPhi(pset.getParameter<double>("maxPhi")),
00061 nintPhi(pset.getParameter<int>("nintPhi")),
00062 minDxy(pset.getParameter<double>("minDxy")),
00063 maxDxy(pset.getParameter<double>("maxDxy")),
00064 nintDxy(pset.getParameter<int>("nintDxy")),
00065 minDz(pset.getParameter<double>("minDz")),
00066 maxDz(pset.getParameter<double>("maxDz")),
00067 nintDz(pset.getParameter<int>("nintDz")),
00068 minVertpos(pset.getParameter<double>("minVertpos")),
00069 maxVertpos(pset.getParameter<double>("maxVertpos")),
00070 nintVertpos(pset.getParameter<int>("nintVertpos")),
00071 minZpos(pset.getParameter<double>("minZpos")),
00072 maxZpos(pset.getParameter<double>("maxZpos")),
00073 nintZpos(pset.getParameter<int>("nintZpos")),
00074 useInvPt(pset.getParameter<bool>("useInvPt")),
00075
00076 ptRes_rangeMin(pset.getParameter<double>("ptRes_rangeMin")),
00077 ptRes_rangeMax(pset.getParameter<double>("ptRes_rangeMax")),
00078 phiRes_rangeMin(pset.getParameter<double>("phiRes_rangeMin")),
00079 phiRes_rangeMax(pset.getParameter<double>("phiRes_rangeMax")),
00080 cotThetaRes_rangeMin(pset.getParameter<double>("cotThetaRes_rangeMin")),
00081 cotThetaRes_rangeMax(pset.getParameter<double>("cotThetaRes_rangeMax")),
00082 dxyRes_rangeMin(pset.getParameter<double>("dxyRes_rangeMin")),
00083 dxyRes_rangeMax(pset.getParameter<double>("dxyRes_rangeMax")),
00084 dzRes_rangeMin(pset.getParameter<double>("dzRes_rangeMin")),
00085 dzRes_rangeMax(pset.getParameter<double>("dzRes_rangeMax")),
00086 ptRes_nbin(pset.getParameter<int>("ptRes_nbin")),
00087 cotThetaRes_nbin(pset.getParameter<int>("cotThetaRes_nbin")),
00088 phiRes_nbin(pset.getParameter<int>("phiRes_nbin")),
00089 dxyRes_nbin(pset.getParameter<int>("dxyRes_nbin")),
00090 dzRes_nbin(pset.getParameter<int>("dzRes_nbin")),
00091 ignoremissingtkcollection_(pset.getUntrackedParameter<bool>("ignoremissingtrackcollection",false)),
00092 useLogPt(pset.getUntrackedParameter<bool>("useLogPt",false))
00093
00094 {
00095 dbe_ = edm::Service<DQMStore>().operator->();
00096 if(useLogPt){
00097 maxpT=log10(maxpT);
00098 minpT=log10(minpT);
00099 }
00100 }
00101
00103 virtual ~MuonTrackValidatorBase(){ }
00104
00105 virtual void doProfileX(TH2 * th2, MonitorElement* me){
00106 if (th2->GetNbinsX()==me->getNbinsX()){
00107 TProfile * p1 = (TProfile*) th2->ProfileX();
00108 p1->Copy(*me->getTProfile());
00109 delete p1;
00110 } else {
00111 throw cms::Exception("MuonTrackValidator") << "Different number of bins!";
00112 }
00113 }
00114
00115 virtual void doProfileX(MonitorElement * th2m, MonitorElement* me) {
00116 doProfileX(th2m->getTH2F(), me);
00117 }
00118
00119 virtual double getEta(double eta) {
00120 if (useFabs) return fabs(eta);
00121 else return eta;
00122 }
00123
00124 virtual double getPt(double pt) {
00125 if (useInvPt && pt!=0) return 1/pt;
00126 else return pt;
00127 }
00128
00129 void fillPlotFromVector(MonitorElement* h, std::vector<int>& vec) {
00130 for (unsigned int j=0; j<vec.size(); j++){
00131 h->setBinContent(j+1, vec[j]);
00132 }
00133 }
00134
00135 void fillPlotFromVectors(MonitorElement* h, std::vector<int>& numerator, std::vector<int>& denominator,std::string type){
00136 double value,err;
00137 for (unsigned int j=0; j<numerator.size(); j++){
00138 if (denominator[j]!=0){
00139 if (type=="effic")
00140 value = ((double) numerator[j])/((double) denominator[j]);
00141 else if (type=="fakerate")
00142 value = 1-((double) numerator[j])/((double) denominator[j]);
00143 else return;
00144 err = sqrt( value*(1-value)/(double) denominator[j] );
00145 h->setBinContent(j+1, value);
00146 h->setBinError(j+1,err);
00147 }
00148 else {
00149 h->setBinContent(j+1, 0);
00150 }
00151 }
00152 }
00153
00154 void BinLogX(TH1*h)
00155 {
00156
00157 TAxis *axis = h->GetXaxis();
00158 int bins = axis->GetNbins();
00159
00160 float from = axis->GetXmin();
00161 float to = axis->GetXmax();
00162 float width = (to - from) / bins;
00163 float *new_bins = new float[bins + 1];
00164
00165 for (int i = 0; i <= bins; i++) {
00166 new_bins[i] = TMath::Power(10, from + i * width);
00167
00168 }
00169 axis->Set(bins, new_bins);
00170 delete[] new_bins;
00171 }
00172
00173 void setUpVectors() {
00174 std::vector<double> etaintervalsv;
00175 std::vector<double> phiintervalsv;
00176 std::vector<double> pTintervalsv;
00177 std::vector<double> dxyintervalsv;
00178 std::vector<double> dzintervalsv;
00179 std::vector<double> vertposintervalsv;
00180 std::vector<double> zposintervalsv;
00181 std::vector<int> totSIMveta,totASSveta,totASS2veta,totRECveta;
00182 std::vector<int> totSIMvpT,totASSvpT,totASS2vpT,totRECvpT;
00183 std::vector<int> totSIMv_hit,totASSv_hit,totASS2v_hit,totRECv_hit;
00184 std::vector<int> totSIMv_phi,totASSv_phi,totASS2v_phi,totRECv_phi;
00185 std::vector<int> totSIMv_dxy,totASSv_dxy,totASS2v_dxy,totRECv_dxy;
00186 std::vector<int> totSIMv_dz,totASSv_dz,totASS2v_dz,totRECv_dz;
00187 std::vector<int> totSIMv_vertpos,totASSv_vertpos,totSIMv_zpos,totASSv_zpos;
00188
00189
00190 std::vector<int> totASSveta_Quality05, totASSveta_Quality075;
00191 std::vector<int> totASSvpT_Quality05, totASSvpT_Quality075;
00192 std::vector<int> totASSv_phi_Quality05, totASSv_phi_Quality075;
00193
00194 double step=(max-min)/nint;
00195 std::ostringstream title,name;
00196 etaintervalsv.push_back(min);
00197 for (int k=1;k<nint+1;k++) {
00198 double d=min+k*step;
00199 etaintervalsv.push_back(d);
00200 totSIMveta.push_back(0);
00201 totASSveta.push_back(0);
00202 totASS2veta.push_back(0);
00203 totRECveta.push_back(0);
00204
00205 totASSveta_Quality05.push_back(0);
00206 totASSveta_Quality075.push_back(0);
00207 }
00208 etaintervals.push_back(etaintervalsv);
00209 totSIMeta.push_back(totSIMveta);
00210 totASSeta.push_back(totASSveta);
00211 totASS2eta.push_back(totASS2veta);
00212 totRECeta.push_back(totRECveta);
00213
00214 totASSeta_Quality05.push_back(totASSveta_Quality05);
00215 totASSeta_Quality075.push_back(totASSveta_Quality075);
00216
00217 double steppT = (maxpT-minpT)/nintpT;
00218 pTintervalsv.push_back(minpT);
00219 for (int k=1;k<nintpT+1;k++) {
00220 double d=0;
00221 if(useLogPt)d=pow(10,minpT+k*steppT);
00222 else d=minpT+k*steppT;
00223 pTintervalsv.push_back(d);
00224 totSIMvpT.push_back(0);
00225 totASSvpT.push_back(0);
00226 totASS2vpT.push_back(0);
00227 totRECvpT.push_back(0);
00228
00229 totASSvpT_Quality05.push_back(0);
00230 totASSvpT_Quality075.push_back(0);
00231 }
00232 pTintervals.push_back(pTintervalsv);
00233 totSIMpT.push_back(totSIMvpT);
00234 totASSpT.push_back(totASSvpT);
00235 totASS2pT.push_back(totASS2vpT);
00236 totRECpT.push_back(totRECvpT);
00237
00238 totASSpT_Quality05.push_back(totASSvpT_Quality05);
00239 totASSpT_Quality075.push_back(totASSvpT_Quality075);
00240
00241 for (int k=1;k<nintHit+1;k++) {
00242 totSIMv_hit.push_back(0);
00243 totASSv_hit.push_back(0);
00244 totASS2v_hit.push_back(0);
00245 totRECv_hit.push_back(0);
00246 }
00247 totSIM_hit.push_back(totSIMv_hit);
00248 totASS_hit.push_back(totASSv_hit);
00249 totASS2_hit.push_back(totASS2v_hit);
00250 totREC_hit.push_back(totRECv_hit);
00251
00252 double stepPhi = (maxPhi-minPhi)/nintPhi;
00253 phiintervalsv.push_back(minPhi);
00254 for (int k=1;k<nintPhi+1;k++) {
00255 double d=minPhi+k*stepPhi;
00256 phiintervalsv.push_back(d);
00257 totSIMv_phi.push_back(0);
00258 totASSv_phi.push_back(0);
00259 totASS2v_phi.push_back(0);
00260 totRECv_phi.push_back(0);
00261
00262 totASSv_phi_Quality05.push_back(0);
00263 totASSv_phi_Quality075.push_back(0);
00264 }
00265 phiintervals.push_back(phiintervalsv);
00266 totSIM_phi.push_back(totSIMv_phi);
00267 totASS_phi.push_back(totASSv_phi);
00268 totASS2_phi.push_back(totASS2v_phi);
00269 totREC_phi.push_back(totRECv_phi);
00270
00271 totASS_phi_Quality05.push_back(totASSv_phi_Quality05);
00272 totASS_phi_Quality075.push_back(totASSv_phi_Quality075);
00273
00274 double stepDxy = (maxDxy-minDxy)/nintDxy;
00275 dxyintervalsv.push_back(minDxy);
00276 for (int k=1;k<nintDxy+1;k++) {
00277 double d=minDxy+k*stepDxy;
00278 dxyintervalsv.push_back(d);
00279 totSIMv_dxy.push_back(0);
00280 totASSv_dxy.push_back(0);
00281 totASS2v_dxy.push_back(0);
00282 totRECv_dxy.push_back(0);
00283 }
00284 dxyintervals.push_back(dxyintervalsv);
00285 totSIM_dxy.push_back(totSIMv_dxy);
00286 totASS_dxy.push_back(totASSv_dxy);
00287 totASS2_dxy.push_back(totASS2v_dxy);
00288 totREC_dxy.push_back(totRECv_dxy);
00289
00290
00291 double stepDz = (maxDz-minDz)/nintDz;
00292 dzintervalsv.push_back(minDz);
00293 for (int k=1;k<nintDz+1;k++) {
00294 double d=minDz+k*stepDz;
00295 dzintervalsv.push_back(d);
00296 totSIMv_dz.push_back(0);
00297 totASSv_dz.push_back(0);
00298 totASS2v_dz.push_back(0);
00299 totRECv_dz.push_back(0);
00300 }
00301 dzintervals.push_back(dzintervalsv);
00302 totSIM_dz.push_back(totSIMv_dz);
00303 totASS_dz.push_back(totASSv_dz);
00304 totASS2_dz.push_back(totASS2v_dz);
00305 totREC_dz.push_back(totRECv_dz);
00306
00307 double stepVertpos = (maxVertpos-minVertpos)/nintVertpos;
00308 vertposintervalsv.push_back(minVertpos);
00309 for (int k=1;k<nintVertpos+1;k++) {
00310 double d=minVertpos+k*stepVertpos;
00311 vertposintervalsv.push_back(d);
00312 totSIMv_vertpos.push_back(0);
00313 totASSv_vertpos.push_back(0);
00314 }
00315 vertposintervals.push_back(vertposintervalsv);
00316 totSIM_vertpos.push_back(totSIMv_vertpos);
00317 totASS_vertpos.push_back(totASSv_vertpos);
00318
00319 double stepZpos = (maxZpos-minZpos)/nintZpos;
00320 zposintervalsv.push_back(minZpos);
00321 for (int k=1;k<nintZpos+1;k++) {
00322 double d=minZpos+k*stepZpos;
00323 zposintervalsv.push_back(d);
00324 totSIMv_zpos.push_back(0);
00325 totASSv_zpos.push_back(0);
00326 }
00327 zposintervals.push_back(zposintervalsv);
00328 totSIM_zpos.push_back(totSIMv_zpos);
00329 totASS_zpos.push_back(totASSv_zpos);
00330
00331 }
00332
00333 protected:
00334
00335 DQMStore* dbe_;
00336
00337 std::vector<edm::InputTag> label;
00338 bool usetracker;
00339 bool usemuon;
00340 edm::InputTag bsSrc;
00341 edm::InputTag label_tp_effic;
00342 edm::InputTag label_tp_fake;
00343 std::vector<std::string> associators;
00344 std::string out;
00345 std::string parametersDefiner;
00346
00347 double min, max;
00348 int nint;
00349 bool useFabs;
00350 double minpT, maxpT;
00351 int nintpT;
00352 double minHit, maxHit;
00353 int nintHit;
00354 double minPhi, maxPhi;
00355 int nintPhi;
00356 double minDxy, maxDxy;
00357 int nintDxy;
00358 double minDz, maxDz;
00359 int nintDz;
00360 double minVertpos, maxVertpos;
00361 int nintVertpos;
00362 double minZpos, maxZpos;
00363 int nintZpos;
00364 bool useInvPt;
00365
00366 double ptRes_rangeMin,ptRes_rangeMax,
00367 phiRes_rangeMin,phiRes_rangeMax, cotThetaRes_rangeMin,cotThetaRes_rangeMax,
00368 dxyRes_rangeMin,dxyRes_rangeMax, dzRes_rangeMin,dzRes_rangeMax;
00369 int ptRes_nbin, cotThetaRes_nbin, phiRes_nbin, dxyRes_nbin, dzRes_nbin;
00370 bool ignoremissingtkcollection_;
00371 bool useLogPt;
00372
00373 edm::ESHandle<MagneticField> theMF;
00374 std::vector<const TrackAssociatorBase*> associator;
00375
00376
00377 std::vector<MonitorElement*> h_ptSIM, h_etaSIM, h_tracksSIM, h_vertposSIM;
00378
00379
00380 std::vector<MonitorElement*> h_tracks, h_fakes, h_hits, h_charge;
00381 std::vector<MonitorElement*> h_recoeta, h_assoceta, h_assoc2eta, h_simuleta;
00382 std::vector<MonitorElement*> h_recopT, h_assocpT, h_assoc2pT, h_simulpT;
00383 std::vector<MonitorElement*> h_recohit, h_assochit, h_assoc2hit, h_simulhit;
00384 std::vector<MonitorElement*> h_recophi, h_assocphi, h_assoc2phi, h_simulphi;
00385 std::vector<MonitorElement*> h_recodxy, h_assocdxy, h_assoc2dxy, h_simuldxy;
00386 std::vector<MonitorElement*> h_recodz, h_assocdz, h_assoc2dz, h_simuldz;
00387 std::vector<MonitorElement*> h_assocvertpos, h_simulvertpos, h_assoczpos, h_simulzpos;
00388 std::vector<MonitorElement*> h_pt, h_eta, h_pullTheta,h_pullPhi,h_pullDxy,h_pullDz,h_pullQoverp;
00389
00390 std::vector<MonitorElement*> h_assoceta_Quality05, h_assoceta_Quality075;
00391 std::vector<MonitorElement*> h_assocpT_Quality05, h_assocpT_Quality075;
00392 std::vector<MonitorElement*> h_assocphi_Quality05, h_assocphi_Quality075;
00393
00394
00395
00396 std::vector<MonitorElement*> nrec_vs_nsim;
00397 std::vector<MonitorElement*> nrecHit_vs_nsimHit_sim2rec;
00398 std::vector<MonitorElement*> nrecHit_vs_nsimHit_rec2sim;
00399
00400
00401 std::vector<MonitorElement*> h_assocFraction, h_assocSharedHit;
00402
00403
00404 std::vector<MonitorElement*> nhits_vs_eta,
00405 nDThits_vs_eta,nCSChits_vs_eta,nRPChits_vs_eta;
00406
00407 std::vector<MonitorElement*> h_hits_eta,
00408 h_DThits_eta,h_CSChits_eta,h_RPChits_eta;
00409
00410
00411 std::vector< std::vector<double> > etaintervals;
00412 std::vector< std::vector<double> > pTintervals;
00413 std::vector< std::vector<double> > phiintervals;
00414 std::vector< std::vector<double> > dxyintervals;
00415 std::vector< std::vector<double> > dzintervals;
00416 std::vector< std::vector<double> > vertposintervals;
00417 std::vector< std::vector<double> > zposintervals;
00418 std::vector< std::vector<int> > totSIMeta,totRECeta,totASSeta,totASS2eta;
00419 std::vector< std::vector<int> > totSIMpT,totRECpT,totASSpT,totASS2pT;
00420 std::vector< std::vector<int> > totSIM_hit,totREC_hit,totASS_hit,totASS2_hit;
00421 std::vector< std::vector<int> > totSIM_phi,totREC_phi,totASS_phi,totASS2_phi;
00422 std::vector< std::vector<int> > totSIM_dxy,totREC_dxy,totASS_dxy,totASS2_dxy;
00423 std::vector< std::vector<int> > totSIM_dz,totREC_dz,totASS_dz,totASS2_dz;
00424 std::vector< std::vector<int> > totSIM_vertpos,totASS_vertpos,totSIM_zpos,totASS_zpos;
00425
00426
00427 std::vector<MonitorElement*> h_PurityVsQuality;
00428 std::vector< std::vector<int> > totASSeta_Quality05,totASSeta_Quality075;
00429 std::vector< std::vector<int> > totASSpT_Quality05, totASSpT_Quality075;
00430 std::vector< std::vector<int> > totASS_phi_Quality05, totASS_phi_Quality075;
00431
00432 };
00433
00434
00435 #endif