CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoVertex/BeamSpotProducer/interface/BeamFitter.h

Go to the documentation of this file.
00001 #ifndef BeamFitter_H
00002 #define BeamFitter_H
00003 
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "DataFormats/Provenance/interface/Timestamp.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00021 #include "DataFormats/TrackReco/interface/TrackBase.h"
00022 #include "RecoVertex/BeamSpotProducer/interface/BSTrkParameters.h"
00023 #include "RecoVertex/BeamSpotProducer/interface/BSFitter.h"
00024 #include "RecoVertex/BeamSpotProducer/interface/PVFitter.h"
00025 
00026 // ROOT
00027 #include "TFile.h"
00028 #include "TTree.h"
00029 #include "TH1F.h"
00030 
00031 #include <fstream>
00032 
00033 class BeamFitter {
00034  public:
00035   BeamFitter() {}
00036   BeamFitter(const edm::ParameterSet& iConfig);
00037   virtual ~BeamFitter();
00038 
00039   void readEvent(const edm::Event& iEvent);
00040 
00041   bool runFitter();
00042   bool runBeamWidthFitter();
00043   bool runPVandTrkFitter();
00044   bool runFitterNoTxt();
00045 
00046   reco::BeamSpot getBeamWidth() { return fbeamWidthFit; }
00047   void runAllFitter();
00048   void resetTrkVector() { fBSvector.clear(); }
00049   void resetTotTrk() { ftotal_tracks=0; }
00050   void resetLSRange() { fbeginLumiOfFit=fendLumiOfFit=-1; }
00051   void resetRefTime() { freftime[0] = freftime[1] = 0; }
00052   void setRefTime(std::time_t t0,std::time_t t1) {
00053     freftime[0] = t0;
00054     freftime[1] = t1;
00055   }
00056   void resetPVFitter() { MyPVFitter->resetAll(); }
00057   void dumpTxtFile(std::string &,bool);
00058   void dumpBWTxtFile(std::string &);
00059   void write2DB();
00060   reco::BeamSpot getBeamSpot() { return fbeamspot; }
00061   std::map<int, reco::BeamSpot> getBeamSpotMap() { return fbspotPVMap; }
00062   std::vector<BSTrkParameters> getBSvector() { return fBSvector; }
00063   TH1F * getCutFlow() { return h1cutFlow; }
00064   void resetCutFlow() {
00065     h1cutFlow->Reset();
00066     ftotal_tracks = 0;
00067     for (unsigned int i=0; i<sizeof(countPass)/sizeof(countPass[0]); i++)
00068       countPass[i]=0;
00069   }
00070   int* getFitLSRange() {
00071     int *tmp=new int[2];
00072     tmp[0] = fbeginLumiOfFit;
00073     tmp[1] = fendLumiOfFit;
00074     return tmp;
00075   }
00076   void setFitLSRange(int ls0,int ls1) {
00077     fbeginLumiOfFit = ls0;
00078     fendLumiOfFit = ls1;
00079   }
00080   void setRun( int run) { frun = run; }
00081 
00082   int getNTracks() {
00083     return fBSvector.size();
00084   }
00085   int getNPVs() {
00086     return MyPVFitter->getNPVs();
00087   }
00088   const std::map<int, int> &getNPVsperBX() {
00089     return MyPVFitter->getNPVsperBX();
00090   }
00091  private:
00092 
00093   const char * formatBTime( const std::time_t &);
00094   std::vector<BSTrkParameters> fBSvector;
00095   reco::BeamSpot fbeamspot;
00096   reco::BeamSpot fbeamWidthFit;
00097   std::map< int, reco::BeamSpot> fbspotPVMap;
00098   BSFitter *fmyalgo;
00099   std::ofstream fasciiFile;
00100   std::ofstream fasciiDIP;
00101 
00102   bool debug_;
00103   bool appendRunTxt_;
00104   edm::InputTag tracksLabel_;
00105   edm::InputTag vertexLabel_;
00106   bool writeTxt_;
00107   bool writeDIPTxt_;
00108   std::string outputTxt_;
00109   std::string outputDIPTxt_;
00110   double trk_MinpT_;
00111   double trk_MaxZ_;
00112   double trk_MaxEta_;
00113   double trk_MaxIP_;
00114   int trk_MinNTotLayers_;
00115   int trk_MinNPixLayers_;
00116   double trk_MaxNormChi2_;
00117   std::vector<std::string> trk_Algorithm_;
00118   std::vector<std::string> trk_Quality_;
00119   std::vector<reco::TrackBase::TrackQuality> quality_;
00120   std::vector<reco::TrackBase::TrackAlgorithm> algorithm_;
00121   double inputBeamWidth_;
00122   double convergence_;
00123   int ftotal_tracks;
00124   int min_Ntrks_;
00125   bool isMuon_;
00126   bool fitted_;
00127   bool ffilename_changed;
00128 
00129   // ntuple
00130   TH1F* h1z;
00131   bool saveNtuple_;
00132   bool saveBeamFit_;
00133   bool savePVVertices_;
00134   std::string outputfilename_;
00135   TFile* file_;
00136   TTree* ftree_;
00137   double ftheta;
00138   double fpt;
00139   double feta;
00140   int    fcharge;
00141   double fnormchi2;
00142   double fphi0;
00143   double fd0;
00144   double fd0bs;
00145   double fsigmad0;
00146   double fz0;
00147   double fsigmaz0;
00148   int fnTotLayerMeas;
00149   int fnPixelLayerMeas;
00150   int fnStripLayerMeas;
00151   int fnTIBLayerMeas;
00152   int fnTIDLayerMeas;
00153   int fnTOBLayerMeas;
00154   int fnTECLayerMeas;
00155   int fnPXBLayerMeas;
00156   int fnPXFLayerMeas;
00157   double fd0phi_chi2;
00158   double fd0phi_d0;
00159   double fcov[7][7];
00160   double fvx;
00161   double fvy;
00162   int frun;
00163   int flumi;
00164   bool fquality;
00165   bool falgo;
00166   bool fpvValid;
00167   double fpvx, fpvy, fpvz;
00168   std::time_t freftime[2];
00169 
00170   //beam fit results
00171   TTree* ftreeFit_;
00172   int frunFit;
00173   int fbeginLumiOfFit;
00174   int fendLumiOfFit;
00175   char fbeginTimeOfFit[32];
00176   char fendTimeOfFit[32];
00177   double fx;
00178   double fy;
00179   double fz;
00180   double fsigmaZ;
00181   double fdxdz;
00182   double fdydz;
00183   double fxErr;
00184   double fyErr;
00185   double fzErr;
00186   double fsigmaZErr;
00187   double fdxdzErr;
00188   double fdydzErr;
00189   double fwidthX;
00190   double fwidthY;
00191   double fwidthXErr;
00192   double fwidthYErr;
00193 
00194   TH1F *h1ntrks;
00195   TH1F *h1vz_event;
00196   TH1F *h1cutFlow;
00197   int countPass[9];
00198 
00199   PVFitter *MyPVFitter;
00200   TTree* fPVTree_;
00201 
00202 };
00203 
00204 #endif