CMS 3D CMS Logo

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
Vector3DBase< float, LocalTag >
DTGeometry
Definition: DTGeometry.h:28
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
DTSegment2DSLPhiQuality::simHitToken_
edm::EDGetTokenT< edm::PSimHitContainer > simHitToken_
Definition: DTSegment2DSLPhiQuality.h:52
DTSegment2DSLPhiQuality::DTSegment2DSLPhiQuality
DTSegment2DSLPhiQuality(const edm::ParameterSet &pset)
Constructor.
Definition: DTSegment2DSLPhiQuality.cc:37
ESHandle.h
DTRecHitCollection.h
DTSegment2DSLPhiQuality::muonGeomToken_
edm::ESGetToken< DTGeometry, MuonGeometryRecord > muonGeomToken_
Definition: DTSegment2DSLPhiQuality.h:56
dtsegment2dsl
Definition: DTSegment2DSLPhiQuality.cc:27
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::Run
Definition: Run.h:45
dtsegment2dsl::Histograms::h2DHitEff_SuperPhi
std::unique_ptr< HEff2DHit > h2DHitEff_SuperPhi
Definition: DTSegment2DSLPhiQuality.cc:30
DTHitQualityUtils::mapMuSimHitsPerWire
std::map< DTWireId, const PSimHit * > mapMuSimHitsPerWire(const std::map< DTWireId, edm::PSimHitContainer > &simHitWireMap)
Create a map between the Mu SimHits and corresponding MuBarWireId ;.
edm
HLT enums.
Definition: AlignableModifier.h:19
DTHitQualityUtils::debug
std::atomic< bool > debug
Definition: DTHitQualityUtils.h:50
gather_cfg.cout
cout
Definition: gather_cfg.py:144
DTChamber
Definition: DTChamber.h:24
PSimHitContainer.h
DTSegment2DSLPhiQuality::dqmAnalyze
void dqmAnalyze(edm::Event const &, edm::EventSetup const &, dtsegment2dsl::Histograms const &) const override
Perform the real analysis.
Definition: DTSegment2DSLPhiQuality.cc:69
DTRecSegment2D::localDirectionError
LocalError localDirectionError() const override
the local direction error (xx,xy,yy) in SL frame: only xx is not 0.
Definition: DTRecSegment2D.cc:76
FastTrackerRecHitCombiner_cfi.simHits
simHits
Definition: FastTrackerRecHitCombiner_cfi.py:5
Histograms.h
DTHitQualityUtils::findSegmentAlphaAndBeta
std::pair< double, double > findSegmentAlphaAndBeta(const LocalVector &direction)
DTRecSegment2D::localPositionError
LocalError localPositionError() const override
local position error in SL frame
Definition: DTRecSegment2D.cc:74
edm::Handle
Definition: AssociativeIterator.h:50
edm::RangeMap::id_iterator
identifier iterator
Definition: RangeMap.h:130
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
DTSegment2DSLPhiQuality::doall_
bool doall_
Definition: DTSegment2DSLPhiQuality.h:64
DTGeometry::chamber
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
DTSegment2DSLPhiQuality.h
DTSegment2DSLPhiQuality::simHitLabel_
edm::InputTag simHitLabel_
Definition: DTSegment2DSLPhiQuality.h:50
DTHitQualityUtils::findMuSimSegment
std::pair< const PSimHit *, const PSimHit * > findMuSimSegment(const std::map< DTWireId, const PSimHit * > &mapWireAndMuSimHit)
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
DTWireId
Definition: DTWireId.h:12
LocalError::xx
float xx() const
Definition: LocalError.h:22
DTSegment2DSLPhiQuality::debug_
bool debug_
Definition: DTSegment2DSLPhiQuality.h:68
rpcPointValidation_cfi.simHit
simHit
Definition: rpcPointValidation_cfi.py:24
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
DTSegment2DSLPhiQuality::segment4DToken_
edm::EDGetTokenT< DTRecSegment4DCollection > segment4DToken_
Definition: DTSegment2DSLPhiQuality.h:53
Point3DBase< float, LocalTag >
DTGeometry.h
DTHitQualityUtils::mapSimHitsPerWire
std::map< DTWireId, edm::PSimHitContainer > mapSimHitsPerWire(const edm::PSimHitContainer &simhits)
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
DTRecSegment2D
Definition: DTRecSegment2D.h:45
LocalError
Definition: LocalError.h:12
edm::RangeMap::const_iterator
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
PV3DBase::eta
T eta() const
Definition: PV3DBase.h:73
DTRecSegment2D::localPosition
LocalPoint localPosition() const override
local position in SL frame
Definition: DTRecSegment2D.h:84
dtsegment2dsl::Histograms
Definition: DTSegment2DSLPhiQuality.cc:28
DTChamberRecSegment2D
Definition: DTChamberRecSegment2D.h:31
DTHitQualityUtils::findMuSimSegmentDirAndPos
std::pair< LocalVector, LocalPoint > findMuSimSegmentDirAndPos(const std::pair< const PSimHit *, const PSimHit * > &inAndOutSimHit, const DetId detId, const DTGeometry &muonGeom)
DTSegment2DSLPhiQuality::segment4DLabel_
edm::InputTag segment4DLabel_
Definition: DTSegment2DSLPhiQuality.h:51
DTSegment2DSLPhiQuality
Definition: DTSegment2DSLPhiQuality.h:33
edm::EventSetup
Definition: EventSetup.h:58
histograms
Definition: histograms.py:1
DTSegment2DSLPhiQuality::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &, dtsegment2dsl::Histograms &) const override
Book the DQM plots.
Definition: DTSegment2DSLPhiQuality.cc:57
edm::RangeMap::range
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
dtsegment2dsl::Histograms::h2DHitSuperPhi
std::unique_ptr< HRes2DHit > h2DHitSuperPhi
Definition: DTSegment2DSLPhiQuality.cc:29
DTWireId.h
Frameworkfwd.h
DTHitQualityUtils.h
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
dqm::implementation::IBooker
Definition: DQMStore.h:43
DTSegment2DSLPhiQuality::sigmaResPos_
double sigmaResPos_
Definition: DTSegment2DSLPhiQuality.h:59
DTChamber.h
DTSegment2DSLPhiQuality::sigmaResAngle_
double sigmaResAngle_
Definition: DTSegment2DSLPhiQuality.h:62
DTRecSegment2D::localDirection
LocalVector localDirection() const override
the local direction in SL frame
Definition: DTRecSegment2D.h:90
DTChamberId
Definition: DTChamberId.h:14
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
DeDxTools::esConsumes
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7746
edm::InputTag
Definition: InputTag.h:15
DTSegment2DSLPhiQuality::local_
bool local_
Definition: DTSegment2DSLPhiQuality.h:65
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
DTRecSegment4DCollection.h