Skip to content

Commit

Permalink
ITSMFT time-evolving dead maps, builder and simulation (AliceO2Group#…
Browse files Browse the repository at this point in the history
…12525)

* ITSMFT time-evolving dead maps, builder and simulation

* adding copyright

* clang

* Dummy commit to restart CI after uploaded CCDB object.

* Dummy update to restart CI after fixing default MFT object

* code revision

* harmless correction on warning message

---------

Co-authored-by: Nicolo Valle <nicolo.valle@cern.ch>
Co-authored-by: Ruben Shahoyan <shahor02@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 17, 2024
1 parent 29c371d commit b33072f
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 49 deletions.
1 change: 1 addition & 0 deletions DataFormats/Detectors/ITSMFT/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ o2_target_root_dictionary(DataFormatsITSMFT
include/DataFormatsITSMFT/Digit.h
include/DataFormatsITSMFT/GBTCalibData.h
include/DataFormatsITSMFT/NoiseMap.h
include/DataFormatsITSMFT/TimeDeadMap.h
include/DataFormatsITSMFT/Cluster.h
include/DataFormatsITSMFT/CompCluster.h
include/DataFormatsITSMFT/ClusterPattern.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class NoiseMap
void print();
void fill(const gsl::span<const CompClusterExt> data);
void merge(const NoiseMap* prev) {}

const std::map<int, int>* getChipMap(int chip) const { return chip < (int)mNoisyPixels.size() ? &mNoisyPixels[chip] : nullptr; }

std::map<int, int>& getChip(int chip) { return mNoisyPixels[chip]; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file TimeDeadMap.h
/// \brief Definition of the ITSMFT time-dependend dead map
#ifndef ALICEO2_ITSMFT_TIMEDEADMAP_H
#define ALICEO2_ITSMFT_TIMEDEADMAP_H

#include "Rtypes.h"
#include "DetectorsCommonDataFormats/DetID.h"
#include <iostream>
#include <vector>
#include <map>

namespace o2
{

namespace itsmft
{

class TimeDeadMap
{
public:
// Constructor
TimeDeadMap(std::map<unsigned long, std::vector<uint16_t>>& deadmap)
{
mEvolvingDeadMap.swap(deadmap);
}

/// Constructor
TimeDeadMap() = default;
/// Destructor
~TimeDeadMap() = default;

void fillMap(unsigned long firstOrbit, const std::vector<uint16_t>& deadVect)
{
mEvolvingDeadMap[firstOrbit] = deadVect;
};

void fillMap(const std::vector<uint16_t>& deadVect)
{
mStaticDeadMap = deadVect;
}

void clear()
{
mEvolvingDeadMap.clear();
mStaticDeadMap.clear();
}

void decodeMap(o2::itsmft::NoiseMap& noisemap)
{ // for static part only
if (mMAP_VERSION != "3") {
LOG(error) << "Trying to decode static part of deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing.";
return;
}
for (int iel = 0; iel < mStaticDeadMap.size(); iel++) {
uint16_t w = mStaticDeadMap[iel];
noisemap.maskFullChip(w & 0x7FFF);
if (w & 0x8000) {
for (int w2 = (w & 0x7FFF) + 1; w2 < mStaticDeadMap.at(iel + 1); w2++) {
noisemap.maskFullChip(w2);
}
}
}
}

void decodeMap(unsigned long orbit, o2::itsmft::NoiseMap& noisemap, bool includeStaticMap = true)
{ // for time-dependent and (optionally) static part

if (mMAP_VERSION != "3" && mMAP_VERSION != "4") {
LOG(error) << "Trying to decode time-dependent deadmap version " << mMAP_VERSION << ". Not implemented, doing nothing.";
return;
}

if (mEvolvingDeadMap.empty()) {
LOG(warning) << "Time-dependent dead map is empty. Doing nothing.";
return;
} else if (orbit > mEvolvingDeadMap.rbegin()->first + 11000 * 300 || orbit < mEvolvingDeadMap.begin()->first - 11000 * 300) {
// the map should not leave several minutes uncovered.
LOG(warning) << "Time-dependent dead map: the requested orbit " << orbit << " seems to be out of the range stored in the map.";
}

std::vector<uint16_t> closestVec;
long dT = getMapAtOrbit(orbit, closestVec);

// add static part if requested. something may be masked twice
if (includeStaticMap && mMAP_VERSION != "3") {
closestVec.insert(closestVec.end(), mStaticDeadMap.begin(), mStaticDeadMap.end());
}

// vector encoding: if 1<<15 = 0x8000 is set, the word encodes the first element of a range, with mask (1<<15)-1 = 0x7FFF. The last element of the range is the next in the vector.

for (int iel = 0; iel < closestVec.size(); iel++) {
uint16_t w = closestVec.at(iel);
noisemap.maskFullChip(w & 0x7FFF);
if (w & 0x8000) {
for (int w2 = (w & 0x7FFF) + 1; w2 < closestVec.at(iel + 1); w2++) {
noisemap.maskFullChip(w2);
}
}
}
};

std::string getMapVersion() const { return mMAP_VERSION; };

unsigned long getEvolvingMapSize() const { return mEvolvingDeadMap.size(); };

std::vector<unsigned long> getEvolvingMapKeys()
{
std::vector<unsigned long> keys;
std::transform(mEvolvingDeadMap.begin(), mEvolvingDeadMap.end(), std::back_inserter(keys),
[](const auto& O) { return O.first; });
return keys;
}

void getStaticMap(std::vector<uint16_t>& mmap) { mmap = mStaticDeadMap; };

long getMapAtOrbit(unsigned long orbit, std::vector<uint16_t>& mmap)
{ // fills mmap and returns orbit - lower_bound
if (mEvolvingDeadMap.empty()) {
LOG(warning) << "Requested orbit " << orbit << "from an empty time-dependent map. Doing nothing";
return (long)orbit;
}
auto closest = mEvolvingDeadMap.lower_bound(orbit);
if (closest != mEvolvingDeadMap.end()) {
mmap = closest->second;
return (long)orbit - closest->first;
} else {
mmap = mEvolvingDeadMap.rbegin()->second;
return (long)(orbit)-mEvolvingDeadMap.rbegin()->first;
}
}

void setMapVersion(std::string version) { mMAP_VERSION = version; };

bool isDefault() { return mIsDefaultObject; };
void setAsDefault(bool isdef = true) { mIsDefaultObject = isdef; };

private:
bool mIsDefaultObject = false;
std::string mMAP_VERSION = "3";
std::map<unsigned long, std::vector<uint16_t>> mEvolvingDeadMap; ///< Internal dead chip map representation. key = orbit
std::vector<uint16_t> mStaticDeadMap; ///< To store map valid for every orbit. Filled starting from version = 4.

ClassDefNV(TimeDeadMap, 2);
};

} // namespace itsmft
} // namespace o2

#endif /* ALICEO2_ITSMFT_TIMEDEADMAP_H */
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma link C++ class o2::itsmft::Digit + ;
#pragma link C++ class o2::itsmft::NoiseMap + ;
#pragma link C++ class o2::itsmft::TimeDeadMap + ;
#pragma link C++ class std::vector < o2::itsmft::Digit> + ;

#pragma link C++ class o2::itsmft::GBTCalibData + ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class Digitizer : public TObject

static constexpr float sec2ns = 1e9;

o2::itsmft::DigiParams mParams; ///< digitization parameters
o2::InteractionTimeRecord mEventTime; ///< global event time and interaction record
o2::itsmft::DigiParams mParams; ///< digitization parameters
o2::InteractionTimeRecord mEventTime; ///< global event time and interaction record
o2::InteractionRecord mIRFirstSampledTF; ///< IR of the 1st sampled IR, noise-only ROFs will be inserted till this IR only
double mCollisionTimeWrtROF;
uint32_t mROFrameMin = 0; ///< lowest RO frame of current digits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <fairmq/Device.h>

#include <ITSMFTReconstruction/RawPixelDecoder.h> //o2::itsmft::RawPixelDecoder
#include "DataFormatsITSMFT/TimeDeadMap.h"
#include "DetectorsCalibration/Utils.h"
#include "DetectorsCommonDataFormats/FileMetaData.h"
#include "DetectorsBase/GRPGeomHelper.h"
Expand Down Expand Up @@ -91,7 +92,7 @@ class ITSMFTDeadMapBuilder : public Task
std::string mObjectName;
std::string mLocalOutputDir;

std::string MAP_VERSION = "2"; // to change in case the encoding or the format change
std::string MAP_VERSION = "3"; // to change in case the encoding or the format change

std::vector<uint16_t> mDeadMapTF{};

Expand All @@ -101,14 +102,14 @@ class ITSMFTDeadMapBuilder : public Task

int mTFSampling = 1000;

std::map<unsigned long, std::vector<uint16_t>> mMapObject{};
o2::itsmft::TimeDeadMap mMapObject;

void finalizeOutput();
void PrepareOutputCcdb(DataAllocator& output);

// Utils

uint16_t getElementIDFromChip(uint16_t);
std::vector<uint16_t> getChipIDsOnSameCable(uint16_t);

o2::framework::DataTakingContext mDataTakingContext{};
o2::framework::TimingInfo mTimingInfo{};
Expand Down
Loading

0 comments on commit b33072f

Please sign in to comment.