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 
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("DTMeantimerPatternReco4D"){
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 
43  computeT0corr = pset.existsAs<bool>("computeT0Seg") ?
44  pset.getParameter<bool>("computeT0Seg") : true;
45 
46  // the updator
47  theUpdator = new DTSegmentUpdator(pset);
48 
49  // the input type.
50  // If true the instructions in setDTRecSegment2DContainer will be schipped and the
51  // theta segment will be recomputed from the 1D rechits
52  // If false the theta segment will be taken from the Event. Caveat: in this case the
53  // event must contain the 2D segments!
54  allDTRecHits = pset.getParameter<bool>("AllDTRecHits");
55 
56  // Get the concrete 2D-segments reconstruction algo from the factory
57  // For the 2D reco I use this reconstructor!
58  the2DAlgo = new DTMeantimerPatternReco(pset.getParameter<ParameterSet>("Reco2DAlgoConfig"));
59 
60  }
61 
62 
64  delete the2DAlgo;
65  delete theUpdator;
66 }
67 
69  setup.get<MuonGeometryRecord>().get(theDTGeometry);
70  the2DAlgo->setES(setup);
71  theUpdator->setES(setup);
72 }
73 
75  // Set the chamber
76  theChamber = theDTGeometry->chamber(chId);
77 }
78 
80  theHitsFromPhi1.clear();
81  theHitsFromPhi2.clear();
82  theHitsFromTheta.clear();
83 
84  DTRecHitCollection::range rangeHitsFromPhi1 =
86  DTRecHitCollection::range rangeHitsFromPhi2 =
88 
89  vector<DTRecHit1DPair> hitsFromPhi1(rangeHitsFromPhi1.first,rangeHitsFromPhi1.second);
90  vector<DTRecHit1DPair> hitsFromPhi2(rangeHitsFromPhi2.first,rangeHitsFromPhi2.second);
91  if(debug)
92  cout<< "Number of DTRecHit1DPair in the SL 1 (Phi 1): " << hitsFromPhi1.size()<<endl
93  << "Number of DTRecHit1DPair in the SL 3 (Phi 2): " << hitsFromPhi2.size()<<endl;
94 
95  theHitsFromPhi1 = hitsFromPhi1;
96  theHitsFromPhi2 = hitsFromPhi2;
97 
98  if(allDTRecHits){
99  DTRecHitCollection::range rangeHitsFromTheta =
101 
102  vector<DTRecHit1DPair> hitsFromTheta(rangeHitsFromTheta.first,rangeHitsFromTheta.second);
103  if(debug)
104  cout<< "Number of DTRecHit1DPair in the SL 2 (Theta): " << hitsFromTheta.size()<<endl;
105  theHitsFromTheta = hitsFromTheta;
106  }
107 
108 }
109 
111  theSegments2DTheta.clear();
112 
113  if(!allDTRecHits){
114 
115  //Extract the DTRecSegment2DCollection range for the theta SL
116  DTRecSegment2DCollection::range rangeTheta =
117  all2DSegments->get(DTSuperLayerId(theChamber->id(),2));
118 
119  // Fill the DTRecSegment2D container for the theta SL
120  vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first,rangeTheta.second);
121 
122  if(debug)
123  cout << "Number of 2D-segments in the second SL (Theta): " << segments2DTheta.size() << endl;
124  theSegments2DTheta = segments2DTheta;
125  }
126 
127 }
128 
129 
132 
134 
135  if (debug){
136  cout << "Segments in " << theChamber->id() << endl;
137  cout << "Reconstructing Phi segments"<<endl;
138  }
139  vector<DTSegmentCand*> resultPhi = buildPhiSuperSegmentsCandidates();
140 
141  if (debug) cout << "There are " << resultPhi.size() << " Phi cand" << endl;
142 
143  if (allDTRecHits){
144  // take the theta SL of this chamber
145  const DTSuperLayer* sl = theChamber->superLayer(2);
146  // sl points to 0 if the theta SL was not found
147  if(sl){
148  // reconstruct the theta segments
149  if(debug) cout << "Reconstructing Theta segments"<<endl;
151  vector<DTSLRecSegment2D> segments2DTheta(thetaSegs.begin(),thetaSegs.end());
152  theSegments2DTheta = segments2DTheta;
153  }
154  }
155 
156  bool hasZed=false;
157 
158  // has this chamber the Z-superlayer?
159  if (theSegments2DTheta.size()){
160  hasZed = theSegments2DTheta.size()>0;
161  if (debug) cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
162  } else {
163  if (debug) cout << "No Theta SL" << endl;
164  }
165 
166  // Now I want to build the concrete DTRecSegment4D.
167  if(debug) cout<<"Building the concrete DTRecSegment4D"<<endl;
168  if (resultPhi.size()) {
169  for (vector<DTSegmentCand*>::const_iterator phi=resultPhi.begin();
170  phi!=resultPhi.end(); ++phi) {
171 
172  DTChamberRecSegment2D* superPhi = (**phi);
173 
174  theUpdator->update(superPhi);
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  //<<
201 
203  theUpdator->update(newSeg);
204  if (debug) cout << "Created a 4D seg " << *newSeg << endl;
205 
206  //update the segment with the t0 and possibly vdrift correction
208  if(applyT0corr) theUpdator->update(newSeg,true);
209 
210  result.push_back(newSeg);
211  }
212  } else {
213  // Only phi
214  DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi);
215 
216  if (debug) cout << "Created a 4D segment using only the 2D Phi segment" << endl;
217 
218  //update the segment with the t0 and possibly vdrift correction
220  if(applyT0corr) theUpdator->update(newSeg,true);
221 
222  result.push_back(newSeg);
223  }
224  }
225  } else {
226  // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
227  if (hasZed) {
228  for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
229  zed != theSegments2DTheta.end(); ++zed){
230 
231  // Important!!
232  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
233 
234  const LocalPoint posZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition() )) ;
235  const LocalVector dirZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection() )) ;
236 
237  DTRecSegment4D* newSeg = new DTRecSegment4D( *zed,posZInCh,dirZInCh);
238  // <<
239 
240  if (debug) cout << "Created a 4D segment using only the 2D Theta segment" << endl;
241 
243  if(applyT0corr) theUpdator->update(newSeg,true);
244 
245  result.push_back(newSeg);
246  }
247  }
248  }
249  // finally delete the candidates!
250  for (vector<DTSegmentCand*>::iterator phi=resultPhi.begin();
251  phi!=resultPhi.end(); ++phi) delete *phi;
252 
253  return result;
254 }
255 
256 
257 
259 
260  DTSuperLayerId slId;
261 
262  if(theHitsFromPhi1.size())
263  slId = theHitsFromPhi1.front().wireId().superlayerId();
264  else
265  if(theHitsFromPhi2.size())
266  slId = theHitsFromPhi2.front().wireId().superlayerId();
267  else{
268  if(debug) cout<<"DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates: "
269  <<"No Hits in the two Phi SL"<<endl;
270  return vector<DTSegmentCand*>();
271  }
272 
273  const DTSuperLayer *sl = theDTGeometry->superLayer(slId);
274 
275  vector<DTHitPairForFit*> pairPhi1 = the2DAlgo->initHits(sl,theHitsFromPhi1);
276  // same sl!! Since the fit will be in the sl phi 1!
277  vector<DTHitPairForFit*> pairPhi2 = the2DAlgo->initHits(sl,theHitsFromPhi2);
278  // copy the pairPhi2 in the pairPhi1 vector
279  copy(pairPhi2.begin(),pairPhi2.end(),back_inserter(pairPhi1));
280 
281  // Build the segment candidate
282  return the2DAlgo->buildSegments(sl,pairPhi1);
283 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< DTSegmentCand * > buildPhiSuperSegmentsCandidates()
virtual void setDTRecHit1DContainer(edm::Handle< DTRecHitCollection > all1DHits)
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
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:187
void update(DTRecSegment4D *seg, const bool calcT0=false) const
recompute hits position and refit the segment4D
virtual void setChamber(const DTChamberId &chId)
void calculateT0corr(DTRecSegment2D *seg) const
DTMeantimerPatternReco * the2DAlgo
double zPos
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
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:62
std::vector< DTRecHit1DPair > theHitsFromPhi1
iterator begin()
Definition: OwnVector.h:227
void push_back(D *&d)
Definition: OwnVector.h:273
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:35
std::vector< DTHitPairForFit * > initHits(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
tuple result
Definition: query.py:137
std::vector< DTRecHit1DPair > theHitsFromTheta
std::vector< DTSLRecSegment2D > theSegments2DTheta
virtual LocalPoint localPosition() const
local position in SL frame
iterator end()
Definition: OwnVector.h:232
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< DTHitPairForFit * > &hits)
const T & get() const
Definition: EventSetup.h:55
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:121
virtual void setDTRecSegment2DContainer(edm::Handle< DTRecSegment2DCollection > all2DSegments)
virtual ~DTMeantimerPatternReco4D()
Destructor.
virtual void setES(const edm::EventSetup &setup)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
virtual edm::OwnVector< DTRecSegment4D > reconstruct()
Operations.
const DTSuperLayer * superLayer(DTSuperLayerId id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:67
Definition: DDAxes.h:10