1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for running the reconstruction //
22 // Clusters and tracks are created for all detectors and all events by //
25 // AliReconstruction rec; //
28 // The Run method returns kTRUE in case of successful execution. //
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 //
33 // rec.SetInput("..."); //
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 //
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 //
45 // rec.SetEventRange(..., ...); //
47 // The index -1 (default) can be used for the last event to indicate no //
48 // upper limit of the event range. //
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): //
56 // rec.SetNumberOfEventsPerFile(...); //
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 //
63 // rec.SetGAliceFile("..."); //
65 // The local reconstruction can be switched on or off for individual //
68 // rec.SetRunLocalReconstruction("..."); //
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. //
74 // The reconstruction of the primary vertex position can be switched off by //
76 // rec.SetRunVertexFinder(kFALSE); //
78 // The tracking and the creation of ESD tracks can be switched on for //
79 // selected detectors by //
81 // rec.SetRunTracking("..."); //
83 // Uniform/nonuniform field tracking switches (default: uniform field) //
85 // rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) //
87 // The filling of additional ESD information can be steered by //
89 // rec.SetFillESD("..."); //
91 // Again, for both methods the string specifies the list of detectors. //
92 // The default is "ALL". //
94 // The call of the shortcut method //
96 // rec.SetRunReconstruction("..."); //
98 // is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
99 // SetFillESD with the same detector selecting string as argument. //
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. //
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. //
115 ///////////////////////////////////////////////////////////////////////////////
121 #include <TPluginManager.h>
122 #include <TStopwatch.h>
123 #include <TGeoManager.h>
124 #include <TLorentzVector.h>
126 #include "AliReconstruction.h"
127 #include "AliReconstructor.h"
129 #include "AliRunLoader.h"
131 #include "AliRawReaderFile.h"
132 #include "AliRawReaderDate.h"
133 #include "AliRawReaderRoot.h"
134 #include "AliRawEventHeaderBase.h"
136 #include "AliESDfriend.h"
137 #include "AliESDVertex.h"
138 #include "AliMultiplicity.h"
139 #include "AliTracker.h"
140 #include "AliVertexer.h"
141 #include "AliVertexerTracks.h"
142 #include "AliV0vertexer.h"
143 #include "AliCascadeVertexer.h"
144 #include "AliHeader.h"
145 #include "AliGenEventHeader.h"
147 #include "AliESDpid.h"
148 #include "AliESDtrack.h"
150 #include "AliRunTag.h"
151 #include "AliDetectorTag.h"
152 #include "AliEventTag.h"
154 #include "AliGeomManager.h"
155 #include "AliTrackPointArray.h"
156 #include "AliCDBManager.h"
157 #include "AliCDBEntry.h"
158 #include "AliAlignObj.h"
160 #include "AliCentralTrigger.h"
161 #include "AliCTPRawStream.h"
163 #include "AliAODEvent.h"
164 #include "AliAODHeader.h"
165 #include "AliAODTrack.h"
166 #include "AliAODVertex.h"
167 #include "AliAODCluster.h"
170 ClassImp(AliReconstruction)
173 //_____________________________________________________________________________
174 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
176 //_____________________________________________________________________________
177 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
178 const char* name, const char* title) :
181 fUniformField(kTRUE),
182 fRunVertexFinder(kTRUE),
183 fRunHLTTracking(kFALSE),
184 fRunMuonTracking(kFALSE),
185 fStopOnError(kFALSE),
186 fWriteAlignmentData(kFALSE),
187 fWriteESDfriend(kFALSE),
189 fFillTriggerESD(kTRUE),
191 fRunLocalReconstruction("ALL"),
194 fGAliceFileName(gAliceFilename),
199 fNumberOfEventsPerFile(1),
202 fLoadAlignFromCDB(kTRUE),
203 fLoadAlignData("ALL"),
209 fDiamondProfile(NULL),
211 fAlignObjArray(NULL),
215 // create reconstruction object with default parameters
217 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
218 fReconstructor[iDet] = NULL;
219 fLoader[iDet] = NULL;
220 fTracker[iDet] = NULL;
225 //_____________________________________________________________________________
226 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
229 fUniformField(rec.fUniformField),
230 fRunVertexFinder(rec.fRunVertexFinder),
231 fRunHLTTracking(rec.fRunHLTTracking),
232 fRunMuonTracking(rec.fRunMuonTracking),
233 fStopOnError(rec.fStopOnError),
234 fWriteAlignmentData(rec.fWriteAlignmentData),
235 fWriteESDfriend(rec.fWriteESDfriend),
236 fWriteAOD(rec.fWriteAOD),
237 fFillTriggerESD(rec.fFillTriggerESD),
239 fRunLocalReconstruction(rec.fRunLocalReconstruction),
240 fRunTracking(rec.fRunTracking),
241 fFillESD(rec.fFillESD),
242 fGAliceFileName(rec.fGAliceFileName),
244 fEquipIdMap(rec.fEquipIdMap),
245 fFirstEvent(rec.fFirstEvent),
246 fLastEvent(rec.fLastEvent),
247 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
250 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
251 fLoadAlignData(rec.fLoadAlignData),
257 fDiamondProfile(NULL),
259 fAlignObjArray(rec.fAlignObjArray),
260 fCDBUri(rec.fCDBUri),
265 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
266 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
268 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
269 fReconstructor[iDet] = NULL;
270 fLoader[iDet] = NULL;
271 fTracker[iDet] = NULL;
273 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
274 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
278 //_____________________________________________________________________________
279 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
281 // assignment operator
283 this->~AliReconstruction();
284 new(this) AliReconstruction(rec);
288 //_____________________________________________________________________________
289 AliReconstruction::~AliReconstruction()
295 fSpecCDBUri.Delete();
298 //_____________________________________________________________________________
299 void AliReconstruction::InitCDBStorage()
301 // activate a default CDB storage
302 // First check if we have any CDB storage set, because it is used
303 // to retrieve the calibration and alignment constants
305 AliCDBManager* man = AliCDBManager::Instance();
306 if (man->IsDefaultStorageSet())
308 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
309 AliWarning("Default CDB storage has been already set !");
310 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
311 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
315 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
316 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
317 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
318 man->SetDefaultStorage(fCDBUri);
321 // Now activate the detector specific CDB storage locations
322 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
323 TObject* obj = fSpecCDBUri[i];
325 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
326 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
327 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
328 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
333 //_____________________________________________________________________________
334 void AliReconstruction::SetDefaultStorage(const char* uri) {
335 // Store the desired default CDB storage location
336 // Activate it later within the Run() method
342 //_____________________________________________________________________________
343 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
344 // Store a detector-specific CDB storage location
345 // Activate it later within the Run() method
347 AliCDBPath aPath(calibType);
348 if(!aPath.IsValid()){
349 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
350 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
351 if(!strcmp(calibType, fgkDetectorName[iDet])) {
352 aPath.SetPath(Form("%s/*", calibType));
353 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
357 if(!aPath.IsValid()){
358 AliError(Form("Not a valid path or detector: %s", calibType));
363 // check that calibType refers to a "valid" detector name
364 Bool_t isDetector = kFALSE;
365 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
366 TString detName = fgkDetectorName[iDet];
367 if(aPath.GetLevel0() == detName) {
374 AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
378 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
379 if (obj) fSpecCDBUri.Remove(obj);
380 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
384 //_____________________________________________________________________________
385 Bool_t AliReconstruction::SetRunNumber()
387 // The method is called in Run() in order
388 // to set a correct run number.
389 // In case of raw data reconstruction the
390 // run number is taken from the raw data header
392 if(AliCDBManager::Instance()->GetRun() < 0) {
394 AliError("No run loader is found !");
397 // read run number from gAlice
398 if(fRunLoader->GetAliRun())
399 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
402 if(fRawReader->NextEvent()) {
403 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
404 fRawReader->RewindEvents();
407 AliError("No raw-data events found !");
412 AliError("Neither gAlice nor RawReader objects are found !");
416 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
421 //_____________________________________________________________________________
422 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
424 // Read the alignment objects from CDB.
425 // Each detector is supposed to have the
426 // alignment objects in DET/Align/Data CDB path.
427 // All the detector objects are then collected,
428 // sorted by geometry level (starting from ALIC) and
429 // then applied to the TGeo geometry.
430 // Finally an overlaps check is performed.
432 // Load alignment data from CDB and fill fAlignObjArray
433 if(fLoadAlignFromCDB){
435 TString detStr = detectors;
436 TString loadAlObjsListOfDets = "";
438 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
439 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
440 loadAlObjsListOfDets += fgkDetectorName[iDet];
441 loadAlObjsListOfDets += " ";
442 } // end loop over detectors
443 (AliGeomManager::Instance())->ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
445 // Check if the array with alignment objects was
446 // provided by the user. If yes, apply the objects
447 // to the present TGeo geometry
448 if (fAlignObjArray) {
449 if (gGeoManager && gGeoManager->IsClosed()) {
450 if ((AliGeomManager::Instance())->ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
451 AliError("The misalignment of one or more volumes failed!"
452 "Compare the list of simulated detectors and the list of detector alignment data!");
457 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
463 delete fAlignObjArray; fAlignObjArray=0;
465 // Update the TGeoPhysicalNodes
466 gGeoManager->RefreshPhysicalNodes();
471 //_____________________________________________________________________________
472 void AliReconstruction::SetGAliceFile(const char* fileName)
474 // set the name of the galice file
476 fGAliceFileName = fileName;
479 //_____________________________________________________________________________
480 void AliReconstruction::SetOption(const char* detector, const char* option)
482 // set options for the reconstruction of a detector
484 TObject* obj = fOptions.FindObject(detector);
485 if (obj) fOptions.Remove(obj);
486 fOptions.Add(new TNamed(detector, option));
490 //_____________________________________________________________________________
491 Bool_t AliReconstruction::Run(const char* input)
493 // run the reconstruction
496 if (!input) input = fInput.Data();
497 TString fileName(input);
498 if (fileName.EndsWith("/")) {
499 fRawReader = new AliRawReaderFile(fileName);
500 } else if (fileName.EndsWith(".root")) {
501 fRawReader = new AliRawReaderRoot(fileName);
502 } else if (!fileName.IsNull()) {
503 fRawReader = new AliRawReaderDate(fileName);
504 fRawReader->SelectEvents(7);
506 if (!fEquipIdMap.IsNull() && fRawReader)
507 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
510 // get the run loader
511 if (!InitRunLoader()) return kFALSE;
513 // Initialize the CDB storage
516 // Set run number in CDBManager (if it is not already set by the user)
517 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
519 // Import ideal TGeo geometry and apply misalignment
521 TString geom(gSystem->DirName(fGAliceFileName));
522 geom += "/geometry.root";
523 TGeoManager::Import(geom.Data());
524 if (!gGeoManager) if (fStopOnError) return kFALSE;
527 AliCDBManager* man = AliCDBManager::Instance();
528 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
530 // local reconstruction
531 if (!fRunLocalReconstruction.IsNull()) {
532 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
533 if (fStopOnError) {CleanUp(); return kFALSE;}
536 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
537 // fFillESD.IsNull()) return kTRUE;
540 if (fRunVertexFinder && !CreateVertexer()) {
548 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
556 TStopwatch stopwatch;
559 // get the possibly already existing ESD file and tree
560 AliESD* esd = new AliESD; AliESD* hltesd = new AliESD;
561 TFile* fileOld = NULL;
562 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
563 if (!gSystem->AccessPathName("AliESDs.root")){
564 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
565 fileOld = TFile::Open("AliESDs.old.root");
566 if (fileOld && fileOld->IsOpen()) {
567 treeOld = (TTree*) fileOld->Get("esdTree");
568 if (treeOld) treeOld->SetBranchAddress("ESD", &esd);
569 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
570 if (hlttreeOld) hlttreeOld->SetBranchAddress("ESD", &hltesd);
574 // create the ESD output file and tree
575 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
576 if (!file->IsOpen()) {
577 AliError("opening AliESDs.root failed");
578 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
580 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
581 tree->Branch("ESD", "AliESD", &esd);
582 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
583 hlttree->Branch("ESD", "AliESD", &hltesd);
584 delete esd; delete hltesd;
585 esd = NULL; hltesd = NULL;
587 // create the branch with ESD additions
588 AliESDfriend *esdf=0;
589 if (fWriteESDfriend) {
590 TBranch *br=tree->Branch("ESDfriend.", "AliESDfriend", &esdf);
591 br->SetFile("AliESDfriends.root");
594 // Get the diamond profile from OCDB
595 AliCDBEntry* entry = AliCDBManager::Instance()
596 ->Get("GRP/Calib/MeanVertex");
599 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
601 AliError("No diamond profile found in OCDB!");
604 AliVertexerTracks tVertexer(AliTracker::GetBz());
605 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
608 if (fRawReader) fRawReader->RewindEvents();
610 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
611 if (fRawReader) fRawReader->NextEvent();
612 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
613 // copy old ESD to the new one
615 treeOld->SetBranchAddress("ESD", &esd);
616 treeOld->GetEntry(iEvent);
620 hlttreeOld->SetBranchAddress("ESD", &hltesd);
621 hlttreeOld->GetEntry(iEvent);
627 AliInfo(Form("processing event %d", iEvent));
628 fRunLoader->GetEvent(iEvent);
631 sprintf(aFileName, "ESD_%d.%d_final.root",
632 fRunLoader->GetHeader()->GetRun(),
633 fRunLoader->GetHeader()->GetEventNrInRun());
634 if (!gSystem->AccessPathName(aFileName)) continue;
636 // local reconstruction
637 if (!fRunLocalReconstruction.IsNull()) {
638 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
639 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
643 esd = new AliESD; hltesd = new AliESD;
644 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
645 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
646 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
647 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
649 // Set magnetic field from the tracker
650 esd->SetMagneticField(AliTracker::GetBz());
651 hltesd->SetMagneticField(AliTracker::GetBz());
653 // Fill raw-data error log into the ESD
654 if (fRawReader) FillRawDataErrorLog(iEvent,esd);
657 if (fRunVertexFinder) {
658 if (!ReadESD(esd, "vertex")) {
659 if (!RunVertexFinder(esd)) {
660 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
662 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
667 if (!fRunTracking.IsNull()) {
668 if (fRunHLTTracking) {
669 hltesd->SetVertex(esd->GetVertex());
670 if (!RunHLTTracking(hltesd)) {
671 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
677 if (!fRunTracking.IsNull()) {
678 if (fRunMuonTracking) {
679 if (!RunMuonTracking()) {
680 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
686 if (!fRunTracking.IsNull()) {
687 if (!ReadESD(esd, "tracking")) {
688 if (!RunTracking(esd)) {
689 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
691 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
696 if (!fFillESD.IsNull()) {
697 if (!FillESD(esd, fFillESD)) {
698 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
701 // fill Event header information from the RawEventHeader
702 if (fRawReader){FillRawEventHeaderESD(esd);}
705 AliESDpid::MakePID(esd);
706 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
708 if (fFillTriggerESD) {
709 if (!ReadESD(esd, "trigger")) {
710 if (!FillTriggerESD(esd)) {
711 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
713 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
717 //Try to improve the reconstructed primary vertex position using the tracks
718 AliESDVertex *pvtx=tVertexer.FindPrimaryVertex(esd);
719 if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
722 if (pvtx->GetStatus()) {
723 // Store the improved primary vertex
724 esd->SetPrimaryVertex(pvtx);
725 // Propagate the tracks to the DCA to the improved primary vertex
726 Double_t somethingbig = 777.;
727 Double_t bz = esd->GetMagneticField();
728 Int_t nt=esd->GetNumberOfTracks();
730 AliESDtrack *t = esd->GetTrack(nt);
731 t->RelateToVertex(pvtx, bz, somethingbig);
738 vtxer.Tracks2V0vertices(esd);
741 AliCascadeVertexer cvtxer;
742 cvtxer.V0sTracks2CascadeVertices(esd);
746 if (fWriteESDfriend) {
747 esdf=new AliESDfriend();
748 esd->GetESDfriend(esdf);
755 if (fCheckPointLevel > 0) WriteESD(esd, "final");
757 delete esd; delete esdf; delete hltesd;
758 esd = NULL; esdf=NULL; hltesd = NULL;
761 AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
762 stopwatch.RealTime(),stopwatch.CpuTime()));
766 tree->SetBranchStatus("ESDfriend*",0);
771 TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE");
772 ESDFile2AODFile(file, aodFile);
776 // Create tags for the events in the ESD tree (the ESD tree is always present)
777 // In case of empty events the tags will contain dummy values
779 CleanUp(file, fileOld);
785 //_____________________________________________________________________________
786 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
788 // run the local reconstruction
790 TStopwatch stopwatch;
793 AliCDBManager* man = AliCDBManager::Instance();
794 Bool_t origCache = man->GetCacheFlag();
796 TString detStr = detectors;
797 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
798 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
799 AliReconstructor* reconstructor = GetReconstructor(iDet);
800 if (!reconstructor) continue;
801 if (reconstructor->HasLocalReconstruction()) continue;
803 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
804 TStopwatch stopwatchDet;
805 stopwatchDet.Start();
807 AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
809 man->SetCacheFlag(kTRUE);
810 TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
811 man->GetAll(calibPath); // entries are cached!
814 fRawReader->RewindEvents();
815 reconstructor->Reconstruct(fRunLoader, fRawReader);
817 reconstructor->Reconstruct(fRunLoader);
819 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
820 fgkDetectorName[iDet],
821 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
823 // unload calibration data
827 man->SetCacheFlag(origCache);
829 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
830 AliError(Form("the following detectors were not found: %s",
832 if (fStopOnError) return kFALSE;
835 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
836 stopwatch.RealTime(),stopwatch.CpuTime()));
841 //_____________________________________________________________________________
842 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
844 // run the local reconstruction
846 TStopwatch stopwatch;
849 TString detStr = detectors;
850 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
851 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
852 AliReconstructor* reconstructor = GetReconstructor(iDet);
853 if (!reconstructor) continue;
854 AliLoader* loader = fLoader[iDet];
856 // conversion of digits
857 if (fRawReader && reconstructor->HasDigitConversion()) {
858 AliInfo(Form("converting raw data digits into root objects for %s",
859 fgkDetectorName[iDet]));
860 TStopwatch stopwatchDet;
861 stopwatchDet.Start();
862 loader->LoadDigits("update");
863 loader->CleanDigits();
864 loader->MakeDigitsContainer();
865 TTree* digitsTree = loader->TreeD();
866 reconstructor->ConvertDigits(fRawReader, digitsTree);
867 loader->WriteDigits("OVERWRITE");
868 loader->UnloadDigits();
869 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
870 fgkDetectorName[iDet],
871 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
874 // local reconstruction
875 if (!reconstructor->HasLocalReconstruction()) continue;
876 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
877 TStopwatch stopwatchDet;
878 stopwatchDet.Start();
879 loader->LoadRecPoints("update");
880 loader->CleanRecPoints();
881 loader->MakeRecPointsContainer();
882 TTree* clustersTree = loader->TreeR();
883 if (fRawReader && !reconstructor->HasDigitConversion()) {
884 reconstructor->Reconstruct(fRawReader, clustersTree);
886 loader->LoadDigits("read");
887 TTree* digitsTree = loader->TreeD();
889 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
890 if (fStopOnError) return kFALSE;
892 reconstructor->Reconstruct(digitsTree, clustersTree);
894 loader->UnloadDigits();
896 loader->WriteRecPoints("OVERWRITE");
897 loader->UnloadRecPoints();
898 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
899 fgkDetectorName[iDet],
900 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
903 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
904 AliError(Form("the following detectors were not found: %s",
906 if (fStopOnError) return kFALSE;
909 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
910 stopwatch.RealTime(),stopwatch.CpuTime()));
915 //_____________________________________________________________________________
916 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
918 // run the barrel tracking
920 TStopwatch stopwatch;
923 AliESDVertex* vertex = NULL;
924 Double_t vtxPos[3] = {0, 0, 0};
925 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
927 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
928 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
929 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
933 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
934 AliInfo("running the ITS vertex finder");
935 if (fLoader[0]) fLoader[0]->LoadRecPoints();
936 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
937 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
939 AliWarning("Vertex not found");
940 vertex = new AliESDVertex();
941 vertex->SetName("default");
944 vertex->SetTruePos(vtxPos); // store also the vertex from MC
945 vertex->SetName("reconstructed");
949 AliInfo("getting the primary vertex from MC");
950 vertex = new AliESDVertex(vtxPos, vtxErr);
954 vertex->GetXYZ(vtxPos);
955 vertex->GetSigmaXYZ(vtxErr);
957 AliWarning("no vertex reconstructed");
958 vertex = new AliESDVertex(vtxPos, vtxErr);
960 esd->SetVertex(vertex);
961 // if SPD multiplicity has been determined, it is stored in the ESD
962 AliMultiplicity *mult = fVertexer->GetMultiplicity();
963 if(mult)esd->SetMultiplicity(mult);
965 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
966 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
970 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
971 stopwatch.RealTime(),stopwatch.CpuTime()));
976 //_____________________________________________________________________________
977 Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
979 // run the HLT barrel tracking
981 TStopwatch stopwatch;
985 AliError("Missing runLoader!");
989 AliInfo("running HLT tracking");
991 // Get a pointer to the HLT reconstructor
992 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
993 if (!reconstructor) return kFALSE;
996 for (Int_t iDet = 1; iDet >= 0; iDet--) {
997 TString detName = fgkDetectorName[iDet];
998 AliDebug(1, Form("%s HLT tracking", detName.Data()));
999 reconstructor->SetOption(detName.Data());
1000 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1002 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1003 if (fStopOnError) return kFALSE;
1007 Double_t vtxErr[3]={0.005,0.005,0.010};
1008 const AliESDVertex *vertex = esd->GetVertex();
1009 vertex->GetXYZ(vtxPos);
1010 tracker->SetVertex(vtxPos,vtxErr);
1012 fLoader[iDet]->LoadRecPoints("read");
1013 TTree* tree = fLoader[iDet]->TreeR();
1015 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1018 tracker->LoadClusters(tree);
1020 if (tracker->Clusters2Tracks(esd) != 0) {
1021 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1025 tracker->UnloadClusters();
1030 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1031 stopwatch.RealTime(),stopwatch.CpuTime()));
1036 //_____________________________________________________________________________
1037 Bool_t AliReconstruction::RunMuonTracking()
1039 // run the muon spectrometer tracking
1041 TStopwatch stopwatch;
1045 AliError("Missing runLoader!");
1048 Int_t iDet = 7; // for MUON
1050 AliInfo("is running...");
1052 // Get a pointer to the MUON reconstructor
1053 AliReconstructor *reconstructor = GetReconstructor(iDet);
1054 if (!reconstructor) return kFALSE;
1057 TString detName = fgkDetectorName[iDet];
1058 AliDebug(1, Form("%s tracking", detName.Data()));
1059 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1061 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1066 fLoader[iDet]->LoadTracks("update");
1067 fLoader[iDet]->CleanTracks();
1068 fLoader[iDet]->MakeTracksContainer();
1071 fLoader[iDet]->LoadRecPoints("read");
1073 if (!tracker->Clusters2Tracks(0x0)) {
1074 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1077 fLoader[iDet]->UnloadRecPoints();
1079 fLoader[iDet]->WriteTracks("OVERWRITE");
1080 fLoader[iDet]->UnloadTracks();
1085 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1086 stopwatch.RealTime(),stopwatch.CpuTime()));
1092 //_____________________________________________________________________________
1093 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
1095 // run the barrel tracking
1097 TStopwatch stopwatch;
1100 AliInfo("running tracking");
1102 //Fill the ESD with the T0 info (will be used by the TOF)
1103 if (fReconstructor[11])
1104 GetReconstructor(11)->FillESD(fRunLoader, esd);
1106 // pass 1: TPC + ITS inwards
1107 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1108 if (!fTracker[iDet]) continue;
1109 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1112 fLoader[iDet]->LoadRecPoints("read");
1113 TTree* tree = fLoader[iDet]->TreeR();
1115 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1118 fTracker[iDet]->LoadClusters(tree);
1121 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1122 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1125 if (fCheckPointLevel > 1) {
1126 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1128 // preliminary PID in TPC needed by the ITS tracker
1130 GetReconstructor(1)->FillESD(fRunLoader, esd);
1131 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1132 AliESDpid::MakePID(esd);
1136 // pass 2: ALL backwards
1137 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1138 if (!fTracker[iDet]) continue;
1139 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1142 if (iDet > 1) { // all except ITS, TPC
1144 fLoader[iDet]->LoadRecPoints("read");
1145 tree = fLoader[iDet]->TreeR();
1147 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1150 fTracker[iDet]->LoadClusters(tree);
1154 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1155 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1158 if (fCheckPointLevel > 1) {
1159 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1163 if (iDet > 2) { // all except ITS, TPC, TRD
1164 fTracker[iDet]->UnloadClusters();
1165 fLoader[iDet]->UnloadRecPoints();
1167 // updated PID in TPC needed by the ITS tracker -MI
1169 GetReconstructor(1)->FillESD(fRunLoader, esd);
1170 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1171 AliESDpid::MakePID(esd);
1175 // write space-points to the ESD in case alignment data output
1177 if (fWriteAlignmentData)
1178 WriteAlignmentData(esd);
1180 // pass 3: TRD + TPC + ITS refit inwards
1181 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1182 if (!fTracker[iDet]) continue;
1183 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1186 if (fTracker[iDet]->RefitInward(esd) != 0) {
1187 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1190 if (fCheckPointLevel > 1) {
1191 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1195 fTracker[iDet]->UnloadClusters();
1196 fLoader[iDet]->UnloadRecPoints();
1199 // Propagate track to the vertex - if not done by ITS
1201 Int_t ntracks = esd->GetNumberOfTracks();
1202 for (Int_t itrack=0; itrack<ntracks; itrack++){
1203 const Double_t kRadius = 3; // beam pipe radius
1204 const Double_t kMaxStep = 5; // max step
1205 const Double_t kMaxD = 123456; // max distance to prim vertex
1206 Double_t fieldZ = AliTracker::GetBz(); //
1207 AliESDtrack * track = esd->GetTrack(itrack);
1208 if (!track) continue;
1209 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1210 track->PropagateTo(kRadius, fieldZ, track->GetMass(),kMaxStep,kTRUE);
1211 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1214 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1215 stopwatch.RealTime(),stopwatch.CpuTime()));
1220 //_____________________________________________________________________________
1221 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
1223 // fill the event summary data
1225 TStopwatch stopwatch;
1227 AliInfo("filling ESD");
1229 TString detStr = detectors;
1230 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1231 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1232 AliReconstructor* reconstructor = GetReconstructor(iDet);
1233 if (!reconstructor) continue;
1235 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1236 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1237 TTree* clustersTree = NULL;
1238 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1239 fLoader[iDet]->LoadRecPoints("read");
1240 clustersTree = fLoader[iDet]->TreeR();
1241 if (!clustersTree) {
1242 AliError(Form("Can't get the %s clusters tree",
1243 fgkDetectorName[iDet]));
1244 if (fStopOnError) return kFALSE;
1247 if (fRawReader && !reconstructor->HasDigitConversion()) {
1248 reconstructor->FillESD(fRawReader, clustersTree, esd);
1250 TTree* digitsTree = NULL;
1251 if (fLoader[iDet]) {
1252 fLoader[iDet]->LoadDigits("read");
1253 digitsTree = fLoader[iDet]->TreeD();
1255 AliError(Form("Can't get the %s digits tree",
1256 fgkDetectorName[iDet]));
1257 if (fStopOnError) return kFALSE;
1260 reconstructor->FillESD(digitsTree, clustersTree, esd);
1261 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1263 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1264 fLoader[iDet]->UnloadRecPoints();
1268 reconstructor->FillESD(fRunLoader, fRawReader, esd);
1270 reconstructor->FillESD(fRunLoader, esd);
1272 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1276 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1277 AliError(Form("the following detectors were not found: %s",
1279 if (fStopOnError) return kFALSE;
1282 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1283 stopwatch.RealTime(),stopwatch.CpuTime()));
1288 //_____________________________________________________________________________
1289 Bool_t AliReconstruction::FillTriggerESD(AliESD*& esd)
1291 // Reads the trigger decision which is
1292 // stored in Trigger.root file and fills
1293 // the corresponding esd entries
1295 AliInfo("Filling trigger information into the ESD");
1298 AliCTPRawStream input(fRawReader);
1299 if (!input.Next()) {
1300 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1303 esd->SetTriggerMask(input.GetClassMask());
1304 esd->SetTriggerCluster(input.GetClusterMask());
1307 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1309 if (!runloader->LoadTrigger()) {
1310 AliCentralTrigger *aCTP = runloader->GetTrigger();
1311 esd->SetTriggerMask(aCTP->GetClassMask());
1312 esd->SetTriggerCluster(aCTP->GetClusterMask());
1315 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1320 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1332 //_____________________________________________________________________________
1333 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESD*& esd)
1336 // Filling information from RawReader Header
1339 AliInfo("Filling information from RawReader Header");
1340 esd->SetBunchCrossNumber(0);
1341 esd->SetOrbitNumber(0);
1342 esd->SetPeriodNumber(0);
1343 esd->SetTimeStamp(0);
1344 esd->SetEventType(0);
1345 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1348 const UInt_t *id = eventHeader->GetP("Id");
1349 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1350 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1351 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1353 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1354 esd->SetEventType((eventHeader->Get("Type")));
1361 //_____________________________________________________________________________
1362 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1364 // check whether detName is contained in detectors
1365 // if yes, it is removed from detectors
1367 // check if all detectors are selected
1368 if ((detectors.CompareTo("ALL") == 0) ||
1369 detectors.BeginsWith("ALL ") ||
1370 detectors.EndsWith(" ALL") ||
1371 detectors.Contains(" ALL ")) {
1376 // search for the given detector
1377 Bool_t result = kFALSE;
1378 if ((detectors.CompareTo(detName) == 0) ||
1379 detectors.BeginsWith(detName+" ") ||
1380 detectors.EndsWith(" "+detName) ||
1381 detectors.Contains(" "+detName+" ")) {
1382 detectors.ReplaceAll(detName, "");
1386 // clean up the detectors string
1387 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1388 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1389 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1394 //_____________________________________________________________________________
1395 Bool_t AliReconstruction::InitRunLoader()
1397 // get or create the run loader
1399 if (gAlice) delete gAlice;
1402 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1403 // load all base libraries to get the loader classes
1404 TString libs = gSystem->GetLibraries();
1405 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1406 TString detName = fgkDetectorName[iDet];
1407 if (detName == "HLT") continue;
1408 if (libs.Contains("lib" + detName + "base.so")) continue;
1409 gSystem->Load("lib" + detName + "base.so");
1411 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1413 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1417 fRunLoader->CdGAFile();
1418 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1419 if (fRunLoader->LoadgAlice() == 0) {
1420 gAlice = fRunLoader->GetAliRun();
1421 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1424 if (!gAlice && !fRawReader) {
1425 AliError(Form("no gAlice object found in file %s",
1426 fGAliceFileName.Data()));
1431 } else { // galice.root does not exist
1433 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1437 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1438 AliConfig::GetDefaultEventFolderName(),
1441 AliError(Form("could not create run loader in file %s",
1442 fGAliceFileName.Data()));
1446 fRunLoader->MakeTree("E");
1448 while (fRawReader->NextEvent()) {
1449 fRunLoader->SetEventNumber(iEvent);
1450 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1452 fRunLoader->MakeTree("H");
1453 fRunLoader->TreeE()->Fill();
1456 fRawReader->RewindEvents();
1457 if (fNumberOfEventsPerFile > 0)
1458 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1460 fRunLoader->SetNumberOfEventsPerFile(iEvent);
1461 fRunLoader->WriteHeader("OVERWRITE");
1462 fRunLoader->CdGAFile();
1463 fRunLoader->Write(0, TObject::kOverwrite);
1464 // AliTracker::SetFieldMap(???);
1470 //_____________________________________________________________________________
1471 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1473 // get the reconstructor object and the loader for a detector
1475 if (fReconstructor[iDet]) return fReconstructor[iDet];
1477 // load the reconstructor object
1478 TPluginManager* pluginManager = gROOT->GetPluginManager();
1479 TString detName = fgkDetectorName[iDet];
1480 TString recName = "Ali" + detName + "Reconstructor";
1481 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1483 if (detName == "HLT") {
1484 if (!gROOT->GetClass("AliLevel3")) {
1485 gSystem->Load("libAliHLTSrc.so");
1486 gSystem->Load("libAliHLTMisc.so");
1487 gSystem->Load("libAliHLTHough.so");
1488 gSystem->Load("libAliHLTComp.so");
1492 AliReconstructor* reconstructor = NULL;
1493 // first check if a plugin is defined for the reconstructor
1494 TPluginHandler* pluginHandler =
1495 pluginManager->FindHandler("AliReconstructor", detName);
1496 // if not, add a plugin for it
1497 if (!pluginHandler) {
1498 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1499 TString libs = gSystem->GetLibraries();
1500 if (libs.Contains("lib" + detName + "base.so") ||
1501 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1502 pluginManager->AddHandler("AliReconstructor", detName,
1503 recName, detName + "rec", recName + "()");
1505 pluginManager->AddHandler("AliReconstructor", detName,
1506 recName, detName, recName + "()");
1508 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1510 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1511 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1513 if (reconstructor) {
1514 TObject* obj = fOptions.FindObject(detName.Data());
1515 if (obj) reconstructor->SetOption(obj->GetTitle());
1516 reconstructor->Init(fRunLoader);
1517 fReconstructor[iDet] = reconstructor;
1520 // get or create the loader
1521 if (detName != "HLT") {
1522 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1523 if (!fLoader[iDet]) {
1524 AliConfig::Instance()
1525 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1527 // first check if a plugin is defined for the loader
1529 pluginManager->FindHandler("AliLoader", detName);
1530 // if not, add a plugin for it
1531 if (!pluginHandler) {
1532 TString loaderName = "Ali" + detName + "Loader";
1533 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1534 pluginManager->AddHandler("AliLoader", detName,
1535 loaderName, detName + "base",
1536 loaderName + "(const char*, TFolder*)");
1537 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1539 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1541 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1542 fRunLoader->GetEventFolder());
1544 if (!fLoader[iDet]) { // use default loader
1545 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1547 if (!fLoader[iDet]) {
1548 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1549 if (fStopOnError) return NULL;
1551 fRunLoader->AddLoader(fLoader[iDet]);
1552 fRunLoader->CdGAFile();
1553 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1554 fRunLoader->Write(0, TObject::kOverwrite);
1559 return reconstructor;
1562 //_____________________________________________________________________________
1563 Bool_t AliReconstruction::CreateVertexer()
1565 // create the vertexer
1568 AliReconstructor* itsReconstructor = GetReconstructor(0);
1569 if (itsReconstructor) {
1570 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1573 AliWarning("couldn't create a vertexer for ITS");
1574 if (fStopOnError) return kFALSE;
1580 //_____________________________________________________________________________
1581 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1583 // create the trackers
1585 TString detStr = detectors;
1586 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1587 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1588 AliReconstructor* reconstructor = GetReconstructor(iDet);
1589 if (!reconstructor) continue;
1590 TString detName = fgkDetectorName[iDet];
1591 if (detName == "HLT") {
1592 fRunHLTTracking = kTRUE;
1595 if (detName == "MUON") {
1596 fRunMuonTracking = kTRUE;
1601 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1602 if (!fTracker[iDet] && (iDet < 7)) {
1603 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1604 if (fStopOnError) return kFALSE;
1611 //_____________________________________________________________________________
1612 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1614 // delete trackers and the run loader and close and delete the file
1616 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1617 delete fReconstructor[iDet];
1618 fReconstructor[iDet] = NULL;
1619 fLoader[iDet] = NULL;
1620 delete fTracker[iDet];
1621 fTracker[iDet] = NULL;
1625 delete fDiamondProfile;
1626 fDiamondProfile = NULL;
1641 gSystem->Unlink("AliESDs.old.root");
1646 //_____________________________________________________________________________
1647 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
1649 // read the ESD event from a file
1651 if (!esd) return kFALSE;
1653 sprintf(fileName, "ESD_%d.%d_%s.root",
1654 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1655 if (gSystem->AccessPathName(fileName)) return kFALSE;
1657 AliInfo(Form("reading ESD from file %s", fileName));
1658 AliDebug(1, Form("reading ESD from file %s", fileName));
1659 TFile* file = TFile::Open(fileName);
1660 if (!file || !file->IsOpen()) {
1661 AliError(Form("opening %s failed", fileName));
1668 esd = (AliESD*) file->Get("ESD");
1674 //_____________________________________________________________________________
1675 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
1677 // write the ESD event to a file
1681 sprintf(fileName, "ESD_%d.%d_%s.root",
1682 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1684 AliDebug(1, Form("writing ESD to file %s", fileName));
1685 TFile* file = TFile::Open(fileName, "recreate");
1686 if (!file || !file->IsOpen()) {
1687 AliError(Form("opening %s failed", fileName));
1698 //_____________________________________________________________________________
1699 void AliReconstruction::CreateTag(TFile* file)
1702 Float_t lhcLuminosity = 0.0;
1703 TString lhcState = "test";
1704 UInt_t detectorMask = 0;
1709 Double_t fMUONMASS = 0.105658369;
1712 Double_t fThetaX, fThetaY, fPyz, fChisquare;
1713 Double_t fPxRec,fPyRec, fPzRec, fEnergy;
1715 TLorentzVector fEPvector;
1717 Float_t fZVertexCut = 10.0;
1718 Float_t fRhoVertexCut = 2.0;
1720 Float_t fLowPtCut = 1.0;
1721 Float_t fHighPtCut = 3.0;
1722 Float_t fVeryHighPtCut = 10.0;
1725 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
1727 // Creates the tags for all the events in a given ESD file
1729 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
1730 Int_t nPos, nNeg, nNeutr;
1731 Int_t nK0s, nNeutrons, nPi0s, nGamas;
1732 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
1733 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
1734 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
1735 Float_t maxPt = .0, meanPt = .0, totalP = .0;
1737 Int_t iRunNumber = 0;
1738 TString fVertexName("default");
1740 AliRunTag *tag = new AliRunTag();
1741 AliEventTag *evTag = new AliEventTag();
1742 TTree ttag("T","A Tree with event tags");
1743 TBranch * btag = ttag.Branch("AliTAG", &tag);
1744 btag->SetCompressionLevel(9);
1746 AliInfo(Form("Creating the tags......."));
1748 if (!file || !file->IsOpen()) {
1749 AliError(Form("opening failed"));
1753 Int_t lastEvent = 0;
1754 TTree *t = (TTree*) file->Get("esdTree");
1755 TBranch * b = t->GetBranch("ESD");
1757 b->SetAddress(&esd);
1759 b->GetEntry(fFirstEvent);
1760 Int_t iInitRunNumber = esd->GetRunNumber();
1762 Int_t iNumberOfEvents = (Int_t)b->GetEntries();
1763 if(fLastEvent != -1) iNumberOfEvents = fLastEvent + 1;
1764 for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
1792 b->GetEntry(iEventNumber);
1793 iRunNumber = esd->GetRunNumber();
1794 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
1795 const AliESDVertex * vertexIn = esd->GetVertex();
1796 if (!vertexIn) AliError("ESD has not defined vertex.");
1797 if (vertexIn) fVertexName = vertexIn->GetName();
1798 if(fVertexName != "default") fVertexflag = 1;
1799 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
1800 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
1801 UInt_t status = esdTrack->GetStatus();
1803 //select only tracks with ITS refit
1804 if ((status&AliESDtrack::kITSrefit)==0) continue;
1805 //select only tracks with TPC refit
1806 if ((status&AliESDtrack::kTPCrefit)==0) continue;
1808 //select only tracks with the "combined PID"
1809 if ((status&AliESDtrack::kESDpid)==0) continue;
1811 esdTrack->GetPxPyPz(p);
1812 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
1813 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
1816 if(fPt > maxPt) maxPt = fPt;
1818 if(esdTrack->GetSign() > 0) {
1820 if(fPt > fLowPtCut) nCh1GeV++;
1821 if(fPt > fHighPtCut) nCh3GeV++;
1822 if(fPt > fVeryHighPtCut) nCh10GeV++;
1824 if(esdTrack->GetSign() < 0) {
1826 if(fPt > fLowPtCut) nCh1GeV++;
1827 if(fPt > fHighPtCut) nCh3GeV++;
1828 if(fPt > fVeryHighPtCut) nCh10GeV++;
1830 if(esdTrack->GetSign() == 0) nNeutr++;
1834 esdTrack->GetESDpid(prob);
1837 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
1838 if(rcc == 0.0) continue;
1841 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
1844 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
1846 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
1848 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
1850 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
1852 if(fPt > fLowPtCut) nEl1GeV++;
1853 if(fPt > fHighPtCut) nEl3GeV++;
1854 if(fPt > fVeryHighPtCut) nEl10GeV++;
1862 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
1863 // loop over all reconstructed tracks (also first track of combination)
1864 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
1865 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
1866 if (muonTrack == 0x0) continue;
1868 // Coordinates at vertex
1869 fZ = muonTrack->GetZ();
1870 fY = muonTrack->GetBendingCoor();
1871 fX = muonTrack->GetNonBendingCoor();
1873 fThetaX = muonTrack->GetThetaX();
1874 fThetaY = muonTrack->GetThetaY();
1876 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
1877 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
1878 fPxRec = fPzRec * TMath::Tan(fThetaX);
1879 fPyRec = fPzRec * TMath::Tan(fThetaY);
1880 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
1882 //ChiSquare of the track if needed
1883 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
1884 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
1885 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
1887 // total number of muons inside a vertex cut
1888 if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
1890 if(fEPvector.Pt() > fLowPtCut) {
1892 if(fEPvector.Pt() > fHighPtCut) {
1894 if (fEPvector.Pt() > fVeryHighPtCut) {
1902 // Fill the event tags
1904 meanPt = meanPt/ntrack;
1906 evTag->SetEventId(iEventNumber+1);
1908 evTag->SetVertexX(vertexIn->GetXv());
1909 evTag->SetVertexY(vertexIn->GetYv());
1910 evTag->SetVertexZ(vertexIn->GetZv());
1911 evTag->SetVertexZError(vertexIn->GetZRes());
1913 evTag->SetVertexFlag(fVertexflag);
1915 evTag->SetT0VertexZ(esd->GetT0zVertex());
1917 evTag->SetTriggerMask(esd->GetTriggerMask());
1918 evTag->SetTriggerCluster(esd->GetTriggerCluster());
1920 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
1921 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
1922 evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
1923 evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
1924 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
1925 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
1928 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
1929 evTag->SetNumOfPosTracks(nPos);
1930 evTag->SetNumOfNegTracks(nNeg);
1931 evTag->SetNumOfNeutrTracks(nNeutr);
1933 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
1934 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
1935 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
1936 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
1938 evTag->SetNumOfProtons(nProtons);
1939 evTag->SetNumOfKaons(nKaons);
1940 evTag->SetNumOfPions(nPions);
1941 evTag->SetNumOfMuons(nMuons);
1942 evTag->SetNumOfElectrons(nElectrons);
1943 evTag->SetNumOfPhotons(nGamas);
1944 evTag->SetNumOfPi0s(nPi0s);
1945 evTag->SetNumOfNeutrons(nNeutrons);
1946 evTag->SetNumOfKaon0s(nK0s);
1948 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1949 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1950 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1951 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1952 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1953 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
1954 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
1955 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
1956 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
1958 evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
1959 evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
1961 evTag->SetTotalMomentum(totalP);
1962 evTag->SetMeanPt(meanPt);
1963 evTag->SetMaxPt(maxPt);
1965 tag->SetLHCTag(lhcLuminosity,lhcState);
1966 tag->SetDetectorTag(detectorMask);
1968 tag->SetRunId(iInitRunNumber);
1969 tag->AddEventTag(*evTag);
1971 if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries();
1972 else lastEvent = fLastEvent;
1978 sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root",
1979 tag->GetRunId(),fFirstEvent,lastEvent );
1980 AliInfo(Form("writing tags to file %s", fileName));
1981 AliDebug(1, Form("writing tags to file %s", fileName));
1983 TFile* ftag = TFile::Open(fileName, "recreate");
1992 //_____________________________________________________________________________
1993 void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
1995 // write all files from the given esd file to an aod file
1997 // create an AliAOD object
1998 AliAODEvent *aod = new AliAODEvent();
1999 aod->CreateStdContent();
2005 TTree *aodTree = new TTree("AOD", "AliAOD tree");
2006 aodTree->Branch(aod->GetList());
2009 TTree *t = (TTree*) esdFile->Get("esdTree");
2010 TBranch *b = t->GetBranch("ESD");
2012 b->SetAddress(&esd);
2014 Int_t nEvents = b->GetEntries();
2016 // set arrays and pointers
2024 // loop over events and fill them
2025 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
2026 b->GetEntry(iEvent);
2028 // Multiplicity information needed by the header (to be revised!)
2029 Int_t nTracks = esd->GetNumberOfTracks();
2030 Int_t nPosTracks = 0;
2031 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack)
2032 if (esd->GetTrack(iTrack)->GetSign()> 0) nPosTracks++;
2034 // create the header
2035 aod->AddHeader(new AliAODHeader(esd->GetRunNumber(),
2036 esd->GetBunchCrossNumber(),
2037 esd->GetOrbitNumber(),
2038 esd->GetPeriodNumber(),
2042 esd->GetMagneticField(),
2043 -999., // fill muon magnetic field
2044 -999., // centrality; to be filled, still
2045 esd->GetZDCN1Energy(),
2046 esd->GetZDCP1Energy(),
2047 esd->GetZDCN2Energy(),
2048 esd->GetZDCP2Energy(),
2049 esd->GetZDCEMEnergy(),
2050 esd->GetTriggerMask(),
2051 esd->GetTriggerCluster(),
2052 esd->GetEventType()));
2054 Int_t nV0s = esd->GetNumberOfV0s();
2055 Int_t nCascades = esd->GetNumberOfCascades();
2056 Int_t nKinks = esd->GetNumberOfKinks();
2057 Int_t nVertices = nV0s + nCascades + nKinks;
2059 aod->ResetStd(nTracks, nVertices);
2060 AliAODTrack *aodTrack;
2063 // Array to take into account the tracks already added to the AOD
2064 Bool_t * usedTrack = NULL;
2066 usedTrack = new Bool_t[nTracks];
2067 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
2069 // Array to take into account the V0s already added to the AOD
2070 Bool_t * usedV0 = NULL;
2072 usedV0 = new Bool_t[nV0s];
2073 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
2075 // Array to take into account the kinks already added to the AOD
2076 Bool_t * usedKink = NULL;
2078 usedKink = new Bool_t[nKinks];
2079 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
2082 // Access to the AOD container of vertices
2083 TClonesArray &vertices = *(aod->GetVertices());
2086 // Access to the AOD container of tracks
2087 TClonesArray &tracks = *(aod->GetTracks());
2090 // Add primary vertex. The primary tracks will be defined
2091 // after the loops on the composite objects (V0, cascades, kinks)
2092 const AliESDVertex *vtx = esd->GetPrimaryVertex();
2094 vtx->GetXYZ(pos); // position
2095 vtx->GetCovMatrix(covVtx); //covariance matrix
2097 AliAODVertex * primary = new(vertices[jVertices++])
2098 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, AliAODVertex::kPrimary);
2100 // Create vertices starting from the most complex objects
2103 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
2104 AliESDcascade *cascade = esd->GetCascade(nCascade);
2106 cascade->GetXYZ(pos[0], pos[1], pos[2]);
2107 cascade->GetPosCovXi(covVtx);
2109 // Add the cascade vertex
2110 AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
2112 cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
2114 AliAODVertex::kCascade);
2116 primary->AddDaughter(vcascade);
2118 // Add the V0 from the cascade. The ESD class have to be optimized...
2119 // Now we have to search for the corresponding Vo in the list of V0s
2120 // using the indeces of the positive and negative tracks
2122 Int_t posFromV0 = cascade->GetPindex();
2123 Int_t negFromV0 = cascade->GetNindex();
2126 AliESDv0 * v0 = 0x0;
2129 for (Int_t iV0=0; iV0<nV0s; ++iV0) {
2131 v0 = esd->GetV0(iV0);
2132 Int_t posV0 = v0->GetPindex();
2133 Int_t negV0 = v0->GetNindex();
2135 if (posV0==posFromV0 && negV0==negFromV0) {
2141 AliAODVertex * vV0FromCascade = 0x0;
2143 if (indV0>-1 && !usedV0[indV0] ) {
2145 // the V0 exists in the array of V0s and is not used
2147 usedV0[indV0] = kTRUE;
2149 v0->GetXYZ(pos[0], pos[1], pos[2]);
2150 v0->GetPosCov(covVtx);
2152 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2154 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2159 // the V0 doesn't exist in the array of V0s or was used
2160 cerr << "Error: event " << iEvent << " cascade " << nCascade
2161 << " The V0 " << indV0
2162 << " doesn't exist in the array of V0s or was used!" << endl;
2164 cascade->GetXYZ(pos[0], pos[1], pos[2]);
2165 cascade->GetPosCov(covVtx);
2167 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2169 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2172 vcascade->AddDaughter(vV0FromCascade);
2175 // Add the positive tracks from the V0
2177 if (! usedTrack[posFromV0]) {
2179 usedTrack[posFromV0] = kTRUE;
2181 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2182 esdTrack->GetPxPyPz(p);
2183 esdTrack->GetXYZ(pos);
2184 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2185 esdTrack->GetESDpid(pid);
2187 vV0FromCascade->AddDaughter(aodTrack =
2188 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2189 esdTrack->GetLabel(),
2195 (Short_t)esdTrack->GetSign(),
2196 esdTrack->GetITSClusterMap(),
2199 kTRUE, // check if this is right
2200 kFALSE, // check if this is right
2201 AliAODTrack::kSecondary)
2203 aodTrack->ConvertAliPIDtoAODPID();
2206 cerr << "Error: event " << iEvent << " cascade " << nCascade
2207 << " track " << posFromV0 << " has already been used!" << endl;
2210 // Add the negative tracks from the V0
2212 if (!usedTrack[negFromV0]) {
2214 usedTrack[negFromV0] = kTRUE;
2216 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2217 esdTrack->GetPxPyPz(p);
2218 esdTrack->GetXYZ(pos);
2219 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2220 esdTrack->GetESDpid(pid);
2222 vV0FromCascade->AddDaughter(aodTrack =
2223 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2224 esdTrack->GetLabel(),
2230 (Short_t)esdTrack->GetSign(),
2231 esdTrack->GetITSClusterMap(),
2234 kTRUE, // check if this is right
2235 kFALSE, // check if this is right
2236 AliAODTrack::kSecondary)
2238 aodTrack->ConvertAliPIDtoAODPID();
2241 cerr << "Error: event " << iEvent << " cascade " << nCascade
2242 << " track " << negFromV0 << " has already been used!" << endl;
2245 // Add the bachelor track from the cascade
2247 Int_t bachelor = cascade->GetBindex();
2249 if(!usedTrack[bachelor]) {
2251 usedTrack[bachelor] = kTRUE;
2253 AliESDtrack *esdTrack = esd->GetTrack(bachelor);
2254 esdTrack->GetPxPyPz(p);
2255 esdTrack->GetXYZ(pos);
2256 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2257 esdTrack->GetESDpid(pid);
2259 vcascade->AddDaughter(aodTrack =
2260 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2261 esdTrack->GetLabel(),
2267 (Short_t)esdTrack->GetSign(),
2268 esdTrack->GetITSClusterMap(),
2271 kTRUE, // check if this is right
2272 kFALSE, // check if this is right
2273 AliAODTrack::kSecondary)
2275 aodTrack->ConvertAliPIDtoAODPID();
2278 cerr << "Error: event " << iEvent << " cascade " << nCascade
2279 << " track " << bachelor << " has already been used!" << endl;
2282 // Add the primary track of the cascade (if any)
2284 } // end of the loop on cascades
2288 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
2290 if (usedV0[nV0]) continue; // skip if aready added to the AOD
2292 AliESDv0 *v0 = esd->GetV0(nV0);
2294 v0->GetXYZ(pos[0], pos[1], pos[2]);
2295 v0->GetPosCov(covVtx);
2297 AliAODVertex * vV0 =
2298 new(vertices[jVertices++]) AliAODVertex(pos,
2300 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2303 primary->AddDaughter(vV0);
2305 Int_t posFromV0 = v0->GetPindex();
2306 Int_t negFromV0 = v0->GetNindex();
2308 // Add the positive tracks from the V0
2310 if (!usedTrack[posFromV0]) {
2312 usedTrack[posFromV0] = kTRUE;
2314 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2315 esdTrack->GetPxPyPz(p);
2316 esdTrack->GetXYZ(pos);
2317 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2318 esdTrack->GetESDpid(pid);
2320 vV0->AddDaughter(aodTrack =
2321 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2322 esdTrack->GetLabel(),
2328 (Short_t)esdTrack->GetSign(),
2329 esdTrack->GetITSClusterMap(),
2332 kTRUE, // check if this is right
2333 kFALSE, // check if this is right
2334 AliAODTrack::kSecondary)
2336 aodTrack->ConvertAliPIDtoAODPID();
2339 cerr << "Error: event " << iEvent << " V0 " << nV0
2340 << " track " << posFromV0 << " has already been used!" << endl;
2343 // Add the negative tracks from the V0
2345 if (!usedTrack[negFromV0]) {
2347 usedTrack[negFromV0] = kTRUE;
2349 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2350 esdTrack->GetPxPyPz(p);
2351 esdTrack->GetXYZ(pos);
2352 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2353 esdTrack->GetESDpid(pid);
2355 vV0->AddDaughter(aodTrack =
2356 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2357 esdTrack->GetLabel(),
2363 (Short_t)esdTrack->GetSign(),
2364 esdTrack->GetITSClusterMap(),
2367 kTRUE, // check if this is right
2368 kFALSE, // check if this is right
2369 AliAODTrack::kSecondary)
2371 aodTrack->ConvertAliPIDtoAODPID();
2374 cerr << "Error: event " << iEvent << " V0 " << nV0
2375 << " track " << negFromV0 << " has already been used!" << endl;
2378 } // end of the loop on V0s
2380 // Kinks: it is a big mess the access to the information in the kinks
2381 // The loop is on the tracks in order to find the mother and daugther of each kink
2384 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2387 AliESDtrack * esdTrack = esd->GetTrack(iTrack);
2389 Int_t ikink = esdTrack->GetKinkIndex(0);
2392 // Negative kink index: mother, positive: daughter
2394 // Search for the second track of the kink
2396 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
2398 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
2400 Int_t jkink = esdTrack1->GetKinkIndex(0);
2402 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
2404 // The two tracks are from the same kink
2406 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
2409 Int_t idaughter = -1;
2411 if (ikink<0 && jkink>0) {
2416 else if (ikink>0 && jkink<0) {
2422 cerr << "Error: Wrong combination of kink indexes: "
2423 << ikink << " " << jkink << endl;
2427 // Add the mother track
2429 AliAODTrack * mother = NULL;
2431 if (!usedTrack[imother]) {
2433 usedTrack[imother] = kTRUE;
2435 AliESDtrack *esdTrack = esd->GetTrack(imother);
2436 esdTrack->GetPxPyPz(p);
2437 esdTrack->GetXYZ(pos);
2438 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2439 esdTrack->GetESDpid(pid);
2442 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2443 esdTrack->GetLabel(),
2449 (Short_t)esdTrack->GetSign(),
2450 esdTrack->GetITSClusterMap(),
2453 kTRUE, // check if this is right
2454 kTRUE, // check if this is right
2455 AliAODTrack::kPrimary);
2456 primary->AddDaughter(mother);
2457 mother->ConvertAliPIDtoAODPID();
2460 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2461 << " track " << imother << " has already been used!" << endl;
2464 // Add the kink vertex
2465 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
2467 AliAODVertex * vkink =
2468 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
2472 AliAODVertex::kKink);
2473 // Add the daughter track
2475 AliAODTrack * daughter = NULL;
2477 if (!usedTrack[idaughter]) {
2479 usedTrack[idaughter] = kTRUE;
2481 AliESDtrack *esdTrack = esd->GetTrack(idaughter);
2482 esdTrack->GetPxPyPz(p);
2483 esdTrack->GetXYZ(pos);
2484 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2485 esdTrack->GetESDpid(pid);
2488 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2489 esdTrack->GetLabel(),
2495 (Short_t)esdTrack->GetSign(),
2496 esdTrack->GetITSClusterMap(),
2499 kTRUE, // check if this is right
2500 kTRUE, // check if this is right
2501 AliAODTrack::kPrimary);
2502 vkink->AddDaughter(daughter);
2503 daughter->ConvertAliPIDtoAODPID();
2506 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2507 << " track " << idaughter << " has already been used!" << endl;
2519 // Tracks (primary and orphan)
2521 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
2524 if (usedTrack[nTrack]) continue;
2526 AliESDtrack *esdTrack = esd->GetTrack(nTrack);
2527 esdTrack->GetPxPyPz(p);
2528 esdTrack->GetXYZ(pos);
2529 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2530 esdTrack->GetESDpid(pid);
2532 Float_t impactXY, impactZ;
2534 esdTrack->GetImpactParameters(impactXY,impactZ);
2537 // track inside the beam pipe
2539 primary->AddDaughter(aodTrack =
2540 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2541 esdTrack->GetLabel(),
2547 (Short_t)esdTrack->GetSign(),
2548 esdTrack->GetITSClusterMap(),
2551 kTRUE, // check if this is right
2552 kTRUE, // check if this is right
2553 AliAODTrack::kPrimary)
2555 aodTrack->ConvertAliPIDtoAODPID();
2558 // outside the beam pipe: orphan track
2560 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2561 esdTrack->GetLabel(),
2567 (Short_t)esdTrack->GetSign(),
2568 esdTrack->GetITSClusterMap(),
2571 kFALSE, // check if this is right
2572 kFALSE, // check if this is right
2573 AliAODTrack::kOrphan);
2574 aodTrack->ConvertAliPIDtoAODPID();
2576 } // end of loop on tracks
2579 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
2580 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
2582 AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);
2583 p[0] = esdMuTrack->Px();
2584 p[1] = esdMuTrack->Py();
2585 p[2] = esdMuTrack->Pz();
2586 pos[0] = primary->GetX();
2587 pos[1] = primary->GetY();
2588 pos[2] = primary->GetZ();
2590 // has to be changed once the muon pid is provided by the ESD
2591 for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
2593 primary->AddDaughter(
2594 new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
2595 0, // no label provided
2600 NULL, // no covariance matrix provided
2601 (Short_t)-99, // no charge provided
2602 0, // no ITSClusterMap
2605 kTRUE, // check if this is right
2606 kTRUE, // not used for vertex fit
2607 AliAODTrack::kPrimary)
2611 // Access to the AOD container of clusters
2612 TClonesArray &clusters = *(aod->GetClusters());
2616 Int_t nClusters = esd->GetNumberOfCaloClusters();
2618 for (Int_t iClust=0; iClust<nClusters; ++iClust) {
2620 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
2622 Int_t id = cluster->GetID();
2624 Float_t energy = cluster->GetClusterEnergy();
2625 cluster->GetGlobalPosition(posF);
2626 AliAODVertex *prodVertex = primary;
2627 AliAODTrack *primTrack = NULL;
2628 Char_t ttype=AliAODCluster::kUndef;
2630 if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral;
2631 else if (cluster->IsEMCAL()) {
2633 if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster)
2634 ttype = AliAODCluster::kEMCALPseudoCluster;
2636 ttype = AliAODCluster::kEMCALClusterv1;
2640 new(clusters[jClusters++]) AliAODCluster(id,
2644 NULL, // no covariance matrix provided
2645 NULL, // no pid for clusters provided
2650 } // end of loop on calo clusters
2652 delete [] usedTrack;
2656 // fill the tree for this event
2658 } // end of event loop
2660 aodTree->GetUserInfo()->Add(aod);
2665 // write the tree to the specified file
2666 aodFile = aodTree->GetCurrentFile();
2674 void AliReconstruction::WriteAlignmentData(AliESD* esd)
2676 // Write space-points which are then used in the alignment procedures
2677 // For the moment only ITS, TRD and TPC
2679 // Load TOF clusters
2681 fLoader[3]->LoadRecPoints("read");
2682 TTree* tree = fLoader[3]->TreeR();
2684 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2687 fTracker[3]->LoadClusters(tree);
2689 Int_t ntracks = esd->GetNumberOfTracks();
2690 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2692 AliESDtrack *track = esd->GetTrack(itrack);
2695 for (Int_t iDet = 3; iDet >= 0; iDet--)
2696 nsp += track->GetNcls(iDet);
2698 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2699 track->SetTrackPointArray(sp);
2701 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2702 AliTracker *tracker = fTracker[iDet];
2703 if (!tracker) continue;
2704 Int_t nspdet = track->GetNcls(iDet);
2705 if (nspdet <= 0) continue;
2706 track->GetClusters(iDet,idx);
2710 while (isp < nspdet) {
2711 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
2712 const Int_t kNTPCmax = 159;
2713 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2714 if (!isvalid) continue;
2715 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2721 fTracker[3]->UnloadClusters();
2722 fLoader[3]->UnloadRecPoints();
2726 //_____________________________________________________________________________
2727 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESD* esd)
2729 // The method reads the raw-data error log
2730 // accumulated within the rawReader.
2731 // It extracts the raw-data errors related to
2732 // the current event and stores them into
2733 // a TClonesArray inside the esd object.
2735 if (!fRawReader) return;
2737 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2739 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2741 if (iEvent != log->GetEventNumber()) continue;
2743 esd->AddRawDataErrorLog(log);