CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
PVFitter Class Reference

#include <PVFitter.h>

Public Member Functions

void compressStore ()
 reduce size of primary vertex cache by increasing quality limit More...
 
void dumpTxtFile ()
 
void FitPerBunchCrossing ()
 
reco::BeamSpot getBeamSpot ()
 
std::map< int, reco::BeamSpotgetBeamSpotMap ()
 
int * getFitLSRange ()
 
int getNPVs ()
 
const std::map< int, int > & getNPVsperBX ()
 
std::vector< BeamSpotFitPVDatagetpvStore ()
 
time_t * getRefTime ()
 
double getWidthX ()
 
double getWidthXerr ()
 
double getWidthY ()
 
double getWidthYerr ()
 
double getWidthZ ()
 
double getWidthZerr ()
 
void initialize (const edm::ParameterSet &iConfig, edm::ConsumesCollector &iColl)
 
bool IsFitPerBunchCrossing ()
 
 PVFitter ()
 
 PVFitter (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iColl)
 
 PVFitter (const edm::ParameterSet &iConfig, edm::ConsumesCollector &iColl)
 
double pvQuality (const reco::Vertex &pv) const
 vertex quality measure More...
 
double pvQuality (const BeamSpotFitPVData &pv) const
 vertex quality measure More...
 
void readEvent (const edm::Event &iEvent)
 
void resetAll ()
 
void resetLSRange ()
 
void resetRefTime ()
 
void resizepvStore (unsigned int rmSize)
 
bool runBXFitter ()
 
bool runFitter ()
 
void setFitLSRange (int ls0, int ls1)
 
void setRefTime (std::time_t t0, std::time_t t1)
 
void setTree (TTree *tree)
 
virtual ~PVFitter ()
 

Private Attributes

std::map< int, std::vector< BeamSpotFitPVData > > bxMap_
 
bool debug_
 
bool do3DFit_
 
double dynamicQualityCut_
 
double errorScale_
 
std::ofstream fasciiFile
 
reco::BeamSpot fbeamspot
 
int fbeginLumiOfFit
 
std::map< int, reco::BeamSpotfbspotMap
 
int fendLumiOfFit
 
bool fFitPerBunchCrossing
 
std::time_t freftime [2]
 
TTree * ftree_
 
double fwidthX
 
double fwidthXerr
 
double fwidthY
 
double fwidthYerr
 
double fwidthZ
 
double fwidthZerr
 
TH2F * hPVx
 
TH2F * hPVy
 
unsigned int maxNrVertices_
 
double maxVtxNormChi2_
 
double maxVtxR_
 
double maxVtxZ_
 
unsigned int minNrVertices_
 
double minVtxNdf_
 
unsigned int minVtxTracks_
 
double minVtxWgt_
 
std::map< int, int > npvsmap_
 
std::string outputTxt_
 
std::vector< double > pvQualities_
 
std::vector< BeamSpotFitPVDatapvStore_
 
double sigmaCut_
 
BeamSpotTreeData theBeamSpotTreeData_
 
edm::EDGetTokenT< reco::VertexCollectionvertexToken_
 

Detailed Description

Definition at line 43 of file PVFitter.h.

Constructor & Destructor Documentation

PVFitter::PVFitter ( )
inline

Definition at line 45 of file PVFitter.h.

References iEvent, initialize(), and d0_phi_analyzer_cff::PVFitter.

45 {}
PVFitter::PVFitter ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  iColl 
)

Definition at line 54 of file PVFitter.cc.

References initialize().

56  : ftree_(0)
57 {
58  initialize(iConfig, iColl);
59 }
void initialize(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iColl)
Definition: PVFitter.cc:68
TTree * ftree_
Definition: PVFitter.h:168
PVFitter::PVFitter ( const edm::ParameterSet iConfig,
edm::ConsumesCollector iColl 
)

Definition at line 61 of file PVFitter.cc.

References initialize().

63  :ftree_(0)
64 {
65  initialize(iConfig, iColl);
66 }
void initialize(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iColl)
Definition: PVFitter.cc:68
TTree * ftree_
Definition: PVFitter.h:168
PVFitter::~PVFitter ( )
virtual

Definition at line 102 of file PVFitter.cc.

102  {
103 
104 }

Member Function Documentation

void PVFitter::compressStore ( )

reduce size of primary vertex cache by increasing quality limit

Definition at line 547 of file PVFitter.cc.

References dynamicQualityCut_, mps_fire::i, pvQualities_, pvQuality(), and pvStore_.

Referenced by readEvent().

548 {
549  //
550  // fill vertex qualities
551  //
552  pvQualities_.resize(pvStore_.size());
553  for ( unsigned int i=0; i<pvStore_.size(); ++i ) pvQualities_[i] = pvQuality(pvStore_[i]);
554  sort(pvQualities_.begin(),pvQualities_.end());
555  //
556  // Set new quality cut to median. This cut will be used to reduce the
557  // number of vertices in the store and also apply to all new vertices
558  // until the next reset
559  //
561  //
562  // remove all vertices failing the cut from the store
563  // (to be moved to a more efficient memory management!)
564  //
565  unsigned int iwrite(0);
566  for ( unsigned int i=0; i<pvStore_.size(); ++i ) {
567  if ( pvQuality(pvStore_[i])>dynamicQualityCut_ ) continue;
568  if ( i!=iwrite ) pvStore_[iwrite] = pvStore_[i];
569  ++iwrite;
570  }
571  pvStore_.resize(iwrite);
572  edm::LogInfo("PVFitter") << "Reduced primary vertex store size to "
573  << pvStore_.size() << " ; new dynamic quality cut = "
574  << dynamicQualityCut_ << std::endl;
575 
576 }
std::vector< double > pvQualities_
Definition: PVFitter.h:205
double dynamicQualityCut_
Definition: PVFitter.h:204
std::vector< BeamSpotFitPVData > pvStore_
Definition: PVFitter.h:202
double pvQuality(const reco::Vertex &pv) const
vertex quality measure
Definition: PVFitter.cc:579
void PVFitter::dumpTxtFile ( )

