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< MuScleFitMuonfillMuonCollection (const std::vector< T > &tracks)
 
template<typename T >
std::vector< MuScleFitMuonfillMuonCollection (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 64 of file TestCorrection.cc.

Constructor & Destructor Documentation

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

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

144  :
145  MuScleFitBase( iConfig )
146 {
147  //now do what ever initialization is needed
148  TFile * outputFile = new TFile(theRootFileName_.c_str(), "RECREATE");
149  theFiles_.push_back(outputFile);
150  // outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
151  // outputFile_->cd();
152  outputFile->cd();
153  MuScleFitUtils::resfind = iConfig.getParameter<std::vector<int> >("resfind");
154  fillHistoMap(outputFile, 0);
155  uncorrectedPt_ = new TH1F("uncorrectedPt", "uncorrected pt", 1000, 0, 100);
156  uncorrectedPtVsEta_ = new TProfile("uncorrectedPtVsEta", "uncorrected pt vs eta", 1000, 0, 100, -3., 3.);
157  correctedPt_ = new TH1F("correctedPt", "corrected pt", 1000, 0, 100);
158  correctedPtVsEta_ = new TProfile("correctedPtVsEta", "corrected pt vs eta", 1000, 0, 100, -3., 3.);
159  eventCounter_ = 0;
160  // Create the corrector and set the parameters
161  corrector_.reset(new MomentumScaleCorrector( iConfig.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) );
162  std::cout << "corrector_ = " << &*corrector_ << std::endl;
163  resolution_.reset(new ResolutionFunction(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) );
164  std::cout << "resolution_ = " << &*resolution_ << std::endl;
165  background_.reset(new BackgroundFunction(iConfig.getUntrackedParameter<std::string>("BackgroundIdentifier") ) );
166 
167  // Initialize the parameters of MuScleFitUtils from those saved in the functions.
168  // MuScleFitUtils::parScale = corrector_.getFunction(0)->parameters();
171 
172  MuScleFitUtils::parResol = resolution_->parameters();
173 }
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 175 of file TestCorrection.cc.

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

176 {
177  theFiles_[0]->cd();
178  TCanvas canvas("ptComparison","pt comparison", 1000, 800);
179  canvas.cd();
180  uncorrectedPt_->GetXaxis()->SetTitle("Pt(GeV)");
181  correctedPt_->SetLineColor(kRed);
182  TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
183  legend->SetTextSize(0.02);
184  legend->SetFillColor(0); // Have a white background
185  legend->AddEntry(uncorrectedPt_, "original pt");
186  legend->AddEntry(correctedPt_, "corrected pt");
187  uncorrectedPt_->Draw();
188  correctedPt_->Draw("same");
189  legend->Draw("same");
190 
191  canvas.Write();
192  uncorrectedPt_->Write();
193  uncorrectedPtVsEta_->Write();
194  correctedPt_->Write();
195  correctedPtVsEta_->Write();
196 
197  writeHistoMap(0);
198  theFiles_[0]->Close();
199 
200  std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
201 }
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 208 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_.

208  {
209  using namespace edm;
210 
211  initialize(iSetup);
212 
213  ++eventCounter_;
214  if ( eventCounter_%100 == 0 ) {
215  std::cout << "Event number " << eventCounter_ << std::endl;
216  }
217 
218  // Take the reco-muons, depending on the type selected in the cfg
219  // --------------------------------------------------------------
220 
221  std::vector<MuScleFitMuon> muons;
222 
223  if (theMuonType_==1) { // GlobalMuons
225  iEvent.getByLabel (theMuonLabel_, glbMuons);
226  muons = fillMuonCollection(*glbMuons);
227  }
228  else if (theMuonType_==2) { // StandaloneMuons
230  iEvent.getByLabel (theMuonLabel_, saMuons);
231  muons = fillMuonCollection(*saMuons);
232  }
233  else if (theMuonType_==3) { // Tracker tracks
235  iEvent.getByLabel (theMuonLabel_, tracks);
236  muons = fillMuonCollection(*tracks);
237  }
238 
239  // Find the two muons from the resonance, and set ResFound bool
240  // ------------------------------------------------------------
241  std::pair <MuScleFitMuon, MuScleFitMuon> recMuFromBestRes =
244  MuScleFitUtils::SavedPair.push_back( std::make_pair (recMuFromBestRes.first.p4(), recMuFromBestRes.second.p4()) );
245  } else {
246  MuScleFitUtils::SavedPair.push_back( std::make_pair (lorentzVector(0.,0.,0.,0.), lorentzVector(0.,0.,0.,0.)) );
247  }
248 
249  // If resonance found, do the hard work
250  // ------------------------------------
252 
253  // Find weight and reference mass for this muon pair
254  // -------------------------------------------------
255  // double weight = MuScleFitUtils::computeWeight ((recMu1+recMu2).mass());
256 
257  // Use the correction function to correct the pt scale of the muons. Note that this takes into
258  // account the corrections from all iterations.
259  lorentzVector recMu1 = correctMuon(recMu1);
260  lorentzVector recMu2 = correctMuon(recMu2);
261 
262  reco::Particle::LorentzVector bestRecRes (recMu1+recMu2);
263 
264  //Fill histograms
265  //------------------
266  mapHisto_["hRecBestMu"]->Fill(recMu1);
267  if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5)) {
268  mapHisto_["hRecBestMu_Acc"]->Fill(recMu1);
269  }
270  mapHisto_["hRecBestMu"]->Fill(recMu2);
271  if ((std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)) {
272  mapHisto_["hRecBestMu_Acc"]->Fill(recMu2);
273  }
274  mapHisto_["hDeltaRecBestMu"]->Fill(recMu1, recMu2);
275 
276  mapHisto_["hRecBestRes"]->Fill(bestRecRes);
277  if ((std::abs(recMu1.eta())<2.5) && (recMu1.pt()>2.5) && (std::abs(recMu2.eta())<2.5) && (recMu2.pt()>2.5)){
278  mapHisto_["hRecBestRes_Acc"]->Fill(bestRecRes);
279  // Fill histogram of Res mass vs muon variable
280  mapHisto_["hRecBestResVSMu"]->Fill (recMu1, bestRecRes, -1);
281  mapHisto_["hRecBestResVSMu"]->Fill (recMu2, bestRecRes, +1);
282  }
283  }
284 
285  // Loop on the recMuons
286  std::vector<MuScleFitMuon>::const_iterator recMuon = muons.begin();
287  int muonCount = 0;
288  for ( ; recMuon!=muons.end(); ++recMuon, ++muonCount ) {
289 
290  // Fill the histogram with uncorrected pt values
291  uncorrectedPt_->Fill(recMuon->pt());
292  uncorrectedPtVsEta_->Fill(recMuon->pt(), recMuon->eta());
293 
294  // Fill the histogram with corrected pt values
295  std::cout << "correcting muon["<<muonCount<<"] with pt = " << recMuon->pt() << std::endl;
296  double corrPt = (*corrector_)(*recMuon);
297  std::cout << "to pt = " << corrPt << std::endl;
298  correctedPt_->Fill(corrPt);
299  correctedPtVsEta_->Fill(corrPt, recMuon->eta());
300  // correctedPt_->Fill(recMuon->pt());
301  }
302 }
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:9
static std::pair< MuScleFitMuon, MuScleFitMuon > findBestRecoRes(const std::vector< MuScleFitMuon > &muons)
static std::vector< std::pair< lorentzVector, lorentzVector > > SavedPair
TProfile * uncorrectedPtVsEta_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
std::vector< MuScleFitMuon > fillMuonCollection(const std::vector< T > &tracks)
tuple tracks
Definition: testEve_cfg.py:39
tuple muons
Definition: patZpeak.py:38
tuple cout
Definition: gather_cfg.py:121
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
lorentzVector TestCorrection::correctMuon ( const lorentzVector muon)
private
lorentzVector TestCorrection::correctMuon ( const lorentzVector muon)
private

