diff --git a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/CMakeLists.txt b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/CMakeLists.txt old mode 100644 new mode 100755 index c5370f5dfda8c003c2df33049a9fa59d2b18b095..d66333886fd7ee8e4fc516407be82e8f433d56b7 --- a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/CMakeLists.txt +++ b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/CMakeLists.txt @@ -12,7 +12,7 @@ atlas_add_library( PixelCalibAlgsLib PixelCalibAlgs/*.h src/*.cxx PUBLIC_HEADERS PixelCalibAlgs INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps CxxUtils GaudiKernel InDetConditionsSummaryService + LINK_LIBRARIES ${ROOT_LIBRARIES} AthenaBaseComps CxxUtils GaudiKernel InDetConditionsSummaryService InDetPrepRawData InDetReadoutGeometry PixelReadoutGeometryLib PixelConditionsData StoreGateLib PRIVATE_LINK_LIBRARIES AthenaPoolUtilities EventInfo InDetIdentifier InDetRawData PixelGeoModelLib ) @@ -25,4 +25,4 @@ atlas_add_executable( makeInactiveModuleList INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} LINK_LIBRARIES ${ROOT_LIBRARIES} PixelConditionsData PixelCalibAlgsLib ) -atlas_install_runtime ( share/HashVSdcsID.dat share/table_Run2.txt share/PixelMapping_Run2.dat ) +atlas_install_runtime ( share/HashVSdcsID.dat share/table_Run2.txt share/PixelMapping_Run2.dat share/PixelModuleFeMask_create_db.py) diff --git a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/HitMapBuilder.h b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/HitMapBuilder.h new file mode 100755 index 0000000000000000000000000000000000000000..013a3f9c6bfa25a1a765baca2bdbcf00526268b6 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/PixelCalibAlgs/HitMapBuilder.h @@ -0,0 +1,103 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef PIXELCONDITIONSALGS_HITMAPBUILDER_H +#define PIXELCONDITIONSALGS_HITMAPBUILDER_H + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "GaudiKernel/ServiceHandle.h" +#include "PixelReadoutGeometry/IPixelReadoutManager.h" + +#include <string> +#include <sstream> +#include <vector> +#include <fstream> +#include <utility> // pair + +//yosuke class IInDetConditionsSvc; +//yosuke class IPixelByteStreamErrorsSvc; +class ITHistSvc; +class PixelID; +class TH2F; +class TH1F; +class TH1; +//yosuke class ISpecialPixelMapSvc; + +namespace InDetDD{ + class PixelDetectorManager; +} + +/** + * + * HitMapBuilder.h + * + * Creates hit maps and maps of noisy pixels for every module + * of the pixel detector. The maps are stored in a root file. + * They can be written to the conditions database using the + * algorithm NoiseMapDBWriter. + * + * ruwiedel@physik.uni-bonn.de + * + */ + +class HitMapBuilder: public AthAlgorithm { + + public: + HitMapBuilder(const std::string& name, ISvcLocator* pSvcLocator); + ~HitMapBuilder(); + + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + + private: + std::string getDCSIDFromPosition(int bec, int layer, int modPhi, int modEta); + std::vector<std::string> &splitter(const std::string &str, char delim, std::vector<std::string> &elems); + std::vector<std::string> splitter(const std::string &str, char delim); + StatusCode registerHistograms(); + const std::string histoSuffix(const int bec, const int layer); + + private: + ServiceHandle <ITHistSvc> m_tHistSvc; + const InDetDD::PixelDetectorManager *m_pixman; + const PixelID *m_pixelID; + + // vector of modulename and vector(barrel/endcap, layer, phi, eta) + std::vector< std::pair< std::string, std::vector<int> > > m_pixelMapping; + + std::string m_pixelRDOKey; + + double m_nEvents; + std::vector<double> m_nEventsLB; // Events per LB + std::vector<double> m_nEventsLBCategory; // Events per certain LB for LB category + + std::unique_ptr<TH1F> m_nEventsHist; + std::unique_ptr<TH1F> m_nEventsLBHist; + std::vector<std::unique_ptr<TH2F>> m_occupancyMaps; + std::vector<std::unique_ptr<TH2F>> m_occupancyMapsIBL2dLB; + std::vector<std::unique_ptr<TH1F>> m_TOTdistributions; + std::vector<std::unique_ptr<TH1F>> m_TOTdistributionsIBL2dLB; + std::vector<std::unique_ptr<TH1F>> m_occupancyLB; + + int m_hist_lbMax; // max number of LB + + bool m_occupancyPerBC; + + unsigned int m_nBCReadout; + + int m_evt_lbMin; // lower limit for LB to be taken into account + int m_evt_lbMax; // upper limit for LB to be taken into account + + int m_LBrange_max = -9999; + + const unsigned int m_nIblFes = 14 * (4 + 6*2) * 2; // 14 stave * (4 3Ds + 6 2Ds * 2 Fes) * 2 sides = 448 + const int m_perLB_min=0, m_perLB_max=3000, m_perLB_step=100; // For plots per certain LBs + const int m_perLB_n = (m_perLB_max-m_perLB_min)/m_perLB_step; // For plots per certain LBs + + const int m_fei4bPixels = 26880; // 80 * 336 + const int m_pixModPixels = 46080; // 144 * 320; +}; + + +#endif // PIXELCONDITIONSALGS_HITMAPBUILDER_H diff --git a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/share/HitMapBuilder.py b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/share/HitMapBuilder.py new file mode 100644 index 0000000000000000000000000000000000000000..53d388a17eb364e5d20694416f1fd8ab166fd9b7 --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/share/HitMapBuilder.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -* +# Filename: HitMapBuilder.py +# Author: Pixel DQ +# Author: Yosuke Takubo (Yosuke.Takubo at cern.ch) +# Project: Hit Map Tool +# Description: ATHENA Jop Options for HitMapBuilder.py +# Date: Jul. 2019 +# Input: inputfilelist (A list of byte stream files or pool files) +# or athena.py arguments --filesInput +# or RAW files in current directory +# Output: A ROOT file +############################################################### + +#============================================================== +# Job options file +#============================================================== +doClusterization = False +doMonitoring = False +doValidate = False +filelist = 'inputfilelist' +nevents = -1 + +from AthenaCommon.AppMgr import theApp +from AthenaCommon.AppMgr import ServiceMgr +from AthenaCommon.AlgSequence import AlgSequence +topSequence = AlgSequence() +from AthenaCommon.AppMgr import ToolSvc +from AthenaCommon.AthenaCommonFlags import athenaCommonFlags + +#------------------------------------------ +# Input files +#------------------------------------------ +import glob +collection = [] +if len(athenaCommonFlags.FilesInput.get_Value()) != 0: # athena.py argument --filesInput ... + collection = athenaCommonFlags.FilesInput.get_Value() +elif os.path.isfile(filelist): # inputfilelist + for line in open(filelist): + if line[0] != '#': + collection.append(line.strip()) + athenaCommonFlags.FilesInput = collection +elif len(glob.glob("data*TeV*RAW*")) != 0: + collection = glob.glob("data*TeV*RAW*") # Find data file from current directory for pathena + athenaCommonFlags.FilesInput = collection +else: + errmess="### Unable to open input filelist: '%s'! or --FilesInput not set! or cannot find data file on current directory!" % filelist + raise RuntimeError(errmess) + +#------------------------------------------ +# DetFlags +#------------------------------------------ +from AthenaCommon.DetFlags import DetFlags +DetFlags.all_setOff() +DetFlags.pixel_setOn() +DetFlags.Print() + +#------------------------------------------ +# PixelDist +#------------------------------------------ +# Conditions sequence for Athena MT +from AthenaCommon.AlgSequence import AthSequencer +condSeq = AthSequencer("AthCondSeq") + +from PixelConditionsAlgorithms.PixelConditionsAlgorithmsConf import PixelConfigCondAlg +alg = PixelConfigCondAlg(name="PixelConfigCondAlg") +PixelConfigCondAlg.DistortionInputSource = 0 +alg.DistortionWriteToFile = False +condSeq += alg + +print(alg) + +from PixelConditionsAlgorithms.PixelConditionsAlgorithmsConf import PixelDistortionAlg +condSeq += PixelDistortionAlg(name="PixelDistortionAlg") +#------------------------------------------ +# GlobalFlags +#------------------------------------------ +from AthenaCommon.GlobalFlags import globalflags +globalflags.DetDescrVersion = "ATLAS-R2-2016-01-00-01" # [SGS] how to know exact version (e.g. AMI) ? +globalflags.DetGeo = 'atlas' +globalflags.DataSource = 'data' + +# set InputFormat +import PyUtils.AthFile as AthFile +inputfile = AthFile.fopen( collection[0] ) + +if inputfile.fileinfos['file_type'] == 'bs': + globalflags.InputFormat = 'bytestream' +elif inputfile.fileinfos['file_type'] == 'pool': + globalflags.InputFormat = 'pool' +else: + raise RuntimeError("Unable to read input file (format not supported)") + + +# show debug info [SGS] +print('## globalflags.InputFormat = %s' % globalflags.InputFormat) + +if globalflags.InputFormat() == 'pool': + globalflags.DetDescrVersion = inputfile.fileinfos['geometry'] +else: + globalflags.ConditionsTag = 'CONDBR2-BLKPA-RUN2-07' + globalflags.DatabaseInstance = 'CONDBR2' + +globalflags.print_JobProperties() + +#------------------------------------------ +# GeoModel +#------------------------------------------ +from AtlasGeoModel import SetGeometryVersion +from AtlasGeoModel import GeoModelInit + +#------------------------------------------ +# ByteStream +#------------------------------------------ +include( "InDetRecExample/InDetReadBS_jobOptions.py" ) +from ByteStreamCnvSvc import ReadByteStream +ServiceMgr.EventSelector.Input = collection + +from PixelReadoutGeometry.PixelReadoutGeometryConf import InDetDD__PixelReadoutManager +PixelReadoutManager = InDetDD__PixelReadoutManager("PixelReadoutManager") +ServiceMgr += PixelReadoutManager + +#------------------------------------------ +# Offline Condition +#------------------------------------------ +if globalflags.InputFormat() == 'bytestream': + if len(globalflags.ConditionsTag())!=0: + conddb.setGlobalTag(globalflags.ConditionsTag()) + + +#------------------------------------------ +# histo service +#------------------------------------------ +from GaudiSvc.GaudiSvcConf import THistSvc +if not hasattr(ServiceMgr, 'THistSvc'): + ServiceMgr += THistSvc() +THistSvc = ServiceMgr.THistSvc +THistSvc.Output += ["histfile DATAFILE='HitMap.root' OPT='RECREATE'"] + +#------------------------------------------ +# HitMapBuilder algorithm +#------------------------------------------ +from PixelCalibAlgs.PixelCalibAlgsConf import HitMapBuilder +HitMapBuilder = HitMapBuilder() +HitMapBuilder.LBMin = 0 +HitMapBuilder.LBMax = -1 +print(HitMapBuilder) +topSequence += HitMapBuilder + +#-------------------------------------------------------------- +# Number of events +#-------------------------------------------------------------- +#ServiceMgr.EventSelector.SkipEvents = 0 +theApp.EvtMax = nevents + +#-------------------------------------------------------------- +# MessageSvc +#-------------------------------------------------------------- +ServiceMgr.MessageSvc.Format = "% F%50W%S%7W%R%T %0W%M" +ServiceMgr.MessageSvc.defaultLimit = 9999999 # all messages +ServiceMgr.MessageSvc.useColors = True + +#-------------------------------------------------------------- +# Message service output level threshold +# (1=VERBOSE, 2=DEBUG, 3=INFO, 4=WARNING, 5=ERROR, 6=FATAL ) +#-------------------------------------------------------------- +ServiceMgr.MessageSvc.OutputLevel = INFO + +#============================================================== +# End of job options file +#============================================================== + diff --git a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/HitMapBuilder.cxx b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/HitMapBuilder.cxx new file mode 100755 index 0000000000000000000000000000000000000000..9c8f5f55189f25ceb3bf159136d6c0527493d6cd --- /dev/null +++ b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/HitMapBuilder.cxx @@ -0,0 +1,639 @@ +/* + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration +*/ + +// PixelCalibAlgs +#include "PixelCalibAlgs/HitMapBuilder.h" +#include "PixelCalibAlgs/PixelConvert.h" + +// Gaudi +#include "GaudiKernel/ITHistSvc.h" + +// EDM +#include "InDetRawData/PixelRDO_Container.h" + +// InnerDetector/InDetDetDescr/InDetReadtoutGeometry + +#include "PixelReadoutGeometry/PixelDetectorManager.h" +#include "InDetReadoutGeometry/SiDetectorElement.h" +#include "InDetReadoutGeometry/SiDetectorElementCollection.h" + +#include "EventInfo/EventInfo.h" +#include "EventInfo/EventID.h" + +// geometry +#include "InDetIdentifier/PixelID.h" + +// ROOT +#include "TH2.h" +#include "TString.h" + +// standard library +#include <string> +#include <sstream> +#include <algorithm> +#include <map> +#include <fstream> +#include <cstdlib> + +HitMapBuilder::HitMapBuilder(const std::string& name, ISvcLocator* pSvcLocator) : + AthAlgorithm(name, pSvcLocator), + m_tHistSvc("THistSvc", name), + m_pixman(0), + m_pixelID(0), + m_pixelRDOKey("PixelRDOs"), + m_nEvents(0.), + m_nEventsHist(nullptr), + m_nEventsLBHist(nullptr), + m_hist_lbMax(3001), + m_evt_lbMin(0), + m_evt_lbMax(-1) { + declareProperty("PixelRDOKey", m_pixelRDOKey, "StoreGate key of pixel RDOs"); + declareProperty("nLBmax", m_hist_lbMax, "Maximum number of LB (for histograms binning)"); + declareProperty("LBMin", m_evt_lbMin, "First lumi block to consider"); + declareProperty("LBMax", m_evt_lbMax, "Last lumi block to consider"); + declareProperty("THistSvc", m_tHistSvc, "THistSvc"); +} + +HitMapBuilder::~HitMapBuilder() { +} + +std::string HitMapBuilder::getDCSIDFromPosition(int barrel_ec, int layer, int modPhi, int module_eta) { + for (unsigned int ii = 0; ii < m_pixelMapping.size(); ii++) { + if (m_pixelMapping[ii].second.size() != 4) { + ATH_MSG_FATAL("getDCSIDFromPosition: Vector size is not 4!"); + return std::string("Error!"); + } + if (m_pixelMapping[ii].second[0] != barrel_ec) continue; + if (m_pixelMapping[ii].second[1] != layer) continue; + if (m_pixelMapping[ii].second[2] != modPhi) continue; + if (m_pixelMapping[ii].second[3] != module_eta) continue; + return m_pixelMapping[ii].first; + } + ATH_MSG_FATAL("DCS ID is not found!"); + return std::string("Error!"); +} + +const std::string HitMapBuilder::histoSuffix(const int bec, const int layer) { + std::ostringstream out; + switch (bec) { + case 0: + if (layer==0) out << "IBL"; + else out << "B" << layer-1; + break; + case +2: out << "Disk" << layer+1 << "A"; break; + case -2: out << "Disk" << layer+1 << "C"; break; + case +4: out << "DBM" << layer+1 << "A"; break; + case -4: out << "DBM" << layer+1 << "C"; break; + default: break; + } + return out.str(); +} + +std::vector<std::string>& HitMapBuilder::splitter(const std::string &str, char delim, std::vector<std::string> &elems) { + std::stringstream ss(str); + std::string item; + while (std::getline(ss, item, delim)) { + elems.push_back(item); + } + return elems; +} + +std::vector<std::string> HitMapBuilder::splitter(const std::string &str, char delim) { + std::vector<std::string> elems; + splitter(str, delim, elems); + return elems; +} + +//========================================================= +// +// initialize +// +//========================================================= +StatusCode HitMapBuilder::initialize() { + ATH_MSG_INFO("Initializing HitMapBuilder"); + + // retrieve THistSvc + StatusCode sc = m_tHistSvc.retrieve(); + if (!sc.isSuccess()) { + ATH_MSG_FATAL("Unable to retrieve THistSvc"); + return StatusCode::FAILURE; + } + // retrieve PixelDetectorManager + sc = detStore()->retrieve(m_pixman,"Pixel"); + if (!sc.isSuccess()) { + ATH_MSG_FATAL("Unable to retrieve PixelDetectorManager"); + return StatusCode::FAILURE; + } + + // retrieve PixelID helper + sc = detStore()->retrieve(m_pixelID, "PixelID"); + if (!sc.isSuccess()) { + ATH_MSG_FATAL("Unable to retrieve PixelID helper"); + return StatusCode::FAILURE; + } + + // resize vectors of histograms + const Identifier::size_type maxHash = m_pixelID->wafer_hash_max(); + ATH_MSG_DEBUG("PixelID maxHash = " << maxHash); + m_occupancyMaps.resize(maxHash+m_nIblFes); + m_occupancyMapsIBL2dLB.resize(m_perLB_n*m_nIblFes); + m_TOTdistributions.resize(maxHash+m_nIblFes); + m_TOTdistributionsIBL2dLB.resize(m_perLB_n*m_nIblFes); + m_occupancyLB.resize(maxHash+m_nIblFes); + + // Resize vector of variables + m_nEventsLB.resize(m_hist_lbMax); + m_nEventsLBCategory.resize(m_perLB_n); + + return (registerHistograms()); +} + + +StatusCode HitMapBuilder::registerHistograms() { + const std::string mapFile = "PixelMapping_Run2.dat"; + + std::vector<std::string> paths = splitter(std::getenv("DATAPATH"), ':'); + bool found(false); + for (const auto& x : paths) { + std::ifstream infile((x+"/"+mapFile).c_str()); + if (infile.is_open()) { + ATH_MSG_INFO("Mapping file '" << mapFile << "' found in " << x); + + int tmp_barrel_ec; int tmp_layer; int tmp_modPhi; int tmp_module_eta; std::string tmp_module_name; + std::vector<int> tmp_position; + tmp_position.resize(4); + while(infile >> tmp_barrel_ec >> tmp_layer >> tmp_modPhi >> tmp_module_eta >> tmp_module_name) { + tmp_position[0] = tmp_barrel_ec; + tmp_position[1] = tmp_layer; + tmp_position[2] = tmp_modPhi; + tmp_position[3] = tmp_module_eta; + m_pixelMapping.push_back(std::make_pair(tmp_module_name, tmp_position)); + } + + found=true; + infile.close(); + break; + } + } + + if (!found) { + ATH_MSG_FATAL("Mapping file '" << mapFile << "' not found in DATAPATH !!!"); + return StatusCode::FAILURE; + } + + // Register event histogram + m_nEventsHist = std::make_unique<TH1F>("NEvents", "NEvents;;# events", 1, 0, 1); + m_nEventsLBHist = std::make_unique<TH1F>("NEventsLB", "NEventsLB;LB;# events", m_hist_lbMax, -0.5, m_hist_lbMax+0.5); + + // Regist TDirectory first + // HARD CODING, TODO do in a smarter way + std::vector<std::pair<int, int>> temp_bec_layer{std::make_pair(2, 3), std::make_pair(-2, 3), std::make_pair(0, 4)}; + std::vector<std::string> temp_dir{"Occupancy2d", "OccupancyLb", "ToT"}; + for (auto const& bl : temp_bec_layer) { + for (int l=0; l<bl.second; l++) { + for (auto const& d: temp_dir) { + std::string temp_str = "/histfile/All/" + d + "/" + histoSuffix(bl.first, l) + "/" + d + histoSuffix(bl.first, l); + std::unique_ptr<TH1F>temp_h1d = std::make_unique<TH1F>((d+histoSuffix(bl.first, l)).c_str(), (d+histoSuffix(bl.first, l)).c_str(), 1, 0, 1); + ATH_CHECK(m_tHistSvc->regHist(temp_str.c_str(), std::move(temp_h1d))); + ATH_CHECK(m_tHistSvc->deReg(temp_str)); + } + } + } + + for (InDetDD::SiDetectorElementCollection::const_iterator iter=m_pixman->getDetectorElementBegin(); iter!=m_pixman->getDetectorElementEnd(); ++iter) { + const InDetDD::SiDetectorElement* element = *iter; + if (!element) continue; + + Identifier ident = element->identify(); + if (!m_pixelID->is_pixel(ident)) continue; + + int bec = m_pixelID->barrel_ec(ident); + int layer = m_pixelID->layer_disk(ident); + int modPhi = m_pixelID->phi_module(ident); + int modEta = m_pixelID->eta_module(ident); + int modHash = m_pixelID->wafer_hash(ident); + const Identifier::size_type maxHash = m_pixelID->wafer_hash_max(); + + if (abs(bec) == 4) continue; // Skip DBM + + int iblFeHash = -99; + // Use special fe chip index for IBL + // {0..3}: 3D C, C8_2, C8_1, C7_2, C7_1 + // {4..15}: 2D C, C6_2, C6_1, ..., C1_2, C1_1 + // {16..27}: 2D A, A1_1, A1_2, ..., A6_1, A6_2 + // {28..31}: 3D A, A7_1, A7_2, A8_1, A8_2 + if (bec == 0 && layer == 0) { + if (modEta <= -7) iblFeHash = modPhi*32 + (modEta+10); // 3D C + else if (-6<=modEta && modEta<=5) iblFeHash = modPhi*32 + ((modEta+6)*2+4); // 2D + else iblFeHash = modPhi*32 + (modEta+22); // 3D A + // iblFeHash, here, is even + } + + std::string onlineID = getDCSIDFromPosition(bec,layer,modPhi,modEta); + + std::ostringstream name; + std::string axisTitle; + + // Construct IBL Planar later + std::string LBCategory; + std::string occ2dDir = "Occupancy2d"; + std::string occLBDir = "OccupancyLb"; + std::string totDir = "ToT"; + + // Category: All + LBCategory = "All"; + if (bec == 0 && layer == 0 && -6 <= modEta && modEta <= 5) { // IBL 2D + for (unsigned chipId=0; chipId<=1; chipId++) { // FE chips in double module + int ibl2dHash; + if (chipId) { + if (modEta <= -1) ibl2dHash = maxHash + iblFeHash; // C side, '_2' + else ibl2dHash = maxHash + iblFeHash + chipId; // A side, '_2' + } + else { + if (modEta <= -1) ibl2dHash = maxHash + iblFeHash + 1; // C side, '_1' + else ibl2dHash = maxHash + iblFeHash; // A side, '_1' + } + std::string histTitle = onlineID + "_" + std::to_string(chipId+1); + // Occupancy Map + axisTitle = ";pixel_eta;pixel_phi;# hits/pixel/event"; + m_occupancyMaps[ibl2dHash] = std::make_unique<TH2F>(histTitle.c_str(), (histTitle+axisTitle).c_str(), 80, -0.5, 79.5, 336, -0.5, 335.5); + name << "/histfile/" << LBCategory << "/" << occ2dDir << "/" << histoSuffix(bec,layer) << "/" << onlineID << "_" << chipId+1; + name.str(""); name.clear(); + m_occupancyMaps[ibl2dHash]->SetOption("colz"); + + // Occupancy vs. LB + axisTitle = ";LB;# hits/pixel/event"; + m_occupancyLB[ibl2dHash] = std::make_unique<TH1F>(histTitle.c_str(), (histTitle+axisTitle).c_str(), m_hist_lbMax, -0.5, m_hist_lbMax-0.5); + name << "/histfile/" << LBCategory << "/" << occLBDir << "/" << histoSuffix(bec,layer) << "/" << onlineID << "_" << chipId+1; + name.str(""); name.clear(); + + // ToT + axisTitle = ";ToT;# hits"; + m_TOTdistributions[ibl2dHash] = std::make_unique<TH1F>(histTitle.c_str(), (histTitle+axisTitle).c_str(), 19, -0.5, 18.5); + name << "/histfile/" << LBCategory << "/" << totDir << "/" << histoSuffix(bec,layer) << "/" << onlineID << "_" << chipId+1; + name.str(""); name.clear(); + } + } + else { // None IBL 2D + // Occupancy Map + axisTitle = ";pixel_eta;pixel_phi;# hits/pixel/event"; + if (bec == 0 && layer == 0) { + m_occupancyMaps[modHash] = std::make_unique<TH2F>(onlineID.c_str(), (onlineID+axisTitle).c_str(), 80, -0.5, 79.5, 336, -0.5, 335.5); // IBL 3D + } + else { + m_occupancyMaps[modHash] = std::make_unique<TH2F>(onlineID.c_str(), (onlineID+axisTitle).c_str(), 144, -0.5, 143.5, 328, -0.5, 327.5); + } + name << "/histfile/" << LBCategory << "/" << occ2dDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + name.str(""); name.clear(); + m_occupancyMaps[modHash].get()->SetOption("colz"); + + // Occupancy vs. LB + axisTitle = ";LB;# hits/pixel/event"; + m_occupancyLB[modHash] = std::make_unique<TH1F>(onlineID.c_str(), (onlineID+axisTitle).c_str(), m_hist_lbMax, -0.5, m_hist_lbMax-0.5); + name << "/histfile/" << LBCategory << "/" << occLBDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + name.str(""); name.clear(); + + // ToT + axisTitle = ";ToT;# hits"; + if (bec == 0 && layer == 0) { + m_TOTdistributions[modHash] = std::make_unique<TH1F>(onlineID.c_str(), (onlineID+axisTitle).c_str(), 19, -0.5, 18.5); // IBL 3D + } + else { + m_TOTdistributions[modHash] = std::make_unique<TH1F>(onlineID.c_str(), (onlineID+axisTitle).c_str(), 256, -0.5, 255.5); + } + name << "/histfile/" << LBCategory << "/" << totDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + name.str(""); name.clear(); + } // End of if ibl 2d + + // Category: LB1-100, 101-200, ... + if (0 <= iblFeHash) { // IBL + for (int i=0; i<m_perLB_n; i++) { + LBCategory = "LB" + std::to_string(m_perLB_min+m_perLB_step*i+1) + "-" + std::to_string(m_perLB_min+m_perLB_step*(i+1)); + if (-6 <= modEta && modEta <= 5) { // IBL 2D + for (int chipId=0; chipId<=1; chipId++) { // FE chips in double module + int ibl2dHash; + if (chipId) { + if (modEta <= -1) ibl2dHash = m_nIblFes*i + iblFeHash; // C side, '_2' + else ibl2dHash = m_nIblFes*i + iblFeHash + chipId; // A side, '_2' + } + else { + if (modEta <= -1) ibl2dHash = m_nIblFes*i + iblFeHash + 1; // C side, '_1' + else ibl2dHash = m_nIblFes*i + iblFeHash; // A side, '_1' + } + std::string histTitle = onlineID + "_" + std::to_string(chipId+1); + // Occupancy Map + axisTitle = ";pixel_eta;pixel_phi;# hits/pixel/event"; + m_occupancyMapsIBL2dLB[ibl2dHash] = std::make_unique<TH2F>(histTitle.c_str(), (histTitle+axisTitle).c_str(), 80, -0.5, 79.5, 336, -0.5, 335.5); + name << "/histfile/" << LBCategory << "/" << occ2dDir << "/" << histoSuffix(bec,layer) << "/" << histTitle; + name.str(""); name.clear(); + m_occupancyMapsIBL2dLB[ibl2dHash]->SetOption("colz"); + + // ToT + axisTitle = ";ToT;# hits"; + m_TOTdistributionsIBL2dLB[ibl2dHash] = std::make_unique<TH1F>(histTitle.c_str(), (histTitle+axisTitle).c_str(), 19, -0.5, 18.5); + name << "/histfile/" << LBCategory << "/" << totDir << "/" << histoSuffix(bec,layer) << "/" << histTitle; + name.str(""); name.clear(); + } + } + else { // IBL 3D + int ibl2dHash = m_nIblFes*i + iblFeHash; + // Occupancy Map + axisTitle = ";pixel_eta;pixel_phi;# hits/pixel/event"; + m_occupancyMapsIBL2dLB[ibl2dHash] = std::make_unique<TH2F>(onlineID.c_str(), (onlineID+axisTitle).c_str(), 80, -0.5, 79.5, 336, -0.5, 335.5); + name << "/histfile/" << LBCategory << "/" << occ2dDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + name.str(""); name.clear(); + m_occupancyMapsIBL2dLB[ibl2dHash]->SetOption("colz"); + + // ToT + axisTitle = ";ToT;# hits"; + m_TOTdistributionsIBL2dLB[ibl2dHash] = std::make_unique<TH1F>(onlineID.c_str(), (onlineID+axisTitle).c_str(), 19, -0.5, 18.5); + name << "/histfile/" << LBCategory << "/" << totDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + name.str(""); name.clear(); + } // End of if ibl 2d + } // End of loop of category: LB + } // End of if IBL + } // end loop in detector elements + + return StatusCode::SUCCESS; +} + +//========================================================= +// +// execute +// +//========================================================= +StatusCode HitMapBuilder::execute() { + ATH_MSG_DEBUG( "Executing HitMapBuilder" ); + + // retrieve EventInfo + const EventInfo* eventInfo; + StatusCode sc = sgSvc()->retrieve(eventInfo); + if (!sc.isSuccess()) { + ATH_MSG_FATAL("Unable to retrieve event info"); + return StatusCode::FAILURE; + } ATH_MSG_DEBUG("Event info retrieved"); + + // check LB is in allowed range + int LB = static_cast<int>(eventInfo->event_ID()->lumi_block()); + if ((LB < m_evt_lbMin) || (m_evt_lbMax >= m_evt_lbMin && LB > m_evt_lbMax)) { + ATH_MSG_VERBOSE("Event in lumiblock " << eventInfo->event_ID()->lumi_block() << " not in selected range [" << m_evt_lbMin << "," << m_evt_lbMax << "] => skipped"); + return StatusCode::SUCCESS; + } + + // Get max LB range + if (m_LBrange_max < LB) m_LBrange_max = LB; + + // retrieve PixelRDO container + const DataHandle<PixelRDO_Container> pixelRDOs; + sc = sgSvc()->retrieve(pixelRDOs, m_pixelRDOKey); + if (!sc.isSuccess()) { + ATH_MSG_FATAL( "Unable to retrieve pixel RDO container at " << m_pixelRDOKey ); + return StatusCode::FAILURE; + } ATH_MSG_DEBUG( "Pixel RDO container retrieved" ); + // loop in RDO container + for (PixelRDO_Container::const_iterator coll=pixelRDOs->begin(); coll!=pixelRDOs->end(); coll++) { + + const InDetRawDataCollection<PixelRDORawData>* PixelRDOCollection(*coll); + if (PixelRDOCollection != 0) { + Identifier moduleID = PixelRDOCollection->identify(); + IdentifierHash modHash = m_pixelID->wafer_hash(moduleID); + ATH_MSG_VERBOSE("moduleID, modHash = " << moduleID << " , " << modHash); + + for (DataVector<PixelRDORawData>::const_iterator rdo=PixelRDOCollection->begin(); rdo!=PixelRDOCollection->end(); ++rdo) { + Identifier rdoID = (*rdo)->identify(); + unsigned int pixel_eta = m_pixelID->eta_index(rdoID); + unsigned int pixel_phi = m_pixelID->phi_index(rdoID); + int bec = m_pixelID->barrel_ec(rdoID); + int layer = m_pixelID->layer_disk(rdoID); + int modPhi = m_pixelID->phi_module(rdoID); + int modEta = m_pixelID->eta_module(rdoID); + const Identifier::size_type maxHash = m_pixelID->wafer_hash_max(); + + if (abs(bec) == 4) continue; // Skip DBM + + int iblFeHash = -99; + if (bec==0 && layer==0) { // IBL FE order: {0..3}: 3D C, {4..15}: 2D C, {16..27}: 2D A, {28..31}: 3D A + if (modEta <= -7) iblFeHash = modPhi*32 + (modEta+10); // 3D C + else if (-6<=modEta && modEta<=5) iblFeHash = modPhi*32 + ((modEta+6)*2+4); // 2D + else iblFeHash = modPhi*32 + (modEta+22); // 3D A + if (pixel_eta/80) iblFeHash++; // For 2D, C side '_1', or A side '_2' for pixel_eta 80~159 + } + + int TOT = (*rdo)->getToT(); // it returns a 8 bits "word" + + // Category: All + if (bec == 0 && layer == 0 && -6 <= modEta && modEta <= 5) { // IBL 2D + int ibl2dHash = maxHash + iblFeHash; + m_occupancyMaps[ibl2dHash]->Fill(pixel_eta%80, pixel_phi); + m_occupancyLB[ibl2dHash]->Fill(LB); + m_TOTdistributions[ibl2dHash]->Fill(TOT); + } + else { // None IBL 2D + m_occupancyMaps[modHash]->Fill(pixel_eta, pixel_phi); + m_occupancyLB[modHash]->Fill(LB); + m_TOTdistributions[modHash]->Fill(TOT); + } + + // Category: LB + if (0 <= iblFeHash) { // IBL + for (int i=0; i<m_perLB_n; i++) { + if ((m_perLB_min+m_perLB_step*i < LB) && (LB <= m_perLB_min+m_perLB_step*(i+1))) { // LB + int ibl2dHash = m_nIblFes*i + iblFeHash; + m_occupancyMapsIBL2dLB[ibl2dHash]->Fill(pixel_eta%80, pixel_phi); + m_TOTdistributionsIBL2dLB[ibl2dHash]->Fill(TOT); + } + } + } + } + } + } + m_nEvents++; + m_nEventsHist->Fill(0.5); + m_nEventsLBHist->Fill(LB); + + m_nEventsLB[LB]++; + m_nEventsLBCategory[(LB-m_perLB_min)/m_perLB_step]++; + + return StatusCode::SUCCESS; +} + +//========================================================= +// +// finalize +// +//========================================================= +StatusCode HitMapBuilder::finalize() { + ATH_MSG_INFO("Finalizing HitMapBuilder"); + + ATH_CHECK(m_tHistSvc->regHist("/histfile/NEvents", std::move(m_nEventsHist))); + ATH_CHECK(m_tHistSvc->regHist("/histfile/NEventsLB", std::move(m_nEventsLBHist))); + + // + // loop in detector elements + // + for (InDetDD::SiDetectorElementCollection::const_iterator iter=m_pixman->getDetectorElementBegin(); iter!=m_pixman->getDetectorElementEnd(); ++iter) { + const InDetDD::SiDetectorElement* element = *iter; + if (element == 0) continue; + + Identifier ident = element->identify(); + if (!m_pixelID->is_pixel(ident)) continue; + + int bec = m_pixelID->barrel_ec (ident); + int layer = m_pixelID->layer_disk(ident); + int modPhi = m_pixelID->phi_module(ident); + int modEta = m_pixelID->eta_module(ident); + int modHash = m_pixelID->wafer_hash(ident); + const Identifier::size_type maxHash = m_pixelID->wafer_hash_max(); + + if (abs(bec) == 4) continue; // Skip DBM + + int iblFeHash = -99; + if (bec==0 && layer==0) { // IBL FE order: {0..3}: 3D C, {4..15}: 2D C, {16..27}: 2D A, {28..31}: 3D A + if (modEta <= -7) iblFeHash = modPhi*32 + (modEta+10); // 3D C + else if (-6<=modEta && modEta<=5) iblFeHash = modPhi*32 + ((modEta+6)*2+4); // 2D + else iblFeHash = modPhi*32 + (modEta+22); // 3D A + } + + // Divide by events for Occupancy Map + // Category: All + if (bec == 0 && layer == 0 && -6 <= modEta && modEta <= 5) { // IBL 2D + int ibl2dHash = maxHash + iblFeHash; + for (int chipId=0; chipId<2; chipId++) { // 2 Fes in double module + //yosuke m_occupancyMaps[ibl2dHash+chipId]->Scale(1.0/(m_nEvents)); + // Occupancy LB + int entries = m_occupancyLB[ibl2dHash+chipId]->GetEntries(); + for (int lb=0; lb<m_hist_lbMax; lb++) { + if (m_nEventsLB[lb] == 0) continue; + m_occupancyLB[ibl2dHash+chipId]->SetBinContent(lb+1, m_occupancyLB[ibl2dHash+chipId]->GetBinContent(lb+1)/(m_nEventsLB[lb]*m_fei4bPixels)); // Also divide by fei4 pixels + } + m_occupancyLB[ibl2dHash+chipId]->SetEntries(entries); + m_occupancyLB[ibl2dHash+chipId]->SetBins(m_LBrange_max+100, -0.5, m_LBrange_max+99.5); + } + } + else { // None IBL 2D + //yosuke m_occupancyMaps[modHash]->Scale(1.0/(m_nEvents)); + // Occupancy LB + int entries = m_occupancyLB[modHash]->GetEntries(); + for (int lb=0; lb<m_hist_lbMax; lb++) { + if (m_nEventsLB[lb] == 0) continue; + if (0 <= iblFeHash) m_occupancyLB[modHash]->SetBinContent(lb+1, m_occupancyLB[modHash]->GetBinContent(lb+1)/(m_nEventsLB[lb]*m_fei4bPixels)); // IBL 3D, divide by fei4 pixels + else m_occupancyLB[modHash]->SetBinContent(lb+1, m_occupancyLB[modHash]->GetBinContent(lb+1)/(m_nEventsLB[lb]*m_pixModPixels)); // Pixel module, divide by pixel module pixels + } + m_occupancyLB[modHash]->SetEntries(entries); + m_occupancyLB[modHash]->SetBins(m_LBrange_max+100, -0.5, m_LBrange_max+99.5); + } + + std::string onlineID = getDCSIDFromPosition(bec,layer,modPhi,modEta); + + std::ostringstream name; + std::string axisTitle; + + // Construct IBL Planar later + std::string LBCategory; + std::string occ2dDir = "Occupancy2d"; + std::string occLBDir = "OccupancyLb"; + std::string totDir = "ToT"; + + // Category: All + LBCategory = "All"; + if (bec == 0 && layer == 0 && -6 <= modEta && modEta <= 5) { // IBL 2D + for (unsigned chipId=0; chipId<=1; chipId++) { // FE chips in double module + int ibl2dHash; + if (chipId) { + if (modEta <= -1) ibl2dHash = maxHash + iblFeHash; // C side, '_2' + else ibl2dHash = maxHash + iblFeHash + chipId; // A side, '_2' + } + else { + if (modEta <= -1) ibl2dHash = maxHash + iblFeHash + 1; // C side, '_1' + else ibl2dHash = maxHash + iblFeHash; // A side, '_1' + } + // Occupancy Map + axisTitle = ";pixel_eta;pixel_phi;# hits/pixel/event"; + name << "/histfile/" << LBCategory << "/" << occ2dDir << "/" << histoSuffix(bec,layer) << "/" << onlineID << "_" << chipId+1; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_occupancyMaps[ibl2dHash]))); + name.str(""); name.clear(); + + // Occupancy vs. LB + axisTitle = ";LB;# hits/pixel/event"; + name << "/histfile/" << LBCategory << "/" << occLBDir << "/" << histoSuffix(bec,layer) << "/" << onlineID << "_" << chipId+1; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_occupancyLB[ibl2dHash]))); + name.str(""); name.clear(); + + // ToT + axisTitle = ";ToT;# hits"; + name << "/histfile/" << LBCategory << "/" << totDir << "/" << histoSuffix(bec,layer) << "/" << onlineID << "_" << chipId+1; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_TOTdistributions[ibl2dHash]))); + name.str(""); name.clear(); + } + } + else { // None IBL 2D + // Occupancy Map + axisTitle = ";pixel_eta;pixel_phi;# hits/pixel/event"; + name << "/histfile/" << LBCategory << "/" << occ2dDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_occupancyMaps[modHash]))); + name.str(""); name.clear(); + + // Occupancy vs. LB + axisTitle = ";LB;# hits/pixel/event"; + name << "/histfile/" << LBCategory << "/" << occLBDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_occupancyLB[modHash]))); + name.str(""); name.clear(); + + // ToT + axisTitle = ";ToT;# hits"; + name << "/histfile/" << LBCategory << "/" << totDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_TOTdistributions[modHash]))); + name.str(""); name.clear(); + } // End of if ibl 2d + + // Category: LB1-100, 101-200, ... + if (0 <= iblFeHash) { // IBL + for (int i=0; i<m_perLB_n; i++) { + LBCategory = "LB" + std::to_string(m_perLB_min+m_perLB_step*i+1) + "-" + std::to_string(m_perLB_min+m_perLB_step*(i+1)); + if (-6 <= modEta && modEta <= 5) { // IBL 2D + for (int chipId=0; chipId<=1; chipId++) { // FE chips in double module + int ibl2dHash; + if (chipId) { + if (modEta <= -1) ibl2dHash = m_nIblFes*i + iblFeHash; // C side, '_2' + else ibl2dHash = m_nIblFes*i + iblFeHash + chipId; // A side, '_2' + } + else { + if (modEta <= -1) ibl2dHash = m_nIblFes*i + iblFeHash + 1; // C side, '_1' + else ibl2dHash = m_nIblFes*i + iblFeHash; // A side, '_1' + } + std::string histTitle = onlineID + "_" + std::to_string(chipId+1); + // Occupancy Map + axisTitle = ";pixel_eta;pixel_phi;# hits/pixel/event"; + name << "/histfile/" << LBCategory << "/" << occ2dDir << "/" << histoSuffix(bec,layer) << "/" << histTitle; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_occupancyMapsIBL2dLB[ibl2dHash]))); + name.str(""); name.clear(); + + // ToT + axisTitle = ";ToT;# hits"; + name << "/histfile/" << LBCategory << "/" << totDir << "/" << histoSuffix(bec,layer) << "/" << histTitle; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_TOTdistributionsIBL2dLB[ibl2dHash]))); + name.str(""); name.clear(); + } + } + else { // IBL 3D + int ibl2dHash = m_nIblFes*i + iblFeHash; + // Occupancy Map + axisTitle = ";pixel_eta;pixel_phi;# hits/pixel/event"; + name << "/histfile/" << LBCategory << "/" << occ2dDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_occupancyMapsIBL2dLB[ibl2dHash]))); + name.str(""); name.clear(); + + // ToT + axisTitle = ";ToT;# hits"; + name << "/histfile/" << LBCategory << "/" << totDir << "/" << histoSuffix(bec,layer) << "/" << onlineID; + ATH_CHECK(m_tHistSvc->regHist(name.str(), std::move(m_TOTdistributionsIBL2dLB[ibl2dHash]))); + name.str(""); name.clear(); + } // End of if ibl 2d + } // End of loop of category: LB + } // End of if IBL + } // end loop in detector elements + + return StatusCode::SUCCESS; + +} // end finalize diff --git a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/components/PixelCalibAlgs_entries.cxx b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/components/PixelCalibAlgs_entries.cxx old mode 100644 new mode 100755 index 7cfcbfda49c3c197c2d11833a1179e32e49c8712..98faf3cff56703c352c860d8f59049aaad1dab8d --- a/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/components/PixelCalibAlgs_entries.cxx +++ b/InnerDetector/InDetCalibAlgs/PixelCalibAlgs/src/components/PixelCalibAlgs_entries.cxx @@ -1,6 +1,6 @@ #include "PixelCalibAlgs/PixelChargeToTConversion.h" -#include "PixelCalibAlgs/OccupancyMapMaker.h" +#include "PixelCalibAlgs/HitMapBuilder.h" DECLARE_COMPONENT( PixelChargeToTConversion ) -DECLARE_COMPONENT( OccupancyMapMaker ) +DECLARE_COMPONENT( HitMapBuilder )