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