CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTRefitAndCombineReco4D.cc
Go to the documentation of this file.
1 
14 
17 
21 
25 
27 
28 using namespace std;
29 using namespace edm;
30 
32 DTRecSegment4DBaseAlgo(pset), theAlgoName("DTRefitAndCombineReco4D"){
33 
34  // debug parameter
35  debug = pset.getUntrackedParameter<bool>("debug");
36 
37  // the updator
38  theUpdator = new DTSegmentUpdator(pset);
39 
40  // the max allowd chi^2 for the fit of th combination of two phi segments
41  theMaxChi2forPhi = pset.getParameter<double>("MaxChi2forPhi");
42 }
43 
45  setup.get<MuonGeometryRecord>().get(theDTGeometry);
46  theUpdator->setES(setup);
47  // the2DAlgo->setES(setup);
48 }
49 
51  // Set the chamber
52  theChamber = theDTGeometry->chamber(chId);
53 }
54 
55 void
57  theSegments2DPhi1.clear();
58  theSegments2DTheta.clear();
59  theSegments2DPhi2.clear();
60 
61  // Get the chamber
62  // const DTChamber *chamber = theDTGeometry->chamber(chId);
63 
64  const DTChamberId chId = theChamber->id();
65 
66  //Extract the DTRecSegment2DCollection ranges for the three different SL
67  DTRecSegment2DCollection::range rangePhi1 = allHits->get(DTSuperLayerId(chId,1));
68  DTRecSegment2DCollection::range rangeTheta = allHits->get(DTSuperLayerId(chId,2));
69  DTRecSegment2DCollection::range rangePhi2 = allHits->get(DTSuperLayerId(chId,3));
70 
71  // Fill the DTSLRecSegment2D containers for the three different SL
72  vector<DTSLRecSegment2D> segments2DPhi1(rangePhi1.first,rangePhi1.second);
73  vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first,rangeTheta.second);
74  vector<DTSLRecSegment2D> segments2DPhi2(rangePhi2.first,rangePhi2.second);
75 
76  if(debug)
77  cout << "Number of 2D-segments in the first SL (Phi)" << segments2DPhi1.size() << endl
78  << "Number of 2D-segments in the second SL (Theta)" << segments2DTheta.size() << endl
79  << "Number of 2D-segments in the third SL (Phi)" << segments2DPhi2.size() << endl;
80 
81  theSegments2DPhi1 = segments2DPhi1;
82  theSegments2DTheta = segments2DTheta;
83  theSegments2DPhi2 = segments2DPhi2;
84 }
85 
86 
87 
91 
92  if (debug) cout << "Segments in " << theChamber->id() << endl;
93 
94  vector<DTChamberRecSegment2D> resultPhi = refitSuperSegments();
95 
96  if (debug) cout << "There are " << resultPhi.size() << " Phi cand" << endl;
97 
98  bool hasZed=false;
99 
100  // has this chamber the Z-superlayer?
101  if (theSegments2DTheta.size()){
102  hasZed = theSegments2DTheta.size()>0;
103  if (debug) cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
104  } else {
105  if (debug) cout << "No Theta SL" << endl;
106  }
107 
108  // Now I want to build the concrete DTRecSegment4D.
109  if (resultPhi.size()) {
110  for (vector<DTChamberRecSegment2D>::const_iterator phi=resultPhi.begin();
111  phi!=resultPhi.end(); ++phi) {
112 
113  if (hasZed) {
114 
115  // Create all the 4D-segment combining the Z view with the Phi one
116  // loop over the Z segments
117  for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
118  zed != theSegments2DTheta.end(); ++zed){
119 
120  //>> Important!!
121  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
122 
123  const LocalPoint posZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition() )) ;
124  const LocalVector dirZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection() )) ;
125 
126  DTRecSegment4D* newSeg = new DTRecSegment4D(*phi,*zed,posZInCh,dirZInCh);
127  //<<
128 
130  theUpdator->update(newSeg);
131  if (debug) cout << "Created a 4D seg " << endl;
132  result.push_back(newSeg);
133  }
134  } else {
135  // Only phi
136  DTRecSegment4D* newSeg = new DTRecSegment4D(*phi);
137  if (debug) cout << "Created a 4D segment using only the 2D Phi segment" << endl;
138  result.push_back(newSeg);
139  }
140  }
141  } else {
142  // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
143  if (hasZed) {
144  for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
145  zed != theSegments2DTheta.end(); ++zed){
146 
147  // Important!!
148  DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
149 
150  const LocalPoint posZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition() )) ;
151  const LocalVector dirZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection() )) ;
152 
153  DTRecSegment4D* newSeg = new DTRecSegment4D( *zed,posZInCh,dirZInCh);
154  //<<
155 
156  if (debug) 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(); ++segment2DPhi1){
171  for(vector<DTSLRecSegment2D>::const_iterator segment2DPhi2 = theSegments2DPhi2.begin();
172  segment2DPhi2 != theSegments2DPhi2.end(); ++segment2DPhi2){
173 
174  // check the id
175  if(segment2DPhi1->chamberId() != segment2DPhi2->chamberId())
176  throw cms::Exception("refitSuperSegments")
177  <<"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);
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 getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< DTSLRecSegment2D > theSegments2DTheta
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
void update(DTRecSegment4D *seg, const bool calcT0=false) const
recompute hits position and refit the segment4D
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:47
virtual double chi2() const
the chi2 of the fit
DTSuperLayerId
virtual edm::OwnVector< DTRecSegment4D > reconstruct()
Operations.
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:62
DTRefitAndCombineReco4D(const edm::ParameterSet &pset)
Constructor.
void push_back(D *&d)
Definition: OwnVector.h:273
void setES(const edm::EventSetup &setup)
set the setup
DTChamberId id() const
Return the DTChamberId of this chamber.
Definition: DTChamber.cc:35
tuple result
Definition: query.py:137
virtual void setDTRecSegment2DContainer(edm::Handle< DTRecSegment2DCollection > all2DSegments)
bool fit(DTSegmentCand *seg) const
std::vector< DTChamberRecSegment2D > refitSuperSegments()
std::vector< DTSLRecSegment2D > theSegments2DPhi1
virtual void setChamber(const DTChamberId &chId)
const T & get() const
Definition: EventSetup.h:55
std::vector< DTSLRecSegment2D > theSegments2DPhi2
tuple cout
Definition: gather_cfg.py:121
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::ESHandle< DTGeometry > theDTGeometry
const DTSuperLayer * superLayer(DTSuperLayerId id) const
Return the superlayer corresponding to the given id.
Definition: DTChamber.cc:67
Definition: DDAxes.h:10