CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Attributes
PatTrackAnalyzer Class Reference
Inheritance diagram for PatTrackAnalyzer:
edm::one::EDAnalyzer< edm::one::SharedResources > edm::one::EDAnalyzerBase edm::EDConsumerBase

Classes

struct  Plots
 

Public Member Functions

void analyze (const edm::Event &event, const edm::EventSetup &es) override
 
void beginJob () override
 
 PatTrackAnalyzer (const edm::ParameterSet &params)
 constructor and destructor More...
 
 ~PatTrackAnalyzer () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::SharedResources >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const *> const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Attributes

edm::EDGetTokenT< reco::BeamSpotbeamSpotToken_
 
std::vector< Plotsplots_
 
std::vector< std::string > qualities_
 
edm::EDGetTokenT< pat::MuonCollectionsrcMuonsToken_
 
edm::EDGetTokenT< edm::View< reco::Track > > srcTracksToken_
 

Additional Inherited Members

- Public Types inherited from edm::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 25 of file PatTrackAnalyzer.cc.

Constructor & Destructor Documentation

◆ PatTrackAnalyzer()

PatTrackAnalyzer::PatTrackAnalyzer ( const edm::ParameterSet params)

constructor and destructor

Definition at line 60 of file PatTrackAnalyzer.cc.

References TFileService::kSharedResource.

62  srcMuonsToken_(mayConsume<pat::MuonCollection>(params.getParameter<edm::InputTag>("src"))),
63  beamSpotToken_(consumes<reco::BeamSpot>(params.getParameter<edm::InputTag>("beamSpot"))),
64  qualities_(params.getParameter<std::vector<std::string> >("qualities")) {
65  usesResource(TFileService::kSharedResource);
66 }
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< std::string > qualities_
edm::EDGetTokenT< pat::MuonCollection > srcMuonsToken_
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
edm::EDGetTokenT< edm::View< reco::Track > > srcTracksToken_
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)

◆ ~PatTrackAnalyzer()

PatTrackAnalyzer::~PatTrackAnalyzer ( )
override

Definition at line 68 of file PatTrackAnalyzer.cc.

68 {}

Member Function Documentation

◆ analyze()

void PatTrackAnalyzer::analyze ( const edm::Event event,
const edm::EventSetup es 
)
overridevirtual

Implements edm::one::EDAnalyzerBase.

Definition at line 114 of file PatTrackAnalyzer.cc.

References funct::abs(), pwdgSkimBPark_cfi::beamSpot, beamSpotToken_, hfClusterShapes_cfi::hits, mps_fire::i, edm::HandleBase::isValid(), HLTObjectsMonitor_cfi::plots, plots_, qualities_, quality, reco::TrackBase::qualityByName(), srcMuonsToken_, srcTracksToken_, HLT_2022v11_cff::track, and tracks.