Definition at line 504 of file PVFitter.cc.

504  {
505 /*
506  fasciiFile << "Runnumber " << frun << std::endl;
507  fasciiFile << "BeginTimeOfFit " << fbeginTimeOfFit << std::endl;
508  fasciiFile << "EndTimeOfFit " << fendTimeOfFit << std::endl;
509  fasciiFile << "LumiRange " << fbeginLumiOfFit << " - " << fendLumiOfFit << std::endl;
510  fasciiFile << "Type " << fbeamspot.type() << std::endl;
511  fasciiFile << "X0 " << fbeamspot.x0() << std::endl;
512  fasciiFile << "Y0 " << fbeamspot.y0() << std::endl;
513  fasciiFile << "Z0 " << fbeamspot.z0() << std::endl;
514  fasciiFile << "sigmaZ0 " << fbeamspot.sigmaZ() << std::endl;
515  fasciiFile << "dxdz " << fbeamspot.dxdz() << std::endl;
516  fasciiFile << "dydz " << fbeamspot.dydz() << std::endl;
517  if (inputBeamWidth_ > 0 ) {
518  fasciiFile << "BeamWidthX " << inputBeamWidth_ << std::endl;
519  fasciiFile << "BeamWidthY " << inputBeamWidth_ << std::endl;
520  } else {
521  fasciiFile << "BeamWidthX " << fbeamspot.BeamWidthX() << std::endl;
522  fasciiFile << "BeamWidthY " << fbeamspot.BeamWidthY() << std::endl;
523  }
524 
525  for (int i = 0; i<6; ++i) {
526  fasciiFile << "Cov("<<i<<",j) ";
527  for (int j=0; j<7; ++j) {
528  fasciiFile << fbeamspot.covariance(i,j) << " ";
529  }
530  fasciiFile << std::endl;
531  }
532  // beam width error
533  if (inputBeamWidth_ > 0 ) {
534  fasciiFile << "Cov(6,j) 0 0 0 0 0 0 " << "1e-4" << std::endl;
535  } else {
536  fasciiFile << "Cov(6,j) 0 0 0 0 0 0 " << fbeamspot.covariance(6,6) << std::endl;
537  }
538  fasciiFile << "EmittanceX " << fbeamspot.emittanceX() << std::endl;
539  fasciiFile << "EmittanceY " << fbeamspot.emittanceY() << std::endl;
540  fasciiFile << "BetaStar " << fbeamspot.betaStar() << std::endl;
541 
542 */
543 }
void PVFitter::FitPerBunchCrossing ( )
inline

Definition at line 63 of file PVFitter.h.

63 { fFitPerBunchCrossing = true; }
bool fFitPerBunchCrossing
Definition: PVFitter.h:141
reco::BeamSpot PVFitter::getBeamSpot ( )
inline

Definition at line 91 of file PVFitter.h.

Referenced by AlcaBeamMonitor::endLuminosityBlock(), and BeamFitter::runPVandTrkFitter().

91 { return fbeamspot; }
reco::BeamSpot fbeamspot
Definition: PVFitter.h:139
std::map<int, reco::BeamSpot> PVFitter::getBeamSpotMap ( )
inline

Definition at line 92 of file PVFitter.h.

Referenced by BeamFitter::runPVandTrkFitter().

92 { return fbspotMap; }
std::map< int, reco::BeamSpot > fbspotMap
Definition: PVFitter.h:140
int* PVFitter::getFitLSRange ( )
inline

Definition at line 94 of file PVFitter.h.

References tmp.

94  {
95  int *tmp=new int[2];
96  tmp[0] = fbeginLumiOfFit;
97  tmp[1] = fendLumiOfFit;
98  return tmp;
99  }
int fbeginLumiOfFit
Definition: PVFitter.h:178
int fendLumiOfFit
Definition: PVFitter.h:179
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
int PVFitter::getNPVs ( )
inline

Definition at line 120 of file PVFitter.h.

120 { return pvStore_.size(); }
std::vector< BeamSpotFitPVData > pvStore_
Definition: PVFitter.h:202
const std::map<int, int>& PVFitter::getNPVsperBX ( )
inline

Definition at line 122 of file PVFitter.h.

References genParticles_cff::map, and findQualityFiles::size.

122  {
123 
124  npvsmap_.clear();
125 
126  for ( std::map<int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore = bxMap_.begin();
127  pvStore!=bxMap_.end(); ++pvStore) {
128 
129  //std::cout << "bx " << pvStore->first << " NPVs = " << (pvStore->second).size() << std::endl;
130  npvsmap_[ pvStore->first ] = (pvStore->second).size();
131 
132  }
133  return npvsmap_;
134  }
size
Write out results.
std::map< int, std::vector< BeamSpotFitPVData > > bxMap_
Definition: PVFitter.h:203
std::map< int, int > npvsmap_
Definition: PVFitter.h:138
std::vector<BeamSpotFitPVData> PVFitter::getpvStore ( )
inline

Definition at line 61 of file PVFitter.h.

61 { return pvStore_; }
std::vector< BeamSpotFitPVData > pvStore_
Definition: PVFitter.h:202
time_t* PVFitter::getRefTime ( )
inline

Definition at line 101 of file PVFitter.h.

101  {
102  time_t *tmptime=new time_t[2];
103  tmptime[0]=freftime[0];
104  tmptime[1]=freftime[1];
105  return tmptime;
106  }
std::time_t freftime[2]
Definition: PVFitter.h:164
double PVFitter::getWidthX ( )
inline

Definition at line 54 of file PVFitter.h.

54 { return fwidthX; }
double fwidthX
Definition: PVFitter.h:182
double PVFitter::getWidthXerr ( )
inline

Definition at line 57 of file PVFitter.h.

Referenced by BeamFitter::runPVandTrkFitter().

57 { return fwidthXerr; }
double fwidthXerr
Definition: PVFitter.h:185
double PVFitter::getWidthY ( )
inline

