CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CosmicTrackingParticleSelector.h
Go to the documentation of this file.
1 #ifndef RecoSelectors_CosmicTrackingParticleSelector_h
2 #define RecoSelectors_CosmicTrackingParticleSelector_h
3 /* \class CosmicTrackingParticleSelector
4  *
5  * \author Yanyan Gao, FNAL
6  *
7  * $Date: 2013/06/24 12:25:14 $
8  * $Revision: 1.5 $
9  *
10  */
21 
29 
32 
34 
36 
37 public:
39  typedef std::vector<const TrackingParticle *> container;
40  typedef container::const_iterator const_iterator;
41 
43 
44  CosmicTrackingParticleSelector ( double ptMin,double minRapidity,double maxRapidity,
45  double tip,double lip,int minHit, bool chargedOnly,
46  std::vector<int> pdgId = std::vector<int>()) :
47  ptMin_( ptMin ), minRapidity_( minRapidity ), maxRapidity_( maxRapidity ),
48  tip_( tip ), lip_( lip ), minHit_( minHit ), chargedOnly_(chargedOnly), pdgId_( pdgId ) { }
49 
50 
52  ptMin_(cfg.getParameter<double>("ptMin")),
53  minRapidity_(cfg.getParameter<double>("minRapidity")),
54  maxRapidity_(cfg.getParameter<double>("maxRapidity")),
55  tip_(cfg.getParameter<double>("tip")),
56  lip_(cfg.getParameter<double>("lip")),
57  minHit_(cfg.getParameter<int>("minHit")),
58  chargedOnly_(cfg.getParameter<bool>("chargedOnly")),
59  pdgId_(cfg.getParameter<std::vector<int> >("pdgId")) { }
60 
61 
63  selected_.clear();
65  event.getByLabel(edm::InputTag("offlineBeamSpot"), beamSpot);
66  for( TrackingParticleCollection::const_iterator itp = c->begin();
67  itp != c->end(); ++ itp )
68  if ( operator()(TrackingParticleRef(c,itp-c->begin()),beamSpot.product(),event,setup) ) {
69  selected_.push_back( & * itp );
70  }
71  }
72 
73  const_iterator begin() const { return selected_.begin(); }
74  const_iterator end() const { return selected_.end(); }
75 
77  simHitsTPAssoc = simHitsTPAssocToSet;
78  }
79 
80  // Operator() performs the selection: e.g. if (tPSelector(tp, bs, event, evtsetup)) {...
81  bool operator()( const TrackingParticleRef tpr, const reco::BeamSpot* bs, const edm::Event &iEvent, const edm::EventSetup& iSetup ) const {
82  if (chargedOnly_ && tpr->charge()==0) return false;//select only if charge!=0
83  //bool testId = false;
84  //unsigned int idSize = pdgId_.size();
85  //if (idSize==0) testId = true;
86  //else for (unsigned int it=0;it!=idSize;++it){
87  //if (tpr->pdgId()==pdgId_[it]) testId = true;
88  //}
89 
91  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
92 
94  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
95 
96  GlobalVector finalGV (0,0,0);
97  GlobalPoint finalGP(0,0,0);
98  GlobalVector momentum(0,0,0);//At the PCA
99  GlobalPoint vertex(0,0,0);//At the PCA
100  double radius(9999);
101  bool found(0);
102 
103 
104  if (simHitsTPAssoc.isValid()==0) {
105  edm::LogError("TrackAssociation") << "Invalid handle!";
106  return false;
107  }
108  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(tpr,TrackPSimHitRef());//SimHit is dummy: for simHitTPAssociationListGreater
109  // sorting only the cluster is needed
110  auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
112  for(auto ip = range.first; ip != range.second; ++ip) {
113  TrackPSimHitRef it = ip->second;
114  const GeomDet* tmpDet = tracker->idToDet( DetId(it->detUnitId()) ) ;
115  LocalVector lv = it->momentumAtEntry();
116  Local3DPoint lp = it->localPosition ();
117  GlobalVector gv = tmpDet->surface().toGlobal( lv );
118  GlobalPoint gp = tmpDet->surface().toGlobal( lp );
119  if(gp.perp()<radius){
120  found=true;
121  radius = gp.perp();
122  finalGV = gv;
123  finalGP = gp;
124  }
125  }
126  if(!found) return 0;
127  else
128  {
129  FreeTrajectoryState ftsAtProduction(finalGP,finalGV,TrackCharge(tpr->charge()),theMF.product());
130  TSCBLBuilderNoMaterial tscblBuilder;
131  TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,*bs);//as in TrackProducerAlgorithm
132  if(!tsAtClosestApproach.isValid()){
133  std::cout << "WARNING: tsAtClosestApproach is not valid" << std::endl;
134  return 0;
135  }
136  else
137  {
138  momentum = tsAtClosestApproach.trackStateAtPCA().momentum();
139  vertex = tsAtClosestApproach.trackStateAtPCA().position();
140  return (
141  tpr->numberOfTrackerLayers() >= minHit_ &&
142  sqrt(momentum.perp2()) >= ptMin_ &&
143  momentum.eta() >= minRapidity_ && momentum.eta() <= maxRapidity_ &&
144  sqrt(vertex.perp2()) <= tip_ &&
145  fabs(vertex.z()) <= lip_
146  );
147  }
148  }
149  }
150 
151  size_t size() const { return selected_.size(); }
152 
153  private:
154 
155  double ptMin_;
156  double minRapidity_;
157  double maxRapidity_;
158  double tip_;
159  double lip_;
160  int minHit_;
162  std::vector<int> pdgId_;
164 
166 
167 };
168 
169 #endif
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
T perp() const
Definition: PV3DBase.h:72
std::vector< TrackingParticle > TrackingParticleCollection
static bool simHitTPAssociationListGreater(SimHitTPPair i, SimHitTPPair j)
void select(const edm::Handle< collection > &c, const edm::Event &event, const edm::EventSetup &setup)
T perp2() const
Definition: PV3DBase.h:71
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
bool operator()(const TrackingParticleRef tpr, const reco::BeamSpot *bs, const edm::Event &iEvent, const edm::EventSetup &iSetup) const
CosmicTrackingParticleSelector(double ptMin, double minRapidity, double maxRapidity, double tip, double lip, int minHit, bool chargedOnly, std::vector< int > pdgId=std::vector< int >())
CosmicTrackingParticleSelector(const edm::ParameterSet &cfg)
int TrackCharge
Definition: TrackCharge.h:4
int iEvent
Definition: GenABIO.cc:243
T sqrt(T t)
Definition: SSEVec.h:48
T z() const
Definition: PV3DBase.h:64
std::vector< const TrackingParticle * > container
void initEvent(edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssocToSet) const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool isValid() const
Definition: HandleBase.h:76
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc
GlobalVector momentum() const
Definition: DetId.h:20
GlobalPoint position() const
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:74
T eta() const
Definition: PV3DBase.h:76
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
tuple cout
Definition: gather_cfg.py:121
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::Ref< TrackingParticleCollection > TrackingParticleRef