34 #include "Minuit2/FCNBase.h" 35 #include "Minuit2/FunctionMinimum.h" 36 #include "Minuit2/MnMigrad.h" 37 #include "Minuit2/MnPrint.h" 39 #include "TMinuitMinimizer.h" 73 TMinuitMinimizer::UseStaticMinuit(
false);
77 .getUntrackedParameter<edm::InputTag>(
"VertexCollection",
145 for (reco::VertexCollection::const_iterator
pv = PVCollection->begin();
pv != PVCollection->end(); ++
pv ) {
151 if (
pv->isFake() ||
pv->tracksSize()==0 )
continue;
180 pvData.
posCorr[0] =
pv->covariance(0,1)/
pv->xError()/
pv->yError();
181 pvData.
posCorr[1] =
pv->covariance(0,2)/
pv->xError()/
pv->zError();
182 pvData.
posCorr[2] =
pv->covariance(1,2)/
pv->yError()/
pv->zError();
212 edm::LogInfo(
"PVFitter") <<
" Number of bunch crossings: " <<
bxMap_.size() << std::endl;
216 for (
std::map<
int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore =
bxMap_.begin();
217 pvStore!=
bxMap_.end(); ++pvStore) {
223 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " << (pvStore->second).
size() <<
" in bx: " << pvStore->first << std::endl;
226 edm::LogWarning(
"PVFitter") <<
" not enough PVs, continue" << std::endl;
232 edm::LogInfo(
"PVFitter") <<
"Calculating beam spot with PVs ..." << std::endl;
241 MnUserParameters upar;
242 upar.Add(
"x" , 0. , 0.02 , -10., 10.);
243 upar.Add(
"y" , 0. , 0.02 , -10., 10.);
244 upar.Add(
"z" , 0. , 0.20 , -30., 30.);
245 upar.Add(
"ex" , 0.015, 0.01 , 0. , 10.);
246 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
247 upar.Add(
"ey" , 0.015, 0.01 , 0. , 10.);
248 upar.Add(
"dxdz" , 0. , 0.0002, -0.1, 0.1);
249 upar.Add(
"dydz" , 0. , 0.0002, -0.1, 0.1);
250 upar.Add(
"ez" , 1. , 0.1 , 0. , 30.);
253 MnMigrad migrad(*fcn, upar);
262 FunctionMinimum ierr = migrad(0,1.);
263 if ( !ierr.IsValid() ) {
264 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
278 if ( !ierr.IsValid() ) {
279 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
290 if ( !ierr.IsValid() ) {
291 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
322 upar.Value(6), upar.Value(7),
330 edm::LogInfo(
"PVFitter") <<
"3D PV fit done for this bunch crossing."<<std::endl;
332 fit_ok = fit_ok &
true;
342 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " <<
pvStore_.size() << std::endl;
348 TH1F *h1PVx = (TH1F*)
hPVx->ProjectionX(
"h1PVx", 0, -1,
"e");
349 TH1F *h1PVy = (TH1F*)
hPVy->ProjectionX(
"h1PVy", 0, -1,
"e");
350 TH1F *h1PVz = (TH1F*)
hPVx->ProjectionY(
"h1PVz", 0, -1,
"e");
353 TF1 gausx(
"localGausX",
"gaus");
354 TF1 gausy(
"localGausY",
"gaus");
355 TF1 gausz(
"localGausZ",
"gaus");
357 h1PVx->Fit(&gausx,
"QLMN0");
358 h1PVy->Fit(&gausy,
"QLMN0");
359 h1PVz->Fit(&gausz,
"QLMN0");
362 fwidthX = gausx.GetParameter(2);
363 fwidthY = gausy.GetParameter(2);
364 fwidthZ = gausz.GetParameter(2);
369 double estX = gausx.GetParameter(1);
370 double estY = gausy.GetParameter(1);
371 double estZ = gausz.GetParameter(1);
379 matrix(2,2) = gausz.GetParError(1) * gausz.GetParError(1);
384 gausy.GetParameter(1),
385 gausz.GetParameter(1) ),
403 MnUserParameters upar;
404 upar.Add(
"x" , estX , errX , -10. , 10. );
405 upar.Add(
"y" , estY , errY , -10. , 10. );
406 upar.Add(
"z" , estZ , errZ , -30. , 30. );
407 upar.Add(
"ex" , 0.015 , 0.01 , 0. , 10. );
408 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
409 upar.Add(
"ey" , 0.015 , 0.01 , 0. , 10. );
410 upar.Add(
"dxdz" , 0. , 0.0002 , -0.1 , 0.1 );
411 upar.Add(
"dydz" , 0. , 0.0002 , -0.1 , 0.1 );
412 upar.Add(
"ez" , 1. , 0.1 , 0. , 30. );
414 MnMigrad migrad(*fcn, upar);
422 FunctionMinimum ierr = migrad(0,1.);
423 if ( !ierr.IsValid() ) {
424 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
433 results = ierr.UserParameters().Params() ; \
434 errors = ierr.UserParameters().Errors() ; \
436 fcn->setLimits(results[0]-
sigmaCut_*results[3],
443 if ( !ierr.IsValid() ) {
444 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
454 if ( !ierr.IsValid() ) {
455 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
464 results = ierr.UserParameters().Params() ; \
465 errors = ierr.UserParameters().Errors() ; \
467 fwidthX = results[3];
476 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
492 results[6], results[7],
564 unsigned int iwrite(0);
565 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
571 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to " 572 <<
pvStore_.size() <<
" ; new dynamic quality cut = " 573 << 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)
Power< A, B >::type pow(const A &a, const B &b)