CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTJetCollectionsForBoostedLeptonPlusJets.cc
Go to the documentation of this file.
2 
4 
9 
11 
13 
16 //(1)
20 #include "TVector3.h"
21 #include <string>
22 #include <vector>
23 #include <typeinfo>
24 //(1)
25 
26 
27 
28 template <typename jetType>
30  hltLeptonTag(iConfig.getParameter< edm::InputTag > ("HltLeptonTag")),
31  sourceJetTag(iConfig.getParameter< edm::InputTag > ("SourceJetTag")),
32  minDeltaR_(iConfig.getParameter< double > ("minDeltaR"))
33 {
34  using namespace edm;
35  using namespace std;
36  typedef vector<RefVector<vector<jetType>,jetType,refhelper::FindUsingAdvance<vector<jetType>,jetType> > > JetCollectionVector;
37  m_theLeptonToken = consumes<trigger::TriggerFilterObjectWithRefs>(hltLeptonTag);
38  m_theJetToken = consumes<std::vector<jetType>>(sourceJetTag);
39  produces<JetCollectionVector> ();
40 }
41 
42 template <typename jetType>
44 {
45  // do anything here that needs to be done at desctruction time
46  // (e.g. close files, deallocate resources etc.)
47 
48 }
49 
50 template <typename jetType>
51 void
54  desc.add<edm::InputTag> ("HltLeptonTag", edm::InputTag("triggerFilterObjectWithRefs"));
55  desc.add<edm::InputTag> ("SourceJetTag", edm::InputTag("jetCollection"));
56  desc.add<double> ("minDeltaR", 0.5);
58 }
59 
60 //
61 // member functions
62 //
63 
64 
65 // ------------ method called to produce the data ------------
66 // template <typename T>
67 template <typename jetType>
68 void
70 {
71  using namespace edm;
72  using namespace std;
73  using namespace reco;
74 
75  typedef vector<RefVector<vector<jetType>,jetType,refhelper::FindUsingAdvance<vector<jetType>,jetType> > > JetCollectionVector;
76  typedef vector<jetType> JetCollection;
80 
82  iEvent.getByToken(m_theLeptonToken,PrevFilterOutput);
83 
84  //its easier on the if statement flow if I try everything at once, shouldnt add to timing
85  // Electrons can be stored as objects of types TriggerCluster, TriggerElectron, or TriggerPhoton
86  vector<Ref<reco::RecoEcalCandidateCollection> > clusCands;
87  PrevFilterOutput->getObjects(trigger::TriggerCluster,clusCands);
88 
89  vector<Ref<reco::ElectronCollection> > eleCands;
90  PrevFilterOutput->getObjects(trigger::TriggerElectron,eleCands);
91 
92  trigger::VRphoton photonCands;
93  PrevFilterOutput->getObjects(trigger::TriggerPhoton, photonCands);
94 
95  vector<reco::RecoChargedCandidateRef> muonCands;
96  PrevFilterOutput->getObjects(trigger::TriggerMuon,muonCands);
97 
98  Handle<JetCollection> theJetCollectionHandle;
99  iEvent.getByToken(m_theJetToken, theJetCollectionHandle);
100 
101  const JetCollection & theJetCollection = *theJetCollectionHandle;
102 
103  auto_ptr < JetCollectionVector > allSelections(new JetCollectionVector());
104 
105  if(!clusCands.empty()){ // try trigger clusters
106  for(size_t candNr=0;candNr<clusCands.size();candNr++){
107  JetRefVector refVector;
108  for (unsigned int j = 0; j < theJetCollection.size(); j++) {
109  if (deltaR(clusCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
110  else{
111  unsigned int w =0 ;
112  std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
113  for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
114  TVector3 ClusP(clusCands[candNr]->p4().Px(),clusCands[candNr]->p4().Py(), clusCands[candNr]->p4().Pz());
115  TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
116  double deltaRPFConste = ClusP.DeltaR(PFJetConstP);
117  if(deltaRPFConste < 0.001 && w==0){
118  const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - clusCands[candNr]->p4();
119  w ++;
120  } //if
121  }//for constituents
122  refVector.push_back(JetRef(theJetCollectionHandle, j));
123  }//else
124  }
125  allSelections->push_back(refVector);
126  }
127  }
128 
129  if(!eleCands.empty()){ // try electrons
130  for(size_t candNr=0;candNr<eleCands.size();candNr++){
131  JetRefVector refVector;
132  for (unsigned int j = 0; j < theJetCollection.size(); j++) {
133  if (deltaR(eleCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
134  else{
135  unsigned int w =0 ;
136  std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
137  for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
138  TVector3 ElectronP(eleCands[candNr]->p4().Px(),eleCands[candNr]->p4().Py(), eleCands[candNr]->p4().Pz());
139  TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
140  double deltaRPFConste = ElectronP.DeltaR(PFJetConstP);
141  if(deltaRPFConste < 0.001 && w==0){
142  const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - eleCands[candNr]->p4();
143  w ++;
144  } //if
145  }//for constituents
146  refVector.push_back(JetRef(theJetCollectionHandle, j));
147  }//else
148  }
149  allSelections->push_back(refVector);
150  }
151  }
152 
153  if(!photonCands.empty()){ // try photons
154  for(size_t candNr=0;candNr<photonCands.size();candNr++){
155  JetRefVector refVector;
156  for (unsigned int j = 0; j < theJetCollection.size(); j++) {
157  if (deltaR(photonCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
158  else{
159  unsigned int w =0 ;
160  std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
161  for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
162  TVector3 PhotonP(photonCands[candNr]->p4().Px(),photonCands[candNr]->p4().Py(), photonCands[candNr]->p4().Pz());
163  TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
164  double deltaRPFConste = PhotonP.DeltaR(PFJetConstP);
165  if(deltaRPFConste < 0.001 && w==0){
166  const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - photonCands[candNr]->p4();
167  w ++;
168  } //if
169  }//for constituents
170  refVector.push_back(JetRef(theJetCollectionHandle, j));
171  }//else
172  }
173  allSelections->push_back(refVector);
174  }
175  }
176 
177  if(!muonCands.empty()){ // muons
178  for(size_t candNr=0;candNr<muonCands.size();candNr++){
179  JetRefVector refVector;
180  for (unsigned int j = 0; j < theJetCollection.size(); j++) {
181  if (deltaR(muonCands[candNr]->p4(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
182  else{
183  unsigned int w =0 ;
184  std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
185  for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
186  TVector3 MuP(muonCands[candNr]->p4().Px(),muonCands[candNr]->p4().Py(), muonCands[candNr]->p4().Pz());
187  TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
188  double deltaRPFConste = MuP.DeltaR(PFJetConstP);
189  if(deltaRPFConste < 0.001 && w==0){
190  const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - muonCands[candNr]->p4();
191  w ++;
192  } //if
193  }//for constituents
194  refVector.push_back(JetRef(theJetCollectionHandle, j));
195  }//else
196  }
197  allSelections->push_back(refVector);
198  }
199  }
200 
201 
202 
203 
204  iEvent.put(allSelections);
205 
206  return;
207 
208 }
209 
const double w
Definition: UKUtility.cc:23
std::vector< Jet > JetCollection
Definition: Jet.h:49
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
virtual void produce(edm::Event &, const edm::EventSetup &)
edm::EDGetTokenT< std::vector< jetType > > m_theJetToken
edm::Ref< JetCollection > JetRef
Definition: Jet.h:51
edm::RefVector< JetCollection > JetRefVector
Definition: Jet.h:52
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:29
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
double p4[4]
Definition: TauolaWrapper.h:92
int j
Definition: DBlmapReader.cc:9
edm::EDGetTokenT< trigger::TriggerFilterObjectWithRefs > m_theLeptonToken
ParameterDescriptionBase * add(U const &iLabel, T const &value)
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< float > > LorentzVector
Definition: analysisEnums.h:9
static int position[264][3]
Definition: ReadPGInfo.cc:509
std::vector< reco::RecoEcalCandidateRef > VRphoton
math::PtEtaPhiELorentzVectorF LorentzVector