CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BeamFitter.h
Go to the documentation of this file.
1 #ifndef BeamFitter_H
2 #define BeamFitter_H
3 
28 
29 // ROOT
30 #include "TFile.h"
31 #include "TTree.h"
32 #include "TH1F.h"
33 
34 #include <fstream>
35 
36 namespace edm {class ConsumesCollector;}
37 
38 class BeamFitter {
39  public:
41  BeamFitter(const edm::ParameterSet& iConfig, edm::ConsumesCollector &&iColl);
42  virtual ~BeamFitter();
43 
44  void readEvent(const edm::Event& iEvent);
45 
46  bool runFitter();
47  bool runBeamWidthFitter();
48  bool runPVandTrkFitter();
49  bool runFitterNoTxt();
50 
52  void runAllFitter();
53  void resetTrkVector() { fBSvector.clear(); }
54  void resetTotTrk() { ftotal_tracks=0; }
56  void resetRefTime() { freftime[0] = freftime[1] = 0; }
57  void setRefTime(time_t t0, time_t t1) {
58  freftime[0] = t0;
59  freftime[1] = t1;
60  // Make sure the string representation of the time
61  // is up-to-date
62  updateBTime();
63  }
64 
65  std::pair<time_t,time_t> getRefTime(){
66  return std::make_pair(freftime[0], freftime[1]);
67  }
68 
70 
71  //---these are added to fasciliate BeamMonitor stuff for DIP
72  std::size_t getPVvectorSize() {return (MyPVFitter->getpvStore()).size(); }
73  //sc
74  void resizeBSvector(unsigned int nsize){
75  fBSvector.erase(fBSvector.begin(),fBSvector.begin()+nsize);
76  }
77 
78  //ssc
79  void resizePVvector(unsigned int npvsize){
80  MyPVFitter->resizepvStore(npvsize);
81  }
82 
83  //ssc
84  void SetPVInfo(const std::vector<float> &v1_){
85  ForDIPPV_.clear();
86  ForDIPPV_.assign( v1_.begin(), v1_.end() );
87  }
88 
89 //----------------
90 
91  void dumpTxtFile(std::string &,bool);
92  void dumpBWTxtFile(std::string &);
93  void write2DB();
95  std::map<int, reco::BeamSpot> getBeamSpotMap() { return fbspotPVMap; }
96  std::vector<BSTrkParameters> getBSvector() { return fBSvector; }
97  TH1F * getCutFlow() { return h1cutFlow; }
98  void subtractFromCutFlow(const TH1F* toSubtract) {
99  h1cutFlow->Add(toSubtract, -1.0);
100  for (unsigned int i=0; i<sizeof(countPass)/sizeof(countPass[0]); i++){
101  countPass[i] = h1cutFlow->GetBinContent(i+1);
102  }
103  }
104 
105  void resetCutFlow() {
106  h1cutFlow->Reset();
107  ftotal_tracks = 0;
108  for (unsigned int i=0; i<sizeof(countPass)/sizeof(countPass[0]); i++)
109  countPass[i]=0;
110  }
111 
112  //ssc
113  int getRunNumber() {
114  return frun;
115  }
116 
117  std::pair<int,int> getFitLSRange() {
118  return std::make_pair(fbeginLumiOfFit, fendLumiOfFit);
119  }
120  void setFitLSRange(int ls0,int ls1) {
121  fbeginLumiOfFit = ls0;
122  fendLumiOfFit = ls1;
123  }
124  void setRun( int run) { frun = run; }
125 
126  int getNTracks() {
127  return fBSvector.size();
128  }
129  int getNPVs() {
130  return MyPVFitter->getNPVs();
131  }
132  const std::map<int, int> &getNPVsperBX() {
133  return MyPVFitter->getNPVsperBX();
134  }
135  private:
136 
137  const char * formatBTime( const std::time_t &);
138  // Update the fbeginTimeOfFit etc from the refTime
139  void updateBTime();
140  std::vector<BSTrkParameters> fBSvector;
143  std::map< int, reco::BeamSpot> fbspotPVMap;
145  std::ofstream fasciiFile;
146  std::ofstream fasciiDIP;
147 
148  bool debug_;
153  bool writeTxt_;
158  double trk_MinpT_;
159  double trk_MaxZ_;
160  double trk_MaxEta_;
161  double trk_MaxIP_;
165  std::vector<std::string> trk_Algorithm_;
166  std::vector<std::string> trk_Quality_;
167  std::vector<reco::TrackBase::TrackQuality> quality_;
168  std::vector<reco::TrackBase::TrackAlgorithm> algorithm_;
170  double convergence_;
173  bool isMuon_;
174  bool fitted_;
176 
177  //ssc
178  std::vector<float> ForDIPPV_;
179 
180 
181  // ntuple
182  TH1F* h1z;
187  TFile* file_;
188  TTree* ftree_;
189  double ftheta;
190  double fpt;
191  double feta;
192  int fcharge;
193  double fnormchi2;
194  double fphi0;
195  double fd0;
196  double fd0bs;
197  double fsigmad0;
198  double fz0;
199  double fsigmaz0;
209  double fd0phi_chi2;
210  double fd0phi_d0;
211  double fcov[7][7];
212  double fvx;
213  double fvy;
214  int frun;
215  int flumi;
216  bool fquality;
217  bool falgo;
218  bool fpvValid;
219  double fpvx, fpvy, fpvz;
220  std::time_t freftime[2];
221 
222  //beam fit results
223  TTree* ftreeFit_;
224  int frunFit;
227  char fbeginTimeOfFit[32];
228  char fendTimeOfFit[32];
229  double fx;
230  double fy;
231  double fz;
232  double fsigmaZ;
233  double fdxdz;
234  double fdydz;
235  double fxErr;
236  double fyErr;
237  double fzErr;
238  double fsigmaZErr;
239  double fdxdzErr;
240  double fdydzErr;
241  double fwidthX;
242  double fwidthY;
243  double fwidthXErr;
244  double fwidthYErr;
245 
246  TH1F *h1ntrks;
247  TH1F *h1vz_event;
248  TH1F *h1cutFlow;
249  int countPass[9];
250 
252  TTree* fPVTree_;
253 
254 };
255 
256 #endif
int getNPVs()
Definition: BeamFitter.h:129
double trk_MaxZ_
Definition: BeamFitter.h:159
double trk_MaxEta_
Definition: BeamFitter.h:160
reco::BeamSpot fbeamspot
Definition: BeamFitter.h:141
double fwidthXErr
Definition: BeamFitter.h:243
int i
Definition: DBlmapReader.cc:9
double fwidthX
Definition: BeamFitter.h:241
std::vector< std::string > trk_Algorithm_
Definition: BeamFitter.h:165
const std::map< int, int > & getNPVsperBX()
Definition: BeamFitter.h:132
int fendLumiOfFit
Definition: BeamFitter.h:226
double fwidthY
Definition: BeamFitter.h:242
int countPass[9]
Definition: BeamFitter.h:249
int getNTracks()
Definition: BeamFitter.h:126
const std::map< int, int > & getNPVsperBX()
Definition: PVFitter.h:122
bool isMuon_
Definition: BeamFitter.h:173
bool runPVandTrkFitter()
Definition: BeamFitter.cc:410
void write2DB()
Definition: BeamFitter.cc:740
char fendTimeOfFit[32]
Definition: BeamFitter.h:228
void setRun(int run)
Definition: BeamFitter.h:124
double fdxdz
Definition: BeamFitter.h:233
std::vector< BSTrkParameters > getBSvector()
Definition: BeamFitter.h:96
double fx
Definition: BeamFitter.h:229
double fnormchi2
Definition: BeamFitter.h:193
bool ffilename_changed
Definition: BeamFitter.h:175
bool debug_
Definition: BeamFitter.h:148
void subtractFromCutFlow(const TH1F *toSubtract)
Definition: BeamFitter.h:98
bool runBeamWidthFitter()
Definition: BeamFitter.cc:591
TH1F * h1z
Definition: BeamFitter.h:182
int fnTOBLayerMeas
Definition: BeamFitter.h:205
std::size_t getPVvectorSize()
Definition: BeamFitter.h:72
double feta
Definition: BeamFitter.h:191
std::vector< std::string > trk_Quality_
Definition: BeamFitter.h:166
double convergence_
Definition: BeamFitter.h:170
double trk_MaxNormChi2_
Definition: BeamFitter.h:164
void dumpBWTxtFile(std::string &)
Definition: BeamFitter.cc:626
void resetTrkVector()
Definition: BeamFitter.h:53
double fsigmaZErr
Definition: BeamFitter.h:238
TH1F * h1vz_event
Definition: BeamFitter.h:247
const char * formatBTime(const std::time_t &)
Definition: BeamFitter.cc:30
double fvy
Definition: BeamFitter.h:213
BSFitter * fmyalgo
Definition: BeamFitter.h:144
int fnPixelLayerMeas
Definition: BeamFitter.h:201
void readEvent(const edm::Event &iEvent)
Definition: BeamFitter.cc:224
reco::BeamSpot getBeamWidth()
Definition: BeamFitter.h:51
double fphi0
Definition: BeamFitter.h:194
std::ofstream fasciiDIP
Definition: BeamFitter.h:146
std::map< int, reco::BeamSpot > getBeamSpotMap()
Definition: BeamFitter.h:95
reco::BeamSpot fbeamWidthFit
Definition: BeamFitter.h:142
std::time_t freftime[2]
Definition: BeamFitter.h:220
PVFitter * MyPVFitter
Definition: BeamFitter.h:251
std::vector< BSTrkParameters > fBSvector
Definition: BeamFitter.h:140
int fnTotLayerMeas
Definition: BeamFitter.h:200
std::string outputTxt_
Definition: BeamFitter.h:156
double fpvx
Definition: BeamFitter.h:219
int iEvent
Definition: GenABIO.cc:243
double fdxdzErr
Definition: BeamFitter.h:239
double trk_MaxIP_
Definition: BeamFitter.h:161
bool runFitter()
Definition: BeamFitter.cc:580
bool runFitterNoTxt()
Definition: BeamFitter.cc:512
TFile * file_
Definition: BeamFitter.h:187
TTree * ftree_
Definition: BeamFitter.h:188
double fyErr
Definition: BeamFitter.h:236
bool falgo
Definition: BeamFitter.h:217
double fd0phi_chi2
Definition: BeamFitter.h:209
int ftotal_tracks
Definition: BeamFitter.h:171
int min_Ntrks_
Definition: BeamFitter.h:172
TH1F * h1cutFlow
Definition: BeamFitter.h:248
double fdydz
Definition: BeamFitter.h:234
TTree * fPVTree_
Definition: BeamFitter.h:252
std::vector< reco::TrackBase::TrackAlgorithm > algorithm_
Definition: BeamFitter.h:168
TH1F * h1ntrks
Definition: BeamFitter.h:246
char fbeginTimeOfFit[32]
Definition: BeamFitter.h:227
double fpvz
Definition: BeamFitter.h:219
double fz0
Definition: BeamFitter.h:198
double ftheta
Definition: BeamFitter.h:189
void setFitLSRange(int ls0, int ls1)
Definition: BeamFitter.h:120
double fd0
Definition: BeamFitter.h:195
bool fquality
Definition: BeamFitter.h:216
std::pair< time_t, time_t > getRefTime()
Definition: BeamFitter.h:65
double fy
Definition: BeamFitter.h:230
void resetLSRange()
Definition: BeamFitter.h:55
int fnStripLayerMeas
Definition: BeamFitter.h:202
double fwidthYErr
Definition: BeamFitter.h:244
double fxErr
Definition: BeamFitter.h:235
bool appendRunTxt_
Definition: BeamFitter.h:149
int fnTIDLayerMeas
Definition: BeamFitter.h:204
void SetPVInfo(const std::vector< float > &v1_)
Definition: BeamFitter.h:84
bool saveNtuple_
Definition: BeamFitter.h:183
std::vector< BeamSpotFitPVData > getpvStore()
Definition: PVFitter.h:61
double fsigmaZ
Definition: BeamFitter.h:232
int fbeginLumiOfFit
Definition: BeamFitter.h:225
std::string outputfilename_
Definition: BeamFitter.h:186
bool writeTxt_
Definition: BeamFitter.h:153
int getRunNumber()
Definition: BeamFitter.h:113
double fsigmad0
Definition: BeamFitter.h:197
std::string outputDIPTxt_
Definition: BeamFitter.h:157
bool fpvValid
Definition: BeamFitter.h:218
double fdydzErr
Definition: BeamFitter.h:240
virtual ~BeamFitter()
Definition: BeamFitter.cc:196
void dumpTxtFile(std::string &, bool)
Definition: BeamFitter.cc:636
std::vector< float > ForDIPPV_
Definition: BeamFitter.h:178
void resizeBSvector(unsigned int nsize)
Definition: BeamFitter.h:74
double inputBeamWidth_
Definition: BeamFitter.h:169
bool savePVVertices_
Definition: BeamFitter.h:185
void resizepvStore(unsigned int rmSize)
Definition: PVFitter.h:109
void updateBTime()
Definition: BeamFitter.cc:40
void runAllFitter()
Definition: BeamFitter.cc:780
void resetAll()
Definition: PVFitter.h:80
bool writeDIPTxt_
Definition: BeamFitter.h:154
double fvx
Definition: BeamFitter.h:212
double fpt
Definition: BeamFitter.h:190
std::map< int, reco::BeamSpot > fbspotPVMap
Definition: BeamFitter.h:143
TH1F * getCutFlow()
Definition: BeamFitter.h:97
double fcov[7][7]
Definition: BeamFitter.h:211
void resetPVFitter()
Definition: BeamFitter.h:69
std::vector< reco::TrackBase::TrackQuality > quality_
Definition: BeamFitter.h:167
void resizePVvector(unsigned int npvsize)
Definition: BeamFitter.h:79
double fsigmaz0
Definition: BeamFitter.h:199
int trk_MinNPixLayers_
Definition: BeamFitter.h:163
int fnTIBLayerMeas
Definition: BeamFitter.h:203
TTree * ftreeFit_
Definition: BeamFitter.h:223
int getNPVs()
Definition: PVFitter.h:120
void resetCutFlow()
Definition: BeamFitter.h:105
double fd0bs
Definition: BeamFitter.h:196
edm::EDGetTokenT< reco::TrackCollection > tracksToken_
Definition: BeamFitter.h:150
void setRefTime(time_t t0, time_t t1)
Definition: BeamFitter.h:57
double trk_MinpT_
Definition: BeamFitter.h:158
bool writeDIPBadFit_
Definition: BeamFitter.h:155
double fd0phi_d0
Definition: BeamFitter.h:210
std::ofstream fasciiFile
Definition: BeamFitter.h:145
std::pair< int, int > getFitLSRange()
Definition: BeamFitter.h:117
double fzErr
Definition: BeamFitter.h:237
int fnPXBLayerMeas
Definition: BeamFitter.h:207
tuple size
Write out results.
reco::BeamSpot getBeamSpot()
Definition: BeamFitter.h:94
double fpvy
Definition: BeamFitter.h:219
bool saveBeamFit_
Definition: BeamFitter.h:184
edm::EDGetTokenT< edm::View< reco::Vertex > > vertexToken_
Definition: BeamFitter.h:151
double fz
Definition: BeamFitter.h:231
bool fitted_
Definition: BeamFitter.h:174
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
Definition: BeamFitter.h:152
int fnPXFLayerMeas
Definition: BeamFitter.h:208
void resetTotTrk()
Definition: BeamFitter.h:54
int fnTECLayerMeas
Definition: BeamFitter.h:206
int trk_MinNTotLayers_
Definition: BeamFitter.h:162
void resetRefTime()
Definition: BeamFitter.h:56