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


//! PanTau includes
#include "PanTauAlgs/Tool_InputConverter.h"
#include "PanTauAlgs/Tool_InformationStore.h"
#include "PanTauAlgs/TauConstituent.h"
#include "PanTauAlgs/PanTauSeed.h"
11
#include "PanTauAlgs/HelperFunctions.h"
12
13
14
15
16
17
18
19
20
21
22
23
24

//! xAOD EDM
#include "xAODTau/TauJet.h"
#include "xAODPFlow/PFO.h"
#include "xAODPFlow/PFODefs.h"


PanTau::Tool_InputConverter::Tool_InputConverter(
    const std::string& name ) :
        asg::AsgTool(name),
        m_Tool_InformationStore("PanTau::Tool_InformationStore/Tool_InformationStore")
{
    declareProperty("Tool_InformationStore",     m_Tool_InformationStore, "Link to tool with all information");
25
    declareProperty("Tool_InformationStoreName", m_Tool_InformationStoreName="", "Optional Name for InformationStore insance in ABR");
26
27
28
29
30
31
32
33
}

PanTau::Tool_InputConverter::~Tool_InputConverter() {
}

StatusCode PanTau::Tool_InputConverter::initialize() {

    ATH_MSG_INFO(" initialize()");
34
35
36
37
    m_init=true;

    ATH_CHECK( HelperFunctions::bindToolHandle( m_Tool_InformationStore, m_Tool_InformationStoreName) ); //ABR only

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
    ATH_CHECK( m_Tool_InformationStore.retrieve() );
    
    ATH_CHECK( m_Tool_InformationStore->getInfo_Int("TauConstituents_UsePionMass", m_Config_UsePionMass) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_Int("TauConstituents_UseShrinkingCone", m_Config_TauConstituents_UseShrinkingCone) );
    
    
    ATH_CHECK( m_Tool_InformationStore->getInfo_Double("TauConstituents_Types_DeltaRCore", m_Config_TauConstituents_Types_DeltaRCore) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_Double("TauConstituents_PreselectionMinEnergy", m_Config_TauConstituents_PreselectionMinEnergy) );
    
    
    ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_BinEdges_Eta", m_Config_CellBased_BinEdges_Eta) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_EtaBinned_Pi0MVACut_1prong", m_Config_CellBased_EtaBinned_Pi0MVACut_1prong) );
    ATH_CHECK( m_Tool_InformationStore->getInfo_VecDouble("CellBased_EtaBinned_Pi0MVACut_3prong", m_Config_CellBased_EtaBinned_Pi0MVACut_3prong) );  

    return StatusCode::SUCCESS;
}


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


bool    PanTau::Tool_InputConverter::passesPreselectionEnergy(double itsEnergy) const {
    if(itsEnergy < m_Config_TauConstituents_PreselectionMinEnergy) return false;
    return true;
}



//! ============================================
//! PFO converter
//! ============================================


