CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
TestCorrection Class Reference

#include <MuonAnalysis/MomentumScaleCalibration/plugins/TestCorrection.cc>

Inheritance diagram for TestCorrection:
edm::EDAnalyzer MuScleFitBase edm::EDAnalyzer MuScleFitBase

Public Member Functions

 TestCorrection (const edm::ParameterSet &)
 
 TestCorrection (const edm::ParameterSet &)
 
 ~TestCorrection ()
 
 ~TestCorrection ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
lorentzVector correctMuon (const lorentzVector &muon)
 
lorentzVector correctMuon (const lorentzVector &muon)
 
virtual void endJob ()
 
virtual void endJob ()
 
template<typename T >
std::vector< reco::LeafCandidatefillMuonCollection (const std::vector< T > &tracks)
 
template<typename T >
std::vector< reco::LeafCandidatefillMuonCollection (const std::vector< T > &tracks)
 
virtual void initialize (const edm::EventSetup &)
 
virtual void initialize (const edm::EventSetup &)
 
- Private Member Functions inherited from MuScleFitBase
 MuScleFitBase (const edm::ParameterSet &iConfig)
 
virtual ~MuScleFitBase ()
 
void clearHistoMap ()
 Clean the histograms map. More...
 
void fillHistoMap (TFile *outputFile, unsigned int iLoop)
 Create the histograms map. More...
 
void readProbabilityDistributionsFromFile ()
 Read probability distributions from a local root file. More...
 
void writeHistoMap (const unsigned int iLoop)
 Save the histograms map to file. More...
 

Private Attributes

std::auto_ptr< BackgroundFunctionbackground_
 
TH1F * correctedPt_
 
TProfile * correctedPtVsEta_
 
std::auto_ptr
< MomentumScaleCorrector
corrector_
 
int eventCounter_
 
std::auto_ptr< ResolutionFunctionresolution_
 
TH1F * uncorrectedPt_
 
TProfile * uncorrectedPtVsEta_
 
- Private Attributes inherited from MuScleFitBase
int debug_
 
std::vector< GenMuonPairgenMuonPairs_
 Stores the genMuon pairs and the motherId prior to the creation of the internal tree. More...
 
std::map< std::string,
Histograms * > 
mapHisto_
 The map of histograms. More...
 
std::vector< MuonPairmuonPairs_
 Used to store the muon pairs plus run and event number prior to the creation of the internal tree. More...
 
std::string probabilitiesFile_
 
std::string probabilitiesFileInPath_
 
std::vector< TFile * > theFiles_
 The files were the histograms are saved. More...
 
std::string theGenInfoRootFileName_
 
edm::InputTag theMuonLabel_
 
int theMuonType_
 
std::string theRootFileName_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Description: <one line="" class="" summary>="">

Implementation: <Notes on="" implementation>="">

Definition at line 62 of file TestCorrection.cc.

Constructor & Destructor Documentation

TestCorrection::TestCorrection ( const edm::ParameterSet iConfig)
explicit

Definition at line 116 of file TestCorrection.cc.

References background_, correctedPt_, correctedPtVsEta_, corrector_, gather_cfg::cout, eventCounter_, MuScleFitBase::fillHistoMap(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), download_sqlite_cfg::outputFile, MuScleFitUtils::parResol, MuScleFitUtils::resfind, resolution_, MuScleFitUtils::resolutionFunction, MuScleFitUtils::resolutionFunctionForVec, resolutionFunctionVecService(), MuScleFitBase::theFiles_, MuScleFitBase::theRootFileName_, uncorrectedPt_, and uncorrectedPtVsEta_.

