Skip to content

Commit 9a2cea6

Browse files
committed
Important bug fixes for HepMC aux tables
I found two problems with the HepMC aux tables after looking at the data a little deeper - I used the BC identifier as the collision index field in the HepMC aux tables. This happened because I took my clues from the MC producer. The MC producer does not generate a BC ID - even though it sort of looked like it - the BC ID in the MC producer is essentially an index. I've fixed this by passing the collision index (called `collisionID` most places) to the relevant member functions and the table updates. - The producers were set up so that HepMC aux tables would _only_ be written if the input had the corresponding data. If a model gave the Cross-section, but not PDF nor Heavy-Ion information, then only the cross-section table would be populated. Pythia, for example, gives the cross-section and PDF information, but no Heavy-Ion information. All three tables would be produced, but some may not have any entries. Later on, when we want to process the events (by Rivet f.ex.), we like to access as much HepMC aux information as possible so we may build the most complete HepMC event possible. Thus, we would like to read in - MC Collisions - MC particles - 3 HepMC aux However, if one or more of the AOD trees of the 3 HepMC aux tables had no entries, it will cause the producer to crash ``` libO2FrameworkAnalysisSupport.so: std::function<void (o2::framework::TreeToTable&)>::operator()(o2::framework::TreeToTable&) const libO2FrameworkAnalysisSupport.so: o2::framework::LifetimeHolder<o2::framework::TreeToTable>::release() libO2FrameworkAnalysisSupport.so: o2::framework::LifetimeHolder<o2::framework::TreeToTable>::~LifetimeHolder() libO2FrameworkAnalysisSupport.so: o2::framework::DataInputDescriptor::readTree(o2::framework::DataAllocator&, o2::header::DataHeader, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned long&, unsigned long&) ``` I cannot quite figure out why that happens, but I guess it's a problem triggered by `TreeToTable` or the call back on that object. The (temporary) solution to the above problem is to set the update policy on the HepMC aux tables to be `always`. That means we will always write the tables and give them entries. The real solution to the problem will be to fix `TreeToTable` or what ever is causing the above `SIGSEGV`. I also took the opportunity to fix up `o2-aod-mc-to-hepmc` a bit.
1 parent 979e20a commit 9a2cea6

File tree

7 files changed

+210
-34
lines changed

7 files changed

+210
-34
lines changed

Detectors/AOD/include/AODProducerWorkflow/AODMcProducerWorkflowSpec.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ class AODMcProducerWorkflowDPL : public Task
8888
* @param pdfInfoCursor Cursor over aod::HepMCPdfInfos
8989
* @param heavyIonCursor Cursor over aod::HepMCHeavyIons
9090
* @param header Header to read information from
91-
* @param eventID Current event identifier (bcID)
91+
* @param collisionID Index of collision in table
92+
* @param bcID Current event identifier (bcID)
9293
* @param time Time of event
9394
* @param generatorID Generator identifier, if any
9495
* @param sourceID Source identifier
@@ -99,7 +100,8 @@ class AODMcProducerWorkflowDPL : public Task
99100
PdfInfoCursor& pdfInfoCursor,
100101
HeavyIonCursor& heavyIonCursor,
101102
const MCEventHeader& header,
102-
int eventID,
103+
int collisionID, // Index
104+
int bcID,
103105
float time,
104106
short generatorID,
105107
int sourceID);

Detectors/AOD/include/AODProducerWorkflow/AODProducerWorkflowSpec.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,8 @@ class AODProducerWorkflowDPL : public Task
583583
* @param pdfInfoCursor Cursor over aod::HepMCPdfInfos
584584
* @param heavyIonCursor Cursor over aod::HepMCHeavyIons
585585
* @param header Header to read information from
586-
* @param eventID Current event identifier (bcID)
586+
* @param collisionID Index of collision in the table
587+
* @param bcID Current event identifier (bcID)
587588
* @param time Time of event
588589
* @param generatorID Generator identifier, if any
589590
* @param sourceID Source identifier
@@ -594,7 +595,8 @@ class AODProducerWorkflowDPL : public Task
594595
PdfInfoCursor& pdfInfoCursor,
595596
HeavyIonCursor& heavyIonCursor,
596597
const MCEventHeader& header,
597-
int eventID,
598+
int collisionID,
599+
int bcID,
598600
float time,
599601
short generatorID,
600602
int sourceID);

