CMS 3D CMS Logo

TrackEfficiencyMonitor.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2009/04/02 14:39:59 $
00005  *  $Revision: 1.4 $
00006  *  \author Jeremy Andrea
00007  */
00008 
00009 #include "DataFormats/TrackReco/interface/Track.h"
00010 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00011 //#include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00012 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00013 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00014 #include "MagneticField/Engine/interface/MagneticField.h"
00015 
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 #include "FWCore/ParameterSet/interface/InputTag.h"
00018 #include "DQMServices/Core/interface/DQMStore.h"
00019 #include "DQM/TrackingMonitor/plugins/TrackEfficiencyMonitor.h"
00020 #include <string>
00021 
00022 // needed to compute the efficiency
00023 
00024 #include "DataFormats/TrackCandidate/interface/TrackCandidate.h"
00025 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00026 #include "DataFormats/MuonReco/interface/Muon.h"
00027 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00028 #include "TrackingTools/PatternTools/interface/TwoTrackMinimumDistance.h"
00029 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00030 
00031 #include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00032 #include "TrackingTools/GeomPropagators/interface/SmartPropagator.h"
00033 #include "DataFormats/Math/interface/Vector3D.h"
00034 #include "DataFormats/GeometrySurface/interface/Plane.h"
00035 #include "DataFormats/GeometrySurface/interface/BoundPlane.h"
00036 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00037 
00038 #include "PhysicsTools/UtilAlgos/interface/TFileService.h"
00039 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
00040 
00041 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00042 #include <RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h>
00043 
00044 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00045 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00046 #include "RecoTracker/TkNavigation/interface/CosmicNavigationSchool.h"
00047 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
00048 #include "TrackingTools/DetLayers/interface/NavigationSetter.h"
00049 
00050 
00051 
00052 //-----------------------------------------------------------------------------------
00053 TrackEfficiencyMonitor::TrackEfficiencyMonitor(const edm::ParameterSet& iConfig) 
00054 //-----------------------------------------------------------------------------------
00055 {
00056   dqmStore_            = edm::Service<DQMStore>().operator->(); 
00057  
00058   theRadius_           = iConfig.getParameter<double>("theRadius");
00059   theMaxZ_             = iConfig.getParameter<double>("theMaxZ");
00060   isBFieldOff_         = iConfig.getParameter<bool>("isBFieldOff");
00061   trackEfficiency_     = iConfig.getParameter<bool>("trackEfficiency");
00062   theTKTracksLabel_    = iConfig.getParameter<InputTag>("TKTrackCollection");
00063   theSTATracksLabel_   = iConfig.getParameter<InputTag>("STATrackCollection");
00064   
00065  
00066   conf_ = iConfig;
00067 }
00068 
00069 
00070 
00071 //-----------------------------------------------------------------------------------
00072 TrackEfficiencyMonitor::~TrackEfficiencyMonitor() 
00073 //-----------------------------------------------------------------------------------
00074 {}
00075 
00076 
00077 
00078 
00079 //-----------------------------------------------------------------------------------
00080 void TrackEfficiencyMonitor::beginJob(edm::EventSetup const& iSetup) 
00081 //-----------------------------------------------------------------------------------
00082 {
00083   using namespace edm;
00084   std::string MEFolderName = conf_.getParameter<std::string>("FolderName"); 
00085   std::string AlgoName     = conf_.getParameter<std::string>("AlgoName");
00086   
00087   
00088   dqmStore_->setCurrentFolder(MEFolderName);
00089   
00090   //
00091   int    muonXBin = conf_.getParameter<int>   ("muonXBin");
00092   double muonXMin = conf_.getParameter<double>("muonXMin");
00093   double muonXMax = conf_.getParameter<double>("muonXMax");
00094  
00095   histname = "muonX_";
00096   muonX = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, muonXBin, muonXMin, muonXMax);
00097   muonX->setAxisTitle("");
00098   
00099   //
00100   int    muonYBin = conf_.getParameter<int>   ("muonYBin");
00101   double muonYMin = conf_.getParameter<double>("muonYMin");
00102   double muonYMax = conf_.getParameter<double>("muonYMax");
00103  
00104   histname = "muonY_";
00105   muonY = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, muonYBin, muonYMin, muonYMax);
00106   muonY->setAxisTitle("");
00107   
00108   //
00109   int    muonZBin = conf_.getParameter<int>   ("muonZBin");
00110   double muonZMin = conf_.getParameter<double>("muonZMin");
00111   double muonZMax = conf_.getParameter<double>("muonZMax");
00112  
00113   histname = "muonZ_";
00114   muonZ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, muonZBin, muonZMin, muonZMax);
00115   muonZ->setAxisTitle("");
00116   
00117   //
00118   int    muonEtaBin = conf_.getParameter<int>   ("muonEtaBin");
00119   double muonEtaMin = conf_.getParameter<double>("muonEtaMin");
00120   double muonEtaMax = conf_.getParameter<double>("muonEtaMax");
00121  
00122   histname = "muonEta_";
00123   muonEta = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, muonEtaBin, muonEtaMin, muonEtaMax);
00124   muonEta->setAxisTitle("");
00125   
00126   //
00127   int    muonPhiBin = conf_.getParameter<int>   ("muonPhiBin");
00128   double muonPhiMin = conf_.getParameter<double>("muonPhiMin");
00129   double muonPhiMax = conf_.getParameter<double>("muonPhiMax");
00130  
00131   histname = "muonPhi_";
00132   muonPhi = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, muonPhiBin, muonPhiMin, muonPhiMax);
00133   muonPhi->setAxisTitle("");
00134   
00135   //
00136   int    muonD0Bin = conf_.getParameter<int>   ("muonD0Bin");
00137   double muonD0Min = conf_.getParameter<double>("muonD0Min");
00138   double muonD0Max = conf_.getParameter<double>("muonD0Max");
00139  
00140   histname = "muonD0_";
00141   muonD0 = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, muonD0Bin, muonD0Min, muonD0Max);
00142   muonD0->setAxisTitle("");
00143   
00144   //
00145   int    muonCompatibleLayersBin = conf_.getParameter<int>   ("muonCompatibleLayersBin");
00146   double muonCompatibleLayersMin = conf_.getParameter<double>("muonCompatibleLayersMin");
00147   double muonCompatibleLayersMax = conf_.getParameter<double>("muonCompatibleLayersMax");
00148  
00149   histname = "muonCompatibleLayers_";
00150   muonCompatibleLayers = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, muonCompatibleLayersBin, muonCompatibleLayersMin, muonCompatibleLayersMax);
00151   muonCompatibleLayers->setAxisTitle("");
00152 
00153   //------------------------------------------------------------------------------------
00154   
00155   //
00156   int    trackXBin = conf_.getParameter<int>   ("trackXBin");
00157   double trackXMin = conf_.getParameter<double>("trackXMin");
00158   double trackXMax = conf_.getParameter<double>("trackXMax");
00159  
00160   histname = "trackX_";
00161   trackX = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, trackXBin, trackXMin, trackXMax);
00162   trackX->setAxisTitle("");
00163   
00164   //
00165   int    trackYBin = conf_.getParameter<int>   ("trackYBin");
00166   double trackYMin = conf_.getParameter<double>("trackYMin");
00167   double trackYMax = conf_.getParameter<double>("trackYMax");
00168  
00169   histname = "trackY_";
00170   trackY = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, trackYBin, trackYMin, trackYMax);
00171   trackY->setAxisTitle("");
00172   
00173   //
00174   int    trackZBin = conf_.getParameter<int>   ("trackZBin");
00175   double trackZMin = conf_.getParameter<double>("trackZMin");
00176   double trackZMax = conf_.getParameter<double>("trackZMax");
00177  
00178   histname = "trackZ_";
00179   trackZ = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, trackZBin, trackZMin, trackZMax);
00180   trackZ->setAxisTitle("");
00181   
00182   //
00183   int    trackEtaBin = conf_.getParameter<int>   ("trackEtaBin");
00184   double trackEtaMin = conf_.getParameter<double>("trackEtaMin");
00185   double trackEtaMax = conf_.getParameter<double>("trackEtaMax");
00186  
00187   histname = "trackEta_";
00188   trackEta = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, trackEtaBin, trackEtaMin, trackEtaMax);
00189   trackEta->setAxisTitle("");
00190   
00191   //
00192   int    trackPhiBin = conf_.getParameter<int>   ("trackPhiBin");
00193   double trackPhiMin = conf_.getParameter<double>("trackPhiMin");
00194   double trackPhiMax = conf_.getParameter<double>("trackPhiMax");
00195  
00196   histname = "trackPhi_";
00197   trackPhi = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, trackPhiBin, trackPhiMin, trackPhiMax);
00198   trackPhi->setAxisTitle("");
00199   
00200   //
00201   int    trackD0Bin = conf_.getParameter<int>   ("trackD0Bin");
00202   double trackD0Min = conf_.getParameter<double>("trackD0Min");
00203   double trackD0Max = conf_.getParameter<double>("trackD0Max");
00204  
00205   histname = "trackD0_";
00206   trackD0 = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, trackD0Bin, trackD0Min, trackD0Max);
00207   trackD0->setAxisTitle("");
00208   
00209   //
00210   int    trackCompatibleLayersBin = conf_.getParameter<int>   ("trackCompatibleLayersBin");
00211   double trackCompatibleLayersMin = conf_.getParameter<double>("trackCompatibleLayersMin");
00212   double trackCompatibleLayersMax = conf_.getParameter<double>("trackCompatibleLayersMax");
00213  
00214   histname = "trackCompatibleLayers_";
00215   trackCompatibleLayers = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, trackCompatibleLayersBin, trackCompatibleLayersMin, trackCompatibleLayersMax);
00216   trackCompatibleLayers->setAxisTitle("");
00217 
00218   //------------------------------------------------------------------------------------
00219  
00220   //
00221   int    deltaXBin = conf_.getParameter<int>   ("deltaXBin");
00222   double deltaXMin = conf_.getParameter<double>("deltaXMin");
00223   double deltaXMax = conf_.getParameter<double>("deltaXMax");
00224  
00225   histname = "deltaX_";
00226   deltaX = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, deltaXBin, deltaXMin, deltaXMax);
00227   deltaX->setAxisTitle("");
00228   
00229   //
00230   int    deltaYBin = conf_.getParameter<int>   ("deltaYBin");
00231   double deltaYMin = conf_.getParameter<double>("deltaYMin");
00232   double deltaYMax = conf_.getParameter<double>("deltaYMax");
00233  
00234   histname = "deltaY_";
00235   deltaY = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, deltaYBin, deltaYMin, deltaYMax);
00236   deltaY->setAxisTitle("");
00237   
00238   //
00239   int    signDeltaXBin = conf_.getParameter<int>   ("signDeltaXBin");
00240   double signDeltaXMin = conf_.getParameter<double>("signDeltaXMin");
00241   double signDeltaXMax = conf_.getParameter<double>("signDeltaXMax");
00242  
00243   histname = "signDeltaX_";
00244   signDeltaX = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, signDeltaXBin, signDeltaXMin, signDeltaXMax);
00245   signDeltaX->setAxisTitle("");
00246   
00247   //
00248   int    signDeltaYBin = conf_.getParameter<int>   ("signDeltaYBin");
00249   double signDeltaYMin = conf_.getParameter<double>("signDeltaYMin");
00250   double signDeltaYMax = conf_.getParameter<double>("signDeltaYMax");
00251  
00252   histname = "signDeltaY_";
00253   signDeltaY = dqmStore_->book1D(histname+AlgoName, histname+AlgoName, signDeltaYBin, signDeltaYMin, signDeltaYMax);
00254   signDeltaY->setAxisTitle("");
00255   
00256 }
00257 
00258 
00259 
00260 //-----------------------------------------------------------------------------------
00261 void TrackEfficiencyMonitor::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) 
00262 //-----------------------------------------------------------------------------------
00263 {
00264    
00265   using namespace edm;
00266 
00267   edm::Handle<reco::TrackCollection> tkTracks;
00268   iEvent.getByLabel(theTKTracksLabel_, tkTracks);
00269   edm::Handle<reco::TrackCollection> staTracks;
00270   iEvent.getByLabel(theSTATracksLabel_, staTracks);
00271   edm::ESHandle<NavigationSchool> nav;
00272   iSetup.get<NavigationSchoolRecord>().get("CosmicNavigationSchool", nav); 
00273   NavigationSetter setter(*nav.product());
00274   iSetup.get<CkfComponentsRecord>().get(measurementTrackerHandle);
00275  
00276   nCompatibleLayers = 0; 
00277   
00278   iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theTTrackBuilder);
00279   iSetup.get<TrackingComponentsRecord>().get("SteppingHelixPropagatorAny",thePropagator);
00280   iSetup.get<IdealMagneticFieldRecord>().get(bField); 
00281   iSetup.get<TrackerRecoGeometryRecord>().get(theTracker);
00282   theNavigation = new DirectTrackerNavigation(theTracker);
00283   
00284   
00285   if(trackEfficiency_){
00286   //---------------------------------------------------
00287   // Select muons with good quality
00288   // If B field is on, no up-down matching between the muons
00289   //---------------------------------------------------  
00290   bool isGoodMuon = false;
00291   double mudd0 = 0., mudphi = 0., muddsz = 0., mudeta = 0.;
00292   if(isBFieldOff_)
00293   {
00294     if ( staTracks->size() == 2 )
00295     {
00296       for ( unsigned int bindex = 0; bindex < staTracks->size(); ++bindex ) 
00297       {
00298         
00299         if (0 == bindex){
00300            mudd0+=(*staTracks)[bindex].d0(); 
00301            mudphi+=(*staTracks)[bindex].phi();
00302            muddsz+=(*staTracks)[bindex].dsz(); 
00303            mudeta+=(*staTracks)[bindex].eta();}
00304         if (1 == bindex){
00305            mudd0-=(*staTracks)[bindex].d0(); 
00306            mudphi-=(*staTracks)[bindex].phi();
00307            muddsz-=(*staTracks)[bindex].dsz(); 
00308            mudeta-=(*staTracks)[bindex].eta();}
00309        }
00310       if ((fabs(mudd0)<15.0)&&(fabs(mudphi)<0.045)&&(fabs(muddsz)<20.0)&&(fabs(mudeta)<0.060))  isGoodMuon = true;
00311      }
00312      
00313     if(isGoodMuon) testTrackerTracks(tkTracks,staTracks);
00314   
00315   }
00316   else if ( staTracks->size() == 1 || staTracks->size() == 2) testTrackerTracks(tkTracks,staTracks);
00317   }
00318   
00319   
00320   if(!trackEfficiency_ && tkTracks->size() == 1 ){
00321     if( (tkTracks->front()).normalizedChi2() < 5 &&
00322     (tkTracks->front()).hitPattern().numberOfValidHits() > 8)
00323      testSTATracks(tkTracks,staTracks);  
00324   }
00325   
00326   
00327   delete theNavigation;
00328    
00329 }
00330 
00331 
00332 
00333 //-----------------------------------------------------------------------------------
00334 void TrackEfficiencyMonitor::endJob(void) 
00335 //-----------------------------------------------------------------------------------
00336 { 
00337   bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
00338   std::string outputFileName = conf_.getParameter<std::string>("OutputFileName");
00339   if(outputMEsInRootFile){
00340     dqmStore_->showDirStructure(); 
00341     dqmStore_->save(outputFileName); 
00342     }
00343 
00344   //if ( theNavigation ) delete theNavigation; 
00345 
00346 }
00347 
00348 
00349 
00350 //-----------------------------------------------------------------------------------
00351 void TrackEfficiencyMonitor::testTrackerTracks(Handle<reco::TrackCollection> tkTracks, Handle<reco::TrackCollection> staTracks)
00352 //-----------------------------------------------------------------------------------
00353 {
00354   
00355   const std::string metname = "testStandAloneMuonTracks";
00356 
00357   //---------------------------------------------------
00358   // get the index of the "up" muon
00359   // histograms will only be computed for the "up" muon
00360   //---------------------------------------------------
00361  
00362   int nUpMuon = 0;
00363   int idxUpMuon = -1;
00364   for(unsigned int i =0; i< staTracks->size(); i++){
00365      if( checkSemiCylinder((*staTracks)[i]) == TrackEfficiencyMonitor::Up ){
00366         nUpMuon++;
00367         idxUpMuon = i;
00368      }
00369   }
00370     
00371    
00372   if( nUpMuon == 1)
00373   {
00374     
00375     //---------------------------------------------------
00376     //get the muon informations
00377     //---------------------------------------------------
00378     
00379     reco::TransientTrack staTT = theTTrackBuilder->build((*staTracks)[idxUpMuon]);
00380     double ipX   = staTT.impactPointState().globalPosition().x();
00381     double ipY   = staTT.impactPointState().globalPosition().y();
00382     double ipZ   = staTT.impactPointState().globalPosition().z();
00383     double eta   = staTT.impactPointState().globalDirection().eta();
00384     double phi   = staTT.impactPointState().globalDirection().phi();
00385     double d0    = (*staTracks)[idxUpMuon].d0();
00386     
00387     TrajectoryStateOnSurface theTSOS = staTT.outermostMeasurementState(); 
00388     TrajectoryStateOnSurface theTSOSCompLayers = staTT.outermostMeasurementState(); 
00389     
00390     
00391     //---------------------------------------------------
00392     //check if the muon is in the tracker acceptance
00393     //---------------------------------------------------    
00394     bool isInTrackerAcceptance = false;   
00395     isInTrackerAcceptance = trackerAcceptance( theTSOS, theRadius_ , theMaxZ_ );
00396     
00397     //---------------------------------------------------st
00398     //count the number of compatible layers
00399     //---------------------------------------------------       
00400     nCompatibleLayers = compatibleLayers(theTSOSCompLayers);
00401     
00402     if(isInTrackerAcceptance && (*staTracks)[idxUpMuon].hitPattern().numberOfValidHits() > 28)
00403     {
00404       //---------------------------------------------------
00405       //count the number of good muon candidates
00406       //---------------------------------------------------   
00407         
00408       TrajectoryStateOnSurface staState;      
00409       LocalVector diffLocal;   
00410      
00411          
00412       bool isTrack = false;
00413       if(!tkTracks->empty())
00414       {
00415        //---------------------------------------------------   
00416        //look for associated tracks
00417        //---------------------------------------------------   
00418         float DR2min = 1000;
00419         reco::TrackCollection::const_iterator closestTrk = tkTracks->end();
00420 
00421        for(reco::TrackCollection::const_iterator tkTrack = tkTracks->begin(); tkTrack != tkTracks->end(); ++tkTrack)
00422        {
00423           reco::TransientTrack tkTT = theTTrackBuilder->build(*tkTrack);
00424           TrajectoryStateOnSurface tkInner = tkTT.innermostMeasurementState();
00425           staState = thePropagator->propagate(staTT.outermostMeasurementState(),tkInner.surface());      
00426           failedToPropagate = 1;
00427             
00428           if(staState.isValid())
00429           {
00430             failedToPropagate = 0;
00431             diffLocal = tkInner.localPosition() - staState.localPosition();
00432             double DR2 = diffLocal.x()*diffLocal.x()+diffLocal.y()*diffLocal.y();
00433             if (DR2<DR2min) { DR2min = DR2; closestTrk = tkTrack;}
00434             if ( pow(DR2,0.5) < 100. ) isTrack = true;
00435             }
00436           }
00437          
00438           
00439           if (DR2min != 1000) 
00440           { 
00441             
00442             reco::TransientTrack tkTT = theTTrackBuilder->build(*closestTrk);
00443             TrajectoryStateOnSurface tkInner = tkTT.innermostMeasurementState();
00444             staState = thePropagator->propagate(staTT.outermostMeasurementState(),tkInner.surface());
00445             deltaX->Fill(diffLocal.x());
00446             deltaY->Fill(diffLocal.y());
00447             signDeltaX->Fill(diffLocal.x()/(tkInner.localError().positionError().xx() + staState.localError().positionError().xx()));
00448             signDeltaY->Fill(diffLocal.y()/(tkInner.localError().positionError().yy() + staState.localError().positionError().yy()));
00449                    
00450            } 
00451         }
00452       
00453       
00454       if(failedToPropagate == 0)
00455       {       
00456          muonX->Fill(ipX);
00457          muonY->Fill(ipY);
00458          muonZ->Fill(ipZ);
00459          muonEta->Fill(eta);
00460          muonPhi->Fill(phi);
00461          muonD0->Fill(d0);
00462          muonCompatibleLayers->Fill(nCompatibleLayers);
00463 
00464          if(isTrack)
00465          { 
00466             trackX->Fill(ipX);
00467             trackY->Fill(ipY);
00468             trackZ->Fill(ipZ);
00469             trackEta->Fill(eta);
00470             trackPhi->Fill(phi);
00471             trackD0->Fill(d0);
00472             trackCompatibleLayers->Fill(nCompatibleLayers);
00473           }     
00474         }
00475      }
00476    }
00477     
00478 }
00479 
00480 
00481 
00482 
00483 
00484 
00485 
00486 
00487 
00488 
00489 
00490 //-----------------------------------------------------------------------------------
00491 void TrackEfficiencyMonitor::testSTATracks(Handle<reco::TrackCollection> tkTracks, Handle<reco::TrackCollection> staTracks)
00492 //-----------------------------------------------------------------------------------
00493 {
00494 
00495    
00496    reco::TransientTrack tkTT = theTTrackBuilder->build(tkTracks->front());
00497    double ipX   = tkTT.impactPointState().globalPosition().x();
00498    double ipY   = tkTT.impactPointState().globalPosition().y();
00499    double ipZ   = tkTT.impactPointState().globalPosition().z();
00500    double eta   = tkTT.impactPointState().globalDirection().eta();
00501    double phi   = tkTT.impactPointState().globalDirection().phi();
00502    double d0    = (*tkTracks)[0].d0();
00503 
00504    TrajectoryStateOnSurface tkInner = tkTT.innermostMeasurementState();
00505    LocalVector diffLocal;   
00506    TrajectoryStateOnSurface staState;      
00507    bool isTrack = false;
00508    
00509    
00510    if(!staTracks->empty()){     
00511         
00512        //---------------------------------------------------   
00513        //look for associated muons
00514        //---------------------------------------------------   
00515        
00516     float DR2min = 1000;
00517     reco::TrackCollection::const_iterator closestTrk = staTracks->end();
00518        //----------------------loop on tracker tracks:
00519     for(reco::TrackCollection::const_iterator staTrack = staTracks->begin(); staTrack != staTracks->end(); ++staTrack){
00520       if(checkSemiCylinder(*staTrack) == TrackEfficiencyMonitor::Up){
00521       
00522         reco::TransientTrack staTT = theTTrackBuilder->build(*staTrack); 
00523         failedToPropagate = 1;  
00524         staState = thePropagator->propagate(staTT.outermostMeasurementState(),tkInner.surface());       
00525 
00526        
00527           if(staState.isValid())
00528           {
00529             failedToPropagate = 0;
00530             diffLocal = tkInner.localPosition() - staState.localPosition();
00531                
00532             double DR2 = diffLocal.x()*diffLocal.x()+diffLocal.y()*diffLocal.y();
00533             if (DR2<DR2min) { DR2min = DR2; closestTrk = staTrack;}
00534             if ( pow(DR2,0.5) < 100. ) isTrack = true;
00535            }
00536           }     
00537       }
00538     }
00539    
00540    if(failedToPropagate == 0)
00541       {         
00542          
00543          trackX->Fill(ipX);
00544          trackY->Fill(ipY);
00545          trackZ->Fill(ipZ);
00546          trackEta->Fill(eta);
00547          trackPhi->Fill(phi);
00548          trackD0->Fill(d0);
00549 
00550          if(isTrack)
00551          { 
00552             muonX->Fill(ipX);
00553             muonY->Fill(ipY);
00554             muonZ->Fill(ipZ);
00555             muonEta->Fill(eta);
00556             muonPhi->Fill(phi);
00557             muonD0->Fill(d0);
00558           }     
00559         }
00560 
00561 
00562 
00563 }
00564 
00565 
00566 
00567 
00568 
00569 
00570 
00571 
00572 
00573 
00574 
00575 
00576 
00577 
00578 
00579 
00580 
00581 //-----------------------------------------------------------------------------------
00582 TrackEfficiencyMonitor::SemiCylinder TrackEfficiencyMonitor::checkSemiCylinder(const reco::Track& tk)
00583 //-----------------------------------------------------------------------------------
00584 {
00585   return tk.innerPosition().phi() > 0 ? TrackEfficiencyMonitor::Up : TrackEfficiencyMonitor::Down;
00586 }
00587 
00588   
00589   
00590 //-----------------------------------------------------------------------------------
00591 bool TrackEfficiencyMonitor::trackerAcceptance( TrajectoryStateOnSurface theTSOS, double theRadius, double theMaxZ)
00592 //-----------------------------------------------------------------------------------
00593 {
00594 
00595   //---------------------------------------------------  
00596   // check if the muon is in the tracker acceptance    
00597   // check the compatibility with a cylinder of radius "theRadius"
00598   //---------------------------------------------------   
00599       
00600   //Propagator*  theTmpPropagator = new SteppingHelixPropagator(&*bField,anyDirection);
00601   
00602   //Propagator*  theTmpPropagator = &*thePropagator;
00603   Propagator* theTmpPropagator = &*thePropagator->clone();
00604   
00605   if (theTSOS.globalPosition().y() <0 ) theTmpPropagator->setPropagationDirection(oppositeToMomentum);
00606   else                                  theTmpPropagator->setPropagationDirection(alongMomentum);
00607   
00608   Cylinder::PositionType pos0;
00609   Cylinder::RotationType rot0;
00610   const Cylinder::CylinderPointer cyl = Cylinder::build(pos0, rot0, theRadius);
00611   TrajectoryStateOnSurface tsosAtCyl  = theTmpPropagator->propagate(*theTSOS.freeState(), *cyl);  
00612   double accept = false;
00613   if ( tsosAtCyl.isValid() ) {
00614     if (fabs(tsosAtCyl.globalPosition().z())<theMaxZ ) {
00615       Cylinder::PositionType pos02;
00616       Cylinder::RotationType rot02;
00617       const Cylinder::CylinderPointer cyl2 = Cylinder::build(pos02, rot02, theRadius -10);
00618       TrajectoryStateOnSurface tsosAtCyl2 = theTmpPropagator->propagate(*tsosAtCyl.freeState(), *cyl2);
00619       if ( tsosAtCyl2.isValid() ) {
00620         Cylinder::PositionType pos03;
00621         Cylinder::RotationType rot03;
00622         const Cylinder::CylinderPointer cyl3 = Cylinder::build(pos03, rot03, theRadius );
00623         TrajectoryStateOnSurface tsosAtCyl3 = theTmpPropagator->propagate(*tsosAtCyl2.freeState(), *cyl3);
00624         if ( tsosAtCyl3.isValid() ) {
00625           accept=true;
00626         }
00627       }
00628       
00629     }
00630   }
00631   delete theTmpPropagator;
00632   //muon propagated to the barrel cylinder
00633   return accept;
00634 
00635 }
00636 
00637 
00638 
00639 //-----------------------------------------------------------------------------------
00640 int TrackEfficiencyMonitor::compatibleLayers( TrajectoryStateOnSurface theTSOS)
00641 //-----------------------------------------------------------------------------------
00642 {  
00643   //---------------------------------------------------   
00644   // check the number of compatible layers
00645   //---------------------------------------------------   
00646   
00647   std::vector< BarrelDetLayer*> barrelTOBLayers = measurementTrackerHandle->geometricSearchTracker()->tobLayers() ;
00648   
00649   unsigned int layers = 0;
00650   for ( unsigned int k=0 ; k < barrelTOBLayers.size() ; k++ ) 
00651   {  
00652     const DetLayer* firstLay = barrelTOBLayers[barrelTOBLayers.size() -1 - k];  
00653     
00654     //Propagator*  theTmpPropagator = new SteppingHelixPropagator(&*bField,anyDirection);
00655     
00656     
00657     
00658     Propagator* theTmpPropagator = &*thePropagator->clone();
00659     theTmpPropagator->setPropagationDirection(alongMomentum); 
00660     
00661     TrajectoryStateOnSurface startTSOS = theTmpPropagator->propagate(*theTSOS.freeState(),firstLay->surface());
00662     
00663     std::vector< const DetLayer*> trackCompatibleLayers;
00664     
00665     findDetLayer      = true;
00666     bool isUpMuon     = false;
00667     bool firstdtep    = true; 
00668     
00669     if(startTSOS.isValid())
00670     {
00671       
00672       if(firstdtep) layers++; 
00673       
00674       int nwhile = 0;
00675       
00676       //for other compatible layers 
00677       while ( startTSOS.isValid() &&  firstLay && findDetLayer)
00678       {
00679         
00680         if(firstdtep && startTSOS.globalPosition().y()> 0) isUpMuon = true;
00681         
00682         if(firstdtep){
00683           std::vector< const DetLayer*> firstCompatibleLayers;
00684           firstCompatibleLayers.push_back(firstLay);
00685           std::pair<TrajectoryStateOnSurface, const  DetLayer* > nextLayer = findNextLayer(theTSOS, firstCompatibleLayers, isUpMuon );
00686           firstdtep = false;
00687         }
00688         else{
00689           trackCompatibleLayers =  firstLay->nextLayers(*(startTSOS.freeState()),alongMomentum);
00690           std::pair<TrajectoryStateOnSurface, const  DetLayer* > nextLayer = findNextLayer(startTSOS, trackCompatibleLayers, isUpMuon );
00691           if(trackCompatibleLayers.size()!=0  && firstLay != nextLayer.second ){
00692             firstLay  = nextLayer.second;
00693             startTSOS = nextLayer.first;
00694             layers++;         
00695           }
00696           else firstLay=0;
00697         }
00698         nwhile++;
00699         if(nwhile > 100) break;
00700                 
00701       }
00702       delete theTmpPropagator;
00703       break;
00704     }
00705     delete theTmpPropagator;
00706   }
00707   return layers;
00708   
00709 }
00710 
00711 
00712 
00713 
00714 //-----------------------------------------------------------------------------------
00715 std::pair<TrajectoryStateOnSurface,  const DetLayer*>  TrackEfficiencyMonitor::findNextLayer( TrajectoryStateOnSurface sTSOS, std::vector< const DetLayer*> trackCompatibleLayers , bool isUpMuon )
00716 //-----------------------------------------------------------------------------------
00717 {
00718   
00719   //Propagator*  theTmpPropagator = new SteppingHelixPropagator(&*bField,anyDirection);
00720   
00721   
00722   Propagator* theTmpPropagator = &*thePropagator->clone();
00723   theTmpPropagator->setPropagationDirection(alongMomentum); 
00724   
00725   
00726   std::vector<const DetLayer*>::iterator itl;
00727   findDetLayer = false;
00728   for (itl=trackCompatibleLayers.begin();itl!=trackCompatibleLayers.end();++itl) {
00729     TrajectoryStateOnSurface tsos = theTmpPropagator->propagate(*(sTSOS.freeState()),(**itl).surface());
00730     if (tsos.isValid()) 
00731     {
00732       sTSOS = tsos;
00733       findDetLayer = true; 
00734       
00735       break;
00736     }
00737   }
00738   std::pair<TrajectoryStateOnSurface,  const DetLayer* >  blabla;
00739   blabla.first = sTSOS;
00740   blabla.second = &**itl;
00741   delete theTmpPropagator;
00742   return blabla;
00743 }
00744 
00745 
00746 DEFINE_FWK_MODULE(TrackEfficiencyMonitor);

Generated on Tue Jun 9 17:33:43 2009 for CMSSW by  doxygen 1.5.4