Skip to content

Commit a7ed955

Browse files
committed
Fixes issues 22-24 concerning various code cleanliness concerns.
1 parent f3d5228 commit a7ed955

File tree

3 files changed

+41
-90
lines changed

3 files changed

+41
-90
lines changed

MCValidation/lifetime_plots.h

+17-20
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,34 @@
1010

1111
#include <string>
1212

13-
// Group added
1413
using namespace std;
1514

1615
class lifetime_plots {
17-
public:
18-
// Book the plots
19-
lifetime_plots (const std::string &name, const std::string &title, EL::Worker *wk, int maxN = 10)
16+
public:
17+
// Book the plots
18+
lifetime_plots (const std::string &name, const std::string &title, EL::Worker *wk)
2019
{
2120
_deltaT = new TH1F((name + "DeltaT").c_str(), (title + " Delta t; t_{dec} - t_{prod} [ns]").c_str(),260,-6,20);
2221
wk->addOutput (_deltaT);
2322
}
2423

25-
// Fill the plots.
26-
void Process(const xAOD::TruthParticle *p) {
27-
if (p->hasProdVtx() && p->hasDecayVtx()) {
28-
_deltaT->Fill(p->decayVtx()->v4().T()*0.001 - p->prodVtx()->v4().T()*0.001);
29-
if ( (p->decayVtx()->v4().T()*0.001 - p->prodVtx()->v4().T()*0.001)<0 ) {
30-
cout << " - Decay = " << p->decayVtx()->v4().T()*0.001 << endl;
31-
cout << " - Prod = " << p->prodVtx()->v4().T()*0.001 << endl;
32-
cout << " -- diff = " << p->decayVtx()->v4().T()*0.001 - p->prodVtx()->v4().T()*0.001 << endl;
24+
// Fill the plots.
25+
void Process(const xAOD::TruthParticle *p)
26+
{
27+
if (p->hasProdVtx() && p->hasDecayVtx())
28+
{
29+
_deltaT->Fill(p->decayVtx()->v4().T()*0.001 - p->prodVtx()->v4().T()*0.001);
30+
if ( (p->decayVtx()->v4().T()*0.001 - p->prodVtx()->v4().T()*0.001)<0 )
31+
{
32+
cout << " - Decay = " << p->decayVtx()->v4().T()*0.001 << endl;
33+
cout << " - Prod = " << p->prodVtx()->v4().T()*0.001 << endl;
34+
cout << " -- diff = " << p->decayVtx()->v4().T()*0.001 - p->prodVtx()->v4().T()*0.001 << endl;
35+
}
3336
}
3437
}
35-
}
36-
void EndOfEvent()
37-
{
38-
_counter = 0;
39-
}
40-
private:
41-
int _counter;
42-
TH1F *_deltaT;
4338

39+
private:
40+
TH1F *_deltaT;
4441
};
4542

4643
#endif

Root/MyxAODAnalysis.cxx

+10-45
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@ EL::StatusCode MyxAODAnalysis :: setupJob (EL::Job& job)
5959
// activated/deactivated when you add/remove the algorithm from your
6060
// job, which may or may not be of value to you.
6161

62-
// GitHubProgramCode added
6362
// let's initialize the algorithm to use the xAODRootAccess package
6463
job.useXAOD ();
65-
// xAOD::Init(); // call before opening first file
6664
ANA_CHECK_SET_TYPE (EL::StatusCode); // set type of return code you are expecting (add to top of each function once)
67-
ANA_CHECK(xAOD::Init());
65+
ANA_CHECK(xAOD::Init());
6866

6967
return EL::StatusCode::SUCCESS;
7068
}
@@ -78,7 +76,6 @@ EL::StatusCode MyxAODAnalysis :: histInitialize ()
7876
// trees. This method gets called before any input files are
7977
// connected.
8078

81-
// GitHubProgramCode added
8279
// This method is called before processing any events. Note that the wk()->addOutput call is a mechanism EventLoop uses for delivering the results of an algorithm to the outside world. When running in PROOF, ROOT will merge all of the objects in this list.
8380

8481
// Initializing histograms
@@ -109,6 +106,7 @@ EL::StatusCode MyxAODAnalysis :: changeInput (bool firstFile)
109106
// Here you do everything you need to do when we change input files,
110107
// e.g. resetting branch addresses on trees. If you are using
111108
// D3PDReader or a similar service this method is not needed.
109+
(void)firstFile; // Suppress unused-variable warning.
112110
return EL::StatusCode::SUCCESS;
113111
}
114112

