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 edm::EDConsumerBase edm::EDConsumerBase

Public Member Functions

 TestCorrection (const edm::ParameterSet &)
 
 TestCorrection (const edm::ParameterSet &)
 
 ~TestCorrection ()
 
 ~TestCorrection ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void analyze (const edm::Event &, const edm::EventSetup &) override
 
lorentzVector correctMuon (const lorentzVector &muon)
 
lorentzVector correctMuon (const lorentzVector &muon)
 
virtual void endJob ()
 
virtual void endJob () override
 
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
 
- 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::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

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

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

Definition at line 61 of file TestCorrection.cc.

Constructor & Destructor Documentation

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

Definition at line 115 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(), AlCaHLTBitMon_QueryRunRegistry::string, MuScleFitBase::theFiles_, MuScleFitBase::theRootFileName_, uncorrectedPt_, and uncorrectedPtVsEta_.

115  :
116  MuScleFitBase( iConfig )
117 {
118  //now do what ever initialization is needed
119  TFile * outputFile = new TFile(theRootFileName_.c_str(), "RECREATE");
120  theFiles_.push_back(outputFile);
121  // outputFile_ = new TFile(theRootFileName_.c_str(), "RECREATE");
122  // outputFile_->cd();
123  outputFile->cd();
124  MuScleFitUtils::resfind = iConfig.getParameter<std::vector<int> >("resfind");
125  fillHistoMap(outputFile, 0);
126  uncorrectedPt_ = new TH1F("uncorrectedPt", "uncorrected pt", 1000, 0, 100);
127  uncorrectedPtVsEta_ = new TProfile("uncorrectedPtVsEta", "uncorrected pt vs eta", 1000, 0, 100, -3., 3.);
128  correctedPt_ = new TH1F("correctedPt", "corrected pt", 1000, 0, 100);
129  correctedPtVsEta_ = new TProfile("correctedPtVsEta", "corrected pt vs eta", 1000, 0, 100, -3., 3.);
130  eventCounter_ = 0;
131  // Create the corrector and set the parameters
132  corrector_.reset(new MomentumScaleCorrector( iConfig.getUntrackedParameter<std::string>("CorrectionsIdentifier") ) );
133  std::cout << "corrector_ = " << &*corrector_ << std::endl;
134  resolution_.reset(new ResolutionFunction(iConfig.getUntrackedParameter<std::string>("ResolutionsIdentifier") ) );
135  std::cout << "resolution_ = " << &*resolution_ << std::endl;
136  background_.reset(new BackgroundFunction(iConfig.getUntrackedParameter<std::string>("BackgroundIdentifier") ) );
137 
138  // Initialize the parameters of MuScleFitUtils from those saved in the functions.
139  // MuScleFitUtils::parScale = corrector_.getFunction(0)->parameters();
142 
143  MuScleFitUtils::parResol = resolution_->parameters();
144 }
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 146 of file TestCorrection.cc.

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

147 {
148  theFiles_[0]->cd();
149  TCanvas canvas("ptComparison","pt comparison", 1000, 800);
150  canvas.cd();
151  uncorrectedPt_->GetXaxis()->SetTitle("Pt(GeV)");
152  correctedPt_->SetLineColor(kRed);
153  TLegend * legend = new TLegend(0.7,0.71,0.98,1.);
154  legend->SetTextSize(0.02);
155  legend->SetFillColor(0); // Have a white background
156  legend->AddEntry(uncorrectedPt_, "original pt");
157  legend->AddEntry(correctedPt_, "corrected pt");
158  uncorrectedPt_->Draw();
159  correctedPt_->Draw("same");
160  legend->Draw("same");
161 
162  canvas.Write();
163  uncorrectedPt_->Write();
164  uncorrectedPtVsEta_->Write();
165  correctedPt_->Write();
166  correctedPtVsEta_->Write();
167 
168  writeHistoMap(0);
169  theFiles_[0]->Close();
170 
171  std::cout << "Total analyzed events = " << eventCounter_ << std::endl;
172 }
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 
)
overrideprivatevirtual

Implements edm::EDAnalyzer.

Definition at line 179 of file TestCorrection.cc.

References funct::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_.

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

References corrector_, and MuScleFitUtils::fromPtEtaPhiToPxPyPz().

Referenced by analyze().

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

Reimplemented from edm::EDAnalyzer.

Definition at line 66 of file TestCorrection.h.

66 {};
virtual void TestCorrection::endJob ( void  )
inlineoverrideprivatevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 69 of file TestCorrection.cc.

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

Definition at line 68 of file TestCorrection.h.

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

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

Definition at line 71 of file TestCorrection.cc.

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

Referenced by analyze().

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

Definition at line 282 of file TestCorrection.cc.

References MuScleFitBase::readProbabilityDistributionsFromFile().

Referenced by analyze().

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

Member Data Documentation

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

Definition at line 100 of file TestCorrection.cc.

Referenced by TestCorrection().

TH1F * TestCorrection::correctedPt_
private

Definition at line 93 of file TestCorrection.cc.

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

TProfile * TestCorrection::correctedPtVsEta_
private

Definition at line 94 of file TestCorrection.cc.

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

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

Definition at line 98 of file TestCorrection.cc.

Referenced by correctMuon(), and TestCorrection().

int TestCorrection::eventCounter_
private

Definition at line 96 of file TestCorrection.cc.

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

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

Definition at line 99 of file TestCorrection.cc.

Referenced by TestCorrection().

TH1F * TestCorrection::uncorrectedPt_
private

Definition at line 91 of file TestCorrection.cc.

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

TProfile * TestCorrection::uncorrectedPtVsEta_
private

Definition at line 92 of file TestCorrection.cc.

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