114  {
115  // handles to kinds of data we might want to read
117  edm::Handle<edm::View<reco::Track> > tracksHandle;
119 
120  // read the beam spot
121  event.getByToken(beamSpotToken_, beamSpot);
122 
123  // our internal copy of track points
124  // (we need this in order to able to simultaneously access tracks
125  // directly or embedded in PAT objects, like muons, normally you
126  // would iterate over the handle directly)
127  std::vector<const reco::Track *> tracks;
128 
129  event.getByToken(srcTracksToken_, tracksHandle);
130  if (tracksHandle.isValid()) {
131  // framework was able to read the collection as a view of
132  // tracks, no copy them to our "tracks" variable
133  for (edm::View<reco::Track>::const_iterator iter = tracksHandle->begin(); iter != tracksHandle->end(); ++iter)
134  tracks.push_back(&*iter);
135  } else {
136  // does not exist or is not a track collection
137  // let's assume it is a collection of PAT muons
138  event.getByToken(srcMuonsToken_, muonsHandle);
139 
140  // and copy them over
141  // NOTE: We are using ->globalTrack() here
142  // This means we are using the global fit over both
143  // the inner tracker and the muon stations!
144  // other alternatives are: innerTrack(), outerTrack()
145  for (pat::MuonCollection::const_iterator iter = muonsHandle->begin(); iter != muonsHandle->end(); ++iter) {
146  reco::TrackRef track = iter->globalTrack();
147  // the muon might not be a "global" muon
148  if (track.isNonnull())
149  tracks.push_back(&*track);
150  }
151  }
152 
153  // we are done filling the tracks into our "tracks" vector.
154  // now analyze them, once for each track quality category
155 
156  unsigned int nQualities = qualities_.size();
157  for (unsigned int i = 0; i < nQualities; ++i) {
158  // we convert the quality flag from its name as a string
159  // to the enumeration value used by the tracking code
160  // (which is essentially an integer number)
162 
163  // our set of plots
164  Plots &plots = plots_[i];
165 
166  // now loop over the tracks
167  for (std::vector<const reco::Track *>::const_iterator iter = tracks.begin(); iter != tracks.end(); ++iter) {
168  // this is our track
169  const reco::Track &track = **iter;
170 
171  // ignore tracks that fail the quality cut
172  if (!track.quality(quality))
173  continue;
174 
175  // and fill all the plots
176  plots.eta->Fill(track.eta());
177  plots.phi->Fill(track.phi());
178 
179  plots.pt->Fill(track.pt());
180  plots.ptErr->Fill(track.ptError());
181 
182  plots.invPt->Fill(track.qoverp());
183  plots.invPtErr->Fill(track.qoverpError());
184 
185  // the transverse IP is taken with respect to
186  // the beam spot instead of (0, 0)
187  // because the beam spot in CMS is not at (0, 0)
188  plots.d0->Fill(track.dxy(beamSpot->position()));
189  plots.d0Err->Fill(track.dxyError());
190 
191  plots.nHits->Fill(track.numberOfValidHits());
192 
193  // the hit pattern contains information about
194  // which modules of the detector have been hit
195  const reco::HitPattern &hits = track.hitPattern();
196 
197  double absEta = std::abs(track.eta());
198  // now fill the number of hits in a layer depending on eta
199  plots.pxbHitsEta->Fill(absEta, hits.numberOfValidPixelBarrelHits());
200  plots.pxeHitsEta->Fill(absEta, hits.numberOfValidPixelEndcapHits());
201  plots.tibHitsEta->Fill(absEta, hits.numberOfValidStripTIBHits());
202  plots.tobHitsEta->Fill(absEta, hits.numberOfValidStripTOBHits());
203  plots.tidHitsEta->Fill(absEta, hits.numberOfValidStripTIDHits());
204  plots.tecHitsEta->Fill(absEta, hits.numberOfValidStripTECHits());
205  }
206  }
207 }
TrackQuality
track quality
Definition: TrackBase.h:150
std::vector< Plots > plots_
std::vector< std::string > qualities_
edm::EDGetTokenT< pat::MuonCollection > srcMuonsToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
auto const & tracks
cannot be loose
bool isValid() const
Definition: HandleBase.h:70
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::EDGetTokenT< edm::View< reco::Track > > srcTracksToken_
string quality

◆ beginJob()

void PatTrackAnalyzer::beginJob ( void  )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 70 of file PatTrackAnalyzer.cc.

References compareTotals::fs, mps_fire::i, M_PI, HLTObjectsMonitor_cfi::plots, plots_, qualities_, and quality.

