CMS 3D CMS Logo

BPHWriteSpecificDecay.h
Go to the documentation of this file.
1 #ifndef HeavyFlavorAnalysis_SpecificDecay_BPHWriteSpecificDecay_h
2 #define HeavyFlavorAnalysis_SpecificDecay_BPHWriteSpecificDecay_h
3 
5 
10 
14 
20 
23 
24 #include <string>
25 #include <vector>
26 #include <map>
27 #include <iostream>
28 #include <fstream>
29 
30 class TH1F;
31 class BPHRecoCandidate;
32 
34  public BPHAnalyzerWrapper<BPHModuleWrapper::one_producer> {
35 
36  public:
37 
38  explicit BPHWriteSpecificDecay( const edm::ParameterSet& ps );
39  ~BPHWriteSpecificDecay() override;
40 
41  static void fillDescriptions( edm::ConfigurationDescriptions& descriptions );
42 
43  void beginJob() override;
44  void produce( edm::Event& ev, const edm::EventSetup& es ) override;
45  virtual void fill( edm::Event& ev, const edm::EventSetup& es );
46  void endJob() override;
47 
48  private:
49 
56 
57  // token wrappers to allow running both on "old" and "new" CMSSW versions
64 
65  bool usePV;
66  bool usePM;
67  bool useCC;
68  bool usePF;
69  bool usePC;
70  bool useGP;
71 
78 
79  enum recoType { Onia, Pmm , Psi1, Psi2, Ups , Ups1, Ups2, Ups3,
80  Kx0, Pkk, Bu, Bd, Bs };
81  enum parType { ptMin, etaMax,
85  std::map<std::string,recoType> rMap;
86  std::map<std::string, parType> pMap;
87  std::map<std::string, parType> fMap;
88  std::map< recoType, std::map<parType,double> > parMap;
89 
90  bool recoOnia;
91  bool recoKx0;
92  bool recoPkk;
93  bool recoBu;
94  bool recoBd;
95  bool recoBs;
96 
97  bool writeOnia;
98  bool writeKx0;
99  bool writePkk;
100  bool writeBu;
101  bool writeBd;
102  bool writeBs;
103 
106 
107  std::vector<BPHPlusMinusConstCandPtr> lFull;
108  std::vector<BPHPlusMinusConstCandPtr> lJPsi;
109  std::vector<BPHRecoConstCandPtr> lSd;
110  std::vector<BPHRecoConstCandPtr> lSs;
111  std::vector<BPHRecoConstCandPtr> lBu;
112  std::vector<BPHRecoConstCandPtr> lBd;
113  std::vector<BPHRecoConstCandPtr> lBs;
114 
115  std::map<const BPHRecoCandidate*,const BPHRecoCandidate*> jPsiOMap;
117  std::map<const BPHRecoCandidate*,vertex_ref> pvRefMap;
119  std::map<const BPHRecoCandidate*,compcc_ref> ccRefMap;
120 
121  void setRecoParameters( const edm::ParameterSet& ps );
122 
123  template <class T>
125  const std::vector<T>& list, const std::string& name ) {
128  int i;
129  int n = list.size();
130  std::map<const BPHRecoCandidate*,
131  const BPHRecoCandidate*>::const_iterator jpoIter;
132  std::map<const BPHRecoCandidate*,
133  const BPHRecoCandidate*>::const_iterator jpoIend = jPsiOMap.end();
134  std::map<const BPHRecoCandidate*,vertex_ref>::const_iterator pvrIter;
135  std::map<const BPHRecoCandidate*,vertex_ref>::const_iterator pvrIend =
136  pvRefMap.end();
137  std::map<const BPHRecoCandidate*,compcc_ref>::const_iterator ccrIter;
138  std::map<const BPHRecoCandidate*,compcc_ref>::const_iterator ccrIend =
139  ccRefMap.end();
140  for ( i = 0; i < n; ++i ) {
141  const T& ptr = list[i];
142  ccList->push_back( ptr->composite() );
143  pat::CompositeCandidate& cc = ccList->back();
144  if ( ( pvrIter = pvRefMap.find( ptr.get() ) ) != pvrIend )
145  cc.addUserData ( "primaryVertex", pvrIter->second );
146  const std::vector<std::string>& cNames = ptr->compNames();
147  int j = 0;
148  int m = cNames.size();
149  while ( j < m ) {
150  const std::string& compName = cNames[j++];
151  const BPHRecoCandidate* cptr = ptr->getComp( compName ).get();
152  if ( ( ccrIter = ccRefMap.find( cptr ) ) == ccrIend ) {
153  if ( ( jpoIter = jPsiOMap.find( cptr ) ) != jpoIend )
154  cptr = jpoIter->second;
155  else cptr = nullptr;
156  }
157  if ( ( ccrIter = ccRefMap.find( cptr ) ) != ccrIend ) {
158  compcc_ref cref = ccrIter->second;
159  if ( cref.isNonnull() ) cc.addUserData ( "refTo" + compName, cref );
160  }
161  }
162  const BPHPlusMinusCandidate* pmp =
163  dynamic_cast<const BPHPlusMinusCandidate*>( ptr.get() );
164  if ( pmp != nullptr ) cc.addUserData( "cowboy", pmp->isCowboy() );
165  if ( ptr->isEmpty() ) {
166  if ( writeVertex ) cc.addUserData( "vertex" , ptr->vertex() );
167  continue;
168  }
169  if ( writeVertex ) cc.addUserData( "fitVertex",
170  reco::Vertex( *ptr->currentDecayVertex() ) );
171  if ( ptr->isValidFit() ) {
172  const RefCountedKinematicParticle kinPart = ptr->currentParticle();
173  const KinematicState kinStat = kinPart->currentState();
174  cc.addUserFloat( "fitMass", kinStat.mass() );
175  if ( writeMomentum ) cc.addUserData ( "fitMomentum",
176  kinStat.kinematicParameters().momentum() );
177  }
178 
179  }
180  typedef std::unique_ptr<pat::CompositeCandidateCollection> ccc_pointer;
182  ev.put( ccc_pointer( ccList ), name );
183  for ( i = 0; i < n; ++i ) {
184  const BPHRecoCandidate* ptr = list[i].get();
185  edm::Ref<pat::CompositeCandidateCollection> ccRef( ccHandle, i );
186  ccRefMap[ptr] = ccRef;
187  }
188  return ccHandle;
189  }
190 
191 };
192 
193 #endif
Analysis-level particle class.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
std::vector< BPHPlusMinusConstCandPtr > lJPsi
BPHTokenWrapper< std::vector< reco::PFCandidate > > pfCandsToken
std::vector< BPHPlusMinusConstCandPtr > lFull
std::vector< BPHRecoConstCandPtr > lBs
bool ev
std::map< const BPHRecoCandidate *, compcc_ref > ccRefMap
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:813
BPHTokenWrapper< std::vector< pat::CompositeCandidate > > ccCandsToken
std::map< std::string, recoType > rMap
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void fill(edm::Event &ev, const edm::EventSetup &es)
ParticleMass mass() const
std::map< std::string, parType > pMap
std::vector< BPHRecoConstCandPtr > lSs
BPHWriteSpecificDecay(const edm::ParameterSet &ps)
BPHTokenWrapper< pat::MuonCollection > patMuonToken
edm::Ref< pat::CompositeCandidateCollection > compcc_ref
BPHTokenWrapper< std::vector< reco::Vertex > > pVertexToken
bool isCowboy() const
get cowboy/sailor classification
BPHTokenWrapper< std::vector< pat::GenericParticle > > gpCandsToken
edm::Ref< std::vector< reco::Vertex > > vertex_ref
std::vector< BPHRecoConstCandPtr > lSd
KinematicParameters const & kinematicParameters() const
std::vector< CompositeCandidate > CompositeCandidateCollection
std::map< recoType, std::map< parType, double > > parMap
edm::OrphanHandle< pat::CompositeCandidateCollection > write(edm::Event &ev, const std::vector< T > &list, const std::string &name)
std::vector< BPHRecoConstCandPtr > lBu
BPHTokenWrapper< std::vector< BPHTrackReference::candidate > > pcCandsToken
std::map< const BPHRecoCandidate *, vertex_ref > pvRefMap
long double T
void produce(edm::Event &ev, const edm::EventSetup &es) override
std::vector< BPHRecoConstCandPtr > lBd
void setRecoParameters(const edm::ParameterSet &ps)
std::map< std::string, parType > fMap
void addUserData(const std::string &label, const T &data, bool transientOnly=false, bool overwrite=false)
Definition: PATObject.h:309
std::map< const BPHRecoCandidate *, const BPHRecoCandidate * > jPsiOMap
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 list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
GlobalVector momentum() const