CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/TrackingMonitor/plugins/TrackingMonitor.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2011/10/01 10:11:54 $
00005  *  $Revision: 1.30 $
00006  *  \author Suchandra Dutta , Giorgia Mila
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 // TrackingMonitor 
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     , doAllPlots( conf_.getParameter<bool>("doAllPlots"))
00062     , doGeneralPropertiesPlots_( conf_.getParameter<bool>("doGeneralPropertiesPlots"))
00063     , doHitPropertiesPlots_( conf_.getParameter<bool>("doHitPropertiesPlots"))
00064     , genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig))
00065 {
00066 }
00067 
00068 
00069 TrackingMonitor::~TrackingMonitor() 
00070 {
00071   if (theTrackAnalyzer)          delete theTrackAnalyzer;
00072   if (theTrackBuildingAnalyzer)  delete theTrackBuildingAnalyzer;
00073   if (genTriggerEventFlag_)      delete genTriggerEventFlag_;
00074 }
00075 
00076 
00077 void TrackingMonitor::beginJob(void) 
00078 {
00079 
00080     // parameters from the configuration
00081     std::string Quality      = conf_.getParameter<std::string>("Quality");
00082     std::string AlgoName     = conf_.getParameter<std::string>("AlgoName");
00083     std::string MEFolderName = conf_.getParameter<std::string>("FolderName"); 
00084 
00085     // test for the Quality veriable validity
00086     if( Quality != "")
00087     {
00088         if( Quality != "highPurity" && Quality != "tight" && Quality != "loose") 
00089         {
00090             edm::LogWarning("TrackingMonitor")  << "Qualty Name is invalid, using no quality criterea by default";
00091             Quality = "";
00092         }
00093     }
00094 
00095     // use the AlgoName and Quality Name
00096     std::string CatagoryName = Quality != "" ? AlgoName + "_" + Quality : AlgoName;
00097 
00098     // get binning from the configuration
00099     int    TKNoBin     = conf_.getParameter<int>(   "TkSizeBin");
00100     double TKNoMin     = conf_.getParameter<double>("TkSizeMin");
00101     double TKNoMax     = conf_.getParameter<double>("TkSizeMax");
00102 
00103     int    TCNoBin     = conf_.getParameter<int>(   "TCSizeBin");
00104     double TCNoMin     = conf_.getParameter<double>("TCSizeMin");
00105     double TCNoMax     = conf_.getParameter<double>("TCSizeMax");
00106 
00107     int    TKNoSeedBin = conf_.getParameter<int>(   "TkSeedSizeBin");
00108     double TKNoSeedMin = conf_.getParameter<double>("TkSeedSizeMin");
00109     double TKNoSeedMax = conf_.getParameter<double>("TkSeedSizeMax");
00110 
00111     int    MeanHitBin  = conf_.getParameter<int>(   "MeanHitBin");
00112     double MeanHitMin  = conf_.getParameter<double>("MeanHitMin");
00113     double MeanHitMax  = conf_.getParameter<double>("MeanHitMax");
00114 
00115     int    MeanLayBin  = conf_.getParameter<int>(   "MeanLayBin");
00116     double MeanLayMin  = conf_.getParameter<double>("MeanLayMin");
00117     double MeanLayMax  = conf_.getParameter<double>("MeanLayMax");
00118 
00119     int LSBin = conf_.getParameter<int>(   "LSBin");
00120     int LSMin = conf_.getParameter<double>("LSMin");
00121     int LSMax = conf_.getParameter<double>("LSMax");
00122 
00123     std::string StateName = conf_.getParameter<std::string>("MeasurementState");
00124     if
00125     (
00126         StateName != "OuterSurface" &&
00127         StateName != "InnerSurface" &&
00128         StateName != "ImpactPoint"  &&
00129         StateName != "default"      &&
00130         StateName != "All"
00131     )
00132     {
00133         // print warning
00134         edm::LogWarning("TrackingMonitor")  << "State Name is invalid, using 'ImpactPoint' by default";
00135     }
00136 
00137     dqmStore_->setCurrentFolder(MEFolderName);
00138 
00139     // book the General Property histograms
00140     // ---------------------------------------------------------------------------------//
00141 
00142     if (doGeneralPropertiesPlots_ || doAllPlots){
00143      
00144       dqmStore_->setCurrentFolder(MEFolderName+"/GeneralProperties");
00145 
00146       histname = "NumberOfTracks_" + CatagoryName;
00147       NumberOfTracks = dqmStore_->book1D(histname, histname, TKNoBin, TKNoMin, TKNoMax);
00148       NumberOfTracks->setAxisTitle("Number of Tracks per Event", 1);
00149       NumberOfTracks->setAxisTitle("Number of Events", 2);
00150       
00151       histname = "NumberOfMeanRecHitsPerTrack_" + CatagoryName;
00152       NumberOfMeanRecHitsPerTrack = dqmStore_->book1D(histname, histname, MeanHitBin, MeanHitMin, MeanHitMax);
00153       NumberOfMeanRecHitsPerTrack->setAxisTitle("Mean number of RecHits per Track", 1);
00154       NumberOfMeanRecHitsPerTrack->setAxisTitle("Entries", 2);
00155       
00156       histname = "NumberOfMeanLayersPerTrack_" + CatagoryName;
00157       NumberOfMeanLayersPerTrack = dqmStore_->book1D(histname, histname, MeanLayBin, MeanLayMin, MeanLayMax);
00158       NumberOfMeanLayersPerTrack->setAxisTitle("Mean number of Layers per Track", 1);
00159       NumberOfMeanLayersPerTrack->setAxisTitle("Entries", 2);
00160       
00161       histname = "NumberOfGoodTracks_" + CatagoryName;
00162       NumberOfGoodTracks = dqmStore_->book1D(histname, histname, TKNoBin, TKNoMin, TKNoMax);
00163       NumberOfGoodTracks->setAxisTitle("Number of Good Tracks per Event", 1);
00164       NumberOfGoodTracks->setAxisTitle("Number of Events", 2);
00165       
00166       histname = "FractionOfGoodTracks_" + CatagoryName;
00167       FractionOfGoodTracks = dqmStore_->book1D(histname, histname, 101, -0.005, 1.005);
00168       FractionOfGoodTracks->setAxisTitle("Fraction of High Purity Tracks (Tracks with Pt>1GeV)", 1);
00169       FractionOfGoodTracks->setAxisTitle("Entries", 2);
00170       
00171     }
00172 
00173 
00174     // book profile plots vs LS :  
00175     //---------------------------  
00176    
00177  
00178     if ( doProfilesVsLS_ || doAllPlots) {
00179       histname = "GoodTracksFractionVsLS_"+ CatagoryName;
00180       GoodTracksFractionVsLS = dqmStore_->bookProfile(histname,histname, LSBin,LSMin,LSMax,0,1.1,"");
00181       GoodTracksFractionVsLS->getTH1()->SetBit(TH1::kCanRebin);
00182       GoodTracksFractionVsLS->setAxisTitle("#Lumi section",1);
00183       GoodTracksFractionVsLS->setAxisTitle("Fraction of Good Tracks",2);
00184       
00185       histname = "GoodTracksNumberOfRecHitsPerTrackVsLS_" + CatagoryName;
00186       GoodTracksNumberOfRecHitsPerTrackVsLS = dqmStore_->bookProfile(histname,histname, LSBin,LSMin,LSMax,0.,40.,"");
00187       GoodTracksNumberOfRecHitsPerTrackVsLS->getTH1()->SetBit(TH1::kCanRebin);
00188       GoodTracksNumberOfRecHitsPerTrackVsLS->setAxisTitle("#Lumi section",1);
00189       GoodTracksNumberOfRecHitsPerTrackVsLS->setAxisTitle("Mean number of RecHits per Good track",2);
00190     }
00191 
00192     theTrackAnalyzer->beginJob(dqmStore_);
00193 
00194     // book the Seed Property histograms
00195     // ---------------------------------------------------------------------------------//
00196 
00197     dqmStore_->setCurrentFolder(MEFolderName+"/TrackBuilding");
00198 
00199     doAllSeedPlots=conf_.getParameter<bool>("doSeedParameterHistos");
00200     doSeedNumberPlot=conf_.getParameter<bool>("doSeedNumberHisto");
00201     doSeedVsClusterPlot=conf_.getParameter<bool>("doSeedVsClusterHisto");
00202     //    if (doAllPlots) doAllSeedPlots=true;
00203 
00204     runTrackBuildingAnalyzerForSeed=(doAllSeedPlots || conf_.getParameter<bool>("doSeedPTHisto") ||conf_.getParameter<bool>("doSeedETAHisto") || conf_.getParameter<bool>("doSeedPHIHisto") || conf_.getParameter<bool>("doSeedPHIVsETAHisto") || conf_.getParameter<bool>("doSeedThetaHisto") || conf_.getParameter<bool>("doSeedQHisto") || conf_.getParameter<bool>("doSeedDxyHisto") || conf_.getParameter<bool>("doSeedDzHisto") || conf_.getParameter<bool>("doSeedNRecHitsHisto") || conf_.getParameter<bool>("doSeedNVsPhiProf")|| conf_.getParameter<bool>("doSeedNVsEtaProf"));
00205 
00206     edm::InputTag seedProducer   = conf_.getParameter<edm::InputTag>("SeedProducer");
00207 
00208     if (doAllSeedPlots || doSeedNumberPlot){
00209       histname = "NumberOfSeeds_"+ seedProducer.label() + "_"+ CatagoryName;
00210       NumberOfSeeds = dqmStore_->book1D(histname, histname, TKNoSeedBin, TKNoSeedMin, TKNoSeedMax);
00211       NumberOfSeeds->setAxisTitle("Number of Seeds per Event", 1);
00212       NumberOfSeeds->setAxisTitle("Number of Events", 2);
00213     }
00214 
00215     if (doAllSeedPlots || doSeedVsClusterPlot){
00216 
00217       ClusterLabels=  conf_.getParameter<std::vector<std::string> >("ClusterLabels");
00218 
00219       std::vector<double> histoMin,histoMax;
00220       std::vector<int> histoBin; //these vectors are for max min and nbins in histograms 
00221 
00222       int    NClusPxBin  = conf_.getParameter<int>(   "NClusPxBin");
00223       double NClusPxMin  = conf_.getParameter<double>("NClusPxMin");
00224       double NClusPxMax = conf_.getParameter<double>("NClusPxMax");
00225       
00226       int    NClusStrBin = conf_.getParameter<int>(   "NClusStrBin");
00227       double NClusStrMin = conf_.getParameter<double>("NClusStrMin");
00228       double NClusStrMax = conf_.getParameter<double>("NClusStrMax");
00229 
00230       setMaxMinBin(histoMin,histoMax,histoBin,NClusStrMin,NClusStrMax,NClusStrBin,NClusPxMin,NClusPxMax,NClusPxBin);
00231      
00232       for (uint i=0; i<ClusterLabels.size(); i++){
00233         histname = "SeedsVsClusters_" + seedProducer.label() + "_Vs_" + ClusterLabels[i] + "_" + CatagoryName;
00234         SeedsVsClusters.push_back(dynamic_cast<MonitorElement*>(dqmStore_->book2D(histname, histname, histoBin[i], histoMin[i], histoMax[i],
00235                                                                                   TKNoSeedBin, TKNoSeedMin, TKNoSeedMax)));
00236         SeedsVsClusters[i]->setAxisTitle("Number of Clusters", 1);
00237         SeedsVsClusters[i]->setAxisTitle("Number of Seeds", 2);
00238       }
00239     }
00240     
00241 
00242     doTkCandPlots=conf_.getParameter<bool>("doTrackCandHistos");
00243     //    if (doAllPlots) doTkCandPlots=true;
00244 
00245     if (doTkCandPlots){
00246 
00247       edm::InputTag tcProducer     = conf_.getParameter<edm::InputTag>("TCProducer");
00248 
00249       histname = "NumberOfTrackCandidates_"+ tcProducer.label() + "_"+ CatagoryName;
00250       NumberOfTrackCandidates = dqmStore_->book1D(histname, histname, TCNoBin, TCNoMin, TCNoMax);
00251       NumberOfTrackCandidates->setAxisTitle("Number of Track Candidates per Event", 1);
00252       NumberOfTrackCandidates->setAxisTitle("Number of Event", 2);
00253     }
00254 
00255    
00256     theTrackBuildingAnalyzer->beginJob(dqmStore_);
00257     
00258 
00259     if (doLumiAnalysis) {
00260       if (NumberOfTracks) NumberOfTracks->setLumiFlag();
00261       if (NumberOfGoodTracks) NumberOfGoodTracks->setLumiFlag();
00262       if (FractionOfGoodTracks) FractionOfGoodTracks->setLumiFlag();
00263       theTrackAnalyzer->setLumiFlag();    
00264     }
00265 
00266     if (doTrackerSpecific_ || doAllPlots) {
00267 
00268       int    NClusPxBin  = conf_.getParameter<int>(   "NClusPxBin");
00269       double NClusPxMin  = conf_.getParameter<double>("NClusPxMin");
00270       double NClusPxMax = conf_.getParameter<double>("NClusPxMax");
00271 
00272       int    NClusStrBin = conf_.getParameter<int>(   "NClusStrBin");
00273       double NClusStrMin = conf_.getParameter<double>("NClusStrMin");
00274       double NClusStrMax = conf_.getParameter<double>("NClusStrMax");
00275 
00276       int    NClus2DTotBin = conf_.getParameter<int>(   "NClus2DTotBin");
00277       double NClus2DTotMin = conf_.getParameter<double>("NClus2DTotMin");
00278       double NClus2DTotMax = conf_.getParameter<double>("NClus2DTotMax");
00279       int    NTrk2DBin     = conf_.getParameter<int>(   "NTrk2DBin");
00280       double NTrk2DMin     = conf_.getParameter<double>("NTrk2DMin");
00281       double NTrk2DMax     = conf_.getParameter<double>("NTrk2DMax");
00282 
00283       dqmStore_->setCurrentFolder(MEFolderName+"/HitProperties");
00284 
00285       histname = "NumberOfClustersInPixel_" + CatagoryName; 
00286       NumberOfPixelClus = dqmStore_->book1D(histname, histname, NClusPxBin, NClusPxMin, NClusPxMax);
00287       NumberOfPixelClus->setAxisTitle("# of Clusters in Pixel", 1);
00288       NumberOfPixelClus->setAxisTitle("Number of Events", 2);
00289 
00290       histname = "NumberOfClustersInStrip_" + CatagoryName; 
00291       NumberOfStripClus = dqmStore_->book1D(histname, histname, NClusStrBin, NClusStrMin, NClusStrMax);
00292       NumberOfStripClus->setAxisTitle("# of Clusters in Strip Detectors", 1);
00293       NumberOfStripClus->setAxisTitle("Number of Events", 2);
00294 
00295       histname = "RatioOfPixelAndStripClusters_" + CatagoryName; 
00296       RatioOfPixelAndStripClus = dqmStore_->book1D(histname, histname, 100, 0.0, 1.6);
00297       RatioOfPixelAndStripClus->setAxisTitle("ArcTan(PixelCluster/StripClusters)", 1);
00298       RatioOfPixelAndStripClus->setAxisTitle("Number of Events", 2);
00299 
00300       histname = "TracksVsClusters_" + CatagoryName; 
00301       NumberOfTrkVsClus = dqmStore_->book2D(histname,histname,NTrk2DBin,NTrk2DMin,NTrk2DMax,
00302                                                        NClus2DTotBin,NClus2DTotMin,NClus2DTotMax);
00303       NumberOfTrkVsClus->setAxisTitle("Number of Tracks", 1);
00304       NumberOfTrkVsClus->setAxisTitle("# of Clusters in (Pixel+Strip) Detectors", 2);
00305 
00306     }
00307 
00308     
00309 }
00310 
00311 // -- BeginRun
00312 //---------------------------------------------------------------------------------//
00313 void TrackingMonitor::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00314 {
00315  
00316   // Initialize the GenericTriggerEventFlag
00317   if ( genTriggerEventFlag_->on() ) genTriggerEventFlag_->initRun( iRun, iSetup );
00318 }
00319 
00320 // - BeginLumi
00321 // ---------------------------------------------------------------------------------//
00322 void TrackingMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumi, const edm::EventSetup&  eSetup) {
00323 
00324   if (doLumiAnalysis) {
00325     dqmStore_->softReset(NumberOfTracks);
00326     dqmStore_->softReset(NumberOfGoodTracks);
00327     dqmStore_->softReset(FractionOfGoodTracks);
00328     theTrackAnalyzer->doSoftReset(dqmStore_);    
00329   }
00330 }
00331 
00332 // -- Analyse
00333 // ---------------------------------------------------------------------------------//
00334 void TrackingMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) 
00335 {
00336     // Filter out events if Trigger Filtering is requested
00337     if (genTriggerEventFlag_->on()&& ! genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
00338 
00339     // input tags for collections from the configuration
00340     edm::InputTag trackProducer  = conf_.getParameter<edm::InputTag>("TrackProducer");
00341     edm::InputTag seedProducer   = conf_.getParameter<edm::InputTag>("SeedProducer");
00342     edm::InputTag tcProducer     = conf_.getParameter<edm::InputTag>("TCProducer");
00343     edm::InputTag bsSrc          = conf_.getParameter<edm::InputTag>("beamSpot");
00344     std::string Quality     = conf_.getParameter<std::string>("Quality");
00345     std::string Algo        = conf_.getParameter<std::string>("AlgoName");
00346 
00347     //  Analyse the tracks
00348     //  if the collection is empty, do not fill anything
00349     // ---------------------------------------------------------------------------------//
00350 
00351     // get the track collection
00352     edm::Handle<reco::TrackCollection> trackHandle;
00353     iEvent.getByLabel(trackProducer, trackHandle);
00354 
00355     if (trackHandle.isValid()) 
00356     {
00357 
00358        reco::TrackCollection trackCollection = *trackHandle;
00359         // calculate the mean # rechits and layers
00360         int totalNumTracks = 0, totalRecHits = 0, totalLayers = 0;
00361         int totalNumHPTracks = 0, totalNumPt1Tracks = 0, totalNumHPPt1Tracks = 0;
00362 
00363         for (reco::TrackCollection::const_iterator track = trackCollection.begin(); track!=trackCollection.end(); ++track) 
00364         {
00365 
00366             if( track->quality(reco::TrackBase::highPurity) ) {
00367               ++totalNumHPTracks;
00368               if ( track->pt() >= 1. ) {
00369                 ++totalNumHPPt1Tracks;
00370                 if ( doProfilesVsLS_ || doAllPlots)
00371                   GoodTracksNumberOfRecHitsPerTrackVsLS->Fill(static_cast<double>(iEvent.id().luminosityBlock()),track->recHitsSize());
00372               }
00373             }
00374             
00375             if ( track->pt() >= 1. ) ++totalNumPt1Tracks;
00376 
00377 
00378             if( Quality == "highPurity") 
00379             {
00380                 if( !track->quality(reco::TrackBase::highPurity) ) continue;
00381             }
00382             else if( Quality == "tight") 
00383             {
00384                 if( !track->quality(reco::TrackBase::tight) ) continue;
00385             }
00386             else if( Quality == "loose") 
00387             {
00388                 if( !track->quality(reco::TrackBase::loose) ) continue;
00389             }
00390             
00391             totalNumTracks++;
00392             totalRecHits    += track->found();
00393             totalLayers     += track->hitPattern().trackerLayersWithMeasurement();
00394 
00395             // do analysis per track
00396             theTrackAnalyzer->analyze(iEvent, iSetup, *track);
00397         }
00398 
00399         if (doGeneralPropertiesPlots_ || doAllPlots){
00400           NumberOfTracks->Fill(totalNumTracks);
00401           NumberOfGoodTracks->Fill(totalNumHPPt1Tracks);
00402         }
00403 
00404           double frac = 0.;
00405           if (totalNumPt1Tracks > 0) frac = static_cast<double>(totalNumHPPt1Tracks)/static_cast<double>(totalNumPt1Tracks);
00406           if (doGeneralPropertiesPlots_ || doAllPlots) FractionOfGoodTracks->Fill(frac);
00407           if ( doProfilesVsLS_ || doAllPlots)
00408             GoodTracksFractionVsLS->Fill(static_cast<double>(iEvent.id().luminosityBlock()),frac);
00409 
00410           if (doGeneralPropertiesPlots_ || doAllPlots){
00411             if( totalNumTracks > 0 )
00412               {
00413                 double meanRecHits = static_cast<double>(totalRecHits) / static_cast<double>(totalNumTracks);
00414                 double meanLayers  = static_cast<double>(totalLayers)  / static_cast<double>(totalNumTracks);
00415                 NumberOfMeanRecHitsPerTrack->Fill(meanRecHits);
00416                 NumberOfMeanLayersPerTrack->Fill(meanLayers);
00417               }
00418           }
00419     
00420         //  Analyse the Track Building variables 
00421         //  if the collection is empty, do not fill anything
00422         // ---------------------------------------------------------------------------------//
00423         
00424                             
00425             // fill the TrackCandidate info
00426             if (doTkCandPlots) 
00427               {
00428         
00429                 // magnetic field
00430                 edm::ESHandle<MagneticField> theMF;
00431                 iSetup.get<IdealMagneticFieldRecord>().get(theMF);  
00432                 
00433                 // get the beam spot
00434                 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00435                 iEvent.getByLabel(bsSrc,recoBeamSpotHandle);
00436                 const reco::BeamSpot& bs = *recoBeamSpotHandle;      
00437                 
00438                 // get the candidate collection
00439                 edm::Handle<TrackCandidateCollection> theTCHandle;
00440                 iEvent.getByLabel(tcProducer, theTCHandle ); 
00441                 const TrackCandidateCollection& theTCCollection = *theTCHandle;
00442 
00443                 if (theTCHandle.isValid())
00444                   {
00445                     NumberOfTrackCandidates->Fill(theTCCollection.size());
00446                     iSetup.get<TransientRecHitRecord>().get(builderName,theTTRHBuilder);
00447                     for( TrackCandidateCollection::const_iterator cand = theTCCollection.begin(); cand != theTCCollection.end(); ++cand)
00448                       {
00449                         theTrackBuildingAnalyzer->analyze(iEvent, iSetup, *cand, bs, theMF, theTTRHBuilder);
00450                       }
00451                   }
00452                 else
00453                   {
00454                     edm::LogWarning("TrackingMonitor") << "No Track Candidates in the event.  Not filling associated histograms";
00455                   }
00456               }
00457     
00458             //plots for trajectory seeds
00459 
00460             if (doAllSeedPlots || doSeedNumberPlot || doSeedVsClusterPlot || runTrackBuildingAnalyzerForSeed){
00461             
00462             // get the seed collection
00463             edm::Handle<edm::View<TrajectorySeed> > seedHandle;
00464             iEvent.getByLabel(seedProducer, seedHandle);
00465             const edm::View<TrajectorySeed>& seedCollection = *seedHandle;
00466             
00467             // fill the seed info
00468             if (seedHandle.isValid()) 
00469               {
00470                 if(doAllSeedPlots || doSeedNumberPlot) NumberOfSeeds->Fill(seedCollection.size());
00471 
00472                 if(doAllSeedPlots || doSeedVsClusterPlot){
00473 
00474                   std::vector<int> NClus;
00475                   setNclus(iEvent,NClus);
00476                   for (uint  i=0; i< ClusterLabels.size(); i++){
00477                     SeedsVsClusters[i]->Fill(NClus[i],seedCollection.size());
00478                   }
00479                 }
00480 
00481                 if (doAllSeedPlots || runTrackBuildingAnalyzerForSeed){
00482 
00483                   //here duplication of mag field and be informations is needed to allow seed and track cand histos to be independent
00484                   // magnetic field
00485                   edm::ESHandle<MagneticField> theMF;
00486                   iSetup.get<IdealMagneticFieldRecord>().get(theMF);  
00487                   
00488                   // get the beam spot
00489                   edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00490                   iEvent.getByLabel(bsSrc,recoBeamSpotHandle);
00491                   const reco::BeamSpot& bs = *recoBeamSpotHandle;      
00492                   
00493                   iSetup.get<TransientRecHitRecord>().get(builderName,theTTRHBuilder);
00494                   for(size_t i=0; i < seedHandle->size(); ++i)
00495                     {
00496                       edm::RefToBase<TrajectorySeed> seed(seedHandle, i);
00497                       theTrackBuildingAnalyzer->analyze(iEvent, iSetup, *seed, bs, theMF, theTTRHBuilder);
00498                     }
00499                 }
00500                 
00501               }
00502             else
00503               {
00504                 edm::LogWarning("TrackingMonitor") << "No Trajectory seeds in the event.  Not filling associated histograms";
00505               }
00506             }
00507 
00508 
00509         if (doTrackerSpecific_ || doAllPlots) 
00510           {
00511             edm::Handle< edmNew::DetSetVector<SiStripCluster> > strip_clusters;
00512             iEvent.getByLabel("siStripClusters", strip_clusters);
00513             edm::Handle< edmNew::DetSetVector<SiPixelCluster> > pixel_clusters;
00514             iEvent.getByLabel("siPixelClusters", pixel_clusters);
00515             if (strip_clusters.isValid() && pixel_clusters.isValid()) 
00516               {
00517                 unsigned int ncluster_pix   = (*pixel_clusters).dataSize(); 
00518                 unsigned int ncluster_strip = (*strip_clusters).dataSize(); 
00519                 double ratio = 0.0;
00520                 if ( ncluster_pix > 0) ratio = atan(ncluster_pix*1.0/ncluster_strip);
00521 
00522                 NumberOfStripClus->Fill(ncluster_strip);
00523                 NumberOfPixelClus->Fill(ncluster_pix);
00524                 RatioOfPixelAndStripClus->Fill(ratio);
00525                 NumberOfTrkVsClus->Fill(totalNumTracks, ncluster_strip+ncluster_pix);
00526               }
00527           }
00528 
00529     }
00530     else
00531     {
00532         return;
00533     }
00534 }
00535 
00536 
00537 void TrackingMonitor::endRun(const edm::Run&, const edm::EventSetup&) 
00538 {
00539   if (doLumiAnalysis) {
00540     dqmStore_->disableSoftReset(NumberOfTracks);
00541     dqmStore_->disableSoftReset(NumberOfGoodTracks);
00542     dqmStore_->disableSoftReset(FractionOfGoodTracks);
00543     theTrackAnalyzer->undoSoftReset(dqmStore_);    
00544   }
00545   
00546 }
00547 
00548 void TrackingMonitor::endJob(void) 
00549 {
00550     bool outputMEsInRootFile   = conf_.getParameter<bool>("OutputMEsInRootFile");
00551     std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00552     if(outputMEsInRootFile)
00553     {
00554         dqmStore_->showDirStructure();
00555         dqmStore_->save(outputFileName);
00556     }
00557 }
00558 
00559 void TrackingMonitor::setMaxMinBin(std::vector<double> &arrayMin,  std::vector<double> &arrayMax, std::vector<int> &arrayBin, double smin, double smax, int sbin, double pmin, double pmax, int pbin) 
00560 {
00561   arrayMin.resize(ClusterLabels.size());
00562   arrayMax.resize(ClusterLabels.size());
00563   arrayBin.resize(ClusterLabels.size());
00564 
00565   for (uint i=0; i<ClusterLabels.size(); ++i){
00566 
00567     if (ClusterLabels[i].compare("Pix")==0) {arrayMin[i]=pmin; arrayMax[i]=pmax; arrayBin[i]=pbin;}
00568     else if(ClusterLabels[i].compare("Strip")==0){arrayMin[i]=smin; arrayMax[i]=smax; arrayBin[i]=sbin;}
00569     else if(ClusterLabels[i].compare("Tot")==0){arrayMin[i]=smin; arrayMax[i]=smax+pmax; arrayBin[i]=sbin;}
00570     else {edm::LogWarning("TrackingMonitor")  << "Cluster Label " << ClusterLabels[i] << " not defined, using strip parameters "; 
00571       arrayMin[i]=smin; arrayMax[i]=smax; arrayBin[i]=sbin;}
00572 
00573   }
00574     
00575 }
00576 
00577 void TrackingMonitor::setNclus(const edm::Event& iEvent,std::vector<int> &arrayNclus) 
00578 {
00579 
00580   int ncluster_pix=-1;
00581   int ncluster_strip=-1;
00582 
00583   edm::Handle< edmNew::DetSetVector<SiStripCluster> > strip_clusters;
00584   iEvent.getByLabel("siStripClusters", strip_clusters);
00585   edm::Handle< edmNew::DetSetVector<SiPixelCluster> > pixel_clusters;
00586   iEvent.getByLabel("siPixelClusters", pixel_clusters);
00587 
00588   if (strip_clusters.isValid() && pixel_clusters.isValid()) 
00589     {
00590                 ncluster_pix   = (*pixel_clusters).dataSize(); 
00591                 ncluster_strip = (*strip_clusters).dataSize(); 
00592     }
00593 
00594   arrayNclus.resize(ClusterLabels.size());
00595   for (uint i=0; i<ClusterLabels.size(); ++i){
00596 
00597     if (ClusterLabels[i].compare("Pix")==0) arrayNclus[i]=ncluster_pix ;
00598     else if(ClusterLabels[i].compare("Strip")==0) arrayNclus[i]=ncluster_strip;
00599     else if(ClusterLabels[i].compare("Tot")==0)arrayNclus[i]=ncluster_pix+ncluster_strip;
00600     else {edm::LogWarning("TrackingMonitor") << "Cluster Label " << ClusterLabels[i] << " not defined using stri parametrs ";
00601       arrayNclus[i]=ncluster_strip ;}
00602   }
00603     
00604 }
00605 DEFINE_FWK_MODULE(TrackingMonitor);