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 <TStopwatch.h>
123 #include <TGeoManager.h>
124 #include <TLorentzVector.h>
126 #include "AliReconstruction.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"
136 #include "AliESDfriend.h"
137 #include "AliESDVertex.h"
138 #include "AliMultiplicity.h"
139 #include "AliTracker.h"
140 #include "AliVertexer.h"
141 #include "AliVertexerTracks.h"
142 #include "AliV0vertexer.h"
143 #include "AliCascadeVertexer.h"
144 #include "AliHeader.h"
145 #include "AliGenEventHeader.h"
147 #include "AliESDpid.h"
148 #include "AliESDtrack.h"
150 #include "AliRunTag.h"
151 #include "AliDetectorTag.h"
152 #include "AliEventTag.h"
154 #include "AliGeomManager.h"
155 #include "AliTrackPointArray.h"
156 #include "AliCDBManager.h"
157 #include "AliCDBEntry.h"
158 #include "AliAlignObj.h"
160 #include "AliCentralTrigger.h"
161 #include "AliCTPRawStream.h"
163 #include "AliAODEvent.h"
164 #include "AliAODHeader.h"
165 #include "AliAODTrack.h"
166 #include "AliAODVertex.h"
167 #include "AliAODCluster.h"
170 ClassImp(AliReconstruction)
173 //_____________________________________________________________________________
174 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
176 //_____________________________________________________________________________
177 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
178 const char* name, const char* title) :
181 fUniformField(kTRUE),
182 fRunVertexFinder(kTRUE),
183 fRunHLTTracking(kFALSE),
184 fRunMuonTracking(kFALSE),
185 fStopOnError(kFALSE),
186 fWriteAlignmentData(kFALSE),
187 fWriteESDfriend(kFALSE),
189 fFillTriggerESD(kTRUE),
191 fRunLocalReconstruction("ALL"),
194 fGAliceFileName(gAliceFilename),
199 fNumberOfEventsPerFile(1),
202 fLoadAlignFromCDB(kTRUE),
203 fLoadAlignData("ALL"),
210 fDiamondProfile(NULL),
212 fAlignObjArray(NULL),
216 // create reconstruction object with default parameters
218 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
219 fReconstructor[iDet] = NULL;
220 fLoader[iDet] = NULL;
221 fTracker[iDet] = NULL;
226 //_____________________________________________________________________________
227 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
230 fUniformField(rec.fUniformField),
231 fRunVertexFinder(rec.fRunVertexFinder),
232 fRunHLTTracking(rec.fRunHLTTracking),
233 fRunMuonTracking(rec.fRunMuonTracking),
234 fStopOnError(rec.fStopOnError),
235 fWriteAlignmentData(rec.fWriteAlignmentData),
236 fWriteESDfriend(rec.fWriteESDfriend),
237 fWriteAOD(rec.fWriteAOD),
238 fFillTriggerESD(rec.fFillTriggerESD),
240 fRunLocalReconstruction(rec.fRunLocalReconstruction),
241 fRunTracking(rec.fRunTracking),
242 fFillESD(rec.fFillESD),
243 fGAliceFileName(rec.fGAliceFileName),
245 fEquipIdMap(rec.fEquipIdMap),
246 fFirstEvent(rec.fFirstEvent),
247 fLastEvent(rec.fLastEvent),
248 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
251 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
252 fLoadAlignData(rec.fLoadAlignData),
253 fESDPar(rec.fESDPar),
259 fDiamondProfile(NULL),
261 fAlignObjArray(rec.fAlignObjArray),
262 fCDBUri(rec.fCDBUri),
267 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
268 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
270 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
271 fReconstructor[iDet] = NULL;
272 fLoader[iDet] = NULL;
273 fTracker[iDet] = NULL;
275 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
276 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
280 //_____________________________________________________________________________
281 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
283 // assignment operator
285 this->~AliReconstruction();
286 new(this) AliReconstruction(rec);
290 //_____________________________________________________________________________
291 AliReconstruction::~AliReconstruction()
297 fSpecCDBUri.Delete();
300 //_____________________________________________________________________________
301 void AliReconstruction::InitCDBStorage()
303 // activate a default CDB storage
304 // First check if we have any CDB storage set, because it is used
305 // to retrieve the calibration and alignment constants
307 AliCDBManager* man = AliCDBManager::Instance();
308 if (man->IsDefaultStorageSet())
310 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
311 AliWarning("Default CDB storage has been already set !");
312 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
313 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
317 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
318 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
319 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
320 man->SetDefaultStorage(fCDBUri);
323 // Now activate the detector specific CDB storage locations
324 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
325 TObject* obj = fSpecCDBUri[i];
327 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
328 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
329 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
330 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
335 //_____________________________________________________________________________
336 void AliReconstruction::SetDefaultStorage(const char* uri) {
337 // Store the desired default CDB storage location
338 // Activate it later within the Run() method
344 //_____________________________________________________________________________
345 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
346 // Store a detector-specific CDB storage location
347 // Activate it later within the Run() method
349 AliCDBPath aPath(calibType);
350 if(!aPath.IsValid()){
351 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
352 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
353 if(!strcmp(calibType, fgkDetectorName[iDet])) {
354 aPath.SetPath(Form("%s/*", calibType));
355 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
359 if(!aPath.IsValid()){
360 AliError(Form("Not a valid path or detector: %s", calibType));
365 // check that calibType refers to a "valid" detector name
366 Bool_t isDetector = kFALSE;
367 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
368 TString detName = fgkDetectorName[iDet];
369 if(aPath.GetLevel0() == detName) {
376 AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
380 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
381 if (obj) fSpecCDBUri.Remove(obj);
382 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
389 //_____________________________________________________________________________
390 Bool_t AliReconstruction::SetRunNumber()
392 // The method is called in Run() in order
393 // to set a correct run number.
394 // In case of raw data reconstruction the
395 // run number is taken from the raw data header
397 if(AliCDBManager::Instance()->GetRun() < 0) {
399 AliError("No run loader is found !");
402 // read run number from gAlice
403 if(fRunLoader->GetAliRun())
404 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
407 if(fRawReader->NextEvent()) {
408 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
409 fRawReader->RewindEvents();
412 AliError("No raw-data events found !");
417 AliError("Neither gAlice nor RawReader objects are found !");
421 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
426 //_____________________________________________________________________________
427 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
429 // Read the alignment objects from CDB.
430 // Each detector is supposed to have the
431 // alignment objects in DET/Align/Data CDB path.
432 // All the detector objects are then collected,
433 // sorted by geometry level (starting from ALIC) and
434 // then applied to the TGeo geometry.
435 // Finally an overlaps check is performed.
437 // Load alignment data from CDB and fill fAlignObjArray
438 if(fLoadAlignFromCDB){
440 TString detStr = detectors;
441 TString loadAlObjsListOfDets = "";
443 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
444 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
445 loadAlObjsListOfDets += fgkDetectorName[iDet];
446 loadAlObjsListOfDets += " ";
447 } // end loop over detectors
448 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
450 // Check if the array with alignment objects was
451 // provided by the user. If yes, apply the objects
452 // to the present TGeo geometry
453 if (fAlignObjArray) {
454 if (gGeoManager && gGeoManager->IsClosed()) {
455 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
456 AliError("The misalignment of one or more volumes failed!"
457 "Compare the list of simulated detectors and the list of detector alignment data!");
462 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
468 delete fAlignObjArray; fAlignObjArray=0;
473 //_____________________________________________________________________________
474 void AliReconstruction::SetGAliceFile(const char* fileName)
476 // set the name of the galice file
478 fGAliceFileName = fileName;
481 //_____________________________________________________________________________
482 void AliReconstruction::SetOption(const char* detector, const char* option)
484 // set options for the reconstruction of a detector
486 TObject* obj = fOptions.FindObject(detector);
487 if (obj) fOptions.Remove(obj);
488 fOptions.Add(new TNamed(detector, option));
492 //_____________________________________________________________________________
493 Bool_t AliReconstruction::Run(const char* input)
495 // run the reconstruction
498 if (!input) input = fInput.Data();
499 TString fileName(input);
500 if (fileName.EndsWith("/")) {
501 fRawReader = new AliRawReaderFile(fileName);
502 } else if (fileName.EndsWith(".root")) {
503 fRawReader = new AliRawReaderRoot(fileName);
504 } else if (!fileName.IsNull()) {
505 fRawReader = new AliRawReaderDate(fileName);
506 fRawReader->SelectEvents(7);
508 if (!fEquipIdMap.IsNull() && fRawReader)
509 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
512 // get the run loader
513 if (!InitRunLoader()) return kFALSE;
515 // Initialize the CDB storage
518 // Set run number in CDBManager (if it is not already set by the user)
519 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
521 // Import ideal TGeo geometry and apply misalignment
523 TString geom(gSystem->DirName(fGAliceFileName));
524 geom += "/geometry.root";
525 AliGeomManager::LoadGeometry(geom.Data());
526 if (!gGeoManager) if (fStopOnError) return kFALSE;
529 AliCDBManager* man = AliCDBManager::Instance();
530 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
532 // local reconstruction
533 if (!fRunLocalReconstruction.IsNull()) {
534 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
535 if (fStopOnError) {CleanUp(); return kFALSE;}
538 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
539 // fFillESD.IsNull()) return kTRUE;
542 if (fRunVertexFinder && !CreateVertexer()) {
550 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
558 TStopwatch stopwatch;
561 // get the possibly already existing ESD file and tree
562 AliESD* esd = new AliESD(); AliESD* hltesd = new AliESD();
563 TFile* fileOld = NULL;
564 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
565 if (!gSystem->AccessPathName("AliESDs.root")){
566 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
567 fileOld = TFile::Open("AliESDs.old.root");
568 if (fileOld && fileOld->IsOpen()) {
569 treeOld = (TTree*) fileOld->Get("esdTree");
570 if (treeOld)esd->ReadFromTree(treeOld);
571 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
572 if (hlttreeOld) hltesd->ReadFromTree(hlttreeOld);
576 // create the ESD output file and tree
577 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
578 file->SetCompressionLevel(2);
579 if (!file->IsOpen()) {
580 AliError("opening AliESDs.root failed");
581 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
584 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
586 esd->CreateStdContent();
587 esd->WriteToTree(tree);
589 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
590 hltesd = new AliESD();
591 hltesd->CreateStdContent();
592 hltesd->WriteToTree(hlttree);
595 delete esd; delete hltesd;
596 esd = NULL; hltesd = NULL;
598 // create the branch with ESD additions
599 AliESDfriend *esdf = 0;
600 if (fWriteESDfriend) {
601 esdf = new AliESDfriend();
602 TBranch *br=tree->Branch("ESDfriend.","AliESDfriend", &esdf);
603 br->SetFile("AliESDfriends.root");
604 esd->AddObject(esdf);
607 // Get the diamond profile from OCDB
608 AliCDBEntry* entry = AliCDBManager::Instance()
609 ->Get("GRP/Calib/MeanVertex");
612 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
614 AliError("No diamond profile found in OCDB!");
617 AliVertexerTracks tVertexer(AliTracker::GetBz());
618 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
621 if (fRawReader) fRawReader->RewindEvents();
623 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
624 if (fRawReader) fRawReader->NextEvent();
625 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
626 // copy old ESD to the new one
628 esd->ReadFromTree(treeOld);
629 treeOld->GetEntry(iEvent);
633 esd->ReadFromTree(hlttreeOld);
634 hlttreeOld->GetEntry(iEvent);
640 AliInfo(Form("processing event %d", iEvent));
641 fRunLoader->GetEvent(iEvent);
644 sprintf(aFileName, "ESD_%d.%d_final.root",
645 fRunLoader->GetHeader()->GetRun(),
646 fRunLoader->GetHeader()->GetEventNrInRun());
647 if (!gSystem->AccessPathName(aFileName)) continue;
649 // local reconstruction
650 if (!fRunLocalReconstruction.IsNull()) {
651 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
652 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
657 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
658 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
659 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
660 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
662 // Set magnetic field from the tracker
663 esd->SetMagneticField(AliTracker::GetBz());
664 hltesd->SetMagneticField(AliTracker::GetBz());
668 // Fill raw-data error log into the ESD
669 if (fRawReader) FillRawDataErrorLog(iEvent,esd);
672 if (fRunVertexFinder) {
673 if (!ReadESD(esd, "vertex")) {
674 if (!RunVertexFinder(esd)) {
675 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
677 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
682 if (!fRunTracking.IsNull()) {
683 if (fRunHLTTracking) {
684 hltesd->SetVertex(esd->GetVertex());
685 if (!RunHLTTracking(hltesd)) {
686 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
692 if (!fRunTracking.IsNull()) {
693 if (fRunMuonTracking) {
694 if (!RunMuonTracking(esd)) {
695 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
701 if (!fRunTracking.IsNull()) {
702 if (!ReadESD(esd, "tracking")) {
703 if (!RunTracking(esd)) {
704 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
706 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
711 if (!fFillESD.IsNull()) {
712 if (!FillESD(esd, fFillESD)) {
713 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
716 // fill Event header information from the RawEventHeader
717 if (fRawReader){FillRawEventHeaderESD(esd);}
720 AliESDpid::MakePID(esd);
721 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
723 if (fFillTriggerESD) {
724 if (!ReadESD(esd, "trigger")) {
725 if (!FillTriggerESD(esd)) {
726 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
728 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
732 //Try to improve the reconstructed primary vertex position using the tracks
733 AliESDVertex *pvtx=0;
734 Bool_t dovertex=kTRUE;
735 TObject* obj = fOptions.FindObject("ITS");
737 TString optITS = obj->GetTitle();
738 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
741 if(dovertex) pvtx=tVertexer.FindPrimaryVertex(esd);
742 if(fDiamondProfile) esd->SetDiamond(fDiamondProfile);
745 if (pvtx->GetStatus()) {
746 // Store the improved primary vertex
747 esd->SetPrimaryVertex(pvtx);
748 // Propagate the tracks to the DCA to the improved primary vertex
749 Double_t somethingbig = 777.;
750 Double_t bz = esd->GetMagneticField();
751 Int_t nt=esd->GetNumberOfTracks();
753 AliESDtrack *t = esd->GetTrack(nt);
754 t->RelateToVertex(pvtx, bz, somethingbig);
761 vtxer.Tracks2V0vertices(esd);
764 AliCascadeVertexer cvtxer;
765 cvtxer.V0sTracks2CascadeVertices(esd);
769 if (fWriteESDfriend) {
770 new (esdf) AliESDfriend(); // Reset...
771 esd->GetESDfriend(esdf);
778 if (fCheckPointLevel > 0) WriteESD(esd, "final");
782 // delete esdf; esdf = 0;
786 tree->GetUserInfo()->Add(esd);
787 hlttree->GetUserInfo()->Add(hltesd);
791 if(fESDPar.Contains("ESD.par")){
792 AliInfo("Attaching ESD.par to Tree");
793 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
794 tree->GetUserInfo()->Add(fn);
798 AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
799 stopwatch.RealTime(),stopwatch.CpuTime()));
803 tree->SetBranchStatus("ESDfriend*",0);
808 TFile *aodFile = TFile::Open("AliAOD.root", "RECREATE");
809 ESDFile2AODFile(file, aodFile);
814 // Create tags for the events in the ESD tree (the ESD tree is always present)
815 // In case of empty events the tags will contain dummy values
818 CleanUp(file, fileOld);
824 //_____________________________________________________________________________
825 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
827 // run the local reconstruction
829 TStopwatch stopwatch;
832 AliCDBManager* man = AliCDBManager::Instance();
833 Bool_t origCache = man->GetCacheFlag();
835 TString detStr = detectors;
836 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
837 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
838 AliReconstructor* reconstructor = GetReconstructor(iDet);
839 if (!reconstructor) continue;
840 if (reconstructor->HasLocalReconstruction()) continue;
842 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
843 TStopwatch stopwatchDet;
844 stopwatchDet.Start();
846 AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
848 man->SetCacheFlag(kTRUE);
849 TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
850 man->GetAll(calibPath); // entries are cached!
853 fRawReader->RewindEvents();
854 reconstructor->Reconstruct(fRunLoader, fRawReader);
856 reconstructor->Reconstruct(fRunLoader);
858 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
859 fgkDetectorName[iDet],
860 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
862 // unload calibration data
863 man->UnloadFromCache(calibPath);
867 man->SetCacheFlag(origCache);
869 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
870 AliError(Form("the following detectors were not found: %s",
872 if (fStopOnError) return kFALSE;
875 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
876 stopwatch.RealTime(),stopwatch.CpuTime()));
881 //_____________________________________________________________________________
882 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
884 // run the local reconstruction
886 TStopwatch stopwatch;
889 TString detStr = detectors;
890 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
891 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
892 AliReconstructor* reconstructor = GetReconstructor(iDet);
893 if (!reconstructor) continue;
894 AliLoader* loader = fLoader[iDet];
896 // conversion of digits
897 if (fRawReader && reconstructor->HasDigitConversion()) {
898 AliInfo(Form("converting raw data digits into root objects for %s",
899 fgkDetectorName[iDet]));
900 TStopwatch stopwatchDet;
901 stopwatchDet.Start();
902 loader->LoadDigits("update");
903 loader->CleanDigits();
904 loader->MakeDigitsContainer();
905 TTree* digitsTree = loader->TreeD();
906 reconstructor->ConvertDigits(fRawReader, digitsTree);
907 loader->WriteDigits("OVERWRITE");
908 loader->UnloadDigits();
909 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
910 fgkDetectorName[iDet],
911 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
914 // local reconstruction
915 if (!reconstructor->HasLocalReconstruction()) continue;
916 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
917 TStopwatch stopwatchDet;
918 stopwatchDet.Start();
919 loader->LoadRecPoints("update");
920 loader->CleanRecPoints();
921 loader->MakeRecPointsContainer();
922 TTree* clustersTree = loader->TreeR();
923 if (fRawReader && !reconstructor->HasDigitConversion()) {
924 reconstructor->Reconstruct(fRawReader, clustersTree);
926 loader->LoadDigits("read");
927 TTree* digitsTree = loader->TreeD();
929 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
930 if (fStopOnError) return kFALSE;
932 reconstructor->Reconstruct(digitsTree, clustersTree);
934 loader->UnloadDigits();
936 loader->WriteRecPoints("OVERWRITE");
937 loader->UnloadRecPoints();
938 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
939 fgkDetectorName[iDet],
940 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
943 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
944 AliError(Form("the following detectors were not found: %s",
946 if (fStopOnError) return kFALSE;
949 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
950 stopwatch.RealTime(),stopwatch.CpuTime()));
955 //_____________________________________________________________________________
956 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
958 // run the barrel tracking
960 TStopwatch stopwatch;
963 AliESDVertex* vertex = NULL;
964 Double_t vtxPos[3] = {0, 0, 0};
965 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
967 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
968 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
969 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
973 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
974 AliInfo("running the ITS vertex finder");
975 if (fLoader[0]) fLoader[0]->LoadRecPoints();
976 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
977 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
979 AliWarning("Vertex not found");
980 vertex = new AliESDVertex();
981 vertex->SetName("default");
984 vertex->SetName("reconstructed");
988 AliInfo("getting the primary vertex from MC");
989 vertex = new AliESDVertex(vtxPos, vtxErr);
993 vertex->GetXYZ(vtxPos);
994 vertex->GetSigmaXYZ(vtxErr);
996 AliWarning("no vertex reconstructed");
997 vertex = new AliESDVertex(vtxPos, vtxErr);
999 esd->SetVertex(vertex);
1000 // if SPD multiplicity has been determined, it is stored in the ESD
1001 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1002 if(mult)esd->SetMultiplicity(mult);
1004 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1005 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1009 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1010 stopwatch.RealTime(),stopwatch.CpuTime()));
1015 //_____________________________________________________________________________
1016 Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
1018 // run the HLT barrel tracking
1020 TStopwatch stopwatch;
1024 AliError("Missing runLoader!");
1028 AliInfo("running HLT tracking");
1030 // Get a pointer to the HLT reconstructor
1031 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1032 if (!reconstructor) return kFALSE;
1035 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1036 TString detName = fgkDetectorName[iDet];
1037 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1038 reconstructor->SetOption(detName.Data());
1039 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1041 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1042 if (fStopOnError) return kFALSE;
1046 Double_t vtxErr[3]={0.005,0.005,0.010};
1047 const AliESDVertex *vertex = esd->GetVertex();
1048 vertex->GetXYZ(vtxPos);
1049 tracker->SetVertex(vtxPos,vtxErr);
1051 fLoader[iDet]->LoadRecPoints("read");
1052 TTree* tree = fLoader[iDet]->TreeR();
1054 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1057 tracker->LoadClusters(tree);
1059 if (tracker->Clusters2Tracks(esd) != 0) {
1060 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1064 tracker->UnloadClusters();
1069 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1070 stopwatch.RealTime(),stopwatch.CpuTime()));
1075 //_____________________________________________________________________________
1076 Bool_t AliReconstruction::RunMuonTracking(AliESD*& esd)
1078 // run the muon spectrometer tracking
1080 TStopwatch stopwatch;
1084 AliError("Missing runLoader!");
1087 Int_t iDet = 7; // for MUON
1089 AliInfo("is running...");
1091 // Get a pointer to the MUON reconstructor
1092 AliReconstructor *reconstructor = GetReconstructor(iDet);
1093 if (!reconstructor) return kFALSE;
1096 TString detName = fgkDetectorName[iDet];
1097 AliDebug(1, Form("%s tracking", detName.Data()));
1098 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1100 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1105 fLoader[iDet]->LoadTracks("update");
1106 fLoader[iDet]->CleanTracks();
1107 fLoader[iDet]->MakeTracksContainer();
1110 fLoader[iDet]->LoadRecPoints("read");
1111 tracker->LoadClusters(fLoader[iDet]->TreeR());
1113 Int_t rv = tracker->Clusters2Tracks(esd);
1115 fLoader[iDet]->UnloadRecPoints();
1119 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1123 tracker->UnloadClusters();
1125 fLoader[iDet]->UnloadRecPoints();
1127 fLoader[iDet]->WriteTracks("OVERWRITE");
1128 fLoader[iDet]->UnloadTracks();
1132 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1133 stopwatch.RealTime(),stopwatch.CpuTime()));
1139 //_____________________________________________________________________________
1140 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
1142 // run the barrel tracking
1144 TStopwatch stopwatch;
1147 AliInfo("running tracking");
1149 //Fill the ESD with the T0 info (will be used by the TOF)
1150 if (fReconstructor[11])
1151 GetReconstructor(11)->FillESD(fRunLoader, esd);
1153 // pass 1: TPC + ITS inwards
1154 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1155 if (!fTracker[iDet]) continue;
1156 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1159 fLoader[iDet]->LoadRecPoints("read");
1160 TTree* tree = fLoader[iDet]->TreeR();
1162 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1165 fTracker[iDet]->LoadClusters(tree);
1168 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1169 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1172 if (fCheckPointLevel > 1) {
1173 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1175 // preliminary PID in TPC needed by the ITS tracker
1177 GetReconstructor(1)->FillESD(fRunLoader, esd);
1178 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1179 AliESDpid::MakePID(esd);
1183 // pass 2: ALL backwards
1184 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1185 if (!fTracker[iDet]) continue;
1186 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1189 if (iDet > 1) { // all except ITS, TPC
1191 fLoader[iDet]->LoadRecPoints("read");
1192 tree = fLoader[iDet]->TreeR();
1194 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1197 fTracker[iDet]->LoadClusters(tree);
1201 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1202 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1205 if (fCheckPointLevel > 1) {
1206 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1210 if (iDet > 2) { // all except ITS, TPC, TRD
1211 fTracker[iDet]->UnloadClusters();
1212 fLoader[iDet]->UnloadRecPoints();
1214 // updated PID in TPC needed by the ITS tracker -MI
1216 GetReconstructor(1)->FillESD(fRunLoader, esd);
1217 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1218 AliESDpid::MakePID(esd);
1222 // write space-points to the ESD in case alignment data output
1224 if (fWriteAlignmentData)
1225 WriteAlignmentData(esd);
1227 // pass 3: TRD + TPC + ITS refit inwards
1228 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1229 if (!fTracker[iDet]) continue;
1230 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1233 if (fTracker[iDet]->RefitInward(esd) != 0) {
1234 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1237 if (fCheckPointLevel > 1) {
1238 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1242 fTracker[iDet]->UnloadClusters();
1243 fLoader[iDet]->UnloadRecPoints();
1246 // Propagate track to the vertex - if not done by ITS
1248 Int_t ntracks = esd->GetNumberOfTracks();
1249 for (Int_t itrack=0; itrack<ntracks; itrack++){
1250 const Double_t kRadius = 3; // beam pipe radius
1251 const Double_t kMaxStep = 5; // max step
1252 const Double_t kMaxD = 123456; // max distance to prim vertex
1253 Double_t fieldZ = AliTracker::GetBz(); //
1254 AliESDtrack * track = esd->GetTrack(itrack);
1255 if (!track) continue;
1256 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1257 track->PropagateTo(kRadius, fieldZ, track->GetMass(),kMaxStep,kTRUE);
1258 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1261 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1262 stopwatch.RealTime(),stopwatch.CpuTime()));
1267 //_____________________________________________________________________________
1268 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
1270 // fill the event summary data
1272 TStopwatch stopwatch;
1274 AliInfo("filling ESD");
1276 TString detStr = detectors;
1277 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1278 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1279 AliReconstructor* reconstructor = GetReconstructor(iDet);
1280 if (!reconstructor) continue;
1282 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1283 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1284 TTree* clustersTree = NULL;
1285 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1286 fLoader[iDet]->LoadRecPoints("read");
1287 clustersTree = fLoader[iDet]->TreeR();
1288 if (!clustersTree) {
1289 AliError(Form("Can't get the %s clusters tree",
1290 fgkDetectorName[iDet]));
1291 if (fStopOnError) return kFALSE;
1294 if (fRawReader && !reconstructor->HasDigitConversion()) {
1295 reconstructor->FillESD(fRawReader, clustersTree, esd);
1297 TTree* digitsTree = NULL;
1298 if (fLoader[iDet]) {
1299 fLoader[iDet]->LoadDigits("read");
1300 digitsTree = fLoader[iDet]->TreeD();
1302 AliError(Form("Can't get the %s digits tree",
1303 fgkDetectorName[iDet]));
1304 if (fStopOnError) return kFALSE;
1307 reconstructor->FillESD(digitsTree, clustersTree, esd);
1308 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1310 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1311 fLoader[iDet]->UnloadRecPoints();
1315 reconstructor->FillESD(fRunLoader, fRawReader, esd);
1317 reconstructor->FillESD(fRunLoader, esd);
1319 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1323 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1324 AliError(Form("the following detectors were not found: %s",
1326 if (fStopOnError) return kFALSE;
1329 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1330 stopwatch.RealTime(),stopwatch.CpuTime()));
1335 //_____________________________________________________________________________
1336 Bool_t AliReconstruction::FillTriggerESD(AliESD*& esd)
1338 // Reads the trigger decision which is
1339 // stored in Trigger.root file and fills
1340 // the corresponding esd entries
1342 AliInfo("Filling trigger information into the ESD");
1345 AliCTPRawStream input(fRawReader);
1346 if (!input.Next()) {
1347 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1350 esd->SetTriggerMask(input.GetClassMask());
1351 esd->SetTriggerCluster(input.GetClusterMask());
1354 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1356 if (!runloader->LoadTrigger()) {
1357 AliCentralTrigger *aCTP = runloader->GetTrigger();
1358 esd->SetTriggerMask(aCTP->GetClassMask());
1359 esd->SetTriggerCluster(aCTP->GetClusterMask());
1362 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1367 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1379 //_____________________________________________________________________________
1380 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESD*& esd)
1383 // Filling information from RawReader Header
1386 AliInfo("Filling information from RawReader Header");
1387 esd->SetBunchCrossNumber(0);
1388 esd->SetOrbitNumber(0);
1389 esd->SetPeriodNumber(0);
1390 esd->SetTimeStamp(0);
1391 esd->SetEventType(0);
1392 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1395 const UInt_t *id = eventHeader->GetP("Id");
1396 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1397 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1398 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1400 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1401 esd->SetEventType((eventHeader->Get("Type")));
1408 //_____________________________________________________________________________
1409 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1411 // check whether detName is contained in detectors
1412 // if yes, it is removed from detectors
1414 // check if all detectors are selected
1415 if ((detectors.CompareTo("ALL") == 0) ||
1416 detectors.BeginsWith("ALL ") ||
1417 detectors.EndsWith(" ALL") ||
1418 detectors.Contains(" ALL ")) {
1423 // search for the given detector
1424 Bool_t result = kFALSE;
1425 if ((detectors.CompareTo(detName) == 0) ||
1426 detectors.BeginsWith(detName+" ") ||
1427 detectors.EndsWith(" "+detName) ||
1428 detectors.Contains(" "+detName+" ")) {
1429 detectors.ReplaceAll(detName, "");
1433 // clean up the detectors string
1434 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1435 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1436 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1441 //_____________________________________________________________________________
1442 Bool_t AliReconstruction::InitRunLoader()
1444 // get or create the run loader
1446 if (gAlice) delete gAlice;
1449 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1450 // load all base libraries to get the loader classes
1451 TString libs = gSystem->GetLibraries();
1452 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1453 TString detName = fgkDetectorName[iDet];
1454 if (detName == "HLT") continue;
1455 if (libs.Contains("lib" + detName + "base.so")) continue;
1456 gSystem->Load("lib" + detName + "base.so");
1458 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1460 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1464 fRunLoader->CdGAFile();
1465 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1466 if (fRunLoader->LoadgAlice() == 0) {
1467 gAlice = fRunLoader->GetAliRun();
1468 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1471 if (!gAlice && !fRawReader) {
1472 AliError(Form("no gAlice object found in file %s",
1473 fGAliceFileName.Data()));
1478 } else { // galice.root does not exist
1480 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1484 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1485 AliConfig::GetDefaultEventFolderName(),
1488 AliError(Form("could not create run loader in file %s",
1489 fGAliceFileName.Data()));
1493 fRunLoader->MakeTree("E");
1495 while (fRawReader->NextEvent()) {
1496 fRunLoader->SetEventNumber(iEvent);
1497 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1499 fRunLoader->MakeTree("H");
1500 fRunLoader->TreeE()->Fill();
1503 fRawReader->RewindEvents();
1504 if (fNumberOfEventsPerFile > 0)
1505 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1507 fRunLoader->SetNumberOfEventsPerFile(iEvent);
1508 fRunLoader->WriteHeader("OVERWRITE");
1509 fRunLoader->CdGAFile();
1510 fRunLoader->Write(0, TObject::kOverwrite);
1511 // AliTracker::SetFieldMap(???);
1517 //_____________________________________________________________________________
1518 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1520 // get the reconstructor object and the loader for a detector
1522 if (fReconstructor[iDet]) return fReconstructor[iDet];
1524 // load the reconstructor object
1525 TPluginManager* pluginManager = gROOT->GetPluginManager();
1526 TString detName = fgkDetectorName[iDet];
1527 TString recName = "Ali" + detName + "Reconstructor";
1528 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1530 if (detName == "HLT") {
1531 if (!gROOT->GetClass("AliLevel3")) {
1532 gSystem->Load("libAliHLTSrc.so");
1533 gSystem->Load("libAliHLTMisc.so");
1534 gSystem->Load("libAliHLTHough.so");
1535 gSystem->Load("libAliHLTComp.so");
1539 AliReconstructor* reconstructor = NULL;
1540 // first check if a plugin is defined for the reconstructor
1541 TPluginHandler* pluginHandler =
1542 pluginManager->FindHandler("AliReconstructor", detName);
1543 // if not, add a plugin for it
1544 if (!pluginHandler) {
1545 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1546 TString libs = gSystem->GetLibraries();
1547 if (libs.Contains("lib" + detName + "base.so") ||
1548 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1549 pluginManager->AddHandler("AliReconstructor", detName,
1550 recName, detName + "rec", recName + "()");
1552 pluginManager->AddHandler("AliReconstructor", detName,
1553 recName, detName, recName + "()");
1555 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1557 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1558 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1560 if (reconstructor) {
1561 TObject* obj = fOptions.FindObject(detName.Data());
1562 if (obj) reconstructor->SetOption(obj->GetTitle());
1563 reconstructor->Init(fRunLoader);
1564 fReconstructor[iDet] = reconstructor;
1567 // get or create the loader
1568 if (detName != "HLT") {
1569 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1570 if (!fLoader[iDet]) {
1571 AliConfig::Instance()
1572 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1574 // first check if a plugin is defined for the loader
1576 pluginManager->FindHandler("AliLoader", detName);
1577 // if not, add a plugin for it
1578 if (!pluginHandler) {
1579 TString loaderName = "Ali" + detName + "Loader";
1580 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1581 pluginManager->AddHandler("AliLoader", detName,
1582 loaderName, detName + "base",
1583 loaderName + "(const char*, TFolder*)");
1584 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1586 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1588 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1589 fRunLoader->GetEventFolder());
1591 if (!fLoader[iDet]) { // use default loader
1592 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1594 if (!fLoader[iDet]) {
1595 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1596 if (fStopOnError) return NULL;
1598 fRunLoader->AddLoader(fLoader[iDet]);
1599 fRunLoader->CdGAFile();
1600 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1601 fRunLoader->Write(0, TObject::kOverwrite);
1606 return reconstructor;
1609 //_____________________________________________________________________________
1610 Bool_t AliReconstruction::CreateVertexer()
1612 // create the vertexer
1615 AliReconstructor* itsReconstructor = GetReconstructor(0);
1616 if (itsReconstructor) {
1617 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1620 AliWarning("couldn't create a vertexer for ITS");
1621 if (fStopOnError) return kFALSE;
1627 //_____________________________________________________________________________
1628 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1630 // create the trackers
1632 TString detStr = detectors;
1633 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1634 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1635 AliReconstructor* reconstructor = GetReconstructor(iDet);
1636 if (!reconstructor) continue;
1637 TString detName = fgkDetectorName[iDet];
1638 if (detName == "HLT") {
1639 fRunHLTTracking = kTRUE;
1642 if (detName == "MUON") {
1643 fRunMuonTracking = kTRUE;
1648 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1649 if (!fTracker[iDet] && (iDet < 7)) {
1650 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1651 if (fStopOnError) return kFALSE;
1658 //_____________________________________________________________________________
1659 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1661 // delete trackers and the run loader and close and delete the file
1663 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1664 delete fReconstructor[iDet];
1665 fReconstructor[iDet] = NULL;
1666 fLoader[iDet] = NULL;
1667 delete fTracker[iDet];
1668 fTracker[iDet] = NULL;
1672 delete fDiamondProfile;
1673 fDiamondProfile = NULL;
1688 gSystem->Unlink("AliESDs.old.root");
1693 //_____________________________________________________________________________
1694 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
1696 // read the ESD event from a file
1698 if (!esd) return kFALSE;
1700 sprintf(fileName, "ESD_%d.%d_%s.root",
1701 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1702 if (gSystem->AccessPathName(fileName)) return kFALSE;
1704 AliInfo(Form("reading ESD from file %s", fileName));
1705 AliDebug(1, Form("reading ESD from file %s", fileName));
1706 TFile* file = TFile::Open(fileName);
1707 if (!file || !file->IsOpen()) {
1708 AliError(Form("opening %s failed", fileName));
1715 esd = (AliESD*) file->Get("ESD");
1721 //_____________________________________________________________________________
1722 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
1724 // write the ESD event to a file
1728 sprintf(fileName, "ESD_%d.%d_%s.root",
1729 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1731 AliDebug(1, Form("writing ESD to file %s", fileName));
1732 TFile* file = TFile::Open(fileName, "recreate");
1733 if (!file || !file->IsOpen()) {
1734 AliError(Form("opening %s failed", fileName));
1745 //_____________________________________________________________________________
1746 void AliReconstruction::CreateTag(TFile* file)
1749 Float_t lhcLuminosity = 0.0;
1750 TString lhcState = "test";
1751 UInt_t detectorMask = 0;
1756 Double_t fMUONMASS = 0.105658369;
1759 Double_t fThetaX, fThetaY, fPyz, fChisquare;
1760 Double_t fPxRec,fPyRec, fPzRec, fEnergy;
1762 TLorentzVector fEPvector;
1764 Float_t fZVertexCut = 10.0;
1765 Float_t fRhoVertexCut = 2.0;
1767 Float_t fLowPtCut = 1.0;
1768 Float_t fHighPtCut = 3.0;
1769 Float_t fVeryHighPtCut = 10.0;
1772 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
1774 // Creates the tags for all the events in a given ESD file
1776 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
1777 Int_t nPos, nNeg, nNeutr;
1778 Int_t nK0s, nNeutrons, nPi0s, nGamas;
1779 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
1780 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
1781 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
1782 Float_t maxPt = .0, meanPt = .0, totalP = .0;
1784 Int_t iRunNumber = 0;
1785 TString fVertexName("default");
1787 AliRunTag *tag = new AliRunTag();
1788 AliEventTag *evTag = new AliEventTag();
1789 TTree ttag("T","A Tree with event tags");
1790 TBranch * btag = ttag.Branch("AliTAG", &tag);
1791 btag->SetCompressionLevel(9);
1793 AliInfo(Form("Creating the tags......."));
1795 if (!file || !file->IsOpen()) {
1796 AliError(Form("opening failed"));
1800 Int_t lastEvent = 0;
1801 TTree *b = (TTree*) file->Get("esdTree");
1802 AliESD *esd = new AliESD();
1803 esd->ReadFromTree(b);
1805 b->GetEntry(fFirstEvent);
1806 Int_t iInitRunNumber = esd->GetRunNumber();
1808 Int_t iNumberOfEvents = (Int_t)b->GetEntries();
1809 if(fLastEvent != -1) iNumberOfEvents = fLastEvent + 1;
1810 for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
1838 b->GetEntry(iEventNumber);
1839 iRunNumber = esd->GetRunNumber();
1840 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
1841 const AliESDVertex * vertexIn = esd->GetVertex();
1842 if (!vertexIn) AliError("ESD has not defined vertex.");
1843 if (vertexIn) fVertexName = vertexIn->GetName();
1844 if(fVertexName != "default") fVertexflag = 1;
1845 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
1846 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
1847 UInt_t status = esdTrack->GetStatus();
1849 //select only tracks with ITS refit
1850 if ((status&AliESDtrack::kITSrefit)==0) continue;
1851 //select only tracks with TPC refit
1852 if ((status&AliESDtrack::kTPCrefit)==0) continue;
1854 //select only tracks with the "combined PID"
1855 if ((status&AliESDtrack::kESDpid)==0) continue;
1857 esdTrack->GetPxPyPz(p);
1858 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
1859 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
1862 if(fPt > maxPt) maxPt = fPt;
1864 if(esdTrack->GetSign() > 0) {
1866 if(fPt > fLowPtCut) nCh1GeV++;
1867 if(fPt > fHighPtCut) nCh3GeV++;
1868 if(fPt > fVeryHighPtCut) nCh10GeV++;
1870 if(esdTrack->GetSign() < 0) {
1872 if(fPt > fLowPtCut) nCh1GeV++;
1873 if(fPt > fHighPtCut) nCh3GeV++;
1874 if(fPt > fVeryHighPtCut) nCh10GeV++;
1876 if(esdTrack->GetSign() == 0) nNeutr++;
1880 esdTrack->GetESDpid(prob);
1883 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
1884 if(rcc == 0.0) continue;
1887 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
1890 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
1892 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
1894 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
1896 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
1898 if(fPt > fLowPtCut) nEl1GeV++;
1899 if(fPt > fHighPtCut) nEl3GeV++;
1900 if(fPt > fVeryHighPtCut) nEl10GeV++;
1908 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
1909 // loop over all reconstructed tracks (also first track of combination)
1910 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
1911 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
1912 if (muonTrack == 0x0) continue;
1914 // Coordinates at vertex
1915 fZ = muonTrack->GetZ();
1916 fY = muonTrack->GetBendingCoor();
1917 fX = muonTrack->GetNonBendingCoor();
1919 fThetaX = muonTrack->GetThetaX();
1920 fThetaY = muonTrack->GetThetaY();
1922 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
1923 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
1924 fPxRec = fPzRec * TMath::Tan(fThetaX);
1925 fPyRec = fPzRec * TMath::Tan(fThetaY);
1926 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
1928 //ChiSquare of the track if needed
1929 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
1930 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
1931 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
1933 // total number of muons inside a vertex cut
1934 if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
1936 if(fEPvector.Pt() > fLowPtCut) {
1938 if(fEPvector.Pt() > fHighPtCut) {
1940 if (fEPvector.Pt() > fVeryHighPtCut) {
1948 // Fill the event tags
1950 meanPt = meanPt/ntrack;
1952 evTag->SetEventId(iEventNumber+1);
1954 evTag->SetVertexX(vertexIn->GetXv());
1955 evTag->SetVertexY(vertexIn->GetYv());
1956 evTag->SetVertexZ(vertexIn->GetZv());
1957 evTag->SetVertexZError(vertexIn->GetZRes());
1959 evTag->SetVertexFlag(fVertexflag);
1961 evTag->SetT0VertexZ(esd->GetT0zVertex());
1963 evTag->SetTriggerMask(esd->GetTriggerMask());
1964 evTag->SetTriggerCluster(esd->GetTriggerCluster());
1966 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
1967 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
1968 evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
1969 evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
1970 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
1971 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
1974 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
1975 evTag->SetNumOfPosTracks(nPos);
1976 evTag->SetNumOfNegTracks(nNeg);
1977 evTag->SetNumOfNeutrTracks(nNeutr);
1979 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
1980 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
1981 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
1982 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
1984 evTag->SetNumOfProtons(nProtons);
1985 evTag->SetNumOfKaons(nKaons);
1986 evTag->SetNumOfPions(nPions);
1987 evTag->SetNumOfMuons(nMuons);
1988 evTag->SetNumOfElectrons(nElectrons);
1989 evTag->SetNumOfPhotons(nGamas);
1990 evTag->SetNumOfPi0s(nPi0s);
1991 evTag->SetNumOfNeutrons(nNeutrons);
1992 evTag->SetNumOfKaon0s(nK0s);
1994 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1995 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1996 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1997 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1998 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1999 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
2000 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
2001 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
2002 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
2004 evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
2005 evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
2007 evTag->SetTotalMomentum(totalP);
2008 evTag->SetMeanPt(meanPt);
2009 evTag->SetMaxPt(maxPt);
2011 tag->SetLHCTag(lhcLuminosity,lhcState);
2012 tag->SetDetectorTag(detectorMask);
2014 tag->SetRunId(iInitRunNumber);
2015 tag->AddEventTag(*evTag);
2017 if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries();
2018 else lastEvent = fLastEvent;
2024 sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root",
2025 tag->GetRunId(),fFirstEvent,lastEvent );
2026 AliInfo(Form("writing tags to file %s", fileName));
2027 AliDebug(1, Form("writing tags to file %s", fileName));
2029 TFile* ftag = TFile::Open(fileName, "recreate");
2038 //_____________________________________________________________________________
2039 void AliReconstruction::ESDFile2AODFile(TFile* esdFile, TFile* aodFile)
2041 // write all files from the given esd file to an aod file
2043 // create an AliAOD object
2044 AliAODEvent *aod = new AliAODEvent();
2045 aod->CreateStdContent();
2051 TTree *aodTree = new TTree("AOD", "AliAOD tree");
2052 aodTree->Branch(aod->GetList());
2055 TTree *t = (TTree*) esdFile->Get("esdTree");
2056 AliESD *esd = new AliESD();
2057 esd->ReadFromTree(t);
2059 Int_t nEvents = t->GetEntries();
2061 // set arrays and pointers
2069 // loop over events and fill them
2070 for (Int_t iEvent = 0; iEvent < nEvents; ++iEvent) {
2071 t->GetEntry(iEvent);
2073 // Multiplicity information needed by the header (to be revised!)
2074 Int_t nTracks = esd->GetNumberOfTracks();
2075 Int_t nPosTracks = 0;
2076 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack)
2077 if (esd->GetTrack(iTrack)->GetSign()> 0) nPosTracks++;
2079 // Update the header
2080 AliAODHeader* header = aod->GetHeader();
2082 header->SetRunNumber (esd->GetRunNumber() );
2083 header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
2084 header->SetOrbitNumber (esd->GetOrbitNumber() );
2085 header->SetPeriodNumber (esd->GetPeriodNumber() );
2086 header->SetTriggerMask (esd->GetTriggerMask() );
2087 header->SetTriggerCluster (esd->GetTriggerCluster() );
2088 header->SetEventType (esd->GetEventType() );
2089 header->SetMagneticField (esd->GetMagneticField() );
2090 header->SetZDCN1Energy (esd->GetZDCN1Energy() );
2091 header->SetZDCP1Energy (esd->GetZDCP1Energy() );
2092 header->SetZDCN2Energy (esd->GetZDCN2Energy() );
2093 header->SetZDCP2Energy (esd->GetZDCP2Energy() );
2094 header->SetZDCEMEnergy (esd->GetZDCEMEnergy() );
2095 header->SetRefMultiplicity (nTracks);
2096 header->SetRefMultiplicityPos(nPosTracks);
2097 header->SetRefMultiplicityNeg(nTracks - nPosTracks);
2098 header->SetMuonMagFieldScale(-999.); // FIXME
2099 header->SetCentrality(-999.); // FIXME
2103 Int_t nV0s = esd->GetNumberOfV0s();
2104 Int_t nCascades = esd->GetNumberOfCascades();
2105 Int_t nKinks = esd->GetNumberOfKinks();
2106 Int_t nVertices = nV0s + nCascades + nKinks;
2108 aod->ResetStd(nTracks, nVertices);
2109 AliAODTrack *aodTrack;
2112 // Array to take into account the tracks already added to the AOD
2113 Bool_t * usedTrack = NULL;
2115 usedTrack = new Bool_t[nTracks];
2116 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) usedTrack[iTrack]=kFALSE;
2118 // Array to take into account the V0s already added to the AOD
2119 Bool_t * usedV0 = NULL;
2121 usedV0 = new Bool_t[nV0s];
2122 for (Int_t iV0=0; iV0<nV0s; ++iV0) usedV0[iV0]=kFALSE;
2124 // Array to take into account the kinks already added to the AOD
2125 Bool_t * usedKink = NULL;
2127 usedKink = new Bool_t[nKinks];
2128 for (Int_t iKink=0; iKink<nKinks; ++iKink) usedKink[iKink]=kFALSE;
2131 // Access to the AOD container of vertices
2132 TClonesArray &vertices = *(aod->GetVertices());
2135 // Access to the AOD container of tracks
2136 TClonesArray &tracks = *(aod->GetTracks());
2139 // Add primary vertex. The primary tracks will be defined
2140 // after the loops on the composite objects (V0, cascades, kinks)
2141 const AliESDVertex *vtx = esd->GetPrimaryVertex();
2143 vtx->GetXYZ(pos); // position
2144 vtx->GetCovMatrix(covVtx); //covariance matrix
2146 AliAODVertex * primary = new(vertices[jVertices++])
2147 AliAODVertex(pos, covVtx, vtx->GetChi2toNDF(), NULL, AliAODVertex::kPrimary);
2149 // Create vertices starting from the most complex objects
2152 for (Int_t nCascade = 0; nCascade < nCascades; ++nCascade) {
2153 AliESDcascade *cascade = esd->GetCascade(nCascade);
2155 cascade->GetXYZ(pos[0], pos[1], pos[2]);
2156 cascade->GetPosCovXi(covVtx);
2158 // Add the cascade vertex
2159 AliAODVertex * vcascade = new(vertices[jVertices++]) AliAODVertex(pos,
2161 cascade->GetChi2Xi(), // = chi2/NDF since NDF = 2*2-3
2163 AliAODVertex::kCascade);
2165 primary->AddDaughter(vcascade);
2167 // Add the V0 from the cascade. The ESD class have to be optimized...
2168 // Now we have to search for the corresponding Vo in the list of V0s
2169 // using the indeces of the positive and negative tracks
2171 Int_t posFromV0 = cascade->GetPindex();
2172 Int_t negFromV0 = cascade->GetNindex();
2175 AliESDv0 * v0 = 0x0;
2178 for (Int_t iV0=0; iV0<nV0s; ++iV0) {
2180 v0 = esd->GetV0(iV0);
2181 Int_t posV0 = v0->GetPindex();
2182 Int_t negV0 = v0->GetNindex();
2184 if (posV0==posFromV0 && negV0==negFromV0) {
2190 AliAODVertex * vV0FromCascade = 0x0;
2192 if (indV0>-1 && !usedV0[indV0] ) {
2194 // the V0 exists in the array of V0s and is not used
2196 usedV0[indV0] = kTRUE;
2198 v0->GetXYZ(pos[0], pos[1], pos[2]);
2199 v0->GetPosCov(covVtx);
2201 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2203 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2208 // the V0 doesn't exist in the array of V0s or was used
2209 cerr << "Error: event " << iEvent << " cascade " << nCascade
2210 << " The V0 " << indV0
2211 << " doesn't exist in the array of V0s or was used!" << endl;
2213 cascade->GetXYZ(pos[0], pos[1], pos[2]);
2214 cascade->GetPosCov(covVtx);
2216 vV0FromCascade = new(vertices[jVertices++]) AliAODVertex(pos,
2218 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2221 vcascade->AddDaughter(vV0FromCascade);
2224 // Add the positive tracks from the V0
2226 if (! usedTrack[posFromV0]) {
2228 usedTrack[posFromV0] = kTRUE;
2230 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2231 esdTrack->GetPxPyPz(p);
2232 esdTrack->GetXYZ(pos);
2233 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2234 esdTrack->GetESDpid(pid);
2236 vV0FromCascade->AddDaughter(aodTrack =
2237 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2238 esdTrack->GetLabel(),
2244 (Short_t)esdTrack->GetSign(),
2245 esdTrack->GetITSClusterMap(),
2248 kTRUE, // check if this is right
2249 kFALSE, // check if this is right
2250 AliAODTrack::kSecondary)
2252 aodTrack->ConvertAliPIDtoAODPID();
2255 cerr << "Error: event " << iEvent << " cascade " << nCascade
2256 << " track " << posFromV0 << " has already been used!" << endl;
2259 // Add the negative tracks from the V0
2261 if (!usedTrack[negFromV0]) {
2263 usedTrack[negFromV0] = kTRUE;
2265 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2266 esdTrack->GetPxPyPz(p);
2267 esdTrack->GetXYZ(pos);
2268 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2269 esdTrack->GetESDpid(pid);
2271 vV0FromCascade->AddDaughter(aodTrack =
2272 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2273 esdTrack->GetLabel(),
2279 (Short_t)esdTrack->GetSign(),
2280 esdTrack->GetITSClusterMap(),
2283 kTRUE, // check if this is right
2284 kFALSE, // check if this is right
2285 AliAODTrack::kSecondary)
2287 aodTrack->ConvertAliPIDtoAODPID();
2290 cerr << "Error: event " << iEvent << " cascade " << nCascade
2291 << " track " << negFromV0 << " has already been used!" << endl;
2294 // Add the bachelor track from the cascade
2296 Int_t bachelor = cascade->GetBindex();
2298 if(!usedTrack[bachelor]) {
2300 usedTrack[bachelor] = kTRUE;
2302 AliESDtrack *esdTrack = esd->GetTrack(bachelor);
2303 esdTrack->GetPxPyPz(p);
2304 esdTrack->GetXYZ(pos);
2305 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2306 esdTrack->GetESDpid(pid);
2308 vcascade->AddDaughter(aodTrack =
2309 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2310 esdTrack->GetLabel(),
2316 (Short_t)esdTrack->GetSign(),
2317 esdTrack->GetITSClusterMap(),
2320 kTRUE, // check if this is right
2321 kFALSE, // check if this is right
2322 AliAODTrack::kSecondary)
2324 aodTrack->ConvertAliPIDtoAODPID();
2327 cerr << "Error: event " << iEvent << " cascade " << nCascade
2328 << " track " << bachelor << " has already been used!" << endl;
2331 // Add the primary track of the cascade (if any)
2333 } // end of the loop on cascades
2337 for (Int_t nV0 = 0; nV0 < nV0s; ++nV0) {
2339 if (usedV0[nV0]) continue; // skip if aready added to the AOD
2341 AliESDv0 *v0 = esd->GetV0(nV0);
2343 v0->GetXYZ(pos[0], pos[1], pos[2]);
2344 v0->GetPosCov(covVtx);
2346 AliAODVertex * vV0 =
2347 new(vertices[jVertices++]) AliAODVertex(pos,
2349 v0->GetChi2V0(), // = chi2/NDF since NDF = 2*2-3
2352 primary->AddDaughter(vV0);
2354 Int_t posFromV0 = v0->GetPindex();
2355 Int_t negFromV0 = v0->GetNindex();
2357 // Add the positive tracks from the V0
2359 if (!usedTrack[posFromV0]) {
2361 usedTrack[posFromV0] = kTRUE;
2363 AliESDtrack *esdTrack = esd->GetTrack(posFromV0);
2364 esdTrack->GetPxPyPz(p);
2365 esdTrack->GetXYZ(pos);
2366 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2367 esdTrack->GetESDpid(pid);
2369 vV0->AddDaughter(aodTrack =
2370 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2371 esdTrack->GetLabel(),
2377 (Short_t)esdTrack->GetSign(),
2378 esdTrack->GetITSClusterMap(),
2381 kTRUE, // check if this is right
2382 kFALSE, // check if this is right
2383 AliAODTrack::kSecondary)
2385 aodTrack->ConvertAliPIDtoAODPID();
2388 cerr << "Error: event " << iEvent << " V0 " << nV0
2389 << " track " << posFromV0 << " has already been used!" << endl;
2392 // Add the negative tracks from the V0
2394 if (!usedTrack[negFromV0]) {
2396 usedTrack[negFromV0] = kTRUE;
2398 AliESDtrack *esdTrack = esd->GetTrack(negFromV0);
2399 esdTrack->GetPxPyPz(p);
2400 esdTrack->GetXYZ(pos);
2401 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2402 esdTrack->GetESDpid(pid);
2404 vV0->AddDaughter(aodTrack =
2405 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2406 esdTrack->GetLabel(),
2412 (Short_t)esdTrack->GetSign(),
2413 esdTrack->GetITSClusterMap(),
2416 kTRUE, // check if this is right
2417 kFALSE, // check if this is right
2418 AliAODTrack::kSecondary)
2420 aodTrack->ConvertAliPIDtoAODPID();
2423 cerr << "Error: event " << iEvent << " V0 " << nV0
2424 << " track " << negFromV0 << " has already been used!" << endl;
2427 } // end of the loop on V0s
2429 // Kinks: it is a big mess the access to the information in the kinks
2430 // The loop is on the tracks in order to find the mother and daugther of each kink
2433 for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) {
2436 AliESDtrack * esdTrack = esd->GetTrack(iTrack);
2438 Int_t ikink = esdTrack->GetKinkIndex(0);
2441 // Negative kink index: mother, positive: daughter
2443 // Search for the second track of the kink
2445 for (Int_t jTrack = iTrack+1; jTrack<nTracks; ++jTrack) {
2447 AliESDtrack * esdTrack1 = esd->GetTrack(jTrack);
2449 Int_t jkink = esdTrack1->GetKinkIndex(0);
2451 if ( TMath::Abs(ikink)==TMath::Abs(jkink) ) {
2453 // The two tracks are from the same kink
2455 if (usedKink[TMath::Abs(ikink)-1]) continue; // skip used kinks
2458 Int_t idaughter = -1;
2460 if (ikink<0 && jkink>0) {
2465 else if (ikink>0 && jkink<0) {
2471 cerr << "Error: Wrong combination of kink indexes: "
2472 << ikink << " " << jkink << endl;
2476 // Add the mother track
2478 AliAODTrack * mother = NULL;
2480 if (!usedTrack[imother]) {
2482 usedTrack[imother] = kTRUE;
2484 AliESDtrack *esdTrack = esd->GetTrack(imother);
2485 esdTrack->GetPxPyPz(p);
2486 esdTrack->GetXYZ(pos);
2487 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2488 esdTrack->GetESDpid(pid);
2491 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2492 esdTrack->GetLabel(),
2498 (Short_t)esdTrack->GetSign(),
2499 esdTrack->GetITSClusterMap(),
2502 kTRUE, // check if this is right
2503 kTRUE, // check if this is right
2504 AliAODTrack::kPrimary);
2505 primary->AddDaughter(mother);
2506 mother->ConvertAliPIDtoAODPID();
2509 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2510 << " track " << imother << " has already been used!" << endl;
2513 // Add the kink vertex
2514 AliESDkink * kink = esd->GetKink(TMath::Abs(ikink)-1);
2516 AliAODVertex * vkink =
2517 new(vertices[jVertices++]) AliAODVertex(kink->GetPosition(),
2521 AliAODVertex::kKink);
2522 // Add the daughter track
2524 AliAODTrack * daughter = NULL;
2526 if (!usedTrack[idaughter]) {
2528 usedTrack[idaughter] = kTRUE;
2530 AliESDtrack *esdTrack = esd->GetTrack(idaughter);
2531 esdTrack->GetPxPyPz(p);
2532 esdTrack->GetXYZ(pos);
2533 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2534 esdTrack->GetESDpid(pid);
2537 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2538 esdTrack->GetLabel(),
2544 (Short_t)esdTrack->GetSign(),
2545 esdTrack->GetITSClusterMap(),
2548 kTRUE, // check if this is right
2549 kTRUE, // check if this is right
2550 AliAODTrack::kPrimary);
2551 vkink->AddDaughter(daughter);
2552 daughter->ConvertAliPIDtoAODPID();
2555 cerr << "Error: event " << iEvent << " kink " << TMath::Abs(ikink)-1
2556 << " track " << idaughter << " has already been used!" << endl;
2568 // Tracks (primary and orphan)
2570 for (Int_t nTrack = 0; nTrack < nTracks; ++nTrack) {
2573 if (usedTrack[nTrack]) continue;
2575 AliESDtrack *esdTrack = esd->GetTrack(nTrack);
2576 esdTrack->GetPxPyPz(p);
2577 esdTrack->GetXYZ(pos);
2578 esdTrack->GetCovarianceXYZPxPyPz(covTr);
2579 esdTrack->GetESDpid(pid);
2581 Float_t impactXY, impactZ;
2583 esdTrack->GetImpactParameters(impactXY,impactZ);
2586 // track inside the beam pipe
2588 primary->AddDaughter(aodTrack =
2589 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2590 esdTrack->GetLabel(),
2596 (Short_t)esdTrack->GetSign(),
2597 esdTrack->GetITSClusterMap(),
2600 kTRUE, // check if this is right
2601 kTRUE, // check if this is right
2602 AliAODTrack::kPrimary)
2604 aodTrack->ConvertAliPIDtoAODPID();
2607 // outside the beam pipe: orphan track
2609 new(tracks[jTracks++]) AliAODTrack(esdTrack->GetID(),
2610 esdTrack->GetLabel(),
2616 (Short_t)esdTrack->GetSign(),
2617 esdTrack->GetITSClusterMap(),
2620 kFALSE, // check if this is right
2621 kFALSE, // check if this is right
2622 AliAODTrack::kOrphan);
2623 aodTrack->ConvertAliPIDtoAODPID();
2625 } // end of loop on tracks
2628 Int_t nMuTracks = esd->GetNumberOfMuonTracks();
2629 for (Int_t nMuTrack = 0; nMuTrack < nMuTracks; ++nMuTrack) {
2631 AliESDMuonTrack *esdMuTrack = esd->GetMuonTrack(nMuTrack);
2632 p[0] = esdMuTrack->Px();
2633 p[1] = esdMuTrack->Py();
2634 p[2] = esdMuTrack->Pz();
2635 pos[0] = primary->GetX();
2636 pos[1] = primary->GetY();
2637 pos[2] = primary->GetZ();
2639 // has to be changed once the muon pid is provided by the ESD
2640 for (Int_t i = 0; i < 10; pid[i++] = 0.); pid[AliAODTrack::kMuon]=1.;
2642 primary->AddDaughter(
2643 new(tracks[jTracks++]) AliAODTrack(0, // no ID provided
2644 0, // no label provided
2649 NULL, // no covariance matrix provided
2650 (Short_t)-99, // no charge provided
2651 0, // no ITSClusterMap
2654 kTRUE, // check if this is right
2655 kTRUE, // not used for vertex fit
2656 AliAODTrack::kPrimary)
2660 // Access to the AOD container of clusters
2661 TClonesArray &clusters = *(aod->GetClusters());
2665 Int_t nClusters = esd->GetNumberOfCaloClusters();
2667 for (Int_t iClust=0; iClust<nClusters; ++iClust) {
2669 AliESDCaloCluster * cluster = esd->GetCaloCluster(iClust);
2671 Int_t id = cluster->GetID();
2673 Float_t energy = cluster->E();
2674 cluster->GetPosition(posF);
2675 AliAODVertex *prodVertex = primary;
2676 AliAODTrack *primTrack = NULL;
2677 Char_t ttype=AliAODCluster::kUndef;
2679 if (cluster->IsPHOS()) ttype=AliAODCluster::kPHOSNeutral;
2680 else if (cluster->IsEMCAL()) {
2682 if (cluster->GetClusterType() == AliESDCaloCluster::kPseudoCluster)
2683 ttype = AliAODCluster::kEMCALPseudoCluster;
2685 ttype = AliAODCluster::kEMCALClusterv1;
2689 new(clusters[jClusters++]) AliAODCluster(id,
2693 NULL, // no covariance matrix provided
2694 NULL, // no pid for clusters provided
2699 } // end of loop on calo clusters
2701 delete [] usedTrack;
2705 // fill the tree for this event
2707 } // end of event loop
2709 aodTree->GetUserInfo()->Add(aod);
2714 // write the tree to the specified file
2715 aodFile = aodTree->GetCurrentFile();
2722 void AliReconstruction::WriteAlignmentData(AliESD* esd)
2724 // Write space-points which are then used in the alignment procedures
2725 // For the moment only ITS, TRD and TPC
2727 // Load TOF clusters
2729 fLoader[3]->LoadRecPoints("read");
2730 TTree* tree = fLoader[3]->TreeR();
2732 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2735 fTracker[3]->LoadClusters(tree);
2737 Int_t ntracks = esd->GetNumberOfTracks();
2738 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2740 AliESDtrack *track = esd->GetTrack(itrack);
2743 for (Int_t iDet = 3; iDet >= 0; iDet--)
2744 nsp += track->GetNcls(iDet);
2746 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2747 track->SetTrackPointArray(sp);
2749 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2750 AliTracker *tracker = fTracker[iDet];
2751 if (!tracker) continue;
2752 Int_t nspdet = track->GetNcls(iDet);
2753 if (nspdet <= 0) continue;
2754 track->GetClusters(iDet,idx);
2758 while (isp < nspdet) {
2759 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
2760 const Int_t kNTPCmax = 159;
2761 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2762 if (!isvalid) continue;
2763 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2769 fTracker[3]->UnloadClusters();
2770 fLoader[3]->UnloadRecPoints();
2774 //_____________________________________________________________________________
2775 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESD* esd)
2777 // The method reads the raw-data error log
2778 // accumulated within the rawReader.
2779 // It extracts the raw-data errors related to
2780 // the current event and stores them into
2781 // a TClonesArray inside the esd object.
2783 if (!fRawReader) return;
2785 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2787 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2789 if (iEvent != log->GetEventNumber()) continue;
2791 esd->AddRawDataErrorLog(log);
2796 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2797 // Dump a file content into a char in TNamed
2799 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2800 Int_t kBytes = (Int_t)in.tellg();
2801 printf("Size: %d \n",kBytes);
2804 char* memblock = new char [kBytes];
2805 in.seekg (0, ios::beg);
2806 in.read (memblock, kBytes);
2808 TString fData(memblock,kBytes);
2809 fn = new TNamed(fName,fData);
2810 printf("fData Size: %d \n",fData.Sizeof());
2811 printf("fName Size: %d \n",fName.Sizeof());
2812 printf("fn Size: %d \n",fn->Sizeof());
2816 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2822 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2823 // This is not really needed in AliReconstruction at the moment
2824 // but can serve as a template
2826 TList *fList = fTree->GetUserInfo();
2827 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2828 printf("fn Size: %d \n",fn->Sizeof());
2830 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2831 const char* cdata = fn->GetTitle();
2832 printf("fTmp Size %d\n",fTmp.Sizeof());
2834 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2835 printf("calculated size %d\n",size);
2836 ofstream out(fName.Data(),ios::out | ios::binary);
2837 out.write(cdata,size);