CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CSCSegmentValidation.cc
Go to the documentation of this file.
3 #include <algorithm>
4 
6  : CSCBaseValidation(ps), theLayerHitsPerChamber(), theChamberSegmentMap(), theShowerThreshold(10) {
7  const auto &pset = ps.getParameterSet("cscSegment");
8  inputTag_ = pset.getParameter<edm::InputTag>("inputTag");
10 }
11 
13 
15  theNPerEventPlot = iBooker.book1D("CSCSegmentsPerEvent", "Number of CSC segments per event", 100, 0, 50);
16  theNRecHitsPlot = iBooker.book1D("CSCRecHitsPerSegment", "Number of CSC rec hits per segment", 8, 0, 7);
18  iBooker.book1D("CSCSegmentsPerChamberType", "Number of CSC segments per chamber type", 11, 0, 10);
19  theTypePlot4HitsNoShower = iBooker.book1D("CSCSegments4HitsNoShower", "", 100, 0, 10);
20  theTypePlot4HitsNoShowerSeg = iBooker.book1D("CSCSegments4HitsNoShowerSeg", "", 100, 0, 10);
21  theTypePlot4HitsShower = iBooker.book1D("CSCSegments4HitsShower", "", 100, 0, 10);
22  theTypePlot4HitsShowerSeg = iBooker.book1D("CSCSegments4HitsShowerSeg", "", 100, 0, 10);
23  theTypePlot5HitsNoShower = iBooker.book1D("CSCSegments5HitsNoShower", "", 100, 0, 10);
24  theTypePlot5HitsNoShowerSeg = iBooker.book1D("CSCSegments5HitsNoShowerSeg", "", 100, 0, 10);
25  theTypePlot5HitsShower = iBooker.book1D("CSCSegments5HitsShower", "", 100, 0, 10);
26  theTypePlot5HitsShowerSeg = iBooker.book1D("CSCSegments5HitsShowerSeg", "", 100, 0, 10);
27  theTypePlot6HitsNoShower = iBooker.book1D("CSCSegments6HitsNoShower", "", 100, 0, 10);
28  theTypePlot6HitsNoShowerSeg = iBooker.book1D("CSCSegments6HitsNoShowerSeg", "", 100, 0, 10);
29  theTypePlot6HitsShower = iBooker.book1D("CSCSegments6HitsShower", "", 100, 0, 10);
30  theTypePlot6HitsShowerSeg = iBooker.book1D("CSCSegments6HitsShowerSeg", "", 100, 0, 10);
31 
32  for (int i = 1; i <= 10; ++i) {
34 
35  const std::string t1("CSCSegmentRdPhiResolution_" + cn);
36  const std::string t2("CSCSegmentRdPhiPull_" + cn);
37  const std::string t3("CSCSegmentThetaResolution_" + cn);
38  const std::string t5("CSCSegmentdXdZResolution_" + cn);
39  const std::string t6("CSCSegmentdXdZPull_" + cn);
40  const std::string t7("CSCSegmentdYdZResolution_" + cn);
41  const std::string t8("CSCSegmentdYdZPull_" + cn);
42 
43  theRdPhiResolutionPlots[i - 1] = iBooker.book1D(t1, t1, 100, -0.4, 0.4);
44  theRdPhiPullPlots[i - 1] = iBooker.book1D(t2, t2, 100, -5, 5);
45  theThetaResolutionPlots[i - 1] = iBooker.book1D(t3, t3, 100, -1, 1);
46  thedXdZResolutionPlots[i - 1] = iBooker.book1D(t5, t5, 100, -1, 1);
47  thedXdZPullPlots[i - 1] = iBooker.book1D(t6, t6, 100, -5, 5);
48  thedYdZResolutionPlots[i - 1] = iBooker.book1D(t7, t7, 100, -1, 1);
49  thedYdZPullPlots[i - 1] = iBooker.book1D(t8, t8, 100, -5, 5);
50  }
51 }
52 
53 void CSCSegmentValidation::analyze(const edm::Event &e, const edm::EventSetup &eventSetup) {
54  // get the collection of CSCRecHsegmentItrD
56  e.getByToken(segments_Token_, hRecHits);
57  const CSCSegmentCollection *cscRecHits = hRecHits.product();
58 
59  theChamberSegmentMap.clear();
60  unsigned nPerEvent = 0;
61  for (auto segmentItr = cscRecHits->begin(); segmentItr != cscRecHits->end(); segmentItr++) {
62  ++nPerEvent;
63  int detId = segmentItr->geographicalId().rawId();
64  int chamberType = segmentItr->cscDetId().iChamberType();
65 
66  theNRecHitsPlot->Fill(segmentItr->nRecHits());
67  theNPerChamberTypePlot->Fill(chamberType);
68  theChamberSegmentMap[detId].push_back(*segmentItr);
69 
70  // do the resolution plots
71  const PSimHit *hit = keyHit(detId);
72  if (hit != nullptr) {
73  const CSCLayer *layer = findLayer(hit->detUnitId());
74  plotResolution(*hit, *segmentItr, layer, chamberType);
75  }
76  }
77 
78  theNPerEventPlot->Fill(nPerEvent);
79 
82 }
83 
85  // now plot efficiency by looping over all chambers with hits
86  for (auto mapItr = theLayerHitsPerChamber.begin(), mapEnd = theLayerHitsPerChamber.end(); mapItr != mapEnd;
87  ++mapItr) {
88  int chamberId = mapItr->first;
89  int nHitsInChamber = mapItr->second.size();
90  bool isShower = (nHitsInChamber > theShowerThreshold);
91  bool hasSeg = hasSegment(chamberId);
92  int chamberType = CSCDetId(chamberId).iChamberType();
93  // find how many layers were hit in this chamber
94  std::vector<int> v = mapItr->second;
95  std::sort(v.begin(), v.end());
96  // maybe can just count
97  v.erase(std::unique(v.begin(), v.end()), v.end());
98  int nLayersHit = v.size();
99 
100  if (nLayersHit == 4) {
101  if (isShower)
102  theTypePlot4HitsShower->Fill(chamberType);
103  else
104  theTypePlot4HitsNoShower->Fill(chamberType);
105 
106  if (hasSeg) {
107  if (isShower)
108  theTypePlot4HitsShowerSeg->Fill(chamberType);
109  else
110  theTypePlot4HitsNoShowerSeg->Fill(chamberType);
111  }
112  }
113 
114  if (nLayersHit == 5) {
115  if (isShower)
116  theTypePlot5HitsShower->Fill(chamberType);
117  else
118  theTypePlot5HitsNoShower->Fill(chamberType);
119 
120  if (hasSeg) {
121  if (isShower)
122  theTypePlot5HitsShowerSeg->Fill(chamberType);
123  else
124  theTypePlot5HitsNoShowerSeg->Fill(chamberType);
125  }
126  }
127 
128  if (nLayersHit == 6) {
129  if (isShower)
130  theTypePlot6HitsShower->Fill(chamberType);
131  else
132  theTypePlot6HitsNoShower->Fill(chamberType);
133 
134  if (hasSeg) {
135  if (isShower)
136  theTypePlot6HitsShowerSeg->Fill(chamberType);
137  else
138  theTypePlot6HitsNoShowerSeg->Fill(chamberType);
139  }
140  }
141  }
142 }
143 
144 bool CSCSegmentValidation::hasSegment(int chamberId) const {
145  return (theChamberSegmentMap.find(chamberId) != theChamberSegmentMap.end());
146 }
147 
149  const CSCSegment &segment,
150  const CSCLayer *layer,
151  int chamberType) {
152  GlobalPoint simHitPos = layer->toGlobal(simHit.localPosition());
153  GlobalPoint segmentPos = layer->toGlobal(segment.localPosition());
154  LocalVector simHitDir = simHit.localDirection();
155  LocalVector segmentDir = segment.localDirection();
156 
157  double dphi = segmentPos.phi() - simHitPos.phi();
158  double rdphi = segmentPos.perp() * dphi;
159  double dtheta = segmentPos.theta() - simHitPos.theta();
160 
161  double sigmax = sqrt(segment.localPositionError().xx());
162 
163  double ddxdz = segmentDir.x() / segmentDir.z() - simHitDir.x() / simHitDir.z();
164  double ddydz = segmentDir.y() / segmentDir.z() - simHitDir.y() / simHitDir.z();
165  double sigmadxdz = sqrt(segment.localDirectionError().xx());
166  double sigmadydz = sqrt(segment.localDirectionError().yy());
167 
168  theRdPhiResolutionPlots[chamberType - 1]->Fill(rdphi);
169  theRdPhiPullPlots[chamberType - 1]->Fill(rdphi / sigmax);
170  theThetaResolutionPlots[chamberType - 1]->Fill(dtheta);
171 
172  thedXdZResolutionPlots[chamberType - 1]->Fill(ddxdz);
173  thedXdZPullPlots[chamberType - 1]->Fill(ddxdz / sigmadxdz);
174  thedYdZResolutionPlots[chamberType - 1]->Fill(ddydz);
175  thedYdZPullPlots[chamberType - 1]->Fill(ddydz / sigmadydz);
176 }
177 
179  theLayerHitsPerChamber.clear();
180  std::vector<int> layersHit = theSimHitMap->detsWithHits();
181  for (auto layerItr = layersHit.begin(), layersHitEnd = layersHit.end(); layerItr != layersHitEnd; ++layerItr) {
182  CSCDetId layerId(*layerItr);
183  CSCDetId chamberId = layerId.chamberId();
184  int nhits = theSimHitMap->hits(*layerItr).size();
185  // multiple entries, so we can see showers
186  for (int i = 0; i < nhits; ++i) {
187  theLayerHitsPerChamber[chamberId.rawId()].push_back(*layerItr);
188  }
189  }
190 }
191 
192 const PSimHit *CSCSegmentValidation::keyHit(int chamberId) const {
193  auto SimHitPabsLessThan = [](const PSimHit &p1, const PSimHit &p2) -> bool { return p1.pabs() < p2.pabs(); };
194 
195  const PSimHit *result = nullptr;
196  int layerId = chamberId + 3;
197  const auto &layerHits = theSimHitMap->hits(layerId);
198 
199  if (!layerHits.empty()) {
200  // pick the hit with maximum energy
201  auto hitItr = std::max_element(layerHits.begin(), layerHits.end(), SimHitPabsLessThan);
202  result = &(*hitItr);
203  }
204  return result;
205 }
MonitorElement * theNPerEventPlot
float xx() const
Definition: LocalError.h:22
void plotResolution(const PSimHit &simHit, const CSCSegment &recHit, const CSCLayer *layer, int chamberType)
MonitorElement * theTypePlot5HitsNoShowerSeg
CSCSegmentValidation(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
LocalPoint localPosition() const override
Definition: CSCSegment.h:39
T perp() const
Definition: PV3DBase.h:69
const TString p2
Definition: fwPaths.cc:13
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
MonitorElement * theTypePlot4HitsShowerSeg
MonitorElement * theNPerChamberTypePlot
MonitorElement * theTypePlot6HitsShower
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
def unique
Definition: tier0.py:24
T y() const
Definition: PV3DBase.h:60
MonitorElement * theTypePlot5HitsNoShower
edm::EDGetTokenT< CSCSegmentCollection > segments_Token_
MonitorElement * theNRecHitsPlot
MonitorElement * theTypePlot4HitsShower
MonitorElement * theRdPhiResolutionPlots[10]
MonitorElement * theTypePlot6HitsShowerSeg
constexpr std::array< uint8_t, layerIndexSize > layer
tuple result
Definition: mps_fire.py:311
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
void Fill(long long x)
LocalVector localDirection() const override
Local direction.
Definition: CSCSegment.h:42
MonitorElement * theTypePlot4HitsNoShower
float yy() const
Definition: LocalError.h:24
Local3DPoint localPosition() const
Definition: PSimHit.h:52
const PSimHitMap * theSimHitMap
T sqrt(T t)
Definition: SSEVec.h:19
MonitorElement * theTypePlot6HitsNoShowerSeg
T z() const
Definition: PV3DBase.h:61
const TString p1
Definition: fwPaths.cc:12
const edm::PSimHitContainer & hits(int detId) const
Definition: PSimHitMap.cc:20
CSCDetId chamberId() const
Definition: CSCDetId.h:47
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
Definition: PSimHit.h:67
MonitorElement * theTypePlot6HitsNoShower
ChamberHitMap theLayerHitsPerChamber
MonitorElement * thedYdZResolutionPlots[10]
std::vector< int > detsWithHits() const
Definition: PSimHitMap.cc:29
MonitorElement * theRdPhiPullPlots[10]
LocalVector localDirection() const
Obsolete. Same as momentumAtEntry().unit(), for backward compatibility.
Definition: PSimHit.h:58
LocalError localDirectionError() const override
Error on the local direction.
Definition: CSCSegment.cc:52
std::string chamberName() const
Definition: CSCDetId.cc:92
T const * product() const
Definition: Handle.h:70
const PSimHit * keyHit(int chamberId) const
ParameterSet const & getParameterSet(std::string const &) const
MonitorElement * thedXdZPullPlots[10]
bool hasSegment(int chamberId) const
MonitorElement * theTypePlot5HitsShowerSeg
MonitorElement * theThetaResolutionPlots[10]
ChamberSegmentMap theChamberSegmentMap
MonitorElement * theTypePlot4HitsNoShowerSeg
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
LocalError localPositionError() const override
Definition: CSCSegment.cc:48
void bookHistograms(DQMStore::IBooker &)
T x() const
Definition: PV3DBase.h:59
void analyze(const edm::Event &, const edm::EventSetup &) override
MonitorElement * theTypePlot5HitsShower
const CSCLayer * findLayer(int detId) const
unsigned int detUnitId() const
Definition: PSimHit.h:97
MonitorElement * thedXdZResolutionPlots[10]
MonitorElement * thedYdZPullPlots[10]