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;
208 edm::LogInfo(
"PVFitter") <<
" Number of bunch crossings: " <<
bxMap_.size() << std::endl;
212 for ( std::map<
int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore =
bxMap_.begin();
213 pvStore!=
bxMap_.end(); ++pvStore) {
219 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " << (pvStore->second).
size() <<
" in bx: " << pvStore->first << std::endl;
222 edm::LogWarning(
"PVFitter") <<
" not enough PVs, continue" << std::endl;
228 edm::LogInfo(
"PVFitter") <<
"Calculating beam spot with PVs ..." << std::endl;
237 MnUserParameters upar;
238 upar.Add(
"x" , 0. , 0.02 , -10., 10.);
239 upar.Add(
"y" , 0. , 0.02 , -10., 10.);
240 upar.Add(
"z" , 0. , 0.20 , -30., 30.);
241 upar.Add(
"ex" , 0.015, 0.01 , 0. , 10.);
242 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
243 upar.Add(
"ey" , 0.015, 0.01 , 0. , 10.);
244 upar.Add(
"dxdz" , 0. , 0.0002, -0.1, 0.1);
245 upar.Add(
"dydz" , 0. , 0.0002, -0.1, 0.1);
246 upar.Add(
"ez" , 1. , 0.1 , 0. , 30.);
249 MnMigrad migrad(*fcn, upar);
258 FunctionMinimum ierr = migrad(0,1.);
259 if ( !ierr.IsValid() ) {
260 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
274 if ( !ierr.IsValid() ) {
275 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
286 if ( !ierr.IsValid() ) {
287 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
318 upar.Value(6), upar.Value(7),
326 edm::LogInfo(
"PVFitter") <<
"3D PV fit done for this bunch crossing."<<std::endl;
328 fit_ok = fit_ok &
true;
337 using namespace ROOT::Minuit2;
338 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " <<
pvStore_.size() << std::endl;
344 TH1F *h1PVx = (TH1F*)
hPVx->ProjectionX(
"h1PVx", 0, -1,
"e");
345 TH1F *h1PVy = (TH1F*)
hPVy->ProjectionX(
"h1PVy", 0, -1,
"e");
346 TH1F *h1PVz = (TH1F*)
hPVx->ProjectionY(
"h1PVz", 0, -1,
"e");
349 TF1 gaus(
"localGaus",
"gaus");
351 h1PVx->Fit(&gaus,
"QLM0");
352 h1PVy->Fit(&gaus,
"QLM0");
353 h1PVz->Fit(&gaus,
"QLM0");
355 TF1 *gausx = h1PVx->GetFunction(
"localGaus");
356 TF1 *gausy = h1PVy->GetFunction(
"localGaus");
357 TF1 *gausz = h1PVz->GetFunction(
"localGaus");
359 fwidthX = gausx->GetParameter(2);
360 fwidthY = gausy->GetParameter(2);
361 fwidthZ = gausz->GetParameter(2);
366 double estX = gausx->GetParameter(1);
367 double estY = gausy->GetParameter(1);
368 double estZ = gausz->GetParameter(1);
376 matrix(2,2) = gausz->GetParError(1) * gausz->GetParError(1);
381 gausy->GetParameter(1),
382 gausz->GetParameter(1) ),
400 MnUserParameters upar;
401 upar.Add(
"x" , estX , errX , -10. , 10. );
402 upar.Add(
"y" , estY , errY , -10. , 10. );
403 upar.Add(
"z" , estZ , errZ , -30. , 30. );
404 upar.Add(
"ex" , 0.015 , 0.01 , 0. , 10. );
405 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
406 upar.Add(
"ey" , 0.015 , 0.01 , 0. , 10. );
407 upar.Add(
"dxdz" , 0. , 0.0002 , -0.1 , 0.1 );
408 upar.Add(
"dydz" , 0. , 0.0002 , -0.1 , 0.1 );
409 upar.Add(
"ez" , 1. , 0.1 , 0. , 30. );
411 MnMigrad migrad(*fcn, upar);
419 FunctionMinimum ierr = migrad(0,1.);
420 if ( !ierr.IsValid() ) {
421 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
430 results = ierr.UserParameters().Params() ;
\
431 errors = ierr.UserParameters().Errors() ;
\
440 if ( !ierr.IsValid() ) {
441 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
451 if ( !ierr.IsValid() ) {
452 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
461 results = ierr.UserParameters().Params() ;
\
462 errors = ierr.UserParameters().Errors() ;
\
473 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
489 results[6], results[7],
561 unsigned int iwrite(0);
562 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
568 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to "
569 <<
pvStore_.size() <<
" ; new dynamic quality cut = "
570 << 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)