34 #include "Minuit2/FCNBase.h"
35 #include "Minuit2/FunctionMinimum.h"
36 #include "Minuit2/MnMigrad.h"
37 #include "Minuit2/MnPrint.h"
73 .getUntrackedParameter<edm::InputTag>(
"VertexCollection",
141 for (reco::VertexCollection::const_iterator
pv = PVCollection->begin();
pv != PVCollection->end(); ++
pv ) {
147 if (
pv->isFake() ||
pv->tracksSize()==0 )
continue;
176 pvData.
posCorr[0] =
pv->covariance(0,1)/
pv->xError()/
pv->yError();
177 pvData.
posCorr[1] =
pv->covariance(0,2)/
pv->xError()/
pv->zError();
178 pvData.
posCorr[2] =
pv->covariance(1,2)/
pv->yError()/
pv->zError();
207 using namespace ROOT::Minuit2;
209 edm::LogInfo(
"PVFitter") <<
" Number of bunch crossings: " <<
bxMap_.size() << std::endl;
213 for (
std::map<
int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore =
bxMap_.begin();
214 pvStore!=
bxMap_.end(); ++pvStore) {
220 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " << (pvStore->second).
size() <<
" in bx: " << pvStore->first << std::endl;
223 edm::LogWarning(
"PVFitter") <<
" not enough PVs, continue" << std::endl;
229 edm::LogInfo(
"PVFitter") <<
"Calculating beam spot with PVs ..." << std::endl;
238 MnUserParameters upar;
239 upar.Add(
"x", 0., 0.02, -10., 10.);
240 upar.Add(
"y", 0., 0.02, -10., 10.);
241 upar.Add(
"z", 0., 0.20, -30., 30.);
242 upar.Add(
"ex", 0.015, 0.01, 0., 10.);
243 upar.Add(
"corrxy", 0., 0.02, -1., 1.);
244 upar.Add(
"ey", 0.015, 0.01, 0., 10.);
245 upar.Add(
"dxdz", 0., 0.0002, -0.1, 0.1);
246 upar.Add(
"dydz", 0., 0.0002, -0.1, 0.1);
247 upar.Add(
"ez", 1., 0.1, 0., 30.);
250 MnMigrad migrad(*fcn, upar);
259 FunctionMinimum ierr = migrad();
260 if ( !ierr.IsValid() ) {
261 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
275 if ( !ierr.IsValid() ) {
276 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
287 if ( !ierr.IsValid() ) {
288 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
319 upar.Value(6), upar.Value(7),
327 edm::LogInfo(
"PVFitter") <<
"3D PV fit done for this bunch crossing."<<std::endl;
329 fit_ok = fit_ok &
true;
338 using namespace ROOT::Minuit2;
339 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " <<
pvStore_.size() << std::endl;
346 TH1F *h1PVx = (TH1F*)
hPVx->ProjectionX(
"h1PVx", 0, -1,
"e");
347 TH1F *h1PVy = (TH1F*)
hPVy->ProjectionX(
"h1PVy", 0, -1,
"e");
348 TH1F *h1PVz = (TH1F*)
hPVx->ProjectionY(
"h1PVz", 0, -1,
"e");
351 TF1 gaus(
"localGaus",
"gaus");
353 h1PVx->Fit(&gaus,
"QLM0");
354 h1PVy->Fit(&gaus,
"QLM0");
355 h1PVz->Fit(&gaus,
"QLM0");
357 TF1 *gausx = h1PVx->GetFunction(
"localGaus");
358 TF1 *gausy = h1PVy->GetFunction(
"localGaus");
359 TF1 *gausz = h1PVz->GetFunction(
"localGaus");
361 fwidthX = gausx->GetParameter(2);
362 fwidthY = gausy->GetParameter(2);
363 fwidthZ = gausz->GetParameter(2);
369 matrix(2,2) = gausz->GetParError(1) * gausz->GetParError(1);
374 gausy->GetParameter(1),
375 gausz->GetParameter(1) ),
393 MnUserParameters upar;
394 upar.Add(
"x" , 0. , 0.02 , -10. , 10. );
395 upar.Add(
"y" , 0. , 0.02 , -10. , 10. );
396 upar.Add(
"z" , 0. , 0.20 , -30. , 30. );
397 upar.Add(
"ex" , 0.015 , 0.01 , 0. , 10. );
398 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
399 upar.Add(
"ey" , 0.015 , 0.01 , 0. , 10. );
400 upar.Add(
"dxdz" , 0. , 0.0002 , -0.1 , 0.1 );
401 upar.Add(
"dydz" , 0. , 0.0002 , -0.1 , 0.1 );
402 upar.Add(
"ez" , 1. , 0.1 , 0. , 30. );
404 MnMigrad migrad(*fcn, upar);
412 FunctionMinimum ierr = migrad();
413 if ( !ierr.IsValid() ) {
414 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
423 results = ierr.UserParameters().Params() ;
\
424 errors = ierr.UserParameters().Errors() ;
\
433 if ( !ierr.IsValid() ) {
434 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
444 if ( !ierr.IsValid() ) {
445 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
454 results = ierr.UserParameters().Params() ;
\
455 errors = ierr.UserParameters().Errors() ;
\
466 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
482 results[6], results[7],
554 unsigned int iwrite(0);
555 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
561 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to "
562 <<
pvStore_.size() <<
" ; new dynamic quality cut = "
563 << dynamicQualityCut_ << std::endl;
std::vector< double > pvQualities_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
math::Error< dimension >::type CovarianceMatrix
T getParameter(std::string const &) const
void setTree(TTree *tree)
std::map< int, std::vector< BeamSpotFitPVData > > bxMap_
void initialize(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iColl)
void run(unsigned int run)
void compressStore()
reduce size of primary vertex cache by increasing quality limit
bool getByToken(EDGetToken token, Handle< PROD > &result) const
int bunchCrossing() const
edm::LuminosityBlockNumber_t luminosityBlock() const
std::vector< Vertex > VertexCollection
collection of Vertex objects
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
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
double pvQuality(const reco::Vertex &pv) const
vertex quality measure
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)