Definition at line 304 of file TestCorrection.cc.

References corrector_, and MuScleFitUtils::fromPtEtaPhiToPxPyPz().

Referenced by analyze().

304  {
305  double corrPt = corrector_->correct(muon);
306  double ptEtaPhiE[4] = {corrPt, muon.Eta(), muon.Phi(), muon.E()};
307  return MuScleFitUtils::fromPtEtaPhiToPxPyPz(ptEtaPhiE);
308 }
static lorentzVector fromPtEtaPhiToPxPyPz(const double *ptEtaPhiE)
std::auto_ptr< MomentumScaleCorrector > corrector_
virtual void TestCorrection::endJob ( void  )
inlineprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 70 of file TestCorrection.h.

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

Reimplemented from edm::EDAnalyzer.

Definition at line 72 of file TestCorrection.cc.

72 {};
template<typename T >
std::vector<MuScleFitMuon> TestCorrection::fillMuonCollection ( const std::vector< T > &  tracks)
inlineprivate

Definition at line 72 of file TestCorrection.h.

References gather_cfg::cout, MuScleFitBase::debug_, RPCpg::mu, metsig::muon, patZpeak::muons, and mathSSE::sqrt().

73  {
74  std::vector<MuScleFitMuon> muons;
75  typename std::vector<T>::const_iterator track;
76  for( track = tracks.begin(); track != tracks.end(); ++track ) {
78  mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
79  sqrt(track->p()*track->p() + + 0.011163612));
80 
81  Double_t hitsTk(0), hitsMuon(0), ptError(0);
82  if ( const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track)) ){
83  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
84  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
85  ptError = myMu->innerTrack()->ptError();
86  }
87  else if ( const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track)) ) {
88  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
89  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
90  ptError = myMu->innerTrack()->ptError();
91  }
92  else if (const reco::Track* myMu = dynamic_cast<const reco::Track*>(&(*track))){
93  hitsTk = myMu->hitPattern().numberOfValidTrackerHits();
94  hitsMuon = myMu->hitPattern().numberOfValidMuonHits();
95  ptError = myMu->ptError();
96  }
97 
98  MuScleFitMuon muon(mu,track->charge(),ptError,hitsTk,hitsMuon,false);
99 
100  if (debug_>0) {
101  std::cout<<"[TestCorrection::fillMuonCollection] after MuScleFitMuon initialization"<<std::endl;
102  std::cout<<" muon = "<<muon<<std::endl;
103  }
104 
105  muons.push_back(muon);
106  }
107  return muons;
108  }
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
tuple cout
Definition: gather_cfg.py:121
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
Analysis-level muon class.
Definition: Muon.h:51
template<typename T >
std::vector<MuScleFitMuon> TestCorrection::fillMuonCollection ( const std::vector< T > &  tracks)
inlineprivate

