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 
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 
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") ?
42  pset.getParameter<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<std::shared_ptr<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(),0);
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,0,0);
205  if (debug) cout << " seg updated " << *newSeg << endl;
206 
207 
209  if(applyT0corr) theUpdator->update(newSeg,true,0);
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,0);
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,0);
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 
256  return result;
257 }
258 
259 
260 
261 vector<DTSegmentCand*> DTCombinatorialPatternReco4D::buildPhiSuperSegmentsCandidates(vector<std::shared_ptr<DTHitPairForFit>> &pairPhiOwned){
262 
263  DTSuperLayerId slId;
264 
265  if(theHitsFromPhi1.size())
266  slId = theHitsFromPhi1.front().wireId().superlayerId();
267  else
268  if(theHitsFromPhi2.size())
269  slId = theHitsFromPhi2.front().wireId().superlayerId();
270  else{
271  if(debug) cout<<"DTCombinatorialPatternReco4D::buildPhiSuperSegmentsCandidates: "
272  <<"No Hits in the two Phi SL"<<endl;
273  return vector<DTSegmentCand*>();
274  }
275 
276  const DTSuperLayer *sl = theDTGeometry->superLayer(slId);
277 
278  vector<std::shared_ptr<DTHitPairForFit>> pairPhi1 = the2DAlgo->initHits(sl,theHitsFromPhi1);
279  // same sl!! Since the fit will be in the sl phi 1!
280  vector<std::shared_ptr<DTHitPairForFit>> pairPhi2 = the2DAlgo->initHits(sl,theHitsFromPhi2);
281  // copy the pairPhi2 in the pairPhi1 vector
282  copy(pairPhi2.begin(),pairPhi2.end(),back_inserter(pairPhi1));
283 
284  pairPhiOwned.swap(pairPhi1);
285  // Build the segment candidate
286  return the2DAlgo->buildSegments(sl,pairPhiOwned);
287 }
288 
291  // Get the zed projection
292  //if (!seg->hasZed()) return seg;
293  const DTSLRecSegment2D* zedSeg=seg->zSegment();
294  std::vector<DTRecHit1D> hits = zedSeg->specificRecHits();
295 
296  // pick up a hit "in the middle", where the single hit will be put.
297  int nHits=hits.size();
298  DTRecHit1D middle=hits[static_cast<int>(nHits/2.)];
299 
300  // Need to extrapolate pos to the middle layer z
301  LocalPoint posInSL = zedSeg->localPosition();
302  LocalVector dirInSL = zedSeg->localDirection();
303  LocalPoint posInMiddleLayer = posInSL+dirInSL*(-posInSL.z())/cos(dirInSL.theta());
304 
305  // create a hit with position and error as the Zed projection one's
306  auto_ptr<DTRecHit1D> hit(new DTRecHit1D( middle.wireId(),
307  middle.lrSide(),
308  middle.digiTime(),
309  posInMiddleLayer,
310  zedSeg->localPositionError()));
311 
312  std::vector<DTRecHit1D> newHits(1,*hit);
313 
314  // create a new zed segment with that single hits, but same dir and pos
315  LocalPoint pos(zedSeg->localPosition());
316  LocalVector dir(zedSeg->localDirection());
317  AlgebraicSymMatrix cov(zedSeg->covMatrix());
318  double chi2(zedSeg->chi2());
319  //cout << "zed " << *zedSeg << endl;
320  auto_ptr<DTSLRecSegment2D> newZed(new DTSLRecSegment2D(zedSeg->superLayerId(),
321  pos,
322  dir,
323  cov,
324  chi2,
325  newHits));
326  //cout << "newZed " << *newZed << endl;
327 
328  // create a 4d segment with the special zed
330  *newZed,
331  seg->localPosition(),
332  seg->localDirection());
333  // delete the input segment
334  delete seg;
335 
336  // return it
337  return result;
338 }
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:50
virtual void setES(const edm::EventSetup &setup)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
std::vector< std::shared_ptr< DTHitPairForFit > > initHits(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
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:52
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:67
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:234
virtual LocalVector localDirection() const
Local direction in Chamber frame.
void push_back(D *&d)
Definition: OwnVector.h:280
void setES(const edm::EventSetup &setup)
set the setup
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:33
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:113
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
iterator end()
Definition: OwnVector.h:239
const DTSLRecSegment2D * zSegment() const
The Z segment: 0 if not zed projection available.
virtual ~DTCombinatorialPatternReco4D()
Destructor.
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits)
std::vector< DTRecHit1DPair > theHitsFromPhi1
std::vector< DTSLRecSegment2D > theSegments2DTheta
const T & get() const
Definition: EventSetup.h:56
virtual void setChamber(const DTChamberId &chId)
virtual void setDTRecHit1DContainer(edm::Handle< DTRecHitCollection > all1DHits)
std::vector< DTRecHit1DPair > theHitsFromTheta
edm::ESHandle< DTGeometry > theDTGeometry
std::vector< DTSegmentCand * > buildPhiSuperSegmentsCandidates(std::vector< std::shared_ptr< DTHitPairForFit >> &pairPhiOwned)
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
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
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:82
const DTSuperLayer * superLayer(DTSuperLayerId id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:65
DTWireId wireId() const
Return the wireId.
Definition: DTRecHit1D.h:107