CMS 3D CMS Logo

CaloParticleSelector.h
Go to the documentation of this file.
1 #ifndef Validation_HGCalValidation_CaloParticleSelector_h
2 #define Validation_HGCalValidation_CaloParticleSelector_h
3 /* \class CaloParticleSelector
4  *
5  * \author Giuseppe Cerati, INFN
6  *
7  * $Date: 2013/05/14 15:46:46 $
8  * $Revision: 1.5.4.2 $
9  *
10  */
16 
18 
19  public:
21  CaloParticleSelector ( double ptMin, double ptMax, double minRapidity,double maxRapidity, double lip, double tip,
22  int minHit, bool signalOnly, bool intimeOnly, bool chargedOnly, bool stableOnly,
23  const std::vector<int>& pdgId = std::vector<int>(),
24  double minPhi=-3.2, double maxPhi=3.2) :
25  ptMin2_( ptMin*ptMin ), ptMax2_( ptMax*ptMax ), minRapidity_( minRapidity ), maxRapidity_( maxRapidity ), lip_( lip ), tip2_( tip*tip ), meanPhi_((minPhi+maxPhi)/2.), rangePhi_((maxPhi-minPhi)/2.), minHit_( minHit ), signalOnly_(signalOnly), intimeOnly_(intimeOnly), chargedOnly_(chargedOnly), stableOnly_(stableOnly), pdgId_( pdgId ) {
26  if(minPhi >= maxPhi) {
27  throw cms::Exception("Configuration") << "CaloParticleSelector: minPhi (" << minPhi << ") must be smaller than maxPhi (" << maxPhi << "). The range is constructed from minPhi to maxPhi around their average.";
28  }
29  if(minPhi >= M_PI) {
30  throw cms::Exception("Configuration") << "CaloParticleSelector: minPhi (" << minPhi << ") must be smaller than PI. The range is constructed from minPhi to maxPhi around their average.";
31  }
32  if(maxPhi <= -M_PI) {
33  throw cms::Exception("Configuration") << "CaloParticleSelector: maxPhi (" << maxPhi << ") must be larger than -PI. The range is constructed from minPhi to maxPhi around their average.";
34  }
35  }
36 
37  // Operator() performs the selection: e.g. if (cPSelector(cp)) {...}
38  // For the moment there shouldn't be any SimTracks from different crossings in the CaloParticle.
39  bool operator()( const CaloParticle & tp , std::vector<SimVertex> const & simVertices) const {
40  // signal only means no PU particles
41  if (signalOnly_ && !(tp.eventId().bunchCrossing()== 0 && tp.eventId().event() == 0)) return false;
42  // intime only means no OOT PU particles
43  if (intimeOnly_ && !(tp.eventId().bunchCrossing()==0)) return false;
44 
45  auto pdgid = tp.pdgId();
46  if(!pdgId_.empty()) {
47  bool testId = false;
48  for(auto id: pdgId_) {
49  if(id == pdgid) { testId = true; break;}
50  }
51  if(!testId) return false;
52  }
53 
54  if (chargedOnly_ && tp.charge()==0) return false;//select only if charge!=0
55 
56  // select only stable particles
57  if (stableOnly_) {
58  for( CaloParticle::genp_iterator j = tp.genParticle_begin(); j != tp.genParticle_end(); ++ j ) {
59  if (j->get()==nullptr || j->get()->status() != 1) {
60  return false;
61  }
62  }
63 
64  // test for remaining unstabled due to lack of genparticle pointer
65  std::vector<int> pdgids {11,13,211,321,2212,3112,3222,3312,3334};
66  if( tp.status() == -99 &&
67  (!std::binary_search(pdgids.begin(), pdgids.end(), std::abs(pdgid) ))
68  ){ return false; }
69  }
70 
71  auto etaOk = [&](const CaloParticle& p)->bool{ float eta= etaFromXYZ(p.px(),p.py(),p.pz()); return (eta>= minRapidity_) & (eta<=maxRapidity_);};
72  auto phiOk = [&](const CaloParticle& p) { float dphi = deltaPhi(atan2f(p.py(),p.px()), meanPhi_); return dphi >= -rangePhi_ && dphi <= rangePhi_; };
73  auto ptOk = [&](const CaloParticle& p) { double pt2 = tp.p4().perp2(); return pt2 >= ptMin2_ && pt2 <= ptMax2_; };
74 
75  return (
76  ptOk(tp) &&
77  etaOk(tp) &&
78  phiOk(tp)
79  );
80  }
81 
82  private:
83  double ptMin2_;
84  double ptMax2_;
85  float minRapidity_;
86  float maxRapidity_;
87  double lip_;
88  double tip2_;
89  float meanPhi_;
90  float rangePhi_;
91  int minHit_;
96  std::vector<int> pdgId_;
97 };
98 
101 
102 namespace reco {
103  namespace modules {
104 
105  template<>
108  return make(cfg);
109  }
110 
112  return CaloParticleSelector(
113  cfg.getParameter<double>( "ptMin" ),
114  cfg.getParameter<double>( "ptMax" ),
115  cfg.getParameter<double>( "minRapidity" ),
116  cfg.getParameter<double>( "maxRapidity" ),
117  cfg.getParameter<double>( "lip" ),
118  cfg.getParameter<double>( "tip" ),
119  cfg.getParameter<int>( "minHit" ),
120  cfg.getParameter<bool>( "signalOnly" ),
121  cfg.getParameter<bool>( "intimeOnly" ),
122  cfg.getParameter<bool>( "chargedOnly" ),
123  cfg.getParameter<bool>( "stableOnly" ),
124  cfg.getParameter<std::vector<int> >( "pdgId" ),
125  cfg.getParameter<double>( "minPhi" ),
126  cfg.getParameter<double>( "maxPhi" ));
127  }
128  };
129 
130  }
131 }
132 
133 #endif
T getParameter(std::string const &) const
int event() const
get the contents of the subdetector field (should be protected?)
CaloParticleSelector(double ptMin, double ptMax, double minRapidity, double maxRapidity, double lip, double tip, int minHit, bool signalOnly, bool intimeOnly, bool chargedOnly, bool stableOnly, const std::vector< int > &pdgId=std::vector< int >(), double minPhi=-3.2, double maxPhi=3.2)
static CaloParticleSelector make(const edm::ParameterSet &cfg, edm::ConsumesCollector &iC)
S make(const edm::ParameterSet &cfg)
EncodedEventId eventId() const
Signal source, crossing number.
Definition: CaloParticle.h:54
float charge() const
Electric charge. Note this is taken from the first SimTrack only.
Definition: CaloParticle.h:79
int status() const
Status word.
Definition: CaloParticle.h:155
genp_iterator genParticle_begin() const
iterators
Definition: CaloParticle.h:63
pdgids
Definition: ntuple.py:98
const math::XYZTLorentzVectorF & p4() const
Four-momentum Lorentz vector. Note this is taken from the first SimTrack only.
Definition: CaloParticle.h:85
int bunchCrossing() const
get the detector field from this detid
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define M_PI
int pdgId() const
PDG ID.
Definition: CaloParticle.h:43
static CaloParticleSelector make(const edm::ParameterSet &cfg)
fixed size matrix
std::vector< int > pdgId_
bool operator()(const CaloParticle &tp, std::vector< SimVertex > const &simVertices) const
genp_iterator genParticle_end() const
Definition: CaloParticle.h:64