Definition at line 74 of file TestCorrection.cc.

References gather_cfg::cout, MuScleFitBase::debug_, RPCpg::mu, metsig::muon, patZpeak::muons, and mathSSE::sqrt().

Referenced by analyze().

75  {
76  std::vector<MuScleFitMuon> muons;
77  typename std::vector<T>::const_iterator track;
78  for( track = tracks.begin(); track != tracks.end(); ++track ) {
80  mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
81  sqrt(track->p()*track->p() + + 0.011163612));
82 
83  Double_t hitsTk(0), hitsMuon(0), ptError(0);
84  if ( const reco::Muon* myMu = dynamic_cast<const reco::Muon*>(&(*track)) ){
85  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
86  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
87  ptError = myMu->innerTrack()->ptError();
88  }
89  else if ( const pat::Muon* myMu = dynamic_cast<const pat::Muon*>(&(*track)) ) {
90  hitsTk = myMu->innerTrack()->hitPattern().numberOfValidTrackerHits();
91  hitsMuon = myMu->innerTrack()->hitPattern().numberOfValidMuonHits();
92  ptError = myMu->innerTrack()->ptError();
93  }
94  else if (const reco::Track* myMu = dynamic_cast<const reco::Track*>(&(*track))){
95  hitsTk = myMu->hitPattern().numberOfValidTrackerHits();
96  hitsMuon = myMu->hitPattern().numberOfValidMuonHits();
97  ptError = myMu->ptError();
98  }
99 
100  MuScleFitMuon muon(mu,track->charge(),ptError,hitsTk,hitsMuon);
101 
102  if (debug_>0) {
103  std::cout<<"[TestCorrection::fillMuonCollection] after MuScleFitMuon initialization"<<std::endl;
104  std::cout<<" muon = "<<muon<<std::endl;
105  }
106 
107  muons.push_back(muon);
108  }
109  return muons;
110  }
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
tuple cout
Definition: gather_cfg.py:121
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Particle.h:25
Analysis-level muon class.
Definition: Muon.h:51
virtual void TestCorrection::initialize ( const edm::EventSetup )
privatevirtual
void TestCorrection::initialize ( const edm::EventSetup )
privatevirtual

Definition at line 311 of file TestCorrection.cc.

References MuScleFitBase::readProbabilityDistributionsFromFile().

Referenced by analyze().

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

Member Data Documentation

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

Definition at line 129 of file TestCorrection.cc.

Referenced by TestCorrection().

TH1F * TestCorrection::correctedPt_
private

Definition at line 122 of file TestCorrection.cc.

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

TProfile * TestCorrection::correctedPtVsEta_
private

Definition at line 123 of file TestCorrection.cc.

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

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

Definition at line 127 of file TestCorrection.cc.

Referenced by correctMuon(), and TestCorrection().

int TestCorrection::eventCounter_
private

Definition at line 125 of file TestCorrection.cc.

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

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

Definition at line 128 of file TestCorrection.cc.

Referenced by TestCorrection().

TH1F * TestCorrection::uncorrectedPt_
private

Definition at line 120 of file TestCorrection.cc.

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

TProfile * TestCorrection::uncorrectedPtVsEta_
private

Definition at line 121 of file TestCorrection.cc.

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