CMS 3D CMS Logo

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