30 #include "TFitterMinuit.h"
31 #include "Minuit2/FCNBase.h"
121 for (reco::VertexCollection::const_iterator pv = PVCollection->begin(); pv != PVCollection->end(); ++pv ) {
127 if ( pv->isFake() || pv->tracksSize()==0 )
continue;
131 hPVx->Fill( pv->x(), pv->z() );
132 hPVy->Fill( pv->y(), pv->z() );
156 pvData.
posCorr[0] = pv->covariance(0,1)/pv->xError()/pv->yError();
157 pvData.
posCorr[1] = pv->covariance(0,2)/pv->xError()/pv->zError();
158 pvData.
posCorr[2] = pv->covariance(1,2)/pv->yError()/pv->zError();
187 edm::LogInfo(
"PVFitter") <<
" Number of bunch crossings: " <<
bxMap_.size() << std::endl;
191 for (
std::map<
int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore =
bxMap_.begin();
192 pvStore!=
bxMap_.end(); ++pvStore) {
198 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " << (pvStore->second).
size() <<
" in bx: " << pvStore->first << std::endl;
201 edm::LogWarning(
"PVFitter") <<
" not enough PVs, continue" << std::endl;
207 edm::LogInfo(
"PVFitter") <<
"Calculating beam spot with PVs ..." << std::endl;
213 TFitterMinuit minuitx;
214 minuitx.SetMinuitFCN(fcn);
218 minuitx.SetParameter(0,
"x",0.,0.02,-10.,10.);
219 minuitx.SetParameter(1,
"y",0.,0.02,-10.,10.);
220 minuitx.SetParameter(2,
"z",0.,0.20,-30.,30.);
221 minuitx.SetParameter(3,
"ex",0.015,0.01,0.,10.);
222 minuitx.SetParameter(4,
"corrxy",0.,0.02,-1.,1.);
223 minuitx.SetParameter(5,
"ey",0.015,0.01,0.,10.);
224 minuitx.SetParameter(6,
"dxdz",0.,0.0002,-0.1,0.1);
225 minuitx.SetParameter(7,
"dydz",0.,0.0002,-0.1,0.1);
226 minuitx.SetParameter(8,
"ez",1.,0.1,0.,30.);
232 minuitx.FixParameter(4);
233 minuitx.FixParameter(6);
234 minuitx.FixParameter(7);
235 minuitx.FixParameter(9);
236 minuitx.SetMaxIterations(100);
238 minuitx.SetPrintLevel(0);
239 minuitx.CreateMinimizer();
240 ierr = minuitx.Minimize();
242 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
250 minuitx.GetParameter(0)+
sigmaCut_*minuitx.GetParameter(3),
251 minuitx.GetParameter(1)-
sigmaCut_*minuitx.GetParameter(5),
252 minuitx.GetParameter(1)+
sigmaCut_*minuitx.GetParameter(5),
253 minuitx.GetParameter(2)-
sigmaCut_*minuitx.GetParameter(8),
254 minuitx.GetParameter(2)+
sigmaCut_*minuitx.GetParameter(8));
255 ierr = minuitx.Minimize();
257 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
264 minuitx.ReleaseParameter(4);
265 minuitx.ReleaseParameter(6);
266 minuitx.ReleaseParameter(7);
268 ierr = minuitx.Minimize();
270 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
280 fwidthX = minuitx.GetParameter(3);
281 fwidthY = minuitx.GetParameter(5);
282 fwidthZ = minuitx.GetParameter(8);
289 matrix(0,0) =
pow( minuitx.GetParError(0), 2);
290 matrix(1,1) =
pow( minuitx.GetParError(1), 2);
291 matrix(2,2) =
pow( minuitx.GetParError(2), 2);
293 matrix(4,4) =
pow( minuitx.GetParError(6), 2);
294 matrix(5,5) =
pow( minuitx.GetParError(7), 2);
298 minuitx.GetParameter(1),
299 minuitx.GetParameter(2) ),
301 minuitx.GetParameter(6), minuitx.GetParameter(7),
309 edm::LogInfo(
"PVFitter") <<
"3D PV fit done for this bunch crossing."<<std::endl;
312 fit_ok = fit_ok &
true;
321 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " <<
pvStore_.size() << std::endl;
328 TH1F *h1PVx = (TH1F*)
hPVx->ProjectionX(
"h1PVx", 0, -1,
"e");
329 TH1F *h1PVy = (TH1F*)
hPVy->ProjectionX(
"h1PVy", 0, -1,
"e");
330 TH1F *h1PVz = (TH1F*)
hPVx->ProjectionY(
"h1PVz", 0, -1,
"e");
332 h1PVx->Fit(
"gaus",
"QLM0");
333 h1PVy->Fit(
"gaus",
"QLM0");
334 h1PVz->Fit(
"gaus",
"QLM0");
336 TF1 *gausx = h1PVx->GetFunction(
"gaus");
337 TF1 *gausy = h1PVy->GetFunction(
"gaus");
338 TF1 *gausz = h1PVz->GetFunction(
"gaus");
340 fwidthX = gausx->GetParameter(2);
341 fwidthY = gausy->GetParameter(2);
342 fwidthZ = gausz->GetParameter(2);
348 matrix(2,2) = gausz->GetParError(1) * gausz->GetParError(1);
353 gausy->GetParameter(1),
354 gausz->GetParameter(1) ),
369 TFitterMinuit minuitx;
370 minuitx.SetMinuitFCN(fcn);
374 minuitx.SetParameter(0,
"x",0.,0.02,-10.,10.);
375 minuitx.SetParameter(1,
"y",0.,0.02,-10.,10.);
376 minuitx.SetParameter(2,
"z",0.,0.20,-30.,30.);
378 minuitx.SetParameter(3,
"ex",0.015,0.01,0.0001,10.);
379 minuitx.SetParameter(4,
"corrxy",0.,0.02,-1.,1.);
381 minuitx.SetParameter(5,
"ey",0.015,0.01,0.0001,10.);
382 minuitx.SetParameter(6,
"dxdz",0.,0.0002,-0.1,0.1);
383 minuitx.SetParameter(7,
"dydz",0.,0.0002,-0.1,0.1);
385 minuitx.SetParameter(8,
"ez",1.,0.1,1.0,30.);
391 minuitx.FixParameter(4);
392 minuitx.FixParameter(6);
393 minuitx.FixParameter(7);
394 minuitx.FixParameter(9);
395 minuitx.SetMaxIterations(100);
397 minuitx.SetPrintLevel(0);
398 minuitx.CreateMinimizer();
399 ierr = minuitx.Minimize();
401 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
408 minuitx.GetParameter(0)+
sigmaCut_*minuitx.GetParameter(3),
409 minuitx.GetParameter(1)-
sigmaCut_*minuitx.GetParameter(5),
410 minuitx.GetParameter(1)+
sigmaCut_*minuitx.GetParameter(5),
411 minuitx.GetParameter(2)-
sigmaCut_*minuitx.GetParameter(8),
412 minuitx.GetParameter(2)+
sigmaCut_*minuitx.GetParameter(8));
413 ierr = minuitx.Minimize();
415 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
421 minuitx.ReleaseParameter(4);
422 minuitx.ReleaseParameter(6);
423 minuitx.ReleaseParameter(7);
424 ierr = minuitx.Minimize();
426 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
435 fwidthX = minuitx.GetParameter(3);
436 fwidthY = minuitx.GetParameter(5);
437 fwidthZ = minuitx.GetParameter(8);
444 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
450 matrix(0,0) =
pow( minuitx.GetParError(0), 2);
451 matrix(1,1) =
pow( minuitx.GetParError(1), 2);
452 matrix(2,2) =
pow( minuitx.GetParError(2), 2);
457 minuitx.GetParameter(1),
458 minuitx.GetParameter(2) ),
460 minuitx.GetParameter(6), minuitx.GetParameter(7),
532 unsigned int iwrite(0);
533 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
539 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to "
540 <<
pvStore_.size() <<
" ; new dynamic quality cut = "
541 << dynamicQualityCut_ << std::endl;
std::vector< double > pvQualities_
math::Error< dimension >::type CovarianceMatrix
T getParameter(std::string const &) const
void setTree(TTree *tree)
std::map< int, std::vector< BeamSpotFitPVData > > bxMap_
void run(unsigned int run)
edm::InputTag vertexLabel_
void compressStore()
reduce size of primary vertex cache by increasing quality limit
int bunchCrossing() const
edm::LuminosityBlockNumber_t luminosityBlock() const
math::XYZPoint Point
point in the space
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
double dynamicQualityCut_
void setType(BeamType type)
set beam type
void bunchCrossing(unsigned int bunchCrossing)
void lumi(unsigned int lumi)
std::vector< BeamSpotFitPVData > pvStore_
void readEvent(const edm::Event &iEvent)
void setBeamWidthY(double v)
BeamSpotTreeData theBeamSpotTreeData_
bool fFitPerBunchCrossing
std::map< int, reco::BeamSpot > fbspotMap
double pvQuality(const reco::Vertex &pv) const
vertex quality measure
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
unsigned int maxNrVertices_
unsigned int minVtxTracks_
void pvData(BeamSpotFitPVData pvData)
void fcn(int &, double *, double &, double *, int)
unsigned int minNrVertices_
void setLimits(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax)
void setBeamWidthX(double v)
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)