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 "AliQADataMaker.h"
175 //#include "TMemStatManager.h" // memory snapshots
176 #include "AliSysInfo.h" // memory snapshots
178 ClassImp(AliReconstruction)
181 //_____________________________________________________________________________
182 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
184 //_____________________________________________________________________________
185 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
186 const char* name, const char* title) :
189 fUniformField(kTRUE),
190 fRunVertexFinder(kTRUE),
191 fRunHLTTracking(kFALSE),
192 fRunMuonTracking(kFALSE),
194 fRunCascadeFinder(kTRUE),
195 fStopOnError(kFALSE),
196 fWriteAlignmentData(kFALSE),
197 fWriteESDfriend(kFALSE),
199 fFillTriggerESD(kTRUE),
205 fRunLocalReconstruction("ALL"),
208 fUseTrackingErrorsForAlignment(""),
209 fGAliceFileName(gAliceFilename),
214 fNumberOfEventsPerFile(1),
217 fLoadAlignFromCDB(kTRUE),
218 fLoadAlignData("ALL"),
225 fDiamondProfile(NULL),
227 fAlignObjArray(NULL),
232 // create reconstruction object with default parameters
234 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
235 fReconstructor[iDet] = NULL;
236 fLoader[iDet] = NULL;
237 fTracker[iDet] = NULL;
238 fQADataMaker[iDet] = NULL;
239 fQACycles[iDet] = 999999;
244 //_____________________________________________________________________________
245 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
248 fUniformField(rec.fUniformField),
249 fRunVertexFinder(rec.fRunVertexFinder),
250 fRunHLTTracking(rec.fRunHLTTracking),
251 fRunMuonTracking(rec.fRunMuonTracking),
252 fRunV0Finder(rec.fRunV0Finder),
253 fRunCascadeFinder(rec.fRunCascadeFinder),
254 fStopOnError(rec.fStopOnError),
255 fWriteAlignmentData(rec.fWriteAlignmentData),
256 fWriteESDfriend(rec.fWriteESDfriend),
257 fWriteAOD(rec.fWriteAOD),
258 fFillTriggerESD(rec.fFillTriggerESD),
260 fCleanESD(rec.fCleanESD),
264 fRunLocalReconstruction(rec.fRunLocalReconstruction),
265 fRunTracking(rec.fRunTracking),
266 fFillESD(rec.fFillESD),
267 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
268 fGAliceFileName(rec.fGAliceFileName),
270 fEquipIdMap(rec.fEquipIdMap),
271 fFirstEvent(rec.fFirstEvent),
272 fLastEvent(rec.fLastEvent),
273 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
276 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
277 fLoadAlignData(rec.fLoadAlignData),
278 fESDPar(rec.fESDPar),
284 fDiamondProfile(NULL),
286 fAlignObjArray(rec.fAlignObjArray),
287 fCDBUri(rec.fCDBUri),
288 fRemoteCDBUri(rec.fRemoteCDBUri),
293 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
294 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
296 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
297 fReconstructor[iDet] = NULL;
298 fLoader[iDet] = NULL;
299 fTracker[iDet] = NULL;
300 fQADataMaker[iDet] = NULL;
301 fQACycles[iDet] = rec.fQACycles[iDet];
303 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
304 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
308 //_____________________________________________________________________________
309 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
311 // assignment operator
313 this->~AliReconstruction();
314 new(this) AliReconstruction(rec);
318 //_____________________________________________________________________________
319 AliReconstruction::~AliReconstruction()
325 fSpecCDBUri.Delete();
327 AliCodeTimer::Instance()->Print();
330 //_____________________________________________________________________________
331 void AliReconstruction::InitCDBStorage()
333 // activate a default CDB storage
334 // First check if we have any CDB storage set, because it is used
335 // to retrieve the calibration and alignment constants
337 AliCDBManager* man = AliCDBManager::Instance();
338 if (man->IsDefaultStorageSet())
340 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
341 AliWarning("Default CDB storage has been already set !");
342 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
343 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
347 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
348 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
349 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
350 man->SetDefaultStorage(fCDBUri);
353 // Remote storage (the Grid storage) is used if it is activated
354 // and if the object is not found in the default storage
356 // if (man->IsRemoteStorageSet())
358 // AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
359 // AliWarning("Remote CDB storage has been already set !");
360 // AliWarning(Form("Ignoring the remote storage declared in AliReconstruction: %s",fRemoteCDBUri.Data()));
361 // AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
362 // fRemoteCDBUri = "";
365 // AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
366 // AliDebug(2, Form("Remote CDB storage is set to: %s",fRemoteCDBUri.Data()));
367 // AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
368 // man->SetRemoteStorage(fRemoteCDBUri);
371 // Now activate the detector specific CDB storage locations
372 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
373 TObject* obj = fSpecCDBUri[i];
375 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
376 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
377 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
378 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
383 //_____________________________________________________________________________
384 void AliReconstruction::SetDefaultStorage(const char* uri) {
385 // Store the desired default CDB storage location
386 // Activate it later within the Run() method
392 //_____________________________________________________________________________
393 void AliReconstruction::SetRemoteStorage(const char* uri) {
394 // Store the desired remote CDB storage location
395 // Activate it later within the Run() method
396 // Remote storage (the Grid storage) is used if it is activated
397 // and if the object is not found in the default storage
403 //_____________________________________________________________________________
404 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
405 // Store a detector-specific CDB storage location
406 // Activate it later within the Run() method
408 AliCDBPath aPath(calibType);
409 if(!aPath.IsValid()){
410 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
411 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
412 if(!strcmp(calibType, fgkDetectorName[iDet])) {
413 aPath.SetPath(Form("%s/*", calibType));
414 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
418 if(!aPath.IsValid()){
419 AliError(Form("Not a valid path or detector: %s", calibType));
424 // // check that calibType refers to a "valid" detector name
425 // Bool_t isDetector = kFALSE;
426 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
427 // TString detName = fgkDetectorName[iDet];
428 // if(aPath.GetLevel0() == detName) {
429 // isDetector = kTRUE;
435 // AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
439 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
440 if (obj) fSpecCDBUri.Remove(obj);
441 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
448 //_____________________________________________________________________________
449 Bool_t AliReconstruction::SetRunNumber()
451 // The method is called in Run() in order
452 // to set a correct run number.
453 // In case of raw data reconstruction the
454 // run number is taken from the raw data header
456 if(AliCDBManager::Instance()->GetRun() < 0) {
458 AliError("No run loader is found !");
461 // read run number from gAlice
462 if(fRunLoader->GetAliRun())
463 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
466 if(fRawReader->NextEvent()) {
467 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
468 fRawReader->RewindEvents();
471 AliError("No raw-data events found !");
476 AliError("Neither gAlice nor RawReader objects are found !");
480 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
485 //_____________________________________________________________________________
486 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
488 // Read the alignment objects from CDB.
489 // Each detector is supposed to have the
490 // alignment objects in DET/Align/Data CDB path.
491 // All the detector objects are then collected,
492 // sorted by geometry level (starting from ALIC) and
493 // then applied to the TGeo geometry.
494 // Finally an overlaps check is performed.
496 // Load alignment data from CDB and fill fAlignObjArray
497 if(fLoadAlignFromCDB){
499 TString detStr = detectors;
500 TString loadAlObjsListOfDets = "";
502 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
503 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
504 loadAlObjsListOfDets += fgkDetectorName[iDet];
505 loadAlObjsListOfDets += " ";
506 } // end loop over detectors
507 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
508 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
510 // Check if the array with alignment objects was
511 // provided by the user. If yes, apply the objects
512 // to the present TGeo geometry
513 if (fAlignObjArray) {
514 if (gGeoManager && gGeoManager->IsClosed()) {
515 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
516 AliError("The misalignment of one or more volumes failed!"
517 "Compare the list of simulated detectors and the list of detector alignment data!");
522 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
528 delete fAlignObjArray; fAlignObjArray=0;
533 //_____________________________________________________________________________
534 void AliReconstruction::SetGAliceFile(const char* fileName)
536 // set the name of the galice file
538 fGAliceFileName = fileName;
541 //_____________________________________________________________________________
542 void AliReconstruction::SetOption(const char* detector, const char* option)
544 // set options for the reconstruction of a detector
546 TObject* obj = fOptions.FindObject(detector);
547 if (obj) fOptions.Remove(obj);
548 fOptions.Add(new TNamed(detector, option));
552 //_____________________________________________________________________________
553 Bool_t AliReconstruction::Run(const char* input)
555 // run the reconstruction
560 if (!input) input = fInput.Data();
561 TString fileName(input);
562 if (fileName.EndsWith("/")) {
563 fRawReader = new AliRawReaderFile(fileName);
564 } else if (fileName.EndsWith(".root")) {
565 fRawReader = new AliRawReaderRoot(fileName);
566 } else if (!fileName.IsNull()) {
567 fRawReader = new AliRawReaderDate(fileName);
568 fRawReader->SelectEvents(7);
570 if (!fEquipIdMap.IsNull() && fRawReader)
571 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
573 AliSysInfo::AddStamp("Start");
574 // get the run loader
575 if (!InitRunLoader()) return kFALSE;
576 AliSysInfo::AddStamp("LoadLoader");
578 // Initialize the CDB storage
580 AliSysInfo::AddStamp("LoadCDB");
582 // Set run number in CDBManager (if it is not already set by the user)
583 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
585 // Import ideal TGeo geometry and apply misalignment
587 TString geom(gSystem->DirName(fGAliceFileName));
588 geom += "/geometry.root";
589 AliGeomManager::LoadGeometry(geom.Data());
590 if (!gGeoManager) if (fStopOnError) return kFALSE;
593 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
594 AliSysInfo::AddStamp("LoadGeom");
596 // local reconstruction
597 if (!fRunLocalReconstruction.IsNull()) {
598 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
599 if (fStopOnError) {CleanUp(); return kFALSE;}
602 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
603 // fFillESD.IsNull()) return kTRUE;
606 if (fRunVertexFinder && !CreateVertexer()) {
612 AliSysInfo::AddStamp("Vertexer");
615 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
621 AliSysInfo::AddStamp("LoadTrackers");
623 // get the possibly already existing ESD file and tree
624 AliESDEvent* esd = new AliESDEvent(); AliESDEvent* hltesd = new AliESDEvent();
625 TFile* fileOld = NULL;
626 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
627 if (!gSystem->AccessPathName("AliESDs.root")){
628 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
629 fileOld = TFile::Open("AliESDs.old.root");
630 if (fileOld && fileOld->IsOpen()) {
631 treeOld = (TTree*) fileOld->Get("esdTree");
632 if (treeOld)esd->ReadFromTree(treeOld);
633 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
634 if (hlttreeOld) hltesd->ReadFromTree(hlttreeOld);
638 // create the ESD output file and tree
639 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
640 file->SetCompressionLevel(2);
641 if (!file->IsOpen()) {
642 AliError("opening AliESDs.root failed");
643 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
646 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
647 esd = new AliESDEvent();
648 esd->CreateStdContent();
649 esd->WriteToTree(tree);
651 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
652 hltesd = new AliESDEvent();
653 hltesd->CreateStdContent();
654 hltesd->WriteToTree(hlttree);
657 delete esd; delete hltesd;
658 esd = NULL; hltesd = NULL;
660 // create the branch with ESD additions
664 AliESDfriend *esdf = 0;
665 if (fWriteESDfriend) {
666 esdf = new AliESDfriend();
667 TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
668 br->SetFile("AliESDfriends.root");
669 esd->AddObject(esdf);
673 // Get the diamond profile from OCDB
674 AliCDBEntry* entry = AliCDBManager::Instance()
675 ->Get("GRP/Calib/MeanVertex");
678 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
680 AliError("No diamond profile found in OCDB!");
683 AliVertexerTracks tVertexer(AliTracker::GetBz());
684 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
688 if (fRawReader) fRawReader->RewindEvents();
689 TString detStr(fFillESD) ;
692 gSystem->GetProcInfo(&ProcInfo);
693 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
695 // checking the QA of previous steps
698 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
699 if (fRawReader) fRawReader->NextEvent();
700 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
701 // copy old ESD to the new one
703 esd->ReadFromTree(treeOld);
704 treeOld->GetEntry(iEvent);
708 esd->ReadFromTree(hlttreeOld);
709 hlttreeOld->GetEntry(iEvent);
715 AliInfo(Form("processing event %d", iEvent));
716 fRunLoader->GetEvent(iEvent);
719 sprintf(aFileName, "ESD_%d.%d_final.root",
720 fRunLoader->GetHeader()->GetRun(),
721 fRunLoader->GetHeader()->GetEventNrInRun());
722 if (!gSystem->AccessPathName(aFileName)) continue;
724 // local reconstruction
725 if (!fRunLocalReconstruction.IsNull()) {
726 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
727 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
732 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
733 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
734 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
735 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
737 // Set magnetic field from the tracker
738 esd->SetMagneticField(AliTracker::GetBz());
739 hltesd->SetMagneticField(AliTracker::GetBz());
743 // Fill raw-data error log into the ESD
744 if (fRawReader) FillRawDataErrorLog(iEvent,esd);
747 if (fRunVertexFinder) {
748 if (!ReadESD(esd, "vertex")) {
749 if (!RunVertexFinder(esd)) {
750 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
752 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
757 if (!fRunTracking.IsNull()) {
758 if (fRunHLTTracking) {
759 hltesd->SetVertex(esd->GetVertex());
760 if (!RunHLTTracking(hltesd)) {
761 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
767 if (!fRunTracking.IsNull()) {
768 if (fRunMuonTracking) {
769 if (!RunMuonTracking(esd)) {
770 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
776 if (!fRunTracking.IsNull()) {
777 if (!ReadESD(esd, "tracking")) {
778 if (!RunTracking(esd)) {
779 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
781 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
786 if (!fFillESD.IsNull()) {
787 if (!FillESD(esd, fFillESD)) {
788 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
792 if (!fFillESD.IsNull())
793 RunQA(fFillESD.Data(), esd);
795 // fill Event header information from the RawEventHeader
796 if (fRawReader){FillRawEventHeaderESD(esd);}
799 AliESDpid::MakePID(esd);
800 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
802 if (fFillTriggerESD) {
803 if (!ReadESD(esd, "trigger")) {
804 if (!FillTriggerESD(esd)) {
805 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
807 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
813 //Try to improve the reconstructed primary vertex position using the tracks
814 AliESDVertex *pvtx=0;
815 Bool_t dovertex=kTRUE;
816 TObject* obj = fOptions.FindObject("ITS");
818 TString optITS = obj->GetTitle();
819 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
822 if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
823 if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
826 if (pvtx->GetStatus()) {
827 // Store the improved primary vertex
828 esd->SetPrimaryVertex(pvtx);
829 // Propagate the tracks to the DCA to the improved primary vertex
830 Double_t somethingbig = 777.;
831 Double_t bz = esd->GetMagneticField();
832 Int_t nt=esd->GetNumberOfTracks();
834 AliESDtrack *t = esd->GetTrack(nt);
835 t->RelateToVertex(pvtx, bz, somethingbig);
842 vtxer.Tracks2V0vertices(esd);
844 if (fRunCascadeFinder) {
846 AliCascadeVertexer cvtxer;
847 cvtxer.V0sTracks2CascadeVertices(esd);
852 if (fCleanESD) CleanESD(esd);
853 if (fWriteESDfriend) {
854 esdf->~AliESDfriend();
855 new (esdf) AliESDfriend(); // Reset...
856 esd->GetESDfriend(esdf);
863 if (fCheckPointLevel > 0) WriteESD(esd, "final");
866 if (fWriteESDfriend) {
867 esdf->~AliESDfriend();
868 new (esdf) AliESDfriend(); // Reset...
871 // delete esdf; esdf = 0;
874 gSystem->GetProcInfo(&ProcInfo);
875 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
879 // write quality assurance ESDs data (one entry for all events)
880 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
881 if (!IsSelected(fgkDetectorName[iDet], detStr))
883 AliQADataMaker * qadm = GetQADataMaker(iDet);
885 qadm->EndOfCycle(AliQA::kRECPOINTS);
886 qadm->EndOfCycle(AliQA::kESDS);
887 qadm->Finish(AliQA::kRECPOINTS);
888 qadm->Finish(AliQA::kESDS) ;
891 tree->GetUserInfo()->Add(esd);
892 hlttree->GetUserInfo()->Add(hltesd);
896 if(fESDPar.Contains("ESD.par")){
897 AliInfo("Attaching ESD.par to Tree");
898 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
899 tree->GetUserInfo()->Add(fn);
905 tree->SetBranchStatus("ESDfriend*",0);
906 // we want to have only one tree version number
907 tree->Write(tree->GetName(),TObject::kOverwrite);
911 TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE");
912 ESDFile2AODFile(file, aodFile);
917 CleanUp(file, fileOld);
919 // Create tags for the events in the ESD tree (the ESD tree is always present)
920 // In case of empty events the tags will contain dummy values
921 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
922 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent);
924 AliAODTagCreator *aodtagCreator = new AliAODTagCreator();
925 aodtagCreator->CreateAODTags(fFirstEvent,fLastEvent);
932 //_____________________________________________________________________________
933 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
935 // run the local reconstruction
936 static Int_t eventNr=0;
939 // AliCDBManager* man = AliCDBManager::Instance();
940 // Bool_t origCache = man->GetCacheFlag();
942 // TString detStr = detectors;
943 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
944 // if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
945 // AliReconstructor* reconstructor = GetReconstructor(iDet);
946 // if (!reconstructor) continue;
947 // if (reconstructor->HasLocalReconstruction()) continue;
949 // AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
950 // AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
952 // AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
953 // AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
955 // man->SetCacheFlag(kTRUE);
956 // TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
957 // man->GetAll(calibPath); // entries are cached!
959 // AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
962 // fRawReader->RewindEvents();
963 // reconstructor->Reconstruct(fRunLoader, fRawReader);
965 // reconstructor->Reconstruct(fRunLoader);
968 // AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
969 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
971 // // unload calibration data
972 // man->UnloadFromCache(calibPath);
973 // //man->ClearCache();
976 // man->SetCacheFlag(origCache);
978 // if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
979 // AliError(Form("the following detectors were not found: %s",
981 // if (fStopOnError) return kFALSE;
988 //_____________________________________________________________________________
989 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
991 // run the local reconstruction
992 static Int_t eventNr=0;
995 TString detStr = detectors;
996 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
997 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
998 AliReconstructor* reconstructor = GetReconstructor(iDet);
999 if (!reconstructor) continue;
1000 AliLoader* loader = fLoader[iDet];
1002 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1006 // conversion of digits
1007 if (fRawReader && reconstructor->HasDigitConversion()) {
1008 AliInfo(Form("converting raw data digits into root objects for %s",
1009 fgkDetectorName[iDet]));
1010 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1011 fgkDetectorName[iDet]));
1012 loader->LoadDigits("update");
1013 loader->CleanDigits();
1014 loader->MakeDigitsContainer();
1015 TTree* digitsTree = loader->TreeD();
1016 reconstructor->ConvertDigits(fRawReader, digitsTree);
1017 loader->WriteDigits("OVERWRITE");
1018 loader->UnloadDigits();
1021 // local reconstruction
1022 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1023 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1024 loader->LoadRecPoints("update");
1025 loader->CleanRecPoints();
1026 loader->MakeRecPointsContainer();
1027 TTree* clustersTree = loader->TreeR();
1028 if (fRawReader && !reconstructor->HasDigitConversion()) {
1029 reconstructor->Reconstruct(fRawReader, clustersTree);
1031 loader->LoadDigits("read");
1032 TTree* digitsTree = loader->TreeD();
1034 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1035 if (fStopOnError) return kFALSE;
1037 reconstructor->Reconstruct(digitsTree, clustersTree);
1039 loader->UnloadDigits();
1042 AliQADataMaker * qadm = GetQADataMaker(iDet);
1044 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1045 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1047 if (qadm->IsCycleDone() ) {
1048 qadm->EndOfCycle(AliQA::kRECPOINTS) ;
1049 qadm->EndOfCycle(AliQA::kESDS) ;
1050 qadm->StartOfCycle(AliQA::kRECPOINTS) ;
1051 qadm->StartOfCycle(AliQA::kESDS, "same") ;
1053 qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
1054 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
1057 loader->WriteRecPoints("OVERWRITE");
1058 loader->UnloadRecPoints();
1059 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
1062 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1063 AliError(Form("the following detectors were not found: %s",
1065 if (fStopOnError) return kFALSE;
1071 //_____________________________________________________________________________
1072 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
1074 // run the barrel tracking
1076 AliCodeTimerAuto("")
1078 AliESDVertex* vertex = NULL;
1079 Double_t vtxPos[3] = {0, 0, 0};
1080 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1081 TArrayF mcVertex(3);
1082 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1083 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1084 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1088 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1089 AliInfo("running the ITS vertex finder");
1090 if (fLoader[0]) fLoader[0]->LoadRecPoints();
1091 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
1092 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
1094 AliWarning("Vertex not found");
1095 vertex = new AliESDVertex();
1096 vertex->SetName("default");
1099 vertex->SetName("reconstructed");
1103 AliInfo("getting the primary vertex from MC");
1104 vertex = new AliESDVertex(vtxPos, vtxErr);
1108 vertex->GetXYZ(vtxPos);
1109 vertex->GetSigmaXYZ(vtxErr);
1111 AliWarning("no vertex reconstructed");
1112 vertex = new AliESDVertex(vtxPos, vtxErr);
1114 esd->SetVertex(vertex);
1115 // if SPD multiplicity has been determined, it is stored in the ESD
1116 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1117 if(mult)esd->SetMultiplicity(mult);
1119 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1120 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1127 //_____________________________________________________________________________
1128 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1130 // run the HLT barrel tracking
1132 AliCodeTimerAuto("")
1135 AliError("Missing runLoader!");
1139 AliInfo("running HLT tracking");
1141 // Get a pointer to the HLT reconstructor
1142 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1143 if (!reconstructor) return kFALSE;
1146 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1147 TString detName = fgkDetectorName[iDet];
1148 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1149 reconstructor->SetOption(detName.Data());
1150 AliTracker *tracker = reconstructor->CreateTracker();
1152 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1153 if (fStopOnError) return kFALSE;
1157 Double_t vtxErr[3]={0.005,0.005,0.010};
1158 const AliESDVertex *vertex = esd->GetVertex();
1159 vertex->GetXYZ(vtxPos);
1160 tracker->SetVertex(vtxPos,vtxErr);
1162 fLoader[iDet]->LoadRecPoints("read");
1163 TTree* tree = fLoader[iDet]->TreeR();
1165 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1168 tracker->LoadClusters(tree);
1170 if (tracker->Clusters2Tracks(esd) != 0) {
1171 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1175 tracker->UnloadClusters();
1183 //_____________________________________________________________________________
1184 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1186 // run the muon spectrometer tracking
1188 AliCodeTimerAuto("")
1191 AliError("Missing runLoader!");
1194 Int_t iDet = 7; // for MUON
1196 AliInfo("is running...");
1198 // Get a pointer to the MUON reconstructor
1199 AliReconstructor *reconstructor = GetReconstructor(iDet);
1200 if (!reconstructor) return kFALSE;
1203 TString detName = fgkDetectorName[iDet];
1204 AliDebug(1, Form("%s tracking", detName.Data()));
1205 AliTracker *tracker = reconstructor->CreateTracker();
1207 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1212 fLoader[iDet]->LoadTracks("update");
1213 fLoader[iDet]->CleanTracks();
1214 fLoader[iDet]->MakeTracksContainer();
1217 fLoader[iDet]->LoadRecPoints("read");
1218 tracker->LoadClusters(fLoader[iDet]->TreeR());
1220 Int_t rv = tracker->Clusters2Tracks(esd);
1222 fLoader[iDet]->UnloadRecPoints();
1226 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1230 tracker->UnloadClusters();
1232 fLoader[iDet]->UnloadRecPoints();
1234 fLoader[iDet]->WriteTracks("OVERWRITE");
1235 fLoader[iDet]->UnloadTracks();
1243 //_____________________________________________________________________________
1244 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1246 // run the barrel tracking
1247 static Int_t eventNr=0;
1248 AliCodeTimerAuto("")
1250 AliInfo("running tracking");
1252 //Fill the ESD with the T0 info (will be used by the TOF)
1253 if (fReconstructor[11] && fLoader[11]) {
1254 fLoader[11]->LoadRecPoints("READ");
1255 TTree *treeR = fLoader[11]->TreeR();
1256 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1259 // pass 1: TPC + ITS inwards
1260 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1261 if (!fTracker[iDet]) continue;
1262 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1265 fLoader[iDet]->LoadRecPoints("read");
1266 TTree* tree = fLoader[iDet]->TreeR();
1268 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1271 fTracker[iDet]->LoadClusters(tree);
1274 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1275 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1278 if (fCheckPointLevel > 1) {
1279 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1281 // preliminary PID in TPC needed by the ITS tracker
1283 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1284 AliESDpid::MakePID(esd);
1286 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr));
1289 // pass 2: ALL backwards
1290 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1291 if (!fTracker[iDet]) continue;
1292 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1295 if (iDet > 1) { // all except ITS, TPC
1297 fLoader[iDet]->LoadRecPoints("read");
1298 tree = fLoader[iDet]->TreeR();
1300 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1303 fTracker[iDet]->LoadClusters(tree);
1304 AliSysInfo::AddStamp(Form("LoadCluster0%s_%d",fgkDetectorName[iDet],eventNr));
1308 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1309 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1312 if (fCheckPointLevel > 1) {
1313 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1317 if (iDet > 2) { // all except ITS, TPC, TRD
1318 fTracker[iDet]->UnloadClusters();
1319 fLoader[iDet]->UnloadRecPoints();
1321 // updated PID in TPC needed by the ITS tracker -MI
1323 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1324 AliESDpid::MakePID(esd);
1326 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr));
1329 // write space-points to the ESD in case alignment data output
1331 if (fWriteAlignmentData)
1332 WriteAlignmentData(esd);
1334 // pass 3: TRD + TPC + ITS refit inwards
1335 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1336 if (!fTracker[iDet]) continue;
1337 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1340 if (fTracker[iDet]->RefitInward(esd) != 0) {
1341 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1344 if (fCheckPointLevel > 1) {
1345 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1349 fTracker[iDet]->UnloadClusters();
1350 fLoader[iDet]->UnloadRecPoints();
1351 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr));
1354 // Propagate track to the vertex - if not done by ITS
1356 Int_t ntracks = esd->GetNumberOfTracks();
1357 for (Int_t itrack=0; itrack<ntracks; itrack++){
1358 const Double_t kRadius = 3; // beam pipe radius
1359 const Double_t kMaxStep = 5; // max step
1360 const Double_t kMaxD = 123456; // max distance to prim vertex
1361 Double_t fieldZ = AliTracker::GetBz(); //
1362 AliESDtrack * track = esd->GetTrack(itrack);
1363 if (!track) continue;
1364 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1365 AliTracker::PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1366 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1372 //_____________________________________________________________________________
1373 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1375 // Remove the data which are not needed for the physics analysis.
1378 AliInfo("Cleaning the ESD...");
1379 Int_t nTracks=esd->GetNumberOfTracks();
1380 AliInfo(Form("Number of ESD tracks before cleaning %d",nTracks));
1382 Float_t cleanPars[]={fDmax,fZmax};
1383 Bool_t rc=esd->Clean(cleanPars);
1385 nTracks=esd->GetNumberOfTracks();
1386 AliInfo(Form("Number of ESD tracks after cleaning %d",nTracks));
1391 //_____________________________________________________________________________
1392 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1394 // fill the event summary data
1396 AliCodeTimerAuto("")
1397 static Int_t eventNr=0;
1398 TString detStr = detectors;
1399 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1400 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1401 AliReconstructor* reconstructor = GetReconstructor(iDet);
1402 if (!reconstructor) continue;
1404 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1405 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1406 TTree* clustersTree = NULL;
1407 if (fLoader[iDet]) {
1408 fLoader[iDet]->LoadRecPoints("read");
1409 clustersTree = fLoader[iDet]->TreeR();
1410 if (!clustersTree) {
1411 AliError(Form("Can't get the %s clusters tree",
1412 fgkDetectorName[iDet]));
1413 if (fStopOnError) return kFALSE;
1416 if (fRawReader && !reconstructor->HasDigitConversion()) {
1417 reconstructor->FillESD(fRawReader, clustersTree, esd);
1419 TTree* digitsTree = NULL;
1420 if (fLoader[iDet]) {
1421 fLoader[iDet]->LoadDigits("read");
1422 digitsTree = fLoader[iDet]->TreeD();
1424 AliError(Form("Can't get the %s digits tree",
1425 fgkDetectorName[iDet]));
1426 if (fStopOnError) return kFALSE;
1429 reconstructor->FillESD(digitsTree, clustersTree, esd);
1430 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1432 if (fLoader[iDet]) {
1433 fLoader[iDet]->UnloadRecPoints();
1436 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1440 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1441 AliError(Form("the following detectors were not found: %s",
1443 if (fStopOnError) return kFALSE;
1445 AliSysInfo::AddStamp(Form("FillESD%d",eventNr));
1450 //_____________________________________________________________________________
1451 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1453 // Reads the trigger decision which is
1454 // stored in Trigger.root file and fills
1455 // the corresponding esd entries
1457 AliCodeTimerAuto("")
1459 AliInfo("Filling trigger information into the ESD");
1462 AliCTPRawStream input(fRawReader);
1463 if (!input.Next()) {
1464 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1467 esd->SetTriggerMask(input.GetClassMask());
1468 esd->SetTriggerCluster(input.GetClusterMask());
1471 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1473 if (!runloader->LoadTrigger()) {
1474 AliCentralTrigger *aCTP = runloader->GetTrigger();
1475 esd->SetTriggerMask(aCTP->GetClassMask());
1476 esd->SetTriggerCluster(aCTP->GetClusterMask());
1479 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1484 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1496 //_____________________________________________________________________________
1497 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1500 // Filling information from RawReader Header
1503 AliInfo("Filling information from RawReader Header");
1504 esd->SetBunchCrossNumber(0);
1505 esd->SetOrbitNumber(0);
1506 esd->SetPeriodNumber(0);
1507 esd->SetTimeStamp(0);
1508 esd->SetEventType(0);
1509 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1512 const UInt_t *id = eventHeader->GetP("Id");
1513 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1514 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1515 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1517 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1518 esd->SetEventType((eventHeader->Get("Type")));
1525 //_____________________________________________________________________________
1526 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1528 // check whether detName is contained in detectors
1529 // if yes, it is removed from detectors
1531 // check if all detectors are selected
1532 if ((detectors.CompareTo("ALL") == 0) ||
1533 detectors.BeginsWith("ALL ") ||
1534 detectors.EndsWith(" ALL") ||
1535 detectors.Contains(" ALL ")) {
1540 // search for the given detector
1541 Bool_t result = kFALSE;
1542 if ((detectors.CompareTo(detName) == 0) ||
1543 detectors.BeginsWith(detName+" ") ||
1544 detectors.EndsWith(" "+detName) ||
1545 detectors.Contains(" "+detName+" ")) {
1546 detectors.ReplaceAll(detName, "");
1550 // clean up the detectors string
1551 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1552 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1553 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1558 //_____________________________________________________________________________
1559 Bool_t AliReconstruction::InitRunLoader()
1561 // get or create the run loader
1563 if (gAlice) delete gAlice;
1566 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1567 // load all base libraries to get the loader classes
1568 TString libs = gSystem->GetLibraries();
1569 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1570 TString detName = fgkDetectorName[iDet];
1571 if (detName == "HLT") continue;
1572 if (libs.Contains("lib" + detName + "base.so")) continue;
1573 gSystem->Load("lib" + detName + "base.so");
1575 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1577 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1581 fRunLoader->CdGAFile();
1582 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1583 if (fRunLoader->LoadgAlice() == 0) {
1584 gAlice = fRunLoader->GetAliRun();
1585 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1588 if (!gAlice && !fRawReader) {
1589 AliError(Form("no gAlice object found in file %s",
1590 fGAliceFileName.Data()));
1595 //PH This is a temporary fix to give access to the kinematics
1596 //PH that is needed for the labels of ITS clusters
1597 fRunLoader->LoadKinematics();
1599 } else { // galice.root does not exist
1601 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1605 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1606 AliConfig::GetDefaultEventFolderName(),
1609 AliError(Form("could not create run loader in file %s",
1610 fGAliceFileName.Data()));
1614 fRunLoader->MakeTree("E");
1616 while (fRawReader->NextEvent()) {
1617 fRunLoader->SetEventNumber(iEvent);
1618 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1620 fRunLoader->MakeTree("H");
1621 fRunLoader->TreeE()->Fill();
1624 fRawReader->RewindEvents();
1625 if (fNumberOfEventsPerFile > 0)
1626 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1628 fRunLoader->SetNumberOfEventsPerFile(iEvent);
1629 fRunLoader->WriteHeader("OVERWRITE");
1630 fRunLoader->CdGAFile();
1631 fRunLoader->Write(0, TObject::kOverwrite);
1632 // AliTracker::SetFieldMap(???);
1638 //_____________________________________________________________________________
1639 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1641 // get the reconstructor object and the loader for a detector
1643 if (fReconstructor[iDet]) return fReconstructor[iDet];
1645 // load the reconstructor object
1646 TPluginManager* pluginManager = gROOT->GetPluginManager();
1647 TString detName = fgkDetectorName[iDet];
1648 TString recName = "Ali" + detName + "Reconstructor";
1649 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1651 AliReconstructor* reconstructor = NULL;
1652 // first check if a plugin is defined for the reconstructor
1653 TPluginHandler* pluginHandler =
1654 pluginManager->FindHandler("AliReconstructor", detName);
1655 // if not, add a plugin for it
1656 if (!pluginHandler) {
1657 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1658 TString libs = gSystem->GetLibraries();
1659 if (libs.Contains("lib" + detName + "base.so") ||
1660 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1661 pluginManager->AddHandler("AliReconstructor", detName,
1662 recName, detName + "rec", recName + "()");
1664 pluginManager->AddHandler("AliReconstructor", detName,
1665 recName, detName, recName + "()");
1667 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1669 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1670 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1672 if (reconstructor) {
1673 TObject* obj = fOptions.FindObject(detName.Data());
1674 if (obj) reconstructor->SetOption(obj->GetTitle());
1675 reconstructor->Init();
1676 fReconstructor[iDet] = reconstructor;
1679 // get or create the loader
1680 if (detName != "HLT") {
1681 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1682 if (!fLoader[iDet]) {
1683 AliConfig::Instance()
1684 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1686 // first check if a plugin is defined for the loader
1688 pluginManager->FindHandler("AliLoader", detName);
1689 // if not, add a plugin for it
1690 if (!pluginHandler) {
1691 TString loaderName = "Ali" + detName + "Loader";
1692 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1693 pluginManager->AddHandler("AliLoader", detName,
1694 loaderName, detName + "base",
1695 loaderName + "(const char*, TFolder*)");
1696 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1698 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1700 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1701 fRunLoader->GetEventFolder());
1703 if (!fLoader[iDet]) { // use default loader
1704 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1706 if (!fLoader[iDet]) {
1707 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1708 if (fStopOnError) return NULL;
1710 fRunLoader->AddLoader(fLoader[iDet]);
1711 fRunLoader->CdGAFile();
1712 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1713 fRunLoader->Write(0, TObject::kOverwrite);
1718 return reconstructor;
1721 //_____________________________________________________________________________
1722 Bool_t AliReconstruction::CreateVertexer()
1724 // create the vertexer
1727 AliReconstructor* itsReconstructor = GetReconstructor(0);
1728 if (itsReconstructor) {
1729 fVertexer = itsReconstructor->CreateVertexer();
1732 AliWarning("couldn't create a vertexer for ITS");
1733 if (fStopOnError) return kFALSE;
1739 //_____________________________________________________________________________
1740 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1742 // create the trackers
1744 TString detStr = detectors;
1745 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1746 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1747 AliReconstructor* reconstructor = GetReconstructor(iDet);
1748 if (!reconstructor) continue;
1749 TString detName = fgkDetectorName[iDet];
1750 if (detName == "HLT") {
1751 fRunHLTTracking = kTRUE;
1754 if (detName == "MUON") {
1755 fRunMuonTracking = kTRUE;
1760 fTracker[iDet] = reconstructor->CreateTracker();
1761 if (!fTracker[iDet] && (iDet < 7)) {
1762 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1763 if (fStopOnError) return kFALSE;
1770 //_____________________________________________________________________________
1771 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1773 // delete trackers and the run loader and close and delete the file
1775 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1776 delete fReconstructor[iDet];
1777 fReconstructor[iDet] = NULL;
1778 fLoader[iDet] = NULL;
1779 delete fTracker[iDet];
1780 fTracker[iDet] = NULL;
1781 delete fQADataMaker[iDet];
1782 fQADataMaker[iDet] = NULL;
1786 delete fDiamondProfile;
1787 fDiamondProfile = NULL;
1802 gSystem->Unlink("AliESDs.old.root");
1806 //_____________________________________________________________________________
1808 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
1810 // read the ESD event from a file
1812 if (!esd) return kFALSE;
1814 sprintf(fileName, "ESD_%d.%d_%s.root",
1815 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1816 if (gSystem->AccessPathName(fileName)) return kFALSE;
1818 AliInfo(Form("reading ESD from file %s", fileName));
1819 AliDebug(1, Form("reading ESD from file %s", fileName));
1820 TFile* file = TFile::Open(fileName);
1821 if (!file || !file->IsOpen()) {
1822 AliError(Form("opening %s failed", fileName));
1829 esd = (AliESDEvent*) file->Get("ESD");
1838 //_____________________________________________________________________________
1839 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
1841 // write the ESD event to a file
1845 sprintf(fileName, "ESD_%d.%d_%s.root",
1846 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1848 AliDebug(1, Form("writing ESD to file %s", fileName));
1849 TFile* file = TFile::Open(fileName, "recreate");
1850 if (!file || !file->IsOpen()) {
1851 AliError(Form("opening %s failed", fileName));
1863 //_____________________________________________________________________________
1864 void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
1866 // write all files from the given esd file to an aod file
1868 // create an AliAOD object
1869 AliAODEvent *aod = new AliAODEvent();
1870 aod->CreateStdContent();
1876 TTree *aodTree = new TTree("aodTree", "AliAOD tree");
1877 aodTree->Branch(aod->GetList());
1880 TTree *t = (TTree*) esdFile->Get("esdTree");
1881 AliESDEvent *esd = new AliESDEvent();
1882 esd->ReadFromTree(t);
1884 Int_t nEvents = t->GetEntries();
1886 // set arrays and pointers
1894 // loop over events and fill them
1895 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
1896 t->GetEntry(iEvent);
1898 // Multiplicity information needed by the header (to be revised!)
1899 Int_t nTracks = esd->GetNumberOfTracks();
1900 Int_t nPosTracks = 0;
1901 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack)
1902 if (esd->GetTrack(iTrack)->Charge()> 0) nPosTracks++;
1904 // Access the header
1905 AliAODHeader *header = aod->GetHeader();
1908 header->SetRunNumber (esd->GetRunNumber() );
1909 header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
1910 header->SetOrbitNumber (esd->GetOrbitNumber() );
1911 header->SetPeriodNumber (esd->GetPeriodNumber() );
1912 header->SetTriggerMask (esd->GetTriggerMask() );
1913 header->SetTriggerCluster (esd->GetTriggerCluster() );
1914 header->SetEventType (esd->GetEventType() );
1915 header->SetMagneticField (esd->GetMagneticField() );
1916 header->SetZDCN1Energy (esd->GetZDCN1Energy() );
1917 header->SetZDCP1Energy (esd->GetZDCP1Energy() );
1918 header->SetZDCN2Energy (esd->GetZDCN2Energy() );
1919 header->SetZDCP2Energy (esd->GetZDCP2Energy() );
1920 header->SetZDCEMEnergy (esd->GetZDCEMEnergy() );
1921 header->SetRefMultiplicity (nTracks);
1922 header->SetRefMultiplicityPos(nPosTracks);
1923 header->SetRefMultiplicityNeg(nTracks - nPosTracks);
1924 header->SetMuonMagFieldScale(-999.); // FIXME
1925 header->SetCentrality(-999.); // FIXME
1927 Int_t nV0s = esd->GetNumberOfV0s();
1928 Int_t nCascades = esd->GetNumberOfCascades();
1929 Int_t nKinks = esd->GetNumberOfKinks();
1930 Int_t nVertices = nV0s + nCascades + nKinks;
1932 aod->ResetStd(nTracks, nVertices);
1933 AliAODTrack *aodTrack;
1935 // Array to take into account the tracks already added to the AOD
1936 Bool_t * usedTrack = NULL;
1938 usedTrack = new Bool_t[nTracks];
1939 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
1941 // Array to take into account the V0s already added to the AOD
1942 Bool_t * usedV0 = NULL;
1944 usedV0 = new Bool_t[nV0s];
1945 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
1947 // Array to take into account the kinks already added to the AOD
1948 Bool_t * usedKink = NULL;
1950 usedKink = new Bool_t[nKinks];
1951 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
1954 // Access to the AOD container of vertices
1955 TClonesArray &vertices = *(aod->GetVertices());
1958 // Access to the AOD container of tracks
1959 TClonesArray &tracks = *(aod->GetTracks());
1962 // Add primary vertex. The primary tracks will be defined
1963 // after the loops on the composite objects (V0, cascades, kinks)
1964 const AliESDVertex *vtx = esd->GetPrimaryVertex();
1966 vtx->GetXYZ(pos); // position
1967 vtx->GetCovMatrix(covVtx); //covariance matrix
1969 AliAODVertex * primary = new(vertices[jVertices++])
1970 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, -1, AliAODVertex::kPrimary);
1972 // Create vertices starting from the most complex objects
1975 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
1976 AliESDcascade *cascade = esd->GetCascade(nCascade);
1978 cascade->GetXYZcascade(pos[0], pos[1], pos[2]); // Bo: bug correction
1979 cascade->GetPosCovXi(covVtx);
1981 // Add the cascade vertex
1982 AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
1984 cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
1987 AliAODVertex::kCascade);
1989 primary->AddDaughter(vcascade);
1991 // Add the V0 from the cascade. The ESD class have to be optimized...
1992 // Now we have to search for the corresponding V0 in the list of V0s
1993 // using the indeces of the positive and negative tracks
1995 Int_t posFromV0 = cascade->GetPindex();
1996 Int_t negFromV0 = cascade->GetNindex();
1998 AliESDv0 * v0 = 0x0;
2001 for (Int_t iV0=0; iV0<nV0s; ++iV0) {
2003 v0 = esd->GetV0(iV0);
2004 Int_t posV0 = v0->GetPindex();
2005 Int_t negV0 = v0->GetNindex();
2007 if (posV0==posFromV0 && negV0==negFromV0) {
2013 AliAODVertex * vV0FromCascade = 0x0;
2015 if (indV0>-1 && !usedV0[indV0] ) {
2017 // the V0 exists in the array of V0s and is not used
2019 usedV0[indV0] = kTRUE;
2021 v0->GetXYZ(pos[0], pos[1], pos[2]);
2022 v0->GetPosCov(covVtx);
2024 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2026 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2032 // the V0 doesn't exist in the array of V0s or was used
2033 cerr << "Error: event " << iEvent << " cascade " << nCascade
2034 << " The V0 " << indV0
2035 << " doesn't exist in the array of V0s or was used!" << endl;
2037 cascade->GetXYZ(pos[0], pos[1], pos[2]);
2038 cascade->GetPosCov(covVtx);
2040 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2042 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2046 vcascade->AddDaughter(vV0FromCascade);
2049 // Add the positive tracks from the V0
2051 if (! usedTrack[posFromV0]) {
2053 usedTrack[posFromV0] = kTRUE;
2055 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2056 esdTrack->GetPxPyPz(p);
2057 esdTrack->GetXYZ(pos);
2058 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2059 esdTrack->GetESDpid(pid);
2061 vV0FromCascade->AddDaughter(aodTrack =
2062 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2063 esdTrack->GetLabel(),
2069 (Short_t)esdTrack->Charge(),
2070 esdTrack->GetITSClusterMap(),
2073 kTRUE, // check if this is right
2074 kFALSE, // check if this is right
2075 AliAODTrack::kSecondary)
2077 aodTrack->ConvertAliPIDtoAODPID();
2080 cerr << "Error: event " << iEvent << " cascade " << nCascade
2081 << " track " << posFromV0 << " has already been used!" << endl;
2084 // Add the negative tracks from the V0
2086 if (!usedTrack[negFromV0]) {
2088 usedTrack[negFromV0] = kTRUE;
2090 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2091 esdTrack->GetPxPyPz(p);
2092 esdTrack->GetXYZ(pos);
2093 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2094 esdTrack->GetESDpid(pid);
2096 vV0FromCascade->AddDaughter(aodTrack =
2097 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2098 esdTrack->GetLabel(),
2104 (Short_t)esdTrack->Charge(),
2105 esdTrack->GetITSClusterMap(),
2108 kTRUE, // check if this is right
2109 kFALSE, // check if this is right
2110 AliAODTrack::kSecondary)
2112 aodTrack->ConvertAliPIDtoAODPID();
2115 cerr << "Error: event " << iEvent << " cascade " << nCascade
2116 << " track " << negFromV0 << " has already been used!" << endl;
2119 // Add the bachelor track from the cascade
2121 Int_t bachelor = cascade->GetBindex();
2123 if(!usedTrack[bachelor]) {
2125 usedTrack[bachelor] = kTRUE;
2127 AliESDtrack *esdTrack = esd->GetTrack(bachelor);
2128 esdTrack->GetPxPyPz(p);
2129 esdTrack->GetXYZ(pos);
2130 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2131 esdTrack->GetESDpid(pid);
2133 vcascade->AddDaughter(aodTrack =
2134 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2135 esdTrack->GetLabel(),
2141 (Short_t)esdTrack->Charge(),
2142 esdTrack->GetITSClusterMap(),
2145 kTRUE, // check if this is right
2146 kFALSE, // check if this is right
2147 AliAODTrack::kSecondary)
2149 aodTrack->ConvertAliPIDtoAODPID();
2152 cerr << "Error: event " << iEvent << " cascade " << nCascade
2153 << " track " << bachelor << " has already been used!" << endl;
2156 // Add the primary track of the cascade (if any)
2158 } // end of the loop on cascades
2162 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
2164 if (usedV0[nV0]) continue; // skip if aready added to the AOD
2166 AliESDv0 *v0 = esd->GetV0(nV0);
2168 v0->GetXYZ(pos[0], pos[1], pos[2]);
2169 v0->GetPosCov(covVtx);
2171 AliAODVertex * vV0 =
2172 new(vertices[jVertices++]) AliAODVertex(pos,
2174 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2178 primary->AddDaughter(vV0);
2180 Int_t posFromV0 = v0->GetPindex();
2181 Int_t negFromV0 = v0->GetNindex();
2183 // Add the positive tracks from the V0
2185 if (!usedTrack[posFromV0]) {
2187 usedTrack[posFromV0] = kTRUE;
2189 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2190 esdTrack->GetPxPyPz(p);
2191 esdTrack->GetXYZ(pos);
2192 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2193 esdTrack->GetESDpid(pid);
2195 vV0->AddDaughter(aodTrack =
2196 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2197 esdTrack->GetLabel(),
2203 (Short_t)esdTrack->Charge(),
2204 esdTrack->GetITSClusterMap(),
2207 kTRUE, // check if this is right
2208 kFALSE, // check if this is right
2209 AliAODTrack::kSecondary)
2211 aodTrack->ConvertAliPIDtoAODPID();
2214 cerr << "Error: event " << iEvent << " V0 " << nV0
2215 << " track " << posFromV0 << " has already been used!" << endl;
2218 // Add the negative tracks from the V0
2220 if (!usedTrack[negFromV0]) {
2222 usedTrack[negFromV0] = kTRUE;
2224 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2225 esdTrack->GetPxPyPz(p);
2226 esdTrack->GetXYZ(pos);
2227 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2228 esdTrack->GetESDpid(pid);
2230 vV0->AddDaughter(aodTrack =
2231 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2232 esdTrack->GetLabel(),
2238 (Short_t)esdTrack->Charge(),
2239 esdTrack->GetITSClusterMap(),
2242 kTRUE, // check if this is right
2243 kFALSE, // check if this is right
2244 AliAODTrack::kSecondary)
2246 aodTrack->ConvertAliPIDtoAODPID();
2249 cerr << "Error: event " << iEvent << " V0 " << nV0
2250 << " track " << negFromV0 << " has already been used!" << endl;
2253 } // end of the loop on V0s
2255 // Kinks: it is a big mess the access to the information in the kinks
2256 // The loop is on the tracks in order to find the mother and daugther of each kink
2259 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2262 AliESDtrack * esdTrack = esd->GetTrack(iTrack);
2264 Int_t ikink = esdTrack->GetKinkIndex(0);
2267 // Negative kink index: mother, positive: daughter
2269 // Search for the second track of the kink
2271 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
2273 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
2275 Int_t jkink = esdTrack1->GetKinkIndex(0);
2277 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
2279 // The two tracks are from the same kink
2281 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
2284 Int_t idaughter = -1;
2286 if (ikink<0 && jkink>0) {
2291 else if (ikink>0 && jkink<0) {
2297 cerr << "Error: Wrong combination of kink indexes: "
2298 << ikink << " " << jkink << endl;
2302 // Add the mother track
2304 AliAODTrack * mother = NULL;
2306 if (!usedTrack[imother]) {
2308 usedTrack[imother] = kTRUE;
2310 AliESDtrack *esdTrack = esd->GetTrack(imother);
2311 esdTrack->GetPxPyPz(p);
2312 esdTrack->GetXYZ(pos);
2313 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2314 esdTrack->GetESDpid(pid);
2317 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2318 esdTrack->GetLabel(),
2324 (Short_t)esdTrack->Charge(),
2325 esdTrack->GetITSClusterMap(),
2328 kTRUE, // check if this is right
2329 kTRUE, // check if this is right
2330 AliAODTrack::kPrimary);
2331 primary->AddDaughter(mother);
2332 mother->ConvertAliPIDtoAODPID();
2335 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2336 << " track " << imother << " has already been used!" << endl;
2339 // Add the kink vertex
2340 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
2342 AliAODVertex * vkink =
2343 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
2347 esdTrack->GetID(), // This is the track ID of the mother's track!
2348 AliAODVertex::kKink);
2349 // Add the daughter track
2351 AliAODTrack * daughter = NULL;
2353 if (!usedTrack[idaughter]) {
2355 usedTrack[idaughter] = kTRUE;
2357 AliESDtrack *esdTrack = esd->GetTrack(idaughter);
2358 esdTrack->GetPxPyPz(p);
2359 esdTrack->GetXYZ(pos);
2360 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2361 esdTrack->GetESDpid(pid);
2364 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2365 esdTrack->GetLabel(),
2371 (Short_t)esdTrack->Charge(),
2372 esdTrack->GetITSClusterMap(),
2375 kTRUE, // check if this is right
2376 kTRUE, // check if this is right
2377 AliAODTrack::kPrimary);
2378 vkink->AddDaughter(daughter);
2379 daughter->ConvertAliPIDtoAODPID();
2382 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2383 << " track " << idaughter << " has already been used!" << endl;
2395 // Tracks (primary and orphan)
2397 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
2400 if (usedTrack[nTrack]) continue;
2402 AliESDtrack *esdTrack = esd->GetTrack(nTrack);
2403 esdTrack->GetPxPyPz(p);
2404 esdTrack->GetXYZ(pos);
2405 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2406 esdTrack->GetESDpid(pid);
2408 Float_t impactXY, impactZ;
2410 esdTrack->GetImpactParameters(impactXY,impactZ);
2413 // track inside the beam pipe
2415 primary->AddDaughter(aodTrack =
2416 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2417 esdTrack->GetLabel(),
2423 (Short_t)esdTrack->Charge(),
2424 esdTrack->GetITSClusterMap(),
2427 kTRUE, // check if this is right
2428 kTRUE, // check if this is right
2429 AliAODTrack::kPrimary)
2431 aodTrack->ConvertAliPIDtoAODPID();
2434 // outside the beam pipe: orphan track
2436 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2437 esdTrack->GetLabel(),
2443 (Short_t)esdTrack->Charge(),
2444 esdTrack->GetITSClusterMap(),
2447 kFALSE, // check if this is right
2448 kFALSE, // check if this is right
2449 AliAODTrack::kOrphan);
2450 aodTrack->ConvertAliPIDtoAODPID();
2452 } // end of loop on tracks
2455 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
2456 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
2458 AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);
2459 p[0] = esdMuTrack->Px();
2460 p[1] = esdMuTrack->Py();
2461 p[2] = esdMuTrack->Pz();
2462 pos[0] = primary->GetX();
2463 pos[1] = primary->GetY();
2464 pos[2] = primary->GetZ();
2466 // has to be changed once the muon pid is provided by the ESD
2467 for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
2469 primary->AddDaughter(aodTrack =
2470 new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
2471 0, // no label provided
2476 NULL, // no covariance matrix provided
2477 esdMuTrack->Charge(),
2478 0, // ITSClusterMap is set below
2481 kFALSE, // muon tracks are not used to fit the primary vtx
2482 kFALSE, // not used for vertex fit
2483 AliAODTrack::kPrimary)
2486 aodTrack->SetHitsPatternInTrigCh(esdMuTrack->GetHitsPatternInTrigCh());
2487 Int_t track2Trigger = esdMuTrack->GetMatchTrigger();
2488 aodTrack->SetMatchTrigger(track2Trigger);
2490 aodTrack->SetChi2MatchTrigger(esdMuTrack->GetChi2MatchTrigger());
2492 aodTrack->SetChi2MatchTrigger(0.);
2495 // Access to the AOD container of clusters
2496 TClonesArray &clusters = *(aod->GetClusters());
2500 Int_t nClusters = esd->GetNumberOfCaloClusters();
2502 for (Int_t iClust=0; iClust<nClusters; ++iClust) {
2504 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
2506 Int_t id = cluster->GetID();
2508 Float_t energy = cluster->E();
2509 cluster->GetPosition(posF);
2510 AliAODVertex *prodVertex = primary;
2511 AliAODTrack *primTrack = NULL;
2512 Char_t ttype=AliAODCluster::kUndef;
2514 if (cluster->GetClusterType() == AliESDCaloCluster::kPHOSCluster){
2515 ttype = AliAODCluster::kPHOSNeutral;
2517 else if (cluster->GetClusterType() == AliESDCaloCluster::kEMCALClusterv1){
2518 ttype = AliAODCluster::kEMCALClusterv1;
2520 else if (cluster->GetClusterType() == AliESDCaloCluster::kEMCALPseudoCluster){
2521 ttype = AliAODCluster::kEMCALPseudoCluster;
2524 new(clusters[jClusters++]) AliAODCluster(id,
2528 NULL, // no covariance matrix provided
2529 NULL, // no pid for clusters provided
2534 } // end of loop on calo clusters
2537 const AliMultiplicity *mult = esd->GetMultiplicity();
2539 if (mult->GetNumberOfTracklets()>0) {
2540 aod->GetTracklets()->CreateContainer(mult->GetNumberOfTracklets());
2542 for (Int_t n=0; n<mult->GetNumberOfTracklets(); n++) {
2543 aod->GetTracklets()->SetTracklet(n, mult->GetTheta(n), mult->GetPhi(n), mult->GetDeltaPhi(n), mult->GetLabel(n));
2547 Printf("ERROR: AliMultiplicity could not be retrieved from ESD");
2550 delete [] usedTrack;
2554 // fill the tree for this event
2556 } // end of event loop
2558 aodTree->GetUserInfo()->Add(aod);
2563 // write the tree to the specified file
2564 aodFile = aodTree->GetCurrentFile();
2571 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2573 // Write space-points which are then used in the alignment procedures
2574 // For the moment only ITS, TRD and TPC
2576 // Load TOF clusters
2578 fLoader[3]->LoadRecPoints("read");
2579 TTree* tree = fLoader[3]->TreeR();
2581 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2584 fTracker[3]->LoadClusters(tree);
2586 Int_t ntracks = esd->GetNumberOfTracks();
2587 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2589 AliESDtrack *track = esd->GetTrack(itrack);
2592 for (Int_t iDet = 3; iDet >= 0; iDet--)
2593 nsp += track->GetNcls(iDet);
2595 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2596 track->SetTrackPointArray(sp);
2598 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2599 AliTracker *tracker = fTracker[iDet];
2600 if (!tracker) continue;
2601 Int_t nspdet = track->GetNcls(iDet);
2602 if (nspdet <= 0) continue;
2603 track->GetClusters(iDet,idx);
2607 while (isp < nspdet) {
2609 if(IsSelected(fgkDetectorName[iDet],fUseTrackingErrorsForAlignment)) {
2610 isvalid = tracker->GetTrackPointTrackingError(idx[isp2],p,track);
2612 isvalid = tracker->GetTrackPoint(idx[isp2],p);
2615 const Int_t kNTPCmax = 159;
2616 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2617 if (!isvalid) continue;
2618 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2624 fTracker[3]->UnloadClusters();
2625 fLoader[3]->UnloadRecPoints();
2629 //_____________________________________________________________________________
2630 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2632 // The method reads the raw-data error log
2633 // accumulated within the rawReader.
2634 // It extracts the raw-data errors related to
2635 // the current event and stores them into
2636 // a TClonesArray inside the esd object.
2638 if (!fRawReader) return;
2640 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2642 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2644 if (iEvent != log->GetEventNumber()) continue;
2646 esd->AddRawDataErrorLog(log);
2651 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2652 // Dump a file content into a char in TNamed
2654 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2655 Int_t kBytes = (Int_t)in.tellg();
2656 printf("Size: %d \n",kBytes);
2659 char* memblock = new char [kBytes];
2660 in.seekg (0, ios::beg);
2661 in.read (memblock, kBytes);
2663 TString fData(memblock,kBytes);
2664 fn = new TNamed(fName,fData);
2665 printf("fData Size: %d \n",fData.Sizeof());
2666 printf("fName Size: %d \n",fName.Sizeof());
2667 printf("fn Size: %d \n",fn->Sizeof());
2671 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2677 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2678 // This is not really needed in AliReconstruction at the moment
2679 // but can serve as a template
2681 TList *fList = fTree->GetUserInfo();
2682 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2683 printf("fn Size: %d \n",fn->Sizeof());
2685 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2686 const char* cdata = fn->GetTitle();
2687 printf("fTmp Size %d\n",fTmp.Sizeof());
2689 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2690 printf("calculated size %d\n",size);
2691 ofstream out(fName.Data(),ios::out | ios::binary);
2692 out.write(cdata,size);
2697 //_____________________________________________________________________________
2698 AliQADataMaker * AliReconstruction::GetQADataMaker(Int_t iDet)
2700 // get the quality assurance data maker object and the loader for a detector
2702 if (fQADataMaker[iDet])
2703 return fQADataMaker[iDet];
2705 // load the QA data maker object
2706 TPluginManager* pluginManager = gROOT->GetPluginManager();
2707 TString detName = fgkDetectorName[iDet];
2708 TString qadmName = "Ali" + detName + "QADataMaker";
2709 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT"))
2712 AliQADataMaker * qadm = NULL;
2713 // first check if a plugin is defined for the quality assurance data maker
2714 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName);
2715 // if not, add a plugin for it
2716 if (!pluginHandler) {
2717 AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2718 TString libs = gSystem->GetLibraries();
2719 if (libs.Contains("lib" + detName + "base.so") ||
2720 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2721 pluginManager->AddHandler("AliQADataMaker", detName,
2722 qadmName, detName + "qadm", qadmName + "()");
2724 pluginManager->AddHandler("AliQADataMaker", detName,
2725 qadmName, detName, qadmName + "()");
2727 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName);
2729 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2730 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0);
2733 AliInfo(Form("Initializing quality assurance data maker for %s", fgkDetectorName[iDet]));
2734 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun(), GetQACycles(fgkDetectorName[iDet]));
2735 qadm->StartOfCycle(AliQA::kRECPOINTS);
2736 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
2737 qadm->StartOfCycle(AliQA::kESDS, "same") ;
2738 fQADataMaker[iDet] = qadm;
2744 //_____________________________________________________________________________
2745 Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
2747 // run the Quality Assurance data producer
2749 AliCodeTimerAuto("")
2750 TString detStr = detectors;
2751 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2752 if (!IsSelected(fgkDetectorName[iDet], detStr))
2754 AliQADataMaker * qadm = GetQADataMaker(iDet);
2757 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2758 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2760 qadm->Exec(AliQA::kESDS, esd) ;
2763 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2765 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2766 AliError(Form("the following detectors were not found: %s",
2777 //_____________________________________________________________________________
2778 void AliReconstruction::CheckQA()
2780 // check the QA of SIM for this run and remove the detectors
2781 // with status Fatal
2783 TString newDetList ;
2784 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2785 TString detName(AliQA::GetDetName(iDet)) ;
2786 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2787 fRunLocalReconstruction.Contains("ALL") ) {
2788 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX(iDet)) ;
2789 if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kFATAL)) {
2790 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
2791 } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kERROR)) {
2792 AliError(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was ERROR", detName.Data())) ;
2793 newDetList += detName ;
2795 } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kWARNING) ) {
2796 AliWarning(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was WARNING", detName.Data())) ;
2797 newDetList += detName ;
2799 } else if ( qa->IsSet(AliQA::DETECTORINDEX(iDet), AliQA::kSIM, AliQA::kINFO) ) {
2800 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was INFO", detName.Data())) ;
2801 newDetList += detName ;
2806 fRunLocalReconstruction = newDetList ;
2809 //_____________________________________________________________________________
2810 Int_t AliReconstruction::GetDetIndex(const char* detector)
2812 // return the detector index corresponding to detector
2814 for (index = 0; index < fgkNDetectors ; index++) {
2815 if ( strcmp(detector, fgkDetectorName[index]) == 0 )