test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTMeantimerPatternReco4D.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("DTMeantimerPatternReco4D"){
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 DTMeantimerPatternReco(pset.getParameter<ParameterSet>("Reco2DAlgoConfig"));
57 }
58 
59 
61  delete the2DAlgo;
62  delete theUpdator;
63 }
64 
66  setup.get<MuonGeometryRecord>().get(theDTGeometry);
67  the2DAlgo->setES(setup);
68  theUpdator->setES(setup);
69 }
70 
72  // Set the chamber
73  theChamber = theDTGeometry->chamber(chId);
74 }
75 
77  theHitsFromPhi1.clear();
78  theHitsFromPhi2.clear();
79  theHitsFromTheta.clear();
80 
81  DTRecHitCollection::range rangeHitsFromPhi1 =
83  DTRecHitCollection::range rangeHitsFromPhi2 =
85 
86  vector<DTRecHit1DPair> hitsFromPhi1(rangeHitsFromPhi1.first,rangeHitsFromPhi1.second);
87  vector<DTRecHit1DPair> hitsFromPhi2(rangeHitsFromPhi2.first,rangeHitsFromPhi2.second);
88  if(debug)
89  cout<< "Number of DTRecHit1DPair in the SL 1 (Phi 1): " << hitsFromPhi1.size()<<endl
90  << "Number of DTRecHit1DPair in the SL 3 (Phi 2): " << hitsFromPhi2.size()<<endl;
91 
92  theHitsFromPhi1 = hitsFromPhi1;
93  theHitsFromPhi2 = hitsFromPhi2;
94 
95  if(allDTRecHits){
96  DTRecHitCollection::range rangeHitsFromTheta =
98 
99  vector<DTRecHit1DPair> hitsFromTheta(rangeHitsFromTheta.first,rangeHitsFromTheta.second);
100  if(debug)
101  cout<< "Number of DTRecHit1DPair in the SL 2 (Theta): " << hitsFromTheta.size()<<endl;
102  theHitsFromTheta = hitsFromTheta;
103  }
104 
105 }
106 
108  theSegments2DTheta.clear();
109 
110  if(!allDTRecHits){
111 
112  //Extract the DTRecSegment2DCollection range for the theta SL
113  DTRecSegment2DCollection::range rangeTheta =
114  all2DSegments->get(DTSuperLayerId(theChamber->id(),2));
115 
116  // Fill the DTRecSegment2D container for the theta SL
117  vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first,rangeTheta.second);
118 
119  if(debug)
120  cout << "Number of 2D-segments in the second SL (Theta): " << segments2DTheta.size() << endl;
121  theSegments2DTheta = segments2DTheta;
122  }
123 
124 }
125 
126 
129 
131 
132  if (debug){
133  cout << "Segments in " << theChamber->id() << endl;
134  cout << "Reconstructing Phi segments"<<endl;
135  }
136 
137  vector<std::shared_ptr<DTHitPairForFit>> pairPhiOwned;
138  vector<DTSegmentCand*> resultPhi = buildPhiSuperSegmentsCandidates(pairPhiOwned);
139 
140  if (debug) cout << "There are " << resultPhi.size() << " Phi cand" << endl;
141 
142  if (allDTRecHits){
143  // take the theta SL of this chamber
144  const DTSuperLayer* sl = theChamber->superLayer(2);
145  // sl points to 0 if the theta SL was not found
146  if(sl){
147  // reconstruct the theta segments
148  if(debug) cout << "Reconstructing Theta segments"<<endl;
150  vector<DTSLRecSegment2D> segments2DTheta(thetaSegs.begin(),thetaSegs.end());
151  theSegments2DTheta = segments2DTheta;
152  }
153  }
154 
155  bool hasZed=false;
156 
157  // has this chamber the Z-superlayer?
158  if (theSegments2DTheta.size()){
159  hasZed = theSegments2DTheta.size()>0;
160  if (debug) cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
161  } else {
162  if (debug) cout << "No Theta candidates." << endl;
163  }
164 
165  // Now I want to build the concrete DTRecSegment4D.
166  if(debug) cout << "Building the concrete DTRecSegment4D" << endl;
167  if (resultPhi.size()) {
168  for (vector<DTSegmentCand*>::const_iterator phi=resultPhi.begin();
169  phi!=resultPhi.end(); ++phi) {
170 
171  std::auto_ptr<DTChamberRecSegment2D> superPhi(**phi);
172 
173  theUpdator->update(superPhi.get(),1);
174  if(debug) cout << "superPhi: " << *superPhi << endl;
175 
176  if (hasZed) {
177 
178  // Create all the 4D-segment combining the Z view with the Phi one
179  // loop over the Z segments
180  for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
181  zed != theSegments2DTheta.end(); ++zed){
182 
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 
202  theUpdator->update(newSeg,0,1);
203  if (debug) cout << "Created a 4D seg " << *newSeg << endl;
204 
205  //update the segment with the t0 and possibly vdrift correction
207  if(applyT0corr) theUpdator->update(newSeg,true,1);
208 
209  result.push_back(newSeg);
210  }
211  } else {
212  // Only phi
213  DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi);
214 
215  if (debug) cout << "Created a 4D segment using only the 2D Phi segment" << endl;
216 
217  //update the segment with the t0 and possibly vdrift correction
219  if(applyT0corr) theUpdator->update(newSeg,true,1);
220 
221  result.push_back(newSeg);
222  }
223  }
224  } else {
225  // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
226  if (hasZed) {
227  for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
228  zed != theSegments2DTheta.end(); ++zed){
229 
230  // Important!!
231  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
232 
233  const LocalPoint posZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition() )) ;
234  const LocalVector dirZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection() )) ;
235 
236  DTRecSegment4D* newSeg = new DTRecSegment4D( *zed,posZInCh,dirZInCh);
237  // <<
238 
239  if (debug) cout << "Created a 4D segment using only the 2D Theta segment" << endl;
240 
242  if(applyT0corr) theUpdator->update(newSeg,true,1);
243 
244  result.push_back(newSeg);
245  }
246  }
247  }
248  // finally delete the candidates!
249  for (vector<DTSegmentCand*>::iterator phi=resultPhi.begin();
250  phi!=resultPhi.end(); ++phi) delete *phi;
251 
252  return result;
253 }
254 
255 
256 
257 vector<DTSegmentCand*> DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates(vector<std::shared_ptr<DTHitPairForFit>> &pairPhiOwned){
258 
259  DTSuperLayerId slId;
260 
261  if(theHitsFromPhi1.size())
262  slId = theHitsFromPhi1.front().wireId().superlayerId();
263  else
264  if(theHitsFromPhi2.size())
265  slId = theHitsFromPhi2.front().wireId().superlayerId();
266  else{
267  if(debug) 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 getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual void setDTRecHit1DContainer(edm::Handle< DTRecHitCollection > all1DHits)
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:186
virtual void setChamber(const DTChamberId &chId)
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:54
static std::pair< DTLayerId, DTSuperLayerIdComparator > layersBySuperLayer(DTSuperLayerId slId)
Access by SL objects written into a RangeMap by layer.
DTSuperLayerId
DTMeantimerPatternReco4D(const edm::ParameterSet &pset)
Constructor.
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:69
std::vector< DTRecHit1DPair > theHitsFromPhi1
tuple result
Definition: mps_fire.py:83
iterator begin()
Definition: OwnVector.h:244
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits)
void push_back(D *&d)
Definition: OwnVector.h:290
virtual void setES(const edm::EventSetup &setup)
void setES(const edm::EventSetup &setup)
set the setup
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:33
std::vector< DTRecHit1DPair > theHitsFromTheta
std::vector< DTSegmentCand * > buildPhiSuperSegmentsCandidates(std::vector< std::shared_ptr< DTHitPairForFit >> &pairPhiOwned)
std::vector< DTSLRecSegment2D > theSegments2DTheta
iterator end()
Definition: OwnVector.h:249
const T & get() const
Definition: EventSetup.h:56
virtual edm::OwnVector< DTSLRecSegment2D > reconstruct(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
this function is called in the producer
edm::ESHandle< DTGeometry > theDTGeometry
tuple cout
Definition: gather_cfg.py:145
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
virtual void setDTRecSegment2DContainer(edm::Handle< DTRecSegment2DCollection > all2DSegments)
virtual ~DTMeantimerPatternReco4D()
Destructor.
virtual void setES(const edm::EventSetup &setup)
virtual edm::OwnVector< DTRecSegment4D > reconstruct()
Operations.
const DTSuperLayer * superLayer(DTSuperLayerId id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:65