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"
156 #include "AliAODTagCreator.h"
158 #include "AliGeomManager.h"
159 #include "AliTrackPointArray.h"
160 #include "AliCDBManager.h"
161 #include "AliCDBEntry.h"
162 #include "AliAlignObj.h"
164 #include "AliCentralTrigger.h"
165 #include "AliCTPRawStream.h"
167 #include "AliAODEvent.h"
168 #include "AliAODHeader.h"
169 #include "AliAODTrack.h"
170 #include "AliAODVertex.h"
171 #include "AliAODCluster.h"
173 #include "AliQualAssDataMaker.h"
175 ClassImp(AliReconstruction)
178 //_____________________________________________________________________________
179 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
181 //_____________________________________________________________________________
182 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
183 const char* name, const char* title) :
186 fUniformField(kTRUE),
187 fRunVertexFinder(kTRUE),
188 fRunHLTTracking(kFALSE),
189 fRunMuonTracking(kFALSE),
191 fRunCascadeFinder(kTRUE),
192 fStopOnError(kFALSE),
193 fWriteAlignmentData(kFALSE),
195 fWriteESDfriend(kFALSE),
197 fFillTriggerESD(kTRUE),
199 fRunLocalReconstruction("ALL"),
202 fGAliceFileName(gAliceFilename),
207 fNumberOfEventsPerFile(1),
210 fLoadAlignFromCDB(kTRUE),
211 fLoadAlignData("ALL"),
218 fDiamondProfile(NULL),
220 fAlignObjArray(NULL),
225 // create reconstruction object with default parameters
227 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
228 fReconstructor[iDet] = NULL;
229 fLoader[iDet] = NULL;
230 fTracker[iDet] = NULL;
231 fQualAssDataMaker[iDet] = NULL;
236 //_____________________________________________________________________________
237 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
240 fUniformField(rec.fUniformField),
241 fRunVertexFinder(rec.fRunVertexFinder),
242 fRunHLTTracking(rec.fRunHLTTracking),
243 fRunMuonTracking(rec.fRunMuonTracking),
244 fRunV0Finder(rec.fRunV0Finder),
245 fRunCascadeFinder(rec.fRunCascadeFinder),
246 fStopOnError(rec.fStopOnError),
247 fWriteAlignmentData(rec.fWriteAlignmentData),
248 fCleanESD(rec.fCleanESD),
249 fWriteESDfriend(rec.fWriteESDfriend),
250 fWriteAOD(rec.fWriteAOD),
251 fFillTriggerESD(rec.fFillTriggerESD),
253 fRunLocalReconstruction(rec.fRunLocalReconstruction),
254 fRunTracking(rec.fRunTracking),
255 fFillESD(rec.fFillESD),
256 fGAliceFileName(rec.fGAliceFileName),
258 fEquipIdMap(rec.fEquipIdMap),
259 fFirstEvent(rec.fFirstEvent),
260 fLastEvent(rec.fLastEvent),
261 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
264 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
265 fLoadAlignData(rec.fLoadAlignData),
266 fESDPar(rec.fESDPar),
272 fDiamondProfile(NULL),
274 fAlignObjArray(rec.fAlignObjArray),
275 fCDBUri(rec.fCDBUri),
276 fRemoteCDBUri(rec.fRemoteCDBUri),
281 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
282 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
284 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
285 fReconstructor[iDet] = NULL;
286 fLoader[iDet] = NULL;
287 fTracker[iDet] = NULL;
288 fQualAssDataMaker[iDet] = NULL;
290 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
291 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
295 //_____________________________________________________________________________
296 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
298 // assignment operator
300 this->~AliReconstruction();
301 new(this) AliReconstruction(rec);
305 //_____________________________________________________________________________
306 AliReconstruction::~AliReconstruction()
312 fSpecCDBUri.Delete();
314 AliCodeTimer::Instance()->Print();
317 //_____________________________________________________________________________
318 void AliReconstruction::InitCDBStorage()
320 // activate a default CDB storage
321 // First check if we have any CDB storage set, because it is used
322 // to retrieve the calibration and alignment constants
324 AliCDBManager* man = AliCDBManager::Instance();
325 if (man->IsDefaultStorageSet())
327 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
328 AliWarning("Default CDB storage has been already set !");
329 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
330 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
334 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
335 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
336 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
337 man->SetDefaultStorage(fCDBUri);
340 // Remote storage (the Grid storage) is used if it is activated
341 // and if the object is not found in the default storage
342 if (man->IsRemoteStorageSet())
344 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
345 AliWarning("Remote CDB storage has been already set !");
346 AliWarning(Form("Ignoring the remote storage declared in AliReconstruction: %s",fRemoteCDBUri.Data()));
347 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
351 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
352 AliDebug(2, Form("Remote CDB storage is set to: %s",fRemoteCDBUri.Data()));
353 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
354 man->SetRemoteStorage(fRemoteCDBUri);
357 // Now activate the detector specific CDB storage locations
358 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
359 TObject* obj = fSpecCDBUri[i];
361 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
362 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
363 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
364 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
369 //_____________________________________________________________________________
370 void AliReconstruction::SetDefaultStorage(const char* uri) {
371 // Store the desired default CDB storage location
372 // Activate it later within the Run() method
378 //_____________________________________________________________________________
379 void AliReconstruction::SetRemoteStorage(const char* uri) {
380 // Store the desired remote CDB storage location
381 // Activate it later within the Run() method
382 // Remote storage (the Grid storage) is used if it is activated
383 // and if the object is not found in the default storage
389 //_____________________________________________________________________________
390 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
391 // Store a detector-specific CDB storage location
392 // Activate it later within the Run() method
394 AliCDBPath aPath(calibType);
395 if(!aPath.IsValid()){
396 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
397 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
398 if(!strcmp(calibType, fgkDetectorName[iDet])) {
399 aPath.SetPath(Form("%s/*", calibType));
400 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
404 if(!aPath.IsValid()){
405 AliError(Form("Not a valid path or detector: %s", calibType));
410 // // check that calibType refers to a "valid" detector name
411 // Bool_t isDetector = kFALSE;
412 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
413 // TString detName = fgkDetectorName[iDet];
414 // if(aPath.GetLevel0() == detName) {
415 // isDetector = kTRUE;
421 // AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
425 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
426 if (obj) fSpecCDBUri.Remove(obj);
427 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
434 //_____________________________________________________________________________
435 Bool_t AliReconstruction::SetRunNumber()
437 // The method is called in Run() in order
438 // to set a correct run number.
439 // In case of raw data reconstruction the
440 // run number is taken from the raw data header
442 if(AliCDBManager::Instance()->GetRun() < 0) {
444 AliError("No run loader is found !");
447 // read run number from gAlice
448 if(fRunLoader->GetAliRun())
449 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
452 if(fRawReader->NextEvent()) {
453 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
454 fRawReader->RewindEvents();
457 AliError("No raw-data events found !");
462 AliError("Neither gAlice nor RawReader objects are found !");
466 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
471 //_____________________________________________________________________________
472 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
474 // Read the alignment objects from CDB.
475 // Each detector is supposed to have the
476 // alignment objects in DET/Align/Data CDB path.
477 // All the detector objects are then collected,
478 // sorted by geometry level (starting from ALIC) and
479 // then applied to the TGeo geometry.
480 // Finally an overlaps check is performed.
482 // Load alignment data from CDB and fill fAlignObjArray
483 if(fLoadAlignFromCDB){
485 TString detStr = detectors;
486 TString loadAlObjsListOfDets = "";
488 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
489 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
490 loadAlObjsListOfDets += fgkDetectorName[iDet];
491 loadAlObjsListOfDets += " ";
492 } // end loop over detectors
493 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
494 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
496 // Check if the array with alignment objects was
497 // provided by the user. If yes, apply the objects
498 // to the present TGeo geometry
499 if (fAlignObjArray) {
500 if (gGeoManager && gGeoManager->IsClosed()) {
501 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
502 AliError("The misalignment of one or more volumes failed!"
503 "Compare the list of simulated detectors and the list of detector alignment data!");
508 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
514 delete fAlignObjArray; fAlignObjArray=0;
519 //_____________________________________________________________________________
520 void AliReconstruction::SetGAliceFile(const char* fileName)
522 // set the name of the galice file
524 fGAliceFileName = fileName;
527 //_____________________________________________________________________________
528 void AliReconstruction::SetOption(const char* detector, const char* option)
530 // set options for the reconstruction of a detector
532 TObject* obj = fOptions.FindObject(detector);
533 if (obj) fOptions.Remove(obj);
534 fOptions.Add(new TNamed(detector, option));
538 //_____________________________________________________________________________
539 Bool_t AliReconstruction::Run(const char* input)
541 // run the reconstruction
546 if (!input) input = fInput.Data();
547 TString fileName(input);
548 if (fileName.EndsWith("/")) {
549 fRawReader = new AliRawReaderFile(fileName);
550 } else if (fileName.EndsWith(".root")) {
551 fRawReader = new AliRawReaderRoot(fileName);
552 } else if (!fileName.IsNull()) {
553 fRawReader = new AliRawReaderDate(fileName);
554 fRawReader->SelectEvents(7);
556 if (!fEquipIdMap.IsNull() && fRawReader)
557 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
560 // get the run loader
561 if (!InitRunLoader()) return kFALSE;
563 // Initialize the CDB storage
566 // Set run number in CDBManager (if it is not already set by the user)
567 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
569 // Import ideal TGeo geometry and apply misalignment
571 TString geom(gSystem->DirName(fGAliceFileName));
572 geom += "/geometry.root";
573 AliGeomManager::LoadGeometry(geom.Data());
574 if (!gGeoManager) if (fStopOnError) return kFALSE;
577 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
579 // local reconstruction
580 if (!fRunLocalReconstruction.IsNull()) {
581 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
582 if (fStopOnError) {CleanUp(); return kFALSE;}
585 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
586 // fFillESD.IsNull()) return kTRUE;
589 if (fRunVertexFinder && !CreateVertexer()) {
597 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
604 // get the possibly already existing ESD file and tree
605 AliESDEvent* esd = new AliESDEvent(); AliESDEvent* hltesd = new AliESDEvent();
606 TFile* fileOld = NULL;
607 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
608 if (!gSystem->AccessPathName("AliESDs.root")){
609 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
610 fileOld = TFile::Open("AliESDs.old.root");
611 if (fileOld && fileOld->IsOpen()) {
612 treeOld = (TTree*) fileOld->Get("esdTree");
613 if (treeOld)esd->ReadFromTree(treeOld);
614 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
615 if (hlttreeOld) hltesd->ReadFromTree(hlttreeOld);
619 // create the ESD output file and tree
620 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
621 file->SetCompressionLevel(2);
622 if (!file->IsOpen()) {
623 AliError("opening AliESDs.root failed");
624 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
627 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
628 esd = new AliESDEvent();
629 esd->CreateStdContent();
630 esd->WriteToTree(tree);
632 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
633 hltesd = new AliESDEvent();
634 hltesd->CreateStdContent();
635 hltesd->WriteToTree(hlttree);
638 delete esd; delete hltesd;
639 esd = NULL; hltesd = NULL;
641 // create the branch with ESD additions
645 AliESDfriend *esdf = 0;
646 if (fWriteESDfriend) {
647 esdf = new AliESDfriend();
648 TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
649 br->SetFile("AliESDfriends.root");
650 esd->AddObject(esdf);
654 // Get the diamond profile from OCDB
655 AliCDBEntry* entry = AliCDBManager::Instance()
656 ->Get("GRP/Calib/MeanVertex");
659 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
661 AliError("No diamond profile found in OCDB!");
664 AliVertexerTracks tVertexer(AliTracker::GetBz());
665 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
669 if (fRawReader) fRawReader->RewindEvents();
670 TString detStr(fFillESD) ;
673 gSystem->GetProcInfo(&ProcInfo);
674 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
675 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
676 if (fRawReader) fRawReader->NextEvent();
677 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
678 // copy old ESD to the new one
680 esd->ReadFromTree(treeOld);
681 treeOld->GetEntry(iEvent);
685 esd->ReadFromTree(hlttreeOld);
686 hlttreeOld->GetEntry(iEvent);
692 AliInfo(Form("processing event %d", iEvent));
693 fRunLoader->GetEvent(iEvent);
696 sprintf(aFileName, "ESD_%d.%d_final.root",
697 fRunLoader->GetHeader()->GetRun(),
698 fRunLoader->GetHeader()->GetEventNrInRun());
699 if (!gSystem->AccessPathName(aFileName)) continue;
701 // local reconstruction
702 if (!fRunLocalReconstruction.IsNull()) {
703 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
704 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
709 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
710 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
711 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
712 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
714 // Set magnetic field from the tracker
715 esd->SetMagneticField(AliTracker::GetBz());
716 hltesd->SetMagneticField(AliTracker::GetBz());
720 // Fill raw-data error log into the ESD
721 if (fRawReader) FillRawDataErrorLog(iEvent,esd);
724 if (fRunVertexFinder) {
725 if (!ReadESD(esd, "vertex")) {
726 if (!RunVertexFinder(esd)) {
727 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
729 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
734 if (!fRunTracking.IsNull()) {
735 if (fRunHLTTracking) {
736 hltesd->SetVertex(esd->GetVertex());
737 if (!RunHLTTracking(hltesd)) {
738 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
744 if (!fRunTracking.IsNull()) {
745 if (fRunMuonTracking) {
746 if (!RunMuonTracking(esd)) {
747 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
753 if (!fRunTracking.IsNull()) {
754 if (!ReadESD(esd, "tracking")) {
755 if (!RunTracking(esd)) {
756 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
758 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
763 if (!fFillESD.IsNull()) {
764 if (!FillESD(esd, fFillESD)) {
765 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
769 if (!fFillESD.IsNull())
770 RunQualAss(fFillESD.Data(), esd);
772 // fill Event header information from the RawEventHeader
773 if (fRawReader){FillRawEventHeaderESD(esd);}
776 AliESDpid::MakePID(esd);
777 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
779 if (fFillTriggerESD) {
780 if (!ReadESD(esd, "trigger")) {
781 if (!FillTriggerESD(esd)) {
782 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
784 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
788 //Try to improve the reconstructed primary vertex position using the tracks
789 AliESDVertex *pvtx=0;
790 Bool_t dovertex=kTRUE;
791 TObject* obj = fOptions.FindObject("ITS");
793 TString optITS = obj->GetTitle();
794 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
797 if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
798 if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
801 if (pvtx->GetStatus()) {
802 // Store the improved primary vertex
803 esd->SetPrimaryVertex(pvtx);
804 // Propagate the tracks to the DCA to the improved primary vertex
805 Double_t somethingbig = 777.;
806 Double_t bz = esd->GetMagneticField();
807 Int_t nt=esd->GetNumberOfTracks();
809 AliESDtrack *t = esd->GetTrack(nt);
810 t->RelateToVertex(pvtx, bz, somethingbig);
817 vtxer.Tracks2V0vertices(esd);
819 if (fRunCascadeFinder) {
821 AliCascadeVertexer cvtxer;
822 cvtxer.V0sTracks2CascadeVertices(esd);
827 if (fCleanESD) CleanESD(esd);
828 if (fWriteESDfriend) {
829 esdf->~AliESDfriend();
830 new (esdf) AliESDfriend(); // Reset...
831 esd->GetESDfriend(esdf);
838 if (fCheckPointLevel > 0) WriteESD(esd, "final");
841 if (fWriteESDfriend) {
842 esdf->~AliESDfriend();
843 new (esdf) AliESDfriend(); // Reset...
846 // delete esdf; esdf = 0;
849 gSystem->GetProcInfo(&ProcInfo);
850 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
854 // write quality assurance ESDs data (one entry for all events)
855 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
856 if (!IsSelected(fgkDetectorName[iDet], detStr))
858 AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
860 qadm->Finish(AliQualAss::kRECPOINTS);
861 qadm->Finish(AliQualAss::kESDS) ;
864 tree->GetUserInfo()->Add(esd);
865 hlttree->GetUserInfo()->Add(hltesd);
869 if(fESDPar.Contains("ESD.par")){
870 AliInfo("Attaching ESD.par to Tree");
871 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
872 tree->GetUserInfo()->Add(fn);
878 tree->SetBranchStatus("ESDfriend*",0);
883 TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE");
884 ESDFile2AODFile(file, aodFile);
889 CleanUp(file, fileOld);
891 // Create tags for the events in the ESD tree (the ESD tree is always present)
892 // In case of empty events the tags will contain dummy values
893 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
894 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent);
896 AliAODTagCreator *aodtagCreator = new AliAODTagCreator();
897 aodtagCreator->CreateAODTags(fFirstEvent,fLastEvent);
904 //_____________________________________________________________________________
905 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
907 // run the local reconstruction
911 // AliCDBManager* man = AliCDBManager::Instance();
912 // Bool_t origCache = man->GetCacheFlag();
914 // TString detStr = detectors;
915 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
916 // if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
917 // AliReconstructor* reconstructor = GetReconstructor(iDet);
918 // if (!reconstructor) continue;
919 // if (reconstructor->HasLocalReconstruction()) continue;
921 // AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
922 // AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
924 // AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
925 // AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
927 // man->SetCacheFlag(kTRUE);
928 // TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
929 // man->GetAll(calibPath); // entries are cached!
931 // AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
934 // fRawReader->RewindEvents();
935 // reconstructor->Reconstruct(fRunLoader, fRawReader);
937 // reconstructor->Reconstruct(fRunLoader);
940 // AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
942 // // unload calibration data
943 // man->UnloadFromCache(calibPath);
944 // //man->ClearCache();
947 // man->SetCacheFlag(origCache);
949 // if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
950 // AliError(Form("the following detectors were not found: %s",
952 // if (fStopOnError) return kFALSE;
958 //_____________________________________________________________________________
959 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
961 // run the local reconstruction
965 TString detStr = detectors;
966 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
967 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
968 AliReconstructor* reconstructor = GetReconstructor(iDet);
969 if (!reconstructor) continue;
970 AliLoader* loader = fLoader[iDet];
972 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
976 // conversion of digits
977 if (fRawReader && reconstructor->HasDigitConversion()) {
978 AliInfo(Form("converting raw data digits into root objects for %s",
979 fgkDetectorName[iDet]));
980 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
981 fgkDetectorName[iDet]));
982 loader->LoadDigits("update");
983 loader->CleanDigits();
984 loader->MakeDigitsContainer();
985 TTree* digitsTree = loader->TreeD();
986 reconstructor->ConvertDigits(fRawReader, digitsTree);
987 loader->WriteDigits("OVERWRITE");
988 loader->UnloadDigits();
991 // local reconstruction
992 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
993 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
994 loader->LoadRecPoints("update");
995 loader->CleanRecPoints();
996 loader->MakeRecPointsContainer();
997 TTree* clustersTree = loader->TreeR();
998 if (fRawReader && !reconstructor->HasDigitConversion()) {
999 reconstructor->Reconstruct(fRawReader, clustersTree);
1001 loader->LoadDigits("read");
1002 TTree* digitsTree = loader->TreeD();
1004 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1005 if (fStopOnError) return kFALSE;
1007 reconstructor->Reconstruct(digitsTree, clustersTree);
1009 loader->UnloadDigits();
1012 AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
1014 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1015 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1016 qadm->Exec(AliQualAss::kRECPOINTS, clustersTree) ;
1017 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1020 loader->WriteRecPoints("OVERWRITE");
1021 loader->UnloadRecPoints();
1024 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1025 AliError(Form("the following detectors were not found: %s",
1027 if (fStopOnError) return kFALSE;
1033 //_____________________________________________________________________________
1034 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
1036 // run the barrel tracking
1038 AliCodeTimerAuto("")
1040 AliESDVertex* vertex = NULL;
1041 Double_t vtxPos[3] = {0, 0, 0};
1042 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1043 TArrayF mcVertex(3);
1044 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1045 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1046 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1050 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1051 AliInfo("running the ITS vertex finder");
1052 if (fLoader[0]) fLoader[0]->LoadRecPoints();
1053 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
1054 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
1056 AliWarning("Vertex not found");
1057 vertex = new AliESDVertex();
1058 vertex->SetName("default");
1061 vertex->SetName("reconstructed");
1065 AliInfo("getting the primary vertex from MC");
1066 vertex = new AliESDVertex(vtxPos, vtxErr);
1070 vertex->GetXYZ(vtxPos);
1071 vertex->GetSigmaXYZ(vtxErr);
1073 AliWarning("no vertex reconstructed");
1074 vertex = new AliESDVertex(vtxPos, vtxErr);
1076 esd->SetVertex(vertex);
1077 // if SPD multiplicity has been determined, it is stored in the ESD
1078 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1079 if(mult)esd->SetMultiplicity(mult);
1081 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1082 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1089 //_____________________________________________________________________________
1090 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1092 // run the HLT barrel tracking
1094 AliCodeTimerAuto("")
1097 AliError("Missing runLoader!");
1101 AliInfo("running HLT tracking");
1103 // Get a pointer to the HLT reconstructor
1104 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1105 if (!reconstructor) return kFALSE;
1108 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1109 TString detName = fgkDetectorName[iDet];
1110 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1111 reconstructor->SetOption(detName.Data());
1112 AliTracker *tracker = reconstructor->CreateTracker();
1114 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1115 if (fStopOnError) return kFALSE;
1119 Double_t vtxErr[3]={0.005,0.005,0.010};
1120 const AliESDVertex *vertex = esd->GetVertex();
1121 vertex->GetXYZ(vtxPos);
1122 tracker->SetVertex(vtxPos,vtxErr);
1124 fLoader[iDet]->LoadRecPoints("read");
1125 TTree* tree = fLoader[iDet]->TreeR();
1127 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1130 tracker->LoadClusters(tree);
1132 if (tracker->Clusters2Tracks(esd) != 0) {
1133 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1137 tracker->UnloadClusters();
1145 //_____________________________________________________________________________
1146 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1148 // run the muon spectrometer tracking
1150 AliCodeTimerAuto("")
1153 AliError("Missing runLoader!");
1156 Int_t iDet = 7; // for MUON
1158 AliInfo("is running...");
1160 // Get a pointer to the MUON reconstructor
1161 AliReconstructor *reconstructor = GetReconstructor(iDet);
1162 if (!reconstructor) return kFALSE;
1165 TString detName = fgkDetectorName[iDet];
1166 AliDebug(1, Form("%s tracking", detName.Data()));
1167 AliTracker *tracker = reconstructor->CreateTracker();
1169 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1174 fLoader[iDet]->LoadTracks("update");
1175 fLoader[iDet]->CleanTracks();
1176 fLoader[iDet]->MakeTracksContainer();
1179 fLoader[iDet]->LoadRecPoints("read");
1180 tracker->LoadClusters(fLoader[iDet]->TreeR());
1182 Int_t rv = tracker->Clusters2Tracks(esd);
1184 fLoader[iDet]->UnloadRecPoints();
1188 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1192 tracker->UnloadClusters();
1194 fLoader[iDet]->UnloadRecPoints();
1196 fLoader[iDet]->WriteTracks("OVERWRITE");
1197 fLoader[iDet]->UnloadTracks();
1205 //_____________________________________________________________________________
1206 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1208 // run the barrel tracking
1210 AliCodeTimerAuto("")
1212 AliInfo("running tracking");
1214 //Fill the ESD with the T0 info (will be used by the TOF)
1215 if (fReconstructor[11] && fLoader[11]) {
1216 fLoader[11]->LoadRecPoints("READ");
1217 TTree *treeR = fLoader[11]->TreeR();
1218 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1221 // pass 1: TPC + ITS inwards
1222 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1223 if (!fTracker[iDet]) continue;
1224 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1227 fLoader[iDet]->LoadRecPoints("read");
1228 TTree* tree = fLoader[iDet]->TreeR();
1230 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1233 fTracker[iDet]->LoadClusters(tree);
1236 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1237 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1240 if (fCheckPointLevel > 1) {
1241 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1243 // preliminary PID in TPC needed by the ITS tracker
1245 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1246 AliESDpid::MakePID(esd);
1250 // pass 2: ALL backwards
1251 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1252 if (!fTracker[iDet]) continue;
1253 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1256 if (iDet > 1) { // all except ITS, TPC
1258 fLoader[iDet]->LoadRecPoints("read");
1259 tree = fLoader[iDet]->TreeR();
1261 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1264 fTracker[iDet]->LoadClusters(tree);
1268 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1269 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1272 if (fCheckPointLevel > 1) {
1273 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1277 if (iDet > 2) { // all except ITS, TPC, TRD
1278 fTracker[iDet]->UnloadClusters();
1279 fLoader[iDet]->UnloadRecPoints();
1281 // updated PID in TPC needed by the ITS tracker -MI
1283 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1284 AliESDpid::MakePID(esd);
1288 // write space-points to the ESD in case alignment data output
1290 if (fWriteAlignmentData)
1291 WriteAlignmentData(esd);
1293 // pass 3: TRD + TPC + ITS refit inwards
1294 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1295 if (!fTracker[iDet]) continue;
1296 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1299 if (fTracker[iDet]->RefitInward(esd) != 0) {
1300 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1303 if (fCheckPointLevel > 1) {
1304 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1308 fTracker[iDet]->UnloadClusters();
1309 fLoader[iDet]->UnloadRecPoints();
1312 // Propagate track to the vertex - if not done by ITS
1314 Int_t ntracks = esd->GetNumberOfTracks();
1315 for (Int_t itrack=0; itrack<ntracks; itrack++){
1316 const Double_t kRadius = 3; // beam pipe radius
1317 const Double_t kMaxStep = 5; // max step
1318 const Double_t kMaxD = 123456; // max distance to prim vertex
1319 Double_t fieldZ = AliTracker::GetBz(); //
1320 AliESDtrack * track = esd->GetTrack(itrack);
1321 if (!track) continue;
1322 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1323 AliTracker::PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1324 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1330 //_____________________________________________________________________________
1331 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1333 // Remove the data which are not needed for the physics analysis.
1336 AliInfo("Cleaning the ESD...");
1338 const AliESDVertex *vertex=esd->GetVertex();
1339 Double_t vz=vertex->GetZv();
1341 Int_t nTracks=esd->GetNumberOfTracks();
1342 for (Int_t i=0; i<nTracks; i++) {
1343 AliESDtrack *track=esd->GetTrack(i);
1345 Float_t xy,z; track->GetImpactParameters(xy,z);
1346 if (TMath::Abs(xy) < 50.) continue;
1347 if (vertex->GetStatus())
1348 if (TMath::Abs(vz-z) < 5.) continue;
1350 esd->RemoveTrack(i);
1356 //_____________________________________________________________________________
1357 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1359 // fill the event summary data
1361 AliCodeTimerAuto("")
1363 TString detStr = detectors;
1364 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1365 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1366 AliReconstructor* reconstructor = GetReconstructor(iDet);
1367 if (!reconstructor) continue;
1369 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1370 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1371 TTree* clustersTree = NULL;
1372 if (fLoader[iDet]) {
1373 fLoader[iDet]->LoadRecPoints("read");
1374 clustersTree = fLoader[iDet]->TreeR();
1375 if (!clustersTree) {
1376 AliError(Form("Can't get the %s clusters tree",
1377 fgkDetectorName[iDet]));
1378 if (fStopOnError) return kFALSE;
1381 if (fRawReader && !reconstructor->HasDigitConversion()) {
1382 reconstructor->FillESD(fRawReader, clustersTree, esd);
1384 TTree* digitsTree = NULL;
1385 if (fLoader[iDet]) {
1386 fLoader[iDet]->LoadDigits("read");
1387 digitsTree = fLoader[iDet]->TreeD();
1389 AliError(Form("Can't get the %s digits tree",
1390 fgkDetectorName[iDet]));
1391 if (fStopOnError) return kFALSE;
1394 reconstructor->FillESD(digitsTree, clustersTree, esd);
1395 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1397 if (fLoader[iDet]) {
1398 fLoader[iDet]->UnloadRecPoints();
1401 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1405 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1406 AliError(Form("the following detectors were not found: %s",
1408 if (fStopOnError) return kFALSE;
1414 //_____________________________________________________________________________
1415 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1417 // Reads the trigger decision which is
1418 // stored in Trigger.root file and fills
1419 // the corresponding esd entries
1421 AliCodeTimerAuto("")
1423 AliInfo("Filling trigger information into the ESD");
1426 AliCTPRawStream input(fRawReader);
1427 if (!input.Next()) {
1428 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1431 esd->SetTriggerMask(input.GetClassMask());
1432 esd->SetTriggerCluster(input.GetClusterMask());
1435 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1437 if (!runloader->LoadTrigger()) {
1438 AliCentralTrigger *aCTP = runloader->GetTrigger();
1439 esd->SetTriggerMask(aCTP->GetClassMask());
1440 esd->SetTriggerCluster(aCTP->GetClusterMask());
1443 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1448 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1460 //_____________________________________________________________________________
1461 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1464 // Filling information from RawReader Header
1467 AliInfo("Filling information from RawReader Header");
1468 esd->SetBunchCrossNumber(0);
1469 esd->SetOrbitNumber(0);
1470 esd->SetPeriodNumber(0);
1471 esd->SetTimeStamp(0);
1472 esd->SetEventType(0);
1473 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1476 const UInt_t *id = eventHeader->GetP("Id");
1477 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1478 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1479 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1481 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1482 esd->SetEventType((eventHeader->Get("Type")));
1489 //_____________________________________________________________________________
1490 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1492 // check whether detName is contained in detectors
1493 // if yes, it is removed from detectors
1495 // check if all detectors are selected
1496 if ((detectors.CompareTo("ALL") == 0) ||
1497 detectors.BeginsWith("ALL ") ||
1498 detectors.EndsWith(" ALL") ||
1499 detectors.Contains(" ALL ")) {
1504 // search for the given detector
1505 Bool_t result = kFALSE;
1506 if ((detectors.CompareTo(detName) == 0) ||
1507 detectors.BeginsWith(detName+" ") ||
1508 detectors.EndsWith(" "+detName) ||
1509 detectors.Contains(" "+detName+" ")) {
1510 detectors.ReplaceAll(detName, "");
1514 // clean up the detectors string
1515 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1516 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1517 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1522 //_____________________________________________________________________________
1523 Bool_t AliReconstruction::InitRunLoader()
1525 // get or create the run loader
1527 if (gAlice) delete gAlice;
1530 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1531 // load all base libraries to get the loader classes
1532 TString libs = gSystem->GetLibraries();
1533 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1534 TString detName = fgkDetectorName[iDet];
1535 if (detName == "HLT") continue;
1536 if (libs.Contains("lib" + detName + "base.so")) continue;
1537 gSystem->Load("lib" + detName + "base.so");
1539 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1541 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1545 fRunLoader->CdGAFile();
1546 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1547 if (fRunLoader->LoadgAlice() == 0) {
1548 gAlice = fRunLoader->GetAliRun();
1549 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1552 if (!gAlice && !fRawReader) {
1553 AliError(Form("no gAlice object found in file %s",
1554 fGAliceFileName.Data()));
1559 //PH This is a temporary fix to give access to the kinematics
1560 //PH that is needed for the labels of ITS clusters
1561 fRunLoader->LoadKinematics();
1563 } else { // galice.root does not exist
1565 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1569 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1570 AliConfig::GetDefaultEventFolderName(),
1573 AliError(Form("could not create run loader in file %s",
1574 fGAliceFileName.Data()));
1578 fRunLoader->MakeTree("E");
1580 while (fRawReader->NextEvent()) {
1581 fRunLoader->SetEventNumber(iEvent);
1582 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1584 fRunLoader->MakeTree("H");
1585 fRunLoader->TreeE()->Fill();
1588 fRawReader->RewindEvents();
1589 if (fNumberOfEventsPerFile > 0)
1590 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1592 fRunLoader->SetNumberOfEventsPerFile(iEvent);
1593 fRunLoader->WriteHeader("OVERWRITE");
1594 fRunLoader->CdGAFile();
1595 fRunLoader->Write(0, TObject::kOverwrite);
1596 // AliTracker::SetFieldMap(???);
1602 //_____________________________________________________________________________
1603 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1605 // get the reconstructor object and the loader for a detector
1607 if (fReconstructor[iDet]) return fReconstructor[iDet];
1609 // load the reconstructor object
1610 TPluginManager* pluginManager = gROOT->GetPluginManager();
1611 TString detName = fgkDetectorName[iDet];
1612 TString recName = "Ali" + detName + "Reconstructor";
1613 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1615 if (detName == "HLT") {
1616 if (!gROOT->GetClass("AliLevel3")) {
1617 gSystem->Load("libAliHLTSrc.so");
1618 gSystem->Load("libAliHLTMisc.so");
1619 gSystem->Load("libAliHLTHough.so");
1620 gSystem->Load("libAliHLTComp.so");
1624 AliReconstructor* reconstructor = NULL;
1625 // first check if a plugin is defined for the reconstructor
1626 TPluginHandler* pluginHandler =
1627 pluginManager->FindHandler("AliReconstructor", detName);
1628 // if not, add a plugin for it
1629 if (!pluginHandler) {
1630 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1631 TString libs = gSystem->GetLibraries();
1632 if (libs.Contains("lib" + detName + "base.so") ||
1633 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1634 pluginManager->AddHandler("AliReconstructor", detName,
1635 recName, detName + "rec", recName + "()");
1637 pluginManager->AddHandler("AliReconstructor", detName,
1638 recName, detName, recName + "()");
1640 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1642 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1643 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1645 if (reconstructor) {
1646 TObject* obj = fOptions.FindObject(detName.Data());
1647 if (obj) reconstructor->SetOption(obj->GetTitle());
1648 reconstructor->Init();
1649 fReconstructor[iDet] = reconstructor;
1652 // get or create the loader
1653 if (detName != "HLT") {
1654 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1655 if (!fLoader[iDet]) {
1656 AliConfig::Instance()
1657 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1659 // first check if a plugin is defined for the loader
1661 pluginManager->FindHandler("AliLoader", detName);
1662 // if not, add a plugin for it
1663 if (!pluginHandler) {
1664 TString loaderName = "Ali" + detName + "Loader";
1665 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1666 pluginManager->AddHandler("AliLoader", detName,
1667 loaderName, detName + "base",
1668 loaderName + "(const char*, TFolder*)");
1669 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1671 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1673 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1674 fRunLoader->GetEventFolder());
1676 if (!fLoader[iDet]) { // use default loader
1677 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1679 if (!fLoader[iDet]) {
1680 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1681 if (fStopOnError) return NULL;
1683 fRunLoader->AddLoader(fLoader[iDet]);
1684 fRunLoader->CdGAFile();
1685 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1686 fRunLoader->Write(0, TObject::kOverwrite);
1691 return reconstructor;
1694 //_____________________________________________________________________________
1695 Bool_t AliReconstruction::CreateVertexer()
1697 // create the vertexer
1700 AliReconstructor* itsReconstructor = GetReconstructor(0);
1701 if (itsReconstructor) {
1702 fVertexer = itsReconstructor->CreateVertexer();
1705 AliWarning("couldn't create a vertexer for ITS");
1706 if (fStopOnError) return kFALSE;
1712 //_____________________________________________________________________________
1713 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1715 // create the trackers
1717 TString detStr = detectors;
1718 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1719 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1720 AliReconstructor* reconstructor = GetReconstructor(iDet);
1721 if (!reconstructor) continue;
1722 TString detName = fgkDetectorName[iDet];
1723 if (detName == "HLT") {
1724 fRunHLTTracking = kTRUE;
1727 if (detName == "MUON") {
1728 fRunMuonTracking = kTRUE;
1733 fTracker[iDet] = reconstructor->CreateTracker();
1734 if (!fTracker[iDet] && (iDet < 7)) {
1735 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1736 if (fStopOnError) return kFALSE;
1743 //_____________________________________________________________________________
1744 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1746 // delete trackers and the run loader and close and delete the file
1748 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1749 delete fReconstructor[iDet];
1750 fReconstructor[iDet] = NULL;
1751 fLoader[iDet] = NULL;
1752 delete fTracker[iDet];
1753 fTracker[iDet] = NULL;
1754 delete fQualAssDataMaker[iDet];
1755 fQualAssDataMaker[iDet] = NULL;
1759 delete fDiamondProfile;
1760 fDiamondProfile = NULL;
1775 gSystem->Unlink("AliESDs.old.root");
1779 //_____________________________________________________________________________
1781 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
1783 // read the ESD event from a file
1785 if (!esd) return kFALSE;
1787 sprintf(fileName, "ESD_%d.%d_%s.root",
1788 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1789 if (gSystem->AccessPathName(fileName)) return kFALSE;
1791 AliInfo(Form("reading ESD from file %s", fileName));
1792 AliDebug(1, Form("reading ESD from file %s", fileName));
1793 TFile* file = TFile::Open(fileName);
1794 if (!file || !file->IsOpen()) {
1795 AliError(Form("opening %s failed", fileName));
1802 esd = (AliESDEvent*) file->Get("ESD");
1811 //_____________________________________________________________________________
1812 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
1814 // write the ESD event to a file
1818 sprintf(fileName, "ESD_%d.%d_%s.root",
1819 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1821 AliDebug(1, Form("writing ESD to file %s", fileName));
1822 TFile* file = TFile::Open(fileName, "recreate");
1823 if (!file || !file->IsOpen()) {
1824 AliError(Form("opening %s failed", fileName));
1836 //_____________________________________________________________________________
1837 void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
1839 // write all files from the given esd file to an aod file
1841 // create an AliAOD object
1842 AliAODEvent *aod = new AliAODEvent();
1843 aod->CreateStdContent();
1849 TTree *aodTree = new TTree("aodTree", "AliAOD tree");
1850 aodTree->Branch(aod->GetList());
1853 TTree *t = (TTree*) esdFile->Get("esdTree");
1854 AliESDEvent *esd = new AliESDEvent();
1855 esd->ReadFromTree(t);
1857 Int_t nEvents = t->GetEntries();
1859 // set arrays and pointers
1867 // loop over events and fill them
1868 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
1869 t->GetEntry(iEvent);
1871 // Multiplicity information needed by the header (to be revised!)
1872 Int_t nTracks = esd->GetNumberOfTracks();
1873 Int_t nPosTracks = 0;
1874 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack)
1875 if (esd->GetTrack(iTrack)->Charge()> 0) nPosTracks++;
1877 // Access the header
1878 AliAODHeader *header = aod->GetHeader();
1881 header->SetRunNumber (esd->GetRunNumber() );
1882 header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
1883 header->SetOrbitNumber (esd->GetOrbitNumber() );
1884 header->SetPeriodNumber (esd->GetPeriodNumber() );
1885 header->SetTriggerMask (esd->GetTriggerMask() );
1886 header->SetTriggerCluster (esd->GetTriggerCluster() );
1887 header->SetEventType (esd->GetEventType() );
1888 header->SetMagneticField (esd->GetMagneticField() );
1889 header->SetZDCN1Energy (esd->GetZDCN1Energy() );
1890 header->SetZDCP1Energy (esd->GetZDCP1Energy() );
1891 header->SetZDCN2Energy (esd->GetZDCN2Energy() );
1892 header->SetZDCP2Energy (esd->GetZDCP2Energy() );
1893 header->SetZDCEMEnergy (esd->GetZDCEMEnergy() );
1894 header->SetRefMultiplicity (nTracks);
1895 header->SetRefMultiplicityPos(nPosTracks);
1896 header->SetRefMultiplicityNeg(nTracks - nPosTracks);
1897 header->SetMuonMagFieldScale(-999.); // FIXME
1898 header->SetCentrality(-999.); // FIXME
1900 Int_t nV0s = esd->GetNumberOfV0s();
1901 Int_t nCascades = esd->GetNumberOfCascades();
1902 Int_t nKinks = esd->GetNumberOfKinks();
1903 Int_t nVertices = nV0s + nCascades + nKinks;
1905 aod->ResetStd(nTracks, nVertices);
1906 AliAODTrack *aodTrack;
1908 // Array to take into account the tracks already added to the AOD
1909 Bool_t * usedTrack = NULL;
1911 usedTrack = new Bool_t[nTracks];
1912 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
1914 // Array to take into account the V0s already added to the AOD
1915 Bool_t * usedV0 = NULL;
1917 usedV0 = new Bool_t[nV0s];
1918 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
1920 // Array to take into account the kinks already added to the AOD
1921 Bool_t * usedKink = NULL;
1923 usedKink = new Bool_t[nKinks];
1924 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
1927 // Access to the AOD container of vertices
1928 TClonesArray &vertices = *(aod->GetVertices());
1931 // Access to the AOD container of tracks
1932 TClonesArray &tracks = *(aod->GetTracks());
1935 // Add primary vertex. The primary tracks will be defined
1936 // after the loops on the composite objects (V0, cascades, kinks)
1937 const AliESDVertex *vtx = esd->GetPrimaryVertex();
1939 vtx->GetXYZ(pos); // position
1940 vtx->GetCovMatrix(covVtx); //covariance matrix
1942 AliAODVertex * primary = new(vertices[jVertices++])
1943 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);
1945 // Create vertices starting from the most complex objects
1948 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
1949 AliESDcascade *cascade = esd->GetCascade(nCascade);
1951 cascade->GetXYZcascade(pos[0], pos[1], pos[2]); // Bo: bug correction
1952 cascade->GetPosCovXi(covVtx);
1954 // Add the cascade vertex
1955 AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
1957 cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
1960 AliAODVertex::kCascade);
1962 primary->AddDaughter(vcascade);
1964 // Add the V0 from the cascade. The ESD class have to be optimized...
1965 // Now we have to search for the corresponding V0 in the list of V0s
1966 // using the indeces of the positive and negative tracks
1968 Int_t posFromV0 = cascade->GetPindex();
1969 Int_t negFromV0 = cascade->GetNindex();
1971 AliESDv0 * v0 = 0x0;
1974 for (Int_t iV0=0; iV0<nV0s; ++iV0) {
1976 v0 = esd->GetV0(iV0);
1977 Int_t posV0 = v0->GetPindex();
1978 Int_t negV0 = v0->GetNindex();
1980 if (posV0==posFromV0 && negV0==negFromV0) {
1986 AliAODVertex * vV0FromCascade = 0x0;
1988 if (indV0>-1 && !usedV0[indV0] ) {
1990 // the V0 exists in the array of V0s and is not used
1992 usedV0[indV0] = kTRUE;
1994 v0->GetXYZ(pos[0], pos[1], pos[2]);
1995 v0->GetPosCov(covVtx);
1997 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
1999 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2005 // the V0 doesn't exist in the array of V0s or was used
2006 cerr << "Error: event " << iEvent << " cascade " << nCascade
2007 << " The V0 " << indV0
2008 << " doesn't exist in the array of V0s or was used!" << endl;
2010 cascade->GetXYZ(pos[0], pos[1], pos[2]);
2011 cascade->GetPosCov(covVtx);
2013 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2015 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2019 vcascade->AddDaughter(vV0FromCascade);
2022 // Add the positive tracks from the V0
2024 if (! usedTrack[posFromV0]) {
2026 usedTrack[posFromV0] = kTRUE;
2028 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2029 esdTrack->GetPxPyPz(p);
2030 esdTrack->GetXYZ(pos);
2031 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2032 esdTrack->GetESDpid(pid);
2034 vV0FromCascade->AddDaughter(aodTrack =
2035 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2036 esdTrack->GetLabel(),
2042 (Short_t)esdTrack->Charge(),
2043 esdTrack->GetITSClusterMap(),
2046 kTRUE, // check if this is right
2047 kFALSE, // check if this is right
2048 AliAODTrack::kSecondary)
2050 aodTrack->ConvertAliPIDtoAODPID();
2053 cerr << "Error: event " << iEvent << " cascade " << nCascade
2054 << " track " << posFromV0 << " has already been used!" << endl;
2057 // Add the negative tracks from the V0
2059 if (!usedTrack[negFromV0]) {
2061 usedTrack[negFromV0] = kTRUE;
2063 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2064 esdTrack->GetPxPyPz(p);
2065 esdTrack->GetXYZ(pos);
2066 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2067 esdTrack->GetESDpid(pid);
2069 vV0FromCascade->AddDaughter(aodTrack =
2070 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2071 esdTrack->GetLabel(),
2077 (Short_t)esdTrack->Charge(),
2078 esdTrack->GetITSClusterMap(),
2081 kTRUE, // check if this is right
2082 kFALSE, // check if this is right
2083 AliAODTrack::kSecondary)
2085 aodTrack->ConvertAliPIDtoAODPID();
2088 cerr << "Error: event " << iEvent << " cascade " << nCascade
2089 << " track " << negFromV0 << " has already been used!" << endl;
2092 // Add the bachelor track from the cascade
2094 Int_t bachelor = cascade->GetBindex();
2096 if(!usedTrack[bachelor]) {
2098 usedTrack[bachelor] = kTRUE;
2100 AliESDtrack *esdTrack = esd->GetTrack(bachelor);
2101 esdTrack->GetPxPyPz(p);
2102 esdTrack->GetXYZ(pos);
2103 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2104 esdTrack->GetESDpid(pid);
2106 vcascade->AddDaughter(aodTrack =
2107 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2108 esdTrack->GetLabel(),
2114 (Short_t)esdTrack->Charge(),
2115 esdTrack->GetITSClusterMap(),
2118 kTRUE, // check if this is right
2119 kFALSE, // check if this is right
2120 AliAODTrack::kSecondary)
2122 aodTrack->ConvertAliPIDtoAODPID();
2125 cerr << "Error: event " << iEvent << " cascade " << nCascade
2126 << " track " << bachelor << " has already been used!" << endl;
2129 // Add the primary track of the cascade (if any)
2131 } // end of the loop on cascades
2135 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
2137 if (usedV0[nV0]) continue; // skip if aready added to the AOD
2139 AliESDv0 *v0 = esd->GetV0(nV0);
2141 v0->GetXYZ(pos[0], pos[1], pos[2]);
2142 v0->GetPosCov(covVtx);
2144 AliAODVertex * vV0 =
2145 new(vertices[jVertices++]) AliAODVertex(pos,
2147 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2151 primary->AddDaughter(vV0);
2153 Int_t posFromV0 = v0->GetPindex();
2154 Int_t negFromV0 = v0->GetNindex();
2156 // Add the positive tracks from the V0
2158 if (!usedTrack[posFromV0]) {
2160 usedTrack[posFromV0] = kTRUE;
2162 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2163 esdTrack->GetPxPyPz(p);
2164 esdTrack->GetXYZ(pos);
2165 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2166 esdTrack->GetESDpid(pid);
2168 vV0->AddDaughter(aodTrack =
2169 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2170 esdTrack->GetLabel(),
2176 (Short_t)esdTrack->Charge(),
2177 esdTrack->GetITSClusterMap(),
2180 kTRUE, // check if this is right
2181 kFALSE, // check if this is right
2182 AliAODTrack::kSecondary)
2184 aodTrack->ConvertAliPIDtoAODPID();
2187 cerr << "Error: event " << iEvent << " V0 " << nV0
2188 << " track " << posFromV0 << " has already been used!" << endl;
2191 // Add the negative tracks from the V0
2193 if (!usedTrack[negFromV0]) {
2195 usedTrack[negFromV0] = kTRUE;
2197 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2198 esdTrack->GetPxPyPz(p);
2199 esdTrack->GetXYZ(pos);
2200 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2201 esdTrack->GetESDpid(pid);
2203 vV0->AddDaughter(aodTrack =
2204 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2205 esdTrack->GetLabel(),
2211 (Short_t)esdTrack->Charge(),
2212 esdTrack->GetITSClusterMap(),
2215 kTRUE, // check if this is right
2216 kFALSE, // check if this is right
2217 AliAODTrack::kSecondary)
2219 aodTrack->ConvertAliPIDtoAODPID();
2222 cerr << "Error: event " << iEvent << " V0 " << nV0
2223 << " track " << negFromV0 << " has already been used!" << endl;
2226 } // end of the loop on V0s
2228 // Kinks: it is a big mess the access to the information in the kinks
2229 // The loop is on the tracks in order to find the mother and daugther of each kink
2232 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2235 AliESDtrack * esdTrack = esd->GetTrack(iTrack);
2237 Int_t ikink = esdTrack->GetKinkIndex(0);
2240 // Negative kink index: mother, positive: daughter
2242 // Search for the second track of the kink
2244 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
2246 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
2248 Int_t jkink = esdTrack1->GetKinkIndex(0);
2250 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
2252 // The two tracks are from the same kink
2254 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
2257 Int_t idaughter = -1;
2259 if (ikink<0 && jkink>0) {
2264 else if (ikink>0 && jkink<0) {
2270 cerr << "Error: Wrong combination of kink indexes: "
2271 << ikink << " " << jkink << endl;
2275 // Add the mother track
2277 AliAODTrack * mother = NULL;
2279 if (!usedTrack[imother]) {
2281 usedTrack[imother] = kTRUE;
2283 AliESDtrack *esdTrack = esd->GetTrack(imother);
2284 esdTrack->GetPxPyPz(p);
2285 esdTrack->GetXYZ(pos);
2286 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2287 esdTrack->GetESDpid(pid);
2290 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2291 esdTrack->GetLabel(),
2297 (Short_t)esdTrack->Charge(),
2298 esdTrack->GetITSClusterMap(),
2301 kTRUE, // check if this is right
2302 kTRUE, // check if this is right
2303 AliAODTrack::kPrimary);
2304 primary->AddDaughter(mother);
2305 mother->ConvertAliPIDtoAODPID();
2308 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2309 << " track " << imother << " has already been used!" << endl;
2312 // Add the kink vertex
2313 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
2315 AliAODVertex * vkink =
2316 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
2320 esdTrack->GetID(), // This is the track ID of the mother's track!
2321 AliAODVertex::kKink);
2322 // Add the daughter track
2324 AliAODTrack * daughter = NULL;
2326 if (!usedTrack[idaughter]) {
2328 usedTrack[idaughter] = kTRUE;
2330 AliESDtrack *esdTrack = esd->GetTrack(idaughter);
2331 esdTrack->GetPxPyPz(p);
2332 esdTrack->GetXYZ(pos);
2333 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2334 esdTrack->GetESDpid(pid);
2337 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2338 esdTrack->GetLabel(),
2344 (Short_t)esdTrack->Charge(),
2345 esdTrack->GetITSClusterMap(),
2348 kTRUE, // check if this is right
2349 kTRUE, // check if this is right
2350 AliAODTrack::kPrimary);
2351 vkink->AddDaughter(daughter);
2352 daughter->ConvertAliPIDtoAODPID();
2355 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2356 << " track " << idaughter << " has already been used!" << endl;
2368 // Tracks (primary and orphan)
2370 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
2373 if (usedTrack[nTrack]) continue;
2375 AliESDtrack *esdTrack = esd->GetTrack(nTrack);
2376 esdTrack->GetPxPyPz(p);
2377 esdTrack->GetXYZ(pos);
2378 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2379 esdTrack->GetESDpid(pid);
2381 Float_t impactXY, impactZ;
2383 esdTrack->GetImpactParameters(impactXY,impactZ);
2386 // track inside the beam pipe
2388 primary->AddDaughter(aodTrack =
2389 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2390 esdTrack->GetLabel(),
2396 (Short_t)esdTrack->Charge(),
2397 esdTrack->GetITSClusterMap(),
2400 kTRUE, // check if this is right
2401 kTRUE, // check if this is right
2402 AliAODTrack::kPrimary)
2404 aodTrack->ConvertAliPIDtoAODPID();
2407 // outside the beam pipe: orphan track
2409 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2410 esdTrack->GetLabel(),
2416 (Short_t)esdTrack->Charge(),
2417 esdTrack->GetITSClusterMap(),
2420 kFALSE, // check if this is right
2421 kFALSE, // check if this is right
2422 AliAODTrack::kOrphan);
2423 aodTrack->ConvertAliPIDtoAODPID();
2425 } // end of loop on tracks
2428 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
2429 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
2431 AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);
2432 p[0] = esdMuTrack->Px();
2433 p[1] = esdMuTrack->Py();
2434 p[2] = esdMuTrack->Pz();
2435 pos[0] = primary->GetX();
2436 pos[1] = primary->GetY();
2437 pos[2] = primary->GetZ();
2439 // has to be changed once the muon pid is provided by the ESD
2440 for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
2442 primary->AddDaughter(aodTrack =
2443 new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
2444 0, // no label provided
2449 NULL, // no covariance matrix provided
2450 esdMuTrack->Charge(),
2451 0, // ITSClusterMap is set below
2454 kFALSE, // muon tracks are not used to fit the primary vtx
2455 kFALSE, // not used for vertex fit
2456 AliAODTrack::kPrimary)
2459 aodTrack->SetHitsPatternInTrigCh(esdMuTrack->GetHitsPatternInTrigCh());
2460 Int_t track2Trigger = esdMuTrack->GetMatchTrigger();
2461 aodTrack->SetMatchTrigger(track2Trigger);
2463 aodTrack->SetChi2MatchTrigger(esdMuTrack->GetChi2MatchTrigger());
2465 aodTrack->SetChi2MatchTrigger(0.);
2468 // Access to the AOD container of clusters
2469 TClonesArray &clusters = *(aod->GetClusters());
2473 Int_t nClusters = esd->GetNumberOfCaloClusters();
2475 for (Int_t iClust=0; iClust<nClusters; ++iClust) {
2477 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
2479 Int_t id = cluster->GetID();
2481 Float_t energy = cluster->E();
2482 cluster->GetPosition(posF);
2483 AliAODVertex *prodVertex = primary;
2484 AliAODTrack *primTrack = NULL;
2485 Char_t ttype=AliAODCluster::kUndef;
2487 if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral;
2488 else if (cluster->IsEMCAL()) {
2490 if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster)
2491 ttype = AliAODCluster::kEMCALPseudoCluster;
2493 ttype = AliAODCluster::kEMCALClusterv1;
2497 new(clusters[jClusters++]) AliAODCluster(id,
2501 NULL, // no covariance matrix provided
2502 NULL, // no pid for clusters provided
2507 } // end of loop on calo clusters
2510 const AliMultiplicity *mult = esd->GetMultiplicity();
2512 if (mult->GetNumberOfTracklets()>0) {
2513 aod->GetTracklets()->CreateContainer(mult->GetNumberOfTracklets());
2515 for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {
2516 aod->GetTracklets()->SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n));
2520 Printf("ERROR: AliMultiplicity could not be retrieved from ESD");
2523 delete [] usedTrack;
2527 // fill the tree for this event
2529 } // end of event loop
2531 aodTree->GetUserInfo()->Add(aod);
2536 // write the tree to the specified file
2537 aodFile = aodTree->GetCurrentFile();
2544 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2546 // Write space-points which are then used in the alignment procedures
2547 // For the moment only ITS, TRD and TPC
2549 // Load TOF clusters
2551 fLoader[3]->LoadRecPoints("read");
2552 TTree* tree = fLoader[3]->TreeR();
2554 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2557 fTracker[3]->LoadClusters(tree);
2559 Int_t ntracks = esd->GetNumberOfTracks();
2560 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2562 AliESDtrack *track = esd->GetTrack(itrack);
2565 for (Int_t iDet = 3; iDet >= 0; iDet--)
2566 nsp += track->GetNcls(iDet);
2568 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2569 track->SetTrackPointArray(sp);
2571 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2572 AliTracker *tracker = fTracker[iDet];
2573 if (!tracker) continue;
2574 Int_t nspdet = track->GetNcls(iDet);
2575 if (nspdet <= 0) continue;
2576 track->GetClusters(iDet,idx);
2580 while (isp < nspdet) {
2581 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
2582 const Int_t kNTPCmax = 159;
2583 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2584 if (!isvalid) continue;
2585 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2591 fTracker[3]->UnloadClusters();
2592 fLoader[3]->UnloadRecPoints();
2596 //_____________________________________________________________________________
2597 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2599 // The method reads the raw-data error log
2600 // accumulated within the rawReader.
2601 // It extracts the raw-data errors related to
2602 // the current event and stores them into
2603 // a TClonesArray inside the esd object.
2605 if (!fRawReader) return;
2607 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2609 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2611 if (iEvent != log->GetEventNumber()) continue;
2613 esd->AddRawDataErrorLog(log);
2618 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2619 // Dump a file content into a char in TNamed
2621 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2622 Int_t kBytes = (Int_t)in.tellg();
2623 printf("Size: %d \n",kBytes);
2626 char* memblock = new char [kBytes];
2627 in.seekg (0, ios::beg);
2628 in.read (memblock, kBytes);
2630 TString fData(memblock,kBytes);
2631 fn = new TNamed(fName,fData);
2632 printf("fData Size: %d \n",fData.Sizeof());
2633 printf("fName Size: %d \n",fName.Sizeof());
2634 printf("fn Size: %d \n",fn->Sizeof());
2638 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2644 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2645 // This is not really needed in AliReconstruction at the moment
2646 // but can serve as a template
2648 TList *fList = fTree->GetUserInfo();
2649 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2650 printf("fn Size: %d \n",fn->Sizeof());
2652 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2653 const char* cdata = fn->GetTitle();
2654 printf("fTmp Size %d\n",fTmp.Sizeof());
2656 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2657 printf("calculated size %d\n",size);
2658 ofstream out(fName.Data(),ios::out | ios::binary);
2659 out.write(cdata,size);
2664 //_____________________________________________________________________________
2665 AliQualAssDataMaker * AliReconstruction::GetQualAssDataMaker(Int_t iDet)
2667 // get the quality assurance data maker object and the loader for a detector
2669 if (fQualAssDataMaker[iDet])
2670 return fQualAssDataMaker[iDet];
2672 // load the QA data maker object
2673 TPluginManager* pluginManager = gROOT->GetPluginManager();
2674 TString detName = fgkDetectorName[iDet];
2675 TString qadmName = "Ali" + detName + "QualAssDataMaker";
2676 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT"))
2679 AliQualAssDataMaker * qadm = NULL;
2680 // first check if a plugin is defined for the quality assurance data maker
2681 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQualAssDataMaker", detName);
2682 // if not, add a plugin for it
2683 if (!pluginHandler) {
2684 AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2685 TString libs = gSystem->GetLibraries();
2686 if (libs.Contains("lib" + detName + "base.so") ||
2687 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2688 pluginManager->AddHandler("AliQualAssDataMaker", detName,
2689 qadmName, detName + "qadm", qadmName + "()");
2691 pluginManager->AddHandler("AliQualAssDataMaker", detName,
2692 qadmName, detName, qadmName + "()");
2694 pluginHandler = pluginManager->FindHandler("AliQualAssDataMaker", detName);
2696 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2697 qadm = (AliQualAssDataMaker *) pluginHandler->ExecPlugin(0);
2700 AliInfo(Form("Initializing quality assurance data maker for %s", fgkDetectorName[iDet]));
2701 qadm->Init(AliQualAss::kRECPOINTS);
2702 qadm->Init(AliQualAss::kESDS) ;
2703 fQualAssDataMaker[iDet] = qadm;
2709 //_____________________________________________________________________________
2710 Bool_t AliReconstruction::RunQualAss(const char* detectors, AliESDEvent *& esd)
2712 // run the Quality Assurance data producer
2714 AliCodeTimerAuto("")
2715 TString detStr = detectors;
2716 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2717 if (!IsSelected(fgkDetectorName[iDet], detStr))
2719 AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
2722 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2723 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2725 qadm->Exec(AliQualAss::kESDS, esd) ;
2727 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2729 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2730 AliError(Form("the following detectors were not found: %s",