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 
29 template <typename jetType>
31  hltLeptonTag(iConfig.getParameter< edm::InputTag > ("HltLeptonTag")),
32  sourceJetTag(iConfig.getParameter< edm::InputTag > ("SourceJetTag")),
33  minDeltaR_(iConfig.getParameter< double > ("minDeltaR"))
34 {
35  using namespace edm;
36  using namespace std;
37  typedef vector<RefVector<vector<jetType>,jetType,refhelper::FindUsingAdvance<vector<jetType>,jetType> > > JetCollectionVector;
38  m_theLeptonToken = consumes<trigger::TriggerFilterObjectWithRefs>(hltLeptonTag);
39  m_theJetToken = consumes<std::vector<jetType>>(sourceJetTag);
40  produces<JetCollectionVector> ();
41 }
42 
43 template <typename jetType>
45 {
46  // do anything here that needs to be done at desctruction time
47  // (e.g. close files, deallocate resources etc.)
48 
49 }
50 
51 template <typename jetType>
52 void
55  desc.add<edm::InputTag> ("HltLeptonTag", edm::InputTag("triggerFilterObjectWithRefs"));
56  //(2)
57  desc.add<edm::InputTag> ("SourceJetTag", edm::InputTag("jetCollection"));
58  //(2)
59  desc.add<double> ("minDeltaR", 0.5);
61 }
62 
63 //
64 // member functions
65 //
66 
67 
68 // ------------ method called to produce the data ------------
69 // template <typename T>
70 template <typename jetType>
71 void
73 {
74  using namespace edm;
75  using namespace std;
76  //(3)
77  using namespace reco;
78  //(3)
79 
80  typedef vector<RefVector<vector<jetType>,jetType,refhelper::FindUsingAdvance<vector<jetType>,jetType> > > JetCollectionVector;
81  typedef vector<jetType> JetCollection;
84  //(4)
86  //(4)
87 
89  iEvent.getByToken(m_theLeptonToken,PrevFilterOutput);
90 
91  //its easier on the if statement flow if I try everything at once, shouldnt add to timing
92  // Electrons can be stored as objects of types TriggerCluster, TriggerElectron, or TriggerPhoton
93  vector<Ref<reco::RecoEcalCandidateCollection> > clusCands;
94  PrevFilterOutput->getObjects(trigger::TriggerCluster,clusCands);
95 
96  vector<Ref<reco::ElectronCollection> > eleCands;
97  PrevFilterOutput->getObjects(trigger::TriggerElectron,eleCands);
98 
99  trigger::VRphoton photonCands;
100  PrevFilterOutput->getObjects(trigger::TriggerPhoton, photonCands);
101 
102  vector<reco::RecoChargedCandidateRef> muonCands;
103  PrevFilterOutput->getObjects(trigger::TriggerMuon,muonCands);
104 
105  Handle<JetCollection> theJetCollectionHandle;
106  iEvent.getByToken(m_theJetToken, theJetCollectionHandle);
107 
108  const JetCollection & theJetCollection = *theJetCollectionHandle;
109 
110  auto_ptr < JetCollectionVector > allSelections(new JetCollectionVector());
111 
112  if(!clusCands.empty()){ // try trigger clusters
113  for(size_t candNr=0;candNr<clusCands.size();candNr++){
114  JetRefVector refVector;
115  for (unsigned int j = 0; j < theJetCollection.size(); j++) {
116  if (deltaR(clusCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
117  else{
118  unsigned int w =0 ;
119  std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
120  for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
121  TVector3 ClusP(clusCands[candNr]->p4().Px(),clusCands[candNr]->p4().Py(), clusCands[candNr]->p4().Pz());
122  TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
123  double deltaRPFConste = ClusP.DeltaR(PFJetConstP);
124  if(deltaRPFConste < 0.001 && w==0){
125  const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - clusCands[candNr]->p4();
126  w ++;
127  } //if
128  }//for constituents
129  refVector.push_back(JetRef(theJetCollectionHandle, j));
130  }//else
131  }
132  allSelections->push_back(refVector);
133  }
134  }
135 
136  if(!eleCands.empty()){ // try electrons
137  for(size_t candNr=0;candNr<eleCands.size();candNr++){
138  JetRefVector refVector;
139  for (unsigned int j = 0; j < theJetCollection.size(); j++) {
140  if (deltaR(eleCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
141  else{
142  unsigned int w =0 ;
143  std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
144  for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
145  TVector3 ElectronP(eleCands[candNr]->p4().Px(),eleCands[candNr]->p4().Py(), eleCands[candNr]->p4().Pz());
146  TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
147  double deltaRPFConste = ElectronP.DeltaR(PFJetConstP);
148  if(deltaRPFConste < 0.001 && w==0){
149  const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - eleCands[candNr]->p4();
150  w ++;
151  } //if
152  }//for constituents
153  refVector.push_back(JetRef(theJetCollectionHandle, j));
154  }//else
155  }//for jet collection
156 
157  allSelections->push_back(refVector);
158  }
159  }
160 
161  if(!photonCands.empty()){ // try photons
162  for(size_t candNr=0;candNr<photonCands.size();candNr++){
163  JetRefVector refVector;
164  for (unsigned int j = 0; j < theJetCollection.size(); j++) {
165  if (deltaR(photonCands[candNr]->superCluster()->position(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
166  else{
167  unsigned int w =0 ;
168  std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
169  for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
170  TVector3 PhotonP(photonCands[candNr]->p4().Px(),photonCands[candNr]->p4().Py(), photonCands[candNr]->p4().Pz());
171  TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
172  double deltaRPFConste = PhotonP.DeltaR(PFJetConstP);
173  if(deltaRPFConste < 0.001 && w==0){
174  const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - photonCands[candNr]->p4();
175  w ++;
176  } //if
177  }//for constituents
178  refVector.push_back(JetRef(theJetCollectionHandle, j));
179  }//else
180  }//for jet collection
181  allSelections->push_back(refVector);
182  }
183  }
184 
185  if(!muonCands.empty()){ // muons
186  for(size_t candNr=0;candNr<muonCands.size();candNr++){
187  JetRefVector refVector;
188  for (unsigned int j = 0; j < theJetCollection.size(); j++) {
189  if (deltaR(muonCands[candNr]->p4(),theJetCollection[j]) > minDeltaR_) refVector.push_back(JetRef(theJetCollectionHandle, j));
190  else{
191  unsigned int w =0 ;
192  std::vector<reco::PFCandidatePtr> pfConstituents = theJetCollection[j].getPFConstituents();
193  for(std::vector<reco::PFCandidatePtr>::const_iterator i_candidate = pfConstituents.begin(); i_candidate != pfConstituents.end(); ++i_candidate){
194  TVector3 MuP(muonCands[candNr]->p4().Px(),muonCands[candNr]->p4().Py(), muonCands[candNr]->p4().Pz());
195  TVector3 PFJetConstP((*i_candidate)->px(),(*i_candidate)->py(),(*i_candidate)->pz());
196  double deltaRPFConste = MuP.DeltaR(PFJetConstP);
197  if(deltaRPFConste < 0.001 && w==0){
198  const_cast<LorentzVector&>(theJetCollection[j].p4()) = theJetCollection[j].p4() - muonCands[candNr]->p4();
199  w ++;
200  } //if
201  }//for constituents
202  refVector.push_back(JetRef(theJetCollectionHandle, j));
203  }//else
204  }
205  allSelections->push_back(refVector);
206  }
207  }
208 
209 
210 
211 
212  iEvent.put(allSelections);
213 
214  return;
215 
216 }
217 
const double w
Definition: UKUtility.cc:23
std::vector< Jet > JetCollection
Definition: Jet.h:52
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
virtual void produce(edm::Event &, const edm::EventSetup &)
tuple jetType
JET
Definition: autophobj.py:147
edm::EDGetTokenT< std::vector< jetType > > m_theJetToken
edm::Ref< JetCollection > JetRef
Definition: Jet.h:54
edm::RefVector< JetCollection > JetRefVector
Definition: Jet.h:55
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:113
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