Skip to content

Commit 4b6daad

Browse files
committed
T0 simulation works with this
1 parent 195f1c2 commit 4b6daad

File tree

13 files changed

+173
-109
lines changed

13 files changed

+173
-109
lines changed

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/DetID.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class DetID
5858
static constexpr ID MCH = 9;
5959
static constexpr ID MID = 10;
6060
static constexpr ID ZDC = 11;
61-
static constexpr ID FIT = 12;
61+
static constexpr ID T0 = 12;
6262
static constexpr ID ACO = 13;
6363
static constexpr ID First = ITS;
6464
static constexpr ID Last = ACO; ///< if extra detectors added, update this !!!
@@ -105,13 +105,13 @@ class DetID
105105
ID mID = First; ///< detector ID
106106

107107
static constexpr const char* sDetNames[nDetectors + 1] = ///< defined detector names
108-
{ "ITS", "TPC", "TRD", "TOF", "PHS", "CPV", "EMC", "HMP", "MFT", "MCH", "MID", "ZDC", "FIT", "ACO", nullptr };
108+
{ "ITS", "TPC", "TRD", "TOF", "PHS", "CPV", "EMC", "HMP", "MFT", "MCH", "MID", "ZDC", "T0", "ACO", nullptr };
109109

110110
// detector names, will be defined in DataSources
111111
static constexpr std::array<mask_t, nDetectors> sMasks = ///< detectot masks
112112
{ utils::bit2Mask(ITS), utils::bit2Mask(TPC), utils::bit2Mask(TRD), utils::bit2Mask(TOF), utils::bit2Mask(PHS),
113113
utils::bit2Mask(CPV), utils::bit2Mask(EMC), utils::bit2Mask(HMP), utils::bit2Mask(MFT), utils::bit2Mask(MCH),
114-
utils::bit2Mask(MID), utils::bit2Mask(ZDC), utils::bit2Mask(FIT), utils::bit2Mask(ACO) };
114+
utils::bit2Mask(MID), utils::bit2Mask(ZDC), utils::bit2Mask(T0), utils::bit2Mask(ACO) };
115115

116116
ClassDefNV(DetID, 1);
117117
};

DataFormats/Detectors/Common/src/DetID.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ constexpr std::array<DetID::mask_t, DetID::nDetectors> DetID::sMasks;
2525

2626
// redundant declarations
2727
constexpr DetID::ID DetID::ITS, DetID::TPC, DetID::TRD, DetID::TOF, DetID::PHS, DetID::CPV, DetID::EMC,
28-
DetID::HMP, DetID::MFT, DetID::MCH, DetID::MID, DetID::ZDC, DetID::FIT, DetID::ACO, DetID::First, DetID::Last;
28+
DetID::HMP, DetID::MFT, DetID::MCH, DetID::MID, DetID::ZDC, DetID::T0, DetID::ACO, DetID::First, DetID::Last;
2929

3030
constexpr int DetID::nDetectors;
3131

DataFormats/Headers/include/Headers/DataHeader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ constexpr o2::header::DataOrigin gDataOriginACO{ "ACO" };
589589
constexpr o2::header::DataOrigin gDataOriginCPV{ "CPV" };
590590
constexpr o2::header::DataOrigin gDataOriginCTP{ "CTP" };
591591
constexpr o2::header::DataOrigin gDataOriginEMC{ "EMC" };
592-
constexpr o2::header::DataOrigin gDataOriginFIT{ "FIT" };
592+
constexpr o2::header::DataOrigin gDataOriginT0{ "T0" };
593593
constexpr o2::header::DataOrigin gDataOriginHMP{ "HMP" };
594594
constexpr o2::header::DataOrigin gDataOriginITS{ "ITS" };
595595
constexpr o2::header::DataOrigin gDataOriginMCH{ "MCH" };

Detectors/FIT/T0/simulation/src/Detector.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using o2::t0::Geometry;
3434
ClassImp(Detector);
3535

3636
Detector::Detector(Bool_t Active)
37-
: o2::Base::DetImpl<Detector>("FIT", Active), mIdSens1(0), mPMTeff(nullptr), mHits(o2::utils::createSimVector<HitType>())
37+
: o2::Base::DetImpl<Detector>("T0", Active), mIdSens1(0), mPMTeff(nullptr), mHits(o2::utils::createSimVector<HitType>())
3838

