test
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  */
22 
27 
33 
36 
38 
40 
41 public:
43  typedef std::vector<const TrackingParticle *> container;
44  typedef container::const_iterator const_iterator;
45 
47 
49  double tip,double lip,int minHit, bool chargedOnly,
50  const std::vector<int>& pdgId = std::vector<int>()) :
51  ptMin_( ptMin ), minRapidity_( minRapidity ), maxRapidity_( maxRapidity ),
52  tip_( tip ), lip_( lip ), minHit_( minHit ), chargedOnly_(chargedOnly), pdgId_( pdgId ) { }
53 
54 
56  ptMin_(cfg.getParameter<double>("ptMin")),
57  minRapidity_(cfg.getParameter<double>("minRapidity")),
58  maxRapidity_(cfg.getParameter<double>("maxRapidity")),
59  tip_(cfg.getParameter<double>("tip")),
60  lip_(cfg.getParameter<double>("lip")),
61  minHit_(cfg.getParameter<int>("minHit")),
62  chargedOnly_(cfg.getParameter<bool>("chargedOnly")),
63  pdgId_(cfg.getParameter<std::vector<int> >("pdgId")),
64  beamSpotToken_(iC.consumes<reco::BeamSpot>(edm::InputTag("offlineBeamSpot"))) { }
65 
66 
68  selected_.clear();
70  event.getByToken(beamSpotToken_, beamSpot);
71  for( TrackingParticleCollection::const_iterator itp = c->begin();
72  itp != c->end(); ++ itp )
73  if ( operator()(TrackingParticleRef(c,itp-c->begin()),beamSpot.product(),event,setup) ) {
74  selected_.push_back( & * itp );
75  }
76  }
77 
78  const_iterator begin() const { return selected_.begin(); }
79  const_iterator end() const { return selected_.end(); }
80 
82  simHitsTPAssoc = simHitsTPAssocToSet;
83  }
84 
85  // Operator() performs the selection: e.g. if (tPSelector(tp, bs, event, evtsetup)) {...
86  bool operator()( const TrackingParticleRef tpr, const reco::BeamSpot* bs, const edm::Event &iEvent, const edm::EventSetup& iSetup ) const {
87  if (chargedOnly_ && tpr->charge()==0) return false;//select only if charge!=0
88  //bool testId = false;
89  //unsigned int idSize = pdgId_.size();
90  //if (idSize==0) testId = true;
91  //else for (unsigned int it=0;it!=idSize;++it){
92  //if (tpr->pdgId()==pdgId_[it]) testId = true;
93  //}
94 
96  iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
98  iSetup.get<GlobalTrackingGeometryRecord>().get(theGeometry);
99 
101  iSetup.get<IdealMagneticFieldRecord>().get(theMF);
102 
103  GlobalVector finalGV (0,0,0);
104  GlobalPoint finalGP(0,0,0);
105  GlobalVector momentum(0,0,0);//At the PCA
106  GlobalPoint vertex(0,0,0);//At the PCA
107  double radius(9999);
108  bool found(0);
109 
110  int ii=0;
111  DetId::Detector det;
112  int subdet;
113 
114  edm::LogVerbatim("CosmicTrackingParticleSelector")
115  <<"TOT Number of PSimHits = "<< tpr->numberOfHits() << ", Number of Tracker PSimHits = "<< tpr->numberOfTrackerHits() <<"\n";
116 
117  if (simHitsTPAssoc.isValid()==0) {
118  edm::LogError("CosmicTrackingParticleSelector") << "Invalid handle!";
119  return false;
120  }
121  std::pair<TrackingParticleRef, TrackPSimHitRef> clusterTPpairWithDummyTP(tpr,TrackPSimHitRef());//SimHit is dummy: for simHitTPAssociationListGreater
122  // sorting only the cluster is needed
123  auto range = std::equal_range(simHitsTPAssoc->begin(), simHitsTPAssoc->end(),
125  for(auto ip = range.first; ip != range.second; ++ip) {
126  TrackPSimHitRef it = ip->second;
127  ++ii;
128  const GeomDet* tmpDet = theGeometry->idToDet( DetId(it->detUnitId()) ) ;
129  if (!tmpDet) {
130  edm::LogVerbatim("CosmicTrackingParticleSelector")
131  <<"***WARNING: PSimHit "<<ii <<", no GeomDet for: "<<it->detUnitId()<<". Skipping it.";
132  continue;
133  } else {
134  det = DetId(it->detUnitId()).det();
135  subdet = DetId(it->detUnitId()).subdetId();
136  }
137 
138  LocalVector lv = it->momentumAtEntry();
139  Local3DPoint lp = it->localPosition ();
140  GlobalVector gv = tmpDet->surface().toGlobal( lv );
141  GlobalPoint gp = tmpDet->surface().toGlobal( lp );
142  edm::LogVerbatim("CosmicTrackingParticleSelector")
143  <<"PSimHit "<<ii<<", Detector = "<<det<<", subdet = "<<subdet
144  <<"\t Radius = "<< gp.perp() << ", z = "<< gp.z()
145  <<"\t pt = "<< gv.perp() << ", pz = "<< gv.z();
146  edm::LogVerbatim("CosmicTrackingParticleSelector")
147  <<"\t trackId = "<<it->trackId()<<", particleType = "<<it->particleType()<<", processType = "<<it->processType();
148 
149  // discard hits related to low energy debris from the primary particle
150  if (it->processType()!=0) continue;
151 
152  if(gp.perp()<radius){
153  found=true;
154  radius = gp.perp();
155  finalGV = gv;
156  finalGP = gp;
157  }
158  }
159  edm::LogVerbatim("CosmicTrackingParticleSelector")
160  <<"\n"<<"FINAL State at InnerMost Hit: Radius = "<< finalGP.perp() << ", z = "<< finalGP.z()
161  <<", pt = "<< finalGV.perp() << ", pz = "<< finalGV.z();
162 
163  if(!found) return 0;
164  else
165  {
166  FreeTrajectoryState ftsAtProduction(finalGP,finalGV,TrackCharge(tpr->charge()),theMF.product());
167  TSCBLBuilderNoMaterial tscblBuilder;
168  TrajectoryStateClosestToBeamLine tsAtClosestApproach = tscblBuilder(ftsAtProduction,*bs);//as in TrackProducerAlgorithm
169  if(!tsAtClosestApproach.isValid()){
170  edm::LogVerbatim("CosmicTrackingParticleSelector")
171  <<"*** WARNING in CosmicTrackingParticleSelector: tsAtClosestApproach is not valid." <<"\n";
172  return 0;
173  }
174  else
175  {
176  momentum = tsAtClosestApproach.trackStateAtPCA().momentum();
177  vertex = tsAtClosestApproach.trackStateAtPCA().position();
178 
179  edm::LogVerbatim("CosmicTrackingParticleSelector")
180  <<"FINAL State extrapolated at PCA: Radius = "<< vertex.perp() << ", z = "<< vertex.z()
181  <<", pt = "<< momentum.perp() << ", pz = "<< momentum.z() <<"\n";
182 
183  return (
184  tpr->numberOfTrackerLayers() >= minHit_ &&
185  sqrt(momentum.perp2()) >= ptMin_ &&
186  momentum.eta() >= minRapidity_ && momentum.eta() <= maxRapidity_ &&
187  sqrt(vertex.perp2()) <= tip_ &&
188  fabs(vertex.z()) <= lip_
189  );
190  }
191  }
192  }
193 
194  size_t size() const { return selected_.size(); }
195 
196  private:
197 
198  double ptMin_;
199  double minRapidity_;
200  double maxRapidity_;
201  double tip_;
202  double lip_;
203  int minHit_;
205  std::vector<int> pdgId_;
208 
210 
211 };
212 
213 #endif
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:114
tuple cfg
Definition: looper.py:293
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)
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
T perp2() const
Definition: PV3DBase.h:71
int ii
Definition: cuy.py:588
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:40
bool operator()(const TrackingParticleRef tpr, const reco::BeamSpot *bs, const edm::Event &iEvent, const edm::EventSetup &iSetup) const
int TrackCharge
Definition: TrackCharge.h:4
int iEvent
Definition: GenABIO.cc:230
CosmicTrackingParticleSelector(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
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:75
edm::Handle< SimHitTPAssociationProducer::SimHitTPAssociationList > simHitsTPAssoc
GlobalVector momentum() const
Definition: DetId.h:18
GlobalPoint position() const
T const * product() const
Definition: Handle.h:81
Detector
Definition: DetId.h:24
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
T eta() const
Definition: PV3DBase.h:76
edm::Ref< edm::PSimHitContainer > TrackPSimHitRef
CosmicTrackingParticleSelector(double ptMin, double minRapidity, double maxRapidity, double tip, double lip, int minHit, bool chargedOnly, const std::vector< int > &pdgId=std::vector< int >())
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::Ref< TrackingParticleCollection > TrackingParticleRef