File indexing completed on 2023-03-17 11:19:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include "RecoLocalMuon/DTSegment/src/DTRefitAndCombineReco4D.h"
0012
0013 #include "RecoLocalMuon/DTSegment/src/DTSegmentUpdator.h"
0014 #include "RecoLocalMuon/DTSegment/src/DTSegmentCand.h"
0015
0016 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/ConsumesCollector.h"
0019 #include "FWCore/Utilities/interface/Exception.h"
0020
0021 #include "DataFormats/Common/interface/OwnVector.h"
0022 #include "DataFormats/DTRecHit/interface/DTChamberRecSegment2D.h"
0023 #include "DataFormats/DTRecHit/interface/DTRecSegment2DCollection.h"
0024
0025 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0026
0027 using namespace std;
0028 using namespace edm;
0029
0030 DTRefitAndCombineReco4D::DTRefitAndCombineReco4D(const ParameterSet& pset, ConsumesCollector cc)
0031 : DTRecSegment4DBaseAlgo(pset), theAlgoName("DTRefitAndCombineReco4D"), theDTGeometryToken(cc.esConsumes()) {
0032
0033 debug = pset.getUntrackedParameter<bool>("debug");
0034
0035
0036 theUpdator = new DTSegmentUpdator(pset, cc);
0037
0038
0039 theMaxChi2forPhi = pset.getParameter<double>("MaxChi2forPhi");
0040 }
0041
0042 void DTRefitAndCombineReco4D::setES(const EventSetup& setup) {
0043 theDTGeometry = setup.getHandle(theDTGeometryToken);
0044 theUpdator->setES(setup);
0045
0046 }
0047
0048 void DTRefitAndCombineReco4D::setChamber(const DTChamberId& chId) {
0049
0050 theChamber = theDTGeometry->chamber(chId);
0051 }
0052
0053 void DTRefitAndCombineReco4D::setDTRecSegment2DContainer(Handle<DTRecSegment2DCollection> allHits) {
0054 theSegments2DPhi1.clear();
0055 theSegments2DTheta.clear();
0056 theSegments2DPhi2.clear();
0057
0058
0059
0060
0061 const DTChamberId chId = theChamber->id();
0062
0063
0064 DTRecSegment2DCollection::range rangePhi1 = allHits->get(DTSuperLayerId(chId, 1));
0065 DTRecSegment2DCollection::range rangeTheta = allHits->get(DTSuperLayerId(chId, 2));
0066 DTRecSegment2DCollection::range rangePhi2 = allHits->get(DTSuperLayerId(chId, 3));
0067
0068
0069 vector<DTSLRecSegment2D> segments2DPhi1(rangePhi1.first, rangePhi1.second);
0070 vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first, rangeTheta.second);
0071 vector<DTSLRecSegment2D> segments2DPhi2(rangePhi2.first, rangePhi2.second);
0072
0073 if (debug)
0074 cout << "Number of 2D-segments in the first SL (Phi)" << segments2DPhi1.size() << endl
0075 << "Number of 2D-segments in the second SL (Theta)" << segments2DTheta.size() << endl
0076 << "Number of 2D-segments in the third SL (Phi)" << segments2DPhi2.size() << endl;
0077
0078 theSegments2DPhi1 = segments2DPhi1;
0079 theSegments2DTheta = segments2DTheta;
0080 theSegments2DPhi2 = segments2DPhi2;
0081 }
0082
0083 OwnVector<DTRecSegment4D> DTRefitAndCombineReco4D::reconstruct() {
0084 OwnVector<DTRecSegment4D> result;
0085
0086 if (debug)
0087 cout << "Segments in " << theChamber->id() << endl;
0088
0089 vector<DTChamberRecSegment2D> resultPhi = refitSuperSegments();
0090
0091 if (debug)
0092 cout << "There are " << resultPhi.size() << " Phi cand" << endl;
0093
0094 bool hasZed = false;
0095
0096
0097 if (!theSegments2DTheta.empty()) {
0098 hasZed = !theSegments2DTheta.empty();
0099 if (debug)
0100 cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
0101 } else {
0102 if (debug)
0103 cout << "No Theta SL" << endl;
0104 }
0105
0106
0107 if (!resultPhi.empty()) {
0108 for (vector<DTChamberRecSegment2D>::const_iterator phi = resultPhi.begin(); phi != resultPhi.end(); ++phi) {
0109 if (hasZed) {
0110
0111
0112 for (vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin(); zed != theSegments2DTheta.end();
0113 ++zed) {
0114
0115 DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
0116
0117 const LocalPoint posZInCh =
0118 theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition()));
0119 const LocalVector dirZInCh =
0120 theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection()));
0121
0122 DTRecSegment4D* newSeg = new DTRecSegment4D(*phi, *zed, posZInCh, dirZInCh);
0123
0124
0125
0126 theUpdator->update(newSeg, false, true);
0127 if (debug)
0128 cout << "Created a 4D seg " << endl;
0129 result.push_back(newSeg);
0130 }
0131 } else {
0132
0133 DTRecSegment4D* newSeg = new DTRecSegment4D(*phi);
0134 if (debug)
0135 cout << "Created a 4D segment using only the 2D Phi segment" << endl;
0136 result.push_back(newSeg);
0137 }
0138 }
0139 } else {
0140
0141 if (hasZed) {
0142 for (vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin(); zed != theSegments2DTheta.end();
0143 ++zed) {
0144
0145 DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
0146
0147 const LocalPoint posZInCh =
0148 theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition()));
0149 const LocalVector dirZInCh =
0150 theChamber->toLocal(theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection()));
0151
0152 DTRecSegment4D* newSeg = new DTRecSegment4D(*zed, posZInCh, dirZInCh);
0153
0154
0155 if (debug)
0156 cout << "Created a 4D segment using only the 2D Theta segment" << endl;
0157 result.push_back(newSeg);
0158 }
0159 }
0160 }
0161
0162 return result;
0163 }
0164
0165 vector<DTChamberRecSegment2D> DTRefitAndCombineReco4D::refitSuperSegments() {
0166 vector<DTChamberRecSegment2D> result;
0167
0168
0169 for (vector<DTSLRecSegment2D>::const_iterator segment2DPhi1 = theSegments2DPhi1.begin();
0170 segment2DPhi1 != theSegments2DPhi1.end();
0171 ++segment2DPhi1) {
0172 for (vector<DTSLRecSegment2D>::const_iterator segment2DPhi2 = theSegments2DPhi2.begin();
0173 segment2DPhi2 != theSegments2DPhi2.end();
0174 ++segment2DPhi2) {
0175
0176 if (segment2DPhi1->chamberId() != segment2DPhi2->chamberId())
0177 throw cms::Exception("refitSuperSegments") << "he phi segments have different chamber id" << std::endl;
0178
0179
0180 vector<DTRecHit1D> recHitsSeg2DPhi1 = segment2DPhi1->specificRecHits();
0181 vector<DTRecHit1D> recHitsSeg2DPhi2 = segment2DPhi2->specificRecHits();
0182
0183 copy(recHitsSeg2DPhi2.begin(), recHitsSeg2DPhi2.end(), back_inserter(recHitsSeg2DPhi1));
0184
0185 const DTChamberId chId = segment2DPhi1->chamberId();
0186
0187
0188 DTChamberRecSegment2D superPhi(chId, recHitsSeg2DPhi1);
0189
0190
0191 theUpdator->fit(&superPhi, false, false);
0192
0193
0194 if (superPhi.chi2() > theMaxChi2forPhi)
0195 result.push_back(superPhi);
0196 }
0197 }
0198
0199
0200
0201 return result;
0202 }