Project
Loading...
Searching...
No Matches
HitProcessingManager.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13#include <fairlogger/Logger.h>
14#include <vector>
15#include <map>
16#include <iostream>
17#include <TFile.h>
18#include <TClass.h>
19#include <TRandom3.h>
20
22
23namespace o2
24{
25namespace steer
26{
27
28bool HitProcessingManager::setupChain()
29{
30 if (mBackgroundFileNames.size() == 0 && mSignalFileNames.size() == 0) {
31 // there are no files to be analysed/processed;
32 LOG(warning) << "No files to be analysed";
33 return false;
34 }
35
36 // count max signal id
37 int sourcecounter = 0;
38 int maxsourceid = 0;
39 for (auto& pair : mSignalFileNames) {
40 sourcecounter++;
41 maxsourceid = std::max(pair.first, maxsourceid);
42 }
43 if (maxsourceid != sourcecounter) {
44 LOG(warning) << "max source id " << maxsourceid << " vs " << sourcecounter;
45 }
46 LOG(info) << "setting up " << maxsourceid + 1 << " chains";
47 mSimChains.resize(maxsourceid + 1);
48
49 // allocate chains
50 for (int i = 0; i < mSimChains.size(); ++i) {
51 // make o2sim a parameter
52 mSimChains[i] = new TChain("o2sim");
53 }
54
55 // background chain
56 auto& c = *mSimChains[0];
57 c.Reset();
58 for (auto& filename : mBackgroundFileNames) {
60 }
61
62 for (auto& pair : mSignalFileNames) {
63 const auto& signalid = pair.first;
64 const auto& filenamevector = pair.second;
65 auto& chain = *mSimChains[signalid];
66 for (auto& filename : filenamevector) {
68 }
69 }
70
71 return true;
72}
73
74void HitProcessingManager::setupRun(int ncollisions)
75{
76 if (!setupChain()) {
77 return;
78 }
79 if (mGeometryFile.size() > 0) {
80 // load geometry
81 TGeoManager::Import(mGeometryFile.c_str());
82 }
83
84 //
85 if (ncollisions != -1) {
86 mNumberOfCollisions = ncollisions;
87 } else {
88 mNumberOfCollisions = mSimChains[0]->GetEntries();
89 LOG(info) << "Automatic deduction of number of collisions ... will just take number of background entries "
90 << mNumberOfCollisions;
91 }
92 mDigitizationContext.setNCollisions(mNumberOfCollisions);
94
95 // sample collision (background-signal) constituents
97
98 // store prefixes as part of Context
99 std::vector<std::string> prefixes;
100 prefixes.emplace_back(mBackgroundFileNames[0]);
101 for (auto k : mSignalFileNames) {
102 prefixes.emplace_back(k.second[0]);
103 }
104 mDigitizationContext.setSimPrefixes(prefixes);
105}
106
108{
109 mDigitizationContext.saveToFile(filename);
110}
111
113{
115 if (context) {
116 context->printCollisionSummary();
117 mDigitizationContext = *context;
118 return true;
119 }
120 LOG(warn) << "NO DIGITIZATIONCONTEXT FOUND";
121 return false;
122}
123
125{
126 mDigitizationContext.getEventRecords().resize(mDigitizationContext.getNCollisions());
127 mInteractionSampler.generateCollisionTimes(mDigitizationContext.getEventRecords());
128 mDigitizationContext.setBunchFilling(mInteractionSampler.getBunchFilling());
129 mDigitizationContext.setMuPerBC(mInteractionSampler.getMuPerBC());
130}
131
133{
134 TRandom3 rnd(0); // we don't use the global to be in isolation
135 auto getBackgroundRoundRobin = [this]() {
136 static int bgcounter = 0;
137 int numbg = mSimChains[0]->GetEntries();
138 if (bgcounter == numbg) {
139 bgcounter = 0;
140 }
141 return EventPart(0, bgcounter++);
142 };
143
144 const int nsignalids = mSimChains.size() - 1;
145 auto getSignalRoundRobin = [this, nsignalids]() {
146 static int bgcounter = 0;
147 static int signalid = 0;
148 static std::vector<int> counter(nsignalids, 0);
149 if (signalid == nsignalids) {
150 signalid = 0;
151 }
152 const auto realsourceid = signalid + 1;
153 int numentries = mSimChains[realsourceid]->GetEntries();
154 if (counter[signalid] == numentries) {
155 counter[signalid] = 0;
156 }
157 EventPart e(realsourceid, counter[signalid]);
158 counter[signalid]++;
159 signalid++;
160 return e;
161 };
162
163 auto getRandomBackground = [this, &rnd]() {
164 int numbg = mSimChains[0]->GetEntries();
165 const auto eventID = (int)numbg * rnd.Rndm();
166 return EventPart(0, eventID);
167 };
168
169 auto getRandomSignal = [this, nsignalids, &rnd]() {
170 const auto sourceID = 1 + (int)(rnd.Rndm() * nsignalids);
171 const auto signalID = (int)(rnd.Rndm() * mSimChains[sourceID]->GetEntries());
172 return EventPart(sourceID, signalID);
173 };
174
175 // we fill mDigitizationContext.mEventParts
176 auto& eventparts = mDigitizationContext.getEventParts();
177 eventparts.clear();
178 eventparts.resize(mDigitizationContext.getEventRecords().size());
179 for (int i = 0; i < mDigitizationContext.getEventRecords().size(); ++i) {
180 eventparts[i].clear();
181 // NOTE: THIS PART WOULD BENEFIT FROM A MAJOR REDESIGN
182 // WISHFUL ITEMS WOULD BE:
183 // - ALLOW COLLISION ENGINEERING FROM OUTSIDE (give wanted sequence as file)
184 // * the outside person can decide what kind of sampling and sequence to use
185 // - CHECK IF VERTEX IS CONSISTENT
186 if (mSampleCollisionsRandomly) {
187 eventparts[i].emplace_back(getRandomBackground());
188 if (mSimChains.size() > 1) {
189 eventparts[i].emplace_back(getRandomSignal());
190 }
191 } else {
192 // push any number of constituents?
193 // for the moment just 2 : one background and one signal
194 eventparts[i].emplace_back(getBackgroundRoundRobin());
195 if (mSimChains.size() > 1) {
196 eventparts[i].emplace_back(getSignalRoundRobin());
197 }
198 }
199 }
200
201 // push any number of constituents?
202 // for the moment just max 2 : one background and one signal
203 mDigitizationContext.setMaxNumberParts(1);
204 if (mSimChains.size() > 1) {
205 mDigitizationContext.setMaxNumberParts(2);
206 }
207
208 mDigitizationContext.printCollisionSummary();
209}
210
212{
213 setupRun();
214 // sample other stuff
215 for (auto& f : mRegisteredRunFunctions) {
216 f(mDigitizationContext);
217 }
218}
219
220} // end namespace steer
221} // end namespace o2
int32_t i
GPUChain * chain
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
ClassImp(o2::steer::HitProcessingManager)
uint32_t c
Definition RawData.h:2
static std::string getMCHeadersFileName(const std::string_view prefix=STANDARDSIMPREFIX)
Definition NameConf.h:52
void printCollisionSummary(bool withQED=false, int truncateOutputTo=-1) const
void setSimPrefixes(std::vector< std::string > const &p)
std::vector< o2::InteractionTimeRecord > & getEventRecords(bool withQED=false)
std::vector< std::vector< o2::steer::EventPart > > & getEventParts(bool withQED=false)
void saveToFile(std::string_view filename) const
void setBunchFilling(o2::BunchFilling const &bf)
static DigitizationContext * loadFromFile(std::string_view filename="")
O2 specific run class; steering hit processing.
bool setupRunFromExistingContext(const char *filename)
void writeDigitizationContext(const char *filename) const
const BunchFilling & getBunchFilling() const
void generateCollisionTimes(std::vector< o2::InteractionTimeRecord > &dest)
GLsizeiptr size
Definition glcorearb.h:659
GLdouble f
Definition glcorearb.h:310
GLuint counter
Definition glcorearb.h:3987
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string filename()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"