CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DTSegment2DSLPhiQuality.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author S. Bolognesi and G. Cerminara - INFN Torino
5  */
6 
7 #include <iostream>
8 #include <map>
9 
20 
22 #include "Histograms.h"
23 
24 using namespace std;
25 using namespace edm;
26 
27 namespace dtsegment2dsl {
28  struct Histograms {
29  std::unique_ptr<HRes2DHit> h2DHitSuperPhi;
30  std::unique_ptr<HEff2DHit> h2DHitEff_SuperPhi;
31  };
32 } // namespace dtsegment2dsl
33 
34 using namespace dtsegment2dsl;
35 
36 // Constructor
38  // Get the debug parameter for verbose output
39  debug_ = pset.getUntrackedParameter<bool>("debug");
41 
42  // the name of the simhit collection
43  simHitLabel_ = pset.getUntrackedParameter<InputTag>("simHitLabel");
44  simHitToken_ = consumes<PSimHitContainer>(pset.getUntrackedParameter<InputTag>("simHitLabel"));
45  // the name of the 2D rec hit collection
46  segment4DLabel_ = pset.getUntrackedParameter<InputTag>("segment4DLabel");
47  segment4DToken_ = consumes<DTRecSegment4DCollection>(pset.getUntrackedParameter<InputTag>("segment4DLabel"));
48 
49  // sigma resolution on position
50  sigmaResPos_ = pset.getParameter<double>("sigmaResPos");
51  // sigma resolution on angle
52  sigmaResAngle_ = pset.getParameter<double>("sigmaResAngle");
53  doall_ = pset.getUntrackedParameter<bool>("doall", false);
54  local_ = pset.getUntrackedParameter<bool>("local", false);
55 }
56 
58  edm::Run const &run,
59  edm::EventSetup const &setup,
60  Histograms &histograms) const {
61  // Book the histos
62  histograms.h2DHitSuperPhi = std::make_unique<HRes2DHit>("SuperPhi", booker, doall_, local_);
63  if (doall_) {
64  histograms.h2DHitEff_SuperPhi = std::make_unique<HEff2DHit>("SuperPhi", booker);
65  }
66 }
67 
68 // The real analysis
70  edm::EventSetup const &setup,
71  Histograms const &histograms) const {
72  // Get the DT Geometry
73  const DTGeometry &dtGeom = setup.getData(muonGeomToken_);
74 
75  // Get the SimHit collection from the event
77  event.getByToken(simHitToken_, simHits); // FIXME: second string to be removed
78 
79  // Map simHits by chamber
80  map<DTChamberId, PSimHitContainer> simHitsPerCh;
81  for (const auto &simHit : *simHits) {
82  // Create the id of the chamber (the simHits in the DT known their wireId)
83  DTChamberId chamberId = (((DTWireId(simHit.detUnitId())).layerId()).superlayerId()).chamberId();
84  // Fill the map
85  simHitsPerCh[chamberId].push_back(simHit);
86  }
87 
88  // Get the 4D rechits from the event
90  event.getByToken(segment4DToken_, segment4Ds);
91 
92  if (!segment4Ds.isValid()) {
93  if (debug_) {
94  cout << "[DTSegment2DSLPhiQuality]**Warning: no 4D Segments with label: " << segment4DLabel_
95  << " in this event, skipping!" << endl;
96  }
97  return;
98  }
99 
100  // Loop over all chambers containing a segment
102  for (chamberId = segment4Ds->id_begin(); chamberId != segment4Ds->id_end(); ++chamberId) {
103  //------------------------- simHits ---------------------------//
104  // Get simHits of each chamber
105  PSimHitContainer simHits = simHitsPerCh[(*chamberId)];
106 
107  // Map simhits per wire
108  map<DTWireId, PSimHitContainer> simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(simHits);
109  map<DTWireId, const PSimHit *> muSimHitPerWire = DTHitQualityUtils::mapMuSimHitsPerWire(simHitsPerWire);
110  int nMuSimHit = muSimHitPerWire.size();
111  if (nMuSimHit == 0 || nMuSimHit == 1) {
112  if (debug_ && nMuSimHit == 1) {
113  cout << "[DTSegment2DSLPhiQuality] Only " << nMuSimHit << " mu SimHit in this chamber, skipping!" << endl;
114  }
115  continue; // If no or only one mu SimHit is found skip this chamber
116  }
117  if (debug_) {
118  cout << "=== Chamber " << (*chamberId) << " has " << nMuSimHit << " SimHits" << endl;
119  }
120 
121  // Find outer and inner mu SimHit to build a segment
122  pair<const PSimHit *, const PSimHit *> inAndOutSimHit = DTHitQualityUtils::findMuSimSegment(muSimHitPerWire);
123 
124  // Find direction and position of the sim Segment in Chamber RF
125  pair<LocalVector, LocalPoint> dirAndPosSimSegm =
126  DTHitQualityUtils::findMuSimSegmentDirAndPos(inAndOutSimHit, (*chamberId), dtGeom);
127 
128  LocalVector simSegmLocalDir = dirAndPosSimSegm.first;
129  LocalPoint simSegmLocalPos = dirAndPosSimSegm.second;
130  const DTChamber *chamber = dtGeom.chamber(*chamberId);
131  GlobalPoint simSegmGlobalPos = chamber->toGlobal(simSegmLocalPos);
132 
133  // Atan(x/z) angle and x position in SL RF
134  float angleSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).first;
135  float posSimSeg = simSegmLocalPos.x();
136  // Position (in eta, phi coordinates) in lobal RF
137  float etaSimSeg = simSegmGlobalPos.eta();
138  float phiSimSeg = simSegmGlobalPos.phi();
139 
140  if (debug_) {
141  cout << " Simulated segment: local direction " << simSegmLocalDir << endl
142  << " local position " << simSegmLocalPos << endl
143  << " angle " << angleSimSeg << endl;
144  }
145 
146  //---------------------------- recHits --------------------------//
147  // Get the range of rechit for the corresponding chamberId
148  bool recHitFound = false;
149  DTRecSegment4DCollection::range range = segment4Ds->get(*chamberId);
150  int nsegm = distance(range.first, range.second);
151  if (debug_) {
152  cout << " Chamber: " << *chamberId << " has " << nsegm << " 4D segments" << endl;
153  }
154 
155  if (nsegm != 0) {
156  // Find the best RecHit: look for the 4D RecHit with the phi angle closest
157  // to that of segment made of SimHits.
158  // RecHits must have delta alpha and delta position within 5 sigma of
159  // the residual distribution (we are looking for residuals of segments
160  // usefull to the track fit) for efficency purpose
161  const DTRecSegment2D *bestRecHit = nullptr;
162  bool bestRecHitFound = false;
163  double deltaAlpha = 99999;
164 
165  // Loop over the recHits of this chamberId
166  for (DTRecSegment4DCollection::const_iterator segment4D = range.first; segment4D != range.second; ++segment4D) {
167  // Check the dimension
168  if ((*segment4D).dimension() != 4) {
169  if (debug_) {
170  cout << "[DTSegment2DSLPhiQuality]***Error: This is not 4D "
171  "segment!!!"
172  << endl;
173  }
174  continue;
175  }
176 
177  // Get 2D superPhi segments from 4D segments
178  const DTChamberRecSegment2D *phiSegment2D = (*segment4D).phiSegment();
179  if ((*phiSegment2D).dimension() != 2) {
180  if (debug_) {
181  cout << "[DTSegment2DQuality]***Error: This is not 2D segment!!!" << endl;
182  }
183  abort();
184  }
185 
186  // Segment Local Direction and position (in Chamber RF)
187  LocalVector recSegDirection = (*phiSegment2D).localDirection();
188 
189  float recSegAlpha = DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).first;
190  if (debug_) {
191  cout << " RecSegment direction: " << recSegDirection << endl
192  << " position : " << (*phiSegment2D).localPosition() << endl
193  << " alpha : " << recSegAlpha << endl;
194  }
195 
196  if (fabs(recSegAlpha - angleSimSeg) < deltaAlpha) {
197  deltaAlpha = fabs(recSegAlpha - angleSimSeg);
198  bestRecHit = &(*phiSegment2D);
199  bestRecHitFound = true;
200  }
201  } // End of Loop over all 4D RecHits of this chambers
202 
203  if (bestRecHitFound) {
204  // Best rechit direction and position in Chamber RF
205  LocalPoint bestRecHitLocalPos = bestRecHit->localPosition();
206  LocalVector bestRecHitLocalDir = bestRecHit->localDirection();
207 
208  LocalError bestRecHitLocalPosErr = bestRecHit->localPositionError();
209  LocalError bestRecHitLocalDirErr = bestRecHit->localDirectionError();
210 
211  float angleBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).first;
212  if (fabs(angleBestRHit - angleSimSeg) < 5 * sigmaResAngle_ &&
213  fabs(bestRecHitLocalPos.x() - posSimSeg) < 5 * sigmaResPos_) {
214  recHitFound = true;
215  }
216 
217  // Fill Residual histos
218  histograms.h2DHitSuperPhi->fill(angleSimSeg,
219  angleBestRHit,
220  posSimSeg,
221  bestRecHitLocalPos.x(),
222  etaSimSeg,
223  phiSimSeg,
224  sqrt(bestRecHitLocalPosErr.xx()),
225  sqrt(bestRecHitLocalDirErr.xx()));
226  }
227  } // end of if (nsegm!= 0)
228 
229  // Fill Efficiency plot
230  if (doall_) {
231  histograms.h2DHitEff_SuperPhi->fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
232  }
233  } // End of loop over chambers
234 }
235 
236 // declare this as a framework plugin
edm::EDGetTokenT< edm::PSimHitContainer > simHitToken_
std::pair< double, double > findSegmentAlphaAndBeta(const LocalVector &direction)
DTSegment2DSLPhiQuality(const edm::ParameterSet &pset)
Constructor.
T getUntrackedParameter(std::string const &, T const &) const
float xx() const
Definition: LocalError.h:22
std::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
LocalPoint localPosition() const override
local position in SL frame
LocalVector localDirection() const override
the local direction in SL frame
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
void dqmAnalyze(edm::Event const &, edm::EventSetup const &, dtsegment2dsl::Histograms const &) const override
Perform the real analysis.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< HEff2DHit > h2DHitEff_SuperPhi
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
identifier iterator
Definition: RangeMap.h:130
std::pair< LocalVector, LocalPoint > findMuSimSegmentDirAndPos(const std::pair< const PSimHit *, const PSimHit * > &inAndOutSimHit, const DetId detId, const DTGeometry &muonGeom)
std::atomic< bool > debug
const uint16_t range(const Frame &aFrame)
bool getData(T &iHolder) const
Definition: EventSetup.h:128
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
T sqrt(T t)
Definition: SSEVec.h:19
edm::EDGetTokenT< DTRecSegment4DCollection > segment4DToken_
LocalError localDirectionError() const override
the local direction error (xx,xy,yy) in SL frame: only xx is not 0.
std::map< DTWireId, const PSimHit * > mapMuSimHitsPerWire(const std::map< DTWireId, edm::PSimHitContainer > &simHitWireMap)
Create a map between the Mu SimHits and corresponding MuBarWireId ;.
LocalError localPositionError() const override
local position error in SL frame
std::pair< const PSimHit *, const PSimHit * > findMuSimSegment(const std::map< DTWireId, const PSimHit * > &mapWireAndMuSimHit)
bool isValid() const
Definition: HandleBase.h:70
std::unique_ptr< HRes2DHit > h2DHitSuperPhi
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple simHits
Definition: trackerHits.py:16
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, dtsegment2dsl::Histograms &) const override
Book the DQM plots.
T eta() const
Definition: PV3DBase.h:73
tuple cout
Definition: gather_cfg.py:144
std::vector< PSimHit > PSimHitContainer
T x() const
Definition: PV3DBase.h:59
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
Definition: Run.h:45