@@ -125,17 +123,14 @@ EL::StatusCode MyxAODAnalysis :: initialize ()
125123
// you create here won't be available in the output if you have no
126124
// input events.
127125

128-
// GitHubProgramCode added
129126
ANA_CHECK_SET_TYPE (EL::StatusCode); // set type of return code you are expecting (add to top of each function once)
130127
xAOD::TEvent* event = wk()->xaodEvent();
131128

132-
// GitHubProgramCode added
133129
// as a check, let's see the number of events in our xAOD
134130
Info("initialize()", "Number of events = %lli", event->getEntries() ); // print long long int
135131

136-
// GitHubProgramCode added
137132
// count number of events
138-
m_eventCounter = 0;
133+
m_eventCounter = 0;
139134

140135
return EL::StatusCode::SUCCESS;
141136
}
@@ -149,47 +144,20 @@ EL::StatusCode MyxAODAnalysis :: execute ()
149144
// histograms and trees. This is where most of your actual analysis
150145
// code will go.
151146

152-
// GitHubProgramCode added
153147
ANA_CHECK_SET_TYPE (EL::StatusCode); // set type of return code you are expecting (add to top of each function once)
154148
xAOD::TEvent* event = wk()->xaodEvent();
155149

156-
// GitHubProgramCode added
157150
// print every 100 events, so we know where we are:
158-
if( (m_eventCounter % 100) ==0 ) Info("execute()", "Event number = %i", m_eventCounter );
151+
if ((m_eventCounter % 100) == 0)
152+
{
153+
Info("execute()", "Event number = %i", m_eventCounter);
154+
}
159155
m_eventCounter++;
160156

161-
//----------------------------
162-
// Event information
163-
//---------------------------
164-
const xAOD::EventInfo* eventInfo = 0;
165-
ANA_CHECK(event->retrieve( eventInfo, "EventInfo"));
166-
167-
// check if the event is data or MC
168-
// (many tools are applied either to data or MC)
169-
// Warning: set but not used below commented out
170-
// bool isMC = false;
171-
// check if the event is MC
172-
// if(eventInfo->eventType( xAOD::EventInfo::IS_SIMULATION ) ){
173-
// isMC = true; // can do something with this later
174-
// }
175-
176-
// GitHubProgramCode added + Gordoncode
177-
// get jet container of interest
178-
const xAOD::TruthEventContainer* truths = 0;
179-
ANA_CHECK(event->retrieve( truths, "TruthEvents" ));
180-
Info("execute()", " number of truths = %lu", truths->size());
181-
182-
// loop over the jets in the container
183-
xAOD::TruthEventContainer::const_iterator truth_itr = truths->begin();
184-
xAOD::TruthEventContainer::const_iterator truth_end = truths->end();
185-
186-
// Get the truth info
157+
// Get the truth events.
187158
const xAOD::TruthEventContainer *truth = nullptr;
188-
// RETURN_CHECK (APP_NAME, event->retrieve(truth, "TruthEvents"));
189-
ANA_CHECK(event->retrieve( truth, "TruthEvents" ));
190-
// Warning: set but not used below commented out
191-
// bool isHiggs62 = false;
192-
// Loop over all the truth particles in there
159+
ANA_CHECK(event->retrieve( truth, "TruthEvents"));
160+
// Loop over all of the truth events.
193161
for (auto evt : *truth)
194162
{
195163
for (auto p : truth_as_range(evt))
@@ -249,10 +217,7 @@ EL::StatusCode MyxAODAnalysis :: finalize ()
249217
// merged. This is different from histFinalize() in that it only
250218
// gets called on worker nodes that processed input events.
251219

252-
// GitHubProgramCode added
253220
ANA_CHECK_SET_TYPE (EL::StatusCode); // set type of return code you are expecting (add to top of each function once)
254-
// Warning: unused variable below commented out
255-
// xAOD::TEvent* event = wk()->xaodEvent();
256221

257222
return EL::StatusCode::SUCCESS;
258223
}