70  {
71  // retrieve handle to auxiliary service
72  // used for storing histograms into ROOT file
74 
75  // now book the histograms, for each category
76  unsigned int nQualities = qualities_.size();
77 
78  plots_.resize(nQualities);
79 
80  for (unsigned int i = 0; i < nQualities; ++i) {
81  // the name of the quality flag
82  const char *quality = qualities_[i].c_str();
83 
84  // the set of plots
85  Plots &plots = plots_[i];
86 
87  plots.eta = fs->make<TH1F>(Form("eta_%s", quality), Form("track \\eta (%s)", quality), 100, -3, 3);
88  plots.phi = fs->make<TH1F>(Form("phi_%s", quality), Form("track \\phi (%s)", quality), 100, -M_PI, +M_PI);
89  plots.pt = fs->make<TH1F>(Form("pt_%s", quality), Form("track p_{T} (%s)", quality), 100, 0, 10);
90  plots.ptErr = fs->make<TH1F>(Form("ptErr_%s", quality), Form("track p_{T} error (%s)", quality), 100, 0, 1);
91  plots.invPt = fs->make<TH1F>(Form("invPt_%s", quality), Form("track 1/p_{T} (%s)", quality), 100, -5, 5);
92  plots.invPtErr =
93  fs->make<TH1F>(Form("invPtErr_%s", quality), Form("track 1/p_{T} error (%s)", quality), 100, 0, 0.1);
94  plots.d0 = fs->make<TH1F>(Form("d0_%s", quality), Form("track d0 (%s)", quality), 100, 0, 0.1);
95  plots.d0Err = fs->make<TH1F>(Form("d0Err_%s", quality), Form("track d0 error (%s)", quality), 100, 0, 0.1);
96  plots.nHits =
97  fs->make<TH1F>(Form("nHits_%s", quality), Form("track number of total hits (%s)", quality), 60, 0, 60);
98 
99  plots.pxbHitsEta =
100  fs->make<TProfile>(Form("pxbHitsEta_%s", quality), Form("#hits in Pixel Barrel (%s)", quality), 100, 0, 3);
101  plots.pxeHitsEta =
102  fs->make<TProfile>(Form("pxeHitsEta_%s", quality), Form("#hits in Pixel Endcap (%s)", quality), 100, 0, 3);
103  plots.tibHitsEta = fs->make<TProfile>(
104  Form("tibHitsEta_%s", quality), Form("#hits in Tracker Inner Barrel (%s)", quality), 100, 0, 3);
105  plots.tobHitsEta = fs->make<TProfile>(
106  Form("tobHitsEta_%s", quality), Form("#hits in Tracker Outer Barrel (%s)", quality), 100, 0, 3);
107  plots.tidHitsEta = fs->make<TProfile>(
108  Form("tidHitsEta_%s", quality), Form("#hits in Tracker Inner Disk (%s)", quality), 100, 0, 3);
109  plots.tecHitsEta =
110  fs->make<TProfile>(Form("tecHitsEta_%s", quality), Form("#hits in Tracker Endcap (%s)", quality), 100, 0, 3);
111  }
112 }
std::vector< Plots > plots_
std::vector< std::string > qualities_
#define M_PI
string quality

Member Data Documentation

◆ beamSpotToken_

edm::EDGetTokenT<reco::BeamSpot> PatTrackAnalyzer::beamSpotToken_
private

Definition at line 39 of file PatTrackAnalyzer.cc.

Referenced by analyze().

◆ plots_

std::vector<Plots> PatTrackAnalyzer::plots_
private

Definition at line 57 of file PatTrackAnalyzer.cc.

Referenced by analyze(), and beginJob().

◆ qualities_

std::vector<std::string> PatTrackAnalyzer::qualities_
private

Definition at line 42 of file PatTrackAnalyzer.cc.

Referenced by analyze(), and beginJob().

◆ srcMuonsToken_

edm::EDGetTokenT<pat::MuonCollection> PatTrackAnalyzer::srcMuonsToken_
private

Definition at line 38 of file PatTrackAnalyzer.cc.

Referenced by analyze().

◆ srcTracksToken_

edm::EDGetTokenT<edm::View<reco::Track> > PatTrackAnalyzer::srcTracksToken_
private

Definition at line 37 of file PatTrackAnalyzer.cc.

Referenced by analyze().