]>
Commit | Line | Data |
---|---|---|
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 the reconstruction // | |
21 | // // | |
22 | // Clusters and tracks are created for all detectors and all events by // | |
23 | // typing: // | |
24 | // // | |
25 | // AliReconstruction rec; // | |
26 | // rec.Run(); // | |
27 | // // | |
28 | // The Run method returns kTRUE in case of successful execution. // | |
29 | // // | |
30 | // If the input to the reconstruction are not simulated digits but raw data, // | |
31 | // this can be specified by an argument of the Run method or by the method // | |
32 | // // | |
33 | // rec.SetInput("..."); // | |
34 | // // | |
35 | // The input formats and the corresponding argument are: // | |
36 | // - DDL raw data files: directory name, ends with "/" // | |
37 | // - raw data root file: root file name, extension ".root" // | |
38 | // - raw data DATE file: DATE file name, any other non-empty string // | |
39 | // - MC root files : empty string, default // | |
40 | // // | |
41 | // By default all events are reconstructed. The reconstruction can be // | |
42 | // limited to a range of events by giving the index of the first and the // | |
43 | // last event as an argument to the Run method or by calling // | |
44 | // // | |
45 | // rec.SetEventRange(..., ...); // | |
46 | // // | |
47 | // The index -1 (default) can be used for the last event to indicate no // | |
48 | // upper limit of the event range. // | |
49 | // // | |
50 | // In case of raw-data reconstruction the user can modify the default // | |
51 | // number of events per digits/clusters/tracks file. In case the option // | |
52 | // is not used the number is set 1. In case the user provides 0, than // | |
53 | // the number of events is equal to the number of events inside the // | |
54 | // raw-data file (i.e. one digits/clusters/tracks file): // | |
55 | // // | |
56 | // rec.SetNumberOfEventsPerFile(...); // | |
57 | // // | |
58 | // // | |
59 | // The name of the galice file can be changed from the default // | |
60 | // "galice.root" by passing it as argument to the AliReconstruction // | |
61 | // constructor or by // | |
62 | // // | |
63 | // rec.SetGAliceFile("..."); // | |
64 | // // | |
65 | // The local reconstruction can be switched on or off for individual // | |
66 | // detectors by // | |
67 | // // | |
68 | // rec.SetRunLocalReconstruction("..."); // | |
69 | // // | |
70 | // The argument is a (case sensitive) string with the names of the // | |
71 | // detectors separated by a space. The special string "ALL" selects all // | |
72 | // available detectors. This is the default. // | |
73 | // // | |
74 | // The reconstruction of the primary vertex position can be switched off by // | |
75 | // // | |
76 | // rec.SetRunVertexFinder(kFALSE); // | |
77 | // // | |
78 | // The tracking and the creation of ESD tracks can be switched on for // | |
79 | // selected detectors by // | |
80 | // // | |
81 | // rec.SetRunTracking("..."); // | |
82 | // // | |
83 | // Uniform/nonuniform field tracking switches (default: uniform field) // | |
84 | // // | |
85 | // rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) // | |
86 | // // | |
87 | // The filling of additional ESD information can be steered by // | |
88 | // // | |
89 | // rec.SetFillESD("..."); // | |
90 | // // | |
91 | // Again, for both methods the string specifies the list of detectors. // | |
92 | // The default is "ALL". // | |
93 | // // | |
94 | // The call of the shortcut method // | |
95 | // // | |
96 | // rec.SetRunReconstruction("..."); // | |
97 | // // | |
98 | // is equivalent to calling SetRunLocalReconstruction, SetRunTracking and // | |
99 | // SetFillESD with the same detector selecting string as argument. // | |
100 | // // | |
101 | // The reconstruction requires digits or raw data as input. For the creation // | |
102 | // of digits and raw data have a look at the class AliSimulation. // | |
103 | // // | |
104 | // For debug purposes the method SetCheckPointLevel can be used. If the // | |
105 | // argument is greater than 0, files with ESD events will be written after // | |
106 | // selected steps of the reconstruction for each event: // | |
107 | // level 1: after tracking and after filling of ESD (final) // | |
108 | // level 2: in addition after each tracking step // | |
109 | // level 3: in addition after the filling of ESD for each detector // | |
110 | // If a final check point file exists for an event, this event will be // | |
111 | // skipped in the reconstruction. The tracking and the filling of ESD for // | |
112 | // a detector will be skipped as well, if the corresponding check point // | |
113 | // file exists. The ESD event will then be loaded from the file instead. // | |
114 | // // | |
115 | /////////////////////////////////////////////////////////////////////////////// | |
116 | ||
117 | #include <TArrayF.h> | |
118 | #include <TFile.h> | |
119 | #include <TSystem.h> | |
120 | #include <TROOT.h> | |
121 | #include <TPluginManager.h> | |
122 | #include <TGeoManager.h> | |
123 | #include <TLorentzVector.h> | |
124 | ||
125 | #include "AliReconstruction.h" | |
126 | #include "AliCodeTimer.h" | |
127 | #include "AliReconstructor.h" | |
128 | #include "AliLog.h" | |
129 | #include "AliRunLoader.h" | |
130 | #include "AliRun.h" | |
131 | #include "AliRawReaderFile.h" | |
132 | #include "AliRawReaderDate.h" | |
133 | #include "AliRawReaderRoot.h" | |
134 | #include "AliRawEventHeaderBase.h" | |
135 | #include "AliESDEvent.h" | |
136 | #include "AliESDMuonTrack.h" | |
137 | #include "AliESDfriend.h" | |
138 | #include "AliESDVertex.h" | |
139 | #include "AliESDcascade.h" | |
140 | #include "AliESDkink.h" | |
141 | #include "AliESDtrack.h" | |
142 | #include "AliESDCaloCluster.h" | |
143 | #include "AliMultiplicity.h" | |
144 | #include "AliTracker.h" | |
145 | #include "AliVertexer.h" | |
146 | #include "AliVertexerTracks.h" | |
147 | #include "AliV0vertexer.h" | |
148 | #include "AliCascadeVertexer.h" | |
149 | #include "AliHeader.h" | |
150 | #include "AliGenEventHeader.h" | |
151 | #include "AliPID.h" | |
152 | #include "AliESDpid.h" | |
153 | #include "AliESDtrack.h" | |
154 | ||
155 | #include "AliESDTagCreator.h" | |
156 | #include "AliAODTagCreator.h" | |
157 | ||
158 | #include "AliGeomManager.h" | |
159 | #include "AliTrackPointArray.h" | |
160 | #include "AliCDBManager.h" | |
161 | #include "AliCDBEntry.h" | |
162 | #include "AliAlignObj.h" | |
163 | ||
164 | #include "AliCentralTrigger.h" | |
165 | #include "AliCTPRawStream.h" | |
166 | ||
167 | #include "AliAODEvent.h" | |
168 | #include "AliAODHeader.h" | |
169 | #include "AliAODTrack.h" | |
170 | #include "AliAODVertex.h" | |
171 | #include "AliAODCluster.h" | |
172 | ||
173 | #include "AliQualAssDataMaker.h" | |
174 | ||
175 | ClassImp(AliReconstruction) | |
176 | ||
177 | ||
178 | //_____________________________________________________________________________ | |
179 | const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"}; | |
180 | ||
181 | //_____________________________________________________________________________ | |
182 | AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri, | |
183 | const char* name, const char* title) : | |
184 | TNamed(name, title), | |
185 | ||
186 | fUniformField(kTRUE), | |
187 | fRunVertexFinder(kTRUE), | |
188 | fRunHLTTracking(kFALSE), | |
189 | fRunMuonTracking(kFALSE), | |
190 | fStopOnError(kFALSE), | |
191 | fWriteAlignmentData(kFALSE), | |
192 | fCleanESD(kTRUE), | |
193 | fWriteESDfriend(kFALSE), | |
194 | fWriteAOD(kFALSE), | |
195 | fFillTriggerESD(kTRUE), | |
196 | ||
197 | fRunLocalReconstruction("ALL"), | |
198 | fRunTracking("ALL"), | |
199 | fFillESD("ALL"), | |
200 | fGAliceFileName(gAliceFilename), | |
201 | fInput(""), | |
202 | fEquipIdMap(""), | |
203 | fFirstEvent(0), | |
204 | fLastEvent(-1), | |
205 | fNumberOfEventsPerFile(1), | |
206 | fCheckPointLevel(0), | |
207 | fOptions(), | |
208 | fLoadAlignFromCDB(kTRUE), | |
209 | fLoadAlignData("ALL"), | |
210 | fESDPar(""), | |
211 | ||
212 | fRunLoader(NULL), | |
213 | fRawReader(NULL), | |
214 | ||
215 | fVertexer(NULL), | |
216 | fDiamondProfile(NULL), | |
217 | ||
218 | fAlignObjArray(NULL), | |
219 | fCDBUri(cdbUri), | |
220 | fSpecCDBUri() | |
221 | { | |
222 | // create reconstruction object with default parameters | |
223 | ||
224 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
225 | fReconstructor[iDet] = NULL; | |
226 | fLoader[iDet] = NULL; | |
227 | fTracker[iDet] = NULL; | |
228 | } | |
229 | AliPID pid; | |
230 | } | |
231 | ||
232 | //_____________________________________________________________________________ | |
233 | AliReconstruction::AliReconstruction(const AliReconstruction& rec) : | |
234 | TNamed(rec), | |
235 | ||
236 | fUniformField(rec.fUniformField), | |
237 | fRunVertexFinder(rec.fRunVertexFinder), | |
238 | fRunHLTTracking(rec.fRunHLTTracking), | |
239 | fRunMuonTracking(rec.fRunMuonTracking), | |
240 | fStopOnError(rec.fStopOnError), | |
241 | fWriteAlignmentData(rec.fWriteAlignmentData), | |
242 | fCleanESD(rec.fCleanESD), | |
243 | fWriteESDfriend(rec.fWriteESDfriend), | |
244 | fWriteAOD(rec.fWriteAOD), | |
245 | fFillTriggerESD(rec.fFillTriggerESD), | |
246 | ||
247 | fRunLocalReconstruction(rec.fRunLocalReconstruction), | |
248 | fRunTracking(rec.fRunTracking), | |
249 | fFillESD(rec.fFillESD), | |
250 | fGAliceFileName(rec.fGAliceFileName), | |
251 | fInput(rec.fInput), | |
252 | fEquipIdMap(rec.fEquipIdMap), | |
253 | fFirstEvent(rec.fFirstEvent), | |
254 | fLastEvent(rec.fLastEvent), | |
255 | fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile), | |
256 | fCheckPointLevel(0), | |
257 | fOptions(), | |
258 | fLoadAlignFromCDB(rec.fLoadAlignFromCDB), | |
259 | fLoadAlignData(rec.fLoadAlignData), | |
260 | fESDPar(rec.fESDPar), | |
261 | ||
262 | fRunLoader(NULL), | |
263 | fRawReader(NULL), | |
264 | ||
265 | fVertexer(NULL), | |
266 | fDiamondProfile(NULL), | |
267 | ||
268 | fAlignObjArray(rec.fAlignObjArray), | |
269 | fCDBUri(rec.fCDBUri), | |
270 | fSpecCDBUri() | |
271 | { | |
272 | // copy constructor | |
273 | ||
274 | for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) { | |
275 | if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone()); | |
276 | } | |
277 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
278 | fReconstructor[iDet] = NULL; | |
279 | fLoader[iDet] = NULL; | |
280 | fTracker[iDet] = NULL; | |
281 | } | |
282 | for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) { | |
283 | if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone()); | |
284 | } | |
285 | } | |
286 | ||
287 | //_____________________________________________________________________________ | |
288 | AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec) | |
289 | { | |
290 | // assignment operator | |
291 | ||
292 | this->~AliReconstruction(); | |
293 | new(this) AliReconstruction(rec); | |
294 | return *this; | |
295 | } | |
296 | ||
297 | //_____________________________________________________________________________ | |
298 | AliReconstruction::~AliReconstruction() | |
299 | { | |
300 | // clean up | |
301 | ||
302 | CleanUp(); | |
303 | fOptions.Delete(); | |
304 | fSpecCDBUri.Delete(); | |
305 | ||
306 | AliCodeTimer::Instance()->Print(); | |
307 | } | |
308 | ||
309 | //_____________________________________________________________________________ | |
310 | void AliReconstruction::InitCDBStorage() | |
311 | { | |
312 | // activate a default CDB storage | |
313 | // First check if we have any CDB storage set, because it is used | |
314 | // to retrieve the calibration and alignment constants | |
315 | ||
316 | AliCDBManager* man = AliCDBManager::Instance(); | |
317 | if (man->IsDefaultStorageSet()) | |
318 | { | |
319 | AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
320 | AliWarning("Default CDB storage has been already set !"); | |
321 | AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data())); | |
322 | AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
323 | fCDBUri = ""; | |
324 | } | |
325 | else { | |
326 | AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
327 | AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data())); | |
328 | AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
329 | man->SetDefaultStorage(fCDBUri); | |
330 | } | |
331 | ||
332 | // Now activate the detector specific CDB storage locations | |
333 | for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) { | |
334 | TObject* obj = fSpecCDBUri[i]; | |
335 | if (!obj) continue; | |
336 | AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
337 | AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle())); | |
338 | AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); | |
339 | man->SetSpecificStorage(obj->GetName(), obj->GetTitle()); | |
340 | } | |
341 | man->Print(); | |
342 | } | |
343 | ||
344 | //_____________________________________________________________________________ | |
345 | void AliReconstruction::SetDefaultStorage(const char* uri) { | |
346 | // Store the desired default CDB storage location | |
347 | // Activate it later within the Run() method | |
348 | ||
349 | fCDBUri = uri; | |
350 | ||
351 | } | |
352 | ||
353 | //_____________________________________________________________________________ | |
354 | void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) { | |
355 | // Store a detector-specific CDB storage location | |
356 | // Activate it later within the Run() method | |
357 | ||
358 | AliCDBPath aPath(calibType); | |
359 | if(!aPath.IsValid()){ | |
360 | // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path | |
361 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
362 | if(!strcmp(calibType, fgkDetectorName[iDet])) { | |
363 | aPath.SetPath(Form("%s/*", calibType)); | |
364 | AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data())); | |
365 | break; | |
366 | } | |
367 | } | |
368 | if(!aPath.IsValid()){ | |
369 | AliError(Form("Not a valid path or detector: %s", calibType)); | |
370 | return; | |
371 | } | |
372 | } | |
373 | ||
374 | // check that calibType refers to a "valid" detector name | |
375 | Bool_t isDetector = kFALSE; | |
376 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
377 | TString detName = fgkDetectorName[iDet]; | |
378 | if(aPath.GetLevel0() == detName) { | |
379 | isDetector = kTRUE; | |
380 | break; | |
381 | } | |
382 | } | |
383 | ||
384 | if(!isDetector) { | |
385 | AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data())); | |
386 | return; | |
387 | } | |
388 | ||
389 | TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data()); | |
390 | if (obj) fSpecCDBUri.Remove(obj); | |
391 | fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri)); | |
392 | ||
393 | } | |
394 | ||
395 | ||
396 | ||
397 | ||
398 | //_____________________________________________________________________________ | |
399 | Bool_t AliReconstruction::SetRunNumber() | |
400 | { | |
401 | // The method is called in Run() in order | |
402 | // to set a correct run number. | |
403 | // In case of raw data reconstruction the | |
404 | // run number is taken from the raw data header | |
405 | ||
406 | if(AliCDBManager::Instance()->GetRun() < 0) { | |
407 | if (!fRunLoader) { | |
408 | AliError("No run loader is found !"); | |
409 | return kFALSE; | |
410 | } | |
411 | // read run number from gAlice | |
412 | if(fRunLoader->GetAliRun()) | |
413 | AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber()); | |
414 | else { | |
415 | if(fRawReader) { | |
416 | if(fRawReader->NextEvent()) { | |
417 | AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber()); | |
418 | fRawReader->RewindEvents(); | |
419 | } | |
420 | else { | |
421 | AliError("No raw-data events found !"); | |
422 | return kFALSE; | |
423 | } | |
424 | } | |
425 | else { | |
426 | AliError("Neither gAlice nor RawReader objects are found !"); | |
427 | return kFALSE; | |
428 | } | |
429 | } | |
430 | AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun())); | |
431 | } | |
432 | return kTRUE; | |
433 | } | |
434 | ||
435 | //_____________________________________________________________________________ | |
436 | Bool_t AliReconstruction::MisalignGeometry(const TString& detectors) | |
437 | { | |
438 | // Read the alignment objects from CDB. | |
439 | // Each detector is supposed to have the | |
440 | // alignment objects in DET/Align/Data CDB path. | |
441 | // All the detector objects are then collected, | |
442 | // sorted by geometry level (starting from ALIC) and | |
443 | // then applied to the TGeo geometry. | |
444 | // Finally an overlaps check is performed. | |
445 | ||
446 | // Load alignment data from CDB and fill fAlignObjArray | |
447 | if(fLoadAlignFromCDB){ | |
448 | ||
449 | TString detStr = detectors; | |
450 | TString loadAlObjsListOfDets = ""; | |
451 | ||
452 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
453 | if (!IsSelected(fgkDetectorName[iDet], detStr)) continue; | |
454 | loadAlObjsListOfDets += fgkDetectorName[iDet]; | |
455 | loadAlObjsListOfDets += " "; | |
456 | } // end loop over detectors | |
457 | AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data()); | |
458 | }else{ | |
459 | // Check if the array with alignment objects was | |
460 | // provided by the user. If yes, apply the objects | |
461 | // to the present TGeo geometry | |
462 | if (fAlignObjArray) { | |
463 | if (gGeoManager && gGeoManager->IsClosed()) { | |
464 | if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) { | |
465 | AliError("The misalignment of one or more volumes failed!" | |
466 | "Compare the list of simulated detectors and the list of detector alignment data!"); | |
467 | return kFALSE; | |
468 | } | |
469 | } | |
470 | else { | |
471 | AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!"); | |
472 | return kFALSE; | |
473 | } | |
474 | } | |
475 | } | |
476 | ||
477 | delete fAlignObjArray; fAlignObjArray=0; | |
478 | ||
479 | return kTRUE; | |
480 | } | |
481 | ||
482 | //_____________________________________________________________________________ | |
483 | void AliReconstruction::SetGAliceFile(const char* fileName) | |
484 | { | |
485 | // set the name of the galice file | |
486 | ||
487 | fGAliceFileName = fileName; | |
488 | } | |
489 | ||
490 | //_____________________________________________________________________________ | |
491 | void AliReconstruction::SetOption(const char* detector, const char* option) | |
492 | { | |
493 | // set options for the reconstruction of a detector | |
494 | ||
495 | TObject* obj = fOptions.FindObject(detector); | |
496 | if (obj) fOptions.Remove(obj); | |
497 | fOptions.Add(new TNamed(detector, option)); | |
498 | } | |
499 | ||
500 | ||
501 | //_____________________________________________________________________________ | |
502 | Bool_t AliReconstruction::Run(const char* input) | |
503 | { | |
504 | // run the reconstruction | |
505 | ||
506 | AliCodeTimerAuto("") | |
507 | ||
508 | // set the input | |
509 | if (!input) input = fInput.Data(); | |
510 | TString fileName(input); | |
511 | if (fileName.EndsWith("/")) { | |
512 | fRawReader = new AliRawReaderFile(fileName); | |
513 | } else if (fileName.EndsWith(".root")) { | |
514 | fRawReader = new AliRawReaderRoot(fileName); | |
515 | } else if (!fileName.IsNull()) { | |
516 | fRawReader = new AliRawReaderDate(fileName); | |
517 | fRawReader->SelectEvents(7); | |
518 | } | |
519 | if (!fEquipIdMap.IsNull() && fRawReader) | |
520 | fRawReader->LoadEquipmentIdsMap(fEquipIdMap); | |
521 | ||
522 | ||
523 | // get the run loader | |
524 | if (!InitRunLoader()) return kFALSE; | |
525 | ||
526 | // Initialize the CDB storage | |
527 | InitCDBStorage(); | |
528 | ||
529 | // Set run number in CDBManager (if it is not already set by the user) | |
530 | if (!SetRunNumber()) if (fStopOnError) return kFALSE; | |
531 | ||
532 | // Import ideal TGeo geometry and apply misalignment | |
533 | if (!gGeoManager) { | |
534 | TString geom(gSystem->DirName(fGAliceFileName)); | |
535 | geom += "/geometry.root"; | |
536 | AliGeomManager::LoadGeometry(geom.Data()); | |
537 | if (!gGeoManager) if (fStopOnError) return kFALSE; | |
538 | } | |
539 | ||
540 | AliCDBManager* man = AliCDBManager::Instance(); | |
541 | if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE; | |
542 | ||
543 | // local reconstruction | |
544 | if (!fRunLocalReconstruction.IsNull()) { | |
545 | if (!RunLocalReconstruction(fRunLocalReconstruction)) { | |
546 | if (fStopOnError) {CleanUp(); return kFALSE;} | |
547 | } | |
548 | } | |
549 | // if (!fRunVertexFinder && fRunTracking.IsNull() && | |
550 | // fFillESD.IsNull()) return kTRUE; | |
551 | ||
552 | // get vertexer | |
553 | if (fRunVertexFinder && !CreateVertexer()) { | |
554 | if (fStopOnError) { | |
555 | CleanUp(); | |
556 | return kFALSE; | |
557 | } | |
558 | } | |
559 | ||
560 | // get trackers | |
561 | if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) { | |
562 | if (fStopOnError) { | |
563 | CleanUp(); | |
564 | return kFALSE; | |
565 | } | |
566 | } | |
567 | ||
568 | // get the possibly already existing ESD file and tree | |
569 | AliESDEvent* esd = new AliESDEvent(); AliESDEvent* hltesd = new AliESDEvent(); | |
570 | TFile* fileOld = NULL; | |
571 | TTree* treeOld = NULL; TTree *hlttreeOld = NULL; | |
572 | if (!gSystem->AccessPathName("AliESDs.root")){ | |
573 | gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE); | |
574 | fileOld = TFile::Open("AliESDs.old.root"); | |
575 | if (fileOld && fileOld->IsOpen()) { | |
576 | treeOld = (TTree*) fileOld->Get("esdTree"); | |
577 | if (treeOld)esd->ReadFromTree(treeOld); | |
578 | hlttreeOld = (TTree*) fileOld->Get("HLTesdTree"); | |
579 | if (hlttreeOld) hltesd->ReadFromTree(hlttreeOld); | |
580 | } | |
581 | } | |
582 | ||
583 | // create the ESD output file and tree | |
584 | TFile* file = TFile::Open("AliESDs.root", "RECREATE"); | |
585 | file->SetCompressionLevel(2); | |
586 | if (!file->IsOpen()) { | |
587 | AliError("opening AliESDs.root failed"); | |
588 | if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;} | |
589 | } | |
590 | ||
591 | TTree* tree = new TTree("esdTree", "Tree with ESD objects"); | |
592 | esd = new AliESDEvent(); | |
593 | esd->CreateStdContent(); | |
594 | esd->WriteToTree(tree); | |
595 | ||
596 | TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects"); | |
597 | hltesd = new AliESDEvent(); | |
598 | hltesd->CreateStdContent(); | |
599 | hltesd->WriteToTree(hlttree); | |
600 | ||
601 | /* CKB Why? | |
602 | delete esd; delete hltesd; | |
603 | esd = NULL; hltesd = NULL; | |
604 | */ | |
605 | // create the branch with ESD additions | |
606 | ||
607 | ||
608 | ||
609 | AliESDfriend *esdf = 0; | |
610 | if (fWriteESDfriend) { | |
611 | esdf = new AliESDfriend(); | |
612 | TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf); | |
613 | br->SetFile("AliESDfriends.root"); | |
614 | esd->AddObject(esdf); | |
615 | } | |
616 | ||
617 | ||
618 | // Get the diamond profile from OCDB | |
619 | AliCDBEntry* entry = AliCDBManager::Instance() | |
620 | ->Get("GRP/Calib/MeanVertex"); | |
621 | ||
622 | if(entry) { | |
623 | fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject()); | |
624 | } else { | |
625 | AliError("No diamond profile found in OCDB!"); | |
626 | } | |
627 | ||
628 | AliVertexerTracks tVertexer(AliTracker::GetBz()); | |
629 | if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile); | |
630 | ||
631 | // loop over events | |
632 | ||
633 | if (fRawReader) fRawReader->RewindEvents(); | |
634 | TString detStr(fFillESD) ; | |
635 | ||
636 | // initialises quality assurance for ESDs | |
637 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
638 | if (!IsSelected(fgkDetectorName[iDet], detStr)) | |
639 | continue; | |
640 | AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet); | |
641 | if (!qadm) | |
642 | continue; | |
643 | qadm->Init(AliQualAss::kESDS) ; | |
644 | } | |
645 | ||
646 | for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) { | |
647 | if (fRawReader) fRawReader->NextEvent(); | |
648 | if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) { | |
649 | // copy old ESD to the new one | |
650 | if (treeOld) { | |
651 | esd->ReadFromTree(treeOld); | |
652 | treeOld->GetEntry(iEvent); | |
653 | } | |
654 | tree->Fill(); | |
655 | if (hlttreeOld) { | |
656 | esd->ReadFromTree(hlttreeOld); | |
657 | hlttreeOld->GetEntry(iEvent); | |
658 | } | |
659 | hlttree->Fill(); | |
660 | continue; | |
661 | } | |
662 | ||
663 | AliInfo(Form("processing event %d", iEvent)); | |
664 | fRunLoader->GetEvent(iEvent); | |
665 | ||
666 | char aFileName[256]; | |
667 | sprintf(aFileName, "ESD_%d.%d_final.root", | |
668 | fRunLoader->GetHeader()->GetRun(), | |
669 | fRunLoader->GetHeader()->GetEventNrInRun()); | |
670 | if (!gSystem->AccessPathName(aFileName)) continue; | |
671 | ||
672 | // local reconstruction | |
673 | if (!fRunLocalReconstruction.IsNull()) { | |
674 | if (!RunLocalEventReconstruction(fRunLocalReconstruction)) { | |
675 | if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;} | |
676 | } | |
677 | } | |
678 | ||
679 | ||
680 | esd->SetRunNumber(fRunLoader->GetHeader()->GetRun()); | |
681 | hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun()); | |
682 | esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun()); | |
683 | hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun()); | |
684 | ||
685 | // Set magnetic field from the tracker | |
686 | esd->SetMagneticField(AliTracker::GetBz()); | |
687 | hltesd->SetMagneticField(AliTracker::GetBz()); | |
688 | ||
689 | ||
690 | ||
691 | // Fill raw-data error log into the ESD | |
692 | if (fRawReader) FillRawDataErrorLog(iEvent,esd); | |
693 | ||
694 | // vertex finder | |
695 | if (fRunVertexFinder) { | |
696 | if (!ReadESD(esd, "vertex")) { | |
697 | if (!RunVertexFinder(esd)) { | |
698 | if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;} | |
699 | } | |
700 | if (fCheckPointLevel > 0) WriteESD(esd, "vertex"); | |
701 | } | |
702 | } | |
703 | ||
704 | // HLT tracking | |
705 | if (!fRunTracking.IsNull()) { | |
706 | if (fRunHLTTracking) { | |
707 | hltesd->SetVertex(esd->GetVertex()); | |
708 | if (!RunHLTTracking(hltesd)) { | |
709 | if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;} | |
710 | } | |
711 | } | |
712 | } | |
713 | ||
714 | // Muon tracking | |
715 | if (!fRunTracking.IsNull()) { | |
716 | if (fRunMuonTracking) { | |
717 | if (!RunMuonTracking(esd)) { | |
718 | if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;} | |
719 | } | |
720 | } | |
721 | } | |
722 | ||
723 | // barrel tracking | |
724 | if (!fRunTracking.IsNull()) { | |
725 | if (!ReadESD(esd, "tracking")) { | |
726 | if (!RunTracking(esd)) { | |
727 | if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;} | |
728 | } | |
729 | if (fCheckPointLevel > 0) WriteESD(esd, "tracking"); | |
730 | } | |
731 | } | |
732 | ||
733 | // fill ESD | |
734 | if (!fFillESD.IsNull()) { | |
735 | if (!FillESD(esd, fFillESD)) { | |
736 | if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;} | |
737 | } | |
738 | } | |
739 | ||
740 | if (!fFillESD.IsNull()) | |
741 | RunQualAss(fFillESD.Data(), esd); | |
742 | ||
743 | // fill Event header information from the RawEventHeader | |
744 | if (fRawReader){FillRawEventHeaderESD(esd);} | |
745 | ||
746 | // combined PID | |
747 | AliESDpid::MakePID(esd); | |
748 | if (fCheckPointLevel > 1) WriteESD(esd, "PID"); | |
749 | ||
750 | if (fFillTriggerESD) { | |
751 | if (!ReadESD(esd, "trigger")) { | |
752 | if (!FillTriggerESD(esd)) { | |
753 | if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;} | |
754 | } | |
755 | if (fCheckPointLevel > 1) WriteESD(esd, "trigger"); | |
756 | } | |
757 | } | |
758 | ||
759 | //Try to improve the reconstructed primary vertex position using the tracks | |
760 | AliESDVertex *pvtx=0; | |
761 | Bool_t dovertex=kTRUE; | |
762 | TObject* obj = fOptions.FindObject("ITS"); | |
763 | if (obj) { | |
764 | TString optITS = obj->GetTitle(); | |
765 | if (optITS.Contains("cosmics") || optITS.Contains("COSMICS")) | |
766 | dovertex=kFALSE; | |
767 | } | |
768 | if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd); | |
769 | if(fDiamondProfile) esd->SetDiamond(fDiamondProfile); | |
770 | ||
771 | if (pvtx) | |
772 | if (pvtx->GetStatus()) { | |
773 | // Store the improved primary vertex | |
774 | esd->SetPrimaryVertex(pvtx); | |
775 | // Propagate the tracks to the DCA to the improved primary vertex | |
776 | Double_t somethingbig = 777.; | |
777 | Double_t bz = esd->GetMagneticField(); | |
778 | Int_t nt=esd->GetNumberOfTracks(); | |
779 | while (nt--) { | |
780 | AliESDtrack *t = esd->GetTrack(nt); | |
781 | t->RelateToVertex(pvtx, bz, somethingbig); | |
782 | } | |
783 | } | |
784 | ||
785 | { | |
786 | // V0 finding | |
787 | AliV0vertexer vtxer; | |
788 | vtxer.Tracks2V0vertices(esd); | |
789 | ||
790 | // Cascade finding | |
791 | AliCascadeVertexer cvtxer; | |
792 | cvtxer.V0sTracks2CascadeVertices(esd); | |
793 | } | |
794 | ||
795 | // write ESD | |
796 | if (fCleanESD) CleanESD(esd); | |
797 | if (fWriteESDfriend) { | |
798 | new (esdf) AliESDfriend(); // Reset... | |
799 | esd->GetESDfriend(esdf); | |
800 | } | |
801 | tree->Fill(); | |
802 | ||
803 | // write HLT ESD | |
804 | hlttree->Fill(); | |
805 | ||
806 | if (fCheckPointLevel > 0) WriteESD(esd, "final"); | |
807 | esd->Reset(); | |
808 | hltesd->Reset(); | |
809 | if (fWriteESDfriend) { | |
810 | new (esdf) AliESDfriend(); // Reset... | |
811 | } | |
812 | // esdf->Reset(); | |
813 | // delete esdf; esdf = 0; | |
814 | // ESD QA | |
815 | ||
816 | } | |
817 | ||
818 | detStr = fFillESD ; | |
819 | // write quality assurance ESDs data (one entry for all events) | |
820 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
821 | if (!IsSelected(fgkDetectorName[iDet], detStr)) | |
822 | continue; | |
823 | AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet); | |
824 | if (!qadm) | |
825 | continue; | |
826 | qadm->Finish(AliQualAss::kESDS) ; | |
827 | } | |
828 | ||
829 | tree->GetUserInfo()->Add(esd); | |
830 | hlttree->GetUserInfo()->Add(hltesd); | |
831 | ||
832 | ||
833 | ||
834 | if(fESDPar.Contains("ESD.par")){ | |
835 | AliInfo("Attaching ESD.par to Tree"); | |
836 | TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par"); | |
837 | tree->GetUserInfo()->Add(fn); | |
838 | } | |
839 | ||
840 | ||
841 | file->cd(); | |
842 | if (fWriteESDfriend) | |
843 | tree->SetBranchStatus("ESDfriend*",0); | |
844 | tree->Write(); | |
845 | hlttree->Write(); | |
846 | ||
847 | if (fWriteAOD) { | |
848 | TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE"); | |
849 | ESDFile2AODFile(file, aodFile); | |
850 | aodFile->Close(); | |
851 | } | |
852 | ||
853 | gROOT->cd(); | |
854 | CleanUp(file, fileOld); | |
855 | ||
856 | // Create tags for the events in the ESD tree (the ESD tree is always present) | |
857 | // In case of empty events the tags will contain dummy values | |
858 | AliESDTagCreator *esdtagCreator = new AliESDTagCreator(); | |
859 | esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent); | |
860 | if (fWriteAOD) { | |
861 | AliAODTagCreator *aodtagCreator = new AliAODTagCreator(); | |
862 | aodtagCreator->CreateAODTags(fFirstEvent,fLastEvent); | |
863 | } | |
864 | ||
865 | return kTRUE; | |
866 | } | |
867 | ||
868 | ||
869 | //_____________________________________________________________________________ | |
870 | Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors) | |
871 | { | |
872 | // run the local reconstruction | |
873 | ||
874 | AliCodeTimerAuto("") | |
875 | ||
876 | AliCDBManager* man = AliCDBManager::Instance(); | |
877 | Bool_t origCache = man->GetCacheFlag(); | |
878 | ||
879 | TString detStr = detectors; | |
880 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
881 | if (!IsSelected(fgkDetectorName[iDet], detStr)) continue; | |
882 | AliReconstructor* reconstructor = GetReconstructor(iDet); | |
883 | if (!reconstructor) continue; | |
884 | if (reconstructor->HasLocalReconstruction()) continue; | |
885 | ||
886 | AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet])); | |
887 | AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet])); | |
888 | ||
889 | AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet])); | |
890 | AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet])); | |
891 | ||
892 | man->SetCacheFlag(kTRUE); | |
893 | TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]); | |
894 | man->GetAll(calibPath); // entries are cached! | |
895 | ||
896 | AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet])); | |
897 | ||
898 | if (fRawReader) { | |
899 | fRawReader->RewindEvents(); | |
900 | reconstructor->Reconstruct(fRunLoader, fRawReader); | |
901 | } else { | |
902 | reconstructor->Reconstruct(fRunLoader); | |
903 | } | |
904 | ||
905 | AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet])); | |
906 | ||
907 | // unload calibration data | |
908 | man->UnloadFromCache(calibPath); | |
909 | //man->ClearCache(); | |
910 | } | |
911 | ||
912 | man->SetCacheFlag(origCache); | |
913 | ||
914 | if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) { | |
915 | AliError(Form("the following detectors were not found: %s", | |
916 | detStr.Data())); | |
917 | if (fStopOnError) return kFALSE; | |
918 | } | |
919 | ||
920 | return kTRUE; | |
921 | } | |
922 | ||
923 | //_____________________________________________________________________________ | |
924 | Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors) | |
925 | { | |
926 | // run the local reconstruction | |
927 | ||
928 | AliCodeTimerAuto("") | |
929 | ||
930 | TString detStr = detectors; | |
931 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
932 | if (!IsSelected(fgkDetectorName[iDet], detStr)) continue; | |
933 | AliReconstructor* reconstructor = GetReconstructor(iDet); | |
934 | if (!reconstructor) continue; | |
935 | AliLoader* loader = fLoader[iDet]; | |
936 | ||
937 | // conversion of digits | |
938 | if (fRawReader && reconstructor->HasDigitConversion()) { | |
939 | AliInfo(Form("converting raw data digits into root objects for %s", | |
940 | fgkDetectorName[iDet])); | |
941 | AliCodeTimerAuto(Form("converting raw data digits into root objects for %s", | |
942 | fgkDetectorName[iDet])); | |
943 | loader->LoadDigits("update"); | |
944 | loader->CleanDigits(); | |
945 | loader->MakeDigitsContainer(); | |
946 | TTree* digitsTree = loader->TreeD(); | |
947 | reconstructor->ConvertDigits(fRawReader, digitsTree); | |
948 | loader->WriteDigits("OVERWRITE"); | |
949 | loader->UnloadDigits(); | |
950 | } | |
951 | ||
952 | // local reconstruction | |
953 | if (!reconstructor->HasLocalReconstruction()) continue; | |
954 | AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet])); | |
955 | AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet])); | |
956 | loader->LoadRecPoints("update"); | |
957 | loader->CleanRecPoints(); | |
958 | loader->MakeRecPointsContainer(); | |
959 | TTree* clustersTree = loader->TreeR(); | |
960 | if (fRawReader && !reconstructor->HasDigitConversion()) { | |
961 | reconstructor->Reconstruct(fRawReader, clustersTree); | |
962 | } else { | |
963 | loader->LoadDigits("read"); | |
964 | TTree* digitsTree = loader->TreeD(); | |
965 | if (!digitsTree) { | |
966 | AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet])); | |
967 | if (fStopOnError) return kFALSE; | |
968 | } else { | |
969 | reconstructor->Reconstruct(digitsTree, clustersTree); | |
970 | } | |
971 | loader->UnloadDigits(); | |
972 | } | |
973 | loader->WriteRecPoints("OVERWRITE"); | |
974 | loader->UnloadRecPoints(); | |
975 | } | |
976 | ||
977 | if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) { | |
978 | AliError(Form("the following detectors were not found: %s", | |
979 | detStr.Data())); | |
980 | if (fStopOnError) return kFALSE; | |
981 | } | |
982 | ||
983 | return kTRUE; | |
984 | } | |
985 | ||
986 | //_____________________________________________________________________________ | |
987 | Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd) | |
988 | { | |
989 | // run the barrel tracking | |
990 | ||
991 | AliCodeTimerAuto("") | |
992 | ||
993 | AliESDVertex* vertex = NULL; | |
994 | Double_t vtxPos[3] = {0, 0, 0}; | |
995 | Double_t vtxErr[3] = {0.07, 0.07, 0.1}; | |
996 | TArrayF mcVertex(3); | |
997 | if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) { | |
998 | fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex); | |
999 | for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i]; | |
1000 | } | |
1001 | ||
1002 | if (fVertexer) { | |
1003 | if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile); | |
1004 | AliInfo("running the ITS vertex finder"); | |
1005 | if (fLoader[0]) fLoader[0]->LoadRecPoints(); | |
1006 | vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber()); | |
1007 | if (fLoader[0]) fLoader[0]->UnloadRecPoints(); | |
1008 | if(!vertex){ | |
1009 | AliWarning("Vertex not found"); | |
1010 | vertex = new AliESDVertex(); | |
1011 | vertex->SetName("default"); | |
1012 | } | |
1013 | else { | |
1014 | vertex->SetName("reconstructed"); | |
1015 | } | |
1016 | ||
1017 | } else { | |
1018 | AliInfo("getting the primary vertex from MC"); | |
1019 | vertex = new AliESDVertex(vtxPos, vtxErr); | |
1020 | } | |
1021 | ||
1022 | if (vertex) { | |
1023 | vertex->GetXYZ(vtxPos); | |
1024 | vertex->GetSigmaXYZ(vtxErr); | |
1025 | } else { | |
1026 | AliWarning("no vertex reconstructed"); | |
1027 | vertex = new AliESDVertex(vtxPos, vtxErr); | |
1028 | } | |
1029 | esd->SetVertex(vertex); | |
1030 | // if SPD multiplicity has been determined, it is stored in the ESD | |
1031 | AliMultiplicity *mult = fVertexer->GetMultiplicity(); | |
1032 | if(mult)esd->SetMultiplicity(mult); | |
1033 | ||
1034 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
1035 | if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr); | |
1036 | } | |
1037 | delete vertex; | |
1038 | ||
1039 | return kTRUE; | |
1040 | } | |
1041 | ||
1042 | //_____________________________________________________________________________ | |
1043 | Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd) | |
1044 | { | |
1045 | // run the HLT barrel tracking | |
1046 | ||
1047 | AliCodeTimerAuto("") | |
1048 | ||
1049 | if (!fRunLoader) { | |
1050 | AliError("Missing runLoader!"); | |
1051 | return kFALSE; | |
1052 | } | |
1053 | ||
1054 | AliInfo("running HLT tracking"); | |
1055 | ||
1056 | // Get a pointer to the HLT reconstructor | |
1057 | AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1); | |
1058 | if (!reconstructor) return kFALSE; | |
1059 | ||
1060 | // TPC + ITS | |
1061 | for (Int_t iDet = 1; iDet >= 0; iDet--) { | |
1062 | TString detName = fgkDetectorName[iDet]; | |
1063 | AliDebug(1, Form("%s HLT tracking", detName.Data())); | |
1064 | reconstructor->SetOption(detName.Data()); | |
1065 | AliTracker *tracker = reconstructor->CreateTracker(fRunLoader); | |
1066 | if (!tracker) { | |
1067 | AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data())); | |
1068 | if (fStopOnError) return kFALSE; | |
1069 | continue; | |
1070 | } | |
1071 | Double_t vtxPos[3]; | |
1072 | Double_t vtxErr[3]={0.005,0.005,0.010}; | |
1073 | const AliESDVertex *vertex = esd->GetVertex(); | |
1074 | vertex->GetXYZ(vtxPos); | |
1075 | tracker->SetVertex(vtxPos,vtxErr); | |
1076 | if(iDet != 1) { | |
1077 | fLoader[iDet]->LoadRecPoints("read"); | |
1078 | TTree* tree = fLoader[iDet]->TreeR(); | |
1079 | if (!tree) { | |
1080 | AliError(Form("Can't get the %s cluster tree", detName.Data())); | |
1081 | return kFALSE; | |
1082 | } | |
1083 | tracker->LoadClusters(tree); | |
1084 | } | |
1085 | if (tracker->Clusters2Tracks(esd) != 0) { | |
1086 | AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet])); | |
1087 | return kFALSE; | |
1088 | } | |
1089 | if(iDet != 1) { | |
1090 | tracker->UnloadClusters(); | |
1091 | } | |
1092 | delete tracker; | |
1093 | } | |
1094 | ||
1095 | return kTRUE; | |
1096 | } | |
1097 | ||
1098 | //_____________________________________________________________________________ | |
1099 | Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd) | |
1100 | { | |
1101 | // run the muon spectrometer tracking | |
1102 | ||
1103 | AliCodeTimerAuto("") | |
1104 | ||
1105 | if (!fRunLoader) { | |
1106 | AliError("Missing runLoader!"); | |
1107 | return kFALSE; | |
1108 | } | |
1109 | Int_t iDet = 7; // for MUON | |
1110 | ||
1111 | AliInfo("is running..."); | |
1112 | ||
1113 | // Get a pointer to the MUON reconstructor | |
1114 | AliReconstructor *reconstructor = GetReconstructor(iDet); | |
1115 | if (!reconstructor) return kFALSE; | |
1116 | ||
1117 | ||
1118 | TString detName = fgkDetectorName[iDet]; | |
1119 | AliDebug(1, Form("%s tracking", detName.Data())); | |
1120 | AliTracker *tracker = reconstructor->CreateTracker(fRunLoader); | |
1121 | if (!tracker) { | |
1122 | AliWarning(Form("couldn't create a tracker for %s", detName.Data())); | |
1123 | return kFALSE; | |
1124 | } | |
1125 | ||
1126 | // create Tracks | |
1127 | fLoader[iDet]->LoadTracks("update"); | |
1128 | fLoader[iDet]->CleanTracks(); | |
1129 | fLoader[iDet]->MakeTracksContainer(); | |
1130 | ||
1131 | // read RecPoints | |
1132 | fLoader[iDet]->LoadRecPoints("read"); | |
1133 | tracker->LoadClusters(fLoader[iDet]->TreeR()); | |
1134 | ||
1135 | Int_t rv = tracker->Clusters2Tracks(esd); | |
1136 | ||
1137 | fLoader[iDet]->UnloadRecPoints(); | |
1138 | ||
1139 | if ( rv ) | |
1140 | { | |
1141 | AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet])); | |
1142 | return kFALSE; | |
1143 | } | |
1144 | ||
1145 | tracker->UnloadClusters(); | |
1146 | ||
1147 | fLoader[iDet]->UnloadRecPoints(); | |
1148 | ||
1149 | fLoader[iDet]->WriteTracks("OVERWRITE"); | |
1150 | fLoader[iDet]->UnloadTracks(); | |
1151 | ||
1152 | delete tracker; | |
1153 | ||
1154 | return kTRUE; | |
1155 | } | |
1156 | ||
1157 | ||
1158 | //_____________________________________________________________________________ | |
1159 | Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd) | |
1160 | { | |
1161 | // run the barrel tracking | |
1162 | ||
1163 | AliCodeTimerAuto("") | |
1164 | ||
1165 | AliInfo("running tracking"); | |
1166 | ||
1167 | //Fill the ESD with the T0 info (will be used by the TOF) | |
1168 | if (fReconstructor[11]) | |
1169 | GetReconstructor(11)->FillESD(fRunLoader, esd); | |
1170 | ||
1171 | // pass 1: TPC + ITS inwards | |
1172 | for (Int_t iDet = 1; iDet >= 0; iDet--) { | |
1173 | if (!fTracker[iDet]) continue; | |
1174 | AliDebug(1, Form("%s tracking", fgkDetectorName[iDet])); | |
1175 | ||
1176 | // load clusters | |
1177 | fLoader[iDet]->LoadRecPoints("read"); | |
1178 | TTree* tree = fLoader[iDet]->TreeR(); | |
1179 | if (!tree) { | |
1180 | AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet])); | |
1181 | return kFALSE; | |
1182 | } | |
1183 | fTracker[iDet]->LoadClusters(tree); | |
1184 | ||
1185 | // run tracking | |
1186 | if (fTracker[iDet]->Clusters2Tracks(esd) != 0) { | |
1187 | AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet])); | |
1188 | return kFALSE; | |
1189 | } | |
1190 | if (fCheckPointLevel > 1) { | |
1191 | WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet])); | |
1192 | } | |
1193 | // preliminary PID in TPC needed by the ITS tracker | |
1194 | if (iDet == 1) { | |
1195 | GetReconstructor(1)->FillESD(fRunLoader, esd); | |
1196 | GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd); | |
1197 | AliESDpid::MakePID(esd); | |
1198 | } | |
1199 | } | |
1200 | ||
1201 | // pass 2: ALL backwards | |
1202 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
1203 | if (!fTracker[iDet]) continue; | |
1204 | AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet])); | |
1205 | ||
1206 | // load clusters | |
1207 | if (iDet > 1) { // all except ITS, TPC | |
1208 | TTree* tree = NULL; | |
1209 | fLoader[iDet]->LoadRecPoints("read"); | |
1210 | tree = fLoader[iDet]->TreeR(); | |
1211 | if (!tree) { | |
1212 | AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet])); | |
1213 | return kFALSE; | |
1214 | } | |
1215 | fTracker[iDet]->LoadClusters(tree); | |
1216 | } | |
1217 | ||
1218 | // run tracking | |
1219 | if (fTracker[iDet]->PropagateBack(esd) != 0) { | |
1220 | AliError(Form("%s backward propagation failed", fgkDetectorName[iDet])); | |
1221 | // return kFALSE; | |
1222 | } | |
1223 | if (fCheckPointLevel > 1) { | |
1224 | WriteESD(esd, Form("%s.back", fgkDetectorName[iDet])); | |
1225 | } | |
1226 | ||
1227 | // unload clusters | |
1228 | if (iDet > 2) { // all except ITS, TPC, TRD | |
1229 | fTracker[iDet]->UnloadClusters(); | |
1230 | fLoader[iDet]->UnloadRecPoints(); | |
1231 | } | |
1232 | // updated PID in TPC needed by the ITS tracker -MI | |
1233 | if (iDet == 1) { | |
1234 | GetReconstructor(1)->FillESD(fRunLoader, esd); | |
1235 | GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd); | |
1236 | AliESDpid::MakePID(esd); | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | // write space-points to the ESD in case alignment data output | |
1241 | // is switched on | |
1242 | if (fWriteAlignmentData) | |
1243 | WriteAlignmentData(esd); | |
1244 | ||
1245 | // pass 3: TRD + TPC + ITS refit inwards | |
1246 | for (Int_t iDet = 2; iDet >= 0; iDet--) { | |
1247 | if (!fTracker[iDet]) continue; | |
1248 | AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet])); | |
1249 | ||
1250 | // run tracking | |
1251 | if (fTracker[iDet]->RefitInward(esd) != 0) { | |
1252 | AliError(Form("%s inward refit failed", fgkDetectorName[iDet])); | |
1253 | // return kFALSE; | |
1254 | } | |
1255 | if (fCheckPointLevel > 1) { | |
1256 | WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet])); | |
1257 | } | |
1258 | ||
1259 | // unload clusters | |
1260 | fTracker[iDet]->UnloadClusters(); | |
1261 | fLoader[iDet]->UnloadRecPoints(); | |
1262 | } | |
1263 | // | |
1264 | // Propagate track to the vertex - if not done by ITS | |
1265 | // | |
1266 | Int_t ntracks = esd->GetNumberOfTracks(); | |
1267 | for (Int_t itrack=0; itrack<ntracks; itrack++){ | |
1268 | const Double_t kRadius = 3; // beam pipe radius | |
1269 | const Double_t kMaxStep = 5; // max step | |
1270 | const Double_t kMaxD = 123456; // max distance to prim vertex | |
1271 | Double_t fieldZ = AliTracker::GetBz(); // | |
1272 | AliESDtrack * track = esd->GetTrack(itrack); | |
1273 | if (!track) continue; | |
1274 | if (track->IsOn(AliESDtrack::kITSrefit)) continue; | |
1275 | AliTracker::PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE); | |
1276 | track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD); | |
1277 | } | |
1278 | ||
1279 | return kTRUE; | |
1280 | } | |
1281 | ||
1282 | //_____________________________________________________________________________ | |
1283 | Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){ | |
1284 | // | |
1285 | // Remove the data which are not needed for the physics analysis. | |
1286 | // | |
1287 | ||
1288 | AliInfo("Cleaning the ESD..."); | |
1289 | ||
1290 | const AliESDVertex *vertex=esd->GetVertex(); | |
1291 | Double_t vz=vertex->GetZv(); | |
1292 | ||
1293 | Int_t nTracks=esd->GetNumberOfTracks(); | |
1294 | for (Int_t i=0; i<nTracks; i++) { | |
1295 | AliESDtrack *track=esd->GetTrack(i); | |
1296 | ||
1297 | Float_t xy,z; track->GetImpactParameters(xy,z); | |
1298 | if (TMath::Abs(xy) < 50.) continue; | |
1299 | if (vertex->GetStatus()) | |
1300 | if (TMath::Abs(vz-z) < 5.) continue; | |
1301 | ||
1302 | esd->RemoveTrack(i); | |
1303 | } | |
1304 | ||
1305 | return kTRUE; | |
1306 | } | |
1307 | ||
1308 | //_____________________________________________________________________________ | |
1309 | Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors) | |
1310 | { | |
1311 | // fill the event summary data | |
1312 | ||
1313 | AliCodeTimerAuto("") | |
1314 | ||
1315 | TString detStr = detectors; | |
1316 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
1317 | if (!IsSelected(fgkDetectorName[iDet], detStr)) continue; | |
1318 | AliReconstructor* reconstructor = GetReconstructor(iDet); | |
1319 | if (!reconstructor) continue; | |
1320 | ||
1321 | if (!ReadESD(esd, fgkDetectorName[iDet])) { | |
1322 | AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet])); | |
1323 | TTree* clustersTree = NULL; | |
1324 | if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) { | |
1325 | fLoader[iDet]->LoadRecPoints("read"); | |
1326 | clustersTree = fLoader[iDet]->TreeR(); | |
1327 | if (!clustersTree) { | |
1328 | AliError(Form("Can't get the %s clusters tree", | |
1329 | fgkDetectorName[iDet])); | |
1330 | if (fStopOnError) return kFALSE; | |
1331 | } | |
1332 | } | |
1333 | if (fRawReader && !reconstructor->HasDigitConversion()) { | |
1334 | reconstructor->FillESD(fRawReader, clustersTree, esd); | |
1335 | } else { | |
1336 | TTree* digitsTree = NULL; | |
1337 | if (fLoader[iDet]) { | |
1338 | fLoader[iDet]->LoadDigits("read"); | |
1339 | digitsTree = fLoader[iDet]->TreeD(); | |
1340 | if (!digitsTree) { | |
1341 | AliError(Form("Can't get the %s digits tree", | |
1342 | fgkDetectorName[iDet])); | |
1343 | if (fStopOnError) return kFALSE; | |
1344 | } | |
1345 | } | |
1346 | reconstructor->FillESD(digitsTree, clustersTree, esd); | |
1347 | if (fLoader[iDet]) fLoader[iDet]->UnloadDigits(); | |
1348 | } | |
1349 | if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) { | |
1350 | fLoader[iDet]->UnloadRecPoints(); | |
1351 | } | |
1352 | ||
1353 | if (fRawReader) { | |
1354 | reconstructor->FillESD(fRunLoader, fRawReader, esd); | |
1355 | } else { | |
1356 | reconstructor->FillESD(fRunLoader, esd); | |
1357 | } | |
1358 | if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]); | |
1359 | } | |
1360 | } | |
1361 | ||
1362 | if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) { | |
1363 | AliError(Form("the following detectors were not found: %s", | |
1364 | detStr.Data())); | |
1365 | if (fStopOnError) return kFALSE; | |
1366 | } | |
1367 | ||
1368 | return kTRUE; | |
1369 | } | |
1370 | ||
1371 | //_____________________________________________________________________________ | |
1372 | Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd) | |
1373 | { | |
1374 | // Reads the trigger decision which is | |
1375 | // stored in Trigger.root file and fills | |
1376 | // the corresponding esd entries | |
1377 | ||
1378 | AliCodeTimerAuto("") | |
1379 | ||
1380 | AliInfo("Filling trigger information into the ESD"); | |
1381 | ||
1382 | if (fRawReader) { | |
1383 | AliCTPRawStream input(fRawReader); | |
1384 | if (!input.Next()) { | |
1385 | AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !"); | |
1386 | return kFALSE; | |
1387 | } | |
1388 | esd->SetTriggerMask(input.GetClassMask()); | |
1389 | esd->SetTriggerCluster(input.GetClusterMask()); | |
1390 | } | |
1391 | else { | |
1392 | AliRunLoader *runloader = AliRunLoader::GetRunLoader(); | |
1393 | if (runloader) { | |
1394 | if (!runloader->LoadTrigger()) { | |
1395 | AliCentralTrigger *aCTP = runloader->GetTrigger(); | |
1396 | esd->SetTriggerMask(aCTP->GetClassMask()); | |
1397 | esd->SetTriggerCluster(aCTP->GetClusterMask()); | |
1398 | } | |
1399 | else { | |
1400 | AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !"); | |
1401 | return kFALSE; | |
1402 | } | |
1403 | } | |
1404 | else { | |
1405 | AliError("No run loader is available! The trigger information is not stored in the ESD !"); | |
1406 | return kFALSE; | |
1407 | } | |
1408 | } | |
1409 | ||
1410 | return kTRUE; | |
1411 | } | |
1412 | ||
1413 | ||
1414 | ||
1415 | ||
1416 | ||
1417 | //_____________________________________________________________________________ | |
1418 | Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd) | |
1419 | { | |
1420 | // | |
1421 | // Filling information from RawReader Header | |
1422 | // | |
1423 | ||
1424 | AliInfo("Filling information from RawReader Header"); | |
1425 | esd->SetBunchCrossNumber(0); | |
1426 | esd->SetOrbitNumber(0); | |
1427 | esd->SetPeriodNumber(0); | |
1428 | esd->SetTimeStamp(0); | |
1429 | esd->SetEventType(0); | |
1430 | const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader(); | |
1431 | if (eventHeader){ | |
1432 | ||
1433 | const UInt_t *id = eventHeader->GetP("Id"); | |
1434 | esd->SetBunchCrossNumber((id)[1]&0x00000fff); | |
1435 | esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff)); | |
1436 | esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff); | |
1437 | ||
1438 | esd->SetTimeStamp((eventHeader->Get("Timestamp"))); | |
1439 | esd->SetEventType((eventHeader->Get("Type"))); | |
1440 | } | |
1441 | ||
1442 | return kTRUE; | |
1443 | } | |
1444 | ||
1445 | ||
1446 | //_____________________________________________________________________________ | |
1447 | Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const | |
1448 | { | |
1449 | // check whether detName is contained in detectors | |
1450 | // if yes, it is removed from detectors | |
1451 | ||
1452 | // check if all detectors are selected | |
1453 | if ((detectors.CompareTo("ALL") == 0) || | |
1454 | detectors.BeginsWith("ALL ") || | |
1455 | detectors.EndsWith(" ALL") || | |
1456 | detectors.Contains(" ALL ")) { | |
1457 | detectors = "ALL"; | |
1458 | return kTRUE; | |
1459 | } | |
1460 | ||
1461 | // search for the given detector | |
1462 | Bool_t result = kFALSE; | |
1463 | if ((detectors.CompareTo(detName) == 0) || | |
1464 | detectors.BeginsWith(detName+" ") || | |
1465 | detectors.EndsWith(" "+detName) || | |
1466 | detectors.Contains(" "+detName+" ")) { | |
1467 | detectors.ReplaceAll(detName, ""); | |
1468 | result = kTRUE; | |
1469 | } | |
1470 | ||
1471 | // clean up the detectors string | |
1472 | while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " "); | |
1473 | while (detectors.BeginsWith(" ")) detectors.Remove(0, 1); | |
1474 | while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1); | |
1475 | ||
1476 | return result; | |
1477 | } | |
1478 | ||
1479 | //_____________________________________________________________________________ | |
1480 | Bool_t AliReconstruction::InitRunLoader() | |
1481 | { | |
1482 | // get or create the run loader | |
1483 | ||
1484 | if (gAlice) delete gAlice; | |
1485 | gAlice = NULL; | |
1486 | ||
1487 | if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists | |
1488 | // load all base libraries to get the loader classes | |
1489 | TString libs = gSystem->GetLibraries(); | |
1490 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
1491 | TString detName = fgkDetectorName[iDet]; | |
1492 | if (detName == "HLT") continue; | |
1493 | if (libs.Contains("lib" + detName + "base.so")) continue; | |
1494 | gSystem->Load("lib" + detName + "base.so"); | |
1495 | } | |
1496 | fRunLoader = AliRunLoader::Open(fGAliceFileName.Data()); | |
1497 | if (!fRunLoader) { | |
1498 | AliError(Form("no run loader found in file %s", fGAliceFileName.Data())); | |
1499 | CleanUp(); | |
1500 | return kFALSE; | |
1501 | } | |
1502 | fRunLoader->CdGAFile(); | |
1503 | if (gFile->GetKey(AliRunLoader::GetGAliceName())) { | |
1504 | if (fRunLoader->LoadgAlice() == 0) { | |
1505 | gAlice = fRunLoader->GetAliRun(); | |
1506 | AliTracker::SetFieldMap(gAlice->Field(),fUniformField); | |
1507 | } | |
1508 | } | |
1509 | if (!gAlice && !fRawReader) { | |
1510 | AliError(Form("no gAlice object found in file %s", | |
1511 | fGAliceFileName.Data())); | |
1512 | CleanUp(); | |
1513 | return kFALSE; | |
1514 | } | |
1515 | ||
1516 | //PH This is a temporary fix to give access to the kinematics | |
1517 | //PH that is needed for the labels of ITS clusters | |
1518 | fRunLoader->LoadKinematics(); | |
1519 | ||
1520 | } else { // galice.root does not exist | |
1521 | if (!fRawReader) { | |
1522 | AliError(Form("the file %s does not exist", fGAliceFileName.Data())); | |
1523 | CleanUp(); | |
1524 | return kFALSE; | |
1525 | } | |
1526 | fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(), | |
1527 | AliConfig::GetDefaultEventFolderName(), | |
1528 | "recreate"); | |
1529 | if (!fRunLoader) { | |
1530 | AliError(Form("could not create run loader in file %s", | |
1531 | fGAliceFileName.Data())); | |
1532 | CleanUp(); | |
1533 | return kFALSE; | |
1534 | } | |
1535 | fRunLoader->MakeTree("E"); | |
1536 | Int_t iEvent = 0; | |
1537 | while (fRawReader->NextEvent()) { | |
1538 | fRunLoader->SetEventNumber(iEvent); | |
1539 | fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(), | |
1540 | iEvent, iEvent); | |
1541 | fRunLoader->MakeTree("H"); | |
1542 | fRunLoader->TreeE()->Fill(); | |
1543 | iEvent++; | |
1544 | } | |
1545 | fRawReader->RewindEvents(); | |
1546 | if (fNumberOfEventsPerFile > 0) | |
1547 | fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile); | |
1548 | else | |
1549 | fRunLoader->SetNumberOfEventsPerFile(iEvent); | |
1550 | fRunLoader->WriteHeader("OVERWRITE"); | |
1551 | fRunLoader->CdGAFile(); | |
1552 | fRunLoader->Write(0, TObject::kOverwrite); | |
1553 | // AliTracker::SetFieldMap(???); | |
1554 | } | |
1555 | ||
1556 | return kTRUE; | |
1557 | } | |
1558 | ||
1559 | //_____________________________________________________________________________ | |
1560 | AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet) | |
1561 | { | |
1562 | // get the reconstructor object and the loader for a detector | |
1563 | ||
1564 | if (fReconstructor[iDet]) return fReconstructor[iDet]; | |
1565 | ||
1566 | // load the reconstructor object | |
1567 | TPluginManager* pluginManager = gROOT->GetPluginManager(); | |
1568 | TString detName = fgkDetectorName[iDet]; | |
1569 | TString recName = "Ali" + detName + "Reconstructor"; | |
1570 | if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL; | |
1571 | ||
1572 | if (detName == "HLT") { | |
1573 | if (!gROOT->GetClass("AliLevel3")) { | |
1574 | gSystem->Load("libAliHLTSrc.so"); | |
1575 | gSystem->Load("libAliHLTMisc.so"); | |
1576 | gSystem->Load("libAliHLTHough.so"); | |
1577 | gSystem->Load("libAliHLTComp.so"); | |
1578 | } | |
1579 | } | |
1580 | ||
1581 | AliReconstructor* reconstructor = NULL; | |
1582 | // first check if a plugin is defined for the reconstructor | |
1583 | TPluginHandler* pluginHandler = | |
1584 | pluginManager->FindHandler("AliReconstructor", detName); | |
1585 | // if not, add a plugin for it | |
1586 | if (!pluginHandler) { | |
1587 | AliDebug(1, Form("defining plugin for %s", recName.Data())); | |
1588 | TString libs = gSystem->GetLibraries(); | |
1589 | if (libs.Contains("lib" + detName + "base.so") || | |
1590 | (gSystem->Load("lib" + detName + "base.so") >= 0)) { | |
1591 | pluginManager->AddHandler("AliReconstructor", detName, | |
1592 | recName, detName + "rec", recName + "()"); | |
1593 | } else { | |
1594 | pluginManager->AddHandler("AliReconstructor", detName, | |
1595 | recName, detName, recName + "()"); | |
1596 | } | |
1597 | pluginHandler = pluginManager->FindHandler("AliReconstructor", detName); | |
1598 | } | |
1599 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
1600 | reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0); | |
1601 | } | |
1602 | if (reconstructor) { | |
1603 | TObject* obj = fOptions.FindObject(detName.Data()); | |
1604 | if (obj) reconstructor->SetOption(obj->GetTitle()); | |
1605 | reconstructor->Init(fRunLoader); | |
1606 | fReconstructor[iDet] = reconstructor; | |
1607 | } | |
1608 | ||
1609 | // get or create the loader | |
1610 | if (detName != "HLT") { | |
1611 | fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader"); | |
1612 | if (!fLoader[iDet]) { | |
1613 | AliConfig::Instance() | |
1614 | ->CreateDetectorFolders(fRunLoader->GetEventFolder(), | |
1615 | detName, detName); | |
1616 | // first check if a plugin is defined for the loader | |
1617 | pluginHandler = | |
1618 | pluginManager->FindHandler("AliLoader", detName); | |
1619 | // if not, add a plugin for it | |
1620 | if (!pluginHandler) { | |
1621 | TString loaderName = "Ali" + detName + "Loader"; | |
1622 | AliDebug(1, Form("defining plugin for %s", loaderName.Data())); | |
1623 | pluginManager->AddHandler("AliLoader", detName, | |
1624 | loaderName, detName + "base", | |
1625 | loaderName + "(const char*, TFolder*)"); | |
1626 | pluginHandler = pluginManager->FindHandler("AliLoader", detName); | |
1627 | } | |
1628 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
1629 | fLoader[iDet] = | |
1630 | (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(), | |
1631 | fRunLoader->GetEventFolder()); | |
1632 | } | |
1633 | if (!fLoader[iDet]) { // use default loader | |
1634 | fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder()); | |
1635 | } | |
1636 | if (!fLoader[iDet]) { | |
1637 | AliWarning(Form("couldn't get loader for %s", detName.Data())); | |
1638 | if (fStopOnError) return NULL; | |
1639 | } else { | |
1640 | fRunLoader->AddLoader(fLoader[iDet]); | |
1641 | fRunLoader->CdGAFile(); | |
1642 | if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE"); | |
1643 | fRunLoader->Write(0, TObject::kOverwrite); | |
1644 | } | |
1645 | } | |
1646 | } | |
1647 | ||
1648 | return reconstructor; | |
1649 | } | |
1650 | ||
1651 | //_____________________________________________________________________________ | |
1652 | Bool_t AliReconstruction::CreateVertexer() | |
1653 | { | |
1654 | // create the vertexer | |
1655 | ||
1656 | fVertexer = NULL; | |
1657 | AliReconstructor* itsReconstructor = GetReconstructor(0); | |
1658 | if (itsReconstructor) { | |
1659 | fVertexer = itsReconstructor->CreateVertexer(fRunLoader); | |
1660 | } | |
1661 | if (!fVertexer) { | |
1662 | AliWarning("couldn't create a vertexer for ITS"); | |
1663 | if (fStopOnError) return kFALSE; | |
1664 | } | |
1665 | ||
1666 | return kTRUE; | |
1667 | } | |
1668 | ||
1669 | //_____________________________________________________________________________ | |
1670 | Bool_t AliReconstruction::CreateTrackers(const TString& detectors) | |
1671 | { | |
1672 | // create the trackers | |
1673 | ||
1674 | TString detStr = detectors; | |
1675 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
1676 | if (!IsSelected(fgkDetectorName[iDet], detStr)) continue; | |
1677 | AliReconstructor* reconstructor = GetReconstructor(iDet); | |
1678 | if (!reconstructor) continue; | |
1679 | TString detName = fgkDetectorName[iDet]; | |
1680 | if (detName == "HLT") { | |
1681 | fRunHLTTracking = kTRUE; | |
1682 | continue; | |
1683 | } | |
1684 | if (detName == "MUON") { | |
1685 | fRunMuonTracking = kTRUE; | |
1686 | continue; | |
1687 | } | |
1688 | ||
1689 | ||
1690 | fTracker[iDet] = reconstructor->CreateTracker(fRunLoader); | |
1691 | if (!fTracker[iDet] && (iDet < 7)) { | |
1692 | AliWarning(Form("couldn't create a tracker for %s", detName.Data())); | |
1693 | if (fStopOnError) return kFALSE; | |
1694 | } | |
1695 | } | |
1696 | ||
1697 | return kTRUE; | |
1698 | } | |
1699 | ||
1700 | //_____________________________________________________________________________ | |
1701 | void AliReconstruction::CleanUp(TFile* file, TFile* fileOld) | |
1702 | { | |
1703 | // delete trackers and the run loader and close and delete the file | |
1704 | ||
1705 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
1706 | delete fReconstructor[iDet]; | |
1707 | fReconstructor[iDet] = NULL; | |
1708 | fLoader[iDet] = NULL; | |
1709 | delete fTracker[iDet]; | |
1710 | fTracker[iDet] = NULL; | |
1711 | } | |
1712 | delete fVertexer; | |
1713 | fVertexer = NULL; | |
1714 | delete fDiamondProfile; | |
1715 | fDiamondProfile = NULL; | |
1716 | ||
1717 | delete fRunLoader; | |
1718 | fRunLoader = NULL; | |
1719 | delete fRawReader; | |
1720 | fRawReader = NULL; | |
1721 | ||
1722 | if (file) { | |
1723 | file->Close(); | |
1724 | delete file; | |
1725 | } | |
1726 | ||
1727 | if (fileOld) { | |
1728 | fileOld->Close(); | |
1729 | delete fileOld; | |
1730 | gSystem->Unlink("AliESDs.old.root"); | |
1731 | } | |
1732 | } | |
1733 | ||
1734 | //_____________________________________________________________________________ | |
1735 | ||
1736 | Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const | |
1737 | { | |
1738 | // read the ESD event from a file | |
1739 | ||
1740 | if (!esd) return kFALSE; | |
1741 | char fileName[256]; | |
1742 | sprintf(fileName, "ESD_%d.%d_%s.root", | |
1743 | esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep); | |
1744 | if (gSystem->AccessPathName(fileName)) return kFALSE; | |
1745 | ||
1746 | AliInfo(Form("reading ESD from file %s", fileName)); | |
1747 | AliDebug(1, Form("reading ESD from file %s", fileName)); | |
1748 | TFile* file = TFile::Open(fileName); | |
1749 | if (!file || !file->IsOpen()) { | |
1750 | AliError(Form("opening %s failed", fileName)); | |
1751 | delete file; | |
1752 | return kFALSE; | |
1753 | } | |
1754 | ||
1755 | gROOT->cd(); | |
1756 | delete esd; | |
1757 | esd = (AliESDEvent*) file->Get("ESD"); | |
1758 | file->Close(); | |
1759 | delete file; | |
1760 | return kTRUE; | |
1761 | ||
1762 | } | |
1763 | ||
1764 | ||
1765 | ||
1766 | //_____________________________________________________________________________ | |
1767 | void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const | |
1768 | { | |
1769 | // write the ESD event to a file | |
1770 | ||
1771 | if (!esd) return; | |
1772 | char fileName[256]; | |
1773 | sprintf(fileName, "ESD_%d.%d_%s.root", | |
1774 | esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep); | |
1775 | ||
1776 | AliDebug(1, Form("writing ESD to file %s", fileName)); | |
1777 | TFile* file = TFile::Open(fileName, "recreate"); | |
1778 | if (!file || !file->IsOpen()) { | |
1779 | AliError(Form("opening %s failed", fileName)); | |
1780 | } else { | |
1781 | esd->Write("ESD"); | |
1782 | file->Close(); | |
1783 | } | |
1784 | delete file; | |
1785 | } | |
1786 | ||
1787 | ||
1788 | ||
1789 | ||
1790 | ||
1791 | //_____________________________________________________________________________ | |
1792 | void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile) | |
1793 | { | |
1794 | // write all files from the given esd file to an aod file | |
1795 | ||
1796 | // create an AliAOD object | |
1797 | AliAODEvent *aod = new AliAODEvent(); | |
1798 | aod->CreateStdContent(); | |
1799 | ||
1800 | // go to the file | |
1801 | aodFile->cd(); | |
1802 | ||
1803 | // create the tree | |
1804 | TTree *aodTree = new TTree("aodTree", "AliAOD tree"); | |
1805 | aodTree->Branch(aod->GetList()); | |
1806 | ||
1807 | // connect to ESD | |
1808 | TTree *t = (TTree*) esdFile->Get("esdTree"); | |
1809 | AliESDEvent *esd = new AliESDEvent(); | |
1810 | esd->ReadFromTree(t); | |
1811 | ||
1812 | Int_t nEvents = t->GetEntries(); | |
1813 | ||
1814 | // set arrays and pointers | |
1815 | Float_t posF[3]; | |
1816 | Double_t pos[3]; | |
1817 | Double_t p[3]; | |
1818 | Double_t covVtx[6]; | |
1819 | Double_t covTr[21]; | |
1820 | Double_t pid[10]; | |
1821 | ||
1822 | // loop over events and fill them | |
1823 | for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) { | |
1824 | t->GetEntry(iEvent); | |
1825 | ||
1826 | // Multiplicity information needed by the header (to be revised!) | |
1827 | Int_t nTracks = esd->GetNumberOfTracks(); | |
1828 | Int_t nPosTracks = 0; | |
1829 | for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) | |
1830 | if (esd->GetTrack(iTrack)->Charge()> 0) nPosTracks++; | |
1831 | ||
1832 | // Access the header | |
1833 | AliAODHeader *header = aod->GetHeader(); | |
1834 | ||
1835 | // fill the header | |
1836 | header->SetRunNumber (esd->GetRunNumber() ); | |
1837 | header->SetBunchCrossNumber(esd->GetBunchCrossNumber()); | |
1838 | header->SetOrbitNumber (esd->GetOrbitNumber() ); | |
1839 | header->SetPeriodNumber (esd->GetPeriodNumber() ); | |
1840 | header->SetTriggerMask (esd->GetTriggerMask() ); | |
1841 | header->SetTriggerCluster (esd->GetTriggerCluster() ); | |
1842 | header->SetEventType (esd->GetEventType() ); | |
1843 | header->SetMagneticField (esd->GetMagneticField() ); | |
1844 | header->SetZDCN1Energy (esd->GetZDCN1Energy() ); | |
1845 | header->SetZDCP1Energy (esd->GetZDCP1Energy() ); | |
1846 | header->SetZDCN2Energy (esd->GetZDCN2Energy() ); | |
1847 | header->SetZDCP2Energy (esd->GetZDCP2Energy() ); | |
1848 | header->SetZDCEMEnergy (esd->GetZDCEMEnergy() ); | |
1849 | header->SetRefMultiplicity (nTracks); | |
1850 | header->SetRefMultiplicityPos(nPosTracks); | |
1851 | header->SetRefMultiplicityNeg(nTracks - nPosTracks); | |
1852 | header->SetMuonMagFieldScale(-999.); // FIXME | |
1853 | header->SetCentrality(-999.); // FIXME | |
1854 | ||
1855 | Int_t nV0s = esd->GetNumberOfV0s(); | |
1856 | Int_t nCascades = esd->GetNumberOfCascades(); | |
1857 | Int_t nKinks = esd->GetNumberOfKinks(); | |
1858 | Int_t nVertices = nV0s + nCascades + nKinks; | |
1859 | ||
1860 | aod->ResetStd(nTracks, nVertices); | |
1861 | AliAODTrack *aodTrack; | |
1862 | ||
1863 | // Array to take into account the tracks already added to the AOD | |
1864 | Bool_t * usedTrack = NULL; | |
1865 | if (nTracks>0) { | |
1866 | usedTrack = new Bool_t[nTracks]; | |
1867 | for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE; | |
1868 | } | |
1869 | // Array to take into account the V0s already added to the AOD | |
1870 | Bool_t * usedV0 = NULL; | |
1871 | if (nV0s>0) { | |
1872 | usedV0 = new Bool_t[nV0s]; | |
1873 | for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE; | |
1874 | } | |
1875 | // Array to take into account the kinks already added to the AOD | |
1876 | Bool_t * usedKink = NULL; | |
1877 | if (nKinks>0) { | |
1878 | usedKink = new Bool_t[nKinks]; | |
1879 | for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE; | |
1880 | } | |
1881 | ||
1882 | // Access to the AOD container of vertices | |
1883 | TClonesArray &vertices = *(aod->GetVertices()); | |
1884 | Int_t jVertices=0; | |
1885 | ||
1886 | // Access to the AOD container of tracks | |
1887 | TClonesArray &tracks = *(aod->GetTracks()); | |
1888 | Int_t jTracks=0; | |
1889 | ||
1890 | // Add primary vertex. The primary tracks will be defined | |
1891 | // after the loops on the composite objects (V0, cascades, kinks) | |
1892 | const AliESDVertex *vtx = esd->GetPrimaryVertex(); | |
1893 | ||
1894 | vtx->GetXYZ(pos); // position | |
1895 | vtx->GetCovMatrix(covVtx); //covariance matrix | |
1896 | ||
1897 | AliAODVertex * primary = new(vertices[jVertices++]) | |
1898 | AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary); | |
1899 | ||
1900 | // Create vertices starting from the most complex objects | |
1901 | ||
1902 | // Cascades | |
1903 | for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) { | |
1904 | AliESDcascade *cascade = esd->GetCascade(nCascade); | |
1905 | ||
1906 | cascade->GetXYZ(pos[0], pos[1], pos[2]); | |
1907 | cascade->GetPosCovXi(covVtx); | |
1908 | ||
1909 | // Add the cascade vertex | |
1910 | AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos, | |
1911 | covVtx, | |
1912 | cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3 | |
1913 | primary, | |
1914 | nCascade, | |
1915 | AliAODVertex::kCascade); | |
1916 | ||
1917 | primary->AddDaughter(vcascade); | |
1918 | ||
1919 | // Add the V0 from the cascade. The ESD class have to be optimized... | |
1920 | // Now we have to search for the corresponding V0 in the list of V0s | |
1921 | // using the indeces of the positive and negative tracks | |
1922 | ||
1923 | Int_t posFromV0 = cascade->GetPindex(); | |
1924 | Int_t negFromV0 = cascade->GetNindex(); | |
1925 | ||
1926 | ||
1927 | AliESDv0 * v0 = 0x0; | |
1928 | Int_t indV0 = -1; | |
1929 | ||
1930 | for (Int_t iV0=0; iV0<nV0s; ++iV0) { | |
1931 | ||
1932 | v0 = esd->GetV0(iV0); | |
1933 | Int_t posV0 = v0->GetPindex(); | |
1934 | Int_t negV0 = v0->GetNindex(); | |
1935 | ||
1936 | if (posV0==posFromV0 && negV0==negFromV0) { | |
1937 | indV0 = iV0; | |
1938 | break; | |
1939 | } | |
1940 | } | |
1941 | ||
1942 | AliAODVertex * vV0FromCascade = 0x0; | |
1943 | ||
1944 | if (indV0>-1 && !usedV0[indV0] ) { | |
1945 | ||
1946 | // the V0 exists in the array of V0s and is not used | |
1947 | ||
1948 | usedV0[indV0] = kTRUE; | |
1949 | ||
1950 | v0->GetXYZ(pos[0], pos[1], pos[2]); | |
1951 | v0->GetPosCov(covVtx); | |
1952 | ||
1953 | vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos, | |
1954 | covVtx, | |
1955 | v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3 | |
1956 | vcascade, | |
1957 | indV0, | |
1958 | AliAODVertex::kV0); | |
1959 | } else { | |
1960 | ||
1961 | // the V0 doesn't exist in the array of V0s or was used | |
1962 | cerr << "Error: event " << iEvent << " cascade " << nCascade | |
1963 | << " The V0 " << indV0 | |
1964 | << " doesn't exist in the array of V0s or was used!" << endl; | |
1965 | ||
1966 | cascade->GetXYZ(pos[0], pos[1], pos[2]); | |
1967 | cascade->GetPosCov(covVtx); | |
1968 | ||
1969 | vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos, | |
1970 | covVtx, | |
1971 | v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3 | |
1972 | vcascade, | |
1973 | indV0, | |
1974 | AliAODVertex::kV0); | |
1975 | vcascade->AddDaughter(vV0FromCascade); | |
1976 | } | |
1977 | ||
1978 | // Add the positive tracks from the V0 | |
1979 | ||
1980 | if (! usedTrack[posFromV0]) { | |
1981 | ||
1982 | usedTrack[posFromV0] = kTRUE; | |
1983 | ||
1984 | AliESDtrack *esdTrack = esd->GetTrack(posFromV0); | |
1985 | esdTrack->GetPxPyPz(p); | |
1986 | esdTrack->GetXYZ(pos); | |
1987 | esdTrack->GetCovarianceXYZPxPyPz(covTr); | |
1988 | esdTrack->GetESDpid(pid); | |
1989 | ||
1990 | vV0FromCascade->AddDaughter(aodTrack = | |
1991 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
1992 | esdTrack->GetLabel(), | |
1993 | p, | |
1994 | kTRUE, | |
1995 | pos, | |
1996 | kFALSE, | |
1997 | covTr, | |
1998 | (Short_t)esdTrack->Charge(), | |
1999 | esdTrack->GetITSClusterMap(), | |
2000 | pid, | |
2001 | vV0FromCascade, | |
2002 | kTRUE, // check if this is right | |
2003 | kFALSE, // check if this is right | |
2004 | AliAODTrack::kSecondary) | |
2005 | ); | |
2006 | aodTrack->ConvertAliPIDtoAODPID(); | |
2007 | } | |
2008 | else { | |
2009 | cerr << "Error: event " << iEvent << " cascade " << nCascade | |
2010 | << " track " << posFromV0 << " has already been used!" << endl; | |
2011 | } | |
2012 | ||
2013 | // Add the negative tracks from the V0 | |
2014 | ||
2015 | if (!usedTrack[negFromV0]) { | |
2016 | ||
2017 | usedTrack[negFromV0] = kTRUE; | |
2018 | ||
2019 | AliESDtrack *esdTrack = esd->GetTrack(negFromV0); | |
2020 | esdTrack->GetPxPyPz(p); | |
2021 | esdTrack->GetXYZ(pos); | |
2022 | esdTrack->GetCovarianceXYZPxPyPz(covTr); | |
2023 | esdTrack->GetESDpid(pid); | |
2024 | ||
2025 | vV0FromCascade->AddDaughter(aodTrack = | |
2026 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
2027 | esdTrack->GetLabel(), | |
2028 | p, | |
2029 | kTRUE, | |
2030 | pos, | |
2031 | kFALSE, | |
2032 | covTr, | |
2033 | (Short_t)esdTrack->Charge(), | |
2034 | esdTrack->GetITSClusterMap(), | |
2035 | pid, | |
2036 | vV0FromCascade, | |
2037 | kTRUE, // check if this is right | |
2038 | kFALSE, // check if this is right | |
2039 | AliAODTrack::kSecondary) | |
2040 | ); | |
2041 | aodTrack->ConvertAliPIDtoAODPID(); | |
2042 | } | |
2043 | else { | |
2044 | cerr << "Error: event " << iEvent << " cascade " << nCascade | |
2045 | << " track " << negFromV0 << " has already been used!" << endl; | |
2046 | } | |
2047 | ||
2048 | // Add the bachelor track from the cascade | |
2049 | ||
2050 | Int_t bachelor = cascade->GetBindex(); | |
2051 | ||
2052 | if(!usedTrack[bachelor]) { | |
2053 | ||
2054 | usedTrack[bachelor] = kTRUE; | |
2055 | ||
2056 | AliESDtrack *esdTrack = esd->GetTrack(bachelor); | |
2057 | esdTrack->GetPxPyPz(p); | |
2058 | esdTrack->GetXYZ(pos); | |
2059 | esdTrack->GetCovarianceXYZPxPyPz(covTr); | |
2060 | esdTrack->GetESDpid(pid); | |
2061 | ||
2062 | vcascade->AddDaughter(aodTrack = | |
2063 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
2064 | esdTrack->GetLabel(), | |
2065 | p, | |
2066 | kTRUE, | |
2067 | pos, | |
2068 | kFALSE, | |
2069 | covTr, | |
2070 | (Short_t)esdTrack->Charge(), | |
2071 | esdTrack->GetITSClusterMap(), | |
2072 | pid, | |
2073 | vcascade, | |
2074 | kTRUE, // check if this is right | |
2075 | kFALSE, // check if this is right | |
2076 | AliAODTrack::kSecondary) | |
2077 | ); | |
2078 | aodTrack->ConvertAliPIDtoAODPID(); | |
2079 | } | |
2080 | else { | |
2081 | cerr << "Error: event " << iEvent << " cascade " << nCascade | |
2082 | << " track " << bachelor << " has already been used!" << endl; | |
2083 | } | |
2084 | ||
2085 | // Add the primary track of the cascade (if any) | |
2086 | ||
2087 | } // end of the loop on cascades | |
2088 | ||
2089 | // V0s | |
2090 | ||
2091 | for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) { | |
2092 | ||
2093 | if (usedV0[nV0]) continue; // skip if aready added to the AOD | |
2094 | ||
2095 | AliESDv0 *v0 = esd->GetV0(nV0); | |
2096 | ||
2097 | v0->GetXYZ(pos[0], pos[1], pos[2]); | |
2098 | v0->GetPosCov(covVtx); | |
2099 | ||
2100 | AliAODVertex * vV0 = | |
2101 | new(vertices[jVertices++]) AliAODVertex(pos, | |
2102 | covVtx, | |
2103 | v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3 | |
2104 | primary, | |
2105 | nV0, | |
2106 | AliAODVertex::kV0); | |
2107 | primary->AddDaughter(vV0); | |
2108 | ||
2109 | Int_t posFromV0 = v0->GetPindex(); | |
2110 | Int_t negFromV0 = v0->GetNindex(); | |
2111 | ||
2112 | // Add the positive tracks from the V0 | |
2113 | ||
2114 | if (!usedTrack[posFromV0]) { | |
2115 | ||
2116 | usedTrack[posFromV0] = kTRUE; | |
2117 | ||
2118 | AliESDtrack *esdTrack = esd->GetTrack(posFromV0); | |
2119 | esdTrack->GetPxPyPz(p); | |
2120 | esdTrack->GetXYZ(pos); | |
2121 | esdTrack->GetCovarianceXYZPxPyPz(covTr); | |
2122 | esdTrack->GetESDpid(pid); | |
2123 | ||
2124 | vV0->AddDaughter(aodTrack = | |
2125 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
2126 | esdTrack->GetLabel(), | |
2127 | p, | |
2128 | kTRUE, | |
2129 | pos, | |
2130 | kFALSE, | |
2131 | covTr, | |
2132 | (Short_t)esdTrack->Charge(), | |
2133 | esdTrack->GetITSClusterMap(), | |
2134 | pid, | |
2135 | vV0, | |
2136 | kTRUE, // check if this is right | |
2137 | kFALSE, // check if this is right | |
2138 | AliAODTrack::kSecondary) | |
2139 | ); | |
2140 | aodTrack->ConvertAliPIDtoAODPID(); | |
2141 | } | |
2142 | else { | |
2143 | cerr << "Error: event " << iEvent << " V0 " << nV0 | |
2144 | << " track " << posFromV0 << " has already been used!" << endl; | |
2145 | } | |
2146 | ||
2147 | // Add the negative tracks from the V0 | |
2148 | ||
2149 | if (!usedTrack[negFromV0]) { | |
2150 | ||
2151 | usedTrack[negFromV0] = kTRUE; | |
2152 | ||
2153 | AliESDtrack *esdTrack = esd->GetTrack(negFromV0); | |
2154 | esdTrack->GetPxPyPz(p); | |
2155 | esdTrack->GetXYZ(pos); | |
2156 | esdTrack->GetCovarianceXYZPxPyPz(covTr); | |
2157 | esdTrack->GetESDpid(pid); | |
2158 | ||
2159 | vV0->AddDaughter(aodTrack = | |
2160 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
2161 | esdTrack->GetLabel(), | |
2162 | p, | |
2163 | kTRUE, | |
2164 | pos, | |
2165 | kFALSE, | |
2166 | covTr, | |
2167 | (Short_t)esdTrack->Charge(), | |
2168 | esdTrack->GetITSClusterMap(), | |
2169 | pid, | |
2170 | vV0, | |
2171 | kTRUE, // check if this is right | |
2172 | kFALSE, // check if this is right | |
2173 | AliAODTrack::kSecondary) | |
2174 | ); | |
2175 | aodTrack->ConvertAliPIDtoAODPID(); | |
2176 | } | |
2177 | else { | |
2178 | cerr << "Error: event " << iEvent << " V0 " << nV0 | |
2179 | << " track " << negFromV0 << " has already been used!" << endl; | |
2180 | } | |
2181 | ||
2182 | } // end of the loop on V0s | |
2183 | ||
2184 | // Kinks: it is a big mess the access to the information in the kinks | |
2185 | // The loop is on the tracks in order to find the mother and daugther of each kink | |
2186 | ||
2187 | ||
2188 | for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) { | |
2189 | ||
2190 | ||
2191 | AliESDtrack * esdTrack = esd->GetTrack(iTrack); | |
2192 | ||
2193 | Int_t ikink = esdTrack->GetKinkIndex(0); | |
2194 | ||
2195 | if (ikink) { | |
2196 | // Negative kink index: mother, positive: daughter | |
2197 | ||
2198 | // Search for the second track of the kink | |
2199 | ||
2200 | for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) { | |
2201 | ||
2202 | AliESDtrack * esdTrack1 = esd->GetTrack(jTrack); | |
2203 | ||
2204 | Int_t jkink = esdTrack1->GetKinkIndex(0); | |
2205 | ||
2206 | if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) { | |
2207 | ||
2208 | // The two tracks are from the same kink | |
2209 | ||
2210 | if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks | |
2211 | ||
2212 | Int_t imother = -1; | |
2213 | Int_t idaughter = -1; | |
2214 | ||
2215 | if (ikink<0 && jkink>0) { | |
2216 | ||
2217 | imother = iTrack; | |
2218 | idaughter = jTrack; | |
2219 | } | |
2220 | else if (ikink>0 && jkink<0) { | |
2221 | ||
2222 | imother = jTrack; | |
2223 | idaughter = iTrack; | |
2224 | } | |
2225 | else { | |
2226 | cerr << "Error: Wrong combination of kink indexes: " | |
2227 | << ikink << " " << jkink << endl; | |
2228 | continue; | |
2229 | } | |
2230 | ||
2231 | // Add the mother track | |
2232 | ||
2233 | AliAODTrack * mother = NULL; | |
2234 | ||
2235 | if (!usedTrack[imother]) { | |
2236 | ||
2237 | usedTrack[imother] = kTRUE; | |
2238 | ||
2239 | AliESDtrack *esdTrack = esd->GetTrack(imother); | |
2240 | esdTrack->GetPxPyPz(p); | |
2241 | esdTrack->GetXYZ(pos); | |
2242 | esdTrack->GetCovarianceXYZPxPyPz(covTr); | |
2243 | esdTrack->GetESDpid(pid); | |
2244 | ||
2245 | mother = | |
2246 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
2247 | esdTrack->GetLabel(), | |
2248 | p, | |
2249 | kTRUE, | |
2250 | pos, | |
2251 | kFALSE, | |
2252 | covTr, | |
2253 | (Short_t)esdTrack->Charge(), | |
2254 | esdTrack->GetITSClusterMap(), | |
2255 | pid, | |
2256 | primary, | |
2257 | kTRUE, // check if this is right | |
2258 | kTRUE, // check if this is right | |
2259 | AliAODTrack::kPrimary); | |
2260 | primary->AddDaughter(mother); | |
2261 | mother->ConvertAliPIDtoAODPID(); | |
2262 | } | |
2263 | else { | |
2264 | cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1 | |
2265 | << " track " << imother << " has already been used!" << endl; | |
2266 | } | |
2267 | ||
2268 | // Add the kink vertex | |
2269 | AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1); | |
2270 | ||
2271 | AliAODVertex * vkink = | |
2272 | new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(), | |
2273 | NULL, | |
2274 | 0., | |
2275 | mother, | |
2276 | esdTrack->GetID(), // This is the track ID of the mother's track! | |
2277 | AliAODVertex::kKink); | |
2278 | // Add the daughter track | |
2279 | ||
2280 | AliAODTrack * daughter = NULL; | |
2281 | ||
2282 | if (!usedTrack[idaughter]) { | |
2283 | ||
2284 | usedTrack[idaughter] = kTRUE; | |
2285 | ||
2286 | AliESDtrack *esdTrack = esd->GetTrack(idaughter); | |
2287 | esdTrack->GetPxPyPz(p); | |
2288 | esdTrack->GetXYZ(pos); | |
2289 | esdTrack->GetCovarianceXYZPxPyPz(covTr); | |
2290 | esdTrack->GetESDpid(pid); | |
2291 | ||
2292 | daughter = | |
2293 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
2294 | esdTrack->GetLabel(), | |
2295 | p, | |
2296 | kTRUE, | |
2297 | pos, | |
2298 | kFALSE, | |
2299 | covTr, | |
2300 | (Short_t)esdTrack->Charge(), | |
2301 | esdTrack->GetITSClusterMap(), | |
2302 | pid, | |
2303 | vkink, | |
2304 | kTRUE, // check if this is right | |
2305 | kTRUE, // check if this is right | |
2306 | AliAODTrack::kPrimary); | |
2307 | vkink->AddDaughter(daughter); | |
2308 | daughter->ConvertAliPIDtoAODPID(); | |
2309 | } | |
2310 | else { | |
2311 | cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1 | |
2312 | << " track " << idaughter << " has already been used!" << endl; | |
2313 | } | |
2314 | ||
2315 | ||
2316 | } | |
2317 | } | |
2318 | ||
2319 | } | |
2320 | ||
2321 | } | |
2322 | ||
2323 | ||
2324 | // Tracks (primary and orphan) | |
2325 | ||
2326 | for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) { | |
2327 | ||
2328 | ||
2329 | if (usedTrack[nTrack]) continue; | |
2330 | ||
2331 | AliESDtrack *esdTrack = esd->GetTrack(nTrack); | |
2332 | esdTrack->GetPxPyPz(p); | |
2333 | esdTrack->GetXYZ(pos); | |
2334 | esdTrack->GetCovarianceXYZPxPyPz(covTr); | |
2335 | esdTrack->GetESDpid(pid); | |
2336 | ||
2337 | Float_t impactXY, impactZ; | |
2338 | ||
2339 | esdTrack->GetImpactParameters(impactXY,impactZ); | |
2340 | ||
2341 | if (impactXY<3) { | |
2342 | // track inside the beam pipe | |
2343 | ||
2344 | primary->AddDaughter(aodTrack = | |
2345 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
2346 | esdTrack->GetLabel(), | |
2347 | p, | |
2348 | kTRUE, | |
2349 | pos, | |
2350 | kFALSE, | |
2351 | covTr, | |
2352 | (Short_t)esdTrack->Charge(), | |
2353 | esdTrack->GetITSClusterMap(), | |
2354 | pid, | |
2355 | primary, | |
2356 | kTRUE, // check if this is right | |
2357 | kTRUE, // check if this is right | |
2358 | AliAODTrack::kPrimary) | |
2359 | ); | |
2360 | aodTrack->ConvertAliPIDtoAODPID(); | |
2361 | } | |
2362 | else { | |
2363 | // outside the beam pipe: orphan track | |
2364 | aodTrack = | |
2365 | new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(), | |
2366 | esdTrack->GetLabel(), | |
2367 | p, | |
2368 | kTRUE, | |
2369 | pos, | |
2370 | kFALSE, | |
2371 | covTr, | |
2372 | (Short_t)esdTrack->Charge(), | |
2373 | esdTrack->GetITSClusterMap(), | |
2374 | pid, | |
2375 | NULL, | |
2376 | kFALSE, // check if this is right | |
2377 | kFALSE, // check if this is right | |
2378 | AliAODTrack::kOrphan); | |
2379 | aodTrack->ConvertAliPIDtoAODPID(); | |
2380 | } | |
2381 | } // end of loop on tracks | |
2382 | ||
2383 | // muon tracks | |
2384 | Int_t nMuTracks = esd->GetNumberOfMuonTracks(); | |
2385 | for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) { | |
2386 | ||
2387 | AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack); | |
2388 | p[0] = esdMuTrack->Px(); | |
2389 | p[1] = esdMuTrack->Py(); | |
2390 | p[2] = esdMuTrack->Pz(); | |
2391 | pos[0] = primary->GetX(); | |
2392 | pos[1] = primary->GetY(); | |
2393 | pos[2] = primary->GetZ(); | |
2394 | ||
2395 | // has to be changed once the muon pid is provided by the ESD | |
2396 | for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.; | |
2397 | ||
2398 | primary->AddDaughter(aodTrack = | |
2399 | new(tracks[jTracks++]) AliAODTrack(0, // no ID provided | |
2400 | 0, // no label provided | |
2401 | p, | |
2402 | kTRUE, | |
2403 | pos, | |
2404 | kFALSE, | |
2405 | NULL, // no covariance matrix provided | |
2406 | esdMuTrack->Charge(), | |
2407 | 0, // ITSClusterMap is set below | |
2408 | pid, | |
2409 | primary, | |
2410 | kFALSE, // muon tracks are not used to fit the primary vtx | |
2411 | kFALSE, // not used for vertex fit | |
2412 | AliAODTrack::kPrimary) | |
2413 | ); | |
2414 | ||
2415 | aodTrack->SetHitsPatternInTrigCh(esdMuTrack->GetHitsPatternInTrigCh()); | |
2416 | Int_t track2Trigger = esdMuTrack->GetMatchTrigger(); | |
2417 | aodTrack->SetMatchTrigger(track2Trigger); | |
2418 | if (track2Trigger) | |
2419 | aodTrack->SetChi2MatchTrigger(esdMuTrack->GetChi2MatchTrigger()); | |
2420 | else | |
2421 | aodTrack->SetChi2MatchTrigger(0.); | |
2422 | } | |
2423 | ||
2424 | // Access to the AOD container of clusters | |
2425 | TClonesArray &clusters = *(aod->GetClusters()); | |
2426 | Int_t jClusters=0; | |
2427 | ||
2428 | // Calo Clusters | |
2429 | Int_t nClusters = esd->GetNumberOfCaloClusters(); | |
2430 | ||
2431 | for (Int_t iClust=0; iClust<nClusters; ++iClust) { | |
2432 | ||
2433 | AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust); | |
2434 | ||
2435 | Int_t id = cluster->GetID(); | |
2436 | Int_t label = -1; | |
2437 | Float_t energy = cluster->E(); | |
2438 | cluster->GetPosition(posF); | |
2439 | AliAODVertex *prodVertex = primary; | |
2440 | AliAODTrack *primTrack = NULL; | |
2441 | Char_t ttype=AliAODCluster::kUndef; | |
2442 | ||
2443 | if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral; | |
2444 | else if (cluster->IsEMCAL()) { | |
2445 | ||
2446 | if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster) | |
2447 | ttype = AliAODCluster::kEMCALPseudoCluster; | |
2448 | else | |
2449 | ttype = AliAODCluster::kEMCALClusterv1; | |
2450 | ||
2451 | } | |
2452 | ||
2453 | new(clusters[jClusters++]) AliAODCluster(id, | |
2454 | label, | |
2455 | energy, | |
2456 | pos, | |
2457 | NULL, // no covariance matrix provided | |
2458 | NULL, // no pid for clusters provided | |
2459 | prodVertex, | |
2460 | primTrack, | |
2461 | ttype); | |
2462 | ||
2463 | } // end of loop on calo clusters | |
2464 | ||
2465 | // tracklets | |
2466 | const AliMultiplicity *mult = esd->GetMultiplicity(); | |
2467 | if (mult) { | |
2468 | if (mult->GetNumberOfTracklets()>0) { | |
2469 | aod->GetTracklets()->CreateContainer(mult->GetNumberOfTracklets()); | |
2470 | ||
2471 | for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) { | |
2472 | aod->GetTracklets()->SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n)); | |
2473 | } | |
2474 | } | |
2475 | } else { | |
2476 | Printf("ERROR: AliMultiplicity could not be retrieved from ESD"); | |
2477 | } | |
2478 | ||
2479 | delete [] usedTrack; | |
2480 | delete [] usedV0; | |
2481 | delete [] usedKink; | |
2482 | ||
2483 | // fill the tree for this event | |
2484 | aodTree->Fill(); | |
2485 | } // end of event loop | |
2486 | ||
2487 | aodTree->GetUserInfo()->Add(aod); | |
2488 | ||
2489 | // close ESD file | |
2490 | esdFile->Close(); | |
2491 | ||
2492 | // write the tree to the specified file | |
2493 | aodFile = aodTree->GetCurrentFile(); | |
2494 | aodFile->cd(); | |
2495 | aodTree->Write(); | |
2496 | ||
2497 | return; | |
2498 | } | |
2499 | ||
2500 | void AliReconstruction::WriteAlignmentData(AliESDEvent* esd) | |
2501 | { | |
2502 | // Write space-points which are then used in the alignment procedures | |
2503 | // For the moment only ITS, TRD and TPC | |
2504 | ||
2505 | // Load TOF clusters | |
2506 | if (fTracker[3]){ | |
2507 | fLoader[3]->LoadRecPoints("read"); | |
2508 | TTree* tree = fLoader[3]->TreeR(); | |
2509 | if (!tree) { | |
2510 | AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3])); | |
2511 | return; | |
2512 | } | |
2513 | fTracker[3]->LoadClusters(tree); | |
2514 | } | |
2515 | Int_t ntracks = esd->GetNumberOfTracks(); | |
2516 | for (Int_t itrack = 0; itrack < ntracks; itrack++) | |
2517 | { | |
2518 | AliESDtrack *track = esd->GetTrack(itrack); | |
2519 | Int_t nsp = 0; | |
2520 | Int_t idx[200]; | |
2521 | for (Int_t iDet = 3; iDet >= 0; iDet--) | |
2522 | nsp += track->GetNcls(iDet); | |
2523 | if (nsp) { | |
2524 | AliTrackPointArray *sp = new AliTrackPointArray(nsp); | |
2525 | track->SetTrackPointArray(sp); | |
2526 | Int_t isptrack = 0; | |
2527 | for (Int_t iDet = 3; iDet >= 0; iDet--) { | |
2528 | AliTracker *tracker = fTracker[iDet]; | |
2529 | if (!tracker) continue; | |
2530 | Int_t nspdet = track->GetNcls(iDet); | |
2531 | if (nspdet <= 0) continue; | |
2532 | track->GetClusters(iDet,idx); | |
2533 | AliTrackPoint p; | |
2534 | Int_t isp = 0; | |
2535 | Int_t isp2 = 0; | |
2536 | while (isp < nspdet) { | |
2537 | Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++; | |
2538 | const Int_t kNTPCmax = 159; | |
2539 | if (iDet==1 && isp2>kNTPCmax) break; // to be fixed | |
2540 | if (!isvalid) continue; | |
2541 | sp->AddPoint(isptrack,&p); isptrack++; isp++; | |
2542 | } | |
2543 | } | |
2544 | } | |
2545 | } | |
2546 | if (fTracker[3]){ | |
2547 | fTracker[3]->UnloadClusters(); | |
2548 | fLoader[3]->UnloadRecPoints(); | |
2549 | } | |
2550 | } | |
2551 | ||
2552 | //_____________________________________________________________________________ | |
2553 | void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd) | |
2554 | { | |
2555 | // The method reads the raw-data error log | |
2556 | // accumulated within the rawReader. | |
2557 | // It extracts the raw-data errors related to | |
2558 | // the current event and stores them into | |
2559 | // a TClonesArray inside the esd object. | |
2560 | ||
2561 | if (!fRawReader) return; | |
2562 | ||
2563 | for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) { | |
2564 | ||
2565 | AliRawDataErrorLog *log = fRawReader->GetErrorLog(i); | |
2566 | if (!log) continue; | |
2567 | if (iEvent != log->GetEventNumber()) continue; | |
2568 | ||
2569 | esd->AddRawDataErrorLog(log); | |
2570 | } | |
2571 | ||
2572 | } | |
2573 | ||
2574 | TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){ | |
2575 | // Dump a file content into a char in TNamed | |
2576 | ifstream in; | |
2577 | in.open(fPath.Data(),ios::in | ios::binary|ios::ate); | |
2578 | Int_t kBytes = (Int_t)in.tellg(); | |
2579 | printf("Size: %d \n",kBytes); | |
2580 | TNamed *fn = 0; | |
2581 | if(in.good()){ | |
2582 | char* memblock = new char [kBytes]; | |
2583 | in.seekg (0, ios::beg); | |
2584 | in.read (memblock, kBytes); | |
2585 | in.close(); | |
2586 | TString fData(memblock,kBytes); | |
2587 | fn = new TNamed(fName,fData); | |
2588 | printf("fData Size: %d \n",fData.Sizeof()); | |
2589 | printf("fName Size: %d \n",fName.Sizeof()); | |
2590 | printf("fn Size: %d \n",fn->Sizeof()); | |
2591 | delete[] memblock; | |
2592 | } | |
2593 | else{ | |
2594 | AliInfo(Form("Could not Open %s\n",fPath.Data())); | |
2595 | } | |
2596 | ||
2597 | return fn; | |
2598 | } | |
2599 | ||
2600 | void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){ | |
2601 | // This is not really needed in AliReconstruction at the moment | |
2602 | // but can serve as a template | |
2603 | ||
2604 | TList *fList = fTree->GetUserInfo(); | |
2605 | TNamed *fn = (TNamed*)fList->FindObject(fName.Data()); | |
2606 | printf("fn Size: %d \n",fn->Sizeof()); | |
2607 | ||
2608 | TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works | |
2609 | const char* cdata = fn->GetTitle(); | |
2610 | printf("fTmp Size %d\n",fTmp.Sizeof()); | |
2611 | ||
2612 | int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()... | |
2613 | printf("calculated size %d\n",size); | |
2614 | ofstream out(fName.Data(),ios::out | ios::binary); | |
2615 | out.write(cdata,size); | |
2616 | out.close(); | |
2617 | ||
2618 | } | |
2619 | ||
2620 | //_____________________________________________________________________________ | |
2621 | AliQualAssDataMaker * AliReconstruction::GetQualAssDataMaker(Int_t iDet) | |
2622 | { | |
2623 | // get the quality assurance data maker object and the loader for a detector | |
2624 | ||
2625 | if (fQualAssDataMaker[iDet]) | |
2626 | return fQualAssDataMaker[iDet]; | |
2627 | ||
2628 | // load the QA data maker object | |
2629 | TPluginManager* pluginManager = gROOT->GetPluginManager(); | |
2630 | TString detName = fgkDetectorName[iDet]; | |
2631 | TString qadmName = "Ali" + detName + "QualAssDataMaker"; | |
2632 | if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) | |
2633 | return NULL; | |
2634 | ||
2635 | AliQualAssDataMaker * qadm = NULL; | |
2636 | // first check if a plugin is defined for the quality assurance data maker | |
2637 | TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQualAssDataMaker", detName); | |
2638 | // if not, add a plugin for it | |
2639 | if (!pluginHandler) { | |
2640 | AliDebug(1, Form("defining plugin for %s", qadmName.Data())); | |
2641 | TString libs = gSystem->GetLibraries(); | |
2642 | if (libs.Contains("lib" + detName + "base.so") || | |
2643 | (gSystem->Load("lib" + detName + "base.so") >= 0)) { | |
2644 | pluginManager->AddHandler("AliQualAssDataMaker", detName, | |
2645 | qadmName, detName + "qadm", qadmName + "()"); | |
2646 | } else { | |
2647 | pluginManager->AddHandler("AliQualAssDataMaker", detName, | |
2648 | qadmName, detName, qadmName + "()"); | |
2649 | } | |
2650 | pluginHandler = pluginManager->FindHandler("AliQualAssDataMaker", detName); | |
2651 | } | |
2652 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
2653 | qadm = (AliQualAssDataMaker *) pluginHandler->ExecPlugin(0); | |
2654 | } | |
2655 | if (qadm) { | |
2656 | // TObject* obj = fOptions.FindObject(detName.Data()); | |
2657 | // if (obj) reconstructor->SetOption(obj->GetTitle()); | |
2658 | fQualAssDataMaker[iDet] = qadm; | |
2659 | } | |
2660 | ||
2661 | // get or create the loader | |
2662 | fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader"); | |
2663 | if (!fLoader[iDet]) { | |
2664 | AliConfig::Instance() | |
2665 | ->CreateDetectorFolders(fRunLoader->GetEventFolder(), | |
2666 | detName, detName); | |
2667 | // first check if a plugin is defined for the loader | |
2668 | pluginHandler = | |
2669 | pluginManager->FindHandler("AliLoader", detName); | |
2670 | // if not, add a plugin for it | |
2671 | if (!pluginHandler) { | |
2672 | TString loaderName = "Ali" + detName + "Loader"; | |
2673 | AliDebug(1, Form("defining plugin for %s", loaderName.Data())); | |
2674 | pluginManager->AddHandler("AliLoader", detName, | |
2675 | loaderName, detName + "base", | |
2676 | loaderName + "(const char*, TFolder*)"); | |
2677 | pluginHandler = pluginManager->FindHandler("AliLoader", detName); | |
2678 | } | |
2679 | if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) { | |
2680 | fLoader[iDet] = | |
2681 | (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(), | |
2682 | fRunLoader->GetEventFolder()); | |
2683 | } | |
2684 | if (!fLoader[iDet]) { // use default loader | |
2685 | fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder()); | |
2686 | } | |
2687 | if (!fLoader[iDet]) { | |
2688 | AliWarning(Form("couldn't get loader for %s", detName.Data())); | |
2689 | if (fStopOnError) return NULL; | |
2690 | } else { | |
2691 | fRunLoader->AddLoader(fLoader[iDet]); | |
2692 | fRunLoader->CdGAFile(); | |
2693 | if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE"); | |
2694 | fRunLoader->Write(0, TObject::kOverwrite); | |
2695 | } | |
2696 | } | |
2697 | ||
2698 | return qadm; | |
2699 | } | |
2700 | ||
2701 | //_____________________________________________________________________________ | |
2702 | Bool_t AliReconstruction::RunQualAss(const char* detectors, AliESDEvent *& esd) | |
2703 | { | |
2704 | // run the Quality Assurance data producer | |
2705 | ||
2706 | AliCodeTimerAuto("") | |
2707 | TString detStr = detectors; | |
2708 | for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) { | |
2709 | if (!IsSelected(fgkDetectorName[iDet], detStr)) | |
2710 | continue; | |
2711 | AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet); | |
2712 | if (!qadm) | |
2713 | continue; | |
2714 | AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet])); | |
2715 | AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet])); | |
2716 | ||
2717 | qadm->SetData(esd) ; | |
2718 | qadm->Exec(AliQualAss::kESDS) ; | |
2719 | ||
2720 | AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet])); | |
2721 | } | |
2722 | if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) { | |
2723 | AliError(Form("the following detectors were not found: %s", | |
2724 | detStr.Data())); | |
2725 | if (fStopOnError) | |
2726 | return kFALSE; | |
2727 | } | |
2728 | ||
2729 | return kTRUE; | |
2730 | } |