Detectors/AOD/src/AODMcProducerWorkflowSpec.cxx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ void AODMcProducerWorkflowDPL::updateHeader(CollisionCursor& collisionCursor,
7575
PdfInfoCursor& pdfInfoCursor,
7676
HeavyIonCursor& heavyIonCursor,
7777
const MCEventHeader& header,
78-
int eventID,
78+
int collisionID, // Index
79+
int bcID,
7980
float time,
8081
short generatorID,
8182
int sourceID)
@@ -86,28 +87,28 @@ void AODMcProducerWorkflowDPL::updateHeader(CollisionCursor& collisionCursor,
8687
using aodmchelpers::updateMCCollisions;
8788

8889
auto genID = updateMCCollisions(collisionCursor,
89-
eventID,
90+
bcID,
9091
time,
9192
header,
9293
generatorID,
9394
sourceID,
9495
mCollisionPosition);
9596
mXSectionUpdate = (updateHepMCXSection(xSectionCursor, //
96-
eventID, //
97+
collisionID, //
9798
genID, //
9899
header, //
99100
mXSectionUpdate) //
100101
? HepMCUpdate::always //
101102
: HepMCUpdate::never);
102103
mPdfInfoUpdate = (updateHepMCPdfInfo(pdfInfoCursor, //
103-
eventID, //
104+
collisionID, //
104105
genID, //
105106
header, //
106107
mPdfInfoUpdate) //
107108
? HepMCUpdate::always //
108109
: HepMCUpdate::never);
109110
mHeavyIonUpdate = (updateHepMCHeavyIon(heavyIonCursor, //
110-
eventID, //
111+
collisionID, //
111112
genID, //
112113
header, //
113114
mHeavyIonUpdate) //
@@ -165,6 +166,7 @@ void AODMcProducerWorkflowDPL::run(ProcessingContext& pc)
165166
heavyIonCursor.cursor,
166167
header,
167168
ievt,
169+
ievt, // BC is the same as collision index
168170
time,
169171
generatorID,
170172
isrc);
@@ -199,6 +201,7 @@ void AODMcProducerWorkflowDPL::run(ProcessingContext& pc)
199201
heavyIonCursor.cursor,
200202
header,
201203
icol,
204+
icol, // BC is the same as collision index
202205
time,
203206
generatorID,
204207
sourceID);
@@ -316,7 +319,7 @@ DataProcessorSpec getAODMcProducerWorkflowSpec()
316319
ConfigParamSpec{"filter-mctracks", VariantType::Int, 1, {"Store only physical primary MC tracks and their mothers/daughters. 0 -- off, != 0 -- on"}},
317320
ConfigParamSpec{"enable-embedding", VariantType::Int, 0, {"Use collisioncontext.root to process embedded events"}},
318321
ConfigParamSpec{"mckine-fname", VariantType::String, "o2sim", {"MC kinematics file name prefix: e.g. 'o2sim', 'bkg', 'sgn_1'. Used only if 'enable-embedding' is 0"}},
319-
ConfigParamSpec{"hepmc-update", VariantType::String, "any", {"When to update HepMC Aux tables: always - force update, never - never update, all - if all keys are present, any - when any key is present"}}}};
322+
ConfigParamSpec{"hepmc-update", VariantType::String, "always", {"When to update HepMC Aux tables: always - force update, never - never update, all - if all keys are present, any - when any key is present (not valid yet)"}}}};
320323
}
321324

322325
} // namespace o2::aodmcproducer

