18#include <FairRootManager.h>
22#include <TClonesArray.h>
29#include <TStopwatch.h>
46 , fShowDebugHistos(kFALSE)
47 , fNoiseSensors(kFALSE)
49 , fInputPoints(nullptr)
60 , fDeltaBufferSize(-1)
63 , fInputBranchName(
"")
66 , fHistoFileName(
"./CbmMvdDigitizer_defaultHistoFile.root")
68 , fPileupManager(nullptr)
69 , fDeltaManager(nullptr)
72 fTmpDigi =
new TClonesArray(
"CbmMvdDigi", 1000);
73 fTmpMatch =
new TClonesArray(
"CbmMatch", 1000);
82 , fShowDebugHistos(kFALSE)
83 , fNoiseSensors(kFALSE)
85 , fInputPoints(nullptr)
96 , fDeltaBufferSize(-1)
99 , fInputBranchName(
"MvdPoint")
102 , fHistoFileName(
"./CbmMvdDigitizer_defaultHistoFile.root")
104 , fPileupManager(nullptr)
105 , fDeltaManager(nullptr)
108 fTmpDigi =
new TClonesArray(
"CbmMvdDigi", 1000);
109 fTmpMatch =
new TClonesArray(
"CbmMatch", 1000);
135 cout <<
"- I - CbmMvdDigitizer:: Exec : Event time = " <<
fCurrentEventTime << endl;
144 cout << fName <<
"Debug: 1" << endl;
147 LOG(debug) <<
"//----------------------------------------//";
148 LOG(debug) << fName <<
": Send Input";
156 for (
Int_t i = 0; i < nPoints; i++) {
162 cout << fName <<
"Debug: 2" << endl;
165 LOG(debug) << fName <<
": Execute DigitizerPlugin Nr. " <<
fDigiPluginNr;
167 LOG(debug) << fName <<
": End Chain";
184 for (
Int_t index = 0; index < nEntries; index++) {
208 LOG(debug) << fName <<
": Sent " << nDigis <<
" digis to DAQ";
215 LOG(debug) <<
"//----------------------------------------//";
228 LOG(info) <<
"+ " << setw(15) << GetName() <<
": Event " << setw(6) << right <<
fCurrentEvent <<
" at " << fixed
229 << setprecision(3) <<
fCurrentEventTime <<
" ns, points: " << nPoints <<
", digis: " << nDigis
230 <<
". Exec time " << setprecision(6) <<
fTimer.RealTime() <<
" s.";
237 LOG(info) << GetName() <<
": Initialisation...";
240 FairRootManager* ioman = FairRootManager::Instance();
242 LOG(fatal) <<
"No FairRootManager!";
247 fInputPoints = (TClonesArray*) ioman->GetObject(
"MvdPoint");
250 LOG(error) <<
"No MvdPoint branch found. There was no MVD in the "
251 "simulation. Switch this task off";
258 fMcPileUp =
new TClonesArray(
"CbmMvdPoint", 10000);
259 ioman->Register(
"MvdPileUpMC",
"Mvd MC Points after Pile Up",
fMcPileUp, IsOutputBranchPersistent(
"MvdPileUpMC"));
266 LOG(error) <<
"Pileup events needed, but no background file name given! ";
271 LOG(error) <<
"The size of your BG-File is insufficient to perform the requested pileup";
272 LOG(error) <<
" You need at least events > 2* fNPileup but there are only" <<
fNPileup <<
", events in file "
274 LOG(fatal) <<
"The size of your BG-File is insufficient";
282 LOG(error) <<
"Delta events needed, but no delta elector file name given! ";
287 LOG(error) <<
"The size of your Delta-File is insufficient to perform the requested pileup";
288 LOG(error) <<
" You need at least events > 2* fNDeltaElect but there are only" <<
fNDeltaElect
290 LOG(fatal) <<
"The size of your Delta-File is insufficient";
297 LOG(info) << GetName() <<
": Running in event mode";
300 LOG(info) << GetName() <<
": Running in time based mode";
307 for (
auto itr = sensorMap.begin(); itr != sensorMap.end(); itr++) {
313 itr->second->AddPlugin(digiTask);
314 itr->second->SetDigiPlugin(plugincount);
327 if (!result.second) {
328 LOG(error) << GetName() <<
": Error in reading from file! Task will be inactive.";
331 LOG(info) << GetName() <<
": " << std::get<0>(result) <<
" lines read from file, " <<
fInactiveChannels.size()
332 <<
" channels set inactive";
336 LOG(debug) << GetName() <<
" initialised with parameters: ";
353 LOG(debug) <<
"CbmMvdDigitizer::Finish() Autodetect: " << nTargetPlugin <<
" Manual Detect " <<
fDigiPluginNr;
354 LOG(debug) <<
"finishing";
363 LOG(debug) <<
"Histograms completed";
372 LOG(info) << GetName() <<
" Finalising buffers with " << nEntries <<
" digis";
373 for (
Int_t index = 0; index < nEntries; index++) {
402 LOG(debug) <<
"CbmMvdDigitizer::CollectHistograms - Targeting nTargetPlugin= " << nTargetPlugin;
406 LOG(debug) <<
"CbmMvdDigitizer::CollectHistograms - Created new TObjArray";
410 LOG(debug) <<
"CbmMvdDigitizer::CollectHistograms - Cleared new TObjArray";
419 LOG(debug) <<
"CbmMvdDigitizer::CollectHistograms - Trying to read histogram " << i;
432 LOG(info) <<
"CbmMvdDigitizer::DisplayDebugHistos - Error: fHistoArray not initialized. Disabling histograms.";
435 for (
Int_t i = 0; i < 9; i++) {
439 LOG(debug) <<
"Trying to display histogram" << i;
440 TString myCanvasName = TString(
"DigiCanvas") + i;
441 LOG(debug) <<
"Trying to generate Canvas with name" << myCanvasName;
443 new TCanvas(myCanvasName, myCanvasName, 150, 10, 800, 600);
461 LOG(info) <<
"CbmMvdDigitizerL::SafeDebugHistosToFile - Error: fHistoArray not initialized. Disabling histograms.";
464 TFile* gFileCopy = gFile;
465 TFile* myFile =
new TFile(histoFile,
"Recreate");
466 LOG(info) <<
"CbmMvdDigitizer::SafeDebugHistosToFile - Writing histograms to file: " << histoFile;
470 LOG(debug) <<
"CbmMvdDigitizer::SafeDebugHistosToFil - Saving histogram number " << i;
512 std::stringstream ss;
513 ss.setf(std::ios_base::fixed, std::ios_base::floatfield);
514 ss <<
"============================================================" << endl;
515 ss <<
"============== Parameters MvdDigitizer =====================" << endl;
516 ss <<
"============================================================" << endl;
517 ss <<
"=============== End Task ===================================" << endl;
540 for (
int iPoint = 0; iPoint < nOrig; iPoint++) {
551 vector<Int_t> freeEvents(nBuffer);
552 for (
Int_t i = 0; i < nBuffer; i++)
559 Int_t index = gRandom->Integer(freeEvents.size());
561 Int_t iEvent = freeEvents[index];
563 freeEvents.erase(freeEvents.begin() + index);
566 for (
Int_t iPoint = 0; iPoint <
points->GetEntriesFast(); iPoint++) {
568 point->SetTrackID(-2);
586 vector<Int_t> freeDeltaEvents(nDeltaBuffer);
587 for (
Int_t i = 0; i < nDeltaBuffer; i++)
588 freeDeltaEvents[i] = i;
594 Int_t indexD = gRandom->Integer(freeDeltaEvents.size());
595 Int_t iEventD = freeDeltaEvents[indexD];
597 freeDeltaEvents.erase(freeDeltaEvents.begin() + indexD);
600 for (
Int_t iPoint = 0; iPoint < pointsD->GetEntriesFast(); iPoint++) {
602 point->SetTrackID(-3);
618 LOG(debug) <<
"+ " << GetName() <<
"::BuildEvent: original " << nOrig <<
", pileup " << nPile <<
", delta " << nElec
619 <<
", total " << nOrig + nPile + nElec <<
" MvdPoints";
ClassImp(CbmMvdDigitizer)
virtual std::pair< size_t, bool > ReadInactiveChannels()
Set of inactive channels, indicated by CbmAddress.
Int_t fCurrentEvent
Number of current input.
TString fInactiveChannelFileName
Time of current MC event [ns].
std::set< uint32_t > fInactiveChannels
Name of file with inactive channels.
void GetEventInfo()
Get event information.
Double_t fCurrentEventTime
Number of current MC entry.
Bool_t fCreateMatches
Flag for production of inter-event noise.
Base class template for CBM digitisation tasks.
void SendData(Double_t time, CbmMvdDigi *digi, CbmMatch *match=nullptr)
std::map< int, CbmMvdSensor * > & GetSensorMap()
TH1 * GetHistogram(UInt_t nPlugin, UInt_t nHistogramNumber)
Int_t GetPluginArraySize()
UInt_t GetMaxHistoNumber(UInt_t nPlugin)
static CbmMvdDetector * Instance()
Int_t DetectPlugin(Int_t pluginID)
void SetSensorArrayFilled(Bool_t value=kTRUE)
void SendInputToSensorPlugin(Int_t detectorid, Int_t nPlugin, TObject *input)
void GetOutputArray(Int_t nPlugin, TClonesArray *outputArray)
void GetMatchArray(Int_t nPlugin, TClonesArray *matchArray)
void SetPluginCount(UInt_t count)
std::string ParametersToString() const
CbmMvdPileupManager * fDeltaManager
CbmMvdPileupManager * fPileupManager
TObjArray * fHistoArray
Temporary TClonesArray to absorb from MvdDetector.
void DisplayDebugHistos()
TClonesArray * fInputPoints
virtual InitStatus Init()
std::vector< CbmMatch * > fMatchVect
Temporary storage for CbmDaq.
TClonesArray * fTmpDigi
Temporary TClonesArray to absorb from MvdDetector.
virtual void ResetArrays()
Clear data arrays.
std::vector< CbmMvdDigi * > fDigiVect
virtual InitStatus ReInit()
Int_t DetectPlugin(Int_t pluginID)
CbmMvdDetector * fDetector
void SafeDebugHistosToFile(TString histoFile)
void PrintParameters() const
TStopwatch fTimer
ROOT timer.
TClonesArray * GetEvent(Int_t iEvent)
void SetPointId(int32_t myId)