Skip to content

Commit ab44148

Browse files
Benedikt Volkelsawenzel
authored andcommitted
[o2-sim] En-/disable hit creation per detector
Be able to en-/disable hit creation of detectors while still building the geometry. This is an extension to the -m/--skipModules options. * introduce --readoutDetectors and --skipReadoutDetectors options if a passive module name is passed for either of the options it will be ignored * --readoutDetectors det_1 ... det_N * if det_i specified, only the given detectors will be readout * if det_i not contained in active modules (see -m/--skipModules), it takes precedence and det_i is added to active modules * if not specified, all detectors will be readout which are in line with the -m and --skipModules options * --skipReadoutDetectors det_1 ... det_N * given detectors will not produce any hits * has no effect on the constructed geometry * take care of corner cases such as --skipModules m --readoutDetectors m --skipReadoutDetectors m in which case m is not built at all and therefore not readout
1 parent 13cb02e commit ab44148

File tree

8 files changed

+151
-93
lines changed

8 files changed

+151
-93
lines changed

Common/SimConfig/include/SimConfig/SimConfig.h

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,36 @@ namespace conf
2222

2323
// configuration struct (which can be passed around)
2424
struct SimConfigData {
25-
std::vector<std::string> mActiveDetectors; // list of active detectors
26-
std::string mMCEngine; // chosen VMC engine
27-
std::string mGenerator; // chosen VMC generator
28-
std::string mTrigger; // chosen VMC generator trigger
29-
unsigned int mNEvents; // number of events to be simulated
30-
std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator)
31-
std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding
32-
unsigned int mStartEvent; // index of first event to be taken
33-
float mBMax; // maximum for impact parameter sampling
34-
bool mIsMT; // chosen MT mode (Geant4 only)
35-
std::string mOutputPrefix; // prefix to be used for output files
36-
std::string mLogSeverity; // severity for FairLogger
37-
std::string mLogVerbosity; // loglevel for FairLogger
38-
std::string mKeyValueTokens; // a string holding arbitrary sequence of key-value tokens
39-
// Foo.parameter1=x,Bar.parameter2=y,Baz.paramter3=hello
40-
// (can be used to **loosely** change any configuration parameter from command-line)
41-
std::string mConfigFile; // path to a JSON or INI config file (file extension is required to determine type).
42-
// values within the config file will override values set in code by the param classes
43-
// but will themselves be overridden by any values given in mKeyValueTokens.
44-
int mPrimaryChunkSize; // defining max granularity for input primaries of a sim job
45-
int mInternalChunkSize; //
46-
int mStartSeed; // base for random number seeds
47-
int mSimWorkers = 1; // number of parallel sim workers (when it applies)
48-
bool mFilterNoHitEvents = false; // whether to filter out events not leaving any response
49-
std::string mCCDBUrl; // the URL where to find CCDB
50-
uint64_t mTimestamp; // timestamp in ms to anchor transport simulation to
51-
int mField; // L3 field setting in kGauss: +-2,+-5 and 0
52-
bool mUniformField = false; // uniform magnetic field
53-
bool mAsService = false; // if simulation should be run as service/deamon (does not exit after run)
25+
std::vector<std::string> mActiveModules; // list of active modules
26+
std::vector<std::string> mReadoutDetectors; // list of readout detectors
27+
std::string mMCEngine; // chosen VMC engine
28+
std::string mGenerator; // chosen VMC generator
29+
std::string mTrigger; // chosen VMC generator trigger
30+
unsigned int mNEvents; // number of events to be simulated
31+
std::string mExtKinFileName; // file name of external kinematics file (needed for ext kinematics generator)
32+
std::string mEmbedIntoFileName; // filename containing the reference events to be used for the embedding
33+
unsigned int mStartEvent; // index of first event to be taken
34+
float mBMax; // maximum for impact parameter sampling
35+
bool mIsMT; // chosen MT mode (Geant4 only)
36+
std::string mOutputPrefix; // prefix to be used for output files
37+
std::string mLogSeverity; // severity for FairLogger
38+
std::string mLogVerbosity; // loglevel for FairLogger
39+
std::string mKeyValueTokens; // a string holding arbitrary sequence of key-value tokens
40+
// Foo.parameter1=x,Bar.parameter2=y,Baz.paramter3=hello
41+
// (can be used to **loosely** change any configuration parameter from command-line)
42+
std::string mConfigFile; // path to a JSON or INI config file (file extension is required to determine type).
43+
// values within the config file will override values set in code by the param classes
44+
// but will themselves be overridden by any values given in mKeyValueTokens.
45+
int mPrimaryChunkSize; // defining max granularity for input primaries of a sim job
46+
int mInternalChunkSize; //
47+
int mStartSeed; // base for random number seeds
48+
int mSimWorkers = 1; // number of parallel sim workers (when it applies)
49+
bool mFilterNoHitEvents = false; // whether to filter out events not leaving any response
50+
std::string mCCDBUrl; // the URL where to find CCDB
51+
uint64_t mTimestamp; // timestamp in ms to anchor transport simulation to
52+
int mField; // L3 field setting in kGauss: +-2,+-5 and 0
53+
bool mUniformField = false; // uniform magnetic field
54+
bool mAsService = false; // if simulation should be run as service/deamon (does not exit after run)
5455

