CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/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(time_t t0, time_t t1) {
00053     freftime[0] = t0;
00054     freftime[1] = t1;
00055     // Make sure the string representation of the time
00056     // is up-to-date
00057     updateBTime();
00058   }
00059 
00060   std::pair<time_t,time_t> getRefTime(){
00061     return std::make_pair(freftime[0], freftime[1]);
00062   }
00063 
00064   void resetPVFitter() { MyPVFitter->resetAll(); }
00065 
00066   //---these are added to fasciliate BeamMonitor stuff for DIP
00067   std::size_t  getPVvectorSize() {return (MyPVFitter->getpvStore()).size(); }
00068   //sc
00069   void resizeBSvector(unsigned int nsize){
00070     fBSvector.erase(fBSvector.begin(),fBSvector.begin()+nsize);
00071    }
00072 
00073   //ssc
00074   void resizePVvector(unsigned int npvsize){
00075        MyPVFitter->resizepvStore(npvsize);
00076    }
00077 
00078  //ssc
00079   void SetPVInfo(std::vector<float> v1_){
00080      ForDIPPV_.clear();
00081      ForDIPPV_.assign( v1_.begin(), v1_.end() );
00082     }
00083 
00084 //----------------
00085 
00086   void dumpTxtFile(std::string &,bool);
00087   void dumpBWTxtFile(std::string &);
00088   void write2DB();
00089   reco::BeamSpot getBeamSpot() { return fbeamspot; }
00090   std::map<int, reco::BeamSpot> getBeamSpotMap() { return fbspotPVMap; }
00091   std::vector<BSTrkParameters> getBSvector() { return fBSvector; }
00092   TH1F * getCutFlow() { return h1cutFlow; }
00093   void subtractFromCutFlow(const TH1F* toSubtract) {
00094     h1cutFlow->Add(toSubtract, -1.0);
00095     for (unsigned int i=0; i<sizeof(countPass)/sizeof(countPass[0]); i++){
00096       countPass[i] = h1cutFlow->GetBinContent(i+1);
00097     }
00098   }
00099 
00100   void resetCutFlow() {
00101     h1cutFlow->Reset();
00102     ftotal_tracks = 0;
00103     for (unsigned int i=0; i<sizeof(countPass)/sizeof(countPass[0]); i++)
00104       countPass[i]=0;
00105   }
00106 
00107   //ssc
00108   int getRunNumber() {
00109     return frun;
00110   }
00111 
00112   std::pair<int,int> getFitLSRange() {
00113     return std::make_pair(fbeginLumiOfFit, fendLumiOfFit);
00114   }
00115   void setFitLSRange(int ls0,int ls1) {
00116     fbeginLumiOfFit = ls0;
00117     fendLumiOfFit = ls1;
00118   }
00119   void setRun( int run) { frun = run; }
00120 
00121   int getNTracks() {
00122     return fBSvector.size();
00123   }
00124   int getNPVs() {
00125     return MyPVFitter->getNPVs();
00126   }
00127   const std::map<int, int> &getNPVsperBX() {
00128     return MyPVFitter->getNPVsperBX();
00129   }
00130  private:
00131 
00132   const char * formatBTime( const std::time_t &);
00133   // Update the fbeginTimeOfFit etc from the refTime
00134   void updateBTime();
00135   std::vector<BSTrkParameters> fBSvector;
00136   reco::BeamSpot fbeamspot;
00137   reco::BeamSpot fbeamWidthFit;
00138   std::map< int, reco::BeamSpot> fbspotPVMap;
00139   BSFitter *fmyalgo;
00140   std::ofstream fasciiFile;
00141   std::ofstream fasciiDIP;
00142 
00143   bool debug_;
00144   bool appendRunTxt_;
00145   edm::InputTag tracksLabel_;
00146   edm::InputTag vertexLabel_;
00147   bool writeTxt_;
00148   bool writeDIPTxt_;
00149   bool writeDIPBadFit_;
00150   std::string outputTxt_;
00151   std::string outputDIPTxt_;
00152   double trk_MinpT_;
00153   double trk_MaxZ_;
00154   double trk_MaxEta_;
00155   double trk_MaxIP_;
00156   int trk_MinNTotLayers_;
00157   int trk_MinNPixLayers_;
00158   double trk_MaxNormChi2_;
00159   std::vector<std::string> trk_Algorithm_;
00160   std::vector<std::string> trk_Quality_;
00161   std::vector<reco::TrackBase::TrackQuality> quality_;
00162   std::vector<reco::TrackBase::TrackAlgorithm> algorithm_;
00163   double inputBeamWidth_;
00164   double convergence_;
00165   int ftotal_tracks;
00166   int min_Ntrks_;
00167   bool isMuon_;
00168   bool fitted_;
00169   bool ffilename_changed;
00170    
00171   //ssc
00172   std::vector<float> ForDIPPV_; 
00173   
00174 
00175   // ntuple
00176   TH1F* h1z;
00177   bool saveNtuple_;
00178   bool saveBeamFit_;
00179   bool savePVVertices_;
00180   std::string outputfilename_;
00181   TFile* file_;
00182   TTree* ftree_;
00183   double ftheta;
00184   double fpt;
00185   double feta;
00186   int    fcharge;
00187   double fnormchi2;
00188   double fphi0;
00189   double fd0;
00190   double fd0bs;
00191   double fsigmad0;
00192   double fz0;
00193   double fsigmaz0;
00194   int fnTotLayerMeas;
00195   int fnPixelLayerMeas;
00196   int fnStripLayerMeas;
00197   int fnTIBLayerMeas;
00198   int fnTIDLayerMeas;
00199   int fnTOBLayerMeas;
00200   int fnTECLayerMeas;
00201   int fnPXBLayerMeas;
00202   int fnPXFLayerMeas;
00203   double fd0phi_chi2;
00204   double fd0phi_d0;
00205   double fcov[7][7];
00206   double fvx;
00207   double fvy;
00208   int frun;
00209   int flumi;
00210   bool fquality;
00211   bool falgo;
00212   bool fpvValid;
00213   double fpvx, fpvy, fpvz;
00214   std::time_t freftime[2];
00215 
00216   //beam fit results
00217   TTree* ftreeFit_;
00218   int frunFit;
00219   int fbeginLumiOfFit;
00220   int fendLumiOfFit;
00221   char fbeginTimeOfFit[32];
00222   char fendTimeOfFit[32];
00223   double fx;
00224   double fy;
00225   double fz;
00226   double fsigmaZ;
00227   double fdxdz;
00228   double fdydz;
00229   double fxErr;
00230   double fyErr;
00231   double fzErr;
00232   double fsigmaZErr;
00233   double fdxdzErr;
00234   double fdydzErr;
00235   double fwidthX;
00236   double fwidthY;
00237   double fwidthXErr;
00238   double fwidthYErr;
00239 
00240   TH1F *h1ntrks;
00241   TH1F *h1vz_event;
00242   TH1F *h1cutFlow;
00243   int countPass[9];
00244 
00245   PVFitter *MyPVFitter;
00246   TTree* fPVTree_;
00247 
00248 };
00249 
00250 #endif