CMS 3D CMS Logo

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