Definition at line 55 of file PVFitter.h.

55 { return fwidthY; }
double fwidthY
Definition: PVFitter.h:183
double PVFitter::getWidthYerr ( )
inline

Definition at line 58 of file PVFitter.h.

58 { return fwidthYerr; }
double fwidthYerr
Definition: PVFitter.h:186
double PVFitter::getWidthZ ( )
inline

Definition at line 56 of file PVFitter.h.

56 { return fwidthZ; }
double fwidthZ
Definition: PVFitter.h:184
double PVFitter::getWidthZerr ( )
inline

Definition at line 59 of file PVFitter.h.

59 { return fwidthZerr; }
double fwidthZerr
Definition: PVFitter.h:187
void PVFitter::initialize ( const edm::ParameterSet iConfig,
edm::ConsumesCollector iColl 
)

Definition at line 68 of file PVFitter.cc.

References edm::ConsumesCollector::consumes(), debug_, do3DFit_, dynamicQualityCut_, errorScale_, fFitPerBunchCrossing, edm::ParameterSet::getParameter(), hPVx, hPVy, maxNrVertices_, maxVtxNormChi2_, maxVtxR_, maxVtxZ_, minNrVertices_, minVtxNdf_, minVtxTracks_, minVtxWgt_, sigmaCut_, and vertexToken_.

Referenced by PVFitter().

70 {
71  //In order to make fitting ROOT histograms thread safe
72  // one must call this undocumented function
73  TMinuitMinimizer::UseStaticMinuit(false);
74  debug_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<bool>("Debug");
76  iConfig.getParameter<edm::ParameterSet>("PVFitter")
77  .getUntrackedParameter<edm::InputTag>("VertexCollection",
78  edm::InputTag("offlinePrimaryVertices")));
79  do3DFit_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<bool>("Apply3DFit");
80  //writeTxt_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<bool>("WriteAscii");
81  //outputTxt_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<std::string>("AsciiFileName");
82 
83  maxNrVertices_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<unsigned int>("maxNrStoredVertices");
84  minNrVertices_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<unsigned int>("minNrVerticesForFit");
85  minVtxNdf_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<double>("minVertexNdf");
86  maxVtxNormChi2_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<double>("maxVertexNormChi2");
87  minVtxTracks_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<unsigned int>("minVertexNTracks");
88  minVtxWgt_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<double>("minVertexMeanWeight");
89  maxVtxR_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<double>("maxVertexR");
90  maxVtxZ_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<double>("maxVertexZ");
91  errorScale_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<double>("errorScale");
92  sigmaCut_ = iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<double>("nSigmaCut");
93  fFitPerBunchCrossing=iConfig.getParameter<edm::ParameterSet>("PVFitter").getUntrackedParameter<bool>("FitPerBunchCrossing");
94 
95  // preset quality cut to "infinite"
96  dynamicQualityCut_ = 1.e30;
97 
98  hPVx = new TH2F("hPVx","PVx vs PVz distribution",200,-maxVtxR_, maxVtxR_, 200, -maxVtxZ_, maxVtxZ_);
99  hPVy = new TH2F("hPVy","PVy vs PVz distribution",200,-maxVtxR_, maxVtxR_, 200, -maxVtxZ_, maxVtxZ_);
100 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
bool debug_
Definition: PVFitter.h:145
double maxVtxNormChi2_
Definition: PVFitter.h:154
double minVtxWgt_
Definition: PVFitter.h:156
double minVtxNdf_
Definition: PVFitter.h:153
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
double errorScale_
Definition: PVFitter.h:159
bool do3DFit_
Definition: PVFitter.h:146
double dynamicQualityCut_
Definition: PVFitter.h:204
bool fFitPerBunchCrossing
Definition: PVFitter.h:141
TH2F * hPVy
Definition: PVFitter.h:166
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Definition: PVFitter.h:147
double maxVtxR_
Definition: PVFitter.h:157
double maxVtxZ_
Definition: PVFitter.h:158
unsigned int maxNrVertices_
Definition: PVFitter.h:151
unsigned int minVtxTracks_
Definition: PVFitter.h:155
TH2F * hPVx
Definition: PVFitter.h:166
unsigned int minNrVertices_
Definition: PVFitter.h:152
double sigmaCut_
Definition: PVFitter.h:160
bool PVFitter::IsFitPerBunchCrossing ( )
inline

Definition at line 93 of file PVFitter.h.

Referenced by BeamFitter::dumpTxtFile(), and BeamFitter::runPVandTrkFitter().

93 { return fFitPerBunchCrossing; }
bool fFitPerBunchCrossing
Definition: PVFitter.h:141
double PVFitter::pvQuality ( const reco::Vertex pv) const

vertex quality measure

Definition at line 579 of file PVFitter.cc.

References reco::Vertex::covariance().

Referenced by compressStore(), and readEvent().

580 {
581  //
582  // determinant of the transverse part of the PV covariance matrix
583  //
584  return
585  pv.covariance(0,0)*pv.covariance(1,1)-
586  pv.covariance(0,1)*pv.covariance(0,1);
587 }
double covariance(int i, int j) const
(i, j)-th element of error matrix, i, j = 0, ... 2
Definition: Vertex.h:130
double PVFitter::pvQuality ( const BeamSpotFitPVData pv) const

vertex quality measure

Definition at line 590 of file PVFitter.cc.

References BeamSpotFitPVData::posCorr, and BeamSpotFitPVData::posError.

591 {
592  //
593  // determinant of the transverse part of the PV covariance matrix
594  //
595  double ex = pv.posError[0];
596  double ey = pv.posError[1];
597  return ex*ex*ey*ey*(1-pv.posCorr[0]*pv.posCorr[0]);
598 }
void PVFitter::readEvent ( const edm::Event iEvent)

Definition at line 107 of file PVFitter.cc.

