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 ///////////////////////////////////////////////////////////////////////////////
110 #include <TGeoGlobalMagField.h>
111 #include <TGeoManager.h>
112 #include <TObjString.h>
115 #include <TVirtualMC.h>
116 #include <TVirtualMCApplication.h>
119 #include "AliAlignObj.h"
120 #include "AliCDBEntry.h"
121 #include "AliCDBManager.h"
122 #include "AliGRPManager.h"
123 #include "AliCDBStorage.h"
124 #include "AliCTPRawData.h"
125 #include "AliCentralTrigger.h"
126 #include "AliCentralTrigger.h"
127 #include "AliCodeTimer.h"
129 #include "AliDigitizer.h"
130 #include "AliESDEvent.h"
131 #include "AliGRPObject.h"
132 #include "AliGenEventHeader.h"
133 #include "AliGenerator.h"
134 #include "AliGeomManager.h"
135 #include "AliHLTSimulation.h"
136 #include "AliHeader.h"
138 #include "AliLegoGenerator.h"
142 #include "AliModule.h"
144 #include "AliRawReaderDate.h"
145 #include "AliRawReaderFile.h"
146 #include "AliRawReaderRoot.h"
148 #include "AliRunDigitizer.h"
149 #include "AliRunLoader.h"
150 #include "AliSimulation.h"
151 #include "AliSysInfo.h"
152 #include "AliVertexGenFile.h"
154 ClassImp(AliSimulation)
156 AliSimulation *AliSimulation::fgInstance = 0;
157 const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
159 //_____________________________________________________________________________
160 AliSimulation::AliSimulation(const char* configFileName,
161 const char* name, const char* title) :
164 fRunGeneration(kTRUE),
165 fRunSimulation(kTRUE),
166 fLoadAlignFromCDB(kTRUE),
167 fLoadAlObjsListOfDets("ALL"),
171 fMakeDigitsFromHits(""),
173 fRawDataFileName(""),
174 fDeleteIntermediateFiles(kFALSE),
175 fWriteSelRawData(kFALSE),
176 fStopOnError(kFALSE),
178 fConfigFileName(configFileName),
179 fGAliceFileName("galice.root"),
181 fBkgrdFileNames(NULL),
182 fAlignObjArray(NULL),
183 fUseBkgrdVertex(kTRUE),
184 fRegionOfInterest(kFALSE),
190 fInitCDBCalled(kFALSE),
191 fInitRunNumberCalled(kFALSE),
192 fSetRunNumberFromDataCalled(kFALSE),
193 fEmbeddingFlag(kFALSE),
196 fUseVertexFromCDB(0),
197 fUseMagFieldFromGRP(0),
198 fGRPWriteLocation(Form("local://%s", gSystem->pwd())),
202 fEventSpecie(AliRecoParam::kDefault),
203 fWriteQAExpertData(kTRUE),
207 fWriteGRPEntry(kTRUE)
209 // create simulation object with default parameters
211 SetGAliceFile("galice.root");
214 AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kSIMMODE) ;
215 qam->SetActiveDetectors(fQADetectors) ;
216 fQATasks = Form("%d %d %d", AliQAv1::kHITS, AliQAv1::kSDIGITS, AliQAv1::kDIGITS) ;
217 qam->SetTasks(fQATasks) ;
220 //_____________________________________________________________________________
221 AliSimulation::~AliSimulation()
225 fEventsPerFile.Delete();
226 // if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
227 // delete fAlignObjArray; fAlignObjArray=0;
229 if (fBkgrdFileNames) {
230 fBkgrdFileNames->Delete();
231 delete fBkgrdFileNames;
234 fSpecCDBUri.Delete();
235 if (fgInstance==this) fgInstance = 0;
237 AliQAManager::QAManager()->ShowQA() ;
238 AliQAManager::Destroy() ;
239 AliCodeTimer::Instance()->Print();
243 //_____________________________________________________________________________
244 void AliSimulation::SetNumberOfEvents(Int_t nEvents)
246 // set the number of events for one run
251 //_____________________________________________________________________________
252 void AliSimulation::InitQA()
254 // activate a default CDB storage
255 // First check if we have any CDB storage set, because it is used
256 // to retrieve the calibration and alignment constants
258 if (fInitCDBCalled) return;
259 fInitCDBCalled = kTRUE;
261 AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kSIMMODE) ;
262 qam->SetActiveDetectors(fQADetectors) ;
263 fQATasks = Form("%d %d %d", AliQAv1::kHITS, AliQAv1::kSDIGITS, AliQAv1::kDIGITS) ;
264 qam->SetTasks(fQATasks) ;
265 if (fWriteQAExpertData)
266 qam->SetWriteExpert() ;
268 if (qam->IsDefaultStorageSet()) {
269 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
270 AliWarning("Default QA reference storage has been already set !");
271 AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fQARefUri.Data()));
272 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
273 fQARefUri = qam->GetDefaultStorage()->GetURI();
275 if (fQARefUri.Length() > 0) {
276 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
277 AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
278 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
280 fQARefUri="local://$ALICE_ROOT/QARef";
281 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
282 AliWarning("Default QA reference storage not yet set !!!!");
283 AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
284 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
286 qam->SetDefaultStorage(fQARefUri);
290 //_____________________________________________________________________________
291 void AliSimulation::InitCDB()
293 // activate a default CDB storage
294 // First check if we have any CDB storage set, because it is used
295 // to retrieve the calibration and alignment constants
297 if (fInitCDBCalled) return;
298 fInitCDBCalled = kTRUE;
300 AliCDBManager* man = AliCDBManager::Instance();
301 if (man->IsDefaultStorageSet())
303 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
304 AliWarning("Default CDB storage has been already set !");
305 AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fCDBUri.Data()));
306 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
307 fCDBUri = man->GetDefaultStorage()->GetURI();
310 if (fCDBUri.Length() > 0)
312 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
313 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
314 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
316 fCDBUri="local://$ALICE_ROOT/OCDB";
317 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
318 AliWarning("Default CDB storage not yet set !!!!");
319 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
320 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
323 man->SetDefaultStorage(fCDBUri);
326 // Now activate the detector specific CDB storage locations
327 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
328 TObject* obj = fSpecCDBUri[i];
330 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
331 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
332 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
333 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
338 //_____________________________________________________________________________
339 void AliSimulation::InitRunNumber(){
340 // check run number. If not set, set it to 0 !!!!
342 if (fInitRunNumberCalled) return;
343 fInitRunNumberCalled = kTRUE;
345 AliCDBManager* man = AliCDBManager::Instance();
346 if (man->GetRun() >= 0)
348 AliFatal(Form("Run number cannot be set in AliCDBManager before start of simulation: "
349 "Use external variable DC_RUN or AliSimulation::SetRun()!"));
353 AliDebug(2, Form("Setting CDB run number to: %d",fRun));
356 AliWarning(Form("Run number not yet set !!!! Setting it now to: %d",
365 //_____________________________________________________________________________
366 void AliSimulation::SetCDBLock() {
367 // Set CDB lock: from now on it is forbidden to reset the run number
368 // or the default storage or to activate any further storage!
370 ULong_t key = AliCDBManager::Instance()->SetLock(1);
374 //_____________________________________________________________________________
375 void AliSimulation::SetDefaultStorage(const char* uri) {
376 // Store the desired default CDB storage location
377 // Activate it later within the Run() method
383 //_____________________________________________________________________________
384 void AliSimulation::SetQARefDefaultStorage(const char* uri) {
385 // Store the desired default CDB storage location
386 // Activate it later within the Run() method
389 AliQAv1::SetQARefStorage(fQARefUri.Data()) ;
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->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(!IsGeometryFromFile()) 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
612 AliCodeTimerAuto("",0)
613 AliSysInfo::AddStamp("Start_Run");
615 // Load run number and seed from environmental vars
616 ProcessEnvironmentVars();
617 AliSysInfo::AddStamp("ProcessEnvironmentVars");
619 gRandom->SetSeed(fSeed);
621 if (nEvents > 0) fNEvents = nEvents;
623 // create and setup the HLT instance
624 if (!fRunHLT.IsNull() && !CreateHLT()) {
625 if (fStopOnError) return kFALSE;
630 // generation and simulation -> hits
631 if (fRunGeneration) {
632 if (!RunSimulation()) if (fStopOnError) return kFALSE;
634 AliSysInfo::AddStamp("RunSimulation");
636 // initialize CDB storage from external environment
637 // (either CDB manager or AliSimulation setters),
638 // if not already done in RunSimulation()
640 AliSysInfo::AddStamp("InitCDB");
642 // Set run number in CDBManager from data
643 // From this point on the run number must be always loaded from data!
644 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
646 // Set CDB lock: from now on it is forbidden to reset the run number
647 // or the default storage or to activate any further storage!
650 // If RunSimulation was not called, load the geometry and misalign it
651 if (!AliGeomManager::GetGeometry()) {
652 // Initialize the geometry manager
653 AliGeomManager::LoadGeometry("geometry.root");
654 AliSysInfo::AddStamp("GetGeometry");
655 // // Check that the consistency of symbolic names for the activated subdetectors
656 // // in the geometry loaded by AliGeomManager
657 // AliRunLoader* runLoader = LoadRun("READ");
658 // if (!runLoader) return kFALSE;
660 // TString detsToBeChecked = "";
661 // TObjArray* detArray = runLoader->GetAliRun()->Detectors();
662 // for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
663 // AliModule* det = (AliModule*) detArray->At(iDet);
664 // if (!det || !det->IsActive()) continue;
665 // detsToBeChecked += det->GetName();
666 // detsToBeChecked += " ";
667 // } // end loop over detectors
668 // if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
669 if(!AliGeomManager::CheckSymNamesLUT("ALL"))
670 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
672 if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
674 if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
676 AliSysInfo::AddStamp("MissalignGeometry");
679 // hits -> summable digits
680 AliSysInfo::AddStamp("Start_sdigitization");
681 if (!fMakeSDigits.IsNull()) {
682 if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
685 AliSysInfo::AddStamp("Stop_sdigitization");
687 AliSysInfo::AddStamp("Start_digitization");
688 // summable digits -> digits
689 if (!fMakeDigits.IsNull()) {
690 if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
691 if (fStopOnError) return kFALSE;
694 AliSysInfo::AddStamp("Stop_digitization");
699 if (!fMakeDigitsFromHits.IsNull()) {
700 if (fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
701 AliWarning(Form("Merging and direct creation of digits from hits "
702 "was selected for some detectors. "
703 "No merging will be done for the following detectors: %s",
704 fMakeDigitsFromHits.Data()));
706 if (!RunHitsDigitization(fMakeDigitsFromHits)) {
707 if (fStopOnError) return kFALSE;
711 AliSysInfo::AddStamp("Hits2Digits");
715 if (!RunTrigger(fTriggerConfig,fMakeDigits)) {
716 if (fStopOnError) return kFALSE;
719 AliSysInfo::AddStamp("RunTrigger");
722 // digits -> raw data
723 if (!fWriteRawData.IsNull()) {
724 if (!WriteRawData(fWriteRawData, fRawDataFileName,
725 fDeleteIntermediateFiles,fWriteSelRawData)) {
726 if (fStopOnError) return kFALSE;
730 AliSysInfo::AddStamp("WriteRaw");
732 // run HLT simulation on simulated digit data if raw data is not
733 // simulated, otherwise its called as part of WriteRawData
734 if (!fRunHLT.IsNull() && fWriteRawData.IsNull()) {
736 if (fStopOnError) return kFALSE;
740 AliSysInfo::AddStamp("RunHLT");
744 Bool_t rv = RunQA() ;
750 AliSysInfo::AddStamp("RunQA");
752 // Cleanup of CDB manager: cache and active storages!
753 AliCDBManager::Instance()->ClearCache();
758 //_______________________________________________________________________
759 Bool_t AliSimulation::RunLego(const char *setup, Int_t nc1, Float_t c1min,
760 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
761 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener, Int_t nev)
764 // Generates lego plots of:
765 // - radiation length map phi vs theta
766 // - radiation length map phi vs eta
767 // - interaction length map
768 // - g/cm2 length map
770 // ntheta bins in theta, eta
771 // themin minimum angle in theta (degrees)
772 // themax maximum angle in theta (degrees)
774 // phimin minimum angle in phi (degrees)
775 // phimax maximum angle in phi (degrees)
776 // rmin minimum radius
777 // rmax maximum radius
780 // The number of events generated = ntheta*nphi
781 // run input parameters in macro setup (default="Config.C")
783 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
786 <img src="picts/AliRunLego1.gif">
791 <img src="picts/AliRunLego2.gif">
796 <img src="picts/AliRunLego3.gif">
801 // run the generation and simulation
803 AliCodeTimerAuto("",0)
805 // initialize CDB storage and run number from external environment
806 // (either CDB manager or AliSimulation setters)
812 AliError("no gAlice object. Restart aliroot and try again.");
815 if (gAlice->Modules()->GetEntries() > 0) {
816 AliError("gAlice was already run. Restart aliroot and try again.");
820 AliInfo(Form("initializing gAlice with config file %s",
821 fConfigFileName.Data()));
824 if (nev == -1) nev = nc1 * nc2;
826 // check if initialisation has been done
827 // If runloader has been initialized, set the number of events per file to nc1 * nc2
830 if (!gener) gener = new AliLegoGenerator();
832 // Configure Generator
834 gener->SetRadiusRange(rmin, rmax);
835 gener->SetZMax(zmax);
836 gener->SetCoor1Range(nc1, c1min, c1max);
837 gener->SetCoor2Range(nc2, c2min, c2max);
841 fLego = new AliLego("lego",gener);
843 //__________________________________________________________________________
847 gROOT->LoadMacro(setup);
848 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
850 if(AliCDBManager::Instance()->GetRun() >= 0) {
851 SetRunNumber(AliCDBManager::Instance()->GetRun());
853 AliWarning("Run number not initialized!!");
856 AliRunLoader::Instance()->CdGAFile();
858 AliPDG::AddParticlesToPdgDataBase();
860 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
862 gAlice->GetMCApp()->Init();
865 //Must be here because some MCs (G4) adds detectors here and not in Config.C
866 gAlice->InitLoaders();
867 AliRunLoader::Instance()->MakeTree("E");
870 // Save stuff at the beginning of the file to avoid file corruption
871 AliRunLoader::Instance()->CdGAFile();
874 //Save current generator
875 AliGenerator *gen=gAlice->GetMCApp()->Generator();
876 gAlice->GetMCApp()->ResetGenerator(gener);
877 //Prepare MC for Lego Run
883 AliRunLoader::Instance()->SetNumberOfEventsPerFile(nev);
884 gMC->ProcessRun(nev);
886 // End of this run, close files
888 // Restore current generator
889 gAlice->GetMCApp()->ResetGenerator(gen);
890 // Delete Lego Object
896 //_____________________________________________________________________________
897 Bool_t AliSimulation::RunTrigger(const char* config, const char* detectors)
901 AliCodeTimerAuto("",0)
903 // initialize CDB storage from external environment
904 // (either CDB manager or AliSimulation setters),
905 // if not already done in RunSimulation()
908 // Set run number in CDBManager from data
909 // From this point on the run number must be always loaded from data!
910 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
912 // Set CDB lock: from now on it is forbidden to reset the run number
913 // or the default storage or to activate any further storage!
916 AliRunLoader* runLoader = LoadRun("READ");
917 if (!runLoader) return kFALSE;
918 TString trconfiguration = config;
920 if (trconfiguration.IsNull()) {
921 if(!fTriggerConfig.IsNull()) {
922 trconfiguration = fTriggerConfig;
925 AliWarning("No trigger descriptor is specified. Loading the one that is in the CDB.");
928 runLoader->MakeTree( "GG" );
929 AliCentralTrigger* aCTP = runLoader->GetTrigger();
930 // Load Configuration
931 if (!aCTP->LoadConfiguration( trconfiguration ))
935 if( !aCTP->RunTrigger( runLoader , detectors ) ) {
947 //_____________________________________________________________________________
948 Bool_t AliSimulation::WriteTriggerRawData()
950 // Writes the CTP (trigger) DDL raw data
951 // Details of the format are given in the
952 // trigger TDR - pages 134 and 135.
953 AliCTPRawData writer;
959 //_____________________________________________________________________________
960 Bool_t AliSimulation::RunSimulation(Int_t nEvents)
962 // run the generation and simulation
964 AliCodeTimerAuto("",0)
966 // initialize CDB storage and run number from external environment
967 // (either CDB manager or AliSimulation setters)
968 AliSysInfo::AddStamp("RunSimulation_Begin");
970 AliSysInfo::AddStamp("RunSimulation_InitCDB");
973 AliSysInfo::AddStamp("RunSimulation_SetCDBLock");
976 AliError("no gAlice object. Restart aliroot and try again.");
979 if (gAlice->Modules()->GetEntries() > 0) {
980 AliError("gAlice was already run. Restart aliroot and try again.");
984 AliInfo(Form("initializing gAlice with config file %s",
985 fConfigFileName.Data()));
988 // Initialize ALICE Simulation run
993 // If requested set the mag. field from the GRP entry.
994 // After this the field is loccked and cannot be changed by Config.C
995 if (fUseMagFieldFromGRP) {
999 AliInfo("Field is locked now. It cannot be changed in Config.C");
1003 gROOT->LoadMacro(fConfigFileName.Data());
1004 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
1005 AliSysInfo::AddStamp("RunSimulation_Config");
1008 // If requested obtain the vertex position and vertex sigma_z from the CDB
1009 // This overwrites the settings from the Config.C
1010 if (fUseVertexFromCDB) {
1011 Double_t vtxPos[3] = {0., 0., 0.};
1012 Double_t vtxSig[3] = {0., 0., 0.};
1013 AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertex");
1015 AliESDVertex* vertex = dynamic_cast<AliESDVertex*> (entry->GetObject());
1017 if(vertex->GetXRes()>2.8) { // > pipe radius --> it's a dummy object, don't use it
1018 entry = AliCDBManager::Instance()->Get("GRP/Calib/MeanVertexSPD");
1019 if (entry) vertex = dynamic_cast<AliESDVertex*> (entry->GetObject());
1023 vertex->GetXYZ(vtxPos);
1024 vertex->GetSigmaXYZ(vtxSig);
1025 AliInfo("Overwriting Config.C vertex settings !");
1026 AliInfo(Form("Vertex position from OCDB entry: x = %13.3f, y = %13.3f, z = %13.3f (sigma = %13.3f)\n",
1027 vtxPos[0], vtxPos[1], vtxPos[2], vtxSig[2]));
1029 AliGenerator *gen = gAlice->GetMCApp()->Generator();
1030 gen->SetOrigin(vtxPos[0], vtxPos[1], vtxPos[2]); // vertex position
1031 gen->SetSigmaZ(vtxSig[2]);
1036 if(AliCDBManager::Instance()->GetRun() >= 0) {
1037 AliRunLoader::Instance()->SetRunNumber(AliCDBManager::Instance()->GetRun());
1038 AliRunLoader::Instance()->SetNumberOfEventsPerRun(fNEvents);
1040 AliWarning("Run number not initialized!!");
1043 AliRunLoader::Instance()->CdGAFile();
1046 AliPDG::AddParticlesToPdgDataBase();
1048 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
1049 AliSysInfo::AddStamp("RunSimulation_GetField");
1051 gAlice->GetMCApp()->Init();
1052 AliSysInfo::AddStamp("RunSimulation_InitMCApp");
1054 //Must be here because some MCs (G4) adds detectors here and not in Config.C
1055 gAlice->InitLoaders();
1056 AliRunLoader::Instance()->MakeTree("E");
1057 AliRunLoader::Instance()->LoadKinematics("RECREATE");
1058 AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
1059 AliRunLoader::Instance()->LoadHits("all","RECREATE");
1061 // Save stuff at the beginning of the file to avoid file corruption
1062 AliRunLoader::Instance()->CdGAFile();
1064 gAlice->SetEventNrInRun(-1); //important - we start Begin event from increasing current number in run
1065 AliSysInfo::AddStamp("RunSimulation_InitLoaders");
1066 //___________________________________________________________________________________________
1068 AliSysInfo::AddStamp("RunSimulation_TriggerDescriptor");
1070 // Set run number in CDBManager
1071 AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
1073 AliRunLoader* runLoader = AliRunLoader::Instance();
1075 AliError(Form("gAlice has no run loader object. "
1076 "Check your config file: %s", fConfigFileName.Data()));
1079 SetGAliceFile(runLoader->GetFileName());
1081 // Misalign geometry
1082 #if ROOT_VERSION_CODE < 331527
1083 AliGeomManager::SetGeometry(gGeoManager);
1085 // Check that the consistency of symbolic names for the activated subdetectors
1086 // in the geometry loaded by AliGeomManager
1087 TString detsToBeChecked = "";
1088 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1089 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1090 AliModule* det = (AliModule*) detArray->At(iDet);
1091 if (!det || !det->IsActive()) continue;
1092 detsToBeChecked += det->GetName();
1093 detsToBeChecked += " ";
1094 } // end loop over detectors
1095 if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
1096 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
1097 MisalignGeometry(runLoader);
1098 AliSysInfo::AddStamp("RunSimulation_MisalignGeometry");
1101 // AliRunLoader* runLoader = AliRunLoader::Instance();
1102 // if (!runLoader) {
1103 // AliError(Form("gAlice has no run loader object. "
1104 // "Check your config file: %s", fConfigFileName.Data()));
1107 // SetGAliceFile(runLoader->GetFileName());
1109 if (!gAlice->GetMCApp()->Generator()) {
1110 AliError(Form("gAlice has no generator object. "
1111 "Check your config file: %s", fConfigFileName.Data()));
1115 // Write GRP entry corresponding to the setting found in Cofig.C
1118 AliSysInfo::AddStamp("RunSimulation_WriteGRP");
1120 if (nEvents <= 0) nEvents = fNEvents;
1122 // get vertex from background file in case of merging
1123 if (fUseBkgrdVertex &&
1124 fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
1125 Int_t signalPerBkgrd = GetNSignalPerBkgrd(nEvents);
1126 const char* fileName = ((TObjString*)
1127 (fBkgrdFileNames->At(0)))->GetName();
1128 AliInfo(Form("The vertex will be taken from the background "
1129 "file %s with nSignalPerBackground = %d",
1130 fileName, signalPerBkgrd));
1131 AliVertexGenFile* vtxGen = new AliVertexGenFile(fileName, signalPerBkgrd);
1132 gAlice->GetMCApp()->Generator()->SetVertexGenerator(vtxGen);
1135 if (!fRunSimulation) {
1136 gAlice->GetMCApp()->Generator()->SetTrackingFlag(0);
1139 // set the number of events per file for given detectors and data types
1140 for (Int_t i = 0; i < fEventsPerFile.GetEntriesFast(); i++) {
1141 if (!fEventsPerFile[i]) continue;
1142 const char* detName = fEventsPerFile[i]->GetName();
1143 const char* typeName = fEventsPerFile[i]->GetTitle();
1144 TString loaderName(detName);
1145 loaderName += "Loader";
1146 AliLoader* loader = runLoader->GetLoader(loaderName);
1148 AliError(Form("RunSimulation no loader for %s found\n Number of events per file not set for %s %s",
1149 detName, typeName, detName));
1152 AliDataLoader* dataLoader =
1153 loader->GetDataLoader(typeName);
1155 AliError(Form("no data loader for %s found\n"
1156 "Number of events per file not set for %s %s",
1157 typeName, detName, typeName));
1160 dataLoader->SetNumberOfEventsPerFile(fEventsPerFile[i]->GetUniqueID());
1161 AliDebug(1, Form("number of events per file set to %d for %s %s",
1162 fEventsPerFile[i]->GetUniqueID(), detName, typeName));
1165 AliInfo("running gAlice");
1166 AliSysInfo::AddStamp("Start_ProcessRun");
1168 // Create the Root Tree with one branch per detector
1169 //Hits moved to begin event -> now we are crating separate tree for each event
1171 gMC->ProcessRun(nEvents);
1173 // End of this run, close files
1174 if(nEvents>0) FinishRun();
1176 AliSysInfo::AddStamp("Stop_ProcessRun");
1182 //_____________________________________________________________________________
1183 Bool_t AliSimulation::RunSDigitization(const char* detectors)
1185 // run the digitization and produce summable digits
1186 static Int_t eventNr=0;
1187 AliCodeTimerAuto("",0) ;
1189 // initialize CDB storage, run number, set CDB lock
1191 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1194 AliRunLoader* runLoader = LoadRun();
1195 if (!runLoader) return kFALSE;
1197 TString detStr = detectors;
1198 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1199 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1200 AliModule* det = (AliModule*) detArray->At(iDet);
1201 if (!det || !det->IsActive()) continue;
1202 if (IsSelected(det->GetName(), detStr)) {
1203 AliInfo(Form("creating summable digits for %s", det->GetName()));
1204 AliCodeTimerStart(Form("creating summable digits for %s", det->GetName()));
1205 det->Hits2SDigits();
1206 AliCodeTimerStop(Form("creating summable digits for %s", det->GetName()));
1207 AliSysInfo::AddStamp(Form("Digit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
1211 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1212 AliError(Form("the following detectors were not found: %s",
1214 if (fStopOnError) return kFALSE;
1223 //_____________________________________________________________________________
1224 Bool_t AliSimulation::RunDigitization(const char* detectors,
1225 const char* excludeDetectors)
1227 // run the digitization and produce digits from sdigits
1229 AliCodeTimerAuto("",0)
1231 // initialize CDB storage, run number, set CDB lock
1233 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1236 delete AliRunLoader::Instance();
1241 if (fBkgrdFileNames) nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
1242 Int_t signalPerBkgrd = GetNSignalPerBkgrd();
1243 AliRunDigitizer* manager = new AliRunDigitizer(nStreams, signalPerBkgrd);
1244 // manager->SetEmbeddingFlag(fEmbeddingFlag);
1245 manager->SetInputStream(0, fGAliceFileName.Data());
1246 for (Int_t iStream = 1; iStream < nStreams; iStream++) {
1247 const char* fileName = ((TObjString*)
1248 (fBkgrdFileNames->At(iStream-1)))->GetName();
1249 manager->SetInputStream(iStream, fileName);
1252 TString detStr = detectors;
1253 TString detExcl = excludeDetectors;
1254 manager->GetInputStream(0)->ImportgAlice();
1255 AliRunLoader* runLoader =
1256 AliRunLoader::GetRunLoader(manager->GetInputStream(0)->GetFolderName());
1257 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1258 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1259 AliModule* det = (AliModule*) detArray->At(iDet);
1260 if (!det || !det->IsActive()) continue;
1261 if (IsSelected(det->GetName(), detStr) &&
1262 !IsSelected(det->GetName(), detExcl)) {
1263 AliDigitizer* digitizer = det->CreateDigitizer(manager);
1266 AliError(Form("no digitizer for %s", det->GetName()));
1267 if (fStopOnError) return kFALSE;
1269 digitizer->SetRegionOfInterest(fRegionOfInterest);
1274 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1275 AliError(Form("the following detectors were not found: %s",
1277 if (fStopOnError) return kFALSE;
1280 if (!manager->GetListOfTasks()->IsEmpty()) {
1281 AliInfo("executing digitization");
1290 //_____________________________________________________________________________
1291 Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
1293 // run the digitization and produce digits from hits
1295 AliCodeTimerAuto("",0)
1297 // initialize CDB storage, run number, set CDB lock
1299 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1302 AliRunLoader* runLoader = LoadRun("READ");
1303 if (!runLoader) return kFALSE;
1305 TString detStr = detectors;
1306 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1307 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1308 AliModule* det = (AliModule*) detArray->At(iDet);
1309 if (!det || !det->IsActive()) continue;
1310 if (IsSelected(det->GetName(), detStr)) {
1311 AliInfo(Form("creating digits from hits for %s", det->GetName()));
1316 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1317 AliError(Form("the following detectors were not found: %s",
1319 if (fStopOnError) return kFALSE;
1325 //_____________________________________________________________________________
1326 Bool_t AliSimulation::WriteRawData(const char* detectors,
1327 const char* fileName,
1328 Bool_t deleteIntermediateFiles,
1331 // convert the digits to raw data
1332 // First DDL raw data files for the given detectors are created.
1333 // If a file name is given, the DDL files are then converted to a DATE file.
1334 // If deleteIntermediateFiles is true, the DDL raw files are deleted
1336 // If the file name has the extension ".root", the DATE file is converted
1338 // If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
1339 // 'selrawdata' flag can be used to enable writing of detectors raw data
1340 // accoring to the trigger cluster.
1342 AliCodeTimerAuto("",0)
1343 AliSysInfo::AddStamp("WriteRawData_Start");
1345 TString detStr = detectors;
1346 if (!WriteRawFiles(detStr.Data())) {
1347 if (fStopOnError) return kFALSE;
1349 AliSysInfo::AddStamp("WriteRawFiles");
1351 // run HLT simulation on simulated DDL raw files
1352 // and produce HLT ddl raw files to be included in date/root file
1353 // bugfix 2009-06-26: the decision whether to write HLT raw data
1354 // is taken in RunHLT. Here HLT always needs to be run in order to
1355 // create HLT digits, unless its switched off. This is due to the
1356 // special placement of the HLT between the generation of DDL files
1357 // and conversion to DATE/Root file.
1358 detStr.ReplaceAll("HLT", "");
1359 if (!fRunHLT.IsNull()) {
1361 if (fStopOnError) return kFALSE;
1364 AliSysInfo::AddStamp("WriteRawData_RunHLT");
1366 TString dateFileName(fileName);
1367 if (!dateFileName.IsNull()) {
1368 Bool_t rootOutput = dateFileName.EndsWith(".root");
1369 if (rootOutput) dateFileName += ".date";
1370 TString selDateFileName;
1372 selDateFileName = "selected.";
1373 selDateFileName+= dateFileName;
1375 if (!ConvertRawFilesToDate(dateFileName,selDateFileName)) {
1376 if (fStopOnError) return kFALSE;
1378 AliSysInfo::AddStamp("ConvertRawFilesToDate");
1379 if (deleteIntermediateFiles) {
1380 AliRunLoader* runLoader = LoadRun("READ");
1381 if (runLoader) for (Int_t iEvent = 0;
1382 iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1384 snprintf(command, 256, "rm -r raw%d", iEvent);
1385 gSystem->Exec(command);
1391 if (!ConvertDateToRoot(dateFileName, fileName)) {
1392 if (fStopOnError) return kFALSE;
1394 AliSysInfo::AddStamp("ConvertDateToRoot");
1395 if (deleteIntermediateFiles) {
1396 gSystem->Unlink(dateFileName);
1399 TString selFileName = "selected.";
1400 selFileName += fileName;
1401 if (!ConvertDateToRoot(selDateFileName, selFileName)) {
1402 if (fStopOnError) return kFALSE;
1404 if (deleteIntermediateFiles) {
1405 gSystem->Unlink(selDateFileName);
1414 //_____________________________________________________________________________
1415 Bool_t AliSimulation::WriteRawFiles(const char* detectors)
1417 // convert the digits to raw data DDL files
1419 AliCodeTimerAuto("",0)
1421 AliRunLoader* runLoader = LoadRun("READ");
1422 if (!runLoader) return kFALSE;
1424 // write raw data to DDL files
1425 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1426 AliInfo(Form("processing event %d", iEvent));
1427 runLoader->GetEvent(iEvent);
1428 TString baseDir = gSystem->WorkingDirectory();
1430 snprintf(dirName, 256, "raw%d", iEvent);
1431 gSystem->MakeDirectory(dirName);
1432 if (!gSystem->ChangeDirectory(dirName)) {
1433 AliError(Form("couldn't change to directory %s", dirName));
1434 if (fStopOnError) return kFALSE; else continue;
1437 ofstream runNbFile(Form("run%u",runLoader->GetHeader()->GetRun()));
1440 TString detStr = detectors;
1441 if (IsSelected("HLT", detStr)) {
1442 // Do nothing. "HLT" will be removed from detStr and HLT raw
1443 // data files are generated in RunHLT.
1446 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1447 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1448 AliModule* det = (AliModule*) detArray->At(iDet);
1449 if (!det || !det->IsActive()) continue;
1450 if (IsSelected(det->GetName(), detStr)) {
1451 AliInfo(Form("creating raw data from digits for %s", det->GetName()));
1456 if (!WriteTriggerRawData())
1457 if (fStopOnError) return kFALSE;
1459 gSystem->ChangeDirectory(baseDir);
1460 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1461 AliError(Form("the following detectors were not found: %s",
1463 if (fStopOnError) return kFALSE;
1472 //_____________________________________________________________________________
1473 Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
1474 const char* selDateFileName)
1476 // convert raw data DDL files to a DATE file with the program "dateStream"
1477 // The second argument is not empty when the user decides to write
1478 // the detectors raw data according to the trigger cluster.
1480 AliCodeTimerAuto("",0)
1482 char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
1484 AliError("the program dateStream was not found");
1485 if (fStopOnError) return kFALSE;
1490 AliRunLoader* runLoader = LoadRun("READ");
1491 if (!runLoader) return kFALSE;
1493 AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
1494 Bool_t selrawdata = kFALSE;
1495 if (strcmp(selDateFileName,"") != 0) selrawdata = kTRUE;
1498 // Note the option -s. It is used in order to avoid
1499 // the generation of SOR/EOR events.
1500 snprintf(command, 256, "dateStream -c -s -D -o %s -# %d -C -run %d",
1501 dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
1502 FILE* pipe = gSystem->OpenPipe(command, "w");
1505 AliError(Form("Cannot execute command: %s",command));
1509 Int_t selEvents = 0;
1510 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1512 UInt_t detectorPattern = 0;
1513 runLoader->GetEvent(iEvent);
1514 if (!runLoader->LoadTrigger()) {
1515 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1516 detectorPattern = aCTP->GetClusterMask();
1517 // Check if the event was triggered by CTP
1519 if (aCTP->GetClassMask()) selEvents++;
1523 AliWarning("No trigger can be loaded! Some fields in the event header will be empty !");
1525 AliWarning("No trigger can be loaded! Writing of selected raw data is abandoned !");
1526 selrawdata = kFALSE;
1530 fprintf(pipe, "GDC DetectorPattern %u\n", detectorPattern);
1534 // loop over detectors and DDLs
1535 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1536 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1538 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1539 Int_t ldcID = Int_t(ldc + 0.0001);
1540 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1542 char rawFileName[256];
1543 snprintf(rawFileName, 256, "raw%d/%s",
1544 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1546 // check existence and size of raw data file
1547 FILE* file = fopen(rawFileName, "rb");
1548 if (!file) continue;
1549 fseek(file, 0, SEEK_END);
1550 unsigned long size = ftell(file);
1552 if (!size) continue;
1554 if (ldcID != prevLDC) {
1555 fprintf(pipe, " LDC Id %d\n", ldcID);
1558 fprintf(pipe, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1563 Int_t result = gSystem->ClosePipe(pipe);
1565 if (!(selrawdata && selEvents > 0)) {
1567 return (result == 0);
1570 AliInfo(Form("converting selected by trigger cluster raw data DDL files to DATE file %s", selDateFileName));
1572 snprintf(command, 256, "dateStream -c -s -D -o %s -# %d -C -run %d",
1573 selDateFileName,selEvents,runLoader->GetHeader()->GetRun());
1574 FILE* pipe2 = gSystem->OpenPipe(command, "w");
1576 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1578 // Get the trigger decision and cluster
1579 UInt_t detectorPattern = 0;
1581 runLoader->GetEvent(iEvent);
1582 if (!runLoader->LoadTrigger()) {
1583 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1584 if (aCTP->GetClassMask() == 0) continue;
1585 detectorPattern = aCTP->GetClusterMask();
1586 detClust = AliDAQ::ListOfTriggeredDetectors(detectorPattern);
1587 AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
1590 fprintf(pipe2, "GDC DetectorPattern %u\n", detectorPattern);
1594 // loop over detectors and DDLs
1595 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1596 // Write only raw data from detectors that
1597 // are contained in the trigger cluster(s)
1598 if (!IsSelected(AliDAQ::DetectorName(iDet),detClust)) continue;
1600 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1602 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1603 Int_t ldcID = Int_t(ldc + 0.0001);
1604 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1606 char rawFileName[256];
1607 snprintf(rawFileName, 256, "raw%d/%s",
1608 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1610 // check existence and size of raw data file
1611 FILE* file = fopen(rawFileName, "rb");
1612 if (!file) continue;
1613 fseek(file, 0, SEEK_END);
1614 unsigned long size = ftell(file);
1616 if (!size) continue;
1618 if (ldcID != prevLDC) {
1619 fprintf(pipe2, " LDC Id %d\n", ldcID);
1622 fprintf(pipe2, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1627 Int_t result2 = gSystem->ClosePipe(pipe2);
1630 return ((result == 0) && (result2 == 0));
1633 //_____________________________________________________________________________
1634 Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
1635 const char* rootFileName)
1637 // convert a DATE file to a root file with the program "alimdc"
1640 const Int_t kDBSize = 2000000000;
1641 const Int_t kTagDBSize = 1000000000;
1642 const Bool_t kFilter = kFALSE;
1643 const Int_t kCompression = 1;
1645 char* path = gSystem->Which(gSystem->Getenv("PATH"), "alimdc");
1647 AliError("the program alimdc was not found");
1648 if (fStopOnError) return kFALSE;
1653 AliInfo(Form("converting DATE file %s to root file %s",
1654 dateFileName, rootFileName));
1656 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
1657 const char* tagDBFS = "/tmp/mdc1/tags";
1659 // User defined file system locations
1660 if (gSystem->Getenv("ALIMDC_RAWDB1"))
1661 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
1662 if (gSystem->Getenv("ALIMDC_RAWDB2"))
1663 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
1664 if (gSystem->Getenv("ALIMDC_TAGDB"))
1665 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
1667 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1668 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1669 gSystem->Exec(Form("rm -rf %s",tagDBFS));
1671 gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
1672 gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
1673 gSystem->Exec(Form("mkdir %s",tagDBFS));
1675 Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s",
1676 kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
1677 gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0], rootFileName));
1679 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1680 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1681 gSystem->Exec(Form("rm -rf %s",tagDBFS));
1683 return (result == 0);
1687 //_____________________________________________________________________________
1688 AliRunLoader* AliSimulation::LoadRun(const char* mode) const
1690 // delete existing run loaders, open a new one and load gAlice
1692 delete AliRunLoader::Instance();
1693 AliRunLoader* runLoader =
1694 AliRunLoader::Open(fGAliceFileName.Data(),
1695 AliConfig::GetDefaultEventFolderName(), mode);
1697 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1700 runLoader->LoadgAlice();
1701 runLoader->LoadHeader();
1702 gAlice = runLoader->GetAliRun();
1704 AliError(Form("no gAlice object found in file %s",
1705 fGAliceFileName.Data()));
1711 //_____________________________________________________________________________
1712 Int_t AliSimulation::GetNSignalPerBkgrd(Int_t nEvents) const
1714 // get or calculate the number of signal events per background event
1716 if (!fBkgrdFileNames) return 1;
1717 Int_t nBkgrdFiles = fBkgrdFileNames->GetEntriesFast();
1718 if (nBkgrdFiles == 0) return 1;
1720 // get the number of signal events
1722 AliRunLoader* runLoader =
1723 AliRunLoader::Open(fGAliceFileName.Data(), "SIGNAL");
1724 if (!runLoader) return 1;
1726 nEvents = runLoader->GetNumberOfEvents();
1731 for (Int_t iBkgrdFile = 0; iBkgrdFile < nBkgrdFiles; iBkgrdFile++) {
1732 // get the number of background events
1733 const char* fileName = ((TObjString*)
1734 (fBkgrdFileNames->At(iBkgrdFile)))->GetName();
1735 AliRunLoader* runLoader =
1736 AliRunLoader::Open(fileName, "BKGRD");
1737 if (!runLoader) continue;
1738 Int_t nBkgrdEvents = runLoader->GetNumberOfEvents();
1741 // get or calculate the number of signal per background events
1742 Int_t nSignalPerBkgrd = fBkgrdFileNames->At(iBkgrdFile)->GetUniqueID();
1743 if (nSignalPerBkgrd <= 0) {
1744 nSignalPerBkgrd = (nEvents-1) / nBkgrdEvents + 1;
1745 } else if (result && (result != nSignalPerBkgrd)) {
1746 AliInfo(Form("the number of signal events per background event "
1747 "will be changed from %d to %d for stream %d",
1748 nSignalPerBkgrd, result, iBkgrdFile+1));
1749 nSignalPerBkgrd = result;
1752 if (!result) result = nSignalPerBkgrd;
1753 if (nSignalPerBkgrd * nBkgrdEvents < nEvents) {
1754 AliWarning(Form("not enough background events (%d) for %d signal events "
1755 "using %d signal per background events for stream %d",
1756 nBkgrdEvents, nEvents, nSignalPerBkgrd, iBkgrdFile+1));
1763 //_____________________________________________________________________________
1764 Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
1766 // check whether detName is contained in detectors
1767 // if yes, it is removed from detectors
1769 // check if all detectors are selected
1770 if ((detectors.CompareTo("ALL") == 0) ||
1771 detectors.BeginsWith("ALL ") ||
1772 detectors.EndsWith(" ALL") ||
1773 detectors.Contains(" ALL ")) {
1778 // search for the given detector
1779 Bool_t result = kFALSE;
1780 if ((detectors.CompareTo(detName) == 0) ||
1781 detectors.BeginsWith(detName+" ") ||
1782 detectors.EndsWith(" "+detName) ||
1783 detectors.Contains(" "+detName+" ")) {
1784 detectors.ReplaceAll(detName, "");
1788 // clean up the detectors string
1789 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1790 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1791 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1796 //_____________________________________________________________________________
1797 Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName, Int_t N)
1800 // Steering routine to convert raw data in directory rawDirectory/ to fake SDigits.
1801 // These can be used for embedding of MC tracks into RAW data using the standard
1802 // merging procedure.
1804 // If an ESD file is given the reconstructed vertex is taken from it and stored in the event header.
1807 AliError("no gAlice object. Restart aliroot and try again.");
1810 if (gAlice->Modules()->GetEntries() > 0) {
1811 AliError("gAlice was already run. Restart aliroot and try again.");
1815 AliInfo(Form("initializing gAlice with config file %s",fConfigFileName.Data()));
1819 gROOT->LoadMacro(fConfigFileName.Data());
1820 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
1822 if(AliCDBManager::Instance()->GetRun() >= 0) {
1823 SetRunNumber(AliCDBManager::Instance()->GetRun());
1825 AliWarning("Run number not initialized!!");
1828 AliRunLoader::Instance()->CdGAFile();
1830 AliPDG::AddParticlesToPdgDataBase();
1832 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
1834 gAlice->GetMCApp()->Init();
1836 //Must be here because some MCs (G4) adds detectors here and not in Config.C
1837 gAlice->InitLoaders();
1838 AliRunLoader::Instance()->MakeTree("E");
1839 AliRunLoader::Instance()->LoadKinematics("RECREATE");
1840 AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
1841 AliRunLoader::Instance()->LoadHits("all","RECREATE");
1844 // Save stuff at the beginning of the file to avoid file corruption
1845 AliRunLoader::Instance()->CdGAFile();
1850 //AliCDBManager* man = AliCDBManager::Instance();
1851 //man->SetRun(0); // Should this come from rawdata header ?
1855 // Get the runloader
1856 AliRunLoader* runLoader = AliRunLoader::Instance();
1858 // Open esd file if available
1861 AliESDEvent* esd = 0;
1862 if (esdFileName && (strlen(esdFileName)>0)) {
1863 esdFile = TFile::Open(esdFileName);
1865 esd = new AliESDEvent();
1866 esdFile->GetObject("esdTree", treeESD);
1867 if (treeESD) esd->ReadFromTree(treeESD);
1872 // Create the RawReader
1873 TString fileName(rawDirectory);
1874 AliRawReader* rawReader = 0x0;
1875 if (fileName.EndsWith("/")) {
1876 rawReader = new AliRawReaderFile(fileName);
1877 } else if (fileName.EndsWith(".root")) {
1878 rawReader = new AliRawReaderRoot(fileName);
1879 } else if (!fileName.IsNull()) {
1880 rawReader = new AliRawReaderDate(fileName);
1882 if (!rawReader) return (kFALSE);
1884 // if (!fEquipIdMap.IsNull() && fRawReader)
1885 // fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1887 // Get list of detectors
1888 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1891 AliHeader* header = runLoader->GetHeader();
1895 if (!(rawReader->NextEvent())) break;
1896 runLoader->SetEventNumber(nev);
1897 runLoader->GetHeader()->Reset(rawReader->GetRunNumber(),
1899 runLoader->GetEvent(nev);
1900 AliInfo(Form("We are at event %d",nev));
1903 TString detStr = fMakeSDigits;
1904 for (iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1905 AliModule* det = (AliModule*) detArray->At(iDet);
1906 if (!det || !det->IsActive()) continue;
1907 if (IsSelected(det->GetName(), detStr)) {
1908 AliInfo(Form("Calling Raw2SDigits for %s", det->GetName()));
1909 det->Raw2SDigits(rawReader);
1916 // If ESD information available obtain reconstructed vertex and store in header.
1918 treeESD->GetEvent(nev);
1919 const AliESDVertex* esdVertex = esd->GetPrimaryVertex();
1920 Double_t position[3];
1921 esdVertex->GetXYZ(position);
1922 AliGenEventHeader* mcHeader = new AliGenEventHeader("ESD");
1925 for (Int_t i = 0; i < 3; i++) mcV[i] = position[i];
1926 mcHeader->SetPrimaryVertex(mcV);
1927 header->Reset(0,nev);
1928 header->SetGenEventHeader(mcHeader);
1929 AliInfo(Form("***** Saved vertex %f %f %f \n", position[0], position[1], position[2]));
1933 runLoader->TreeE()->Fill();
1934 AliInfo(Form("Finished event %d",nev));
1943 runLoader->CdGAFile();
1944 runLoader->WriteHeader("OVERWRITE");
1945 runLoader->WriteRunLoader();
1950 //_____________________________________________________________________________
1951 void AliSimulation::FinishRun()
1954 // Called at the end of the run.
1959 AliDebug(1, "Finish Lego");
1960 AliRunLoader::Instance()->CdGAFile();
1964 // Clean detector information
1965 TIter next(gAlice->Modules());
1966 AliModule *detector;
1967 while((detector = dynamic_cast<AliModule*>(next()))) {
1968 AliDebug(2, Form("%s->FinishRun()", detector->GetName()));
1969 detector->FinishRun();
1972 AliDebug(1, "AliRunLoader::Instance()->WriteHeader(OVERWRITE)");
1973 AliRunLoader::Instance()->WriteHeader("OVERWRITE");
1975 // Write AliRun info and all detectors parameters
1976 AliRunLoader::Instance()->CdGAFile();
1977 gAlice->Write(0,TObject::kOverwrite);//write AliRun
1978 AliRunLoader::Instance()->Write(0,TObject::kOverwrite);//write RunLoader itself
1980 if(gAlice->GetMCApp()) gAlice->GetMCApp()->FinishRun();
1981 AliRunLoader::Instance()->Synchronize();
1984 //_____________________________________________________________________________
1985 Int_t AliSimulation::GetDetIndex(const char* detector)
1987 // return the detector index corresponding to detector
1989 for (index = 0; index < fgkNDetectors ; index++) {
1990 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
1996 //_____________________________________________________________________________
1997 Bool_t AliSimulation::CreateHLT()
1999 // Init the HLT simulation.
2000 // The function loads the library and creates the instance of AliHLTSimulation.
2001 // the main reason for the decoupled creation is to set the transient OCDB
2002 // objects before the OCDB is locked
2004 // load the library dynamically
2005 gSystem->Load(ALIHLTSIMULATION_LIBRARY);
2007 // check for the library version
2008 AliHLTSimulationGetLibraryVersion_t fctVersion=(AliHLTSimulationGetLibraryVersion_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_GET_LIBRARY_VERSION));
2010 AliError(Form("can not load library %s", ALIHLTSIMULATION_LIBRARY));
2013 if (fctVersion()!= ALIHLTSIMULATION_LIBRARY_VERSION) {
2014 AliWarning(Form("%s version does not match: compiled for version %d, loaded %d", ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_LIBRARY_VERSION, fctVersion()));
2017 // print compile info
2018 typedef void (*CompileInfo)( const char*& date, const char*& time);
2019 CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
2021 const char* date="";
2022 const char* time="";
2023 (*fctInfo)(date, time);
2024 if (!date) date="unknown";
2025 if (!time) time="unknown";
2026 AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
2028 AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
2031 // create instance of the HLT simulation
2032 AliHLTSimulationCreateInstance_t fctCreate=(AliHLTSimulationCreateInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_CREATE_INSTANCE));
2033 if (fctCreate==NULL || (fpHLT=(fctCreate()))==NULL) {
2034 AliError(Form("can not create instance of HLT simulation (creator %p)", fctCreate));
2038 TString specObjects;
2039 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
2040 if (specObjects.Length()>0) specObjects+=" ";
2041 specObjects+=fSpecCDBUri[i]->GetName();
2044 AliHLTSimulationSetup_t fctSetup=(AliHLTSimulationSetup_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_SETUP));
2045 if (fctSetup==NULL || fctSetup(fpHLT, this, specObjects.Data())<0) {
2046 AliWarning(Form("failed to setup HLT simulation (function %p)", fctSetup));
2052 //_____________________________________________________________________________
2053 Bool_t AliSimulation::RunHLT()
2055 // Run the HLT simulation
2056 // HLT simulation is implemented in HLT/sim/AliHLTSimulation
2057 // Disabled if fRunHLT is empty, default vaule is "default".
2058 // AliSimulation::SetRunHLT can be used to set the options for HLT simulation
2059 // The default simulation depends on the HLT component libraries and their
2060 // corresponding agents which define components and chains to run. See
2061 // http://web.ift.uib.no/~kjeks/doc/alice-hlt-current/
2062 // http://web.ift.uib.no/~kjeks/doc/alice-hlt-current/classAliHLTModuleAgent.html
2064 // The libraries to be loaded can be specified as an option.
2066 // AliSimulation sim;
2067 // sim.SetRunHLT("libAliHLTSample.so");
2069 // will only load <tt>libAliHLTSample.so</tt>
2071 // Other available options:
2072 // \li loglevel=<i>level</i> <br>
2073 // logging level for this processing
2075 // disable redirection of log messages to AliLog class
2076 // \li config=<i>macro</i>
2077 // configuration macro
2078 // \li chains=<i>configuration</i>
2079 // comma separated list of configurations to be run during simulation
2080 // \li rawfile=<i>file</i>
2081 // source for the RawReader to be created, the default is <i>./</i> if
2082 // raw data is simulated
2086 if (!fpHLT && !CreateHLT()) {
2089 AliHLTSimulation* pHLT=fpHLT;
2091 AliRunLoader* pRunLoader = LoadRun("READ");
2092 if (!pRunLoader) return kFALSE;
2094 // initialize CDB storage, run number, set CDB lock
2095 // thats for the case of running HLT simulation without all the other steps
2096 // multiple calls are handled by the function, so we can just call
2098 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
2101 // init the HLT simulation
2103 if (fRunHLT.CompareTo("default")!=0) options=fRunHLT;
2104 TString detStr = fWriteRawData;
2105 if (!IsSelected("HLT", detStr)) {
2106 options+=" writerawfiles=";
2108 options+=" writerawfiles=HLT";
2111 if (!detStr.IsNull() && !options.Contains("rawfile=")) {
2112 // as a matter of fact, HLT will run reconstruction and needs the RawReader
2113 // in order to get detector data. By default, RawReaderFile is used to read
2114 // the already simulated ddl files. Date and Root files from the raw data
2115 // are generated after the HLT simulation.
2116 options+=" rawfile=./";
2119 AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
2120 if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, options.Data())))<0) {
2121 AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
2123 // run the HLT simulation
2124 AliHLTSimulationRun_t fctRun=(AliHLTSimulationRun_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_RUN));
2125 if (fctRun==NULL || (iResult=(fctRun(pHLT, pRunLoader)))<0) {
2126 AliError(Form("can not run HLT simulation: error %d (run %p)", iResult, fctRun));
2130 // delete the instance
2131 AliHLTSimulationDeleteInstance_t fctDelete=(AliHLTSimulationDeleteInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_DELETE_INSTANCE));
2132 if (fctDelete==NULL || fctDelete(pHLT)<0) {
2133 AliError(Form("can not delete instance of HLT simulation (creator %p)", fctDelete));
2137 return iResult>=0?kTRUE:kFALSE;
2140 //_____________________________________________________________________________
2141 Bool_t AliSimulation::RunQA()
2143 // run the QA on summable hits, digits or digits
2145 //if(!gAlice) return kFALSE;
2146 AliQAManager::QAManager()->SetRunLoader(AliRunLoader::Instance()) ;
2148 TString detectorsw("") ;
2150 AliQAManager::QAManager()->SetEventSpecie(fEventSpecie) ;
2151 detectorsw = AliQAManager::QAManager()->Run(fQADetectors.Data()) ;
2152 if ( detectorsw.IsNull() )
2157 //_____________________________________________________________________________
2158 Bool_t AliSimulation::SetRunQA(TString detAndAction)
2160 // Allows to run QA for a selected set of detectors
2161 // and a selected set of tasks among HITS, SDIGITS and DIGITS
2162 // all selected detectors run the same selected tasks
2164 if (!detAndAction.Contains(":")) {
2165 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2169 Int_t colon = detAndAction.Index(":") ;
2170 fQADetectors = detAndAction(0, colon) ;
2171 if (fQADetectors.Contains("ALL") ){
2172 TString tmp = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ;
2173 Int_t minus = fQADetectors.Last('-') ;
2174 TString toKeep = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ;
2175 TString toRemove("") ;
2176 while (minus >= 0) {
2177 toRemove = fQADetectors(minus+1, fQADetectors.Length()) ;
2178 toRemove = toRemove.Strip() ;
2179 toKeep.ReplaceAll(toRemove, "") ;
2180 fQADetectors.ReplaceAll(Form("-%s", toRemove.Data()), "") ;
2181 minus = fQADetectors.Last('-') ;
2183 fQADetectors = toKeep ;
2185 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
2186 if (fQATasks.Contains("ALL") ) {
2187 fQATasks = Form("%d %d %d", AliQAv1::kHITS, AliQAv1::kSDIGITS, AliQAv1::kDIGITS) ;
2189 fQATasks.ToUpper() ;
2191 if ( fQATasks.Contains("HIT") )
2192 tempo = Form("%d ", AliQAv1::kHITS) ;
2193 if ( fQATasks.Contains("SDIGIT") )
2194 tempo += Form("%d ", AliQAv1::kSDIGITS) ;
2195 if ( fQATasks.Contains("DIGIT") )
2196 tempo += Form("%d ", AliQAv1::kDIGITS) ;
2198 if (fQATasks.IsNull()) {
2199 AliInfo("No QA requested\n") ;
2204 TString tempo(fQATasks) ;
2205 tempo.ReplaceAll(Form("%d", AliQAv1::kHITS), AliQAv1::GetTaskName(AliQAv1::kHITS)) ;
2206 tempo.ReplaceAll(Form("%d", AliQAv1::kSDIGITS), AliQAv1::GetTaskName(AliQAv1::kSDIGITS)) ;
2207 tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITS), AliQAv1::GetTaskName(AliQAv1::kDIGITS)) ;
2208 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2210 AliQAManager::QAManager()->SetActiveDetectors(fQADetectors) ;
2211 AliQAManager::QAManager()->SetTasks(fQATasks) ;
2212 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
2213 AliQAManager::QAManager()->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
2218 //_____________________________________________________________________________
2219 void AliSimulation::ProcessEnvironmentVars()
2221 // Extract run number and random generator seed from env variables
2223 AliInfo("Processing environment variables");
2225 // Random Number seed
2227 // first check that seed is not already set
2229 if (gSystem->Getenv("CONFIG_SEED")) {
2230 fSeed = atoi(gSystem->Getenv("CONFIG_SEED"));
2233 if (gSystem->Getenv("CONFIG_SEED")) {
2234 AliInfo(Form("Seed for random number generation already set (%d)"
2235 ": CONFIG_SEED variable ignored!", fSeed));
2239 AliInfo(Form("Seed for random number generation = %d ", fSeed));
2243 // first check that run number is not already set
2245 if (gSystem->Getenv("DC_RUN")) {
2246 fRun = atoi(gSystem->Getenv("DC_RUN"));
2249 if (gSystem->Getenv("DC_RUN")) {
2250 AliInfo(Form("Run number already set (%d): DC_RUN variable ignored!", fRun));
2254 AliInfo(Form("Run number = %d", fRun));
2257 //---------------------------------------------------------------------
2258 void AliSimulation::WriteGRPEntry()
2260 // Get the necessary information from galice (generator, trigger etc) and
2261 // write a GRP entry corresponding to the settings in the Config.C used
2262 // note that Hall probes and Cavern and Surface Atmos pressures are not simulated.
2265 AliInfo("Writing global run parameters entry into the OCDB");
2267 AliGRPObject* grpObj = new AliGRPObject();
2269 grpObj->SetRunType("PHYSICS");
2270 grpObj->SetTimeStart(0);
2272 grpObj->SetTimeStart(0);
2273 grpObj->SetTimeEnd(curtime.Convert());
2274 grpObj->SetBeamEnergyIsSqrtSHalfGeV(); // new format of GRP: store sqrt(s)/2 in GeV
2276 const AliGenerator *gen = gAlice->GetMCApp()->Generator();
2282 gen->GetProjectile(projectile,a,z);
2284 gen->GetTarget(target,a,z);
2285 TString beamType = projectile + "-" + target;
2286 beamType.ReplaceAll(" ","");
2287 if (!beamType.CompareTo("-")) {
2288 grpObj->SetBeamType("UNKNOWN");
2289 grpObj->SetBeamEnergy(gen->GetEnergyCMS()/2);
2292 grpObj->SetBeamType(beamType);
2294 grpObj->SetBeamEnergy(gen->GetEnergyCMS()/2 * a / z);
2296 grpObj->SetBeamEnergy(gen->GetEnergyCMS()/2 );
2298 // Heavy ion run, the event specie is set to kHighMult
2299 fEventSpecie = AliRecoParam::kHighMult;
2300 if ((strcmp(beamType,"p-p") == 0) ||
2301 (strcmp(beamType,"p-") == 0) ||
2302 (strcmp(beamType,"-p") == 0) ||
2303 (strcmp(beamType,"P-P") == 0) ||
2304 (strcmp(beamType,"P-") == 0) ||
2305 (strcmp(beamType,"-P") == 0)) {
2306 // Proton run, the event specie is set to kLowMult
2307 fEventSpecie = AliRecoParam::kLowMult;
2311 AliWarning("Unknown beam type and energy! Setting energy to 0");
2312 grpObj->SetBeamEnergy(0);
2313 grpObj->SetBeamType("UNKNOWN");
2316 UInt_t detectorPattern = 0;
2318 TObjArray *detArray = gAlice->Detectors();
2319 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors-1; iDet++) {
2320 if (detArray->FindObject(AliDAQ::OfflineModuleName(iDet))) {
2321 detectorPattern |= (1 << iDet);
2326 if (!fTriggerConfig.IsNull())
2327 detectorPattern |= (1 << AliDAQ::DetectorID("TRG"));
2330 if (!fRunHLT.IsNull())
2331 detectorPattern |= (1 << AliDAQ::kHLTId);
2333 grpObj->SetNumberOfDetectors((Char_t)nDets);
2334 grpObj->SetDetectorMask((Int_t)detectorPattern);
2335 grpObj->SetLHCPeriod("LHC08c");
2336 grpObj->SetLHCState("STABLE_BEAMS");
2338 AliMagF *field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
2339 Float_t solenoidField = field ? TMath::Abs(field->SolenoidField()) : 0;
2341 Float_t factorSol = field ? field->GetFactorSol() : 0;
2342 Float_t currentSol = TMath::Abs(factorSol)>1E-6 ?
2343 TMath::Nint(TMath::Abs(solenoidField/factorSol))/5.*30000.*TMath::Abs(factorSol) : 0;
2345 Float_t factorDip = field ? field->GetFactorDip() : 0;
2346 Float_t currentDip = 6000.*TMath::Abs(factorDip);
2348 grpObj->SetL3Current(currentSol,(AliGRPObject::Stats)0);
2349 grpObj->SetDipoleCurrent(currentDip,(AliGRPObject::Stats)0);
2350 grpObj->SetL3Polarity(factorSol>0 ? 0:1);
2351 grpObj->SetDipolePolarity(factorDip>0 ? 0:1);
2352 if (field) grpObj->SetUniformBMap(field->IsUniform()); // for special MC with k5kGUniform map
2353 grpObj->SetPolarityConventionLHC(); // LHC convention +/+ current -> -/- field main components
2355 grpObj->SetCavernTemperature(0,(AliGRPObject::Stats)0);
2357 //grpMap->Add(new TObjString("fCavernPressure"),new TObjString("0")); ---> not inserted in simulation with the new object, since it is now an AliDCSSensor
2359 // Now store the entry in OCDB
2360 AliCDBManager* man = AliCDBManager::Instance();
2362 man->SetLock(0, fKey);
2364 AliCDBStorage* sto = man->GetStorage(fGRPWriteLocation.Data());
2367 AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun(), 1, 1);
2368 AliCDBMetaData *metadata= new AliCDBMetaData();
2370 metadata->SetResponsible("alice-off@cern.ch");
2371 metadata->SetComment("Automatically produced GRP entry for Monte Carlo");
2373 sto->Put(grpObj,id,metadata);
2374 man->SetLock(1, fKey);