116  :
117  MuScleFitBase( iConfig )
118 {
119  //now do what ever initialization is needed
120  TFile * outputFile = new TFile(theRootFileName_.c_str(), "RECREATE");
121  theFiles_.push_back(outputFile);
122  // outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
123  // outputFile_->cd();
124  outputFile->cd();
125  MuScleFitUtils::resfind = iConfig.getParameter<std::vector<int> >("resfind");
126  fillHistoMap(outputFile, 0);
127  uncorrectedPt_ = new TH1F("uncorrectedPt", "uncorrected pt", 1000, 0, 100);
128  uncorrectedPtVsEta_ = new TProfile("uncorrectedPtVsEta", "uncorrected pt vs eta", 1000, 0, 100, -3., 3.);
129  correctedPt_ = new TH1F("correctedPt", "corrected pt", 1000, 0, 100);
130  correctedPtVsEta_ = new TProfile("correctedPtVsEta", "corrected pt vs eta", 1000, 0, 100, -3., 3.);
131  eventCounter_ = 0;
132  // Create the corrector and set the parameters
133  corrector_.reset(new MomentumScaleCorrector( iConfig.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) );
134  std::cout << "corrector_ = " << &*corrector_ << std::endl;
135  resolution_.reset(new ResolutionFunction(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) );
136  std::cout << "resolution_ = " << &*resolution_ << std::endl;
137  background_.reset(new BackgroundFunction(iConfig.getUntrackedParameter<std::string>("BackgroundIdentifier") ) );
138 
139  // Initialize the parameters of MuScleFitUtils from those saved in the functions.
140  // MuScleFitUtils::parScale = corrector_.getFunction(0)->parameters();
143 
144  MuScleFitUtils::parResol = resolution_->parameters();
145 }
T getParameter(std::string const &) const
MuScleFitBase(const edm::ParameterSet &iConfig)
Definition: MuScleFitBase.h:21
T getUntrackedParameter(std::string const &, T const &) const
TProfile * correctedPtVsEta_
static std::vector< double > parResol
std::auto_ptr< BackgroundFunction > background_
resolutionFunctionBase< std::vector< double > > * resolutionFunctionVecService(const int identifier)
Service to build the resolution functor corresponding to the passed identifier when receiving a std::...
Definition: Functions.cc:156
TProfile * uncorrectedPtVsEta_
std::string theRootFileName_
Definition: MuScleFitBase.h:47
std::auto_ptr< MomentumScaleCorrector > corrector_
void fillHistoMap(TFile *outputFile, unsigned int iLoop)
Create the histograms map.
Definition: MuScleFitBase.cc:7
std::vector< TFile * > theFiles_
The files were the histograms are saved.
Definition: MuScleFitBase.h:74
tuple cout
Definition: gather_cfg.py:121
std::auto_ptr< ResolutionFunction > resolution_
static std::vector< int > resfind
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
static resolutionFunctionBase< double * > * resolutionFunction
TestCorrection::~TestCorrection ( )

Definition at line 147 of file TestCorrection.cc.

References svgfig::canvas(), correctedPt_, correctedPtVsEta_, gather_cfg::cout, eventCounter_, MuScleFitBase::theFiles_, uncorrectedPt_, uncorrectedPtVsEta_, and MuScleFitBase::writeHistoMap().

148 {
149  theFiles_[0]->cd();
150  TCanvas canvas("ptComparison","pt comparison", 1000, 800);
151  canvas.cd();
152  uncorrectedPt_->GetXaxis()->SetTitle("Pt(GeV)");
153  correctedPt_->SetLineColor(kRed);
154  TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
155  legend->SetTextSize(0.02);
156  legend->SetFillColor(0); // Have a white background
157  legend->AddEntry(uncorrectedPt_, "original pt");
158  legend->AddEntry(correctedPt_, "corrected pt");
159  uncorrectedPt_->Draw();
160  correctedPt_->Draw("same");
161  legend->Draw("same");
162 
163  canvas.Write();
164  uncorrectedPt_->Write();
165  uncorrectedPtVsEta_->Write();
166  correctedPt_->Write();
167  correctedPtVsEta_->Write();
168 
169  writeHistoMap(0);
170  theFiles_[0]->Close();
171 
172  std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
173 }
TProfile * correctedPtVsEta_
def canvas
Definition: svgfig.py:481
TProfile * uncorrectedPtVsEta_
void writeHistoMap(const unsigned int iLoop)
Save the histograms map to file.
std::vector< TFile * > theFiles_
The files were the histograms are saved.
Definition: MuScleFitBase.h:74
tuple cout
Definition: gather_cfg.py:121
TestCorrection::TestCorrection ( const edm::ParameterSet )
explicit
TestCorrection::~TestCorrection ( )

