34 #include "Minuit2/FCNBase.h"
35 #include "Minuit2/FunctionMinimum.h"
36 #include "Minuit2/MnMigrad.h"
71 .getUntrackedParameter<edm::InputTag>(
"VertexCollection",
139 for (reco::VertexCollection::const_iterator pv = PVCollection->begin(); pv != PVCollection->end(); ++pv ) {
145 if ( pv->isFake() || pv->tracksSize()==0 )
continue;
149 hPVx->Fill( pv->x(), pv->z() );
150 hPVy->Fill( pv->y(), pv->z() );
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;
207 edm::LogInfo(
"PVFitter") <<
" Number of bunch crossings: " <<
bxMap_.size() << std::endl;
211 for (
std::map<
int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore =
bxMap_.begin();
212 pvStore!=
bxMap_.end(); ++pvStore) {
218 edm::LogInfo(
"PVFitter") <<
" Number of PVs collected for PVFitter: " << (pvStore->second).
size() <<
" in bx: " << pvStore->first << std::endl;
221 edm::LogWarning(
"PVFitter") <<
" not enough PVs, continue" << std::endl;
227 edm::LogInfo(
"PVFitter") <<
"Calculating beam spot with PVs ..." << std::endl;
236 MnUserParameters upar;
237 upar.Add(
"x", 0., 0.02, -10., 10.);
238 upar.Add(
"y", 0., 0.02, -10., 10.);
239 upar.Add(
"z", 0., 0.20, -30., 30.);
240 upar.Add(
"ex", 0.015, 0.01, 0., 10.);
241 upar.Add(
"corrxy", 0., 0.02, -1., 1.);
242 upar.Add(
"ey", 0.015, 0.01, 0., 10.);
243 upar.Add(
"dxdz", 0., 0.0002, -0.1, 0.1);
244 upar.Add(
"dydz", 0., 0.0002, -0.1, 0.1);
245 upar.Add(
"ez", 1., 0.1, 0., 30.);
248 MnMigrad migrad(*fcn, upar);
257 FunctionMinimum ierr = migrad();
258 if ( !ierr.IsValid() ) {
259 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
273 if ( !ierr.IsValid() ) {
274 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
285 if ( !ierr.IsValid() ) {
286 edm::LogInfo(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
317 upar.Value(6), upar.Value(7),
325 edm::LogInfo(
"PVFitter") <<
"3D PV fit done for this bunch crossing."<<std::endl;
327 fit_ok = fit_ok &
true;
336 using namespace ROOT::Minuit2;
337 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");
348 h1PVx->Fit(
"gaus",
"QLM0");
349 h1PVy->Fit(
"gaus",
"QLM0");
350 h1PVz->Fit(
"gaus",
"QLM0");
352 TF1 *gausx = h1PVx->GetFunction(
"gaus");
353 TF1 *gausy = h1PVy->GetFunction(
"gaus");
354 TF1 *gausz = h1PVz->GetFunction(
"gaus");
356 fwidthX = gausx->GetParameter(2);
357 fwidthY = gausy->GetParameter(2);
358 fwidthZ = gausz->GetParameter(2);
364 matrix(2,2) = gausz->GetParError(1) * gausz->GetParError(1);
369 gausy->GetParameter(1),
370 gausz->GetParameter(1) ),
388 MnUserParameters upar;
389 upar.Add(
"x", 0., 0.02, -10., 10.);
390 upar.Add(
"y", 0., 0.02, -10., 10.);
391 upar.Add(
"z", 0., 0.20, -30., 30.);
392 upar.Add(
"ex", 0.005, 0.0005, 0.0001, 0.05);
393 upar.Add(
"corrxy", 0., 0.02, -1., 1.);
394 upar.Add(
"ey", 0.005, 0.0005, 0.0001, 0.05);
395 upar.Add(
"dxdz", 0., 0.0002, -0.1, 0.1);
396 upar.Add(
"dydz", 0., 0.0002, -0.1, 0.1);
397 upar.Add(
"ez", 1., 0.1, 1.0, 30.);
400 MnMigrad migrad(*fcn, upar);
408 FunctionMinimum ierr = migrad();
409 if ( !ierr.IsValid() ) {
410 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 1st iteration" << std::endl;
423 if ( !ierr.IsValid() ) {
424 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 2nd iteration" << std::endl;
434 if ( !ierr.IsValid() ) {
435 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit failed in 3rd iteration" << std::endl;
453 edm::LogWarning(
"PVFitter") <<
"3D beam spot fit returns nan in 3rd iteration" << std::endl;
469 upar.Value(6), upar.Value(7),
541 unsigned int iwrite(0);
542 for (
unsigned int i=0; i<
pvStore_.size(); ++
i ) {
548 edm::LogInfo(
"PVFitter") <<
"Reduced primary vertex store size to "
549 <<
pvStore_.size() <<
" ; new dynamic quality cut = "
550 << 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)