Reducing verbosity: AliInfo --> AliDebug
[u/mrichter/AliRoot.git] / STEER / AliSimulation.cxx
CommitLineData
85a5290f 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18///////////////////////////////////////////////////////////////////////////////
19// //
20// class for running generation, simulation and digitization //
21// //
22// Hits, sdigits and digits are created for all detectors by typing: //
23// //
24// AliSimulation sim; //
25// sim.Run(); //
26// //
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 //
29// can be set by //
30// //
31// sim.SetNumberOfEvents(n); //
32// //
95601147 33// The name of the configuration file can be passed as argument to the //
34// AliSimulation constructor or can be specified by //
85a5290f 35// //
36// sim.SetConfigFile("..."); //
37// //
38// The generation of particles and the simulation of detector hits can be //
39// switched on or off by //
40// //
41// sim.SetRunGeneration(kTRUE); // generation of primary particles //
42// sim.SetRunSimulation(kFALSE); // but no tracking //
43// //
44// For which detectors sdigits and digits will be created, can be steered //
45// by //
46// //
47// sim.SetMakeSDigits("ALL"); // make sdigits for all detectors //
48// sim.SetMakeDigits("ITS TPC"); // make digits only for ITS and TPC //
49// //
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. //
54// //
55// The creation of digits from hits instead of from sdigits can be selected //
56// by //
57// //
58// sim.SetMakeDigitsFromHits("TRD"); //
59// //
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. //
63// //
05526d44 64// Background events can be merged by calling //
85a5290f 65// //
66// sim.MergeWith("background/galice.root", 2); //
67// //
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. //
05526d44 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. //
85a5290f 74// //
0421c3d1 75// The output of raw data can be switched on by calling //
76// //
77// sim.SetWriteRawData("MUON"); // write raw data for MUON //
78// //
06c7e392 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 //
86// kTRUE. //
87// //
0421c3d1 88// The methods RunSimulation, RunSDigitization, RunDigitization, //
89// RunHitsDigitization and WriteRawData can be used to run only parts of //
06c7e392 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. //
95601147 93// //
18b43626 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 //
96// by calling //
97// //
98// sim.SetEventsPerFile("PHOS", "Reconstructed Points", 3); //
99// //
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. //
105// //
85a5290f 106///////////////////////////////////////////////////////////////////////////////
107
3e2e3ece 108#include <TCint.h>
109#include <TFile.h>
f7a1cc68 110#include <TGeoGlobalMagField.h>
e8d02863 111#include <TGeoManager.h>
85a5290f 112#include <TObjString.h>
fc7e1b1c 113#include <TROOT.h>
3e2e3ece 114#include <TSystem.h>
115#include <TVirtualMC.h>
116#include <TVirtualMCApplication.h>
85a5290f 117
3e2e3ece 118#include "AliAlignObj.h"
e8d02863 119#include "AliCDBEntry.h"
120#include "AliCDBManager.h"
3e2e3ece 121#include "AliCDBStorage.h"
122#include "AliCTPRawData.h"
123#include "AliCentralTrigger.h"
e8d02863 124#include "AliCentralTrigger.h"
3e2e3ece 125#include "AliCodeTimer.h"
362c9d61 126#include "AliDAQ.h"
af7ba10c 127#include "AliDigitizer.h"
3e2e3ece 128#include "AliESD.h"
129#include "AliGRPObject.h"
130#include "AliGenEventHeader.h"
af7ba10c 131#include "AliGenerator.h"
3e2e3ece 132#include "AliGeomManager.h"
133#include "AliHLTSimulation.h"
134#include "AliHeader.h"
f7a1cc68 135#include "AliLego.h"
136#include "AliLegoGenerator.h"
e8d02863 137#include "AliLog.h"
3e2e3ece 138#include "AliMC.h"
139#include "AliMagF.h"
af7ba10c 140#include "AliModule.h"
3e2e3ece 141#include "AliPDG.h"
142#include "AliRawReaderDate.h"
143#include "AliRawReaderFile.h"
144#include "AliRawReaderRoot.h"
af7ba10c 145#include "AliRun.h"
146#include "AliRunDigitizer.h"
147#include "AliRunLoader.h"
148#include "AliSimulation.h"
27fc67fa 149#include "AliSysInfo.h"
3e2e3ece 150#include "AliVertexGenFile.h"
85a5290f 151
152ClassImp(AliSimulation)
153
b856a511 154AliSimulation *AliSimulation::fgInstance = 0;
5b188f2f 155const char* AliSimulation::fgkDetectorName[AliSimulation::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
85a5290f 156
157//_____________________________________________________________________________
795e4a22 158AliSimulation::AliSimulation(const char* configFileName,
95601147 159 const char* name, const char* title) :
160 TNamed(name, title),
161
162 fRunGeneration(kTRUE),
163 fRunSimulation(kTRUE),
024cf675 164 fLoadAlignFromCDB(kTRUE),
25be1e5c 165 fLoadAlObjsListOfDets("ALL"),
95601147 166 fMakeSDigits("ALL"),
167 fMakeDigits("ALL"),
a5a091ce 168 fMakeTrigger(""),
95601147 169 fMakeDigitsFromHits(""),
0421c3d1 170 fWriteRawData(""),
06c7e392 171 fRawDataFileName(""),
172 fDeleteIntermediateFiles(kFALSE),
67327b72 173 fWriteSelRawData(kFALSE),
95601147 174 fStopOnError(kFALSE),
95601147 175 fNEvents(1),
176 fConfigFileName(configFileName),
177 fGAliceFileName("galice.root"),
18b43626 178 fEventsPerFile(),
95601147 179 fBkgrdFileNames(NULL),
995ad051 180 fAlignObjArray(NULL),
04bae0a0 181 fUseBkgrdVertex(kTRUE),
024cf675 182 fRegionOfInterest(kFALSE),
795e4a22 183 fCDBUri(""),
f1c1204d 184 fQARefUri(""),
ca30848f 185 fSpecCDBUri(),
795e4a22 186 fRun(-1),
187 fSeed(0),
188 fInitCDBCalled(kFALSE),
189 fInitRunNumberCalled(kFALSE),
190 fSetRunNumberFromDataCalled(kFALSE),
cae21299 191 fEmbeddingFlag(kFALSE),
3e2e3ece 192 fLego(NULL),
e3b20d9a 193 fQADetectors("ALL"),
194 fQATasks("ALL"),
b03591ab 195 fQAManager(NULL),
759c1df1 196 fRunQA(kTRUE),
57acd2d2 197 fEventSpecie(AliRecoParam::kDefault),
75373542 198 fWriteQAExpertData(kTRUE),
fc7e1b1c 199 fRunHLT("default"),
200 fWriteGRPEntry(kTRUE)
85a5290f 201{
202// create simulation object with default parameters
b856a511 203 fgInstance = this;
0421c3d1 204 SetGAliceFile("galice.root");
5b188f2f 205
206// for QA
b03591ab 207 fQAManager = AliQAManager::QAManager("sim") ;
208 fQAManager->SetActiveDetectors(fQADetectors) ;
4e25ac79 209 fQATasks = Form("%d %d %d", AliQAv1::kHITS, AliQAv1::kSDIGITS, AliQAv1::kDIGITS) ;
b03591ab 210 fQAManager->SetTasks(fQATasks) ;
85a5290f 211}
212
213//_____________________________________________________________________________
85a5290f 214AliSimulation::~AliSimulation()
215{
216// clean up
217
18b43626 218 fEventsPerFile.Delete();
024cf675 219// if(fAlignObjArray) fAlignObjArray->Delete(); // fAlignObjArray->RemoveAll() ???
220// delete fAlignObjArray; fAlignObjArray=0;
18b43626 221
95601147 222 if (fBkgrdFileNames) {
223 fBkgrdFileNames->Delete();
224 delete fBkgrdFileNames;
225 }
ec92bee0 226
227 fSpecCDBUri.Delete();
b856a511 228 if (fgInstance==this) fgInstance = 0;
87932dab 229
b03591ab 230 delete fQAManager ;
940d8e5f 231
87932dab 232 AliCodeTimer::Instance()->Print();
85a5290f 233}
234
235
236//_____________________________________________________________________________
237void AliSimulation::SetNumberOfEvents(Int_t nEvents)
238{
239// set the number of events for one run
240
241 fNEvents = nEvents;
242}
243
244//_____________________________________________________________________________
f1c1204d 245void AliSimulation::InitQA()
246{
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
250
251 if (fInitCDBCalled) return;
252 fInitCDBCalled = kTRUE;
253
254 fQAManager = AliQAManager::QAManager("sim") ;
255 fQAManager->SetActiveDetectors(fQADetectors) ;
4e25ac79 256 fQATasks = Form("%d %d %d", AliQAv1::kHITS, AliQAv1::kSDIGITS, AliQAv1::kDIGITS) ;
75373542 257 fQAManager->SetTasks(fQATasks) ;
258 if (fWriteQAExpertData)
259 fQAManager->SetWriteExpert() ;
f1c1204d 260
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();
267 } else {
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, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
272 } else {
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("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
278 }
279 fQAManager->SetDefaultStorage(fQARefUri);
280 }
281}
282
283//_____________________________________________________________________________
795e4a22 284void AliSimulation::InitCDB()
024cf675 285{
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
289
795e4a22 290 if (fInitCDBCalled) return;
291 fInitCDBCalled = kTRUE;
292
024cf675 293 AliCDBManager* man = AliCDBManager::Instance();
ec92bee0 294 if (man->IsDefaultStorageSet())
024cf675 295 {
ec92bee0 296 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
297 AliWarning("Default CDB storage has been already set !");
ced249e6 298 AliWarning(Form("Ignoring the default storage declared in AliSimulation: %s",fCDBUri.Data()));
ec92bee0 299 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
795e4a22 300 fCDBUri = man->GetDefaultStorage()->GetURI();
ec92bee0 301 }
302 else {
795e4a22 303 if (fCDBUri.Length() > 0)
304 {
305 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
306 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
307 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
308 } else {
162637e4 309 fCDBUri="local://$ALICE_ROOT/OCDB";
795e4a22 310 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
311 AliWarning("Default CDB storage not yet set !!!!");
312 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
313 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
314
315 }
ec92bee0 316 man->SetDefaultStorage(fCDBUri);
317 }
318
319 // Now activate the detector specific CDB storage locations
320 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
321 TObject* obj = fSpecCDBUri[i];
322 if (!obj) continue;
b8ec52f6 323 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
324 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
325 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
c3a7b59a 326 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
ec92bee0 327 }
795e4a22 328
024cf675 329}
330
331//_____________________________________________________________________________
795e4a22 332void AliSimulation::InitRunNumber(){
333// check run number. If not set, set it to 0 !!!!
334
335 if (fInitRunNumberCalled) return;
336 fInitRunNumberCalled = kTRUE;
337
338 AliCDBManager* man = AliCDBManager::Instance();
339 if (man->GetRun() >= 0)
340 {
8c8fbdcd 341 AliFatal(Form("Run number cannot be set in AliCDBManager before start of simulation: "
342 "Use external variable DC_RUN or AliSimulation::SetRun()!"));
795e4a22 343 }
8c8fbdcd 344
345 if(fRun >= 0) {
795e4a22 346 AliDebug(2, Form("Setting CDB run number to: %d",fRun));
8c8fbdcd 347 } else {
795e4a22 348 fRun=0;
76c8e8d6 349 AliWarning(Form("Run number not yet set !!!! Setting it now to: %d",
350 fRun));
795e4a22 351 }
8c8fbdcd 352 man->SetRun(fRun);
024cf675 353
795e4a22 354 man->Print();
024cf675 355
356}
357
358//_____________________________________________________________________________
795e4a22 359void AliSimulation::SetCDBLock() {
360 // Set CDB lock: from now on it is forbidden to reset the run number
361 // or the default storage or to activate any further storage!
362
363 AliCDBManager::Instance()->SetLock(1);
364}
365
366//_____________________________________________________________________________
367void AliSimulation::SetDefaultStorage(const char* uri) {
f1c1204d 368 // Store the desired default CDB storage location
369 // Activate it later within the Run() method
370
795e4a22 371 fCDBUri = uri;
f1c1204d 372
373}
00aa02d5 374
f1c1204d 375//_____________________________________________________________________________
376void AliSimulation::SetQARefDefaultStorage(const char* uri) {
377 // Store the desired default CDB storage location
378 // Activate it later within the Run() method
379
380 fQARefUri = uri;
4e25ac79 381 AliQAv1::SetQARefStorage(fQARefUri.Data()) ;
00aa02d5 382}
383
384//_____________________________________________________________________________
c3a7b59a 385void AliSimulation::SetSpecificStorage(const char* calibType, const char* uri) {
ec92bee0 386// Store a detector-specific CDB storage location
387// Activate it later within the Run() method
024cf675 388
c3a7b59a 389 AliCDBPath aPath(calibType);
390 if(!aPath.IsValid()){
391 AliError(Form("Not a valid path: %s", calibType));
392 return;
393 }
394
395 TObject* obj = fSpecCDBUri.FindObject(calibType);
ec92bee0 396 if (obj) fSpecCDBUri.Remove(obj);
c3a7b59a 397 fSpecCDBUri.Add(new TNamed(calibType, uri));
024cf675 398
399}
400
401//_____________________________________________________________________________
795e4a22 402void AliSimulation::SetRunNumber(Int_t run)
403{
404// sets run number
405// Activate it later within the Run() method
406
407 fRun = run;
408}
409
410//_____________________________________________________________________________
411void AliSimulation::SetSeed(Int_t seed)
412{
413// sets seed number
414// Activate it later within the Run() method
415
416 fSeed = seed;
417}
418
419//_____________________________________________________________________________
420Bool_t AliSimulation::SetRunNumberFromData()
421{
422 // Set the CDB manager run number
423 // The run number is retrieved from gAlice
424
425 if (fSetRunNumberFromDataCalled) return kTRUE;
426 fSetRunNumberFromDataCalled = kTRUE;
427
428 AliCDBManager* man = AliCDBManager::Instance();
429 Int_t runData = -1, runCDB = -1;
430
431 AliRunLoader* runLoader = LoadRun("READ");
432 if (!runLoader) return kFALSE;
433 else {
d3b3a3b2 434 runData = runLoader->GetHeader()->GetRun();
795e4a22 435 delete runLoader;
436 }
437
438 runCDB = man->GetRun();
439 if(runCDB >= 0) {
440 if (runCDB != runData) {
441 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
442 AliWarning(Form("A run number was previously set in AliCDBManager: %d !", runCDB));
443 AliWarning(Form("It will be replaced with the run number got from run header: %d !", runData));
444 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
445 }
446
447 }
448
449 man->SetRun(runData);
450 fRun = runData;
451
452 if(man->GetRun() < 0) {
453 AliError("Run number not properly initalized!");
454 return kFALSE;
455 }
456
457 man->Print();
458
459 return kTRUE;
460}
461
462//_____________________________________________________________________________
85a5290f 463void AliSimulation::SetConfigFile(const char* fileName)
464{
465// set the name of the config file
466
467 fConfigFileName = fileName;
468}
469
470//_____________________________________________________________________________
0421c3d1 471void AliSimulation::SetGAliceFile(const char* fileName)
472{
473// set the name of the galice file
474// the path is converted to an absolute one if it is relative
475
476 fGAliceFileName = fileName;
477 if (!gSystem->IsAbsoluteFileName(fGAliceFileName)) {
478 char* absFileName = gSystem->ConcatFileName(gSystem->WorkingDirectory(),
479 fGAliceFileName);
480 fGAliceFileName = absFileName;
481 delete[] absFileName;
482 }
ac1671c0 483
484 AliDebug(2, Form("galice file name set to %s", fileName));
0421c3d1 485}
486
487//_____________________________________________________________________________
18b43626 488void AliSimulation::SetEventsPerFile(const char* detector, const char* type,
489 Int_t nEvents)
490{
491// set the number of events per file for the given detector and data type
492// ("Hits", "Summable Digits", "Digits", "Reconstructed Points" or "Tracks")
493
494 TNamed* obj = new TNamed(detector, type);
495 obj->SetUniqueID(nEvents);
496 fEventsPerFile.Add(obj);
497}
498
499//_____________________________________________________________________________
6bae477a 500Bool_t AliSimulation::MisalignGeometry(AliRunLoader *runLoader)
501{
502 // Read the alignment objects from CDB.
503 // Each detector is supposed to have the
504 // alignment objects in DET/Align/Data CDB path.
505 // All the detector objects are then collected,
506 // sorted by geometry level (starting from ALIC) and
507 // then applied to the TGeo geometry.
508 // Finally an overlaps check is performed.
509
74ae4297 510 if (!AliGeomManager::GetGeometry() || !AliGeomManager::GetGeometry()->IsClosed()) {
511 AliError("Can't apply the misalignment! Geometry is not loaded or it is still opened!");
0717eed2 512 return kFALSE;
513 }
795e4a22 514
515 // initialize CDB storage, run number, set CDB lock
516 InitCDB();
517// if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
518 SetCDBLock();
519
6bae477a 520 Bool_t delRunLoader = kFALSE;
521 if (!runLoader) {
522 runLoader = LoadRun("READ");
523 if (!runLoader) return kFALSE;
524 delRunLoader = kTRUE;
525 }
795e4a22 526
b856a511 527 // Export ideal geometry
ced249e6 528 if(!gAlice->IsRootGeometry()) AliGeomManager::GetGeometry()->Export("geometry.root");
b856a511 529
25be1e5c 530 // Load alignment data from CDB and apply to geometry through AliGeomManager
6bae477a 531 if(fLoadAlignFromCDB){
25be1e5c 532
533 TString detStr = fLoadAlObjsListOfDets;
534 TString loadAlObjsListOfDets = "";
535
536 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
537 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
538 AliModule* det = (AliModule*) detArray->At(iDet);
539 if (!det || !det->IsActive()) continue;
540 if (IsSelected(det->GetName(), detStr)) {
0717eed2 541 //add det to list of dets to be aligned from CDB
542 loadAlObjsListOfDets += det->GetName();
543 loadAlObjsListOfDets += " ";
25be1e5c 544 }
545 } // end loop over detectors
53dd3c3d 546 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
45daac75 547 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
25be1e5c 548 }else{
549 // Check if the array with alignment objects was
550 // provided by the user. If yes, apply the objects
551 // to the present TGeo geometry
552 if (fAlignObjArray) {
45daac75 553 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
0717eed2 554 AliError("The misalignment of one or more volumes failed!"
555 "Compare the list of simulated detectors and the list of detector alignment data!");
556 if (delRunLoader) delete runLoader;
557 return kFALSE;
6bae477a 558 }
559 }
6bae477a 560 }
561
ef7ff1f9 562 // Update the internal geometry of modules (ITS needs it)
25be1e5c 563 TString detStr = fLoadAlObjsListOfDets;
ef7ff1f9 564 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
565 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
566
567 AliModule* det = (AliModule*) detArray->At(iDet);
568 if (!det || !det->IsActive()) continue;
569 if (IsSelected(det->GetName(), detStr)) {
570 det->UpdateInternalGeometry();
571 }
572 } // end loop over detectors
573
574
6bae477a 575 if (delRunLoader) delete runLoader;
576
577 return kTRUE;
578}
579
6bae477a 580//_____________________________________________________________________________
85a5290f 581void AliSimulation::MergeWith(const char* fileName, Int_t nSignalPerBkgrd)
582{
583// add a file with background events for merging
584
585 TObjString* fileNameStr = new TObjString(fileName);
586 fileNameStr->SetUniqueID(nSignalPerBkgrd);
95601147 587 if (!fBkgrdFileNames) fBkgrdFileNames = new TObjArray;
85a5290f 588 fBkgrdFileNames->Add(fileNameStr);
589}
590
ca30848f 591void AliSimulation::EmbedInto(const char* fileName, Int_t nSignalPerBkgrd)
592{
593// add a file with background events for embeddin
594 MergeWith(fileName, nSignalPerBkgrd);
595 fEmbeddingFlag = kTRUE;
596}
85a5290f 597
598//_____________________________________________________________________________
599Bool_t AliSimulation::Run(Int_t nEvents)
600{
601// run the generation, simulation and digitization
602
c65c502a 603
795e4a22 604 AliCodeTimerAuto("")
87932dab 605
795e4a22 606 // Load run number and seed from environmental vars
607 ProcessEnvironmentVars();
b0314964 608
795e4a22 609 gRandom->SetSeed(fSeed);
610
85a5290f 611 if (nEvents > 0) fNEvents = nEvents;
612
c516e34c 613
85a5290f 614 // generation and simulation -> hits
615 if (fRunGeneration) {
85a5290f 616 if (!RunSimulation()) if (fStopOnError) return kFALSE;
617 }
795e4a22 618
619 // initialize CDB storage from external environment
620 // (either CDB manager or AliSimulation setters),
621 // if not already done in RunSimulation()
622 InitCDB();
623
624 // Set run number in CDBManager from data
625 // From this point on the run number must be always loaded from data!
626 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
627
628 // Set CDB lock: from now on it is forbidden to reset the run number
629 // or the default storage or to activate any further storage!
630 SetCDBLock();
6bae477a 631
25be1e5c 632 // If RunSimulation was not called, load the geometry and misalign it
74ae4297 633 if (!AliGeomManager::GetGeometry()) {
634 // Initialize the geometry manager
45daac75 635 AliGeomManager::LoadGeometry("geometry.root");
ff5970a3 636
637// // Check that the consistency of symbolic names for the activated subdetectors
638// // in the geometry loaded by AliGeomManager
639// AliRunLoader* runLoader = LoadRun("READ");
640// if (!runLoader) return kFALSE;
641//
642// TString detsToBeChecked = "";
643// TObjArray* detArray = runLoader->GetAliRun()->Detectors();
644// for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
645// AliModule* det = (AliModule*) detArray->At(iDet);
646// if (!det || !det->IsActive()) continue;
647// detsToBeChecked += det->GetName();
648// detsToBeChecked += " ";
649// } // end loop over detectors
650// if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
651 if(!AliGeomManager::CheckSymNamesLUT("ALL"))
0bf7aade 652 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
ff5970a3 653
74ae4297 654 if (!AliGeomManager::GetGeometry()) if (fStopOnError) return kFALSE;
655 // Misalign geometry
25be1e5c 656 if(!MisalignGeometry()) if (fStopOnError) return kFALSE;
6bae477a 657 }
25be1e5c 658
27fc67fa 659
85a5290f 660 // hits -> summable digits
27fc67fa 661 AliSysInfo::AddStamp("Start_sdigitization");
85a5290f 662 if (!fMakeSDigits.IsNull()) {
663 if (!RunSDigitization(fMakeSDigits)) if (fStopOnError) return kFALSE;
a1b90a73 664
85a5290f 665 }
27fc67fa 666 AliSysInfo::AddStamp("Stop_sdigitization");
c65c502a 667
27fc67fa 668 AliSysInfo::AddStamp("Start_digitization");
795e4a22 669 // summable digits -> digits
85a5290f 670 if (!fMakeDigits.IsNull()) {
671 if (!RunDigitization(fMakeDigits, fMakeDigitsFromHits)) {
672 if (fStopOnError) return kFALSE;
673 }
a1b90a73 674 }
27fc67fa 675 AliSysInfo::AddStamp("Stop_digitization");
85a5290f 676
795e4a22 677
678
85a5290f 679 // hits -> digits
680 if (!fMakeDigitsFromHits.IsNull()) {
95601147 681 if (fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
ac1671c0 682 AliWarning(Form("Merging and direct creation of digits from hits "
683 "was selected for some detectors. "
684 "No merging will be done for the following detectors: %s",
685 fMakeDigitsFromHits.Data()));
85a5290f 686 }
687 if (!RunHitsDigitization(fMakeDigitsFromHits)) {
688 if (fStopOnError) return kFALSE;
689 }
690 }
691
795e4a22 692
693
a5a091ce 694 // digits -> trigger
8480396b 695 if (!RunTrigger(fMakeTrigger,fMakeDigits)) {
087426de 696 if (fStopOnError) return kFALSE;
a5a091ce 697 }
698
795e4a22 699
700
0421c3d1 701 // digits -> raw data
702 if (!fWriteRawData.IsNull()) {
06c7e392 703 if (!WriteRawData(fWriteRawData, fRawDataFileName,
67327b72 704 fDeleteIntermediateFiles,fWriteSelRawData)) {
0421c3d1 705 if (fStopOnError) return kFALSE;
706 }
707 }
708
795e4a22 709
5f6d0c0d 710 // run HLT simulation on simulated digit data if raw data is not
711 // simulated, otherwise its called as part of WriteRawData
712 if (!fRunHLT.IsNull() && fWriteRawData.IsNull()) {
cae21299 713 if (!RunHLT()) {
714 if (fStopOnError) return kFALSE;
715 }
716 }
795e4a22 717
04236e67 718 //QA
719 if (fRunQA) {
720 Bool_t rv = RunQA() ;
721 if (!rv)
722 if (fStopOnError)
723 return kFALSE ;
724 }
795e4a22 725
726 // Cleanup of CDB manager: cache and active storages!
727 AliCDBManager::Instance()->ClearCache();
728
85a5290f 729 return kTRUE;
730}
731
3e2e3ece 732//_______________________________________________________________________
733Bool_t AliSimulation::RunLego(const char *setup, Int_t nc1, Float_t c1min,
734 Float_t c1max,Int_t nc2,Float_t c2min,Float_t c2max,
735 Float_t rmin,Float_t rmax,Float_t zmax, AliLegoGenerator* gener, Int_t nev)
736{
737 //
738 // Generates lego plots of:
739 // - radiation length map phi vs theta
740 // - radiation length map phi vs eta
741 // - interaction length map
742 // - g/cm2 length map
743 //
744 // ntheta bins in theta, eta
745 // themin minimum angle in theta (degrees)
746 // themax maximum angle in theta (degrees)
747 // nphi bins in phi
748 // phimin minimum angle in phi (degrees)
749 // phimax maximum angle in phi (degrees)
750 // rmin minimum radius
751 // rmax maximum radius
752 //
753 //
754 // The number of events generated = ntheta*nphi
755 // run input parameters in macro setup (default="Config.C")
756 //
757 // Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
758 //Begin_Html
759 /*
760 <img src="picts/AliRunLego1.gif">
761 */
762 //End_Html
763 //Begin_Html
764 /*
765 <img src="picts/AliRunLego2.gif">
766 */
767 //End_Html
768 //Begin_Html
769 /*
770 <img src="picts/AliRunLego3.gif">
771 */
772 //End_Html
773 //
774
775// run the generation and simulation
776
777 AliCodeTimerAuto("")
778
779 // initialize CDB storage and run number from external environment
780 // (either CDB manager or AliSimulation setters)
781 InitCDB();
782 InitRunNumber();
783 SetCDBLock();
784
785 if (!gAlice) {
786 AliError("no gAlice object. Restart aliroot and try again.");
787 return kFALSE;
788 }
789 if (gAlice->Modules()->GetEntries() > 0) {
790 AliError("gAlice was already run. Restart aliroot and try again.");
791 return kFALSE;
792 }
793
794 AliInfo(Form("initializing gAlice with config file %s",
795 fConfigFileName.Data()));
796
797 // Number of events
798 if (nev == -1) nev = nc1 * nc2;
799
800 // check if initialisation has been done
801 // If runloader has been initialized, set the number of events per file to nc1 * nc2
802
803 // Set new generator
804 if (!gener) gener = new AliLegoGenerator();
805 //
806 // Configure Generator
807
808 gener->SetRadiusRange(rmin, rmax);
809 gener->SetZMax(zmax);
810 gener->SetCoor1Range(nc1, c1min, c1max);
811 gener->SetCoor2Range(nc2, c2min, c2max);
812
813
814 //Create Lego object
815 fLego = new AliLego("lego",gener);
816
817 //__________________________________________________________________________
818
819 gAlice->Announce();
820
821 gROOT->LoadMacro(setup);
822 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
823
824 if(AliCDBManager::Instance()->GetRun() >= 0) {
825 SetRunNumber(AliCDBManager::Instance()->GetRun());
826 } else {
827 AliWarning("Run number not initialized!!");
828 }
f7a1cc68 829
33c3c91a 830 AliRunLoader::Instance()->CdGAFile();
3e2e3ece 831
832 AliPDG::AddParticlesToPdgDataBase();
833
834 gAlice->GetMCApp()->Init();
835
f7a1cc68 836 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
837
838
3e2e3ece 839 //Must be here because some MCs (G4) adds detectors here and not in Config.C
840 gAlice->InitLoaders();
33c3c91a 841 AliRunLoader::Instance()->MakeTree("E");
3e2e3ece 842
843 //
844 // Save stuff at the beginning of the file to avoid file corruption
33c3c91a 845 AliRunLoader::Instance()->CdGAFile();
3e2e3ece 846 gAlice->Write();
847
848 //Save current generator
849 AliGenerator *gen=gAlice->GetMCApp()->Generator();
850 gAlice->GetMCApp()->ResetGenerator(gener);
851 //Prepare MC for Lego Run
852 gMC->InitLego();
853
854 //Run Lego Object
855
856
33c3c91a 857 AliRunLoader::Instance()->SetNumberOfEventsPerFile(nev);
3e2e3ece 858 gMC->ProcessRun(nev);
859
860 // End of this run, close files
861 FinishRun();
862 // Restore current generator
863 gAlice->GetMCApp()->ResetGenerator(gen);
864 // Delete Lego Object
865 delete fLego;
866
867 return kTRUE;
868}
869
85a5290f 870//_____________________________________________________________________________
8480396b 871Bool_t AliSimulation::RunTrigger(const char* config, const char* detectors)
a5a091ce 872{
873 // run the trigger
874
87932dab 875 AliCodeTimerAuto("")
a5a091ce 876
795e4a22 877 // initialize CDB storage from external environment
878 // (either CDB manager or AliSimulation setters),
879 // if not already done in RunSimulation()
880 InitCDB();
881
882 // Set run number in CDBManager from data
883 // From this point on the run number must be always loaded from data!
884 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
885
886 // Set CDB lock: from now on it is forbidden to reset the run number
887 // or the default storage or to activate any further storage!
888 SetCDBLock();
889
bacbe0fd 890 AliRunLoader* runLoader = LoadRun("READ");
891 if (!runLoader) return kFALSE;
51f6d619 892 TString trconfiguration = config;
bacbe0fd 893
51f6d619 894 if (trconfiguration.IsNull()) {
f12d42ce 895 if (strcmp(gAlice->GetTriggerDescriptor(),"")) {
51f6d619 896 trconfiguration = gAlice->GetTriggerDescriptor();
087426de 897 }
51f6d619 898 else
8480396b 899 AliWarning("No trigger descriptor is specified. Loading the one that is in the CDB.");
087426de 900 }
901
0f46f5fa 902 runLoader->MakeTree( "GG" );
bacbe0fd 903 AliCentralTrigger* aCTP = runLoader->GetTrigger();
51f6d619 904 // Load Configuration
905 if (!aCTP->LoadConfiguration( trconfiguration ))
906 return kFALSE;
a5a091ce 907
51f6d619 908 // digits -> trigger
8480396b 909 if( !aCTP->RunTrigger( runLoader , detectors ) ) {
a5a091ce 910 if (fStopOnError) {
51f6d619 911 // delete aCTP;
912 return kFALSE;
a5a091ce 913 }
bacbe0fd 914 }
a5a091ce 915
bacbe0fd 916 delete runLoader;
a5a091ce 917
bacbe0fd 918 return kTRUE;
a5a091ce 919}
920
007155cc 921//_____________________________________________________________________________
922Bool_t AliSimulation::WriteTriggerRawData()
923{
924 // Writes the CTP (trigger) DDL raw data
925 // Details of the format are given in the
926 // trigger TDR - pages 134 and 135.
927 AliCTPRawData writer;
928 writer.RawData();
a5a091ce 929
007155cc 930 return kTRUE;
931}
a5a091ce 932
933//_____________________________________________________________________________
95601147 934Bool_t AliSimulation::RunSimulation(Int_t nEvents)
85a5290f 935{
936// run the generation and simulation
937
87932dab 938 AliCodeTimerAuto("")
4df28b43 939
795e4a22 940 // initialize CDB storage and run number from external environment
941 // (either CDB manager or AliSimulation setters)
942 InitCDB();
943 InitRunNumber();
944 SetCDBLock();
945
95601147 946 if (!gAlice) {
ac1671c0 947 AliError("no gAlice object. Restart aliroot and try again.");
95601147 948 return kFALSE;
949 }
950 if (gAlice->Modules()->GetEntries() > 0) {
ac1671c0 951 AliError("gAlice was already run. Restart aliroot and try again.");
95601147 952 return kFALSE;
953 }
954
ac1671c0 955 AliInfo(Form("initializing gAlice with config file %s",
956 fConfigFileName.Data()));
3e2e3ece 957
958 //
959 // Initialize ALICE Simulation run
960 //
961
962 gAlice->Announce();
963
964 gROOT->LoadMacro(fConfigFileName.Data());
965 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
966
967 if(AliCDBManager::Instance()->GetRun() >= 0) {
33c3c91a 968 AliRunLoader::Instance()->SetRunNumber(AliCDBManager::Instance()->GetRun());
c516e34c 969 AliRunLoader::Instance()->SetNumberOfEventsPerRun(fNEvents);
3e2e3ece 970 } else {
971 AliWarning("Run number not initialized!!");
972 }
973
33c3c91a 974 AliRunLoader::Instance()->CdGAFile();
3e2e3ece 975
976 AliPDG::AddParticlesToPdgDataBase();
977
978 gAlice->GetMCApp()->Init();
f7a1cc68 979
980 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
3e2e3ece 981
982 //Must be here because some MCs (G4) adds detectors here and not in Config.C
983 gAlice->InitLoaders();
33c3c91a 984 AliRunLoader::Instance()->MakeTree("E");
985 AliRunLoader::Instance()->LoadKinematics("RECREATE");
986 AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
987 AliRunLoader::Instance()->LoadHits("all","RECREATE");
3e2e3ece 988 //
989 // Save stuff at the beginning of the file to avoid file corruption
33c3c91a 990 AliRunLoader::Instance()->CdGAFile();
3e2e3ece 991 gAlice->Write();
992 gAlice->SetEventNrInRun(-1); //important - we start Begin event from increasing current number in run
993 //___________________________________________________________________________________________
795e4a22 994
087426de 995 // Get the trigger descriptor string
996 // Either from AliSimulation or from
997 // gAlice
998 if (fMakeTrigger.IsNull()) {
f12d42ce 999 if (strcmp(gAlice->GetTriggerDescriptor(),""))
087426de 1000 fMakeTrigger = gAlice->GetTriggerDescriptor();
1001 }
1002 else
1003 gAlice->SetTriggerDescriptor(fMakeTrigger.Data());
1004
6bae477a 1005 // Set run number in CDBManager
024cf675 1006 AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
1007
33c3c91a 1008 AliRunLoader* runLoader = AliRunLoader::Instance();
024cf675 1009 if (!runLoader) {
1010 AliError(Form("gAlice has no run loader object. "
1011 "Check your config file: %s", fConfigFileName.Data()));
1012 return kFALSE;
1013 }
1014 SetGAliceFile(runLoader->GetFileName());
795e4a22 1015
6bae477a 1016 // Misalign geometry
caf9c464 1017#if ROOT_VERSION_CODE < 331527
74ae4297 1018 AliGeomManager::SetGeometry(gGeoManager);
ff5970a3 1019
1020 // Check that the consistency of symbolic names for the activated subdetectors
1021 // in the geometry loaded by AliGeomManager
1022 TString detsToBeChecked = "";
1023 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1024 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1025 AliModule* det = (AliModule*) detArray->At(iDet);
1026 if (!det || !det->IsActive()) continue;
1027 detsToBeChecked += det->GetName();
1028 detsToBeChecked += " ";
1029 } // end loop over detectors
1030 if(!AliGeomManager::CheckSymNamesLUT(detsToBeChecked.Data()))
0bf7aade 1031 AliFatalClass("Current loaded geometry differs in the definition of symbolic names!");
caf9c464 1032 MisalignGeometry(runLoader);
1033#endif
995ad051 1034
33c3c91a 1035// AliRunLoader* runLoader = AliRunLoader::Instance();
024cf675 1036// if (!runLoader) {
1037// AliError(Form("gAlice has no run loader object. "
1038// "Check your config file: %s", fConfigFileName.Data()));
1039// return kFALSE;
1040// }
1041// SetGAliceFile(runLoader->GetFileName());
85a5290f 1042
3e2e3ece 1043 if (!gAlice->GetMCApp()->Generator()) {
ac1671c0 1044 AliError(Form("gAlice has no generator object. "
1045 "Check your config file: %s", fConfigFileName.Data()));
04bae0a0 1046 return kFALSE;
1047 }
fc7e1b1c 1048
1049 // Write GRP entry corresponding to the setting found in Cofig.C
1050 if (fWriteGRPEntry)
1051 WriteGRPEntry();
1052
05526d44 1053 if (nEvents <= 0) nEvents = fNEvents;
04bae0a0 1054
1055 // get vertex from background file in case of merging
1056 if (fUseBkgrdVertex &&
1057 fBkgrdFileNames && (fBkgrdFileNames->GetEntriesFast() > 0)) {
05526d44 1058 Int_t signalPerBkgrd = GetNSignalPerBkgrd(nEvents);
04bae0a0 1059 const char* fileName = ((TObjString*)
1060 (fBkgrdFileNames->At(0)))->GetName();
ac1671c0 1061 AliInfo(Form("The vertex will be taken from the background "
1062 "file %s with nSignalPerBackground = %d",
1063 fileName, signalPerBkgrd));
04bae0a0 1064 AliVertexGenFile* vtxGen = new AliVertexGenFile(fileName, signalPerBkgrd);
3e2e3ece 1065 gAlice->GetMCApp()->Generator()->SetVertexGenerator(vtxGen);
04bae0a0 1066 }
1067
85a5290f 1068 if (!fRunSimulation) {
3e2e3ece 1069 gAlice->GetMCApp()->Generator()->SetTrackingFlag(0);
85a5290f 1070 }
1071
18b43626 1072 // set the number of events per file for given detectors and data types
1073 for (Int_t i = 0; i < fEventsPerFile.GetEntriesFast(); i++) {
1074 if (!fEventsPerFile[i]) continue;
1075 const char* detName = fEventsPerFile[i]->GetName();
1076 const char* typeName = fEventsPerFile[i]->GetTitle();
1077 TString loaderName(detName);
1078 loaderName += "Loader";
1079 AliLoader* loader = runLoader->GetLoader(loaderName);
1080 if (!loader) {
ac1671c0 1081 AliError(Form("RunSimulation", "no loader for %s found\n"
1082 "Number of events per file not set for %s %s",
1083 detName, typeName, detName));
18b43626 1084 continue;
1085 }
1086 AliDataLoader* dataLoader =
1087 loader->GetDataLoader(typeName);
1088 if (!dataLoader) {
ac1671c0 1089 AliError(Form("no data loader for %s found\n"
1090 "Number of events per file not set for %s %s",
1091 typeName, detName, typeName));
18b43626 1092 continue;
1093 }
1094 dataLoader->SetNumberOfEventsPerFile(fEventsPerFile[i]->GetUniqueID());
ac1671c0 1095 AliDebug(1, Form("number of events per file set to %d for %s %s",
1096 fEventsPerFile[i]->GetUniqueID(), detName, typeName));
18b43626 1097 }
1098
ac1671c0 1099 AliInfo("running gAlice");
27fc67fa 1100 AliSysInfo::AddStamp("Start_simulation");
124253ee 1101
124253ee 1102 // Create the Root Tree with one branch per detector
1103 //Hits moved to begin event -> now we are crating separate tree for each event
1104
1105 gMC->ProcessRun(nEvents);
1106
1107 // End of this run, close files
3e2e3ece 1108 if(nEvents>0) FinishRun();
124253ee 1109
27fc67fa 1110 AliSysInfo::AddStamp("Stop_simulation");
95601147 1111 delete runLoader;
85a5290f 1112
1113 return kTRUE;
1114}
1115
1116//_____________________________________________________________________________
95601147 1117Bool_t AliSimulation::RunSDigitization(const char* detectors)
85a5290f 1118{
1119// run the digitization and produce summable digits
27fc67fa 1120 static Int_t eventNr=0;
87932dab 1121 AliCodeTimerAuto("")
4df28b43 1122
795e4a22 1123 // initialize CDB storage, run number, set CDB lock
1124 InitCDB();
1125 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1126 SetCDBLock();
1127
95601147 1128 AliRunLoader* runLoader = LoadRun();
1129 if (!runLoader) return kFALSE;
1130
85a5290f 1131 TString detStr = detectors;
95601147 1132 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
85a5290f 1133 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1134 AliModule* det = (AliModule*) detArray->At(iDet);
1135 if (!det || !det->IsActive()) continue;
1136 if (IsSelected(det->GetName(), detStr)) {
ac1671c0 1137 AliInfo(Form("creating summable digits for %s", det->GetName()));
87932dab 1138 AliCodeTimerAuto(Form("creating summable digits for %s", det->GetName()));
85a5290f 1139 det->Hits2SDigits();
27fc67fa 1140 AliSysInfo::AddStamp(Form("Digit_%s_%d",det->GetName(),eventNr), 0,1, eventNr);
85a5290f 1141 }
1142 }
1143
1144 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
ac1671c0 1145 AliError(Form("the following detectors were not found: %s",
1146 detStr.Data()));
85a5290f 1147 if (fStopOnError) return kFALSE;
1148 }
27fc67fa 1149 eventNr++;
95601147 1150 delete runLoader;
1151
85a5290f 1152 return kTRUE;
1153}
1154
1155
1156//_____________________________________________________________________________
95601147 1157Bool_t AliSimulation::RunDigitization(const char* detectors,
1158 const char* excludeDetectors)
85a5290f 1159{
1160// run the digitization and produce digits from sdigits
1161
87932dab 1162 AliCodeTimerAuto("")
4df28b43 1163
795e4a22 1164 // initialize CDB storage, run number, set CDB lock
1165 InitCDB();
1166 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1167 SetCDBLock();
1168
33c3c91a 1169 delete AliRunLoader::Instance();
124253ee 1170 delete gAlice;
95601147 1171 gAlice = NULL;
1172
1173 Int_t nStreams = 1;
05526d44 1174 if (fBkgrdFileNames) nStreams = fBkgrdFileNames->GetEntriesFast() + 1;
1175 Int_t signalPerBkgrd = GetNSignalPerBkgrd();
85a5290f 1176 AliRunDigitizer* manager = new AliRunDigitizer(nStreams, signalPerBkgrd);
ca30848f 1177 // manager->SetEmbeddingFlag(fEmbeddingFlag);
85a5290f 1178 manager->SetInputStream(0, fGAliceFileName.Data());
1179 for (Int_t iStream = 1; iStream < nStreams; iStream++) {
1180 const char* fileName = ((TObjString*)
1181 (fBkgrdFileNames->At(iStream-1)))->GetName();
1182 manager->SetInputStream(iStream, fileName);
1183 }
1184
1185 TString detStr = detectors;
1186 TString detExcl = excludeDetectors;
95601147 1187 manager->GetInputStream(0)->ImportgAlice();
1188 AliRunLoader* runLoader =
1189 AliRunLoader::GetRunLoader(manager->GetInputStream(0)->GetFolderName());
1190 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
85a5290f 1191 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1192 AliModule* det = (AliModule*) detArray->At(iDet);
1193 if (!det || !det->IsActive()) continue;
1194 if (IsSelected(det->GetName(), detStr) &&
1195 !IsSelected(det->GetName(), detExcl)) {
4df28b43 1196 AliDigitizer* digitizer = det->CreateDigitizer(manager);
ca30848f 1197
4df28b43 1198 if (!digitizer) {
ac1671c0 1199 AliError(Form("no digitizer for %s", det->GetName()));
85a5290f 1200 if (fStopOnError) return kFALSE;
4df28b43 1201 } else {
1202 digitizer->SetRegionOfInterest(fRegionOfInterest);
85a5290f 1203 }
1204 }
1205 }
1206
1207 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
ac1671c0 1208 AliError(Form("the following detectors were not found: %s",
1209 detStr.Data()));
85a5290f 1210 if (fStopOnError) return kFALSE;
1211 }
1212
1213 if (!manager->GetListOfTasks()->IsEmpty()) {
ac1671c0 1214 AliInfo("executing digitization");
85a5290f 1215 manager->Exec("");
1216 }
95601147 1217
85a5290f 1218 delete manager;
1219
1220 return kTRUE;
1221}
1222
1223//_____________________________________________________________________________
95601147 1224Bool_t AliSimulation::RunHitsDigitization(const char* detectors)
85a5290f 1225{
1226// run the digitization and produce digits from hits
1227
87932dab 1228 AliCodeTimerAuto("")
4df28b43 1229
795e4a22 1230 // initialize CDB storage, run number, set CDB lock
1231 InitCDB();
1232 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1233 SetCDBLock();
1234
591f51bb 1235 AliRunLoader* runLoader = LoadRun("READ");
95601147 1236 if (!runLoader) return kFALSE;
1237
85a5290f 1238 TString detStr = detectors;
95601147 1239 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
85a5290f 1240 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1241 AliModule* det = (AliModule*) detArray->At(iDet);
1242 if (!det || !det->IsActive()) continue;
1243 if (IsSelected(det->GetName(), detStr)) {
ac1671c0 1244 AliInfo(Form("creating digits from hits for %s", det->GetName()));
85a5290f 1245 det->Hits2Digits();
1246 }
1247 }
1248
1249 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
ac1671c0 1250 AliError(Form("the following detectors were not found: %s",
1251 detStr.Data()));
85a5290f 1252 if (fStopOnError) return kFALSE;
1253 }
1254
1255 return kTRUE;
1256}
1257
0421c3d1 1258//_____________________________________________________________________________
06c7e392 1259Bool_t AliSimulation::WriteRawData(const char* detectors,
1260 const char* fileName,
67327b72 1261 Bool_t deleteIntermediateFiles,
1262 Bool_t selrawdata)
0421c3d1 1263{
1264// convert the digits to raw data
06c7e392 1265// First DDL raw data files for the given detectors are created.
1266// If a file name is given, the DDL files are then converted to a DATE file.
1267// If deleteIntermediateFiles is true, the DDL raw files are deleted
1268// afterwards.
1269// If the file name has the extension ".root", the DATE file is converted
1270// to a root file.
1271// If deleteIntermediateFiles is true, the DATE file is deleted afterwards.
67327b72 1272// 'selrawdata' flag can be used to enable writing of detectors raw data
1273// accoring to the trigger cluster.
0421c3d1 1274
87932dab 1275 AliCodeTimerAuto("")
4cce3e4e 1276
1277 TString detStr = detectors;
4cce3e4e 1278 if (!WriteRawFiles(detStr.Data())) {
06c7e392 1279 if (fStopOnError) return kFALSE;
1280 }
1281
5f6d0c0d 1282 // run HLT simulation on simulated DDL raw files
1283 // and produce HLT ddl raw files to be included in date/root file
1284 if (IsSelected("HLT", detStr) && !fRunHLT.IsNull()) {
1285 if (!RunHLT()) {
1286 if (fStopOnError) return kFALSE;
1287 }
1288 }
1289
06c7e392 1290 TString dateFileName(fileName);
1291 if (!dateFileName.IsNull()) {
1292 Bool_t rootOutput = dateFileName.EndsWith(".root");
1293 if (rootOutput) dateFileName += ".date";
67327b72 1294 TString selDateFileName;
1295 if (selrawdata) {
1296 selDateFileName = "selected.";
1297 selDateFileName+= dateFileName;
1298 }
1299 if (!ConvertRawFilesToDate(dateFileName,selDateFileName)) {
06c7e392 1300 if (fStopOnError) return kFALSE;
1301 }
1302 if (deleteIntermediateFiles) {
1303 AliRunLoader* runLoader = LoadRun("READ");
1304 if (runLoader) for (Int_t iEvent = 0;
1305 iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1306 char command[256];
1307 sprintf(command, "rm -r raw%d", iEvent);
1308 gSystem->Exec(command);
1309 }
1310 }
1311
1312 if (rootOutput) {
1313 if (!ConvertDateToRoot(dateFileName, fileName)) {
1314 if (fStopOnError) return kFALSE;
1315 }
1316 if (deleteIntermediateFiles) {
1317 gSystem->Unlink(dateFileName);
1318 }
67327b72 1319 if (selrawdata) {
1320 TString selFileName = "selected.";
1321 selFileName += fileName;
1322 if (!ConvertDateToRoot(selDateFileName, selFileName)) {
1323 if (fStopOnError) return kFALSE;
1324 }
1325 if (deleteIntermediateFiles) {
1326 gSystem->Unlink(selDateFileName);
1327 }
1328 }
06c7e392 1329 }
1330 }
1331
06c7e392 1332 return kTRUE;
1333}
1334
1335//_____________________________________________________________________________
1336Bool_t AliSimulation::WriteRawFiles(const char* detectors)
1337{
1338// convert the digits to raw data DDL files
1339
87932dab 1340 AliCodeTimerAuto("")
1341
06c7e392 1342 AliRunLoader* runLoader = LoadRun("READ");
0421c3d1 1343 if (!runLoader) return kFALSE;
1344
06c7e392 1345 // write raw data to DDL files
0421c3d1 1346 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
ac1671c0 1347 AliInfo(Form("processing event %d", iEvent));
0421c3d1 1348 runLoader->GetEvent(iEvent);
1349 TString baseDir = gSystem->WorkingDirectory();
1350 char dirName[256];
1351 sprintf(dirName, "raw%d", iEvent);
1352 gSystem->MakeDirectory(dirName);
1353 if (!gSystem->ChangeDirectory(dirName)) {
ac1671c0 1354 AliError(Form("couldn't change to directory %s", dirName));
0421c3d1 1355 if (fStopOnError) return kFALSE; else continue;
1356 }
1357
3fbd60fe 1358 ofstream runNbFile(Form("run%u",runLoader->GetHeader()->GetRun()));
1359 runNbFile.close();
1360
0421c3d1 1361 TString detStr = detectors;
5f6d0c0d 1362 if (IsSelected("HLT", detStr)) {
1363 // Do nothing. "HLT" will be removed from detStr and HLT raw
1364 // data files are generated in RunHLT.
1365 }
1366
0421c3d1 1367 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1368 for (Int_t iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1369 AliModule* det = (AliModule*) detArray->At(iDet);
1370 if (!det || !det->IsActive()) continue;
1371 if (IsSelected(det->GetName(), detStr)) {
ac1671c0 1372 AliInfo(Form("creating raw data from digits for %s", det->GetName()));
0421c3d1 1373 det->Digits2Raw();
1374 }
1375 }
1376
007155cc 1377 if (!WriteTriggerRawData())
1378 if (fStopOnError) return kFALSE;
1379
0421c3d1 1380 gSystem->ChangeDirectory(baseDir);
1381 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
ac1671c0 1382 AliError(Form("the following detectors were not found: %s",
1383 detStr.Data()));
0421c3d1 1384 if (fStopOnError) return kFALSE;
1385 }
1386 }
1387
1388 delete runLoader;
87932dab 1389
06c7e392 1390 return kTRUE;
1391}
0421c3d1 1392
06c7e392 1393//_____________________________________________________________________________
67327b72 1394Bool_t AliSimulation::ConvertRawFilesToDate(const char* dateFileName,
1395 const char* selDateFileName)
06c7e392 1396{
1397// convert raw data DDL files to a DATE file with the program "dateStream"
67327b72 1398// The second argument is not empty when the user decides to write
1399// the detectors raw data according to the trigger cluster.
06c7e392 1400
87932dab 1401 AliCodeTimerAuto("")
1402
06c7e392 1403 char* path = gSystem->Which(gSystem->Getenv("PATH"), "dateStream");
1404 if (!path) {
ac1671c0 1405 AliError("the program dateStream was not found");
06c7e392 1406 if (fStopOnError) return kFALSE;
1407 } else {
1408 delete[] path;
1409 }
0421c3d1 1410
06c7e392 1411 AliRunLoader* runLoader = LoadRun("READ");
1412 if (!runLoader) return kFALSE;
1413
ac1671c0 1414 AliInfo(Form("converting raw data DDL files to DATE file %s", dateFileName));
67327b72 1415 Bool_t selrawdata = kFALSE;
1416 if (strcmp(selDateFileName,"") != 0) selrawdata = kTRUE;
1417
06c7e392 1418 char command[256];
f28a8d2d 1419 // Note the option -s. It is used in order to avoid
1420 // the generation of SOR/EOR events.
f86775a3 1421 sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
5c0fd670 1422 dateFileName, runLoader->GetNumberOfEvents(),runLoader->GetHeader()->GetRun());
06c7e392 1423 FILE* pipe = gSystem->OpenPipe(command, "w");
1424
f5e7d9d8 1425 if (!pipe) {
1426 AliError(Form("Cannot execute command: %s",command));
1427 return kFALSE;
1428 }
1429
67327b72 1430 Int_t selEvents = 0;
06c7e392 1431 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
06c7e392 1432
f59c50c6 1433 UInt_t detectorPattern = 0;
1434 runLoader->GetEvent(iEvent);
1435 if (!runLoader->LoadTrigger()) {
1436 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1437 detectorPattern = aCTP->GetClusterMask();
67327b72 1438 // Check if the event was triggered by CTP
f59c50c6 1439 if (selrawdata) {
67327b72 1440 if (aCTP->GetClassMask()) selEvents++;
1441 }
f59c50c6 1442 }
1443 else {
1444 AliWarning("No trigger can be loaded! Some fields in the event header will be empty !");
1445 if (selrawdata) {
67327b72 1446 AliWarning("No trigger can be loaded! Writing of selected raw data is abandoned !");
1447 selrawdata = kFALSE;
1448 }
1449 }
1450
f59c50c6 1451 fprintf(pipe, "GDC DetectorPattern %u\n", detectorPattern);
1452 Float_t ldc = 0;
1453 Int_t prevLDC = -1;
1454
06c7e392 1455 // loop over detectors and DDLs
362c9d61 1456 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1457 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
06c7e392 1458
362c9d61 1459 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
06c7e392 1460 Int_t ldcID = Int_t(ldc + 0.0001);
362c9d61 1461 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
06c7e392 1462
1463 char rawFileName[256];
362c9d61 1464 sprintf(rawFileName, "raw%d/%s",
1465 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
06c7e392 1466
1467 // check existence and size of raw data file
1468 FILE* file = fopen(rawFileName, "rb");
1469 if (!file) continue;
1470 fseek(file, 0, SEEK_END);
1471 unsigned long size = ftell(file);
aa04f81b 1472 fclose(file);
1473 if (!size) continue;
06c7e392 1474
1475 if (ldcID != prevLDC) {
1476 fprintf(pipe, " LDC Id %d\n", ldcID);
1477 prevLDC = ldcID;
1478 }
1479 fprintf(pipe, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1480 }
1481 }
1482 }
1483
1484 Int_t result = gSystem->ClosePipe(pipe);
1485
cf30933c 1486 if (!(selrawdata && selEvents > 0)) {
67327b72 1487 delete runLoader;
1488 return (result == 0);
1489 }
1490
1491 AliInfo(Form("converting selected by trigger cluster raw data DDL files to DATE file %s", selDateFileName));
1492
1493 sprintf(command, "dateStream -c -s -D -o %s -# %d -C -run %d",
1494 selDateFileName,selEvents,runLoader->GetHeader()->GetRun());
1495 FILE* pipe2 = gSystem->OpenPipe(command, "w");
1496
1497 for (Int_t iEvent = 0; iEvent < runLoader->GetNumberOfEvents(); iEvent++) {
1498
1499 // Get the trigger decision and cluster
f59c50c6 1500 UInt_t detectorPattern = 0;
67327b72 1501 TString detClust;
1502 runLoader->GetEvent(iEvent);
1503 if (!runLoader->LoadTrigger()) {
1504 AliCentralTrigger *aCTP = runLoader->GetTrigger();
1505 if (aCTP->GetClassMask() == 0) continue;
f59c50c6 1506 detectorPattern = aCTP->GetClusterMask();
1507 detClust = AliDAQ::ListOfTriggeredDetectors(detectorPattern);
67327b72 1508 AliInfo(Form("List of detectors to be read out: %s",detClust.Data()));
1509 }
1510
f59c50c6 1511 fprintf(pipe2, "GDC DetectorPattern %u\n", detectorPattern);
67327b72 1512 Float_t ldc = 0;
1513 Int_t prevLDC = -1;
1514
1515 // loop over detectors and DDLs
1516 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors; iDet++) {
1517 // Write only raw data from detectors that
1518 // are contained in the trigger cluster(s)
1519 if (!IsSelected(AliDAQ::DetectorName(iDet),detClust)) continue;
1520
1521 for (Int_t iDDL = 0; iDDL < AliDAQ::NumberOfDdls(iDet); iDDL++) {
1522
1523 Int_t ddlID = AliDAQ::DdlID(iDet,iDDL);
1524 Int_t ldcID = Int_t(ldc + 0.0001);
1525 ldc += AliDAQ::NumberOfLdcs(iDet) / AliDAQ::NumberOfDdls(iDet);
1526
1527 char rawFileName[256];
1528 sprintf(rawFileName, "raw%d/%s",
1529 iEvent, AliDAQ::DdlFileName(iDet,iDDL));
1530
1531 // check existence and size of raw data file
1532 FILE* file = fopen(rawFileName, "rb");
1533 if (!file) continue;
1534 fseek(file, 0, SEEK_END);
1535 unsigned long size = ftell(file);
1536 fclose(file);
1537 if (!size) continue;
1538
1539 if (ldcID != prevLDC) {
1540 fprintf(pipe2, " LDC Id %d\n", ldcID);
1541 prevLDC = ldcID;
1542 }
1543 fprintf(pipe2, " Equipment Id %d Payload %s\n", ddlID, rawFileName);
1544 }
1545 }
1546 }
1547
1548 Int_t result2 = gSystem->ClosePipe(pipe2);
1549
06c7e392 1550 delete runLoader;
67327b72 1551 return ((result == 0) && (result2 == 0));
06c7e392 1552}
1553
1554//_____________________________________________________________________________
1555Bool_t AliSimulation::ConvertDateToRoot(const char* dateFileName,
1556 const char* rootFileName)
1557{
1558// convert a DATE file to a root file with the program "alimdc"
1559
1560 // ALIMDC setup
f28a8d2d 1561 const Int_t kDBSize = 2000000000;
c83eb8f4 1562 const Int_t kTagDBSize = 1000000000;
06c7e392 1563 const Bool_t kFilter = kFALSE;
8ec1d12b 1564 const Int_t kCompression = 1;
06c7e392 1565
1566 char* path = gSystem->Which(gSystem->Getenv("PATH"), "alimdc");
1567 if (!path) {
ac1671c0 1568 AliError("the program alimdc was not found");
06c7e392 1569 if (fStopOnError) return kFALSE;
1570 } else {
1571 delete[] path;
1572 }
1573
ac1671c0 1574 AliInfo(Form("converting DATE file %s to root file %s",
1575 dateFileName, rootFileName));
06c7e392 1576
f732bd7d 1577 const char* rawDBFS[2] = { "/tmp/mdc1", "/tmp/mdc2" };
1578 const char* tagDBFS = "/tmp/mdc1/tags";
f732bd7d 1579
1580 // User defined file system locations
1581 if (gSystem->Getenv("ALIMDC_RAWDB1"))
1582 rawDBFS[0] = gSystem->Getenv("ALIMDC_RAWDB1");
1583 if (gSystem->Getenv("ALIMDC_RAWDB2"))
1584 rawDBFS[1] = gSystem->Getenv("ALIMDC_RAWDB2");
1585 if (gSystem->Getenv("ALIMDC_TAGDB"))
1586 tagDBFS = gSystem->Getenv("ALIMDC_TAGDB");
f732bd7d 1587
1588 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1589 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1590 gSystem->Exec(Form("rm -rf %s",tagDBFS));
f732bd7d 1591
1592 gSystem->Exec(Form("mkdir %s",rawDBFS[0]));
1593 gSystem->Exec(Form("mkdir %s",rawDBFS[1]));
1594 gSystem->Exec(Form("mkdir %s",tagDBFS));
f732bd7d 1595
1596 Int_t result = gSystem->Exec(Form("alimdc %d %d %d %d %s",
1597 kDBSize, kTagDBSize, kFilter, kCompression, dateFileName));
1598 gSystem->Exec(Form("mv %s/*.root %s", rawDBFS[0], rootFileName));
1599
1600 gSystem->Exec(Form("rm -rf %s",rawDBFS[0]));
1601 gSystem->Exec(Form("rm -rf %s",rawDBFS[1]));
1602 gSystem->Exec(Form("rm -rf %s",tagDBFS));
06c7e392 1603
1604 return (result == 0);
0421c3d1 1605}
1606
85a5290f 1607
1608//_____________________________________________________________________________
06c7e392 1609AliRunLoader* AliSimulation::LoadRun(const char* mode) const
95601147 1610{
1611// delete existing run loaders, open a new one and load gAlice
1612
33c3c91a 1613 delete AliRunLoader::Instance();
95601147 1614 AliRunLoader* runLoader =
1615 AliRunLoader::Open(fGAliceFileName.Data(),
06c7e392 1616 AliConfig::GetDefaultEventFolderName(), mode);
95601147 1617 if (!runLoader) {
ac1671c0 1618 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
95601147 1619 return NULL;
1620 }
1621 runLoader->LoadgAlice();
795e4a22 1622 runLoader->LoadHeader();
95601147 1623 gAlice = runLoader->GetAliRun();
1624 if (!gAlice) {
ac1671c0 1625 AliError(Form("no gAlice object found in file %s",
1626 fGAliceFileName.Data()));
95601147 1627 return NULL;
1628 }
1629 return runLoader;
1630}
1631
1632//_____________________________________________________________________________
05526d44 1633Int_t AliSimulation::GetNSignalPerBkgrd(Int_t nEvents) const
1634{
1635// get or calculate the number of signal events per background event
1636
1637 if (!fBkgrdFileNames) return 1;
1638 Int_t nBkgrdFiles = fBkgrdFileNames->GetEntriesFast();
1639 if (nBkgrdFiles == 0) return 1;
1640
1641 // get the number of signal events
1642 if (nEvents <= 0) {
1643 AliRunLoader* runLoader =
ca30848f 1644 AliRunLoader::Open(fGAliceFileName.Data(), "SIGNAL");
05526d44 1645 if (!runLoader) return 1;
ca30848f 1646
05526d44 1647 nEvents = runLoader->GetNumberOfEvents();
1648 delete runLoader;
1649 }
1650
1651 Int_t result = 0;
1652 for (Int_t iBkgrdFile = 0; iBkgrdFile < nBkgrdFiles; iBkgrdFile++) {
1653 // get the number of background events
1654 const char* fileName = ((TObjString*)
1655 (fBkgrdFileNames->At(iBkgrdFile)))->GetName();
ca30848f 1656 AliRunLoader* runLoader =
05526d44 1657 AliRunLoader::Open(fileName, "BKGRD");
1658 if (!runLoader) continue;
1659 Int_t nBkgrdEvents = runLoader->GetNumberOfEvents();
1660 delete runLoader;
ca30848f 1661
05526d44 1662 // get or calculate the number of signal per background events
1663 Int_t nSignalPerBkgrd = fBkgrdFileNames->At(iBkgrdFile)->GetUniqueID();
1664 if (nSignalPerBkgrd <= 0) {
1665 nSignalPerBkgrd = (nEvents-1) / nBkgrdEvents + 1;
1666 } else if (result && (result != nSignalPerBkgrd)) {
ac1671c0 1667 AliInfo(Form("the number of signal events per background event "
1668 "will be changed from %d to %d for stream %d",
1669 nSignalPerBkgrd, result, iBkgrdFile+1));
05526d44 1670 nSignalPerBkgrd = result;
1671 }
1672
1673 if (!result) result = nSignalPerBkgrd;
1674 if (nSignalPerBkgrd * nBkgrdEvents < nEvents) {
ac1671c0 1675 AliWarning(Form("not enough background events (%d) for %d signal events "
1676 "using %d signal per background events for stream %d",
1677 nBkgrdEvents, nEvents, nSignalPerBkgrd, iBkgrdFile+1));
05526d44 1678 }
1679 }
1680
1681 return result;
1682}
1683
1684//_____________________________________________________________________________
85a5290f 1685Bool_t AliSimulation::IsSelected(TString detName, TString& detectors) const
1686{
1687// check whether detName is contained in detectors
1688// if yes, it is removed from detectors
1689
1690 // check if all detectors are selected
1691 if ((detectors.CompareTo("ALL") == 0) ||
1692 detectors.BeginsWith("ALL ") ||
1693 detectors.EndsWith(" ALL") ||
1694 detectors.Contains(" ALL ")) {
1695 detectors = "ALL";
1696 return kTRUE;
1697 }
1698
1699 // search for the given detector
1700 Bool_t result = kFALSE;
1701 if ((detectors.CompareTo(detName) == 0) ||
1702 detectors.BeginsWith(detName+" ") ||
1703 detectors.EndsWith(" "+detName) ||
1704 detectors.Contains(" "+detName+" ")) {
1705 detectors.ReplaceAll(detName, "");
1706 result = kTRUE;
1707 }
1708
1709 // clean up the detectors string
1710 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1711 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1712 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1713
1714 return result;
1715}
ca30848f 1716
795e4a22 1717//_____________________________________________________________________________
ca30848f 1718Bool_t AliSimulation::ConvertRaw2SDigits(const char* rawDirectory, const char* esdFileName)
1719{
1720//
1721// Steering routine to convert raw data in directory rawDirectory/ to fake SDigits.
1722// These can be used for embedding of MC tracks into RAW data using the standard
1723// merging procedure.
1724//
1725// If an ESD file is given the reconstructed vertex is taken from it and stored in the event header.
1726//
3e2e3ece 1727 if (!gAlice) {
1728 AliError("no gAlice object. Restart aliroot and try again.");
1729 return kFALSE;
1730 }
1731 if (gAlice->Modules()->GetEntries() > 0) {
1732 AliError("gAlice was already run. Restart aliroot and try again.");
1733 return kFALSE;
1734 }
1735
1736 AliInfo(Form("initializing gAlice with config file %s",fConfigFileName.Data()));
1737
1738 gAlice->Announce();
1739
1740 gROOT->LoadMacro(fConfigFileName.Data());
1741 gInterpreter->ProcessLine(gAlice->GetConfigFunction());
1742
1743 if(AliCDBManager::Instance()->GetRun() >= 0) {
1744 SetRunNumber(AliCDBManager::Instance()->GetRun());
1745 } else {
1746 AliWarning("Run number not initialized!!");
1747 }
1748
33c3c91a 1749 AliRunLoader::Instance()->CdGAFile();
ca30848f 1750
3e2e3ece 1751 AliPDG::AddParticlesToPdgDataBase();
1752
1753 gAlice->GetMCApp()->Init();
f7a1cc68 1754
1755 gMC->SetMagField(TGeoGlobalMagField::Instance()->GetField());
3e2e3ece 1756
1757 //Must be here because some MCs (G4) adds detectors here and not in Config.C
1758 gAlice->InitLoaders();
33c3c91a 1759 AliRunLoader::Instance()->MakeTree("E");
1760 AliRunLoader::Instance()->LoadKinematics("RECREATE");
1761 AliRunLoader::Instance()->LoadTrackRefs("RECREATE");
1762 AliRunLoader::Instance()->LoadHits("all","RECREATE");
3e2e3ece 1763 //
1764 // Save stuff at the beginning of the file to avoid file corruption
33c3c91a 1765 AliRunLoader::Instance()->CdGAFile();
3e2e3ece 1766 gAlice->Write();
ca30848f 1767//
1768// Initialize CDB
795e4a22 1769 InitCDB();
1770 //AliCDBManager* man = AliCDBManager::Instance();
1771 //man->SetRun(0); // Should this come from rawdata header ?
ca30848f 1772
1773 Int_t iDet;
1774 //
1775 // Get the runloader
33c3c91a 1776 AliRunLoader* runLoader = AliRunLoader::Instance();
ca30848f 1777 //
1778 // Open esd file if available
1779 TFile* esdFile = TFile::Open(esdFileName);
1780 Bool_t esdOK = (esdFile != 0);
1781 AliESD* esd = new AliESD;
1782 TTree* treeESD = 0;
1783 if (esdOK) {
1784 treeESD = (TTree*) esdFile->Get("esdTree");
1785 if (!treeESD) {
1786 AliWarning("No ESD tree found");
1787 esdOK = kFALSE;
1788 } else {
1789 treeESD->SetBranchAddress("ESD", &esd);
1790 }
1791 }
1792 //
1793 // Create the RawReader
8b31e840 1794 TString fileName(rawDirectory);
1795 AliRawReader* rawReader = 0x0;
1796 if (fileName.EndsWith("/")) {
1797 rawReader = new AliRawReaderFile(fileName);
1798 } else if (fileName.EndsWith(".root")) {
1799 rawReader = new AliRawReaderRoot(fileName);
1800 } else if (!fileName.IsNull()) {
1801 rawReader = new AliRawReaderDate(fileName);
8b31e840 1802 }
1803// if (!fEquipIdMap.IsNull() && fRawReader)
1804// fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
ca30848f 1805 //
1806 // Get list of detectors
1807 TObjArray* detArray = runLoader->GetAliRun()->Detectors();
1808 //
1809 // Get Header
1810 AliHeader* header = runLoader->GetHeader();
1811 //
8b31e840 1812 TString detStr = fMakeSDigits;
ca30848f 1813 // Event loop
1814 Int_t nev = 0;
1815 while(kTRUE) {
1816 if (!(rawReader->NextEvent())) break;
1817 //
1818 // Detector loop
1819 for (iDet = 0; iDet < detArray->GetEntriesFast(); iDet++) {
1820 AliModule* det = (AliModule*) detArray->At(iDet);
8b31e840 1821 if (!det || !det->IsActive()) continue;
1822 if (IsSelected(det->GetName(), detStr)) {
1823 AliInfo(Form("Calling Raw2SDigits for %s\n", det->GetName()));
1824 det->Raw2SDigits(rawReader);
1825 rawReader->Reset();
1826 }
ca30848f 1827 } // detectors
1828
5b188f2f 1829
ca30848f 1830 //
1831 // If ESD information available obtain reconstructed vertex and store in header.
1832 if (esdOK) {
1833 treeESD->GetEvent(nev);
1834 const AliESDVertex* esdVertex = esd->GetPrimaryVertex();
1835 Double_t position[3];
1836 esdVertex->GetXYZ(position);
1837 AliGenEventHeader* mcHeader = new AliGenEventHeader("ESD");
1838 TArrayF mcV;
1839 mcV.Set(3);
1840 for (Int_t i = 0; i < 3; i++) mcV[i] = position[i];
1841 mcHeader->SetPrimaryVertex(mcV);
1842 header->Reset(0,nev);
1843 header->SetGenEventHeader(mcHeader);
1844 printf("***** Saved vertex %f %f %f \n", position[0], position[1], position[2]);
1845 }
1846 nev++;
1847//
1848// Finish the event
1849 runLoader->TreeE()->Fill();
1850 runLoader->SetNextEvent();
1851 } // events
1852
1853 delete rawReader;
1854//
1855// Finish the run
1856 runLoader->CdGAFile();
1857 runLoader->WriteHeader("OVERWRITE");
1858 runLoader->WriteRunLoader();
1859
1860 return kTRUE;
1861}
5b188f2f 1862
1863//_____________________________________________________________________________
3e2e3ece 1864void AliSimulation::FinishRun()
1865{
1866 //
1867 // Called at the end of the run.
1868 //
1869
1870 if(IsLegoRun())
1871 {
1872 AliDebug(1, "Finish Lego");
33c3c91a 1873 AliRunLoader::Instance()->CdGAFile();
3e2e3ece 1874 fLego->FinishRun();
1875 }
1876
1877 // Clean detector information
1878 TIter next(gAlice->Modules());
1879 AliModule *detector;
1880 while((detector = dynamic_cast<AliModule*>(next()))) {
1881 AliDebug(2, Form("%s->FinishRun()", detector->GetName()));
1882 detector->FinishRun();
1883 }
1884
33c3c91a 1885 AliDebug(1, "AliRunLoader::Instance()->WriteHeader(OVERWRITE)");
1886 AliRunLoader::Instance()->WriteHeader("OVERWRITE");
3e2e3ece 1887
1888 // Write AliRun info and all detectors parameters
33c3c91a 1889 AliRunLoader::Instance()->CdGAFile();
3e2e3ece 1890 gAlice->Write(0,TObject::kOverwrite);//write AliRun
33c3c91a 1891 AliRunLoader::Instance()->Write(0,TObject::kOverwrite);//write RunLoader itself
3e2e3ece 1892
1893 if(gAlice->GetMCApp()) gAlice->GetMCApp()->FinishRun();
33c3c91a 1894 AliRunLoader::Instance()->Synchronize();
3e2e3ece 1895}
1896
1897//_____________________________________________________________________________
5b188f2f 1898Int_t AliSimulation::GetDetIndex(const char* detector)
1899{
1900 // return the detector index corresponding to detector
1901 Int_t index = -1 ;
1902 for (index = 0; index < fgkNDetectors ; index++) {
1903 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
1904 break ;
1905 }
1906 return index ;
1907}
cae21299 1908
1909//_____________________________________________________________________________
1910Bool_t AliSimulation::RunHLT()
1911{
1912 // Run the HLT simulation
1913 // HLT simulation is implemented in HLT/sim/AliHLTSimulation
1914 // Disabled if fRunHLT is empty, default vaule is "default".
1915 // AliSimulation::SetRunHLT can be used to set the options for HLT simulation
1916 // The default simulation depends on the HLT component libraries and their
1917 // corresponding agents which define components and chains to run. See
5f6d0c0d 1918 // http://web.ift.uib.no/~kjeks/doc/alice-hlt-current/
1919 // http://web.ift.uib.no/~kjeks/doc/alice-hlt-current/classAliHLTModuleAgent.html
cae21299 1920 //
1921 // The libraries to be loaded can be specified as an option.
1922 // <pre>
1923 // AliSimulation sim;
1924 // sim.SetRunHLT("libAliHLTSample.so");
1925 // </pre>
1926 // will only load <tt>libAliHLTSample.so</tt>
1927
1928 // Other available options:
1929 // \li loglevel=<i>level</i> <br>
1930 // logging level for this processing
1931 // \li alilog=off
1932 // disable redirection of log messages to AliLog class
1933 // \li config=<i>macro</i>
1934 // configuration macro
5f6d0c0d 1935 // \li chains=<i>configuration</i>
cae21299 1936 // comma separated list of configurations to be run during simulation
5f6d0c0d 1937 // \li rawfile=<i>file</i>
1938 // source for the RawReader to be created, the default is <i>./</i> if
1939 // raw data is simulated
cae21299 1940
1941 int iResult=0;
1942 AliRunLoader* pRunLoader = LoadRun("READ");
1943 if (!pRunLoader) return kFALSE;
1944
795e4a22 1945 // initialize CDB storage, run number, set CDB lock
1946 InitCDB();
1947 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
1948 SetCDBLock();
1949
cae21299 1950 // load the library dynamically
1951 gSystem->Load(ALIHLTSIMULATION_LIBRARY);
1952
1953 // check for the library version
1954 AliHLTSimulationGetLibraryVersion_t fctVersion=(AliHLTSimulationGetLibraryVersion_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_GET_LIBRARY_VERSION));
1955 if (!fctVersion) {
1956 AliError(Form("can not load library %s", ALIHLTSIMULATION_LIBRARY));
1957 return kFALSE;
1958 }
1959 if (fctVersion()!= ALIHLTSIMULATION_LIBRARY_VERSION) {
1960 AliError(Form("%s version does not match: compiled for version %d, loaded %d", ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_LIBRARY_VERSION, fctVersion()));
1961 return kFALSE;
1962 }
1963
1964 // print compile info
26f6245d 1965 typedef void (*CompileInfo)( const char*& date, const char*& time);
cae21299 1966 CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, "CompileInfo");
1967 if (fctInfo) {
26f6245d 1968 const char* date="";
1969 const char* time="";
1970 (*fctInfo)(date, time);
1971 if (!date) date="unknown";
1972 if (!time) time="unknown";
cae21299 1973 AliInfo(Form("%s build on %s (%s)", ALIHLTSIMULATION_LIBRARY, date, time));
1974 } else {
1975 AliInfo(Form("no build info available for %s", ALIHLTSIMULATION_LIBRARY));
1976 }
1977
1978 // create instance of the HLT simulation
1979 AliHLTSimulationCreateInstance_t fctCreate=(AliHLTSimulationCreateInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_CREATE_INSTANCE));
1980 AliHLTSimulation* pHLT=NULL;
1981 if (fctCreate==NULL || (pHLT=(fctCreate()))==NULL) {
1982 AliError(Form("can not create instance of HLT simulation (creator %p)", fctCreate));
1983 return kFALSE;
1984 }
1985
1986 // init the HLT simulation
a441bf51 1987 TString options;
1988 if (fRunHLT.CompareTo("default")!=0) options=fRunHLT;
5f6d0c0d 1989 TString detStr = fWriteRawData;
1990 if (!IsSelected("HLT", detStr)) {
a441bf51 1991 options+=" writerawfiles=";
1992 } else {
1993 options+=" writerawfiles=HLT";
1994 }
5f6d0c0d 1995
1996 if (!detStr.IsNull() && !options.Contains("rawfile=")) {
1997 // as a matter of fact, HLT will run reconstruction and needs the RawReader
1998 // in order to get detector data. By default, RawReaderFile is used to read
1999 // the already simulated ddl files. Date and Root files from the raw data
2000 // are generated after the HLT simulation.
2001 options+=" rawfile=./";
2002 }
2003
cae21299 2004 AliHLTSimulationInit_t fctInit=(AliHLTSimulationInit_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_INIT));
a441bf51 2005 if (fctInit==NULL || (iResult=(fctInit(pHLT, pRunLoader, options.Data())))<0) {
cae21299 2006 AliError(Form("can not init HLT simulation: error %d (init %p)", iResult, fctInit));
2007 } else {
2008 // run the HLT simulation
2009 AliHLTSimulationRun_t fctRun=(AliHLTSimulationRun_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_RUN));
2010 if (fctRun==NULL || (iResult=(fctRun(pHLT, pRunLoader)))<0) {
2011 AliError(Form("can not run HLT simulation: error %d (run %p)", iResult, fctRun));
2012 }
2013 }
2014
2015 // delete the instance
2016 AliHLTSimulationDeleteInstance_t fctDelete=(AliHLTSimulationDeleteInstance_t)(gSystem->DynFindSymbol(ALIHLTSIMULATION_LIBRARY, ALIHLTSIMULATION_DELETE_INSTANCE));
2017 if (fctDelete==NULL || fctDelete(pHLT)<0) {
2018 AliError(Form("can not delete instance of HLT simulation (creator %p)", fctDelete));
2019 }
2020 pHLT=NULL;
2021
2022 return iResult>=0?kTRUE:kFALSE;
2023}
cae17938 2024
2025//_____________________________________________________________________________
a1b90a73 2026Bool_t AliSimulation::RunQA()
cae17938 2027{
a1b90a73 2028 // run the QA on summable hits, digits or digits
940d8e5f 2029
f00f2d9c 2030 if(!gAlice) return kFALSE;
b03591ab 2031 fQAManager->SetRunLoader(AliRunLoader::Instance()) ;
a1b90a73 2032
e5dedfe2 2033 TString detectorsw("") ;
2034 Bool_t rv = kTRUE ;
b03591ab 2035 fQAManager->SetEventSpecie(fEventSpecie) ;
2036 detectorsw = fQAManager->Run(fQADetectors.Data()) ;
e5dedfe2 2037 if ( detectorsw.IsNull() )
2038 rv = kFALSE ;
a1b90a73 2039 return rv ;
cae17938 2040}
2041
795e4a22 2042//_____________________________________________________________________________
e3b20d9a 2043Bool_t AliSimulation::SetRunQA(TString detAndAction)
2044{
2045 // Allows to run QA for a selected set of detectors
2046 // and a selected set of tasks among HITS, SDIGITS and DIGITS
2047 // all selected detectors run the same selected tasks
2048
2049 if (!detAndAction.Contains(":")) {
2050 AliError( Form("%s is a wrong syntax, use \"DetectorList:ActionList\" \n", detAndAction.Data()) ) ;
2051 fRunQA = kFALSE ;
2052 return kFALSE ;
2053 }
2054 Int_t colon = detAndAction.Index(":") ;
2055 fQADetectors = detAndAction(0, colon) ;
2056 if (fQADetectors.Contains("ALL") )
2057 fQADetectors = Form("%s %s", fMakeDigits.Data(), fMakeDigitsFromHits.Data()) ;
678caae8 2058 fQATasks = detAndAction(colon+1, detAndAction.Sizeof() ) ;
e3b20d9a 2059 if (fQATasks.Contains("ALL") ) {
4e25ac79 2060 fQATasks = Form("%d %d %d", AliQAv1::kHITS, AliQAv1::kSDIGITS, AliQAv1::kDIGITS) ;
e3b20d9a 2061 } else {
2062 fQATasks.ToUpper() ;
2063 TString tempo("") ;
2064 if ( fQATasks.Contains("HIT") )
4e25ac79 2065 tempo = Form("%d ", AliQAv1::kHITS) ;
e3b20d9a 2066 if ( fQATasks.Contains("SDIGIT") )
4e25ac79 2067 tempo += Form("%d ", AliQAv1::kSDIGITS) ;
e3b20d9a 2068 if ( fQATasks.Contains("DIGIT") )
4e25ac79 2069 tempo += Form("%d ", AliQAv1::kDIGITS) ;
e3b20d9a 2070 fQATasks = tempo ;
2071 if (fQATasks.IsNull()) {
2072 AliInfo("No QA requested\n") ;
2073 fRunQA = kFALSE ;
2074 return kTRUE ;
2075 }
2076 }
2077 TString tempo(fQATasks) ;
4e25ac79 2078 tempo.ReplaceAll(Form("%d", AliQAv1::kHITS), AliQAv1::GetTaskName(AliQAv1::kHITS)) ;
2079 tempo.ReplaceAll(Form("%d", AliQAv1::kSDIGITS), AliQAv1::GetTaskName(AliQAv1::kSDIGITS)) ;
2080 tempo.ReplaceAll(Form("%d", AliQAv1::kDIGITS), AliQAv1::GetTaskName(AliQAv1::kDIGITS)) ;
e3b20d9a 2081 AliInfo( Form("QA will be done on \"%s\" for \"%s\"\n", fQADetectors.Data(), tempo.Data()) ) ;
2082 fRunQA = kTRUE ;
b03591ab 2083 fQAManager->SetActiveDetectors(fQADetectors) ;
2084 fQAManager->SetTasks(fQATasks) ;
4e25ac79 2085 for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++)
2086 fQAManager->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
57acd2d2 2087
e3b20d9a 2088 return kTRUE;
2089}
2090
2091//_____________________________________________________________________________
795e4a22 2092void AliSimulation::ProcessEnvironmentVars()
2093{
2094// Extract run number and random generator seed from env variables
2095
2096 AliInfo("Processing environment variables");
2097
2098 // Random Number seed
2099
2100 // first check that seed is not already set
2101 if (fSeed == 0) {
2102 if (gSystem->Getenv("CONFIG_SEED")) {
2103 fSeed = atoi(gSystem->Getenv("CONFIG_SEED"));
2104 }
2105 } else {
2106 if (gSystem->Getenv("CONFIG_SEED")) {
2107 AliInfo(Form("Seed for random number generation already set (%d)"
2108 ": CONFIG_SEED variable ignored!", fSeed));
2109 }
2110 }
2111
2112 AliInfo(Form("Seed for random number generation = %d ", fSeed));
2113
2114 // Run Number
2115
2116 // first check that run number is not already set
2117 if(fRun < 0) {
2118 if (gSystem->Getenv("DC_RUN")) {
2119 fRun = atoi(gSystem->Getenv("DC_RUN"));
2120 }
2121 } else {
2122 if (gSystem->Getenv("DC_RUN")) {
2123 AliInfo(Form("Run number already set (%d): DC_RUN variable ignored!", fRun));
2124 }
2125 }
2126
2127 AliInfo(Form("Run number = %d", fRun));
2128}
ff5970a3 2129
44e45fac 2130//---------------------------------------------------------------------
fc7e1b1c 2131void AliSimulation::WriteGRPEntry()
2132{
2133 // Get the necessary information from galice (generator, trigger etc) and
2134 // write a GRP entry corresponding to the settings in the Config.C used
44e45fac 2135 // note that Hall probes and Cavern and Surface Atmos pressures are not simulated.
2136
2137
fc7e1b1c 2138 AliInfo("Writing global run parameters entry into the OCDB");
2139
44e45fac 2140 AliGRPObject* grpObj = new AliGRPObject();
fc7e1b1c 2141
44e45fac 2142 grpObj->SetRunType("PHYSICS");
2143 grpObj->SetTimeStart(0);
2144 grpObj->SetTimeEnd(9999);
fc7e1b1c 2145
3e2e3ece 2146 const AliGenerator *gen = gAlice->GetMCApp()->Generator();
fc7e1b1c 2147 if (gen) {
44e45fac 2148 grpObj->SetBeamEnergy(gen->GetEnergyCMS());
fc7e1b1c 2149 TString projectile;
2150 Int_t a,z;
2151 gen->GetProjectile(projectile,a,z);
2152 TString target;
2153 gen->GetTarget(target,a,z);
2154 TString beamType = projectile + "-" + target;
214a2a31 2155 beamType.ReplaceAll(" ","");
e7c989e4 2156 if (!beamType.CompareTo("-")) {
57acd2d2 2157 grpObj->SetBeamType("UNKNOWN");
e7c989e4 2158 }
2159 else {
57acd2d2 2160 grpObj->SetBeamType(beamType);
2161 // Heavy ion run, the event specie is set to kHighMult
2162 fEventSpecie = AliRecoParam::kHighMult;
2163 if ((strcmp(beamType,"p-p") == 0) ||
2164 (strcmp(beamType,"p-") == 0) ||
2165 (strcmp(beamType,"-p") == 0) ||
2166 (strcmp(beamType,"P-P") == 0) ||
2167 (strcmp(beamType,"P-") == 0) ||
2168 (strcmp(beamType,"-P") == 0)) {
2169 // Proton run, the event specie is set to kLowMult
2170 fEventSpecie = AliRecoParam::kLowMult;
2171 }
e7c989e4 2172 }
57acd2d2 2173 } else {
44e45fac 2174 AliWarning("Unknown beam type and energy! Setting energy to 0");
2175 grpObj->SetBeamEnergy(0);
2176 grpObj->SetBeamType("UNKNOWN");
fc7e1b1c 2177 }
2178
2179 UInt_t detectorPattern = 0;
2180 Int_t nDets = 0;
2181 TObjArray *detArray = gAlice->Detectors();
2182 for (Int_t iDet = 0; iDet < AliDAQ::kNDetectors-1; iDet++) {
2183 if (detArray->FindObject(AliDAQ::OfflineModuleName(iDet))) {
2184 detectorPattern |= (1 << iDet);
2185 nDets++;
2186 }
2187 }
1be29b9e 2188 // CTP
2189 if (!fMakeTrigger.IsNull() || strcmp(gAlice->GetTriggerDescriptor(),""))
2190 detectorPattern |= (1 << AliDAQ::DetectorID("TRG"));
2191
fc7e1b1c 2192 // HLT
2193 if (!fRunHLT.IsNull())
2194 detectorPattern |= (1 << AliDAQ::kHLTId);
ff5970a3 2195
44e45fac 2196 grpObj->SetNumberOfDetectors((Char_t)nDets);
2197 grpObj->SetDetectorMask((Int_t)detectorPattern);
2198 grpObj->SetLHCPeriod("LHC08c");
2199 grpObj->SetLHCState("STABLE_BEAMS");
2200 grpObj->SetLHCLuminosity(0,(AliGRPObject::Stats)0);
2201 grpObj->SetBeamIntensity(0,(AliGRPObject::Stats)0);
fc7e1b1c 2202
f7a1cc68 2203 AliMagF *field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
2204 Float_t solenoidField = field ? TMath::Abs(field->SolenoidField()) : 0;
2205 Float_t factor = field ? field->Factor() : 0;
fc7e1b1c 2206 Float_t l3current = TMath::Abs(factor)*solenoidField*30000./5.;
44e45fac 2207 grpObj->SetL3Current(l3current,(AliGRPObject::Stats)0);
fc7e1b1c 2208
2209 if (factor > 0) {
44e45fac 2210 grpObj->SetL3Polarity(0);
2211 grpObj->SetDipolePolarity(0);
fc7e1b1c 2212 }
2213 else {
44e45fac 2214 grpObj->SetL3Polarity(1);
2215 grpObj->SetDipolePolarity(1);
fc7e1b1c 2216 }
2217
2218 if (TMath::Abs(factor) != 0)
44e45fac 2219 grpObj->SetDipoleCurrent(6000,(AliGRPObject::Stats)0);
fc7e1b1c 2220 else
44e45fac 2221 grpObj->SetDipoleCurrent(0,(AliGRPObject::Stats)0);
fc7e1b1c 2222
44e45fac 2223 grpObj->SetCavernTemperature(0,(AliGRPObject::Stats)0);
2224
2225 //grpMap->Add(new TObjString("fCavernPressure"),new TObjString("0")); ---> not inserted in simulation with the new object, since it is now an AliDCSSensor
fc7e1b1c 2226
2227 // Now store the entry in OCDB
2228 AliCDBManager* man = AliCDBManager::Instance();
2229
2b541cc7 2230 AliCDBId id("GRP/GRP/Data", man->GetRun(), man->GetRun(), 1, 1);
fc7e1b1c 2231 AliCDBMetaData *metadata= new AliCDBMetaData();
2232
fc7e1b1c 2233 metadata->SetResponsible("alice-off@cern.ch");
2234 metadata->SetComment("Automatically produced GRP entry for Monte Carlo");
2235
44e45fac 2236 man->Put(grpObj,id,metadata);
fc7e1b1c 2237}
44e45fac 2238
2239