Member Function Documentation

virtual void TestCorrection::analyze ( const edm::Event ,
const edm::EventSetup  
)
privatevirtual

Implements edm::EDAnalyzer.

void TestCorrection::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDAnalyzer.

Definition at line 180 of file TestCorrection.cc.

References abs, correctedPt_, correctedPtVsEta_, correctMuon(), gather_cfg::cout, eventCounter_, fillMuonCollection(), MuScleFitUtils::findBestRecoRes(), edm::Event::getByLabel(), initialize(), MuScleFitBase::mapHisto_, patZpeak::muons, MuScleFitUtils::ResFound, MuScleFitUtils::SavedPair, MuScleFitBase::theMuonLabel_, MuScleFitBase::theMuonType_, testEve_cfg::tracks, uncorrectedPt_, and uncorrectedPtVsEta_.

180  {
181  using namespace edm;
182 
183  initialize(iSetup);
184 
185  ++eventCounter_;
186  if ( eventCounter_%100 == 0 ) {
187  std::cout << "Event number " << eventCounter_ << std::endl;
188  }
189 
190  // Take the reco-muons, depending on the type selected in the cfg
191  // --------------------------------------------------------------
192 
193  std::vector<reco::LeafCandidate> muons;
194 
195  if (theMuonType_==1) { // GlobalMuons
197  iEvent.getByLabel (theMuonLabel_, glbMuons);
198  muons = fillMuonCollection(*glbMuons);
199  }
200  else if (theMuonType_==2) { // StandaloneMuons
202  iEvent.getByLabel (theMuonLabel_, saMuons);
203  muons = fillMuonCollection(*saMuons);
204  }
205  else if (theMuonType_==3) { // Tracker tracks
207  iEvent.getByLabel (theMuonLabel_, tracks);
208  muons = fillMuonCollection(*tracks);
209  }
210 
211  // Find the two muons from the resonance, and set ResFound bool
212  // ------------------------------------------------------------
213  std::pair <reco::Particle::LorentzVector, reco::Particle::LorentzVector> recMuFromBestRes =
216  MuScleFitUtils::SavedPair.push_back( std::make_pair (recMuFromBestRes.first, recMuFromBestRes.second) );
217  } else {
218  MuScleFitUtils::SavedPair.push_back( std::make_pair (lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.)) );
219  }
220 
221  // If resonance found, do the hard work
222  // ------------------------------------
224 
225  // Find weight and reference mass for this muon pair
226  // -------------------------------------------------
227  // double weight = MuScleFitUtils::computeWeight ((recMu1+recMu2).mass());
228 
229  // Use the correction function to correct the pt scale of the muons. Note that this takes into
230  // account the corrections from all iterations.
231  lorentzVector recMu1 = correctMuon(recMu1);
232  lorentzVector recMu2 = correctMuon(recMu2);
233 
234  reco::Particle::LorentzVector bestRecRes (recMu1+recMu2);
235 
236  //Fill histograms
237  //------------------
238  mapHisto_["hRecBestMu"]->Fill(recMu1);
239  if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5)) {
240  mapHisto_["hRecBestMu_Acc"]->Fill(recMu1);
241  }
242  mapHisto_["hRecBestMu"]->Fill(recMu2);
243  if ((std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)) {
244  mapHisto_["hRecBestMu_Acc"]->Fill(recMu2);
245  }
246  mapHisto_["hDeltaRecBestMu"]->Fill(recMu1, recMu2);
247 
248  mapHisto_["hRecBestRes"]->Fill(bestRecRes);
249  if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5) && (std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)){
250  mapHisto_["hRecBestRes_Acc"]->Fill(bestRecRes);
251  // Fill histogram of Res mass vs muon variable
252  mapHisto_["hRecBestResVSMu"]->Fill (recMu1, bestRecRes, -1);
253  mapHisto_["hRecBestResVSMu"]->Fill (recMu2, bestRecRes, +1);
254  }
255  }
256 
257  // Loop on the recMuons
258  std::vector<reco::LeafCandidate>::const_iterator recMuon = muons.begin();
259  int muonCount = 0;
260  for ( ; recMuon!=muons.end(); ++recMuon, ++muonCount ) {
261 
262  // Fill the histogram with uncorrected pt values
263  uncorrectedPt_->Fill(recMuon->pt());
264  uncorrectedPtVsEta_->Fill(recMuon->pt(), recMuon->eta());
265 
266  // Fill the histogram with corrected pt values
267  std::cout << "correcting muon["<<muonCount<<"] with pt = " << recMuon->pt() << std::endl;
268  double corrPt = (*corrector_)(*recMuon);
269  std::cout << "to pt = " << corrPt << std::endl;
270  correctedPt_->Fill(corrPt);
271  correctedPtVsEta_->Fill(corrPt, recMuon->eta());
272  // correctedPt_->Fill(recMuon->pt());
273  }
274 }
edm::InputTag theMuonLabel_
Definition: MuScleFitBase.h:46
lorentzVector correctMuon(const lorentzVector &muon)
TProfile * correctedPtVsEta_
virtual void initialize(const edm::EventSetup &)
#define abs(x)
Definition: mlp_lapack.h:159
std::map< std::string, Histograms * > mapHisto_
The map of histograms.
Definition: MuScleFitBase.h:77
static bool ResFound
reco::Particle::LorentzVector lorentzVector
Definition: GenMuonPair.h:8
static std::vector< std::pair< lorentzVector, lorentzVector > > SavedPair
TProfile * uncorrectedPtVsEta_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple tracks
Definition: testEve_cfg.py:39
tuple muons
Definition: patZpeak.py:38
std::vector< reco::LeafCandidate > fillMuonCollection(const std::vector< T > &tracks)
tuple cout
Definition: gather_cfg.py:121
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
static std::pair< lorentzVector, lorentzVector > findBestRecoRes(const std::vector< reco::LeafCandidate > &muons)
lorentzVector TestCorrection::correctMuon ( const lorentzVector muon)
private
lorentzVector TestCorrection::correctMuon ( const lorentzVector muon)
private

