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  // the updator
41  theUpdator = new DTSegmentUpdator(pset);
42 
43  // the input type.
44  // If true the instructions in setDTRecSegment2DContainer will be schipped and the
45  // theta segment will be recomputed from the 1D rechits
46  // If false the theta segment will be taken from the Event. Caveat: in this case the
47  // event must contain the 2D segments!
48  allDTRecHits = pset.getParameter<bool>("AllDTRecHits");
49 
50  // Get the concrete 2D-segments reconstruction algo from the factory
51  // For the 2D reco I use this reconstructor!
52  the2DAlgo = new DTMeantimerPatternReco(pset.getParameter<ParameterSet>("Reco2DAlgoConfig"));
53  }
54 
55 
57  delete the2DAlgo;
58  delete theUpdator;
59 }
60 
62  setup.get<MuonGeometryRecord>().get(theDTGeometry);
63  the2DAlgo->setES(setup);
64  theUpdator->setES(setup);
65 }
66 
68  // Set the chamber
69  theChamber = theDTGeometry->chamber(chId);
70 }
71 
73  theHitsFromPhi1.clear();
74  theHitsFromPhi2.clear();
75  theHitsFromTheta.clear();
76 
77  DTRecHitCollection::range rangeHitsFromPhi1 =
79  DTRecHitCollection::range rangeHitsFromPhi2 =
81 
82  vector<DTRecHit1DPair> hitsFromPhi1(rangeHitsFromPhi1.first,rangeHitsFromPhi1.second);
83  vector<DTRecHit1DPair> hitsFromPhi2(rangeHitsFromPhi2.first,rangeHitsFromPhi2.second);
84  if(debug)
85  cout<< "Number of DTRecHit1DPair in the SL 1 (Phi 1): " << hitsFromPhi1.size()<<endl
86  << "Number of DTRecHit1DPair in the SL 3 (Phi 2): " << hitsFromPhi2.size()<<endl;
87 
88  theHitsFromPhi1 = hitsFromPhi1;
89  theHitsFromPhi2 = hitsFromPhi2;
90 
91  if(allDTRecHits){
92  DTRecHitCollection::range rangeHitsFromTheta =
94 
95  vector<DTRecHit1DPair> hitsFromTheta(rangeHitsFromTheta.first,rangeHitsFromTheta.second);
96  if(debug)
97  cout<< "Number of DTRecHit1DPair in the SL 2 (Theta): " << hitsFromTheta.size()<<endl;
98  theHitsFromTheta = hitsFromTheta;
99  }
100 
101 }
102 
104  theSegments2DTheta.clear();
105 
106  if(!allDTRecHits){
107 
108  //Extract the DTRecSegment2DCollection range for the theta SL
109  DTRecSegment2DCollection::range rangeTheta =
110  all2DSegments->get(DTSuperLayerId(theChamber->id(),2));
111 
112  // Fill the DTRecSegment2D container for the theta SL
113  vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first,rangeTheta.second);
114 
115  if(debug)
116  cout << "Number of 2D-segments in the second SL (Theta): " << segments2DTheta.size() << endl;
117  theSegments2DTheta = segments2DTheta;
118  }
119 
120 }
121 
122 
125 
127 
128  if (debug){
129  cout << "Segments in " << theChamber->id() << endl;
130  cout << "Reconstructing Phi segments"<<endl;
131  }
132  vector<DTSegmentCand*> resultPhi = buildPhiSuperSegmentsCandidates();
133 
134  if (debug) cout << "There are " << resultPhi.size() << " Phi cand" << endl;
135 
136  if (allDTRecHits){
137  // take the theta SL of this chamber
138  const DTSuperLayer* sl = theChamber->superLayer(2);
139  // sl points to 0 if the theta SL was not found
140  if(sl){
141  // reconstruct the theta segments
142  if(debug) cout << "Reconstructing Theta segments"<<endl;
144  vector<DTSLRecSegment2D> segments2DTheta(thetaSegs.begin(),thetaSegs.end());
145  theSegments2DTheta = segments2DTheta;
146  }
147  }
148 
149  bool hasZed=false;
150 
151  // has this chamber the Z-superlayer?
152  if (theSegments2DTheta.size()){
153  hasZed = theSegments2DTheta.size()>0;
154  if (debug) cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
155  } else {
156  if (debug) cout << "No Theta SL" << endl;
157  }
158 
159  // Now I want to build the concrete DTRecSegment4D.
160  if(debug) cout<<"Building the concrete DTRecSegment4D"<<endl;
161  if (resultPhi.size()) {
162  for (vector<DTSegmentCand*>::const_iterator phi=resultPhi.begin();
163  phi!=resultPhi.end(); ++phi) {
164 
165  DTChamberRecSegment2D* superPhi = (**phi);
166 
167  theUpdator->update(superPhi);
168 
169  if (hasZed) {
170 
171  // Create all the 4D-segment combining the Z view with the Phi one
172  // loop over the Z segments
173  for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
174  zed != theSegments2DTheta.end(); ++zed){
175 
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(zed->localPosition().x(),
185  (zSL->toLocal(theChamber->toGlobal(superPhi->localPosition()))).y(),
186  0.);
187 
188  const LocalPoint posZInCh = theChamber->toLocal( zSL->toGlobal(zPos));
189  // FIXME: zed->localDirection() is in 2D. Should add the phi direction in the orthogonal plane as well!!
190  const LocalVector dirZInCh = theChamber->toLocal( zSL->toGlobal(zed->localDirection()));
191 
192  DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi,*zed,posZInCh,dirZInCh);
193  //<<
194 
196  theUpdator->update(newSeg);
197  if (debug) cout << "Created a 4D seg " << *newSeg << endl;
198  result.push_back(newSeg);
199  }
200  } else {
201  // Only phi
202  DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi);
203 
204  if (debug) cout << "Created a 4D segment using only the 2D Phi segment" << endl;
205  result.push_back(newSeg);
206  }
207  }
208  } else {
209  // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
210  if (hasZed) {
211  for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
212  zed != theSegments2DTheta.end(); ++zed){
213 
214  // Important!!
215  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
216 
217  const LocalPoint posZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition() )) ;
218  const LocalVector dirZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection() )) ;
219 
220  DTRecSegment4D* newSeg = new DTRecSegment4D( *zed,posZInCh,dirZInCh);
221  // <<
222 
223  if (debug) cout << "Created a 4D segment using only the 2D Theta segment" << endl;
224  result.push_back(newSeg);
225  }
226  }
227  }
228  // finally delete the candidates!
229  for (vector<DTSegmentCand*>::iterator phi=resultPhi.begin();
230  phi!=resultPhi.end(); ++phi) delete *phi;
231 
232  return result;
233 }
234 
235 
236 
238 
239  DTSuperLayerId slId;
240 
241  if(theHitsFromPhi1.size())
242  slId = theHitsFromPhi1.front().wireId().superlayerId();
243  else
244  if(theHitsFromPhi2.size())
245  slId = theHitsFromPhi2.front().wireId().superlayerId();
246  else{
247  if(debug) cout<<"DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates: "
248  <<"No Hits in the two Phi SL"<<endl;
249  return vector<DTSegmentCand*>();
250  }
251 
252  const DTSuperLayer *sl = theDTGeometry->superLayer(slId);
253 
254  vector<DTHitPairForFit*> pairPhi1 = the2DAlgo->initHits(sl,theHitsFromPhi1);
255  // same sl!! Since the fit will be in the sl phi 1!
256  vector<DTHitPairForFit*> pairPhi2 = the2DAlgo->initHits(sl,theHitsFromPhi2);
257  // copy the pairPhi2 in the pairPhi1 vector
258  copy(pairPhi2.begin(),pairPhi2.end(),back_inserter(pairPhi1));
259 
260  // Build the segment candidate
261  return the2DAlgo->buildSegments(sl,pairPhi1);
262 }
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
void update(DTRecSegment4D *seg, const bool calcT0=false) const
recompute hits position and refit the segment4D
virtual void setChamber(const DTChamberId &chId)
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