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"
142 #include "AliSysInfo.h"
144 ClassImp(AliSimulation)
146 AliSimulation *AliSimulation::fgInstance = 0;
147 const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
149 //_____________________________________________________________________________
150 AliSimulation::AliSimulation(const char* configFileName,
151 const char* name, const char* title) :
154 fRunGeneration(kTRUE),
155 fRunSimulation(kTRUE),
156 fLoadAlignFromCDB(kTRUE),
157 fLoadAlObjsListOfDets("ALL"),
161 fMakeDigitsFromHits(""),
163 fRawDataFileName(""),
164 fDeleteIntermediateFiles(kFALSE),
165 fWriteSelRawData(kFALSE),
166 fStopOnError(kFALSE),
169 fConfigFileName(configFileName),
170 fGAliceFileName("galice.root"),
172 fBkgrdFileNames(NULL),
173 fAlignObjArray(NULL),
174 fUseBkgrdVertex(kTRUE),
175 fRegionOfInterest(kFALSE),
180 fInitCDBCalled(kFALSE),
181 fInitRunNumberCalled(kFALSE),
182 fSetRunNumberFromDataCalled(kFALSE),
183 fEmbeddingFlag(kFALSE),
187 // create simulation object with default parameters
189 SetGAliceFile("galice.root");
192 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++)
193 fQACycles[iDet] = 999999;
196 //_____________________________________________________________________________
197 AliSimulation::AliSimulation(const AliSimulation& sim) :
200 fRunGeneration(sim.fRunGeneration),
201 fRunSimulation(sim.fRunSimulation),
202 fLoadAlignFromCDB(sim.fLoadAlignFromCDB),
203 fLoadAlObjsListOfDets(sim.fLoadAlObjsListOfDets),
204 fMakeSDigits(sim.fMakeSDigits),
205 fMakeDigits(sim.fMakeDigits),
206 fMakeTrigger(sim.fMakeTrigger),
207 fMakeDigitsFromHits(sim.fMakeDigitsFromHits),
208 fWriteRawData(sim.fWriteRawData),
209 fRawDataFileName(""),
210 fDeleteIntermediateFiles(kFALSE),
211 fWriteSelRawData(kFALSE),
212 fStopOnError(sim.fStopOnError),
214 fNEvents(sim.fNEvents),
215 fConfigFileName(sim.fConfigFileName),
216 fGAliceFileName(sim.fGAliceFileName),
218 fBkgrdFileNames(NULL),
219 fAlignObjArray(NULL),
220 fUseBkgrdVertex(sim.fUseBkgrdVertex),
221 fRegionOfInterest(sim.fRegionOfInterest),
222 fCDBUri(sim.fCDBUri),
226 fInitCDBCalled(sim.fInitCDBCalled),
227 fInitRunNumberCalled(sim.fInitRunNumberCalled),
228 fSetRunNumberFromDataCalled(sim.fSetRunNumberFromDataCalled),
229 fEmbeddingFlag(sim.fEmbeddingFlag),
235 for (Int_t i = 0; i < sim.fEventsPerFile.GetEntriesFast(); i++) {
236 if (!sim.fEventsPerFile[i]) continue;
237 fEventsPerFile.Add(sim.fEventsPerFile[i]->Clone());
240 fBkgrdFileNames = new TObjArray;
241 for (Int_t i = 0; i < sim.fBkgrdFileNames->GetEntriesFast(); i++) {
242 if (!sim.fBkgrdFileNames->At(i)) continue;
243 fBkgrdFileNames->Add(sim.fBkgrdFileNames->At(i)->Clone());
246 for (Int_t i = 0; i < sim.fSpecCDBUri.GetEntriesFast(); i++) {
247 if (sim.fSpecCDBUri[i]) fSpecCDBUri.Add(sim.fSpecCDBUri[i]->Clone());
252 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++)
253 fQACycles[iDet] = sim.fQACycles[iDet];
256 //_____________________________________________________________________________
257 AliSimulation& AliSimulation::operator = (const AliSimulation& sim)
259 // assignment operator
261 this->~AliSimulation();
262 new(this) AliSimulation(sim);
266 //_____________________________________________________________________________
267 AliSimulation::~AliSimulation()
271 fEventsPerFile.Delete();
272 // if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
273 // delete fAlignObjArray; fAlignObjArray=0;
275 if (fBkgrdFileNames) {
276 fBkgrdFileNames->Delete();
277 delete fBkgrdFileNames;
280 fSpecCDBUri.Delete();
281 if (fgInstance==this) fgInstance = 0;
283 AliCodeTimer::Instance()->Print();
287 //_____________________________________________________________________________
288 void AliSimulation::SetNumberOfEvents(Int_t nEvents)
290 // set the number of events for one run
295 //_____________________________________________________________________________
296 void AliSimulation::InitCDB()
298 // activate a default CDB storage
299 // First check if we have any CDB storage set, because it is used
300 // to retrieve the calibration and alignment constants
302 if (fInitCDBCalled) return;
303 fInitCDBCalled = kTRUE;
305 AliCDBManager* man = AliCDBManager::Instance();
306 if (man->IsDefaultStorageSet())
308 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
309 AliWarning("Default CDB storage has been already set !");
310 AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fCDBUri.Data()));
311 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
312 fCDBUri = man->GetDefaultStorage()->GetURI();
315 if (fCDBUri.Length() > 0)
317 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
318 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
319 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
321 fCDBUri="local://$ALICE_ROOT";
322 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
323 AliWarning("Default CDB storage not yet set !!!!");
324 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
325 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
328 man->SetDefaultStorage(fCDBUri);
331 // Now activate the detector specific CDB storage locations
332 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
333 TObject* obj = fSpecCDBUri[i];
335 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
336 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
337 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
338 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
343 //_____________________________________________________________________________
344 void AliSimulation::InitRunNumber(){
345 // check run number. If not set, set it to 0 !!!!
347 if (fInitRunNumberCalled) return;
348 fInitRunNumberCalled = kTRUE;
350 AliCDBManager* man = AliCDBManager::Instance();
351 if (man->GetRun() >= 0)
353 AliFatal(Form("Run number cannot be set in AliCDBManager before start of simulation: "
354 "Use external variable DC_RUN or AliSimulation::SetRun()!"));
358 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
359 AliDebug(2, Form("Setting CDB run number to: %d",fRun));
360 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
363 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
364 AliWarning("Run number not yet set !!!!");
365 AliWarning(Form("Setting it now to: %d", fRun));
366 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
375 //_____________________________________________________________________________
376 void AliSimulation::SetCDBLock() {
377 // Set CDB lock: from now on it is forbidden to reset the run number
378 // or the default storage or to activate any further storage!
380 AliCDBManager::Instance()->SetLock(1);
383 //_____________________________________________________________________________
384 void AliSimulation::SetDefaultStorage(const char* uri) {
385 // Store the desired default CDB storage location
386 // Activate it later within the Run() method
392 //_____________________________________________________________________________
393 void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
394 // Store a detector-specific CDB storage location
395 // Activate it later within the Run() method
397 AliCDBPath aPath(calibType);
398 if(!aPath.IsValid()){
399 AliError(Form("Not a valid path: %s", calibType));
403 TObject* obj = fSpecCDBUri.FindObject(calibType);
404 if (obj) fSpecCDBUri.Remove(obj);
405 fSpecCDBUri.Add(new TNamed(calibType, uri));
409 //_____________________________________________________________________________
410 void AliSimulation::SetRunNumber(Int_t run)
413 // Activate it later within the Run() method
418 //_____________________________________________________________________________
419 void AliSimulation::SetSeed(Int_t seed)
422 // Activate it later within the Run() method
427 //_____________________________________________________________________________
428 Bool_t AliSimulation::SetRunNumberFromData()
430 // Set the CDB manager run number
431 // The run number is retrieved from gAlice
433 if (fSetRunNumberFromDataCalled) return kTRUE;
434 fSetRunNumberFromDataCalled = kTRUE;
436 AliCDBManager* man = AliCDBManager::Instance();
437 Int_t runData = -1, runCDB = -1;
439 AliRunLoader* runLoader = LoadRun("READ");
440 if (!runLoader) return kFALSE;
442 runData = runLoader->GetAliRun()->GetHeader()->GetRun();
446 runCDB = man->GetRun();
448 if (runCDB != runData) {
449 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
450 AliWarning(Form("A run number was previously set in AliCDBManager: %d !", runCDB));
451 AliWarning(Form("It will be replaced with the run number got from run header: %d !", runData));
452 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
457 man->SetRun(runData);
460 if(man->GetRun() < 0) {
461 AliError("Run number not properly initalized!");
470 //_____________________________________________________________________________
471 void AliSimulation::SetConfigFile(const char* fileName)
473 // set the name of the config file
475 fConfigFileName = fileName;
478 //_____________________________________________________________________________
479 void AliSimulation::SetGAliceFile(const char* fileName)
481 // set the name of the galice file
482 // the path is converted to an absolute one if it is relative
484 fGAliceFileName = fileName;
485 if (!gSystem->IsAbsoluteFileName(fGAliceFileName)) {
486 char* absFileName = gSystem->ConcatFileName(gSystem->WorkingDirectory(),
488 fGAliceFileName = absFileName;
489 delete[] absFileName;
492 AliDebug(2, Form("galice file name set to %s", fileName));
495 //_____________________________________________________________________________
496 void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
499 // set the number of events per file for the given detector and data type
500 // ("Hits", "Summable Digits", "Digits", "Reconstructed Points" or "Tracks")
502 TNamed* obj = new TNamed(detector, type);
503 obj->SetUniqueID(nEvents);
504 fEventsPerFile.Add(obj);
507 //_____________________________________________________________________________
508 Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
510 // Read the alignment objects from CDB.
511 // Each detector is supposed to have the
512 // alignment objects in DET/Align/Data CDB path.
513 // All the detector objects are then collected,
514 // sorted by geometry level (starting from ALIC) and
515 // then applied to the TGeo geometry.
516 // Finally an overlaps check is performed.
518 if (!AliGeomManager::GetGeometry() || !AliGeomManager::GetGeometry()->IsClosed()) {
519 AliError("Can't apply the misalignment! Geometry is not loaded or it is still opened!");
523 // initialize CDB storage, run number, set CDB lock
525 // if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
528 Bool_t delRunLoader = kFALSE;
530 runLoader = LoadRun("READ");
531 if (!runLoader) return kFALSE;
532 delRunLoader = kTRUE;
535 // Export ideal geometry
536 if(!gAlice->IsRootGeometry()) AliGeomManager::GetGeometry()->Export("geometry.root");
538 // Load alignment data from CDB and apply to geometry through AliGeomManager
539 if(fLoadAlignFromCDB){
541 TString detStr = fLoadAlObjsListOfDets;
542 TString loadAlObjsListOfDets = "";
544 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
545 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
546 AliModule* det = (AliModule*) detArray->At(iDet);
547 if (!det || !det->IsActive()) continue;
548 if (IsSelected(det->GetName(), detStr)) {
549 //add det to list of dets to be aligned from CDB
550 loadAlObjsListOfDets += det->GetName();
551 loadAlObjsListOfDets += " ";
553 } // end loop over detectors
554 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
555 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
557 // Check if the array with alignment objects was
558 // provided by the user. If yes, apply the objects
559 // to the present TGeo geometry
560 if (fAlignObjArray) {
561 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
562 AliError("The misalignment of one or more volumes failed!"
563 "Compare the list of simulated detectors and the list of detector alignment data!");
564 if (delRunLoader) delete runLoader;
570 // Update the internal geometry of modules (ITS needs it)
571 TString detStr = fLoadAlObjsListOfDets;
572 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
573 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
575 AliModule* det = (AliModule*) detArray->At(iDet);
576 if (!det || !det->IsActive()) continue;
577 if (IsSelected(det->GetName(), detStr)) {
578 det->UpdateInternalGeometry();
580 } // end loop over detectors
583 if (delRunLoader) delete runLoader;
588 //_____________________________________________________________________________
589 void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
591 // add a file with background events for merging
593 TObjString* fileNameStr = new TObjString(fileName);
594 fileNameStr->SetUniqueID(nSignalPerBkgrd);
595 if (!fBkgrdFileNames) fBkgrdFileNames = new TObjArray;
596 fBkgrdFileNames->Add(fileNameStr);
599 void AliSimulation::EmbedInto(const char* fileName, Int_t nSignalPerBkgrd)
601 // add a file with background events for embeddin
602 MergeWith(fileName, nSignalPerBkgrd);
603 fEmbeddingFlag = kTRUE;
606 //_____________________________________________________________________________
607 Bool_t AliSimulation::Run(Int_t nEvents)
609 // run the generation, simulation and digitization
614 // Load run number and seed from environmental vars
615 ProcessEnvironmentVars();
617 gRandom->SetSeed(fSeed);
619 if (nEvents > 0) fNEvents = nEvents;
621 // generation and simulation -> hits
622 if (fRunGeneration) {
623 if (!RunSimulation()) if (fStopOnError) return kFALSE;
626 // initialize CDB storage from external environment
627 // (either CDB manager or AliSimulation setters),
628 // if not already done in RunSimulation()
631 // Set run number in CDBManager from data
632 // From this point on the run number must be always loaded from data!
633 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
635 // Set CDB lock: from now on it is forbidden to reset the run number
636 // or the default storage or to activate any further storage!
639 // If RunSimulation was not called, load the geometry and misalign it
640 if (!AliGeomManager::GetGeometry()) {
641 // Initialize the geometry manager
642 AliGeomManager::LoadGeometry("geometry.root");
643 if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
645 if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
649 // hits -> summable digits
650 AliSysInfo::AddStamp("Start_sdigitization");
651 if (!fMakeSDigits.IsNull()) {
652 if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
655 AliSysInfo::AddStamp("Stop_sdigitization");
657 AliSysInfo::AddStamp("Start_digitization");
658 // summable digits -> digits
659 if (!fMakeDigits.IsNull()) {
660 if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
661 if (fStopOnError) return kFALSE;
664 AliSysInfo::AddStamp("Stop_digitization");
669 if (!fMakeDigitsFromHits.IsNull()) {
670 if (fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
671 AliWarning(Form("Merging and direct creation of digits from hits "
672 "was selected for some detectors. "
673 "No merging will be done for the following detectors: %s",
674 fMakeDigitsFromHits.Data()));
676 if (!RunHitsDigitization(fMakeDigitsFromHits)) {
677 if (fStopOnError) return kFALSE;
684 if (!RunTrigger(fMakeTrigger,fMakeDigits)) {
685 if (fStopOnError) return kFALSE;
690 // digits -> raw data
691 if (!fWriteRawData.IsNull()) {
692 if (!WriteRawData(fWriteRawData, fRawDataFileName,
693 fDeleteIntermediateFiles,fWriteSelRawData)) {
694 if (fStopOnError) return kFALSE;
700 // run HLT simulation
701 if (!fRunHLT.IsNull()) {
703 if (fStopOnError) return kFALSE;
709 Bool_t rv = RunQA() ;
715 // Cleanup of CDB manager: cache and active storages!
716 AliCDBManager::Instance()->ClearCache();
721 //_____________________________________________________________________________
722 Bool_t AliSimulation::RunTrigger(const char* config, const char* detectors)
728 // initialize CDB storage from external environment
729 // (either CDB manager or AliSimulation setters),
730 // if not already done in RunSimulation()
733 // Set run number in CDBManager from data
734 // From this point on the run number must be always loaded from data!
735 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
737 // Set CDB lock: from now on it is forbidden to reset the run number
738 // or the default storage or to activate any further storage!
741 AliRunLoader* runLoader = LoadRun("READ");
742 if (!runLoader) return kFALSE;
743 TString trconfiguration = config;
745 if (trconfiguration.IsNull()) {
746 if (gAlice->GetTriggerDescriptor() != "") {
747 trconfiguration = gAlice->GetTriggerDescriptor();
750 AliWarning("No trigger descriptor is specified. Loading the one that is in the CDB.");
753 runLoader->MakeTree( "GG" );
754 AliCentralTrigger* aCTP = runLoader->GetTrigger();
755 // Load Configuration
756 if (!aCTP->LoadConfiguration( trconfiguration ))
760 if( !aCTP->RunTrigger( runLoader , detectors ) ) {
772 //_____________________________________________________________________________
773 Bool_t AliSimulation::WriteTriggerRawData()
775 // Writes the CTP (trigger) DDL raw data
776 // Details of the format are given in the
777 // trigger TDR - pages 134 and 135.
778 AliCTPRawData writer;
784 //_____________________________________________________________________________
785 Bool_t AliSimulation::RunSimulation(Int_t nEvents)
787 // run the generation and simulation
791 // initialize CDB storage and run number from external environment
792 // (either CDB manager or AliSimulation setters)
798 AliError("no gAlice object. Restart aliroot and try again.");
801 if (gAlice->Modules()->GetEntries() > 0) {
802 AliError("gAlice was already run. Restart aliroot and try again.");
806 AliInfo(Form("initializing gAlice with config file %s",
807 fConfigFileName.Data()));
808 StdoutToAliInfo(StderrToAliError(
809 gAlice->Init(fConfigFileName.Data());
812 // Get the trigger descriptor string
813 // Either from AliSimulation or from
815 if (fMakeTrigger.IsNull()) {
816 if (gAlice->GetTriggerDescriptor() != "")
817 fMakeTrigger = gAlice->GetTriggerDescriptor();
820 gAlice->SetTriggerDescriptor(fMakeTrigger.Data());
822 // Set run number in CDBManager
823 AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
825 AliRunLoader* runLoader = gAlice->GetRunLoader();
827 AliError(Form("gAlice has no run loader object. "
828 "Check your config file: %s", fConfigFileName.Data()));
831 SetGAliceFile(runLoader->GetFileName());
834 #if ROOT_VERSION_CODE < 331527
835 AliGeomManager::SetGeometry(gGeoManager);
836 MisalignGeometry(runLoader);
839 // AliRunLoader* runLoader = gAlice->GetRunLoader();
841 // AliError(Form("gAlice has no run loader object. "
842 // "Check your config file: %s", fConfigFileName.Data()));
845 // SetGAliceFile(runLoader->GetFileName());
847 if (!gAlice->Generator()) {
848 AliError(Form("gAlice has no generator object. "
849 "Check your config file: %s", fConfigFileName.Data()));
852 if (nEvents <= 0) nEvents = fNEvents;
854 // get vertex from background file in case of merging
855 if (fUseBkgrdVertex &&
856 fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
857 Int_t signalPerBkgrd = GetNSignalPerBkgrd(nEvents);
858 const char* fileName = ((TObjString*)
859 (fBkgrdFileNames->At(0)))->GetName();
860 AliInfo(Form("The vertex will be taken from the background "
861 "file %s with nSignalPerBackground = %d",
862 fileName, signalPerBkgrd));
863 AliVertexGenFile* vtxGen = new AliVertexGenFile(fileName, signalPerBkgrd);
864 gAlice->Generator()->SetVertexGenerator(vtxGen);
867 if (!fRunSimulation) {
868 gAlice->Generator()->SetTrackingFlag(0);
871 // set the number of events per file for given detectors and data types
872 for (Int_t i = 0; i < fEventsPerFile.GetEntriesFast(); i++) {
873 if (!fEventsPerFile[i]) continue;
874 const char* detName = fEventsPerFile[i]->GetName();
875 const char* typeName = fEventsPerFile[i]->GetTitle();
876 TString loaderName(detName);
877 loaderName += "Loader";
878 AliLoader* loader = runLoader->GetLoader(loaderName);
880 AliError(Form("RunSimulation", "no loader for %s found\n"
881 "Number of events per file not set for %s %s",
882 detName, typeName, detName));
885 AliDataLoader* dataLoader =
886 loader->GetDataLoader(typeName);
888 AliError(Form("no data loader for %s found\n"
889 "Number of events per file not set for %s %s",
890 typeName, detName, typeName));
893 dataLoader->SetNumberOfEventsPerFile(fEventsPerFile[i]->GetUniqueID());
894 AliDebug(1, Form("number of events per file set to %d for %s %s",
895 fEventsPerFile[i]->GetUniqueID(), detName, typeName));
898 AliInfo("running gAlice");
899 AliSysInfo::AddStamp("Start_simulation");
900 StdoutToAliInfo(StderrToAliError(
901 gAlice->Run(nEvents);
903 AliSysInfo::AddStamp("Stop_simulation");
909 //_____________________________________________________________________________
910 Bool_t AliSimulation::RunSDigitization(const char* detectors)
912 // run the digitization and produce summable digits
913 static Int_t eventNr=0;
916 // initialize CDB storage, run number, set CDB lock
918 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
921 AliRunLoader* runLoader = LoadRun();
922 if (!runLoader) return kFALSE;
924 TString detStr = detectors;
925 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
926 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
927 AliModule* det = (AliModule*) detArray->At(iDet);
928 if (!det || !det->IsActive()) continue;
929 if (IsSelected(det->GetName(), detStr)) {
930 AliInfo(Form("creating summable digits for %s", det->GetName()));
931 AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
933 AliSysInfo::AddStamp(Form("Digit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
937 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
938 AliError(Form("the following detectors were not found: %s",
940 if (fStopOnError) return kFALSE;
949 //_____________________________________________________________________________
950 Bool_t AliSimulation::RunDigitization(const char* detectors,
951 const char* excludeDetectors)
953 // run the digitization and produce digits from sdigits
957 // initialize CDB storage, run number, set CDB lock
959 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
962 while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
963 if (gAlice) delete gAlice;
967 if (fBkgrdFileNames) nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
968 Int_t signalPerBkgrd = GetNSignalPerBkgrd();
969 AliRunDigitizer* manager = new AliRunDigitizer(nStreams, signalPerBkgrd);
970 // manager->SetEmbeddingFlag(fEmbeddingFlag);
971 manager->SetInputStream(0, fGAliceFileName.Data());
972 for (Int_t iStream = 1; iStream < nStreams; iStream++) {
973 const char* fileName = ((TObjString*)
974 (fBkgrdFileNames->At(iStream-1)))->GetName();
975 manager->SetInputStream(iStream, fileName);
978 TString detStr = detectors;
979 TString detExcl = excludeDetectors;
980 manager->GetInputStream(0)->ImportgAlice();
981 AliRunLoader* runLoader =
982 AliRunLoader::GetRunLoader(manager->GetInputStream(0)->GetFolderName());
983 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
984 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
985 AliModule* det = (AliModule*) detArray->At(iDet);
986 if (!det || !det->IsActive()) continue;
987 if (IsSelected(det->GetName(), detStr) &&
988 !IsSelected(det->GetName(), detExcl)) {
989 AliDigitizer* digitizer = det->CreateDigitizer(manager);
992 AliError(Form("no digitizer for %s", det->GetName()));
993 if (fStopOnError) return kFALSE;
995 digitizer->SetRegionOfInterest(fRegionOfInterest);
1000 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1001 AliError(Form("the following detectors were not found: %s",
1003 if (fStopOnError) return kFALSE;
1006 if (!manager->GetListOfTasks()->IsEmpty()) {
1007 AliInfo("executing digitization");
1016 //_____________________________________________________________________________
1017 Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
1019 // run the digitization and produce digits from hits
1021 AliCodeTimerAuto("")
1023 // initialize CDB storage, run number, set CDB lock
1025 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1028 AliRunLoader* runLoader = LoadRun("READ");
1029 if (!runLoader) return kFALSE;
1031 TString detStr = detectors;
1032 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1033 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1034 AliModule* det = (AliModule*) detArray->At(iDet);
1035 if (!det || !det->IsActive()) continue;
1036 if (IsSelected(det->GetName(), detStr)) {
1037 AliInfo(Form("creating digits from hits for %s", det->GetName()));
1042 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1043 AliError(Form("the following detectors were not found: %s",
1045 if (fStopOnError) return kFALSE;
1049 //PH Temporary fix to avoid interference with the PHOS loder/getter
1050 //PH The problem has to be solved in more general way 09/06/05
1055 //_____________________________________________________________________________
1056 Bool_t AliSimulation::WriteRawData(const char* detectors,
1057 const char* fileName,
1058 Bool_t deleteIntermediateFiles,
1061 // convert the digits to raw data
1062 // First DDL raw data files for the given detectors are created.
1063 // If a file name is given, the DDL files are then converted to a DATE file.
1064 // If deleteIntermediateFiles is true, the DDL raw files are deleted
1066 // If the file name has the extension ".root", the DATE file is converted
1068 // If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
1069 // 'selrawdata' flag can be used to enable writing of detectors raw data
1070 // accoring to the trigger cluster.
1072 AliCodeTimerAuto("")
1074 if (!WriteRawFiles(detectors)) {
1075 if (fStopOnError) return kFALSE;
1078 TString dateFileName(fileName);
1079 if (!dateFileName.IsNull()) {
1080 Bool_t rootOutput = dateFileName.EndsWith(".root");
1081 if (rootOutput) dateFileName += ".date";
1082 TString selDateFileName;
1084 selDateFileName = "selected.";
1085 selDateFileName+= dateFileName;
1087 if (!ConvertRawFilesToDate(dateFileName,selDateFileName)) {
1088 if (fStopOnError) return kFALSE;
1090 if (deleteIntermediateFiles) {
1091 AliRunLoader* runLoader = LoadRun("READ");
1092 if (runLoader) for (Int_t iEvent = 0;
1093 iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1095 sprintf(command, "rm -r raw%d", iEvent);
1096 gSystem->Exec(command);
1101 if (!ConvertDateToRoot(dateFileName, fileName)) {
1102 if (fStopOnError) return kFALSE;
1104 if (deleteIntermediateFiles) {
1105 gSystem->Unlink(dateFileName);
1108 TString selFileName = "selected.";
1109 selFileName += fileName;
1110 if (!ConvertDateToRoot(selDateFileName, selFileName)) {
1111 if (fStopOnError) return kFALSE;
1113 if (deleteIntermediateFiles) {
1114 gSystem->Unlink(selDateFileName);
1123 //_____________________________________________________________________________
1124 Bool_t AliSimulation::WriteRawFiles(const char* detectors)
1126 // convert the digits to raw data DDL files
1128 AliCodeTimerAuto("")
1130 AliRunLoader* runLoader = LoadRun("READ");
1131 if (!runLoader) return kFALSE;
1133 // write raw data to DDL files
1134 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1135 AliInfo(Form("processing event %d", iEvent));
1136 runLoader->GetEvent(iEvent);
1137 TString baseDir = gSystem->WorkingDirectory();
1139 sprintf(dirName, "raw%d", iEvent);
1140 gSystem->MakeDirectory(dirName);
1141 if (!gSystem->ChangeDirectory(dirName)) {
1142 AliError(Form("couldn't change to directory %s", dirName));
1143 if (fStopOnError) return kFALSE; else continue;
1146 TString detStr = detectors;
1147 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1148 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1149 AliModule* det = (AliModule*) detArray->At(iDet);
1150 if (!det || !det->IsActive()) continue;
1151 if (IsSelected(det->GetName(), detStr)) {
1152 AliInfo(Form("creating raw data from digits for %s", det->GetName()));
1157 if (!WriteTriggerRawData())
1158 if (fStopOnError) return kFALSE;
1160 gSystem->ChangeDirectory(baseDir);
1161 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1162 AliError(Form("the following detectors were not found: %s",
1164 if (fStopOnError) return kFALSE;
1173 //_____________________________________________________________________________
1174 Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
1175 const char* selDateFileName)
1177 // convert raw data DDL files to a DATE file with the program "dateStream"
1178 // The second argument is not empty when the user decides to write
1179 // the detectors raw data according to the trigger cluster.
1181 AliCodeTimerAuto("")
1183 char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
1185 AliError("the program dateStream was not found");
1186 if (fStopOnError) return kFALSE;
1191 AliRunLoader* runLoader = LoadRun("READ");
1192 if (!runLoader) return kFALSE;
1194 AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
1195 Bool_t selrawdata = kFALSE;
1196 if (strcmp(selDateFileName,"") != 0) selrawdata = kTRUE;
1199 // Note the option -s. It is used in order to avoid
1200 // the generation of SOR/EOR events.
1201 sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
1202 dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
1203 FILE* pipe = gSystem->OpenPipe(command, "w");
1205 Int_t selEvents = 0;
1206 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1207 fprintf(pipe, "GDC\n");
1212 // Check if the event was triggered by CTP
1213 runLoader->GetEvent(iEvent);
1214 if (!runLoader->LoadTrigger()) {
1215 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1216 if (aCTP->GetClassMask()) selEvents++;
1219 AliWarning("No trigger can be loaded! Writing of selected raw data is abandoned !");
1220 selrawdata = kFALSE;
1224 // loop over detectors and DDLs
1225 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1226 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1228 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1229 Int_t ldcID = Int_t(ldc + 0.0001);
1230 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1232 char rawFileName[256];
1233 sprintf(rawFileName, "raw%d/%s",
1234 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1236 // check existence and size of raw data file
1237 FILE* file = fopen(rawFileName, "rb");
1238 if (!file) continue;
1239 fseek(file, 0, SEEK_END);
1240 unsigned long size = ftell(file);
1242 if (!size) continue;
1244 if (ldcID != prevLDC) {
1245 fprintf(pipe, " LDC Id %d\n", ldcID);
1248 fprintf(pipe, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1253 Int_t result = gSystem->ClosePipe(pipe);
1255 if (!(selrawdata && selEvents > 0)) {
1257 return (result == 0);
1260 AliInfo(Form("converting selected by trigger cluster raw data DDL files to DATE file %s", selDateFileName));
1262 sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
1263 selDateFileName,selEvents,runLoader->GetHeader()->GetRun());
1264 FILE* pipe2 = gSystem->OpenPipe(command, "w");
1266 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1268 // Get the trigger decision and cluster
1270 runLoader->GetEvent(iEvent);
1271 if (!runLoader->LoadTrigger()) {
1272 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1273 if (aCTP->GetClassMask() == 0) continue;
1274 detClust = aCTP->GetTriggeredDetectors();
1275 AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
1278 fprintf(pipe2, "GDC\n");
1282 // loop over detectors and DDLs
1283 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1284 // Write only raw data from detectors that
1285 // are contained in the trigger cluster(s)
1286 if (!IsSelected(AliDAQ::DetectorName(iDet),detClust)) continue;
1288 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1290 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1291 Int_t ldcID = Int_t(ldc + 0.0001);
1292 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1294 char rawFileName[256];
1295 sprintf(rawFileName, "raw%d/%s",
1296 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1298 // check existence and size of raw data file
1299 FILE* file = fopen(rawFileName, "rb");
1300 if (!file) continue;
1301 fseek(file, 0, SEEK_END);
1302 unsigned long size = ftell(file);
1304 if (!size) continue;
1306 if (ldcID != prevLDC) {
1307 fprintf(pipe2, " LDC Id %d\n", ldcID);
1310 fprintf(pipe2, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1315 Int_t result2 = gSystem->ClosePipe(pipe2);
1318 return ((result == 0) && (result2 == 0));
1321 //_____________________________________________________________________________
1322 Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
1323 const char* rootFileName)
1325 // convert a DATE file to a root file with the program "alimdc"
1328 const Int_t kDBSize = 2000000000;
1329 const Int_t kTagDBSize = 1000000000;
1330 const Bool_t kFilter = kFALSE;
1331 const Int_t kCompression = 1;
1333 char* path = gSystem->Which(gSystem->Getenv("PATH"), "alimdc");
1335 AliError("the program alimdc was not found");
1336 if (fStopOnError) return kFALSE;
1341 AliInfo(Form("converting DATE file %s to root file %s",
1342 dateFileName, rootFileName));
1344 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
1345 const char* tagDBFS = "/tmp/mdc1/tags";
1347 // User defined file system locations
1348 if (gSystem->Getenv("ALIMDC_RAWDB1"))
1349 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
1350 if (gSystem->Getenv("ALIMDC_RAWDB2"))
1351 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
1352 if (gSystem->Getenv("ALIMDC_TAGDB"))
1353 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
1355 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1356 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1357 gSystem->Exec(Form("rm -rf %s",tagDBFS));
1359 gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
1360 gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
1361 gSystem->Exec(Form("mkdir %s",tagDBFS));
1363 Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s",
1364 kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
1365 gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0], rootFileName));
1367 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1368 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1369 gSystem->Exec(Form("rm -rf %s",tagDBFS));
1371 return (result == 0);
1375 //_____________________________________________________________________________
1376 AliRunLoader* AliSimulation::LoadRun(const char* mode) const
1378 // delete existing run loaders, open a new one and load gAlice
1380 while (AliRunLoader::GetRunLoader()) delete AliRunLoader::GetRunLoader();
1381 AliRunLoader* runLoader =
1382 AliRunLoader::Open(fGAliceFileName.Data(),
1383 AliConfig::GetDefaultEventFolderName(), mode);
1385 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1388 runLoader->LoadgAlice();
1389 runLoader->LoadHeader();
1390 gAlice = runLoader->GetAliRun();
1392 AliError(Form("no gAlice object found in file %s",
1393 fGAliceFileName.Data()));
1399 //_____________________________________________________________________________
1400 Int_t AliSimulation::GetNSignalPerBkgrd(Int_t nEvents) const
1402 // get or calculate the number of signal events per background event
1404 if (!fBkgrdFileNames) return 1;
1405 Int_t nBkgrdFiles = fBkgrdFileNames->GetEntriesFast();
1406 if (nBkgrdFiles == 0) return 1;
1408 // get the number of signal events
1410 AliRunLoader* runLoader =
1411 AliRunLoader::Open(fGAliceFileName.Data(), "SIGNAL");
1412 if (!runLoader) return 1;
1414 nEvents = runLoader->GetNumberOfEvents();
1419 for (Int_t iBkgrdFile = 0; iBkgrdFile < nBkgrdFiles; iBkgrdFile++) {
1420 // get the number of background events
1421 const char* fileName = ((TObjString*)
1422 (fBkgrdFileNames->At(iBkgrdFile)))->GetName();
1423 AliRunLoader* runLoader =
1424 AliRunLoader::Open(fileName, "BKGRD");
1425 if (!runLoader) continue;
1426 Int_t nBkgrdEvents = runLoader->GetNumberOfEvents();
1429 // get or calculate the number of signal per background events
1430 Int_t nSignalPerBkgrd = fBkgrdFileNames->At(iBkgrdFile)->GetUniqueID();
1431 if (nSignalPerBkgrd <= 0) {
1432 nSignalPerBkgrd = (nEvents-1) / nBkgrdEvents + 1;
1433 } else if (result && (result != nSignalPerBkgrd)) {
1434 AliInfo(Form("the number of signal events per background event "
1435 "will be changed from %d to %d for stream %d",
1436 nSignalPerBkgrd, result, iBkgrdFile+1));
1437 nSignalPerBkgrd = result;
1440 if (!result) result = nSignalPerBkgrd;
1441 if (nSignalPerBkgrd * nBkgrdEvents < nEvents) {
1442 AliWarning(Form("not enough background events (%d) for %d signal events "
1443 "using %d signal per background events for stream %d",
1444 nBkgrdEvents, nEvents, nSignalPerBkgrd, iBkgrdFile+1));
1451 //_____________________________________________________________________________
1452 Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
1454 // check whether detName is contained in detectors
1455 // if yes, it is removed from detectors
1457 // check if all detectors are selected
1458 if ((detectors.CompareTo("ALL") == 0) ||
1459 detectors.BeginsWith("ALL ") ||
1460 detectors.EndsWith(" ALL") ||
1461 detectors.Contains(" ALL ")) {
1466 // search for the given detector
1467 Bool_t result = kFALSE;
1468 if ((detectors.CompareTo(detName) == 0) ||
1469 detectors.BeginsWith(detName+" ") ||
1470 detectors.EndsWith(" "+detName) ||
1471 detectors.Contains(" "+detName+" ")) {
1472 detectors.ReplaceAll(detName, "");
1476 // clean up the detectors string
1477 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1478 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1479 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1484 //_____________________________________________________________________________
1485 Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName)
1488 // Steering routine to convert raw data in directory rawDirectory/ to fake SDigits.
1489 // These can be used for embedding of MC tracks into RAW data using the standard
1490 // merging procedure.
1492 // If an ESD file is given the reconstructed vertex is taken from it and stored in the event header.
1495 AliError("no gAlice object. Restart aliroot and try again.");
1498 if (gAlice->Modules()->GetEntries() > 0) {
1499 AliError("gAlice was already run. Restart aliroot and try again.");
1503 AliInfo(Form("initializing gAlice with config file %s",fConfigFileName.Data()));
1504 StdoutToAliInfo(StderrToAliError(gAlice->Init(fConfigFileName.Data());););
1508 //AliCDBManager* man = AliCDBManager::Instance();
1509 //man->SetRun(0); // Should this come from rawdata header ?
1513 // Get the runloader
1514 AliRunLoader* runLoader = gAlice->GetRunLoader();
1516 // Open esd file if available
1517 TFile* esdFile = TFile::Open(esdFileName);
1518 Bool_t esdOK = (esdFile != 0);
1519 AliESD* esd = new AliESD;
1522 treeESD = (TTree*) esdFile->Get("esdTree");
1524 AliWarning("No ESD tree found");
1527 treeESD->SetBranchAddress("ESD", &esd);
1531 // Create the RawReader
1532 TString fileName(rawDirectory);
1533 AliRawReader* rawReader = 0x0;
1534 if (fileName.EndsWith("/")) {
1535 rawReader = new AliRawReaderFile(fileName);
1536 } else if (fileName.EndsWith(".root")) {
1537 rawReader = new AliRawReaderRoot(fileName);
1538 } else if (!fileName.IsNull()) {
1539 rawReader = new AliRawReaderDate(fileName);
1540 rawReader->SelectEvents(7);
1542 // if (!fEquipIdMap.IsNull() && fRawReader)
1543 // fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1545 // Get list of detectors
1546 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1549 AliHeader* header = runLoader->GetHeader();
1551 TString detStr = fMakeSDigits;
1555 if (!(rawReader->NextEvent())) break;
1558 for (iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1559 AliModule* det = (AliModule*) detArray->At(iDet);
1560 if (!det || !det->IsActive()) continue;
1561 if (IsSelected(det->GetName(), detStr)) {
1562 AliInfo(Form("Calling Raw2SDigits for %s\n", det->GetName()));
1563 det->Raw2SDigits(rawReader);
1570 // If ESD information available obtain reconstructed vertex and store in header.
1572 treeESD->GetEvent(nev);
1573 const AliESDVertex* esdVertex = esd->GetPrimaryVertex();
1574 Double_t position[3];
1575 esdVertex->GetXYZ(position);
1576 AliGenEventHeader* mcHeader = new AliGenEventHeader("ESD");
1579 for (Int_t i = 0; i < 3; i++) mcV[i] = position[i];
1580 mcHeader->SetPrimaryVertex(mcV);
1581 header->Reset(0,nev);
1582 header->SetGenEventHeader(mcHeader);
1583 printf("***** Saved vertex %f %f %f \n", position[0], position[1], position[2]);
1588 runLoader->TreeE()->Fill();
1589 runLoader->SetNextEvent();
1595 runLoader->CdGAFile();
1596 runLoader->WriteHeader("OVERWRITE");
1597 runLoader->WriteRunLoader();
1602 //_____________________________________________________________________________
1603 Int_t AliSimulation::GetDetIndex(const char* detector)
1605 // return the detector index corresponding to detector
1607 for (index = 0; index < fgkNDetectors ; index++) {
1608 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
1614 //_____________________________________________________________________________
1615 Bool_t AliSimulation::RunHLT()
1617 // Run the HLT simulation
1618 // HLT simulation is implemented in HLT/sim/AliHLTSimulation
1619 // Disabled if fRunHLT is empty, default vaule is "default".
1620 // AliSimulation::SetRunHLT can be used to set the options for HLT simulation
1621 // The default simulation depends on the HLT component libraries and their
1622 // corresponding agents which define components and chains to run. See
1623 // http://web.ift.uib.no/~kjeks/doc/alice-hlt/
1624 // http://web.ift.uib.no/~kjeks/doc/alice-hlt/classAliHLTModuleAgent.html
1626 // The libraries to be loaded can be specified as an option.
1628 // AliSimulation sim;
1629 // sim.SetRunHLT("libAliHLTSample.so");
1631 // will only load <tt>libAliHLTSample.so</tt>
1633 // Other available options:
1634 // \li loglevel=<i>level</i> <br>
1635 // logging level for this processing
1637 // disable redirection of log messages to AliLog class
1638 // \li config=<i>macro</i>
1639 // configuration macro
1640 // \li localrec=<i>configuration</i>
1641 // comma separated list of configurations to be run during simulation
1644 AliRunLoader* pRunLoader = LoadRun("READ");
1645 if (!pRunLoader) return kFALSE;
1647 // initialize CDB storage, run number, set CDB lock
1649 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1652 // load the library dynamically
1653 gSystem->Load(ALIHLTSIMULATION_LIBRARY);
1655 // check for the library version
1656 AliHLTSimulationGetLibraryVersion_t fctVersion=(AliHLTSimulationGetLibraryVersion_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_GET_LIBRARY_VERSION));
1658 AliError(Form("can not load library %s", ALIHLTSIMULATION_LIBRARY));
1661 if (fctVersion()!= ALIHLTSIMULATION_LIBRARY_VERSION) {
1662 AliError(Form("%s version does not match: compiled for version %d, loaded %d", ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_LIBRARY_VERSION, fctVersion()));
1666 // print compile info
1667 typedef void (*CompileInfo)( char*& date, char*& time);
1668 CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
1672 (*fctInfo)(date, time);
1673 if (!date) date="unknown";
1674 if (!time) time="unknown";
1675 AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
1677 AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
1680 // create instance of the HLT simulation
1681 AliHLTSimulationCreateInstance_t fctCreate=(AliHLTSimulationCreateInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_CREATE_INSTANCE));
1682 AliHLTSimulation* pHLT=NULL;
1683 if (fctCreate==NULL || (pHLT=(fctCreate()))==NULL) {
1684 AliError(Form("can not create instance of HLT simulation (creator %p)", fctCreate));
1688 // init the HLT simulation
1689 if (fRunHLT.CompareTo("default")==0) fRunHLT="";
1690 AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
1691 if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, fRunHLT.Data())))<0) {
1692 AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
1694 // run the HLT simulation
1695 AliHLTSimulationRun_t fctRun=(AliHLTSimulationRun_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_RUN));
1696 if (fctRun==NULL || (iResult=(fctRun(pHLT, pRunLoader)))<0) {
1697 AliError(Form("can not run HLT simulation: error %d (run %p)", iResult, fctRun));
1701 // delete the instance
1702 AliHLTSimulationDeleteInstance_t fctDelete=(AliHLTSimulationDeleteInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_DELETE_INSTANCE));
1703 if (fctDelete==NULL || fctDelete(pHLT)<0) {
1704 AliError(Form("can not delete instance of HLT simulation (creator %p)", fctDelete));
1708 return iResult>=0?kTRUE:kFALSE;
1711 //_____________________________________________________________________________
1712 Bool_t AliSimulation::RunQA()
1714 // run the QA on summable hits, digits or digits
1716 AliQADataMakerSteer qas ;
1717 qas.SetRunLoader(gAlice->GetRunLoader()) ;
1719 Bool_t rv = qas.Run("ALL", AliQA::kHITS) ;
1721 rv *= qas.Run(fMakeSDigits.Data(), AliQA::kSDIGITS) ;
1723 rv *= qas.Run(fMakeDigits.Data(), AliQA::kDIGITS) ;
1725 rv *= qas.Run(fMakeDigitsFromHits.Data(), AliQA::kDIGITS) ;
1730 //_____________________________________________________________________________
1731 void AliSimulation::ProcessEnvironmentVars()
1733 // Extract run number and random generator seed from env variables
1735 AliInfo("Processing environment variables");
1737 // Random Number seed
1739 // first check that seed is not already set
1741 if (gSystem->Getenv("CONFIG_SEED")) {
1742 fSeed = atoi(gSystem->Getenv("CONFIG_SEED"));
1745 if (gSystem->Getenv("CONFIG_SEED")) {
1746 AliInfo(Form("Seed for random number generation already set (%d)"
1747 ": CONFIG_SEED variable ignored!", fSeed));
1751 AliInfo(Form("Seed for random number generation = %d ", fSeed));
1755 // first check that run number is not already set
1757 if (gSystem->Getenv("DC_RUN")) {
1758 fRun = atoi(gSystem->Getenv("DC_RUN"));
1761 if (gSystem->Getenv("DC_RUN")) {
1762 AliInfo(Form("Run number already set (%d): DC_RUN variable ignored!", fRun));
1766 AliInfo(Form("Run number = %d", fRun));