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();
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;
345 TH1F *h1PVx = (TH1F*)
hPVx->ProjectionX(
"h1PVx", 0, -1,
"e");
346 TH1F *h1PVy = (TH1F*)
hPVy->ProjectionX(
"h1PVy", 0, -1,
"e");
347 TH1F *h1PVz = (TH1F*)
hPVx->ProjectionY(
"h1PVz", 0, -1,
"e");
350 TF1 gaus(
"localGaus",
"gaus");
352 h1PVx->Fit(&gaus,
"QLM0");
353 h1PVy->Fit(&gaus,
"QLM0");
354 h1PVz->Fit(&gaus,
"QLM0");
356 TF1 *gausx = h1PVx->GetFunction(
"localGaus");
357 TF1 *gausy = h1PVy->GetFunction(
"localGaus");
358 TF1 *gausz = h1PVz->GetFunction(
"localGaus");
360 fwidthX = gausx->GetParameter(2);
361 fwidthY = gausy->GetParameter(2);
362 fwidthZ = gausz->GetParameter(2);
368 matrix(2,2) = gausz->GetParError(1) * gausz->GetParError(1);
373 gausy->GetParameter(1),
374 gausz->GetParameter(1) ),
392 MnUserParameters upar;
393 upar.Add(
"x" , 0. , 0.02 , -10. , 10. );
394 upar.Add(
"y" , 0. , 0.02 , -10. , 10. );
395 upar.Add(
"z" , 0. , 0.20 , -30. , 30. );
396 upar.Add(
"ex" , 0.015 , 0.01 , 0. , 10. );
397 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
398 upar.Add(
"ey" , 0.015 , 0.01 , 0. , 10. );
399 upar.Add(
"dxdz" , 0. , 0.0002 , -0.1 , 0.1 );
400 upar.Add(
"dydz" , 0. , 0.0002 , -0.1 , 0.1 );
401 upar.Add(
"ez" , 1. , 0.1 , 0. , 30. );
403 MnMigrad migrad(*fcn, upar);
411 FunctionMinimum ierr = migrad();
412 if ( !ierr.IsValid() ) {
413 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
422 results = ierr.UserParameters().Params() ;
\
423 errors = ierr.UserParameters().Errors() ;
\
432 if ( !ierr.IsValid() ) {
433 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
443 if ( !ierr.IsValid() ) {
444 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
453 results = ierr.UserParameters().Params() ;
\
454 errors = ierr.UserParameters().Errors() ;
\
465 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
481 results[6], results[7],
553 unsigned int iwrite(0);
554 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
560 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to "
561 <<
pvStore_.size() <<
" ; new dynamic quality cut = "
562 << 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)