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",
140 for (reco::VertexCollection::const_iterator
pv = PVCollection->begin();
pv != PVCollection->end(); ++
pv ) {
146 if (
pv->isFake() ||
pv->tracksSize()==0 )
continue;
174 pvData.
posCorr[0] =
pv->covariance(0,1)/
pv->xError()/
pv->yError();
175 pvData.
posCorr[1] =
pv->covariance(0,2)/
pv->xError()/
pv->zError();
176 pvData.
posCorr[2] =
pv->covariance(1,2)/
pv->yError()/
pv->zError();
205 using namespace ROOT::Minuit2;
206 edm::LogInfo(
"PVFitter") <<
" Number of bunch crossings: " <<
bxMap_.size() << std::endl;
210 for (
std::map<
int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore =
bxMap_.begin();
211 pvStore!=
bxMap_.end(); ++pvStore) {
217 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " << (pvStore->second).
size() <<
" in bx: " << pvStore->first << std::endl;
220 edm::LogWarning(
"PVFitter") <<
" not enough PVs, continue" << std::endl;
226 edm::LogInfo(
"PVFitter") <<
"Calculating beam spot with PVs ..." << std::endl;
235 MnUserParameters upar;
236 upar.Add(
"x" , 0. , 0.02 , -10., 10.);
237 upar.Add(
"y" , 0. , 0.02 , -10., 10.);
238 upar.Add(
"z" , 0. , 0.20 , -30., 30.);
239 upar.Add(
"ex" , 0.015, 0.01 , 0. , 10.);
240 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
241 upar.Add(
"ey" , 0.015, 0.01 , 0. , 10.);
242 upar.Add(
"dxdz" , 0. , 0.0002, -0.1, 0.1);
243 upar.Add(
"dydz" , 0. , 0.0002, -0.1, 0.1);
244 upar.Add(
"ez" , 1. , 0.1 , 0. , 30.);
247 MnMigrad migrad(*fcn, upar);
256 FunctionMinimum ierr = migrad(0,1.);
257 if ( !ierr.IsValid() ) {
258 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
272 if ( !ierr.IsValid() ) {
273 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
284 if ( !ierr.IsValid() ) {
285 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
316 upar.Value(6), upar.Value(7),
324 edm::LogInfo(
"PVFitter") <<
"3D PV fit done for this bunch crossing."<<std::endl;
326 fit_ok = fit_ok &
true;
335 using namespace ROOT::Minuit2;
336 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " <<
pvStore_.size() << std::endl;
342 TH1F *h1PVx = (TH1F*)
hPVx->ProjectionX(
"h1PVx", 0, -1,
"e");
343 TH1F *h1PVy = (TH1F*)
hPVy->ProjectionX(
"h1PVy", 0, -1,
"e");
344 TH1F *h1PVz = (TH1F*)
hPVx->ProjectionY(
"h1PVz", 0, -1,
"e");
347 TF1 gaus(
"localGaus",
"gaus");
349 h1PVx->Fit(&gaus,
"QLM0");
350 h1PVy->Fit(&gaus,
"QLM0");
351 h1PVz->Fit(&gaus,
"QLM0");
353 TF1 *gausx = h1PVx->GetFunction(
"localGaus");
354 TF1 *gausy = h1PVy->GetFunction(
"localGaus");
355 TF1 *gausz = h1PVz->GetFunction(
"localGaus");
357 fwidthX = gausx->GetParameter(2);
358 fwidthY = gausy->GetParameter(2);
359 fwidthZ = gausz->GetParameter(2);
364 double estX = gausx->GetParameter(1);
365 double estY = gausy->GetParameter(1);
366 double estZ = gausz->GetParameter(1);
374 matrix(2,2) = gausz->GetParError(1) * gausz->GetParError(1);
379 gausy->GetParameter(1),
380 gausz->GetParameter(1) ),
398 MnUserParameters upar;
399 upar.Add(
"x" , estX , errX , -10. , 10. );
400 upar.Add(
"y" , estY , errY , -10. , 10. );
401 upar.Add(
"z" , estZ , errZ , -30. , 30. );
402 upar.Add(
"ex" , 0.015 , 0.01 , 0. , 10. );
403 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
404 upar.Add(
"ey" , 0.015 , 0.01 , 0. , 10. );
405 upar.Add(
"dxdz" , 0. , 0.0002 , -0.1 , 0.1 );
406 upar.Add(
"dydz" , 0. , 0.0002 , -0.1 , 0.1 );
407 upar.Add(
"ez" , 1. , 0.1 , 0. , 30. );
409 MnMigrad migrad(*fcn, upar);
417 FunctionMinimum ierr = migrad(0,1.);
418 if ( !ierr.IsValid() ) {
419 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
428 results = ierr.UserParameters().Params() ;
\
429 errors = ierr.UserParameters().Errors() ;
\
438 if ( !ierr.IsValid() ) {
439 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
449 if ( !ierr.IsValid() ) {
450 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
459 results = ierr.UserParameters().Params() ;
\
460 errors = ierr.UserParameters().Errors() ;
\
471 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
487 results[6], results[7],
559 unsigned int iwrite(0);
560 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
566 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to "
567 <<
pvStore_.size() <<
" ; new dynamic quality cut = "
568 << 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)