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