CMS 3D CMS Logo

TkAlCaRecoMonitor.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  */
5 
15 
16 #include <string>
17 #include "TLorentzVector.h"
18 
20  : tkGeomToken_(esConsumes()),
21  mfToken_(esConsumes()),
22  trackProducer_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("TrackProducer"))),
23  referenceTrackProducer_(
24  consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("ReferenceTrackProducer"))),
25  jetCollection_(mayConsume<reco::CaloJetCollection>(iConfig.getParameter<edm::InputTag>("CaloJetCollection"))),
26  daughterMass_(iConfig.getParameter<double>("daughterMass")),
27  maxJetPt_(iConfig.getParameter<double>("maxJetPt")),
28  fillInvariantMass_(iConfig.getParameter<bool>("fillInvariantMass")),
29  fillRawIdMap_(iConfig.getParameter<bool>("fillRawIdMap")),
30  runsOnReco_(iConfig.getParameter<bool>("runsOnReco")),
31  useSignedR_(iConfig.getParameter<bool>("useSignedR")) {
32  // copy configuration object to use it in bookHistograms
33  conf_ = iConfig;
34 }
35 
37  std::string histname; // for naming the histograms according to algorithm used
38 
40  std::string MEFolderName = conf_.getParameter<std::string>("FolderName");
41  iBooker.setCurrentFolder(MEFolderName + "/TkAlignmentSpecific");
42 
43  //
44  unsigned int MassBin = conf_.getParameter<unsigned int>("MassBin");
45  double MassMin = conf_.getParameter<double>("MassMin");
46  double MassMax = conf_.getParameter<double>("MassMax");
47 
48  if (fillInvariantMass_) {
49  histname = "InvariantMass_";
50  invariantMass_ = iBooker.book1D(histname + AlgoName, histname + AlgoName, MassBin, MassMin, MassMax);
51  invariantMass_->setAxisTitle("invariant Mass / GeV");
52  } else {
53  invariantMass_ = nullptr;
54  }
55 
56  unsigned int TrackPtPositiveBin = conf_.getParameter<unsigned int>("TrackPtBin");
57  double TrackPtPositiveMin = conf_.getParameter<double>("TrackPtMin");
58  double TrackPtPositiveMax = conf_.getParameter<double>("TrackPtMax");
59 
60  histname = "TrackPtPositive_";
61  TrackPtPositive_ = iBooker.book1D(
62  histname + AlgoName, histname + AlgoName, TrackPtPositiveBin, TrackPtPositiveMin, TrackPtPositiveMax);
63  TrackPtPositive_->setAxisTitle("p_{T} of tracks charge > 0");
64 
65  unsigned int TrackPtNegativeBin = conf_.getParameter<unsigned int>("TrackPtBin");
66  double TrackPtNegativeMin = conf_.getParameter<double>("TrackPtMin");
67  double TrackPtNegativeMax = conf_.getParameter<double>("TrackPtMax");
68 
69  histname = "TrackPtNegative_";
70  TrackPtNegative_ = iBooker.book1D(
71  histname + AlgoName, histname + AlgoName, TrackPtNegativeBin, TrackPtNegativeMin, TrackPtNegativeMax);
72  TrackPtNegative_->setAxisTitle("p_{T} of tracks charge < 0");
73 
74  histname = "TrackQuality_";
75  TrackQuality_ = iBooker.book1D(
76  histname + AlgoName, histname + AlgoName, reco::TrackBase::qualitySize, -0.5, reco::TrackBase::qualitySize - 0.5);
77  TrackQuality_->setAxisTitle("quality");
78  for (int i = 0; i < reco::TrackBase::qualitySize; ++i) {
79  TrackQuality_->getTH1()->GetXaxis()->SetBinLabel(
81  }
82 
83  unsigned int SumChargeBin = conf_.getParameter<unsigned int>("SumChargeBin");
84  double SumChargeMin = conf_.getParameter<double>("SumChargeMin");
85  double SumChargeMax = conf_.getParameter<double>("SumChargeMax");
86 
87  histname = "SumCharge_";
88  sumCharge_ = iBooker.book1D(histname + AlgoName, histname + AlgoName, SumChargeBin, SumChargeMin, SumChargeMax);
89  sumCharge_->setAxisTitle("#SigmaCharge");
90 
91  unsigned int TrackCurvatureBin = conf_.getParameter<unsigned int>("TrackCurvatureBin");
92  double TrackCurvatureMin = conf_.getParameter<double>("TrackCurvatureMin");
93  double TrackCurvatureMax = conf_.getParameter<double>("TrackCurvatureMax");
94 
95  histname = "TrackCurvature_";
98  TrackCurvature_->setAxisTitle("#kappa track");
99 
100  if (runsOnReco_) {
101  unsigned int JetPtBin = conf_.getParameter<unsigned int>("JetPtBin");
102  double JetPtMin = conf_.getParameter<double>("JetPtMin");
103  double JetPtMax = conf_.getParameter<double>("JetPtMax");
104 
105  histname = "JetPt_";
106  jetPt_ = iBooker.book1D(histname + AlgoName, histname + AlgoName, JetPtBin, JetPtMin, JetPtMax);
107  jetPt_->setAxisTitle("jet p_{T} / GeV");
108 
109  unsigned int MinJetDeltaRBin = conf_.getParameter<unsigned int>("MinJetDeltaRBin");
110  double MinJetDeltaRMin = conf_.getParameter<double>("MinJetDeltaRMin");
111  double MinJetDeltaRMax = conf_.getParameter<double>("MinJetDeltaRMax");
112 
113  histname = "MinJetDeltaR_";
114  minJetDeltaR_ =
115  iBooker.book1D(histname + AlgoName, histname + AlgoName, MinJetDeltaRBin, MinJetDeltaRMin, MinJetDeltaRMax);
116  minJetDeltaR_->setAxisTitle("minimal Jet #DeltaR / rad");
117  } else {
118  jetPt_ = nullptr;
119  minJetDeltaR_ = nullptr;
120  }
121 
122  unsigned int MinTrackDeltaRBin = conf_.getParameter<unsigned int>("MinTrackDeltaRBin");
123  double MinTrackDeltaRMin = conf_.getParameter<double>("MinTrackDeltaRMin");
124  double MinTrackDeltaRMax = conf_.getParameter<double>("MinTrackDeltaRMax");
125 
126  histname = "MinTrackDeltaR_";
129  minTrackDeltaR_->setAxisTitle("minimal Track #DeltaR / rad");
130 
131  unsigned int TrackEfficiencyBin = conf_.getParameter<unsigned int>("TrackEfficiencyBin");
132  double TrackEfficiencyMin = conf_.getParameter<double>("TrackEfficiencyMin");
133  double TrackEfficiencyMax = conf_.getParameter<double>("TrackEfficiencyMax");
134 
135  histname = "AlCaRecoTrackEfficiency_";
138  Labels l_tp, l_rtp;
139  labelsForToken(referenceTrackProducer_, l_rtp);
140  labelsForToken(trackProducer_, l_tp);
141  AlCaRecoTrackEfficiency_->setAxisTitle("n(" + std::string(l_tp.module) + ") / n(" + std::string(l_rtp.module) + ")");
142 
143  int zBin = conf_.getParameter<unsigned int>("HitMapsZBin"); // 300
144  double zMax = conf_.getParameter<double>("HitMapZMax"); // 300.0; //cm
145 
146  int rBin = conf_.getParameter<unsigned int>("HitMapsRBin"); // 120;
147  double rMax = conf_.getParameter<double>("HitMapRMax"); // 120.0; //cm
148 
149  histname = "Hits_ZvsR_";
150  double rMin = 0.0;
151  if (useSignedR_)
152  rMin = -rMax;
153 
154  Hits_ZvsR_ = iBooker.book2D(histname + AlgoName, histname + AlgoName, zBin, -zMax, zMax, rBin, rMin, rMax);
155 
156  histname = "Hits_XvsY_";
157  Hits_XvsY_ = iBooker.book2D(histname + AlgoName, histname + AlgoName, rBin, -rMax, rMax, rBin, -rMax, rMax);
158 
159  if (fillRawIdMap_) {
160  histname = "Hits_perDetId_";
161 
162  // leads to differences in axsis between samples??
163  // int nModules = binByRawId_.size();
164  // Hits_perDetId_ = iBooker.book1D(histname+AlgoName, histname+AlgoName,
165  // nModules, static_cast<double>(nModules) -0.5,
166  // static_cast<double>(nModules) -0.5);
167  Hits_perDetId_ = iBooker.book1D(histname + AlgoName, histname + AlgoName, 16601, -0.5, 16600.5);
168  Hits_perDetId_->setAxisTitle("rawId Bins");
169 
171  // std::stringstream binLabel;
172  // for( std::map<int,int>::iterator it = binByRawId_.begin(); it !=
173  // binByRawId_.end(); ++it ){
174  // binLabel.str() = "";
175  // binLabel << (*it).first;
176  // Hits_perDetId_->getTH1()->GetXaxis()->SetBinLabel( (*it).second +1,
177  // binLabel.str().c_str());
178  // }
179  }
180 }
181 //
182 // -- Analyse
183 //
184 //*************************************************************
186 //*************************************************************
187 {
190  if (!trackCollection.isValid()) {
191  edm::LogError("Alignment") << "invalid trackcollection encountered!";
192  return;
193  }
194 
195  edm::Handle<reco::TrackCollection> referenceTrackCollection;
196  iEvent.getByToken(referenceTrackProducer_, referenceTrackCollection);
197  if (!trackCollection.isValid()) {
198  edm::LogError("Alignment") << "invalid reference track-collection encountered!";
199  return;
200  }
201 
202  const auto &geometry = iSetup.getHandle(tkGeomToken_);
203  if (!geometry.isValid()) {
204  edm::LogError("Alignment") << "invalid geometry found in event setup!";
205  }
206 
207  const auto &magneticField = iSetup.getHandle(mfToken_);
208  if (!magneticField.isValid()) {
209  edm::LogError("Alignment") << "invalid magnetic field configuration encountered!";
210  return;
211  }
212 
214  if (runsOnReco_) {
215  iEvent.getByToken(jetCollection_, jets);
216  if (!jets.isValid()) {
217  edm::LogError("Alignment") << "no jet collection found in event!";
218  }
219  }
220  // fill only once - not yet in beginJob since no access to geometry
221  if (fillRawIdMap_ && binByRawId_.empty())
222  this->fillRawIdMap(*geometry);
223 
224  AlCaRecoTrackEfficiency_->Fill(static_cast<double>((*trackCollection).size()) / (*referenceTrackCollection).size());
225 
226  double sumOfCharges = 0;
227  for (const auto &track : *trackCollection) {
228  double dR2 = 0;
229  if (runsOnReco_) {
230  double minJetDeltaR2 = 10 * 10; // some number > 2pi
231  for (const auto &itJet : *jets) {
232  jetPt_->Fill(itJet.pt());
233  dR2 = deltaR2(track, itJet);
234  if (itJet.pt() > maxJetPt_ && dR2 < minJetDeltaR2)
235  minJetDeltaR2 = dR2;
236 
237  // edm::LogInfo("Alignment") <<"> isolated: "<< isolated << " jetPt "<<
238  // (*itJet).pt() <<" deltaR: "<< deltaR(*(*it),(*itJet)) ;
239  }
240  minJetDeltaR_->Fill(std::sqrt(minJetDeltaR2));
241  }
242 
243  double minTrackDeltaR2 = 10 * 10; // some number > 2pi
244  for (const auto &track2 : *trackCollection) {
245  dR2 = deltaR2(track, track2);
246  if (dR2 < minTrackDeltaR2 && dR2 > 1e-12)
247  minTrackDeltaR2 = dR2;
248  }
249 
250  for (int i = 0; i < reco::TrackBase::qualitySize; ++i) {
251  if (track.quality(reco::TrackBase::TrackQuality(i))) {
252  TrackQuality_->Fill(i);
253  }
254  }
255 
256  GlobalPoint gPoint(track.vx(), track.vy(), track.vz());
257  double B = magneticField->inTesla(gPoint).z();
258  double curv = -track.charge() * 0.002998 * B / track.pt();
259  TrackCurvature_->Fill(curv);
260 
261  track.charge() > 0 ? TrackPtPositive_->Fill(track.pt()) : TrackPtNegative_->Fill(track.pt());
262 
263  minTrackDeltaR_->Fill(std::sqrt(minTrackDeltaR2));
265  sumOfCharges += track.charge();
266  }
267 
268  sumCharge_->Fill(sumOfCharges);
269 
270  if (fillInvariantMass_) {
271  if ((*trackCollection).size() == 2) {
272  TLorentzVector track0(
273  (*trackCollection).at(0).px(),
274  (*trackCollection).at(0).py(),
275  (*trackCollection).at(0).pz(),
276  sqrt(((*trackCollection).at(0).p() * (*trackCollection).at(0).p()) + daughterMass_ * daughterMass_));
277  TLorentzVector track1(
278  (*trackCollection).at(1).px(),
279  (*trackCollection).at(1).py(),
280  (*trackCollection).at(1).pz(),
281  sqrt(((*trackCollection).at(1).p() * (*trackCollection).at(1).p()) + daughterMass_ * daughterMass_));
282  TLorentzVector mother = track0 + track1;
283 
284  invariantMass_->Fill(mother.M());
285  } else {
286  edm::LogInfo("Alignment") << "wrong number of tracks trackcollection encountered: " << (*trackCollection).size();
287  }
288  }
289 }
290 
291 //*************************************************************
293 //*************************************************************
294 {
295  for (auto const &iHit : track.recHits()) {
296  if (iHit->isValid()) {
297  const DetId geoId(iHit->geographicalId());
298  const GeomDet *gd = geometry.idToDet(geoId);
299  // since 2_1_X local hit positions are transient. taking center of the hit
300  // module for now. The alternative would be the coarse estimation or a
301  // refit.
302  // const GlobalPoint globP( gd->toGlobal( hit->localPosition() ) );
303  const GlobalPoint globP(gd->toGlobal(Local3DPoint(0., 0., 0.)));
304  double r = sqrt(globP.x() * globP.x() + globP.y() * globP.y());
305  if (useSignedR_)
306  r *= globP.y() / fabs(globP.y());
307 
308  Hits_ZvsR_->Fill(globP.z(), r);
309  Hits_XvsY_->Fill(globP.x(), globP.y());
310 
311  if (fillRawIdMap_)
312  Hits_perDetId_->Fill(binByRawId_[geoId.rawId()]);
313  }
314  }
315 }
316 
317 //*************************************************************
319 //*************************************************************
320 {
321  std::vector<int> sortedRawIds;
322  for (const auto &iDetId : geometry.detUnitIds()) {
323  sortedRawIds.push_back(iDetId.rawId());
324  }
325  std::sort(sortedRawIds.begin(), sortedRawIds.end());
326 
327  int i = 0;
328  for (const auto &iRawId : sortedRawIds) {
329  binByRawId_[iRawId] = i;
330  ++i;
331  }
332 }
333 
334 //*************************************************************
336 //*************************************************************
337 {
339  desc.setComment("Generic track analyzer to check ALCARECO Tracker Alignment specific sample quantities");
340  desc.add<edm::InputTag>("TrackProducer", edm::InputTag("generalTracks"));
341  desc.add<edm::InputTag>("ReferenceTrackProducer", edm::InputTag("generalTrakcs"));
342  desc.add<edm::InputTag>("CaloJetCollection", edm::InputTag("ak4CaloJets"));
343  desc.add<std::string>("AlgoName", "testTkAlCaReco");
344  desc.add<std::string>("FolderName", "TkAlCaRecoMonitor");
345  desc.add<double>("daughterMass", kMuonMass_)->setComment("GeV");
346  desc.add<double>("maxJetPt", 10.)->setComment("GeV");
347  desc.add<bool>("fillInvariantMass", false);
348  desc.add<bool>("runsOnReco", false);
349  desc.add<bool>("useSignedR", false);
350  desc.add<bool>("fillRawIdMap", false);
351  desc.add<unsigned int>("MassBin", 100);
352  desc.add<double>("MassMin", 0.0);
353  desc.add<double>("MassMax", 100.0);
354  desc.add<unsigned int>("TrackPtBin", 110);
355  desc.add<double>("TrackPtMin", 0.0);
356  desc.add<double>("TrackPtMax", 110.);
357  desc.add<unsigned int>("TrackCurvatureBin", 2000);
358  desc.add<double>("TrackCurvatureMin", -0.01)->setComment("1/GeV");
359  desc.add<double>("TrackCurvatureMax", 0.01)->setComment("1/GeV");
360  desc.add<unsigned int>("SumChargeBin", 11);
361  desc.add<double>("SumChargeMin", -5.5);
362  desc.add<double>("SumChargeMax", 5.5);
363  desc.add<unsigned int>("JetPtBin", 100);
364  desc.add<double>("JetPtMin", 0.0);
365  desc.add<double>("JetPtMax", 50.0);
366  desc.add<unsigned int>("MinJetDeltaRBin", 100);
367  desc.add<double>("MinJetDeltaRMin", 0);
368  desc.add<double>("MinJetDeltaRMax", 10);
369  desc.add<unsigned int>("MinTrackDeltaRBin", 100);
370  desc.add<double>("MinTrackDeltaRMin", 0);
371  desc.add<double>("MinTrackDeltaRMax", 3.2);
372  desc.add<unsigned int>("TrackEfficiencyBin", 102);
373  desc.add<double>("TrackEfficiencyMin", -0.01);
374  desc.add<double>("TrackEfficiencyMax", 1.01);
375  desc.add<unsigned int>("HitMapsZBin", 300);
376  desc.add<double>("HitMapZMax", 300.)->setComment("cm");
377  desc.add<unsigned int>("HitMapsRBin", 120);
378  desc.add<double>("HitMapRMax", 120.)->setComment("cm");
379  descriptions.addWithDefaultLabel(desc);
380 }
381 
std::map< int, int > binByRawId_
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static std::string qualityName(TrackQuality)
Definition: TrackBase.h:572
Definition: APVGainStruct.h:7
void analyze(const edm::Event &, const edm::EventSetup &) override
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
const bool fillInvariantMass_
void fillRawIdMap(const TrackerGeometry &geometry)
TrackQuality
track quality
Definition: TrackBase.h:150
MonitorElement * TrackQuality_
const bool fillRawIdMap_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
MonitorElement * minJetDeltaR_
Log< level::Error, false > LogError
const edm::EDGetTokenT< reco::TrackCollection > trackProducer_
const edm::EDGetTokenT< reco::CaloJetCollection > jetCollection_
MonitorElement * Hits_XvsY_
MonitorElement * Hits_ZvsR_
void Fill(long long x)
MonitorElement * AlCaRecoTrackEfficiency_
const double daughterMass_
MonitorElement * sumCharge_
int iEvent
Definition: GenABIO.cc:224
ALPAKA_FN_ACC static ALPAKA_FN_INLINE float dR2(Position4 pos1, Position4 pos2)
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_
T sqrt(T t)
Definition: SSEVec.h:19
MonitorElement * invariantMass_
MonitorElement * TrackPtNegative_
void fillHitmaps(const reco::Track &track, const TrackerGeometry &geometry)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
trackCollection
Definition: JetHT_cfg.py:51
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const edm::EDGetTokenT< reco::TrackCollection > referenceTrackProducer_
static void fillDescriptions(edm::ConfigurationDescriptions &)
Log< level::Info, false > LogInfo
Definition: DetId.h:17
MonitorElement * Hits_perDetId_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
static constexpr const double kMuonMass_
MonitorElement * TrackCurvature_
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
MonitorElement * jetPt_
edm::ParameterSet conf_
fixed size matrix
HLT enums.
MonitorElement * minTrackDeltaR_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
MonitorElement * TrackPtPositive_
const double maxJetPt_
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > tkGeomToken_
Definition: Run.h:45
std::vector< CaloJet > CaloJetCollection
collection of CaloJet objects
TkAlCaRecoMonitor(const edm::ParameterSet &)
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)