jFEXDriver.cxx 9.41 KB
Newer Older
1
/*
2
    Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
*/


#undef NDEBUG

#include "CaloEvent/CaloCellContainer.h"
#include "CaloIdentifier/CaloIdManager.h"
#include "CaloIdentifier/CaloCell_SuperCell_ID.h"

#include "xAODTrigL1Calo/TriggerTowerContainer.h"

#include "L1CaloFEXSim/jTower.h"
#include "L1CaloFEXSim/jTowerBuilder.h"
#include "L1CaloFEXSim/jFEXDriver.h"

#include "L1CaloFEXSim/jSuperCellTowerMapper.h"

#include "L1CaloFEXSim/jFEXSim.h"
21
22
#include "L1CaloFEXSim/jFEXOutputCollection.h"
#include "L1CaloFEXSim/jFEXSmallRJetTOB.h"
23
24
#include "L1CaloFEXSim/jFEXLargeRJetTOB.h"
#include "L1CaloFEXSim/jFEXtauTOB.h"
25

26

27
28
29
#include "TROOT.h"
#include "TH1.h"
#include "TH1F.h"
30
#include "TH1I.h"
31
#include "TPad.h"
32
#include "TFile.h"
33
34
35
36
37
38
39
#include "TCanvas.h"

#include "StoreGate/WriteHandle.h"
#include "StoreGate/ReadHandle.h"

#include "L1CaloFEXSim/jTowerContainer.h"

Varsiha Sothilingam's avatar
Varsiha Sothilingam committed
40
41
42
#include "xAODTrigger/jFexSRJetRoI.h"
#include "xAODTrigger/jFexSRJetRoIContainer.h" 

43
44
45
46
47
48
#include "xAODTrigger/jFexLRJetRoI.h"
#include "xAODTrigger/jFexLRJetRoIContainer.h"

#include "xAODTrigger/jFexTauRoI.h"
#include "xAODTrigger/jFexTauRoIContainer.h" 

49
50
#include <cassert>
#include "SGTools/TestStore.h"
51
#include "PathResolver/PathResolver.h"
52
53
54
55
56
57
58
#include <ctime>

#define DEBUG_VHB 1


namespace LVL1 {

59
60
61
62
jFEXDriver::jFEXDriver(const std::string& name, ISvcLocator* pSvcLocator):  AthAlgorithm(name, pSvcLocator){
    declareProperty("PileupWeigthFile", m_PileupWeigthFile = "Run3L1CaloSimulation/Noise/jTowerCorrection.20210308.r12406.root");
    declareProperty("PileupHelperFile", m_PileupHelperFile = "Run3L1CaloSimulation/Calibrations/jFEX_MatchedMapping.2021Oct14.r12406.root");
}
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79


