CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DTMeantimerPatternReco4D.cc
Go to the documentation of this file.
1 
7 
11 
13 // For the 2D reco I use thei reconstructor!
16 
23 
25 
26 using namespace std;
27 using namespace edm;
28 
29 // TODO
30 // Throw an exception if a theta segment container is requested and in the event
31 // there isn't it. (Or launch a "lazy" reco on demand)
32 
34  : DTRecSegment4DBaseAlgo(pset), theAlgoName("DTMeantimerPatternReco4D"), theDTGeometryToken(cc.esConsumes()) {
35  // debug parameter
36  debug = pset.getUntrackedParameter<bool>("debug");
37 
38  //do you want the T0 correction?
39  applyT0corr = pset.getParameter<bool>("performT0SegCorrection");
40 
41  computeT0corr = pset.existsAs<bool>("computeT0Seg") ? pset.getParameter<bool>("computeT0Seg") : true;
42 
43  // the updator
44  theUpdator = new DTSegmentUpdator(pset, cc);
45 
46  // the input type.
47  // If true the instructions in setDTRecSegment2DContainer will be schipped and the
48  // theta segment will be recomputed from the 1D rechits
49  // If false the theta segment will be taken from the Event. Caveat: in this case the
50  // event must contain the 2D segments!
51  allDTRecHits = pset.getParameter<bool>("AllDTRecHits");
52 
53  // Get the concrete 2D-segments reconstruction algo from the factory
54  // For the 2D reco I use this reconstructor!
55  the2DAlgo = new DTMeantimerPatternReco(pset.getParameter<ParameterSet>("Reco2DAlgoConfig"), cc);
56 }
57 
59  delete the2DAlgo;
60  delete theUpdator;
61 }
62 
65  the2DAlgo->setES(setup);
66  theUpdator->setES(setup);
67 }
68 
70  // Set the chamber
71  theChamber = theDTGeometry->chamber(chId);
72 }
73 
75  theHitsFromPhi1.clear();
76  theHitsFromPhi2.clear();
77  theHitsFromTheta.clear();
78 
79  DTRecHitCollection::range rangeHitsFromPhi1 =
81  DTRecHitCollection::range rangeHitsFromPhi2 =
83 
84  vector<DTRecHit1DPair> hitsFromPhi1(rangeHitsFromPhi1.first, rangeHitsFromPhi1.second);
85  vector<DTRecHit1DPair> hitsFromPhi2(rangeHitsFromPhi2.first, rangeHitsFromPhi2.second);
86  if (debug)
87  cout << "Number of DTRecHit1DPair in the SL 1 (Phi 1): " << hitsFromPhi1.size() << endl
88  << "Number of DTRecHit1DPair in the SL 3 (Phi 2): " << hitsFromPhi2.size() << endl;
89 
90  theHitsFromPhi1 = hitsFromPhi1;
91  theHitsFromPhi2 = hitsFromPhi2;
92 
93  if (allDTRecHits) {
94  DTRecHitCollection::range rangeHitsFromTheta =
96 
97  vector<DTRecHit1DPair> hitsFromTheta(rangeHitsFromTheta.first, rangeHitsFromTheta.second);
98  if (debug)
99  cout << "Number of DTRecHit1DPair in the SL 2 (Theta): " << hitsFromTheta.size() << endl;
100  theHitsFromTheta = hitsFromTheta;
101  }
102 }
103 
105  theSegments2DTheta.clear();
106 
107  if (!allDTRecHits) {
108  //Extract the DTRecSegment2DCollection range for the theta SL
109  DTRecSegment2DCollection::range rangeTheta = all2DSegments->get(DTSuperLayerId(theChamber->id(), 2));
110 
111  // Fill the DTRecSegment2D container for the theta SL
112  vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first, rangeTheta.second);
113 
114  if (debug)
115  cout << "Number of 2D-segments in the second SL (Theta): " << segments2DTheta.size() << endl;
116  theSegments2DTheta = segments2DTheta;
117  }
118 }
119 
122 
123  if (debug) {
124  cout << "Segments in " << theChamber->id() << endl;
125  cout << "Reconstructing Phi segments" << endl;
126  }
127 
128  vector<std::shared_ptr<DTHitPairForFit>> pairPhiOwned;
129  vector<DTSegmentCand*> resultPhi = buildPhiSuperSegmentsCandidates(pairPhiOwned);
130 
131  if (debug)
132  cout << "There are " << resultPhi.size() << " Phi cand" << endl;
133 
134  if (allDTRecHits) {
135  // take the theta SL of this chamber
136  const DTSuperLayer* sl = theChamber->superLayer(2);
137  // sl points to 0 if the theta SL was not found
138  if (sl) {
139  // reconstruct the theta segments
140  if (debug)
141  cout << "Reconstructing Theta segments" << endl;
143  vector<DTSLRecSegment2D> segments2DTheta(thetaSegs.begin(), thetaSegs.end());
144  theSegments2DTheta = segments2DTheta;
145  }
146  }
147 
148  bool hasZed = false;
149 
150  // has this chamber the Z-superlayer?
151  if (!theSegments2DTheta.empty()) {
152  hasZed = !theSegments2DTheta.empty();
153  if (debug)
154  cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
155  } else {
156  if (debug)
157  cout << "No Theta candidates." << endl;
158  }
159 
160  // Now I want to build the concrete DTRecSegment4D.
161  if (debug)
162  cout << "Building the concrete DTRecSegment4D" << endl;
163  if (!resultPhi.empty()) {
164  for (vector<DTSegmentCand*>::const_iterator phi = resultPhi.begin(); phi != resultPhi.end(); ++phi) {
165  std::unique_ptr<DTChamberRecSegment2D> superPhi(**phi);
166 
167  theUpdator->update(superPhi.get(), true);
168  if (debug)
169  cout << "superPhi: " << *superPhi << endl;
170 
171  if (hasZed) {
172  // Create all the 4D-segment combining the Z view with the Phi one
173  // loop over the Z segments
174  for (vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin(); zed != theSegments2DTheta.end();
175  ++zed) {
176  // Important!!
177  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
178 
179  // Put the theta segment poistion in its 3D place.
180  // note: (superPhi is in the CHAMBER local frame)
181  const DTSuperLayer* zSL = theChamber->superLayer(ZedSegSLId);
182 
183  // FIXME: should rather extrapolate for Y!
184  LocalPoint zPos(
185  zed->localPosition().x(), (zSL->toLocal(theChamber->toGlobal(superPhi->localPosition()))).y(), 0.);
186 
187  const LocalPoint posZInCh = theChamber->toLocal(zSL->toGlobal(zPos));
188  // FIXME: zed->localDirection() is in 2D. Should add the phi direction in the orthogonal plane as well!!
189  const LocalVector dirZInCh = theChamber->toLocal(zSL->toGlobal(zed->localDirection()));
190 
191  DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi, *zed, posZInCh, dirZInCh);
192 
194  theUpdator->update(newSeg, false, true);
195  if (debug)
196  cout << "Created a 4D seg " << *newSeg << endl;
197 
198  //update the segment with the t0 and possibly vdrift correction
199  if (!applyT0corr && computeT0corr)
200  theUpdator->calculateT0corr(newSeg);
201  if (applyT0corr)
202  theUpdator->update(newSeg, true, true);
203 
204  result.push_back(newSeg);
205  }
206  } else {
207  // Only phi
208  DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi);
209 
210  if (debug)
211  cout << "Created a 4D segment using only the 2D Phi segment" << endl;
212 
213  //update the segment with the t0 and possibly vdrift correction
214  if (!applyT0corr && computeT0corr)
215  theUpdator->calculateT0corr(newSeg);
216  if (applyT0corr)
217  theUpdator->update(newSeg, true, true);
218 
219  result.push_back(newSeg);
220  }
221  }
222  } else {
223  // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
224  if (hasZed) {
225  for (vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin(); zed != theSegments2DTheta.end();
226  ++zed) {
227  // Important!!
228  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
229 
230  const LocalPoint posZInCh =
231  theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition()));
232  const LocalVector dirZInCh =
233  theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection()));
234 
235  DTRecSegment4D* newSeg = new DTRecSegment4D(*zed, posZInCh, dirZInCh);
236  // <<
237 
238  if (debug)
239  cout << "Created a 4D segment using only the 2D Theta segment" << endl;
240 
241  if (!applyT0corr && computeT0corr)
242  theUpdator->calculateT0corr(newSeg);
243  if (applyT0corr)
244  theUpdator->update(newSeg, true, true);
245 
246  result.push_back(newSeg);
247  }
248  }
249  }
250  // finally delete the candidates!
251  for (vector<DTSegmentCand*>::iterator phi = resultPhi.begin(); phi != resultPhi.end(); ++phi)
252  delete *phi;
253 
254  return result;
255 }
256 
258  vector<std::shared_ptr<DTHitPairForFit>>& pairPhiOwned) {
259  DTSuperLayerId slId;
260 
261  if (!theHitsFromPhi1.empty())
262  slId = theHitsFromPhi1.front().wireId().superlayerId();
263  else if (!theHitsFromPhi2.empty())
264  slId = theHitsFromPhi2.front().wireId().superlayerId();
265  else {
266  if (debug)
267  cout << "DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates: "
268  << "No Hits in the two Phi SL" << endl;
269  return vector<DTSegmentCand*>();
270  }
271 
272  const DTSuperLayer* sl = theDTGeometry->superLayer(slId);
273 
274  vector<std::shared_ptr<DTHitPairForFit>> pairPhi1 = the2DAlgo->initHits(sl, theHitsFromPhi1);
275  // same sl!! Since the fit will be in the sl phi 1!
276  vector<std::shared_ptr<DTHitPairForFit>> pairPhi2 = the2DAlgo->initHits(sl, theHitsFromPhi2);
277  // copy the pairPhi2 in the pairPhi1 vector
278  copy(pairPhi2.begin(), pairPhi2.end(), back_inserter(pairPhi1));
279 
280  pairPhiOwned.swap(pairPhi1);
281  // Build the segment candidate
282  return the2DAlgo->buildSegments(sl, pairPhiOwned);
283 }
std::vector< std::shared_ptr< DTHitPairForFit > > initHits(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
T getUntrackedParameter(std::string const &, T const &) const
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:53
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
std::vector< DTRecHit1DPair > theHitsFromPhi2
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
edm::OwnVector< DTSLRecSegment2D > reconstruct(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits) override
this function is called in the producer
void setES(const edm::EventSetup &setup) override
DTMeantimerPatternReco4D(const edm::ParameterSet &pset, edm::ConsumesCollector)
Constructor.
void calculateT0corr(DTRecSegment2D *seg) const
DTMeantimerPatternReco * the2DAlgo
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
static std::pair< DTLayerId, DTSuperLayerIdComparator > layersBySuperLayer(DTSuperLayerId slId)
Access by SL objects written into a RangeMap by layer.
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > theDTGeometryToken
DTSuperLayerId
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
std::vector< DTRecHit1DPair > theHitsFromPhi1
edm::OwnVector< DTRecSegment4D > reconstruct() override
Operations.
tuple result
Definition: mps_fire.py:311
iterator begin()
Definition: OwnVector.h:280
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits)
void push_back(D *&d)
Definition: OwnVector.h:326
void setES(const edm::EventSetup &setup) override
void setES(const edm::EventSetup &setup)
set the setup
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:32
void setDTRecHit1DContainer(edm::Handle< DTRecHitCollection > all1DHits) override
std::vector< DTRecHit1DPair > theHitsFromTheta
std::vector< DTSegmentCand * > buildPhiSuperSegmentsCandidates(std::vector< std::shared_ptr< DTHitPairForFit >> &pairPhiOwned)
std::vector< DTSLRecSegment2D > theSegments2DTheta
iterator end()
Definition: OwnVector.h:285
~DTMeantimerPatternReco4D() override
Destructor.
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::ESHandle< DTGeometry > theDTGeometry
void setDTRecSegment2DContainer(edm::Handle< DTRecSegment2DCollection > all2DSegments) override
tuple cout
Definition: gather_cfg.py:144
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void setChamber(const DTChamberId &chId) override