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