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);
267 Int_t cdbRun = AliCDBManager::Instance()->GetRun();
269 AliWarning("AliCDBManager's run number temporarily set to 0!!");
270 AliCDBManager::Instance()->SetRun(0);
276 //_____________________________________________________________________________
277 void AliReconstruction::SetDefaultStorage(const char* uri) {
278 // activate a default CDB storage
280 AliCDBManager::Instance()->SetDefaultStorage(uri);
284 //_____________________________________________________________________________
285 void AliReconstruction::SetSpecificStorage(const char* detName, const char* uri) {
286 // activate a detector-specific CDB storage
288 AliCDBManager::Instance()->SetSpecificStorage(detName, uri);
292 //_____________________________________________________________________________
293 Bool_t AliReconstruction::SetRunNumber()
295 // The method is called in Run() in order
296 // to set a correct run number.
297 // In case of raw data reconstruction the
298 // run number is taken from the raw data header
300 if(AliCDBManager::Instance()->GetRun() < 0) {
302 AliError("No run loader is found !");
305 // read run number from gAlice
306 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
307 AliInfo(Form("Run number: %d",AliCDBManager::Instance()->GetRun()));
312 //_____________________________________________________________________________
313 Bool_t AliReconstruction::ApplyAlignObjsToGeom(TObjArray* alObjArray)
315 // Read collection of alignment objects (AliAlignObj derived) saved
316 // in the TClonesArray ClArrayName and apply them to the geometry
317 // manager singleton.
320 Int_t nvols = alObjArray->GetEntriesFast();
322 for(Int_t j=0; j<nvols; j++)
324 AliAlignObj* alobj = (AliAlignObj*) alObjArray->UncheckedAt(j);
325 if (alobj->ApplyToGeometry() == kFALSE)
329 if (AliDebugLevelClass() >= 1) {
330 gGeoManager->CheckOverlaps(20);
331 TObjArray* ovexlist = gGeoManager->GetListOfOverlaps();
332 if(ovexlist->GetEntriesFast()){
333 AliError("The application of alignment objects to the geometry caused huge overlaps/extrusions!");
341 //_____________________________________________________________________________
342 Bool_t AliReconstruction::SetAlignObjArraySingleDet(const char* detName)
344 // Fills array of single detector's alignable objects from CDB
346 AliDebug(2, Form("Loading alignment data for detector: %s",detName));
350 AliCDBPath path(detName,"Align","Data");
352 entry=AliCDBManager::Instance()->Get(path.GetPath());
354 AliDebug(2,Form("Couldn't load alignment data for detector %s",detName));
358 TClonesArray *alignArray = (TClonesArray*) entry->GetObject();
359 alignArray->SetOwner(0);
360 AliDebug(2,Form("Found %d alignment objects for %s",
361 alignArray->GetEntries(),detName));
363 AliAlignObj *alignObj=0;
364 TIter iter(alignArray);
366 // loop over align objects in detector
367 while( ( alignObj=(AliAlignObj *) iter.Next() ) ){
368 fAlignObjArray->Add(alignObj);
370 // delete entry --- Don't delete, it is cached!
372 AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
377 //_____________________________________________________________________________
378 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
380 // Read the alignment objects from CDB.
381 // Each detector is supposed to have the
382 // alignment objects in DET/Align/Data CDB path.
383 // All the detector objects are then collected,
384 // sorted by geometry level (starting from ALIC) and
385 // then applied to the TGeo geometry.
386 // Finally an overlaps check is performed.
388 // Load alignment data from CDB and fill fAlignObjArray
389 if(fLoadAlignFromCDB){
390 if(!fAlignObjArray) fAlignObjArray = new TObjArray();
392 //fAlignObjArray->RemoveAll();
393 fAlignObjArray->Clear();
394 fAlignObjArray->SetOwner(0);
396 TString detStr = detectors;
397 TString dataNotLoaded="";
398 TString dataLoaded="";
400 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
401 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
402 if(!SetAlignObjArraySingleDet(fgkDetectorName[iDet])){
403 dataNotLoaded += fgkDetectorName[iDet];
404 dataNotLoaded += " ";
406 dataLoaded += fgkDetectorName[iDet];
409 } // end loop over detectors
411 if ((detStr.CompareTo("ALL") == 0)) detStr = "";
412 dataNotLoaded += detStr;
413 AliInfo(Form("Alignment data loaded for: %s",
415 AliInfo(Form("Didn't/couldn't load alignment data for: %s",
416 dataNotLoaded.Data()));
417 } // fLoadAlignFromCDB flag
419 // Check if the array with alignment objects was
420 // provided by the user. If yes, apply the objects
421 // to the present TGeo geometry
422 if (fAlignObjArray) {
423 if (gGeoManager && gGeoManager->IsClosed()) {
424 if (ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
425 AliError("The application of misalignment failed! Restart aliroot and try again. ");
430 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
438 //_____________________________________________________________________________
439 void AliReconstruction::SetGAliceFile(const char* fileName)
441 // set the name of the galice file
443 fGAliceFileName = fileName;
446 //_____________________________________________________________________________
447 void AliReconstruction::SetOption(const char* detector, const char* option)
449 // set options for the reconstruction of a detector
451 TObject* obj = fOptions.FindObject(detector);
452 if (obj) fOptions.Remove(obj);
453 fOptions.Add(new TNamed(detector, option));
457 //_____________________________________________________________________________
458 Bool_t AliReconstruction::Run(const char* input,
459 Int_t firstEvent, Int_t lastEvent)
461 // run the reconstruction
466 if (!input) input = fInput.Data();
467 TString fileName(input);
468 if (fileName.EndsWith("/")) {
469 fRawReader = new AliRawReaderFile(fileName);
470 } else if (fileName.EndsWith(".root")) {
471 fRawReader = new AliRawReaderRoot(fileName);
472 } else if (!fileName.IsNull()) {
473 fRawReader = new AliRawReaderDate(fileName);
474 fRawReader->SelectEvents(7);
477 // get the run loader
478 if (!InitRunLoader()) return kFALSE;
480 // Set run number in CDBManager (if it is not already set by the user)
481 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
483 // Import ideal TGeo geometry and apply misalignment
485 TString geom(gSystem->DirName(fGAliceFileName));
486 geom += "/geometry.root";
487 TGeoManager::Import(geom.Data());
488 if (!gGeoManager) if (fStopOnError) return kFALSE;
490 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
492 // Temporary fix by A.Gheata
493 // Could be removed with the next Root version (>5.11)
495 TIter next(gGeoManager->GetListOfVolumes());
497 while ((vol = (TGeoVolume *)next())) {
498 if (vol->GetVoxels()) {
499 if (vol->GetVoxels()->NeedRebuild()) {
500 vol->GetVoxels()->Voxelize();
507 // local reconstruction
508 if (!fRunLocalReconstruction.IsNull()) {
509 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
510 if (fStopOnError) {CleanUp(); return kFALSE;}
513 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
514 // fFillESD.IsNull()) return kTRUE;
517 if (fRunVertexFinder && !CreateVertexer()) {
525 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
533 TStopwatch stopwatch;
536 // get the possibly already existing ESD file and tree
537 AliESD* esd = new AliESD; AliESD* hltesd = new AliESD;
538 TFile* fileOld = NULL;
539 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
540 if (!gSystem->AccessPathName("AliESDs.root")){
541 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
542 fileOld = TFile::Open("AliESDs.old.root");
543 if (fileOld && fileOld->IsOpen()) {
544 treeOld = (TTree*) fileOld->Get("esdTree");
545 if (treeOld) treeOld->SetBranchAddress("ESD", &esd);
546 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
547 if (hlttreeOld) hlttreeOld->SetBranchAddress("ESD", &hltesd);
551 // create the ESD output file and tree
552 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
553 if (!file->IsOpen()) {
554 AliError("opening AliESDs.root failed");
555 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
557 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
558 tree->Branch("ESD", "AliESD", &esd);
559 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
560 hlttree->Branch("ESD", "AliESD", &hltesd);
561 delete esd; delete hltesd;
562 esd = NULL; hltesd = NULL;
566 if (fRawReader) fRawReader->RewindEvents();
568 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
569 if (fRawReader) fRawReader->NextEvent();
570 if ((iEvent < firstEvent) || ((lastEvent >= 0) && (iEvent > lastEvent))) {
571 // copy old ESD to the new one
573 treeOld->SetBranchAddress("ESD", &esd);
574 treeOld->GetEntry(iEvent);
578 hlttreeOld->SetBranchAddress("ESD", &hltesd);
579 hlttreeOld->GetEntry(iEvent);
585 AliInfo(Form("processing event %d", iEvent));
586 fRunLoader->GetEvent(iEvent);
589 sprintf(fileName, "ESD_%d.%d_final.root",
590 fRunLoader->GetHeader()->GetRun(),
591 fRunLoader->GetHeader()->GetEventNrInRun());
592 if (!gSystem->AccessPathName(fileName)) continue;
594 // local reconstruction
595 if (!fRunLocalReconstruction.IsNull()) {
596 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
597 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
601 esd = new AliESD; hltesd = new AliESD;
602 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
603 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
604 esd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
605 hltesd->SetEventNumber(fRunLoader->GetHeader()->GetEventNrInRun());
607 esd->SetMagneticField(AliTracker::GetBz());
608 hltesd->SetMagneticField(AliTracker::GetBz());
614 if (fRunVertexFinder) {
615 if (!ReadESD(esd, "vertex")) {
616 if (!RunVertexFinder(esd)) {
617 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
619 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
624 if (!fRunTracking.IsNull()) {
625 if (fRunHLTTracking) {
626 hltesd->SetVertex(esd->GetVertex());
627 if (!RunHLTTracking(hltesd)) {
628 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
634 if (!fRunTracking.IsNull()) {
635 if (!ReadESD(esd, "tracking")) {
636 if (!RunTracking(esd)) {
637 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
639 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
644 if (!fFillESD.IsNull()) {
645 if (!FillESD(esd, fFillESD)) {
646 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
651 AliESDpid::MakePID(esd);
652 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
659 if (fCheckPointLevel > 0) WriteESD(esd, "final");
661 delete esd; delete hltesd;
662 esd = NULL; hltesd = NULL;
665 AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
666 stopwatch.RealTime(),stopwatch.CpuTime()));
672 // Create tags for the events in the ESD tree (the ESD tree is always present)
673 // In case of empty events the tags will contain dummy values
675 CleanUp(file, fileOld);
681 //_____________________________________________________________________________
682 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
684 // run the local reconstruction
686 TStopwatch stopwatch;
689 TString detStr = detectors;
690 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
691 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
692 AliReconstructor* reconstructor = GetReconstructor(iDet);
693 if (!reconstructor) continue;
694 if (reconstructor->HasLocalReconstruction()) continue;
696 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
697 TStopwatch stopwatchDet;
698 stopwatchDet.Start();
700 fRawReader->RewindEvents();
701 reconstructor->Reconstruct(fRunLoader, fRawReader);
703 reconstructor->Reconstruct(fRunLoader);
705 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
706 fgkDetectorName[iDet],
707 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
710 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
711 AliError(Form("the following detectors were not found: %s",
713 if (fStopOnError) return kFALSE;
716 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
717 stopwatch.RealTime(),stopwatch.CpuTime()));
722 //_____________________________________________________________________________
723 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
725 // run the local reconstruction
727 TStopwatch stopwatch;
730 TString detStr = detectors;
731 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
732 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
733 AliReconstructor* reconstructor = GetReconstructor(iDet);
734 if (!reconstructor) continue;
735 AliLoader* loader = fLoader[iDet];
737 // conversion of digits
738 if (fRawReader && reconstructor->HasDigitConversion()) {
739 AliInfo(Form("converting raw data digits into root objects for %s",
740 fgkDetectorName[iDet]));
741 TStopwatch stopwatchDet;
742 stopwatchDet.Start();
743 loader->LoadDigits("update");
744 loader->CleanDigits();
745 loader->MakeDigitsContainer();
746 TTree* digitsTree = loader->TreeD();
747 reconstructor->ConvertDigits(fRawReader, digitsTree);
748 loader->WriteDigits("OVERWRITE");
749 loader->UnloadDigits();
750 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
751 fgkDetectorName[iDet],
752 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
755 // local reconstruction
756 if (!reconstructor->HasLocalReconstruction()) continue;
757 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
758 TStopwatch stopwatchDet;
759 stopwatchDet.Start();
760 loader->LoadRecPoints("update");
761 loader->CleanRecPoints();
762 loader->MakeRecPointsContainer();
763 TTree* clustersTree = loader->TreeR();
764 if (fRawReader && !reconstructor->HasDigitConversion()) {
765 reconstructor->Reconstruct(fRawReader, clustersTree);
767 loader->LoadDigits("read");
768 TTree* digitsTree = loader->TreeD();
770 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
771 if (fStopOnError) return kFALSE;
773 reconstructor->Reconstruct(digitsTree, clustersTree);
775 loader->UnloadDigits();
777 loader->WriteRecPoints("OVERWRITE");
778 loader->UnloadRecPoints();
779 AliDebug(1,Form("Execution time for %s: R:%.2fs C:%.2fs",
780 fgkDetectorName[iDet],
781 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
784 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
785 AliError(Form("the following detectors were not found: %s",
787 if (fStopOnError) return kFALSE;
790 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
791 stopwatch.RealTime(),stopwatch.CpuTime()));
796 //_____________________________________________________________________________
797 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
799 // run the barrel tracking
801 TStopwatch stopwatch;
804 AliESDVertex* vertex = NULL;
805 Double_t vtxPos[3] = {0, 0, 0};
806 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
808 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
809 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
810 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
814 AliInfo("running the ITS vertex finder");
815 if (fLoader[0]) fLoader[0]->LoadRecPoints();
816 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
817 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
819 AliWarning("Vertex not found");
820 vertex = new AliESDVertex();
821 vertex->SetName("default");
824 vertex->SetTruePos(vtxPos); // store also the vertex from MC
825 vertex->SetName("reconstructed");
829 AliInfo("getting the primary vertex from MC");
830 vertex = new AliESDVertex(vtxPos, vtxErr);
834 vertex->GetXYZ(vtxPos);
835 vertex->GetSigmaXYZ(vtxErr);
837 AliWarning("no vertex reconstructed");
838 vertex = new AliESDVertex(vtxPos, vtxErr);
840 esd->SetVertex(vertex);
841 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
842 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
846 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
847 stopwatch.RealTime(),stopwatch.CpuTime()));
852 //_____________________________________________________________________________
853 Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
855 // run the HLT barrel tracking
857 TStopwatch stopwatch;
861 AliError("Missing runLoader!");
865 AliInfo("running HLT tracking");
867 // Get a pointer to the HLT reconstructor
868 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
869 if (!reconstructor) return kFALSE;
872 for (Int_t iDet = 1; iDet >= 0; iDet--) {
873 TString detName = fgkDetectorName[iDet];
874 AliDebug(1, Form("%s HLT tracking", detName.Data()));
875 reconstructor->SetOption(detName.Data());
876 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
878 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
879 if (fStopOnError) return kFALSE;
883 Double_t vtxErr[3]={0.005,0.005,0.010};
884 const AliESDVertex *vertex = esd->GetVertex();
885 vertex->GetXYZ(vtxPos);
886 tracker->SetVertex(vtxPos,vtxErr);
888 fLoader[iDet]->LoadRecPoints("read");
889 TTree* tree = fLoader[iDet]->TreeR();
891 AliError(Form("Can't get the %s cluster tree", detName.Data()));
894 tracker->LoadClusters(tree);
896 if (tracker->Clusters2Tracks(esd) != 0) {
897 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
901 tracker->UnloadClusters();
906 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
907 stopwatch.RealTime(),stopwatch.CpuTime()));
912 //_____________________________________________________________________________
913 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
915 // run the barrel tracking
917 TStopwatch stopwatch;
920 AliInfo("running tracking");
922 // pass 1: TPC + ITS inwards
923 for (Int_t iDet = 1; iDet >= 0; iDet--) {
924 if (!fTracker[iDet]) continue;
925 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
928 fLoader[iDet]->LoadRecPoints("read");
929 TTree* tree = fLoader[iDet]->TreeR();
931 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
934 fTracker[iDet]->LoadClusters(tree);
937 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
938 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
941 if (fCheckPointLevel > 1) {
942 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
944 // preliminary PID in TPC needed by the ITS tracker
946 GetReconstructor(1)->FillESD(fRunLoader, esd);
947 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
948 AliESDpid::MakePID(esd);
952 // pass 2: ALL backwards
953 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
954 if (!fTracker[iDet]) continue;
955 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
958 if (iDet > 1) { // all except ITS, TPC
960 fLoader[iDet]->LoadRecPoints("read");
961 tree = fLoader[iDet]->TreeR();
963 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
966 fTracker[iDet]->LoadClusters(tree);
970 if (fTracker[iDet]->PropagateBack(esd) != 0) {
971 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
974 if (fCheckPointLevel > 1) {
975 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
979 if (iDet > 2) { // all except ITS, TPC, TRD
980 fTracker[iDet]->UnloadClusters();
981 fLoader[iDet]->UnloadRecPoints();
983 // updated PID in TPC needed by the ITS tracker -MI
985 GetReconstructor(1)->FillESD(fRunLoader, esd);
986 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
987 AliESDpid::MakePID(esd);
991 // write space-points to the ESD in case alignment data output
993 if (fWriteAlignmentData)
994 WriteAlignmentData(esd);
996 // pass 3: TRD + TPC + ITS refit inwards
997 for (Int_t iDet = 2; iDet >= 0; iDet--) {
998 if (!fTracker[iDet]) continue;
999 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1002 if (fTracker[iDet]->RefitInward(esd) != 0) {
1003 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1006 if (fCheckPointLevel > 1) {
1007 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1011 fTracker[iDet]->UnloadClusters();
1012 fLoader[iDet]->UnloadRecPoints();
1015 // Propagate track to the vertex - if not done by ITS
1017 Int_t ntracks = esd->GetNumberOfTracks();
1018 for (Int_t itrack=0; itrack<ntracks; itrack++){
1019 const Double_t kRadius = 3; // beam pipe radius
1020 const Double_t kMaxStep = 5; // max step
1021 const Double_t kMaxD = 123456; // max distance to prim vertex
1022 Double_t fieldZ = AliTracker::GetBz(); //
1023 AliESDtrack * track = esd->GetTrack(itrack);
1024 if (!track) continue;
1025 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1026 track->PropagateTo(kRadius, track->GetMass(),kMaxStep,kTRUE);
1027 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1030 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1031 stopwatch.RealTime(),stopwatch.CpuTime()));
1036 //_____________________________________________________________________________
1037 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
1039 // fill the event summary data
1041 TStopwatch stopwatch;
1043 AliInfo("filling ESD");
1045 TString detStr = detectors;
1046 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1047 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1048 AliReconstructor* reconstructor = GetReconstructor(iDet);
1049 if (!reconstructor) continue;
1051 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1052 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1053 TTree* clustersTree = NULL;
1054 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1055 fLoader[iDet]->LoadRecPoints("read");
1056 clustersTree = fLoader[iDet]->TreeR();
1057 if (!clustersTree) {
1058 AliError(Form("Can't get the %s clusters tree",
1059 fgkDetectorName[iDet]));
1060 if (fStopOnError) return kFALSE;
1063 if (fRawReader && !reconstructor->HasDigitConversion()) {
1064 reconstructor->FillESD(fRawReader, clustersTree, esd);
1066 TTree* digitsTree = NULL;
1067 if (fLoader[iDet]) {
1068 fLoader[iDet]->LoadDigits("read");
1069 digitsTree = fLoader[iDet]->TreeD();
1071 AliError(Form("Can't get the %s digits tree",
1072 fgkDetectorName[iDet]));
1073 if (fStopOnError) return kFALSE;
1076 reconstructor->FillESD(digitsTree, clustersTree, esd);
1077 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1079 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1080 fLoader[iDet]->UnloadRecPoints();
1084 reconstructor->FillESD(fRunLoader, fRawReader, esd);
1086 reconstructor->FillESD(fRunLoader, esd);
1088 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1092 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1093 AliError(Form("the following detectors were not found: %s",
1095 if (fStopOnError) return kFALSE;
1098 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1099 stopwatch.RealTime(),stopwatch.CpuTime()));
1105 //_____________________________________________________________________________
1106 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1108 // check whether detName is contained in detectors
1109 // if yes, it is removed from detectors
1111 // check if all detectors are selected
1112 if ((detectors.CompareTo("ALL") == 0) ||
1113 detectors.BeginsWith("ALL ") ||
1114 detectors.EndsWith(" ALL") ||
1115 detectors.Contains(" ALL ")) {
1120 // search for the given detector
1121 Bool_t result = kFALSE;
1122 if ((detectors.CompareTo(detName) == 0) ||
1123 detectors.BeginsWith(detName+" ") ||
1124 detectors.EndsWith(" "+detName) ||
1125 detectors.Contains(" "+detName+" ")) {
1126 detectors.ReplaceAll(detName, "");
1130 // clean up the detectors string
1131 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1132 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1133 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1138 //_____________________________________________________________________________
1139 Bool_t AliReconstruction::InitRunLoader()
1141 // get or create the run loader
1143 if (gAlice) delete gAlice;
1146 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1147 // load all base libraries to get the loader classes
1148 TString libs = gSystem->GetLibraries();
1149 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1150 TString detName = fgkDetectorName[iDet];
1151 if (detName == "HLT") continue;
1152 if (libs.Contains("lib" + detName + "base.so")) continue;
1153 gSystem->Load("lib" + detName + "base.so");
1155 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1157 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1161 fRunLoader->CdGAFile();
1162 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1163 if (fRunLoader->LoadgAlice() == 0) {
1164 gAlice = fRunLoader->GetAliRun();
1165 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1168 if (!gAlice && !fRawReader) {
1169 AliError(Form("no gAlice object found in file %s",
1170 fGAliceFileName.Data()));
1175 } else { // galice.root does not exist
1177 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1181 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1182 AliConfig::GetDefaultEventFolderName(),
1185 AliError(Form("could not create run loader in file %s",
1186 fGAliceFileName.Data()));
1190 fRunLoader->MakeTree("E");
1192 while (fRawReader->NextEvent()) {
1193 fRunLoader->SetEventNumber(iEvent);
1194 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1196 fRunLoader->MakeTree("H");
1197 fRunLoader->TreeE()->Fill();
1200 fRawReader->RewindEvents();
1201 fRunLoader->WriteHeader("OVERWRITE");
1202 fRunLoader->CdGAFile();
1203 fRunLoader->Write(0, TObject::kOverwrite);
1204 // AliTracker::SetFieldMap(???);
1210 //_____________________________________________________________________________
1211 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1213 // get the reconstructor object and the loader for a detector
1215 if (fReconstructor[iDet]) return fReconstructor[iDet];
1217 // load the reconstructor object
1218 TPluginManager* pluginManager = gROOT->GetPluginManager();
1219 TString detName = fgkDetectorName[iDet];
1220 TString recName = "Ali" + detName + "Reconstructor";
1221 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1223 if (detName == "HLT") {
1224 if (!gROOT->GetClass("AliLevel3")) {
1225 gSystem->Load("libAliL3Src.so");
1226 gSystem->Load("libAliL3Misc.so");
1227 gSystem->Load("libAliL3Hough.so");
1228 gSystem->Load("libAliL3Comp.so");
1232 AliReconstructor* reconstructor = NULL;
1233 // first check if a plugin is defined for the reconstructor
1234 TPluginHandler* pluginHandler =
1235 pluginManager->FindHandler("AliReconstructor", detName);
1236 // if not, add a plugin for it
1237 if (!pluginHandler) {
1238 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1239 TString libs = gSystem->GetLibraries();
1240 if (libs.Contains("lib" + detName + "base.so") ||
1241 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1242 pluginManager->AddHandler("AliReconstructor", detName,
1243 recName, detName + "rec", recName + "()");
1245 pluginManager->AddHandler("AliReconstructor", detName,
1246 recName, detName, recName + "()");
1248 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1250 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1251 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1253 if (reconstructor) {
1254 TObject* obj = fOptions.FindObject(detName.Data());
1255 if (obj) reconstructor->SetOption(obj->GetTitle());
1256 reconstructor->Init(fRunLoader);
1257 fReconstructor[iDet] = reconstructor;
1260 // get or create the loader
1261 if (detName != "HLT") {
1262 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1263 if (!fLoader[iDet]) {
1264 AliConfig::Instance()
1265 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1267 // first check if a plugin is defined for the loader
1268 TPluginHandler* pluginHandler =
1269 pluginManager->FindHandler("AliLoader", detName);
1270 // if not, add a plugin for it
1271 if (!pluginHandler) {
1272 TString loaderName = "Ali" + detName + "Loader";
1273 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1274 pluginManager->AddHandler("AliLoader", detName,
1275 loaderName, detName + "base",
1276 loaderName + "(const char*, TFolder*)");
1277 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1279 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1281 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1282 fRunLoader->GetEventFolder());
1284 if (!fLoader[iDet]) { // use default loader
1285 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1287 if (!fLoader[iDet]) {
1288 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1289 if (fStopOnError) return NULL;
1291 fRunLoader->AddLoader(fLoader[iDet]);
1292 fRunLoader->CdGAFile();
1293 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1294 fRunLoader->Write(0, TObject::kOverwrite);
1299 return reconstructor;
1302 //_____________________________________________________________________________
1303 Bool_t AliReconstruction::CreateVertexer()
1305 // create the vertexer
1308 AliReconstructor* itsReconstructor = GetReconstructor(0);
1309 if (itsReconstructor) {
1310 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1313 AliWarning("couldn't create a vertexer for ITS");
1314 if (fStopOnError) return kFALSE;
1320 //_____________________________________________________________________________
1321 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1323 // create the trackers
1325 TString detStr = detectors;
1326 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1327 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1328 AliReconstructor* reconstructor = GetReconstructor(iDet);
1329 if (!reconstructor) continue;
1330 TString detName = fgkDetectorName[iDet];
1331 if (detName == "HLT") {
1332 fRunHLTTracking = kTRUE;
1336 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1337 if (!fTracker[iDet] && (iDet < 7)) {
1338 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1339 if (fStopOnError) return kFALSE;
1346 //_____________________________________________________________________________
1347 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1349 // delete trackers and the run loader and close and delete the file
1351 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1352 delete fReconstructor[iDet];
1353 fReconstructor[iDet] = NULL;
1354 fLoader[iDet] = NULL;
1355 delete fTracker[iDet];
1356 fTracker[iDet] = NULL;
1374 gSystem->Unlink("AliESDs.old.root");
1379 //_____________________________________________________________________________
1380 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
1382 // read the ESD event from a file
1384 if (!esd) return kFALSE;
1386 sprintf(fileName, "ESD_%d.%d_%s.root",
1387 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
1388 if (gSystem->AccessPathName(fileName)) return kFALSE;
1390 AliInfo(Form("reading ESD from file %s", fileName));
1391 AliDebug(1, Form("reading ESD from file %s", fileName));
1392 TFile* file = TFile::Open(fileName);
1393 if (!file || !file->IsOpen()) {
1394 AliError(Form("opening %s failed", fileName));
1401 esd = (AliESD*) file->Get("ESD");
1407 //_____________________________________________________________________________
1408 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
1410 // write the ESD event to a file
1414 sprintf(fileName, "ESD_%d.%d_%s.root",
1415 esd->GetRunNumber(), esd->GetEventNumber(), recStep);
1417 AliDebug(1, Form("writing ESD to file %s", fileName));
1418 TFile* file = TFile::Open(fileName, "recreate");
1419 if (!file || !file->IsOpen()) {
1420 AliError(Form("opening %s failed", fileName));
1431 //_____________________________________________________________________________
1432 void AliReconstruction::CreateTag(TFile* file)
1437 Double_t fMUONMASS = 0.105658369;
1440 Double_t fThetaX, fThetaY, fPyz, fChisquare;
1441 Double_t fPxRec,fPyRec, fPzRec, fEnergy;
1443 TLorentzVector fEPvector;
1445 Float_t fZVertexCut = 10.0;
1446 Float_t fRhoVertexCut = 2.0;
1448 Float_t fLowPtCut = 1.0;
1449 Float_t fHighPtCut = 3.0;
1450 Float_t fVeryHighPtCut = 10.0;
1453 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
1455 // Creates the tags for all the events in a given ESD file
1457 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
1458 Int_t nPos, nNeg, nNeutr;
1459 Int_t nK0s, nNeutrons, nPi0s, nGamas;
1460 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
1461 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
1462 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
1463 Float_t maxPt = .0, meanPt = .0, totalP = .0;
1465 TString fVertexName;
1467 AliRunTag *tag = new AliRunTag();
1468 AliEventTag *evTag = new AliEventTag();
1469 TTree ttag("T","A Tree with event tags");
1470 TBranch * btag = ttag.Branch("AliTAG", &tag);
1471 btag->SetCompressionLevel(9);
1473 AliInfo(Form("Creating the tags......."));
1475 if (!file || !file->IsOpen()) {
1476 AliError(Form("opening failed"));
1480 Int_t firstEvent = 0,lastEvent = 0;
1481 TTree *t = (TTree*) file->Get("esdTree");
1482 TBranch * b = t->GetBranch("ESD");
1484 b->SetAddress(&esd);
1486 tag->SetRunId(esd->GetRunNumber());
1488 Int_t iNumberOfEvents = b->GetEntries();
1489 for (Int_t iEventNumber = 0; iEventNumber < iNumberOfEvents; iEventNumber++) {
1517 b->GetEntry(iEventNumber);
1518 const AliESDVertex * vertexIn = esd->GetVertex();
1519 fVertexName = vertexIn->GetName();
1520 if(fVertexName == "default") fVertexflag = 0;
1521 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
1522 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
1523 UInt_t status = esdTrack->GetStatus();
1525 //select only tracks with ITS refit
1526 if ((status&AliESDtrack::kITSrefit)==0) continue;
1527 //select only tracks with TPC refit
1528 if ((status&AliESDtrack::kTPCrefit)==0) continue;
1530 //select only tracks with the "combined PID"
1531 if ((status&AliESDtrack::kESDpid)==0) continue;
1533 esdTrack->GetPxPyPz(p);
1534 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
1535 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
1538 if(fPt > maxPt) maxPt = fPt;
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) {
1548 if(fPt > fLowPtCut) nCh1GeV++;
1549 if(fPt > fHighPtCut) nCh3GeV++;
1550 if(fPt > fVeryHighPtCut) nCh10GeV++;
1552 if(esdTrack->GetSign() == 0) nNeutr++;
1556 esdTrack->GetESDpid(prob);
1559 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
1560 if(rcc == 0.0) continue;
1563 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
1566 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
1568 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
1570 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
1572 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
1574 if(fPt > fLowPtCut) nEl1GeV++;
1575 if(fPt > fHighPtCut) nEl3GeV++;
1576 if(fPt > fVeryHighPtCut) nEl10GeV++;
1584 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
1585 // loop over all reconstructed tracks (also first track of combination)
1586 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
1587 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
1588 if (muonTrack == 0x0) continue;
1590 // Coordinates at vertex
1591 fZ = muonTrack->GetZ();
1592 fY = muonTrack->GetBendingCoor();
1593 fX = muonTrack->GetNonBendingCoor();
1595 fThetaX = muonTrack->GetThetaX();
1596 fThetaY = muonTrack->GetThetaY();
1598 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
1599 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
1600 fPxRec = fPzRec * TMath::Tan(fThetaX);
1601 fPyRec = fPzRec * TMath::Tan(fThetaY);
1602 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
1604 //ChiSquare of the track if needed
1605 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
1606 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
1607 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
1609 // total number of muons inside a vertex cut
1610 if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
1612 if(fEPvector.Pt() > fLowPtCut) {
1614 if(fEPvector.Pt() > fHighPtCut) {
1616 if (fEPvector.Pt() > fVeryHighPtCut) {
1624 // Fill the event tags
1626 meanPt = meanPt/ntrack;
1628 evTag->SetEventId(iEventNumber+1);
1629 evTag->SetVertexX(vertexIn->GetXv());
1630 evTag->SetVertexY(vertexIn->GetYv());
1631 evTag->SetVertexZ(vertexIn->GetZv());
1632 evTag->SetVertexZError(vertexIn->GetZRes());
1633 evTag->SetVertexFlag(fVertexflag);
1635 evTag->SetT0VertexZ(esd->GetT0zVertex());
1637 evTag->SetTrigger(esd->GetTrigger());
1639 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
1640 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
1641 evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
1642 evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
1643 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
1644 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
1647 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
1648 evTag->SetNumOfPosTracks(nPos);
1649 evTag->SetNumOfNegTracks(nNeg);
1650 evTag->SetNumOfNeutrTracks(nNeutr);
1652 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
1653 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
1654 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
1655 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
1657 evTag->SetNumOfProtons(nProtons);
1658 evTag->SetNumOfKaons(nKaons);
1659 evTag->SetNumOfPions(nPions);
1660 evTag->SetNumOfMuons(nMuons);
1661 evTag->SetNumOfElectrons(nElectrons);
1662 evTag->SetNumOfPhotons(nGamas);
1663 evTag->SetNumOfPi0s(nPi0s);
1664 evTag->SetNumOfNeutrons(nNeutrons);
1665 evTag->SetNumOfKaon0s(nK0s);
1667 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1668 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1669 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1670 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1671 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1672 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
1673 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
1674 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
1675 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
1677 evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
1678 evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
1680 evTag->SetTotalMomentum(totalP);
1681 evTag->SetMeanPt(meanPt);
1682 evTag->SetMaxPt(maxPt);
1684 tag->AddEventTag(*evTag);
1686 lastEvent = iNumberOfEvents;
1692 sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root",
1693 tag->GetRunId(),firstEvent,lastEvent );
1694 AliInfo(Form("writing tags to file %s", fileName));
1695 AliDebug(1, Form("writing tags to file %s", fileName));
1697 TFile* ftag = TFile::Open(fileName, "recreate");
1706 void AliReconstruction::WriteAlignmentData(AliESD* esd)
1708 // Write space-points which are then used in the alignment procedures
1709 // For the moment only ITS, TRD and TPC
1711 // Load TOF clusters
1713 fLoader[3]->LoadRecPoints("read");
1714 TTree* tree = fLoader[3]->TreeR();
1716 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
1719 fTracker[3]->LoadClusters(tree);
1721 Int_t ntracks = esd->GetNumberOfTracks();
1722 for (Int_t itrack = 0; itrack < ntracks; itrack++)
1724 AliESDtrack *track = esd->GetTrack(itrack);
1727 for (Int_t iDet = 3; iDet >= 0; iDet--)
1728 nsp += track->GetNcls(iDet);
1730 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
1731 track->SetTrackPointArray(sp);
1733 for (Int_t iDet = 3; iDet >= 0; iDet--) {
1734 AliTracker *tracker = fTracker[iDet];
1735 if (!tracker) continue;
1736 Int_t nspdet = track->GetNcls(iDet);
1737 if (nspdet <= 0) continue;
1738 track->GetClusters(iDet,idx);
1742 while (isp < nspdet) {
1743 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
1744 const Int_t kNTPCmax = 159;
1745 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
1746 if (!isvalid) continue;
1747 sp->AddPoint(isptrack,&p); isptrack++; isp++;
1753 fTracker[3]->UnloadClusters();
1754 fLoader[3]->UnloadRecPoints();