ATLAS Offline Software
Loading...
Searching...
No Matches
ringsHist.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4//
5// Create a histogram with offline rings information
6//
7
10
12
19
24
25#include "TChain.h"
26#include "TError.h"
27#include "TFile.h"
28#include "TCanvas.h"
29#include "TH1F.h"
30#include "TH2F.h"
31
32#include <iostream>
33
34using namespace std;
35using namespace xAOD;
36
37// Config
38const char* APP_NAME = "ringsHist";
39const char* OUTPUT_FILE = "histRings.root";
40
41// Helpers
42TChain *getChain(int argc, char* argv[], const char *chainName = "CollectionTree");
43
44int main( int argc, char* argv[] ) {
45
46 // Initialize (as done for all xAOD standalone programs!)
48
49 auto chain = getChain(argc, argv,"CollectionTree");
50 if (chain == nullptr) {
51 return 1;
52 }
53
54 const auto& ringsReader = getCaloRingsReader();
55
56 //
57 // Add initialization code for tools here
58 //
59
60 // The TEvent object
62 RETURN_CHECK( APP_NAME, event.readFrom(chain));
63
64 // Get an output file open, book events.
65 auto outputFile = TFile::Open(OUTPUT_FILE, "RECREATE");
66 if (outputFile == nullptr || !outputFile->IsOpen()) {
67 return 1;
68 }
69
70 auto hRingsE = new TH1F("RingsE", "Rings energy dist", 30, 0.0, 1.0);
71 hRingsE->GetXaxis()->SetCanExtend(kTRUE);
72 hRingsE->SetStats(false);
73
74 auto hOutput = new TH1F("NeuralRingerOffline", "Neural Ringer Offline", 30, -1.0, 1.0);
75 hOutput->SetStats(false);
76
77 auto hNNvrEta = new TH2F("NNOutput vs rEta",
78 "NNOutput w.r.t rEta;rEta;NNOutput",
79 50, 0, 1.2, 50, -1.00, 1.00);
80 hNNvrEta->SetOption("COLZ");
81 hNNvrEta->SetStats(false);
82
83 const xAOD::ElectronContainer *electronCont;
84
85 std::vector<float> ringsE;
86
87 // Run the files
88 size_t nEntries = chain->GetEntries();
89 for (size_t entry = 0; entry < nEntries; entry++) {
90
91 event.getEntry(entry);
92
93 const xAOD::EventInfo* event_info = 0;
94 RETURN_CHECK( APP_NAME, event.retrieve( event_info, "EventInfo" ) );
95
96 if ( event.retrieve(electronCont, "Electrons").isSuccess() ){
97 for ( const Electron *electron : *electronCont ){
98 const xAOD::CaloRingsLinks &caloRingsELVec = ringsReader(*electron);
99 for ( const ElementLink<xAOD::CaloRingsContainer> &clRingsEL : caloRingsELVec ){
100 (*clRingsEL)->exportRingsTo(ringsE);
101 for ( auto ringE : ringsE ){
102 hRingsE->Fill( ringE );
103 }
104 }
105 // Loose Output = Medium Output = Tight Output
106 SG::AuxElement::ConstAccessor<float> looseOutput("ToolSvc.ElectronRingerSelector_TestLoose_output");
107 float output = looseOutput( *electron );
108 hOutput->Fill( output );
109 hNNvrEta->Fill( electron->showerShapeValue( EgammaParameters::Reta ) ,
110 output );
111 }
112 } else {
113 std::cout << "Could not retrieve electrons container" << std::endl;
114 }
115 }
116
117 auto metaChain = getChain(argc, argv,"MetaData");
118
120 TEvent metaEvent( TEvent::kBranchAccess );
121 RETURN_CHECK( APP_NAME, metaEvent.readFrom(metaChain));
122
123 const xAOD::RingSetConfContainer *electronRingSetConf;
124
125 size_t nEntriesMeta = metaChain->GetEntries();
126 for (size_t entry = 0; entry < nEntriesMeta; entry++) {
127 metaEvent.getEntry(entry);
128 std::cout << " :: Entry :: " << entry << "/" << nEntriesMeta << std::endl;
129 std::cout << "----------------- Reading RingSetConfs ------------------- " << std::endl;
130 if ( metaEvent.retrieve(electronRingSetConf,"ElectronRingSetsConf").isSuccess() ){
131 try {
132 for ( const xAOD::RingSetConf *ringsConf : *electronRingSetConf ){
133 ringsConf->print(std::cout);
134 }
135 std::cout << "----------------- Printing its RawConfCollection ------------------- " << std::endl;
137 xAOD::RingSetConf::getRawConfCol( rawConfCol, electronRingSetConf );
138 xAOD::RingSetConf::print( rawConfCol, std::cout );
139 } catch (const std::runtime_error &e) {
140 std::cout << "Coudln't read RingSetConfs, reason: " << e.what() << std::endl;
141 }
142 } else {
143 std::cout << "ElectronRingSetsConf not available." << std::endl;
144 }
145 }
146
147 // Draw
148 auto canvas = new TCanvas("RingsEnergyHist");
149 hRingsE->Draw();
150 canvas->SaveAs( "ringsE.gif");
151 canvas->SaveAs( "ringsE.eps");
152 canvas = new TCanvas("NNOutput");
153 hOutput->Draw();
154 canvas->SaveAs( "nnOutput.gif");
155 canvas->SaveAs( "nnOutput.eps");
156 canvas = new TCanvas("NNOutVsReta");
157 hNNvrEta->Draw();
158 canvas->SaveAs( "nnWrtReta.gif");
159 canvas->SaveAs( "nnWrtReta.eps");
160
161 outputFile->Write();
162 outputFile->Close();
163
164}
165
166
167TChain *getChain(int argc, char* argv[], const char *chainName)
168{
169 if (argc < 2) {
170 ::Error(APP_NAME, "Usage: %s <xAOD file> [xAOD file2]...", APP_NAME);
171 return nullptr;
172 }
173
174 auto chain = new TChain( chainName );
175 for (int i = 1; i < argc; i++) {
176 chain->Add(argv[i]);
177 }
178
179 return chain;
180}
181
#define APP_NAME
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition ReturnCheck.h:26
SG::ConstAccessor< T, ALLOC > ConstAccessor
Definition AuxElement.h:569
Class describing an electron.
StatusCode retrieve(const T *&obj, const std::string &key)
Retrieve either an input or an output object from the event.
std::vector< RawConf > RawConfCollection
typedef The raw configuration structure data holder
static void print(const RawConf &raw, std::ostream &stream)
Prints rawConf.
static void getRawConfCol(RawConfCollection &rawConfCol, const RingSetConfContainer_v1 *container)
Retrieve RawConfCollection from RingSetConf container.
Tool for accessing xAOD files outside of Athena.
@ kClassAccess
Access auxiliary data using the aux containers.
@ kBranchAccess
Access auxiliary data branch-by-branch.
StatusCode readFrom(::TFile *file, bool useTreeCache=true, std::string_view treeName=EVENT_TREE_NAME)
Connect the object to a new input file.
::Int_t getEntry(::Long64_t entry, ::Int_t getall=0)
Function loading a given entry of the input TTree.
int main()
Definition hello.cxx:18
STL namespace.
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
ElectronContainer_v1 ElectronContainer
Definition of the current "electron container version".
RingSetConf_v1 RingSetConf
Definition of the current "RingSetConf version".
Definition RingSetConf.h:15
EventInfo_v1 EventInfo
Definition of the latest event info version.
std::vector< ElementLink< CaloRingsContainer > > CaloRingsLinks
ElementLink type pointing at such objects.
const caloRingsReader_t & getCaloRingsReader()
Get CaloRings accessor with read only permissions.
RingSetConfContainer_v1 RingSetConfContainer
Definition of the current "RingSetConf container version".
TChain * getChain(int argc, char *argv[], const char *chainName="CollectionTree")
const char * OUTPUT_FILE
Definition ringsHist.cxx:39