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 // The name of the galice file can be changed from the default //
51 // "galice.root" by passing it as argument to the AliReconstruction //
52 // constructor or by //
54 // rec.SetGAliceFile("..."); //
56 // The local reconstruction can be switched on or off for individual //
59 // rec.SetRunLocalReconstruction("..."); //
61 // The argument is a (case sensitive) string with the names of the //
62 // detectors separated by a space. The special string "ALL" selects all //
63 // available detectors. This is the default. //
65 // The reconstruction of the primary vertex position can be switched off by //
67 // rec.SetRunVertexFinder(kFALSE); //
69 // The tracking and the creation of ESD tracks can be switched on for //
70 // selected detectors by //
72 // rec.SetRunTracking("..."); //
74 // Uniform/nonuniform field tracking switches (default: uniform field) //
76 // rec.SetUniformFieldTracking(); ( rec.SetNonuniformFieldTracking(); ) //
78 // The filling of additional ESD information can be steered by //
80 // rec.SetFillESD("..."); //
82 // Again, for both methods the string specifies the list of detectors. //
83 // The default is "ALL". //
85 // The call of the shortcut method //
87 // rec.SetRunReconstruction("..."); //
89 // is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
90 // SetFillESD with the same detector selecting string as argument. //
92 // The reconstruction requires digits or raw data as input. For the creation //
93 // of digits and raw data have a look at the class AliSimulation. //
95 // For debug purposes the method SetCheckPointLevel can be used. If the //
96 // argument is greater than 0, files with ESD events will be written after //
97 // selected steps of the reconstruction for each event: //
98 // level 1: after tracking and after filling of ESD (final) //
99 // level 2: in addition after each tracking step //
100 // level 3: in addition after the filling of ESD for each detector //
101 // If a final check point file exists for an event, this event will be //
102 // skipped in the reconstruction. The tracking and the filling of ESD for //
103 // a detector will be skipped as well, if the corresponding check point //
104 // file exists. The ESD event will then be loaded from the file instead. //
106 ///////////////////////////////////////////////////////////////////////////////
112 #include <TPluginManager.h>
113 #include <TStopwatch.h>
114 #include <TGeoManager.h>
115 #include <TLorentzVector.h>
117 #include "AliReconstruction.h"
118 #include "AliReconstructor.h"
120 #include "AliRunLoader.h"
122 #include "AliRawReaderFile.h"
123 #include "AliRawReaderDate.h"
124 #include "AliRawReaderRoot.h"
126 #include "AliESDVertex.h"
127 #include "AliTracker.h"
128 #include "AliVertexer.h"
129 #include "AliHeader.h"
130 #include "AliGenEventHeader.h"
132 #include "AliESDpid.h"
133 #include "AliESDtrack.h"
135 #include "AliRunTag.h"
136 //#include "AliLHCTag.h"
137 #include "AliDetectorTag.h"
138 #include "AliEventTag.h"
140 #include "AliTrackPointArray.h"
141 #include "AliCDBManager.h"
142 #include "AliCDBEntry.h"
143 #include "AliAlignObj.h"
145 ClassImp(AliReconstruction)
148 //_____________________________________________________________________________
149 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "RICH", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "START", "VZERO", "CRT", "HLT"};
151 //_____________________________________________________________________________
152 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
153 const char* name, const char* title) :
156 fRunLocalReconstruction("ALL"),
157 fUniformField(kTRUE),
158 fRunVertexFinder(kTRUE),
159 fRunHLTTracking(kFALSE),
162 fGAliceFileName(gAliceFilename),
166 fStopOnError(kFALSE),
169 fLoadAlignFromCDB(kTRUE),
170 fLoadAlignData("ALL"),
177 fAlignObjArray(NULL),
178 fWriteAlignmentData(kFALSE),
181 // create reconstruction object with default parameters
183 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
184 fReconstructor[iDet] = NULL;
185 fLoader[iDet] = NULL;
186 fTracker[iDet] = NULL;
191 //_____________________________________________________________________________
192 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
195 fRunLocalReconstruction(rec.fRunLocalReconstruction),
196 fUniformField(rec.fUniformField),
197 fRunVertexFinder(rec.fRunVertexFinder),
198 fRunHLTTracking(rec.fRunHLTTracking),
199 fRunTracking(rec.fRunTracking),
200 fFillESD(rec.fFillESD),
201 fGAliceFileName(rec.fGAliceFileName),
203 fFirstEvent(rec.fFirstEvent),
204 fLastEvent(rec.fLastEvent),
205 fStopOnError(rec.fStopOnError),
208 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
209 fLoadAlignData(rec.fLoadAlignData),
216 fAlignObjArray(rec.fAlignObjArray),
217 fWriteAlignmentData(rec.fWriteAlignmentData),
222 for (Int_t i = 0; i < fOptions.GetEntriesFast(); i++) {
223 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
225 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
226 fReconstructor[iDet] = NULL;
227 fLoader[iDet] = NULL;
228 fTracker[iDet] = NULL;
232 //_____________________________________________________________________________
233 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
235 // assignment operator
237 this->~AliReconstruction();
238 new(this) AliReconstruction(rec);
242 //_____________________________________________________________________________
243 AliReconstruction::~AliReconstruction()
251 //_____________________________________________________________________________
252 void AliReconstruction::InitCDBStorage()
254 // activate a default CDB storage
255 // First check if we have any CDB storage set, because it is used
256 // to retrieve the calibration and alignment constants
258 AliCDBManager* man = AliCDBManager::Instance();
259 if (!man->IsDefaultStorageSet())
261 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
262 AliWarning("Default CDB storage not yet set");
263 AliWarning(Form("Using default storage declared in AliSimulation: %s",fCDBUri.Data()));
264 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
265 SetDefaultStorage(fCDBUri);
270 //_____________________________________________________________________________
271 void AliReconstruction::SetDefaultStorage(const char* uri) {
272 // activate a default CDB storage
274 AliCDBManager::Instance()->SetDefaultStorage(uri);
278 //_____________________________________________________________________________
279 void AliReconstruction::SetSpecificStorage(const char* detName, const char* uri) {
280 // activate a detector-specific CDB storage
282 AliCDBManager::Instance()->SetSpecificStorage(detName, uri);
286 //_____________________________________________________________________________
287 Bool_t AliReconstruction::SetRunNumber()
289 // The method is called in Run() in order
290 // to set a correct run number.
291 // In case of raw data reconstruction the
292 // run number is taken from the raw data header
294 if(AliCDBManager::Instance()->GetRun() < 0) {
296 AliError("No run loader is found !");
299 // read run number from gAlice
300 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
301 AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
306 //_____________________________________________________________________________
307 Bool_t AliReconstruction::ApplyAlignObjsToGeom(TObjArray* alObjArray)
309 // Read collection of alignment objects (AliAlignObj derived) saved
310 // in the TClonesArray ClArrayName and apply them to the geometry
311 // manager singleton.
314 Int_t nvols = alObjArray->GetEntriesFast();
316 for(Int_t j=0; j<nvols; j++)
318 AliAlignObj* alobj = (AliAlignObj*) alObjArray->UncheckedAt(j);
319 if (alobj->ApplyToGeometry() == kFALSE)
323 if (AliDebugLevelClass() >= 1) {
324 gGeoManager->CheckOverlaps(20);
325 TObjArray* ovexlist = gGeoManager->GetListOfOverlaps();
326 if(ovexlist->GetEntriesFast()){
327 AliError("The application of alignment objects to the geometry caused huge overlaps/extrusions!");
335 //_____________________________________________________________________________
336 Bool_t AliReconstruction::SetAlignObjArraySingleDet(const char* detName)
338 // Fills array of single detector's alignable objects from CDB
340 AliDebug(2, Form("Loading alignment data for detector: %s",detName));
344 AliCDBPath path(detName,"Align","Data");
346 entry=AliCDBManager::Instance()->Get(path.GetPath());
348 AliDebug(2,Form("Couldn't load alignment data for detector %s",detName));
352 TClonesArray *alignArray = (TClonesArray*) entry->GetObject();
353 alignArray->SetOwner(0);
354 AliDebug(2,Form("Found %d alignment objects for %s",
355 alignArray->GetEntries(),detName));
357 AliAlignObj *alignObj=0;
358 TIter iter(alignArray);
360 // loop over align objects in detector
361 while( ( alignObj=(AliAlignObj *) iter.Next() ) ){
362 fAlignObjArray->Add(alignObj);
364 // delete entry --- Don't delete, it is cached!
366 AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
371 //_____________________________________________________________________________
372 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
374 // Read the alignment objects from CDB.
375 // Each detector is supposed to have the
376 // alignment objects in DET/Align/Data CDB path.
377 // All the detector objects are then collected,
378 // sorted by geometry level (starting from ALIC) and
379 // then applied to the TGeo geometry.
380 // Finally an overlaps check is performed.
382 // Load alignment data from CDB and fill fAlignObjArray
383 if(fLoadAlignFromCDB){
384 if(!fAlignObjArray) fAlignObjArray = new TObjArray();
386 //fAlignObjArray->RemoveAll();
387 fAlignObjArray->Clear();
388 fAlignObjArray->SetOwner(0);
390 TString detStr = detectors;
391 TString dataNotLoaded="";
392 TString dataLoaded="";
394 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
395 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
396 if(!SetAlignObjArraySingleDet(fgkDetectorName[iDet])){
397 dataNotLoaded += fgkDetectorName[iDet];
398 dataNotLoaded += " ";
400 dataLoaded += fgkDetectorName[iDet];
403 } // end loop over detectors
405 if ((detStr.CompareTo("ALL") == 0)) detStr = "";
406 dataNotLoaded += detStr;
407 AliInfo(Form("Alignment data loaded for: %s",
409 AliInfo(Form("Didn't/couldn't load alignment data for: %s",
410 dataNotLoaded.Data()));
411 } // fLoadAlignFromCDB flag
413 // Check if the array with alignment objects was
414 // provided by the user. If yes, apply the objects
415 // to the present TGeo geometry
416 if (fAlignObjArray) {
417 if (gGeoManager && gGeoManager->IsClosed()) {
418 if (ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
419 AliError("The application of misalignment failed! Restart aliroot and try again. ");
424 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
432 //_____________________________________________________________________________
433 void AliReconstruction::SetGAliceFile(const char* fileName)
435 // set the name of the galice file
437 fGAliceFileName = fileName;
440 //_____________________________________________________________________________
441 void AliReconstruction::SetOption(const char* detector, const char* option)
443 // set options for the reconstruction of a detector
445 TObject* obj = fOptions.FindObject(detector);
446 if (obj) fOptions.Remove(obj);
447 fOptions.Add(new TNamed(detector, option));
451 //_____________________________________________________________________________
452 Bool_t AliReconstruction::Run(const char* input,
453 Int_t firstEvent, Int_t lastEvent)
455 // run the reconstruction
460 if (!input) input = fInput.Data();
461 TString fileName(input);
462 if (fileName.EndsWith("/")) {
463 fRawReader = new AliRawReaderFile(fileName);
464 } else if (fileName.EndsWith(".root")) {
465 fRawReader = new AliRawReaderRoot(fileName);
466 } else if (!fileName.IsNull()) {
467 fRawReader = new AliRawReaderDate(fileName);
468 fRawReader->SelectEvents(7);
471 // get the run loader
472 if (!InitRunLoader()) return kFALSE;
474 // Set run number in CDBManager (if it is not already set by the user)
475 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
477 // Import ideal TGeo geometry and apply misalignment
479 TString geom(gSystem->DirName(fGAliceFileName));
480 geom += "/geometry.root";
481 TGeoManager::Import(geom.Data());
482 if (!gGeoManager) if (fStopOnError) return kFALSE;
484 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
486 // Temporary fix by A.Gheata
487 // Could be removed with the next Root version (>5.11)
489 TIter next(gGeoManager->GetListOfVolumes());
491 while ((vol = (TGeoVolume *)next())) {
492 if (vol->GetVoxels()) {
493 if (vol->GetVoxels()->NeedRebuild()) {
494 vol->GetVoxels()->Voxelize();
501 // local reconstruction
502 if (!fRunLocalReconstruction.IsNull()) {
503 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
504 if (fStopOnError) {CleanUp(); return kFALSE;}
507 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
508 // fFillESD.IsNull()) return kTRUE;
511 if (fRunVertexFinder && !CreateVertexer()) {
519 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
527 TStopwatch stopwatch;
530 // get the possibly already existing ESD file and tree
531 AliESD* esd = new AliESD; AliESD* hltesd = new AliESD;
532 TFile* fileOld = NULL;
533 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
534 if (!gSystem->AccessPathName("AliESDs.root")){
535 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
536 fileOld = TFile::Open("AliESDs.old.root");
537 if (fileOld && fileOld->IsOpen()) {
538 treeOld = (TTree*) fileOld->Get("esdTree");
539 if (treeOld) treeOld->SetBranchAddress("ESD", &esd);
540 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
541 if (hlttreeOld) hlttreeOld->SetBranchAddress("ESD", &hltesd);
545 // create the ESD output file and tree
546 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
547 if (!file->IsOpen()) {
548 AliError("opening AliESDs.root failed");
549 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
551 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
552 tree->Branch("ESD", "AliESD", &esd);
553 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
554 hlttree->Branch("ESD", "AliESD", &hltesd);
555 delete esd; delete hltesd;
556 esd = NULL; hltesd = NULL;
560 if (fRawReader) fRawReader->RewindEvents();
562 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
563 if (fRawReader) fRawReader->NextEvent();
564 if ((iEvent < firstEvent) || ((lastEvent >= 0) && (iEvent > lastEvent))) {
565 // copy old ESD to the new one
567 treeOld->SetBranchAddress("ESD", &esd);
568 treeOld->GetEntry(iEvent);
572 hlttreeOld->SetBranchAddress("ESD", &hltesd);
573 hlttreeOld->GetEntry(iEvent);
579 AliInfo(Form("processing event %d", iEvent));
580 fRunLoader->GetEvent(iEvent);
583 sprintf(fileName, "ESD_%d.%d_final.root",
584 fRunLoader->GetHeader()->GetRun(),
585 fRunLoader->GetHeader()->GetEventNrInRun());
586 if (!gSystem->AccessPathName(fileName)) continue;
588 // local reconstruction
589 if (!fRunLocalReconstruction.IsNull()) {
590 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
591 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
595 esd = new AliESD; hltesd = new AliESD;
596 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
597 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
598 esd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
599 hltesd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
601 esd->SetMagneticField(AliTracker::GetBz());
602 hltesd->SetMagneticField(AliTracker::GetBz());
608 if (fRunVertexFinder) {
609 if (!ReadESD(esd, "vertex")) {
610 if (!RunVertexFinder(esd)) {
611 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
613 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
618 if (!fRunTracking.IsNull()) {
619 if (fRunHLTTracking) {
620 hltesd->SetVertex(esd->GetVertex());
621 if (!RunHLTTracking(hltesd)) {
622 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
628 if (!fRunTracking.IsNull()) {
629 if (!ReadESD(esd, "tracking")) {
630 if (!RunTracking(esd)) {
631 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
633 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
638 if (!fFillESD.IsNull()) {
639 if (!FillESD(esd, fFillESD)) {
640 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
645 AliESDpid::MakePID(esd);
646 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
653 if (fCheckPointLevel > 0) WriteESD(esd, "final");
655 delete esd; delete hltesd;
656 esd = NULL; hltesd = NULL;
659 AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
660 stopwatch.RealTime(),stopwatch.CpuTime()));
666 // Create tags for the events in the ESD tree (the ESD tree is always present)
667 // In case of empty events the tags will contain dummy values
669 CleanUp(file, fileOld);
675 //_____________________________________________________________________________
676 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
678 // run the local reconstruction
680 TStopwatch stopwatch;
683 TString detStr = detectors;
684 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
685 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
686 AliReconstructor* reconstructor = GetReconstructor(iDet);
687 if (!reconstructor) continue;
688 if (reconstructor->HasLocalReconstruction()) continue;
690 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
691 TStopwatch stopwatchDet;
692 stopwatchDet.Start();
694 fRawReader->RewindEvents();
695 reconstructor->Reconstruct(fRunLoader, fRawReader);
697 reconstructor->Reconstruct(fRunLoader);
699 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
700 fgkDetectorName[iDet],
701 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
704 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
705 AliError(Form("the following detectors were not found: %s",
707 if (fStopOnError) return kFALSE;
710 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
711 stopwatch.RealTime(),stopwatch.CpuTime()));
716 //_____________________________________________________________________________
717 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
719 // run the local reconstruction
721 TStopwatch stopwatch;
724 TString detStr = detectors;
725 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
726 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
727 AliReconstructor* reconstructor = GetReconstructor(iDet);
728 if (!reconstructor) continue;
729 AliLoader* loader = fLoader[iDet];
731 // conversion of digits
732 if (fRawReader && reconstructor->HasDigitConversion()) {
733 AliInfo(Form("converting raw data digits into root objects for %s",
734 fgkDetectorName[iDet]));
735 TStopwatch stopwatchDet;
736 stopwatchDet.Start();
737 loader->LoadDigits("update");
738 loader->CleanDigits();
739 loader->MakeDigitsContainer();
740 TTree* digitsTree = loader->TreeD();
741 reconstructor->ConvertDigits(fRawReader, digitsTree);
742 loader->WriteDigits("OVERWRITE");
743 loader->UnloadDigits();
744 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
745 fgkDetectorName[iDet],
746 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
749 // local reconstruction
750 if (!reconstructor->HasLocalReconstruction()) continue;
751 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
752 TStopwatch stopwatchDet;
753 stopwatchDet.Start();
754 loader->LoadRecPoints("update");
755 loader->CleanRecPoints();
756 loader->MakeRecPointsContainer();
757 TTree* clustersTree = loader->TreeR();
758 if (fRawReader && !reconstructor->HasDigitConversion()) {
759 reconstructor->Reconstruct(fRawReader, clustersTree);
761 loader->LoadDigits("read");
762 TTree* digitsTree = loader->TreeD();
764 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
765 if (fStopOnError) return kFALSE;
767 reconstructor->Reconstruct(digitsTree, clustersTree);
769 loader->UnloadDigits();
771 loader->WriteRecPoints("OVERWRITE");
772 loader->UnloadRecPoints();
773 AliDebug(1,Form("Execution time for %s: R:%.2fs C:%.2fs",
774 fgkDetectorName[iDet],
775 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
778 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
779 AliError(Form("the following detectors were not found: %s",
781 if (fStopOnError) return kFALSE;
784 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
785 stopwatch.RealTime(),stopwatch.CpuTime()));
790 //_____________________________________________________________________________
791 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
793 // run the barrel tracking
795 TStopwatch stopwatch;
798 AliESDVertex* vertex = NULL;
799 Double_t vtxPos[3] = {0, 0, 0};
800 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
802 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
803 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
804 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
808 AliInfo("running the ITS vertex finder");
809 if (fLoader[0]) fLoader[0]->LoadRecPoints();
810 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
811 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
813 AliWarning("Vertex not found");
814 vertex = new AliESDVertex();
815 vertex->SetName("default");
818 vertex->SetTruePos(vtxPos); // store also the vertex from MC
819 vertex->SetName("reconstructed");
823 AliInfo("getting the primary vertex from MC");
824 vertex = new AliESDVertex(vtxPos, vtxErr);
828 vertex->GetXYZ(vtxPos);
829 vertex->GetSigmaXYZ(vtxErr);
831 AliWarning("no vertex reconstructed");
832 vertex = new AliESDVertex(vtxPos, vtxErr);
834 esd->SetVertex(vertex);
835 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
836 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
840 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
841 stopwatch.RealTime(),stopwatch.CpuTime()));
846 //_____________________________________________________________________________
847 Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
849 // run the HLT barrel tracking
851 TStopwatch stopwatch;
855 AliError("Missing runLoader!");
859 AliInfo("running HLT tracking");
861 // Get a pointer to the HLT reconstructor
862 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
863 if (!reconstructor) return kFALSE;
866 for (Int_t iDet = 1; iDet >= 0; iDet--) {
867 TString detName = fgkDetectorName[iDet];
868 AliDebug(1, Form("%s HLT tracking", detName.Data()));
869 reconstructor->SetOption(detName.Data());
870 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
872 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
873 if (fStopOnError) return kFALSE;
877 Double_t vtxErr[3]={0.005,0.005,0.010};
878 const AliESDVertex *vertex = esd->GetVertex();
879 vertex->GetXYZ(vtxPos);
880 tracker->SetVertex(vtxPos,vtxErr);
882 fLoader[iDet]->LoadRecPoints("read");
883 TTree* tree = fLoader[iDet]->TreeR();
885 AliError(Form("Can't get the %s cluster tree", detName.Data()));
888 tracker->LoadClusters(tree);
890 if (tracker->Clusters2Tracks(esd) != 0) {
891 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
895 tracker->UnloadClusters();
900 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
901 stopwatch.RealTime(),stopwatch.CpuTime()));
906 //_____________________________________________________________________________
907 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
909 // run the barrel tracking
911 TStopwatch stopwatch;
914 AliInfo("running tracking");
916 // pass 1: TPC + ITS inwards
917 for (Int_t iDet = 1; iDet >= 0; iDet--) {
918 if (!fTracker[iDet]) continue;
919 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
922 fLoader[iDet]->LoadRecPoints("read");
923 TTree* tree = fLoader[iDet]->TreeR();
925 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
928 fTracker[iDet]->LoadClusters(tree);
931 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
932 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
935 if (fCheckPointLevel > 1) {
936 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
938 // preliminary PID in TPC needed by the ITS tracker
940 GetReconstructor(1)->FillESD(fRunLoader, esd);
941 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
942 AliESDpid::MakePID(esd);
946 // pass 2: ALL backwards
947 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
948 if (!fTracker[iDet]) continue;
949 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
952 if (iDet > 1) { // all except ITS, TPC
954 fLoader[iDet]->LoadRecPoints("read");
955 tree = fLoader[iDet]->TreeR();
957 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
960 fTracker[iDet]->LoadClusters(tree);
964 if (fTracker[iDet]->PropagateBack(esd) != 0) {
965 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
968 if (fCheckPointLevel > 1) {
969 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
973 if (iDet > 2) { // all except ITS, TPC, TRD
974 fTracker[iDet]->UnloadClusters();
975 fLoader[iDet]->UnloadRecPoints();
977 // updated PID in TPC needed by the ITS tracker -MI
979 GetReconstructor(1)->FillESD(fRunLoader, esd);
980 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
981 AliESDpid::MakePID(esd);
985 // write space-points to the ESD in case alignment data output
987 if (fWriteAlignmentData)
988 WriteAlignmentData(esd);
990 // pass 3: TRD + TPC + ITS refit inwards
991 for (Int_t iDet = 2; iDet >= 0; iDet--) {
992 if (!fTracker[iDet]) continue;
993 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
996 if (fTracker[iDet]->RefitInward(esd) != 0) {
997 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1000 if (fCheckPointLevel > 1) {
1001 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1005 fTracker[iDet]->UnloadClusters();
1006 fLoader[iDet]->UnloadRecPoints();
1009 // Propagate track to the vertex - if not done by ITS
1011 Int_t ntracks = esd->GetNumberOfTracks();
1012 for (Int_t itrack=0; itrack<ntracks; itrack++){
1013 const Double_t kRadius = 3; // beam pipe radius
1014 const Double_t kMaxStep = 5; // max step
1015 const Double_t kMaxD = 123456; // max distance to prim vertex
1016 Double_t fieldZ = AliTracker::GetBz(); //
1017 AliESDtrack * track = esd->GetTrack(itrack);
1018 if (!track) continue;
1019 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1020 track->PropagateTo(kRadius, track->GetMass(),kMaxStep,kTRUE);
1021 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1024 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1025 stopwatch.RealTime(),stopwatch.CpuTime()));
1030 //_____________________________________________________________________________
1031 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
1033 // fill the event summary data
1035 TStopwatch stopwatch;
1037 AliInfo("filling ESD");
1039 TString detStr = detectors;
1040 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1041 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1042 AliReconstructor* reconstructor = GetReconstructor(iDet);
1043 if (!reconstructor) continue;
1045 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1046 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1047 TTree* clustersTree = NULL;
1048 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1049 fLoader[iDet]->LoadRecPoints("read");
1050 clustersTree = fLoader[iDet]->TreeR();
1051 if (!clustersTree) {
1052 AliError(Form("Can't get the %s clusters tree",
1053 fgkDetectorName[iDet]));
1054 if (fStopOnError) return kFALSE;
1057 if (fRawReader && !reconstructor->HasDigitConversion()) {
1058 reconstructor->FillESD(fRawReader, clustersTree, esd);
1060 TTree* digitsTree = NULL;
1061 if (fLoader[iDet]) {
1062 fLoader[iDet]->LoadDigits("read");
1063 digitsTree = fLoader[iDet]->TreeD();
1065 AliError(Form("Can't get the %s digits tree",
1066 fgkDetectorName[iDet]));
1067 if (fStopOnError) return kFALSE;
1070 reconstructor->FillESD(digitsTree, clustersTree, esd);
1071 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1073 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1074 fLoader[iDet]->UnloadRecPoints();
1078 reconstructor->FillESD(fRunLoader, fRawReader, esd);
1080 reconstructor->FillESD(fRunLoader, esd);
1082 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1086 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1087 AliError(Form("the following detectors were not found: %s",
1089 if (fStopOnError) return kFALSE;
1092 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1093 stopwatch.RealTime(),stopwatch.CpuTime()));
1099 //_____________________________________________________________________________
1100 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1102 // check whether detName is contained in detectors
1103 // if yes, it is removed from detectors
1105 // check if all detectors are selected
1106 if ((detectors.CompareTo("ALL") == 0) ||
1107 detectors.BeginsWith("ALL ") ||
1108 detectors.EndsWith(" ALL") ||
1109 detectors.Contains(" ALL ")) {
1114 // search for the given detector
1115 Bool_t result = kFALSE;
1116 if ((detectors.CompareTo(detName) == 0) ||
1117 detectors.BeginsWith(detName+" ") ||
1118 detectors.EndsWith(" "+detName) ||
1119 detectors.Contains(" "+detName+" ")) {
1120 detectors.ReplaceAll(detName, "");
1124 // clean up the detectors string
1125 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1126 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1127 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1132 //_____________________________________________________________________________
1133 Bool_t AliReconstruction::InitRunLoader()
1135 // get or create the run loader
1137 if (gAlice) delete gAlice;
1140 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1141 // load all base libraries to get the loader classes
1142 TString libs = gSystem->GetLibraries();
1143 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1144 TString detName = fgkDetectorName[iDet];
1145 if (detName == "HLT") continue;
1146 if (libs.Contains("lib" + detName + "base.so")) continue;
1147 gSystem->Load("lib" + detName + "base.so");
1149 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1151 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1155 fRunLoader->CdGAFile();
1156 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1157 if (fRunLoader->LoadgAlice() == 0) {
1158 gAlice = fRunLoader->GetAliRun();
1159 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1162 if (!gAlice && !fRawReader) {
1163 AliError(Form("no gAlice object found in file %s",
1164 fGAliceFileName.Data()));
1169 } else { // galice.root does not exist
1171 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1175 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1176 AliConfig::GetDefaultEventFolderName(),
1179 AliError(Form("could not create run loader in file %s",
1180 fGAliceFileName.Data()));
1184 fRunLoader->MakeTree("E");
1186 while (fRawReader->NextEvent()) {
1187 fRunLoader->SetEventNumber(iEvent);
1188 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1190 fRunLoader->MakeTree("H");
1191 fRunLoader->TreeE()->Fill();
1194 fRawReader->RewindEvents();
1195 fRunLoader->WriteHeader("OVERWRITE");
1196 fRunLoader->CdGAFile();
1197 fRunLoader->Write(0, TObject::kOverwrite);
1198 // AliTracker::SetFieldMap(???);
1204 //_____________________________________________________________________________
1205 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1207 // get the reconstructor object and the loader for a detector
1209 if (fReconstructor[iDet]) return fReconstructor[iDet];
1211 // load the reconstructor object
1212 TPluginManager* pluginManager = gROOT->GetPluginManager();
1213 TString detName = fgkDetectorName[iDet];
1214 TString recName = "Ali" + detName + "Reconstructor";
1215 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1217 if (detName == "HLT") {
1218 if (!gROOT->GetClass("AliLevel3")) {
1219 gSystem->Load("libAliL3Src.so");
1220 gSystem->Load("libAliL3Misc.so");
1221 gSystem->Load("libAliL3Hough.so");
1222 gSystem->Load("libAliL3Comp.so");
1226 AliReconstructor* reconstructor = NULL;
1227 // first check if a plugin is defined for the reconstructor
1228 TPluginHandler* pluginHandler =
1229 pluginManager->FindHandler("AliReconstructor", detName);
1230 // if not, add a plugin for it
1231 if (!pluginHandler) {
1232 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1233 TString libs = gSystem->GetLibraries();
1234 if (libs.Contains("lib" + detName + "base.so") ||
1235 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1236 pluginManager->AddHandler("AliReconstructor", detName,
1237 recName, detName + "rec", recName + "()");
1239 pluginManager->AddHandler("AliReconstructor", detName,
1240 recName, detName, recName + "()");
1242 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1244 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1245 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1247 if (reconstructor) {
1248 TObject* obj = fOptions.FindObject(detName.Data());
1249 if (obj) reconstructor->SetOption(obj->GetTitle());
1250 reconstructor->Init(fRunLoader);
1251 fReconstructor[iDet] = reconstructor;
1254 // get or create the loader
1255 if (detName != "HLT") {
1256 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1257 if (!fLoader[iDet]) {
1258 AliConfig::Instance()
1259 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1261 // first check if a plugin is defined for the loader
1262 TPluginHandler* pluginHandler =
1263 pluginManager->FindHandler("AliLoader", detName);
1264 // if not, add a plugin for it
1265 if (!pluginHandler) {
1266 TString loaderName = "Ali" + detName + "Loader";
1267 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1268 pluginManager->AddHandler("AliLoader", detName,
1269 loaderName, detName + "base",
1270 loaderName + "(const char*, TFolder*)");
1271 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1273 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1275 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1276 fRunLoader->GetEventFolder());
1278 if (!fLoader[iDet]) { // use default loader
1279 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1281 if (!fLoader[iDet]) {
1282 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1283 if (fStopOnError) return NULL;
1285 fRunLoader->AddLoader(fLoader[iDet]);
1286 fRunLoader->CdGAFile();
1287 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1288 fRunLoader->Write(0, TObject::kOverwrite);
1293 return reconstructor;
1296 //_____________________________________________________________________________
1297 Bool_t AliReconstruction::CreateVertexer()
1299 // create the vertexer
1302 AliReconstructor* itsReconstructor = GetReconstructor(0);
1303 if (itsReconstructor) {
1304 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1307 AliWarning("couldn't create a vertexer for ITS");
1308 if (fStopOnError) return kFALSE;
1314 //_____________________________________________________________________________
1315 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1317 // create the trackers
1319 TString detStr = detectors;
1320 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1321 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1322 AliReconstructor* reconstructor = GetReconstructor(iDet);
1323 if (!reconstructor) continue;
1324 TString detName = fgkDetectorName[iDet];
1325 if (detName == "HLT") {
1326 fRunHLTTracking = kTRUE;
1330 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1331 if (!fTracker[iDet] && (iDet < 7)) {
1332 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1333 if (fStopOnError) return kFALSE;
1340 //_____________________________________________________________________________
1341 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1343 // delete trackers and the run loader and close and delete the file
1345 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1346 delete fReconstructor[iDet];
1347 fReconstructor[iDet] = NULL;
1348 fLoader[iDet] = NULL;
1349 delete fTracker[iDet];
1350 fTracker[iDet] = NULL;
1368 gSystem->Unlink("AliESDs.old.root");
1373 //_____________________________________________________________________________
1374 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
1376 // read the ESD event from a file
1378 if (!esd) return kFALSE;
1380 sprintf(fileName, "ESD_%d.%d_%s.root",
1381 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
1382 if (gSystem->AccessPathName(fileName)) return kFALSE;
1384 AliInfo(Form("reading ESD from file %s", fileName));
1385 AliDebug(1, Form("reading ESD from file %s", fileName));
1386 TFile* file = TFile::Open(fileName);
1387 if (!file || !file->IsOpen()) {
1388 AliError(Form("opening %s failed", fileName));
1395 esd = (AliESD*) file->Get("ESD");
1401 //_____________________________________________________________________________
1402 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
1404 // write the ESD event to a file
1408 sprintf(fileName, "ESD_%d.%d_%s.root",
1409 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
1411 AliDebug(1, Form("writing ESD to file %s", fileName));
1412 TFile* file = TFile::Open(fileName, "recreate");
1413 if (!file || !file->IsOpen()) {
1414 AliError(Form("opening %s failed", fileName));
1425 //_____________________________________________________________________________
1426 void AliReconstruction::CreateTag(TFile* file)
1431 Double_t fMUONMASS = 0.105658369;
1434 Double_t fThetaX, fThetaY, fPyz, fChisquare;
1435 Double_t fPxRec,fPyRec, fPzRec, fEnergy;
1437 TLorentzVector fEPvector;
1439 Float_t fZVertexCut = 10.0;
1440 Float_t fRhoVertexCut = 2.0;
1442 Float_t fLowPtCut = 1.0;
1443 Float_t fHighPtCut = 3.0;
1444 Float_t fVeryHighPtCut = 10.0;
1447 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
1449 // Creates the tags for all the events in a given ESD file
1451 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
1452 Int_t nPos, nNeg, nNeutr;
1453 Int_t nK0s, nNeutrons, nPi0s, nGamas;
1454 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
1455 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
1456 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
1457 Float_t maxPt = .0, meanPt = .0, totalP = .0;
1459 TString fVertexName;
1461 AliRunTag *tag = new AliRunTag();
1462 AliEventTag *evTag = new AliEventTag();
1463 TTree ttag("T","A Tree with event tags");
1464 TBranch * btag = ttag.Branch("AliTAG", &tag);
1465 btag->SetCompressionLevel(9);
1467 AliInfo(Form("Creating the tags......."));
1469 if (!file || !file->IsOpen()) {
1470 AliError(Form("opening failed"));
1474 Int_t firstEvent = 0,lastEvent = 0;
1475 TTree *t = (TTree*) file->Get("esdTree");
1476 TBranch * b = t->GetBranch("ESD");
1478 b->SetAddress(&esd);
1480 tag->SetRunId(esd->GetRunNumber());
1482 Int_t iNumberOfEvents = b->GetEntries();
1483 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
1511 b->GetEntry(iEventNumber);
1512 const AliESDVertex * vertexIn = esd->GetVertex();
1513 fVertexName = vertexIn->GetName();
1514 if(fVertexName == "default") fVertexflag = 0;
1515 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
1516 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
1517 UInt_t status = esdTrack->GetStatus();
1519 //select only tracks with ITS refit
1520 if ((status&AliESDtrack::kITSrefit)==0) continue;
1521 //select only tracks with TPC refit
1522 if ((status&AliESDtrack::kTPCrefit)==0) continue;
1524 //select only tracks with the "combined PID"
1525 if ((status&AliESDtrack::kESDpid)==0) continue;
1527 esdTrack->GetPxPyPz(p);
1528 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
1529 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
1532 if(fPt > maxPt) maxPt = fPt;
1534 if(esdTrack->GetSign() > 0) {
1536 if(fPt > fLowPtCut) nCh1GeV++;
1537 if(fPt > fHighPtCut) nCh3GeV++;
1538 if(fPt > fVeryHighPtCut) nCh10GeV++;
1540 if(esdTrack->GetSign() < 0) {
1542 if(fPt > fLowPtCut) nCh1GeV++;
1543 if(fPt > fHighPtCut) nCh3GeV++;
1544 if(fPt > fVeryHighPtCut) nCh10GeV++;
1546 if(esdTrack->GetSign() == 0) nNeutr++;
1550 esdTrack->GetESDpid(prob);
1553 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
1554 if(rcc == 0.0) continue;
1557 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
1560 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
1562 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
1564 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
1566 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
1568 if(fPt > fLowPtCut) nEl1GeV++;
1569 if(fPt > fHighPtCut) nEl3GeV++;
1570 if(fPt > fVeryHighPtCut) nEl10GeV++;
1578 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
1579 // loop over all reconstructed tracks (also first track of combination)
1580 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
1581 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
1582 if (muonTrack == 0x0) continue;
1584 // Coordinates at vertex
1585 fZ = muonTrack->GetZ();
1586 fY = muonTrack->GetBendingCoor();
1587 fX = muonTrack->GetNonBendingCoor();
1589 fThetaX = muonTrack->GetThetaX();
1590 fThetaY = muonTrack->GetThetaY();
1592 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
1593 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
1594 fPxRec = fPzRec * TMath::Tan(fThetaX);
1595 fPyRec = fPzRec * TMath::Tan(fThetaY);
1596 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
1598 //ChiSquare of the track if needed
1599 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
1600 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
1601 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
1603 // total number of muons inside a vertex cut
1604 if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
1606 if(fEPvector.Pt() > fLowPtCut) {
1608 if(fEPvector.Pt() > fHighPtCut) {
1610 if (fEPvector.Pt() > fVeryHighPtCut) {
1618 // Fill the event tags
1620 meanPt = meanPt/ntrack;
1622 evTag->SetEventId(iEventNumber+1);
1623 evTag->SetVertexX(vertexIn->GetXv());
1624 evTag->SetVertexY(vertexIn->GetYv());
1625 evTag->SetVertexZ(vertexIn->GetZv());
1626 evTag->SetVertexZError(vertexIn->GetZRes());
1627 evTag->SetVertexFlag(fVertexflag);
1629 evTag->SetT0VertexZ(esd->GetT0zVertex());
1631 evTag->SetTrigger(esd->GetTrigger());
1633 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
1634 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
1635 evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
1636 evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
1637 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
1638 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
1641 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
1642 evTag->SetNumOfPosTracks(nPos);
1643 evTag->SetNumOfNegTracks(nNeg);
1644 evTag->SetNumOfNeutrTracks(nNeutr);
1646 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
1647 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
1648 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
1649 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
1651 evTag->SetNumOfProtons(nProtons);
1652 evTag->SetNumOfKaons(nKaons);
1653 evTag->SetNumOfPions(nPions);
1654 evTag->SetNumOfMuons(nMuons);
1655 evTag->SetNumOfElectrons(nElectrons);
1656 evTag->SetNumOfPhotons(nGamas);
1657 evTag->SetNumOfPi0s(nPi0s);
1658 evTag->SetNumOfNeutrons(nNeutrons);
1659 evTag->SetNumOfKaon0s(nK0s);
1661 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1662 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1663 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1664 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1665 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1666 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
1667 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
1668 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
1669 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
1671 evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
1672 evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
1674 evTag->SetTotalMomentum(totalP);
1675 evTag->SetMeanPt(meanPt);
1676 evTag->SetMaxPt(maxPt);
1678 tag->AddEventTag(*evTag);
1680 lastEvent = iNumberOfEvents;
1686 sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root",
1687 tag->GetRunId(),firstEvent,lastEvent );
1688 AliInfo(Form("writing tags to file %s", fileName));
1689 AliDebug(1, Form("writing tags to file %s", fileName));
1691 TFile* ftag = TFile::Open(fileName, "recreate");
1700 void AliReconstruction::WriteAlignmentData(AliESD* esd)
1702 // Write space-points which are then used in the alignment procedures
1703 // For the moment only ITS, TRD and TPC
1705 // Load TOF clusters
1707 fLoader[3]->LoadRecPoints("read");
1708 TTree* tree = fLoader[3]->TreeR();
1710 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
1713 fTracker[3]->LoadClusters(tree);
1715 Int_t ntracks = esd->GetNumberOfTracks();
1716 for (Int_t itrack = 0; itrack < ntracks; itrack++)
1718 AliESDtrack *track = esd->GetTrack(itrack);
1721 for (Int_t iDet = 3; iDet >= 0; iDet--)
1722 nsp += track->GetNcls(iDet);
1724 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
1725 track->SetTrackPointArray(sp);
1727 for (Int_t iDet = 3; iDet >= 0; iDet--) {
1728 AliTracker *tracker = fTracker[iDet];
1729 if (!tracker) continue;
1730 Int_t nspdet = track->GetNcls(iDet);
1731 if (nspdet <= 0) continue;
1732 track->GetClusters(iDet,idx);
1736 while (isp < nspdet) {
1737 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
1738 const Int_t kNTPCmax = 159;
1739 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
1740 if (!isvalid) continue;
1741 sp->AddPoint(isptrack,&p); isptrack++; isp++;
1747 fTracker[3]->UnloadClusters();
1748 fLoader[3]->UnloadRecPoints();