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>
118 #include "AliAlignObj.h"
119 #include "AliCDBEntry.h"
120 #include "AliCDBManager.h"
121 #include "AliCDBStorage.h"
122 #include "AliCTPRawData.h"
123 #include "AliCentralTrigger.h"
124 #include "AliCentralTrigger.h"
125 #include "AliCodeTimer.h"
127 #include "AliDigitizer.h"
129 #include "AliGRPObject.h"
130 #include "AliGenEventHeader.h"
131 #include "AliGenerator.h"
132 #include "AliGeomManager.h"
133 #include "AliHLTSimulation.h"
134 #include "AliHeader.h"
136 #include "AliLegoGenerator.h"
140 #include "AliModule.h"
142 #include "AliRawReaderDate.h"
143 #include "AliRawReaderFile.h"
144 #include "AliRawReaderRoot.h"
146 #include "AliRunDigitizer.h"
147 #include "AliRunLoader.h"
148 #include "AliSimulation.h"
149 #include "AliSysInfo.h"
150 #include "AliVertexGenFile.h"
152 ClassImp(AliSimulation)
154 AliSimulation *AliSimulation::fgInstance = 0;
155 const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
157 //_____________________________________________________________________________
158 AliSimulation::AliSimulation(const char* configFileName,
159 const char* name, const char* title) :
162 fRunGeneration(kTRUE),
163 fRunSimulation(kTRUE),
164 fLoadAlignFromCDB(kTRUE),
165 fLoadAlObjsListOfDets("ALL"),
169 fMakeDigitsFromHits(""),
171 fRawDataFileName(""),
172 fDeleteIntermediateFiles(kFALSE),
173 fWriteSelRawData(kFALSE),
174 fStopOnError(kFALSE),
176 fConfigFileName(configFileName),
177 fGAliceFileName("galice.root"),
179 fBkgrdFileNames(NULL),
180 fAlignObjArray(NULL),
181 fUseBkgrdVertex(kTRUE),
182 fRegionOfInterest(kFALSE),
188 fInitCDBCalled(kFALSE),
189 fInitRunNumberCalled(kFALSE),
190 fSetRunNumberFromDataCalled(kFALSE),
191 fEmbeddingFlag(kFALSE),
197 fEventSpecie(AliRecoParam::kDefault),
198 fWriteQAExpertData(kTRUE),
200 fWriteGRPEntry(kTRUE)
202 // create simulation object with default parameters
204 SetGAliceFile("galice.root");
207 fQAManager = AliQAManager::QAManager("sim") ;
208 fQAManager->SetActiveDetectors(fQADetectors) ;
209 fQATasks = Form("%d %d %d", AliQA::kHITS, AliQA::kSDIGITS, AliQA::kDIGITS) ;
210 fQAManager->SetTasks(fQATasks) ;
213 //_____________________________________________________________________________
214 AliSimulation::~AliSimulation()
218 fEventsPerFile.Delete();
219 // if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
220 // delete fAlignObjArray; fAlignObjArray=0;
222 if (fBkgrdFileNames) {
223 fBkgrdFileNames->Delete();
224 delete fBkgrdFileNames;
227 fSpecCDBUri.Delete();
228 if (fgInstance==this) fgInstance = 0;
232 AliCodeTimer::Instance()->Print();
236 //_____________________________________________________________________________
237 void AliSimulation::SetNumberOfEvents(Int_t nEvents)
239 // set the number of events for one run
244 //_____________________________________________________________________________
245 void AliSimulation::InitQA()
247 // activate a default CDB storage
248 // First check if we have any CDB storage set, because it is used
249 // to retrieve the calibration and alignment constants
251 if (fInitCDBCalled) return;
252 fInitCDBCalled = kTRUE;
254 fQAManager = AliQAManager::QAManager("sim") ;
255 fQAManager->SetActiveDetectors(fQADetectors) ;
256 fQATasks = Form("%d %d %d", AliQA::kHITS, AliQA::kSDIGITS, AliQA::kDIGITS) ;
257 fQAManager->SetTasks(fQATasks) ;
258 if (fWriteQAExpertData)
259 fQAManager->SetWriteExpert() ;
261 if (fQAManager->IsDefaultStorageSet()) {
262 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
263 AliWarning("Default QA reference storage has been already set !");
264 AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fQARefUri.Data()));
265 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
266 fQARefUri = fQAManager->GetDefaultStorage()->GetURI();
268 if (fQARefUri.Length() > 0) {
269 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
270 AliDebug(2, Form("Default QA reference storage is set to: %s", fQARefUri.Data()));
271 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
273 fQARefUri="local://$ALICE_ROOT/QARef";
274 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
275 AliWarning("Default QA reference storage not yet set !!!!");
276 AliWarning(Form("Setting it now to: %s", fQARefUri.Data()));
277 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
279 fQAManager->SetDefaultStorage(fQARefUri);
283 //_____________________________________________________________________________
284 void AliSimulation::InitCDB()
286 // activate a default CDB storage
287 // First check if we have any CDB storage set, because it is used
288 // to retrieve the calibration and alignment constants
290 if (fInitCDBCalled) return;
291 fInitCDBCalled = kTRUE;
293 AliCDBManager* man = AliCDBManager::Instance();
294 if (man->IsDefaultStorageSet())
296 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
297 AliWarning("Default CDB storage has been already set !");
298 AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fCDBUri.Data()));
299 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
300 fCDBUri = man->GetDefaultStorage()->GetURI();
303 if (fCDBUri.Length() > 0)
305 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
306 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
307 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
309 fCDBUri="local://$ALICE_ROOT/OCDB";
310 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
311 AliWarning("Default CDB storage not yet set !!!!");
312 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
313 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
316 man->SetDefaultStorage(fCDBUri);
319 // Now activate the detector specific CDB storage locations
320 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
321 TObject* obj = fSpecCDBUri[i];
323 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
324 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
325 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
326 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
331 //_____________________________________________________________________________
332 void AliSimulation::InitRunNumber(){
333 // check run number. If not set, set it to 0 !!!!
335 if (fInitRunNumberCalled) return;
336 fInitRunNumberCalled = kTRUE;
338 AliCDBManager* man = AliCDBManager::Instance();
339 if (man->GetRun() >= 0)
341 AliFatal(Form("Run number cannot be set in AliCDBManager before start of simulation: "
342 "Use external variable DC_RUN or AliSimulation::SetRun()!"));
346 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
347 AliDebug(2, Form("Setting CDB run number to: %d",fRun));
348 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
351 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
352 AliWarning("Run number not yet set !!!!");
353 AliWarning(Form("Setting it now to: %d", fRun));
354 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
363 //_____________________________________________________________________________
364 void AliSimulation::SetCDBLock() {
365 // Set CDB lock: from now on it is forbidden to reset the run number
366 // or the default storage or to activate any further storage!
368 AliCDBManager::Instance()->SetLock(1);
371 //_____________________________________________________________________________
372 void AliSimulation::SetDefaultStorage(const char* uri) {
373 // Store the desired default CDB storage location
374 // Activate it later within the Run() method
380 //_____________________________________________________________________________
381 void AliSimulation::SetQARefDefaultStorage(const char* uri) {
382 // Store the desired default CDB storage location
383 // Activate it later within the Run() method
386 AliQA::SetQARefStorage(fQARefUri.Data()) ;
389 //_____________________________________________________________________________
390 void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
391 // Store a detector-specific CDB storage location
392 // Activate it later within the Run() method
394 AliCDBPath aPath(calibType);
395 if(!aPath.IsValid()){
396 AliError(Form("Not a valid path: %s", calibType));
400 TObject* obj = fSpecCDBUri.FindObject(calibType);
401 if (obj) fSpecCDBUri.Remove(obj);
402 fSpecCDBUri.Add(new TNamed(calibType, uri));
406 //_____________________________________________________________________________
407 void AliSimulation::SetRunNumber(Int_t run)
410 // Activate it later within the Run() method
415 //_____________________________________________________________________________
416 void AliSimulation::SetSeed(Int_t seed)
419 // Activate it later within the Run() method
424 //_____________________________________________________________________________
425 Bool_t AliSimulation::SetRunNumberFromData()
427 // Set the CDB manager run number
428 // The run number is retrieved from gAlice
430 if (fSetRunNumberFromDataCalled) return kTRUE;
431 fSetRunNumberFromDataCalled = kTRUE;
433 AliCDBManager* man = AliCDBManager::Instance();
434 Int_t runData = -1, runCDB = -1;
436 AliRunLoader* runLoader = LoadRun("READ");
437 if (!runLoader) return kFALSE;
439 runData = runLoader->GetHeader()->GetRun();
443 runCDB = man->GetRun();
445 if (runCDB != runData) {
446 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
447 AliWarning(Form("A run number was previously set in AliCDBManager: %d !", runCDB));
448 AliWarning(Form("It will be replaced with the run number got from run header: %d !", runData));
449 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
454 man->SetRun(runData);
457 if(man->GetRun() < 0) {
458 AliError("Run number not properly initalized!");
467 //_____________________________________________________________________________
468 void AliSimulation::SetConfigFile(const char* fileName)
470 // set the name of the config file
472 fConfigFileName = fileName;
475 //_____________________________________________________________________________
476 void AliSimulation::SetGAliceFile(const char* fileName)
478 // set the name of the galice file
479 // the path is converted to an absolute one if it is relative
481 fGAliceFileName = fileName;
482 if (!gSystem->IsAbsoluteFileName(fGAliceFileName)) {
483 char* absFileName = gSystem->ConcatFileName(gSystem->WorkingDirectory(),
485 fGAliceFileName = absFileName;
486 delete[] absFileName;
489 AliDebug(2, Form("galice file name set to %s", fileName));
492 //_____________________________________________________________________________
493 void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
496 // set the number of events per file for the given detector and data type
497 // ("Hits", "Summable Digits", "Digits", "Reconstructed Points" or "Tracks")
499 TNamed* obj = new TNamed(detector, type);
500 obj->SetUniqueID(nEvents);
501 fEventsPerFile.Add(obj);
504 //_____________________________________________________________________________
505 Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
507 // Read the alignment objects from CDB.
508 // Each detector is supposed to have the
509 // alignment objects in DET/Align/Data CDB path.
510 // All the detector objects are then collected,
511 // sorted by geometry level (starting from ALIC) and
512 // then applied to the TGeo geometry.
513 // Finally an overlaps check is performed.
515 if (!AliGeomManager::GetGeometry() || !AliGeomManager::GetGeometry()->IsClosed()) {
516 AliError("Can't apply the misalignment! Geometry is not loaded or it is still opened!");
520 // initialize CDB storage, run number, set CDB lock
522 // if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
525 Bool_t delRunLoader = kFALSE;
527 runLoader = LoadRun("READ");
528 if (!runLoader) return kFALSE;
529 delRunLoader = kTRUE;
532 // Export ideal geometry
533 if(!gAlice->IsRootGeometry()) AliGeomManager::GetGeometry()->Export("geometry.root");
535 // Load alignment data from CDB and apply to geometry through AliGeomManager
536 if(fLoadAlignFromCDB){
538 TString detStr = fLoadAlObjsListOfDets;
539 TString loadAlObjsListOfDets = "";
541 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
542 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
543 AliModule* det = (AliModule*) detArray->At(iDet);
544 if (!det || !det->IsActive()) continue;
545 if (IsSelected(det->GetName(), detStr)) {
546 //add det to list of dets to be aligned from CDB
547 loadAlObjsListOfDets += det->GetName();
548 loadAlObjsListOfDets += " ";
550 } // end loop over detectors
551 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
552 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
554 // Check if the array with alignment objects was
555 // provided by the user. If yes, apply the objects
556 // to the present TGeo geometry
557 if (fAlignObjArray) {
558 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
559 AliError("The misalignment of one or more volumes failed!"
560 "Compare the list of simulated detectors and the list of detector alignment data!");
561 if (delRunLoader) delete runLoader;
567 // Update the internal geometry of modules (ITS needs it)
568 TString detStr = fLoadAlObjsListOfDets;
569 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
570 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
572 AliModule* det = (AliModule*) detArray->At(iDet);
573 if (!det || !det->IsActive()) continue;
574 if (IsSelected(det->GetName(), detStr)) {
575 det->UpdateInternalGeometry();
577 } // end loop over detectors
580 if (delRunLoader) delete runLoader;
585 //_____________________________________________________________________________
586 void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
588 // add a file with background events for merging
590 TObjString* fileNameStr = new TObjString(fileName);
591 fileNameStr->SetUniqueID(nSignalPerBkgrd);
592 if (!fBkgrdFileNames) fBkgrdFileNames = new TObjArray;
593 fBkgrdFileNames->Add(fileNameStr);
596 void AliSimulation::EmbedInto(const char* fileName, Int_t nSignalPerBkgrd)
598 // add a file with background events for embeddin
599 MergeWith(fileName, nSignalPerBkgrd);
600 fEmbeddingFlag = kTRUE;
603 //_____________________________________________________________________________
604 Bool_t AliSimulation::Run(Int_t nEvents)
606 // run the generation, simulation and digitization
611 // Load run number and seed from environmental vars
612 ProcessEnvironmentVars();
614 gRandom->SetSeed(fSeed);
616 if (nEvents > 0) fNEvents = nEvents;
618 // generation and simulation -> hits
619 if (fRunGeneration) {
620 if (!RunSimulation()) if (fStopOnError) return kFALSE;
623 // initialize CDB storage from external environment
624 // (either CDB manager or AliSimulation setters),
625 // if not already done in RunSimulation()
628 // Set run number in CDBManager from data
629 // From this point on the run number must be always loaded from data!
630 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
632 // Set CDB lock: from now on it is forbidden to reset the run number
633 // or the default storage or to activate any further storage!
636 // If RunSimulation was not called, load the geometry and misalign it
637 if (!AliGeomManager::GetGeometry()) {
638 // Initialize the geometry manager
639 AliGeomManager::LoadGeometry("geometry.root");
641 // // Check that the consistency of symbolic names for the activated subdetectors
642 // // in the geometry loaded by AliGeomManager
643 // AliRunLoader* runLoader = LoadRun("READ");
644 // if (!runLoader) return kFALSE;
646 // TString detsToBeChecked = "";
647 // TObjArray* detArray = runLoader->GetAliRun()->Detectors();
648 // for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
649 // AliModule* det = (AliModule*) detArray->At(iDet);
650 // if (!det || !det->IsActive()) continue;
651 // detsToBeChecked += det->GetName();
652 // detsToBeChecked += " ";
653 // } // end loop over detectors
654 // if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
655 if(!AliGeomManager::CheckSymNamesLUT("ALL"))
656 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
658 if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
660 if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
664 // hits -> summable digits
665 AliSysInfo::AddStamp("Start_sdigitization");
666 if (!fMakeSDigits.IsNull()) {
667 if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
670 AliSysInfo::AddStamp("Stop_sdigitization");
672 AliSysInfo::AddStamp("Start_digitization");
673 // summable digits -> digits
674 if (!fMakeDigits.IsNull()) {
675 if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
676 if (fStopOnError) return kFALSE;
679 AliSysInfo::AddStamp("Stop_digitization");
684 if (!fMakeDigitsFromHits.IsNull()) {
685 if (fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
686 AliWarning(Form("Merging and direct creation of digits from hits "
687 "was selected for some detectors. "
688 "No merging will be done for the following detectors: %s",
689 fMakeDigitsFromHits.Data()));
691 if (!RunHitsDigitization(fMakeDigitsFromHits)) {
692 if (fStopOnError) return kFALSE;
699 if (!RunTrigger(fMakeTrigger,fMakeDigits)) {
700 if (fStopOnError) return kFALSE;
705 // digits -> raw data
706 if (!fWriteRawData.IsNull()) {
707 if (!WriteRawData(fWriteRawData, fRawDataFileName,
708 fDeleteIntermediateFiles,fWriteSelRawData)) {
709 if (fStopOnError) return kFALSE;
714 // run HLT simulation on simulated digit data if raw data is not
715 // simulated, otherwise its called as part of WriteRawData
716 if (!fRunHLT.IsNull() && fWriteRawData.IsNull()) {
718 if (fStopOnError) return kFALSE;
724 Bool_t rv = RunQA() ;
730 // Cleanup of CDB manager: cache and active storages!
731 AliCDBManager::Instance()->ClearCache();
736 //_______________________________________________________________________
737 Bool_t AliSimulation::RunLego(const char *setup, Int_t nc1, Float_t c1min,
738 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
739 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener, Int_t nev)
742 // Generates lego plots of:
743 // - radiation length map phi vs theta
744 // - radiation length map phi vs eta
745 // - interaction length map
746 // - g/cm2 length map
748 // ntheta bins in theta, eta
749 // themin minimum angle in theta (degrees)
750 // themax maximum angle in theta (degrees)
752 // phimin minimum angle in phi (degrees)
753 // phimax maximum angle in phi (degrees)
754 // rmin minimum radius
755 // rmax maximum radius
758 // The number of events generated = ntheta*nphi
759 // run input parameters in macro setup (default="Config.C")
761 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
764 <img src="picts/AliRunLego1.gif">
769 <img src="picts/AliRunLego2.gif">
774 <img src="picts/AliRunLego3.gif">
779 // run the generation and simulation
783 // initialize CDB storage and run number from external environment
784 // (either CDB manager or AliSimulation setters)
790 AliError("no gAlice object. Restart aliroot and try again.");
793 if (gAlice->Modules()->GetEntries() > 0) {
794 AliError("gAlice was already run. Restart aliroot and try again.");
798 AliInfo(Form("initializing gAlice with config file %s",
799 fConfigFileName.Data()));
802 if (nev == -1) nev = nc1 * nc2;
804 // check if initialisation has been done
805 // If runloader has been initialized, set the number of events per file to nc1 * nc2
808 if (!gener) gener = new AliLegoGenerator();
810 // Configure Generator
812 gener->SetRadiusRange(rmin, rmax);
813 gener->SetZMax(zmax);
814 gener->SetCoor1Range(nc1, c1min, c1max);
815 gener->SetCoor2Range(nc2, c2min, c2max);
819 fLego = new AliLego("lego",gener);
821 //__________________________________________________________________________
825 gROOT->LoadMacro(setup);
826 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
828 if(AliCDBManager::Instance()->GetRun() >= 0) {
829 SetRunNumber(AliCDBManager::Instance()->GetRun());
831 AliWarning("Run number not initialized!!");
834 AliRunLoader::Instance()->CdGAFile();
836 AliPDG::AddParticlesToPdgDataBase();
838 gAlice->GetMCApp()->Init();
840 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
843 //Must be here because some MCs (G4) adds detectors here and not in Config.C
844 gAlice->InitLoaders();
845 AliRunLoader::Instance()->MakeTree("E");
848 // Save stuff at the beginning of the file to avoid file corruption
849 AliRunLoader::Instance()->CdGAFile();
852 //Save current generator
853 AliGenerator *gen=gAlice->GetMCApp()->Generator();
854 gAlice->GetMCApp()->ResetGenerator(gener);
855 //Prepare MC for Lego Run
861 AliRunLoader::Instance()->SetNumberOfEventsPerFile(nev);
862 gMC->ProcessRun(nev);
864 // End of this run, close files
866 // Restore current generator
867 gAlice->GetMCApp()->ResetGenerator(gen);
868 // Delete Lego Object
874 //_____________________________________________________________________________
875 Bool_t AliSimulation::RunTrigger(const char* config, const char* detectors)
881 // initialize CDB storage from external environment
882 // (either CDB manager or AliSimulation setters),
883 // if not already done in RunSimulation()
886 // Set run number in CDBManager from data
887 // From this point on the run number must be always loaded from data!
888 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
890 // Set CDB lock: from now on it is forbidden to reset the run number
891 // or the default storage or to activate any further storage!
894 AliRunLoader* runLoader = LoadRun("READ");
895 if (!runLoader) return kFALSE;
896 TString trconfiguration = config;
898 if (trconfiguration.IsNull()) {
899 if (strcmp(gAlice->GetTriggerDescriptor(),"")) {
900 trconfiguration = gAlice->GetTriggerDescriptor();
903 AliWarning("No trigger descriptor is specified. Loading the one that is in the CDB.");
906 runLoader->MakeTree( "GG" );
907 AliCentralTrigger* aCTP = runLoader->GetTrigger();
908 // Load Configuration
909 if (!aCTP->LoadConfiguration( trconfiguration ))
913 if( !aCTP->RunTrigger( runLoader , detectors ) ) {
925 //_____________________________________________________________________________
926 Bool_t AliSimulation::WriteTriggerRawData()
928 // Writes the CTP (trigger) DDL raw data
929 // Details of the format are given in the
930 // trigger TDR - pages 134 and 135.
931 AliCTPRawData writer;
937 //_____________________________________________________________________________
938 Bool_t AliSimulation::RunSimulation(Int_t nEvents)
940 // run the generation and simulation
944 // initialize CDB storage and run number from external environment
945 // (either CDB manager or AliSimulation setters)
951 AliError("no gAlice object. Restart aliroot and try again.");
954 if (gAlice->Modules()->GetEntries() > 0) {
955 AliError("gAlice was already run. Restart aliroot and try again.");
959 AliInfo(Form("initializing gAlice with config file %s",
960 fConfigFileName.Data()));
963 // Initialize ALICE Simulation run
968 gROOT->LoadMacro(fConfigFileName.Data());
969 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
971 if(AliCDBManager::Instance()->GetRun() >= 0) {
972 AliRunLoader::Instance()->SetRunNumber(AliCDBManager::Instance()->GetRun());
974 AliWarning("Run number not initialized!!");
977 AliRunLoader::Instance()->CdGAFile();
979 AliPDG::AddParticlesToPdgDataBase();
981 gAlice->GetMCApp()->Init();
983 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
985 //Must be here because some MCs (G4) adds detectors here and not in Config.C
986 gAlice->InitLoaders();
987 AliRunLoader::Instance()->MakeTree("E");
988 AliRunLoader::Instance()->LoadKinematics("RECREATE");
989 AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
990 AliRunLoader::Instance()->LoadHits("all","RECREATE");
992 // Save stuff at the beginning of the file to avoid file corruption
993 AliRunLoader::Instance()->CdGAFile();
995 gAlice->SetEventNrInRun(-1); //important - we start Begin event from increasing current number in run
996 //___________________________________________________________________________________________
998 // Get the trigger descriptor string
999 // Either from AliSimulation or from
1001 if (fMakeTrigger.IsNull()) {
1002 if (strcmp(gAlice->GetTriggerDescriptor(),""))
1003 fMakeTrigger = gAlice->GetTriggerDescriptor();
1006 gAlice->SetTriggerDescriptor(fMakeTrigger.Data());
1008 // Set run number in CDBManager
1009 AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
1011 AliRunLoader* runLoader = AliRunLoader::Instance();
1013 AliError(Form("gAlice has no run loader object. "
1014 "Check your config file: %s", fConfigFileName.Data()));
1017 SetGAliceFile(runLoader->GetFileName());
1019 // Misalign geometry
1020 #if ROOT_VERSION_CODE < 331527
1021 AliGeomManager::SetGeometry(gGeoManager);
1023 // Check that the consistency of symbolic names for the activated subdetectors
1024 // in the geometry loaded by AliGeomManager
1025 TString detsToBeChecked = "";
1026 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1027 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1028 AliModule* det = (AliModule*) detArray->At(iDet);
1029 if (!det || !det->IsActive()) continue;
1030 detsToBeChecked += det->GetName();
1031 detsToBeChecked += " ";
1032 } // end loop over detectors
1033 if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
1034 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
1035 MisalignGeometry(runLoader);
1038 // AliRunLoader* runLoader = AliRunLoader::Instance();
1039 // if (!runLoader) {
1040 // AliError(Form("gAlice has no run loader object. "
1041 // "Check your config file: %s", fConfigFileName.Data()));
1044 // SetGAliceFile(runLoader->GetFileName());
1046 if (!gAlice->GetMCApp()->Generator()) {
1047 AliError(Form("gAlice has no generator object. "
1048 "Check your config file: %s", fConfigFileName.Data()));
1052 // Write GRP entry corresponding to the setting found in Cofig.C
1056 if (nEvents <= 0) nEvents = fNEvents;
1058 // get vertex from background file in case of merging
1059 if (fUseBkgrdVertex &&
1060 fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
1061 Int_t signalPerBkgrd = GetNSignalPerBkgrd(nEvents);
1062 const char* fileName = ((TObjString*)
1063 (fBkgrdFileNames->At(0)))->GetName();
1064 AliInfo(Form("The vertex will be taken from the background "
1065 "file %s with nSignalPerBackground = %d",
1066 fileName, signalPerBkgrd));
1067 AliVertexGenFile* vtxGen = new AliVertexGenFile(fileName, signalPerBkgrd);
1068 gAlice->GetMCApp()->Generator()->SetVertexGenerator(vtxGen);
1071 if (!fRunSimulation) {
1072 gAlice->GetMCApp()->Generator()->SetTrackingFlag(0);
1075 // set the number of events per file for given detectors and data types
1076 for (Int_t i = 0; i < fEventsPerFile.GetEntriesFast(); i++) {
1077 if (!fEventsPerFile[i]) continue;
1078 const char* detName = fEventsPerFile[i]->GetName();
1079 const char* typeName = fEventsPerFile[i]->GetTitle();
1080 TString loaderName(detName);
1081 loaderName += "Loader";
1082 AliLoader* loader = runLoader->GetLoader(loaderName);
1084 AliError(Form("RunSimulation", "no loader for %s found\n"
1085 "Number of events per file not set for %s %s",
1086 detName, typeName, detName));
1089 AliDataLoader* dataLoader =
1090 loader->GetDataLoader(typeName);
1092 AliError(Form("no data loader for %s found\n"
1093 "Number of events per file not set for %s %s",
1094 typeName, detName, typeName));
1097 dataLoader->SetNumberOfEventsPerFile(fEventsPerFile[i]->GetUniqueID());
1098 AliDebug(1, Form("number of events per file set to %d for %s %s",
1099 fEventsPerFile[i]->GetUniqueID(), detName, typeName));
1102 AliInfo("running gAlice");
1103 AliSysInfo::AddStamp("Start_simulation");
1105 // Create the Root Tree with one branch per detector
1106 //Hits moved to begin event -> now we are crating separate tree for each event
1108 gMC->ProcessRun(nEvents);
1110 // End of this run, close files
1111 if(nEvents>0) FinishRun();
1113 AliSysInfo::AddStamp("Stop_simulation");
1119 //_____________________________________________________________________________
1120 Bool_t AliSimulation::RunSDigitization(const char* detectors)
1122 // run the digitization and produce summable digits
1123 static Int_t eventNr=0;
1124 AliCodeTimerAuto("")
1126 // initialize CDB storage, run number, set CDB lock
1128 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1131 AliRunLoader* runLoader = LoadRun();
1132 if (!runLoader) return kFALSE;
1134 TString detStr = detectors;
1135 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1136 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1137 AliModule* det = (AliModule*) detArray->At(iDet);
1138 if (!det || !det->IsActive()) continue;
1139 if (IsSelected(det->GetName(), detStr)) {
1140 AliInfo(Form("creating summable digits for %s", det->GetName()));
1141 AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
1142 det->Hits2SDigits();
1143 AliSysInfo::AddStamp(Form("Digit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
1147 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1148 AliError(Form("the following detectors were not found: %s",
1150 if (fStopOnError) return kFALSE;
1159 //_____________________________________________________________________________
1160 Bool_t AliSimulation::RunDigitization(const char* detectors,
1161 const char* excludeDetectors)
1163 // run the digitization and produce digits from sdigits
1165 AliCodeTimerAuto("")
1167 // initialize CDB storage, run number, set CDB lock
1169 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1172 delete AliRunLoader::Instance();
1177 if (fBkgrdFileNames) nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
1178 Int_t signalPerBkgrd = GetNSignalPerBkgrd();
1179 AliRunDigitizer* manager = new AliRunDigitizer(nStreams, signalPerBkgrd);
1180 // manager->SetEmbeddingFlag(fEmbeddingFlag);
1181 manager->SetInputStream(0, fGAliceFileName.Data());
1182 for (Int_t iStream = 1; iStream < nStreams; iStream++) {
1183 const char* fileName = ((TObjString*)
1184 (fBkgrdFileNames->At(iStream-1)))->GetName();
1185 manager->SetInputStream(iStream, fileName);
1188 TString detStr = detectors;
1189 TString detExcl = excludeDetectors;
1190 manager->GetInputStream(0)->ImportgAlice();
1191 AliRunLoader* runLoader =
1192 AliRunLoader::GetRunLoader(manager->GetInputStream(0)->GetFolderName());
1193 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1194 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1195 AliModule* det = (AliModule*) detArray->At(iDet);
1196 if (!det || !det->IsActive()) continue;
1197 if (IsSelected(det->GetName(), detStr) &&
1198 !IsSelected(det->GetName(), detExcl)) {
1199 AliDigitizer* digitizer = det->CreateDigitizer(manager);
1202 AliError(Form("no digitizer for %s", det->GetName()));
1203 if (fStopOnError) return kFALSE;
1205 digitizer->SetRegionOfInterest(fRegionOfInterest);
1210 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1211 AliError(Form("the following detectors were not found: %s",
1213 if (fStopOnError) return kFALSE;
1216 if (!manager->GetListOfTasks()->IsEmpty()) {
1217 AliInfo("executing digitization");
1226 //_____________________________________________________________________________
1227 Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
1229 // run the digitization and produce digits from hits
1231 AliCodeTimerAuto("")
1233 // initialize CDB storage, run number, set CDB lock
1235 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1238 AliRunLoader* runLoader = LoadRun("READ");
1239 if (!runLoader) return kFALSE;
1241 TString detStr = detectors;
1242 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1243 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1244 AliModule* det = (AliModule*) detArray->At(iDet);
1245 if (!det || !det->IsActive()) continue;
1246 if (IsSelected(det->GetName(), detStr)) {
1247 AliInfo(Form("creating digits from hits for %s", det->GetName()));
1252 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1253 AliError(Form("the following detectors were not found: %s",
1255 if (fStopOnError) return kFALSE;
1261 //_____________________________________________________________________________
1262 Bool_t AliSimulation::WriteRawData(const char* detectors,
1263 const char* fileName,
1264 Bool_t deleteIntermediateFiles,
1267 // convert the digits to raw data
1268 // First DDL raw data files for the given detectors are created.
1269 // If a file name is given, the DDL files are then converted to a DATE file.
1270 // If deleteIntermediateFiles is true, the DDL raw files are deleted
1272 // If the file name has the extension ".root", the DATE file is converted
1274 // If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
1275 // 'selrawdata' flag can be used to enable writing of detectors raw data
1276 // accoring to the trigger cluster.
1278 AliCodeTimerAuto("")
1280 TString detStr = detectors;
1281 if (!WriteRawFiles(detStr.Data())) {
1282 if (fStopOnError) return kFALSE;
1285 // run HLT simulation on simulated DDL raw files
1286 // and produce HLT ddl raw files to be included in date/root file
1287 if (IsSelected("HLT", detStr) && !fRunHLT.IsNull()) {
1289 if (fStopOnError) return kFALSE;
1293 TString dateFileName(fileName);
1294 if (!dateFileName.IsNull()) {
1295 Bool_t rootOutput = dateFileName.EndsWith(".root");
1296 if (rootOutput) dateFileName += ".date";
1297 TString selDateFileName;
1299 selDateFileName = "selected.";
1300 selDateFileName+= dateFileName;
1302 if (!ConvertRawFilesToDate(dateFileName,selDateFileName)) {
1303 if (fStopOnError) return kFALSE;
1305 if (deleteIntermediateFiles) {
1306 AliRunLoader* runLoader = LoadRun("READ");
1307 if (runLoader) for (Int_t iEvent = 0;
1308 iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1310 sprintf(command, "rm -r raw%d", iEvent);
1311 gSystem->Exec(command);
1316 if (!ConvertDateToRoot(dateFileName, fileName)) {
1317 if (fStopOnError) return kFALSE;
1319 if (deleteIntermediateFiles) {
1320 gSystem->Unlink(dateFileName);
1323 TString selFileName = "selected.";
1324 selFileName += fileName;
1325 if (!ConvertDateToRoot(selDateFileName, selFileName)) {
1326 if (fStopOnError) return kFALSE;
1328 if (deleteIntermediateFiles) {
1329 gSystem->Unlink(selDateFileName);
1338 //_____________________________________________________________________________
1339 Bool_t AliSimulation::WriteRawFiles(const char* detectors)
1341 // convert the digits to raw data DDL files
1343 AliCodeTimerAuto("")
1345 AliRunLoader* runLoader = LoadRun("READ");
1346 if (!runLoader) return kFALSE;
1348 // write raw data to DDL files
1349 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1350 AliInfo(Form("processing event %d", iEvent));
1351 runLoader->GetEvent(iEvent);
1352 TString baseDir = gSystem->WorkingDirectory();
1354 sprintf(dirName, "raw%d", iEvent);
1355 gSystem->MakeDirectory(dirName);
1356 if (!gSystem->ChangeDirectory(dirName)) {
1357 AliError(Form("couldn't change to directory %s", dirName));
1358 if (fStopOnError) return kFALSE; else continue;
1361 ofstream runNbFile(Form("run%u",runLoader->GetHeader()->GetRun()));
1364 TString detStr = detectors;
1365 if (IsSelected("HLT", detStr)) {
1366 // Do nothing. "HLT" will be removed from detStr and HLT raw
1367 // data files are generated in RunHLT.
1370 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1371 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1372 AliModule* det = (AliModule*) detArray->At(iDet);
1373 if (!det || !det->IsActive()) continue;
1374 if (IsSelected(det->GetName(), detStr)) {
1375 AliInfo(Form("creating raw data from digits for %s", det->GetName()));
1380 if (!WriteTriggerRawData())
1381 if (fStopOnError) return kFALSE;
1383 gSystem->ChangeDirectory(baseDir);
1384 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1385 AliError(Form("the following detectors were not found: %s",
1387 if (fStopOnError) return kFALSE;
1396 //_____________________________________________________________________________
1397 Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
1398 const char* selDateFileName)
1400 // convert raw data DDL files to a DATE file with the program "dateStream"
1401 // The second argument is not empty when the user decides to write
1402 // the detectors raw data according to the trigger cluster.
1404 AliCodeTimerAuto("")
1406 char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
1408 AliError("the program dateStream was not found");
1409 if (fStopOnError) return kFALSE;
1414 AliRunLoader* runLoader = LoadRun("READ");
1415 if (!runLoader) return kFALSE;
1417 AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
1418 Bool_t selrawdata = kFALSE;
1419 if (strcmp(selDateFileName,"") != 0) selrawdata = kTRUE;
1422 // Note the option -s. It is used in order to avoid
1423 // the generation of SOR/EOR events.
1424 sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
1425 dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
1426 FILE* pipe = gSystem->OpenPipe(command, "w");
1429 AliError(Form("Cannot execute command: %s",command));
1433 Int_t selEvents = 0;
1434 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1436 UInt_t detectorPattern = 0;
1437 runLoader->GetEvent(iEvent);
1438 if (!runLoader->LoadTrigger()) {
1439 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1440 detectorPattern = aCTP->GetClusterMask();
1441 // Check if the event was triggered by CTP
1443 if (aCTP->GetClassMask()) selEvents++;
1447 AliWarning("No trigger can be loaded! Some fields in the event header will be empty !");
1449 AliWarning("No trigger can be loaded! Writing of selected raw data is abandoned !");
1450 selrawdata = kFALSE;
1454 fprintf(pipe, "GDC DetectorPattern %u\n", detectorPattern);
1458 // loop over detectors and DDLs
1459 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1460 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1462 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1463 Int_t ldcID = Int_t(ldc + 0.0001);
1464 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1466 char rawFileName[256];
1467 sprintf(rawFileName, "raw%d/%s",
1468 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1470 // check existence and size of raw data file
1471 FILE* file = fopen(rawFileName, "rb");
1472 if (!file) continue;
1473 fseek(file, 0, SEEK_END);
1474 unsigned long size = ftell(file);
1476 if (!size) continue;
1478 if (ldcID != prevLDC) {
1479 fprintf(pipe, " LDC Id %d\n", ldcID);
1482 fprintf(pipe, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1487 Int_t result = gSystem->ClosePipe(pipe);
1489 if (!(selrawdata && selEvents > 0)) {
1491 return (result == 0);
1494 AliInfo(Form("converting selected by trigger cluster raw data DDL files to DATE file %s", selDateFileName));
1496 sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
1497 selDateFileName,selEvents,runLoader->GetHeader()->GetRun());
1498 FILE* pipe2 = gSystem->OpenPipe(command, "w");
1500 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1502 // Get the trigger decision and cluster
1503 UInt_t detectorPattern = 0;
1505 runLoader->GetEvent(iEvent);
1506 if (!runLoader->LoadTrigger()) {
1507 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1508 if (aCTP->GetClassMask() == 0) continue;
1509 detectorPattern = aCTP->GetClusterMask();
1510 detClust = AliDAQ::ListOfTriggeredDetectors(detectorPattern);
1511 AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
1514 fprintf(pipe2, "GDC DetectorPattern %u\n", detectorPattern);
1518 // loop over detectors and DDLs
1519 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1520 // Write only raw data from detectors that
1521 // are contained in the trigger cluster(s)
1522 if (!IsSelected(AliDAQ::DetectorName(iDet),detClust)) continue;
1524 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1526 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1527 Int_t ldcID = Int_t(ldc + 0.0001);
1528 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1530 char rawFileName[256];
1531 sprintf(rawFileName, "raw%d/%s",
1532 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1534 // check existence and size of raw data file
1535 FILE* file = fopen(rawFileName, "rb");
1536 if (!file) continue;
1537 fseek(file, 0, SEEK_END);
1538 unsigned long size = ftell(file);
1540 if (!size) continue;
1542 if (ldcID != prevLDC) {
1543 fprintf(pipe2, " LDC Id %d\n", ldcID);
1546 fprintf(pipe2, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1551 Int_t result2 = gSystem->ClosePipe(pipe2);
1554 return ((result == 0) && (result2 == 0));
1557 //_____________________________________________________________________________
1558 Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
1559 const char* rootFileName)
1561 // convert a DATE file to a root file with the program "alimdc"
1564 const Int_t kDBSize = 2000000000;
1565 const Int_t kTagDBSize = 1000000000;
1566 const Bool_t kFilter = kFALSE;
1567 const Int_t kCompression = 1;
1569 char* path = gSystem->Which(gSystem->Getenv("PATH"), "alimdc");
1571 AliError("the program alimdc was not found");
1572 if (fStopOnError) return kFALSE;
1577 AliInfo(Form("converting DATE file %s to root file %s",
1578 dateFileName, rootFileName));
1580 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
1581 const char* tagDBFS = "/tmp/mdc1/tags";
1583 // User defined file system locations
1584 if (gSystem->Getenv("ALIMDC_RAWDB1"))
1585 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
1586 if (gSystem->Getenv("ALIMDC_RAWDB2"))
1587 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
1588 if (gSystem->Getenv("ALIMDC_TAGDB"))
1589 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
1591 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1592 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1593 gSystem->Exec(Form("rm -rf %s",tagDBFS));
1595 gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
1596 gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
1597 gSystem->Exec(Form("mkdir %s",tagDBFS));
1599 Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s",
1600 kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
1601 gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0], rootFileName));
1603 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1604 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1605 gSystem->Exec(Form("rm -rf %s",tagDBFS));
1607 return (result == 0);
1611 //_____________________________________________________________________________
1612 AliRunLoader* AliSimulation::LoadRun(const char* mode) const
1614 // delete existing run loaders, open a new one and load gAlice
1616 delete AliRunLoader::Instance();
1617 AliRunLoader* runLoader =
1618 AliRunLoader::Open(fGAliceFileName.Data(),
1619 AliConfig::GetDefaultEventFolderName(), mode);
1621 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1624 runLoader->LoadgAlice();
1625 runLoader->LoadHeader();
1626 gAlice = runLoader->GetAliRun();
1628 AliError(Form("no gAlice object found in file %s",
1629 fGAliceFileName.Data()));
1635 //_____________________________________________________________________________
1636 Int_t AliSimulation::GetNSignalPerBkgrd(Int_t nEvents) const
1638 // get or calculate the number of signal events per background event
1640 if (!fBkgrdFileNames) return 1;
1641 Int_t nBkgrdFiles = fBkgrdFileNames->GetEntriesFast();
1642 if (nBkgrdFiles == 0) return 1;
1644 // get the number of signal events
1646 AliRunLoader* runLoader =
1647 AliRunLoader::Open(fGAliceFileName.Data(), "SIGNAL");
1648 if (!runLoader) return 1;
1650 nEvents = runLoader->GetNumberOfEvents();
1655 for (Int_t iBkgrdFile = 0; iBkgrdFile < nBkgrdFiles; iBkgrdFile++) {
1656 // get the number of background events
1657 const char* fileName = ((TObjString*)
1658 (fBkgrdFileNames->At(iBkgrdFile)))->GetName();
1659 AliRunLoader* runLoader =
1660 AliRunLoader::Open(fileName, "BKGRD");
1661 if (!runLoader) continue;
1662 Int_t nBkgrdEvents = runLoader->GetNumberOfEvents();
1665 // get or calculate the number of signal per background events
1666 Int_t nSignalPerBkgrd = fBkgrdFileNames->At(iBkgrdFile)->GetUniqueID();
1667 if (nSignalPerBkgrd <= 0) {
1668 nSignalPerBkgrd = (nEvents-1) / nBkgrdEvents + 1;
1669 } else if (result && (result != nSignalPerBkgrd)) {
1670 AliInfo(Form("the number of signal events per background event "
1671 "will be changed from %d to %d for stream %d",
1672 nSignalPerBkgrd, result, iBkgrdFile+1));
1673 nSignalPerBkgrd = result;
1676 if (!result) result = nSignalPerBkgrd;
1677 if (nSignalPerBkgrd * nBkgrdEvents < nEvents) {
1678 AliWarning(Form("not enough background events (%d) for %d signal events "
1679 "using %d signal per background events for stream %d",
1680 nBkgrdEvents, nEvents, nSignalPerBkgrd, iBkgrdFile+1));
1687 //_____________________________________________________________________________
1688 Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
1690 // check whether detName is contained in detectors
1691 // if yes, it is removed from detectors
1693 // check if all detectors are selected
1694 if ((detectors.CompareTo("ALL") == 0) ||
1695 detectors.BeginsWith("ALL ") ||
1696 detectors.EndsWith(" ALL") ||
1697 detectors.Contains(" ALL ")) {
1702 // search for the given detector
1703 Bool_t result = kFALSE;
1704 if ((detectors.CompareTo(detName) == 0) ||
1705 detectors.BeginsWith(detName+" ") ||
1706 detectors.EndsWith(" "+detName) ||
1707 detectors.Contains(" "+detName+" ")) {
1708 detectors.ReplaceAll(detName, "");
1712 // clean up the detectors string
1713 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1714 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1715 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1720 //_____________________________________________________________________________
1721 Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName)
1724 // Steering routine to convert raw data in directory rawDirectory/ to fake SDigits.
1725 // These can be used for embedding of MC tracks into RAW data using the standard
1726 // merging procedure.
1728 // If an ESD file is given the reconstructed vertex is taken from it and stored in the event header.
1731 AliError("no gAlice object. Restart aliroot and try again.");
1734 if (gAlice->Modules()->GetEntries() > 0) {
1735 AliError("gAlice was already run. Restart aliroot and try again.");
1739 AliInfo(Form("initializing gAlice with config file %s",fConfigFileName.Data()));
1743 gROOT->LoadMacro(fConfigFileName.Data());
1744 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
1746 if(AliCDBManager::Instance()->GetRun() >= 0) {
1747 SetRunNumber(AliCDBManager::Instance()->GetRun());
1749 AliWarning("Run number not initialized!!");
1752 AliRunLoader::Instance()->CdGAFile();
1754 AliPDG::AddParticlesToPdgDataBase();
1756 gAlice->GetMCApp()->Init();
1758 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
1760 //Must be here because some MCs (G4) adds detectors here and not in Config.C
1761 gAlice->InitLoaders();
1762 AliRunLoader::Instance()->MakeTree("E");
1763 AliRunLoader::Instance()->LoadKinematics("RECREATE");
1764 AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
1765 AliRunLoader::Instance()->LoadHits("all","RECREATE");
1767 // Save stuff at the beginning of the file to avoid file corruption
1768 AliRunLoader::Instance()->CdGAFile();
1773 //AliCDBManager* man = AliCDBManager::Instance();
1774 //man->SetRun(0); // Should this come from rawdata header ?
1778 // Get the runloader
1779 AliRunLoader* runLoader = AliRunLoader::Instance();
1781 // Open esd file if available
1782 TFile* esdFile = TFile::Open(esdFileName);
1783 Bool_t esdOK = (esdFile != 0);
1784 AliESD* esd = new AliESD;
1787 treeESD = (TTree*) esdFile->Get("esdTree");
1789 AliWarning("No ESD tree found");
1792 treeESD->SetBranchAddress("ESD", &esd);
1796 // Create the RawReader
1797 TString fileName(rawDirectory);
1798 AliRawReader* rawReader = 0x0;
1799 if (fileName.EndsWith("/")) {
1800 rawReader = new AliRawReaderFile(fileName);
1801 } else if (fileName.EndsWith(".root")) {
1802 rawReader = new AliRawReaderRoot(fileName);
1803 } else if (!fileName.IsNull()) {
1804 rawReader = new AliRawReaderDate(fileName);
1806 // if (!fEquipIdMap.IsNull() && fRawReader)
1807 // fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
1809 // Get list of detectors
1810 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1813 AliHeader* header = runLoader->GetHeader();
1815 TString detStr = fMakeSDigits;
1819 if (!(rawReader->NextEvent())) break;
1822 for (iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1823 AliModule* det = (AliModule*) detArray->At(iDet);
1824 if (!det || !det->IsActive()) continue;
1825 if (IsSelected(det->GetName(), detStr)) {
1826 AliInfo(Form("Calling Raw2SDigits for %s\n", det->GetName()));
1827 det->Raw2SDigits(rawReader);
1834 // If ESD information available obtain reconstructed vertex and store in header.
1836 treeESD->GetEvent(nev);
1837 const AliESDVertex* esdVertex = esd->GetPrimaryVertex();
1838 Double_t position[3];
1839 esdVertex->GetXYZ(position);
1840 AliGenEventHeader* mcHeader = new AliGenEventHeader("ESD");
1843 for (Int_t i = 0; i < 3; i++) mcV[i] = position[i];
1844 mcHeader->SetPrimaryVertex(mcV);
1845 header->Reset(0,nev);
1846 header->SetGenEventHeader(mcHeader);
1847 printf("***** Saved vertex %f %f %f \n", position[0], position[1], position[2]);
1852 runLoader->TreeE()->Fill();
1853 runLoader->SetNextEvent();
1859 runLoader->CdGAFile();
1860 runLoader->WriteHeader("OVERWRITE");
1861 runLoader->WriteRunLoader();
1866 //_____________________________________________________________________________
1867 void AliSimulation::FinishRun()
1870 // Called at the end of the run.
1875 AliDebug(1, "Finish Lego");
1876 AliRunLoader::Instance()->CdGAFile();
1880 // Clean detector information
1881 TIter next(gAlice->Modules());
1882 AliModule *detector;
1883 while((detector = dynamic_cast<AliModule*>(next()))) {
1884 AliDebug(2, Form("%s->FinishRun()", detector->GetName()));
1885 detector->FinishRun();
1888 AliDebug(1, "AliRunLoader::Instance()->WriteHeader(OVERWRITE)");
1889 AliRunLoader::Instance()->WriteHeader("OVERWRITE");
1891 // Write AliRun info and all detectors parameters
1892 AliRunLoader::Instance()->CdGAFile();
1893 gAlice->Write(0,TObject::kOverwrite);//write AliRun
1894 AliRunLoader::Instance()->Write(0,TObject::kOverwrite);//write RunLoader itself
1896 if(gAlice->GetMCApp()) gAlice->GetMCApp()->FinishRun();
1897 AliRunLoader::Instance()->Synchronize();
1900 //_____________________________________________________________________________
1901 Int_t AliSimulation::GetDetIndex(const char* detector)
1903 // return the detector index corresponding to detector
1905 for (index = 0; index < fgkNDetectors ; index++) {
1906 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
1912 //_____________________________________________________________________________
1913 Bool_t AliSimulation::RunHLT()
1915 // Run the HLT simulation
1916 // HLT simulation is implemented in HLT/sim/AliHLTSimulation
1917 // Disabled if fRunHLT is empty, default vaule is "default".
1918 // AliSimulation::SetRunHLT can be used to set the options for HLT simulation
1919 // The default simulation depends on the HLT component libraries and their
1920 // corresponding agents which define components and chains to run. See
1921 // http://web.ift.uib.no/~kjeks/doc/alice-hlt-current/
1922 // http://web.ift.uib.no/~kjeks/doc/alice-hlt-current/classAliHLTModuleAgent.html
1924 // The libraries to be loaded can be specified as an option.
1926 // AliSimulation sim;
1927 // sim.SetRunHLT("libAliHLTSample.so");
1929 // will only load <tt>libAliHLTSample.so</tt>
1931 // Other available options:
1932 // \li loglevel=<i>level</i> <br>
1933 // logging level for this processing
1935 // disable redirection of log messages to AliLog class
1936 // \li config=<i>macro</i>
1937 // configuration macro
1938 // \li chains=<i>configuration</i>
1939 // comma separated list of configurations to be run during simulation
1940 // \li rawfile=<i>file</i>
1941 // source for the RawReader to be created, the default is <i>./</i> if
1942 // raw data is simulated
1945 AliRunLoader* pRunLoader = LoadRun("READ");
1946 if (!pRunLoader) return kFALSE;
1948 // initialize CDB storage, run number, set CDB lock
1950 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1953 // load the library dynamically
1954 gSystem->Load(ALIHLTSIMULATION_LIBRARY);
1956 // check for the library version
1957 AliHLTSimulationGetLibraryVersion_t fctVersion=(AliHLTSimulationGetLibraryVersion_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_GET_LIBRARY_VERSION));
1959 AliError(Form("can not load library %s", ALIHLTSIMULATION_LIBRARY));
1962 if (fctVersion()!= ALIHLTSIMULATION_LIBRARY_VERSION) {
1963 AliError(Form("%s version does not match: compiled for version %d, loaded %d", ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_LIBRARY_VERSION, fctVersion()));
1967 // print compile info
1968 typedef void (*CompileInfo)( char*& date, char*& time);
1969 CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
1973 (*fctInfo)(date,time);
1974 if (!date) {date=new Char_t[8]; strcpy(date,"unknown");}
1975 if (!time) {time=new Char_t[8]; strcpy(time,"unknown");}
1976 AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
1980 AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
1983 // create instance of the HLT simulation
1984 AliHLTSimulationCreateInstance_t fctCreate=(AliHLTSimulationCreateInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_CREATE_INSTANCE));
1985 AliHLTSimulation* pHLT=NULL;
1986 if (fctCreate==NULL || (pHLT=(fctCreate()))==NULL) {
1987 AliError(Form("can not create instance of HLT simulation (creator %p)", fctCreate));
1991 // init the HLT simulation
1993 if (fRunHLT.CompareTo("default")!=0) options=fRunHLT;
1994 TString detStr = fWriteRawData;
1995 if (!IsSelected("HLT", detStr)) {
1996 options+=" writerawfiles=";
1998 options+=" writerawfiles=HLT";
2001 if (!detStr.IsNull() && !options.Contains("rawfile=")) {
2002 // as a matter of fact, HLT will run reconstruction and needs the RawReader
2003 // in order to get detector data. By default, RawReaderFile is used to read
2004 // the already simulated ddl files. Date and Root files from the raw data
2005 // are generated after the HLT simulation.
2006 options+=" rawfile=./";
2009 AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
2010 if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, options.Data())))<0) {
2011 AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
2013 // run the HLT simulation
2014 AliHLTSimulationRun_t fctRun=(AliHLTSimulationRun_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_RUN));
2015 if (fctRun==NULL || (iResult=(fctRun(pHLT, pRunLoader)))<0) {
2016 AliError(Form("can not run HLT simulation: error %d (run %p)", iResult, fctRun));
2020 // delete the instance
2021 AliHLTSimulationDeleteInstance_t fctDelete=(AliHLTSimulationDeleteInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_DELETE_INSTANCE));
2022 if (fctDelete==NULL || fctDelete(pHLT)<0) {
2023 AliError(Form("can not delete instance of HLT simulation (creator %p)", fctDelete));
2027 return iResult>=0?kTRUE:kFALSE;
2030 //_____________________________________________________________________________
2031 Bool_t AliSimulation::RunQA()
2033 // run the QA on summable hits, digits or digits
2035 if(!gAlice) return kFALSE;
2036 fQAManager->SetRunLoader(AliRunLoader::Instance()) ;
2038 TString detectorsw("") ;
2040 fQAManager->SetEventSpecie(fEventSpecie) ;
2041 detectorsw = fQAManager->Run(fQADetectors.Data()) ;
2042 if ( detectorsw.IsNull() )
2047 //_____________________________________________________________________________
2048 Bool_t AliSimulation::SetRunQA(TString detAndAction)
2050 // Allows to run QA for a selected set of detectors
2051 // and a selected set of tasks among HITS, SDIGITS and DIGITS
2052 // all selected detectors run the same selected tasks
2054 if (!detAndAction.Contains(":")) {
2055 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2059 Int_t colon = detAndAction.Index(":") ;
2060 fQADetectors = detAndAction(0, colon) ;
2061 if (fQADetectors.Contains("ALL") )
2062 fQADetectors = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ;
2063 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
2064 if (fQATasks.Contains("ALL") ) {
2065 fQATasks = Form("%d %d %d", AliQA::kHITS, AliQA::kSDIGITS, AliQA::kDIGITS) ;
2067 fQATasks.ToUpper() ;
2069 if ( fQATasks.Contains("HIT") )
2070 tempo = Form("%d ", AliQA::kHITS) ;
2071 if ( fQATasks.Contains("SDIGIT") )
2072 tempo += Form("%d ", AliQA::kSDIGITS) ;
2073 if ( fQATasks.Contains("DIGIT") )
2074 tempo += Form("%d ", AliQA::kDIGITS) ;
2076 if (fQATasks.IsNull()) {
2077 AliInfo("No QA requested\n") ;
2082 TString tempo(fQATasks) ;
2083 tempo.ReplaceAll(Form("%d", AliQA::kHITS), AliQA::GetTaskName(AliQA::kHITS)) ;
2084 tempo.ReplaceAll(Form("%d", AliQA::kSDIGITS), AliQA::GetTaskName(AliQA::kSDIGITS)) ;
2085 tempo.ReplaceAll(Form("%d", AliQA::kDIGITS), AliQA::GetTaskName(AliQA::kDIGITS)) ;
2086 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2088 fQAManager->SetActiveDetectors(fQADetectors) ;
2089 fQAManager->SetTasks(fQATasks) ;
2090 for (Int_t det = 0 ; det < AliQA::kNDET ; det++)
2091 fQAManager->SetWriteExpert(AliQA::DETECTORINDEX_t(det)) ;
2096 //_____________________________________________________________________________
2097 void AliSimulation::ProcessEnvironmentVars()
2099 // Extract run number and random generator seed from env variables
2101 AliInfo("Processing environment variables");
2103 // Random Number seed
2105 // first check that seed is not already set
2107 if (gSystem->Getenv("CONFIG_SEED")) {
2108 fSeed = atoi(gSystem->Getenv("CONFIG_SEED"));
2111 if (gSystem->Getenv("CONFIG_SEED")) {
2112 AliInfo(Form("Seed for random number generation already set (%d)"
2113 ": CONFIG_SEED variable ignored!", fSeed));
2117 AliInfo(Form("Seed for random number generation = %d ", fSeed));
2121 // first check that run number is not already set
2123 if (gSystem->Getenv("DC_RUN")) {
2124 fRun = atoi(gSystem->Getenv("DC_RUN"));
2127 if (gSystem->Getenv("DC_RUN")) {
2128 AliInfo(Form("Run number already set (%d): DC_RUN variable ignored!", fRun));
2132 AliInfo(Form("Run number = %d", fRun));
2135 //---------------------------------------------------------------------
2136 void AliSimulation::WriteGRPEntry()
2138 // Get the necessary information from galice (generator, trigger etc) and
2139 // write a GRP entry corresponding to the settings in the Config.C used
2140 // note that Hall probes and Cavern and Surface Atmos pressures are not simulated.
2143 AliInfo("Writing global run parameters entry into the OCDB");
2145 AliGRPObject* grpObj = new AliGRPObject();
2147 grpObj->SetRunType("PHYSICS");
2148 grpObj->SetTimeStart(0);
2149 grpObj->SetTimeEnd(9999);
2151 const AliGenerator *gen = gAlice->GetMCApp()->Generator();
2153 grpObj->SetBeamEnergy(gen->GetEnergyCMS());
2156 gen->GetProjectile(projectile,a,z);
2158 gen->GetTarget(target,a,z);
2159 TString beamType = projectile + "-" + target;
2160 beamType.ReplaceAll(" ","");
2161 if (!beamType.CompareTo("-")) {
2162 grpObj->SetBeamType("UNKNOWN");
2165 grpObj->SetBeamType(beamType);
2166 // Heavy ion run, the event specie is set to kHighMult
2167 fEventSpecie = AliRecoParam::kHighMult;
2168 if ((strcmp(beamType,"p-p") == 0) ||
2169 (strcmp(beamType,"p-") == 0) ||
2170 (strcmp(beamType,"-p") == 0) ||
2171 (strcmp(beamType,"P-P") == 0) ||
2172 (strcmp(beamType,"P-") == 0) ||
2173 (strcmp(beamType,"-P") == 0)) {
2174 // Proton run, the event specie is set to kLowMult
2175 fEventSpecie = AliRecoParam::kLowMult;
2179 AliWarning("Unknown beam type and energy! Setting energy to 0");
2180 grpObj->SetBeamEnergy(0);
2181 grpObj->SetBeamType("UNKNOWN");
2184 UInt_t detectorPattern = 0;
2186 TObjArray *detArray = gAlice->Detectors();
2187 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors-1; iDet++) {
2188 if (detArray->FindObject(AliDAQ::OfflineModuleName(iDet))) {
2189 detectorPattern |= (1 << iDet);
2194 if (!fMakeTrigger.IsNull() || strcmp(gAlice->GetTriggerDescriptor(),""))
2195 detectorPattern |= (1 << AliDAQ::DetectorID("TRG"));
2198 if (!fRunHLT.IsNull())
2199 detectorPattern |= (1 << AliDAQ::kHLTId);
2201 grpObj->SetNumberOfDetectors((Char_t)nDets);
2202 grpObj->SetDetectorMask((Int_t)detectorPattern);
2203 grpObj->SetLHCPeriod("LHC08c");
2204 grpObj->SetLHCState("STABLE_BEAMS");
2205 grpObj->SetLHCLuminosity(0,(AliGRPObject::Stats)0);
2206 grpObj->SetBeamIntensity(0,(AliGRPObject::Stats)0);
2208 AliMagF *field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
2209 Float_t solenoidField = field ? TMath::Abs(field->SolenoidField()) : 0;
2210 Float_t factor = field ? field->Factor() : 0;
2211 Float_t l3current = TMath::Abs(factor)*solenoidField*30000./5.;
2212 grpObj->SetL3Current(l3current,(AliGRPObject::Stats)0);
2215 grpObj->SetL3Polarity(0);
2216 grpObj->SetDipolePolarity(0);
2219 grpObj->SetL3Polarity(1);
2220 grpObj->SetDipolePolarity(1);
2223 if (TMath::Abs(factor) != 0)
2224 grpObj->SetDipoleCurrent(6000,(AliGRPObject::Stats)0);
2226 grpObj->SetDipoleCurrent(0,(AliGRPObject::Stats)0);
2228 grpObj->SetCavernTemperature(0,(AliGRPObject::Stats)0);
2230 //grpMap->Add(new TObjString("fCavernPressure"),new TObjString("0")); ---> not inserted in simulation with the new object, since it is now an AliDCSSensor
2232 // Now store the entry in OCDB
2233 AliCDBManager* man = AliCDBManager::Instance();
2235 AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun(), 1, 1);
2236 AliCDBMetaData *metadata= new AliCDBMetaData();
2238 metadata->SetResponsible("alice-off@cern.ch");
2239 metadata->SetComment("Automatically produced GRP entry for Monte Carlo");
2241 man->Put(grpObj,id,metadata);