34 #include "Minuit2/FCNBase.h" 35 #include "Minuit2/FunctionMinimum.h" 36 #include "Minuit2/MnMigrad.h" 37 #include "Minuit2/MnPrint.h" 39 #include "TMinuitMinimizer.h" 63 TMinuitMinimizer::UseStaticMinuit(
false);
67 .getUntrackedParameter<edm::InputTag>(
"VertexCollection",
edm::InputTag(
"offlinePrimaryVertices")));
111 for (reco::VertexCollection::const_iterator
pv = PVCollection->begin();
pv != PVCollection->end(); ++
pv ) {
113 if (
pv != PVCollection->begin())
break;
117 if (
pv->isFake() ||
pv->tracksSize()==0 )
continue;
123 const auto& testTrack =
pv->trackRefAt(0);
124 if(testTrack.isNull() || !testTrack.isAvailable())
126 edm::LogInfo(
"") <<
"Track collection not found. Skipping cut on sumPt.";
131 for(
auto iTrack =
pv->tracks_begin(); iTrack !=
pv->tracks_end(); ++iTrack)
133 const auto pt = (*iTrack)->pt();
164 pvData.
posCorr[0] =
pv->covariance(0,1)/
pv->xError()/
pv->yError();
165 pvData.
posCorr[1] =
pv->covariance(0,2)/
pv->xError()/
pv->zError();
166 pvData.
posCorr[2] =
pv->covariance(1,2)/
pv->yError()/
pv->zError();
193 edm::LogInfo(
"PVFitter") <<
" Number of bunch crossings: " <<
bxMap_.size() << std::endl;
197 for (
std::map<
int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore =
bxMap_.begin();
198 pvStore!=
bxMap_.end(); ++pvStore) {
204 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " << (pvStore->second).
size() <<
" in bx: " << pvStore->first << std::endl;
207 edm::LogWarning(
"PVFitter") <<
" not enough PVs, continue" << std::endl;
212 edm::LogInfo(
"PVFitter") <<
"Calculating beam spot with PVs ..." << std::endl;
221 MnUserParameters upar;
222 upar.Add(
"x" , 0. , 0.02 , -10., 10.);
223 upar.Add(
"y" , 0. , 0.02 , -10., 10.);
224 upar.Add(
"z" , 0. , 0.20 , -30., 30.);
225 upar.Add(
"ex" , 0.015, 0.01 , 0. , 10.);
226 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
227 upar.Add(
"ey" , 0.015, 0.01 , 0. , 10.);
228 upar.Add(
"dxdz" , 0. , 0.0002, -0.1, 0.1);
229 upar.Add(
"dydz" , 0. , 0.0002, -0.1, 0.1);
230 upar.Add(
"ez" , 1. , 0.1 , 0. , 30.);
233 MnMigrad migrad(*fcn, upar);
242 FunctionMinimum ierr = migrad(0,1.);
243 if ( !ierr.IsValid() ) {
244 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
258 if ( !ierr.IsValid() ) {
259 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
270 if ( !ierr.IsValid() ) {
271 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
297 upar.Value(6), upar.Value(7),
305 edm::LogInfo(
"PVFitter") <<
"3D PV fit done for this bunch crossing."<<std::endl;
307 fit_ok = fit_ok &
true;
317 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " <<
pvStore_.size() << std::endl;
321 TH1F *h1PVx = (TH1F*)
hPVx->ProjectionX(
"h1PVx", 0, -1,
"e");
322 TH1F *h1PVy = (TH1F*)
hPVy->ProjectionX(
"h1PVy", 0, -1,
"e");
323 TH1F *h1PVz = (TH1F*)
hPVx->ProjectionY(
"h1PVz", 0, -1,
"e");
327 TF1 gausx(
"localGausX",
"gaus",0.,1.,TF1::EAddToList::kNo);
328 TF1 gausy(
"localGausY",
"gaus",0.,1.,TF1::EAddToList::kNo);
329 TF1 gausz(
"localGausZ",
"gaus",0.,1.,TF1::EAddToList::kNo);
331 h1PVx->Fit(&gausx,
"QLMN0");
332 h1PVy->Fit(&gausy,
"QLMN0");
333 h1PVz->Fit(&gausz,
"QLMN0");
336 fwidthX = gausx.GetParameter(2);
337 fwidthY = gausy.GetParameter(2);
338 fwidthZ = gausz.GetParameter(2);
343 double estX = gausx.GetParameter(1);
344 double estY = gausy.GetParameter(1);
345 double estZ = gausz.GetParameter(1);
353 matrix(2,2) = gausz.GetParError(1) * gausz.GetParError(1);
358 gausy.GetParameter(1),
359 gausz.GetParameter(1) ),
377 MnUserParameters upar;
378 upar.Add(
"x" , estX , errX , -10. , 10. );
379 upar.Add(
"y" , estY , errY , -10. , 10. );
380 upar.Add(
"z" , estZ , errZ , -30. , 30. );
381 upar.Add(
"ex" , 0.015 , 0.01 , 0. , 10. );
382 upar.Add(
"corrxy", 0. , 0.02 , -1. , 1. );
383 upar.Add(
"ey" , 0.015 , 0.01 , 0. , 10. );
384 upar.Add(
"dxdz" , 0. , 0.0002 , -0.1 , 0.1 );
385 upar.Add(
"dydz" , 0. , 0.0002 , -0.1 , 0.1 );
386 upar.Add(
"ez" , 1. , 0.1 , 0. , 30. );
388 MnMigrad migrad(*fcn, upar);
396 FunctionMinimum ierr = migrad(0,1.);
397 if ( !ierr.IsValid() ) {
398 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
407 results = ierr.UserParameters().Params() ; \
408 errors = ierr.UserParameters().Errors() ; \
411 fcn->setLimits(results[0]-
sigmaCut_*results[3],
418 if ( !ierr.IsValid() ) {
419 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
429 if ( !ierr.IsValid() ) {
430 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
434 results = ierr.UserParameters().Params() ; \
435 errors = ierr.UserParameters().Errors() ; \
437 fwidthX = results[3];
446 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
462 results[6], results[7],
497 unsigned int iwrite(0);
498 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
504 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to " 505 <<
pvStore_.size() <<
" ; new dynamic quality cut = " 506 << 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)