References BeamSpotFitPVData::bunchCrossing, BeamSpotTreeData::bunchCrossing(), edm::EventBase::bunchCrossing(), bxMap_, compressStore(), dynamicQualityCut_, fFitPerBunchCrossing, ftree_, edm::Event::getByToken(), hPVx, hPVy, edm::EventBase::id(), BeamSpotTreeData::lumi(), edm::EventBase::luminosityBlock(), maxNrVertices_, minVtxNdf_, minVtxWgt_, BeamSpotFitPVData::posCorr, BeamSpotFitPVData::posError, BeamSpotFitPVData::position, MetAnalyzer::pv(), BeamSpotTreeData::pvData(), pvQuality(), pvStore_, BeamSpotTreeData::run(), edm::EventID::run(), theBeamSpotTreeData_, and vertexToken_.

Referenced by AlcaBeamMonitor::analyze(), and BeamFitter::readEvent().

108 {
109 
110 // frun = iEvent.id().run();
111 // const edm::TimeValue_t ftimestamp = iEvent.time().value();
112 // const std::time_t ftmptime = ftimestamp >> 32;
113 
114 // if (fbeginLumiOfFit == -1) freftime[0] = freftime[1] = ftmptime;
115 // if (freftime[0] == 0 || ftmptime < freftime[0]) freftime[0] = ftmptime;
116 // const char* fbeginTime = formatTime(freftime[0]);
117 // sprintf(fbeginTimeOfFit,"%s",fbeginTime);
118 
119 // if (freftime[1] == 0 || ftmptime > freftime[1]) freftime[1] = ftmptime;
120 // const char* fendTime = formatTime(freftime[1]);
121 // sprintf(fendTimeOfFit,"%s",fendTime);
122 
123 // flumi = iEvent.luminosityBlock();
124 // frunFit = frun;
125 
126 // if (fbeginLumiOfFit == -1 || fbeginLumiOfFit > flumi) fbeginLumiOfFit = flumi;
127 // if (fendLumiOfFit == -1 || fendLumiOfFit < flumi) fendLumiOfFit = flumi;
128 // std::cout << "flumi = " <<flumi<<"; fbeginLumiOfFit = " << fbeginLumiOfFit <<"; fendLumiOfFit = "<<fendLumiOfFit<<std::endl;
129 
130  //------ Primary Vertices
132  bool hasPVs = false;
133  //edm::View<reco::Vertex> vertices;
134  //const reco::VertexCollection & vertices = 0;
135 
136  if ( iEvent.getByToken(vertexToken_, PVCollection ) ) {
137  //pv = *PVCollection;
138  //vertices = *PVCollection;
139  hasPVs = true;
140  }
141  //------
142 
143  if ( hasPVs ) {
144 
145  for (reco::VertexCollection::const_iterator pv = PVCollection->begin(); pv != PVCollection->end(); ++pv ) {
146 
147 
148  //for ( size_t ipv=0; ipv != pv.size(); ++ipv ) {
149 
150  //--- vertex selection
151  if ( pv->isFake() || pv->tracksSize()==0 ) continue;
152  if ( pv->ndof() < minVtxNdf_ || (pv->ndof()+3.)/pv->tracksSize()<2*minVtxWgt_ ) continue;
153  //---
154 
155  hPVx->Fill( pv->x(), pv->z() );
156  hPVy->Fill( pv->y(), pv->z() );
157 
158  //
159  // 3D fit section
160  //
161  // apply additional quality cut
162  if ( pvQuality(*pv)>dynamicQualityCut_ ) continue;
163  // if store exceeds max. size: reduce size and apply new quality cut
164  if ( pvStore_.size()>=maxNrVertices_ ) {
165  compressStore();
166  if ( pvQuality(*pv)>dynamicQualityCut_ ) continue;
167  }
168  //
169  // copy PV to store
170  //
171  int bx = iEvent.bunchCrossing();
172  BeamSpotFitPVData pvData;
173  pvData.bunchCrossing = bx;
174  pvData.position[0] = pv->x();
175  pvData.position[1] = pv->y();
176  pvData.position[2] = pv->z();
177  pvData.posError[0] = pv->xError();
178  pvData.posError[1] = pv->yError();
179  pvData.posError[2] = pv->zError();
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();
183  pvStore_.push_back(pvData);
184 
185  if(ftree_ != 0){
186  theBeamSpotTreeData_.run(iEvent.id().run());
190  ftree_->Fill();
191  }
192 
193  if (fFitPerBunchCrossing) bxMap_[bx].push_back(pvData);
194 
195  }
196 
197  }
198 
199 
200 
201 
202 }
RunNumber_t run() const
Definition: EventID.h:39
std::map< int, std::vector< BeamSpotFitPVData > > bxMap_
Definition: PVFitter.h:203
void run(unsigned int run)
void compressStore()
reduce size of primary vertex cache by increasing quality limit
Definition: PVFitter.cc:547
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
double minVtxWgt_
Definition: PVFitter.h:156
double minVtxNdf_
Definition: PVFitter.h:153
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
double dynamicQualityCut_
Definition: PVFitter.h:204
void bunchCrossing(unsigned int bunchCrossing)
void lumi(unsigned int lumi)
std::vector< BeamSpotFitPVData > pvStore_
Definition: PVFitter.h:202
BeamSpotTreeData theBeamSpotTreeData_
Definition: PVFitter.h:207
bool fFitPerBunchCrossing
Definition: PVFitter.h:141
TH2F * hPVy
Definition: PVFitter.h:166
def pv(vc)
Definition: MetAnalyzer.py:6
void pvData(const BeamSpotFitPVData &pvData)
TTree * ftree_
Definition: PVFitter.h:168
edm::EDGetTokenT< reco::VertexCollection > vertexToken_
Definition: PVFitter.h:147
double pvQuality(const reco::Vertex &pv) const
vertex quality measure
Definition: PVFitter.cc:579
unsigned int maxNrVertices_
Definition: PVFitter.h:151
TH2F * hPVx
Definition: PVFitter.h:166
edm::EventID id() const
Definition: EventBase.h:60
void PVFitter::resetAll ( )
inline

Definition at line 80 of file PVFitter.h.

