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") {
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
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"));
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 }
Vector3DBase< float, LocalTag >
DTChamber::id
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:32
DTCombinatorialPatternReco4D::setDTRecHit1DContainer
void setDTRecHit1DContainer(edm::Handle< DTRecHitCollection > all1DHits) override
Definition: DTCombinatorialPatternReco4D.cc:73
DTSLRecSegment2D
Definition: DTSLRecSegment2D.h:15
DTSuperLayerId
Definition: DTSuperLayerId.h:12
DDAxes::y
DTRecSegment4D
Definition: DTRecSegment4D.h:23
DTCombinatorialPatternReco4D::DTCombinatorialPatternReco4D
DTCombinatorialPatternReco4D(const edm::ParameterSet &pset)
Constructor.
Definition: DTCombinatorialPatternReco4D.cc:32
DTRecSegment4D::localDirection
LocalVector localDirection() const override
Local direction in Chamber frame.
Definition: DTRecSegment4D.h:67
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm::OwnVector::end
iterator end()
Definition: OwnVector.h:285
DTSegmentUpdator::calculateT0corr
void calculateT0corr(DTRecSegment2D *seg) const
Definition: DTSegmentUpdator.cc:618
DTRecHit1D::lrSide
DTEnums::DTCellSide lrSide() const
The side of the cell.
Definition: DTRecHit1D.h:61
edm
HLT enums.
Definition: AlignableModifier.h:19
DTCombinatorialPatternReco4D::~DTCombinatorialPatternReco4D
~DTCombinatorialPatternReco4D() override
Destructor.
Definition: DTCombinatorialPatternReco4D.cc:57
DTSLRecSegment2D::superLayerId
DTSuperLayerId superLayerId() const
The id of the superlayer on which reside the segment.
Definition: DTSLRecSegment2D.cc:24
DTCombinatorialPatternReco4D::theHitsFromPhi1
std::vector< DTRecHit1DPair > theHitsFromPhi1
Definition: DTCombinatorialPatternReco4D.h:89
PV3DBase::theta
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
DTRecHit1D
Definition: DTRecHit1D.h:25
DTCombinatorialPatternReco4D::allDTRecHits
bool allDTRecHits
Definition: DTCombinatorialPatternReco4D.h:83
DTCombinatorialPatternReco4D.h
DTCombinatorialPatternReco
Definition: DTCombinatorialPatternReco.h:42
DTCombinatorialPatternReco4D::theDTGeometry
edm::ESHandle< DTGeometry > theDTGeometry
Definition: DTCombinatorialPatternReco4D.h:71
DTCombinatorialPatternReco4D::buildPhiSuperSegmentsCandidates
std::vector< DTSegmentCand * > buildPhiSuperSegmentsCandidates(std::vector< std::shared_ptr< DTHitPairForFit >> &pairPhiOwned)
Definition: DTCombinatorialPatternReco4D.cc:263
DTCombinatorialPatternReco4D::theSegments2DTheta
std::vector< DTSLRecSegment2D > theSegments2DTheta
Definition: DTCombinatorialPatternReco4D.h:88
DTSuperLayer
Definition: DTSuperLayer.h:24
DTCombinatorialPatternReco4D::setES
void setES(const edm::EventSetup &setup) override
Definition: DTCombinatorialPatternReco4D.cc:62
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
DTRecSegment2D::localPositionError
LocalError localPositionError() const override
local position error in SL frame
Definition: DTRecSegment2D.cc:74
edm::Handle< DTRecHitCollection >
DTRecSegment4D::localPosition
LocalPoint localPosition() const override
Local position in Chamber frame.
Definition: DTRecSegment4D.h:61
DTRecSegment4D::zSegment
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
Definition: DTRecSegment4D.h:99
DTCombinatorialPatternReco4D::theHitsFromTheta
std::vector< DTRecHit1DPair > theHitsFromTheta
Definition: DTCombinatorialPatternReco4D.h:90
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
DTCombinatorialPatternReco::initHits
std::vector< std::shared_ptr< DTHitPairForFit > > initHits(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
Definition: DTCombinatorialPatternReco.cc:83
DTGeometry::chamber
const DTChamber * chamber(const DTChamberId &id) const
Return a DTChamber given its id.
Definition: DTGeometry.cc:90
DTSegmentUpdator
Definition: DTSegmentUpdator.h:43
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
DTSegmentCand.h
DTRecHit1D::wireId
DTWireId wireId() const
Return the wireId.
Definition: DTRecHit1D.h:76
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
nHits
const caConstants::TupleMultiplicity *__restrict__ const HitsOnGPU *__restrict__ double *__restrict__ float *__restrict__ double *__restrict__ uint32_t nHits
Definition: BrokenLineFitOnGPU.h:27
DTCombinatorialPatternReco4D::debug
bool debug
Definition: DTCombinatorialPatternReco4D.h:67
DTCombinatorialPatternReco4D::the2DAlgo
DTCombinatorialPatternReco * the2DAlgo
Definition: DTCombinatorialPatternReco4D.h:75
Point3DBase< float, LocalTag >
GeomDet::toLocal
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
GeomDet::toGlobal
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
edm::ParameterSet
Definition: ParameterSet.h:47
DTRangeMapAccessor::layersBySuperLayer
static std::pair< DTLayerId, DTSuperLayerIdComparator > layersBySuperLayer(DTSuperLayerId slId)
Access by SL objects written into a RangeMap by layer.
Definition: DTRangeMapAccessor.cc:15
DTRecSegment2D::chi2
double chi2() const override
the chi2 of the fit
Definition: DTRecSegment2D.h:96
DTRangeMapAccessor.h
DTRecSegment2D::localPosition
LocalPoint localPosition() const override
local position in SL frame
Definition: DTRecSegment2D.h:84
DTRecSegment4DBaseAlgo
Definition: DTRecSegment4DBaseAlgo.h:33
DTCombinatorialPatternReco4D::setDTRecSegment2DContainer
void setDTRecSegment2DContainer(edm::Handle< DTRecSegment2DCollection > all2DSegments) override
Definition: DTCombinatorialPatternReco4D.cc:103
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
DTRecHit1DPair.h
AlgebraicSymMatrix
CLHEP::HepSymMatrix AlgebraicSymMatrix
Definition: AlgebraicObjects.h:15
edm::EventSetup
Definition: EventSetup.h:58
DTRecSegment2D::covMatrix
AlgebraicSymMatrix covMatrix() const
the Covariance Matrix
Definition: DTRecSegment2D.h:111
DTCombinatorialPatternReco4D::reconstruct
edm::OwnVector< DTRecSegment4D > reconstruct() override
Operations.
Definition: DTCombinatorialPatternReco4D.cc:119
DTSegmentUpdator::setES
void setES(const edm::EventSetup &setup)
set the setup
Definition: DTSegmentUpdator.cc:68
get
#define get
DTSegmentUpdator.h
DTChamberRecSegment2D.h
DTCombinatorialPatternReco4D::theHitsFromPhi2
std::vector< DTRecHit1DPair > theHitsFromPhi2
Definition: DTCombinatorialPatternReco4D.h:91
DTCombinatorialPatternReco.h
DTRecHit1D::digiTime
float digiTime() const
Return the time (ns) of the digi used to build the rechit.
Definition: DTRecHit1D.h:79
DDAxes::phi
edm::RangeMap::range
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
std
Definition: JetResolutionObject.h:76
DTCombinatorialPatternReco::setES
void setES(const edm::EventSetup &setup) override
Definition: DTCombinatorialPatternReco.cc:77
DTWireId.h
DTCombinatorialPatternReco4D::setChamber
void setChamber(const DTChamberId &chId) override
Definition: DTCombinatorialPatternReco4D.cc:68
DTCombinatorialPatternReco4D::computeT0corr
bool computeT0corr
Definition: DTCombinatorialPatternReco4D.h:85
DTRecSegment2D::specificRecHits
std::vector< DTRecHit1D > specificRecHits() const
Access to specific components.
Definition: DTRecSegment2D.cc:104
DTCombinatorialPatternReco4D::theUpdator
DTSegmentUpdator * theUpdator
Definition: DTCombinatorialPatternReco4D.h:78
EventSetup.h
DTSLRecSegment2D.h
DTCombinatorialPatternReco::reconstruct
edm::OwnVector< DTSLRecSegment2D > reconstruct(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits) override
this function is called in the producer
Definition: DTCombinatorialPatternReco.cc:52
DTCombinatorialPatternReco4D::segmentSpecialZed
DTRecSegment4D * segmentSpecialZed(const DTRecSegment4D *seg)
Build a 4d segment with a zed component made by just one hits.
Definition: DTCombinatorialPatternReco4D.cc:292
mps_fire.result
result
Definition: mps_fire.py:311
DTCombinatorialPatternReco::buildSegments
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits)
Definition: DTCombinatorialPatternReco.cc:92
DTGeometry::superLayer
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return a DTSuperLayer given its id.
Definition: DTGeometry.cc:92
DTRecSegment2D::localDirection
LocalVector localDirection() const override
the local direction in SL frame
Definition: DTRecSegment2D.h:90
DTChamberId
Definition: DTChamberId.h:14
ParameterSet.h
edm::OwnVector::begin
iterator begin()
Definition: OwnVector.h:280
OwnVector.h
MuonGeometryRecord.h
DTChamber::superLayer
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:53
DTRecSegment4D::phiSegment
const DTChamberRecSegment2D * phiSegment() const
The superPhi segment: 0 if no phi projection available.
Definition: DTRecSegment4D.h:96
MuonGeometryRecord
Definition: MuonGeometryRecord.h:34
DTCombinatorialPatternReco4D::theChamber
const DTChamber * theChamber
Definition: DTCombinatorialPatternReco4D.h:80
hit
Definition: SiStripHitEffFromCalibTree.cc:88
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::OwnVector
Definition: OwnVector.h:24
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
DTCombinatorialPatternReco4D::applyT0corr
bool applyT0corr
Definition: DTCombinatorialPatternReco4D.h:84
DTSegmentUpdator::update
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
Definition: DTSegmentUpdator.cc:73