Tool_DecayModeDeterminator.cxx 17.7 KB
Newer Older
1
2
3
4
5
6
7
8
/*
  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/


//! PanTau includes
#include "PanTauAlgs/Tool_DecayModeDeterminator.h"

9
10
11
12
#include "PanTauAlgs/PanTauSeed.h"
#include "PanTauAlgs/TauClassificationTypes.h"

#include "xAODTau/TauDefs.h"
13
14
15
16



PanTau::Tool_DecayModeDeterminator::Tool_DecayModeDeterminator(
17
18
    const std::string& name ) :
        asg::AsgTool(name),
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
        m_Tool_InformationStore("PanTau::Tool_InformationStore/Tool_InformationStore"),
        m_Tool_ModeDiscriminator_1p0n_vs_1p1n("PanTau::Tool_ModeDiscriminator/Tool_ModeDiscriminator"),
        m_Tool_ModeDiscriminator_1p1n_vs_1pXn("PanTau::Tool_ModeDiscriminator/Tool_ModeDiscriminator"),
        m_Tool_ModeDiscriminator_3p0n_vs_3pXn("PanTau::Tool_ModeDiscriminator/Tool_ModeDiscriminator")
        {

    declareProperty("Tool_InformationStore",          m_Tool_InformationStore,          "Tool handle to the information store tool");
    declareProperty("Tool_ModeDiscriminator_1p0n_vs_1p1n",    m_Tool_ModeDiscriminator_1p0n_vs_1p1n,    "Handle to the ModeDiscriminator tool for 1p0n_vs_1p1n");
    declareProperty("Tool_ModeDiscriminator_1p1n_vs_1pXn",    m_Tool_ModeDiscriminator_1p1n_vs_1pXn,    "Handle to the ModeDiscriminator tool for 1p1n_vs_1pXn");
    declareProperty("Tool_ModeDiscriminator_3p0n_vs_3pXn",    m_Tool_ModeDiscriminator_3p0n_vs_3pXn,    "Handle to the ModeDiscriminator tool for 3p0n_vs_3pXn");
}



PanTau::Tool_DecayModeDeterminator::~Tool_DecayModeDeterminator() {
}



StatusCode PanTau::Tool_DecayModeDeterminator::initialize() {
    ATH_MSG_INFO( name() << " initialize()" );
    
    //get the discri tools
42
43
44
    ATH_CHECK(m_Tool_ModeDiscriminator_1p0n_vs_1p1n.retrieve());
    ATH_CHECK(m_Tool_ModeDiscriminator_1p1n_vs_1pXn.retrieve());
    ATH_CHECK(m_Tool_ModeDiscriminator_3p0n_vs_3pXn.retrieve());
45
46
    
    //get the variable prefix
47
48
    ATH_CHECK( m_Tool_InformationStore->getInfo_String("FeatureExtractor_VarTypeName_varTypeName_Basic",        m_varTypeName_Prefix_Basic) );

49
    //get the BDT cut values
50
51
52
53
54
55
56
    ATH_CHECK( m_Tool_InformationStore->getInfo_Double("DecayModeDeterminator_BDTCutValue_R10X_CellBased",        m_BDTCutValue_R10X_CellBased) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_Double("DecayModeDeterminator_BDTCutValue_R11X_CellBased",        m_BDTCutValue_R11X_CellBased) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_Double("DecayModeDeterminator_BDTCutValue_R110_CellBased",        m_BDTCutValue_R110_CellBased) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_Double("DecayModeDeterminator_BDTCutValue_R1XX_CellBased",        m_BDTCutValue_R1XX_CellBased) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_Double("DecayModeDeterminator_BDTCutValue_R30X_CellBased",        m_BDTCutValue_R30X_CellBased) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_Double("DecayModeDeterminator_BDTCutValue_R3XX_CellBased",        m_BDTCutValue_R3XX_CellBased) );

57
58
59
60
61
62
63
64
65
66
67
68
69
70
    return StatusCode::SUCCESS;
}



// StatusCode PanTau::Tool_DecayModeDeterminator::finalize() {
//     StatusCode sc = AlgTool::finalize();
//     return sc;
// }





71
StatusCode PanTau::Tool_DecayModeDeterminator::execute(PanTau::PanTauSeed2* inSeed) {
72
73
    
    
74
    ATH_MSG_DEBUG("determine DecayMode for inSeed at " << inSeed);
75
    std::string         inAlgName   = inSeed->getNameInputAlgorithm();
76
    PanTau::TauFeature2* features    = inSeed->getFeatures();
77
78
79
    
    
    //check for invalid input seed
80
81
82
    bool    noValidInput        = inSeed->isOfTechnicalQuality(PanTau::PanTauSeed2::t_NoValidInputTau);
    bool    noAnyConstituents   = inSeed->isOfTechnicalQuality(PanTau::PanTauSeed2::t_NoConstituentsAtAll);
    bool    noSelConstituents   = inSeed->isOfTechnicalQuality(PanTau::PanTauSeed2::t_NoSelectedConstituents);
83
84
    bool    invalidForDecayMode = (noValidInput || noAnyConstituents || noSelConstituents);
    if(invalidForDecayMode) {
85
        ATH_MSG_DEBUG("Seed has no constituents assigned and/or input seed has no substructure info - use NotSet mode for this");
86
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_RecoMode_PanTau", xAOD::TauJetParameters::Mode_NotSet);
87
88
89
90
91
92
        return StatusCode::SUCCESS;
    }
    
    
    //get the mode as it was determined by the subalgorithm
    int decayMode_SubAlg = inSeed->getDecayModeBySubAlg();
93
    int decayMode_PanTau = xAOD::TauJetParameters::Mode_NotSet;
94
95
    
    //and calc the number of additional neutrals, not tagged as pi0
96
97
98
    int nCharged_SubAlg     = inSeed->getNumberOfConstituentsOfType(PanTau::TauConstituent2::t_Charged);
    int nPi0Neut_SubAlg     = inSeed->getNumberOfConstituentsOfType(PanTau::TauConstituent2::t_Pi0Neut);
    int nNeutrals_SubAlg    = inSeed->getNumberOfConstituentsOfType(PanTau::TauConstituent2::t_Neutral);
99
100
101
102
103
104
105
106
107
    int AdditionalNeutrals = nNeutrals_SubAlg - nPi0Neut_SubAlg;
    
    double BDTCutValue_R10X = 0.;
    double BDTCutValue_R110 = 0.;
    double BDTCutValue_R11X = 0.;
    double BDTCutValue_R1XX = 0.;
    double BDTCutValue_R30X = 0.;
    double BDTCutValue_R3XX = 0.;
    
108
109
110
111
112
113
    BDTCutValue_R10X = m_BDTCutValue_R10X_CellBased;
    BDTCutValue_R110 = m_BDTCutValue_R110_CellBased;
    BDTCutValue_R11X = m_BDTCutValue_R11X_CellBased;
    BDTCutValue_R1XX = m_BDTCutValue_R1XX_CellBased;
    BDTCutValue_R30X = m_BDTCutValue_R30X_CellBased;
    BDTCutValue_R3XX = m_BDTCutValue_R3XX_CellBased;
114
115
    
    //based on the subAlg decay mode, pass to corresponding PanTau BDT...
116
    ATH_MSG_DEBUG("The subalg mode is set by nChrg/nPi0Neut/nAddNeut = " << nCharged_SubAlg << " / " << nPi0Neut_SubAlg << " / " << AdditionalNeutrals << " to " << decayMode_SubAlg << " - " << PanTau::PanTauSeed2::getDecayModeName(decayMode_SubAlg));
117
118
119
120
    
    double          bdtResponse = -5;
    DecayModeTest   bdtTest     = t_UnknownTest;
    // 1p0n mode
121
    if(decayMode_SubAlg == xAOD::TauJetParameters::Mode_1p0n) {
122
123
124
125
126
        
        
        //1 prong, and no other objects at all -> use 1p0n
        if(AdditionalNeutrals == 0) {
            ATH_MSG_DEBUG("Set 1p0n because there is only one object");
127
            decayMode_PanTau = xAOD::TauJetParameters::Mode_1p0n;
128
            bdtResponse = -3.;
129
130
131
            
        //if there are neutrals which are not pi0-tagged, check BDT to maybe set 1p1n
        } else {
132
133
134
135
136
137
138
139
140
	  /*
	  // simplify this code to:
	  bdtTest     = t_1p0n_vs_1p1n;
	  ATH_MSG_DEBUG("Entering bdtTest " << bdtTest);
	  decayMode_PanTau=GetPanTauDecayMode(inSeed, m_Tool_ModeDiscriminator_1p0n_vs_1p1n, BDTCutValue_R10X, bdtResponse);

	  int GetPanTauDecayMode(PanTauSeed2* inSeed, ToolHandle<PanTau::ITool_ModeDiscriminator> tool_ModeDiscriminator, int decayMode_SubAlg, double BDTCutValue, double &bdtResponse){
	  */

