ATLAS Offline Software
Qw.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "fastjet/ClusterSequence.hh"
7 #include "fastjet/JetDefinition.hh"
8 #include <math.h>
9 
10 using namespace std;
11 using namespace JetSubStructureUtils;
12 
13 Qw::Qw(QwVariant mode, double p, fastjet::JetAlgorithm jetalg) : m_vMode(mode), m_jetdef(), m_massCut(-1) {
14 
15  switch (mode ) {
16  case Normal:
17  case MassCut:
18  m_jetdef = fastjet::JetDefinition(jetalg, 1.5) ;
19  m_massCut = p;
20  break;
21  case SmallSubjets:
22  if(p==-1) p = 0.2;
23  m_jetdef = fastjet::JetDefinition(jetalg, p) ;
24  break;
25  }
26 }
27 
28 double Qw::result(const fastjet::PseudoJet &jet) const
29 {
30  std::vector<fastjet::PseudoJet> constituents = jet.constituents();
31  return result(constituents);
32 }
33 
34 
35 namespace {
36  void decomposeToJetMass(fastjet::PseudoJet & jet, double massCut, std::vector<fastjet::PseudoJet> & outSubJets){
37 
38  if(jet.m() < massCut ) {
39  outSubJets.push_back(jet);
40  return;
41  }
42 
43  // else decompose and apply procedure to parent
44  fastjet::PseudoJet p1, p2;
45  if( ! jet.has_parents (p1, p2) ) return ;
46  decomposeToJetMass(p1, massCut, outSubJets);
47  decomposeToJetMass(p2, massCut, outSubJets);
48 
49  }
50 
51 }
52 
53 double Qw::result(std::vector<fastjet::PseudoJet> &constituents) const {
54 
55  // deal with extreme cases first.
56  // early exit in this cases.
57  size_t nconst = constituents.size();
58  if( nconst < 3 ) return 0;
59 
60  // Build the subjets
61  fastjet::ClusterSequence cs(constituents, m_jetdef);
62 
63  double scaleF = 1.;
64 
65  std::vector<fastjet::PseudoJet> outjets;
66 
67  switch( m_vMode) {
68  case Normal :
69  outjets= cs.exclusive_jets(3);
70  //std::cout << " Normal mode : scaleF " << scaleF << " m1="<< outjets[0].m() << std::endl;
71 
72  break;
73 
74  case MassCut: {
75  outjets= cs.exclusive_jets(3);
76  fastjet::PseudoJet sumTot(0,0,0,0) ;
77  sumTot = outjets[0] + outjets[1] + outjets[2];
78 
79  // make sure we deal only with subjets with mass < m_massCut
80  std::vector<fastjet::PseudoJet> tmp_subjets; tmp_subjets.reserve(4);
81  decomposeToJetMass(outjets[0], m_massCut , tmp_subjets);
82  decomposeToJetMass(outjets[1], m_massCut , tmp_subjets);
83  decomposeToJetMass(outjets[2], m_massCut , tmp_subjets);
84  // Take the 3 highest pt subjets.
85  outjets = fastjet::sorted_by_pt( tmp_subjets) ;
86  outjets.resize(3);
87 
88 
89  // resum the 3 highest pt subjets to compute the scale factor.
90  fastjet::PseudoJet sumSubJ(0,0,0,0);
91  sumSubJ = outjets[0] + outjets[1] + outjets[2];
92  scaleF = sumTot.pt()/sumSubJ.pt();
93  // std::cout << " MassCut mode : scaleF " << scaleF << " m1="<< outjets[0].m() << std::endl;
94 
95  }
96  break;
97  case SmallSubjets: {
98  outjets = fastjet::sorted_by_pt(cs.inclusive_jets());
99 
100  // deal with extreme case first.
101  // early exit in this case.
102  size_t nsubjets = outjets.size();
103  if( nsubjets < 3 ) return 0;
104 
105  // compute the scale factor : as we choose only the 1st 3 subjets,
106  // we scale back the contribution of these 3 subjets to the total Pt.
107  fastjet::PseudoJet sumTot(0,0,0,0), sumSubJ(0,0,0,0);
108  for( fastjet::PseudoJet& c: constituents) sumTot+=c;
109 
110  // take the 3 highest subjets only
111  outjets.resize(3);
112 
113  for( fastjet::PseudoJet& c: outjets ) sumSubJ+=c;
114  scaleF = sumTot.pt()/sumSubJ.pt();
115  // std::cout << " SmallSubjets mode : scaleF " << scaleF << " m1="<< outjets[0].m() << std::endl;
116  }
117  break;
118  }
119 
120  double m12 = (outjets[0]+outjets[1]).m();
121  double m23 = (outjets[2]+outjets[1]).m();
122  double m13 = (outjets[2]+outjets[0]).m();
123 
124  // std::cout << " ---------> qw="<< scaleF*std::min(m12, std::min(m23,m13) ) << std::endl;
125  return scaleF*std::min(m12, std::min(m23,m13) );
126 }
127 
128 
JetSubStructureUtils::Qw::Normal
@ Normal
Definition: Qw.h:39
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
JetSubStructureUtils::Qw::m_massCut
double m_massCut
Definition: Qw.h:58
JetSubStructureUtils
Definition: Angularity.h:10
JetSubStructureUtils::Qw::m_jetdef
fastjet::JetDefinition m_jetdef
Definition: Qw.h:56
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
jet::ClusterSequence
fastjet::ClusterSequence ClusterSequence
Definition: ClusterSequence.h:21
jet::CompScaleVar::Qw
@ Qw
Definition: UncertaintyEnum.h:107
Preparation.mode
mode
Definition: Preparation.py:94
JetSubStructureUtils::Qw::QwVariant
QwVariant
describes the differnt calculation variants
Definition: Qw.h:38
JetSubStructureUtils::Qw::SmallSubjets
@ SmallSubjets
Definition: Qw.h:41
JetSubStructureUtils::Qw::MassCut
@ MassCut
Definition: Qw.h:40
Qw.h
JetSubStructureUtils::Qw::m_vMode
QwVariant m_vMode
Definition: Qw.h:55
JetSubStructureUtils::Qw::result
virtual double result(const fastjet::PseudoJet &jet) const
SubstructureCalculator interface.
Definition: Qw.cxx:28
python.compressB64.c
def c
Definition: compressB64.py:93