Definition at line 276 of file TestCorrection.cc.

References corrector_, and MuScleFitUtils::fromPtEtaPhiToPxPyPz().

Referenced by analyze().

276  {
277  double corrPt = corrector_->correct(muon);
278  double ptEtaPhiE[4] = {corrPt, muon.Eta(), muon.Phi(), muon.E()};
279  return MuScleFitUtils::fromPtEtaPhiToPxPyPz(ptEtaPhiE);
280 }
static lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
std::auto_ptr< MomentumScaleCorrector > corrector_
virtual void TestCorrection::endJob ( void  )
inlineprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 67 of file TestCorrection.h.

67 {};
virtual void TestCorrection::endJob ( void  )
inlineprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 70 of file TestCorrection.cc.

70 {};
template<typename T >
std::vector<reco::LeafCandidate> TestCorrection::fillMuonCollection ( const std::vector< T > &  tracks)
inlineprivate

Definition at line 69 of file TestCorrection.h.

References RPCpg::mu, metsig::muon, patZpeak::muons, and mathSSE::sqrt().

69  {
70  std::vector<reco::LeafCandidate> muons;
71  typename std::vector<T>::const_iterator track;
72  for (track = tracks.begin(); track != tracks.end(); ++track){
73  // Where 0.011163612 is the squared muon mass.
74  reco::Particle::LorentzVector mu(track->px(),track->py(),track->pz(),
75  sqrt(track->p()*track->p() + 0.011163612));
76  reco::LeafCandidate muon(track->charge(),mu);
77  // Store muon
78  // ----------
79  muons.push_back (muon);
80  }
81  return muons;
82  }
T sqrt(T t)
Definition: SSEVec.h:46
const int mu
Definition: Constants.h:23
tuple tracks
Definition: testEve_cfg.py:39
tuple muons
Definition: patZpeak.py:38
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
template<typename T >
std::vector<reco::LeafCandidate> TestCorrection::fillMuonCollection ( const std::vector< T > &  tracks)
inlineprivate

