30 #include "TFitterMinuit.h"
31 #include "Minuit2/FCNBase.h"
122 for (reco::VertexCollection::const_iterator pv = PVCollection->begin(); pv != PVCollection->end(); ++pv ) {
128 if ( pv->isFake() || pv->tracksSize()==0 )
continue;
132 hPVx->Fill( pv->x(), pv->z() );
133 hPVy->Fill( pv->y(), pv->z() );
157 pvData.
posCorr[0] = pv->covariance(0,1)/pv->xError()/pv->yError();
158 pvData.
posCorr[1] = pv->covariance(0,2)/pv->xError()/pv->zError();
159 pvData.
posCorr[2] = pv->covariance(1,2)/pv->yError()/pv->zError();
188 edm::LogInfo(
"PVFitter") <<
" Number of bunch crossings: " <<
bxMap_.size() << std::endl;
192 for (
std::map<
int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore =
bxMap_.begin();
193 pvStore!=
bxMap_.end(); ++pvStore) {
199 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " << (pvStore->second).
size() <<
" in bx: " << pvStore->first << std::endl;
202 edm::LogWarning(
"PVFitter") <<
" not enough PVs, continue" << std::endl;
208 edm::LogInfo(
"PVFitter") <<
"Calculating beam spot with PVs ..." << std::endl;
214 TFitterMinuit minuitx;
215 minuitx.SetMinuitFCN(fcn);
219 minuitx.SetParameter(0,
"x",0.,0.02,-10.,10.);
220 minuitx.SetParameter(1,
"y",0.,0.02,-10.,10.);
221 minuitx.SetParameter(2,
"z",0.,0.20,-30.,30.);
222 minuitx.SetParameter(3,
"ex",0.015,0.01,0.,10.);
223 minuitx.SetParameter(4,
"corrxy",0.,0.02,-1.,1.);
224 minuitx.SetParameter(5,
"ey",0.015,0.01,0.,10.);
225 minuitx.SetParameter(6,
"dxdz",0.,0.0002,-0.1,0.1);
226 minuitx.SetParameter(7,
"dydz",0.,0.0002,-0.1,0.1);
227 minuitx.SetParameter(8,
"ez",1.,0.1,0.,30.);
233 minuitx.FixParameter(4);
234 minuitx.FixParameter(6);
235 minuitx.FixParameter(7);
236 minuitx.FixParameter(9);
237 minuitx.SetMaxIterations(100);
239 minuitx.SetPrintLevel(0);
240 minuitx.CreateMinimizer();
241 ierr = minuitx.Minimize();
243 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
251 minuitx.GetParameter(0)+
sigmaCut_*minuitx.GetParameter(3),
252 minuitx.GetParameter(1)-
sigmaCut_*minuitx.GetParameter(5),
253 minuitx.GetParameter(1)+
sigmaCut_*minuitx.GetParameter(5),
254 minuitx.GetParameter(2)-
sigmaCut_*minuitx.GetParameter(8),
255 minuitx.GetParameter(2)+
sigmaCut_*minuitx.GetParameter(8));
256 ierr = minuitx.Minimize();
258 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
265 minuitx.ReleaseParameter(4);
266 minuitx.ReleaseParameter(6);
267 minuitx.ReleaseParameter(7);
269 ierr = minuitx.Minimize();
271 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
281 fwidthX = minuitx.GetParameter(3);
282 fwidthY = minuitx.GetParameter(5);
283 fwidthZ = minuitx.GetParameter(8);
290 matrix(0,0) =
pow( minuitx.GetParError(0), 2);
291 matrix(1,1) =
pow( minuitx.GetParError(1), 2);
292 matrix(2,2) =
pow( minuitx.GetParError(2), 2);
294 matrix(4,4) =
pow( minuitx.GetParError(6), 2);
295 matrix(5,5) =
pow( minuitx.GetParError(7), 2);
299 minuitx.GetParameter(1),
300 minuitx.GetParameter(2) ),
302 minuitx.GetParameter(6), minuitx.GetParameter(7),
310 edm::LogInfo(
"PVFitter") <<
"3D PV fit done for this bunch crossing."<<std::endl;
313 fit_ok = fit_ok &
true;
322 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " <<
pvStore_.size() << std::endl;
329 TH1F *h1PVx = (TH1F*)
hPVx->ProjectionX(
"h1PVx", 0, -1,
"e");
330 TH1F *h1PVy = (TH1F*)
hPVy->ProjectionX(
"h1PVy", 0, -1,
"e");
331 TH1F *h1PVz = (TH1F*)
hPVx->ProjectionY(
"h1PVz", 0, -1,
"e");
333 h1PVx->Fit(
"gaus",
"QLM0");
334 h1PVy->Fit(
"gaus",
"QLM0");
335 h1PVz->Fit(
"gaus",
"QLM0");
337 TF1 *gausx = h1PVx->GetFunction(
"gaus");
338 TF1 *gausy = h1PVy->GetFunction(
"gaus");
339 TF1 *gausz = h1PVz->GetFunction(
"gaus");
341 fwidthX = gausx->GetParameter(2);
342 fwidthY = gausy->GetParameter(2);
343 fwidthZ = gausz->GetParameter(2);
349 matrix(2,2) = gausz->GetParError(1) * gausz->GetParError(1);
354 gausy->GetParameter(1),
355 gausz->GetParameter(1) ),
370 TFitterMinuit minuitx;
371 minuitx.SetMinuitFCN(fcn);
375 minuitx.SetParameter(0,
"x",0.,0.02,-10.,10.);
376 minuitx.SetParameter(1,
"y",0.,0.02,-10.,10.);
377 minuitx.SetParameter(2,
"z",0.,0.20,-30.,30.);
380 minuitx.SetParameter(3,
"ex",0.005,0.0005,0.0001,0.05);
381 minuitx.SetParameter(4,
"corrxy",0.,0.02,-1.,1.);
384 minuitx.SetParameter(5,
"ey",0.005,0.0005,0.0001,0.05);
385 minuitx.SetParameter(6,
"dxdz",0.,0.0002,-0.1,0.1);
386 minuitx.SetParameter(7,
"dydz",0.,0.0002,-0.1,0.1);
388 minuitx.SetParameter(8,
"ez",1.,0.1,1.0,30.);
394 minuitx.FixParameter(4);
395 minuitx.FixParameter(6);
396 minuitx.FixParameter(7);
397 minuitx.FixParameter(9);
398 minuitx.SetMaxIterations(100);
400 minuitx.SetPrintLevel(0);
401 minuitx.CreateMinimizer();
402 ierr = minuitx.Minimize();
404 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
411 minuitx.GetParameter(0)+
sigmaCut_*minuitx.GetParameter(3),
412 minuitx.GetParameter(1)-
sigmaCut_*minuitx.GetParameter(5),
413 minuitx.GetParameter(1)+
sigmaCut_*minuitx.GetParameter(5),
414 minuitx.GetParameter(2)-
sigmaCut_*minuitx.GetParameter(8),
415 minuitx.GetParameter(2)+
sigmaCut_*minuitx.GetParameter(8));
416 ierr = minuitx.Minimize();
418 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
424 minuitx.ReleaseParameter(4);
425 minuitx.ReleaseParameter(6);
426 minuitx.ReleaseParameter(7);
427 ierr = minuitx.Minimize();
429 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
438 fwidthX = minuitx.GetParameter(3);
439 fwidthY = minuitx.GetParameter(5);
440 fwidthZ = minuitx.GetParameter(8);
447 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
453 matrix(0,0) =
pow( minuitx.GetParError(0), 2);
454 matrix(1,1) =
pow( minuitx.GetParError(1), 2);
455 matrix(2,2) =
pow( minuitx.GetParError(2), 2);
460 minuitx.GetParameter(1),
461 minuitx.GetParameter(2) ),
463 minuitx.GetParameter(6), minuitx.GetParameter(7),
535 unsigned int iwrite(0);
536 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
542 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to "
543 <<
pvStore_.size() <<
" ; new dynamic quality cut = "
544 << 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
void pvData(const BeamSpotFitPVData &pvData)
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 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)