141
142
143
144
            bool    isOK        = false;
            bdtResponse = m_Tool_ModeDiscriminator_1p0n_vs_1p1n->getResponse(inSeed, isOK);
            bdtTest     = t_1p0n_vs_1p1n;
            if(isOK == false) {
145
                ATH_MSG_WARNING("WARNING: problems getting bdt response for 1p0n + X-neutrals. use subAlg mode");
146
147
                decayMode_PanTau = decayMode_SubAlg;
            } else {
148
149
150
                if(bdtResponse >  BDTCutValue_R10X) decayMode_PanTau = xAOD::TauJetParameters::Mode_1p0n;
                if(bdtResponse <= BDTCutValue_R10X) decayMode_PanTau = xAOD::TauJetParameters::Mode_1p1n;
                ATH_MSG_DEBUG("R10X: Response is: " << bdtResponse << "  Use 1p0n if > " << BDTCutValue_R10X << " -- decision: " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau) );
151
152
153
            }
        }
        
154
        ATH_MSG_DEBUG("SubAlgMode " << decayMode_SubAlg << ". Chrg/Neut: " << nCharged_SubAlg << " / " << nPi0Neut_SubAlg << ". Mode set to: " << decayMode_PanTau << " - " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau));
155
156
157
158
159
160
        
    }//end 1p0n
    
    
    
    //1p1n mode
