00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "DataFormats/TrackReco/interface/Track.h"
00010 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00011 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00012 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00013 #include "DataFormats/TrackCandidate/interface/TrackCandidate.h"
00014 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00015 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00016 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00017 #include "MagneticField/Engine/interface/MagneticField.h"
00018
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 #include "FWCore/Utilities/interface/InputTag.h"
00021 #include "DQMServices/Core/interface/DQMStore.h"
00022 #include "DQM/TrackingMonitor/interface/TrackBuildingAnalyzer.h"
00023 #include "DQM/TrackingMonitor/interface/TrackAnalyzer.h"
00024 #include "DQM/TrackingMonitor/plugins/TrackingMonitor.h"
00025
00026 #include "FWCore/Framework/interface/ESHandle.h"
00027 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00028
00029 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00030 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00031 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
00032 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00033 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00034 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
00035 #include "DataFormats/Common/interface/DetSetVectorNew.h"
00036 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
00037 #include "DataFormats/SiPixelCluster/interface/SiPixelCluster.h"
00038 #include <string>
00039
00040
00041
00042
00043 TrackingMonitor::TrackingMonitor(const edm::ParameterSet& iConfig)
00044 : dqmStore_( edm::Service<DQMStore>().operator->() )
00045 , conf_ ( iConfig )
00046 , theTrackAnalyzer( new TrackAnalyzer(conf_) )
00047 , theTrackBuildingAnalyzer( new TrackBuildingAnalyzer(conf_) )
00048 , NumberOfTracks(NULL)
00049 , NumberOfMeanRecHitsPerTrack(NULL)
00050 , NumberOfMeanLayersPerTrack(NULL)
00051 , NumberOfGoodTracks(NULL)
00052 , FractionOfGoodTracks(NULL)
00053 , NumberOfSeeds(NULL)
00054 , NumberOfTrackCandidates(NULL)
00055 , GoodTracksFractionVsLS(NULL)
00056 , GoodTracksNumberOfRecHitsPerTrackVsLS(NULL)
00057 , builderName( conf_.getParameter<std::string>("TTRHBuilder"))
00058 , doTrackerSpecific_( conf_.getParameter<bool>("doTrackerSpecific") )
00059 , doLumiAnalysis( conf_.getParameter<bool>("doLumiAnalysis"))
00060 , doProfilesVsLS_( conf_.getParameter<bool>("doProfilesVsLS"))
00061 , genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig))
00062 {
00063 }
00064
00065
00066 TrackingMonitor::~TrackingMonitor()
00067 {
00068 if (theTrackAnalyzer) delete theTrackAnalyzer;
00069 if (theTrackBuildingAnalyzer) delete theTrackBuildingAnalyzer;
00070 if (genTriggerEventFlag_) delete genTriggerEventFlag_;
00071 }
00072
00073
00074 void TrackingMonitor::beginJob(void)
00075 {
00076
00077
00078 std::string Quality = conf_.getParameter<std::string>("Quality");
00079 std::string AlgoName = conf_.getParameter<std::string>("AlgoName");
00080 std::string MEFolderName = conf_.getParameter<std::string>("FolderName");
00081
00082
00083 if( Quality != "")
00084 {
00085 if( Quality != "highPurity" && Quality != "tight" && Quality != "loose")
00086 {
00087 edm::LogWarning("TrackingMonitor") << "Qualty Name is invalid, using no quality criterea by default";
00088 Quality = "";
00089 }
00090 }
00091
00092
00093 std::string CatagoryName = Quality != "" ? AlgoName + "_" + Quality : AlgoName;
00094
00095
00096 int TKNoBin = conf_.getParameter<int>( "TkSizeBin");
00097 double TKNoMin = conf_.getParameter<double>("TkSizeMin");
00098 double TKNoMax = conf_.getParameter<double>("TkSizeMax");
00099
00100 int TCNoBin = conf_.getParameter<int>( "TCSizeBin");
00101 double TCNoMin = conf_.getParameter<double>("TCSizeMin");
00102 double TCNoMax = conf_.getParameter<double>("TCSizeMax");
00103
00104 int TKNoSeedBin = conf_.getParameter<int>( "TkSeedSizeBin");
00105 double TKNoSeedMin = conf_.getParameter<double>("TkSeedSizeMin");
00106 double TKNoSeedMax = conf_.getParameter<double>("TkSeedSizeMax");
00107
00108 int MeanHitBin = conf_.getParameter<int>( "MeanHitBin");
00109 double MeanHitMin = conf_.getParameter<double>("MeanHitMin");
00110 double MeanHitMax = conf_.getParameter<double>("MeanHitMax");
00111
00112 int MeanLayBin = conf_.getParameter<int>( "MeanLayBin");
00113 double MeanLayMin = conf_.getParameter<double>("MeanLayMin");
00114 double MeanLayMax = conf_.getParameter<double>("MeanLayMax");
00115
00116 int LSBin = conf_.getParameter<int>( "LSBin");
00117 int LSMin = conf_.getParameter<double>("LSMin");
00118 int LSMax = conf_.getParameter<double>("LSMax");
00119
00120 std::string StateName = conf_.getParameter<std::string>("MeasurementState");
00121 if
00122 (
00123 StateName != "OuterSurface" &&
00124 StateName != "InnerSurface" &&
00125 StateName != "ImpactPoint" &&
00126 StateName != "default" &&
00127 StateName != "All"
00128 )
00129 {
00130
00131 edm::LogWarning("TrackingMonitor") << "State Name is invalid, using 'ImpactPoint' by default";
00132 }
00133
00134 dqmStore_->setCurrentFolder(MEFolderName);
00135
00136
00137
00138 dqmStore_->setCurrentFolder(MEFolderName+"/GeneralProperties");
00139
00140 histname = "NumberOfTracks_" + CatagoryName;
00141 NumberOfTracks = dqmStore_->book1D(histname, histname, TKNoBin, TKNoMin, TKNoMax);
00142 NumberOfTracks->setAxisTitle("Number of Tracks per Event", 1);
00143 NumberOfTracks->setAxisTitle("Number of Events", 2);
00144
00145 histname = "NumberOfMeanRecHitsPerTrack_" + CatagoryName;
00146 NumberOfMeanRecHitsPerTrack = dqmStore_->book1D(histname, histname, MeanHitBin, MeanHitMin, MeanHitMax);
00147 NumberOfMeanRecHitsPerTrack->setAxisTitle("Mean number of RecHits per Track", 1);
00148 NumberOfMeanRecHitsPerTrack->setAxisTitle("Entries", 2);
00149
00150 histname = "NumberOfMeanLayersPerTrack_" + CatagoryName;
00151 NumberOfMeanLayersPerTrack = dqmStore_->book1D(histname, histname, MeanLayBin, MeanLayMin, MeanLayMax);
00152 NumberOfMeanLayersPerTrack->setAxisTitle("Mean number of Layers per Track", 1);
00153 NumberOfMeanLayersPerTrack->setAxisTitle("Entries", 2);
00154
00155 histname = "NumberOfGoodTracks_" + CatagoryName;
00156 NumberOfGoodTracks = dqmStore_->book1D(histname, histname, TKNoBin, TKNoMin, TKNoMax);
00157 NumberOfGoodTracks->setAxisTitle("Number of Good Tracks per Event", 1);
00158 NumberOfGoodTracks->setAxisTitle("Number of Events", 2);
00159
00160 histname = "FractionOfGoodTracks_" + CatagoryName;
00161 FractionOfGoodTracks = dqmStore_->book1D(histname, histname, 101, -0.005, 1.005);
00162 FractionOfGoodTracks->setAxisTitle("Fraction of High Purity Tracks (Tracks with Pt>1GeV)", 1);
00163 FractionOfGoodTracks->setAxisTitle("Entries", 2);
00164
00165
00166
00167
00168 if ( doProfilesVsLS_ ) {
00169 histname = "GoodTracksFractionVsLS_"+ CatagoryName;
00170 GoodTracksFractionVsLS = dqmStore_->bookProfile(histname,histname, LSBin,LSMin,LSMax,0,1.1,"");
00171 GoodTracksFractionVsLS->getTH1()->SetBit(TH1::kCanRebin);
00172 GoodTracksFractionVsLS->setAxisTitle("#Lumi section",1);
00173 GoodTracksFractionVsLS->setAxisTitle("Fraction of Good Tracks",2);
00174
00175 histname = "GoodTracksNumberOfRecHitsPerTrackVsLS_" + CatagoryName;
00176 GoodTracksNumberOfRecHitsPerTrackVsLS = dqmStore_->bookProfile(histname,histname, LSBin,LSMin,LSMax,0.,40.,"");
00177 GoodTracksNumberOfRecHitsPerTrackVsLS->getTH1()->SetBit(TH1::kCanRebin);
00178 GoodTracksNumberOfRecHitsPerTrackVsLS->setAxisTitle("#Lumi section",1);
00179 GoodTracksNumberOfRecHitsPerTrackVsLS->setAxisTitle("Mean number of RecHits per Good track",2);
00180 }
00181
00182 theTrackAnalyzer->beginJob(dqmStore_);
00183
00184
00185
00186 if (conf_.getParameter<bool>("doSeedParameterHistos"))
00187 {
00188 dqmStore_->setCurrentFolder(MEFolderName+"/TrackBuilding");
00189
00190 histname = "NumberOfSeeds_" + CatagoryName;
00191 NumberOfSeeds = dqmStore_->book1D(histname, histname, TKNoSeedBin, TKNoSeedMin, TKNoSeedMax);
00192 NumberOfSeeds->setAxisTitle("Number of Seeds per Event", 1);
00193 NumberOfSeeds->setAxisTitle("Number of Events", 2);
00194
00195 histname = "NumberOfTrackCandidates_" + CatagoryName;
00196 NumberOfTrackCandidates = dqmStore_->book1D(histname, histname, TCNoBin, TCNoMin, TCNoMax);
00197 NumberOfTrackCandidates->setAxisTitle("Number of Track Candidates per Event", 1);
00198 NumberOfTrackCandidates->setAxisTitle("Number of Event", 2);
00199
00200 theTrackBuildingAnalyzer->beginJob(dqmStore_);
00201 }
00202 if (doLumiAnalysis) {
00203 if (NumberOfTracks) NumberOfTracks->setLumiFlag();
00204 if (NumberOfGoodTracks) NumberOfGoodTracks->setLumiFlag();
00205 if (FractionOfGoodTracks) FractionOfGoodTracks->setLumiFlag();
00206 theTrackAnalyzer->setLumiFlag();
00207 }
00208 if (doTrackerSpecific_) {
00209
00210 int NClusPxBin = conf_.getParameter<int>( "NClusPxBin");
00211 double NClusPxMin = conf_.getParameter<double>("NClusPxMin");
00212 double NClusPxMax = conf_.getParameter<double>("NClusPxMax");
00213
00214 int NClusStrBin = conf_.getParameter<int>( "NClusStrBin");
00215 double NClusStrMin = conf_.getParameter<double>("NClusStrMin");
00216 double NClusStrMax = conf_.getParameter<double>("NClusStrMax");
00217
00218 int NClus2DTotBin = conf_.getParameter<int>( "NClus2DTotBin");
00219 double NClus2DTotMin = conf_.getParameter<double>("NClus2DTotMin");
00220 double NClus2DTotMax = conf_.getParameter<double>("NClus2DTotMax");
00221 int NTrk2DBin = conf_.getParameter<int>( "NTrk2DBin");
00222 double NTrk2DMin = conf_.getParameter<double>("NTrk2DMin");
00223 double NTrk2DMax = conf_.getParameter<double>("NTrk2DMax");
00224
00225 dqmStore_->setCurrentFolder(MEFolderName+"/HitProperties");
00226
00227 histname = "NumberOfClustersInPixel_" + CatagoryName;
00228 NumberOfPixelClus = dqmStore_->book1D(histname, histname, NClusPxBin, NClusPxMin, NClusPxMax);
00229 NumberOfPixelClus->setAxisTitle("# of Clusters in Pixel", 1);
00230 NumberOfPixelClus->setAxisTitle("Number of Events", 2);
00231
00232 histname = "NumberOfClustersInStrip_" + CatagoryName;
00233 NumberOfStripClus = dqmStore_->book1D(histname, histname, NClusStrBin, NClusStrMin, NClusStrMax);
00234 NumberOfStripClus->setAxisTitle("# of Clusters in Strip Detectors", 1);
00235 NumberOfStripClus->setAxisTitle("Number of Events", 2);
00236
00237 histname = "RatioOfPixelAndStripClusters_" + CatagoryName;
00238 RatioOfPixelAndStripClus = dqmStore_->book1D(histname, histname, 100, 0.0, 1.6);
00239 RatioOfPixelAndStripClus->setAxisTitle("ArcTan(PixelCluster/StripClusters)", 1);
00240 RatioOfPixelAndStripClus->setAxisTitle("Number of Events", 2);
00241
00242 histname = "TracksVsClusters_" + CatagoryName;
00243 NumberOfTrkVsClus = dqmStore_->book2D(histname,histname,NTrk2DBin,NTrk2DMin,NTrk2DMax,
00244 NClus2DTotBin,NClus2DTotMin,NClus2DTotMax);
00245 NumberOfTrkVsClus->setAxisTitle("Number of Tracks", 1);
00246 NumberOfTrkVsClus->setAxisTitle("# of Clusters in (Pixel+Strip) Detectors", 2);
00247
00248 }
00249
00250
00251 }
00252
00253
00254
00255 void TrackingMonitor::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00256 {
00257
00258 if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
00259 }
00260
00261
00262
00263 void TrackingMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumi, const edm::EventSetup& eSetup) {
00264 if (doLumiAnalysis) {
00265 dqmStore_->softReset(NumberOfTracks);
00266 dqmStore_->softReset(NumberOfGoodTracks);
00267 dqmStore_->softReset(FractionOfGoodTracks);
00268 theTrackAnalyzer->doSoftReset(dqmStore_);
00269 }
00270 }
00271
00272
00273
00274 void TrackingMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00275 {
00276
00277 if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
00278
00279
00280 edm::InputTag trackProducer = conf_.getParameter<edm::InputTag>("TrackProducer");
00281 edm::InputTag seedProducer = conf_.getParameter<edm::InputTag>("SeedProducer");
00282 edm::InputTag tcProducer = conf_.getParameter<edm::InputTag>("TCProducer");
00283 edm::InputTag bsSrc = conf_.getParameter<edm::InputTag>("beamSpot");
00284 std::string Quality = conf_.getParameter<std::string>("Quality");
00285 std::string Algo = conf_.getParameter<std::string>("AlgoName");
00286
00287
00288
00289
00290
00291
00292 edm::Handle<reco::TrackCollection> trackHandle;
00293 iEvent.getByLabel(trackProducer, trackHandle);
00294
00295 if (trackHandle.isValid())
00296 {
00297
00298 reco::TrackCollection trackCollection = *trackHandle;
00299
00300 int totalNumTracks = 0, totalRecHits = 0, totalLayers = 0;
00301 int totalNumHPTracks = 0, totalNumPt1Tracks = 0, totalNumHPPt1Tracks = 0;
00302
00303 for (reco::TrackCollection::const_iterator track = trackCollection.begin(); track!=trackCollection.end(); ++track)
00304 {
00305
00306 if( track->quality(reco::TrackBase::highPurity) ) {
00307 ++totalNumHPTracks;
00308 if ( track->pt() >= 1. ) {
00309 ++totalNumHPPt1Tracks;
00310 if ( doProfilesVsLS_ )
00311 GoodTracksNumberOfRecHitsPerTrackVsLS->Fill(static_cast<double>(iEvent.id().luminosityBlock()),track->recHitsSize());
00312 }
00313 }
00314
00315 if ( track->pt() >= 1. ) ++totalNumPt1Tracks;
00316
00317
00318 if( Quality == "highPurity")
00319 {
00320 if( !track->quality(reco::TrackBase::highPurity) ) continue;
00321 }
00322 else if( Quality == "tight")
00323 {
00324 if( !track->quality(reco::TrackBase::tight) ) continue;
00325 }
00326 else if( Quality == "loose")
00327 {
00328 if( !track->quality(reco::TrackBase::loose) ) continue;
00329 }
00330
00331 totalNumTracks++;
00332 totalRecHits += track->found();
00333 totalLayers += track->hitPattern().trackerLayersWithMeasurement();
00334
00335
00336 theTrackAnalyzer->analyze(iEvent, iSetup, *track);
00337 }
00338
00339 NumberOfTracks->Fill(totalNumTracks);
00340 NumberOfGoodTracks->Fill(totalNumHPPt1Tracks);
00341
00342 double frac = 0.;
00343 if (totalNumPt1Tracks > 0) frac = static_cast<double>(totalNumHPPt1Tracks)/static_cast<double>(totalNumPt1Tracks);
00344 FractionOfGoodTracks->Fill(frac);
00345 if ( doProfilesVsLS_ )
00346 GoodTracksFractionVsLS->Fill(static_cast<double>(iEvent.id().luminosityBlock()),frac);
00347
00348 if( totalNumTracks > 0 )
00349 {
00350 double meanRecHits = static_cast<double>(totalRecHits) / static_cast<double>(totalNumTracks);
00351 double meanLayers = static_cast<double>(totalLayers) / static_cast<double>(totalNumTracks);
00352 NumberOfMeanRecHitsPerTrack->Fill(meanRecHits);
00353 NumberOfMeanLayersPerTrack->Fill(meanLayers);
00354 }
00355
00356
00357
00358
00359
00360
00361 if (conf_.getParameter<bool>("doSeedParameterHistos"))
00362 {
00363
00364
00365 edm::ESHandle<MagneticField> theMF;
00366 iSetup.get<IdealMagneticFieldRecord>().get(theMF);
00367
00368
00369 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00370 iEvent.getByLabel(bsSrc,recoBeamSpotHandle);
00371 const reco::BeamSpot& bs = *recoBeamSpotHandle;
00372
00373
00374 edm::Handle<TrackCandidateCollection> theTCHandle;
00375 iEvent.getByLabel(tcProducer, theTCHandle );
00376 const TrackCandidateCollection& theTCCollection = *theTCHandle;
00377
00378
00379 if (theTCHandle.isValid())
00380 {
00381 NumberOfTrackCandidates->Fill(theTCCollection.size());
00382 iSetup.get<TransientRecHitRecord>().get(builderName,theTTRHBuilder);
00383 for( TrackCandidateCollection::const_iterator cand = theTCCollection.begin(); cand != theTCCollection.end(); ++cand)
00384 {
00385 theTrackBuildingAnalyzer->analyze(iEvent, iSetup, *cand, bs, theMF, theTTRHBuilder);
00386 }
00387 }
00388 else
00389 {
00390 edm::LogWarning("TrackingMonitor") << "No Track Candidates in the event. Not filling associated histograms";
00391 }
00392
00393
00394 edm::Handle<edm::View<TrajectorySeed> > seedHandle;
00395 iEvent.getByLabel(seedProducer, seedHandle);
00396 const edm::View<TrajectorySeed>& seedCollection = *seedHandle;
00397
00398
00399 if (seedHandle.isValid())
00400 {
00401 NumberOfSeeds->Fill(seedCollection.size());
00402
00403 iSetup.get<TransientRecHitRecord>().get(builderName,theTTRHBuilder);
00404 for(size_t i=0; i < seedHandle->size(); ++i)
00405 {
00406 edm::RefToBase<TrajectorySeed> seed(seedHandle, i);
00407 theTrackBuildingAnalyzer->analyze(iEvent, iSetup, *seed, bs, theMF, theTTRHBuilder);
00408 }
00409 }
00410 else
00411 {
00412 edm::LogWarning("TrackingMonitor") << "No Trajectory seeds in the event. Not filling associated histograms";
00413 }
00414 }
00415 if ( doTrackerSpecific_)
00416 {
00417 edm::Handle< edmNew::DetSetVector<SiStripCluster> > strip_clusters;
00418 iEvent.getByLabel("siStripClusters", strip_clusters);
00419 edm::Handle< edmNew::DetSetVector<SiPixelCluster> > pixel_clusters;
00420 iEvent.getByLabel("siPixelClusters", pixel_clusters);
00421 if (strip_clusters.isValid() && pixel_clusters.isValid())
00422 {
00423 unsigned int ncluster_pix = (*pixel_clusters).dataSize();
00424 unsigned int ncluster_strip = (*strip_clusters).dataSize();
00425 double ratio = 0.0;
00426 if ( ncluster_pix > 0) ratio = atan(ncluster_pix*1.0/ncluster_strip);
00427
00428 NumberOfStripClus->Fill(ncluster_strip);
00429 NumberOfPixelClus->Fill(ncluster_pix);
00430 RatioOfPixelAndStripClus->Fill(ratio);
00431 NumberOfTrkVsClus->Fill(totalNumTracks, ncluster_strip+ncluster_pix);
00432 }
00433 }
00434
00435 }
00436 else
00437 {
00438 return;
00439 }
00440 }
00441 void TrackingMonitor::endRun(const edm::Run&, const edm::EventSetup&)
00442 {
00443 if (doLumiAnalysis) {
00444 dqmStore_->disableSoftReset(NumberOfTracks);
00445 dqmStore_->disableSoftReset(NumberOfGoodTracks);
00446 dqmStore_->disableSoftReset(FractionOfGoodTracks);
00447 theTrackAnalyzer->undoSoftReset(dqmStore_);
00448 }
00449
00450 }
00451
00452 void TrackingMonitor::endJob(void)
00453 {
00454 bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00455 std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00456 if(outputMEsInRootFile)
00457 {
00458 dqmStore_->showDirStructure();
00459 dqmStore_->save(outputFileName);
00460 }
00461 }
00462
00463 DEFINE_FWK_MODULE(TrackingMonitor);