File indexing completed on 2024-04-06 12:07:07
0001
0002
0003
0004
0005
0006
0007
0008 #include "DQM/DTMonitorModule/interface/DTCalibValidation.h"
0009
0010
0011 #include "FWCore/Framework/interface/Event.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "DQMServices/Core/interface/DQMStore.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017
0018
0019 #include "Geometry/DTGeometry/interface/DTGeometry.h"
0020
0021
0022 #include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
0023 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
0024
0025 #include <iterator>
0026
0027 using namespace edm;
0028 using namespace std;
0029
0030 DTCalibValidation::DTCalibValidation(const ParameterSet& pset)
0031 : muonGeomToken_(esConsumes<edm::Transition::BeginRun>()) {
0032 parameters = pset;
0033
0034
0035
0036
0037 recHits1DToken_ =
0038 consumes<DTRecHitCollection>(edm::InputTag(parameters.getUntrackedParameter<string>("recHits1DLabel")));
0039
0040 segment2DToken_ =
0041 consumes<DTRecSegment2DCollection>(edm::InputTag(parameters.getUntrackedParameter<string>("segment2DLabel")));
0042
0043 segment4DToken_ =
0044 consumes<DTRecSegment4DCollection>(edm::InputTag(parameters.getUntrackedParameter<string>("segment4DLabel")));
0045
0046 wrongSegment = 0;
0047
0048 rightSegment = 0;
0049
0050 detailedAnalysis = parameters.getUntrackedParameter<bool>("detailedAnalysis", false);
0051
0052 nevent = 0;
0053 }
0054
0055 DTCalibValidation::~DTCalibValidation() {
0056
0057
0058 LogVerbatim("DTCalibValidation") << "Segments used to compute residuals: " << rightSegment;
0059 LogVerbatim("DTCalibValidation") << "Segments not used to compute residuals: " << wrongSegment;
0060 }
0061
0062 void DTCalibValidation::dqmBeginRun(const edm::Run& run, const edm::EventSetup& setup) {
0063
0064 dtGeom = &setup.getData(muonGeomToken_);
0065 }
0066
0067 void DTCalibValidation::analyze(const edm::Event& event, const edm::EventSetup& setup) {
0068 ++nevent;
0069 LogTrace("DTCalibValidation") << "[DTCalibValidation] Analyze #Run: " << event.id().run() << " #Event: " << nevent;
0070
0071
0072 map<DTWireId, vector<DTRecHit1DPair> > recHitsPerWire_1S;
0073
0074
0075 map<DTWireId, vector<DTRecHit1D> > recHitsPerWire_2S;
0076
0077 if (detailedAnalysis) {
0078 LogTrace("DTCalibValidation") << " -- DTRecHit S1: begin analysis:";
0079
0080 Handle<DTRecHitCollection> dtRecHits;
0081 event.getByToken(recHits1DToken_, dtRecHits);
0082 recHitsPerWire_1S = map1DRecHitsPerWire(dtRecHits.product());
0083
0084 LogTrace("DTCalibValidation") << " -- DTRecHit S2: begin analysis:";
0085
0086 Handle<DTRecSegment2DCollection> segment2Ds;
0087 event.getByToken(segment2DToken_, segment2Ds);
0088 recHitsPerWire_2S = map1DRecHitsPerWire(segment2Ds.product());
0089 }
0090
0091
0092 LogTrace("DTCalibValidation") << " -- DTRecHit S3: begin analysis:";
0093
0094 Handle<DTRecSegment4DCollection> segment4Ds;
0095 event.getByToken(segment4DToken_, segment4Ds);
0096 map<DTWireId, vector<DTRecHit1D> > recHitsPerWire_3S = map1DRecHitsPerWire(segment4Ds.product());
0097
0098
0099 for (DTRecSegment4DCollection::const_iterator segment = segment4Ds->begin(); segment != segment4Ds->end();
0100 ++segment) {
0101 if (detailedAnalysis) {
0102 LogTrace("DTCalibValidation") << "Anlysis on recHit at step 1";
0103 compute(dtGeom, (*segment), recHitsPerWire_1S, 1);
0104
0105 LogTrace("DTCalibValidation") << "Anlysis on recHit at step 2";
0106 compute(dtGeom, (*segment), recHitsPerWire_2S, 2);
0107 }
0108
0109 LogTrace("DTCalibValidation") << "Anlysis on recHit at step 3";
0110 compute(dtGeom, (*segment), recHitsPerWire_3S, 3);
0111 }
0112 }
0113
0114
0115 map<DTWireId, vector<DTRecHit1DPair> > DTCalibValidation::map1DRecHitsPerWire(
0116 const DTRecHitCollection* dt1DRecHitPairs) {
0117 map<DTWireId, vector<DTRecHit1DPair> > ret;
0118
0119 for (DTRecHitCollection::const_iterator rechit = dt1DRecHitPairs->begin(); rechit != dt1DRecHitPairs->end();
0120 ++rechit) {
0121 ret[(*rechit).wireId()].push_back(*rechit);
0122 }
0123
0124 return ret;
0125 }
0126
0127
0128 map<DTWireId, vector<DTRecHit1D> > DTCalibValidation::map1DRecHitsPerWire(const DTRecSegment2DCollection* segment2Ds) {
0129 map<DTWireId, vector<DTRecHit1D> > ret;
0130
0131
0132 for (DTRecSegment2DCollection::const_iterator segment = segment2Ds->begin(); segment != segment2Ds->end();
0133 ++segment) {
0134 vector<DTRecHit1D> component1DHits = (*segment).specificRecHits();
0135
0136 for (vector<DTRecHit1D>::const_iterator hit = component1DHits.begin(); hit != component1DHits.end(); ++hit) {
0137 ret[(*hit).wireId()].push_back(*hit);
0138 }
0139 }
0140 return ret;
0141 }
0142
0143
0144 map<DTWireId, std::vector<DTRecHit1D> > DTCalibValidation::map1DRecHitsPerWire(
0145 const DTRecSegment4DCollection* segment4Ds) {
0146 map<DTWireId, vector<DTRecHit1D> > ret;
0147
0148 for (DTRecSegment4DCollection::const_iterator segment = segment4Ds->begin(); segment != segment4Ds->end();
0149 ++segment) {
0150
0151 vector<const TrackingRecHit*> segment2Ds = (*segment).recHits();
0152
0153 for (vector<const TrackingRecHit*>::const_iterator segment2D = segment2Ds.begin(); segment2D != segment2Ds.end();
0154 ++segment2D) {
0155
0156 vector<const TrackingRecHit*> hits = (*segment2D)->recHits();
0157
0158 for (vector<const TrackingRecHit*>::const_iterator hit = hits.begin(); hit != hits.end(); ++hit) {
0159 const DTRecHit1D* hit1D = dynamic_cast<const DTRecHit1D*>(*hit);
0160 ret[hit1D->wireId()].push_back(*hit1D);
0161 }
0162 }
0163 }
0164
0165 return ret;
0166 }
0167
0168
0169 template <typename type>
0170 const type* DTCalibValidation::findBestRecHit(const DTLayer* layer,
0171 DTWireId wireId,
0172 const vector<type>& recHits,
0173 const float segmDist) {
0174 float res = 99999;
0175 const type* theBestRecHit = nullptr;
0176
0177 for (typename vector<type>::const_iterator recHit = recHits.begin(); recHit != recHits.end(); ++recHit) {
0178 float distTmp = recHitDistFromWire(*recHit, layer);
0179 if (fabs(distTmp - segmDist) < res) {
0180 res = fabs(distTmp - segmDist);
0181 theBestRecHit = &(*recHit);
0182 }
0183 }
0184
0185 return theBestRecHit;
0186 }
0187
0188
0189 float DTCalibValidation::recHitDistFromWire(const DTRecHit1DPair& hitPair, const DTLayer* layer) {
0190 return fabs(hitPair.localPosition(DTEnums::Left).x() - hitPair.localPosition(DTEnums::Right).x()) / 2.;
0191 }
0192
0193
0194 float DTCalibValidation::recHitDistFromWire(const DTRecHit1D& recHit, const DTLayer* layer) {
0195 return fabs(recHit.localPosition().x() - layer->specificTopology().wirePosition(recHit.wireId().wire()));
0196 }
0197
0198
0199 float DTCalibValidation::recHitPosition(
0200 const DTRecHit1DPair& hitPair, const DTLayer* layer, const DTChamber* chamber, float segmentPos, int sl) {
0201
0202 GlobalPoint hitPosGlob_right = layer->toGlobal(hitPair.localPosition(DTEnums::Right));
0203 LocalPoint hitPosInChamber_right = chamber->toLocal(hitPosGlob_right);
0204 GlobalPoint hitPosGlob_left = layer->toGlobal(hitPair.localPosition(DTEnums::Left));
0205 LocalPoint hitPosInChamber_left = chamber->toLocal(hitPosGlob_left);
0206
0207 float recHitPos = -1;
0208 if (sl != 2) {
0209 if (fabs(hitPosInChamber_left.x() - segmentPos) < fabs(hitPosInChamber_right.x() - segmentPos))
0210 recHitPos = hitPosInChamber_left.x();
0211 else
0212 recHitPos = hitPosInChamber_right.x();
0213 } else {
0214 if (fabs(hitPosInChamber_left.y() - segmentPos) < fabs(hitPosInChamber_right.y() - segmentPos))
0215 recHitPos = hitPosInChamber_left.y();
0216 else
0217 recHitPos = hitPosInChamber_right.y();
0218 }
0219
0220 return recHitPos;
0221 }
0222
0223
0224 float DTCalibValidation::recHitPosition(
0225 const DTRecHit1D& recHit, const DTLayer* layer, const DTChamber* chamber, float segmentPos, int sl) {
0226
0227 GlobalPoint recHitPosGlob = layer->toGlobal(recHit.localPosition());
0228 LocalPoint recHitPosInChamber = chamber->toLocal(recHitPosGlob);
0229
0230 float recHitPos = -1;
0231 if (sl != 2)
0232 recHitPos = recHitPosInChamber.x();
0233 else
0234 recHitPos = recHitPosInChamber.y();
0235
0236 return recHitPos;
0237 }
0238
0239
0240 template <typename type>
0241 void DTCalibValidation::compute(const DTGeometry* dtGeom,
0242 const DTRecSegment4D& segment,
0243 const std::map<DTWireId, std::vector<type> >& recHitsPerWire,
0244 int step) {
0245 bool computeResidual = true;
0246
0247
0248 vector<DTRecHit1D> recHits1D_S3;
0249
0250
0251
0252 const DTChamberRecSegment2D* phiSeg = segment.phiSegment();
0253 if (phiSeg) {
0254 vector<DTRecHit1D> phiRecHits = phiSeg->specificRecHits();
0255 if (phiRecHits.size() != 8) {
0256 LogTrace("DTCalibValidation") << "[DTCalibValidation] Phi segments has: " << phiRecHits.size()
0257 << " hits, skipping";
0258 computeResidual = false;
0259 }
0260 copy(phiRecHits.begin(), phiRecHits.end(), back_inserter(recHits1D_S3));
0261 }
0262 if (!phiSeg) {
0263 LogTrace("DTCalibValidation") << " [DTCalibValidation] 4D segment has not the phi segment! ";
0264 computeResidual = false;
0265 }
0266
0267 if (segment.dimension() == 4) {
0268 const DTSLRecSegment2D* zSeg = segment.zSegment();
0269 if (zSeg) {
0270 vector<DTRecHit1D> zRecHits = zSeg->specificRecHits();
0271 if (zRecHits.size() != 4) {
0272 LogTrace("DTCalibValidation") << "[DTCalibValidation] Theta segments has: " << zRecHits.size()
0273 << " hits, skipping";
0274 computeResidual = false;
0275 }
0276 copy(zRecHits.begin(), zRecHits.end(), back_inserter(recHits1D_S3));
0277 }
0278 if (!zSeg) {
0279 LogTrace("DTCalibValidation") << " [DTCalibValidation] 4D segment has not the z segment! ";
0280 computeResidual = false;
0281 }
0282 }
0283
0284 if (!computeResidual)
0285 ++wrongSegment;
0286 if (computeResidual) {
0287 ++rightSegment;
0288
0289 for (vector<DTRecHit1D>::const_iterator recHit1D = recHits1D_S3.begin(); recHit1D != recHits1D_S3.end();
0290 ++recHit1D) {
0291 const DTWireId wireId = (*recHit1D).wireId();
0292
0293
0294 const DTLayer* layer = dtGeom->layer(wireId);
0295 float wireX = layer->specificTopology().wirePosition(wireId.wire());
0296
0297
0298
0299
0300 LocalPoint wirePosInLay(wireX, (*recHit1D).localPosition().y(), (*recHit1D).localPosition().z());
0301 GlobalPoint wirePosGlob = layer->toGlobal(wirePosInLay);
0302 const DTChamber* chamber = dtGeom->chamber((*recHit1D).wireId().layerId().chamberId());
0303 LocalPoint wirePosInChamber = chamber->toLocal(wirePosGlob);
0304
0305
0306 LocalPoint segPosAtZWire = segment.localPosition() + segment.localDirection() * wirePosInChamber.z() /
0307 cos(segment.localDirection().theta());
0308
0309
0310 int sl = wireId.superlayer();
0311 float SegmDistance = -1;
0312 if (sl == 1 || sl == 3) {
0313
0314 SegmDistance = fabs(wirePosInChamber.x() - segPosAtZWire.x());
0315 LogTrace("DTCalibValidation") << "SegmDistance: " << SegmDistance;
0316 } else if (sl == 2) {
0317
0318 SegmDistance = fabs(segPosAtZWire.y() - wirePosInChamber.y());
0319 LogTrace("DTCalibValidation") << "SegmDistance: " << SegmDistance;
0320 }
0321 if (SegmDistance > 2.1)
0322 LogTrace("DTCalibValidation") << " Warning: dist segment-wire: " << SegmDistance;
0323
0324
0325 if (recHitsPerWire.find(wireId) == recHitsPerWire.end()) {
0326 LogTrace("DTCalibValidation") << " No RecHit found at Step: " << step << " in cell: " << wireId;
0327 } else {
0328 const vector<type>& recHits = recHitsPerWire.at(wireId);
0329 LogTrace("DTCalibValidation") << " " << recHits.size() << " RecHits, Step " << step
0330 << " in channel: " << wireId;
0331
0332
0333 const DTLayer* layer = dtGeom->layer(wireId);
0334
0335 const type* theBestRecHit = findBestRecHit(layer, wireId, recHits, SegmDistance);
0336
0337 float recHitWireDist = recHitDistFromWire(*theBestRecHit, layer);
0338 LogTrace("DTCalibValidation") << "recHitWireDist: " << recHitWireDist;
0339
0340
0341 float residualOnDistance = recHitWireDist - SegmDistance;
0342 LogTrace("DTCalibValidation") << "WireId: " << wireId << " ResidualOnDistance: " << residualOnDistance;
0343 float residualOnPosition = -1;
0344 float recHitPos = -1;
0345 if (sl == 1 || sl == 3) {
0346 recHitPos = recHitPosition(*theBestRecHit, layer, chamber, segPosAtZWire.x(), sl);
0347 residualOnPosition = recHitPos - segPosAtZWire.x();
0348 } else {
0349 recHitPos = recHitPosition(*theBestRecHit, layer, chamber, segPosAtZWire.y(), sl);
0350 residualOnPosition = recHitPos - segPosAtZWire.y();
0351 }
0352 LogTrace("DTCalibValidation") << "WireId: " << wireId << " ResidualOnPosition: " << residualOnPosition;
0353
0354
0355 if (sl == 1 || sl == 3)
0356 fillHistos(wireId.superlayerId(),
0357 SegmDistance,
0358 residualOnDistance,
0359 (wirePosInChamber.x() - segPosAtZWire.x()),
0360 residualOnPosition,
0361 step);
0362 else
0363 fillHistos(wireId.superlayerId(),
0364 SegmDistance,
0365 residualOnDistance,
0366 (wirePosInChamber.y() - segPosAtZWire.y()),
0367 residualOnPosition,
0368 step);
0369 }
0370 }
0371 }
0372 }
0373
0374 void DTCalibValidation::bookHistograms(DQMStore::IBooker& ibooker,
0375 edm::Run const& iRun,
0376 edm::EventSetup const& iSetup) {
0377
0378 ibooker.setCurrentFolder("DT/DTCalibValidation");
0379
0380 DTSuperLayerId slId;
0381
0382
0383 vector<const DTChamber*>::const_iterator ch_it = dtGeom->chambers().begin();
0384 vector<const DTChamber*>::const_iterator ch_end = dtGeom->chambers().end();
0385 for (; ch_it != ch_end; ++ch_it) {
0386 vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
0387 vector<const DTSuperLayer*>::const_iterator sl_end = (*ch_it)->superLayers().end();
0388
0389 for (; sl_it != sl_end; ++sl_it) {
0390 slId = (*sl_it)->id();
0391
0392 int firstStep = 1;
0393 if (!detailedAnalysis)
0394 firstStep = 3;
0395
0396 for (int step = firstStep; step <= 3; ++step) {
0397 LogTrace("DTCalibValidation") << " Booking histos for SL: " << slId;
0398
0399
0400 stringstream wheel;
0401 wheel << slId.wheel();
0402 stringstream station;
0403 station << slId.station();
0404 stringstream sector;
0405 sector << slId.sector();
0406 stringstream superLayer;
0407 superLayer << slId.superlayer();
0408
0409 stringstream Step;
0410 Step << step;
0411
0412 string slHistoName = "_STEP" + Step.str() + "_W" + wheel.str() + "_St" + station.str() + "_Sec" + sector.str() +
0413 "_SL" + superLayer.str();
0414
0415 ibooker.setCurrentFolder("DT/DTCalibValidation/Wheel" + wheel.str() + "/Station" + station.str() + "/Sector" +
0416 sector.str());
0417
0418 vector<MonitorElement*> histos;
0419
0420 histos.push_back(ibooker.book1D(
0421 "hResDist" + slHistoName, "Residuals on the distance from wire (rec_hit - segm_extr) (cm)", 200, -0.4, 0.4));
0422 histos.push_back(
0423 ibooker.book2D("hResDistVsDist" + slHistoName,
0424 "Residuals on the distance (cm) from wire (rec_hit - segm_extr) vs distance (cm)",
0425 100,
0426 0,
0427 2.5,
0428 200,
0429 -0.4,
0430 0.4));
0431 if (detailedAnalysis) {
0432 histos.push_back(ibooker.book1D("hResPos" + slHistoName,
0433 "Residuals on the position from wire (rec_hit - segm_extr) (cm)",
0434 200,
0435 -0.4,
0436 0.4));
0437 histos.push_back(
0438 ibooker.book2D("hResPosVsPos" + slHistoName,
0439 "Residuals on the position (cm) from wire (rec_hit - segm_extr) vs distance (cm)",
0440 200,
0441 -2.5,
0442 2.5,
0443 200,
0444 -0.4,
0445 0.4));
0446 }
0447
0448 histosPerSL[make_pair(slId, step)] = histos;
0449 }
0450 }
0451 }
0452 }
0453
0454
0455 void DTCalibValidation::fillHistos(
0456 DTSuperLayerId slId, float distance, float residualOnDistance, float position, float residualOnPosition, int step) {
0457
0458 vector<MonitorElement*> histos = histosPerSL[make_pair(slId, step)];
0459 histos[0]->Fill(residualOnDistance);
0460 histos[1]->Fill(distance, residualOnDistance);
0461 if (detailedAnalysis) {
0462 histos[2]->Fill(residualOnPosition);
0463 histos[3]->Fill(position, residualOnPosition);
0464 }
0465 }
0466
0467
0468
0469
0470