Go to the documentation of this file.00001 #ifndef MuScleFit_H
00002 #define MuScleFit_H
00003
00012
00013
00014 #include "FWCore/Framework/interface/EDLooper.h"
00015 #include "FWCore/Utilities/interface/InputTag.h"
00016 #include "DataFormats/Candidate/interface/LeafCandidate.h"
00017 #include <CLHEP/Vector/LorentzVector.h>
00018 #include <vector>
00019
00020 #include "FWCore/Framework/interface/EventSetup.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 #include "FWCore/ServiceRegistry/interface/Service.h"
00023 #include "MuonAnalysis/MomentumScaleCalibration/interface/MuScleFitBase.h"
00024
00025 #include "DataFormats/TrackReco/interface/Track.h"
00026 #include "DataFormats/MuonReco/interface/Muon.h"
00027 #include "DataFormats/MuonReco/interface/CaloMuon.h"
00028
00029 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00030 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00031 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00032 #include "DataFormats/PatCandidates/interface/Muon.h"
00033 #include "DataFormats/PatCandidates/interface/CompositeCandidate.h"
00034
00035 #include "MuonAnalysis/MomentumScaleCalibration/interface/MuScleFitMuonSelector.h"
00036
00037 namespace edm {
00038 class ParameterSet;
00039 class Event;
00040 class EventSetup;
00041 }
00042
00043 class TH1F;
00044 class TH2F;
00045 class TProfile;
00046 class MuonServiceProxy;
00047 class TTree;
00048 class MuScleFitPlotter;
00049
00050 class MuScleFit: public edm::EDLooper, MuScleFitBase
00051 {
00052 public:
00053
00054
00055 MuScleFit( const edm::ParameterSet& pset );
00056
00057
00058
00059 virtual ~MuScleFit();
00060
00061
00062
00063 void beginOfJobInConstructor();
00064
00065
00066 virtual void endOfJob();
00067
00068 virtual void startingNewLoop( unsigned int iLoop );
00069
00070 virtual edm::EDLooper::Status endOfLoop( const edm::EventSetup& eventSetup, unsigned int iLoop );
00071 virtual void endOfFastLoop( const unsigned int iLoop );
00072
00073 virtual edm::EDLooper::Status duringLoop( const edm::Event & event, const edm::EventSetup& eventSetup );
00078 virtual void duringFastLoop();
00079
00080 template<typename T>
00081 std::vector<reco::LeafCandidate> fillMuonCollection( const std::vector<T>& tracks );
00082 private:
00083
00084 protected:
00089 void selectMuons(const edm::Event & event);
00095 void selectMuons(const int maxEvents, const TString & treeFileName);
00096
00098 template<typename T>
00099 void takeSelectedMuonType(const T & muon, std::vector<reco::Track> & tracks);
00101 bool selGlobalMuon(const pat::Muon* aMuon);
00102 bool selTrackerMuon(const pat::Muon* aMuon);
00103
00105 bool checkDeltaR( reco::Particle::LorentzVector& genMu, reco::Particle::LorentzVector& recMu );
00107 void fillComparisonHistograms( const reco::Particle::LorentzVector & genMu, const reco::Particle::LorentzVector & recoMu, const std::string & inputName, const int charge );
00108
00110 void applySmearing( reco::Particle::LorentzVector & mu );
00112 void applyBias( reco::Particle::LorentzVector & mu, const int charge );
00113
00118 void checkParameters();
00119
00120 MuonServiceProxy *theService;
00121
00122
00123
00124 int numberOfSimTracks;
00125 int numberOfSimMuons;
00126 int numberOfSimVertices;
00127 int numberOfEwkZ;
00128
00129 bool ifHepMC;
00130 bool ifGenPart;
00131
00132
00133
00134 double minResMass_hwindow[6];
00135 double maxResMass_hwindow[6];
00136
00137
00138
00139 unsigned int maxLoopNumber;
00140 unsigned int loopCounter;
00141
00142 bool fastLoop;
00143
00144 MuScleFitPlotter *plotter;
00145
00146
00147
00148 reco::Particle::LorentzVector recMu1, recMu2;
00149 int iev;
00150 int totalEvents_;
00151
00152 bool compareToSimTracks_;
00153 edm::InputTag simTracksCollection_;
00154 bool PATmuons_;
00155 std::string genParticlesName_;
00156
00157
00158 std::string inputRootTreeFileName_;
00159
00160 std::string outputRootTreeFileName_;
00161
00162 int maxEventsFromRootTree_;
00163
00164 std::string triggerResultsLabel_;
00165 std::string triggerResultsProcess_;
00166 std::string triggerPath_;
00167 bool negateTrigger_;
00168 bool saveAllToTree_;
00169
00170 std::auto_ptr<MuScleFitMuonSelector> muonSelector_;
00171 };
00172
00173 template<typename T>
00174 std::vector<reco::LeafCandidate> MuScleFit::fillMuonCollection( const std::vector<T>& tracks )
00175 {
00176 std::vector<reco::LeafCandidate> muons;
00177 typename std::vector<T>::const_iterator track;
00178 for( track = tracks.begin(); track != tracks.end(); ++track ) {
00179 reco::Particle::LorentzVector mu;
00180 mu = reco::Particle::LorentzVector(track->px(),track->py(),track->pz(),
00181 sqrt(track->p()*track->p() + MuScleFitUtils::mMu2));
00182
00183
00184 MuScleFitUtils::goodmuon++;
00185 if (debug_>0)
00186 std::cout <<std::setprecision(9)<< "Muon #" << MuScleFitUtils::goodmuon
00187 << ": initial value Pt = " << mu.Pt() << std::endl;
00188
00189 applySmearing(mu);
00190 applyBias(mu, track->charge());
00191
00192 reco::LeafCandidate muon(track->charge(),mu);
00193
00194
00195 muons.push_back (muon);
00196 }
00197 return muons;
00198 }
00199
00200 template<typename T>
00201 void MuScleFit::takeSelectedMuonType(const T & muon, std::vector<reco::Track> & tracks)
00202 {
00203
00204
00205
00206 if(muon->isGlobalMuon() && theMuonType_==1)
00207 tracks.push_back(*(muon->globalTrack()));
00208 else if(muon->isStandAloneMuon() && theMuonType_==2)
00209 tracks.push_back(*(muon->outerTrack()));
00210 else if(muon->isTrackerMuon() && theMuonType_==3)
00211 tracks.push_back(*(muon->innerTrack()));
00212
00213 else if( theMuonType_ == 10 && !(muon->isStandAloneMuon()) )
00214 tracks.push_back(*(muon->innerTrack()));
00215 else if( theMuonType_ == 11 && muon->isGlobalMuon() )
00216 tracks.push_back(*(muon->innerTrack()));
00217 else if( theMuonType_ == 13 && muon->isTrackerMuon() )
00218 tracks.push_back(*(muon->innerTrack()));
00219 }
00220
00221 #endif