References align::BeamSpot.

Referenced by BeamFitter::BeamFitter(), and AlcaBeamMonitor::endLuminosityBlock().

80  {
81  resetLSRange();
82  resetRefTime();
83  pvStore_.clear();
84  bxMap_.clear();
85  dynamicQualityCut_ = 1.e30;
86  hPVx->Reset();
87  hPVy->Reset();
89  fbspotMap.clear();
90  };
std::map< int, std::vector< BeamSpotFitPVData > > bxMap_
Definition: PVFitter.h:203
double dynamicQualityCut_
Definition: PVFitter.h:204
reco::BeamSpot fbeamspot
Definition: PVFitter.h:139
std::vector< BeamSpotFitPVData > pvStore_
Definition: PVFitter.h:202
void resetLSRange()
Definition: PVFitter.h:66
TH2F * hPVy
Definition: PVFitter.h:166
std::map< int, reco::BeamSpot > fbspotMap
Definition: PVFitter.h:140
void resetRefTime()
Definition: PVFitter.h:67
TH2F * hPVx
Definition: PVFitter.h:166
void PVFitter::resetLSRange ( )
inline

Definition at line 66 of file PVFitter.h.

int fbeginLumiOfFit
Definition: PVFitter.h:178
int fendLumiOfFit
Definition: PVFitter.h:179
void PVFitter::resetRefTime ( )
inline

Definition at line 67 of file PVFitter.h.

67 { freftime[0] = freftime[1] = 0; }
std::time_t freftime[2]
Definition: PVFitter.h:164
void PVFitter::resizepvStore ( unsigned int  rmSize)
inline

Definition at line 109 of file PVFitter.h.

References MetAnalyzer::pv().

109  {
110  pvStore_.erase(pvStore_.begin(), pvStore_.begin()+rmSize);
111  }
std::vector< BeamSpotFitPVData > pvStore_
Definition: PVFitter.h:202
bool PVFitter::runBXFitter ( )

Definition at line 209 of file PVFitter.cc.

References align::BeamSpot, bxMap_, errorScale_, fbeamspot, fbspotMap, fcn(), fwidthX, fwidthXerr, fwidthY, fwidthYerr, fwidthZ, fwidthZerr, genParticles_cff::map, makeMuonMisalignmentScenario::matrix, minNrVertices_, funct::pow(), reco::BeamSpot::setBeamWidthX(), reco::BeamSpot::setBeamWidthY(), FcnBeamSpotFitPV::setLimits(), reco::BeamSpot::setType(), sigmaCut_, findQualityFiles::size, and reco::BeamSpot::Tracker.

Referenced by BeamFitter::runPVandTrkFitter().

209  {
210 
211  using namespace ROOT::Minuit2;
212  edm::LogInfo("PVFitter") << " Number of bunch crossings: " << bxMap_.size() << std::endl;
213 
214  bool fit_ok = true;
215 
216  for ( std::map<int,std::vector<BeamSpotFitPVData> >::const_iterator pvStore = bxMap_.begin();
217  pvStore!=bxMap_.end(); ++pvStore) {
218 
219  // first set null beam spot in case
220  // fit fails
221  fbspotMap[pvStore->first] = reco::BeamSpot();
222 
223  edm::LogInfo("PVFitter") << " Number of PVs collected for PVFitter: " << (pvStore->second).size() << " in bx: " << pvStore->first << std::endl;
224 
225  if ( (pvStore->second).size() <= minNrVertices_ ) {
226  edm::LogWarning("PVFitter") << " not enough PVs, continue" << std::endl;
227  fit_ok = false;
228  continue;
229  }
230 
231  //bool fit_ok = false;
232  edm::LogInfo("PVFitter") << "Calculating beam spot with PVs ..." << std::endl;
233 
234  //
235  // LL function and fitter
236  //
237  FcnBeamSpotFitPV* fcn = new FcnBeamSpotFitPV(pvStore->second);
238  //
239  // fit parameters: positions, widths, x-y correlations, tilts in xz and yz
240  //
241  MnUserParameters upar;
242  upar.Add("x" , 0. , 0.02 , -10., 10.); // 0
243  upar.Add("y" , 0. , 0.02 , -10., 10.); // 1
244  upar.Add("z" , 0. , 0.20 , -30., 30.); // 2
245  upar.Add("ex" , 0.015, 0.01 , 0. , 10.); // 3
246  upar.Add("corrxy", 0. , 0.02 , -1. , 1. ); // 4
247  upar.Add("ey" , 0.015, 0.01 , 0. , 10.); // 5
248  upar.Add("dxdz" , 0. , 0.0002, -0.1, 0.1); // 6
249  upar.Add("dydz" , 0. , 0.0002, -0.1, 0.1); // 7
250  upar.Add("ez" , 1. , 0.1 , 0. , 30.); // 8
251  upar.Add("scale", errorScale_ , errorScale_/10.,
252  errorScale_/2., errorScale_*2.); // 9
253  MnMigrad migrad(*fcn, upar);
254 
255  //
256  // first iteration without correlations
257  //
258  upar.Fix(4);
259  upar.Fix(6);
260  upar.Fix(7);
261  upar.Fix(9);
262  FunctionMinimum ierr = migrad(0,1.);
263  if ( !ierr.IsValid() ) {
264  edm::LogInfo("PVFitter") << "3D beam spot fit failed in 1st iteration" << std::endl;
265  fit_ok = false;
266  continue;
267  }
268  //
269  // refit with harder selection on vertices
270  //
271  fcn->setLimits(upar.Value(0)-sigmaCut_*upar.Value(3),
272  upar.Value(0)+sigmaCut_*upar.Value(3),
273  upar.Value(1)-sigmaCut_*upar.Value(5),
274  upar.Value(1)+sigmaCut_*upar.Value(5),
275  upar.Value(2)-sigmaCut_*upar.Value(8),
276  upar.Value(2)+sigmaCut_*upar.Value(8));
277  ierr = migrad(0,1.);
278  if ( !ierr.IsValid() ) {
279  edm::LogInfo("PVFitter") << "3D beam spot fit failed in 2nd iteration" << std::endl;
280  fit_ok = false;
281  continue;
282  }
283  //
284  // refit with correlations
285  //
286  upar.Release(4);
287  upar.Release(6);
288  upar.Release(7);
289  ierr = migrad(0,1.);
290  if ( !ierr.IsValid() ) {
291  edm::LogInfo("PVFitter") << "3D beam spot fit failed in 3rd iteration" << std::endl;
292  fit_ok = false;
293  continue;
294  }
295  // refit with floating scale factor
296  // minuitx.ReleaseParameter(9);
297  // minuitx.Minimize();
298 
299  //minuitx.PrintResults(0,0);
300 
301  fwidthX = upar.Value(3);
302  fwidthY = upar.Value(5);
303  fwidthZ = upar.Value(8);
304  fwidthXerr = upar.Error(3);
305  fwidthYerr = upar.Error(5);
306  fwidthZerr = upar.Error(8);
307 
309  // need to get the full cov matrix
310  matrix(0,0) = pow( upar.Error(0), 2);
311  matrix(1,1) = pow( upar.Error(1), 2);
312  matrix(2,2) = pow( upar.Error(2), 2);
313  matrix(3,3) = fwidthZerr * fwidthZerr;
314  matrix(4,4) = pow( upar.Error(6), 2);
315  matrix(5,5) = pow( upar.Error(7), 2);
316  matrix(6,6) = fwidthXerr * fwidthXerr;
317 
319  upar.Value(1),
320  upar.Value(2) ),
321  fwidthZ,
322  upar.Value(6), upar.Value(7),
323  fwidthX,
324  matrix );
328 
329  fbspotMap[pvStore->first] = fbeamspot;
330  edm::LogInfo("PVFitter") << "3D PV fit done for this bunch crossing."<<std::endl;
331  //delete fcn;
332  fit_ok = fit_ok & true;
333  }
334 
335  return fit_ok;
336 }
size
Write out results.
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:31
std::map< int, std::vector< BeamSpotFitPVData > > bxMap_
Definition: PVFitter.h:203
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
double fwidthY
Definition: PVFitter.h:183
double errorScale_
Definition: PVFitter.h:159
double fwidthYerr
Definition: PVFitter.h:186
double fwidthZ
Definition: PVFitter.h:184
double fwidthXerr
Definition: PVFitter.h:185
void setType(BeamType type)
set beam type
Definition: BeamSpot.h:131
reco::BeamSpot fbeamspot
Definition: PVFitter.h:139
void setBeamWidthY(double v)
Definition: BeamSpot.h:109
std::map< int, reco::BeamSpot > fbspotMap
Definition: PVFitter.h:140
double fwidthZerr
Definition: PVFitter.h:187
void fcn(int &, double *, double &, double *, int)
unsigned int minNrVertices_
Definition: PVFitter.h:152
void setLimits(float xmin, float xmax, float ymin, float ymax, float zmin, float zmax)
double sigmaCut_
Definition: PVFitter.h:160
void setBeamWidthX(double v)
Definition: BeamSpot.h:108
double fwidthX
Definition: PVFitter.h:182
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
bool PVFitter::runFitter ( )

