1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for running generation, simulation and digitization //
22 // Hits, sdigits and digits are created for all detectors by typing: //
24 // AliSimulation sim; //
27 // The Run method returns kTRUE in case of successful execution. //
28 // The number of events can be given as argument to the Run method or it //
31 // sim.SetNumberOfEvents(n); //
33 // The name of the configuration file can be passed as argument to the //
34 // AliSimulation constructor or can be specified by //
36 // sim.SetConfigFile("..."); //
38 // The generation of particles and the simulation of detector hits can be //
39 // switched on or off by //
41 // sim.SetRunGeneration(kTRUE); // generation of primary particles //
42 // sim.SetRunSimulation(kFALSE); // but no tracking //
44 // For which detectors sdigits and digits will be created, can be steered //
47 // sim.SetMakeSDigits("ALL"); // make sdigits for all detectors //
48 // sim.SetMakeDigits("ITS TPC"); // make digits only for ITS and TPC //
50 // The argument is a (case sensitive) string with the names of the //
51 // detectors separated by a space. An empty string ("") can be used to //
52 // disable the creation of sdigits or digits. The special string "ALL" //
53 // selects all available detectors. This is the default. //
55 // The creation of digits from hits instead of from sdigits can be selected //
58 // sim.SetMakeDigitsFromHits("TRD"); //
60 // The argument is again a string with the selected detectors. Be aware that //
61 // this feature is not available for all detectors and that merging is not //
62 // possible, when digits are created directly from hits. //
64 // Background events can be merged by calling //
66 // sim.MergeWith("background/galice.root", 2); //
68 // The first argument is the file name of the background galice file. The //
69 // second argument is the number of signal events per background event. //
70 // By default this number is calculated from the number of available //
71 // background events. MergeWith can be called several times to merge more //
72 // than two event streams. It is assumed that the sdigits were already //
73 // produced for the background events. //
75 // The output of raw data can be switched on by calling //
77 // sim.SetWriteRawData("MUON"); // write raw data for MUON //
79 // The default output format of the raw data are DDL files. They are //
80 // converted to a DATE file, if a file name is given as second argument. //
81 // For this conversion the program "dateStream" is required. If the file //
82 // name has the extension ".root", the DATE file is converted to a root //
83 // file. The program "alimdc" is used for this purpose. For the conversion //
84 // to DATE and root format the two conversion programs have to be installed. //
85 // Only the raw data in the final format is kept if the third argument is //
88 // The methods RunSimulation, RunSDigitization, RunDigitization, //
89 // RunHitsDigitization and WriteRawData can be used to run only parts of //
90 // the full simulation chain. The creation of raw data DDL files and their //
91 // conversion to the DATE or root format can be run directly by calling //
92 // the methods WriteRawFiles, ConvertRawFilesToDate and ConvertDateToRoot. //
94 // The default number of events per file, which is usually set in the //
95 // config file, can be changed for individual detectors and data types //
98 // sim.SetEventsPerFile("PHOS", "Reconstructed Points", 3); //
100 // The first argument is the detector, the second one the data type and the //
101 // last one the number of events per file. Valid data types are "Hits", //
102 // "Summable Digits", "Digits", "Reconstructed Points" and "Tracks". //
103 // The number of events per file has to be set before the simulation of //
104 // hits. Otherwise it has no effect. //
106 ///////////////////////////////////////////////////////////////////////////////
108 #include <TVirtualMCApplication.h>
109 #include <TGeoManager.h>
110 #include <TObjString.h>
114 #include "AliCodeTimer.h"
115 #include "AliCDBStorage.h"
116 #include "AliCDBEntry.h"
117 #include "AliCDBManager.h"
118 #include "AliGeomManager.h"
119 #include "AliAlignObj.h"
120 #include "AliCentralTrigger.h"
122 #include "AliDigitizer.h"
123 #include "AliGenerator.h"
125 #include "AliModule.h"
127 #include "AliRunDigitizer.h"
128 #include "AliRunLoader.h"
129 #include "AliSimulation.h"
130 #include "AliVertexGenFile.h"
131 #include "AliCentralTrigger.h"
132 #include "AliCTPRawData.h"
133 #include "AliRawReaderFile.h"
134 #include "AliRawReaderRoot.h"
135 #include "AliRawReaderDate.h"
137 #include "AliHeader.h"
138 #include "AliGenEventHeader.h"
140 #include "AliHLTSimulation.h"
141 #include "AliQADataMakerSteer.h"
143 ClassImp(AliSimulation)
145 AliSimulation *AliSimulation::fgInstance = 0;
146 const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
148 //_____________________________________________________________________________
149 AliSimulation::AliSimulation(const char* configFileName,
150 const char* name, const char* title) :
153 fRunGeneration(kTRUE),
154 fRunSimulation(kTRUE),
155 fLoadAlignFromCDB(kTRUE),
156 fLoadAlObjsListOfDets("ALL"),
160 fMakeDigitsFromHits(""),
162 fRawDataFileName(""),
163 fDeleteIntermediateFiles(kFALSE),
164 fStopOnError(kFALSE),
167 fConfigFileName(configFileName),
168 fGAliceFileName("galice.root"),
170 fBkgrdFileNames(NULL),
171 fAlignObjArray(NULL),
172 fUseBkgrdVertex(kTRUE),
173 fRegionOfInterest(kFALSE),
178 fInitCDBCalled(kFALSE),
179 fInitRunNumberCalled(kFALSE),
180 fSetRunNumberFromDataCalled(kFALSE),
181 fEmbeddingFlag(kFALSE),
185 // create simulation object with default parameters
187 SetGAliceFile("galice.root");
190 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++)
191 fQACycles[iDet] = 999999;
194 //_____________________________________________________________________________
195 AliSimulation::AliSimulation(const AliSimulation& sim) :
198 fRunGeneration(sim.fRunGeneration),
199 fRunSimulation(sim.fRunSimulation),
200 fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
201 fLoadAlObjsListOfDets(sim.fLoadAlObjsListOfDets),
202 fMakeSDigits(sim.fMakeSDigits),
203 fMakeDigits(sim.fMakeDigits),
204 fMakeTrigger(sim.fMakeTrigger),
205 fMakeDigitsFromHits(sim.fMakeDigitsFromHits),
206 fWriteRawData(sim.fWriteRawData),
207 fRawDataFileName(""),
208 fDeleteIntermediateFiles(kFALSE),
209 fStopOnError(sim.fStopOnError),
211 fNEvents(sim.fNEvents),
212 fConfigFileName(sim.fConfigFileName),
213 fGAliceFileName(sim.fGAliceFileName),
215 fBkgrdFileNames(NULL),
216 fAlignObjArray(NULL),
217 fUseBkgrdVertex(sim.fUseBkgrdVertex),
218 fRegionOfInterest(sim.fRegionOfInterest),
219 fCDBUri(sim.fCDBUri),
223 fInitCDBCalled(sim.fInitCDBCalled),
224 fInitRunNumberCalled(sim.fInitRunNumberCalled),
225 fSetRunNumberFromDataCalled(sim.fSetRunNumberFromDataCalled),
226 fEmbeddingFlag(sim.fEmbeddingFlag),
232 for (Int_t i = 0; i < sim.fEventsPerFile.GetEntriesFast(); i++) {
233 if (!sim.fEventsPerFile[i]) continue;
234 fEventsPerFile.Add(sim.fEventsPerFile[i]->Clone());
237 fBkgrdFileNames = new TObjArray;
238 for (Int_t i = 0; i < sim.fBkgrdFileNames->GetEntriesFast(); i++) {
239 if (!sim.fBkgrdFileNames->At(i)) continue;
240 fBkgrdFileNames->Add(sim.fBkgrdFileNames->At(i)->Clone());
243 for (Int_t i = 0; i < sim.fSpecCDBUri.GetEntriesFast(); i++) {
244 if (sim.fSpecCDBUri[i]) fSpecCDBUri.Add(sim.fSpecCDBUri[i]->Clone());
249 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++)
250 fQACycles[iDet] = sim.fQACycles[iDet];
253 //_____________________________________________________________________________
254 AliSimulation& AliSimulation::operator = (const AliSimulation& sim)
256 // assignment operator
258 this->~AliSimulation();
259 new(this) AliSimulation(sim);
263 //_____________________________________________________________________________
264 AliSimulation::~AliSimulation()
268 fEventsPerFile.Delete();
269 // if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
270 // delete fAlignObjArray; fAlignObjArray=0;
272 if (fBkgrdFileNames) {
273 fBkgrdFileNames->Delete();
274 delete fBkgrdFileNames;
277 fSpecCDBUri.Delete();
278 if (fgInstance==this) fgInstance = 0;
280 AliCodeTimer::Instance()->Print();
284 //_____________________________________________________________________________
285 void AliSimulation::SetNumberOfEvents(Int_t nEvents)
287 // set the number of events for one run
292 //_____________________________________________________________________________
293 void AliSimulation::InitCDB()
295 // activate a default CDB storage
296 // First check if we have any CDB storage set, because it is used
297 // to retrieve the calibration and alignment constants
299 if (fInitCDBCalled) return;
300 fInitCDBCalled = kTRUE;
302 AliCDBManager* man = AliCDBManager::Instance();
303 if (man->IsDefaultStorageSet())
305 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
306 AliWarning("Default CDB storage has been already set !");
307 AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fCDBUri.Data()));
308 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
309 fCDBUri = man->GetDefaultStorage()->GetURI();
312 if (fCDBUri.Length() > 0)
314 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
315 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
316 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
318 fCDBUri="local://$ALICE_ROOT";
319 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
320 AliWarning("Default CDB storage not yet set !!!!");
321 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
322 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
325 man->SetDefaultStorage(fCDBUri);
328 // Now activate the detector specific CDB storage locations
329 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
330 TObject* obj = fSpecCDBUri[i];
332 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
333 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
334 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
335 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
340 //_____________________________________________________________________________
341 void AliSimulation::InitRunNumber(){
342 // check run number. If not set, set it to 0 !!!!
344 if (fInitRunNumberCalled) return;
345 fInitRunNumberCalled = kTRUE;
347 AliCDBManager* man = AliCDBManager::Instance();
348 if (man->GetRun() >= 0)
350 AliFatal(Form("Run number cannot be set in AliCDBManager before start of simulation: "
351 "Use external variable DC_RUN or AliSimulation::SetRun()!"));
355 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
356 AliDebug(2, Form("Setting CDB run number to: %d",fRun));
357 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
360 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
361 AliWarning("Run number not yet set !!!!");
362 AliWarning(Form("Setting it now to: %d", fRun));
363 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
372 //_____________________________________________________________________________
373 void AliSimulation::SetCDBLock() {
374 // Set CDB lock: from now on it is forbidden to reset the run number
375 // or the default storage or to activate any further storage!
377 AliCDBManager::Instance()->SetLock(1);
380 //_____________________________________________________________________________
381 void AliSimulation::SetDefaultStorage(const char* uri) {
382 // Store the desired default CDB storage location
383 // Activate it later within the Run() method
389 //_____________________________________________________________________________
390 void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
391 // Store a detector-specific CDB storage location
392 // Activate it later within the Run() method
394 AliCDBPath aPath(calibType);
395 if(!aPath.IsValid()){
396 AliError(Form("Not a valid path: %s", calibType));
400 TObject* obj = fSpecCDBUri.FindObject(calibType);
401 if (obj) fSpecCDBUri.Remove(obj);
402 fSpecCDBUri.Add(new TNamed(calibType, uri));
406 //_____________________________________________________________________________
407 void AliSimulation::SetRunNumber(Int_t run)
410 // Activate it later within the Run() method
415 //_____________________________________________________________________________
416 void AliSimulation::SetSeed(Int_t seed)
419 // Activate it later within the Run() method
424 //_____________________________________________________________________________
425 Bool_t AliSimulation::SetRunNumberFromData()
427 // Set the CDB manager run number
428 // The run number is retrieved from gAlice
430 if (fSetRunNumberFromDataCalled) return kTRUE;
431 fSetRunNumberFromDataCalled = kTRUE;
433 AliCDBManager* man = AliCDBManager::Instance();
434 Int_t runData = -1, runCDB = -1;
436 AliRunLoader* runLoader = LoadRun("READ");
437 if (!runLoader) return kFALSE;
439 runData = runLoader->GetAliRun()->GetHeader()->GetRun();
443 runCDB = man->GetRun();
445 if (runCDB != runData) {
446 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
447 AliWarning(Form("A run number was previously set in AliCDBManager: %d !", runCDB));
448 AliWarning(Form("It will be replaced with the run number got from run header: %d !", runData));
449 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
454 man->SetRun(runData);
457 if(man->GetRun() < 0) {
458 AliError("Run number not properly initalized!");
467 //_____________________________________________________________________________
468 void AliSimulation::SetConfigFile(const char* fileName)
470 // set the name of the config file
472 fConfigFileName = fileName;
475 //_____________________________________________________________________________
476 void AliSimulation::SetGAliceFile(const char* fileName)
478 // set the name of the galice file
479 // the path is converted to an absolute one if it is relative
481 fGAliceFileName = fileName;
482 if (!gSystem->IsAbsoluteFileName(fGAliceFileName)) {
483 char* absFileName = gSystem->ConcatFileName(gSystem->WorkingDirectory(),
485 fGAliceFileName = absFileName;
486 delete[] absFileName;
489 AliDebug(2, Form("galice file name set to %s", fileName));
492 //_____________________________________________________________________________
493 void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
496 // set the number of events per file for the given detector and data type
497 // ("Hits", "Summable Digits", "Digits", "Reconstructed Points" or "Tracks")
499 TNamed* obj = new TNamed(detector, type);
500 obj->SetUniqueID(nEvents);
501 fEventsPerFile.Add(obj);
504 //_____________________________________________________________________________
505 Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
507 // Read the alignment objects from CDB.
508 // Each detector is supposed to have the
509 // alignment objects in DET/Align/Data CDB path.
510 // All the detector objects are then collected,
511 // sorted by geometry level (starting from ALIC) and
512 // then applied to the TGeo geometry.
513 // Finally an overlaps check is performed.
515 if (!AliGeomManager::GetGeometry() || !AliGeomManager::GetGeometry()->IsClosed()) {
516 AliError("Can't apply the misalignment! Geometry is not loaded or it is still opened!");
520 // initialize CDB storage, run number, set CDB lock
522 // if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
525 Bool_t delRunLoader = kFALSE;
527 runLoader = LoadRun("READ");
528 if (!runLoader) return kFALSE;
529 delRunLoader = kTRUE;
532 // Export ideal geometry
533 if(!gAlice->IsRootGeometry()) AliGeomManager::GetGeometry()->Export("geometry.root");
535 // Load alignment data from CDB and apply to geometry through AliGeomManager
536 if(fLoadAlignFromCDB){
538 TString detStr = fLoadAlObjsListOfDets;
539 TString loadAlObjsListOfDets = "";
541 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
542 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
543 AliModule* det = (AliModule*) detArray->At(iDet);
544 if (!det || !det->IsActive()) continue;
545 if (IsSelected(det->GetName(), detStr)) {
546 //add det to list of dets to be aligned from CDB
547 loadAlObjsListOfDets += det->GetName();
548 loadAlObjsListOfDets += " ";
550 } // end loop over detectors
551 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
552 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
554 // Check if the array with alignment objects was
555 // provided by the user. If yes, apply the objects
556 // to the present TGeo geometry
557 if (fAlignObjArray) {
558 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
559 AliError("The misalignment of one or more volumes failed!"
560 "Compare the list of simulated detectors and the list of detector alignment data!");
561 if (delRunLoader) delete runLoader;
567 // Update the internal geometry of modules (ITS needs it)
568 TString detStr = fLoadAlObjsListOfDets;
569 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
570 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
572 AliModule* det = (AliModule*) detArray->At(iDet);
573 if (!det || !det->IsActive()) continue;
574 if (IsSelected(det->GetName(), detStr)) {
575 det->UpdateInternalGeometry();
577 } // end loop over detectors
580 if (delRunLoader) delete runLoader;
585 //_____________________________________________________________________________
586 void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
588 // add a file with background events for merging
590 TObjString* fileNameStr = new TObjString(fileName);
591 fileNameStr->SetUniqueID(nSignalPerBkgrd);
592 if (!fBkgrdFileNames) fBkgrdFileNames = new TObjArray;
593 fBkgrdFileNames->Add(fileNameStr);
596 void AliSimulation::EmbedInto(const char* fileName, Int_t nSignalPerBkgrd)
598 // add a file with background events for embeddin
599 MergeWith(fileName, nSignalPerBkgrd);
600 fEmbeddingFlag = kTRUE;
603 //_____________________________________________________________________________
604 Bool_t AliSimulation::Run(Int_t nEvents)
606 // run the generation, simulation and digitization
611 // Load run number and seed from environmental vars
612 ProcessEnvironmentVars();
614 gRandom->SetSeed(fSeed);
616 if (nEvents > 0) fNEvents = nEvents;
618 // generation and simulation -> hits
619 if (fRunGeneration) {
620 if (!RunSimulation()) if (fStopOnError) return kFALSE;
623 // initialize CDB storage from external environment
624 // (either CDB manager or AliSimulation setters),
625 // if not already done in RunSimulation()
628 // Set run number in CDBManager from data
629 // From this point on the run number must be always loaded from data!
630 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
632 // Set CDB lock: from now on it is forbidden to reset the run number
633 // or the default storage or to activate any further storage!
636 // If RunSimulation was not called, load the geometry and misalign it
637 if (!AliGeomManager::GetGeometry()) {
638 // Initialize the geometry manager
639 AliGeomManager::LoadGeometry("geometry.root");
640 if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
642 if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
645 // hits -> summable digits
646 if (!fMakeSDigits.IsNull()) {
647 if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
653 // summable digits -> digits
654 if (!fMakeDigits.IsNull()) {
655 if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
656 if (fStopOnError) return kFALSE;
663 if (!fMakeDigitsFromHits.IsNull()) {
664 if (fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
665 AliWarning(Form("Merging and direct creation of digits from hits "
666 "was selected for some detectors. "
667 "No merging will be done for the following detectors: %s",
668 fMakeDigitsFromHits.Data()));
670 if (!RunHitsDigitization(fMakeDigitsFromHits)) {
671 if (fStopOnError) return kFALSE;
678 if (!RunTrigger(fMakeTrigger)) {
679 if (fStopOnError) return kFALSE;
684 // digits -> raw data
685 if (!fWriteRawData.IsNull()) {
686 if (!WriteRawData(fWriteRawData, fRawDataFileName,
687 fDeleteIntermediateFiles)) {
688 if (fStopOnError) return kFALSE;
694 // run HLT simulation
695 if (!fRunHLT.IsNull()) {
697 if (fStopOnError) return kFALSE;
703 // Bool_t rv = RunQA() ;
709 // Cleanup of CDB manager: cache and active storages!
710 AliCDBManager::Instance()->ClearCache();
715 //_____________________________________________________________________________
716 Bool_t AliSimulation::RunTrigger(const char* config)
722 // initialize CDB storage from external environment
723 // (either CDB manager or AliSimulation setters),
724 // if not already done in RunSimulation()
727 // Set run number in CDBManager from data
728 // From this point on the run number must be always loaded from data!
729 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
731 // Set CDB lock: from now on it is forbidden to reset the run number
732 // or the default storage or to activate any further storage!
735 AliRunLoader* runLoader = LoadRun("READ");
736 if (!runLoader) return kFALSE;
737 TString trconfiguration = config;
739 if (trconfiguration.IsNull()) {
740 if (gAlice->GetTriggerDescriptor() != "") {
741 trconfiguration = gAlice->GetTriggerDescriptor();
744 AliWarning("No trigger descriptor is specified. Loading the one that is the CDB.");
747 runLoader->MakeTree( "GG" );
748 AliCentralTrigger* aCTP = runLoader->GetTrigger();
749 // Load Configuration
750 if (!aCTP->LoadConfiguration( trconfiguration ))
754 if( !aCTP->RunTrigger( runLoader ) ) {
766 //_____________________________________________________________________________
767 Bool_t AliSimulation::WriteTriggerRawData()
769 // Writes the CTP (trigger) DDL raw data
770 // Details of the format are given in the
771 // trigger TDR - pages 134 and 135.
772 AliCTPRawData writer;
778 //_____________________________________________________________________________
779 Bool_t AliSimulation::RunSimulation(Int_t nEvents)
781 // run the generation and simulation
785 // initialize CDB storage and run number from external environment
786 // (either CDB manager or AliSimulation setters)
792 AliError("no gAlice object. Restart aliroot and try again.");
795 if (gAlice->Modules()->GetEntries() > 0) {
796 AliError("gAlice was already run. Restart aliroot and try again.");
800 AliInfo(Form("initializing gAlice with config file %s",
801 fConfigFileName.Data()));
802 StdoutToAliInfo(StderrToAliError(
803 gAlice->Init(fConfigFileName.Data());
806 // Get the trigger descriptor string
807 // Either from AliSimulation or from
809 if (fMakeTrigger.IsNull()) {
810 if (gAlice->GetTriggerDescriptor() != "")
811 fMakeTrigger = gAlice->GetTriggerDescriptor();
814 gAlice->SetTriggerDescriptor(fMakeTrigger.Data());
816 // Set run number in CDBManager
817 AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
819 AliRunLoader* runLoader = gAlice->GetRunLoader();
821 AliError(Form("gAlice has no run loader object. "
822 "Check your config file: %s", fConfigFileName.Data()));
825 SetGAliceFile(runLoader->GetFileName());
828 #if ROOT_VERSION_CODE < 331527
829 AliGeomManager::SetGeometry(gGeoManager);
830 MisalignGeometry(runLoader);
833 // AliRunLoader* runLoader = gAlice->GetRunLoader();
835 // AliError(Form("gAlice has no run loader object. "
836 // "Check your config file: %s", fConfigFileName.Data()));
839 // SetGAliceFile(runLoader->GetFileName());
841 if (!gAlice->Generator()) {
842 AliError(Form("gAlice has no generator object. "
843 "Check your config file: %s", fConfigFileName.Data()));
846 if (nEvents <= 0) nEvents = fNEvents;
848 // get vertex from background file in case of merging
849 if (fUseBkgrdVertex &&
850 fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
851 Int_t signalPerBkgrd = GetNSignalPerBkgrd(nEvents);
852 const char* fileName = ((TObjString*)
853 (fBkgrdFileNames->At(0)))->GetName();
854 AliInfo(Form("The vertex will be taken from the background "
855 "file %s with nSignalPerBackground = %d",
856 fileName, signalPerBkgrd));
857 AliVertexGenFile* vtxGen = new AliVertexGenFile(fileName, signalPerBkgrd);
858 gAlice->Generator()->SetVertexGenerator(vtxGen);
861 if (!fRunSimulation) {
862 gAlice->Generator()->SetTrackingFlag(0);
865 // set the number of events per file for given detectors and data types
866 for (Int_t i = 0; i < fEventsPerFile.GetEntriesFast(); i++) {
867 if (!fEventsPerFile[i]) continue;
868 const char* detName = fEventsPerFile[i]->GetName();
869 const char* typeName = fEventsPerFile[i]->GetTitle();
870 TString loaderName(detName);
871 loaderName += "Loader";
872 AliLoader* loader = runLoader->GetLoader(loaderName);
874 AliError(Form("RunSimulation", "no loader for %s found\n"
875 "Number of events per file not set for %s %s",
876 detName, typeName, detName));
879 AliDataLoader* dataLoader =
880 loader->GetDataLoader(typeName);
882 AliError(Form("no data loader for %s found\n"
883 "Number of events per file not set for %s %s",
884 typeName, detName, typeName));
887 dataLoader->SetNumberOfEventsPerFile(fEventsPerFile[i]->GetUniqueID());
888 AliDebug(1, Form("number of events per file set to %d for %s %s",
889 fEventsPerFile[i]->GetUniqueID(), detName, typeName));
892 AliInfo("running gAlice");
893 StdoutToAliInfo(StderrToAliError(
894 gAlice->Run(nEvents);
902 //_____________________________________________________________________________
903 Bool_t AliSimulation::RunSDigitization(const char* detectors)
905 // run the digitization and produce summable digits
909 // initialize CDB storage, run number, set CDB lock
911 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
914 AliRunLoader* runLoader = LoadRun();
915 if (!runLoader) return kFALSE;
917 TString detStr = detectors;
918 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
919 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
920 AliModule* det = (AliModule*) detArray->At(iDet);
921 if (!det || !det->IsActive()) continue;
922 if (IsSelected(det->GetName(), detStr)) {
923 AliInfo(Form("creating summable digits for %s", det->GetName()));
924 AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
930 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
931 AliError(Form("the following detectors were not found: %s",
933 if (fStopOnError) return kFALSE;
942 //_____________________________________________________________________________
943 Bool_t AliSimulation::RunDigitization(const char* detectors,
944 const char* excludeDetectors)
946 // run the digitization and produce digits from sdigits
950 // initialize CDB storage, run number, set CDB lock
952 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
955 while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
956 if (gAlice) delete gAlice;
960 if (fBkgrdFileNames) nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
961 Int_t signalPerBkgrd = GetNSignalPerBkgrd();
962 AliRunDigitizer* manager = new AliRunDigitizer(nStreams, signalPerBkgrd);
963 // manager->SetEmbeddingFlag(fEmbeddingFlag);
964 manager->SetInputStream(0, fGAliceFileName.Data());
965 for (Int_t iStream = 1; iStream < nStreams; iStream++) {
966 const char* fileName = ((TObjString*)
967 (fBkgrdFileNames->At(iStream-1)))->GetName();
968 manager->SetInputStream(iStream, fileName);
971 TString detStr = detectors;
972 TString detExcl = excludeDetectors;
973 manager->GetInputStream(0)->ImportgAlice();
974 AliRunLoader* runLoader =
975 AliRunLoader::GetRunLoader(manager->GetInputStream(0)->GetFolderName());
976 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
977 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
978 AliModule* det = (AliModule*) detArray->At(iDet);
979 if (!det || !det->IsActive()) continue;
980 if (IsSelected(det->GetName(), detStr) &&
981 !IsSelected(det->GetName(), detExcl)) {
982 AliDigitizer* digitizer = det->CreateDigitizer(manager);
985 AliError(Form("no digitizer for %s", det->GetName()));
986 if (fStopOnError) return kFALSE;
988 digitizer->SetRegionOfInterest(fRegionOfInterest);
993 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
994 AliError(Form("the following detectors were not found: %s",
996 if (fStopOnError) return kFALSE;
999 if (!manager->GetListOfTasks()->IsEmpty()) {
1000 AliInfo("executing digitization");
1009 //_____________________________________________________________________________
1010 Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
1012 // run the digitization and produce digits from hits
1014 AliCodeTimerAuto("")
1016 // initialize CDB storage, run number, set CDB lock
1018 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1021 AliRunLoader* runLoader = LoadRun("READ");
1022 if (!runLoader) return kFALSE;
1024 TString detStr = detectors;
1025 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1026 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1027 AliModule* det = (AliModule*) detArray->At(iDet);
1028 if (!det || !det->IsActive()) continue;
1029 if (IsSelected(det->GetName(), detStr)) {
1030 AliInfo(Form("creating digits from hits for %s", det->GetName()));
1035 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1036 AliError(Form("the following detectors were not found: %s",
1038 if (fStopOnError) return kFALSE;
1042 //PH Temporary fix to avoid interference with the PHOS loder/getter
1043 //PH The problem has to be solved in more general way 09/06/05
1048 //_____________________________________________________________________________
1049 Bool_t AliSimulation::WriteRawData(const char* detectors,
1050 const char* fileName,
1051 Bool_t deleteIntermediateFiles)
1053 // convert the digits to raw data
1054 // First DDL raw data files for the given detectors are created.
1055 // If a file name is given, the DDL files are then converted to a DATE file.
1056 // If deleteIntermediateFiles is true, the DDL raw files are deleted
1058 // If the file name has the extension ".root", the DATE file is converted
1060 // If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
1062 AliCodeTimerAuto("")
1064 if (!WriteRawFiles(detectors)) {
1065 if (fStopOnError) return kFALSE;
1068 TString dateFileName(fileName);
1069 if (!dateFileName.IsNull()) {
1070 Bool_t rootOutput = dateFileName.EndsWith(".root");
1071 if (rootOutput) dateFileName += ".date";
1072 if (!ConvertRawFilesToDate(dateFileName)) {
1073 if (fStopOnError) return kFALSE;
1075 if (deleteIntermediateFiles) {
1076 AliRunLoader* runLoader = LoadRun("READ");
1077 if (runLoader) for (Int_t iEvent = 0;
1078 iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1080 sprintf(command, "rm -r raw%d", iEvent);
1081 gSystem->Exec(command);
1086 if (!ConvertDateToRoot(dateFileName, fileName)) {
1087 if (fStopOnError) return kFALSE;
1089 if (deleteIntermediateFiles) {
1090 gSystem->Unlink(dateFileName);
1098 //_____________________________________________________________________________
1099 Bool_t AliSimulation::WriteRawFiles(const char* detectors)
1101 // convert the digits to raw data DDL files
1103 AliCodeTimerAuto("")
1105 AliRunLoader* runLoader = LoadRun("READ");
1106 if (!runLoader) return kFALSE;
1108 // write raw data to DDL files
1109 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1110 AliInfo(Form("processing event %d", iEvent));
1111 runLoader->GetEvent(iEvent);
1112 TString baseDir = gSystem->WorkingDirectory();
1114 sprintf(dirName, "raw%d", iEvent);
1115 gSystem->MakeDirectory(dirName);
1116 if (!gSystem->ChangeDirectory(dirName)) {
1117 AliError(Form("couldn't change to directory %s", dirName));
1118 if (fStopOnError) return kFALSE; else continue;
1121 TString detStr = detectors;
1122 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1123 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1124 AliModule* det = (AliModule*) detArray->At(iDet);
1125 if (!det || !det->IsActive()) continue;
1126 if (IsSelected(det->GetName(), detStr)) {
1127 AliInfo(Form("creating raw data from digits for %s", det->GetName()));
1132 if (!WriteTriggerRawData())
1133 if (fStopOnError) return kFALSE;
1135 gSystem->ChangeDirectory(baseDir);
1136 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1137 AliError(Form("the following detectors were not found: %s",
1139 if (fStopOnError) return kFALSE;
1148 //_____________________________________________________________________________
1149 Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName)
1151 // convert raw data DDL files to a DATE file with the program "dateStream"
1153 AliCodeTimerAuto("")
1155 char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
1157 AliError("the program dateStream was not found");
1158 if (fStopOnError) return kFALSE;
1163 AliRunLoader* runLoader = LoadRun("READ");
1164 if (!runLoader) return kFALSE;
1166 AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
1168 // Note the option -s. It is used in order to avoid
1169 // the generation of SOR/EOR events.
1170 sprintf(command, "dateStream -s -D -o %s -# %d -C -run %d",
1171 dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
1172 FILE* pipe = gSystem->OpenPipe(command, "w");
1174 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1175 fprintf(pipe, "GDC\n");
1179 // loop over detectors and DDLs
1180 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1181 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1183 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1184 Int_t ldcID = Int_t(ldc + 0.0001);
1185 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1187 char rawFileName[256];
1188 sprintf(rawFileName, "raw%d/%s",
1189 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1191 // check existence and size of raw data file
1192 FILE* file = fopen(rawFileName, "rb");
1193 if (!file) continue;
1194 fseek(file, 0, SEEK_END);
1195 unsigned long size = ftell(file);
1197 if (!size) continue;
1199 if (ldcID != prevLDC) {
1200 fprintf(pipe, " LDC Id %d\n", ldcID);
1203 fprintf(pipe, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1208 Int_t result = gSystem->ClosePipe(pipe);
1211 return (result == 0);
1214 //_____________________________________________________________________________
1215 Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
1216 const char* rootFileName)
1218 // convert a DATE file to a root file with the program "alimdc"
1221 const Int_t kDBSize = 2000000000;
1222 const Int_t kTagDBSize = 1000000000;
1223 const Bool_t kFilter = kFALSE;
1224 const Int_t kCompression = 1;
1226 char* path = gSystem->Which(gSystem->Getenv("PATH"), "alimdc");
1228 AliError("the program alimdc was not found");
1229 if (fStopOnError) return kFALSE;
1234 AliInfo(Form("converting DATE file %s to root file %s",
1235 dateFileName, rootFileName));
1237 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
1238 const char* tagDBFS = "/tmp/mdc1/tags";
1240 // User defined file system locations
1241 if (gSystem->Getenv("ALIMDC_RAWDB1"))
1242 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
1243 if (gSystem->Getenv("ALIMDC_RAWDB2"))
1244 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
1245 if (gSystem->Getenv("ALIMDC_TAGDB"))
1246 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
1248 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1249 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1250 gSystem->Exec(Form("rm -rf %s",tagDBFS));
1252 gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
1253 gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
1254 gSystem->Exec(Form("mkdir %s",tagDBFS));
1256 Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s",
1257 kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
1258 gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0], rootFileName));
1260 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1261 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1262 gSystem->Exec(Form("rm -rf %s",tagDBFS));
1264 return (result == 0);
1268 //_____________________________________________________________________________
1269 AliRunLoader* AliSimulation::LoadRun(const char* mode) const
1271 // delete existing run loaders, open a new one and load gAlice
1273 while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
1274 AliRunLoader* runLoader =
1275 AliRunLoader::Open(fGAliceFileName.Data(),
1276 AliConfig::GetDefaultEventFolderName(), mode);
1278 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1281 runLoader->LoadgAlice();
1282 runLoader->LoadHeader();
1283 gAlice = runLoader->GetAliRun();
1285 AliError(Form("no gAlice object found in file %s",
1286 fGAliceFileName.Data()));
1292 //_____________________________________________________________________________
1293 Int_t AliSimulation::GetNSignalPerBkgrd(Int_t nEvents) const
1295 // get or calculate the number of signal events per background event
1297 if (!fBkgrdFileNames) return 1;
1298 Int_t nBkgrdFiles = fBkgrdFileNames->GetEntriesFast();
1299 if (nBkgrdFiles == 0) return 1;
1301 // get the number of signal events
1303 AliRunLoader* runLoader =
1304 AliRunLoader::Open(fGAliceFileName.Data(), "SIGNAL");
1305 if (!runLoader) return 1;
1307 nEvents = runLoader->GetNumberOfEvents();
1312 for (Int_t iBkgrdFile = 0; iBkgrdFile < nBkgrdFiles; iBkgrdFile++) {
1313 // get the number of background events
1314 const char* fileName = ((TObjString*)
1315 (fBkgrdFileNames->At(iBkgrdFile)))->GetName();
1316 AliRunLoader* runLoader =
1317 AliRunLoader::Open(fileName, "BKGRD");
1318 if (!runLoader) continue;
1319 Int_t nBkgrdEvents = runLoader->GetNumberOfEvents();
1322 // get or calculate the number of signal per background events
1323 Int_t nSignalPerBkgrd = fBkgrdFileNames->At(iBkgrdFile)->GetUniqueID();
1324 if (nSignalPerBkgrd <= 0) {
1325 nSignalPerBkgrd = (nEvents-1) / nBkgrdEvents + 1;
1326 } else if (result && (result != nSignalPerBkgrd)) {
1327 AliInfo(Form("the number of signal events per background event "
1328 "will be changed from %d to %d for stream %d",
1329 nSignalPerBkgrd, result, iBkgrdFile+1));
1330 nSignalPerBkgrd = result;
1333 if (!result) result = nSignalPerBkgrd;
1334 if (nSignalPerBkgrd * nBkgrdEvents < nEvents) {
1335 AliWarning(Form("not enough background events (%d) for %d signal events "
1336 "using %d signal per background events for stream %d",
1337 nBkgrdEvents, nEvents, nSignalPerBkgrd, iBkgrdFile+1));
1344 //_____________________________________________________________________________
1345 Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
1347 // check whether detName is contained in detectors
1348 // if yes, it is removed from detectors
1350 // check if all detectors are selected
1351 if ((detectors.CompareTo("ALL") == 0) ||
1352 detectors.BeginsWith("ALL ") ||
1353 detectors.EndsWith(" ALL") ||
1354 detectors.Contains(" ALL ")) {
1359 // search for the given detector
1360 Bool_t result = kFALSE;
1361 if ((detectors.CompareTo(detName) == 0) ||
1362 detectors.BeginsWith(detName+" ") ||
1363 detectors.EndsWith(" "+detName) ||
1364 detectors.Contains(" "+detName+" ")) {
1365 detectors.ReplaceAll(detName, "");
1369 // clean up the detectors string
1370 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1371 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1372 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1377 //_____________________________________________________________________________
1378 Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName)
1381 // Steering routine to convert raw data in directory rawDirectory/ to fake SDigits.
1382 // These can be used for embedding of MC tracks into RAW data using the standard
1383 // merging procedure.
1385 // If an ESD file is given the reconstructed vertex is taken from it and stored in the event header.
1388 AliError("no gAlice object. Restart aliroot and try again.");
1391 if (gAlice->Modules()->GetEntries() > 0) {
1392 AliError("gAlice was already run. Restart aliroot and try again.");
1396 AliInfo(Form("initializing gAlice with config file %s",fConfigFileName.Data()));
1397 StdoutToAliInfo(StderrToAliError(gAlice->Init(fConfigFileName.Data());););
1401 //AliCDBManager* man = AliCDBManager::Instance();
1402 //man->SetRun(0); // Should this come from rawdata header ?
1406 // Get the runloader
1407 AliRunLoader* runLoader = gAlice->GetRunLoader();
1409 // Open esd file if available
1410 TFile* esdFile = TFile::Open(esdFileName);
1411 Bool_t esdOK = (esdFile != 0);
1412 AliESD* esd = new AliESD;
1415 treeESD = (TTree*) esdFile->Get("esdTree");
1417 AliWarning("No ESD tree found");
1420 treeESD->SetBranchAddress("ESD", &esd);
1424 // Create the RawReader
1425 TString fileName(rawDirectory);
1426 AliRawReader* rawReader = 0x0;
1427 if (fileName.EndsWith("/")) {
1428 rawReader = new AliRawReaderFile(fileName);
1429 } else if (fileName.EndsWith(".root")) {
1430 rawReader = new AliRawReaderRoot(fileName);
1431 } else if (!fileName.IsNull()) {
1432 rawReader = new AliRawReaderDate(fileName);
1433 rawReader->SelectEvents(7);
1435 // if (!fEquipIdMap.IsNull() && fRawReader)
1436 // fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1438 // Get list of detectors
1439 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1442 AliHeader* header = runLoader->GetHeader();
1444 TString detStr = fMakeSDigits;
1448 if (!(rawReader->NextEvent())) break;
1451 for (iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1452 AliModule* det = (AliModule*) detArray->At(iDet);
1453 if (!det || !det->IsActive()) continue;
1454 if (IsSelected(det->GetName(), detStr)) {
1455 AliInfo(Form("Calling Raw2SDigits for %s\n", det->GetName()));
1456 det->Raw2SDigits(rawReader);
1463 // If ESD information available obtain reconstructed vertex and store in header.
1465 treeESD->GetEvent(nev);
1466 const AliESDVertex* esdVertex = esd->GetPrimaryVertex();
1467 Double_t position[3];
1468 esdVertex->GetXYZ(position);
1469 AliGenEventHeader* mcHeader = new AliGenEventHeader("ESD");
1472 for (Int_t i = 0; i < 3; i++) mcV[i] = position[i];
1473 mcHeader->SetPrimaryVertex(mcV);
1474 header->Reset(0,nev);
1475 header->SetGenEventHeader(mcHeader);
1476 printf("***** Saved vertex %f %f %f \n", position[0], position[1], position[2]);
1481 runLoader->TreeE()->Fill();
1482 runLoader->SetNextEvent();
1488 runLoader->CdGAFile();
1489 runLoader->WriteHeader("OVERWRITE");
1490 runLoader->WriteRunLoader();
1495 //_____________________________________________________________________________
1496 Int_t AliSimulation::GetDetIndex(const char* detector)
1498 // return the detector index corresponding to detector
1500 for (index = 0; index < fgkNDetectors ; index++) {
1501 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
1507 //_____________________________________________________________________________
1508 Bool_t AliSimulation::RunHLT()
1510 // Run the HLT simulation
1511 // HLT simulation is implemented in HLT/sim/AliHLTSimulation
1512 // Disabled if fRunHLT is empty, default vaule is "default".
1513 // AliSimulation::SetRunHLT can be used to set the options for HLT simulation
1514 // The default simulation depends on the HLT component libraries and their
1515 // corresponding agents which define components and chains to run. See
1516 // http://web.ift.uib.no/~kjeks/doc/alice-hlt/
1517 // http://web.ift.uib.no/~kjeks/doc/alice-hlt/classAliHLTModuleAgent.html
1519 // The libraries to be loaded can be specified as an option.
1521 // AliSimulation sim;
1522 // sim.SetRunHLT("libAliHLTSample.so");
1524 // will only load <tt>libAliHLTSample.so</tt>
1526 // Other available options:
1527 // \li loglevel=<i>level</i> <br>
1528 // logging level for this processing
1530 // disable redirection of log messages to AliLog class
1531 // \li config=<i>macro</i>
1532 // configuration macro
1533 // \li localrec=<i>configuration</i>
1534 // comma separated list of configurations to be run during simulation
1537 AliRunLoader* pRunLoader = LoadRun("READ");
1538 if (!pRunLoader) return kFALSE;
1540 // initialize CDB storage, run number, set CDB lock
1542 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1545 // load the library dynamically
1546 gSystem->Load(ALIHLTSIMULATION_LIBRARY);
1548 // check for the library version
1549 AliHLTSimulationGetLibraryVersion_t fctVersion=(AliHLTSimulationGetLibraryVersion_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_GET_LIBRARY_VERSION));
1551 AliError(Form("can not load library %s", ALIHLTSIMULATION_LIBRARY));
1554 if (fctVersion()!= ALIHLTSIMULATION_LIBRARY_VERSION) {
1555 AliError(Form("%s version does not match: compiled for version %d, loaded %d", ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_LIBRARY_VERSION, fctVersion()));
1559 // print compile info
1560 typedef void (*CompileInfo)( char*& date, char*& time);
1561 CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
1565 (*fctInfo)(date, time);
1566 if (!date) date="unknown";
1567 if (!time) time="unknown";
1568 AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
1570 AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
1573 // create instance of the HLT simulation
1574 AliHLTSimulationCreateInstance_t fctCreate=(AliHLTSimulationCreateInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_CREATE_INSTANCE));
1575 AliHLTSimulation* pHLT=NULL;
1576 if (fctCreate==NULL || (pHLT=(fctCreate()))==NULL) {
1577 AliError(Form("can not create instance of HLT simulation (creator %p)", fctCreate));
1581 // init the HLT simulation
1582 if (fRunHLT.CompareTo("default")==0) fRunHLT="";
1583 AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
1584 if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, fRunHLT.Data())))<0) {
1585 AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
1587 // run the HLT simulation
1588 AliHLTSimulationRun_t fctRun=(AliHLTSimulationRun_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_RUN));
1589 if (fctRun==NULL || (iResult=(fctRun(pHLT, pRunLoader)))<0) {
1590 AliError(Form("can not run HLT simulation: error %d (run %p)", iResult, fctRun));
1594 // delete the instance
1595 AliHLTSimulationDeleteInstance_t fctDelete=(AliHLTSimulationDeleteInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_DELETE_INSTANCE));
1596 if (fctDelete==NULL || fctDelete(pHLT)<0) {
1597 AliError(Form("can not delete instance of HLT simulation (creator %p)", fctDelete));
1601 return iResult>=0?kTRUE:kFALSE;
1604 //_____________________________________________________________________________
1605 Bool_t AliSimulation::RunQA()
1607 // run the QA on summable hits, digits or digits
1609 AliQADataMakerSteer qas ;
1610 qas.SetRunLoader(gAlice->GetRunLoader()) ;
1612 Bool_t rv = qas.Run("ALL", AliQA::kHITS) ;
1614 rv *= qas.Run(fMakeSDigits.Data(), AliQA::kSDIGITS) ;
1616 rv *= qas.Run(fMakeDigits.Data(), AliQA::kDIGITS) ;
1618 rv *= qas.Run(fMakeDigitsFromHits.Data(), AliQA::kDIGITS) ;
1623 //_____________________________________________________________________________
1624 void AliSimulation::ProcessEnvironmentVars()
1626 // Extract run number and random generator seed from env variables
1628 AliInfo("Processing environment variables");
1630 // Random Number seed
1632 // first check that seed is not already set
1634 if (gSystem->Getenv("CONFIG_SEED")) {
1635 fSeed = atoi(gSystem->Getenv("CONFIG_SEED"));
1638 if (gSystem->Getenv("CONFIG_SEED")) {
1639 AliInfo(Form("Seed for random number generation already set (%d)"
1640 ": CONFIG_SEED variable ignored!", fSeed));
1644 AliInfo(Form("Seed for random number generation = %d ", fSeed));
1648 // first check that run number is not already set
1650 if (gSystem->Getenv("DC_RUN")) {
1651 fRun = atoi(gSystem->Getenv("DC_RUN"));
1654 if (gSystem->Getenv("DC_RUN")) {
1655 AliInfo(Form("Run number already set (%d): DC_RUN variable ignored!", fRun));
1659 AliInfo(Form("Run number = %d", fRun));