Definition at line 72 of file TestCorrection.cc.

References RPCpg::mu, metsig::muon, patZpeak::muons, and mathSSE::sqrt().

Referenced by analyze().

72  {
73  std::vector<reco::LeafCandidate> muons;
74  typename std::vector<T>::const_iterator track;
75  for (track = tracks.begin(); track != tracks.end(); ++track){
76  // Where 0.011163612 is the squared muon mass.
77  reco::Particle::LorentzVector mu(track->px(),track->py(),track->pz(),
78  sqrt(track->p()*track->p() + 0.011163612));
79  reco::LeafCandidate muon(track->charge(),mu);
80  // Store muon
81  // ----------
82  muons.push_back (muon);
83  }
84  return muons;
85  }
T sqrt(T t)
Definition: SSEVec.h:46
const int mu
Definition: Constants.h:23
tuple tracks
Definition: testEve_cfg.py:39
tuple muons
Definition: patZpeak.py:38
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
virtual void TestCorrection::initialize ( const edm::EventSetup )
privatevirtual
void TestCorrection::initialize ( const edm::EventSetup )
privatevirtual

Definition at line 283 of file TestCorrection.cc.

References MuScleFitBase::readProbabilityDistributionsFromFile().

Referenced by analyze().

284 {
285  // Read the pdf from root file. They are used by massProb when finding the muon pair, needed
286  // for the mass histograms.
288 }
void readProbabilityDistributionsFromFile()
Read probability distributions from a local root file.

Member Data Documentation

std::auto_ptr< BackgroundFunction > TestCorrection::background_
private

Definition at line 101 of file TestCorrection.cc.

Referenced by TestCorrection().

TH1F * TestCorrection::correctedPt_
private

Definition at line 94 of file TestCorrection.cc.

Referenced by analyze(), TestCorrection(), and ~TestCorrection().

TProfile * TestCorrection::correctedPtVsEta_
private

Definition at line 95 of file TestCorrection.cc.

Referenced by analyze(), TestCorrection(), and ~TestCorrection().

std::auto_ptr< MomentumScaleCorrector > TestCorrection::corrector_
private

Definition at line 99 of file TestCorrection.cc.

Referenced by correctMuon(), and TestCorrection().

int TestCorrection::eventCounter_
private

Definition at line 97 of file TestCorrection.cc.

Referenced by analyze(), TestCorrection(), and ~TestCorrection().

std::auto_ptr< ResolutionFunction > TestCorrection::resolution_
private

Definition at line 100 of file TestCorrection.cc.

Referenced by TestCorrection().

TH1F * TestCorrection::uncorrectedPt_
private

Definition at line 92 of file TestCorrection.cc.

Referenced by analyze(), TestCorrection(), and ~TestCorrection().

TProfile * TestCorrection::uncorrectedPtVsEta_
private

Definition at line 93 of file TestCorrection.cc.

Referenced by analyze(), TestCorrection(), and ~TestCorrection().