Definition at line 339 of file PVFitter.cc.

References align::BeamSpot, do3DFit_, benchmark_cfg::errors, errorScale_, fftjetvertexadder_cfi::errX, fftjetvertexadder_cfi::errY, fftjetvertexadder_cfi::errZ, fbeamspot, fcn(), fwidthX, fwidthXerr, fwidthY, fwidthYerr, fwidthZ, fwidthZerr, hPVx, hPVy, edm::isNotFinite(), makeMuonMisalignmentScenario::matrix, minNrVertices_, funct::pow(), pvStore_, mps_update::results, reco::BeamSpot::setBeamWidthX(), reco::BeamSpot::setBeamWidthY(), reco::BeamSpot::setType(), sigmaCut_, and reco::BeamSpot::Tracker.

Referenced by AlcaBeamMonitor::endLuminosityBlock(), and BeamFitter::runPVandTrkFitter().

339  {
340 
341  using namespace ROOT::Minuit2;
342  edm::LogInfo("PVFitter") << " Number of PVs collected for PVFitter: " << pvStore_.size() << std::endl;
343 
344  if ( pvStore_.size() <= minNrVertices_ ) return false;
345 
346  //bool fit_ok = false;
347 
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");
351 
352  //Use our own copy for thread safety
353  // also do not add to global list of functions
354  TF1 gausx("localGausX","gaus",0.,1.,TF1::EAddToList::kNo);
355  TF1 gausy("localGausY","gaus",0.,1.,TF1::EAddToList::kNo);
356  TF1 gausz("localGausZ","gaus",0.,1.,TF1::EAddToList::kNo);
357 
358  h1PVx->Fit(&gausx,"QLMN0");
359  h1PVy->Fit(&gausy,"QLMN0");
360  h1PVz->Fit(&gausz,"QLMN0");
361 
362 
363  fwidthX = gausx.GetParameter(2);
364  fwidthY = gausy.GetParameter(2);
365  fwidthZ = gausz.GetParameter(2);
366  fwidthXerr = gausx.GetParError(2);
367  fwidthYerr = gausy.GetParError(2);
368  fwidthZerr = gausz.GetParError(2);
369 
370  double estX = gausx.GetParameter(1);
371  double estY = gausy.GetParameter(1);
372  double estZ = gausz.GetParameter(1);
373  double errX = fwidthX*3.;
374  double errY = fwidthY*3.;
375  double errZ = fwidthZ*3.;
376 
377  if ( ! do3DFit_ ) {
378 
380  matrix(2,2) = gausz.GetParError(1) * gausz.GetParError(1);
381  matrix(3,3) = fwidthZerr * fwidthZerr;
382  matrix(6,6) = fwidthXerr * fwidthXerr;
383 
384  fbeamspot = reco::BeamSpot( reco::BeamSpot::Point(gausx.GetParameter(1),
385  gausy.GetParameter(1),
386  gausz.GetParameter(1) ),
387  fwidthZ,
388  0., 0.,
389  fwidthX,
390  matrix );
394 
395  }
396  else { // do 3D fit
397  //
398  // LL function and fitter
399  //
401  //
402  // fit parameters: positions, widths, x-y correlations, tilts in xz and yz
403  //
404  MnUserParameters upar;
405  upar.Add("x" , estX , errX , -10. , 10. ); // 0
406  upar.Add("y" , estY , errY , -10. , 10. ); // 1
407  upar.Add("z" , estZ , errZ , -30. , 30. ); // 2
408  upar.Add("ex" , 0.015 , 0.01 , 0. , 10. ); // 3
409  upar.Add("corrxy", 0. , 0.02 , -1. , 1. ); // 4
410  upar.Add("ey" , 0.015 , 0.01 , 0. , 10. ); // 5
411  upar.Add("dxdz" , 0. , 0.0002 , -0.1 , 0.1 ); // 6
412  upar.Add("dydz" , 0. , 0.0002 , -0.1 , 0.1 ); // 7
413  upar.Add("ez" , 1. , 0.1 , 0. , 30. ); // 8
414  upar.Add("scale" , errorScale_, errorScale_/10.,errorScale_/2., errorScale_*2.); // 9
415  MnMigrad migrad(*fcn, upar);
416  //
417  // first iteration without correlations
418  //
419  migrad.Fix(4);
420  migrad.Fix(6);
421  migrad.Fix(7);
422  migrad.Fix(9);
423  FunctionMinimum ierr = migrad(0,1.);
424  if ( !ierr.IsValid() ) {
425  edm::LogWarning("PVFitter") << "3D beam spot fit failed in 1st iteration" << std::endl;
426  return false;
427  }
428  //
429  // refit with harder selection on vertices
430  //
431 
432  vector<double> results ;
433  vector<double> errors ;
434  results = ierr.UserParameters().Params() ; \
435  errors = ierr.UserParameters().Errors() ; \
436 
437  fcn->setLimits(results[0]-sigmaCut_*results[3],
438  results[0]+sigmaCut_*results[3],
439  results[1]-sigmaCut_*results[5],
440  results[1]+sigmaCut_*results[5],
441  results[2]-sigmaCut_*results[8],
442  results[2]+sigmaCut_*results[8]);
443  ierr = migrad(0,1.);
444  if ( !ierr.IsValid() ) {
445  edm::LogWarning("PVFitter") << "3D beam spot fit failed in 2nd iteration" << std::endl;
446  return false;
447  }
448  //
449  // refit with correlations
450  //
451  migrad.Release(4);
452  migrad.Release(6);
453  migrad.Release(7);
454  ierr = migrad(0,1.);
455  if ( !ierr.IsValid() ) {
456  edm::LogWarning("PVFitter") << "3D beam spot fit failed in 3rd iteration" << std::endl;
457  return false;
458  }
459  // refit with floating scale factor
460  // minuitx.ReleaseParameter(9);
461  // minuitx.Minimize();
462 
463  //minuitx.PrintResults(0,0);
464 
465  results = ierr.UserParameters().Params() ; \
466  errors = ierr.UserParameters().Errors() ; \
467 
468  fwidthX = results[3];
469  fwidthY = results[5];
470  fwidthZ = results[8];
471  fwidthXerr = errors[3];
472  fwidthYerr = errors[5];
473  fwidthZerr = errors[8];
474 
475  // check errors on widths and sigmaZ for nan
476  if ( edm::isNotFinite(fwidthXerr) || edm::isNotFinite(fwidthYerr) || edm::isNotFinite(fwidthZerr) ) {
477  edm::LogWarning("PVFitter") << "3D beam spot fit returns nan in 3rd iteration" << std::endl;
478  return false;
479  }
480 
482  // need to get the full cov matrix
483  matrix(0,0) = pow( errors[0], 2);
484  matrix(1,1) = pow( errors[1], 2);
485  matrix(2,2) = pow( errors[2], 2);
486  matrix(3,3) = fwidthZerr * fwidthZerr;
487  matrix(6,6) = fwidthXerr * fwidthXerr;
488 
490  results[1],
491  results[2] ),
492  fwidthZ,
493  results[6], results[7],
494  fwidthX,
495  matrix );
499  }
500 
501  return true; //FIXME: Need to add quality test for the fit results!
502 }
math::Error< dimension >::type CovarianceMatrix
Definition: BeamSpot.h:31
math::XYZPoint Point
point in the space
Definition: BeamSpot.h:29
double fwidthY
Definition: PVFitter.h:183
double errorScale_
Definition: PVFitter.h:159
bool do3DFit_
Definition: PVFitter.h:146
double fwidthYerr
Definition: PVFitter.h:186
double fwidthZ
Definition: PVFitter.h:184
double fwidthXerr
Definition: PVFitter.h:185
void setType(BeamType type)
set beam type
Definition: BeamSpot.h:131
reco::BeamSpot fbeamspot
Definition: PVFitter.h:139
std::vector< BeamSpotFitPVData > pvStore_
Definition: PVFitter.h:202
bool isNotFinite(T x)
Definition: isFinite.h:10
void setBeamWidthY(double v)
Definition: BeamSpot.h:109
TH2F * hPVy
Definition: PVFitter.h:166
double fwidthZerr
Definition: PVFitter.h:187
void fcn(int &, double *, double &, double *, int)
TH2F * hPVx
Definition: PVFitter.h:166
unsigned int minNrVertices_
Definition: PVFitter.h:152
double sigmaCut_
Definition: PVFitter.h:160
void setBeamWidthX(double v)
Definition: BeamSpot.h:108
double fwidthX
Definition: PVFitter.h:182
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void PVFitter::setFitLSRange ( int  ls0,
int  ls1 
)
inline

