CMS 3D CMS Logo

ShortenedTrackResolution.cc
Go to the documentation of this file.
1 // user includes
11 #include "FWCore/Utilities/interface/transform.h" // for edm::vector_transform
12 
13 // ROOT includes
14 #include "TLorentzVector.h"
15 
16 // standard includes
17 #include <fmt/printf.h>
18 
20 public:
22  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
23 
24 protected:
25  void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override;
26  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
27 
28 private:
30  const std::vector<std::string> hitsRemain_;
31  const double minTracksEta_;
32  const double maxTracksEta_;
33  const double minTracksPt_;
34  const double maxTracksPt_;
35 
36  const double maxDr_;
38  const std::vector<edm::InputTag> tracksRerecoTag_;
40  const std::vector<edm::EDGetTokenT<std::vector<reco::Track>>> tracksRerecoToken_;
41 
42  std::vector<MonitorElement *> histsPtAll_;
43 };
44 
45 // -----------------------------
46 // constructors and destructor
47 // -----------------------------
49  : folderName_(ps.getUntrackedParameter<std::string>("folderName", "TrackRefitting")),
50  hitsRemain_(ps.getUntrackedParameter<std::vector<std::string>>("hitsRemainInput")),
51  minTracksEta_(ps.getUntrackedParameter<double>("minTracksEtaInput", 0.0)),
52  maxTracksEta_(ps.getUntrackedParameter<double>("maxTracksEtaInput", 2.2)),
53  minTracksPt_(ps.getUntrackedParameter<double>("minTracksPtInput", 15.0)),
54  maxTracksPt_(ps.getUntrackedParameter<double>("maxTracksPtInput", 99999.9)),
55  maxDr_(ps.getUntrackedParameter<double>("maxDrInput", 0.01)),
56  tracksTag_(ps.getUntrackedParameter<edm::InputTag>("tracksInputTag", edm::InputTag("generalTracks", "", "DQM"))),
57  tracksRerecoTag_(ps.getUntrackedParameter<std::vector<edm::InputTag>>("tracksRerecoInputTag")),
58  tracksToken_(consumes<std::vector<reco::Track>>(tracksTag_)),
59  tracksRerecoToken_(edm::vector_transform(
60  tracksRerecoTag_, [this](edm::InputTag const &tag) { return consumes<std::vector<reco::Track>>(tag); })) {
61  histsPtAll_.clear();
62 }
63 
64 //__________________________________________________________________________________
66  edm::Run const &iRun,
67  edm::EventSetup const &iSetup) {
68  std::string currentFolder = folderName_ + "/";
69  iBook.setCurrentFolder(currentFolder);
70 
71  for (int i = 0; i < int(hitsRemain_.size()); ++i) {
72  histsPtAll_.push_back(iBook.book1D(
73  fmt::sprintf("trackPtRatio_%s", hitsRemain_[i]).c_str(),
74  fmt::sprintf("Short Track p_{T} / Full Track p_{T} - %s layers;p_{T}^{short}/p_{T}^{full};n. tracks",
75  hitsRemain_[i])
76  .c_str(),
77  101,
78  -0.05,
79  2.05));
80  }
81 }
82 
83 //__________________________________________________________________________________
85  const auto &tracks = iEvent.getHandle(tracksToken_);
86 
87  if (!tracks.isValid()) {
88  edm::LogError("ShortenedTrackResolution") << "Missing input track collection " << tracksTag_.encode() << std::endl;
89  return;
90  }
91 
92  for (const auto &track : *tracks) {
93  const reco::HitPattern &hp = track.hitPattern();
94  if (int(int(hp.numberOfValidHits()) - int(hp.numberOfAllHits(reco::HitPattern::TRACK_HITS))) != 0) {
95  break;
96  }
97 
98  TLorentzVector tvec;
99  tvec.SetPtEtaPhiM(track.pt(), track.eta(), track.phi(), 0.0);
100 
101  int i = 0; // token index
102  for (const auto &token : tracksRerecoToken_) {
103  const auto &tracks_rereco = iEvent.getHandle(token);
104 
105  for (const auto &track_rereco : *tracks_rereco) {
106  TLorentzVector trerecovec;
107  trerecovec.SetPtEtaPhiM(track_rereco.pt(), track_rereco.eta(), track_rereco.phi(), 0.0);
108  double deltaR = tvec.DeltaR(trerecovec);
109 
110  if (deltaR < maxDr_) {
111  if (track_rereco.pt() >= minTracksPt_ && track_rereco.pt() <= maxTracksPt_ &&
112  std::abs(track_rereco.eta()) >= minTracksEta_ && std::abs(track_rereco.eta()) <= maxTracksEta_) {
113  histsPtAll_[i]->Fill(1.0 * track_rereco.pt() / track.pt());
114  }
115  }
116  }
117  ++i;
118  }
119  }
120 }
121 
122 //__________________________________________________________________________________
125  desc.addUntracked<std::string>("folderName", "TrackRefitting");
126  desc.addUntracked<std::vector<std::string>>("hitsRemainInput", {});
127  desc.addUntracked<double>("minTracksEtaInput", 0.0);
128  desc.addUntracked<double>("maxTracksEtaInput", 2.2);
129  desc.addUntracked<double>("minTracksPtInput", 15.0);
130  desc.addUntracked<double>("maxTracksPtInput", 99999.9);
131  desc.addUntracked<double>("maxDrInput", 0.01);
132  desc.addUntracked<edm::InputTag>("tracksInputTag", edm::InputTag("generalTracks", "", "DQM"));
133  desc.addUntracked<std::vector<edm::InputTag>>("tracksRerecoInputTag", {});
134  descriptions.addWithDefaultLabel(desc);
135 }
136 
137 // Define this as a plug-in
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const std::vector< edm::EDGetTokenT< std::vector< reco::Track > > > tracksRerecoToken_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::string encode() const
Definition: InputTag.cc:159
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Log< level::Error, false > LogError
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
ShortenedTrackResolution(const edm::ParameterSet &)
const edm::EDGetTokenT< std::vector< reco::Track > > tracksToken_
const std::vector< edm::InputTag > tracksRerecoTag_
int iEvent
Definition: GenABIO.cc:224
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
const std::vector< std::string > hitsRemain_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
fixed size matrix
HLT enums.
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Definition: Run.h:45
std::vector< MonitorElement * > histsPtAll_