StatusCode PanTau::Tool_InputConverter::ConvertToTauConstituent2(xAOD::PFO* pfo,
                                                                PanTau::TauConstituent2* &tauConstituent,
                                                                const xAOD::TauJet* tauJet) const {
    //
    
    //! ==================================================
    //! check for invalid eta, phi, e "NAN" values:
    //!
    if(pfo->eta() != pfo->eta()) {
        ATH_MSG_WARNING("Will not convert PFO with eta value of " << pfo->eta() << " -> return to Tool_TauConstituentGetter");
        return StatusCode::SUCCESS;
    }
    if(pfo->phi() != pfo->phi()) {
        ATH_MSG_WARNING("Will not convert PFO with phi value of " << pfo->phi() << " -> return to Tool_TauConstituentGetter");
        return StatusCode::SUCCESS;
    }
    if(pfo->e() != pfo->e()) {
        ATH_MSG_WARNING("Will not convert PFO with e value of " << pfo->e() << " -> return to Tool_TauConstituentGetter");
        return StatusCode::SUCCESS;
    }
    
    
    //! ==================================================
    //! Check whether neutral input pfo has pion mass (it may have if xAOD is being reprocessed)
    //! If it does, make it massless again and use that
    if(pfo->charge() == 0 && pfo->m() != 0) {
        TLorentzVector tlvUpdate; 
        PanTau::SetP4EEtaPhiM( tlvUpdate, pfo->e(), pfo->eta(), pfo->phi(), 0);
        pfo->setP4(tlvUpdate.Pt(), pfo->eta(), pfo->phi(), 0);
    }
    
    //! ==================================================
    //! preselection to veto very low energetic PFOs:
    int     pfoCharge       = (int)(pfo->charge());
    double constituentEnergy = pfo->e();
    if (passesPreselectionEnergy(constituentEnergy) == false) {
        ATH_MSG_DEBUG("EFO of charge " << pfoCharge << " and energy " << constituentEnergy << " does not pass presel Energy cut of " << m_Config_TauConstituents_PreselectionMinEnergy);
        return StatusCode::SUCCESS;
    }
    
    
    //! ==================================================
    //! get the mass correct & build 4-vector
    double  constituentMass = pfo->m();
    if(m_Config_UsePionMass == true) {
        
        //clusters: don't touch the measured energy. set mass to pion mass, so momentum will be altered
        if(pfoCharge == 0) {
            constituentMass = 134.98;
        }
   }

 
    ATH_MSG_DEBUG("About to create 4 vector of EFO. E / Eta / Phi / m: " << constituentEnergy << " / " << pfo->eta() << " / " << pfo->phi() << " / " << constituentMass);
    TLorentzVector momentum; 
    PanTau::SetP4EEtaPhiM( momentum, constituentEnergy, pfo->eta(), pfo->phi(), constituentMass);
    
    //! ==================================================
    //! get type (based on charge and DR to tau)
    std::vector<int> itsTypeFlags = std::vector<int>((unsigned int)PanTau::TauConstituent2::t_nTypes, 0);
    itsTypeFlags.at((int)PanTau::TauConstituent2::t_NoType) = 1;
    
    double mvaValue         = PanTau::TauConstituent2::DefaultBDTValue();

    TLorentzVector tlv_intAxis = tauJet->p4(xAOD::TauJetParameters::IntermediateAxis);
    double deltaR_toTauJet = tlv_intAxis.DeltaR( pfo->p4() );
    
    if(deltaR_toTauJet > m_Config_TauConstituents_Types_DeltaRCore) {
        if(pfoCharge != 0) {
            itsTypeFlags.at((int)PanTau::TauConstituent2::t_OutChrg) = 1;
        }
        if(pfoCharge == 0) {
            itsTypeFlags.at((int)PanTau::TauConstituent2::t_OutNeut) = 1;
            mvaValue = pfo->bdtPi0Score();
        }
    }//end if pfo is not in core
    
    if(deltaR_toTauJet <= m_Config_TauConstituents_Types_DeltaRCore) {
    
        if(pfoCharge != 0) {
            itsTypeFlags.at((int)PanTau::TauConstituent2::t_Charged) = 1;
        }
        if(pfoCharge == 0) {
            itsTypeFlags.at((int)PanTau::TauConstituent2::t_Neutral) = 1;
            itsTypeFlags.at((int)PanTau::TauConstituent2::t_NeutLowA) = 1;
            itsTypeFlags.at((int)PanTau::TauConstituent2::t_NeutLowB) = 1;
            
            //neutral PFO arranging --- check for pi0 tag
            mvaValue = pfo->bdtPi0Score();
            
            // bool isThreeProng = false;
            // if(tauJet->nTracks() == 3) isThreeProng = true;
            // ATH_MSG_DEBUG("numTrack = " << tauJet->nTracks() << ", is Threeprong = " << isThreeProng);

	    int nPi0sPerCluster = 0;
	    if( !pfo->attribute(xAOD::PFODetails::nPi0Proto, nPi0sPerCluster) ) {
	      ATH_MSG_WARNING("WARNING: Could not retrieve nPi0Proto. Will set it to 1.");
	      nPi0sPerCluster = 1;
	    }
	    if(nPi0sPerCluster > 0)  itsTypeFlags.at((int)PanTau::TauConstituent2::t_Pi0Neut) = 1;

        }
    }//end if pfo is in core
    
    
    //! ==================================================
    //! create the tau constituent
    tauConstituent = new PanTau::TauConstituent2(momentum, pfoCharge, itsTypeFlags, mvaValue, pfo);
    tauConstituent->makePrivateStore();
    ATH_MSG_DEBUG("Created new TauConstituent2 at: " << tauConstituent);
    ATH_MSG_DEBUG("\t Eta value of its 4-vector: " << momentum.Eta());
    
    //! ==================================================
    //! Check if the pfo object has shots:
    std::vector<const xAOD::IParticle*> list_TauShots = std::vector<const xAOD::IParticle*>(0);
    bool shotsOK = pfo->associatedParticles(xAOD::PFODetails::TauShot, list_TauShots);
    if(shotsOK == false) {
        ATH_MSG_DEBUG("WARNING: Could not get shots from current pfo");
    }
    
    ATH_MSG_DEBUG("Number of shots in cluster:" << list_TauShots.size());
    if(list_TauShots.size() > 0) {
        ATH_MSG_DEBUG("Now converting shots of cluster with E, Eta, Phi, M: " << momentum.E() << ", " << momentum.Eta() << ", " << momentum.Phi() << ", " << momentum.M());
        for(unsigned int iShot=0; iShot<list_TauShots.size(); iShot++) {
        
            if(list_TauShots.at(iShot) == 0) {
                ATH_MSG_WARNING("Shot number " << iShot << " points to 0! Skip it");
                continue;
            }
        
            xAOD::PFO*              curShot         = const_cast<xAOD::PFO*>( dynamic_cast<const xAOD::PFO*>(list_TauShots.at(iShot)) );
            ATH_MSG_DEBUG("Checking shot E, Eta, Phi, M: " << curShot->e() << ", " << curShot->eta() << ", " << curShot->phi() << ", " << curShot->m());
            TLorentzVector          shotMomentum;
	    PanTau::SetP4EEtaPhiM( shotMomentum, curShot->e(), curShot->eta(), curShot->phi(), curShot->m());
            std::vector<int>        shotTypeFlags   = std::vector<int>((unsigned int)PanTau::TauConstituent2::t_nTypes, 0);
            double                  shotMVAValue    = PanTau::TauConstituent2::DefaultBDTValue();
            PanTau::TauConstituent2* shotConstituent = new PanTau::TauConstituent2(shotMomentum, 0, itsTypeFlags, shotMVAValue, curShot);
	    shotConstituent->makePrivateStore();
            ATH_MSG_DEBUG("\tAdded shot with E, Eta, Phi, M: " << shotMomentum.E() << ", " << shotMomentum.Eta() << ", " << shotMomentum.Phi() << ", " << shotMomentum.M());
            
            int nPhotons = 0;
            if( curShot->attribute(xAOD::PFODetails::tauShots_nPhotons, nPhotons) == false) {
                nPhotons = -1;
                ATH_MSG_DEBUG("WARNING: Could not get nPhotons for this shot! Set to -1");
            }
            shotConstituent->setNPhotonsInShot(nPhotons);
            ATH_MSG_DEBUG("\tThe shot has " << shotConstituent->getNPhotonsInShot() << " photons in it");
            tauConstituent->addShot(shotConstituent);
            
        }//end loop over shots
    }
    
    return StatusCode::SUCCESS;
}