// this feature is not available for all detectors and that merging is not //
// possible, when digits are created directly from hits. //
// //
-// Backgound events can be merged by calling //
+// Background events can be merged by calling //
// //
// sim.MergeWith("background/galice.root", 2); //
// //
// The first argument is the file name of the background galice file. The //
// second argument is the number of signal events per background event. //
-// The default value for this is 1. MergeWith can be called several times //
-// to merge more than two event streams. It is assumed that the sdigits //
-// were already produced for the background events. //
+// By default this number is calculated from the number of available //
+// background events. MergeWith can be called several times to merge more //
+// than two event streams. It is assumed that the sdigits were already //
+// produced for the background events. //
// //
-// The methods RunSimulation, RunSDigitization, RunDigitization and //
-// RunHitsDigitization can be used to run only parts of the full simulation //
-// chain. //
+// The output of raw data can be switched on by calling //
+// //
+// sim.SetWriteRawData("MUON"); // write raw data for MUON //
+// //
+// The methods RunSimulation, RunSDigitization, RunDigitization, //
+// RunHitsDigitization and WriteRawData can be used to run only parts of //
+// the full simulation chain. //
// //
///////////////////////////////////////////////////////////////////////////////
+#include <TObjString.h>
+#include <TStopwatch.h>
+#include <TSystem.h>
-#include "AliSimulation.h"
-#include "AliRunLoader.h"
-#include "AliRun.h"
-#include "AliModule.h"
+#include "AliDigitizer.h"
#include "AliGenerator.h"
+#include "AliModule.h"
+#include "AliRun.h"
#include "AliRunDigitizer.h"
-#include "AliDigitizer.h"
-#include <TObjString.h>
-
+#include "AliRunLoader.h"
+#include "AliSimulation.h"
+#include "AliVertexGenFile.h"
ClassImp(AliSimulation)
fMakeSDigits("ALL"),
fMakeDigits("ALL"),
fMakeDigitsFromHits(""),
+ fWriteRawData(""),
fStopOnError(kFALSE),
fNEvents(1),
fConfigFileName(configFileName),
fGAliceFileName("galice.root"),
fBkgrdFileNames(NULL),
+ fUseBkgrdVertex(kTRUE),
fRegionOfInterest(kTRUE)
{
// create simulation object with default parameters
+ SetGAliceFile("galice.root");
}
//_____________________________________________________________________________
fMakeSDigits(sim.fMakeSDigits),
fMakeDigits(sim.fMakeDigits),
fMakeDigitsFromHits(sim.fMakeDigitsFromHits),
+ fWriteRawData(sim.fWriteRawData),
fStopOnError(sim.fStopOnError),
fNEvents(sim.fNEvents),
fConfigFileName(sim.fConfigFileName),
fGAliceFileName(sim.fGAliceFileName),
fBkgrdFileNames(NULL),
+ fUseBkgrdVertex(sim.fUseBkgrdVertex),
fRegionOfInterest(sim.fRegionOfInterest)
{
// copy constructor
fConfigFileName = fileName;
}
+//_____________________________________________________________________________
+void AliSimulation::SetGAliceFile(const char* fileName)
+{
+// set the name of the galice file
+// the path is converted to an absolute one if it is relative
+
+ fGAliceFileName = fileName;
+ if (!gSystem->IsAbsoluteFileName(fGAliceFileName)) {
+ char* absFileName = gSystem->ConcatFileName(gSystem->WorkingDirectory(),
+ fGAliceFileName);
+ fGAliceFileName = absFileName;
+ delete[] absFileName;
+ }
+}
+
//_____________________________________________________________________________
void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
{
}
}
+ // digits -> raw data
+ if (!fWriteRawData.IsNull()) {
+ if (!WriteRawData(fWriteRawData)) {
+ if (fStopOnError) return kFALSE;
+ }
+ }
+
return kTRUE;
}
"Check your config file: %s", fConfigFileName.Data());
return kFALSE;
}
- fGAliceFileName = runLoader->GetFileName();
+ SetGAliceFile(runLoader->GetFileName());
+
+ if (!gAlice->Generator()) {
+ Error("RunSimulation", "gAlice has no generator object. "
+ "Check your config file: %s", fConfigFileName.Data());
+ return kFALSE;
+ }
+ if (nEvents <= 0) nEvents = fNEvents;
+
+ // get vertex from background file in case of merging
+ if (fUseBkgrdVertex &&
+ fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
+ Int_t signalPerBkgrd = GetNSignalPerBkgrd(nEvents);
+ const char* fileName = ((TObjString*)
+ (fBkgrdFileNames->At(0)))->GetName();
+ Info("RunSimulation", "The vertex will be taken from the background "
+ "file %s with nSignalPerBackground = %d",
+ fileName, signalPerBkgrd);
+ AliVertexGenFile* vtxGen = new AliVertexGenFile(fileName, signalPerBkgrd);
+ gAlice->Generator()->SetVertexGenerator(vtxGen);
+ }
if (!fRunSimulation) {
- if (!gAlice->Generator()) {
- Error("RunSimulation", "gAlice has no generator object. "
- "Check your config file: %s", fConfigFileName.Data());
- return kFALSE;
- }
gAlice->Generator()->SetTrackingFlag(0);
}
Info("RunSimulation", "running gAlice");
- if (nEvents <= 0) nEvents = fNEvents;
gAlice->Run(nEvents);
delete runLoader;
if (IsSelected(det->GetName(), detStr)) {
Info("RunSDigitization", "creating summable digits for %s",
det->GetName());
+ TStopwatch stopwatchDet;
+ stopwatchDet.Start();
det->Hits2SDigits();
+ Info("RunSDigitization", "execution time for %s:", det->GetName());
+ stopwatchDet.Print();
}
}
gAlice = NULL;
Int_t nStreams = 1;
- Int_t signalPerBkgrd = 1;
- if (fBkgrdFileNames) {
- nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
- if (nStreams > 1) signalPerBkgrd = fBkgrdFileNames->At(0)->GetUniqueID();
- }
+ if (fBkgrdFileNames) nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
+ Int_t signalPerBkgrd = GetNSignalPerBkgrd();
AliRunDigitizer* manager = new AliRunDigitizer(nStreams, signalPerBkgrd);
manager->SetInputStream(0, fGAliceFileName.Data());
for (Int_t iStream = 1; iStream < nStreams; iStream++) {
return kTRUE;
}
+//_____________________________________________________________________________
+Bool_t AliSimulation::WriteRawData(const char* detectors)
+{
+// convert the digits to raw data
+
+ TStopwatch stopwatch;
+ stopwatch.Start();
+
+ AliRunLoader* runLoader = LoadRun();
+ if (!runLoader) return kFALSE;
+
+ for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
+ Info("WriteRawData", "processing event %d", iEvent);
+ runLoader->GetEvent(iEvent);
+ TString baseDir = gSystem->WorkingDirectory();
+ char dirName[256];
+ sprintf(dirName, "raw%d", iEvent);
+ gSystem->MakeDirectory(dirName);
+ if (!gSystem->ChangeDirectory(dirName)) {
+ Error("WriteRawData", "couldn't change to directory %s", dirName);
+ if (fStopOnError) return kFALSE; else continue;
+ }
+
+ TString detStr = detectors;
+ TObjArray* detArray = runLoader->GetAliRun()->Detectors();
+ for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
+ AliModule* det = (AliModule*) detArray->At(iDet);
+ if (!det || !det->IsActive()) continue;
+ if (IsSelected(det->GetName(), detStr)) {
+ Info("WriteRawData", "creating raw data from digits for %s",
+ det->GetName());
+ det->Digits2Raw();
+ }
+ }
+
+ gSystem->ChangeDirectory(baseDir);
+ if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
+ Error("WriteRawData", "the following detectors were not found: %s",
+ detStr.Data());
+ if (fStopOnError) return kFALSE;
+ }
+ }
+
+ delete runLoader;
+
+ Info("WriteRawData", "execution time:");
+ stopwatch.Print();
+
+ return kTRUE;
+}
+
//_____________________________________________________________________________
AliRunLoader* AliSimulation::LoadRun() const
while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
AliRunLoader* runLoader =
AliRunLoader::Open(fGAliceFileName.Data(),
- AliConfig::fgkDefaultEventFolderName, "UPDATE");
+ AliConfig::GetDefaultEventFolderName(), "UPDATE");
if (!runLoader) {
Error("LoadRun", "no run loader found in file %s",
fGAliceFileName.Data());
return runLoader;
}
+//_____________________________________________________________________________
+Int_t AliSimulation::GetNSignalPerBkgrd(Int_t nEvents) const
+{
+// get or calculate the number of signal events per background event
+
+ if (!fBkgrdFileNames) return 1;
+ Int_t nBkgrdFiles = fBkgrdFileNames->GetEntriesFast();
+ if (nBkgrdFiles == 0) return 1;
+
+ // get the number of signal events
+ if (nEvents <= 0) {
+ AliRunLoader* runLoader =
+ AliRunLoader::Open(fGAliceFileName.Data(), "SIGNAL");
+ if (!runLoader) return 1;
+ nEvents = runLoader->GetNumberOfEvents();
+ delete runLoader;
+ }
+
+ Int_t result = 0;
+ for (Int_t iBkgrdFile = 0; iBkgrdFile < nBkgrdFiles; iBkgrdFile++) {
+ // get the number of background events
+ const char* fileName = ((TObjString*)
+ (fBkgrdFileNames->At(iBkgrdFile)))->GetName();
+ AliRunLoader* runLoader =
+ AliRunLoader::Open(fileName, "BKGRD");
+ if (!runLoader) continue;
+ Int_t nBkgrdEvents = runLoader->GetNumberOfEvents();
+ delete runLoader;
+
+ // get or calculate the number of signal per background events
+ Int_t nSignalPerBkgrd = fBkgrdFileNames->At(iBkgrdFile)->GetUniqueID();
+ if (nSignalPerBkgrd <= 0) {
+ nSignalPerBkgrd = (nEvents-1) / nBkgrdEvents + 1;
+ } else if (result && (result != nSignalPerBkgrd)) {
+ Info("GetNSignalPerBkgrd", "the number of signal events per "
+ "background event will be changed from %d to %d for stream %d",
+ nSignalPerBkgrd, result, iBkgrdFile+1);
+ nSignalPerBkgrd = result;
+ }
+
+ if (!result) result = nSignalPerBkgrd;
+ if (nSignalPerBkgrd * nBkgrdEvents < nEvents) {
+ Warning("GetNSignalPerBkgrd", "not enough background events (%d) for "
+ "%d signal events using %d signal per background events for "
+ "stream %d",
+ nBkgrdEvents, nEvents, nSignalPerBkgrd, iBkgrdFile+1);
+ }
+ }
+
+ return result;
+}
+
//_____________________________________________________________________________
Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
{