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 <TGeoManager.h>
123 #include <TLorentzVector.h>
125 #include "AliReconstruction.h"
126 #include "AliCodeTimer.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"
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"
152 #include "AliESDpid.h"
153 #include "AliESDtrack.h"
155 #include "AliESDTagCreator.h"
157 #include "AliGeomManager.h"
158 #include "AliTrackPointArray.h"
159 #include "AliCDBManager.h"
160 #include "AliCDBEntry.h"
161 #include "AliAlignObj.h"
163 #include "AliCentralTrigger.h"
164 #include "AliCTPRawStream.h"
166 #include "AliAODEvent.h"
167 #include "AliAODHeader.h"
168 #include "AliAODTrack.h"
169 #include "AliAODVertex.h"
170 #include "AliAODCluster.h"
173 ClassImp(AliReconstruction)
176 //_____________________________________________________________________________
177 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
179 //_____________________________________________________________________________
180 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
181 const char* name, const char* title) :
184 fUniformField(kTRUE),
185 fRunVertexFinder(kTRUE),
186 fRunHLTTracking(kFALSE),
187 fRunMuonTracking(kFALSE),
188 fStopOnError(kFALSE),
189 fWriteAlignmentData(kFALSE),
191 fWriteESDfriend(kFALSE),
193 fFillTriggerESD(kTRUE),
195 fRunLocalReconstruction("ALL"),
198 fGAliceFileName(gAliceFilename),
203 fNumberOfEventsPerFile(1),
206 fLoadAlignFromCDB(kTRUE),
207 fLoadAlignData("ALL"),
214 fDiamondProfile(NULL),
216 fAlignObjArray(NULL),
220 // create reconstruction object with default parameters
222 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
223 fReconstructor[iDet] = NULL;
224 fLoader[iDet] = NULL;
225 fTracker[iDet] = NULL;
230 //_____________________________________________________________________________
231 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
234 fUniformField(rec.fUniformField),
235 fRunVertexFinder(rec.fRunVertexFinder),
236 fRunHLTTracking(rec.fRunHLTTracking),
237 fRunMuonTracking(rec.fRunMuonTracking),
238 fStopOnError(rec.fStopOnError),
239 fWriteAlignmentData(rec.fWriteAlignmentData),
240 fCleanESD(rec.fCleanESD),
241 fWriteESDfriend(rec.fWriteESDfriend),
242 fWriteAOD(rec.fWriteAOD),
243 fFillTriggerESD(rec.fFillTriggerESD),
245 fRunLocalReconstruction(rec.fRunLocalReconstruction),
246 fRunTracking(rec.fRunTracking),
247 fFillESD(rec.fFillESD),
248 fGAliceFileName(rec.fGAliceFileName),
250 fEquipIdMap(rec.fEquipIdMap),
251 fFirstEvent(rec.fFirstEvent),
252 fLastEvent(rec.fLastEvent),
253 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
256 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
257 fLoadAlignData(rec.fLoadAlignData),
258 fESDPar(rec.fESDPar),
264 fDiamondProfile(NULL),
266 fAlignObjArray(rec.fAlignObjArray),
267 fCDBUri(rec.fCDBUri),
272 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
273 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
275 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
276 fReconstructor[iDet] = NULL;
277 fLoader[iDet] = NULL;
278 fTracker[iDet] = NULL;
280 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
281 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
285 //_____________________________________________________________________________
286 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
288 // assignment operator
290 this->~AliReconstruction();
291 new(this) AliReconstruction(rec);
295 //_____________________________________________________________________________
296 AliReconstruction::~AliReconstruction()
302 fSpecCDBUri.Delete();
304 AliCodeTimer::Instance()->Print();
307 //_____________________________________________________________________________
308 void AliReconstruction::InitCDBStorage()
310 // activate a default CDB storage
311 // First check if we have any CDB storage set, because it is used
312 // to retrieve the calibration and alignment constants
314 AliCDBManager* man = AliCDBManager::Instance();
315 if (man->IsDefaultStorageSet())
317 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
318 AliWarning("Default CDB storage has been already set !");
319 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
320 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
324 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
325 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
326 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
327 man->SetDefaultStorage(fCDBUri);
330 // Now activate the detector specific CDB storage locations
331 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
332 TObject* obj = fSpecCDBUri[i];
334 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
335 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
336 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
337 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
342 //_____________________________________________________________________________
343 void AliReconstruction::SetDefaultStorage(const char* uri) {
344 // Store the desired default CDB storage location
345 // Activate it later within the Run() method
351 //_____________________________________________________________________________
352 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
353 // Store a detector-specific CDB storage location
354 // Activate it later within the Run() method
356 AliCDBPath aPath(calibType);
357 if(!aPath.IsValid()){
358 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
359 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
360 if(!strcmp(calibType, fgkDetectorName[iDet])) {
361 aPath.SetPath(Form("%s/*", calibType));
362 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
366 if(!aPath.IsValid()){
367 AliError(Form("Not a valid path or detector: %s", calibType));
372 // check that calibType refers to a "valid" detector name
373 Bool_t isDetector = kFALSE;
374 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
375 TString detName = fgkDetectorName[iDet];
376 if(aPath.GetLevel0() == detName) {
383 AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
387 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
388 if (obj) fSpecCDBUri.Remove(obj);
389 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
396 //_____________________________________________________________________________
397 Bool_t AliReconstruction::SetRunNumber()
399 // The method is called in Run() in order
400 // to set a correct run number.
401 // In case of raw data reconstruction the
402 // run number is taken from the raw data header
404 if(AliCDBManager::Instance()->GetRun() < 0) {
406 AliError("No run loader is found !");
409 // read run number from gAlice
410 if(fRunLoader->GetAliRun())
411 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
414 if(fRawReader->NextEvent()) {
415 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
416 fRawReader->RewindEvents();
419 AliError("No raw-data events found !");
424 AliError("Neither gAlice nor RawReader objects are found !");
428 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
433 //_____________________________________________________________________________
434 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
436 // Read the alignment objects from CDB.
437 // Each detector is supposed to have the
438 // alignment objects in DET/Align/Data CDB path.
439 // All the detector objects are then collected,
440 // sorted by geometry level (starting from ALIC) and
441 // then applied to the TGeo geometry.
442 // Finally an overlaps check is performed.
444 // Load alignment data from CDB and fill fAlignObjArray
445 if(fLoadAlignFromCDB){
447 TString detStr = detectors;
448 TString loadAlObjsListOfDets = "";
450 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
451 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
452 loadAlObjsListOfDets += fgkDetectorName[iDet];
453 loadAlObjsListOfDets += " ";
454 } // end loop over detectors
455 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
457 // Check if the array with alignment objects was
458 // provided by the user. If yes, apply the objects
459 // to the present TGeo geometry
460 if (fAlignObjArray) {
461 if (gGeoManager && gGeoManager->IsClosed()) {
462 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
463 AliError("The misalignment of one or more volumes failed!"
464 "Compare the list of simulated detectors and the list of detector alignment data!");
469 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
475 delete fAlignObjArray; fAlignObjArray=0;
480 //_____________________________________________________________________________
481 void AliReconstruction::SetGAliceFile(const char* fileName)
483 // set the name of the galice file
485 fGAliceFileName = fileName;
488 //_____________________________________________________________________________
489 void AliReconstruction::SetOption(const char* detector, const char* option)
491 // set options for the reconstruction of a detector
493 TObject* obj = fOptions.FindObject(detector);
494 if (obj) fOptions.Remove(obj);
495 fOptions.Add(new TNamed(detector, option));
499 //_____________________________________________________________________________
500 Bool_t AliReconstruction::Run(const char* input)
502 // run the reconstruction
507 if (!input) input = fInput.Data();
508 TString fileName(input);
509 if (fileName.EndsWith("/")) {
510 fRawReader = new AliRawReaderFile(fileName);
511 } else if (fileName.EndsWith(".root")) {
512 fRawReader = new AliRawReaderRoot(fileName);
513 } else if (!fileName.IsNull()) {
514 fRawReader = new AliRawReaderDate(fileName);
515 fRawReader->SelectEvents(7);
517 if (!fEquipIdMap.IsNull() && fRawReader)
518 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
521 // get the run loader
522 if (!InitRunLoader()) return kFALSE;
524 // Initialize the CDB storage
527 // Set run number in CDBManager (if it is not already set by the user)
528 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
530 // Import ideal TGeo geometry and apply misalignment
532 TString geom(gSystem->DirName(fGAliceFileName));
533 geom += "/geometry.root";
534 AliGeomManager::LoadGeometry(geom.Data());
535 if (!gGeoManager) if (fStopOnError) return kFALSE;
538 AliCDBManager* man = AliCDBManager::Instance();
539 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
541 // local reconstruction
542 if (!fRunLocalReconstruction.IsNull()) {
543 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
544 if (fStopOnError) {CleanUp(); return kFALSE;}
547 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
548 // fFillESD.IsNull()) return kTRUE;
551 if (fRunVertexFinder && !CreateVertexer()) {
559 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
566 // get the possibly already existing ESD file and tree
567 AliESDEvent* esd = new AliESDEvent(); AliESDEvent* hltesd = new AliESDEvent();
568 TFile* fileOld = NULL;
569 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
570 if (!gSystem->AccessPathName("AliESDs.root")){
571 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
572 fileOld = TFile::Open("AliESDs.old.root");
573 if (fileOld && fileOld->IsOpen()) {
574 treeOld = (TTree*) fileOld->Get("esdTree");
575 if (treeOld)esd->ReadFromTree(treeOld);
576 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
577 if (hlttreeOld) hltesd->ReadFromTree(hlttreeOld);
581 // create the ESD output file and tree
582 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
583 file->SetCompressionLevel(2);
584 if (!file->IsOpen()) {
585 AliError("opening AliESDs.root failed");
586 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
589 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
590 esd = new AliESDEvent();
591 esd->CreateStdContent();
592 esd->WriteToTree(tree);
594 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
595 hltesd = new AliESDEvent();
596 hltesd->CreateStdContent();
597 hltesd->WriteToTree(hlttree);
600 delete esd; delete hltesd;
601 esd = NULL; hltesd = NULL;
603 // create the branch with ESD additions
607 AliESDfriend *esdf = 0;
608 if (fWriteESDfriend) {
609 esdf = new AliESDfriend();
610 TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
611 br->SetFile("AliESDfriends.root");
612 esd->AddObject(esdf);
616 // Get the diamond profile from OCDB
617 AliCDBEntry* entry = AliCDBManager::Instance()
618 ->Get("GRP/Calib/MeanVertex");
621 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
623 AliError("No diamond profile found in OCDB!");
626 AliVertexerTracks tVertexer(AliTracker::GetBz());
627 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
630 if (fRawReader) fRawReader->RewindEvents();
632 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
633 if (fRawReader) fRawReader->NextEvent();
634 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
635 // copy old ESD to the new one
637 esd->ReadFromTree(treeOld);
638 treeOld->GetEntry(iEvent);
642 esd->ReadFromTree(hlttreeOld);
643 hlttreeOld->GetEntry(iEvent);
649 AliInfo(Form("processing event %d", iEvent));
650 fRunLoader->GetEvent(iEvent);
653 sprintf(aFileName, "ESD_%d.%d_final.root",
654 fRunLoader->GetHeader()->GetRun(),
655 fRunLoader->GetHeader()->GetEventNrInRun());
656 if (!gSystem->AccessPathName(aFileName)) continue;
658 // local reconstruction
659 if (!fRunLocalReconstruction.IsNull()) {
660 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
661 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
666 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
667 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
668 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
669 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
671 // Set magnetic field from the tracker
672 esd->SetMagneticField(AliTracker::GetBz());
673 hltesd->SetMagneticField(AliTracker::GetBz());
677 // Fill raw-data error log into the ESD
678 if (fRawReader) FillRawDataErrorLog(iEvent,esd);
681 if (fRunVertexFinder) {
682 if (!ReadESD(esd, "vertex")) {
683 if (!RunVertexFinder(esd)) {
684 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
686 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
691 if (!fRunTracking.IsNull()) {
692 if (fRunHLTTracking) {
693 hltesd->SetVertex(esd->GetVertex());
694 if (!RunHLTTracking(hltesd)) {
695 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
701 if (!fRunTracking.IsNull()) {
702 if (fRunMuonTracking) {
703 if (!RunMuonTracking(esd)) {
704 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
710 if (!fRunTracking.IsNull()) {
711 if (!ReadESD(esd, "tracking")) {
712 if (!RunTracking(esd)) {
713 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
715 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
720 if (!fFillESD.IsNull()) {
721 if (!FillESD(esd, fFillESD)) {
722 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
725 // fill Event header information from the RawEventHeader
726 if (fRawReader){FillRawEventHeaderESD(esd);}
729 AliESDpid::MakePID(esd);
730 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
732 if (fFillTriggerESD) {
733 if (!ReadESD(esd, "trigger")) {
734 if (!FillTriggerESD(esd)) {
735 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
737 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
741 //Try to improve the reconstructed primary vertex position using the tracks
742 AliESDVertex *pvtx=0;
743 Bool_t dovertex=kTRUE;
744 TObject* obj = fOptions.FindObject("ITS");
746 TString optITS = obj->GetTitle();
747 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
750 if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
751 if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
754 if (pvtx->GetStatus()) {
755 // Store the improved primary vertex
756 esd->SetPrimaryVertex(pvtx);
757 // Propagate the tracks to the DCA to the improved primary vertex
758 Double_t somethingbig = 777.;
759 Double_t bz = esd->GetMagneticField();
760 Int_t nt=esd->GetNumberOfTracks();
762 AliESDtrack *t = esd->GetTrack(nt);
763 t->RelateToVertex(pvtx, bz, somethingbig);
770 vtxer.Tracks2V0vertices(esd);
773 AliCascadeVertexer cvtxer;
774 cvtxer.V0sTracks2CascadeVertices(esd);
778 if (fCleanESD) CleanESD(esd);
779 if (fWriteESDfriend) {
780 new (esdf) AliESDfriend(); // Reset...
781 esd->GetESDfriend(esdf);
788 if (fCheckPointLevel > 0) WriteESD(esd, "final");
791 if (fWriteESDfriend) {
792 new (esdf) AliESDfriend(); // Reset...
795 // delete esdf; esdf = 0;
801 tree->GetUserInfo()->Add(esd);
802 hlttree->GetUserInfo()->Add(hltesd);
806 if(fESDPar.Contains("ESD.par")){
807 AliInfo("Attaching ESD.par to Tree");
808 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
809 tree->GetUserInfo()->Add(fn);
815 tree->SetBranchStatus("ESDfriend*",0);
820 TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE");
821 ESDFile2AODFile(file, aodFile);
826 CleanUp(file, fileOld);
828 // Create tags for the events in the ESD tree (the ESD tree is always present)
829 // In case of empty events the tags will contain dummy values
830 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
831 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent);
832 //if (fWriteAOD) tagCreator->CreateAODTags(fFirstEvent,fLastEvent);
838 //_____________________________________________________________________________
839 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
841 // run the local reconstruction
845 AliCDBManager* man = AliCDBManager::Instance();
846 Bool_t origCache = man->GetCacheFlag();
848 TString detStr = detectors;
849 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
850 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
851 AliReconstructor* reconstructor = GetReconstructor(iDet);
852 if (!reconstructor) continue;
853 if (reconstructor->HasLocalReconstruction()) continue;
855 AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
856 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
858 AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
859 AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
861 man->SetCacheFlag(kTRUE);
862 TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
863 man->GetAll(calibPath); // entries are cached!
865 AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
868 fRawReader->RewindEvents();
869 reconstructor->Reconstruct(fRunLoader, fRawReader);
871 reconstructor->Reconstruct(fRunLoader);
874 AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
876 // unload calibration data
877 man->UnloadFromCache(calibPath);
881 man->SetCacheFlag(origCache);
883 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
884 AliError(Form("the following detectors were not found: %s",
886 if (fStopOnError) return kFALSE;
892 //_____________________________________________________________________________
893 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
895 // run the local reconstruction
899 TString detStr = detectors;
900 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
901 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
902 AliReconstructor* reconstructor = GetReconstructor(iDet);
903 if (!reconstructor) continue;
904 AliLoader* loader = fLoader[iDet];
906 // conversion of digits
907 if (fRawReader && reconstructor->HasDigitConversion()) {
908 AliInfo(Form("converting raw data digits into root objects for %s",
909 fgkDetectorName[iDet]));
910 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
911 fgkDetectorName[iDet]));
912 loader->LoadDigits("update");
913 loader->CleanDigits();
914 loader->MakeDigitsContainer();
915 TTree* digitsTree = loader->TreeD();
916 reconstructor->ConvertDigits(fRawReader, digitsTree);
917 loader->WriteDigits("OVERWRITE");
918 loader->UnloadDigits();
921 // local reconstruction
922 if (!reconstructor->HasLocalReconstruction()) continue;
923 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
924 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
925 loader->LoadRecPoints("update");
926 loader->CleanRecPoints();
927 loader->MakeRecPointsContainer();
928 TTree* clustersTree = loader->TreeR();
929 if (fRawReader && !reconstructor->HasDigitConversion()) {
930 reconstructor->Reconstruct(fRawReader, clustersTree);
932 loader->LoadDigits("read");
933 TTree* digitsTree = loader->TreeD();
935 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
936 if (fStopOnError) return kFALSE;
938 reconstructor->Reconstruct(digitsTree, clustersTree);
940 loader->UnloadDigits();
942 loader->WriteRecPoints("OVERWRITE");
943 loader->UnloadRecPoints();
946 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
947 AliError(Form("the following detectors were not found: %s",
949 if (fStopOnError) return kFALSE;
955 //_____________________________________________________________________________
956 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
958 // run the barrel tracking
962 AliESDVertex* vertex = NULL;
963 Double_t vtxPos[3] = {0, 0, 0};
964 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
966 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
967 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
968 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
972 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
973 AliInfo("running the ITS vertex finder");
974 if (fLoader[0]) fLoader[0]->LoadRecPoints();
975 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
976 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
978 AliWarning("Vertex not found");
979 vertex = new AliESDVertex();
980 vertex->SetName("default");
983 vertex->SetName("reconstructed");
987 AliInfo("getting the primary vertex from MC");
988 vertex = new AliESDVertex(vtxPos, vtxErr);
992 vertex->GetXYZ(vtxPos);
993 vertex->GetSigmaXYZ(vtxErr);
995 AliWarning("no vertex reconstructed");
996 vertex = new AliESDVertex(vtxPos, vtxErr);
998 esd->SetVertex(vertex);
999 // if SPD multiplicity has been determined, it is stored in the ESD
1000 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1001 if(mult)esd->SetMultiplicity(mult);
1003 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1004 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1011 //_____________________________________________________________________________
1012 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1014 // run the HLT barrel tracking
1016 AliCodeTimerAuto("")
1019 AliError("Missing runLoader!");
1023 AliInfo("running HLT tracking");
1025 // Get a pointer to the HLT reconstructor
1026 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1027 if (!reconstructor) return kFALSE;
1030 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1031 TString detName = fgkDetectorName[iDet];
1032 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1033 reconstructor->SetOption(detName.Data());
1034 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1036 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1037 if (fStopOnError) return kFALSE;
1041 Double_t vtxErr[3]={0.005,0.005,0.010};
1042 const AliESDVertex *vertex = esd->GetVertex();
1043 vertex->GetXYZ(vtxPos);
1044 tracker->SetVertex(vtxPos,vtxErr);
1046 fLoader[iDet]->LoadRecPoints("read");
1047 TTree* tree = fLoader[iDet]->TreeR();
1049 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1052 tracker->LoadClusters(tree);
1054 if (tracker->Clusters2Tracks(esd) != 0) {
1055 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1059 tracker->UnloadClusters();
1067 //_____________________________________________________________________________
1068 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1070 // run the muon spectrometer tracking
1072 AliCodeTimerAuto("")
1075 AliError("Missing runLoader!");
1078 Int_t iDet = 7; // for MUON
1080 AliInfo("is running...");
1082 // Get a pointer to the MUON reconstructor
1083 AliReconstructor *reconstructor = GetReconstructor(iDet);
1084 if (!reconstructor) return kFALSE;
1087 TString detName = fgkDetectorName[iDet];
1088 AliDebug(1, Form("%s tracking", detName.Data()));
1089 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1091 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1096 fLoader[iDet]->LoadTracks("update");
1097 fLoader[iDet]->CleanTracks();
1098 fLoader[iDet]->MakeTracksContainer();
1101 fLoader[iDet]->LoadRecPoints("read");
1102 tracker->LoadClusters(fLoader[iDet]->TreeR());
1104 Int_t rv = tracker->Clusters2Tracks(esd);
1106 fLoader[iDet]->UnloadRecPoints();
1110 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1114 tracker->UnloadClusters();
1116 fLoader[iDet]->UnloadRecPoints();
1118 fLoader[iDet]->WriteTracks("OVERWRITE");
1119 fLoader[iDet]->UnloadTracks();
1127 //_____________________________________________________________________________
1128 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1130 // run the barrel tracking
1132 AliCodeTimerAuto("")
1134 AliInfo("running tracking");
1136 //Fill the ESD with the T0 info (will be used by the TOF)
1137 if (fReconstructor[11])
1138 GetReconstructor(11)->FillESD(fRunLoader, esd);
1140 // pass 1: TPC + ITS inwards
1141 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1142 if (!fTracker[iDet]) continue;
1143 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1146 fLoader[iDet]->LoadRecPoints("read");
1147 TTree* tree = fLoader[iDet]->TreeR();
1149 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1152 fTracker[iDet]->LoadClusters(tree);
1155 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1156 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1159 if (fCheckPointLevel > 1) {
1160 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1162 // preliminary PID in TPC needed by the ITS tracker
1164 GetReconstructor(1)->FillESD(fRunLoader, esd);
1165 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1166 AliESDpid::MakePID(esd);
1170 // pass 2: ALL backwards
1171 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1172 if (!fTracker[iDet]) continue;
1173 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1176 if (iDet > 1) { // all except ITS, TPC
1178 fLoader[iDet]->LoadRecPoints("read");
1179 tree = fLoader[iDet]->TreeR();
1181 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1184 fTracker[iDet]->LoadClusters(tree);
1188 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1189 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1192 if (fCheckPointLevel > 1) {
1193 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1197 if (iDet > 2) { // all except ITS, TPC, TRD
1198 fTracker[iDet]->UnloadClusters();
1199 fLoader[iDet]->UnloadRecPoints();
1201 // updated PID in TPC needed by the ITS tracker -MI
1203 GetReconstructor(1)->FillESD(fRunLoader, esd);
1204 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1205 AliESDpid::MakePID(esd);
1209 // write space-points to the ESD in case alignment data output
1211 if (fWriteAlignmentData)
1212 WriteAlignmentData(esd);
1214 // pass 3: TRD + TPC + ITS refit inwards
1215 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1216 if (!fTracker[iDet]) continue;
1217 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1220 if (fTracker[iDet]->RefitInward(esd) != 0) {
1221 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1224 if (fCheckPointLevel > 1) {
1225 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1229 fTracker[iDet]->UnloadClusters();
1230 fLoader[iDet]->UnloadRecPoints();
1233 // Propagate track to the vertex - if not done by ITS
1235 Int_t ntracks = esd->GetNumberOfTracks();
1236 for (Int_t itrack=0; itrack<ntracks; itrack++){
1237 const Double_t kRadius = 3; // beam pipe radius
1238 const Double_t kMaxStep = 5; // max step
1239 const Double_t kMaxD = 123456; // max distance to prim vertex
1240 Double_t fieldZ = AliTracker::GetBz(); //
1241 AliESDtrack * track = esd->GetTrack(itrack);
1242 if (!track) continue;
1243 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1244 track->PropagateTo(kRadius, fieldZ, track->GetMass(),kMaxStep,kTRUE);
1245 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1251 //_____________________________________________________________________________
1252 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1254 // Remove the data which are not needed for the physics analysis.
1257 AliInfo("Cleaning the ESD...");
1259 const AliESDVertex *vertex=esd->GetVertex();
1260 Double_t vz=vertex->GetZv();
1262 Int_t nTracks=esd->GetNumberOfTracks();
1263 for (Int_t i=0; i<nTracks; i++) {
1264 AliESDtrack *track=esd->GetTrack(i);
1266 Float_t xy,z; track->GetImpactParameters(xy,z);
1267 if (TMath::Abs(xy) < 50.) continue;
1268 if (vertex->GetStatus())
1269 if (TMath::Abs(vz-z) < 5.) continue;
1271 esd->RemoveTrack(i);
1277 //_____________________________________________________________________________
1278 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1280 // fill the event summary data
1282 AliCodeTimerAuto("")
1284 TString detStr = detectors;
1285 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1286 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1287 AliReconstructor* reconstructor = GetReconstructor(iDet);
1288 if (!reconstructor) continue;
1290 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1291 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1292 TTree* clustersTree = NULL;
1293 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1294 fLoader[iDet]->LoadRecPoints("read");
1295 clustersTree = fLoader[iDet]->TreeR();
1296 if (!clustersTree) {
1297 AliError(Form("Can't get the %s clusters tree",
1298 fgkDetectorName[iDet]));
1299 if (fStopOnError) return kFALSE;
1302 if (fRawReader && !reconstructor->HasDigitConversion()) {
1303 reconstructor->FillESD(fRawReader, clustersTree, esd);
1305 TTree* digitsTree = NULL;
1306 if (fLoader[iDet]) {
1307 fLoader[iDet]->LoadDigits("read");
1308 digitsTree = fLoader[iDet]->TreeD();
1310 AliError(Form("Can't get the %s digits tree",
1311 fgkDetectorName[iDet]));
1312 if (fStopOnError) return kFALSE;
1315 reconstructor->FillESD(digitsTree, clustersTree, esd);
1316 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1318 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1319 fLoader[iDet]->UnloadRecPoints();
1323 reconstructor->FillESD(fRunLoader, fRawReader, esd);
1325 reconstructor->FillESD(fRunLoader, esd);
1327 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1331 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1332 AliError(Form("the following detectors were not found: %s",
1334 if (fStopOnError) return kFALSE;
1340 //_____________________________________________________________________________
1341 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1343 // Reads the trigger decision which is
1344 // stored in Trigger.root file and fills
1345 // the corresponding esd entries
1347 AliCodeTimerAuto("")
1349 AliInfo("Filling trigger information into the ESD");
1352 AliCTPRawStream input(fRawReader);
1353 if (!input.Next()) {
1354 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1357 esd->SetTriggerMask(input.GetClassMask());
1358 esd->SetTriggerCluster(input.GetClusterMask());
1361 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1363 if (!runloader->LoadTrigger()) {
1364 AliCentralTrigger *aCTP = runloader->GetTrigger();
1365 esd->SetTriggerMask(aCTP->GetClassMask());
1366 esd->SetTriggerCluster(aCTP->GetClusterMask());
1369 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1374 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1386 //_____________________________________________________________________________
1387 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1390 // Filling information from RawReader Header
1393 AliInfo("Filling information from RawReader Header");
1394 esd->SetBunchCrossNumber(0);
1395 esd->SetOrbitNumber(0);
1396 esd->SetPeriodNumber(0);
1397 esd->SetTimeStamp(0);
1398 esd->SetEventType(0);
1399 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1402 const UInt_t *id = eventHeader->GetP("Id");
1403 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1404 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1405 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1407 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1408 esd->SetEventType((eventHeader->Get("Type")));
1415 //_____________________________________________________________________________
1416 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1418 // check whether detName is contained in detectors
1419 // if yes, it is removed from detectors
1421 // check if all detectors are selected
1422 if ((detectors.CompareTo("ALL") == 0) ||
1423 detectors.BeginsWith("ALL ") ||
1424 detectors.EndsWith(" ALL") ||
1425 detectors.Contains(" ALL ")) {
1430 // search for the given detector
1431 Bool_t result = kFALSE;
1432 if ((detectors.CompareTo(detName) == 0) ||
1433 detectors.BeginsWith(detName+" ") ||
1434 detectors.EndsWith(" "+detName) ||
1435 detectors.Contains(" "+detName+" ")) {
1436 detectors.ReplaceAll(detName, "");
1440 // clean up the detectors string
1441 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1442 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1443 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1448 //_____________________________________________________________________________
1449 Bool_t AliReconstruction::InitRunLoader()
1451 // get or create the run loader
1453 if (gAlice) delete gAlice;
1456 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1457 // load all base libraries to get the loader classes
1458 TString libs = gSystem->GetLibraries();
1459 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1460 TString detName = fgkDetectorName[iDet];
1461 if (detName == "HLT") continue;
1462 if (libs.Contains("lib" + detName + "base.so")) continue;
1463 gSystem->Load("lib" + detName + "base.so");
1465 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1467 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1471 fRunLoader->CdGAFile();
1472 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1473 if (fRunLoader->LoadgAlice() == 0) {
1474 gAlice = fRunLoader->GetAliRun();
1475 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1478 if (!gAlice && !fRawReader) {
1479 AliError(Form("no gAlice object found in file %s",
1480 fGAliceFileName.Data()));
1485 } else { // galice.root does not exist
1487 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1491 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1492 AliConfig::GetDefaultEventFolderName(),
1495 AliError(Form("could not create run loader in file %s",
1496 fGAliceFileName.Data()));
1500 fRunLoader->MakeTree("E");
1502 while (fRawReader->NextEvent()) {
1503 fRunLoader->SetEventNumber(iEvent);
1504 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1506 fRunLoader->MakeTree("H");
1507 fRunLoader->TreeE()->Fill();
1510 fRawReader->RewindEvents();
1511 if (fNumberOfEventsPerFile > 0)
1512 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1514 fRunLoader->SetNumberOfEventsPerFile(iEvent);
1515 fRunLoader->WriteHeader("OVERWRITE");
1516 fRunLoader->CdGAFile();
1517 fRunLoader->Write(0, TObject::kOverwrite);
1518 // AliTracker::SetFieldMap(???);
1524 //_____________________________________________________________________________
1525 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1527 // get the reconstructor object and the loader for a detector
1529 if (fReconstructor[iDet]) return fReconstructor[iDet];
1531 // load the reconstructor object
1532 TPluginManager* pluginManager = gROOT->GetPluginManager();
1533 TString detName = fgkDetectorName[iDet];
1534 TString recName = "Ali" + detName + "Reconstructor";
1535 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1537 if (detName == "HLT") {
1538 if (!gROOT->GetClass("AliLevel3")) {
1539 gSystem->Load("libAliHLTSrc.so");
1540 gSystem->Load("libAliHLTMisc.so");
1541 gSystem->Load("libAliHLTHough.so");
1542 gSystem->Load("libAliHLTComp.so");
1546 AliReconstructor* reconstructor = NULL;
1547 // first check if a plugin is defined for the reconstructor
1548 TPluginHandler* pluginHandler =
1549 pluginManager->FindHandler("AliReconstructor", detName);
1550 // if not, add a plugin for it
1551 if (!pluginHandler) {
1552 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1553 TString libs = gSystem->GetLibraries();
1554 if (libs.Contains("lib" + detName + "base.so") ||
1555 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1556 pluginManager->AddHandler("AliReconstructor", detName,
1557 recName, detName + "rec", recName + "()");
1559 pluginManager->AddHandler("AliReconstructor", detName,
1560 recName, detName, recName + "()");
1562 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1564 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1565 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1567 if (reconstructor) {
1568 TObject* obj = fOptions.FindObject(detName.Data());
1569 if (obj) reconstructor->SetOption(obj->GetTitle());
1570 reconstructor->Init(fRunLoader);
1571 fReconstructor[iDet] = reconstructor;
1574 // get or create the loader
1575 if (detName != "HLT") {
1576 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1577 if (!fLoader[iDet]) {
1578 AliConfig::Instance()
1579 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1581 // first check if a plugin is defined for the loader
1583 pluginManager->FindHandler("AliLoader", detName);
1584 // if not, add a plugin for it
1585 if (!pluginHandler) {
1586 TString loaderName = "Ali" + detName + "Loader";
1587 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1588 pluginManager->AddHandler("AliLoader", detName,
1589 loaderName, detName + "base",
1590 loaderName + "(const char*, TFolder*)");
1591 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1593 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1595 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1596 fRunLoader->GetEventFolder());
1598 if (!fLoader[iDet]) { // use default loader
1599 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1601 if (!fLoader[iDet]) {
1602 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1603 if (fStopOnError) return NULL;
1605 fRunLoader->AddLoader(fLoader[iDet]);
1606 fRunLoader->CdGAFile();
1607 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1608 fRunLoader->Write(0, TObject::kOverwrite);
1613 return reconstructor;
1616 //_____________________________________________________________________________
1617 Bool_t AliReconstruction::CreateVertexer()
1619 // create the vertexer
1622 AliReconstructor* itsReconstructor = GetReconstructor(0);
1623 if (itsReconstructor) {
1624 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1627 AliWarning("couldn't create a vertexer for ITS");
1628 if (fStopOnError) return kFALSE;
1634 //_____________________________________________________________________________
1635 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1637 // create the trackers
1639 TString detStr = detectors;
1640 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1641 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1642 AliReconstructor* reconstructor = GetReconstructor(iDet);
1643 if (!reconstructor) continue;
1644 TString detName = fgkDetectorName[iDet];
1645 if (detName == "HLT") {
1646 fRunHLTTracking = kTRUE;
1649 if (detName == "MUON") {
1650 fRunMuonTracking = kTRUE;
1655 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1656 if (!fTracker[iDet] && (iDet < 7)) {
1657 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1658 if (fStopOnError) return kFALSE;
1665 //_____________________________________________________________________________
1666 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1668 // delete trackers and the run loader and close and delete the file
1670 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1671 delete fReconstructor[iDet];
1672 fReconstructor[iDet] = NULL;
1673 fLoader[iDet] = NULL;
1674 delete fTracker[iDet];
1675 fTracker[iDet] = NULL;
1679 delete fDiamondProfile;
1680 fDiamondProfile = NULL;
1695 gSystem->Unlink("AliESDs.old.root");
1700 //_____________________________________________________________________________
1702 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
1704 // read the ESD event from a file
1706 if (!esd) return kFALSE;
1708 sprintf(fileName, "ESD_%d.%d_%s.root",
1709 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1710 if (gSystem->AccessPathName(fileName)) return kFALSE;
1712 AliInfo(Form("reading ESD from file %s", fileName));
1713 AliDebug(1, Form("reading ESD from file %s", fileName));
1714 TFile* file = TFile::Open(fileName);
1715 if (!file || !file->IsOpen()) {
1716 AliError(Form("opening %s failed", fileName));
1723 esd = (AliESDEvent*) file->Get("ESD");
1732 //_____________________________________________________________________________
1733 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
1735 // write the ESD event to a file
1739 sprintf(fileName, "ESD_%d.%d_%s.root",
1740 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1742 AliDebug(1, Form("writing ESD to file %s", fileName));
1743 TFile* file = TFile::Open(fileName, "recreate");
1744 if (!file || !file->IsOpen()) {
1745 AliError(Form("opening %s failed", fileName));
1757 //_____________________________________________________________________________
1758 void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
1760 // write all files from the given esd file to an aod file
1762 // create an AliAOD object
1763 AliAODEvent *aod = new AliAODEvent();
1764 aod->CreateStdContent();
1770 TTree *aodTree = new TTree("AOD", "AliAOD tree");
1771 aodTree->Branch(aod->GetList());
1774 TTree *t = (TTree*) esdFile->Get("esdTree");
1775 AliESDEvent *esd = new AliESDEvent();
1776 esd->ReadFromTree(t);
1778 Int_t nEvents = t->GetEntries();
1780 // set arrays and pointers
1788 // loop over events and fill them
1789 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
1790 t->GetEntry(iEvent);
1792 // Multiplicity information needed by the header (to be revised!)
1793 Int_t nTracks = esd->GetNumberOfTracks();
1794 Int_t nPosTracks = 0;
1795 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack)
1796 if (esd->GetTrack(iTrack)->GetSign()> 0) nPosTracks++;
1798 // Update the header
1799 AliAODHeader* header = aod->GetHeader();
1801 header->SetRunNumber (esd->GetRunNumber() );
1802 header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
1803 header->SetOrbitNumber (esd->GetOrbitNumber() );
1804 header->SetPeriodNumber (esd->GetPeriodNumber() );
1805 header->SetTriggerMask (esd->GetTriggerMask() );
1806 header->SetTriggerCluster (esd->GetTriggerCluster() );
1807 header->SetEventType (esd->GetEventType() );
1808 header->SetMagneticField (esd->GetMagneticField() );
1809 header->SetZDCN1Energy (esd->GetZDCN1Energy() );
1810 header->SetZDCP1Energy (esd->GetZDCP1Energy() );
1811 header->SetZDCN2Energy (esd->GetZDCN2Energy() );
1812 header->SetZDCP2Energy (esd->GetZDCP2Energy() );
1813 header->SetZDCEMEnergy (esd->GetZDCEMEnergy() );
1814 header->SetRefMultiplicity (nTracks);
1815 header->SetRefMultiplicityPos(nPosTracks);
1816 header->SetRefMultiplicityNeg(nTracks - nPosTracks);
1817 header->SetMuonMagFieldScale(-999.); // FIXME
1818 header->SetCentrality(-999.); // FIXME
1822 Int_t nV0s = esd->GetNumberOfV0s();
1823 Int_t nCascades = esd->GetNumberOfCascades();
1824 Int_t nKinks = esd->GetNumberOfKinks();
1825 Int_t nVertices = nV0s + nCascades + nKinks;
1827 aod->ResetStd(nTracks, nVertices);
1828 AliAODTrack *aodTrack;
1831 // Array to take into account the tracks already added to the AOD
1832 Bool_t * usedTrack = NULL;
1834 usedTrack = new Bool_t[nTracks];
1835 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
1837 // Array to take into account the V0s already added to the AOD
1838 Bool_t * usedV0 = NULL;
1840 usedV0 = new Bool_t[nV0s];
1841 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
1843 // Array to take into account the kinks already added to the AOD
1844 Bool_t * usedKink = NULL;
1846 usedKink = new Bool_t[nKinks];
1847 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
1850 // Access to the AOD container of vertices
1851 TClonesArray &vertices = *(aod->GetVertices());
1854 // Access to the AOD container of tracks
1855 TClonesArray &tracks = *(aod->GetTracks());
1858 // Add primary vertex. The primary tracks will be defined
1859 // after the loops on the composite objects (V0, cascades, kinks)
1860 const AliESDVertex *vtx = esd->GetPrimaryVertex();
1862 vtx->GetXYZ(pos); // position
1863 vtx->GetCovMatrix(covVtx); //covariance matrix
1865 AliAODVertex * primary = new(vertices[jVertices++])
1866 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, AliAODVertex::kPrimary);
1868 // Create vertices starting from the most complex objects
1871 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
1872 AliESDcascade *cascade = esd->GetCascade(nCascade);
1874 cascade->GetXYZ(pos[0], pos[1], pos[2]);
1875 cascade->GetPosCovXi(covVtx);
1877 // Add the cascade vertex
1878 AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
1880 cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
1882 AliAODVertex::kCascade);
1884 primary->AddDaughter(vcascade);
1886 // Add the V0 from the cascade. The ESD class have to be optimized...
1887 // Now we have to search for the corresponding Vo in the list of V0s
1888 // using the indeces of the positive and negative tracks
1890 Int_t posFromV0 = cascade->GetPindex();
1891 Int_t negFromV0 = cascade->GetNindex();
1894 AliESDv0 * v0 = 0x0;
1897 for (Int_t iV0=0; iV0<nV0s; ++iV0) {
1899 v0 = esd->GetV0(iV0);
1900 Int_t posV0 = v0->GetPindex();
1901 Int_t negV0 = v0->GetNindex();
1903 if (posV0==posFromV0 && negV0==negFromV0) {
1909 AliAODVertex * vV0FromCascade = 0x0;
1911 if (indV0>-1 && !usedV0[indV0] ) {
1913 // the V0 exists in the array of V0s and is not used
1915 usedV0[indV0] = kTRUE;
1917 v0->GetXYZ(pos[0], pos[1], pos[2]);
1918 v0->GetPosCov(covVtx);
1920 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
1922 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
1927 // the V0 doesn't exist in the array of V0s or was used
1928 cerr << "Error: event " << iEvent << " cascade " << nCascade
1929 << " The V0 " << indV0
1930 << " doesn't exist in the array of V0s or was used!" << endl;
1932 cascade->GetXYZ(pos[0], pos[1], pos[2]);
1933 cascade->GetPosCov(covVtx);
1935 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
1937 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
1940 vcascade->AddDaughter(vV0FromCascade);
1943 // Add the positive tracks from the V0
1945 if (! usedTrack[posFromV0]) {
1947 usedTrack[posFromV0] = kTRUE;
1949 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
1950 esdTrack->GetPxPyPz(p);
1951 esdTrack->GetXYZ(pos);
1952 esdTrack->GetCovarianceXYZPxPyPz(covTr);
1953 esdTrack->GetESDpid(pid);
1955 vV0FromCascade->AddDaughter(aodTrack =
1956 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
1957 esdTrack->GetLabel(),
1963 (Short_t)esdTrack->GetSign(),
1964 esdTrack->GetITSClusterMap(),
1967 kTRUE, // check if this is right
1968 kFALSE, // check if this is right
1969 AliAODTrack::kSecondary)
1971 aodTrack->ConvertAliPIDtoAODPID();
1974 cerr << "Error: event " << iEvent << " cascade " << nCascade
1975 << " track " << posFromV0 << " has already been used!" << endl;
1978 // Add the negative tracks from the V0
1980 if (!usedTrack[negFromV0]) {
1982 usedTrack[negFromV0] = kTRUE;
1984 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
1985 esdTrack->GetPxPyPz(p);
1986 esdTrack->GetXYZ(pos);
1987 esdTrack->GetCovarianceXYZPxPyPz(covTr);
1988 esdTrack->GetESDpid(pid);
1990 vV0FromCascade->AddDaughter(aodTrack =
1991 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
1992 esdTrack->GetLabel(),
1998 (Short_t)esdTrack->GetSign(),
1999 esdTrack->GetITSClusterMap(),
2002 kTRUE, // check if this is right
2003 kFALSE, // check if this is right
2004 AliAODTrack::kSecondary)
2006 aodTrack->ConvertAliPIDtoAODPID();
2009 cerr << "Error: event " << iEvent << " cascade " << nCascade
2010 << " track " << negFromV0 << " has already been used!" << endl;
2013 // Add the bachelor track from the cascade
2015 Int_t bachelor = cascade->GetBindex();
2017 if(!usedTrack[bachelor]) {
2019 usedTrack[bachelor] = kTRUE;
2021 AliESDtrack *esdTrack = esd->GetTrack(bachelor);
2022 esdTrack->GetPxPyPz(p);
2023 esdTrack->GetXYZ(pos);
2024 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2025 esdTrack->GetESDpid(pid);
2027 vcascade->AddDaughter(aodTrack =
2028 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2029 esdTrack->GetLabel(),
2035 (Short_t)esdTrack->GetSign(),
2036 esdTrack->GetITSClusterMap(),
2039 kTRUE, // check if this is right
2040 kFALSE, // check if this is right
2041 AliAODTrack::kSecondary)
2043 aodTrack->ConvertAliPIDtoAODPID();
2046 cerr << "Error: event " << iEvent << " cascade " << nCascade
2047 << " track " << bachelor << " has already been used!" << endl;
2050 // Add the primary track of the cascade (if any)
2052 } // end of the loop on cascades
2056 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
2058 if (usedV0[nV0]) continue; // skip if aready added to the AOD
2060 AliESDv0 *v0 = esd->GetV0(nV0);
2062 v0->GetXYZ(pos[0], pos[1], pos[2]);
2063 v0->GetPosCov(covVtx);
2065 AliAODVertex * vV0 =
2066 new(vertices[jVertices++]) AliAODVertex(pos,
2068 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2071 primary->AddDaughter(vV0);
2073 Int_t posFromV0 = v0->GetPindex();
2074 Int_t negFromV0 = v0->GetNindex();
2076 // Add the positive tracks from the V0
2078 if (!usedTrack[posFromV0]) {
2080 usedTrack[posFromV0] = kTRUE;
2082 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2083 esdTrack->GetPxPyPz(p);
2084 esdTrack->GetXYZ(pos);
2085 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2086 esdTrack->GetESDpid(pid);
2088 vV0->AddDaughter(aodTrack =
2089 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2090 esdTrack->GetLabel(),
2096 (Short_t)esdTrack->GetSign(),
2097 esdTrack->GetITSClusterMap(),
2100 kTRUE, // check if this is right
2101 kFALSE, // check if this is right
2102 AliAODTrack::kSecondary)
2104 aodTrack->ConvertAliPIDtoAODPID();
2107 cerr << "Error: event " << iEvent << " V0 " << nV0
2108 << " track " << posFromV0 << " has already been used!" << endl;
2111 // Add the negative tracks from the V0
2113 if (!usedTrack[negFromV0]) {
2115 usedTrack[negFromV0] = kTRUE;
2117 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2118 esdTrack->GetPxPyPz(p);
2119 esdTrack->GetXYZ(pos);
2120 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2121 esdTrack->GetESDpid(pid);
2123 vV0->AddDaughter(aodTrack =
2124 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2125 esdTrack->GetLabel(),
2131 (Short_t)esdTrack->GetSign(),
2132 esdTrack->GetITSClusterMap(),
2135 kTRUE, // check if this is right
2136 kFALSE, // check if this is right
2137 AliAODTrack::kSecondary)
2139 aodTrack->ConvertAliPIDtoAODPID();
2142 cerr << "Error: event " << iEvent << " V0 " << nV0
2143 << " track " << negFromV0 << " has already been used!" << endl;
2146 } // end of the loop on V0s
2148 // Kinks: it is a big mess the access to the information in the kinks
2149 // The loop is on the tracks in order to find the mother and daugther of each kink
2152 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2155 AliESDtrack * esdTrack = esd->GetTrack(iTrack);
2157 Int_t ikink = esdTrack->GetKinkIndex(0);
2160 // Negative kink index: mother, positive: daughter
2162 // Search for the second track of the kink
2164 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
2166 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
2168 Int_t jkink = esdTrack1->GetKinkIndex(0);
2170 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
2172 // The two tracks are from the same kink
2174 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
2177 Int_t idaughter = -1;
2179 if (ikink<0 && jkink>0) {
2184 else if (ikink>0 && jkink<0) {
2190 cerr << "Error: Wrong combination of kink indexes: "
2191 << ikink << " " << jkink << endl;
2195 // Add the mother track
2197 AliAODTrack * mother = NULL;
2199 if (!usedTrack[imother]) {
2201 usedTrack[imother] = kTRUE;
2203 AliESDtrack *esdTrack = esd->GetTrack(imother);
2204 esdTrack->GetPxPyPz(p);
2205 esdTrack->GetXYZ(pos);
2206 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2207 esdTrack->GetESDpid(pid);
2210 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2211 esdTrack->GetLabel(),
2217 (Short_t)esdTrack->GetSign(),
2218 esdTrack->GetITSClusterMap(),
2221 kTRUE, // check if this is right
2222 kTRUE, // check if this is right
2223 AliAODTrack::kPrimary);
2224 primary->AddDaughter(mother);
2225 mother->ConvertAliPIDtoAODPID();
2228 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2229 << " track " << imother << " has already been used!" << endl;
2232 // Add the kink vertex
2233 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
2235 AliAODVertex * vkink =
2236 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
2240 AliAODVertex::kKink);
2241 // Add the daughter track
2243 AliAODTrack * daughter = NULL;
2245 if (!usedTrack[idaughter]) {
2247 usedTrack[idaughter] = kTRUE;
2249 AliESDtrack *esdTrack = esd->GetTrack(idaughter);
2250 esdTrack->GetPxPyPz(p);
2251 esdTrack->GetXYZ(pos);
2252 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2253 esdTrack->GetESDpid(pid);
2256 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2257 esdTrack->GetLabel(),
2263 (Short_t)esdTrack->GetSign(),
2264 esdTrack->GetITSClusterMap(),
2267 kTRUE, // check if this is right
2268 kTRUE, // check if this is right
2269 AliAODTrack::kPrimary);
2270 vkink->AddDaughter(daughter);
2271 daughter->ConvertAliPIDtoAODPID();
2274 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2275 << " track " << idaughter << " has already been used!" << endl;
2287 // Tracks (primary and orphan)
2289 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
2292 if (usedTrack[nTrack]) continue;
2294 AliESDtrack *esdTrack = esd->GetTrack(nTrack);
2295 esdTrack->GetPxPyPz(p);
2296 esdTrack->GetXYZ(pos);
2297 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2298 esdTrack->GetESDpid(pid);
2300 Float_t impactXY, impactZ;
2302 esdTrack->GetImpactParameters(impactXY,impactZ);
2305 // track inside the beam pipe
2307 primary->AddDaughter(aodTrack =
2308 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2309 esdTrack->GetLabel(),
2315 (Short_t)esdTrack->GetSign(),
2316 esdTrack->GetITSClusterMap(),
2319 kTRUE, // check if this is right
2320 kTRUE, // check if this is right
2321 AliAODTrack::kPrimary)
2323 aodTrack->ConvertAliPIDtoAODPID();
2326 // outside the beam pipe: orphan track
2328 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2329 esdTrack->GetLabel(),
2335 (Short_t)esdTrack->GetSign(),
2336 esdTrack->GetITSClusterMap(),
2339 kFALSE, // check if this is right
2340 kFALSE, // check if this is right
2341 AliAODTrack::kOrphan);
2342 aodTrack->ConvertAliPIDtoAODPID();
2344 } // end of loop on tracks
2347 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
2348 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
2350 AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);
2351 p[0] = esdMuTrack->Px();
2352 p[1] = esdMuTrack->Py();
2353 p[2] = esdMuTrack->Pz();
2354 pos[0] = primary->GetX();
2355 pos[1] = primary->GetY();
2356 pos[2] = primary->GetZ();
2358 // has to be changed once the muon pid is provided by the ESD
2359 for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
2361 primary->AddDaughter(
2362 new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
2363 0, // no label provided
2368 NULL, // no covariance matrix provided
2369 (Short_t)-99, // no charge provided
2370 0, // no ITSClusterMap
2373 kFALSE, // muon tracks are not used to fit the primary vtx
2374 kFALSE, // not used for vertex fit
2375 AliAODTrack::kPrimary)
2379 // Access to the AOD container of clusters
2380 TClonesArray &clusters = *(aod->GetClusters());
2384 Int_t nClusters = esd->GetNumberOfCaloClusters();
2386 for (Int_t iClust=0; iClust<nClusters; ++iClust) {
2388 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
2390 Int_t id = cluster->GetID();
2392 Float_t energy = cluster->E();
2393 cluster->GetPosition(posF);
2394 AliAODVertex *prodVertex = primary;
2395 AliAODTrack *primTrack = NULL;
2396 Char_t ttype=AliAODCluster::kUndef;
2398 if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral;
2399 else if (cluster->IsEMCAL()) {
2401 if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster)
2402 ttype = AliAODCluster::kEMCALPseudoCluster;
2404 ttype = AliAODCluster::kEMCALClusterv1;
2408 new(clusters[jClusters++]) AliAODCluster(id,
2412 NULL, // no covariance matrix provided
2413 NULL, // no pid for clusters provided
2418 } // end of loop on calo clusters
2420 delete [] usedTrack;
2424 // fill the tree for this event
2426 } // end of event loop
2428 aodTree->GetUserInfo()->Add(aod);
2433 // write the tree to the specified file
2434 aodFile = aodTree->GetCurrentFile();
2441 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2443 // Write space-points which are then used in the alignment procedures
2444 // For the moment only ITS, TRD and TPC
2446 // Load TOF clusters
2448 fLoader[3]->LoadRecPoints("read");
2449 TTree* tree = fLoader[3]->TreeR();
2451 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2454 fTracker[3]->LoadClusters(tree);
2456 Int_t ntracks = esd->GetNumberOfTracks();
2457 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2459 AliESDtrack *track = esd->GetTrack(itrack);
2462 for (Int_t iDet = 3; iDet >= 0; iDet--)
2463 nsp += track->GetNcls(iDet);
2465 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2466 track->SetTrackPointArray(sp);
2468 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2469 AliTracker *tracker = fTracker[iDet];
2470 if (!tracker) continue;
2471 Int_t nspdet = track->GetNcls(iDet);
2472 if (nspdet <= 0) continue;
2473 track->GetClusters(iDet,idx);
2477 while (isp < nspdet) {
2478 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
2479 const Int_t kNTPCmax = 159;
2480 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2481 if (!isvalid) continue;
2482 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2488 fTracker[3]->UnloadClusters();
2489 fLoader[3]->UnloadRecPoints();
2493 //_____________________________________________________________________________
2494 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2496 // The method reads the raw-data error log
2497 // accumulated within the rawReader.
2498 // It extracts the raw-data errors related to
2499 // the current event and stores them into
2500 // a TClonesArray inside the esd object.
2502 if (!fRawReader) return;
2504 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2506 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2508 if (iEvent != log->GetEventNumber()) continue;
2510 esd->AddRawDataErrorLog(log);
2515 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2516 // Dump a file content into a char in TNamed
2518 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2519 Int_t kBytes = (Int_t)in.tellg();
2520 printf("Size: %d \n",kBytes);
2523 char* memblock = new char [kBytes];
2524 in.seekg (0, ios::beg);
2525 in.read (memblock, kBytes);
2527 TString fData(memblock,kBytes);
2528 fn = new TNamed(fName,fData);
2529 printf("fData Size: %d \n",fData.Sizeof());
2530 printf("fName Size: %d \n",fName.Sizeof());
2531 printf("fn Size: %d \n",fn->Sizeof());
2535 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2541 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2542 // This is not really needed in AliReconstruction at the moment
2543 // but can serve as a template
2545 TList *fList = fTree->GetUserInfo();
2546 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2547 printf("fn Size: %d \n",fn->Sizeof());
2549 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2550 const char* cdata = fn->GetTitle();
2551 printf("fTmp Size %d\n",fTmp.Sizeof());
2553 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2554 printf("calculated size %d\n",size);
2555 ofstream out(fName.Data(),ios::out | ios::binary);
2556 out.write(cdata,size);