CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/MuonAnalysis/MomentumScaleCalibration/plugins/MuScleFit.h

Go to the documentation of this file.
00001 #ifndef MuScleFit_H
00002 #define MuScleFit_H
00003 
00012 // Base Class Headers
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 // #include "MuonAnalysis/MomentumScaleCalibration/interface/Histograms.h"
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 // The following is required in CMSSW v2.0.x (was contained in Muon.h in 1.6.7)
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   // Constructor
00054   // -----------
00055   MuScleFit( const edm::ParameterSet& pset );
00056 
00057   // Destructor
00058   // ----------
00059   virtual ~MuScleFit();
00060 
00061   // Operations
00062   // ----------
00063   void beginOfJobInConstructor();
00064   // void beginOfJob( const edm::EventSetup& eventSetup );
00065   // virtual void beginOfJob();
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   // Counters
00123   // --------
00124   int numberOfSimTracks;
00125   int numberOfSimMuons;
00126   int numberOfSimVertices;
00127   int numberOfEwkZ;
00128 
00129   bool ifHepMC;
00130   bool ifGenPart;
00131 
00132   // Constants
00133   // ---------
00134   double minResMass_hwindow[6];
00135   double maxResMass_hwindow[6];
00136 
00137   // Total number of loops
00138   // ---------------------
00139   unsigned int maxLoopNumber;
00140   unsigned int loopCounter;
00141 
00142   bool fastLoop;
00143 
00144   MuScleFitPlotter *plotter;
00145 
00146   // The reconstructed muon 4-momenta to be put in the tree
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   // Input Root Tree file name. If empty events are read from the edm root file.
00158   std::string inputRootTreeFileName_;
00159   // Output Root Tree file name. If not empty events are dumped to this file at the end of the last iteration.
00160   std::string outputRootTreeFileName_;
00161   // Maximum number of events from root tree. It works in the same way as the maxEvents to configure a input source.
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     // Apply smearing if needed, and then bias
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     // Store modified muon
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   // std::cout<<"muon "<<muon->isGlobalMuon()<<muon->isStandAloneMuon()<<muon->isTrackerMuon()<<std::endl;
00204   //NNBB: one muon can be of many kinds at once but with the theMuonType_ we are sure
00205   // to avoid double counting of the same muon
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()) ) //particular case!!
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