3939
{
4040
// Gegeo = GetGeometry() ;
@@ -384,7 +384,7 @@ void Detector::DefineOpticalProperties()
384384
const char* aliceO2env = std::getenv("O2_ROOT");
385385
if (aliceO2env)
386386
inputDir = aliceO2env;
387-
inputDir += "/share/Detectors/FIT/files/";
387+
inputDir += "/share/Detectors/T0/files/";
388388

389389
TString optPropPath = inputDir + "quartzOptProperties.txt";
390390
optPropPath = gSystem->ExpandPathName(optPropPath.Data()); // Expand $(ALICE_ROOT) into real system path

Detectors/FIT/T0/simulation/src/DigitizerTask.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ClassImp(o2::t0::DigitizerTask);
2222
using namespace o2::fit;
2323
using namespace o2::t0;
2424

25-
DigitizerTask::DigitizerTask() : FairTask("FITDigitizerTask"), mDigitizer() {}
25+
DigitizerTask::DigitizerTask() : FairTask("T0DigitizerTask"), mDigitizer() {}
2626
DigitizerTask::~DigitizerTask()
2727
{
2828
if (mEventDigit)
@@ -50,7 +50,7 @@ InitStatus DigitizerTask::Init()
5050
mDigitizer.setMCLabels(mMCTruthArrayPtr);
5151

5252
// Register output container
53-
mgr->RegisterAny("FITDigit", mEventDigit, kTRUE);
53+
mgr->RegisterAny("FITT0Digit", mEventDigit, kTRUE);
5454
// mMCTruthArray = new typename std::remove_pointer<decltype(mMCTruthArray)>::type;
5555
mgr->RegisterAny("FITDigitMCTruth", mMCTruthArrayPtr, kTRUE);
5656
mDigitizer.init();

Steer/DigitizerWorkflow/src/FITDigitWriterSpec.cxx

Lines changed: 116 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@
88
// granted to it by virtue of its status as an Intergovernmental Organization
99
// or submit itself to any jurisdiction.
1010

11-
/// @brief Processor spec for a ROOT file writer for TOF digits
11+
/// @brief Processor spec for a ROOT file writer for FIT T0&V0 digits
1212

1313
#include "FITDigitWriterSpec.h"
1414
#include "Framework/CallbackService.h"
1515
#include "Framework/ControlService.h"
16-
#include <SimulationDataFormat/MCCompLabel.h>
17-
#include <SimulationDataFormat/MCTruthContainer.h>
18-
#include "TTree.h"
19-
#include "TBranch.h"
20-
#include "TFile.h"
16+
#include "Framework/Task.h"
2117
#include "FITBase/Digit.h"
18+
#include "Headers/DataHeader.h"
19+
#include "DetectorsCommonDataFormats/DetID.h"
20+
#include "SimulationDataFormat/MCTruthContainer.h"
21+
#include "SimulationDataFormat/MCCompLabel.h"
22+
#include <TTree.h>
23+
#include <TBranch.h>
24+
#include <TFile.h>
2225
#include <memory> // for make_shared, make_unique, unique_ptr
2326
#include <vector>
27+
#include <string>
28+
#include <algorithm>
2429

2530
using namespace o2::framework;
2631
using SubSpecificationType = o2::framework::DataAllocator::SubSpecificationType;
@@ -30,88 +35,124 @@ namespace o2
3035
namespace fit
3136
{
3237

33-
template <typename T>
34-
TBranch* getOrMakeBranch(TTree& tree, std::string brname, T* ptr)
38+
class FITDPLDigitWriter
3539
{
36-
if (auto br = tree.GetBranch(brname.c_str())) {
37-
br->SetAddress(static_cast<void*>(&ptr));
38-
return br;
40+
41+
using MCCont = o2::dataformats::MCTruthContainer<o2::MCCompLabel>;
42+
43+
public:
44+
void init(framework::InitContext& ic)
45+
{
46+
std::string detStrL = mID.getName();
47+
std::transform(detStrL.begin(), detStrL.end(), detStrL.begin(), ::tolower);
48+
49+
auto filename = ic.options().get<std::string>((detStrL + "-digit-outfile").c_str());
50+
auto treename = ic.options().get<std::string>("treename");
51+
52+
mOutFile = std::make_unique<TFile>(filename.c_str(), "RECREATE");
53+
if (!mOutFile || mOutFile->IsZombie()) {
54+
LOG(ERROR) << "Failed to open " << filename << " output file";
55+
} else {
56+
LOG(INFO) << "Opened " << filename << " output file";
57+
}
58+
mOutTree = std::make_unique<TTree>(treename.c_str(), treename.c_str());
3959
}
40-
// otherwise make it
41-
return tree.Branch(brname.c_str(), ptr);
42-
}
4360

61+
void run(framework::ProcessingContext& pc)
62+
{
63+
if (mFinished) {
64+
return;
65+
}
66+
std::string detStr = mID.getName();
67+
std::string detStrL = mID.getName();
68+
std::transform(detStrL.begin(), detStrL.end(), detStrL.begin(), ::tolower);
69+
70+
// retrieve the digits from the input
71+
auto inDigits = pc.inputs().get<std::vector<o2::fit::Digit>>((detStr + "digits").c_str());
72+
// auto inROFs = pc.inputs().get<std::vector<o2::ITSMFT::ROFRecord>>((detStr + "digitsROF").c_str());
73+
// auto inMC2ROFs = pc.inputs().get<std::vector<o2::ITSMFT::MC2ROFRecord>>((detStr + "digitsMC2ROF").c_str());
74+
// auto inLabels = pc.inputs().get<MCCont*>((detStr + "digitsMCTR").c_str());
75+
LOG(INFO) << "RECEIVED DIGITS SIZE " << inDigits.size();
76+
77+
auto digitsP = &inDigits;
78+
// auto labelsRaw = inLabels.get();
79+
// connect this to a particular branch
80+
81+
auto brDig = getOrMakeBranch(*mOutTree.get(), (detStr + "Digit").c_str(), &digitsP);
82+
// auto brLbl = getOrMakeBranch(*mOutTree.get(), (detStr + "DigitMCTruth").c_str(), &labelsRaw);
83+
mOutTree->Fill();
84+
85+
mOutFile->cd();
86+
mOutTree->Write();
87+
mOutTree.reset(); // delete the tree before closing the file
88+
mOutFile->Close();
89+
mFinished = true;
90+
pc.services().get<ControlService>().readyToQuit(false);
91+
}
92+
93+
protected:
94+
FITDPLDigitWriter() {}
95+
template <typename T>
96+
TBranch* getOrMakeBranch(TTree& tree, std::string brname, T* ptr)
97+
{
98+
if (auto br = tree.GetBranch(brname.c_str())) {
99+
br->SetAddress(static_cast<void*>(ptr));
100+
return br;
101+
}
102+
// otherwise make it
103+
return tree.Branch(brname.c_str(), ptr);
104+
}
105+
106+
bool mFinished = false;
107+
o2::detectors::DetID mID;
108+
o2::header::DataOrigin mOrigin = o2::header::gDataOriginInvalid;
109+
std::vector<o2::fit::Digit> mDigits; // input digits
110+
std::unique_ptr<TFile> mOutFile;
111+
std::unique_ptr<TTree> mOutTree;
112+
};
113+
114+
//_______________________________________________
115+
class T0DPLDigitWriter : public FITDPLDigitWriter
116+
{
117+
public:
118+
// FIXME: origina should be extractable from the DetID, the problem is 3d party header dependencies
119+
static constexpr o2::detectors::DetID::ID DETID = o2::detectors::DetID::T0;
120+
static constexpr o2::header::DataOrigin DETOR = o2::header::gDataOriginT0;
121+
T0DPLDigitWriter()
122+
{
123+
mID = DETID;
124+
mOrigin = DETOR;
125+
}
126+
};
127+
128+
constexpr o2::detectors::DetID::ID T0DPLDigitWriter::DETID;
129+
constexpr o2::header::DataOrigin T0DPLDigitWriter::DETOR;
130+
131+
//_______________________________________________
44132
/// create the processor spec
45-
/// TODO: replace by generic processor once this is working
46-
DataProcessorSpec getFITDigitWriterSpec()
133+
/// describing a processor receiving digits for ITS/MFT and writing them to file
134+
DataProcessorSpec getT0DigitWriterSpec()
47135
{
48-
auto initFunction = [](InitContext& ic) {
49-
// get the option from the init context
50-
auto filename = ic.options().get<std::string>("fit-digit-outfile");
51-
auto treename = ic.options().get<std::string>("treename");
136+
std::string detStr = o2::detectors::DetID::getName(T0DPLDigitWriter::DETID);
137+
std::string detStrL = detStr;
138+
std::transform(detStrL.begin(), detStrL.end(), detStrL.begin(), ::tolower);
139+
auto detOrig = T0DPLDigitWriter::DETOR;
52140

53-
auto outputfile = std::make_shared<TFile>(filename.c_str(), "RECREATE");
54-
auto outputtree = std::make_shared<TTree>(treename.c_str(), treename.c_str());
55-
56-
// container for incoming digits
57-
auto digits = std::make_shared<std::vector<o2::fit::Digit>>();
58-
59-
// the callback to be set as hook at stop of processing for the framework
60-
auto finishWriting = [outputfile, outputtree]() {
61-
outputtree->SetEntries(1);
62-
outputtree->Write();
63-
outputfile->Close();
64-
};
65-
ic.services().get<CallbackService>().set(CallbackService::Id::Stop, finishWriting);
66-
67-
// setup the processing function
68-
// using by-copy capture of the worker instance shared pointer
69-
// the shared pointer makes sure to clean up the instance when the processing
70-
// function gets out of scope
71-
auto processingFct = [outputfile, outputtree, digits](ProcessingContext& pc) {
72-
static bool finished = false;
73-
if (finished) {
74-
// avoid being executed again when marked as finished;
75-
return;
76-
}
77-
78-
// retrieve the digits from the input
79-
auto indata = pc.inputs().get<std::vector<o2::fit::Digit>>("fitdigits");
80-
LOG(INFO) << "RECEIVED DIGITS SIZE " << indata.size();
81-
*digits.get() = std::move(indata);
82-
83-
// connect this to a particular branch
84-
auto br = getOrMakeBranch(*outputtree.get(), "FITDigit", digits.get());
85-
br->Fill();
86-
87-
// retrieve labels from the input
88-
//auto labeldata = pc.inputs().get<o2::dataformats::MCTruthContainer<o2::MCCompLabel>*>("tofdigitlabels");
89-
//LOG(INFO) << "TOF GOT " << labeldata->getNElements() << " LABELS ";
90-
//auto labeldataraw = labeldata.get();
91-
// connect this to a particular branch
92-
//auto labelbr = getOrMakeBranch(*outputtree.get(), "TOFDigitMCTruth", &labeldataraw);
93-
//labelbr->Fill();
94-
95-
finished = true;
96-
pc.services().get<ControlService>().readyToQuit(false);
97-
};
98-
99-
// return the actual processing function as a lambda function using variables
100-
// of the init function
101-
return processingFct;
102-
};
141+
std::vector<InputSpec> inputs;
142+
inputs.emplace_back(InputSpec{ (detStr + "digits").c_str(), detOrig, "DIGITS", 0, Lifetime::Timeframe });
103143

104144
return DataProcessorSpec{
105-
"FITDigitWriter",
106-
Inputs{ InputSpec{ "fitdigits", "FIT", "DIGITS", 0, Lifetime::Timeframe },
107-
/* InputSpec{ "tofdigitlabels", "TOF", "DIGITSMCTR", 0, Lifetime::Timeframe } */ },
145+
(detStr + "DigitWriter").c_str(),
146+
inputs,
108147
{}, // no output
109-
AlgorithmSpec(initFunction),
148+
AlgorithmSpec(adaptFromTask<T0DPLDigitWriter>()),
110149
Options{
111-
{ "fit-digit-outfile", VariantType::String, "fitdigits.root", { "Name of the input file" } },
150+
{ (detStrL + "-digit-outfile").c_str(), VariantType::String, (detStrL + "digits.root").c_str(), { "Name of the input file" } },
112151
{ "treename", VariantType::String, "o2sim", { "Name of top-level TTree" } },
113152
}
114153
};
115154
}
155+
156+
116157
} // end namespace fit
117158
} // end namespace o2

Steer/DigitizerWorkflow/src/FITDigitWriterSpec.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ namespace o2
1818
namespace fit
1919
{
2020

21-
o2::framework::DataProcessorSpec getFITDigitWriterSpec();
21+
o2::framework::DataProcessorSpec getT0DigitWriterSpec();
22+
//o2::framework::DataProcessorSpec getMFTDigitWriterSpec();
2223

23-
} // end namespace tof
24+
} // end namespace itsmft
2425
} // end namespace o2
25-
26-
#endif /* STEER_DIGITIZERWORKFLOW_FITDIGITWRITER_H_ */
26+
27+
#endif /* STEER_DIGITIZERWORKFLOW_ITSMFTDIGITWRITER_H_ */

0 commit comments

Comments
 (0)