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),
190 fStopOnError(kFALSE),
191 fWriteAlignmentData(kFALSE),
193 fWriteESDfriend(kFALSE),
195 fFillTriggerESD(kTRUE),
197 fRunLocalReconstruction("ALL"),
200 fGAliceFileName(gAliceFilename),
205 fNumberOfEventsPerFile(1),
208 fLoadAlignFromCDB(kTRUE),
209 fLoadAlignData("ALL"),
216 fDiamondProfile(NULL),
218 fAlignObjArray(NULL),
222 // create reconstruction object with default parameters
224 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
225 fReconstructor[iDet] = NULL;
226 fLoader[iDet] = NULL;
227 fTracker[iDet] = NULL;
228 fQualAssDataMaker[iDet] = NULL;
233 //_____________________________________________________________________________
234 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
237 fUniformField(rec.fUniformField),
238 fRunVertexFinder(rec.fRunVertexFinder),
239 fRunHLTTracking(rec.fRunHLTTracking),
240 fRunMuonTracking(rec.fRunMuonTracking),
241 fStopOnError(rec.fStopOnError),
242 fWriteAlignmentData(rec.fWriteAlignmentData),
243 fCleanESD(rec.fCleanESD),
244 fWriteESDfriend(rec.fWriteESDfriend),
245 fWriteAOD(rec.fWriteAOD),
246 fFillTriggerESD(rec.fFillTriggerESD),
248 fRunLocalReconstruction(rec.fRunLocalReconstruction),
249 fRunTracking(rec.fRunTracking),
250 fFillESD(rec.fFillESD),
251 fGAliceFileName(rec.fGAliceFileName),
253 fEquipIdMap(rec.fEquipIdMap),
254 fFirstEvent(rec.fFirstEvent),
255 fLastEvent(rec.fLastEvent),
256 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
259 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
260 fLoadAlignData(rec.fLoadAlignData),
261 fESDPar(rec.fESDPar),
267 fDiamondProfile(NULL),
269 fAlignObjArray(rec.fAlignObjArray),
270 fCDBUri(rec.fCDBUri),
275 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
276 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
278 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
279 fReconstructor[iDet] = NULL;
280 fLoader[iDet] = NULL;
281 fTracker[iDet] = NULL;
282 fQualAssDataMaker[iDet] = NULL;
284 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
285 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
289 //_____________________________________________________________________________
290 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
292 // assignment operator
294 this->~AliReconstruction();
295 new(this) AliReconstruction(rec);
299 //_____________________________________________________________________________
300 AliReconstruction::~AliReconstruction()
306 fSpecCDBUri.Delete();
308 AliCodeTimer::Instance()->Print();
311 //_____________________________________________________________________________
312 void AliReconstruction::InitCDBStorage()
314 // activate a default CDB storage
315 // First check if we have any CDB storage set, because it is used
316 // to retrieve the calibration and alignment constants
318 AliCDBManager* man = AliCDBManager::Instance();
319 if (man->IsDefaultStorageSet())
321 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
322 AliWarning("Default CDB storage has been already set !");
323 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
324 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
328 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
329 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
330 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
331 man->SetDefaultStorage(fCDBUri);
334 // Now activate the detector specific CDB storage locations
335 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
336 TObject* obj = fSpecCDBUri[i];
338 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
339 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
340 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
341 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
346 //_____________________________________________________________________________
347 void AliReconstruction::SetDefaultStorage(const char* uri) {
348 // Store the desired default CDB storage location
349 // Activate it later within the Run() method
355 //_____________________________________________________________________________
356 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
357 // Store a detector-specific CDB storage location
358 // Activate it later within the Run() method
360 AliCDBPath aPath(calibType);
361 if(!aPath.IsValid()){
362 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
363 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
364 if(!strcmp(calibType, fgkDetectorName[iDet])) {
365 aPath.SetPath(Form("%s/*", calibType));
366 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
370 if(!aPath.IsValid()){
371 AliError(Form("Not a valid path or detector: %s", calibType));
376 // check that calibType refers to a "valid" detector name
377 Bool_t isDetector = kFALSE;
378 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
379 TString detName = fgkDetectorName[iDet];
380 if(aPath.GetLevel0() == detName) {
387 AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
391 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
392 if (obj) fSpecCDBUri.Remove(obj);
393 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
400 //_____________________________________________________________________________
401 Bool_t AliReconstruction::SetRunNumber()
403 // The method is called in Run() in order
404 // to set a correct run number.
405 // In case of raw data reconstruction the
406 // run number is taken from the raw data header
408 if(AliCDBManager::Instance()->GetRun() < 0) {
410 AliError("No run loader is found !");
413 // read run number from gAlice
414 if(fRunLoader->GetAliRun())
415 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
418 if(fRawReader->NextEvent()) {
419 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
420 fRawReader->RewindEvents();
423 AliError("No raw-data events found !");
428 AliError("Neither gAlice nor RawReader objects are found !");
432 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
437 //_____________________________________________________________________________
438 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
440 // Read the alignment objects from CDB.
441 // Each detector is supposed to have the
442 // alignment objects in DET/Align/Data CDB path.
443 // All the detector objects are then collected,
444 // sorted by geometry level (starting from ALIC) and
445 // then applied to the TGeo geometry.
446 // Finally an overlaps check is performed.
448 // Load alignment data from CDB and fill fAlignObjArray
449 if(fLoadAlignFromCDB){
451 TString detStr = detectors;
452 TString loadAlObjsListOfDets = "";
454 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
455 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
456 loadAlObjsListOfDets += fgkDetectorName[iDet];
457 loadAlObjsListOfDets += " ";
458 } // end loop over detectors
459 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
461 // Check if the array with alignment objects was
462 // provided by the user. If yes, apply the objects
463 // to the present TGeo geometry
464 if (fAlignObjArray) {
465 if (gGeoManager && gGeoManager->IsClosed()) {
466 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
467 AliError("The misalignment of one or more volumes failed!"
468 "Compare the list of simulated detectors and the list of detector alignment data!");
473 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
479 delete fAlignObjArray; fAlignObjArray=0;
484 //_____________________________________________________________________________
485 void AliReconstruction::SetGAliceFile(const char* fileName)
487 // set the name of the galice file
489 fGAliceFileName = fileName;
492 //_____________________________________________________________________________
493 void AliReconstruction::SetOption(const char* detector, const char* option)
495 // set options for the reconstruction of a detector
497 TObject* obj = fOptions.FindObject(detector);
498 if (obj) fOptions.Remove(obj);
499 fOptions.Add(new TNamed(detector, option));
503 //_____________________________________________________________________________
504 Bool_t AliReconstruction::Run(const char* input)
506 // run the reconstruction
511 if (!input) input = fInput.Data();
512 TString fileName(input);
513 if (fileName.EndsWith("/")) {
514 fRawReader = new AliRawReaderFile(fileName);
515 } else if (fileName.EndsWith(".root")) {
516 fRawReader = new AliRawReaderRoot(fileName);
517 } else if (!fileName.IsNull()) {
518 fRawReader = new AliRawReaderDate(fileName);
519 fRawReader->SelectEvents(7);
521 if (!fEquipIdMap.IsNull() && fRawReader)
522 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
525 // get the run loader
526 if (!InitRunLoader()) return kFALSE;
528 // Initialize the CDB storage
531 // Set run number in CDBManager (if it is not already set by the user)
532 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
534 // Import ideal TGeo geometry and apply misalignment
536 TString geom(gSystem->DirName(fGAliceFileName));
537 geom += "/geometry.root";
538 AliGeomManager::LoadGeometry(geom.Data());
539 if (!gGeoManager) if (fStopOnError) return kFALSE;
542 AliCDBManager* man = AliCDBManager::Instance();
543 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
545 // local reconstruction
546 if (!fRunLocalReconstruction.IsNull()) {
547 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
548 if (fStopOnError) {CleanUp(); return kFALSE;}
551 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
552 // fFillESD.IsNull()) return kTRUE;
555 if (fRunVertexFinder && !CreateVertexer()) {
563 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
570 // get the possibly already existing ESD file and tree
571 AliESDEvent* esd = new AliESDEvent(); AliESDEvent* hltesd = new AliESDEvent();
572 TFile* fileOld = NULL;
573 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
574 if (!gSystem->AccessPathName("AliESDs.root")){
575 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
576 fileOld = TFile::Open("AliESDs.old.root");
577 if (fileOld && fileOld->IsOpen()) {
578 treeOld = (TTree*) fileOld->Get("esdTree");
579 if (treeOld)esd->ReadFromTree(treeOld);
580 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
581 if (hlttreeOld) hltesd->ReadFromTree(hlttreeOld);
585 // create the ESD output file and tree
586 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
587 file->SetCompressionLevel(2);
588 if (!file->IsOpen()) {
589 AliError("opening AliESDs.root failed");
590 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
593 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
594 esd = new AliESDEvent();
595 esd->CreateStdContent();
596 esd->WriteToTree(tree);
598 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
599 hltesd = new AliESDEvent();
600 hltesd->CreateStdContent();
601 hltesd->WriteToTree(hlttree);
604 delete esd; delete hltesd;
605 esd = NULL; hltesd = NULL;
607 // create the branch with ESD additions
611 AliESDfriend *esdf = 0;
612 if (fWriteESDfriend) {
613 esdf = new AliESDfriend();
614 TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
615 br->SetFile("AliESDfriends.root");
616 esd->AddObject(esdf);
620 // Get the diamond profile from OCDB
621 AliCDBEntry* entry = AliCDBManager::Instance()
622 ->Get("GRP/Calib/MeanVertex");
625 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
627 AliError("No diamond profile found in OCDB!");
630 AliVertexerTracks tVertexer(AliTracker::GetBz());
631 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
635 if (fRawReader) fRawReader->RewindEvents();
636 TString detStr(fFillESD) ;
638 // initialises quality assurance for ESDs
639 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
640 if (!IsSelected(fgkDetectorName[iDet], detStr))
642 AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
645 qadm->Init(AliQualAss::kESDS) ;
648 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
649 if (fRawReader) fRawReader->NextEvent();
650 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
651 // copy old ESD to the new one
653 esd->ReadFromTree(treeOld);
654 treeOld->GetEntry(iEvent);
658 esd->ReadFromTree(hlttreeOld);
659 hlttreeOld->GetEntry(iEvent);
665 AliInfo(Form("processing event %d", iEvent));
666 fRunLoader->GetEvent(iEvent);
669 sprintf(aFileName, "ESD_%d.%d_final.root",
670 fRunLoader->GetHeader()->GetRun(),
671 fRunLoader->GetHeader()->GetEventNrInRun());
672 if (!gSystem->AccessPathName(aFileName)) continue;
674 // local reconstruction
675 if (!fRunLocalReconstruction.IsNull()) {
676 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
677 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
682 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
683 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
684 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
685 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
687 // Set magnetic field from the tracker
688 esd->SetMagneticField(AliTracker::GetBz());
689 hltesd->SetMagneticField(AliTracker::GetBz());
693 // Fill raw-data error log into the ESD
694 if (fRawReader) FillRawDataErrorLog(iEvent,esd);
697 if (fRunVertexFinder) {
698 if (!ReadESD(esd, "vertex")) {
699 if (!RunVertexFinder(esd)) {
700 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
702 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
707 if (!fRunTracking.IsNull()) {
708 if (fRunHLTTracking) {
709 hltesd->SetVertex(esd->GetVertex());
710 if (!RunHLTTracking(hltesd)) {
711 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
717 if (!fRunTracking.IsNull()) {
718 if (fRunMuonTracking) {
719 if (!RunMuonTracking(esd)) {
720 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
726 if (!fRunTracking.IsNull()) {
727 if (!ReadESD(esd, "tracking")) {
728 if (!RunTracking(esd)) {
729 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
731 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
736 if (!fFillESD.IsNull()) {
737 if (!FillESD(esd, fFillESD)) {
738 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
742 if (!fFillESD.IsNull())
743 RunQualAss(fFillESD.Data(), esd);
745 // fill Event header information from the RawEventHeader
746 if (fRawReader){FillRawEventHeaderESD(esd);}
749 AliESDpid::MakePID(esd);
750 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
752 if (fFillTriggerESD) {
753 if (!ReadESD(esd, "trigger")) {
754 if (!FillTriggerESD(esd)) {
755 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
757 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
761 //Try to improve the reconstructed primary vertex position using the tracks
762 AliESDVertex *pvtx=0;
763 Bool_t dovertex=kTRUE;
764 TObject* obj = fOptions.FindObject("ITS");
766 TString optITS = obj->GetTitle();
767 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
770 if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
771 if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
774 if (pvtx->GetStatus()) {
775 // Store the improved primary vertex
776 esd->SetPrimaryVertex(pvtx);
777 // Propagate the tracks to the DCA to the improved primary vertex
778 Double_t somethingbig = 777.;
779 Double_t bz = esd->GetMagneticField();
780 Int_t nt=esd->GetNumberOfTracks();
782 AliESDtrack *t = esd->GetTrack(nt);
783 t->RelateToVertex(pvtx, bz, somethingbig);
790 vtxer.Tracks2V0vertices(esd);
793 AliCascadeVertexer cvtxer;
794 cvtxer.V0sTracks2CascadeVertices(esd);
798 if (fCleanESD) CleanESD(esd);
799 if (fWriteESDfriend) {
800 new (esdf) AliESDfriend(); // Reset...
801 esd->GetESDfriend(esdf);
808 if (fCheckPointLevel > 0) WriteESD(esd, "final");
811 if (fWriteESDfriend) {
812 new (esdf) AliESDfriend(); // Reset...
815 // delete esdf; esdf = 0;
821 // write quality assurance ESDs data (one entry for all events)
822 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
823 if (!IsSelected(fgkDetectorName[iDet], detStr))
825 AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
828 qadm->Finish(AliQualAss::kESDS) ;
831 tree->GetUserInfo()->Add(esd);
832 hlttree->GetUserInfo()->Add(hltesd);
836 if(fESDPar.Contains("ESD.par")){
837 AliInfo("Attaching ESD.par to Tree");
838 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
839 tree->GetUserInfo()->Add(fn);
845 tree->SetBranchStatus("ESDfriend*",0);
850 TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE");
851 ESDFile2AODFile(file, aodFile);
856 CleanUp(file, fileOld);
858 // Create tags for the events in the ESD tree (the ESD tree is always present)
859 // In case of empty events the tags will contain dummy values
860 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
861 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent);
863 AliAODTagCreator *aodtagCreator = new AliAODTagCreator();
864 aodtagCreator->CreateAODTags(fFirstEvent,fLastEvent);
871 //_____________________________________________________________________________
872 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
874 // run the local reconstruction
878 AliCDBManager* man = AliCDBManager::Instance();
879 Bool_t origCache = man->GetCacheFlag();
881 TString detStr = detectors;
882 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
883 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
884 AliReconstructor* reconstructor = GetReconstructor(iDet);
885 if (!reconstructor) continue;
886 if (reconstructor->HasLocalReconstruction()) continue;
888 AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
889 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
891 AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
892 AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
894 man->SetCacheFlag(kTRUE);
895 TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
896 man->GetAll(calibPath); // entries are cached!
898 AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
901 fRawReader->RewindEvents();
902 reconstructor->Reconstruct(fRunLoader, fRawReader);
904 reconstructor->Reconstruct(fRunLoader);
907 AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
909 // unload calibration data
910 man->UnloadFromCache(calibPath);
914 man->SetCacheFlag(origCache);
916 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
917 AliError(Form("the following detectors were not found: %s",
919 if (fStopOnError) return kFALSE;
925 //_____________________________________________________________________________
926 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
928 // run the local reconstruction
932 TString detStr = detectors;
933 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
934 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
935 AliReconstructor* reconstructor = GetReconstructor(iDet);
936 if (!reconstructor) continue;
937 AliLoader* loader = fLoader[iDet];
939 // conversion of digits
940 if (fRawReader && reconstructor->HasDigitConversion()) {
941 AliInfo(Form("converting raw data digits into root objects for %s",
942 fgkDetectorName[iDet]));
943 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
944 fgkDetectorName[iDet]));
945 loader->LoadDigits("update");
946 loader->CleanDigits();
947 loader->MakeDigitsContainer();
948 TTree* digitsTree = loader->TreeD();
949 reconstructor->ConvertDigits(fRawReader, digitsTree);
950 loader->WriteDigits("OVERWRITE");
951 loader->UnloadDigits();
954 // local reconstruction
955 if (!reconstructor->HasLocalReconstruction()) continue;
956 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
957 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
958 loader->LoadRecPoints("update");
959 loader->CleanRecPoints();
960 loader->MakeRecPointsContainer();
961 TTree* clustersTree = loader->TreeR();
962 if (fRawReader && !reconstructor->HasDigitConversion()) {
963 reconstructor->Reconstruct(fRawReader, clustersTree);
965 loader->LoadDigits("read");
966 TTree* digitsTree = loader->TreeD();
968 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
969 if (fStopOnError) return kFALSE;
971 reconstructor->Reconstruct(digitsTree, clustersTree);
973 loader->UnloadDigits();
975 loader->WriteRecPoints("OVERWRITE");
976 loader->UnloadRecPoints();
979 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
980 AliError(Form("the following detectors were not found: %s",
982 if (fStopOnError) return kFALSE;
988 //_____________________________________________________________________________
989 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
991 // run the barrel tracking
995 AliESDVertex* vertex = NULL;
996 Double_t vtxPos[3] = {0, 0, 0};
997 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
999 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1000 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1001 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1005 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1006 AliInfo("running the ITS vertex finder");
1007 if (fLoader[0]) fLoader[0]->LoadRecPoints();
1008 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
1009 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
1011 AliWarning("Vertex not found");
1012 vertex = new AliESDVertex();
1013 vertex->SetName("default");
1016 vertex->SetName("reconstructed");
1020 AliInfo("getting the primary vertex from MC");
1021 vertex = new AliESDVertex(vtxPos, vtxErr);
1025 vertex->GetXYZ(vtxPos);
1026 vertex->GetSigmaXYZ(vtxErr);
1028 AliWarning("no vertex reconstructed");
1029 vertex = new AliESDVertex(vtxPos, vtxErr);
1031 esd->SetVertex(vertex);
1032 // if SPD multiplicity has been determined, it is stored in the ESD
1033 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1034 if(mult)esd->SetMultiplicity(mult);
1036 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1037 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1044 //_____________________________________________________________________________
1045 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1047 // run the HLT barrel tracking
1049 AliCodeTimerAuto("")
1052 AliError("Missing runLoader!");
1056 AliInfo("running HLT tracking");
1058 // Get a pointer to the HLT reconstructor
1059 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1060 if (!reconstructor) return kFALSE;
1063 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1064 TString detName = fgkDetectorName[iDet];
1065 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1066 reconstructor->SetOption(detName.Data());
1067 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1069 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1070 if (fStopOnError) return kFALSE;
1074 Double_t vtxErr[3]={0.005,0.005,0.010};
1075 const AliESDVertex *vertex = esd->GetVertex();
1076 vertex->GetXYZ(vtxPos);
1077 tracker->SetVertex(vtxPos,vtxErr);
1079 fLoader[iDet]->LoadRecPoints("read");
1080 TTree* tree = fLoader[iDet]->TreeR();
1082 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1085 tracker->LoadClusters(tree);
1087 if (tracker->Clusters2Tracks(esd) != 0) {
1088 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1092 tracker->UnloadClusters();
1100 //_____________________________________________________________________________
1101 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1103 // run the muon spectrometer tracking
1105 AliCodeTimerAuto("")
1108 AliError("Missing runLoader!");
1111 Int_t iDet = 7; // for MUON
1113 AliInfo("is running...");
1115 // Get a pointer to the MUON reconstructor
1116 AliReconstructor *reconstructor = GetReconstructor(iDet);
1117 if (!reconstructor) return kFALSE;
1120 TString detName = fgkDetectorName[iDet];
1121 AliDebug(1, Form("%s tracking", detName.Data()));
1122 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1124 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1129 fLoader[iDet]->LoadTracks("update");
1130 fLoader[iDet]->CleanTracks();
1131 fLoader[iDet]->MakeTracksContainer();
1134 fLoader[iDet]->LoadRecPoints("read");
1135 tracker->LoadClusters(fLoader[iDet]->TreeR());
1137 Int_t rv = tracker->Clusters2Tracks(esd);
1139 fLoader[iDet]->UnloadRecPoints();
1143 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1147 tracker->UnloadClusters();
1149 fLoader[iDet]->UnloadRecPoints();
1151 fLoader[iDet]->WriteTracks("OVERWRITE");
1152 fLoader[iDet]->UnloadTracks();
1160 //_____________________________________________________________________________
1161 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1163 // run the barrel tracking
1165 AliCodeTimerAuto("")
1167 AliInfo("running tracking");
1169 //Fill the ESD with the T0 info (will be used by the TOF)
1170 if (fReconstructor[11])
1171 GetReconstructor(11)->FillESD(fRunLoader, esd);
1173 // pass 1: TPC + ITS inwards
1174 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1175 if (!fTracker[iDet]) continue;
1176 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1179 fLoader[iDet]->LoadRecPoints("read");
1180 TTree* tree = fLoader[iDet]->TreeR();
1182 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1185 fTracker[iDet]->LoadClusters(tree);
1188 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1189 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1192 if (fCheckPointLevel > 1) {
1193 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1195 // preliminary PID in TPC needed by the ITS tracker
1197 GetReconstructor(1)->FillESD(fRunLoader, esd);
1198 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1199 AliESDpid::MakePID(esd);
1203 // pass 2: ALL backwards
1204 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1205 if (!fTracker[iDet]) continue;
1206 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1209 if (iDet > 1) { // all except ITS, TPC
1211 fLoader[iDet]->LoadRecPoints("read");
1212 tree = fLoader[iDet]->TreeR();
1214 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1217 fTracker[iDet]->LoadClusters(tree);
1221 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1222 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1225 if (fCheckPointLevel > 1) {
1226 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1230 if (iDet > 2) { // all except ITS, TPC, TRD
1231 fTracker[iDet]->UnloadClusters();
1232 fLoader[iDet]->UnloadRecPoints();
1234 // updated PID in TPC needed by the ITS tracker -MI
1236 GetReconstructor(1)->FillESD(fRunLoader, esd);
1237 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1238 AliESDpid::MakePID(esd);
1242 // write space-points to the ESD in case alignment data output
1244 if (fWriteAlignmentData)
1245 WriteAlignmentData(esd);
1247 // pass 3: TRD + TPC + ITS refit inwards
1248 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1249 if (!fTracker[iDet]) continue;
1250 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1253 if (fTracker[iDet]->RefitInward(esd) != 0) {
1254 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1257 if (fCheckPointLevel > 1) {
1258 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1262 fTracker[iDet]->UnloadClusters();
1263 fLoader[iDet]->UnloadRecPoints();
1266 // Propagate track to the vertex - if not done by ITS
1268 Int_t ntracks = esd->GetNumberOfTracks();
1269 for (Int_t itrack=0; itrack<ntracks; itrack++){
1270 const Double_t kRadius = 3; // beam pipe radius
1271 const Double_t kMaxStep = 5; // max step
1272 const Double_t kMaxD = 123456; // max distance to prim vertex
1273 Double_t fieldZ = AliTracker::GetBz(); //
1274 AliESDtrack * track = esd->GetTrack(itrack);
1275 if (!track) continue;
1276 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1277 AliTracker::PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1278 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1284 //_____________________________________________________________________________
1285 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1287 // Remove the data which are not needed for the physics analysis.
1290 AliInfo("Cleaning the ESD...");
1292 const AliESDVertex *vertex=esd->GetVertex();
1293 Double_t vz=vertex->GetZv();
1295 Int_t nTracks=esd->GetNumberOfTracks();
1296 for (Int_t i=0; i<nTracks; i++) {
1297 AliESDtrack *track=esd->GetTrack(i);
1299 Float_t xy,z; track->GetImpactParameters(xy,z);
1300 if (TMath::Abs(xy) < 50.) continue;
1301 if (vertex->GetStatus())
1302 if (TMath::Abs(vz-z) < 5.) continue;
1304 esd->RemoveTrack(i);
1310 //_____________________________________________________________________________
1311 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1313 // fill the event summary data
1315 AliCodeTimerAuto("")
1317 TString detStr = detectors;
1318 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1319 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1320 AliReconstructor* reconstructor = GetReconstructor(iDet);
1321 if (!reconstructor) continue;
1323 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1324 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1325 TTree* clustersTree = NULL;
1326 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1327 fLoader[iDet]->LoadRecPoints("read");
1328 clustersTree = fLoader[iDet]->TreeR();
1329 if (!clustersTree) {
1330 AliError(Form("Can't get the %s clusters tree",
1331 fgkDetectorName[iDet]));
1332 if (fStopOnError) return kFALSE;
1335 if (fRawReader && !reconstructor->HasDigitConversion()) {
1336 reconstructor->FillESD(fRawReader, clustersTree, esd);
1338 TTree* digitsTree = NULL;
1339 if (fLoader[iDet]) {
1340 fLoader[iDet]->LoadDigits("read");
1341 digitsTree = fLoader[iDet]->TreeD();
1343 AliError(Form("Can't get the %s digits tree",
1344 fgkDetectorName[iDet]));
1345 if (fStopOnError) return kFALSE;
1348 reconstructor->FillESD(digitsTree, clustersTree, esd);
1349 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1351 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1352 fLoader[iDet]->UnloadRecPoints();
1356 reconstructor->FillESD(fRunLoader, fRawReader, esd);
1358 reconstructor->FillESD(fRunLoader, esd);
1360 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1364 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1365 AliError(Form("the following detectors were not found: %s",
1367 if (fStopOnError) return kFALSE;
1373 //_____________________________________________________________________________
1374 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1376 // Reads the trigger decision which is
1377 // stored in Trigger.root file and fills
1378 // the corresponding esd entries
1380 AliCodeTimerAuto("")
1382 AliInfo("Filling trigger information into the ESD");
1385 AliCTPRawStream input(fRawReader);
1386 if (!input.Next()) {
1387 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1390 esd->SetTriggerMask(input.GetClassMask());
1391 esd->SetTriggerCluster(input.GetClusterMask());
1394 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1396 if (!runloader->LoadTrigger()) {
1397 AliCentralTrigger *aCTP = runloader->GetTrigger();
1398 esd->SetTriggerMask(aCTP->GetClassMask());
1399 esd->SetTriggerCluster(aCTP->GetClusterMask());
1402 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1407 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1419 //_____________________________________________________________________________
1420 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1423 // Filling information from RawReader Header
1426 AliInfo("Filling information from RawReader Header");
1427 esd->SetBunchCrossNumber(0);
1428 esd->SetOrbitNumber(0);
1429 esd->SetPeriodNumber(0);
1430 esd->SetTimeStamp(0);
1431 esd->SetEventType(0);
1432 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1435 const UInt_t *id = eventHeader->GetP("Id");
1436 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1437 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1438 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1440 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1441 esd->SetEventType((eventHeader->Get("Type")));
1448 //_____________________________________________________________________________
1449 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1451 // check whether detName is contained in detectors
1452 // if yes, it is removed from detectors
1454 // check if all detectors are selected
1455 if ((detectors.CompareTo("ALL") == 0) ||
1456 detectors.BeginsWith("ALL ") ||
1457 detectors.EndsWith(" ALL") ||
1458 detectors.Contains(" ALL ")) {
1463 // search for the given detector
1464 Bool_t result = kFALSE;
1465 if ((detectors.CompareTo(detName) == 0) ||
1466 detectors.BeginsWith(detName+" ") ||
1467 detectors.EndsWith(" "+detName) ||
1468 detectors.Contains(" "+detName+" ")) {
1469 detectors.ReplaceAll(detName, "");
1473 // clean up the detectors string
1474 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1475 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1476 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1481 //_____________________________________________________________________________
1482 Bool_t AliReconstruction::InitRunLoader()
1484 // get or create the run loader
1486 if (gAlice) delete gAlice;
1489 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1490 // load all base libraries to get the loader classes
1491 TString libs = gSystem->GetLibraries();
1492 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1493 TString detName = fgkDetectorName[iDet];
1494 if (detName == "HLT") continue;
1495 if (libs.Contains("lib" + detName + "base.so")) continue;
1496 gSystem->Load("lib" + detName + "base.so");
1498 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1500 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1504 fRunLoader->CdGAFile();
1505 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1506 if (fRunLoader->LoadgAlice() == 0) {
1507 gAlice = fRunLoader->GetAliRun();
1508 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1511 if (!gAlice && !fRawReader) {
1512 AliError(Form("no gAlice object found in file %s",
1513 fGAliceFileName.Data()));
1518 //PH This is a temporary fix to give access to the kinematics
1519 //PH that is needed for the labels of ITS clusters
1520 fRunLoader->LoadKinematics();
1522 } else { // galice.root does not exist
1524 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1528 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1529 AliConfig::GetDefaultEventFolderName(),
1532 AliError(Form("could not create run loader in file %s",
1533 fGAliceFileName.Data()));
1537 fRunLoader->MakeTree("E");
1539 while (fRawReader->NextEvent()) {
1540 fRunLoader->SetEventNumber(iEvent);
1541 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1543 fRunLoader->MakeTree("H");
1544 fRunLoader->TreeE()->Fill();
1547 fRawReader->RewindEvents();
1548 if (fNumberOfEventsPerFile > 0)
1549 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1551 fRunLoader->SetNumberOfEventsPerFile(iEvent);
1552 fRunLoader->WriteHeader("OVERWRITE");
1553 fRunLoader->CdGAFile();
1554 fRunLoader->Write(0, TObject::kOverwrite);
1555 // AliTracker::SetFieldMap(???);
1561 //_____________________________________________________________________________
1562 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1564 // get the reconstructor object and the loader for a detector
1566 if (fReconstructor[iDet]) return fReconstructor[iDet];
1568 // load the reconstructor object
1569 TPluginManager* pluginManager = gROOT->GetPluginManager();
1570 TString detName = fgkDetectorName[iDet];
1571 TString recName = "Ali" + detName + "Reconstructor";
1572 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1574 if (detName == "HLT") {
1575 if (!gROOT->GetClass("AliLevel3")) {
1576 gSystem->Load("libAliHLTSrc.so");
1577 gSystem->Load("libAliHLTMisc.so");
1578 gSystem->Load("libAliHLTHough.so");
1579 gSystem->Load("libAliHLTComp.so");
1583 AliReconstructor* reconstructor = NULL;
1584 // first check if a plugin is defined for the reconstructor
1585 TPluginHandler* pluginHandler =
1586 pluginManager->FindHandler("AliReconstructor", detName);
1587 // if not, add a plugin for it
1588 if (!pluginHandler) {
1589 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1590 TString libs = gSystem->GetLibraries();
1591 if (libs.Contains("lib" + detName + "base.so") ||
1592 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1593 pluginManager->AddHandler("AliReconstructor", detName,
1594 recName, detName + "rec", recName + "()");
1596 pluginManager->AddHandler("AliReconstructor", detName,
1597 recName, detName, recName + "()");
1599 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1601 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1602 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1604 if (reconstructor) {
1605 TObject* obj = fOptions.FindObject(detName.Data());
1606 if (obj) reconstructor->SetOption(obj->GetTitle());
1607 reconstructor->Init(fRunLoader);
1608 fReconstructor[iDet] = reconstructor;
1611 // get or create the loader
1612 if (detName != "HLT") {
1613 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1614 if (!fLoader[iDet]) {
1615 AliConfig::Instance()
1616 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1618 // first check if a plugin is defined for the loader
1620 pluginManager->FindHandler("AliLoader", detName);
1621 // if not, add a plugin for it
1622 if (!pluginHandler) {
1623 TString loaderName = "Ali" + detName + "Loader";
1624 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1625 pluginManager->AddHandler("AliLoader", detName,
1626 loaderName, detName + "base",
1627 loaderName + "(const char*, TFolder*)");
1628 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1630 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1632 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1633 fRunLoader->GetEventFolder());
1635 if (!fLoader[iDet]) { // use default loader
1636 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1638 if (!fLoader[iDet]) {
1639 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1640 if (fStopOnError) return NULL;
1642 fRunLoader->AddLoader(fLoader[iDet]);
1643 fRunLoader->CdGAFile();
1644 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1645 fRunLoader->Write(0, TObject::kOverwrite);
1650 return reconstructor;
1653 //_____________________________________________________________________________
1654 Bool_t AliReconstruction::CreateVertexer()
1656 // create the vertexer
1659 AliReconstructor* itsReconstructor = GetReconstructor(0);
1660 if (itsReconstructor) {
1661 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1664 AliWarning("couldn't create a vertexer for ITS");
1665 if (fStopOnError) return kFALSE;
1671 //_____________________________________________________________________________
1672 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1674 // create the trackers
1676 TString detStr = detectors;
1677 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1678 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1679 AliReconstructor* reconstructor = GetReconstructor(iDet);
1680 if (!reconstructor) continue;
1681 TString detName = fgkDetectorName[iDet];
1682 if (detName == "HLT") {
1683 fRunHLTTracking = kTRUE;
1686 if (detName == "MUON") {
1687 fRunMuonTracking = kTRUE;
1692 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1693 if (!fTracker[iDet] && (iDet < 7)) {
1694 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1695 if (fStopOnError) return kFALSE;
1702 //_____________________________________________________________________________
1703 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1705 // delete trackers and the run loader and close and delete the file
1707 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1708 delete fReconstructor[iDet];
1709 fReconstructor[iDet] = NULL;
1710 fLoader[iDet] = NULL;
1711 delete fTracker[iDet];
1712 fTracker[iDet] = NULL;
1713 delete fQualAssDataMaker[iDet];
1714 fQualAssDataMaker[iDet] = NULL;
1718 delete fDiamondProfile;
1719 fDiamondProfile = NULL;
1734 gSystem->Unlink("AliESDs.old.root");
1738 //_____________________________________________________________________________
1740 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
1742 // read the ESD event from a file
1744 if (!esd) return kFALSE;
1746 sprintf(fileName, "ESD_%d.%d_%s.root",
1747 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1748 if (gSystem->AccessPathName(fileName)) return kFALSE;
1750 AliInfo(Form("reading ESD from file %s", fileName));
1751 AliDebug(1, Form("reading ESD from file %s", fileName));
1752 TFile* file = TFile::Open(fileName);
1753 if (!file || !file->IsOpen()) {
1754 AliError(Form("opening %s failed", fileName));
1761 esd = (AliESDEvent*) file->Get("ESD");
1770 //_____________________________________________________________________________
1771 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
1773 // write the ESD event to a file
1777 sprintf(fileName, "ESD_%d.%d_%s.root",
1778 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1780 AliDebug(1, Form("writing ESD to file %s", fileName));
1781 TFile* file = TFile::Open(fileName, "recreate");
1782 if (!file || !file->IsOpen()) {
1783 AliError(Form("opening %s failed", fileName));
1795 //_____________________________________________________________________________
1796 void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
1798 // write all files from the given esd file to an aod file
1800 // create an AliAOD object
1801 AliAODEvent *aod = new AliAODEvent();
1802 aod->CreateStdContent();
1808 TTree *aodTree = new TTree("aodTree", "AliAOD tree");
1809 aodTree->Branch(aod->GetList());
1812 TTree *t = (TTree*) esdFile->Get("esdTree");
1813 AliESDEvent *esd = new AliESDEvent();
1814 esd->ReadFromTree(t);
1816 Int_t nEvents = t->GetEntries();
1818 // set arrays and pointers
1826 // loop over events and fill them
1827 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
1828 t->GetEntry(iEvent);
1830 // Multiplicity information needed by the header (to be revised!)
1831 Int_t nTracks = esd->GetNumberOfTracks();
1832 Int_t nPosTracks = 0;
1833 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack)
1834 if (esd->GetTrack(iTrack)->Charge()> 0) nPosTracks++;
1836 // Access the header
1837 AliAODHeader *header = aod->GetHeader();
1840 header->SetRunNumber (esd->GetRunNumber() );
1841 header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
1842 header->SetOrbitNumber (esd->GetOrbitNumber() );
1843 header->SetPeriodNumber (esd->GetPeriodNumber() );
1844 header->SetTriggerMask (esd->GetTriggerMask() );
1845 header->SetTriggerCluster (esd->GetTriggerCluster() );
1846 header->SetEventType (esd->GetEventType() );
1847 header->SetMagneticField (esd->GetMagneticField() );
1848 header->SetZDCN1Energy (esd->GetZDCN1Energy() );
1849 header->SetZDCP1Energy (esd->GetZDCP1Energy() );
1850 header->SetZDCN2Energy (esd->GetZDCN2Energy() );
1851 header->SetZDCP2Energy (esd->GetZDCP2Energy() );
1852 header->SetZDCEMEnergy (esd->GetZDCEMEnergy() );
1853 header->SetRefMultiplicity (nTracks);
1854 header->SetRefMultiplicityPos(nPosTracks);
1855 header->SetRefMultiplicityNeg(nTracks - nPosTracks);
1856 header->SetMuonMagFieldScale(-999.); // FIXME
1857 header->SetCentrality(-999.); // FIXME
1859 Int_t nV0s = esd->GetNumberOfV0s();
1860 Int_t nCascades = esd->GetNumberOfCascades();
1861 Int_t nKinks = esd->GetNumberOfKinks();
1862 Int_t nVertices = nV0s + nCascades + nKinks;
1864 aod->ResetStd(nTracks, nVertices);
1865 AliAODTrack *aodTrack;
1867 // Array to take into account the tracks already added to the AOD
1868 Bool_t * usedTrack = NULL;
1870 usedTrack = new Bool_t[nTracks];
1871 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
1873 // Array to take into account the V0s already added to the AOD
1874 Bool_t * usedV0 = NULL;
1876 usedV0 = new Bool_t[nV0s];
1877 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
1879 // Array to take into account the kinks already added to the AOD
1880 Bool_t * usedKink = NULL;
1882 usedKink = new Bool_t[nKinks];
1883 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
1886 // Access to the AOD container of vertices
1887 TClonesArray &vertices = *(aod->GetVertices());
1890 // Access to the AOD container of tracks
1891 TClonesArray &tracks = *(aod->GetTracks());
1894 // Add primary vertex. The primary tracks will be defined
1895 // after the loops on the composite objects (V0, cascades, kinks)
1896 const AliESDVertex *vtx = esd->GetPrimaryVertex();
1898 vtx->GetXYZ(pos); // position
1899 vtx->GetCovMatrix(covVtx); //covariance matrix
1901 AliAODVertex * primary = new(vertices[jVertices++])
1902 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);
1904 // Create vertices starting from the most complex objects
1907 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
1908 AliESDcascade *cascade = esd->GetCascade(nCascade);
1910 cascade->GetXYZ(pos[0], pos[1], pos[2]);
1911 cascade->GetPosCovXi(covVtx);
1913 // Add the cascade vertex
1914 AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
1916 cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
1919 AliAODVertex::kCascade);
1921 primary->AddDaughter(vcascade);
1923 // Add the V0 from the cascade. The ESD class have to be optimized...
1924 // Now we have to search for the corresponding V0 in the list of V0s
1925 // using the indeces of the positive and negative tracks
1927 Int_t posFromV0 = cascade->GetPindex();
1928 Int_t negFromV0 = cascade->GetNindex();
1931 AliESDv0 * v0 = 0x0;
1934 for (Int_t iV0=0; iV0<nV0s; ++iV0) {
1936 v0 = esd->GetV0(iV0);
1937 Int_t posV0 = v0->GetPindex();
1938 Int_t negV0 = v0->GetNindex();
1940 if (posV0==posFromV0 && negV0==negFromV0) {
1946 AliAODVertex * vV0FromCascade = 0x0;
1948 if (indV0>-1 && !usedV0[indV0] ) {
1950 // the V0 exists in the array of V0s and is not used
1952 usedV0[indV0] = kTRUE;
1954 v0->GetXYZ(pos[0], pos[1], pos[2]);
1955 v0->GetPosCov(covVtx);
1957 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
1959 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
1965 // the V0 doesn't exist in the array of V0s or was used
1966 cerr << "Error: event " << iEvent << " cascade " << nCascade
1967 << " The V0 " << indV0
1968 << " doesn't exist in the array of V0s or was used!" << endl;
1970 cascade->GetXYZ(pos[0], pos[1], pos[2]);
1971 cascade->GetPosCov(covVtx);
1973 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
1975 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
1979 vcascade->AddDaughter(vV0FromCascade);
1982 // Add the positive tracks from the V0
1984 if (! usedTrack[posFromV0]) {
1986 usedTrack[posFromV0] = kTRUE;
1988 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
1989 esdTrack->GetPxPyPz(p);
1990 esdTrack->GetXYZ(pos);
1991 esdTrack->GetCovarianceXYZPxPyPz(covTr);
1992 esdTrack->GetESDpid(pid);
1994 vV0FromCascade->AddDaughter(aodTrack =
1995 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
1996 esdTrack->GetLabel(),
2002 (Short_t)esdTrack->Charge(),
2003 esdTrack->GetITSClusterMap(),
2006 kTRUE, // check if this is right
2007 kFALSE, // check if this is right
2008 AliAODTrack::kSecondary)
2010 aodTrack->ConvertAliPIDtoAODPID();
2013 cerr << "Error: event " << iEvent << " cascade " << nCascade
2014 << " track " << posFromV0 << " has already been used!" << endl;
2017 // Add the negative tracks from the V0
2019 if (!usedTrack[negFromV0]) {
2021 usedTrack[negFromV0] = kTRUE;
2023 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2024 esdTrack->GetPxPyPz(p);
2025 esdTrack->GetXYZ(pos);
2026 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2027 esdTrack->GetESDpid(pid);
2029 vV0FromCascade->AddDaughter(aodTrack =
2030 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2031 esdTrack->GetLabel(),
2037 (Short_t)esdTrack->Charge(),
2038 esdTrack->GetITSClusterMap(),
2041 kTRUE, // check if this is right
2042 kFALSE, // check if this is right
2043 AliAODTrack::kSecondary)
2045 aodTrack->ConvertAliPIDtoAODPID();
2048 cerr << "Error: event " << iEvent << " cascade " << nCascade
2049 << " track " << negFromV0 << " has already been used!" << endl;
2052 // Add the bachelor track from the cascade
2054 Int_t bachelor = cascade->GetBindex();
2056 if(!usedTrack[bachelor]) {
2058 usedTrack[bachelor] = kTRUE;
2060 AliESDtrack *esdTrack = esd->GetTrack(bachelor);
2061 esdTrack->GetPxPyPz(p);
2062 esdTrack->GetXYZ(pos);
2063 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2064 esdTrack->GetESDpid(pid);
2066 vcascade->AddDaughter(aodTrack =
2067 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2068 esdTrack->GetLabel(),
2074 (Short_t)esdTrack->Charge(),
2075 esdTrack->GetITSClusterMap(),
2078 kTRUE, // check if this is right
2079 kFALSE, // check if this is right
2080 AliAODTrack::kSecondary)
2082 aodTrack->ConvertAliPIDtoAODPID();
2085 cerr << "Error: event " << iEvent << " cascade " << nCascade
2086 << " track " << bachelor << " has already been used!" << endl;
2089 // Add the primary track of the cascade (if any)
2091 } // end of the loop on cascades
2095 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
2097 if (usedV0[nV0]) continue; // skip if aready added to the AOD
2099 AliESDv0 *v0 = esd->GetV0(nV0);
2101 v0->GetXYZ(pos[0], pos[1], pos[2]);
2102 v0->GetPosCov(covVtx);
2104 AliAODVertex * vV0 =
2105 new(vertices[jVertices++]) AliAODVertex(pos,
2107 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2111 primary->AddDaughter(vV0);
2113 Int_t posFromV0 = v0->GetPindex();
2114 Int_t negFromV0 = v0->GetNindex();
2116 // Add the positive tracks from the V0
2118 if (!usedTrack[posFromV0]) {
2120 usedTrack[posFromV0] = kTRUE;
2122 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2123 esdTrack->GetPxPyPz(p);
2124 esdTrack->GetXYZ(pos);
2125 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2126 esdTrack->GetESDpid(pid);
2128 vV0->AddDaughter(aodTrack =
2129 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2130 esdTrack->GetLabel(),
2136 (Short_t)esdTrack->Charge(),
2137 esdTrack->GetITSClusterMap(),
2140 kTRUE, // check if this is right
2141 kFALSE, // check if this is right
2142 AliAODTrack::kSecondary)
2144 aodTrack->ConvertAliPIDtoAODPID();
2147 cerr << "Error: event " << iEvent << " V0 " << nV0
2148 << " track " << posFromV0 << " has already been used!" << endl;
2151 // Add the negative tracks from the V0
2153 if (!usedTrack[negFromV0]) {
2155 usedTrack[negFromV0] = kTRUE;
2157 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2158 esdTrack->GetPxPyPz(p);
2159 esdTrack->GetXYZ(pos);
2160 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2161 esdTrack->GetESDpid(pid);
2163 vV0->AddDaughter(aodTrack =
2164 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2165 esdTrack->GetLabel(),
2171 (Short_t)esdTrack->Charge(),
2172 esdTrack->GetITSClusterMap(),
2175 kTRUE, // check if this is right
2176 kFALSE, // check if this is right
2177 AliAODTrack::kSecondary)
2179 aodTrack->ConvertAliPIDtoAODPID();
2182 cerr << "Error: event " << iEvent << " V0 " << nV0
2183 << " track " << negFromV0 << " has already been used!" << endl;
2186 } // end of the loop on V0s
2188 // Kinks: it is a big mess the access to the information in the kinks
2189 // The loop is on the tracks in order to find the mother and daugther of each kink
2192 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2195 AliESDtrack * esdTrack = esd->GetTrack(iTrack);
2197 Int_t ikink = esdTrack->GetKinkIndex(0);
2200 // Negative kink index: mother, positive: daughter
2202 // Search for the second track of the kink
2204 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
2206 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
2208 Int_t jkink = esdTrack1->GetKinkIndex(0);
2210 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
2212 // The two tracks are from the same kink
2214 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
2217 Int_t idaughter = -1;
2219 if (ikink<0 && jkink>0) {
2224 else if (ikink>0 && jkink<0) {
2230 cerr << "Error: Wrong combination of kink indexes: "
2231 << ikink << " " << jkink << endl;
2235 // Add the mother track
2237 AliAODTrack * mother = NULL;
2239 if (!usedTrack[imother]) {
2241 usedTrack[imother] = kTRUE;
2243 AliESDtrack *esdTrack = esd->GetTrack(imother);
2244 esdTrack->GetPxPyPz(p);
2245 esdTrack->GetXYZ(pos);
2246 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2247 esdTrack->GetESDpid(pid);
2250 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2251 esdTrack->GetLabel(),
2257 (Short_t)esdTrack->Charge(),
2258 esdTrack->GetITSClusterMap(),
2261 kTRUE, // check if this is right
2262 kTRUE, // check if this is right
2263 AliAODTrack::kPrimary);
2264 primary->AddDaughter(mother);
2265 mother->ConvertAliPIDtoAODPID();
2268 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2269 << " track " << imother << " has already been used!" << endl;
2272 // Add the kink vertex
2273 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
2275 AliAODVertex * vkink =
2276 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
2280 esdTrack->GetID(), // This is the track ID of the mother's track!
2281 AliAODVertex::kKink);
2282 // Add the daughter track
2284 AliAODTrack * daughter = NULL;
2286 if (!usedTrack[idaughter]) {
2288 usedTrack[idaughter] = kTRUE;
2290 AliESDtrack *esdTrack = esd->GetTrack(idaughter);
2291 esdTrack->GetPxPyPz(p);
2292 esdTrack->GetXYZ(pos);
2293 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2294 esdTrack->GetESDpid(pid);
2297 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2298 esdTrack->GetLabel(),
2304 (Short_t)esdTrack->Charge(),
2305 esdTrack->GetITSClusterMap(),
2308 kTRUE, // check if this is right
2309 kTRUE, // check if this is right
2310 AliAODTrack::kPrimary);
2311 vkink->AddDaughter(daughter);
2312 daughter->ConvertAliPIDtoAODPID();
2315 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2316 << " track " << idaughter << " has already been used!" << endl;
2328 // Tracks (primary and orphan)
2330 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
2333 if (usedTrack[nTrack]) continue;
2335 AliESDtrack *esdTrack = esd->GetTrack(nTrack);
2336 esdTrack->GetPxPyPz(p);
2337 esdTrack->GetXYZ(pos);
2338 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2339 esdTrack->GetESDpid(pid);
2341 Float_t impactXY, impactZ;
2343 esdTrack->GetImpactParameters(impactXY,impactZ);
2346 // track inside the beam pipe
2348 primary->AddDaughter(aodTrack =
2349 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2350 esdTrack->GetLabel(),
2356 (Short_t)esdTrack->Charge(),
2357 esdTrack->GetITSClusterMap(),
2360 kTRUE, // check if this is right
2361 kTRUE, // check if this is right
2362 AliAODTrack::kPrimary)
2364 aodTrack->ConvertAliPIDtoAODPID();
2367 // outside the beam pipe: orphan track
2369 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2370 esdTrack->GetLabel(),
2376 (Short_t)esdTrack->Charge(),
2377 esdTrack->GetITSClusterMap(),
2380 kFALSE, // check if this is right
2381 kFALSE, // check if this is right
2382 AliAODTrack::kOrphan);
2383 aodTrack->ConvertAliPIDtoAODPID();
2385 } // end of loop on tracks
2388 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
2389 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
2391 AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);
2392 p[0] = esdMuTrack->Px();
2393 p[1] = esdMuTrack->Py();
2394 p[2] = esdMuTrack->Pz();
2395 pos[0] = primary->GetX();
2396 pos[1] = primary->GetY();
2397 pos[2] = primary->GetZ();
2399 // has to be changed once the muon pid is provided by the ESD
2400 for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
2402 primary->AddDaughter(aodTrack =
2403 new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
2404 0, // no label provided
2409 NULL, // no covariance matrix provided
2410 esdMuTrack->Charge(),
2411 0, // ITSClusterMap is set below
2414 kFALSE, // muon tracks are not used to fit the primary vtx
2415 kFALSE, // not used for vertex fit
2416 AliAODTrack::kPrimary)
2419 aodTrack->SetHitsPatternInTrigCh(esdMuTrack->GetHitsPatternInTrigCh());
2420 Int_t track2Trigger = esdMuTrack->GetMatchTrigger();
2421 aodTrack->SetMatchTrigger(track2Trigger);
2423 aodTrack->SetChi2MatchTrigger(esdMuTrack->GetChi2MatchTrigger());
2425 aodTrack->SetChi2MatchTrigger(0.);
2428 // Access to the AOD container of clusters
2429 TClonesArray &clusters = *(aod->GetClusters());
2433 Int_t nClusters = esd->GetNumberOfCaloClusters();
2435 for (Int_t iClust=0; iClust<nClusters; ++iClust) {
2437 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
2439 Int_t id = cluster->GetID();
2441 Float_t energy = cluster->E();
2442 cluster->GetPosition(posF);
2443 AliAODVertex *prodVertex = primary;
2444 AliAODTrack *primTrack = NULL;
2445 Char_t ttype=AliAODCluster::kUndef;
2447 if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral;
2448 else if (cluster->IsEMCAL()) {
2450 if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster)
2451 ttype = AliAODCluster::kEMCALPseudoCluster;
2453 ttype = AliAODCluster::kEMCALClusterv1;
2457 new(clusters[jClusters++]) AliAODCluster(id,
2461 NULL, // no covariance matrix provided
2462 NULL, // no pid for clusters provided
2467 } // end of loop on calo clusters
2470 const AliMultiplicity *mult = esd->GetMultiplicity();
2472 if (mult->GetNumberOfTracklets()>0) {
2473 aod->GetTracklets()->CreateContainer(mult->GetNumberOfTracklets());
2475 for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {
2476 aod->GetTracklets()->SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n));
2480 Printf("ERROR: AliMultiplicity could not be retrieved from ESD");
2483 delete [] usedTrack;
2487 // fill the tree for this event
2489 } // end of event loop
2491 aodTree->GetUserInfo()->Add(aod);
2496 // write the tree to the specified file
2497 aodFile = aodTree->GetCurrentFile();
2504 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2506 // Write space-points which are then used in the alignment procedures
2507 // For the moment only ITS, TRD and TPC
2509 // Load TOF clusters
2511 fLoader[3]->LoadRecPoints("read");
2512 TTree* tree = fLoader[3]->TreeR();
2514 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2517 fTracker[3]->LoadClusters(tree);
2519 Int_t ntracks = esd->GetNumberOfTracks();
2520 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2522 AliESDtrack *track = esd->GetTrack(itrack);
2525 for (Int_t iDet = 3; iDet >= 0; iDet--)
2526 nsp += track->GetNcls(iDet);
2528 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2529 track->SetTrackPointArray(sp);
2531 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2532 AliTracker *tracker = fTracker[iDet];
2533 if (!tracker) continue;
2534 Int_t nspdet = track->GetNcls(iDet);
2535 if (nspdet <= 0) continue;
2536 track->GetClusters(iDet,idx);
2540 while (isp < nspdet) {
2541 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
2542 const Int_t kNTPCmax = 159;
2543 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2544 if (!isvalid) continue;
2545 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2551 fTracker[3]->UnloadClusters();
2552 fLoader[3]->UnloadRecPoints();
2556 //_____________________________________________________________________________
2557 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2559 // The method reads the raw-data error log
2560 // accumulated within the rawReader.
2561 // It extracts the raw-data errors related to
2562 // the current event and stores them into
2563 // a TClonesArray inside the esd object.
2565 if (!fRawReader) return;
2567 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2569 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2571 if (iEvent != log->GetEventNumber()) continue;
2573 esd->AddRawDataErrorLog(log);
2578 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2579 // Dump a file content into a char in TNamed
2581 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2582 Int_t kBytes = (Int_t)in.tellg();
2583 printf("Size: %d \n",kBytes);
2586 char* memblock = new char [kBytes];
2587 in.seekg (0, ios::beg);
2588 in.read (memblock, kBytes);
2590 TString fData(memblock,kBytes);
2591 fn = new TNamed(fName,fData);
2592 printf("fData Size: %d \n",fData.Sizeof());
2593 printf("fName Size: %d \n",fName.Sizeof());
2594 printf("fn Size: %d \n",fn->Sizeof());
2598 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2604 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2605 // This is not really needed in AliReconstruction at the moment
2606 // but can serve as a template
2608 TList *fList = fTree->GetUserInfo();
2609 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2610 printf("fn Size: %d \n",fn->Sizeof());
2612 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2613 const char* cdata = fn->GetTitle();
2614 printf("fTmp Size %d\n",fTmp.Sizeof());
2616 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2617 printf("calculated size %d\n",size);
2618 ofstream out(fName.Data(),ios::out | ios::binary);
2619 out.write(cdata,size);
2624 //_____________________________________________________________________________
2625 AliQualAssDataMaker * AliReconstruction::GetQualAssDataMaker(Int_t iDet)
2627 // get the quality assurance data maker object and the loader for a detector
2629 if (fQualAssDataMaker[iDet])
2630 return fQualAssDataMaker[iDet];
2632 // load the QA data maker object
2633 TPluginManager* pluginManager = gROOT->GetPluginManager();
2634 TString detName = fgkDetectorName[iDet];
2635 TString qadmName = "Ali" + detName + "QualAssDataMaker";
2636 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT"))
2639 AliQualAssDataMaker * qadm = NULL;
2640 // first check if a plugin is defined for the quality assurance data maker
2641 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQualAssDataMaker", detName);
2642 // if not, add a plugin for it
2643 if (!pluginHandler) {
2644 AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2645 TString libs = gSystem->GetLibraries();
2646 if (libs.Contains("lib" + detName + "base.so") ||
2647 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2648 pluginManager->AddHandler("AliQualAssDataMaker", detName,
2649 qadmName, detName + "qadm", qadmName + "()");
2651 pluginManager->AddHandler("AliQualAssDataMaker", detName,
2652 qadmName, detName, qadmName + "()");
2654 pluginHandler = pluginManager->FindHandler("AliQualAssDataMaker", detName);
2656 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2657 qadm = (AliQualAssDataMaker *) pluginHandler->ExecPlugin(0);
2660 // TObject* obj = fOptions.FindObject(detName.Data());
2661 // if (obj) reconstructor->SetOption(obj->GetTitle());
2662 fQualAssDataMaker[iDet] = qadm;
2665 // get or create the loader
2666 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2667 if (!fLoader[iDet]) {
2668 AliConfig::Instance()
2669 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2671 // first check if a plugin is defined for the loader
2673 pluginManager->FindHandler("AliLoader", detName);
2674 // if not, add a plugin for it
2675 if (!pluginHandler) {
2676 TString loaderName = "Ali" + detName + "Loader";
2677 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2678 pluginManager->AddHandler("AliLoader", detName,
2679 loaderName, detName + "base",
2680 loaderName + "(const char*, TFolder*)");
2681 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2683 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2685 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2686 fRunLoader->GetEventFolder());
2688 if (!fLoader[iDet]) { // use default loader
2689 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2691 if (!fLoader[iDet]) {
2692 AliWarning(Form("couldn't get loader for %s", detName.Data()));
2693 if (fStopOnError) return NULL;
2695 fRunLoader->AddLoader(fLoader[iDet]);
2696 fRunLoader->CdGAFile();
2697 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2698 fRunLoader->Write(0, TObject::kOverwrite);
2705 //_____________________________________________________________________________
2706 Bool_t AliReconstruction::RunQualAss(const char* detectors, AliESDEvent *& esd)
2708 // run the Quality Assurance data producer
2710 AliCodeTimerAuto("")
2711 TString detStr = detectors;
2712 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2713 if (!IsSelected(fgkDetectorName[iDet], detStr))
2715 AliQualAssDataMaker * qadm = GetQualAssDataMaker(iDet);
2718 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2719 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2721 qadm->SetData(esd) ;
2722 qadm->Exec(AliQualAss::kESDS) ;
2724 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2726 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2727 AliError(Form("the following detectors were not found: %s",