CMS 3D CMS Logo

MultiTrackValidatorBase.h

Go to the documentation of this file.
00001 #ifndef MultiTrackValidatorBase_h
00002 #define MultiTrackValidatorBase_h
00003 
00012 #include <memory>
00013 
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00017 
00018 #include "MagneticField/Engine/interface/MagneticField.h" 
00019 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" 
00020 
00021 #include "SimTracker/TrackAssociation/interface/TrackAssociatorByChi2.h"
00022 
00023 #include "DQMServices/Core/interface/DQMStore.h"
00024 #include "DQMServices/Core/interface/MonitorElement.h"
00025 #include "FWCore/ServiceRegistry/interface/Service.h"
00026 
00027 #include "PhysicsTools/RecoAlgos/interface/RecoTrackSelector.h"
00028 #include "PhysicsTools/RecoAlgos/interface/TrackingParticleSelector.h"
00029 
00030 #include <iostream>
00031 #include <sstream>
00032 #include <string>
00033 #include <TH1F.h>
00034 #include <TH2F.h>
00035 
00036 class MultiTrackValidatorBase {
00037  public:
00039   MultiTrackValidatorBase(const edm::ParameterSet& pset):
00040     sim(pset.getParameter<std::string>("sim")),
00041     label(pset.getParameter< std::vector<edm::InputTag> >("label")),
00042     bsSrc(pset.getParameter< edm::InputTag >("beamSpot")),
00043     label_tp_effic(pset.getParameter< edm::InputTag >("label_tp_effic")),
00044     label_tp_fake(pset.getParameter< edm::InputTag >("label_tp_fake")),
00045     associators(pset.getParameter< std::vector<std::string> >("associators")),
00046     out(pset.getParameter<std::string>("outputFile")),   
00047     min(pset.getParameter<double>("min")),
00048     max(pset.getParameter<double>("max")),
00049     nint(pset.getParameter<int>("nint")),
00050     useFabs(pset.getParameter<bool>("useFabsEta")),
00051     minpT(pset.getParameter<double>("minpT")),
00052     maxpT(pset.getParameter<double>("maxpT")),
00053     nintpT(pset.getParameter<int>("nintpT")),
00054     minHit(pset.getParameter<double>("minHit")),
00055     maxHit(pset.getParameter<double>("maxHit")),
00056     nintHit(pset.getParameter<int>("nintHit")),
00057     useInvPt(pset.getParameter<bool>("useInvPt"))
00058     {
00059       dbe_ = edm::Service<DQMStore>().operator->();
00060     }
00061   
00063   virtual ~MultiTrackValidatorBase(){ }
00064   
00065   virtual void doProfileX(TH2 * th2, MonitorElement* me){
00066     if (th2->GetNbinsX()==me->getNbinsX()){
00067       TH1F * h1 = (TH1F*) th2->ProfileX();
00068       for (int bin=0;bin!=h1->GetNbinsX();bin++){
00069         me->setBinContent(bin+1,h1->GetBinContent(bin+1));
00070         me->setBinError(bin+1,h1->GetBinError(bin+1));
00071       }
00072       delete h1;
00073     } else {
00074       throw cms::Exception("MultiTrackValidator") << "Different number of bins!";
00075     }
00076   }
00077 
00078   virtual void doProfileX(MonitorElement * th2m, MonitorElement* me) {
00079     doProfileX(th2m->getTH2F(), me);
00080   }
00081 
00082   virtual double getEta(double eta) {
00083     if (useFabs) return fabs(eta);
00084     else return eta;
00085   }
00086 
00087   virtual double getPt(double pt) {
00088     if (useInvPt && pt!=0) return 1/pt;
00089     else return pt;
00090   }
00091   
00092   void fillPlotFromVector(MonitorElement* h, std::vector<int>& vec) {
00093     for (unsigned int j=0; j<vec.size(); j++){
00094       h->setBinContent(j+1, vec[j]);
00095     }
00096   }
00097 
00098   void fillPlotFromVectors(MonitorElement* h, std::vector<int>& numerator, std::vector<int>& denominator,std::string type){
00099     double value,err;
00100     for (unsigned int j=0; j<numerator.size(); j++){
00101       if (denominator[j]!=0){
00102         if (type=="effic")
00103           value = ((double) numerator[j])/((double) denominator[j]);
00104         else if (type=="fakerate")
00105           value = 1-((double) numerator[j])/((double) denominator[j]);
00106         else return;
00107         err = sqrt( value*(1-value)/(double) denominator[j] );
00108         h->setBinContent(j+1, value);
00109         h->setBinError(j+1,err);
00110       }
00111       else {
00112         h->setBinContent(j+1, 0);
00113       }
00114     }
00115   }
00116 
00117   void setUpVectors() {
00118     std::vector<double> etaintervalsv;
00119     std::vector<double> pTintervalsv;
00120     std::vector<int>    totSIMveta,totASSveta,totASS2veta,totRECveta;
00121     std::vector<int>    totSIMvpT,totASSvpT,totASS2vpT,totRECvpT;
00122     std::vector<int>    totSIMv_hit,totASSv_hit,totASS2v_hit,totRECv_hit;
00123 
00124     double step=(max-min)/nint;
00125     std::ostringstream title,name;
00126     etaintervalsv.push_back(min);
00127     for (int k=1;k<nint+1;k++) {
00128       double d=min+k*step;
00129       etaintervalsv.push_back(d);
00130       totSIMveta.push_back(0);
00131       totASSveta.push_back(0);
00132       totASS2veta.push_back(0);
00133       totRECveta.push_back(0);
00134     }   
00135     etaintervals.push_back(etaintervalsv);
00136     totSIMeta.push_back(totSIMveta);
00137     totASSeta.push_back(totASSveta);
00138     totASS2eta.push_back(totASS2veta);
00139     totRECeta.push_back(totRECveta);
00140   
00141     double steppT = (maxpT-minpT)/nintpT;
00142     pTintervalsv.push_back(minpT);
00143     for (int k=1;k<nintpT+1;k++) {
00144       double d=minpT+k*steppT;
00145       pTintervalsv.push_back(d);
00146       totSIMvpT.push_back(0);
00147       totASSvpT.push_back(0);
00148       totASS2vpT.push_back(0);
00149       totRECvpT.push_back(0);
00150     }
00151     pTintervals.push_back(pTintervalsv);
00152     totSIMpT.push_back(totSIMvpT);
00153     totASSpT.push_back(totASSvpT);
00154     totASS2pT.push_back(totASS2vpT);
00155     totRECpT.push_back(totRECvpT);
00156 
00157     for (int k=1;k<nintHit+1;k++) {
00158       totSIMv_hit.push_back(0);
00159       totASSv_hit.push_back(0);
00160       totASS2v_hit.push_back(0);
00161       totRECv_hit.push_back(0);
00162     }
00163     totSIM_hit.push_back(totSIMv_hit);
00164     totASS_hit.push_back(totASSv_hit);
00165     totASS2_hit.push_back(totASS2v_hit);
00166     totREC_hit.push_back(totRECv_hit);
00167   }
00168 
00169  protected:
00170 
00171   DQMStore* dbe_;
00172 
00173   std::string sim;
00174   std::vector<edm::InputTag> label;
00175   edm::InputTag bsSrc;
00176   edm::InputTag label_tp_effic;
00177   edm::InputTag label_tp_fake;
00178   std::vector<std::string> associators;
00179   std::string out;
00180         
00181   double  min, max;
00182   int nint;
00183   bool useFabs;
00184   double minpT, maxpT;
00185   int nintpT;
00186   double minHit, maxHit;
00187   int nintHit;
00188   bool useInvPt;
00189 
00190   edm::ESHandle<MagneticField> theMF;
00191   std::vector<const TrackAssociatorBase*> associator;
00192 
00193   //sim
00194   std::vector<MonitorElement*> h_ptSIM, h_etaSIM, h_tracksSIM, h_vertposSIM;
00195 
00196   //1D
00197   std::vector<MonitorElement*> h_tracks, h_fakes, h_hits, h_charge;
00198   std::vector<MonitorElement*> h_effic, h_efficPt, h_fakerate, h_fakeratePt, h_recoeta, h_assoceta, h_assoc2eta, h_simuleta;
00199   std::vector<MonitorElement*>  h_effic_vs_hit, h_fake_vs_hit;
00200   std::vector<MonitorElement*> h_recopT, h_assocpT, h_assoc2pT, h_simulpT, h_recohit, h_assochit, h_assoc2hit, h_simulhit;
00201   std::vector<MonitorElement*> h_pt, h_eta, h_pullTheta,h_pullPhi,h_pullDxy,h_pullDz,h_pullQoverp;
00202 
00203   //2D  
00204   std::vector<MonitorElement*> nrec_vs_nsim;
00205 
00206   //assoc hits
00207   std::vector<MonitorElement*> h_assocFraction, h_assocSharedHit;
00208 
00209   //#hit vs eta: to be used with doProfileX
00210   std::vector<MonitorElement*> nhits_vs_eta;
00211   std::vector<MonitorElement*> h_hits_eta;
00212  
00213   std::vector< std::vector<double> > etaintervals;
00214   std::vector< std::vector<double> > pTintervals;
00215   std::vector< std::vector<int> > totSIMeta,totRECeta,totASSeta,totASS2eta;
00216   std::vector< std::vector<int> > totSIMpT,totRECpT,totASSpT,totASS2pT;
00217   std::vector< std::vector<int> > totSIM_hit,totREC_hit,totASS_hit,totASS2_hit;
00218 };
00219 
00220 
00221 #endif

Generated on Tue Jun 9 17:49:36 2009 for CMSSW by  doxygen 1.5.4