23#include "TClonesArray.h"
25#include "TGeoMatrix.h"
26#include "TGeoPhysicalNode.h"
27#include "TGeoVolume.h"
28#include <TMCProcess.h>
31#include "FairEventHeader.h"
34#include "FairMCEventHeader.h"
35#include "FairMCPoint.h"
36#include "FairRunAna.h"
37#include "FairRunSim.h"
38#include "FairRuntimeDb.h"
64using std::setprecision;
67using std::stringstream;
75 , fIsInitialised(kFALSE)
83 , fSensorPitch(0.0058)
86 , fSensorParameterFile()
87 , fSensorConditionFile()
88 , fModuleParameterFile()
113 entry.second->BufferStatus(nSigModule, t1Module, t2Module);
114 nSignals += nSigModule;
135 entry.second->BufferStatus(nSigModule, t1Module, t2Module);
137 nSignals += nSigModule;
138 t1 = t1 < 0. ? t1Module : TMath::Min(t1, t1Module);
139 t2 = TMath::Max(t2, t2Module);
143 std::stringstream ss;
144 ss << nSignals << (nSignals == 1 ?
" signal " :
" signals ") <<
"in analogue buffers";
145 if (nSignals) ss <<
" ( from " << fixed << setprecision(3) << t1 <<
" ns to " << t2 <<
" ns )";
186 if (fair::Logger::Logging(fair::Severity::debug)) {
187 std::cout << std::endl;
201 nNoise += entry.second->GenerateNoise(tNoiseStart, tNoiseEnd);
203 LOG(info) <<
"+ " << setw(20) << GetName() <<
": Generated " << nNoise <<
" noise signals from t = " << tNoiseStart
204 <<
" ns to " << tNoiseEnd <<
" ns";
212 if (fair::Logger::Logging(fair::Severity::debug)) { LOG(debug) << GetName() <<
": " <<
BufferStatus(); }
225 if (fair::Logger::Logging(fair::Severity::debug)) { LOG(debug) << GetName() <<
": " <<
BufferStatus(); }
228 LOG(info) << left << setw(15) << GetName() <<
"[" << fixed << setprecision(3) <<
fTimer.RealTime() <<
" s]"
257 LOG(fatal) << fName <<
": Non-empty analogue buffers at end of event "
258 <<
" in event-by-event mode!";
264 std::cout << std::endl;
265 LOG(info) << GetName() <<
": Finish run";
267 LOG(info) << GetName() <<
": Processing analogue buffers";
271 entry.second->ProcessAnalogBuffer(-1.);
275 ss << GetName() <<
": " <<
fNofDigis << (
fNofDigis == 1 ?
" digi " :
" digis ") <<
"created and sent to DAQ ";
278 LOG(info) << ss.str();
290 std::cout << std::endl;
291 LOG(info) <<
"=====================================";
292 LOG(info) << GetName() <<
": Run summary";
293 LOG(info) <<
"Events processed : " <<
fNofEvents;
304 LOG(info) <<
"=====================================";
312 assert(FairRunAna::Instance());
313 FairRuntimeDb* rtdb = FairRunAna::Instance()->GetRuntimeDb();
327 std::cout << std::endl;
328 LOG(info) <<
"==========================================================";
329 LOG(info) << GetName() <<
": Initialisation \n\n";
345 if (!result.second) {
346 LOG(error) << GetName() <<
": Error in reading from file! Task will be inactive.";
349 LOG(info) << GetName() <<
": " << std::get<0>(result) <<
" lines read from file";
351 size_t nChanInactive = 0;
353 nChanInactive += entry.second.size();
354 LOG(info) << GetName() <<
": " << nChanInactive <<
" channels set inactive";
358 LOG(info) << GetName() <<
": Created " << nModules <<
" modules";
362 LOG(info) << GetName() <<
": Created " << nSensors <<
" sensors";
365 FairRootManager* ioman = FairRootManager::Instance();
369 fPoints = (TClonesArray*) ioman->GetObject(
"StsPoint");
373 fTracks = (TClonesArray*) ioman->GetObject(
"MCTrack");
380 LOG(info) << GetName() <<
": Initialisation successful";
381 LOG(info) <<
"==========================================================";
382 std::cout << std::endl;
405 auto result =
fModules.insert({address, module});
406 assert(result.second);
410 assert(nModules ==
fModules.size());
437 fParSim->setInputVersion(-2, 1);
450 UInt_t deactivated = 0;
456 LOG(info) <<
"--- Deactive channels: " << deactivated <<
" " <<
fUserFracDeadChan;
467 TGeoBBox* box =
dynamic_cast<TGeoBBox*
>(sensor->
GetPnode()->GetShape());
469 Double_t lX = 2. * box->GetDX();
470 Double_t lY = 2. * box->GetDY();
471 Double_t lZ = 2. * box->GetDZ();
479 Double_t nStripsF = dX / pitchF;
480 Double_t nStripsB = dX / pitchB;
484 && TMath::Abs(pitchF - 0.0058) < 0.0001) {
491 && TMath::Abs(pitchF - 0.0058) < 0.0001) {
504 for (UInt_t parIndex = 6; parIndex < 10; parIndex++) {
544 auto moduIt =
fModules.find(moduAddress);
546 assert(moduIt->second);
553 assert(result.second);
554 auto& sensor = result.first->second;
558 sensor->SetElement(geoSensor);
559 sensor->SetModule(moduIt->second);
562 sensor->SetSimSettings(
fParSim);
567 sensor->SetConditions(&cond);
573 if (FairRun::Instance()->GetField()) {
574 Double_t local[3] = {0., 0., 0.};
576 geoSensor->
GetPnode()->GetMatrix()->LocalToMaster(local, global);
577 Double_t field[3] = {0., 0., 0.};
578 FairRun::Instance()->GetField()->Field(global, field);
583 sensor->SetField(bx, by, bz);
586 assert(sensor->Init());
591 assert(nSensors ==
fSensors.size());
621 if (it->second.count(channel))
return false;
633 it.second->ProcessAnalogBuffer(readoutTime);
644 for (Int_t iPoint = 0; iPoint <
fPoints->GetEntriesFast(); iPoint++) {
649 Int_t iTrack = point->GetTrackID();
665 if (point->GetTime() > 1.e6) {
684 UInt_t address =
static_cast<UInt_t
>(point->GetDetectorID());
686 auto& sensor =
fSensors.find(address)->second;
688 Int_t status = sensor->ProcessPoint(point, eventTime, link);
691 Int_t nSignalsF = status / 1000;
692 Int_t nSignalsB = status - 1000 * nSignalsF;
693 LOG(debug2) << GetName() <<
": Produced signals: " << nSignalsF + nSignalsB <<
" ( " << nSignalsF <<
" / "
694 << nSignalsB <<
" )";
708 if (channelFile ==
nullptr)
return std::make_pair(0,
false);
711 uint32_t address = 0;
712 uint16_t channel = 0;
713 while (fscanf(channelFile,
"%u %hu", &address, &channel) == 2) {
717 bool success = feof(channelFile);
720 return std::make_pair(nLines, success);
762 Bool_t eventMode = kFALSE;
764 Bool_t lorentzShift = kTRUE;
765 Bool_t diffusion = kTRUE;
766 Bool_t crossTalk = kTRUE;
767 Bool_t generateNoise = kTRUE;
777 UInt_t nChannels = 2048;
778 UInt_t nAsicChannels = 128;
784 Double_t dynRange = 75000.;
785 Double_t threshold = 3000.;
786 Double_t timeResol = 5.;
787 Double_t deadTime = 800.;
788 Double_t noiseRms = 1000.;
789 Double_t znr = 3.9789e-3;
797 Double_t pitchF = 0.0058;
798 Double_t pitchB = 0.0058;
799 Double_t stereoF = 0.;
800 Double_t stereoB = 7.5;
810 Double_t vBias = 140.;
811 Double_t temperature = 268.;
812 Double_t cCoupling = 17.5;
813 Double_t cInterstrip = 1.;
821 Double_t timeResolution, Double_t deadTime, Double_t noise,
822 Double_t zeroNoiseRate)
828 new CbmStsParAsic(nChannels, nAdc, dynRange, threshold, timeResolution, deadTime, noise, zeroNoiseRate);
846 Double_t cInterstrip)
871 LOG(error) << GetName() <<
": physics processes must be set before "
872 <<
"initialisation! Statement will have no effect.";
886 LOG(fatal) << GetName() <<
": sensor conditions must be set before initialisation!";
899 LOG(fatal) << GetName() <<
": sensor parameters must be set before initialisation!";
ClassImp(CbmConverterManager)
CbmStsSensorClass
Sensor classes.
CbmStsELoss
Energy loss model used in simulation.
TString fInactiveChannelFileName
Time of current MC event [ns].
Double_t fRunStartTime
Flag for creation of links to MC.
void GetEventInfo()
Get event information.
Int_t fCurrentInput
Start time of run [ns].
Double_t fCurrentEventTime
Number of current MC entry.
Int_t fCurrentMCEntry
Number of current MC event.
Bool_t fCreateMatches
Flag for production of inter-event noise.
Bool_t fProduceNoise
Flag for event-by-event mode.
Base class template for CBM digitisation tasks.
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.
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.
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.
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.
CbmStsParSensor * fUserParSensor
User defined, global.
TString fSensorParameterFile
File with sensor parameters.
CbmStsParSim * fParSim
Simulation settings.
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.
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.
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.
std::string ToString() const
Info to string.
Parameters for one STS module.
void SetAllAsics(const CbmStsParAsic &asicPar)
Set all ASICs with the same parameter set.
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.
CbmStsSensorClass GetClass() const
Get the sensor class.
Float_t GetPar(UInt_t index) const
Get a parameter.
Parameters container for CbmStsParModule.
const CbmStsParModule & GetParModule(UInt_t address)
Get condition parameters of a sensor.
virtual void clear()
Reset all parameters.
void SetParModule(UInt_t address, const CbmStsParModule &par)
Set the parameters for a module.
UInt_t DeactivateRandomChannels(Double_t fraction)
Randomly deactivate a fraction of the channels.
std::string ToString() const
Info to string.
Parameters container for CbmStsParSensorCond.
std::string ToString()
Info to string.
void SetGlobalPar(Double_t vDep, Double_t vBias, Double_t temperature, Double_t cCoupling, Double_t cInterstrip)
Set global conditions (for all sensors)
virtual void clear()
Reset all parameters.
const CbmStsParSensorCond & GetParSensor(UInt_t address)
Get condition parameters of a sensor.
Parameters container for CbmStsParSensor.
void SetParSensor(UInt_t address, const CbmStsParSensor &par)
Set the parameters for a sensor.
std::string ToString() const
Info to string.
const CbmStsParSensor & GetParSensor(UInt_t address)
Get condition parameters of a sensor.
virtual void clear()
Reset all parameters.
Settings for STS simulation (digitizer)
std::string ToString() const
String output.
Bool_t Noise() const
Check whether inter-event noise is generated.
void SetGenerateNoise(Bool_t choice=kTRUE)
Activate or de-activate inter-event noise.
void SetProcesses(CbmStsELoss eLossModel, Bool_t useLorentzShift, Bool_t useDiffusion, Bool_t useCrossTalk)
void SetEventMode(Bool_t choice=kTRUE)
Set event-by-event simulation mode.
void SetOnlyPrimaries(Bool_t choice=kTRUE)
Process only primary tracks.
Bool_t OnlyPrimaries() const
Process only primary tracks.
static CbmStsPhysics * Instance()
Accessor to singleton instance.
Class representing an instance of a sensor in the CBM-STS.
Int_t GetNofSensors() const
Bool_t Init(const char *geometryFile=nullptr)
Initialise the setup.
CbmStsModule * GetModule(Int_t index) const
Get a module from the module array.
UInt_t SetSensorConditions(CbmStsParSetSensorCond *conds)
Set sensor conditions from parameter container.
static CbmStsSetup * Instance()
UInt_t SetModuleParameters(CbmStsParSetModule *modulePars)
Set module parameters from parameter container.
CbmStsSensor * GetSensor(Int_t index) const
Get a sensor from the sensor array.
UInt_t SetSensorParameters(CbmStsParSetSensor *parSet)
Set sensor parameters from parameter container.
Int_t GetNofModules() const
Class for the simulation of a readout unit in the CBM-STS.
UP_sensor CreateSensor(const CbmStsParSensor &par)
Create a sensor.