Definition at line 73 of file PVFitter.h.

73  {
74  fbeginLumiOfFit = ls0;
75  fendLumiOfFit = ls1;
76  }
int fbeginLumiOfFit
Definition: PVFitter.h:178
int fendLumiOfFit
Definition: PVFitter.h:179
void PVFitter::setRefTime ( std::time_t  t0,
std::time_t  t1 
)
inline

Definition at line 69 of file PVFitter.h.

References cscNeutronWriter_cfi::t0.

69  {
70  freftime[0] = t0;
71  freftime[1] = t1;
72  }
std::time_t freftime[2]
Definition: PVFitter.h:164
void PVFitter::setTree ( TTree *  tree)

Definition at line 204 of file PVFitter.cc.

References BeamSpotTreeData::branch(), ftree_, theBeamSpotTreeData_, and compare::tree.

Referenced by BeamFitter::BeamFitter().

204  {
205  ftree_ = tree;
207 }
BeamSpotTreeData theBeamSpotTreeData_
Definition: PVFitter.h:207
TTree * ftree_
Definition: PVFitter.h:168
void branch(TTree *tree)

Member Data Documentation

std::map< int, std::vector<BeamSpotFitPVData> > PVFitter::bxMap_
private

Definition at line 203 of file PVFitter.h.

