CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DTRefitAndCombineReco4D.cc
Go to the documentation of this file.
1 
12 
15 
20 
24 
26 
27 using namespace std;
28 using namespace edm;
29 
31  : DTRecSegment4DBaseAlgo(pset), theAlgoName("DTRefitAndCombineReco4D"), theDTGeometryToken(cc.esConsumes()) {
32  // debug parameter
33  debug = pset.getUntrackedParameter<bool>("debug");
34 
35  // the updator
36  theUpdator = new DTSegmentUpdator(pset, cc);
37 
38  // the max allowd chi^2 for the fit of th combination of two phi segments
39  theMaxChi2forPhi = pset.getParameter<double>("MaxChi2forPhi");
40 }
41 
44  theUpdator->setES(setup);
45  // the2DAlgo->setES(setup);
46 }
47 
49  // Set the chamber
50  theChamber = theDTGeometry->chamber(chId);
51 }
52 
54  theSegments2DPhi1.clear();
55  theSegments2DTheta.clear();
56  theSegments2DPhi2.clear();
57 
58  // Get the chamber
59  // const DTChamber *chamber = theDTGeometry->chamber(chId);
60 
61  const DTChamberId chId = theChamber->id();
62 
63  //Extract the DTRecSegment2DCollection ranges for the three different SL
64  DTRecSegment2DCollection::range rangePhi1 = allHits->get(DTSuperLayerId(chId, 1));
65  DTRecSegment2DCollection::range rangeTheta = allHits->get(DTSuperLayerId(chId, 2));
66  DTRecSegment2DCollection::range rangePhi2 = allHits->get(DTSuperLayerId(chId, 3));
67 
68  // Fill the DTSLRecSegment2D containers for the three different SL
69  vector<DTSLRecSegment2D> segments2DPhi1(rangePhi1.first, rangePhi1.second);
70  vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first, rangeTheta.second);
71  vector<DTSLRecSegment2D> segments2DPhi2(rangePhi2.first, rangePhi2.second);
72 
73  if (debug)
74  cout << "Number of 2D-segments in the first SL (Phi)" << segments2DPhi1.size() << endl
75  << "Number of 2D-segments in the second SL (Theta)" << segments2DTheta.size() << endl
76  << "Number of 2D-segments in the third SL (Phi)" << segments2DPhi2.size() << endl;
77 
78  theSegments2DPhi1 = segments2DPhi1;
79  theSegments2DTheta = segments2DTheta;
80  theSegments2DPhi2 = segments2DPhi2;
81 }
82 
85 
86  if (debug)
87  cout << "Segments in " << theChamber->id() << endl;
88 
89  vector<DTChamberRecSegment2D> resultPhi = refitSuperSegments();
90 
91  if (debug)
92  cout << "There are " << resultPhi.size() << " Phi cand" << endl;
93 
94  bool hasZed = false;
95 
96  // has this chamber the Z-superlayer?
97  if (!theSegments2DTheta.empty()) {
98  hasZed = !theSegments2DTheta.empty();
99  if (debug)
100  cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
101  } else {
102  if (debug)
103  cout << "No Theta SL" << endl;
104  }
105 
106  // Now I want to build the concrete DTRecSegment4D.
107  if (!resultPhi.empty()) {
108  for (vector<DTChamberRecSegment2D>::const_iterator phi = resultPhi.begin(); phi != resultPhi.end(); ++phi) {
109  if (hasZed) {
110  // Create all the 4D-segment combining the Z view with the Phi one
111  // loop over the Z segments
112  for (vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin(); zed != theSegments2DTheta.end();
113  ++zed) {
114  //>> Important!!
115  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
116 
117  const LocalPoint posZInCh =
118  theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition()));
119  const LocalVector dirZInCh =
120  theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection()));
121 
122  DTRecSegment4D* newSeg = new DTRecSegment4D(*phi, *zed, posZInCh, dirZInCh);
123  //<<
124 
126  theUpdator->update(newSeg, false, true);
127  if (debug)
128  cout << "Created a 4D seg " << endl;
129  result.push_back(newSeg);
130  }
131  } else {
132  // Only phi
133  DTRecSegment4D* newSeg = new DTRecSegment4D(*phi);
134  if (debug)
135  cout << "Created a 4D segment using only the 2D Phi segment" << endl;
136  result.push_back(newSeg);
137  }
138  }
139  } else {
140  // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
141  if (hasZed) {
142  for (vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin(); zed != theSegments2DTheta.end();
143  ++zed) {
144  // Important!!
145  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
146 
147  const LocalPoint posZInCh =
148  theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition()));
149  const LocalVector dirZInCh =
150  theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection()));
151 
152  DTRecSegment4D* newSeg = new DTRecSegment4D(*zed, posZInCh, dirZInCh);
153  //<<
154 
155  if (debug)
156  cout << "Created a 4D segment using only the 2D Theta segment" << endl;
157  result.push_back(newSeg);
158  }
159  }
160  }
161 
162  return result;
163 }
164 
165 vector<DTChamberRecSegment2D> DTRefitAndCombineReco4D::refitSuperSegments() {
166  vector<DTChamberRecSegment2D> result;
167 
168  //double-loop over all the DTSLRecSegment2D in order to make all the possible pairs
169  for (vector<DTSLRecSegment2D>::const_iterator segment2DPhi1 = theSegments2DPhi1.begin();
170  segment2DPhi1 != theSegments2DPhi1.end();
171  ++segment2DPhi1) {
172  for (vector<DTSLRecSegment2D>::const_iterator segment2DPhi2 = theSegments2DPhi2.begin();
173  segment2DPhi2 != theSegments2DPhi2.end();
174  ++segment2DPhi2) {
175  // check the id
176  if (segment2DPhi1->chamberId() != segment2DPhi2->chamberId())
177  throw cms::Exception("refitSuperSegments") << "he phi segments have different chamber id" << std::endl;
178 
179  // create a super phi starting from 2 phi
180  vector<DTRecHit1D> recHitsSeg2DPhi1 = segment2DPhi1->specificRecHits();
181  vector<DTRecHit1D> recHitsSeg2DPhi2 = segment2DPhi2->specificRecHits();
182  // copy the recHitsSeg2DPhi2 in the recHitsSeg2DPhi1 container
183  copy(recHitsSeg2DPhi2.begin(), recHitsSeg2DPhi2.end(), back_inserter(recHitsSeg2DPhi1));
184 
185  const DTChamberId chId = segment2DPhi1->chamberId();
186 
187  // create the super phi
188  DTChamberRecSegment2D superPhi(chId, recHitsSeg2DPhi1);
189 
190  // refit it!
191  theUpdator->fit(&superPhi, false, false);
192 
193  // cut on the chi^2
194  if (superPhi.chi2() > theMaxChi2forPhi)
195  result.push_back(superPhi);
196  }
197  }
198  // TODO clean the container!!!
199  // there are some possible repetition!
200  // maybe using the cleaner, previous a conversion from DTChamberRecSegment2D to DTSegmentCandidate
201  return result;
202 }
T getUntrackedParameter(std::string const &, T const &) const
const DTSuperLayer * superLayer(const DTSuperLayerId &id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:53
std::vector< DTSLRecSegment2D > theSegments2DTheta
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
double chi2() const override
the chi2 of the fit
DTRefitAndCombineReco4D(const edm::ParameterSet &pset, edm::ConsumesCollector cc)
Constructor.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
void setChamber(const DTChamberId &chId) override
void setDTRecSegment2DContainer(edm::Handle< DTRecSegment2DCollection > all2DSegments) override
DTSuperLayerId
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:58
tuple result
Definition: mps_fire.py:311
void push_back(D *&d)
Definition: OwnVector.h:326
void setES(const edm::EventSetup &setup)
set the setup
void setES(const edm::EventSetup &setup) override
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:32
const edm::ESGetToken< DTGeometry, MuonGeometryRecord > theDTGeometryToken
std::vector< DTChamberRecSegment2D > refitSuperSegments()
std::vector< DTSLRecSegment2D > theSegments2DPhi1
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::OwnVector< DTRecSegment4D > reconstruct() override
Operations.
std::vector< DTSLRecSegment2D > theSegments2DPhi2
tuple cout
Definition: gather_cfg.py:144
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
edm::ESHandle< DTGeometry > theDTGeometry