00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "DTSegment4DQuality.h"
00010 #include "Validation/DTRecHits/interface/DTHitQualityUtils.h"
00011
00012 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00013 #include "Geometry/DTGeometry/interface/DTChamber.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/DTRecSegment4DCollection.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 #include "DQMServices/Core/interface/DQMStore.h"
00026 #include "DQMServices/Core/interface/MonitorElement.h"
00027
00028 #include "Histograms.h"
00029
00030 #include "TFile.h"
00031 #include <iostream>
00032 #include <map>
00033
00034
00035 using namespace std;
00036 using namespace edm;
00037
00038
00039
00040
00041 DTSegment4DQuality::DTSegment4DQuality(const ParameterSet& pset) {
00042
00043 debug = pset.getUntrackedParameter<bool>("debug");
00044 DTHitQualityUtils::debug = debug;
00045
00046 rootFileName = pset.getUntrackedParameter<string>("rootFileName");
00047
00048 simHitLabel = pset.getUntrackedParameter<InputTag>("simHitLabel");
00049
00050 segment4DLabel = pset.getUntrackedParameter<InputTag>("segment4DLabel");
00051
00052
00053 sigmaResX = pset.getParameter<double>("sigmaResX");
00054 sigmaResY = pset.getParameter<double>("sigmaResY");
00055
00056 sigmaResAlpha = pset.getParameter<double>("sigmaResAlpha");
00057 sigmaResBeta = pset.getParameter<double>("sigmaResBeta");
00058 doall = pset.getUntrackedParameter<bool>("doall", false);
00059 local = pset.getUntrackedParameter<bool>("local", false);
00060
00061
00062
00063
00064
00065
00066
00067 dbe_ = 0;
00068 dbe_ = Service<DQMStore>().operator->();
00069 if ( dbe_ ) {
00070 if (debug) {
00071 dbe_->setVerbose(1);
00072 } else {
00073 dbe_->setVerbose(0);
00074 }
00075 }
00076 if ( dbe_ ) {
00077 if ( debug ) dbe_->showDirStructure();
00078 }
00079
00080 h4DHit= new HRes4DHit ("All",dbe_,doall,local);
00081 h4DHit_W0= new HRes4DHit ("W0",dbe_,doall,local);
00082 h4DHit_W1= new HRes4DHit ("W1",dbe_,doall,local);
00083 h4DHit_W2= new HRes4DHit ("W2",dbe_,doall,local);
00084
00085 if(doall) {
00086 hEff_All= new HEff4DHit ("All",dbe_);
00087 hEff_W0= new HEff4DHit ("W0",dbe_);
00088 hEff_W1= new HEff4DHit ("W1",dbe_);
00089 hEff_W2= new HEff4DHit ("W2",dbe_);
00090 }
00091 }
00092
00093
00094 DTSegment4DQuality::~DTSegment4DQuality(){
00095
00096 }
00097 void DTSegment4DQuality::endLuminosityBlock(edm::LuminosityBlock const& lumiSeg,
00098 edm::EventSetup const& c){
00099
00100
00101 }
00102
00103 void DTSegment4DQuality::endJob() {
00104
00105
00106
00107
00108
00109
00110
00111
00112 if(doall){
00113 hEff_All->ComputeEfficiency();
00114 hEff_W0->ComputeEfficiency();
00115 hEff_W1->ComputeEfficiency();
00116 hEff_W2->ComputeEfficiency();
00117 }
00118
00119
00120
00121
00122
00123
00124
00125 }
00126
00127
00128 void DTSegment4DQuality::analyze(const Event & event, const EventSetup& eventSetup){
00129
00130
00131
00132 ESHandle<DTGeometry> dtGeom;
00133 eventSetup.get<MuonGeometryRecord>().get(dtGeom);
00134
00135
00136 edm::Handle<PSimHitContainer> simHits;
00137 event.getByLabel(simHitLabel, simHits);
00138
00139
00140 map<DTChamberId, PSimHitContainer > simHitsPerCh;
00141 for(PSimHitContainer::const_iterator simHit = simHits->begin();
00142 simHit != simHits->end(); simHit++){
00143
00144 DTChamberId chamberId = (((DTWireId(simHit->detUnitId())).layerId()).superlayerId()).chamberId();
00145
00146 simHitsPerCh[chamberId].push_back(*simHit);
00147 }
00148
00149
00150 Handle<DTRecSegment4DCollection> segment4Ds;
00151 event.getByLabel(segment4DLabel, segment4Ds);
00152
00153 if(!segment4Ds.isValid()) {
00154 if(debug) cout << "[DTSegment4DQuality]**Warning: no 4D Segments with label: " <<segment4DLabel
00155 << " in this event, skipping!" << endl;
00156 return;
00157 }
00158
00159
00160 DTRecSegment4DCollection::id_iterator chamberId;
00161 for (chamberId = segment4Ds->id_begin();
00162 chamberId != segment4Ds->id_end();
00163 ++chamberId){
00164
00165 if((*chamberId).station() == 4)
00166 continue;
00167
00168
00169
00170 PSimHitContainer simHits = simHitsPerCh[(*chamberId)];
00171
00172
00173 map<DTWireId, PSimHitContainer > simHitsPerWire = DTHitQualityUtils::mapSimHitsPerWire(simHits);
00174 map<DTWireId, const PSimHit*> muSimHitPerWire = DTHitQualityUtils::mapMuSimHitsPerWire(simHitsPerWire);
00175 int nMuSimHit = muSimHitPerWire.size();
00176 if(nMuSimHit == 0 || nMuSimHit == 1) {
00177 if(debug && nMuSimHit == 1)
00178 cout << "[DTSegment4DQuality] Only " << nMuSimHit << " mu SimHit in this chamber, skipping!" << endl;
00179 continue;
00180 }
00181 if(debug)
00182 cout << "=== Chamber " << (*chamberId) << " has " << nMuSimHit << " SimHits" << endl;
00183
00184
00185 pair<const PSimHit*, const PSimHit*> inAndOutSimHit = DTHitQualityUtils::findMuSimSegment(muSimHitPerWire);
00186
00187
00188 pair<LocalVector, LocalPoint> dirAndPosSimSegm = DTHitQualityUtils::findMuSimSegmentDirAndPos(inAndOutSimHit,
00189 (*chamberId),&(*dtGeom));
00190
00191 LocalVector simSegmLocalDir = dirAndPosSimSegm.first;
00192 LocalPoint simSegmLocalPos = dirAndPosSimSegm.second;
00193 const DTChamber* chamber = dtGeom->chamber(*chamberId);
00194 GlobalPoint simSegmGlobalPos = chamber->toGlobal(simSegmLocalPos);
00195 GlobalVector simSegmGlobalDir = chamber->toGlobal(simSegmLocalDir);
00196
00197
00198 float alphaSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).first;
00199 float betaSimSeg = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegmLocalDir).second;
00200
00201 float xSimSeg = simSegmLocalPos.x();
00202 float ySimSeg = simSegmLocalPos.y();
00203
00204 float etaSimSeg = simSegmGlobalPos.eta();
00205 float phiSimSeg = simSegmGlobalPos.phi();
00206
00207 if(debug)
00208 cout<<" Simulated segment: local direction "<<simSegmLocalDir<<endl
00209 <<" local position "<<simSegmLocalPos<<endl
00210 <<" alpha "<<alphaSimSeg<<endl
00211 <<" beta "<<betaSimSeg<<endl;
00212
00213
00214
00215 bool recHitFound = false;
00216 DTRecSegment4DCollection::range range = segment4Ds->get(*chamberId);
00217 int nsegm = distance(range.first, range.second);
00218 if(debug)
00219 cout << " Chamber: " << *chamberId << " has " << nsegm
00220 << " 4D segments" << endl;
00221
00222 if (nsegm!=0) {
00223
00224
00225
00226
00227
00228 const DTRecSegment4D* bestRecHit = 0;
00229 bool bestRecHitFound = false;
00230 double deltaAlpha = 99999;
00231
00232
00233 for (DTRecSegment4DCollection::const_iterator segment4D = range.first;
00234 segment4D!=range.second;
00235 ++segment4D){
00236
00237 if((*segment4D).dimension() != 4) {
00238 if(debug)cout << "[DTSegment4DQuality]***Error: This is not 4D segment!!!" << endl;
00239 continue;
00240 }
00241
00242 LocalVector recSegDirection = (*segment4D).localDirection();
00243
00244
00245 float recSegAlpha = DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).first;
00246 if(debug)
00247 cout << " RecSegment direction: " << recSegDirection << endl
00248 << " position : " << (*segment4D).localPosition() << endl
00249 << " alpha : " << recSegAlpha << endl
00250 << " beta : " << DTHitQualityUtils::findSegmentAlphaAndBeta(recSegDirection).second << endl;
00251
00252 if(fabs(recSegAlpha - alphaSimSeg) < deltaAlpha) {
00253 deltaAlpha = fabs(recSegAlpha - alphaSimSeg);
00254 bestRecHit = &(*segment4D);
00255 bestRecHitFound = true;
00256 }
00257 }
00258
00259 if(bestRecHitFound) {
00260
00261 LocalPoint bestRecHitLocalPos = bestRecHit->localPosition();
00262 LocalVector bestRecHitLocalDir = bestRecHit->localDirection();
00263
00264 LocalError bestRecHitLocalPosErr = bestRecHit->localPositionError();
00265 LocalError bestRecHitLocalDirErr = bestRecHit->localDirectionError();
00266
00267 float alphaBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).first;
00268 float betaBestRHit = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDir).second;
00269
00270
00271
00272
00273
00274
00275 const DTSLRecSegment2D * zedRecSeg = bestRecHit->zSegment();
00276 LocalPoint bestRecHitLocalPosRZ = zedRecSeg->localPosition();
00277 LocalVector bestRecHitLocalDirRZ = zedRecSeg->localDirection();
00278
00279 LocalError bestRecHitLocalPosErrRZ = zedRecSeg->localPositionError();
00280 LocalError bestRecHitLocalDirErrRZ = zedRecSeg->localDirectionError();
00281
00282 float alphaBestRHitRZ = DTHitQualityUtils::findSegmentAlphaAndBeta(bestRecHitLocalDirRZ).first;
00283
00284
00285 const DTSuperLayer* sl = dtGeom->superLayer(zedRecSeg->superLayerId());
00286 LocalPoint simSegLocalPosRZTmp = sl->toLocal(simSegmGlobalPos);
00287 LocalVector simSegLocalDirRZ = sl->toLocal(simSegmGlobalDir);
00288 LocalPoint simSegLocalPosRZ =
00289 simSegLocalPosRZTmp + simSegLocalDirRZ*(-simSegLocalPosRZTmp.z()/(cos(simSegLocalDirRZ.theta())));
00290 float alphaSimSegRZ = DTHitQualityUtils::findSegmentAlphaAndBeta(simSegLocalDirRZ).first;
00291
00292 if (debug) cout <<
00293 "RZ SL: recPos " << bestRecHitLocalPosRZ <<
00294 "recDir " << bestRecHitLocalDirRZ <<
00295 "recAlpha " << alphaBestRHitRZ << endl <<
00296 "RZ SL: simPos " << simSegLocalPosRZ <<
00297 "simDir " << simSegLocalDirRZ <<
00298 "simAlpha " << alphaSimSegRZ << endl ;
00299
00300
00301
00302 if(fabs(alphaBestRHit - alphaSimSeg) < 5*sigmaResAlpha &&
00303 fabs(betaBestRHit - betaSimSeg) < 5*sigmaResBeta &&
00304 fabs(bestRecHitLocalPos.x() - xSimSeg) < 5*sigmaResX &&
00305 fabs(bestRecHitLocalPos.y() - ySimSeg) < 5*sigmaResY) {
00306 recHitFound = true;
00307 }
00308
00309
00310 HRes4DHit *histo=0;
00311
00312 if((*chamberId).wheel() == 0)
00313 histo = h4DHit_W0;
00314 else if(abs((*chamberId).wheel()) == 1)
00315 histo = h4DHit_W1;
00316 else if(abs((*chamberId).wheel()) == 2)
00317 histo = h4DHit_W2;
00318
00319 histo->Fill(alphaSimSeg,
00320 alphaBestRHit,
00321 betaSimSeg,
00322 betaBestRHit,
00323 xSimSeg,
00324 bestRecHitLocalPos.x(),
00325 ySimSeg,
00326 bestRecHitLocalPos.y(),
00327 etaSimSeg,
00328 phiSimSeg,
00329 bestRecHitLocalPosRZ.x(),
00330 simSegLocalPosRZ.x(),
00331 alphaBestRHitRZ,
00332 alphaSimSegRZ,
00333 sqrt(bestRecHitLocalDirErr.xx()),
00334 sqrt(bestRecHitLocalDirErr.yy()),
00335 sqrt(bestRecHitLocalPosErr.xx()),
00336 sqrt(bestRecHitLocalPosErr.yy()),
00337 sqrt(bestRecHitLocalDirErrRZ.xx()),
00338 sqrt(bestRecHitLocalPosErrRZ.xx())
00339 );
00340
00341 h4DHit->Fill(alphaSimSeg,
00342 alphaBestRHit,
00343 betaSimSeg,
00344 betaBestRHit,
00345 xSimSeg,
00346 bestRecHitLocalPos.x(),
00347 ySimSeg,
00348 bestRecHitLocalPos.y(),
00349 etaSimSeg,
00350 phiSimSeg,
00351 bestRecHitLocalPosRZ.x(),
00352 simSegLocalPosRZ.x(),
00353 alphaBestRHitRZ,
00354 alphaSimSegRZ,
00355 sqrt(bestRecHitLocalDirErr.xx()),
00356 sqrt(bestRecHitLocalDirErr.yy()),
00357 sqrt(bestRecHitLocalPosErr.xx()),
00358 sqrt(bestRecHitLocalPosErr.yy()),
00359 sqrt(bestRecHitLocalDirErrRZ.xx()),
00360 sqrt(bestRecHitLocalPosErrRZ.xx())
00361 );
00362 }
00363 }
00364
00365
00366 if(doall){
00367 HEff4DHit *heff = 0;
00368
00369 if((*chamberId).wheel() == 0)
00370 heff = hEff_W0;
00371 else if(abs((*chamberId).wheel()) == 1)
00372 heff = hEff_W1;
00373 else if(abs((*chamberId).wheel()) == 2)
00374 heff = hEff_W2;
00375 heff->Fill(etaSimSeg, phiSimSeg, xSimSeg, ySimSeg, alphaSimSeg, betaSimSeg, recHitFound);
00376 hEff_All->Fill(etaSimSeg, phiSimSeg, xSimSeg, ySimSeg, alphaSimSeg, betaSimSeg, recHitFound);
00377 }
00378 }
00379 }