161
    else if (decayMode_SubAlg == xAOD::TauJetParameters::Mode_1p1n) {
162
163
164
165
166
167
168
169
        
        
        //1prong, 1pi0 and no other neutrals. check 1p0n-vs-1p1n
        if(AdditionalNeutrals == 0) {
            bool    isOK        = false;
            bdtResponse = m_Tool_ModeDiscriminator_1p0n_vs_1p1n->getResponse(inSeed, isOK);
            bdtTest     = t_1p0n_vs_1p1n;
            if(isOK == false) {
170
                ATH_MSG_WARNING("WARNING problems getting bdt response for 1p1n + 0-neutrals. use subAlg mode");
171
172
                decayMode_PanTau = decayMode_SubAlg;
            } else {
173
174
175
                if(bdtResponse <= BDTCutValue_R110) decayMode_PanTau = xAOD::TauJetParameters::Mode_1p1n;
                if(bdtResponse >  BDTCutValue_R110) decayMode_PanTau = xAOD::TauJetParameters::Mode_1p0n;
                ATH_MSG_DEBUG("R110: Response is: " << bdtResponse << "  Use 1p0n if > " << BDTCutValue_R110 << " -- decision: " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau) );
176
177
178
179
180
181
182
183
184
185
            }
        
        
        //1prong, 1pi0 and additional neutrals. check 1p1n vs 1pXn
        } else {
            //NOTE: May investigate chain of decisions here: first check 1p0n-1p1n, and then (in case of 1p1n) 1p1n-1pXn
            bool    isOK        = false;
            bdtResponse = m_Tool_ModeDiscriminator_1p1n_vs_1pXn->getResponse(inSeed, isOK);
            bdtTest     = t_1p1n_vs_1pXn;
            if(isOK == false) {
186
                ATH_MSG_WARNING("WARNING problems getting bdt response for 1p1n + X-neutrals. use subAlg mode");
187
188
                decayMode_PanTau = decayMode_SubAlg;
            } else {
189
190
191
                if(bdtResponse >  BDTCutValue_R11X) decayMode_PanTau = xAOD::TauJetParameters::Mode_1p1n;
                if(bdtResponse <= BDTCutValue_R11X) decayMode_PanTau = xAOD::TauJetParameters::Mode_1pXn;
                ATH_MSG_DEBUG("R11X: Response is: " << bdtResponse << "  Use 1p1n if > " << BDTCutValue_R11X << " -- decision: " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau) );
192
193
194
            }
        }
        
195
        ATH_MSG_DEBUG("SubAlgMode " << decayMode_SubAlg << ". Chrg/Neut: " << nCharged_SubAlg << " / " << nPi0Neut_SubAlg << ". Mode set to: " << decayMode_PanTau << " - " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau));
196
197
198
199
200
    }//end 1p1n
    
    
    
    //1pXn mode
