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