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

Public Member Functions

 TestCorrection (const edm::ParameterSet &)
 
 ~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 &)
 
lorentzVector correctMuon (const lorentzVector &muon)
 
virtual void endJob ()
 
template<typename T >
std::vector< reco::LeafCandidatefillMuonCollection (const std::vector< T > &tracks)
 
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)
 
- 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 59 of file TestCorrection.h.

Constructor & Destructor Documentation

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

Definition at line 20 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_.

20  :
21  MuScleFitBase( iConfig )
22 {
23  //now do what ever initialization is needed
24  TFile * outputFile = new TFile(theRootFileName_.c_str(), "RECREATE");
25  theFiles_.push_back(outputFile);
26  // outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
27  // outputFile_->cd();
28  outputFile->cd();
29  MuScleFitUtils::resfind = iConfig.getParameter<std::vector<int> >("resfind");
30  fillHistoMap(outputFile, 0);
31  uncorrectedPt_ = new TH1F("uncorrectedPt", "uncorrected pt", 1000, 0, 100);
32  uncorrectedPtVsEta_ = new TProfile("uncorrectedPtVsEta", "uncorrected pt vs eta", 1000, 0, 100, -3., 3.);
33  correctedPt_ = new TH1F("correctedPt", "corrected pt", 1000, 0, 100);
34  correctedPtVsEta_ = new TProfile("correctedPtVsEta", "corrected pt vs eta", 1000, 0, 100, -3., 3.);
35  eventCounter_ = 0;
36  // Create the corrector and set the parameters
37  corrector_.reset(new MomentumScaleCorrector( iConfig.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) );
38  std::cout << "corrector_ = " << &*corrector_ << std::endl;
39  resolution_.reset(new ResolutionFunction(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) );
40  std::cout << "resolution_ = " << &*resolution_ << std::endl;
41  background_.reset(new BackgroundFunction(iConfig.getUntrackedParameter<std::string>("BackgroundIdentifier") ) );
42 
43  // Initialize the parameters of MuScleFitUtils from those saved in the functions.
44  // MuScleFitUtils::parScale = corrector_.getFunction(0)->parameters();
47 
48  MuScleFitUtils::parResol = resolution_->parameters();
49 }
T getParameter(std::string const &) const
MuScleFitBase(const edm::ParameterSet &iConfig)
Definition: MuScleFitBase.h:21
T getUntrackedParameter(std::string const &, T const &) const
std::auto_ptr< MomentumScaleCorrector > corrector_
static std::vector< double > parResol
TH1F * uncorrectedPt_
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:116
std::auto_ptr< BackgroundFunction > background_
std::string theRootFileName_
Definition: MuScleFitBase.h:47
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
std::auto_ptr< ResolutionFunction > resolution_
tuple cout
Definition: gather_cfg.py:41
TProfile * uncorrectedPtVsEta_
TProfile * correctedPtVsEta_
static std::vector< int > resfind
static resolutionFunctionBase< std::vector< double > > * resolutionFunctionForVec
static resolutionFunctionBase< double * > * resolutionFunction
TestCorrection::~TestCorrection ( )

Definition at line 51 of file TestCorrection.cc.

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

52 {
53  theFiles_[0]->cd();
54  TCanvas canvas("ptComparison","pt comparison", 1000, 800);
55  canvas.cd();
56  uncorrectedPt_->GetXaxis()->SetTitle("Pt(GeV)");
57  correctedPt_->SetLineColor(kRed);
58  TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
59  legend->SetTextSize(0.02);
60  legend->SetFillColor(0); // Have a white background
61  legend->AddEntry(uncorrectedPt_, "original pt");
62  legend->AddEntry(correctedPt_, "corrected pt");
63  uncorrectedPt_->Draw();
64  correctedPt_->Draw("same");
65  legend->Draw("same");
66 
67  canvas.Write();
68  uncorrectedPt_->Write();
69  uncorrectedPtVsEta_->Write();
70  correctedPt_->Write();
71  correctedPtVsEta_->Write();
72 
73  writeHistoMap(0);
74  theFiles_[0]->Close();
75 
76  std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
77 }
TH1F * uncorrectedPt_
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:41
TProfile * uncorrectedPtVsEta_
TProfile * correctedPtVsEta_

Member Function Documentation

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

Implements edm::EDAnalyzer.

Definition at line 84 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_.