 jFEXDriver::~jFEXDriver()
{
  ATH_MSG_DEBUG("Destroying " << name() << "...");
}


StatusCode jFEXDriver::initialize()
{

  m_numberOfEvents = 1;

  ATH_CHECK( m_jTowerBuilderTool.retrieve() );
  ATH_CHECK( m_jSuperCellTowerMapperTool.retrieve() );
  ATH_CHECK( m_jFEXSysSimTool.retrieve() );
  ATH_CHECK( m_jTowerContainerSGKey.initialize() );
Varsiha Sothilingam's avatar
Varsiha Sothilingam committed
80
  ATH_CHECK( m_jFexSRJetEDMKey.initialize() );
81
82
  ATH_CHECK( m_jFexLRJetEDMKey.initialize() );
  ATH_CHECK( m_jFexTauEDMKey.initialize() );
83
  ATH_CHECK( m_jFEXOutputCollectionSGKey.initialize() );
84
85
86
87
88
89
90
91
92
93
94
95
96

  return StatusCode::SUCCESS;

}


StatusCode jFEXDriver::finalize()
{
  ATH_MSG_DEBUG("Finalizing " << name() << "...");
  return StatusCode::SUCCESS;
}


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
StatusCode jFEXDriver::execute() {
    
    ATH_MSG_DEBUG("Executing " << name() << ", processing event number " << m_numberOfEvents );

    // OLD DIMA STUFF---------------------- Maybe useful in the future again
    //if (std::fabsf((*cell)->eta()) > 2.55) continue;
    //if (!((*cell)->provenance() & 0x40)) continue; // BCID cut
    //// if (!((*cell)->provenance() & 0x200)) continue;
    //// 8192 & 0x40 = 0
    //// 8256 & 0x40 = 64
    //// 8704 & 0x40 = 0
    //// 8768 & 0x40 = 64

    // STEP 0 - Make a fresh local jTowerContainer
    std::unique_ptr<jTowerContainer> local_jTowerContainerRaw = std::make_unique<jTowerContainer>();
    std::unique_ptr<TFile> jTowerFile(TFile::Open(PathResolver::find_calib_file(m_PileupWeigthFile).c_str()));
    std::unique_ptr<TFile> jTowerMapFile(TFile::Open(PathResolver::find_calib_file(m_PileupHelperFile).c_str()));
    if (!jTowerFile || jTowerFile->IsZombie()) {
        ATH_MSG_ERROR("Failed to open cell timing file " << m_PileupWeigthFile);
        return StatusCode::FAILURE;
    }
    if (!jTowerMapFile || jTowerMapFile->IsZombie()) {
        ATH_MSG_ERROR("Failed to open cell timing file " << m_PileupHelperFile);
        return StatusCode::FAILURE;
    }    
    
    TH1F* jTowerArea_hist    = (TH1F*) jTowerFile->Get("jTowerArea_final_hist");
    TH1I* Firmware2BitwiseID = (TH1I*) jTowerMapFile->Get("Firmware2BitwiseID");
    TH1I* BinLayer           = (TH1I*) jTowerMapFile->Get("BinLayer");
    TH1F* EtaCoords          = (TH1F*) jTowerMapFile->Get("EtaCoords");
    TH1F* PhiCoords          = (TH1F*) jTowerMapFile->Get("PhiCoords");
    
    //detach the Histograms from the TFiles
    jTowerArea_hist->SetDirectory(0);
    Firmware2BitwiseID->SetDirectory(0);
    BinLayer->SetDirectory(0);
    EtaCoords->SetDirectory(0);
    PhiCoords->SetDirectory(0);
    
    jTowerFile->Close();
    jTowerMapFile->Close();


    // STEP 1 TO BE REPLACED IN THE NEAR FUTURE - KEPT HERE FOR REFERENCE
    // STEP 1 - Do some monitoring (code to exported in the future to another algorithm accessing only StoreGate and not appearing in this algorithm)
    jFEXOutputCollection* my_jFEXOutputCollection = new jFEXOutputCollection();
    my_jFEXOutputCollection->setdooutput(true);

    // STEP 2 - Make some jTowers and fill the local container
    m_jTowerBuilderTool->init(local_jTowerContainerRaw);
    local_jTowerContainerRaw->clearContainerMap();
    local_jTowerContainerRaw->fillContainerMap();
    
    // STEP 3 - Do the supercell-tower mapping - put this information into the jTowerContainer
    ATH_CHECK(m_jSuperCellTowerMapperTool->AssignSuperCellsToTowers(local_jTowerContainerRaw));
    ATH_CHECK(m_jSuperCellTowerMapperTool->AssignTriggerTowerMapper(local_jTowerContainerRaw));
    ATH_CHECK(m_jSuperCellTowerMapperTool->AssignPileupAndNoiseValues(local_jTowerContainerRaw,jTowerArea_hist,Firmware2BitwiseID,BinLayer,EtaCoords,PhiCoords));

    // STEP 4 - Write the completed jTowerContainer into StoreGate (move the local copy in memory)
    SG::WriteHandle<LVL1::jTowerContainer> jTowerContainerSG(m_jTowerContainerSGKey/*, ctx*/);
    ATH_CHECK(jTowerContainerSG.record(std::move(/*my_jTowerContainerRaw*/local_jTowerContainerRaw)));

    // STEP 5 - Set up the jFEXSysSim
    m_jFEXSysSimTool->init();


    // STEP 6 - Run THE jFEXSysSim
    ATH_CHECK(m_jFEXSysSimTool->execute(my_jFEXOutputCollection));
    
    //STEP 6.5- test the EDMs
    ATH_CHECK(testSRJetEDM());
    ATH_CHECK(testLRJetEDM());
    ATH_CHECK(testTauEDM());

    // STEP 7 - Close and clean the event  
    m_jFEXSysSimTool->cleanup();
    m_jSuperCellTowerMapperTool->reset();
    m_jTowerBuilderTool->reset();

    // STEP 8 - Write the completed jFEXOutputCollection into StoreGate (move the local copy in memory)
    std::unique_ptr<jFEXOutputCollection> local_jFEXOutputCollection = std::unique_ptr<jFEXOutputCollection>(my_jFEXOutputCollection);
    SG::WriteHandle<LVL1::jFEXOutputCollection> jFEXOutputCollectionSG(m_jFEXOutputCollectionSGKey);
    ATH_CHECK(jFEXOutputCollectionSG.record(std::move(local_jFEXOutputCollection)));

    ATH_MSG_DEBUG("Executed " << name() << ", closing event number " << m_numberOfEvents );

    m_numberOfEvents++;

    return StatusCode::SUCCESS;
186
}
Varsiha Sothilingam's avatar
Varsiha Sothilingam committed
187

188
StatusCode jFEXDriver::testSRJetEDM(){
Varsiha Sothilingam's avatar
Varsiha Sothilingam committed
189
190
191
192
193
194
195
196
197
198
199
  const xAOD::jFexSRJetRoI* myRoI = 0;
  SG::ReadHandle<xAOD::jFexSRJetRoIContainer> myRoIContainer(m_jFexSRJetEDMKey);
    if(!myRoIContainer.isValid()){
      ATH_MSG_FATAL("Could not retrieve EDM Container " << m_jFexSRJetEDMKey.key());
      return StatusCode::FAILURE;
   }

    ATH_MSG_DEBUG("----got container: " << myRoIContainer.key());

    for(const auto& it : * myRoIContainer){
      myRoI = it;
200
      ATH_MSG_DEBUG("SR Jet EDM jFex Number: "
201
            << +myRoI->jFexNumber() // returns an 8 bit unsigned integer referring to the jFEX number
202
203
204
205
206
207
208
            << " et: "
            << myRoI->et() // returns the et value of the EM cluster in MeV
            << " eta: "
            << myRoI->eta() // returns a floating point global eta (will be at full precision 0.025, but currently only at 0.1)
            << " phi: "
            << myRoI->phi() // returns a floating point global phi
            );
Varsiha Sothilingam's avatar
Varsiha Sothilingam committed
209
210
211
212
213
    }

    return StatusCode::SUCCESS;
}  

214
215
216
217
218
219
220
221
222
223
224
225
226
227
StatusCode jFEXDriver::testLRJetEDM(){

  const xAOD::jFexLRJetRoI* myRoI = 0;
  SG::ReadHandle<xAOD::jFexLRJetRoIContainer> myRoIContainer(m_jFexLRJetEDMKey);
    if(!myRoIContainer.isValid()){
      ATH_MSG_FATAL("Could not retrieve EDM Container " << m_jFexLRJetEDMKey.key());
      return StatusCode::FAILURE;
   }

    ATH_MSG_DEBUG("----got container: " << myRoIContainer.key());

    for(const auto& it : * myRoIContainer){
      myRoI = it;
      ATH_MSG_DEBUG("LR Jet EDM jFex Number: "
228
            << +myRoI->jFexNumber() // returns an 8 bit unsigned integer referring to the jFEX number
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
            << " et: "
            << myRoI->et() // returns the et value of the EM cluster in MeV
            << " eta: "
            << myRoI->eta() // returns a floating point global eta (will be at full precision 0.025, but currently only at 0.1)
            << " phi: "
            << myRoI->phi() // returns a floating point global phi
            );
    }

    return StatusCode::SUCCESS;
}

StatusCode jFEXDriver::testTauEDM(){

  const xAOD::jFexTauRoI* myRoI = 0;
  SG::ReadHandle<xAOD::jFexTauRoIContainer> myRoIContainer(m_jFexTauEDMKey);
    if(!myRoIContainer.isValid()){
      ATH_MSG_FATAL("Could not retrieve EDM Container " << m_jFexTauEDMKey.key());
      return StatusCode::FAILURE;
   }

    ATH_MSG_DEBUG("----got container: " << myRoIContainer.key());

    for(const auto& it : * myRoIContainer){
      myRoI = it;
      ATH_MSG_DEBUG("EDM jFex Number: "
255
            << +myRoI->jFexNumber() // returns an 8 bit unsigned integer referring to the jFEX number
256
257
258
259
260
261
262
263
264
265
266
267
            << " et: "
            << myRoI->et() // returns the et value of the EM cluster in MeV
            << " eta: "
            << myRoI->eta() // returns a floating point global eta (will be at full precision 0.025, but currently only at 0.1)
            << " phi: "
            << myRoI->phi() // returns a floating point global phi
            );
    }

    return StatusCode::SUCCESS;
}

268
} // end of LVL1 namespace