Referenced by readEvent(), and runBXFitter().

bool PVFitter::debug_
private

Definition at line 145 of file PVFitter.h.

Referenced by initialize().

bool PVFitter::do3DFit_
private

Definition at line 146 of file PVFitter.h.

Referenced by initialize(), and runFitter().

double PVFitter::dynamicQualityCut_
private

Definition at line 204 of file PVFitter.h.

Referenced by compressStore(), initialize(), and readEvent().

double PVFitter::errorScale_
private

Definition at line 159 of file PVFitter.h.

Referenced by initialize(), runBXFitter(), and runFitter().

std::ofstream PVFitter::fasciiFile
private

Definition at line 143 of file PVFitter.h.

reco::BeamSpot PVFitter::fbeamspot
private

Definition at line 139 of file PVFitter.h.

Referenced by runBXFitter(), and runFitter().

int PVFitter::fbeginLumiOfFit
private

Definition at line 178 of file PVFitter.h.

std::map<int,reco::BeamSpot> PVFitter::fbspotMap
private

Definition at line 140 of file PVFitter.h.

Referenced by runBXFitter().

int PVFitter::fendLumiOfFit
private

Definition at line 179 of file PVFitter.h.

bool PVFitter::fFitPerBunchCrossing
private

Definition at line 141 of file PVFitter.h.

Referenced by initialize(), and readEvent().

std::time_t PVFitter::freftime[2]
private

Definition at line 164 of file PVFitter.h.

TTree* PVFitter::ftree_
private

Definition at line 168 of file PVFitter.h.

Referenced by readEvent(), and setTree().

double PVFitter::fwidthX
private

Definition at line 182 of file PVFitter.h.

Referenced by runBXFitter(), and runFitter().

double PVFitter::fwidthXerr
private

Definition at line 185 of file PVFitter.h.

Referenced by runBXFitter(), and runFitter().

double PVFitter::fwidthY
private

Definition at line 183 of file PVFitter.h.

Referenced by runBXFitter(), and runFitter().

double PVFitter::fwidthYerr
private

Definition at line 186 of file PVFitter.h.

Referenced by runBXFitter(), and runFitter().

double PVFitter::fwidthZ
private

Definition at line 184 of file PVFitter.h.

Referenced by runBXFitter(), and runFitter().

double PVFitter::fwidthZerr
private

Definition at line 187 of file PVFitter.h.

Referenced by runBXFitter(), and runFitter().

TH2F* PVFitter::hPVx
private

Definition at line 166 of file PVFitter.h.

Referenced by initialize(), readEvent(), and runFitter().

TH2F* PVFitter::hPVy
private

Definition at line 166 of file PVFitter.h.

Referenced by initialize(), readEvent(), and runFitter().

unsigned int PVFitter::maxNrVertices_
private

Definition at line 151 of file PVFitter.h.

Referenced by initialize(), and readEvent().

double PVFitter::maxVtxNormChi2_
private

Definition at line 154 of file PVFitter.h.

Referenced by initialize().

double PVFitter::maxVtxR_
private

Definition at line 157 of file PVFitter.h.

Referenced by initialize().

double PVFitter::maxVtxZ_
private

Definition at line 158 of file PVFitter.h.

Referenced by initialize().

unsigned int PVFitter::minNrVertices_
private

Definition at line 152 of file PVFitter.h.

Referenced by initialize(), runBXFitter(), and runFitter().

double PVFitter::minVtxNdf_
private

Definition at line 153 of file PVFitter.h.

Referenced by initialize(), and readEvent().

unsigned int PVFitter::minVtxTracks_
private

Definition at line 155 of file PVFitter.h.

Referenced by initialize().

double PVFitter::minVtxWgt_
private

Definition at line 156 of file PVFitter.h.

Referenced by initialize(), and readEvent().

std::map<int, int> PVFitter::npvsmap_
private

Definition at line 138 of file PVFitter.h.

std::string PVFitter::outputTxt_
private

Definition at line 149 of file PVFitter.h.

std::vector<double> PVFitter::pvQualities_
private

Definition at line 205 of file PVFitter.h.

Referenced by compressStore().

std::vector<BeamSpotFitPVData> PVFitter::pvStore_
private

Definition at line 202 of file PVFitter.h.

Referenced by compressStore(), readEvent(), and runFitter().

double PVFitter::sigmaCut_
private

Definition at line 160 of file PVFitter.h.

Referenced by initialize(), runBXFitter(), and runFitter().

BeamSpotTreeData PVFitter::theBeamSpotTreeData_
private

Definition at line 207 of file PVFitter.h.

Referenced by readEvent(), and setTree().

edm::EDGetTokenT<reco::VertexCollection> PVFitter::vertexToken_
private

Definition at line 147 of file PVFitter.h.

Referenced by initialize(), and readEvent().