Detectors/AOD/src/AODProducerWorkflowSpec.cxx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ void AODProducerWorkflowDPL::updateMCHeader(MCCollisionCursor& collisionCursor,
816816
PdfInfoCursor& pdfInfoCursor,
817817
HeavyIonCursor& heavyIonCursor,
818818
const MCEventHeader& header,
819+
int collisionID,
819820
int eventID,
820821
float time,
821822
short generatorID,
@@ -827,21 +828,30 @@ void AODProducerWorkflowDPL::updateMCHeader(MCCollisionCursor& collisionCursor,
827828
using aodmchelpers::updateMCCollisions;
828829

829830
auto genID = updateMCCollisions(collisionCursor,
830-
eventID,
831+
collisionID,
831832
time,
832833
header,
833834
generatorID,
834835
sourceID,
835836
mCollisionPosition);
836-
mXSectionUpdate = (updateHepMCXSection(xSectionCursor, eventID, genID, header,
837+
mXSectionUpdate = (updateHepMCXSection(xSectionCursor, //
838+
collisionID, //
839+
genID, //
840+
header, //
837841
mXSectionUpdate)
838842
? HepMCUpdate::always
839843
: HepMCUpdate::never);
840-
mPdfInfoUpdate = (updateHepMCPdfInfo(pdfInfoCursor, eventID, genID, header,
844+
mPdfInfoUpdate = (updateHepMCPdfInfo(pdfInfoCursor, //
845+
collisionID, //
846+
genID, //
847+
header, //
841848
mPdfInfoUpdate)
842849
? HepMCUpdate::always
843850
: HepMCUpdate::never);
844-
mHeavyIonUpdate = (updateHepMCHeavyIon(heavyIonCursor, eventID, genID, header,
851+
mHeavyIonUpdate = (updateHepMCHeavyIon(heavyIonCursor, //
852+
collisionID, //
853+
genID, //
854+
header,
845855
mHeavyIonUpdate)
846856
? HepMCUpdate::always
847857
: HepMCUpdate::never);
@@ -1932,6 +1942,7 @@ void AODProducerWorkflowDPL::run(ProcessingContext& pc)
19321942
hepmcPdfInfosCursor.cursor,
19331943
hepmcHeavyIonsCursor.cursor,
19341944
header,
1945+
iCol,
19351946
bcID,
19361947
time,
19371948
0,
@@ -2953,7 +2964,7 @@ DataProcessorSpec getAODProducerWorkflowSpec(GID::mask_t src, bool enableSV, boo
29532964
ConfigParamSpec{"ctpreadout-create", VariantType::Int, 0, {"Create CTP digits from detector readout and CTP inputs. !=1 -- off, 1 -- on"}},
29542965
ConfigParamSpec{"emc-select-leading", VariantType::Bool, false, {"Flag to select if only the leading contributing particle for an EMCal cell should be stored"}},
29552966
ConfigParamSpec{"propagate-tracks", VariantType::Bool, false, {"Propagate tracks (not used for secondary vertices) to IP"}},
2956-
ConfigParamSpec{"hepmc-update", VariantType::String, "any", {"When to update HepMC Aux tables: always - force update, never - never update, all - if all keys are present, any - when any key is present"}},
2967+
ConfigParamSpec{"hepmc-update", VariantType::String, "always", {"When to update HepMC Aux tables: always - force update, never - never update, all - if all keys are present, any - when any key is present (not valid yet)"}},
29572968
ConfigParamSpec{"propagate-muons", VariantType::Bool, false, {"Propagate muons to IP"}},
29582969
ConfigParamSpec{"trackqc-fraction", VariantType::Float, float(0.1), {"Fraction of tracks to QC"}},
29592970
ConfigParamSpec{"trackqc-NTrCut", VariantType::Int64, 4L, {"Minimal length of the track - in amount of tracklets"}},

Generators/include/Generators/AODToHepMC.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <HepMC3/GenCrossSection.h>
2525
#include <HepMC3/WriterAscii.h>
2626
#include <fstream>
27+
#define AODTOHEPMC_WITH_HEAVYION
2728

2829
namespace o2
2930
{
@@ -390,6 +391,11 @@ struct AODToHepMC {
390391
* configurables.
391392
*/
392393
virtual void init();
394+
/**
395+
* Call before starting to process an event. This clears the
396+
* current event and internal data structures.
397+
*/
398+
virtual void startEvent();
393399
/**
394400
* Process the collision header and tracks
395401
*
@@ -407,8 +413,17 @@ struct AODToHepMC {
407413
*/
408414
virtual void process(Header const& collision,
409415
XSections const& xsections,
410-
PdfInfos const& pdfs,
411-
HeavyIons const& heavyions);
416+
PdfInfos const& pdfs
417+
#ifdef AODTOHEPMC_WITH_HEAVYION
418+
,
419+
HeavyIons const& heavyions
420+
#endif
421+
);
422+
/**
423+
* Call after process an. Thisf finalises the event and optionally
424+
* outputs to dump.
425+
*/
426+
virtual void endEvent();
412427
/**
413428
* End of run - closes output file if enabled. This is called via
414429
* specialisation of o2::framework::OutputManager<AODToHepMC>.

Generators/src/AODToHepMC.cxx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ void AODToHepMC::init()
3535
<< " Output precision: " << mPrecision;
3636
}
3737
// -------------------------------------------------------------------
38-
void AODToHepMC::process(Header const& collision,
39-
Tracks const& tracks)
38+
void AODToHepMC::startEvent()
4039
{
41-
LOG(debug) << "--- Processing track information";
40+
LOG(debug) << ">>> Starting an event";
4241
mBeams.clear();
4342
mOrphans.clear();
4443
mParticles.clear();
4544
mVertices.clear();
4645
mEvent.clear();
46+
}
47+
// -------------------------------------------------------------------
48+
void AODToHepMC::process(Header const& collision,
49+
Tracks const& tracks)
50+
{
51+
LOG(debug) << "--- Processing track information";
4752

4853
makeHeader(collision);
4954
makeParticles(tracks);
@@ -52,13 +57,28 @@ void AODToHepMC::process(Header const& collision,
5257
// -------------------------------------------------------------------
5358
void AODToHepMC::process(Header const& collision,
5459
XSections const& xsections,
55-
PdfInfos const& pdfs,
56-
HeavyIons const& heavyions)
60+
PdfInfos const& pdfs
61+
#ifdef AODTOHEPMC_WITH_HEAVYION
62+
,
63+
HeavyIons const& heavyions
64+
#endif
65+
)
5766
{
5867
LOG(debug) << "--- Processing auxiliary information";
5968
makeXSection(xsections);
6069
makePdfInfo(pdfs);
70+
#ifdef AODTOHEPMC_WITH_HEAVYION
6171
makeHeavyIon(heavyions, collision);
72+
#endif
73+
}
74+
// -------------------------------------------------------------------
75+
void AODToHepMC::endEvent()
76+
{
77+
LOG(debug) << "<<< an event";
78+
if (not mWriter)
79+
return;
80+
// If we have a writer, then dump event to output file
81+
mWriter->write_event(mEvent);
6282
}
6383
// ===================================================================
6484
void AODToHepMC::makeEvent(Header const& collision,
@@ -105,10 +125,6 @@ void AODToHepMC::makeEvent(Header const& collision,
105125
}
106126
// Flesh out the tracks based on daughter information.
107127
fleshOut(tracks);
108-
if (mWriter) {
109-
// If we have a writer, then dump event to output file
110-
mWriter->write_event(mEvent);
111-
}
112128
}
113129
// -------------------------------------------------------------------
114130
void AODToHepMC::makeHeader(Header const& header)
@@ -134,6 +150,7 @@ void AODToHepMC::makeHeader(Header const& header)
134150
// -------------------------------------------------------------------
135151
void AODToHepMC::makeXSection(XSections const& xsections)
136152
{
153+
LOG(debug) << "--- Process cross-section information";
137154
if (not mCrossSec) {
138155
// If we do not have a cross-sections object, create it
139156
mCrossSec = std::make_shared<HepMC3::GenCrossSection>();
@@ -144,6 +161,7 @@ void AODToHepMC::makeXSection(XSections const& xsections)
144161

145162
if (xsections.size() <= 0) {
146163
// If we have no info, skip the rest
164+
LOG(warning) << "??? No input cross-section";
147165
return;
148166
}
149167

@@ -156,6 +174,7 @@ void AODToHepMC::makeXSection(XSections const& xsections)
156174
// -------------------------------------------------------------------
157175
void AODToHepMC::makePdfInfo(PdfInfos const& pdfs)
158176
{
177+
LOG(debug) << "--- Process PDF information";
159178
if (not mPdf) {
160179
// If we do not have a Parton Distribution Function object, create it
161180
mPdf = std::make_shared<HepMC3::GenPdfInfo>();
@@ -166,6 +185,7 @@ void AODToHepMC::makePdfInfo(PdfInfos const& pdfs)
166185

167186
if (pdfs.size() <= 0) {
168187
// If we have no PDF info, skip the rest
188+
LOG(warning) << "??? No input pdf-info, skipping";
169189
return;
170190
}
171191

@@ -184,6 +204,7 @@ void AODToHepMC::makePdfInfo(PdfInfos const& pdfs)
184204
void AODToHepMC::makeHeavyIon(HeavyIons const& heavyions,
185205
Header const& header)
186206
{
207+
LOG(debug) << "--- Process input heavy-ion header";
187208
if (not mIon) {
188209
// Generate heavy ion element if it doesn't exist
189210
mIon = std::make_shared<HepMC3::GenHeavyIon>();
@@ -215,6 +236,7 @@ void AODToHepMC::makeHeavyIon(HeavyIons const& heavyions,
215236

216237
if (heavyions.size() <= 0) {
217238
// If we have no heavy-ion information, skip the rest
239+
LOG(warning) << "??? No input heavy-ion header, skipping";
218240
return;
219241
}
220242

0 commit comments

Comments
 (0)