util/PlotGeneratorQuantities.cxx

+14-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// Generate plots from a xAOD file that has the EVNT banks in it.
22
//
33
// Usage:
4-
// PlotGeneratorQanitites
5-
//
4+
// PlotGeneratorQuanitites
65

7-
// GitHubProgramCode added
86
#include "xAODRootAccess/Init.h"
97
#include "SampleHandler/SampleHandler.h"
108
#include "SampleHandler/ScanDir.h"
@@ -14,8 +12,6 @@
1412
#include "SampleHandler/DiskListLocal.h"
1513
#include <TSystem.h>
1614

17-
18-
// GitHubProgramCode added
1915
#include "GeneratorPlotsAlt/MyxAODAnalysis.h"
2016

2117
#include <iostream>
@@ -25,21 +21,18 @@
2521

2622
using namespace std;
2723

28-
// int main()
29-
// {
30-
// cout << "hi" << endl;
31-
// }
3224

3325

34-
// GitHubProgramCode added
35-
int main( int argc, char* argv[] ) {
36-
37-
// GitHubProgramCode added
26+
int main( int argc, char* argv[] )
27+
{
3828
cout << "hi" << endl;
3929

4030
// Take the submit directory from the input if provided:
4131
std::string submitDir = "submitDir";
42-
if( argc > 1 ) submitDir = argv[ 1 ];
32+
if (argc > 1)
33+
{
34+
submitDir = argv[1];
35+
}
4336

4437
// Set up the job for xAOD access:
4538
xAOD::Init().ignore();
@@ -48,32 +41,28 @@ int main( int argc, char* argv[] ) {
4841
SH::SampleHandler sh;
4942

5043
// use SampleHandler to scan all of the subdirectories of a directory for particular MC single file:
51-
const char* inputFilePath = gSystem->ExpandPathName ("$DATAPATH");
44+
const char* inputFilePath = gSystem->ExpandPathName("$DATAPATH");
5245
SH::ScanDir().filePattern("DAOD_TRUTH0.5000_events_v2.pool.root").scan(sh,inputFilePath);
5346

54-
// GitHubProgramCode added to check to make sure things are working up until this point
55-
cout << "Working up 'til here" << endl;
56-
57-
5847
// Set the name of the input TTree. It's always "CollectionTree"
5948
// for xAOD files.
60-
sh.setMetaString( "nc_tree", "CollectionTree" );
49+
sh.setMetaString("nc_tree", "CollectionTree");
6150

6251
// Print what we found:
6352
sh.print();
6453

6554
// Create an EventLoop job:
6655
EL::Job job;
67-
job.sampleHandler( sh );
68-
job.options()->setDouble (EL::Job::optMaxEvents, 500);
56+
job.sampleHandler(sh);
57+
job.options()->setDouble(EL::Job::optMaxEvents, 500);
6958

7059
// Add our analysis to the job:
7160
MyxAODAnalysis* alg = new MyxAODAnalysis();
72-
job.algsAdd( alg );
61+
job.algsAdd(alg);
7362

7463
// Run the job using the local/direct driver:
7564
EL::DirectDriver driver;
76-
driver.submit( job, submitDir );
65+
driver.submit(job, submitDir);
7766

7867
return 0;
79-
}
68+
}

0 commit comments

Comments
 (0)