23#include "TClonesArray.h"
25#include "TGeoMatrix.h"
26#include "TGeoPhysicalNode.h"
27#include "TGeoVolume.h"
29#include <TMCProcess.h>
32#include "FairEventHeader.h"
35#include "FairMCEventHeader.h"
36#include "FairMCPoint.h"
37#include "FairRunAna.h"
38#include "FairRunSim.h"
39#include "FairRuntimeDb.h"
66using std::setprecision;
69using std::stringstream;
116 entry.second->BufferStatus(nSigModule, t1Module, t2Module);
117 nSignals += nSigModule;
138 entry.second->BufferStatus(nSigModule, t1Module, t2Module);
140 nSignals += nSigModule;
141 t1 = t1 < 0. ? t1Module : TMath::Min(t1, t1Module);
142 t2 = TMath::Max(t2, t2Module);
146 std::stringstream ss;
147 ss << nSignals << (nSignals == 1 ?
" signal " :
" signals ") <<
"in analogue buffers";
148 if (nSignals) ss <<
" ( from " << fixed << setprecision(3) << t1 <<
" ns to " << t2 <<
" ns )";
189 if (fair::Logger::Logging(fair::Severity::debug)) {
190 std::cout << std::endl;
204 nNoise += entry.second->GenerateNoise(tNoiseStart, tNoiseEnd);
206 LOG(info) <<
"+ " << setw(20) << GetName() <<
": Generated " << nNoise <<
" noise signals from t = " << tNoiseStart
207 <<
" ns to " << tNoiseEnd <<
" ns";
215 if (fair::Logger::Logging(fair::Severity::debug)) {
233 if (fair::Logger::Logging(fair::Severity::debug)) {
238 LOG(info) << left << setw(15) << GetName() <<
"[" << fixed << setprecision(3) <<
fTimer.RealTime() <<
" s]"
267 LOG(fatal) << fName <<
": Non-empty analogue buffers at end of event "
268 <<
" in event-by-event mode!";
274 std::cout << std::endl;
275 LOG(info) << GetName() <<
": Finish run";
277 LOG(info) << GetName() <<
": Processing analogue buffers";
281 entry.second->ProcessAnalogBuffer(-1.);
285 ss << GetName() <<
": " <<
fNofDigis << (
fNofDigis == 1 ?
" digi " :
" digis ") <<
"created and sent to DAQ ";
288 LOG(info) << ss.str();
300 std::cout << std::endl;
301 LOG(info) <<
"=====================================";
302 LOG(info) << GetName() <<
": Run summary";
303 LOG(info) <<
"Events processed : " <<
fNofEvents;
314 LOG(info) <<
"=====================================";
322 assert(FairRunAna::Instance());
323 FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
337 std::cout << std::endl;
338 LOG(info) <<
"==========================================================";
339 LOG(info) << GetName() <<
": Initialisation \n\n";
355 if (!result.second) {
356 LOG(error) << GetName() <<
": Error in reading from file! Task will be inactive.";
359 LOG(info) << GetName() <<
": " << std::get<0>(result) <<
" lines read from file";
361 size_t nChanInactive = 0;
363 nChanInactive += entry.second.size();
364 LOG(info) << GetName() <<
": " << nChanInactive <<
" channels set inactive";
368 LOG(info) << GetName() <<
": Created " << nModules <<
" modules";
372 LOG(info) << GetName() <<
": Created " << nSensors <<
" sensors";
375 FairRootManager* ioman = FairRootManager::Instance();
379 fPoints = (TClonesArray*) ioman->GetObject(
"StsPoint");
383 fTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
390 LOG(info) << GetName() <<
": Initialisation successful";
391 LOG(info) <<
"==========================================================";
392 std::cout << std::endl;
409 for (
Int_t iModule = 0; iModule <
fSetup->GetNofModules(); iModule++) {
415 auto result =
fModules.insert({address, module});
416 assert(result.second);
420 assert(nModules ==
fModules.size());
447 fParSim->setInputVersion(-2, 1);
448 LOG(info) <<
"--- Settings: " <<
fParSim->ToString();
457 for (
Int_t iModule = 0; iModule <
fSetup->GetNofModules(); iModule++) {
458 UInt_t address =
fSetup->GetModule(iModule)->GetAddress();
461 for (uint32_t iAsic = 0; iAsic < numAsics; iAsic++) {
463 Int_t side = (iAsic < (numAsics / 2)) ? 0 : 1;
465 auto specificKey = std::make_tuple(address, side, iAsic);
466 auto globalKey = std::make_tuple(address, side, -1);
472 asicParam = specificIndex_it->second.get();
476 asicParam = globalIndex_it->second.get();
488 UInt_t deactivated = 0;
494 LOG(info) <<
"--- Using global ASIC parameters: \n " <<
fUserParAsic->ToString();
495 LOG(info) <<
"--- Module parameters: " <<
fParSetModule->ToString();
496 LOG(info) <<
"--- Deactive channels: " << deactivated <<
" " <<
fUserFracDeadChan;
504 for (
Int_t iSensor = 0; iSensor <
fSetup->GetNofSensors(); iSensor++) {
507 TGeoBBox* box =
dynamic_cast<TGeoBBox*
>(sensor->
GetPnode()->GetShape());
509 Double_t lX = 2. * box->GetDX();
510 Double_t lY = 2. * box->GetDY();
511 Double_t lZ = 2. * box->GetDZ();
519 Double_t nStripsF = dX / pitchF;
520 Double_t nStripsB = dX / pitchB;
524 && TMath::Abs(pitchF - 0.0058) < 0.0001) {
531 && TMath::Abs(pitchF - 0.0058) < 0.0001) {
544 for (UInt_t parIndex = 6; parIndex < 10; parIndex++) {
550 LOG(info) <<
"--- Sensor parameters: " <<
fParSetSensor->ToString();
558 LOG(info) <<
"--- Sensor conditions: " <<
fParSetCond->ToString();
573 for (
Int_t iSensor = 0; iSensor <
fSetup->GetNofSensors(); iSensor++) {
584 auto moduIt =
fModules.find(moduAddress);
586 assert(moduIt->second);
593 assert(result.second);
594 auto& sensor = result.first->second;
598 sensor->SetElement(geoSensor);
599 sensor->SetModule(moduIt->second);
602 sensor->SetSimSettings(
fParSim);
607 sensor->SetConditions(&cond);
613 if (FairRun::Instance()->GetField()) {
614 Double_t local[3] = {0., 0., 0.};
616 geoSensor->
GetPnode()->GetMatrix()->LocalToMaster(local, global);
617 Double_t field[3] = {0., 0., 0.};
618 FairRun::Instance()->GetField()->Field(global, field);
623 sensor->SetField(bx, by, bz);
626 assert(sensor->Init());
631 assert(nSensors ==
fSensors.size());
661 if (it->second.count(channel))
return false;
670 LOG(info) <<
"StsDigitize: Process analog buffers at " << readoutTime;
673 it.second->ProcessAnalogBuffer(readoutTime);
684 for (
Int_t iPoint = 0; iPoint <
fPoints->GetEntriesFast(); iPoint++) {
688 if (
fParSim->OnlyPrimaries()) {
689 Int_t iTrack = point->GetTrackID();
705 if (point->GetTime() > 1.e6) {
724 UInt_t address =
static_cast<UInt_t
>(point->GetDetectorID());
726 auto& sensor =
fSensors.find(address)->second;
728 Int_t status = sensor->ProcessPoint(point, eventTime, link);
731 Int_t nSignalsF = status / 1000;
732 Int_t nSignalsB = status - 1000 * nSignalsF;
733 LOG(debug2) << GetName() <<
": Produced signals: " << nSignalsF + nSignalsB <<
" ( " << nSignalsF <<
" / "
734 << nSignalsB <<
" )";
748 if (channelFile ==
nullptr)
return std::make_pair(0,
false);
751 uint32_t address = 0;
752 uint16_t channel = 0;
753 while (fscanf(channelFile,
"%u %hu", &address, &channel) == 2) {
757 bool success = feof(channelFile);
760 return std::make_pair(nLines, success);
770 std::ifstream file(fileName);
772 if (!file.is_open()) {
773 LOG(error) <<
"Error: Could not open file " << fileName;
778 bool File_Load_Success =
false;
779 std::string Error_Message;
781 while (std::getline(file, line)) {
783 if (line.empty() || line[0] ==
'#')
continue;
786 std::istringstream iss(line);
787 std::string moduleAddressStr;
788 UInt_t moduleAddress;
790 UShort_t nAsicChannels, nAdc;
791 Double_t dynRange, threshold, timeResol, deadTime, noiseRms, znr;
794 if (!(iss >> moduleAddressStr >> side >> AsicIdx >> nAsicChannels >> nAdc >> dynRange >> threshold >> timeResol
795 >> deadTime >> noiseRms >> znr)) {
796 Error_Message =
"Error parsing line: " + line;
797 LOG(error) << Error_Message;
803 int base = (moduleAddressStr.compare(0, 2,
"0x") == 0 || moduleAddressStr.compare(0, 2,
"0X") == 0) ? 16 : 10;
804 moduleAddress = std::stoul(moduleAddressStr,
nullptr, base);
806 catch (
const std::exception& e) {
807 LOG(error) <<
"Invalid module address format: " << moduleAddressStr <<
" (" << e.what() <<
")";
811 auto key = std::make_tuple(moduleAddress, side, AsicIdx);
813 fModuleAsicParams.emplace(key, std::make_unique<CbmStsParAsic>(nAsicChannels, nAdc, dynRange, threshold, timeResol,
814 deadTime, noiseRms, znr));
816 File_Load_Success =
true;
820 return File_Load_Success;
861 Bool_t eventMode = kFALSE;
863 Bool_t lorentzShift = kTRUE;
866 Bool_t generateNoise = kTRUE;
868 fUserParSim->SetProcesses(eLossModel, lorentzShift, diffusion, crossTalk);
876 UInt_t nChannels = 2048;
877 UInt_t nAsicChannels = 128;
883 Double_t dynRange = 75000.;
884 Double_t threshold = 4000.;
885 Double_t timeResol = 5.;
886 Double_t deadTime = 200.;
887 Double_t noiseRms = 1000.;
888 Double_t znr = 3.5368e-3;
896 Double_t pitchF = 0.0058;
897 Double_t pitchB = 0.0058;
898 Double_t stereoF = 0.;
899 Double_t stereoB = 7.5;
909 Double_t vBias = 140.;
910 Double_t temperature = 268.;
911 Double_t cCoupling = 17.5;
912 Double_t cInterstrip = 1.;
920 Double_t timeResolution, Double_t deadTime, Double_t noise,
921 Double_t zeroNoiseRate)
927 new CbmStsParAsic(nChannels, nAdc, dynRange, threshold, timeResolution, deadTime, noise, zeroNoiseRate);
945 Double_t cInterstrip)
970 LOG(error) << GetName() <<
": physics processes must be set before "
971 <<
"initialisation! Statement will have no effect.";
975 fUserParSim->SetProcesses(eLossModel, useLorentzShift, useDiffusion, useCrossTalk);
985 LOG(fatal) << GetName() <<
": sensor conditions must be set before initialisation!";
998 LOG(fatal) << GetName() <<
": sensor parameters must be set before initialisation!";
ClassImp(CbmConverterManager)
CbmStsSensorClass
Sensor classes.
CbmStsELoss
Energy loss model used in simulation.
TString fInactiveChannelFileName
Double_t fCurrentEventTime
void SendData(Double_t time, CbmStsDigi *digi, CbmMatch *match=nullptr)
uint32_t GetGeantProcessId() const
Data class for a single-channel message in the STS.
Task class for simulating the detector response of the STS.
TString fSensorConditionFile
File with sensor conditions.
const char * fAsicParamsFileName
Double_t fTimeTot
Total execution time.
void SetGlobalDefaults()
Set global default parameters.
UInt_t InitModules()
Instantiate modules.
virtual void Exec(Option_t *opt)
Bool_t fIsInitialised
kTRUE if Init() was called
Double_t fNofPointsIgnoTot
Total number of ignored points.
virtual ~CbmStsDigitize()
CbmStsParModule * fUserParModule
User defined, global.
Double_t fSensorDinact
Size of inactive border [cm].
Double_t fSensorStereoB
Stereo angle back side [degrees].
void SetSensorParameterFile(const char *fileName)
Set the file name with sensor parameters.
TClonesArray * fTracks
Input array of CbmMCTrack.
void SetSensorConditionFile(const char *fileName)
Set the file name with sensor conditions.
Int_t fNofSignalsF
Number of signals on front side.
TClonesArray * fPoints
Sensor factory.
Double_t fReadoutInterval
Interval for analog buffer readout [ns].
Double_t fSensorPitch
Strip pitch [cm].
CbmStsParAsic * fUserParAsic
User defined, global.
std::map< UInt_t, std::unique_ptr< CbmStsSimSensor > > fSensors
virtual InitStatus Init()
Double_t fNofSignalsFTot
Number of signals on front side.
void SetGlobalModuleParams(UInt_t nChannels, UInt_t nAsicChannels)
Set the global module parameters.
Int_t fNofPointsProc
Number of processed points.
Double_t fTimeDigiFirst
Time of first digi sent to DAQ.
CbmStsSimSensorFactory * fSensorFactory
STS setup interface.
TStopwatch fTimer
ROOT timer.
void ProcessAnalogBuffers(Double_t readoutTime)
Int_t fNofDigis
Number of created digis in Exec.
Int_t BufferSize() const
Number of signals in the analogue buffers @value nSignals Sum of number of signals in all modules.
TString fModuleParameterFile
File with module parameters.
Double_t fNofDigisTot
Total number of digis created.
Double_t fSensorStereoF
Stereo angle front side [degrees].
Double_t fTimeLastReadout
Time of last readout of analog buffers.
CbmStsParSensor * fUserParSensor
User defined, global.
TString fSensorParameterFile
File with sensor parameters.
CbmStsParSim * fParSim
Simulation settings.
std::map< std::tuple< UInt_t, Int_t, Int_t >, std::unique_ptr< CbmStsParAsic > > fModuleAsicParams
void SetGlobalAsicParams(UShort_t nChannels, UShort_t nAdc, Double_t dynRange, Double_t threshold, Double_t timeResolution, Double_t deadTime, Double_t noise, Double_t zeroNoiseRate)
Set individual module parameters.
void UseOnlyPrimaries(Bool_t flag=kTRUE)
Discard processing of secondary tracks.
virtual InitStatus ReInit()
Double_t fNofPointsProcTot
Total number of processed points.
CbmStsParSetModule * fParSetModule
Module parameter.
std::map< UInt_t, CbmStsSimModule * > fModules
Double_t fNofNoiseTot
Total number of noise digis.
void ProcessPoint(const CbmStsPoint *point, Double_t eventTime, const CbmLink &link)
CbmStsParSim * fUserParSim
Settings for simulation.
CbmStsParSetSensorCond * fParSetCond
Sensor conditions.
bool IsChannelActiveSts(Int_t address, UShort_t channel)
Test if the channel of a digi object is set active.
void CreateDigi(Int_t address, UShort_t channel, Long64_t time, UShort_t adc, const CbmMatch &match)
std::pair< size_t, bool > ReadInactiveChannels()
Read the list of inactive channels from file.
std::string BufferStatus() const
Status of the analogue buffers.
void SetProcesses(CbmStsELoss eLossModel, Bool_t useLorentzShift=kTRUE, Bool_t useDiffusion=kTRUE, Bool_t useCrossTalk=kTRUE)
Double_t fUserFracDeadChan
Fraction of inactive ASIC channels.
void InitParams()
Initialise the parameters.
std::map< Int_t, std::set< UShort_t > > fInactiveChannelsSts
Int_t fNofEvents
Total number of processed events.
void SetGlobalSensorConditions(Double_t vDep, Double_t vBias, Double_t temperature, Double_t cCoupling, Double_t cInterstrip)
Set the global sensor conditions.
void SetModuleParameterFile(const char *fileName)
Set the file name with module parameters.
CbmStsParSensorCond * fUserParCond
User defined, global.
Int_t fNofPointsIgno
Number of ignored points.
Double_t fTimePointLast
Time of last processed StsPoint.
Int_t fNofSignalsB
Number of signals on back side.
Double_t fNofSignalsBTot
Number of signals on back side.
UInt_t InitSensors()
Instantiate sensors.
Double_t fUserDinactive
Size of inactive sensor border [cm].
void ResetCounters()
Reset event counters.
CbmStsParSetSensor * fParSetSensor
Sensor parameters.
bool SetAsicParamsFromFile(const char *filename)
Set ASIC parameters from ASCII file.
virtual void SetParContainers()
Inherited from FairTask.
Double_t fTimeDigiLast
Time of last digi sent to DAQ.
Class representing an element of the STS setup.
CbmStsElement * GetMother() const
TGeoPhysicalNode * GetPnode() const
Parameters of the STS readout ASIC.
Parameters for one STS module.
Parameters for operating conditions of a STS sensor.
Constructional parameters of a STS sensor.
void SetPar(UInt_t index, Float_t value)
Set a parameter.
Parameters container for CbmStsParModule.
Parameters container for CbmStsParSensorCond.
Parameters container for CbmStsParSensor.
Settings for STS simulation (digitizer)
static CbmStsPhysics * Instance()
Accessor to singleton instance.
Class representing an instance of a sensor in the CBM-STS.
static CbmStsSetup * Instance()
Class for the simulation of a readout unit in the CBM-STS.