* provided "as is" without express or implied warranty. *
**************************************************************************/
-/* $Id$ */
+/* $Id: AliSimulation.cxx 64623 2013-10-21 13:38:58Z rgrosso $ */
///////////////////////////////////////////////////////////////////////////////
// //
// The number of events per file has to be set before the simulation of //
// hits. Otherwise it has no effect. //
// //
+// The trigger configuration is set by the method SetTriggerConfig(X) //
+// X can take three kinds of values //
+// //
+// - The exact string "none" - case insensitive. In this case, not trigger //
+// information is generated from the digits. //
+// - The empty string or "ocdb" - case insensitive. In this case the //
+// trigger configuration is read from OCDB //
+// - Some string - say "p-p" - in which case the configuration is read from //
+// fixed files in $ALICE_ROOT/GRP/CTP/ - say $ALICE_ROOT/GRP/CTP/p-p.cfg //
+// //
+// Default is to read from OCDB. //
+// //
///////////////////////////////////////////////////////////////////////////////
-#include <TCint.h>
#include <TFile.h>
#include <TGeoGlobalMagField.h>
#include <TGeoManager.h>
#include "AliRun.h"
#include "AliDigitizationInput.h"
#include "AliRunLoader.h"
+#include "AliStack.h"
#include "AliSimulation.h"
#include "AliSysInfo.h"
#include "AliVertexGenFile.h"
ClassImp(AliSimulation)
AliSimulation *AliSimulation::fgInstance = 0;
-const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE"
-// #ifdef MFT_UPGRADE
-// ,"MFT"
-// #endif
- ,"MFT" // AU
- ,"HLT"
-};
+ const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD",
+ "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE","AD",
+ "FIT","MFT","HLT"};
//_____________________________________________________________________________
AliSimulation::AliSimulation(const char* configFileName,
const char* name, const char* title) :
TNamed(name, title),
+ fRunGeneratorOnly(kFALSE),
fRunGeneration(kTRUE),
fRunSimulation(kTRUE),
fLoadAlignFromCDB(kTRUE),
fDeleteIntermediateFiles(kFALSE),
fWriteSelRawData(kFALSE),
fStopOnError(kFALSE),
+ fUseMonitoring(kFALSE),
fNEvents(1),
fConfigFileName(configFileName),
fGAliceFileName("galice.root"),
// Set CDB lock: from now on it is forbidden to reset the run number
// or the default storage or to activate any further storage!
- ULong_t key = AliCDBManager::Instance()->SetLock(1);
+ ULong64_t key = AliCDBManager::Instance()->SetLock(1);
if (key) fKey = key;
}
if (nEvents > 0) fNEvents = nEvents;
+ // Run generator-only code on demand
+ if (fRunGeneratorOnly)
+ {
+ if(!RunGeneratorOnly())
+ {
+ if (fStopOnError) return kFALSE;
+ }
+ else
+ return kTRUE;
+ }
+
// create and setup the HLT instance
if (!fRunHLT.IsNull() && !CreateHLT()) {
if (fStopOnError) return kFALSE;
AliSysInfo::AddStamp("Hits2Digits");
- // digits -> trigger
- if (!fTriggerConfig.IsNull() && !RunTrigger(fTriggerConfig,fMakeDigits)) {
+ // digits -> trigger. Set trigger configuration to "none" - any
+ // case - to not generate the trigger information. Set the trigger
+ // configuration to some string X to read from file at
+ // $ALICE_ROOT/GRP/CTP/X. Set the trigger configuration to the
+ // empty string or "ocdb" - any case - to read from OCDB.
+ if (!fTriggerConfig.EqualTo("none",TString::kIgnoreCase) &&
+ !RunTrigger(fTriggerConfig,fMakeDigits)) {
if (fStopOnError) return kFALSE;
}
}
AliSysInfo::AddStamp("RunQA");
-
+ //
+ StoreUsedCDBMaps();
+ //
TString snapshotFileOut("");
if(TString(gSystem->Getenv("OCDB_SNAPSHOT_CREATE")) == TString("kTRUE")){
AliInfo(" ******** Creating the snapshot! *********");
AliError("gAlice was already run. Restart aliroot and try again.");
return kFALSE;
}
-
AliInfo(Form("initializing gAlice with config file %s",
fConfigFileName.Data()));
gAlice->Announce();
+ // - cholm - Add this here for consitency
+ // If requested set the mag. field from the GRP entry.
+ // After this the field is loccked and cannot be changed by Config.C
+ if (fUseMagFieldFromGRP) {
+ AliGRPManager grpM;
+ grpM.ReadGRPEntry();
+ grpM.SetMagField();
+ AliInfo("Field is locked now. It cannot be changed in Config.C");
+
+ }
+
gROOT->LoadMacro(setup);
gInterpreter->ProcessLine(gAlice->GetConfigFunction());
AliPDG::AddParticlesToPdgDataBase();
- gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
+ TVirtualMC::GetMC()->SetMagField(TGeoGlobalMagField::Instance()->GetField());
gAlice->GetMCApp()->Init();
AliGenerator *gen=gAlice->GetMCApp()->Generator();
gAlice->GetMCApp()->ResetGenerator(gener);
//Prepare MC for Lego Run
- gMC->InitLego();
+ TVirtualMC::GetMC()->InitLego();
//Run Lego Object
AliRunLoader::Instance()->SetNumberOfEventsPerFile(nev);
- gMC->ProcessRun(nev);
+ TVirtualMC::GetMC()->ProcessRun(nev);
// End of this run, close files
FinishRun();
// Details of the format are given in the
// trigger TDR - pages 134 and 135.
AliCTPRawData writer;
- writer.RawData();
+ //writer.RawData();
+ writer.RawDataRun2();
return kTRUE;
}
AliError("gAlice was already run. Restart aliroot and try again.");
return kFALSE;
}
+
+ // Setup monitoring if requested
+ gAlice->GetMCApp()->SetUseMonitoring(fUseMonitoring);
AliInfo(Form("initializing gAlice with config file %s",
fConfigFileName.Data()));
AliPDG::AddParticlesToPdgDataBase();
- gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
+ TVirtualMC::GetMC()->SetMagField(TGeoGlobalMagField::Instance()->GetField());
AliSysInfo::AddStamp("RunSimulation_GetField");
-
gAlice->GetMCApp()->Init();
AliSysInfo::AddStamp("RunSimulation_InitMCApp");
// Create the Root Tree with one branch per detector
//Hits moved to begin event -> now we are crating separate tree for each event
-
- gMC->ProcessRun(nEvents);
+ TVirtualMC::GetMC()->ProcessRun(nEvents);
// End of this run, close files
if(nEvents>0) FinishRun();
return kTRUE;
}
+//_____________________________________________________________________________
+Bool_t AliSimulation::RunGeneratorOnly()
+{
+ // Execute Config.C
+ TInterpreter::EErrorCode interpreterError=TInterpreter::kNoError;
+ gROOT->LoadMacro(fConfigFileName.Data());
+ Long_t interpreterResult=gInterpreter->ProcessLine(gAlice->GetConfigFunction(), &interpreterError);
+ if (interpreterResult!=0 || interpreterError!=TInterpreter::kNoError) {
+ AliFatal(Form("execution of config file \"%s\" failed with error %d", fConfigFileName.Data(), (int)interpreterError));
+ }
+
+ // Setup the runloader and generator, check if everything is OK
+ AliRunLoader* runLoader = AliRunLoader::Instance();
+ AliGenerator* generator = gAlice->GetMCApp()->Generator();
+ if (!runLoader) {
+ AliError(Form("gAlice has no run loader object. "
+ "Check your config file: %s", fConfigFileName.Data()));
+ return kFALSE;
+ }
+ if (!generator) {
+ AliError(Form("gAlice has no generator object. "
+ "Check your config file: %s", fConfigFileName.Data()));
+ return kFALSE;
+ }
+
+ runLoader->LoadKinematics("RECREATE");
+ runLoader->MakeTree("E");
+
+ // Create stack and header
+ runLoader->MakeStack();
+ AliStack* stack = runLoader->Stack();
+ AliHeader* header = runLoader->GetHeader();
+
+ // Intialize generator
+ generator->Init();
+ generator->SetStack(stack);
+
+ // Run main generator loop
+
+ for (Int_t iev=0; iev<fNEvents; iev++)
+ {
+ // Initialize event
+ header->Reset(0,iev);
+ runLoader->SetEventNumber(iev);
+ stack->Reset();
+ runLoader->MakeTree("K");
+
+ // Generate event
+ generator->Generate();
+
+ // Finish event
+ header->SetNprimary(stack->GetNprimary());
+ header->SetNtrack(stack->GetNtrack());
+ stack->FinishEvent();
+ header->SetStack(stack);
+ runLoader->TreeE()->Fill();
+ runLoader->WriteKinematics("OVERWRITE");
+ }
+
+ // Finalize
+ generator->FinishRun();
+ // Write file
+ runLoader->WriteHeader("OVERWRITE");
+ generator->Write();
+ runLoader->Write();
+
+ return kTRUE;
+}
+
//_____________________________________________________________________________
Bool_t AliSimulation::RunSDigitization(const char* detectors)
{
AliCodeTimerStart(Form("creating summable digits for %s", det->GetName()));
det->Hits2SDigits();
AliCodeTimerStop(Form("creating summable digits for %s", det->GetName()));
- AliSysInfo::AddStamp(Form("Digit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
+ AliSysInfo::AddStamp(Form("SDigit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
}
}
const char* excludeDetectors)
{
// run the digitization and produce digits from sdigits
-
AliCodeTimerAuto("",0)
// initialize CDB storage, run number, set CDB lock
}
detArr.AddLast(digitizer);
AliInfo(Form("Created digitizer from SDigits -> Digits for %s", det->GetName()));
+
}
//
if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
digInp.InitEvent(); //this must be after call of Connect Input tress.
if (outRl) outRl->SetEventNumber(eventsCreated-1);
static_cast<AliStream*>(digInp.GetInputStream(0))->ImportgAlice(); // use gAlice of the first input stream
- for (int id=0;id<ndigs;id++) ((AliDigitizer*)detArr[id])->Digitize("");
+ for (int id=0;id<ndigs;id++) {
+ ((AliDigitizer*)detArr[id])->Digitize("");
+ AliSysInfo::AddStamp(Form("Digit_%s_%d",detArr[id]->GetName(),eventsCreated), 0,2, eventsCreated);
+ }
digInp.FinishEvent();
};
digInp.FinishGlobal();
- //
+ //
return kTRUE;
}
}
//_____________________________________________________________________________
-Int_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName, Int_t N)
+Int_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName, Int_t N, Int_t nSkip)
{
//
// Steering routine to convert raw data in directory rawDirectory/ to fake SDigits.
AliPDG::AddParticlesToPdgDataBase();
- gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
+ TVirtualMC::GetMC()->SetMagField(TGeoGlobalMagField::Instance()->GetField());
gAlice->GetMCApp()->Init();
if (esdFile) {
esd = new AliESDEvent();
esdFile->GetObject("esdTree", treeESD);
- if (treeESD) esd->ReadFromTree(treeESD);
+ if (treeESD) {
+ esd->ReadFromTree(treeESD);
+ if (nSkip>0) {
+ AliInfo(Form("Asking to skip first %d ESDs events",nSkip));
+ } else {
+ nSkip=0;
+ }
+ }
}
}
//
// If ESD information available obtain reconstructed vertex and store in header.
if (treeESD) {
- AliInfo(Form("Selected event %d correspond to event %d ins raw and esd",nev,rawReader->GetEventIndex()));
- treeESD->GetEvent(rawReader->GetEventIndex());
+ AliInfo(Form("Selected event %d correspond to event %d in raw and to %d in esd",nev,rawReader->GetEventIndex(),nSkip+rawReader->GetEventIndex()));
+ treeESD->GetEvent(nSkip+rawReader->GetEventIndex());
const AliESDVertex* esdVertex = esd->GetPrimaryVertex();
Double_t position[3];
esdVertex->GetXYZ(position);
AliRunLoader::Instance()->CdGAFile();
gAlice->Write(0,TObject::kOverwrite);//write AliRun
AliRunLoader::Instance()->Write(0,TObject::kOverwrite);//write RunLoader itself
-
+ //
if(gAlice->GetMCApp()) gAlice->GetMCApp()->FinishRun();
AliRunLoader::Instance()->Synchronize();
}
else
return 0;
}
+
+//_____________________________________________________________________________
+void AliSimulation::StoreUsedCDBMaps() const
+{
+ // write in galice.root maps with used CDB paths
+ //
+ //
+ AliRunLoader* runLoader = LoadRun();
+ if (!runLoader) {
+ AliError("Failed to open gAlice.root in write mode");
+ return;
+ }
+ //
+ const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
+ const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
+ //
+ TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
+ cdbMapCopy->SetOwner(1);
+ // cdbMapCopy->SetName("cdbMap");
+ TIter iter(cdbMap->GetTable());
+ //
+ TPair* pair = 0;
+ while((pair = dynamic_cast<TPair*> (iter.Next()))){
+ TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
+ TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
+ if (keyStr && valStr)
+ cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
+ }
+ //
+ TList *cdbListCopy = new TList();
+ cdbListCopy->SetOwner(1);
+ // cdbListCopy->SetName("cdbList");
+ //
+ TIter iter2(cdbList);
+
+ AliCDBId* id=0;
+ while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
+ cdbListCopy->Add(new TObjString(id->ToString().Data()));
+ }
+ //
+ AliRunLoader::Instance()->CdGAFile();
+ gDirectory->WriteObject(cdbMapCopy,"cdbMap","kSingleKey");
+ gDirectory->WriteObject(cdbListCopy,"cdbList","kSingleKey");
+ delete runLoader;
+ //
+ AliInfo(Form("Stored used OCDB entries as TMap %s and TList %s in %s",
+ cdbMapCopy->GetName(),
+ cdbListCopy->GetName(),
+ fGAliceFileName.Data()));
+ //
+}