CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/Validation/RecoHI/plugins/HitPixelLayersTPSelector.h

Go to the documentation of this file.
00001 #ifndef HitPixelLayersTrackSelection_h
00002 #define HitPixelLayersTrackSelection_h
00003 
00004 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
00005 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
00006 
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00009 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00010 
00018 class HitPixelLayersTPSelector
00019 {
00020   
00021  public:
00022   // input collection type
00023   typedef TrackingParticleCollection collection;
00024   
00025   
00026   // output collection type
00027   typedef std::vector<const TrackingParticle*> container;
00028   
00029   // iterator over result collection type.
00030   typedef container::const_iterator const_iterator;
00031   
00032   // constructor from parameter set configurability
00033   HitPixelLayersTPSelector(const edm::ParameterSet & iConfig) : 
00034     tripletSeedOnly_(iConfig.getParameter<bool>("tripletSeedOnly")),
00035     ptMin_(iConfig.getParameter<double>("ptMin")), 
00036     minRapidity_(iConfig.getParameter<double>("minRapidity")), 
00037     maxRapidity_(iConfig.getParameter<double>("maxRapidity")),
00038     tip_(iConfig.getParameter<double>("tip")), 
00039     lip_(iConfig.getParameter<double>("lip")), 
00040     minHit_(iConfig.getParameter<int>("minHit")), 
00041     signalOnly_(iConfig.getParameter<bool>("signalOnly")), 
00042     chargedOnly_(iConfig.getParameter<bool>("chargedOnly")), 
00043     primaryOnly_(iConfig.getParameter<bool>("primaryOnly")),
00044     tpStatusBased_(iConfig.getParameter<bool>("tpStatusBased")),
00045     pdgId_(iConfig.getParameter< std::vector<int> >("pdgId"))                              
00046       {};
00047     
00048     // select object from a collection and
00049     // possibly event content
00050     void select( const edm::Handle<collection> & TPCH, const edm::Event & iEvent, const edm::EventSetup & iSetup)
00051     {
00052       selected_.clear();
00053       //Retrieve tracker topology from geometry
00054       edm::ESHandle<TrackerTopology> tTopoHand;
00055       iSetup.get<IdealGeometryRecord>().get(tTopoHand);
00056       const TrackerTopology *tTopo=tTopoHand.product();
00057       
00058 
00059       const collection & tpc = *(TPCH.product());
00060       
00061       for (TrackingParticleCollection::size_type i=0; i<tpc.size(); i++)
00062         {
00063           TrackingParticleRef tpr(TPCH, i);
00064           
00065           // quickly reject if it is from pile-up
00066           if (signalOnly_ && !(tpr->eventId().bunchCrossing()==0 && tpr->eventId().event()==0) ) continue;
00067           if (chargedOnly_ && tpr->charge()==0) continue; //select only if charge!=0
00068           if (tpStatusBased_ && primaryOnly_ && tpr->status()!=1 ) continue; // TP status based sel primary
00069           if ((!tpStatusBased_) && primaryOnly_ && tpr->parentVertex()->nSourceTracks()!=0 ) continue; // vertex based sel for primary
00070 
00071           // loop over specified PID values 
00072           bool testId = false;
00073           unsigned int idSize = pdgId_.size();
00074           if (idSize==0) testId = true;
00075           else for (unsigned int it=0;it!=idSize;++it){
00076             if (tpr->pdgId()==pdgId_[it]) testId = true;
00077           }
00078           
00079           // selection criteria
00080           if ( tpr->numberOfTrackerLayers() >= minHit_ &&   
00081                sqrt(tpr->momentum().perp2()) >= ptMin_ && 
00082                tpr->momentum().eta() >= minRapidity_ && tpr->momentum().eta() <= maxRapidity_ && 
00083                sqrt(tpr->vertex().perp2()) <= tip_ &&
00084                fabs(tpr->vertex().z()) <= lip_ &&
00085                testId)
00086             {
00087               if (tripletSeedOnly_ && !goodHitPattern(pixelHitPattern(tpr,tTopo)) ) continue; //findable triplet seed
00088               const TrackingParticle * trap = &(tpc[i]);
00089               selected_.push_back(trap);
00090             } 
00091           
00092         }
00093     }
00094     
00095     // return pixel layer hit pattern
00096     std::vector<bool> pixelHitPattern( const TrackingParticleRef& simTrack, const TrackerTopology *tTopo )
00097       {
00098         std::vector<bool> hitpattern(5,false); // PXB 0,1,2  PXF 0,1
00099         
00100 #warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
00101 #ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
00102         for(std::vector<PSimHit>::const_iterator simHit = simTrack->pSimHit_begin();simHit!= simTrack->pSimHit_end();simHit++){
00103           
00104           DetId id = DetId(simHit->detUnitId());
00105           uint32_t detid = id.det();
00106           uint32_t subdet = id.subdetId();
00107           
00108           if (detid == DetId::Tracker) {
00109             if (subdet == PixelSubdetector::PixelBarrel) 
00110               hitpattern[tTopo->pxbLayer(id)-1]=true;
00111             else if (subdet == PixelSubdetector::PixelEndcap) 
00112               hitpattern[tTopo->pxfDisk(id)+2]=true;
00113           }
00114           
00115         }// end simhit loop
00116 #endif
00117         
00118         return hitpattern;
00119       }
00120     
00121     // test whether hit pattern would give a pixel triplet seed
00122     bool goodHitPattern( const std::vector<bool>& hitpattern )
00123     {
00124       if( (hitpattern[0] && hitpattern[1] && hitpattern[2]) ||
00125           (hitpattern[0] && hitpattern[1] && hitpattern[3]) ||
00126           (hitpattern[0] && hitpattern[3] && hitpattern[4]) ) 
00127         return true;
00128       else 
00129         return false;
00130     }
00131     
00132     // iterators over selected objects: collection begin
00133     const_iterator begin() const
00134     {
00135       return selected_.begin();
00136     }
00137     
00138     // iterators over selected objects: collection end
00139     const_iterator end() const
00140     {
00141       return selected_.end();
00142     }
00143     
00144     // true if no object has been selected
00145     size_t size() const
00146     {
00147       return selected_.size();
00148     }
00149     
00150     //private:
00151     
00152     container selected_;
00153     bool tripletSeedOnly_;
00154     double ptMin_;
00155     double minRapidity_;
00156     double maxRapidity_;
00157     double tip_;
00158     double lip_;
00159     int    minHit_;
00160     bool signalOnly_;
00161     bool chargedOnly_;
00162     bool primaryOnly_;
00163     bool tpStatusBased_;
00164     std::vector<int> pdgId_;
00165     
00166     
00167 };
00168 
00169 
00170 #endif