201
    else if (decayMode_SubAlg == xAOD::TauJetParameters::Mode_1pXn) {
202
203
204
205
206
207
        
        //1prong, Xpi0. check 1p1n-vs-1pXn
        bool    isOK        = false;
        bdtResponse = m_Tool_ModeDiscriminator_1p1n_vs_1pXn->getResponse(inSeed, isOK);
        bdtTest     = t_1p1n_vs_1pXn;
        if(isOK == false) {
208
            ATH_MSG_WARNING("WARNING problems getting bdt response for 1p1n + X-neutrals. use subAlg mode");
209
210
            decayMode_PanTau = decayMode_SubAlg;
        } else {
211
212
213
            if(bdtResponse >  BDTCutValue_R1XX) decayMode_PanTau = xAOD::TauJetParameters::Mode_1p1n;
            if(bdtResponse <= BDTCutValue_R1XX) decayMode_PanTau = xAOD::TauJetParameters::Mode_1pXn;
            ATH_MSG_DEBUG("R1XX: Response is: " << bdtResponse << "  Use 1p1n if > " << BDTCutValue_R1XX << " -- decision: " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau) );
214
215
        }
        
216
        ATH_MSG_DEBUG("SubAlgMode " << decayMode_SubAlg << ". Chrg/Neut: " << nCharged_SubAlg << " / " << nPi0Neut_SubAlg << ". Mode set to: " << decayMode_PanTau << " - " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau));
217
218
219
220
221
    }//end 1pXn
    
    
    
    //3p0n mode
222
    else if (decayMode_SubAlg == xAOD::TauJetParameters::Mode_3p0n) {
223
224
225
226
        
        //no additional neutrals. 
        if(AdditionalNeutrals == 0) {
            ATH_MSG_DEBUG("Set 3p0n because there are only charged objects");
227
            decayMode_PanTau = xAOD::TauJetParameters::Mode_3p0n;
228
            bdtResponse = -2.5;
229
230
231
232
233
234
235
236
            
        //additional neutrals
        } else {
            
            bool    isOK        = false;
            bdtResponse = m_Tool_ModeDiscriminator_3p0n_vs_3pXn->getResponse(inSeed, isOK);
            bdtTest     = t_3p0n_vs_3pXn;
            if(isOK == false) {
237
                ATH_MSG_WARNING("WARNING problems getting bdt response for 3p0n + X-neutrals. use subAlg mode");
238
239
                decayMode_PanTau = decayMode_SubAlg;
            } else {
240
241
242
                if(bdtResponse >  BDTCutValue_R30X) decayMode_PanTau = xAOD::TauJetParameters::Mode_3p0n;
                if(bdtResponse <= BDTCutValue_R30X) decayMode_PanTau = xAOD::TauJetParameters::Mode_3pXn;
                ATH_MSG_DEBUG("R30X: Response is: " << bdtResponse << "  Use 3p0n if > " << BDTCutValue_R30X << " -- decision: " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau) );
243
244
245
246
            }
            
        }
        
247
        ATH_MSG_DEBUG("SubAlgMode " << decayMode_SubAlg << ". Chrg/Neut: " << nCharged_SubAlg << " / " << nPi0Neut_SubAlg << ". Mode set to: " << decayMode_PanTau << " - " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau));
248
249
250
251
252
    }//end 3p0n
    
    
    
    //3pXn mode
253
    else if (decayMode_SubAlg == xAOD::TauJetParameters::Mode_3pXn) {
254
255
256
257
258
259
        
        //3prong, Xpi0. check 3p0n-vs-3pXn
        bool    isOK        = false;
        bdtResponse = m_Tool_ModeDiscriminator_3p0n_vs_3pXn->getResponse(inSeed, isOK);
        bdtTest     = t_3p0n_vs_3pXn;
        if(isOK == false) {
260
            ATH_MSG_WARNING("WARNING problems getting bdt response for 3p0n + X-neutrals. use subAlg mode");
261
262
            decayMode_PanTau = decayMode_SubAlg;
        } else {
263
264
265
            if(bdtResponse >  BDTCutValue_R3XX) decayMode_PanTau = xAOD::TauJetParameters::Mode_3p0n;
            if(bdtResponse <= BDTCutValue_R3XX) decayMode_PanTau = xAOD::TauJetParameters::Mode_3pXn;
            ATH_MSG_DEBUG("R3XX: Response is: " << bdtResponse << "  Use 3p0n if > " << BDTCutValue_R3XX << " -- decision: " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau) );
266
267
        }
        
