00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "DTSegment2DQuality.h"
00010 #include "Validation/DTRecHits/interface/DTHitQualityUtils.h"
00011
00012 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
00013 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00014 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00015 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00016
00017 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00018 #include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
00019 #include "DataFormats/DTRecHit/interface/DTRecSegment2DCollection.h"
00020
00021 #include "FWCore/Framework/interface/MakerMacros.h"
00022 #include "FWCore/Framework/interface/Frameworkfwd.h"
00023 #include "FWCore/Framework/interface/Event.h"
00024 #include "FWCore/Framework/interface/ESHandle.h"
00025
00026 #include "Histograms.h"
00027
00028 #include "TFile.h"
00029
00030 #include "DQMServices/Core/interface/DQMStore.h"
00031 #include "DQMServices/Core/interface/MonitorElement.h"
00032 #include <iostream>
00033 #include <map>
00034
00035 using namespace std;
00036 using namespace edm;
00037
00038
00039 DTSegment2DQuality::DTSegment2DQuality(const ParameterSet& pset) {
00040
00041 debug = pset.getUntrackedParameter<bool>("debug");
00042 DTHitQualityUtils::debug = debug;
00043
00044 simHitLabel = pset.getUntrackedParameter<InputTag>("simHitLabel");
00045
00046 segment2DLabel = pset.getUntrackedParameter<InputTag>("segment2DLabel");
00047
00048
00049 sigmaResPos = pset.getParameter<double>("sigmaResPos");
00050
00051 sigmaResAngle = pset.getParameter<double>("sigmaResAngle");
00052
00053
00054
00055
00056
00057 if(debug)
00058 cout << "[DTSegment2DQuality] Constructor called " << endl;
00059
00060
00061
00062 dbe_ = 0;
00063 dbe_ = Service<DQMStore>().operator->();
00064 if ( dbe_ ) {
00065 if (debug) {
00066 dbe_->setVerbose(1);
00067 } else {
00068 dbe_->setVerbose(0);
00069 }
00070 }
00071 if ( dbe_ ) {
00072 if ( debug ) dbe_->showDirStructure();
00073 }
00074
00075 h2DHitRPhi = new HRes2DHit ("RPhi",dbe_,true,true);
00076 h2DHitRZ= new HRes2DHit ("RZ",dbe_,true,true);
00077 h2DHitRZ_W0= new HRes2DHit ("RZ_W0",dbe_,true,true);
00078 h2DHitRZ_W1= new HRes2DHit ("RZ_W1",dbe_,true,true);
00079 h2DHitRZ_W2= new HRes2DHit ("RZ_W2",dbe_,true,true);
00080
00081 h2DHitEff_RPhi= new HEff2DHit ("RPhi",dbe_);
00082 h2DHitEff_RZ= new HEff2DHit ("RZ",dbe_);
00083 h2DHitEff_RZ_W0= new HEff2DHit ("RZ_W0",dbe_);
00084 h2DHitEff_RZ_W1= new HEff2DHit ("RZ_W1",dbe_);
00085 h2DHitEff_RZ_W2= new HEff2DHit ("RZ_W2",dbe_);
00086 if(debug)
00087 cout << "[DTSegment2DQuality] hitsos created " << endl;
00088 }
00089
00090
00091 DTSegment2DQuality::~DTSegment2DQuality(){
00092
00093 }
00094
00095 void DTSegment2DQuality::endJob() {
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 h2DHitEff_RPhi->ComputeEfficiency();
00106 h2DHitEff_RZ->ComputeEfficiency();
00107 h2DHitEff_RZ_W0->ComputeEfficiency();
00108 h2DHitEff_RZ_W1->ComputeEfficiency();
00109 h2DHitEff_RZ_W2->ComputeEfficiency();
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 }
00120
00121
00122 void DTSegment2DQuality::analyze(const Event & event, const EventSetup& eventSetup){
00123
00124
00125
00126 ESHandle<DTGeometry> dtGeom;
00127 eventSetup.get<MuonGeometryRecord>().get(dtGeom);
00128
00129
00130 edm::Handle<PSimHitContainer> simHits;
00131 event.getByLabel(simHitLabel, simHits);
00132
00133
00134 map<DTSuperLayerId, PSimHitContainer > simHitsPerSl;
00135 for(PSimHitContainer::const_iterator simHit = simHits->begin();
00136 simHit != simHits->end(); simHit++){
00137
00138 DTSuperLayerId slId = ((DTWireId(simHit->detUnitId())).layerId()).superlayerId();
00139
00140 simHitsPerSl[slId].push_back(*simHit);
00141 }
00142
00143
00144 Handle<DTRecSegment2DCollection> segment2Ds;
00145 event.getByLabel(segment2DLabel, segment2Ds);
00146
00147 if(!segment2Ds.isValid()) {
00148 if(debug) cout << "[DTSegment2DQuality]**Warning: no 2DSegments with label: " << segment2DLabel
00149 << " in this event, skipping!" << endl;
00150 return;
00151 }
00152
00153
00154 DTRecSegment2DCollection::id_iterator slId;
00155 for (slId = segment2Ds->id_begin();
00156 slId != segment2Ds->id_end();
00157 ++slId){
00158
00159
00160
00161 PSimHitContainer simHits = simHitsPerSl[(*slId)];
00162
00163
00164 map<DTWireId, PSimHitContainer > simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(simHits);
00165 map<DTWireId, const PSimHit*> muSimHitPerWire = DTHitQualityUtils::mapMuSimHitsPerWire(simHitsPerWire);
00166 int nMuSimHit = muSimHitPerWire.size();
00167 if(nMuSimHit == 0 || nMuSimHit == 1) {
00168 if(debug && nMuSimHit == 1)
00169 cout << "[DTSegment2DQuality] Only " << nMuSimHit << " mu SimHit in this SL, skipping!" << endl;
00170 continue;
00171 }
00172 if(debug)
00173 cout << "=== SL " << (*slId) << " has " << nMuSimHit << " SimHits" << endl;
00174
00175
00176 pair<const PSimHit*, const PSimHit*> inAndOutSimHit = DTHitQualityUtils::findMuSimSegment(muSimHitPerWire);
00177
00178 if(inAndOutSimHit.first ==inAndOutSimHit.second ) {
00179 cout << "[DTHitQualityUtils]***Warning: outermost and innermost SimHit are the same!" << endl;
00180 continue;
00181 }
00182
00183
00184 pair<LocalVector, LocalPoint> dirAndPosSimSegm = DTHitQualityUtils::findMuSimSegmentDirAndPos(inAndOutSimHit,
00185 (*slId),&(*dtGeom));
00186
00187 LocalVector simSegmLocalDir = dirAndPosSimSegm.first;
00188 LocalPoint simSegmLocalPos = dirAndPosSimSegm.second;
00189 if(debug)
00190 cout<<" Simulated segment: local direction "<<simSegmLocalDir<<endl
00191 <<" local position "<<simSegmLocalPos<<endl;
00192 const DTSuperLayer* superLayer = dtGeom->superLayer(*slId);
00193 GlobalPoint simSegmGlobalPos = superLayer->toGlobal(simSegmLocalPos);
00194
00195
00196 float angleSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).first;
00197 float posSimSeg = simSegmLocalPos.x();
00198
00199 float etaSimSeg = simSegmGlobalPos.eta();
00200 float phiSimSeg = simSegmGlobalPos.phi();
00201
00202
00203
00204
00205 bool recHitFound = false;
00206 DTRecSegment2DCollection::range range = segment2Ds->get(*slId);
00207 int nsegm = distance(range.first, range.second);
00208 if(debug)
00209 cout << " Sl: " << *slId << " has " << nsegm
00210 << " 2D segments" << endl;
00211
00212 if (nsegm!=0) {
00213
00214
00215
00216
00217
00218 const DTRecSegment2D* bestRecHit = 0;
00219 bool bestRecHitFound = false;
00220 double deltaAlpha = 99999;
00221
00222
00223 for (DTRecSegment2DCollection::const_iterator segment2D = range.first;
00224 segment2D!=range.second;
00225 ++segment2D){
00226
00227 if((*segment2D).dimension() != 2) {
00228 if(debug) cout << "[DTSegment2DQuality]***Error: This is not 2D segment!!!" << endl;
00229 abort();
00230 }
00231
00232 LocalVector recSegDirection = (*segment2D).localDirection();
00233 LocalPoint recSegPosition = (*segment2D).localPosition();
00234
00235 float recSegAlpha = DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).first;
00236 if(debug)
00237 cout << " RecSegment direction: " << recSegDirection << endl
00238 << " position : " << recSegPosition << endl
00239 << " alpha : " << recSegAlpha << endl;
00240
00241 if(fabs(recSegAlpha - angleSimSeg) < deltaAlpha) {
00242 deltaAlpha = fabs(recSegAlpha - angleSimSeg);
00243 bestRecHit = &(*segment2D);
00244 bestRecHitFound = true;
00245 }
00246 }
00247
00248 if(bestRecHitFound) {
00249
00250 LocalPoint bestRecHitLocalPos = bestRecHit->localPosition();
00251 LocalVector bestRecHitLocalDir = bestRecHit->localDirection();
00252
00253 LocalError bestRecHitLocalPosErr = bestRecHit->localPositionError();
00254 LocalError bestRecHitLocalDirErr = bestRecHit->localDirectionError();
00255
00256 float angleBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).first;
00257
00258 if(fabs(angleBestRHit - angleSimSeg) < 5*sigmaResAngle &&
00259 fabs(bestRecHitLocalPos.x() - posSimSeg) < 5*sigmaResPos) {
00260 recHitFound = true;
00261 }
00262
00263
00264 HRes2DHit *hRes = 0;
00265 if((*slId).superlayer() == 1 || (*slId).superlayer() == 3) {
00266 hRes = h2DHitRPhi;
00267 } else if((*slId).superlayer() == 2) {
00268 h2DHitRZ->Fill(angleSimSeg,
00269 angleBestRHit,
00270 posSimSeg,
00271 bestRecHitLocalPos.x(),
00272 etaSimSeg,
00273 phiSimSeg,
00274 sqrt(bestRecHitLocalPosErr.xx()),
00275 sqrt(bestRecHitLocalDirErr.xx())
00276 );
00277 if(abs((*slId).wheel()) == 0)
00278 hRes = h2DHitRZ_W0;
00279 else if(abs((*slId).wheel()) == 1)
00280 hRes = h2DHitRZ_W1;
00281 else if(abs((*slId).wheel()) == 2)
00282 hRes = h2DHitRZ_W2;
00283 }
00284 hRes->Fill(angleSimSeg,
00285 angleBestRHit,
00286 posSimSeg,
00287 bestRecHitLocalPos.x(),
00288 etaSimSeg,
00289 phiSimSeg,
00290 sqrt(bestRecHitLocalPosErr.xx()),
00291 sqrt(bestRecHitLocalDirErr.xx())
00292 );
00293 }
00294 }
00295
00296
00297 HEff2DHit *hEff = 0;
00298 if((*slId).superlayer() == 1 || (*slId).superlayer() == 3) {
00299 hEff = h2DHitEff_RPhi;
00300 } else if((*slId).superlayer() == 2) {
00301 h2DHitEff_RZ->Fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
00302 if(abs((*slId).wheel()) == 0)
00303 hEff = h2DHitEff_RZ_W0;
00304 else if(abs((*slId).wheel()) == 1)
00305 hEff = h2DHitEff_RZ_W1;
00306 else if(abs((*slId).wheel()) == 2)
00307 hEff = h2DHitEff_RZ_W2;
00308 }
00309 hEff->Fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
00310 }
00311 }
00312
00313
00314
00315
00316
00317