84  {
85  using namespace edm;
86 
87  initialize(iSetup);
88 
89  ++eventCounter_;
90  if ( eventCounter_%100 == 0 ) {
91  std::cout << "Event number " << eventCounter_ << std::endl;
92  }
93 
94  // Take the reco-muons, depending on the type selected in the cfg
95  // --------------------------------------------------------------
96 
97  std::vector<reco::LeafCandidate> muons;
98 
99  if (theMuonType_==1) { // GlobalMuons
101  iEvent.getByLabel (theMuonLabel_, glbMuons);
102  muons = fillMuonCollection(*glbMuons);
103  }
104  else if (theMuonType_==2) { // StandaloneMuons
106  iEvent.getByLabel (theMuonLabel_, saMuons);
107  muons = fillMuonCollection(*saMuons);
108  }
109  else if (theMuonType_==3) { // Tracker tracks
111  iEvent.getByLabel (theMuonLabel_, tracks);
112  muons = fillMuonCollection(*tracks);
113  }
114 
115  // Find the two muons from the resonance, and set ResFound bool
116  // ------------------------------------------------------------
117  std::pair <reco::Particle::LorentzVector, reco::Particle::LorentzVector> recMuFromBestRes =
120  MuScleFitUtils::SavedPair.push_back( std::make_pair (recMuFromBestRes.first, recMuFromBestRes.second) );
121  } else {
122  MuScleFitUtils::SavedPair.push_back( std::make_pair (lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.)) );
123  }
124 
125  // If resonance found, do the hard work
126  // ------------------------------------
128 
129  // Find weight and reference mass for this muon pair
130  // -------------------------------------------------
131  // double weight = MuScleFitUtils::computeWeight ((recMu1+recMu2).mass());
132 
133  // Use the correction function to correct the pt scale of the muons. Note that this takes into
134  // account the corrections from all iterations.
135  lorentzVector recMu1 = correctMuon(recMu1);
136  lorentzVector recMu2 = correctMuon(recMu2);
137 
138  reco::Particle::LorentzVector bestRecRes (recMu1+recMu2);
139 
140  //Fill histograms
141  //------------------
142  mapHisto_["hRecBestMu"]->Fill(recMu1);
143  if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5)) {
144  mapHisto_["hRecBestMu_Acc"]->Fill(recMu1);
145  }
146  mapHisto_["hRecBestMu"]->Fill(recMu2);
147  if ((std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)) {
148  mapHisto_["hRecBestMu_Acc"]->Fill(recMu2);
149  }
150  mapHisto_["hDeltaRecBestMu"]->Fill(recMu1, recMu2);
151 
152  mapHisto_["hRecBestRes"]->Fill(bestRecRes);
153  if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5) && (std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)){
154  mapHisto_["hRecBestRes_Acc"]->Fill(bestRecRes);
155  // Fill histogram of Res mass vs muon variable
156  mapHisto_["hRecBestResVSMu"]->Fill (recMu1, bestRecRes, -1);
157  mapHisto_["hRecBestResVSMu"]->Fill (recMu2, bestRecRes, +1);
158  }
159  }
160 
161  // Loop on the recMuons
162  std::vector<reco::LeafCandidate>::const_iterator recMuon = muons.begin();
163  int muonCount = 0;
164  for ( ; recMuon!=muons.end(); ++recMuon, ++muonCount ) {
165 
166  // Fill the histogram with uncorrected pt values
167  uncorrectedPt_->Fill(recMuon->pt());
168  uncorrectedPtVsEta_->Fill(recMuon->pt(), recMuon->eta());
169 
170  // Fill the histogram with corrected pt values
171  std::cout << "correcting muon["<<muonCount<<"] with pt = " << recMuon->pt() << std::endl;
172  double corrPt = (*corrector_)(*recMuon);
173  std::cout << "to pt = " << corrPt << std::endl;
174  correctedPt_->Fill(corrPt);
175  correctedPtVsEta_->Fill(corrPt, recMuon->eta());
176  // correctedPt_->Fill(recMuon->pt());
177  }
178 }
edm::InputTag theMuonLabel_
Definition: MuScleFitBase.h:46
lorentzVector correctMuon(const lorentzVector &muon)
virtual void initialize(const edm::EventSetup &)
TH1F * uncorrectedPt_
#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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
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:41
TProfile * uncorrectedPtVsEta_
TProfile * correctedPtVsEta_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:26
static std::pair< lorentzVector, lorentzVector > findBestRecoRes(const std::vector< reco::LeafCandidate > &muons)
lorentzVector TestCorrection::correctMuon ( const lorentzVector muon)
private

Definition at line 180 of file TestCorrection.cc.

References corrector_, and MuScleFitUtils::fromPtEtaPhiToPxPyPz().

Referenced by analyze().

180  {
181  double corrPt = corrector_->correct(muon);
182  double ptEtaPhiE[4] = {corrPt, muon.Eta(), muon.Phi(), muon.E()};
183  return MuScleFitUtils::fromPtEtaPhiToPxPyPz(ptEtaPhiE);
184 }
std::auto_ptr< MomentumScaleCorrector > corrector_
static lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
virtual void TestCorrection::endJob ( void  )
inlineprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 67 of file TestCorrection.h.

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

Definition at line 69 of file TestCorrection.h.

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

Referenced by analyze().

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:28
tuple tracks
Definition: testEve_cfg.py:39
tuple muons
Definition: patZpeak.py:38
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:26
void TestCorrection::initialize ( const edm::EventSetup )
privatevirtual

Definition at line 187 of file TestCorrection.cc.

References MuScleFitBase::readProbabilityDistributionsFromFile().

Referenced by analyze().

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

Member Data Documentation

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

Definition at line 98 of file TestCorrection.h.

Referenced by TestCorrection().

TH1F* TestCorrection::correctedPt_
private

Definition at line 91 of file TestCorrection.h.

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

TProfile* TestCorrection::correctedPtVsEta_
private

Definition at line 92 of file TestCorrection.h.

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

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

Definition at line 96 of file TestCorrection.h.

Referenced by correctMuon(), and TestCorrection().

int TestCorrection::eventCounter_
private

Definition at line 94 of file TestCorrection.h.

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

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

Definition at line 97 of file TestCorrection.h.

Referenced by TestCorrection().

TH1F* TestCorrection::uncorrectedPt_
private

Definition at line 89 of file TestCorrection.h.

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

TProfile* TestCorrection::uncorrectedPtVsEta_
private

Definition at line 90 of file TestCorrection.h.

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