5556
ClassDefNV(SimConfigData, 4);
5657
};
@@ -93,7 +94,8 @@ class SimConfig
9394
// get MC engine
9495
std::string getMCEngine() const { return mConfigData.mMCEngine; }
9596
// get selected active detectors
96-
std::vector<std::string> const& getActiveDetectors() const { return mConfigData.mActiveDetectors; }
97+
std::vector<std::string> const& getActiveModules() const { return mConfigData.mActiveModules; }
98+
std::vector<std::string> const& getReadoutDetectors() const { return mConfigData.mReadoutDetectors; }
9799
// get selected generator (to be used to select a genconfig)
98100
std::string getGenerator() const { return mConfigData.mGenerator; }
99101
std::string getTrigger() const { return mConfigData.mTrigger; }

Common/SimConfig/src/SimConfig.cxx

Lines changed: 58 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ void SimConfig::initOptions(boost::program_options::options_description& options
2828
"mcEngine,e", bpo::value<std::string>()->default_value("TGeant3"), "VMC backend to be used.")(
2929
"generator,g", bpo::value<std::string>()->default_value("boxgen"), "Event generator to be used.")(
3030
"trigger,t", bpo::value<std::string>()->default_value(""), "Event generator trigger to be used.")(
31-
"modules,m", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>({"all"}), "all modules"), "list of detectors")(
32-
"skipModules", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>({""}), ""), "list of detectors to skip (precendence over -m")(
31+
"modules,m", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>({"all"}), "all modules"), "list of modules included in geometry")(
32+
"skipModules", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>({""}), ""), "list of modules excluded in geometry (precendence over -m")(
33+
"readoutDetectors", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>(), ""), "list of detectors creating hits, all if not given; added to to active modules")(
34+
"skipReadoutDetectors", bpo::value<std::vector<std::string>>()->multitoken()->default_value(std::vector<std::string>(), ""), "list of detectors to skip hit creation (precendence over --readoutDetectors")(
3335
"nEvents,n", bpo::value<unsigned int>()->default_value(1), "number of events")(
3436
"startEvent", bpo::value<unsigned int>()->default_value(0), "index of first event to be used (when applicable)")(
3537
"extKinFile", bpo::value<std::string>()->default_value("Kinematics.root"),
@@ -58,35 +60,73 @@ bool SimConfig::resetFromParsedMap(boost::program_options::variables_map const&
5860
{
5961
using o2::detectors::DetID;
6062
mConfigData.mMCEngine = vm["mcEngine"].as<std::string>();
61-
mConfigData.mActiveDetectors = vm["modules"].as<std::vector<std::string>>();
62-
auto& active = mConfigData.mActiveDetectors;
63-
if (active.size() == 1 && active[0] == "all") {
64-
active.clear();
63+
mConfigData.mActiveModules = vm["modules"].as<std::vector<std::string>>();
64+
auto& activeModules = mConfigData.mActiveModules;
65+
if (activeModules.size() == 1 && activeModules[0] == "all") {
66+
activeModules.clear();
6567
for (int d = DetID::First; d <= DetID::Last; ++d) {
6668
#ifdef ENABLE_UPGRADES
6769
if (d != DetID::IT3 && d != DetID::TRK && d != DetID::FT3) {
68-
active.emplace_back(DetID::getName(d));
70+
activeModules.emplace_back(DetID::getName(d));
6971
}
7072
#else
71-
active.emplace_back(DetID::getName(d));
73+
activeModules.emplace_back(DetID::getName(d));
7274
#endif
7375
}
7476
// add passive components manually (make a PassiveDetID for them!)
75-
active.emplace_back("HALL");
76-
active.emplace_back("MAG");
77-
active.emplace_back("DIPO");
78-
active.emplace_back("COMP");
79-
active.emplace_back("PIPE");
80-
active.emplace_back("ABSO");
81-
active.emplace_back("SHIL");
77+
activeModules.emplace_back("HALL");
78+
activeModules.emplace_back("MAG");
79+
activeModules.emplace_back("DIPO");
80+
activeModules.emplace_back("COMP");
81+
activeModules.emplace_back("PIPE");
82+
activeModules.emplace_back("ABSO");
83+
activeModules.emplace_back("SHIL");
8284
}
8385
// now we take out detectors listed as skipped
8486
auto& skipped = vm["skipModules"].as<std::vector<std::string>>();
8587
for (auto& s : skipped) {
86-
auto iter = std::find(active.begin(), active.end(), s);
87-
if (iter != active.end()) {
88+
auto iter = std::find(activeModules.begin(), activeModules.end(), s);
89+
if (iter != activeModules.end()) {
8890
// take it out
89-
active.erase(iter);
91+
activeModules.erase(iter);
92+
}
93+
}
94+
95+
// find all detectors that should be readout
96+
auto enableReadout = vm["readoutDetectors"].as<std::vector<std::string>>();
97+
auto& disableReadout = vm["skipReadoutDetectors"].as<std::vector<std::string>>();
98+
auto& readoutDetectors = mConfigData.mReadoutDetectors;
99+
readoutDetectors.clear();
100+
101+
auto isDet = [](std::string const& s) {
102+
auto d = DetID::nameToID(s.c_str());
103+
#ifdef ENABLE_UPGRADES
104+
return d >= DetID::First && d != DetID::IT3 && d != DetID::TRK && d != DetID::FT3;
105+
#else
106+
return d >= DetID::First;
107+
#endif
108+
};
109+
110+
if (enableReadout.empty()) {
111+
// if no readout explicitly given, use all detectors from active modules
112+
for (auto& am : activeModules) {
113+
if (!isDet(am) || std::find(disableReadout.begin(), disableReadout.end(), am) != disableReadout.end()) {
114+
// either we found a passive module or one with disabled readout ==> skip
115+
continue;
116+
}
117+
readoutDetectors.emplace_back(am);
118+
}
119+
} else {
120+
for (auto& er : enableReadout) {
121+
if (!isDet(er) || std::find(disableReadout.begin(), disableReadout.end(), er) != disableReadout.end()) {
122+
// either we found a passive module or one with disabled readout ==> skip
123+
continue;
124+
}
125+
readoutDetectors.emplace_back(er);
126+
if (std::find(activeModules.begin(), activeModules.end(), er) == activeModules.end()) {
127+
// add to active modules if not yet there
128+
activeModules.emplace_back(er);
129+
}
90130
}
91131
}
92132

Common/SimConfig/test/TestConfig.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ int main(int argc, char* argv[])
2222
std::cout << "Selected VMC engine " << conf.getMCEngine() << "\n";
2323
std::cout << "Selected Modules:\n";
2424

25-
auto v = conf.getActiveDetectors();
25+
auto v = conf.getActiveModules();
2626
for (auto& m : v) {
2727
std::cout << "@ " << m << "\n";
2828
}
@@ -43,7 +43,7 @@ int main(int argc, char* argv[])
4343

4444
if (inconfigdata) {
4545
conf.resetFromConfigData(*inconfigdata);
46-
auto v2 = conf.getActiveDetectors();
46+
auto v2 = conf.getActiveModules();
4747
for (auto& m : v2) {
4848
std::cout << "@ " << m << "\n";
4949
}

Detectors/ITSMFT/MFT/simulation/include/MFTSimulation/Detector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ namespace mft
4949
class Detector : public o2::base::DetImpl<Detector>
5050
{
5151
public:
52+
/// Name : Detector Name
53+
/// Active: kTRUE for active detectors (ProcessHits() will be called)
54+
/// kFALSE for inactive detectors
55+
Detector(Bool_t active);
56+
5257
/// Default constructor
5358
Detector();
5459

Detectors/ITSMFT/MFT/simulation/src/Detector.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ ClassImp(o2::mft::Detector);
4141
Detector::Detector()
4242
: o2::base::DetImpl<Detector>("MFT", kTRUE), mVersion(1), mDensitySupportOverSi(0.036), mHits(o2::utils::createSimVector<o2::itsmft::Hit>()), mTrackData() {}
4343

44+
//_____________________________________________________________________________
45+
Detector::Detector(Bool_t active)
46+
: o2::base::DetImpl<Detector>("MFT", active), mVersion(1), mDensitySupportOverSi(0.036), mHits(o2::utils::createSimVector<o2::itsmft::Hit>()), mTrackData() {}
47+
4448
//_____________________________________________________________________________
4549
Detector::Detector(const Detector& src)
4650
: o2::base::DetImpl<Detector>(src), mVersion(src.mVersion), mDensitySupportOverSi(src.mDensitySupportOverSi), mHits(o2::utils::createSimVector<o2::itsmft::Hit>()), mTrackData() {}

macro/build_geometry.C

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,25 @@ void finalize_geometry(FairRunSim* run);
5959
bool isActivated(std::string s)
6060
{
6161
// access user configuration for list of wanted modules
62-
auto& modulelist = o2::conf::SimConfig::Instance().getActiveDetectors();
62+
auto& modulelist = o2::conf::SimConfig::Instance().getActiveModules();
6363
auto active = std::find(modulelist.begin(), modulelist.end(), s) != modulelist.end();
6464
if (active) {
6565
LOG(info) << "Activating " << s << " module";
6666
}
6767
return active;
6868
}
6969

70+
bool isReadout(std::string s)
71+
{
72+
// access user configuration for list of wanted modules
73+
auto& modulelist = o2::conf::SimConfig::Instance().getReadoutDetectors();
74+
auto active = std::find(modulelist.begin(), modulelist.end(), s) != modulelist.end();
75+
if (active) {
76+
LOG(info) << "Reading out " << s << " detector";
77+
}
78+
return active;
79+
}
80+
7081
// a "factory" like macro to instantiate the O2 geometry
7182
void build_geometry(FairRunSim* run = nullptr)
7283
{
@@ -151,119 +162,108 @@ void build_geometry(FairRunSim* run = nullptr)
151162
// the absorber
152163
if (isActivated("ABSO")) {
153164
// the frame structure to support other detectors
154-
auto abso = new o2::passive::Absorber("ABSO", "Absorber");
155-
run->AddModule(abso);
165+
run->AddModule(new o2::passive::Absorber("ABSO", "Absorber"));
156166
}
157167

158168
// the shil
159169
if (isActivated("SHIL")) {
160-
auto shil = new o2::passive::Shil("SHIL", "Small angle beam shield");
161-
run->AddModule(shil);
170+
run->AddModule(new o2::passive::Shil("SHIL", "Small angle beam shield"));
162171
}
163172

164173
if (isActivated("TOF") || isActivated("TRD") || isActivated("FRAME")) {
165174
// the frame structure to support other detectors
166-
auto frame = new o2::passive::FrameStructure("FRAME", "Frame");
167-
run->AddModule(frame);
175+
run->AddModule(new o2::passive::FrameStructure("FRAME", "Frame"));
168176
}
169177

170178
if (isActivated("TOF")) {
171179
// TOF
172-
auto tof = new o2::tof::Detector(true);
173-
run->AddModule(tof);
180+
run->AddModule(new o2::tof::Detector(isReadout("TOF")));
174181
}
175182

176183
if (isActivated("TRD")) {
177184
// TRD
178-
auto trd = new o2::trd::Detector(true);
179-
run->AddModule(trd);
185+
run->AddModule(new o2::trd::Detector(isReadout("TRD")));
180186
}
181187

182188
if (isActivated("TPC")) {
183189
// tpc
184-
auto tpc = new o2::tpc::Detector(true);
185-
run->AddModule(tpc);
190+
run->AddModule(new o2::tpc::Detector(isReadout("TPC")));
186191
}
187192
#ifdef ENABLE_UPGRADES
188193
if (isActivated("IT3")) {
189194
// ITS3
190-
auto its3 = new o2::its3::Detector(true);
191-
run->AddModule(its3);
195+
run->AddModule(new o2::its3::Detector(isReadout("IT3")));
192196
}
193197

194198
if (isActivated("TRK")) {
195199
// ALICE 3 TRK
196-
auto trk = new o2::trk::Detector(true);
197-
run->AddModule(trk);
200+
run->AddModule(new o2::trk::Detector(isReadout("TRK")));
198201
}
199202

200203
if (isActivated("FT3")) {
201204
// ALICE 3 FT3
202-
auto ft3 = new o2::ft3::Detector(true);
203-
run->AddModule(ft3);
205+
run->AddModule(new o2::ft3::Detector(isReadout("FT3")));
204206
}
205207
#endif
206208

207209
if (isActivated("ITS")) {
208210
// its
209-
auto its = new o2::its::Detector(true);
210-
run->AddModule(its);
211+
run->AddModule(new o2::its::Detector(isReadout("ITS")));
211212
}
212213

213214
if (isActivated("MFT")) {
214215
// mft
215-
auto mft = new o2::mft::Detector();
216-
run->AddModule(mft);
216+
run->AddModule(new o2::mft::Detector(isReadout("MFT")));
217217
}
218218

219219
if (isActivated("MCH")) {
220220
// mch
221-
run->AddModule(new o2::mch::Detector(true));
221+
run->AddModule(new o2::mch::Detector(isReadout("MCH")));
222222
}
223223

224224
if (isActivated("MID")) {
225225
// mid
226-
run->AddModule(new o2::mid::Detector(true));
226+
run->AddModule(new o2::mid::Detector(isReadout("MID")));
227227
}
228228

229229
if (isActivated("EMC")) {
230230
// emcal
231-
run->AddModule(new o2::emcal::Detector(true));
231+
run->AddModule(new o2::emcal::Detector(isReadout("EMC")));
232232
}
233233

234234
if (isActivated("PHS")) {
235235
// phos
236-
run->AddModule(new o2::phos::Detector(true));
236+
run->AddModule(new o2::phos::Detector(isReadout("PHS")));
237237
}
238238

239239
if (isActivated("CPV")) {
240240
// cpv
241-
run->AddModule(new o2::cpv::Detector(true));
241+
run->AddModule(new o2::cpv::Detector(isReadout("CPV")));
242242
}
243243

244244
if (isActivated("FT0")) {
245245
// FIT-T0
246-
run->AddModule(new o2::ft0::Detector(true));
246+
run->AddModule(new o2::ft0::Detector(isReadout("FT0")));
247247
}
248248

249249
if (isActivated("FV0")) {
250250
// FIT-V0
251-
run->AddModule(new o2::fv0::Detector(true));
251+
run->AddModule(new o2::fv0::Detector(isReadout("FV0")));
252252
}
253253

254254
if (isActivated("FDD")) {
255255
// FIT-FDD
256-
run->AddModule(new o2::fdd::Detector(true));
256+
run->AddModule(new o2::fdd::Detector(isReadout("FDD")));
257257
}
258258

259259
if (isActivated("HMP")) {
260260
// HMP
261-
run->AddModule(new o2::hmpid::Detector(true));
261+
run->AddModule(new o2::hmpid::Detector(isReadout("HMP")));
262262
}
263263

264264
if (isActivated("ZDC")) {
265265
// ZDC
266-
run->AddModule(new o2::zdc::Detector(true));
266+
run->AddModule(new o2::zdc::Detector(isReadout("ZDC")));
267267
}
268268

269269
if (geomonly) {

0 commit comments

Comments
 (0)