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 ///////////////////////////////////////////////////////////////////////////////
122 #include <TPluginManager.h>
123 #include <TGeoManager.h>
124 #include <TLorentzVector.h>
128 #include "AliReconstruction.h"
129 #include "AliCodeTimer.h"
130 #include "AliReconstructor.h"
132 #include "AliRunLoader.h"
134 #include "AliRawReaderFile.h"
135 #include "AliRawReaderDate.h"
136 #include "AliRawReaderRoot.h"
137 #include "AliRawEventHeaderBase.h"
138 #include "AliESDEvent.h"
139 #include "AliESDMuonTrack.h"
140 #include "AliESDfriend.h"
141 #include "AliESDVertex.h"
142 #include "AliESDcascade.h"
143 #include "AliESDkink.h"
144 #include "AliESDtrack.h"
145 #include "AliESDCaloCluster.h"
146 #include "AliMultiplicity.h"
147 #include "AliTracker.h"
148 #include "AliVertexer.h"
149 #include "AliVertexerTracks.h"
150 #include "AliV0vertexer.h"
151 #include "AliCascadeVertexer.h"
152 #include "AliHeader.h"
153 #include "AliGenEventHeader.h"
155 #include "AliESDpid.h"
156 #include "AliESDtrack.h"
157 #include "AliESDPmdTrack.h"
159 #include "AliESDTagCreator.h"
160 #include "AliAODTagCreator.h"
162 #include "AliGeomManager.h"
163 #include "AliTrackPointArray.h"
164 #include "AliCDBManager.h"
165 #include "AliCDBEntry.h"
166 #include "AliAlignObj.h"
168 #include "AliCentralTrigger.h"
169 #include "AliCTPRawStream.h"
171 #include "AliAODEvent.h"
172 #include "AliAODHeader.h"
173 #include "AliAODTrack.h"
174 #include "AliAODVertex.h"
175 #include "AliAODv0.h"
176 #include "AliAODJet.h"
177 #include "AliAODCaloCells.h"
178 #include "AliAODCaloCluster.h"
179 #include "AliAODPmdCluster.h"
180 #include "AliAODFmdCluster.h"
181 #include "AliAODTracklets.h"
183 //#include "AliQADataMaker.h"
185 #include "AliQADataMakerSteer.h"
187 #include "AliSysInfo.h" // memory snapshots
190 ClassImp(AliReconstruction)
193 //_____________________________________________________________________________
194 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
196 //_____________________________________________________________________________
197 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
198 const char* name, const char* title) :
201 fUniformField(kTRUE),
202 fRunVertexFinder(kTRUE),
203 fRunHLTTracking(kFALSE),
204 fRunMuonTracking(kFALSE),
206 fRunCascadeFinder(kTRUE),
207 fStopOnError(kFALSE),
208 fWriteAlignmentData(kFALSE),
209 fWriteESDfriend(kFALSE),
211 fFillTriggerESD(kTRUE),
217 fRunLocalReconstruction("ALL"),
220 fUseTrackingErrorsForAlignment(""),
221 fGAliceFileName(gAliceFilename),
226 fNumberOfEventsPerFile(1),
229 fLoadAlignFromCDB(kTRUE),
230 fLoadAlignData("ALL"),
237 fDiamondProfile(NULL),
241 fAlignObjArray(NULL),
246 // create reconstruction object with default parameters
248 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
249 fReconstructor[iDet] = NULL;
250 fLoader[iDet] = NULL;
251 fTracker[iDet] = NULL;
252 // fQADataMaker[iDet] = NULL;
253 // fQACycles[iDet] = 999999;
258 //_____________________________________________________________________________
259 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
262 fUniformField(rec.fUniformField),
263 fRunVertexFinder(rec.fRunVertexFinder),
264 fRunHLTTracking(rec.fRunHLTTracking),
265 fRunMuonTracking(rec.fRunMuonTracking),
266 fRunV0Finder(rec.fRunV0Finder),
267 fRunCascadeFinder(rec.fRunCascadeFinder),
268 fStopOnError(rec.fStopOnError),
269 fWriteAlignmentData(rec.fWriteAlignmentData),
270 fWriteESDfriend(rec.fWriteESDfriend),
271 fWriteAOD(rec.fWriteAOD),
272 fFillTriggerESD(rec.fFillTriggerESD),
274 fCleanESD(rec.fCleanESD),
278 fRunLocalReconstruction(rec.fRunLocalReconstruction),
279 fRunTracking(rec.fRunTracking),
280 fFillESD(rec.fFillESD),
281 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
282 fGAliceFileName(rec.fGAliceFileName),
284 fEquipIdMap(rec.fEquipIdMap),
285 fFirstEvent(rec.fFirstEvent),
286 fLastEvent(rec.fLastEvent),
287 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
290 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
291 fLoadAlignData(rec.fLoadAlignData),
292 fESDPar(rec.fESDPar),
298 fDiamondProfile(NULL),
302 fAlignObjArray(rec.fAlignObjArray),
303 fCDBUri(rec.fCDBUri),
304 fRemoteCDBUri(rec.fRemoteCDBUri),
309 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
310 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
312 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
313 fReconstructor[iDet] = NULL;
314 fLoader[iDet] = NULL;
315 fTracker[iDet] = NULL;
316 // fQADataMaker[iDet] = NULL;
317 // fQACycles[iDet] = rec.fQACycles[iDet];
319 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
320 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
324 //_____________________________________________________________________________
325 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
327 // assignment operator
329 this->~AliReconstruction();
330 new(this) AliReconstruction(rec);
334 //_____________________________________________________________________________
335 AliReconstruction::~AliReconstruction()
341 fSpecCDBUri.Delete();
343 AliCodeTimer::Instance()->Print();
346 //_____________________________________________________________________________
347 void AliReconstruction::InitCDBStorage()
349 // activate a default CDB storage
350 // First check if we have any CDB storage set, because it is used
351 // to retrieve the calibration and alignment constants
353 AliCDBManager* man = AliCDBManager::Instance();
354 if (man->IsDefaultStorageSet())
356 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
357 AliWarning("Default CDB storage has been already set !");
358 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
359 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
363 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
364 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
365 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
366 man->SetDefaultStorage(fCDBUri);
369 // Remote storage (the Grid storage) is used if it is activated
370 // and if the object is not found in the default storage
372 // if (man->IsRemoteStorageSet())
374 // AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
375 // AliWarning("Remote CDB storage has been already set !");
376 // AliWarning(Form("Ignoring the remote storage declared in AliReconstruction: %s",fRemoteCDBUri.Data()));
377 // AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
378 // fRemoteCDBUri = "";
381 // AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
382 // AliDebug(2, Form("Remote CDB storage is set to: %s",fRemoteCDBUri.Data()));
383 // AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
384 // man->SetRemoteStorage(fRemoteCDBUri);
387 // Now activate the detector specific CDB storage locations
388 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
389 TObject* obj = fSpecCDBUri[i];
391 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
392 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
393 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
394 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
399 //_____________________________________________________________________________
400 void AliReconstruction::SetDefaultStorage(const char* uri) {
401 // Store the desired default CDB storage location
402 // Activate it later within the Run() method
408 //_____________________________________________________________________________
409 void AliReconstruction::SetRemoteStorage(const char* uri) {
410 // Store the desired remote CDB storage location
411 // Activate it later within the Run() method
412 // Remote storage (the Grid storage) is used if it is activated
413 // and if the object is not found in the default storage
419 //_____________________________________________________________________________
420 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
421 // Store a detector-specific CDB storage location
422 // Activate it later within the Run() method
424 AliCDBPath aPath(calibType);
425 if(!aPath.IsValid()){
426 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
427 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
428 if(!strcmp(calibType, fgkDetectorName[iDet])) {
429 aPath.SetPath(Form("%s/*", calibType));
430 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
434 if(!aPath.IsValid()){
435 AliError(Form("Not a valid path or detector: %s", calibType));
440 // // check that calibType refers to a "valid" detector name
441 // Bool_t isDetector = kFALSE;
442 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
443 // TString detName = fgkDetectorName[iDet];
444 // if(aPath.GetLevel0() == detName) {
445 // isDetector = kTRUE;
451 // AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
455 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
456 if (obj) fSpecCDBUri.Remove(obj);
457 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
464 //_____________________________________________________________________________
465 Bool_t AliReconstruction::SetRunNumber()
467 // The method is called in Run() in order
468 // to set a correct run number.
469 // In case of raw data reconstruction the
470 // run number is taken from the raw data header
472 if(AliCDBManager::Instance()->GetRun() < 0) {
474 AliError("No run loader is found !");
477 // read run number from gAlice
478 if(fRunLoader->GetAliRun())
479 AliCDBManager::Instance()->SetRun(fRunLoader->GetHeader()->GetRun());
482 if(fRawReader->NextEvent()) {
483 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
484 fRawReader->RewindEvents();
487 AliError("No raw-data events found !");
492 AliError("Neither gAlice nor RawReader objects are found !");
496 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
501 //_____________________________________________________________________________
502 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
504 // Read the alignment objects from CDB.
505 // Each detector is supposed to have the
506 // alignment objects in DET/Align/Data CDB path.
507 // All the detector objects are then collected,
508 // sorted by geometry level (starting from ALIC) and
509 // then applied to the TGeo geometry.
510 // Finally an overlaps check is performed.
512 // Load alignment data from CDB and fill fAlignObjArray
513 if(fLoadAlignFromCDB){
515 TString detStr = detectors;
516 TString loadAlObjsListOfDets = "";
518 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
519 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
520 loadAlObjsListOfDets += fgkDetectorName[iDet];
521 loadAlObjsListOfDets += " ";
522 } // end loop over detectors
523 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
524 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
526 // Check if the array with alignment objects was
527 // provided by the user. If yes, apply the objects
528 // to the present TGeo geometry
529 if (fAlignObjArray) {
530 if (gGeoManager && gGeoManager->IsClosed()) {
531 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
532 AliError("The misalignment of one or more volumes failed!"
533 "Compare the list of simulated detectors and the list of detector alignment data!");
538 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
544 delete fAlignObjArray; fAlignObjArray=0;
549 //_____________________________________________________________________________
550 void AliReconstruction::SetGAliceFile(const char* fileName)
552 // set the name of the galice file
554 fGAliceFileName = fileName;
557 //_____________________________________________________________________________
558 void AliReconstruction::SetOption(const char* detector, const char* option)
560 // set options for the reconstruction of a detector
562 TObject* obj = fOptions.FindObject(detector);
563 if (obj) fOptions.Remove(obj);
564 fOptions.Add(new TNamed(detector, option));
568 //_____________________________________________________________________________
569 Bool_t AliReconstruction::Run(const char* input)
571 // run the reconstruction
576 if (!input) input = fInput.Data();
577 TString fileName(input);
578 if (fileName.EndsWith("/")) {
579 fRawReader = new AliRawReaderFile(fileName);
580 } else if (fileName.EndsWith(".root")) {
581 fRawReader = new AliRawReaderRoot(fileName);
582 } else if (!fileName.IsNull()) {
583 fRawReader = new AliRawReaderDate(fileName);
584 fRawReader->SelectEvents(7);
586 if (!fEquipIdMap.IsNull() && fRawReader)
587 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
589 AliSysInfo::AddStamp("Start");
590 // get the run loader
591 if (!InitRunLoader()) return kFALSE;
592 AliSysInfo::AddStamp("LoadLoader");
594 // Initialize the CDB storage
596 AliSysInfo::AddStamp("LoadCDB");
598 // Set run number in CDBManager (if it is not already set by the user)
599 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
601 // Import ideal TGeo geometry and apply misalignment
603 TString geom(gSystem->DirName(fGAliceFileName));
604 geom += "/geometry.root";
605 AliGeomManager::LoadGeometry(geom.Data());
606 if (!gGeoManager) if (fStopOnError) return kFALSE;
609 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
610 AliSysInfo::AddStamp("LoadGeom");
612 // local reconstruction
613 if (!fRunLocalReconstruction.IsNull()) {
614 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
615 if (fStopOnError) {CleanUp(); return kFALSE;}
618 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
619 // fFillESD.IsNull()) return kTRUE;
622 if (fRunVertexFinder && !CreateVertexer()) {
628 AliSysInfo::AddStamp("Vertexer");
631 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
637 AliSysInfo::AddStamp("LoadTrackers");
639 // get the possibly already existing ESD file and tree
640 AliESDEvent* esd = new AliESDEvent(); AliESDEvent* hltesd = new AliESDEvent();
641 TFile* fileOld = NULL;
642 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
643 if (!gSystem->AccessPathName("AliESDs.root")){
644 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
645 fileOld = TFile::Open("AliESDs.old.root");
646 if (fileOld && fileOld->IsOpen()) {
647 treeOld = (TTree*) fileOld->Get("esdTree");
648 if (treeOld)esd->ReadFromTree(treeOld);
649 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
650 if (hlttreeOld) hltesd->ReadFromTree(hlttreeOld);
654 // create the ESD output file and tree
655 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
656 file->SetCompressionLevel(2);
657 if (!file->IsOpen()) {
658 AliError("opening AliESDs.root failed");
659 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
662 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
663 esd = new AliESDEvent();
664 esd->CreateStdContent();
665 esd->WriteToTree(tree);
667 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
668 hltesd = new AliESDEvent();
669 hltesd->CreateStdContent();
670 hltesd->WriteToTree(hlttree);
673 delete esd; delete hltesd;
674 esd = NULL; hltesd = NULL;
676 // create the branch with ESD additions
680 AliESDfriend *esdf = 0;
681 if (fWriteESDfriend) {
682 esdf = new AliESDfriend();
683 TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
684 br->SetFile("AliESDfriends.root");
685 esd->AddObject(esdf);
689 // Get the GRP CDB entry
690 AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
693 fGRPList = dynamic_cast<TList*> (entryGRP->GetObject());
695 AliError("No GRP entry found in OCDB!");
698 // Get the diamond profile from OCDB
699 AliCDBEntry* entry = AliCDBManager::Instance()
700 ->Get("GRP/Calib/MeanVertex");
703 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
705 AliError("No diamond profile found in OCDB!");
708 AliVertexerTracks tVertexer(AliTracker::GetBz());
709 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
713 if (fRawReader) fRawReader->RewindEvents();
714 TString detStr(fFillESD) ;
717 gSystem->GetProcInfo(&ProcInfo);
718 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
720 // checking the QA of previous steps
723 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
724 if (fRawReader) fRawReader->NextEvent();
725 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
726 // copy old ESD to the new one
728 esd->ReadFromTree(treeOld);
729 treeOld->GetEntry(iEvent);
733 esd->ReadFromTree(hlttreeOld);
734 hlttreeOld->GetEntry(iEvent);
740 AliInfo(Form("processing event %d", iEvent));
741 fRunLoader->GetEvent(iEvent);
744 sprintf(aFileName, "ESD_%d.%d_final.root",
745 fRunLoader->GetHeader()->GetRun(),
746 fRunLoader->GetHeader()->GetEventNrInRun());
747 if (!gSystem->AccessPathName(aFileName)) continue;
749 // local reconstruction
750 if (!fRunLocalReconstruction.IsNull()) {
751 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
752 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
757 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
758 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
759 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
760 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
762 // Set magnetic field from the tracker
763 esd->SetMagneticField(AliTracker::GetBz());
764 hltesd->SetMagneticField(AliTracker::GetBz());
768 // Fill raw-data error log into the ESD
769 if (fRawReader) FillRawDataErrorLog(iEvent,esd);
772 if (fRunVertexFinder) {
773 if (!ReadESD(esd, "vertex")) {
774 if (!RunVertexFinder(esd)) {
775 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
777 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
782 if (!fRunTracking.IsNull()) {
783 if (fRunHLTTracking) {
784 hltesd->SetVertex(esd->GetVertex());
785 if (!RunHLTTracking(hltesd)) {
786 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
792 if (!fRunTracking.IsNull()) {
793 if (fRunMuonTracking) {
794 if (!RunMuonTracking(esd)) {
795 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
801 if (!fRunTracking.IsNull()) {
802 if (!ReadESD(esd, "tracking")) {
803 if (!RunTracking(esd)) {
804 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
806 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
811 if (!fFillESD.IsNull()) {
812 if (!FillESD(esd, fFillESD)) {
813 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
817 // if (!fFillESD.IsNull())
818 // RunQA(fFillESD.Data(), esd);
820 // fill Event header information from the RawEventHeader
821 if (fRawReader){FillRawEventHeaderESD(esd);}
824 AliESDpid::MakePID(esd);
825 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
827 if (fFillTriggerESD) {
828 if (!ReadESD(esd, "trigger")) {
829 if (!FillTriggerESD(esd)) {
830 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
832 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
838 //Try to improve the reconstructed primary vertex position using the tracks
839 AliESDVertex *pvtx=0;
840 Bool_t dovertex=kTRUE;
841 TObject* obj = fOptions.FindObject("ITS");
843 TString optITS = obj->GetTitle();
844 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
847 if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
848 if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
851 if (pvtx->GetStatus()) {
852 // Store the improved primary vertex
853 esd->SetPrimaryVertex(pvtx);
854 // Propagate the tracks to the DCA to the improved primary vertex
855 Double_t somethingbig = 777.;
856 Double_t bz = esd->GetMagneticField();
857 Int_t nt=esd->GetNumberOfTracks();
859 AliESDtrack *t = esd->GetTrack(nt);
860 t->RelateToVertex(pvtx, bz, somethingbig);
867 vtxer.Tracks2V0vertices(esd);
869 if (fRunCascadeFinder) {
871 AliCascadeVertexer cvtxer;
872 cvtxer.V0sTracks2CascadeVertices(esd);
877 if (fCleanESD) CleanESD(esd);
878 if (fWriteESDfriend) {
879 esdf->~AliESDfriend();
880 new (esdf) AliESDfriend(); // Reset...
881 esd->GetESDfriend(esdf);
888 if (fCheckPointLevel > 0) WriteESD(esd, "final");
891 if (fWriteESDfriend) {
892 esdf->~AliESDfriend();
893 new (esdf) AliESDfriend(); // Reset...
896 // delete esdf; esdf = 0;
899 gSystem->GetProcInfo(&ProcInfo);
900 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
904 // // write quality assurance ESDs data (one entry for all events)
905 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
906 // if (!IsSelected(fgkDetectorName[iDet], detStr))
908 // AliQADataMaker * qadm = GetQADataMaker(iDet);
909 // if (!qadm) continue;
910 // qadm->EndOfCycle(AliQA::kRECPOINTS);
911 // qadm->EndOfCycle(AliQA::kESDS);
915 tree->GetUserInfo()->Add(esd);
916 hlttree->GetUserInfo()->Add(hltesd);
920 if(fESDPar.Contains("ESD.par")){
921 AliInfo("Attaching ESD.par to Tree");
922 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
923 tree->GetUserInfo()->Add(fn);
929 tree->SetBranchStatus("ESDfriend*",0);
930 // we want to have only one tree version number
931 tree->Write(tree->GetName(),TObject::kOverwrite);
935 TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE");
936 ESDFile2AODFile(file, aodFile);
941 CleanUp(file, fileOld);
943 // Create tags for the events in the ESD tree (the ESD tree is always present)
944 // In case of empty events the tags will contain dummy values
945 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
946 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPList);
948 AliAODTagCreator *aodtagCreator = new AliAODTagCreator();
949 aodtagCreator->CreateAODTags(fFirstEvent,fLastEvent,fGRPList);
953 AliQADataMakerSteer qas ;
954 qas.Run(AliQA::kRECPOINTS) ;
956 qas.Run(AliQA::kESDS) ;
962 //_____________________________________________________________________________
963 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
965 // run the local reconstruction
966 static Int_t eventNr=0;
969 // AliCDBManager* man = AliCDBManager::Instance();
970 // Bool_t origCache = man->GetCacheFlag();
972 // TString detStr = detectors;
973 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
974 // if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
975 // AliReconstructor* reconstructor = GetReconstructor(iDet);
976 // if (!reconstructor) continue;
977 // if (reconstructor->HasLocalReconstruction()) continue;
979 // AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
980 // AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
982 // AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
983 // AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
985 // man->SetCacheFlag(kTRUE);
986 // TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
987 // man->GetAll(calibPath); // entries are cached!
989 // AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
992 // fRawReader->RewindEvents();
993 // reconstructor->Reconstruct(fRunLoader, fRawReader);
995 // reconstructor->Reconstruct(fRunLoader);
998 // AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
999 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
1001 // // unload calibration data
1002 // man->UnloadFromCache(calibPath);
1003 // //man->ClearCache();
1006 // man->SetCacheFlag(origCache);
1008 // if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1009 // AliError(Form("the following detectors were not found: %s",
1011 // if (fStopOnError) return kFALSE;
1018 //_____________________________________________________________________________
1019 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1021 // run the local reconstruction
1022 static Int_t eventNr=0;
1023 AliCodeTimerAuto("")
1025 TString detStr = detectors;
1026 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1027 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1028 AliReconstructor* reconstructor = GetReconstructor(iDet);
1029 if (!reconstructor) continue;
1030 AliLoader* loader = fLoader[iDet];
1032 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1036 // conversion of digits
1037 if (fRawReader && reconstructor->HasDigitConversion()) {
1038 AliInfo(Form("converting raw data digits into root objects for %s",
1039 fgkDetectorName[iDet]));
1040 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1041 fgkDetectorName[iDet]));
1042 loader->LoadDigits("update");
1043 loader->CleanDigits();
1044 loader->MakeDigitsContainer();
1045 TTree* digitsTree = loader->TreeD();
1046 reconstructor->ConvertDigits(fRawReader, digitsTree);
1047 loader->WriteDigits("OVERWRITE");
1048 loader->UnloadDigits();
1051 // local reconstruction
1052 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1053 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1054 loader->LoadRecPoints("update");
1055 loader->CleanRecPoints();
1056 loader->MakeRecPointsContainer();
1057 TTree* clustersTree = loader->TreeR();
1058 if (fRawReader && !reconstructor->HasDigitConversion()) {
1059 reconstructor->Reconstruct(fRawReader, clustersTree);
1061 loader->LoadDigits("read");
1062 TTree* digitsTree = loader->TreeD();
1064 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1065 if (fStopOnError) return kFALSE;
1067 reconstructor->Reconstruct(digitsTree, clustersTree);
1069 loader->UnloadDigits();
1072 // AliQADataMaker * qadm = GetQADataMaker(iDet);
1074 // AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1075 // AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1077 // if (qadm->IsCycleDone() ) {
1078 // qadm->EndOfCycle(AliQA::kRECPOINTS) ;
1079 // qadm->EndOfCycle(AliQA::kESDS) ;
1080 // qadm->StartOfCycle(AliQA::kRECPOINTS) ;
1081 // qadm->StartOfCycle(AliQA::kESDS, "same") ;
1083 // qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
1084 // AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1087 loader->WriteRecPoints("OVERWRITE");
1088 loader->UnloadRecPoints();
1089 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1092 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1093 AliError(Form("the following detectors were not found: %s",
1095 if (fStopOnError) return kFALSE;
1101 //_____________________________________________________________________________
1102 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
1104 // run the barrel tracking
1106 AliCodeTimerAuto("")
1108 AliESDVertex* vertex = NULL;
1109 Double_t vtxPos[3] = {0, 0, 0};
1110 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1111 TArrayF mcVertex(3);
1112 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1113 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1114 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1118 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1119 AliInfo("running the ITS vertex finder");
1120 if (fLoader[0]) fLoader[0]->LoadRecPoints();
1121 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
1122 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
1124 AliWarning("Vertex not found");
1125 vertex = new AliESDVertex();
1126 vertex->SetName("default");
1129 vertex->SetName("reconstructed");
1133 AliInfo("getting the primary vertex from MC");
1134 vertex = new AliESDVertex(vtxPos, vtxErr);
1138 vertex->GetXYZ(vtxPos);
1139 vertex->GetSigmaXYZ(vtxErr);
1141 AliWarning("no vertex reconstructed");
1142 vertex = new AliESDVertex(vtxPos, vtxErr);
1144 esd->SetVertex(vertex);
1145 // if SPD multiplicity has been determined, it is stored in the ESD
1146 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1147 if(mult)esd->SetMultiplicity(mult);
1149 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1150 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1157 //_____________________________________________________________________________
1158 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1160 // run the HLT barrel tracking
1162 AliCodeTimerAuto("")
1165 AliError("Missing runLoader!");
1169 AliInfo("running HLT tracking");
1171 // Get a pointer to the HLT reconstructor
1172 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1173 if (!reconstructor) return kFALSE;
1176 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1177 TString detName = fgkDetectorName[iDet];
1178 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1179 reconstructor->SetOption(detName.Data());
1180 AliTracker *tracker = reconstructor->CreateTracker();
1182 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1183 if (fStopOnError) return kFALSE;
1187 Double_t vtxErr[3]={0.005,0.005,0.010};
1188 const AliESDVertex *vertex = esd->GetVertex();
1189 vertex->GetXYZ(vtxPos);
1190 tracker->SetVertex(vtxPos,vtxErr);
1192 fLoader[iDet]->LoadRecPoints("read");
1193 TTree* tree = fLoader[iDet]->TreeR();
1195 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1198 tracker->LoadClusters(tree);
1200 if (tracker->Clusters2Tracks(esd) != 0) {
1201 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1205 tracker->UnloadClusters();
1213 //_____________________________________________________________________________
1214 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1216 // run the muon spectrometer tracking
1218 AliCodeTimerAuto("")
1221 AliError("Missing runLoader!");
1224 Int_t iDet = 7; // for MUON
1226 AliInfo("is running...");
1228 // Get a pointer to the MUON reconstructor
1229 AliReconstructor *reconstructor = GetReconstructor(iDet);
1230 if (!reconstructor) return kFALSE;
1233 TString detName = fgkDetectorName[iDet];
1234 AliDebug(1, Form("%s tracking", detName.Data()));
1235 AliTracker *tracker = reconstructor->CreateTracker();
1237 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1242 fLoader[iDet]->LoadTracks("update");
1243 fLoader[iDet]->CleanTracks();
1244 fLoader[iDet]->MakeTracksContainer();
1247 fLoader[iDet]->LoadRecPoints("read");
1248 tracker->LoadClusters(fLoader[iDet]->TreeR());
1250 Int_t rv = tracker->Clusters2Tracks(esd);
1252 fLoader[iDet]->UnloadRecPoints();
1256 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1260 tracker->UnloadClusters();
1262 fLoader[iDet]->UnloadRecPoints();
1264 fLoader[iDet]->WriteTracks("OVERWRITE");
1265 fLoader[iDet]->UnloadTracks();
1273 //_____________________________________________________________________________
1274 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1276 // run the barrel tracking
1277 static Int_t eventNr=0;
1278 AliCodeTimerAuto("")
1280 AliInfo("running tracking");
1282 //Fill the ESD with the T0 info (will be used by the TOF)
1283 if (fReconstructor[11] && fLoader[11]) {
1284 fLoader[11]->LoadRecPoints("READ");
1285 TTree *treeR = fLoader[11]->TreeR();
1286 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1289 // pass 1: TPC + ITS inwards
1290 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1291 if (!fTracker[iDet]) continue;
1292 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1295 fLoader[iDet]->LoadRecPoints("read");
1296 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
1297 TTree* tree = fLoader[iDet]->TreeR();
1299 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1302 fTracker[iDet]->LoadClusters(tree);
1303 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1305 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1306 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1309 if (fCheckPointLevel > 1) {
1310 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1312 // preliminary PID in TPC needed by the ITS tracker
1314 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1315 AliESDpid::MakePID(esd);
1317 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
1320 // pass 2: ALL backwards
1321 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1322 if (!fTracker[iDet]) continue;
1323 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1326 if (iDet > 1) { // all except ITS, TPC
1328 fLoader[iDet]->LoadRecPoints("read");
1329 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
1330 tree = fLoader[iDet]->TreeR();
1332 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1335 fTracker[iDet]->LoadClusters(tree);
1336 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1340 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1341 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1344 if (fCheckPointLevel > 1) {
1345 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1349 if (iDet > 2) { // all except ITS, TPC, TRD
1350 fTracker[iDet]->UnloadClusters();
1351 fLoader[iDet]->UnloadRecPoints();
1353 // updated PID in TPC needed by the ITS tracker -MI
1355 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1356 AliESDpid::MakePID(esd);
1358 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1361 // write space-points to the ESD in case alignment data output
1363 if (fWriteAlignmentData)
1364 WriteAlignmentData(esd);
1366 // pass 3: TRD + TPC + ITS refit inwards
1367 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1368 if (!fTracker[iDet]) continue;
1369 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1372 if (fTracker[iDet]->RefitInward(esd) != 0) {
1373 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1376 if (fCheckPointLevel > 1) {
1377 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1379 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1381 fTracker[iDet]->UnloadClusters();
1382 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
1383 fLoader[iDet]->UnloadRecPoints();
1384 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
1387 // Propagate track to the vertex - if not done by ITS
1389 Int_t ntracks = esd->GetNumberOfTracks();
1390 for (Int_t itrack=0; itrack<ntracks; itrack++){
1391 const Double_t kRadius = 3; // beam pipe radius
1392 const Double_t kMaxStep = 5; // max step
1393 const Double_t kMaxD = 123456; // max distance to prim vertex
1394 Double_t fieldZ = AliTracker::GetBz(); //
1395 AliESDtrack * track = esd->GetTrack(itrack);
1396 if (!track) continue;
1397 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1398 AliTracker::PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1399 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1405 //_____________________________________________________________________________
1406 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1408 // Remove the data which are not needed for the physics analysis.
1411 AliInfo("Cleaning the ESD...");
1412 Int_t nTracks=esd->GetNumberOfTracks();
1413 AliInfo(Form("Number of ESD tracks before cleaning %d",nTracks));
1415 Float_t cleanPars[]={fDmax,fZmax};
1416 Bool_t rc=esd->Clean(cleanPars);
1418 nTracks=esd->GetNumberOfTracks();
1419 AliInfo(Form("Number of ESD tracks after cleaning %d",nTracks));
1424 //_____________________________________________________________________________
1425 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1427 // fill the event summary data
1429 AliCodeTimerAuto("")
1430 static Int_t eventNr=0;
1431 TString detStr = detectors;
1432 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1433 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1434 AliReconstructor* reconstructor = GetReconstructor(iDet);
1435 if (!reconstructor) continue;
1437 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1438 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1439 TTree* clustersTree = NULL;
1440 if (fLoader[iDet]) {
1441 fLoader[iDet]->LoadRecPoints("read");
1442 clustersTree = fLoader[iDet]->TreeR();
1443 if (!clustersTree) {
1444 AliError(Form("Can't get the %s clusters tree",
1445 fgkDetectorName[iDet]));
1446 if (fStopOnError) return kFALSE;
1449 if (fRawReader && !reconstructor->HasDigitConversion()) {
1450 reconstructor->FillESD(fRawReader, clustersTree, esd);
1452 TTree* digitsTree = NULL;
1453 if (fLoader[iDet]) {
1454 fLoader[iDet]->LoadDigits("read");
1455 digitsTree = fLoader[iDet]->TreeD();
1457 AliError(Form("Can't get the %s digits tree",
1458 fgkDetectorName[iDet]));
1459 if (fStopOnError) return kFALSE;
1462 reconstructor->FillESD(digitsTree, clustersTree, esd);
1463 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1465 if (fLoader[iDet]) {
1466 fLoader[iDet]->UnloadRecPoints();
1469 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1473 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1474 AliError(Form("the following detectors were not found: %s",
1476 if (fStopOnError) return kFALSE;
1478 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
1483 //_____________________________________________________________________________
1484 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1486 // Reads the trigger decision which is
1487 // stored in Trigger.root file and fills
1488 // the corresponding esd entries
1490 AliCodeTimerAuto("")
1492 AliInfo("Filling trigger information into the ESD");
1495 AliCTPRawStream input(fRawReader);
1496 if (!input.Next()) {
1497 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1500 esd->SetTriggerMask(input.GetClassMask());
1501 esd->SetTriggerCluster(input.GetClusterMask());
1504 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1506 if (!runloader->LoadTrigger()) {
1507 AliCentralTrigger *aCTP = runloader->GetTrigger();
1508 esd->SetTriggerMask(aCTP->GetClassMask());
1509 esd->SetTriggerCluster(aCTP->GetClusterMask());
1512 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1517 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1529 //_____________________________________________________________________________
1530 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1533 // Filling information from RawReader Header
1536 AliInfo("Filling information from RawReader Header");
1537 esd->SetBunchCrossNumber(0);
1538 esd->SetOrbitNumber(0);
1539 esd->SetPeriodNumber(0);
1540 esd->SetTimeStamp(0);
1541 esd->SetEventType(0);
1542 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1545 const UInt_t *id = eventHeader->GetP("Id");
1546 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1547 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1548 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1550 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1551 esd->SetEventType((eventHeader->Get("Type")));
1558 //_____________________________________________________________________________
1559 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1561 // check whether detName is contained in detectors
1562 // if yes, it is removed from detectors
1564 // check if all detectors are selected
1565 if ((detectors.CompareTo("ALL") == 0) ||
1566 detectors.BeginsWith("ALL ") ||
1567 detectors.EndsWith(" ALL") ||
1568 detectors.Contains(" ALL ")) {
1573 // search for the given detector
1574 Bool_t result = kFALSE;
1575 if ((detectors.CompareTo(detName) == 0) ||
1576 detectors.BeginsWith(detName+" ") ||
1577 detectors.EndsWith(" "+detName) ||
1578 detectors.Contains(" "+detName+" ")) {
1579 detectors.ReplaceAll(detName, "");
1583 // clean up the detectors string
1584 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1585 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1586 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1591 //_____________________________________________________________________________
1592 Bool_t AliReconstruction::InitRunLoader()
1594 // get or create the run loader
1596 if (gAlice) delete gAlice;
1599 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1600 // load all base libraries to get the loader classes
1601 TString libs = gSystem->GetLibraries();
1602 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1603 TString detName = fgkDetectorName[iDet];
1604 if (detName == "HLT") continue;
1605 if (libs.Contains("lib" + detName + "base.so")) continue;
1606 gSystem->Load("lib" + detName + "base.so");
1608 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1610 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1614 fRunLoader->CdGAFile();
1615 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1616 if (fRunLoader->LoadgAlice() == 0) {
1617 gAlice = fRunLoader->GetAliRun();
1618 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1621 if (!gAlice && !fRawReader) {
1622 AliError(Form("no gAlice object found in file %s",
1623 fGAliceFileName.Data()));
1628 //PH This is a temporary fix to give access to the kinematics
1629 //PH that is needed for the labels of ITS clusters
1630 fRunLoader->LoadHeader();
1631 fRunLoader->LoadKinematics();
1633 } else { // galice.root does not exist
1635 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1639 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1640 AliConfig::GetDefaultEventFolderName(),
1643 AliError(Form("could not create run loader in file %s",
1644 fGAliceFileName.Data()));
1648 fRunLoader->MakeTree("E");
1650 while (fRawReader->NextEvent()) {
1651 fRunLoader->SetEventNumber(iEvent);
1652 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1654 fRunLoader->MakeTree("H");
1655 fRunLoader->TreeE()->Fill();
1658 fRawReader->RewindEvents();
1659 if (fNumberOfEventsPerFile > 0)
1660 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1662 fRunLoader->SetNumberOfEventsPerFile(iEvent);
1663 fRunLoader->WriteHeader("OVERWRITE");
1664 fRunLoader->CdGAFile();
1665 fRunLoader->Write(0, TObject::kOverwrite);
1666 // AliTracker::SetFieldMap(???);
1672 //_____________________________________________________________________________
1673 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1675 // get the reconstructor object and the loader for a detector
1677 if (fReconstructor[iDet]) return fReconstructor[iDet];
1679 // load the reconstructor object
1680 TPluginManager* pluginManager = gROOT->GetPluginManager();
1681 TString detName = fgkDetectorName[iDet];
1682 TString recName = "Ali" + detName + "Reconstructor";
1683 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1685 AliReconstructor* reconstructor = NULL;
1686 // first check if a plugin is defined for the reconstructor
1687 TPluginHandler* pluginHandler =
1688 pluginManager->FindHandler("AliReconstructor", detName);
1689 // if not, add a plugin for it
1690 if (!pluginHandler) {
1691 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1692 TString libs = gSystem->GetLibraries();
1693 if (libs.Contains("lib" + detName + "base.so") ||
1694 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1695 pluginManager->AddHandler("AliReconstructor", detName,
1696 recName, detName + "rec", recName + "()");
1698 pluginManager->AddHandler("AliReconstructor", detName,
1699 recName, detName, recName + "()");
1701 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1703 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1704 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1706 if (reconstructor) {
1707 TObject* obj = fOptions.FindObject(detName.Data());
1708 if (obj) reconstructor->SetOption(obj->GetTitle());
1709 reconstructor->Init();
1710 fReconstructor[iDet] = reconstructor;
1713 // get or create the loader
1714 if (detName != "HLT") {
1715 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1716 if (!fLoader[iDet]) {
1717 AliConfig::Instance()
1718 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1720 // first check if a plugin is defined for the loader
1722 pluginManager->FindHandler("AliLoader", detName);
1723 // if not, add a plugin for it
1724 if (!pluginHandler) {
1725 TString loaderName = "Ali" + detName + "Loader";
1726 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1727 pluginManager->AddHandler("AliLoader", detName,
1728 loaderName, detName + "base",
1729 loaderName + "(const char*, TFolder*)");
1730 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1732 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1734 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1735 fRunLoader->GetEventFolder());
1737 if (!fLoader[iDet]) { // use default loader
1738 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1740 if (!fLoader[iDet]) {
1741 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1742 if (fStopOnError) return NULL;
1744 fRunLoader->AddLoader(fLoader[iDet]);
1745 fRunLoader->CdGAFile();
1746 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1747 fRunLoader->Write(0, TObject::kOverwrite);
1752 return reconstructor;
1755 //_____________________________________________________________________________
1756 Bool_t AliReconstruction::CreateVertexer()
1758 // create the vertexer
1761 AliReconstructor* itsReconstructor = GetReconstructor(0);
1762 if (itsReconstructor) {
1763 fVertexer = itsReconstructor->CreateVertexer();
1766 AliWarning("couldn't create a vertexer for ITS");
1767 if (fStopOnError) return kFALSE;
1773 //_____________________________________________________________________________
1774 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1776 // create the trackers
1778 TString detStr = detectors;
1779 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1780 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1781 AliReconstructor* reconstructor = GetReconstructor(iDet);
1782 if (!reconstructor) continue;
1783 TString detName = fgkDetectorName[iDet];
1784 if (detName == "HLT") {
1785 fRunHLTTracking = kTRUE;
1788 if (detName == "MUON") {
1789 fRunMuonTracking = kTRUE;
1794 fTracker[iDet] = reconstructor->CreateTracker();
1795 if (!fTracker[iDet] && (iDet < 7)) {
1796 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1797 if (fStopOnError) return kFALSE;
1799 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
1805 //_____________________________________________________________________________
1806 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1808 // delete trackers and the run loader and close and delete the file
1810 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1811 delete fReconstructor[iDet];
1812 fReconstructor[iDet] = NULL;
1813 fLoader[iDet] = NULL;
1814 delete fTracker[iDet];
1815 fTracker[iDet] = NULL;
1816 // delete fQADataMaker[iDet];
1817 // fQADataMaker[iDet] = NULL;
1821 delete fDiamondProfile;
1822 fDiamondProfile = NULL;
1840 gSystem->Unlink("AliESDs.old.root");
1844 //_____________________________________________________________________________
1846 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
1848 // read the ESD event from a file
1850 if (!esd) return kFALSE;
1852 sprintf(fileName, "ESD_%d.%d_%s.root",
1853 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1854 if (gSystem->AccessPathName(fileName)) return kFALSE;
1856 AliInfo(Form("reading ESD from file %s", fileName));
1857 AliDebug(1, Form("reading ESD from file %s", fileName));
1858 TFile* file = TFile::Open(fileName);
1859 if (!file || !file->IsOpen()) {
1860 AliError(Form("opening %s failed", fileName));
1867 esd = (AliESDEvent*) file->Get("ESD");
1876 //_____________________________________________________________________________
1877 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
1879 // write the ESD event to a file
1883 sprintf(fileName, "ESD_%d.%d_%s.root",
1884 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1886 AliDebug(1, Form("writing ESD to file %s", fileName));
1887 TFile* file = TFile::Open(fileName, "recreate");
1888 if (!file || !file->IsOpen()) {
1889 AliError(Form("opening %s failed", fileName));
1901 //_____________________________________________________________________________
1902 void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
1904 // write all files from the given esd file to an aod file
1906 // create an AliAOD object
1907 AliAODEvent *aod = new AliAODEvent();
1908 aod->CreateStdContent();
1914 TTree *aodTree = new TTree("aodTree", "AliAOD tree");
1915 aodTree->Branch(aod->GetList());
1918 TTree *t = (TTree*) esdFile->Get("esdTree");
1919 AliESDEvent *esd = new AliESDEvent();
1920 esd->ReadFromTree(t);
1922 Int_t nEvents = t->GetEntries();
1924 // set arrays and pointers
1934 // loop over events and fill them
1935 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
1936 //cout << "event: " << iEvent << endl;
1937 t->GetEntry(iEvent);
1939 // Multiplicity information needed by the header (to be revised!)
1940 Int_t nTracks = esd->GetNumberOfTracks();
1941 Int_t nPosTracks = 0;
1942 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack)
1943 if (esd->GetTrack(iTrack)->Charge()> 0) nPosTracks++;
1945 // Access the header
1946 AliAODHeader *header = aod->GetHeader();
1949 header->SetRunNumber (esd->GetRunNumber() );
1950 header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
1951 header->SetOrbitNumber (esd->GetOrbitNumber() );
1952 header->SetPeriodNumber (esd->GetPeriodNumber() );
1953 header->SetTriggerMask (esd->GetTriggerMask() );
1954 header->SetTriggerCluster (esd->GetTriggerCluster() );
1955 header->SetEventType (esd->GetEventType() );
1956 header->SetMagneticField (esd->GetMagneticField() );
1957 header->SetZDCN1Energy (esd->GetZDCN1Energy() );
1958 header->SetZDCP1Energy (esd->GetZDCP1Energy() );
1959 header->SetZDCN2Energy (esd->GetZDCN2Energy() );
1960 header->SetZDCP2Energy (esd->GetZDCP2Energy() );
1961 header->SetZDCEMEnergy (esd->GetZDCEMEnergy() );
1962 header->SetRefMultiplicity (nTracks);
1963 header->SetRefMultiplicityPos(nPosTracks);
1964 header->SetRefMultiplicityNeg(nTracks - nPosTracks);
1965 header->SetMuonMagFieldScale(-999.); // FIXME
1966 header->SetCentrality(-999.); // FIXME
1968 Int_t nV0s = esd->GetNumberOfV0s();
1969 Int_t nCascades = esd->GetNumberOfCascades();
1970 Int_t nKinks = esd->GetNumberOfKinks();
1971 Int_t nVertices = nV0s + nCascades + nKinks + 1 /* = prim. vtx*/;
1973 Int_t nCaloClus = esd->GetNumberOfCaloClusters();
1975 Int_t nPmdClus = esd->GetNumberOfPmdTracks();
1977 aod->ResetStd(nTracks, nVertices, nV0s+nCascades, nJets, nCaloClus, nFmdClus, nPmdClus);
1979 // Array to take into account the tracks already added to the AOD
1980 Bool_t * usedTrack = NULL;
1982 usedTrack = new Bool_t[nTracks];
1983 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
1985 // Array to take into account the V0s already added to the AOD
1986 Bool_t * usedV0 = NULL;
1988 usedV0 = new Bool_t[nV0s];
1989 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
1991 // Array to take into account the kinks already added to the AOD
1992 Bool_t * usedKink = NULL;
1994 usedKink = new Bool_t[nKinks];
1995 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
1998 // Access to the AOD container of vertices
1999 TClonesArray &vertices = *(aod->GetVertices());
2002 // Access to the AOD container of tracks
2003 TClonesArray &tracks = *(aod->GetTracks());
2006 // Access to the AOD container of V0s
2007 TClonesArray &V0s = *(aod->GetV0s());
2010 // Add primary vertex. The primary tracks will be defined
2011 // after the loops on the composite objects (V0, cascades, kinks)
2012 const AliESDVertex *vtx = esd->GetPrimaryVertex();
2014 vtx->GetXYZ(pos); // position
2015 vtx->GetCovMatrix(covVtx); //covariance matrix
2017 AliAODVertex * primary = new(vertices[jVertices++])
2018 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);
2021 AliAODTrack *aodTrack = 0x0;
2023 // Create vertices starting from the most complex objects
2026 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
2027 AliESDcascade *cascade = esd->GetCascade(nCascade);
2029 cascade->GetXYZ(pos[0], pos[1], pos[2]);
2030 cascade->GetPosCovXi(covVtx);
2032 // Add the cascade vertex
2033 AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
2035 cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
2038 AliAODVertex::kCascade);
2040 primary->AddDaughter(vcascade); // the cascade 'particle' (represented by a vertex) is added as a daughter to the primary vertex
2042 // Add the V0 from the cascade. The ESD class have to be optimized...
2043 // Now we have to search for the corresponding V0 in the list of V0s
2044 // using the indeces of the positive and negative tracks
2046 Int_t posFromV0 = cascade->GetPindex();
2047 Int_t negFromV0 = cascade->GetNindex();
2050 AliESDv0 * v0 = 0x0;
2053 for (Int_t iV0=0; iV0<nV0s; ++iV0) {
2055 v0 = esd->GetV0(iV0);
2056 Int_t posV0 = v0->GetPindex();
2057 Int_t negV0 = v0->GetNindex();
2059 if (posV0==posFromV0 && negV0==negFromV0) {
2065 AliAODVertex * vV0FromCascade = 0x0;
2067 if (indV0>-1 && !usedV0[indV0]) {
2069 // the V0 exists in the array of V0s and is not used
2071 usedV0[indV0] = kTRUE;
2073 v0->GetXYZ(pos[0], pos[1], pos[2]);
2074 v0->GetPosCov(covVtx);
2076 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2078 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2084 // the V0 doesn't exist in the array of V0s or was used
2085 cerr << "Error: event " << iEvent << " cascade " << nCascade
2086 << " The V0 " << indV0
2087 << " doesn't exist in the array of V0s or was used!" << endl;
2089 cascade->GetXYZ(pos[0], pos[1], pos[2]);
2090 cascade->GetPosCov(covVtx);
2092 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2094 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2098 vcascade->AddDaughter(vV0FromCascade);
2102 // Add the positive tracks from the V0
2104 if (! usedTrack[posFromV0]) {
2106 usedTrack[posFromV0] = kTRUE;
2108 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2109 esdTrack->GetPxPyPz(p_pos);
2110 esdTrack->GetXYZ(pos);
2111 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2112 esdTrack->GetESDpid(pid);
2114 vV0FromCascade->AddDaughter(aodTrack =
2115 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2116 esdTrack->GetLabel(),
2122 (Short_t)esdTrack->Charge(),
2123 esdTrack->GetITSClusterMap(),
2126 kTRUE, // check if this is right
2127 kFALSE, // check if this is right
2128 AliAODTrack::kSecondary)
2130 aodTrack->ConvertAliPIDtoAODPID();
2133 cerr << "Error: event " << iEvent << " cascade " << nCascade
2134 << " track " << posFromV0 << " has already been used!" << endl;
2137 // Add the negative tracks from the V0
2139 if (!usedTrack[negFromV0]) {
2141 usedTrack[negFromV0] = kTRUE;
2143 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2144 esdTrack->GetPxPyPz(p_neg);
2145 esdTrack->GetXYZ(pos);
2146 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2147 esdTrack->GetESDpid(pid);
2149 vV0FromCascade->AddDaughter(aodTrack =
2150 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2151 esdTrack->GetLabel(),
2157 (Short_t)esdTrack->Charge(),
2158 esdTrack->GetITSClusterMap(),
2161 kTRUE, // check if this is right
2162 kFALSE, // check if this is right
2163 AliAODTrack::kSecondary)
2165 aodTrack->ConvertAliPIDtoAODPID();
2168 cerr << "Error: event " << iEvent << " cascade " << nCascade
2169 << " track " << negFromV0 << " has already been used!" << endl;
2172 // add it to the V0 array as well
2173 Double_t d0[2] = { -999., -99.};
2174 // counting is probably wrong
2175 new(V0s[jV0s++]) AliAODv0(vV0FromCascade, -999., -99., p_pos, p_neg, d0); // to be refined
2177 // Add the bachelor track from the cascade
2179 Int_t bachelor = cascade->GetBindex();
2181 if(!usedTrack[bachelor]) {
2183 usedTrack[bachelor] = kTRUE;
2185 AliESDtrack *esdTrack = esd->GetTrack(bachelor);
2186 esdTrack->GetPxPyPz(p);
2187 esdTrack->GetXYZ(pos);
2188 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2189 esdTrack->GetESDpid(pid);
2191 vcascade->AddDaughter(aodTrack =
2192 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2193 esdTrack->GetLabel(),
2199 (Short_t)esdTrack->Charge(),
2200 esdTrack->GetITSClusterMap(),
2203 kTRUE, // check if this is right
2204 kFALSE, // check if this is right
2205 AliAODTrack::kSecondary)
2207 aodTrack->ConvertAliPIDtoAODPID();
2210 cerr << "Error: event " << iEvent << " cascade " << nCascade
2211 << " track " << bachelor << " has already been used!" << endl;
2214 // Add the primary track of the cascade (if any)
2216 } // end of the loop on cascades
2220 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
2222 if (usedV0[nV0]) continue; // skip if aready added to the AOD
2224 AliESDv0 *v0 = esd->GetV0(nV0);
2226 v0->GetXYZ(pos[0], pos[1], pos[2]);
2227 v0->GetPosCov(covVtx);
2229 AliAODVertex * vV0 =
2230 new(vertices[jVertices++]) AliAODVertex(pos,
2232 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2236 primary->AddDaughter(vV0);
2238 Int_t posFromV0 = v0->GetPindex();
2239 Int_t negFromV0 = v0->GetNindex();
2241 // Add the positive tracks from the V0
2243 if (!usedTrack[posFromV0]) {
2245 usedTrack[posFromV0] = kTRUE;
2247 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2248 esdTrack->GetPxPyPz(p_pos);
2249 esdTrack->GetXYZ(pos);
2250 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2251 esdTrack->GetESDpid(pid);
2253 vV0->AddDaughter(aodTrack =
2254 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2255 esdTrack->GetLabel(),
2261 (Short_t)esdTrack->Charge(),
2262 esdTrack->GetITSClusterMap(),
2265 kTRUE, // check if this is right
2266 kFALSE, // check if this is right
2267 AliAODTrack::kSecondary)
2269 aodTrack->ConvertAliPIDtoAODPID();
2272 cerr << "Error: event " << iEvent << " V0 " << nV0
2273 << " track " << posFromV0 << " has already been used!" << endl;
2276 // Add the negative tracks from the V0
2278 if (!usedTrack[negFromV0]) {
2280 usedTrack[negFromV0] = kTRUE;
2282 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2283 esdTrack->GetPxPyPz(p_neg);
2284 esdTrack->GetXYZ(pos);
2285 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2286 esdTrack->GetESDpid(pid);
2288 vV0->AddDaughter(aodTrack =
2289 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2290 esdTrack->GetLabel(),
2296 (Short_t)esdTrack->Charge(),
2297 esdTrack->GetITSClusterMap(),
2300 kTRUE, // check if this is right
2301 kFALSE, // check if this is right
2302 AliAODTrack::kSecondary)
2304 aodTrack->ConvertAliPIDtoAODPID();
2307 cerr << "Error: event " << iEvent << " V0 " << nV0
2308 << " track " << negFromV0 << " has already been used!" << endl;
2311 // add it to the V0 array as well
2312 Double_t d0[2] = { 999., 99.};
2313 new(V0s[jV0s++]) AliAODv0(vV0, 999., 99., p_pos, p_neg, d0); // to be refined
2314 } // end of the loop on V0s
2316 // Kinks: it is a big mess the access to the information in the kinks
2317 // The loop is on the tracks in order to find the mother and daugther of each kink
2320 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2322 AliESDtrack * esdTrack = esd->GetTrack(iTrack);
2324 Int_t ikink = esdTrack->GetKinkIndex(0);
2327 // Negative kink index: mother, positive: daughter
2329 // Search for the second track of the kink
2331 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
2333 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
2335 Int_t jkink = esdTrack1->GetKinkIndex(0);
2337 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
2339 // The two tracks are from the same kink
2341 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
2344 Int_t idaughter = -1;
2346 if (ikink<0 && jkink>0) {
2351 else if (ikink>0 && jkink<0) {
2357 cerr << "Error: Wrong combination of kink indexes: "
2358 << ikink << " " << jkink << endl;
2362 // Add the mother track
2364 AliAODTrack * mother = NULL;
2366 if (!usedTrack[imother]) {
2368 usedTrack[imother] = kTRUE;
2370 AliESDtrack *esdTrack = esd->GetTrack(imother);
2371 esdTrack->GetPxPyPz(p);
2372 esdTrack->GetXYZ(pos);
2373 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2374 esdTrack->GetESDpid(pid);
2377 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2378 esdTrack->GetLabel(),
2384 (Short_t)esdTrack->Charge(),
2385 esdTrack->GetITSClusterMap(),
2388 kTRUE, // check if this is right
2389 kTRUE, // check if this is right
2390 AliAODTrack::kPrimary);
2391 primary->AddDaughter(mother);
2392 mother->ConvertAliPIDtoAODPID();
2395 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2396 << " track " << imother << " has already been used!" << endl;
2399 // Add the kink vertex
2400 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
2402 AliAODVertex * vkink =
2403 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
2407 esdTrack->GetID(), // This is the track ID of the mother's track!
2408 AliAODVertex::kKink);
2409 // Add the daughter track
2411 AliAODTrack * daughter = NULL;
2413 if (!usedTrack[idaughter]) {
2415 usedTrack[idaughter] = kTRUE;
2417 AliESDtrack *esdTrack = esd->GetTrack(idaughter);
2418 esdTrack->GetPxPyPz(p);
2419 esdTrack->GetXYZ(pos);
2420 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2421 esdTrack->GetESDpid(pid);
2424 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2425 esdTrack->GetLabel(),
2431 (Short_t)esdTrack->Charge(),
2432 esdTrack->GetITSClusterMap(),
2435 kTRUE, // check if this is right
2436 kTRUE, // check if this is right
2437 AliAODTrack::kPrimary);
2438 vkink->AddDaughter(daughter);
2439 daughter->ConvertAliPIDtoAODPID();
2442 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2443 << " track " << idaughter << " has already been used!" << endl;
2450 // Tracks (primary and orphan)
2451 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
2454 if (usedTrack[nTrack]) continue;
2456 AliESDtrack *esdTrack = esd->GetTrack(nTrack);
2457 esdTrack->GetPxPyPz(p);
2458 esdTrack->GetXYZ(pos);
2459 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2460 esdTrack->GetESDpid(pid);
2462 Float_t impactXY, impactZ;
2464 esdTrack->GetImpactParameters(impactXY,impactZ);
2467 // track inside the beam pipe
2469 primary->AddDaughter(aodTrack =
2470 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2471 esdTrack->GetLabel(),
2477 (Short_t)esdTrack->Charge(),
2478 esdTrack->GetITSClusterMap(),
2481 kTRUE, // check if this is right
2482 kTRUE, // check if this is right
2483 AliAODTrack::kPrimary)
2485 aodTrack->ConvertAliPIDtoAODPID();
2488 // outside the beam pipe: orphan track
2489 // Don't write them anymore!
2492 } // end of loop on tracks
2495 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
2496 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
2498 AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);
2499 p[0] = esdMuTrack->Px();
2500 p[1] = esdMuTrack->Py();
2501 p[2] = esdMuTrack->Pz();
2502 pos[0] = primary->GetX();
2503 pos[1] = primary->GetY();
2504 pos[2] = primary->GetZ();
2506 // has to be changed once the muon pid is provided by the ESD
2507 for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
2509 primary->AddDaughter(aodTrack =
2510 new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
2511 0, // no label provided
2516 NULL, // no covariance matrix provided
2517 esdMuTrack->Charge(),
2518 0, // ITSClusterMap is set below
2521 kFALSE, // muon tracks are not used to fit the primary vtx
2522 kFALSE, // not used for vertex fit
2523 AliAODTrack::kPrimary)
2526 aodTrack->SetHitsPatternInTrigCh(esdMuTrack->GetHitsPatternInTrigCh());
2527 Int_t track2Trigger = esdMuTrack->GetMatchTrigger();
2528 aodTrack->SetMatchTrigger(track2Trigger);
2530 aodTrack->SetChi2MatchTrigger(esdMuTrack->GetChi2MatchTrigger());
2532 aodTrack->SetChi2MatchTrigger(0.);
2535 // Access to the AOD container of PMD clusters
2536 TClonesArray &pmdClusters = *(aod->GetPmdClusters());
2537 Int_t jPmdClusters=0;
2539 for (Int_t iPmd = 0; iPmd < nPmdClus; ++iPmd) {
2540 // file pmd clusters, to be revised!
2541 AliESDPmdTrack *pmdTrack = esd->GetPmdTrack(iPmd);
2544 Double_t pos[3] = { pmdTrack->GetClusterX(), pmdTrack->GetClusterY(), pmdTrack->GetClusterZ() };
2545 Double_t pid[9] = { 0., 0., 0., 0., 0., 0., 0., 0., 0. }; // to be revised!
2547 // assoc cluster not set
2548 new(pmdClusters[jPmdClusters++]) AliAODPmdCluster(iPmd, nLabel, label, pmdTrack->GetClusterADC(), pos, pid);
2551 // Access to the AOD container of clusters
2552 TClonesArray &caloClusters = *(aod->GetCaloClusters());
2556 TArrayS EMCCellNumber(15000);
2557 TArrayD EMCCellAmplitude(15000);
2558 Int_t nEMCCells = 0;
2559 const Float_t fEMCAmpScale = 1./500;
2561 for (Int_t iClust=0; iClust<nCaloClus; ++iClust) {
2563 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
2565 Int_t id = cluster->GetID();
2568 Float_t energy = cluster->E();
2569 cluster->GetPosition(posF);
2570 Char_t ttype=AliAODCluster::kUndef;
2572 if (cluster->GetClusterType() == AliESDCaloCluster::kPHOSCluster) {
2573 ttype=AliAODCluster::kPHOSNeutral;
2575 else if (cluster->GetClusterType() == AliESDCaloCluster::kEMCALClusterv1) {
2576 ttype = AliAODCluster::kEMCALClusterv1;
2578 else if (cluster->GetClusterType() == AliESDCaloCluster::kEMCALPseudoCluster) {
2579 // Collect raw tower info
2580 for (Int_t iDig = 0; iDig < cluster->GetNumberOfDigits(); iDig++) {
2581 EMCCellNumber[nEMCCells] = cluster->GetDigitIndex()->At(iDig);
2582 EMCCellAmplitude[nEMCCells] = fEMCAmpScale*cluster->GetDigitAmplitude()->At(iDig);
2585 // don't write cluster data (it's just a pseudo cluster, holding the tower information)
2589 AliAODCaloCluster *caloCluster = new(caloClusters[jClusters++]) AliAODCaloCluster(id,
2597 caloCluster->SetCaloCluster(); // to be refined!
2599 } // end of loop on calo clusters
2601 // fill EMC cell info
2602 AliAODCaloCells &EMCCells = *(aod->GetCaloCells());
2603 EMCCells.CreateContainer(nEMCCells);
2604 EMCCells.SetType(AliAODCaloCells::kEMCAL);
2605 for (Int_t iCell = 0; iCell < nEMCCells; iCell++) {
2606 EMCCells.SetCell(iCell,EMCCellNumber[iCell],EMCCellAmplitude[iCell]);
2611 AliAODTracklets &SPDTracklets = *(aod->GetTracklets());
2612 const AliMultiplicity *mult = esd->GetMultiplicity();
2614 if (mult->GetNumberOfTracklets()>0) {
2615 SPDTracklets.CreateContainer(mult->GetNumberOfTracklets());
2617 for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {
2618 SPDTracklets.SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n));
2622 Printf("ERROR: AliMultiplicity could not be retrieved from ESD");
2625 delete [] usedTrack;
2629 // fill the tree for this event
2631 } // end of event loop
2633 aodTree->GetUserInfo()->Add(aod);
2638 // write the tree to the specified file
2639 aodFile = aodTree->GetCurrentFile();
2646 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2648 // Write space-points which are then used in the alignment procedures
2649 // For the moment only ITS, TRD and TPC
2651 // Load TOF clusters
2653 fLoader[3]->LoadRecPoints("read");
2654 TTree* tree = fLoader[3]->TreeR();
2656 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2659 fTracker[3]->LoadClusters(tree);
2661 Int_t ntracks = esd->GetNumberOfTracks();
2662 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2664 AliESDtrack *track = esd->GetTrack(itrack);
2667 for (Int_t iDet = 3; iDet >= 0; iDet--)
2668 nsp += track->GetNcls(iDet);
2670 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2671 track->SetTrackPointArray(sp);
2673 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2674 AliTracker *tracker = fTracker[iDet];
2675 if (!tracker) continue;
2676 Int_t nspdet = track->GetNcls(iDet);
2677 if (nspdet <= 0) continue;
2678 track->GetClusters(iDet,idx);
2682 while (isp < nspdet) {
2684 if(IsSelected(fgkDetectorName[iDet],fUseTrackingErrorsForAlignment)) {
2685 isvalid = tracker->GetTrackPointTrackingError(idx[isp2],p,track);
2687 isvalid = tracker->GetTrackPoint(idx[isp2],p);
2690 const Int_t kNTPCmax = 159;
2691 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2692 if (!isvalid) continue;
2693 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2699 fTracker[3]->UnloadClusters();
2700 fLoader[3]->UnloadRecPoints();
2704 //_____________________________________________________________________________
2705 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2707 // The method reads the raw-data error log
2708 // accumulated within the rawReader.
2709 // It extracts the raw-data errors related to
2710 // the current event and stores them into
2711 // a TClonesArray inside the esd object.
2713 if (!fRawReader) return;
2715 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2717 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2719 if (iEvent != log->GetEventNumber()) continue;
2721 esd->AddRawDataErrorLog(log);
2726 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2727 // Dump a file content into a char in TNamed
2729 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2730 Int_t kBytes = (Int_t)in.tellg();
2731 printf("Size: %d \n",kBytes);
2734 char* memblock = new char [kBytes];
2735 in.seekg (0, ios::beg);
2736 in.read (memblock, kBytes);
2738 TString fData(memblock,kBytes);
2739 fn = new TNamed(fName,fData);
2740 printf("fData Size: %d \n",fData.Sizeof());
2741 printf("fName Size: %d \n",fName.Sizeof());
2742 printf("fn Size: %d \n",fn->Sizeof());
2746 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2752 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2753 // This is not really needed in AliReconstruction at the moment
2754 // but can serve as a template
2756 TList *fList = fTree->GetUserInfo();
2757 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2758 printf("fn Size: %d \n",fn->Sizeof());
2760 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2761 const char* cdata = fn->GetTitle();
2762 printf("fTmp Size %d\n",fTmp.Sizeof());
2764 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2765 printf("calculated size %d\n",size);
2766 ofstream out(fName.Data(),ios::out | ios::binary);
2767 out.write(cdata,size);
2774 //_____________________________________________________________________________
2775 //AliQADataMaker * AliReconstruction::GetQADataMaker(Int_t iDet)
2777 // get the quality assurance data maker object and the loader for a detector
2779 // if (fQADataMaker[iDet])
2780 // return fQADataMaker[iDet];
2782 // // load the QA data maker object
2783 // TPluginManager* pluginManager = gROOT->GetPluginManager();
2784 // TString detName = fgkDetectorName[iDet];
2785 // TString qadmName = "Ali" + detName + "QADataMaker";
2786 // if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT"))
2789 // AliQADataMaker * qadm = NULL;
2790 // // first check if a plugin is defined for the quality assurance data maker
2791 // TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName);
2792 // // if not, add a plugin for it
2793 // if (!pluginHandler) {
2794 // AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2795 // TString libs = gSystem->GetLibraries();
2796 // if (libs.Contains("lib" + detName + "base.so") ||
2797 // (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2798 // pluginManager->AddHandler("AliQADataMaker", detName,
2799 // qadmName, detName + "qadm", qadmName + "()");
2801 // pluginManager->AddHandler("AliQADataMaker", detName,
2802 // qadmName, detName, qadmName + "()");
2804 // pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName);
2806 // if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2807 // qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0);
2810 // AliInfo(Form("Initializing quality assurance data maker for %s", fgkDetectorName[iDet]));
2811 // qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun(), GetQACycles(fgkDetectorName[iDet]));
2812 // qadm->StartOfCycle(AliQA::kRECPOINTS);
2813 // qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
2814 // qadm->StartOfCycle(AliQA::kESDS, "same") ;
2815 // fQADataMaker[iDet] = qadm;
2821 //_____________________________________________________________________________
2822 //Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
2824 // // run the Quality Assurance data producer
2826 // AliCodeTimerAuto("")
2827 // TString detStr = detectors;
2828 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2829 // if (!IsSelected(fgkDetectorName[iDet], detStr))
2831 // AliQADataMaker * qadm = GetQADataMaker(iDet);
2834 // AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2835 // AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2837 // qadm->Exec(AliQA::kESDS, esd) ;
2838 // qadm->Increment() ;
2840 // AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2842 // if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2843 // AliError(Form("the following detectors were not found: %s",
2845 // if (fStopOnError)
2854 //_____________________________________________________________________________
2855 void AliReconstruction::CheckQA()
2857 // check the QA of SIM for this run and remove the detectors
2858 // with status Fatal
2860 TString newDetList ;
2861 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2862 TString detName(AliQA::GetDetName(iDet)) ;
2863 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2864 fRunLocalReconstruction.Contains("ALL") ) {
2865 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX(iDet)) ;
2866 if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kFATAL)) {
2867 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
2868 } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kERROR)) {
2869 AliError(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was ERROR", detName.Data())) ;
2870 newDetList += detName ;
2872 } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kWARNING) ) {
2873 AliWarning(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was WARNING", detName.Data())) ;
2874 newDetList += detName ;
2876 } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kINFO) ) {
2877 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was INFO", detName.Data())) ;
2878 newDetList += detName ;
2881 newDetList += detName ;
2886 fRunLocalReconstruction = newDetList ;
2889 //_____________________________________________________________________________
2890 Int_t AliReconstruction::GetDetIndex(const char* detector)
2892 // return the detector index corresponding to detector
2894 for (index = 0; index < fgkNDetectors ; index++) {
2895 if ( strcmp(detector, fgkDetectorName[index]) == 0 )