CMS 3D CMS Logo

DTCombinatorialPatternReco4D.cc
Go to the documentation of this file.
1 
7 
10 
12 // For the 2D reco I use thei reconstructor!
15 
22 
24 
25 using namespace std;
26 using namespace edm;
27 
28 // TODO
29 // Throw an exception if a theta segment container is requested and in the event
30 // there isn't it. (Or launch a "lazy" reco on demand)
31 
33  : DTRecSegment4DBaseAlgo(pset), theAlgoName("DTCombinatorialPatternReco4D"), theDTGeometryToken(cc.esConsumes()) {
34  // debug parameter
35  debug = pset.getUntrackedParameter<bool>("debug");
36 
37  //do you want the T0 correction?
38  applyT0corr = pset.getParameter<bool>("performT0SegCorrection");
39 
40  computeT0corr = pset.existsAs<bool>("computeT0Seg") ? pset.getParameter<bool>("computeT0Seg") : true;
41 
42  // the updator
43  theUpdator = new DTSegmentUpdator(pset, cc);
44 
45  // the input type.
46  // If true the instructions in setDTRecSegment2DContainer will be schipped and the
47  // theta segment will be recomputed from the 1D rechits
48  // If false the theta segment will be taken from the Event. Caveat: in this case the
49  // event must contain the 2D segments!
50  allDTRecHits = pset.getParameter<bool>("AllDTRecHits");
51 
52  // Get the concrete 2D-segments reconstruction algo from the factory
53  // For the 2D reco I use this reconstructor!
54  the2DAlgo = new DTCombinatorialPatternReco(pset.getParameter<ParameterSet>("Reco2DAlgoConfig"), cc);
55 }
56 
58  delete the2DAlgo;
59  delete theUpdator;
60 }
61 
66 }
67 
69  // Set the chamber
71 }
72 
74  theHitsFromPhi1.clear();
75  theHitsFromPhi2.clear();
76  theHitsFromTheta.clear();
77 
78  DTRecHitCollection::range rangeHitsFromPhi1 =
80  DTRecHitCollection::range rangeHitsFromPhi2 =
82 
83  vector<DTRecHit1DPair> hitsFromPhi1(rangeHitsFromPhi1.first, rangeHitsFromPhi1.second);
84  vector<DTRecHit1DPair> hitsFromPhi2(rangeHitsFromPhi2.first, rangeHitsFromPhi2.second);
85  if (debug)
86  cout << "Number of DTRecHit1DPair in the SL 1 (Phi 1): " << hitsFromPhi1.size() << endl
87  << "Number of DTRecHit1DPair in the SL 3 (Phi 2): " << hitsFromPhi2.size() << endl;
88 
89  theHitsFromPhi1 = hitsFromPhi1;
90  theHitsFromPhi2 = hitsFromPhi2;
91 
92  if (allDTRecHits) {
93  DTRecHitCollection::range rangeHitsFromTheta =
95 
96  vector<DTRecHit1DPair> hitsFromTheta(rangeHitsFromTheta.first, rangeHitsFromTheta.second);
97  if (debug)
98  cout << "Number of DTRecHit1DPair in the SL 2 (Theta): " << hitsFromTheta.size() << endl;
99  theHitsFromTheta = hitsFromTheta;
100  }
101 }
102 
104  theSegments2DTheta.clear();
105 
106  if (!allDTRecHits) {
107  //Extract the DTRecSegment2DCollection range for the theta SL
108  DTRecSegment2DCollection::range rangeTheta = all2DSegments->get(DTSuperLayerId(theChamber->id(), 2));
109 
110  // Fill the DTRecSegment2D container for the theta SL
111  vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first, rangeTheta.second);
112 
113  if (debug)
114  cout << "Number of 2D-segments in the second SL (Theta): " << segments2DTheta.size() << endl;
115  theSegments2DTheta = segments2DTheta;
116  }
117 }
118 
121 
122  if (debug) {
123  cout << "Segments in " << theChamber->id() << endl;
124  cout << "Reconstructing of the Phi segments" << endl;
125  }
126 
127  vector<std::shared_ptr<DTHitPairForFit>> pairPhiOwned;
128  vector<DTSegmentCand*> resultPhi = buildPhiSuperSegmentsCandidates(pairPhiOwned);
129 
130  if (debug)
131  cout << "There are " << resultPhi.size() << " Phi cand" << endl;
132 
133  if (allDTRecHits) {
134  // take the theta SL of this chamber
135  const DTSuperLayer* sl = theChamber->superLayer(2);
136  // sl points to 0 if the theta SL was not found
137  if (sl) {
138  // reconstruct the theta segments
139  if (debug)
140  cout << "Reconstructing of the Theta segments" << endl;
142  vector<DTSLRecSegment2D> segments2DTheta(thetaSegs.begin(), thetaSegs.end());
143  theSegments2DTheta = segments2DTheta;
144  }
145  }
146 
147  bool hasZed = false;
148 
149  // has this chamber the Z-superlayer?
150  if (!theSegments2DTheta.empty()) {
151  hasZed = !theSegments2DTheta.empty();
152  if (debug)
153  cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
154  } else {
155  if (debug)
156  cout << "No Theta SL" << endl;
157  }
158 
159  // Now I want to build the concrete DTRecSegment4D.
160  if (debug)
161  cout << "Building of the concrete DTRecSegment4D" << endl;
162  if (!resultPhi.empty()) {
163  for (vector<DTSegmentCand*>::const_iterator phi = resultPhi.begin(); phi != resultPhi.end(); ++phi) {
164  std::unique_ptr<DTChamberRecSegment2D> superPhi(**phi);
165 
166  theUpdator->update(superPhi.get(), false);
167  if (debug)
168  cout << "superPhi: " << *superPhi << endl;
169 
170  if (hasZed) {
171  // Create all the 4D-segment combining the Z view with the Phi one
172  // loop over the Z segments
173  for (vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin(); zed != theSegments2DTheta.end();
174  ++zed) {
175  if (debug)
176  cout << "Theta: " << *zed << endl;
177  // Important!!
178  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
179 
180  // Put the theta segment poistion in its 3D place.
181  // note: (superPhi is in the CHAMBER local frame)
182  const DTSuperLayer* zSL = theChamber->superLayer(ZedSegSLId);
183 
184  // FIXME: should rather extrapolate for Y!
185  LocalPoint zPos(
186  zed->localPosition().x(), (zSL->toLocal(theChamber->toGlobal(superPhi->localPosition()))).y(), 0.);
187 
188  const LocalPoint posZInCh = theChamber->toLocal(zSL->toGlobal(zPos));
189  // FIXME: zed->localDirection() is in 2D. Should add the phi direction in the orthogonal plane as well!!
190  const LocalVector dirZInCh = theChamber->toLocal(zSL->toGlobal(zed->localDirection()));
191 
192  DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi, *zed, posZInCh, dirZInCh);
193 
194  if (debug)
195  cout << "Created a 4D seg " << *newSeg << endl;
196 
198  theUpdator->update(newSeg, false, false);
199  if (debug)
200  cout << " seg updated " << *newSeg << endl;
201 
202  if (!applyT0corr && computeT0corr)
203  theUpdator->calculateT0corr(newSeg);
204  if (applyT0corr)
205  theUpdator->update(newSeg, true, false);
206 
207  result.push_back(newSeg);
208  }
209  } else {
210  // Only phi
211 
212  DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi);
213 
214  if (debug)
215  cout << "Created a 4D segment using only the 2D Phi segment " << *newSeg << endl;
216 
217  //update the segment with the t0 and possibly vdrift correction
218  if (!applyT0corr && computeT0corr)
219  theUpdator->calculateT0corr(newSeg);
220  if (applyT0corr)
221  theUpdator->update(newSeg, true, false);
222 
223  result.push_back(newSeg);
224  }
225  }
226  } else {
227  // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
228  if (hasZed) {
229  for (vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin(); zed != theSegments2DTheta.end();
230  ++zed) {
231  if (debug)
232  cout << "Theta: " << *zed << endl;
233 
234  // Important!!
235  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
236 
237  const LocalPoint posZInCh =
238  theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition()));
239  const LocalVector dirZInCh =
240  theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection()));
241 
242  DTRecSegment4D* newSeg = new DTRecSegment4D(*zed, posZInCh, dirZInCh);
243 
244  if (debug)
245  cout << "Created a 4D segment using only the 2D Theta segment " << *newSeg << endl;
246 
247  if (!applyT0corr && computeT0corr)
248  theUpdator->calculateT0corr(newSeg);
249  if (applyT0corr)
250  theUpdator->update(newSeg, true, false);
251 
252  result.push_back(newSeg);
253  }
254  }
255  }
256  // finally delete the candidates!
257  for (vector<DTSegmentCand*>::iterator phi = resultPhi.begin(); phi != resultPhi.end(); ++phi)
258  delete *phi;
259 
260  return result;
261 }
262 
264  vector<std::shared_ptr<DTHitPairForFit>>& pairPhiOwned) {
265  DTSuperLayerId slId;
266 
267  if (!theHitsFromPhi1.empty())
268  slId = theHitsFromPhi1.front().wireId().superlayerId();
269  else if (!theHitsFromPhi2.empty())
270  slId = theHitsFromPhi2.front().wireId().superlayerId();
271  else {
272  if (debug)
273  cout << "DTCombinatorialPatternReco4D::buildPhiSuperSegmentsCandidates: "
274  << "No Hits in the two Phi SL" << endl;
275  return vector<DTSegmentCand*>();
276  }
277 
278  const DTSuperLayer* sl = theDTGeometry->superLayer(slId);
279 
280  vector<std::shared_ptr<DTHitPairForFit>> pairPhi1 = the2DAlgo->initHits(sl, theHitsFromPhi1);
281  // same sl!! Since the fit will be in the sl phi 1!
282  vector<std::shared_ptr<DTHitPairForFit>> pairPhi2 = the2DAlgo->initHits(sl, theHitsFromPhi2);
283  // copy the pairPhi2 in the pairPhi1 vector
284  copy(pairPhi2.begin(), pairPhi2.end(), back_inserter(pairPhi1));
285 
286  pairPhiOwned.swap(pairPhi1);
287  // Build the segment candidate
288  return the2DAlgo->buildSegments(sl, pairPhiOwned);
289 }
290 
293  // Get the zed projection
294  //if (!seg->hasZed()) return seg;
295  const DTSLRecSegment2D* zedSeg = seg->zSegment();
296  std::vector<DTRecHit1D> hits = zedSeg->specificRecHits();
297 
298  // pick up a hit "in the middle", where the single hit will be put.
299  int nHits = hits.size();
300  DTRecHit1D middle = hits[static_cast<int>(nHits / 2.)];
301 
302  // Need to extrapolate pos to the middle layer z
303  LocalPoint posInSL = zedSeg->localPosition();
304  LocalVector dirInSL = zedSeg->localDirection();
305  LocalPoint posInMiddleLayer = posInSL + dirInSL * (-posInSL.z()) / cos(dirInSL.theta());
306 
307  // create a hit with position and error as the Zed projection one's
308  auto hit = std::make_unique<DTRecHit1D>(
309  middle.wireId(), middle.lrSide(), middle.digiTime(), posInMiddleLayer, zedSeg->localPositionError());
310 
311  std::vector<DTRecHit1D> newHits(1, *hit);
312 
313  // create a new zed segment with that single hits, but same dir and pos
314  LocalPoint pos(zedSeg->localPosition());
315  LocalVector dir(zedSeg->localDirection());
316  AlgebraicSymMatrix cov(zedSeg->covMatrix());
317  double chi2(zedSeg->chi2());
318  //cout << "zed " << *zedSeg << endl;
319  auto newZed = std::make_unique<DTSLRecSegment2D>(zedSeg->superLayerId(), pos, dir, cov, chi2, newHits);
320  //cout << "newZed " << *newZed << endl;
321 
322  // create a 4d segment with the special zed
323  DTRecSegment4D* result = new DTRecSegment4D(*seg->phiSegment(), *newZed, seg->localPosition(), seg->localDirection());
324  // delete the input segment
325  delete seg;
326 
327  // return it
328  return result;
329 }
DTCombinatorialPatternReco * the2DAlgo
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
LocalPoint localPosition() const override
local position in SL frame
void setDTRecSegment2DContainer(edm::Handle< DTRecSegment2DCollection > all2DSegments) override
std::vector< std::shared_ptr< DTHitPairForFit > > initHits(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
LocalVector localDirection() const override
the local direction in SL frame
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:32
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
T z() const
Definition: PV3DBase.h:61
double chi2() const override
the chi2 of the fit
edm::OwnVector< DTSLRecSegment2D > reconstruct(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits) override
this function is called in the producer
static std::pair< DTLayerId, DTSuperLayerIdComparator > layersBySuperLayer(DTSuperLayerId slId)
Access by SL objects written into a RangeMap by layer.
LocalVector localDirection() const override
Local direction in Chamber frame.
edm::OwnVector< DTRecSegment4D > reconstruct() override
Operations.
std::vector< DTRecHit1DPair > theHitsFromPhi2
void setChamber(const DTChamberId &chId) override
LocalPoint localPosition() const override
Local position in Chamber frame.
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
float digiTime() const
Return the time (ns) of the digi used to build the rechit.
Definition: DTRecHit1D.h:79
DTRecSegment4D * segmentSpecialZed(const DTRecSegment4D *seg)
Build a 4d segment with a zed component made by just one hits.
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
iterator begin()
Definition: OwnVector.h:280
void calculateT0corr(DTRecSegment2D *seg) const
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:53
void setES(const edm::EventSetup &setup)
set the setup
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return a DTSuperLayer given its id.
Definition: DTGeometry.cc:92
void setDTRecHit1DContainer(edm::Handle< DTRecHitCollection > all1DHits) override
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
DTEnums::DTCellSide lrSide() const
The side of the cell.
Definition: DTRecHit1D.h:61
LocalError localPositionError() const override
local position error in SL frame
edm::ESGetToken< DTGeometry, MuonGeometryRecord > theDTGeometryToken
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
iterator end()
Definition: OwnVector.h:285
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits)
std::vector< DTRecHit1DPair > theHitsFromPhi1
std::vector< DTSLRecSegment2D > theSegments2DTheta
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
~DTCombinatorialPatternReco4D() override
Destructor.
void setES(const edm::EventSetup &setup) override
AlgebraicSymMatrix covMatrix() const
the Covariance Matrix
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ gpuPixelDoublets::CellNeighborsVector const gpuPixelDoublets::CellTracksVector const GPUCACell::OuterHitOfCell const int32_t nHits
std::vector< DTRecHit1DPair > theHitsFromTheta
edm::ESHandle< DTGeometry > theDTGeometry
std::vector< DTSegmentCand * > buildPhiSuperSegmentsCandidates(std::vector< std::shared_ptr< DTHitPairForFit >> &pairPhiOwned)
HLT enums.
DTWireId wireId() const
Return the wireId.
Definition: DTRecHit1D.h:76
CLHEP::HepSymMatrix AlgebraicSymMatrix
DTCombinatorialPatternReco4D(const edm::ParameterSet &pset, edm::ConsumesCollector)
Constructor.
void setES(const edm::EventSetup &setup) override
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72