00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef PARTICLEJETTOOLS_PARTICLETOJETASSOCIATOR_H
00013 #define PARTICLEJETTOOLS_PARTICLETOJETASSOCIATOR_H
00014
00015 #include "AsgTools/AsgTool.h"
00016 #include "AsgTools/ToolHandle.h"
00017
00018
00019
00020
00021 #include "xAODJet/Jet.h"
00022
00023 #include <vector>
00024 #include <list>
00025 #include <string>
00026
00027 namespace Analysis
00028 {
00029
00030 typedef std::string NameType;
00031 typedef std::vector<xAOD::Jet*> jetcollection_t;
00032
00033 #ifndef ROOTCORE
00034 static const InterfaceID IID_ParticleToJetAssociator("Analysis::ParticleToJetAssociator", 1, 0);
00035 #endif
00036 typedef std::vector<std::string> StringVector;
00037
00043 class ParticleToJetAssociator : public asg::AsgTool {
00044 ASG_TOOL_CLASS0(ParticleToJetAssociator)
00045 public:
00046
00048 ParticleToJetAssociator(const std::string& name);
00049 virtual ~ParticleToJetAssociator();
00050
00052 #ifndef ROOTCORE
00053 static const InterfaceID& interfaceID() { return IID_ParticleToJetAssociator; };
00054 #endif
00055
00057 StatusCode initialize();
00059 StatusCode finalize();
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 template<typename ConstituentType, typename coll>
00070 std::vector<ConstituentType*>
00071 associateParticlesToJets(jetcollection_t* theJets,
00072 const coll* particleContainer,
00073 const std::string& constituentName);
00074
00075 inline double getConeSize(double pt) {
00076 return (m_coneSizeFitPar1 + exp(m_coneSizeFitPar2 + m_coneSizeFitPar3*pt));
00077 }
00078
00079 private:
00080
00081 double m_trackCone;
00082 bool m_useVariableSizedTrackCone;
00083 double m_coneSizeFitPar1;
00084 double m_coneSizeFitPar2;
00085 double m_coneSizeFitPar3;
00086 bool m_shareTracks;
00087 };
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 template<typename ConstituentType, typename coll>
00171 inline std::vector<ConstituentType*>
00172 ParticleToJetAssociator::associateParticlesToJets(jetcollection_t* theJets,
00173 const coll* particleContainer,
00174 const std::string& constituentName) {
00175
00176 std::vector<ConstituentType*> vecTrackConst;
00177 ATH_MSG_VERBOSE("Number of Jets : " << theJets->size());
00178 if (theJets->size()<1) return vecTrackConst;
00179 ATH_MSG_VERBOSE("Number of Particles of Type " << constituentName << " : " << particleContainer->size());
00180
00181 for (jetcollection_t::iterator itr = theJets->begin(); itr != theJets->end(); ++itr) {
00182
00183 vecTrackConst.push_back(new ConstituentType);
00184 }
00185
00186 int index(0);
00187 if(!m_shareTracks) {
00188
00189
00190 typename coll::const_iterator tpItr = particleContainer->begin();
00191 for (; tpItr!=particleContainer->end() ; tpItr++) {
00192 double pt = (*tpItr)->pt();
00193 double deltaRMatch(1000);
00194 ATH_MSG_VERBOSE("Particle-Jet association (no sharing). Jet pT= " << pt);
00195 bool findAMatch = false;
00196 int i(0);
00197 xAOD::Jet *theJet = 0;
00198 for (jetcollection_t::iterator itr = theJets->begin(); itr != theJets->end(); ++itr) {
00199 double r = (*itr)->p4().DeltaR((*tpItr)->p4());
00200 if ( r < deltaRMatch ) {
00201 deltaRMatch = r;
00202 index = i;
00203 findAMatch = true;
00204 theJet = (*itr);
00205 }
00206 i++;
00207 }
00208
00209 ATH_MSG_VERBOSE(" matching: find= " << findAMatch << " dR=" << deltaRMatch);
00210 double trackCone = m_trackCone;
00211 if( m_useVariableSizedTrackCone ) {
00212 if(0 != theJet) trackCone = getConeSize(theJet->pt());
00213 ATH_MSG_VERBOSE("Using Variable Sized Cone of " << trackCone);
00214 } else {
00215 ATH_MSG_VERBOSE("Using Fixed Sized Cone of " << trackCone);
00216 }
00217 if (findAMatch && deltaRMatch < trackCone ) {
00218
00219
00220
00221 vecTrackConst[index]->push_back(*tpItr);
00222 ATH_MSG_VERBOSE(" added constituent to Jet " << index);
00223 }
00224 }
00225 } else {
00226
00227
00228 jetcollection_t::iterator jetItr = theJets->begin();
00229 jetcollection_t::iterator jetEnd = theJets->end();
00230 for(; jetItr!=jetEnd; jetItr++) {
00231 typename coll::const_iterator tpItr = particleContainer->begin();
00232 typename coll::const_iterator tpEnd = particleContainer->end();
00233 for(; tpItr!=tpEnd; tpItr++) {
00234 double dR = (*jetItr)->p4().DeltaR((*tpItr)->p4());
00235 double trackCone = m_trackCone;
00236 if( m_useVariableSizedTrackCone ) {
00237 trackCone = getConeSize((*jetItr)->pt());
00238 ATH_MSG_VERBOSE("Using Variable Sized Cone of " << trackCone);
00239 } else {
00240 ATH_MSG_VERBOSE("Using Fixed Sized Cone of " << trackCone);
00241 }
00242 if(dR<trackCone) {
00243 ATH_MSG_VERBOSE("Particle-jet association (with sharing): "
00244 << " jet pt,phi,eta= " << (*jetItr)->pt() << " " << (*jetItr)->phi() << " " << (*jetItr)->eta()
00245 << " trk pt,phi,eta= " << (*tpItr)->pt() << " " << (*tpItr)->phi() << " " << (*tpItr)->eta());
00246
00247
00248
00249 vecTrackConst[index]->push_back(*tpItr);
00250 }
00251 }
00252 index++;
00253 }
00254 }
00255
00256
00257
00258
00259
00260
00261
00262 return vecTrackConst;
00263 }
00264
00265
00266 }
00267 #endif