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 }
00071
00072
00073 DTSegment2DQuality::~DTSegment2DQuality(){
00074
00075 if(debug)
00076 cout << "[DTSegment2DQuality] Destructor called" << endl;
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 if(debug)
00107 cout << "--- [DTSegment2DQuality] Analysing Event: #Run: " << event.id().run()
00108 << " #Event: " << event.id().event() << endl;
00109 theFile->cd();
00110
00111
00112 ESHandle<DTGeometry> dtGeom;
00113 eventSetup.get<MuonGeometryRecord>().get(dtGeom);
00114
00115
00116 edm::Handle<PSimHitContainer> simHits;
00117 event.getByLabel(simHitLabel, "MuonDTHits", simHits);
00118
00119
00120 map<DTSuperLayerId, PSimHitContainer > simHitsPerSl;
00121 for(PSimHitContainer::const_iterator simHit = simHits->begin();
00122 simHit != simHits->end(); simHit++){
00123
00124 DTSuperLayerId slId = ((DTWireId(simHit->detUnitId())).layerId()).superlayerId();
00125
00126 simHitsPerSl[slId].push_back(*simHit);
00127 }
00128
00129
00130 Handle<DTRecSegment2DCollection> segment2Ds;
00131 event.getByLabel(segment2DLabel, segment2Ds);
00132
00133
00134 DTRecSegment2DCollection::id_iterator slId;
00135 for (slId = segment2Ds->id_begin();
00136 slId != segment2Ds->id_end();
00137 ++slId){
00138
00139
00140
00141 PSimHitContainer simHits = simHitsPerSl[(*slId)];
00142
00143
00144 map<DTWireId, PSimHitContainer > simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(simHits);
00145 map<DTWireId, const PSimHit*> muSimHitPerWire = DTHitQualityUtils::mapMuSimHitsPerWire(simHitsPerWire);
00146 int nMuSimHit = muSimHitPerWire.size();
00147 if(nMuSimHit == 0 || nMuSimHit == 1) {
00148 if(debug && nMuSimHit == 1)
00149 cout << "[DTSegment2DQuality] Only " << nMuSimHit << " mu SimHit in this SL, skipping!" << endl;
00150 continue;
00151 }
00152 if(debug)
00153 cout << "=== SL " << (*slId) << " has " << nMuSimHit << " SimHits" << endl;
00154
00155
00156 pair<const PSimHit*, const PSimHit*> inAndOutSimHit = DTHitQualityUtils::findMuSimSegment(muSimHitPerWire);
00157
00158 if(inAndOutSimHit.first ==inAndOutSimHit.second ) {
00159 cout << "[DTHitQualityUtils]***Warning: outermost and innermost SimHit are the same!" << endl;
00160 continue;
00161 }
00162
00163
00164 pair<LocalVector, LocalPoint> dirAndPosSimSegm = DTHitQualityUtils::findMuSimSegmentDirAndPos(inAndOutSimHit,
00165 (*slId),&(*dtGeom));
00166
00167 LocalVector simSegmLocalDir = dirAndPosSimSegm.first;
00168 LocalPoint simSegmLocalPos = dirAndPosSimSegm.second;
00169 if(debug)
00170 cout<<" Simulated segment: local direction "<<simSegmLocalDir<<endl
00171 <<" local position "<<simSegmLocalPos<<endl;
00172 const DTSuperLayer* superLayer = dtGeom->superLayer(*slId);
00173 GlobalPoint simSegmGlobalPos = superLayer->toGlobal(simSegmLocalPos);
00174
00175
00176 float angleSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).first;
00177 float posSimSeg = simSegmLocalPos.x();
00178
00179 float etaSimSeg = simSegmGlobalPos.eta();
00180 float phiSimSeg = simSegmGlobalPos.phi();
00181
00182
00183
00184
00185 bool recHitFound = false;
00186 DTRecSegment2DCollection::range range = segment2Ds->get(*slId);
00187 int nsegm = distance(range.first, range.second);
00188 if(debug)
00189 cout << " Sl: " << *slId << " has " << nsegm
00190 << " 2D segments" << endl;
00191
00192 if (nsegm!=0) {
00193
00194
00195
00196
00197
00198 const DTRecSegment2D* bestRecHit = 0;
00199 bool bestRecHitFound = false;
00200 double deltaAlpha = 99999;
00201
00202
00203 for (DTRecSegment2DCollection::const_iterator segment2D = range.first;
00204 segment2D!=range.second;
00205 ++segment2D){
00206
00207 if((*segment2D).dimension() != 2) {
00208 if(debug) cout << "[DTSegment2DQuality]***Error: This is not 2D segment!!!" << endl;
00209 abort();
00210 }
00211
00212 LocalVector recSegDirection = (*segment2D).localDirection();
00213 LocalPoint recSegPosition = (*segment2D).localPosition();
00214
00215 float recSegAlpha = DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).first;
00216 if(debug)
00217 cout << " RecSegment direction: " << recSegDirection << endl
00218 << " position : " << recSegPosition << endl
00219 << " alpha : " << recSegAlpha << endl;
00220
00221 if(fabs(recSegAlpha - angleSimSeg) < deltaAlpha) {
00222 deltaAlpha = fabs(recSegAlpha - angleSimSeg);
00223 bestRecHit = &(*segment2D);
00224 bestRecHitFound = true;
00225 }
00226 }
00227
00228 if(bestRecHitFound) {
00229
00230 LocalPoint bestRecHitLocalPos = bestRecHit->localPosition();
00231 LocalVector bestRecHitLocalDir = bestRecHit->localDirection();
00232
00233 LocalError bestRecHitLocalPosErr = bestRecHit->localPositionError();
00234 LocalError bestRecHitLocalDirErr = bestRecHit->localDirectionError();
00235
00236 float angleBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).first;
00237
00238 if(fabs(angleBestRHit - angleSimSeg) < 5*sigmaResAngle &&
00239 fabs(bestRecHitLocalPos.x() - posSimSeg) < 5*sigmaResPos) {
00240 recHitFound = true;
00241 }
00242
00243
00244 HRes2DHit *hRes = 0;
00245 if((*slId).superlayer() == 1 || (*slId).superlayer() == 3) {
00246 hRes = h2DHitRPhi;
00247 } else if((*slId).superlayer() == 2) {
00248 h2DHitRZ->Fill(angleSimSeg,
00249 angleBestRHit,
00250 posSimSeg,
00251 bestRecHitLocalPos.x(),
00252 etaSimSeg,
00253 phiSimSeg,
00254 sqrt(bestRecHitLocalPosErr.xx()),
00255 sqrt(bestRecHitLocalDirErr.xx())
00256 );
00257 if(abs((*slId).wheel()) == 0)
00258 hRes = h2DHitRZ_W0;
00259 else if(abs((*slId).wheel()) == 1)
00260 hRes = h2DHitRZ_W1;
00261 else if(abs((*slId).wheel()) == 2)
00262 hRes = h2DHitRZ_W2;
00263 }
00264 hRes->Fill(angleSimSeg,
00265 angleBestRHit,
00266 posSimSeg,
00267 bestRecHitLocalPos.x(),
00268 etaSimSeg,
00269 phiSimSeg,
00270 sqrt(bestRecHitLocalPosErr.xx()),
00271 sqrt(bestRecHitLocalDirErr.xx())
00272 );
00273 }
00274 }
00275
00276
00277 HEff2DHit *hEff = 0;
00278 if((*slId).superlayer() == 1 || (*slId).superlayer() == 3) {
00279 hEff = h2DHitEff_RPhi;
00280 } else if((*slId).superlayer() == 2) {
00281 h2DHitEff_RZ->Fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
00282 if(abs((*slId).wheel()) == 0)
00283 hEff = h2DHitEff_RZ_W0;
00284 else if(abs((*slId).wheel()) == 1)
00285 hEff = h2DHitEff_RZ_W1;
00286 else if(abs((*slId).wheel()) == 2)
00287 hEff = h2DHitEff_RZ_W2;
00288 }
00289 hEff->Fill(etaSimSeg, phiSimSeg, posSimSeg, angleSimSeg, recHitFound);
00290 }
00291 }
00292
00293
00294
00295
00296
00297