268
        ATH_MSG_DEBUG("SubAlgMode " << decayMode_SubAlg << ". Chrg/Neut: " << nCharged_SubAlg << " / " << nPi0Neut_SubAlg << ". Mode set to: " << decayMode_PanTau << " - " << PanTau::PanTauSeed2::getDecayModeName(decayMode_PanTau));
269
270
271
272
273
274
275
    } //end 3pXn
    
    
    
    //it's none of 1p0n, 1p1n, 1pXn, 3p0n, 3pXn -> set other mode
    else {
        ATH_MSG_DEBUG("WARNING SubAlg mode of tau is not known. set the 'other' mode");
276
        decayMode_PanTau = xAOD::TauJetParameters::Mode_Other;
277
        bdtResponse = -4;
278
279
280
        bdtTest     = t_UnknownTest;
    }

281
    if(inAlgName != "CellBased") {
282
283
284
285
286
287
        ATH_MSG_WARNING("Name of input algorithm not known - use mode from sub alg!");
        decayMode_PanTau = decayMode_SubAlg;
        bdtResponse = -5;
        bdtTest     = t_UnknownTest;
    }
    
288
    // this overrides Pantau BDT 1p1n decision in the following case:
289
    // if cell based counted 1 charged, 1 pi0neut, and number of hits in EM1 for the pi0neut is 3 or larger, set 1pXn;
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    if(nCharged_SubAlg == 1 && nPi0Neut_SubAlg == 1) {
        ATH_MSG_DEBUG("CellBased decay mode 1p1n and a single neutral cluster - check for number of photons in cluster: if >2 then set decay mode 1pXn");
        //check for shots in EM1
        bool isOK = false;
        PanTau::TauConstituent2* pi0Neut = inSeed->getConstituentsOfType(PanTau::TauConstituent2::t_Pi0Neut, isOK).at(0);
        if(isOK == true) {
            double nPhotons = 0;
            std::vector<PanTau::TauConstituent2*> shots = pi0Neut->getShots();
            ATH_MSG_DEBUG("There are " << shots.size() << " shots in the pi0 Neutral");
            for(unsigned int iShot=0; iShot<shots.size(); iShot++) {
                nPhotons = nPhotons + (double)(shots.at(iShot)->getNPhotonsInShot());
            }
            ATH_MSG_DEBUG("Counted " << nPhotons << " photons in the pi0 neutral");
            if(nPhotons > 2) {
                decayMode_SubAlg = xAOD::TauJetParameters::Mode_1pXn;
                decayMode_PanTau = xAOD::TauJetParameters::Mode_1pXn;
                inSeed->setModeHackedByCellBased(true);
                bdtResponse = -2.;
308
            }
309
310
311
312
313
314
            
        //end check for pi0 neutrals were found
        } else {
            ATH_MSG_WARNING("Could not find expected CellBased neutral -> don't check for photons in cluster");
        }
    } //end hack check for 1p1n
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
    
    //update mode of seed and store in features
    ATH_MSG_DEBUG("Storing decay mode in tau and features: SubAlg/PanTau = " << (double)decayMode_SubAlg << " / " << (double)decayMode_PanTau);
    inSeed->setDecayModeByPanTau(decayMode_PanTau);
    features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_RecoMode", (double)decayMode_SubAlg);
    features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_RecoMode_PanTau", (double)decayMode_PanTau);
    
    if(bdtTest == t_1p0n_vs_1p1n) {
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_1p0n_vs_1p1n", bdtResponse);
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_1p1n_vs_1pXn", -5.);
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_3p0n_vs_3pXn", -5.);
    }
    if(bdtTest == t_1p1n_vs_1pXn) {
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_1p0n_vs_1p1n", -5.);
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_1p1n_vs_1pXn", bdtResponse);
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_3p0n_vs_3pXn", -5.);
    }
    if(bdtTest == t_3p0n_vs_3pXn) {
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_1p0n_vs_1p1n", -5.);
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_1p1n_vs_1pXn", -5.);
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_3p0n_vs_3pXn", bdtResponse);
    }
    if(bdtTest == t_UnknownTest) {
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_1p0n_vs_1p1n", -5.);
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_1p1n_vs_1pXn", -5.);
        features->addFeature(inAlgName + "_" + m_varTypeName_Prefix_Basic + "_BDTValue_3p0n_vs_3pXn", -5.);
    }
342

343
344
345
346
347
348
349
350
351
352
    return StatusCode::SUCCESS;
    
}