CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/RecoVertex/BeamSpotProducer/interface/PVFitter.h

Go to the documentation of this file.
00001 #ifndef PVFitter_H
00002 #define PVFitter_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 
00025 #include "RecoVertex/BeamSpotProducer/interface/BeamSpotTreeData.h"
00026 #include "RecoVertex/BeamSpotProducer/interface/BeamSpotFitPVData.h"
00027 
00028 // ROOT
00029 #include "TFile.h"
00030 #include "TTree.h"
00031 #include "TH2F.h"
00032 
00033 #include <fstream>
00034 
00035 namespace reco {
00036   class Vertex;
00037 }
00038 
00039 class PVFitter {
00040  public:
00041   PVFitter() {}
00042   PVFitter(const edm::ParameterSet& iConfig);
00043   virtual ~PVFitter();
00044 
00045   void readEvent(const edm::Event& iEvent);
00046   void setTree(TTree* tree);
00047   
00048   double getWidthX() { return fwidthX; }
00049   double getWidthY() { return fwidthY; }
00050   double getWidthZ() { return fwidthZ; }
00051   double getWidthXerr() { return fwidthXerr; }
00052   double getWidthYerr() { return fwidthYerr; }
00053   double getWidthZerr() { return fwidthZerr; }
00054   //ssc
00055   std::vector<BeamSpotFitPVData> getpvStore() { return pvStore_; } 
00056  
00057   void FitPerBunchCrossing() { fFitPerBunchCrossing = true; }
00058   bool runBXFitter();
00059   bool runFitter(); 
00060   void resetLSRange() { fbeginLumiOfFit=fendLumiOfFit=-1; }
00061   void resetRefTime() { freftime[0] = freftime[1] = 0; }
00062   //ssc
00063    void setRefTime(std::time_t t0,std::time_t t1) {
00064     freftime[0] = t0;
00065     freftime[1] = t1;
00066   }
00067    void setFitLSRange(int ls0,int ls1) {
00068     fbeginLumiOfFit = ls0;
00069     fendLumiOfFit = ls1;
00070   }
00071 
00072 
00073   void dumpTxtFile();
00074   void resetAll() {
00075     resetLSRange();
00076     resetRefTime();
00077     pvStore_.clear();
00078     bxMap_.clear();
00079     dynamicQualityCut_ = 1.e30;
00080     hPVx->Reset();
00081     hPVy->Reset();
00082     fbeamspot = reco::BeamSpot();
00083     fbspotMap.clear();
00084   };
00085   reco::BeamSpot getBeamSpot() { return fbeamspot; }
00086   std::map<int, reco::BeamSpot> getBeamSpotMap() { return fbspotMap; }
00087   bool IsFitPerBunchCrossing() { return fFitPerBunchCrossing; }
00088   int* getFitLSRange() {
00089     int *tmp=new int[2];
00090     tmp[0] = fbeginLumiOfFit;
00091     tmp[1] = fendLumiOfFit;
00092     return tmp;
00093   }
00094  //ssc
00095  time_t* getRefTime(){
00096    time_t *tmptime=new time_t[2];
00097    tmptime[0]=freftime[0];
00098    tmptime[1]=freftime[1];
00099    return tmptime;
00100   }
00101 
00102 //ssc
00103  void resizepvStore(unsigned int rmSize ){
00104   pvStore_.erase(pvStore_.begin(), pvStore_.begin()+rmSize);
00105   }
00106 
00107  
00109   void compressStore ();
00111   double pvQuality (const reco::Vertex& pv) const;
00113   double pvQuality (const BeamSpotFitPVData& pv) const;
00114   int getNPVs() { return pvStore_.size(); }
00115   
00116   const std::map<int, int> &getNPVsperBX() {
00117     
00118     npvsmap_.clear();
00119 
00120     for ( std::map<int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore = bxMap_.begin(); 
00121           pvStore!=bxMap_.end(); ++pvStore) {
00122 
00123       //std::cout << "bx " << pvStore->first << " NPVs = " << (pvStore->second).size() << std::endl;
00124       npvsmap_[ pvStore->first ] = (pvStore->second).size();
00125 
00126     }
00127     return npvsmap_;
00128   }
00129 
00130  private:
00131 
00132   std::map<int, int> npvsmap_;
00133   reco::BeamSpot fbeamspot;
00134   std::map<int,reco::BeamSpot> fbspotMap;
00135   bool fFitPerBunchCrossing;
00136 
00137   std::ofstream fasciiFile;
00138 
00139   bool debug_;
00140   bool do3DFit_;
00141   edm::InputTag vertexLabel_;
00142   bool writeTxt_;
00143   std::string outputTxt_;
00144 
00145   unsigned int maxNrVertices_;
00146   unsigned int minNrVertices_;
00147   double minVtxNdf_;
00148   double maxVtxNormChi2_;
00149   unsigned int minVtxTracks_;
00150   double minVtxWgt_;
00151   double maxVtxR_;
00152   double maxVtxZ_;
00153   double errorScale_;
00154   double sigmaCut_;         
00155   
00156   int frun;
00157   int flumi;
00158   std::time_t freftime[2];
00159 
00160   TH2F* hPVx; TH2F* hPVy; 
00161 
00162   TTree* ftree_;
00163   //bool saveNtuple_;
00164   //bool saveBeamFit_;
00165   //std::string outputfilename_;
00166   //TFile* file_;
00167   //TTree* ftree_;
00168 
00169   //beam fit results
00170   //TTree* ftreeFit_;
00171   int frunFit;
00172   int fbeginLumiOfFit;
00173   int fendLumiOfFit;
00174   char fbeginTimeOfFit[32];
00175   char fendTimeOfFit[32];
00176   double fwidthX;
00177   double fwidthY;
00178   double fwidthZ;
00179   double fwidthXerr;
00180   double fwidthYerr;
00181   double fwidthZerr;
00182   
00183   double fx;
00184   double fy;
00185   double fz;
00186   double fsigmaZ;
00187   double fdxdz;
00188   double fdydz;
00189   double fxErr;
00190   double fyErr;
00191   double fzErr;
00192   double fsigmaZErr;
00193   double fdxdzErr;
00194   double fdydzErr;
00195 
00196   std::vector<BeamSpotFitPVData> pvStore_; //< cache for PV data
00197   std::map< int, std::vector<BeamSpotFitPVData> > bxMap_; // store PV data as a function of bunch crossings
00198   double dynamicQualityCut_;               //< quality cut for vertices (dynamic adjustment)
00199   std::vector<double> pvQualities_;        //< working space for PV store adjustement
00200 
00201   BeamSpotTreeData theBeamSpotTreeData_;
00202 };
00203 
00204 #endif