13 #include "fastjet/PseudoJet.hh"
14 #include "fastjet/ClusterSequence.hh"
18 namespace TemplateOverlap{
20 enum {CONE, GAUSSIAN};
21 enum {HADRONIC, SEMILEPTONIC};
26 double _subConeRadius;
34 Settings(
const double subConeRadiusIn=0.20,
35 const double sigmaIn=0.33,
const double coneRadiusIn = 1.0,
const double coneRadius2In=0.40,
const bool variableConeIn=
false,
36 const double minPtPartonIn = 10.) :
37 _subConeRadius(subConeRadiusIn), _coneRadius(coneRadiusIn), _sigma(sigmaIn),
38 _coneRadius2(coneRadius2In),_variableCone(variableConeIn), _minPtParton(minPtPartonIn) {}
39 double r()
const {
return _subConeRadius;}
40 double R0()
const {
return _coneRadius;}
41 double R1()
const {
return _coneRadius2;}
42 double sigma()
const {
return _sigma;}
43 bool variableCone()
const {
return _variableCone;}
44 double minPtParton()
const {
return _minPtParton;}
55 SingleParticle(
double pTIn = 0.,
double yIn = 0.,
double phiIn = 0.)
56 : pT(pTIn), y(yIn), phi(phiIn), mult(1), isUsed(
false), radius(0.), sigma(0.) { }
58 y(ssj.y), phi(ssj.phi), mult(ssj.mult), isUsed(ssj.isUsed), radius(ssj.radius), sigma(ssj.sigma) { }
60 { pT = ssj.pT; y = ssj.y; phi = ssj.phi;
61 mult = ssj.mult; isUsed = ssj.isUsed; radius =ssj.radius; sigma=ssj.sigma;}
return *
this; }
71 double dPhi = abs(phi - other.phi );
72 if (dPhi > M_PI) dPhi = 2. * M_PI - dPhi;
73 double dEta = y - other.y;
74 return (dEta * dEta + dPhi * dPhi );
79 typedef std::vector<SingleParticle> jet_t;
80 typedef std::pair<double, std::vector<fastjet::PseudoJet> > templ_t;
81 bool checkTemplate (
const jet_t & probe_template);
82 void matchTemplate( jet_t & jet,
const vector<jet_t> & templates, vector<double> & result,
int match_method=CONE,
int normalization=HADRONIC);
83 void maximize(
const vector<double> & result,
double & maxVal,
int & maxLoc );
85 std::vector<fastjet::PseudoJet> ConvertToPseudoJet(
const jet_t& particles) ;
86 std::vector<fastjet::PseudoJet> ConvertToPseudoJet(
const jet_t& particles,
const fastjet::PseudoJet & tilt_axis) ;
88 jet_t ConvertToJet(
const fastjet::PseudoJet & jet) ;
89 double DeltaPhi(
double phi1,
double phi2);
98 vector<jet_t> _templates;
99 double _subConeRadius;
105 int templateRead(ifstream& is);
106 bool checkTemplate (
const jet_t & probe_template);
110 _mystream(templateFile.c_str()), _subConeRadius(mySettings.r()), _sigma(mySettings.sigma()), _minPtParton(mySettings.minPtParton()) {templateRead(_mystream);}
111 templ_t getOv (
const fastjet::PseudoJet & jet);
115 templ_t MatchingMethod::getOv(
const fastjet::PseudoJet& jet)
118 int match_method = CONE;
119 int normalize = HADRONIC;
123 jet_mat = ConvertToJet(jet);
126 vector<double> result;
129 matchTemplate(jet_mat, _templates, result, match_method, normalize);
132 maximize(result, _maxVal, _maxLoc );
135 std::vector<fastjet::PseudoJet> peak_template = ConvertToPseudoJet(_templates[_maxLoc], jet);
136 return std::make_pair<double, std::vector<fastjet::PseudoJet> >(_maxVal, peak_template);
140 int MatchingMethod::templateRead(ifstream& is) {
149 while (getline(is,line)){
150 istringstream getpro(line);
153 if (!getpro)
return false;
156 particlesSave.clear();
159 double pup1, pup2, pup3, pup4;
161 if (!getline(is, line))
return false;
162 istringstream getall(line);
163 getall >> pup1 >> pup2 >> pup3 >> pup4;
165 for (
int ip = 0; ip < nupSave; ++ip) {
166 if (!getline(is, line))
return false;
167 istringstream getall(line);
168 getall >> pup1 >> pup2 >> pup3 >> pup4;
169 if (!getall)
return false;
171 fastjet::PseudoJet pTemp(pup1,pup2,pup3,pup4);
173 pAux.radius = _subConeRadius;
175 particlesSave.push_back(pAux);
178 if (checkTemplate (particlesSave) ) _templates.push_back(particlesSave);
185 return (_templates.size());
190 bool MatchingMethod::checkTemplate(
const jet_t& probe_template)
193 for (jet_t::const_iterator i = probe_template.begin() ; i != probe_template.end() && isOK ; ++i) {
194 if ((*i).pT < _minPtParton) { isOK =
false;
break;}
195 for (jet_t::const_iterator j = i + 1 ; j != probe_template.end(); ++j){
196 if((*i).deltaR2((*j)) < ((*i).radius+(*j).radius) * ((*i).radius+(*j).radius))
197 { isOK =
false; break ;}
206 void reset(jet_t & jet){
207 for (jet_t::iterator j = jet.begin(); j != jet.end(); ++j)
208 if ((*j).isUsed) (*j).isUsed =
false;
214 double overlapDistance (jet_t & jet1, jet_t & jet2,
double R0)
217 for(jet_t::const_iterator k = jet1.begin(); k != jet1.end(); ++k) {
218 double eTjetNow = 0.;
220 for (jet_t::iterator j = jet2.begin(); j !=jet2.end(); ++j) {
221 if ((*j).isUsed)
continue;
222 if ((*j).deltaR2(*k) > R0 * R0 )
continue;
226 double eTcenterNow = (*k).pT;
228 sum += 4.5 * (eTjetNow - eTcenterNow) * (eTjetNow - eTcenterNow)/(eTcenterNow * eTcenterNow);
237 void matchTemplate(jet_t & jet,
const vector<jet_t> & templates, vector<double> & result,
int match_method,
int normalization)
239 for (
int i = 0; i < int (templates.size()); ++i){
242 for(jet_t::const_iterator t_particle = templates[i].begin(); t_particle !=
243 templates[i].end(); ++t_particle)
245 double eTjetNow = 0.;
247 for ( jet_t::iterator particle = jet.begin(); particle != jet.end(); ++particle)
249 if ((*particle).isUsed)
continue;
250 if ((*particle).deltaR2(*t_particle) > (*t_particle).radius * (*t_particle).radius )
continue;
251 eTjetNow += (*particle).pT;
252 (*particle).isUsed =
true;
254 double eTcenterNow = (*t_particle).pT;
257 sum += 0.5*1/ ( ((*t_particle).sigma)*((*t_particle).sigma) ) * (eTjetNow - eTcenterNow) * (eTjetNow - eTcenterNow)/(eTcenterNow * eTcenterNow);
259 if (sum > 4.6 )
break;
265 result.push_back(exp(-sum));
271 void maximize(
const vector<double> & result,
double & maxVal,
int & maxLoc )
276 for (
int i = 0; i < int (result.size()); ++i){
277 double thisVal = result[i];
278 if (thisVal > maxVal){ maxLoc = i; maxVal = thisVal;}
286 std::vector<fastjet::PseudoJet> ConvertToPseudoJet(
const jet_t& particles)
288 std::vector<fastjet::PseudoJet> Jets;
289 for (jet_t::const_iterator part = particles.begin(); part != particles.end(); part++) {
290 fastjet::PseudoJet temp = fastjet::PtYPhiM((*part).pT, (*part).y, (*part).phi);
291 Jets.push_back(temp);
296 std::vector<fastjet::PseudoJet> ConvertToPseudoJet(
const jet_t& particles,
const fastjet::PseudoJet & tilt_axis)
298 std::vector<fastjet::PseudoJet> Jets;
299 double etaJet = tilt_axis.rapidity();
300 double phiJet = tilt_axis.phi();
301 for (jet_t::const_iterator part = particles.begin(); part != particles.end(); part++) {
302 fastjet::PseudoJet temp = fastjet::PtYPhiM((*part).pT, (*part).y + etaJet, (*part).phi + phiJet);
303 Jets.push_back(temp);
308 jet_t ConvertToJet(
const fastjet::PseudoJet& jet)
310 std::vector<fastjet::PseudoJet> particles = jet.constituents();
313 double jetRapidity = jet.rapidity() ;
314 double jetPhi = jet.phi() ;
316 for (
unsigned int i = 0; i < particles.size(); ++i) {
317 double etaNow = particles[i].eta();
318 double phiNow = particles[i].phi();
319 double pTnow = particles[i].perp();
321 jet_mat.push_back( SingleParticle( pTnow, etaNow - jetRapidity, phiNow - jetPhi) );
327 double DeltaPhi(
double phi1,
double phi2)
329 double dphi = phi1-phi2;
331 if (dphi > M_PI) dphi -= 2* M_PI;
332 if (dphi < -M_PI) dphi += 2* M_PI;
342 #endif // end Event_H