CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
17 
23 
26 
27 #include <string>
28 #include <vector>
29 #include <map>
30 
31 class TH1F;
32 class BPHRecoCandidate;
33 
34 class BPHWriteSpecificDecay : public BPHAnalyzerWrapper<BPHModuleWrapper::one_producer> {
35 public:
36  explicit BPHWriteSpecificDecay(const edm::ParameterSet& ps);
37  ~BPHWriteSpecificDecay() override;
38 
39  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
40 
41  void beginJob() override;
42  void produce(edm::Event& ev, const edm::EventSetup& es) override;
43  virtual void fill(edm::Event& ev, const edm::EventSetup& es);
44  void endJob() override;
45 
46 private:
57 
58  // token wrappers to allow running both on "old" and "new" CMSSW versions
69 
70  bool usePV;
71  bool usePM;
72  bool useCC;
73  bool usePF;
74  bool usePC;
75  bool useGP;
76  bool useK0;
77  bool useL0;
78  bool useKS;
79  bool useLS;
80 
93 
94  enum recoType {
96  Pmm,
99  Ups,
105  Bu,
106  Bd,
107  Bs,
110  B0,
112  Bc,
114  };
115  enum parType {
137  };
138  std::map<std::string, recoType> rMap;
139  std::map<std::string, parType> pMap;
140  std::map<std::string, parType> fMap;
141  std::map<recoType, std::map<parType, double>> parMap;
142 
143  bool recoOnia;
144  bool recoKx0;
145  bool recoPkk;
146  bool recoBu;
147  bool recoBd;
148  bool recoBs;
149  bool recoK0s;
151  bool recoB0;
153  bool recoBc;
154  bool recoX3872;
155 
156  bool writeOnia;
157  bool writeKx0;
158  bool writePkk;
159  bool writeBu;
160  bool writeBd;
161  bool writeBs;
162  bool writeK0s;
164  bool writeB0;
166  bool writeBc;
168 
171 
172  std::vector<BPHPlusMinusConstCandPtr> lFull;
173  std::vector<BPHPlusMinusConstCandPtr> lJPsi;
174  std::vector<BPHRecoConstCandPtr> lSd;
175  std::vector<BPHRecoConstCandPtr> lSs;
176  std::vector<BPHRecoConstCandPtr> lBu;
177  std::vector<BPHRecoConstCandPtr> lBd;
178  std::vector<BPHRecoConstCandPtr> lBs;
179  std::vector<BPHPlusMinusConstCandPtr> lK0;
180  std::vector<BPHPlusMinusConstCandPtr> lL0;
181  std::vector<BPHRecoConstCandPtr> lB0;
182  std::vector<BPHRecoConstCandPtr> lLb;
183  std::vector<BPHRecoConstCandPtr> lBc;
184  std::vector<BPHRecoConstCandPtr> lX3872;
185 
186  std::map<const BPHRecoCandidate*, const BPHRecoCandidate*> jPsiOMap;
187  std::map<const BPHRecoCandidate*, const BPHRecoCandidate*> daughMap;
189  std::map<const BPHRecoCandidate*, vertex_ref> pvRefMap;
191  std::map<const BPHRecoCandidate*, compcc_ref> ccRefMap;
192 
193  void setRecoParameters(const edm::ParameterSet& ps);
194 
195  template <class T>
197  const std::vector<T>& list,
198  const std::string& name) {
200  int i;
201  int n = list.size();
202  std::map<const BPHRecoCandidate*, const BPHRecoCandidate*>::const_iterator dauIter;
203  std::map<const BPHRecoCandidate*, const BPHRecoCandidate*>::const_iterator dauIend = daughMap.end();
204  std::map<const BPHRecoCandidate*, const BPHRecoCandidate*>::const_iterator jpoIter;
205  std::map<const BPHRecoCandidate*, const BPHRecoCandidate*>::const_iterator jpoIend = jPsiOMap.end();
206  std::map<const BPHRecoCandidate*, vertex_ref>::const_iterator pvrIter;
207  std::map<const BPHRecoCandidate*, vertex_ref>::const_iterator pvrIend = pvRefMap.end();
208  std::map<const BPHRecoCandidate*, compcc_ref>::const_iterator ccrIter;
209  std::map<const BPHRecoCandidate*, compcc_ref>::const_iterator ccrIend = ccRefMap.end();
210  for (i = 0; i < n; ++i) {
211  const T& ptr = list[i];
212  ccList->push_back(ptr->composite());
213  pat::CompositeCandidate& cc = ccList->back();
214  if ((pvrIter = pvRefMap.find(ptr.get())) != pvrIend)
215  cc.addUserData("primaryVertex", pvrIter->second);
216  const std::vector<std::string>& cNames = ptr->compNames();
217  int j = 0;
218  int m = cNames.size();
219  while (j < m) {
220  const std::string& compName = cNames[j++];
221  const BPHRecoCandidate* cptr = ptr->getComp(compName).get();
222  if ((ccrIter = ccRefMap.find(cptr)) == ccrIend) {
223  if ((dauIter = daughMap.find(cptr)) != dauIend)
224  cptr = dauIter->second;
225  if ((jpoIter = jPsiOMap.find(cptr)) != jpoIend)
226  cptr = jpoIter->second;
227  }
228  if ((ccrIter = ccRefMap.find(cptr)) != ccrIend) {
229  compcc_ref cref = ccrIter->second;
230  if (cref.isNonnull())
231  cc.addUserData("refTo" + compName, cref);
232  }
233  }
234  const BPHPlusMinusCandidate* pmp = dynamic_cast<const BPHPlusMinusCandidate*>(ptr.get());
235  if (pmp != nullptr) {
236  cc.addUserData("cowboy", pmp->isCowboy());
237  // cc.addUserFloat( "dca", pmp->cAppInRPhi().distance() );
238  }
239  if (writeVertex)
240  cc.addUserData("vertex", ptr->vertex());
241  if (ptr->isEmpty())
242  continue;
243  if (writeVertex)
244  cc.addUserData("fitVertex", reco::Vertex(*ptr->topDecayVertex()));
245  if (ptr->isValidFit()) {
246  const RefCountedKinematicParticle kinPart = ptr->topParticle();
247  const KinematicState kinStat = kinPart->currentState();
248  cc.addUserFloat("fitMass", kinStat.mass());
249  if (writeMomentum)
250  cc.addUserData("fitMomentum", kinStat.kinematicParameters().momentum());
251  }
252  }
253  typedef std::unique_ptr<pat::CompositeCandidateCollection> ccc_pointer;
254  edm::OrphanHandle<pat::CompositeCandidateCollection> ccHandle = ev.put(ccc_pointer(ccList), name);
255  for (i = 0; i < n; ++i) {
256  const BPHRecoCandidate* ptr = list[i].get();
258  ccRefMap[ptr] = ccRef;
259  }
260  return ccHandle;
261  }
262 };
263 
264 #endif
BPHTokenWrapper< std::vector< reco::VertexCompositeCandidate > > l0CandsToken
Analysis-level particle class.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
BPHTokenWrapper< std::vector< reco::Vertex > > pVertexToken
std::vector< BPHPlusMinusConstCandPtr > lJPsi
BPHTokenWrapper< std::vector< reco::VertexCompositePtrCandidate > > kSCandsToken
std::vector< BPHPlusMinusConstCandPtr > lK0
edm::Ref< std::vector< reco::Vertex > > vertex_ref
std::map< const BPHRecoCandidate *, compcc_ref > ccRefMap
std::vector< BPHPlusMinusConstCandPtr > lFull
std::map< std::string, recoType > rMap
edm::Ref< pat::CompositeCandidateCollection > compcc_ref
std::vector< BPHRecoConstCandPtr > lBs
BPHTokenWrapper< std::vector< BPHTrackReference::candidate > > pcCandsToken
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:892
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void fill(edm::Event &ev, const edm::EventSetup &es)
std::map< const BPHRecoCandidate *, const BPHRecoCandidate * > daughMap
ParticleMass mass() const
std::map< std::string, parType > pMap
std::vector< BPHRecoConstCandPtr > lSs
BPHTokenWrapper< std::vector< reco::VertexCompositeCandidate > > k0CandsToken
BPHWriteSpecificDecay(const edm::ParameterSet &ps)
BPHTokenWrapper< pat::MuonCollection > patMuonToken
BPHTokenWrapper< std::vector< reco::PFCandidate > > pfCandsToken
bool isCowboy() const
get cowboy/sailor classification
BPHTokenWrapper< std::vector< reco::VertexCompositePtrCandidate > > lSCandsToken
BPHTokenWrapper< std::vector< pat::CompositeCandidate > > ccCandsToken
std::vector< BPHRecoConstCandPtr > lSd
KinematicParameters const & kinematicParameters() const
BPHTokenWrapper< std::vector< pat::GenericParticle > > gpCandsToken
std::vector< CompositeCandidate > CompositeCandidateCollection
edm::OrphanHandle< pat::CompositeCandidateCollection > write(edm::Event &ev, const std::vector< T > &list, const std::string &name)
std::map< const BPHRecoCandidate *, vertex_ref > pvRefMap
std::vector< BPHPlusMinusConstCandPtr > lL0
std::vector< BPHRecoConstCandPtr > lBu
std::vector< BPHRecoConstCandPtr > lLb
virtual BPHRecoConstCandPtr getComp(const std::string &name) const
std::map< recoType, std::map< parType, double > > parMap
std::map< const BPHRecoCandidate *, const BPHRecoCandidate * > jPsiOMap
std::vector< BPHRecoConstCandPtr > lB0
std::vector< BPHRecoConstCandPtr > lBc
std::vector< BPHRecoConstCandPtr > lX3872
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:348
GlobalVector momentum() const