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