1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for running the reconstruction //
22 // Clusters and tracks are created for all detectors and all events by //
25 // AliReconstruction rec; //
28 // The Run method returns kTRUE in case of successful execution. //
30 // If the input to the reconstruction are not simulated digits but raw data, //
31 // this can be specified by an argument of the Run method or by the method //
33 // rec.SetInput("..."); //
35 // The input formats and the corresponding argument are: //
36 // - DDL raw data files: directory name, ends with "/" //
37 // - raw data root file: root file name, extension ".root" //
38 // - raw data DATE file: DATE file name, any other non-empty string //
39 // - MC root files : empty string, default //
41 // By default all events are reconstructed. The reconstruction can be //
42 // limited to a range of events by giving the index of the first and the //
43 // last event as an argument to the Run method or by calling //
45 // rec.SetEventRange(..., ...); //
47 // The index -1 (default) can be used for the last event to indicate no //
48 // upper limit of the event range. //
50 // In case of raw-data reconstruction the user can modify the default //
51 // number of events per digits/clusters/tracks file. In case the option //
52 // is not used the number is set 1. In case the user provides 0, than //
53 // the number of events is equal to the number of events inside the //
54 // raw-data file (i.e. one digits/clusters/tracks file): //
56 // rec.SetNumberOfEventsPerFile(...); //
59 // The name of the galice file can be changed from the default //
60 // "galice.root" by passing it as argument to the AliReconstruction //
61 // constructor or by //
63 // rec.SetGAliceFile("..."); //
65 // The local reconstruction can be switched on or off for individual //
68 // rec.SetRunLocalReconstruction("..."); //
70 // The argument is a (case sensitive) string with the names of the //
71 // detectors separated by a space. The special string "ALL" selects all //
72 // available detectors. This is the default. //
74 // The reconstruction of the primary vertex position can be switched off by //
76 // rec.SetRunVertexFinder(kFALSE); //
78 // The tracking and the creation of ESD tracks can be switched on for //
79 // selected detectors by //
81 // rec.SetRunTracking("..."); //
83 // Uniform/nonuniform field tracking switches (default: uniform field) //
85 // rec.SetUniformFieldTracking(); ( rec.SetUniformFieldTracking(kFALSE); ) //
87 // The filling of additional ESD information can be steered by //
89 // rec.SetFillESD("..."); //
91 // Again, for both methods the string specifies the list of detectors. //
92 // The default is "ALL". //
94 // The call of the shortcut method //
96 // rec.SetRunReconstruction("..."); //
98 // is equivalent to calling SetRunLocalReconstruction, SetRunTracking and //
99 // SetFillESD with the same detector selecting string as argument. //
101 // The reconstruction requires digits or raw data as input. For the creation //
102 // of digits and raw data have a look at the class AliSimulation. //
104 // For debug purposes the method SetCheckPointLevel can be used. If the //
105 // argument is greater than 0, files with ESD events will be written after //
106 // selected steps of the reconstruction for each event: //
107 // level 1: after tracking and after filling of ESD (final) //
108 // level 2: in addition after each tracking step //
109 // level 3: in addition after the filling of ESD for each detector //
110 // If a final check point file exists for an event, this event will be //
111 // skipped in the reconstruction. The tracking and the filling of ESD for //
112 // a detector will be skipped as well, if the corresponding check point //
113 // file exists. The ESD event will then be loaded from the file instead. //
115 ///////////////////////////////////////////////////////////////////////////////
121 #include <TPluginManager.h>
122 #include <TStopwatch.h>
123 #include <TGeoManager.h>
124 #include <TLorentzVector.h>
126 #include "AliReconstruction.h"
127 #include "AliReconstructor.h"
129 #include "AliRunLoader.h"
131 #include "AliRawReaderFile.h"
132 #include "AliRawReaderDate.h"
133 #include "AliRawReaderRoot.h"
134 #include "AliRawEventHeaderBase.h"
136 #include "AliESDfriend.h"
137 #include "AliESDVertex.h"
138 #include "AliMultiplicity.h"
139 #include "AliTracker.h"
140 #include "AliVertexer.h"
141 #include "AliVertexerTracks.h"
142 #include "AliV0vertexer.h"
143 #include "AliCascadeVertexer.h"
144 #include "AliHeader.h"
145 #include "AliGenEventHeader.h"
147 #include "AliESDpid.h"
148 #include "AliESDtrack.h"
150 #include "AliRunTag.h"
151 #include "AliDetectorTag.h"
152 #include "AliEventTag.h"
154 #include "AliTrackPointArray.h"
155 #include "AliCDBManager.h"
156 #include "AliCDBEntry.h"
157 #include "AliAlignObj.h"
159 #include "AliCentralTrigger.h"
160 #include "AliCTPRawStream.h"
162 ClassImp(AliReconstruction)
165 //_____________________________________________________________________________
166 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
168 //_____________________________________________________________________________
169 AliReconstruction::AliReconstruction(const char* gAliceFilename, const char* cdbUri,
170 const char* name, const char* title) :
173 fUniformField(kTRUE),
174 fRunVertexFinder(kTRUE),
175 fRunHLTTracking(kFALSE),
176 fRunMuonTracking(kFALSE),
177 fStopOnError(kFALSE),
178 fWriteAlignmentData(kFALSE),
179 fWriteESDfriend(kFALSE),
181 fFillTriggerESD(kTRUE),
183 fRunLocalReconstruction("ALL"),
186 fGAliceFileName(gAliceFilename),
191 fNumberOfEventsPerFile(1),
194 fLoadAlignFromCDB(kTRUE),
195 fLoadAlignData("ALL"),
201 fDiamondProfile(NULL),
203 fAlignObjArray(NULL),
207 // create reconstruction object with default parameters
209 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
210 fReconstructor[iDet] = NULL;
211 fLoader[iDet] = NULL;
212 fTracker[iDet] = NULL;
217 //_____________________________________________________________________________
218 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
221 fUniformField(rec.fUniformField),
222 fRunVertexFinder(rec.fRunVertexFinder),
223 fRunHLTTracking(rec.fRunHLTTracking),
224 fRunMuonTracking(rec.fRunMuonTracking),
225 fStopOnError(rec.fStopOnError),
226 fWriteAlignmentData(rec.fWriteAlignmentData),
227 fWriteESDfriend(rec.fWriteESDfriend),
228 fWriteAOD(rec.fWriteAOD),
229 fFillTriggerESD(rec.fFillTriggerESD),
231 fRunLocalReconstruction(rec.fRunLocalReconstruction),
232 fRunTracking(rec.fRunTracking),
233 fFillESD(rec.fFillESD),
234 fGAliceFileName(rec.fGAliceFileName),
236 fEquipIdMap(rec.fEquipIdMap),
237 fFirstEvent(rec.fFirstEvent),
238 fLastEvent(rec.fLastEvent),
239 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
242 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
243 fLoadAlignData(rec.fLoadAlignData),
249 fDiamondProfile(NULL),
251 fAlignObjArray(rec.fAlignObjArray),
252 fCDBUri(rec.fCDBUri),
257 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
258 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
260 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
261 fReconstructor[iDet] = NULL;
262 fLoader[iDet] = NULL;
263 fTracker[iDet] = NULL;
265 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
266 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
270 //_____________________________________________________________________________
271 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
273 // assignment operator
275 this->~AliReconstruction();
276 new(this) AliReconstruction(rec);
280 //_____________________________________________________________________________
281 AliReconstruction::~AliReconstruction()
287 fSpecCDBUri.Delete();
290 //_____________________________________________________________________________
291 void AliReconstruction::InitCDBStorage()
293 // activate a default CDB storage
294 // First check if we have any CDB storage set, because it is used
295 // to retrieve the calibration and alignment constants
297 AliCDBManager* man = AliCDBManager::Instance();
298 if (man->IsDefaultStorageSet())
300 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
301 AliWarning("Default CDB storage has been already set !");
302 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
303 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
307 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
308 AliDebug(2, Form("Default CDB storage is set to: %s",fCDBUri.Data()));
309 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
310 man->SetDefaultStorage(fCDBUri);
313 // Now activate the detector specific CDB storage locations
314 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
315 TObject* obj = fSpecCDBUri[i];
317 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
318 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
319 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
320 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
325 //_____________________________________________________________________________
326 void AliReconstruction::SetDefaultStorage(const char* uri) {
327 // Store the desired default CDB storage location
328 // Activate it later within the Run() method
334 //_____________________________________________________________________________
335 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
336 // Store a detector-specific CDB storage location
337 // Activate it later within the Run() method
339 AliCDBPath aPath(calibType);
340 if(!aPath.IsValid()){
341 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
342 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
343 if(!strcmp(calibType, fgkDetectorName[iDet])) {
344 aPath.SetPath(Form("%s/*", calibType));
345 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
349 if(!aPath.IsValid()){
350 AliError(Form("Not a valid path or detector: %s", calibType));
355 // check that calibType refers to a "valid" detector name
356 Bool_t isDetector = kFALSE;
357 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
358 TString detName = fgkDetectorName[iDet];
359 if(aPath.GetLevel0() == detName) {
366 AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
370 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
371 if (obj) fSpecCDBUri.Remove(obj);
372 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
376 //_____________________________________________________________________________
377 Bool_t AliReconstruction::SetRunNumber()
379 // The method is called in Run() in order
380 // to set a correct run number.
381 // In case of raw data reconstruction the
382 // run number is taken from the raw data header
384 if(AliCDBManager::Instance()->GetRun() < 0) {
386 AliError("No run loader is found !");
389 // read run number from gAlice
390 if(fRunLoader->GetAliRun())
391 AliCDBManager::Instance()->SetRun(fRunLoader->GetAliRun()->GetRunNumber());
394 if(fRawReader->NextEvent()) {
395 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
396 fRawReader->RewindEvents();
399 AliError("No raw-data events found !");
404 AliError("Neither gAlice nor RawReader objects are found !");
408 AliInfo(Form("CDB Run number: %d",AliCDBManager::Instance()->GetRun()));
413 //_____________________________________________________________________________
414 Bool_t AliReconstruction::ApplyAlignObjsToGeom(TObjArray* alObjArray)
416 // Read collection of alignment objects (AliAlignObj derived) saved
417 // in the TClonesArray ClArrayName and apply them to the geometry
418 // manager singleton.
421 Int_t nvols = alObjArray->GetEntriesFast();
425 for(Int_t j=0; j<nvols; j++)
427 AliAlignObj* alobj = (AliAlignObj*) alObjArray->UncheckedAt(j);
428 if (alobj->ApplyToGeometry() == kFALSE) flag = kFALSE;
431 if (AliDebugLevelClass() >= 1) {
432 gGeoManager->GetTopNode()->CheckOverlaps(20);
433 TObjArray* ovexlist = gGeoManager->GetListOfOverlaps();
434 if(ovexlist->GetEntriesFast()){
435 AliError("The application of alignment objects to the geometry caused huge overlaps/extrusions!");
443 //_____________________________________________________________________________
444 Bool_t AliReconstruction::SetAlignObjArraySingleDet(const char* detName)
446 // Fills array of single detector's alignable objects from CDB
448 AliDebug(2, Form("Loading alignment data for detector: %s",detName));
452 AliCDBPath path(detName,"Align","Data");
454 entry=AliCDBManager::Instance()->Get(path.GetPath());
456 AliDebug(2,Form("Couldn't load alignment data for detector %s",detName));
460 TClonesArray *alignArray = (TClonesArray*) entry->GetObject();
461 alignArray->SetOwner(0);
462 AliDebug(2,Form("Found %d alignment objects for %s",
463 alignArray->GetEntries(),detName));
465 AliAlignObj *alignObj=0;
466 TIter iter(alignArray);
468 // loop over align objects in detector
469 while( ( alignObj=(AliAlignObj *) iter.Next() ) ){
470 fAlignObjArray->Add(alignObj);
472 // delete entry --- Don't delete, it is cached!
474 AliDebug(2, Form("fAlignObjArray entries: %d",fAlignObjArray->GetEntries() ));
479 //_____________________________________________________________________________
480 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
482 // Read the alignment objects from CDB.
483 // Each detector is supposed to have the
484 // alignment objects in DET/Align/Data CDB path.
485 // All the detector objects are then collected,
486 // sorted by geometry level (starting from ALIC) and
487 // then applied to the TGeo geometry.
488 // Finally an overlaps check is performed.
490 // Load alignment data from CDB and fill fAlignObjArray
491 if(fLoadAlignFromCDB){
492 if(!fAlignObjArray) fAlignObjArray = new TObjArray();
494 //fAlignObjArray->RemoveAll();
495 fAlignObjArray->Clear();
496 fAlignObjArray->SetOwner(0);
498 TString detStr = detectors;
499 TString dataNotLoaded="";
500 TString dataLoaded="";
502 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
503 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
504 if(!SetAlignObjArraySingleDet(fgkDetectorName[iDet])){
505 dataNotLoaded += fgkDetectorName[iDet];
506 dataNotLoaded += " ";
508 dataLoaded += fgkDetectorName[iDet];
511 } // end loop over detectors
513 if ((detStr.CompareTo("ALL") == 0)) detStr = "";
514 dataNotLoaded += detStr;
515 if(!dataLoaded.IsNull()) AliInfo(Form("Alignment data loaded for: %s",
517 if(!dataNotLoaded.IsNull()) AliInfo(Form("Didn't/couldn't load alignment data for: %s",
518 dataNotLoaded.Data()));
519 } // fLoadAlignFromCDB flag
521 // Check if the array with alignment objects was
522 // provided by the user. If yes, apply the objects
523 // to the present TGeo geometry
524 if (fAlignObjArray) {
525 if (gGeoManager && gGeoManager->IsClosed()) {
526 if (ApplyAlignObjsToGeom(fAlignObjArray) == kFALSE) {
527 AliError("The misalignment of one or more volumes failed!"
528 "Compare the list of simulated detectors and the list of detector alignment data!");
533 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
538 delete fAlignObjArray; fAlignObjArray=0;
542 //_____________________________________________________________________________
543 void AliReconstruction::SetGAliceFile(const char* fileName)
545 // set the name of the galice file
547 fGAliceFileName = fileName;
550 //_____________________________________________________________________________
551 void AliReconstruction::SetOption(const char* detector, const char* option)
553 // set options for the reconstruction of a detector
555 TObject* obj = fOptions.FindObject(detector);
556 if (obj) fOptions.Remove(obj);
557 fOptions.Add(new TNamed(detector, option));
561 //_____________________________________________________________________________
562 Bool_t AliReconstruction::Run(const char* input)
564 // run the reconstruction
567 if (!input) input = fInput.Data();
568 TString fileName(input);
569 if (fileName.EndsWith("/")) {
570 fRawReader = new AliRawReaderFile(fileName);
571 } else if (fileName.EndsWith(".root")) {
572 fRawReader = new AliRawReaderRoot(fileName);
573 } else if (!fileName.IsNull()) {
574 fRawReader = new AliRawReaderDate(fileName);
575 fRawReader->SelectEvents(7);
577 if (!fEquipIdMap.IsNull() && fRawReader)
578 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
581 // get the run loader
582 if (!InitRunLoader()) return kFALSE;
584 // Initialize the CDB storage
587 // Set run number in CDBManager (if it is not already set by the user)
588 if (!SetRunNumber()) if (fStopOnError) return kFALSE;
590 // Import ideal TGeo geometry and apply misalignment
592 TString geom(gSystem->DirName(fGAliceFileName));
593 geom += "/geometry.root";
594 TGeoManager::Import(geom.Data());
595 if (!gGeoManager) if (fStopOnError) return kFALSE;
598 AliCDBManager* man = AliCDBManager::Instance();
599 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
601 // local reconstruction
602 if (!fRunLocalReconstruction.IsNull()) {
603 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
604 if (fStopOnError) {CleanUp(); return kFALSE;}
607 // if (!fRunVertexFinder && fRunTracking.IsNull() &&
608 // fFillESD.IsNull()) return kTRUE;
611 if (fRunVertexFinder && !CreateVertexer()) {
619 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
627 TStopwatch stopwatch;
630 // get the possibly already existing ESD file and tree
631 AliESD* esd = new AliESD; AliESD* hltesd = new AliESD;
632 TFile* fileOld = NULL;
633 TTree* treeOld = NULL; TTree *hlttreeOld = NULL;
634 if (!gSystem->AccessPathName("AliESDs.root")){
635 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
636 fileOld = TFile::Open("AliESDs.old.root");
637 if (fileOld && fileOld->IsOpen()) {
638 treeOld = (TTree*) fileOld->Get("esdTree");
639 if (treeOld) treeOld->SetBranchAddress("ESD", &esd);
640 hlttreeOld = (TTree*) fileOld->Get("HLTesdTree");
641 if (hlttreeOld) hlttreeOld->SetBranchAddress("ESD", &hltesd);
645 // create the ESD output file and tree
646 TFile* file = TFile::Open("AliESDs.root", "RECREATE");
647 if (!file->IsOpen()) {
648 AliError("opening AliESDs.root failed");
649 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
651 TTree* tree = new TTree("esdTree", "Tree with ESD objects");
652 tree->Branch("ESD", "AliESD", &esd);
653 TTree* hlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
654 hlttree->Branch("ESD", "AliESD", &hltesd);
655 delete esd; delete hltesd;
656 esd = NULL; hltesd = NULL;
658 // create the branch with ESD additions
659 AliESDfriend *esdf=0;
660 if (fWriteESDfriend) {
661 TBranch *br=tree->Branch("ESDfriend.", "AliESDfriend", &esdf);
662 br->SetFile("AliESDfriends.root");
665 AliVertexerTracks tVertexer;
666 if(fDiamondProfile) tVertexer.SetVtxStart(fDiamondProfile);
669 if (fRawReader) fRawReader->RewindEvents();
671 for (Int_t iEvent = 0; iEvent < fRunLoader->GetNumberOfEvents(); iEvent++) {
672 if (fRawReader) fRawReader->NextEvent();
673 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
674 // copy old ESD to the new one
676 treeOld->SetBranchAddress("ESD", &esd);
677 treeOld->GetEntry(iEvent);
681 hlttreeOld->SetBranchAddress("ESD", &hltesd);
682 hlttreeOld->GetEntry(iEvent);
688 AliInfo(Form("processing event %d", iEvent));
689 fRunLoader->GetEvent(iEvent);
692 sprintf(aFileName, "ESD_%d.%d_final.root",
693 fRunLoader->GetHeader()->GetRun(),
694 fRunLoader->GetHeader()->GetEventNrInRun());
695 if (!gSystem->AccessPathName(aFileName)) continue;
697 // local reconstruction
698 if (!fRunLocalReconstruction.IsNull()) {
699 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
700 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
704 esd = new AliESD; hltesd = new AliESD;
705 esd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
706 hltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
707 esd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
708 hltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
710 // Set magnetic field from the tracker
711 esd->SetMagneticField(AliTracker::GetBz());
712 hltesd->SetMagneticField(AliTracker::GetBz());
715 if (fRunVertexFinder) {
716 if (!ReadESD(esd, "vertex")) {
717 if (!RunVertexFinder(esd)) {
718 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
720 if (fCheckPointLevel > 0) WriteESD(esd, "vertex");
725 if (!fRunTracking.IsNull()) {
726 if (fRunHLTTracking) {
727 hltesd->SetVertex(esd->GetVertex());
728 if (!RunHLTTracking(hltesd)) {
729 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
735 if (!fRunTracking.IsNull()) {
736 if (fRunMuonTracking) {
737 if (!RunMuonTracking()) {
738 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
744 if (!fRunTracking.IsNull()) {
745 if (!fRunMuonTracking) {
746 if (!ReadESD(esd, "tracking")) {
747 if (!RunTracking(esd)) {
748 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
750 if (fCheckPointLevel > 0) WriteESD(esd, "tracking");
755 if (!fFillESD.IsNull()) {
756 if (!FillESD(esd, fFillESD)) {
757 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
760 // fill Event header information from the RawEventHeader
761 if (fRawReader){FillRawEventHeaderESD(esd);}
764 AliESDpid::MakePID(esd);
765 if (fCheckPointLevel > 1) WriteESD(esd, "PID");
767 if (fFillTriggerESD) {
768 if (!ReadESD(esd, "trigger")) {
769 if (!FillTriggerESD(esd)) {
770 if (fStopOnError) {CleanUp(file, fileOld); return kFALSE;}
772 if (fCheckPointLevel > 1) WriteESD(esd, "trigger");
776 //Try to improve the reconstructed primary vertex position using the tracks
777 AliESDVertex *pvtx=tVertexer.FindPrimaryVertex(esd);
779 if (pvtx->GetStatus()) {
780 // Store the improved primary vertex
781 esd->SetPrimaryVertex(pvtx);
782 // Propagate the tracks to the DCA to the improved primary vertex
783 Double_t somethingbig = 777.;
784 Double_t bz = esd->GetMagneticField();
785 Int_t nt=esd->GetNumberOfTracks();
787 AliESDtrack *t = esd->GetTrack(nt);
788 t->RelateToVertex(pvtx, bz, somethingbig);
795 vtxer.Tracks2V0vertices(esd);
798 AliCascadeVertexer cvtxer;
799 cvtxer.V0sTracks2CascadeVertices(esd);
803 if (fWriteESDfriend) {
804 esdf=new AliESDfriend();
805 esd->GetESDfriend(esdf);
812 if (fCheckPointLevel > 0) WriteESD(esd, "final");
814 delete esd; delete esdf; delete hltesd;
815 esd = NULL; esdf=NULL; hltesd = NULL;
818 AliInfo(Form("Execution time for filling ESD : R:%.2fs C:%.2fs",
819 stopwatch.RealTime(),stopwatch.CpuTime()));
823 tree->SetBranchStatus("ESDfriend*",0);
831 // Create tags for the events in the ESD tree (the ESD tree is always present)
832 // In case of empty events the tags will contain dummy values
834 CleanUp(file, fileOld);
840 //_____________________________________________________________________________
841 Bool_t AliReconstruction::RunLocalReconstruction(const TString& detectors)
843 // run the local reconstruction
845 TStopwatch stopwatch;
848 AliCDBManager* man = AliCDBManager::Instance();
849 Bool_t origCache = man->GetCacheFlag();
851 TString detStr = detectors;
852 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
853 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
854 AliReconstructor* reconstructor = GetReconstructor(iDet);
855 if (!reconstructor) continue;
856 if (reconstructor->HasLocalReconstruction()) continue;
858 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
859 TStopwatch stopwatchDet;
860 stopwatchDet.Start();
862 AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
864 man->SetCacheFlag(kTRUE);
865 TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
866 man->GetAll(calibPath); // entries are cached!
869 fRawReader->RewindEvents();
870 reconstructor->Reconstruct(fRunLoader, fRawReader);
872 reconstructor->Reconstruct(fRunLoader);
874 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
875 fgkDetectorName[iDet],
876 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
878 // unload calibration data
882 man->SetCacheFlag(origCache);
884 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
885 AliError(Form("the following detectors were not found: %s",
887 if (fStopOnError) return kFALSE;
890 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
891 stopwatch.RealTime(),stopwatch.CpuTime()));
896 //_____________________________________________________________________________
897 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
899 // run the local reconstruction
901 TStopwatch stopwatch;
904 TString detStr = detectors;
905 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
906 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
907 AliReconstructor* reconstructor = GetReconstructor(iDet);
908 if (!reconstructor) continue;
909 AliLoader* loader = fLoader[iDet];
911 // conversion of digits
912 if (fRawReader && reconstructor->HasDigitConversion()) {
913 AliInfo(Form("converting raw data digits into root objects for %s",
914 fgkDetectorName[iDet]));
915 TStopwatch stopwatchDet;
916 stopwatchDet.Start();
917 loader->LoadDigits("update");
918 loader->CleanDigits();
919 loader->MakeDigitsContainer();
920 TTree* digitsTree = loader->TreeD();
921 reconstructor->ConvertDigits(fRawReader, digitsTree);
922 loader->WriteDigits("OVERWRITE");
923 loader->UnloadDigits();
924 AliInfo(Form("Execution time for %s: R:%.2fs C:%.2fs",
925 fgkDetectorName[iDet],
926 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
929 // local reconstruction
930 if (!reconstructor->HasLocalReconstruction()) continue;
931 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
932 TStopwatch stopwatchDet;
933 stopwatchDet.Start();
934 loader->LoadRecPoints("update");
935 loader->CleanRecPoints();
936 loader->MakeRecPointsContainer();
937 TTree* clustersTree = loader->TreeR();
938 if (fRawReader && !reconstructor->HasDigitConversion()) {
939 reconstructor->Reconstruct(fRawReader, clustersTree);
941 loader->LoadDigits("read");
942 TTree* digitsTree = loader->TreeD();
944 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
945 if (fStopOnError) return kFALSE;
947 reconstructor->Reconstruct(digitsTree, clustersTree);
949 loader->UnloadDigits();
951 loader->WriteRecPoints("OVERWRITE");
952 loader->UnloadRecPoints();
953 AliDebug(1,Form("Execution time for %s: R:%.2fs C:%.2fs",
954 fgkDetectorName[iDet],
955 stopwatchDet.RealTime(),stopwatchDet.CpuTime()));
958 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
959 AliError(Form("the following detectors were not found: %s",
961 if (fStopOnError) return kFALSE;
964 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
965 stopwatch.RealTime(),stopwatch.CpuTime()));
970 //_____________________________________________________________________________
971 Bool_t AliReconstruction::RunVertexFinder(AliESD*& esd)
973 // run the barrel tracking
975 TStopwatch stopwatch;
978 AliESDVertex* vertex = NULL;
979 Double_t vtxPos[3] = {0, 0, 0};
980 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
982 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
983 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
984 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
988 AliInfo("running the ITS vertex finder");
989 if (fLoader[0]) fLoader[0]->LoadRecPoints();
990 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
991 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
993 AliWarning("Vertex not found");
994 vertex = new AliESDVertex();
995 vertex->SetName("default");
998 vertex->SetTruePos(vtxPos); // store also the vertex from MC
999 vertex->SetName("reconstructed");
1003 AliInfo("getting the primary vertex from MC");
1004 vertex = new AliESDVertex(vtxPos, vtxErr);
1008 vertex->GetXYZ(vtxPos);
1009 vertex->GetSigmaXYZ(vtxErr);
1011 AliWarning("no vertex reconstructed");
1012 vertex = new AliESDVertex(vtxPos, vtxErr);
1014 esd->SetVertex(vertex);
1015 // if SPD multiplicity has been determined, it is stored in the ESD
1016 AliMultiplicity *mult= fVertexer->GetMultiplicity();
1017 if(mult)esd->SetMultiplicity(mult);
1019 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1020 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1024 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1025 stopwatch.RealTime(),stopwatch.CpuTime()));
1030 //_____________________________________________________________________________
1031 Bool_t AliReconstruction::RunHLTTracking(AliESD*& esd)
1033 // run the HLT barrel tracking
1035 TStopwatch stopwatch;
1039 AliError("Missing runLoader!");
1043 AliInfo("running HLT tracking");
1045 // Get a pointer to the HLT reconstructor
1046 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1047 if (!reconstructor) return kFALSE;
1050 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1051 TString detName = fgkDetectorName[iDet];
1052 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1053 reconstructor->SetOption(detName.Data());
1054 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1056 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1057 if (fStopOnError) return kFALSE;
1061 Double_t vtxErr[3]={0.005,0.005,0.010};
1062 const AliESDVertex *vertex = esd->GetVertex();
1063 vertex->GetXYZ(vtxPos);
1064 tracker->SetVertex(vtxPos,vtxErr);
1066 fLoader[iDet]->LoadRecPoints("read");
1067 TTree* tree = fLoader[iDet]->TreeR();
1069 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1072 tracker->LoadClusters(tree);
1074 if (tracker->Clusters2Tracks(esd) != 0) {
1075 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1079 tracker->UnloadClusters();
1084 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1085 stopwatch.RealTime(),stopwatch.CpuTime()));
1090 //_____________________________________________________________________________
1091 Bool_t AliReconstruction::RunMuonTracking()
1093 // run the muon spectrometer tracking
1095 TStopwatch stopwatch;
1099 AliError("Missing runLoader!");
1102 Int_t iDet = 7; // for MUON
1104 AliInfo("is running...");
1106 // Get a pointer to the MUON reconstructor
1107 AliReconstructor *reconstructor = GetReconstructor(iDet);
1108 if (!reconstructor) return kFALSE;
1111 TString detName = fgkDetectorName[iDet];
1112 AliDebug(1, Form("%s tracking", detName.Data()));
1113 AliTracker *tracker = reconstructor->CreateTracker(fRunLoader);
1115 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1120 fLoader[iDet]->LoadTracks("update");
1121 fLoader[iDet]->CleanTracks();
1122 fLoader[iDet]->MakeTracksContainer();
1125 fLoader[iDet]->LoadRecPoints("read");
1127 if (!tracker->Clusters2Tracks(0x0)) {
1128 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1131 fLoader[iDet]->UnloadRecPoints();
1133 fLoader[iDet]->WriteTracks("OVERWRITE");
1134 fLoader[iDet]->UnloadTracks();
1139 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1140 stopwatch.RealTime(),stopwatch.CpuTime()));
1146 //_____________________________________________________________________________
1147 Bool_t AliReconstruction::RunTracking(AliESD*& esd)
1149 // run the barrel tracking
1151 TStopwatch stopwatch;
1154 AliInfo("running tracking");
1156 // pass 1: TPC + ITS inwards
1157 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1158 if (!fTracker[iDet]) continue;
1159 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1162 fLoader[iDet]->LoadRecPoints("read");
1163 TTree* tree = fLoader[iDet]->TreeR();
1165 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1168 fTracker[iDet]->LoadClusters(tree);
1171 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1172 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1175 if (fCheckPointLevel > 1) {
1176 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1178 // preliminary PID in TPC needed by the ITS tracker
1180 GetReconstructor(1)->FillESD(fRunLoader, esd);
1181 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1182 AliESDpid::MakePID(esd);
1186 // pass 2: ALL backwards
1187 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1188 if (!fTracker[iDet]) continue;
1189 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1192 if (iDet > 1) { // all except ITS, TPC
1194 fLoader[iDet]->LoadRecPoints("read");
1195 tree = fLoader[iDet]->TreeR();
1197 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1200 fTracker[iDet]->LoadClusters(tree);
1204 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1205 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1208 if (fCheckPointLevel > 1) {
1209 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1213 if (iDet > 2) { // all except ITS, TPC, TRD
1214 fTracker[iDet]->UnloadClusters();
1215 fLoader[iDet]->UnloadRecPoints();
1217 // updated PID in TPC needed by the ITS tracker -MI
1219 GetReconstructor(1)->FillESD(fRunLoader, esd);
1220 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1221 AliESDpid::MakePID(esd);
1225 // write space-points to the ESD in case alignment data output
1227 if (fWriteAlignmentData)
1228 WriteAlignmentData(esd);
1230 // pass 3: TRD + TPC + ITS refit inwards
1231 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1232 if (!fTracker[iDet]) continue;
1233 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1236 if (fTracker[iDet]->RefitInward(esd) != 0) {
1237 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1240 if (fCheckPointLevel > 1) {
1241 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1245 fTracker[iDet]->UnloadClusters();
1246 fLoader[iDet]->UnloadRecPoints();
1249 // Propagate track to the vertex - if not done by ITS
1251 Int_t ntracks = esd->GetNumberOfTracks();
1252 for (Int_t itrack=0; itrack<ntracks; itrack++){
1253 const Double_t kRadius = 3; // beam pipe radius
1254 const Double_t kMaxStep = 5; // max step
1255 const Double_t kMaxD = 123456; // max distance to prim vertex
1256 Double_t fieldZ = AliTracker::GetBz(); //
1257 AliESDtrack * track = esd->GetTrack(itrack);
1258 if (!track) continue;
1259 if (track->IsOn(AliESDtrack::kITSrefit)) continue;
1260 track->PropagateTo(kRadius, fieldZ, track->GetMass(),kMaxStep,kTRUE);
1261 track->RelateToVertex(esd->GetVertex(),fieldZ, kMaxD);
1264 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1265 stopwatch.RealTime(),stopwatch.CpuTime()));
1270 //_____________________________________________________________________________
1271 Bool_t AliReconstruction::FillESD(AliESD*& esd, const TString& detectors)
1273 // fill the event summary data
1275 TStopwatch stopwatch;
1277 AliInfo("filling ESD");
1279 TString detStr = detectors;
1280 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1281 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1282 AliReconstructor* reconstructor = GetReconstructor(iDet);
1283 if (!reconstructor) continue;
1285 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1286 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1287 TTree* clustersTree = NULL;
1288 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1289 fLoader[iDet]->LoadRecPoints("read");
1290 clustersTree = fLoader[iDet]->TreeR();
1291 if (!clustersTree) {
1292 AliError(Form("Can't get the %s clusters tree",
1293 fgkDetectorName[iDet]));
1294 if (fStopOnError) return kFALSE;
1297 if (fRawReader && !reconstructor->HasDigitConversion()) {
1298 reconstructor->FillESD(fRawReader, clustersTree, esd);
1300 TTree* digitsTree = NULL;
1301 if (fLoader[iDet]) {
1302 fLoader[iDet]->LoadDigits("read");
1303 digitsTree = fLoader[iDet]->TreeD();
1305 AliError(Form("Can't get the %s digits tree",
1306 fgkDetectorName[iDet]));
1307 if (fStopOnError) return kFALSE;
1310 reconstructor->FillESD(digitsTree, clustersTree, esd);
1311 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1313 if (reconstructor->HasLocalReconstruction() && fLoader[iDet]) {
1314 fLoader[iDet]->UnloadRecPoints();
1318 reconstructor->FillESD(fRunLoader, fRawReader, esd);
1320 reconstructor->FillESD(fRunLoader, esd);
1322 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1326 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1327 AliError(Form("the following detectors were not found: %s",
1329 if (fStopOnError) return kFALSE;
1332 AliInfo(Form("Execution time: R:%.2fs C:%.2fs",
1333 stopwatch.RealTime(),stopwatch.CpuTime()));
1338 //_____________________________________________________________________________
1339 Bool_t AliReconstruction::FillTriggerESD(AliESD*& esd)
1341 // Reads the trigger decision which is
1342 // stored in Trigger.root file and fills
1343 // the corresponding esd entries
1345 AliInfo("Filling trigger information into the ESD");
1348 AliCTPRawStream input(fRawReader);
1349 if (!input.Next()) {
1350 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1353 esd->SetTriggerMask(input.GetClassMask());
1354 esd->SetTriggerCluster(input.GetClusterMask());
1357 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1359 if (!runloader->LoadTrigger()) {
1360 AliCentralTrigger *aCTP = runloader->GetTrigger();
1361 esd->SetTriggerMask(aCTP->GetClassMask());
1362 esd->SetTriggerCluster(aCTP->GetClusterMask());
1365 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1370 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1382 //_____________________________________________________________________________
1383 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESD*& esd)
1386 // Filling information from RawReader Header
1389 AliInfo("Filling information from RawReader Header");
1390 esd->SetBunchCrossNumber(0);
1391 esd->SetOrbitNumber(0);
1392 esd->SetTimeStamp(0);
1393 esd->SetEventType(0);
1394 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1396 esd->SetBunchCrossNumber((eventHeader->GetP("Id")[0]));
1397 esd->SetOrbitNumber((eventHeader->GetP("Id")[1]));
1398 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1399 esd->SetEventType((eventHeader->Get("Type")));
1406 //_____________________________________________________________________________
1407 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1409 // check whether detName is contained in detectors
1410 // if yes, it is removed from detectors
1412 // check if all detectors are selected
1413 if ((detectors.CompareTo("ALL") == 0) ||
1414 detectors.BeginsWith("ALL ") ||
1415 detectors.EndsWith(" ALL") ||
1416 detectors.Contains(" ALL ")) {
1421 // search for the given detector
1422 Bool_t result = kFALSE;
1423 if ((detectors.CompareTo(detName) == 0) ||
1424 detectors.BeginsWith(detName+" ") ||
1425 detectors.EndsWith(" "+detName) ||
1426 detectors.Contains(" "+detName+" ")) {
1427 detectors.ReplaceAll(detName, "");
1431 // clean up the detectors string
1432 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1433 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1434 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1439 //_____________________________________________________________________________
1440 Bool_t AliReconstruction::InitRunLoader()
1442 // get or create the run loader
1444 if (gAlice) delete gAlice;
1447 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1448 // load all base libraries to get the loader classes
1449 TString libs = gSystem->GetLibraries();
1450 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1451 TString detName = fgkDetectorName[iDet];
1452 if (detName == "HLT") continue;
1453 if (libs.Contains("lib" + detName + "base.so")) continue;
1454 gSystem->Load("lib" + detName + "base.so");
1456 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1458 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1462 fRunLoader->CdGAFile();
1463 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1464 if (fRunLoader->LoadgAlice() == 0) {
1465 gAlice = fRunLoader->GetAliRun();
1466 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1469 if (!gAlice && !fRawReader) {
1470 AliError(Form("no gAlice object found in file %s",
1471 fGAliceFileName.Data()));
1476 } else { // galice.root does not exist
1478 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
1482 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
1483 AliConfig::GetDefaultEventFolderName(),
1486 AliError(Form("could not create run loader in file %s",
1487 fGAliceFileName.Data()));
1491 fRunLoader->MakeTree("E");
1493 while (fRawReader->NextEvent()) {
1494 fRunLoader->SetEventNumber(iEvent);
1495 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
1497 fRunLoader->MakeTree("H");
1498 fRunLoader->TreeE()->Fill();
1501 fRawReader->RewindEvents();
1502 if (fNumberOfEventsPerFile > 0)
1503 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
1505 fRunLoader->SetNumberOfEventsPerFile(iEvent);
1506 fRunLoader->WriteHeader("OVERWRITE");
1507 fRunLoader->CdGAFile();
1508 fRunLoader->Write(0, TObject::kOverwrite);
1509 // AliTracker::SetFieldMap(???);
1515 //_____________________________________________________________________________
1516 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
1518 // get the reconstructor object and the loader for a detector
1520 if (fReconstructor[iDet]) return fReconstructor[iDet];
1522 // load the reconstructor object
1523 TPluginManager* pluginManager = gROOT->GetPluginManager();
1524 TString detName = fgkDetectorName[iDet];
1525 TString recName = "Ali" + detName + "Reconstructor";
1526 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
1528 if (detName == "HLT") {
1529 if (!gROOT->GetClass("AliLevel3")) {
1530 gSystem->Load("libAliHLTSrc.so");
1531 gSystem->Load("libAliHLTMisc.so");
1532 gSystem->Load("libAliHLTHough.so");
1533 gSystem->Load("libAliHLTComp.so");
1537 AliReconstructor* reconstructor = NULL;
1538 // first check if a plugin is defined for the reconstructor
1539 TPluginHandler* pluginHandler =
1540 pluginManager->FindHandler("AliReconstructor", detName);
1541 // if not, add a plugin for it
1542 if (!pluginHandler) {
1543 AliDebug(1, Form("defining plugin for %s", recName.Data()));
1544 TString libs = gSystem->GetLibraries();
1545 if (libs.Contains("lib" + detName + "base.so") ||
1546 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
1547 pluginManager->AddHandler("AliReconstructor", detName,
1548 recName, detName + "rec", recName + "()");
1550 pluginManager->AddHandler("AliReconstructor", detName,
1551 recName, detName, recName + "()");
1553 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
1555 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1556 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
1558 if (reconstructor) {
1559 TObject* obj = fOptions.FindObject(detName.Data());
1560 if (obj) reconstructor->SetOption(obj->GetTitle());
1561 reconstructor->Init(fRunLoader);
1562 fReconstructor[iDet] = reconstructor;
1565 // get or create the loader
1566 if (detName != "HLT") {
1567 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
1568 if (!fLoader[iDet]) {
1569 AliConfig::Instance()
1570 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
1572 // first check if a plugin is defined for the loader
1574 pluginManager->FindHandler("AliLoader", detName);
1575 // if not, add a plugin for it
1576 if (!pluginHandler) {
1577 TString loaderName = "Ali" + detName + "Loader";
1578 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
1579 pluginManager->AddHandler("AliLoader", detName,
1580 loaderName, detName + "base",
1581 loaderName + "(const char*, TFolder*)");
1582 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
1584 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
1586 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
1587 fRunLoader->GetEventFolder());
1589 if (!fLoader[iDet]) { // use default loader
1590 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
1592 if (!fLoader[iDet]) {
1593 AliWarning(Form("couldn't get loader for %s", detName.Data()));
1594 if (fStopOnError) return NULL;
1596 fRunLoader->AddLoader(fLoader[iDet]);
1597 fRunLoader->CdGAFile();
1598 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
1599 fRunLoader->Write(0, TObject::kOverwrite);
1604 return reconstructor;
1607 //_____________________________________________________________________________
1608 Bool_t AliReconstruction::CreateVertexer()
1610 // create the vertexer
1613 AliReconstructor* itsReconstructor = GetReconstructor(0);
1614 if (itsReconstructor) {
1615 fVertexer = itsReconstructor->CreateVertexer(fRunLoader);
1618 AliWarning("couldn't create a vertexer for ITS");
1619 if (fStopOnError) return kFALSE;
1625 //_____________________________________________________________________________
1626 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
1628 // create the trackers
1630 TString detStr = detectors;
1631 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1632 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1633 AliReconstructor* reconstructor = GetReconstructor(iDet);
1634 if (!reconstructor) continue;
1635 TString detName = fgkDetectorName[iDet];
1636 if (detName == "HLT") {
1637 fRunHLTTracking = kTRUE;
1640 if (detName == "MUON") {
1641 fRunMuonTracking = kTRUE;
1646 fTracker[iDet] = reconstructor->CreateTracker(fRunLoader);
1647 if (!fTracker[iDet] && (iDet < 7)) {
1648 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1649 if (fStopOnError) return kFALSE;
1656 //_____________________________________________________________________________
1657 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
1659 // delete trackers and the run loader and close and delete the file
1661 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1662 delete fReconstructor[iDet];
1663 fReconstructor[iDet] = NULL;
1664 fLoader[iDet] = NULL;
1665 delete fTracker[iDet];
1666 fTracker[iDet] = NULL;
1670 delete fDiamondProfile;
1671 fDiamondProfile = NULL;
1686 gSystem->Unlink("AliESDs.old.root");
1691 //_____________________________________________________________________________
1692 Bool_t AliReconstruction::ReadESD(AliESD*& esd, const char* recStep) const
1694 // read the ESD event from a file
1696 if (!esd) return kFALSE;
1698 sprintf(fileName, "ESD_%d.%d_%s.root",
1699 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1700 if (gSystem->AccessPathName(fileName)) return kFALSE;
1702 AliInfo(Form("reading ESD from file %s", fileName));
1703 AliDebug(1, Form("reading ESD from file %s", fileName));
1704 TFile* file = TFile::Open(fileName);
1705 if (!file || !file->IsOpen()) {
1706 AliError(Form("opening %s failed", fileName));
1713 esd = (AliESD*) file->Get("ESD");
1719 //_____________________________________________________________________________
1720 void AliReconstruction::WriteESD(AliESD* esd, const char* recStep) const
1722 // write the ESD event to a file
1726 sprintf(fileName, "ESD_%d.%d_%s.root",
1727 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
1729 AliDebug(1, Form("writing ESD to file %s", fileName));
1730 TFile* file = TFile::Open(fileName, "recreate");
1731 if (!file || !file->IsOpen()) {
1732 AliError(Form("opening %s failed", fileName));
1743 //_____________________________________________________________________________
1744 void AliReconstruction::CreateTag(TFile* file)
1749 Double_t fMUONMASS = 0.105658369;
1752 Double_t fThetaX, fThetaY, fPyz, fChisquare;
1753 Double_t fPxRec,fPyRec, fPzRec, fEnergy;
1755 TLorentzVector fEPvector;
1757 Float_t fZVertexCut = 10.0;
1758 Float_t fRhoVertexCut = 2.0;
1760 Float_t fLowPtCut = 1.0;
1761 Float_t fHighPtCut = 3.0;
1762 Float_t fVeryHighPtCut = 10.0;
1765 Double_t partFrac[5] = {0.01, 0.01, 0.85, 0.10, 0.05};
1767 // Creates the tags for all the events in a given ESD file
1769 Int_t nProtons, nKaons, nPions, nMuons, nElectrons;
1770 Int_t nPos, nNeg, nNeutr;
1771 Int_t nK0s, nNeutrons, nPi0s, nGamas;
1772 Int_t nCh1GeV, nCh3GeV, nCh10GeV;
1773 Int_t nMu1GeV, nMu3GeV, nMu10GeV;
1774 Int_t nEl1GeV, nEl3GeV, nEl10GeV;
1775 Float_t maxPt = .0, meanPt = .0, totalP = .0;
1777 Int_t iRunNumber = 0;
1778 TString fVertexName("default");
1780 AliRunTag *tag = new AliRunTag();
1781 AliEventTag *evTag = new AliEventTag();
1782 TTree ttag("T","A Tree with event tags");
1783 TBranch * btag = ttag.Branch("AliTAG", &tag);
1784 btag->SetCompressionLevel(9);
1786 AliInfo(Form("Creating the tags......."));
1788 if (!file || !file->IsOpen()) {
1789 AliError(Form("opening failed"));
1793 Int_t lastEvent = 0;
1794 TTree *t = (TTree*) file->Get("esdTree");
1795 TBranch * b = t->GetBranch("ESD");
1797 b->SetAddress(&esd);
1799 b->GetEntry(fFirstEvent);
1800 Int_t iInitRunNumber = esd->GetRunNumber();
1802 Int_t iNumberOfEvents = (Int_t)b->GetEntries();
1803 if(fLastEvent != -1) iNumberOfEvents = fLastEvent + 1;
1804 for (Int_t iEventNumber = fFirstEvent; iEventNumber < iNumberOfEvents; iEventNumber++) {
1832 b->GetEntry(iEventNumber);
1833 iRunNumber = esd->GetRunNumber();
1834 if(iRunNumber != iInitRunNumber) AliFatal("Inconsistency of run numbers in the AliESD!!!");
1835 const AliESDVertex * vertexIn = esd->GetVertex();
1836 if (!vertexIn) AliError("ESD has not defined vertex.");
1837 if (vertexIn) fVertexName = vertexIn->GetName();
1838 if(fVertexName != "default") fVertexflag = 1;
1839 for (Int_t iTrackNumber = 0; iTrackNumber < esd->GetNumberOfTracks(); iTrackNumber++) {
1840 AliESDtrack * esdTrack = esd->GetTrack(iTrackNumber);
1841 UInt_t status = esdTrack->GetStatus();
1843 //select only tracks with ITS refit
1844 if ((status&AliESDtrack::kITSrefit)==0) continue;
1845 //select only tracks with TPC refit
1846 if ((status&AliESDtrack::kTPCrefit)==0) continue;
1848 //select only tracks with the "combined PID"
1849 if ((status&AliESDtrack::kESDpid)==0) continue;
1851 esdTrack->GetPxPyPz(p);
1852 Double_t momentum = sqrt(pow(p[0],2) + pow(p[1],2) + pow(p[2],2));
1853 Double_t fPt = sqrt(pow(p[0],2) + pow(p[1],2));
1856 if(fPt > maxPt) maxPt = fPt;
1858 if(esdTrack->GetSign() > 0) {
1860 if(fPt > fLowPtCut) nCh1GeV++;
1861 if(fPt > fHighPtCut) nCh3GeV++;
1862 if(fPt > fVeryHighPtCut) nCh10GeV++;
1864 if(esdTrack->GetSign() < 0) {
1866 if(fPt > fLowPtCut) nCh1GeV++;
1867 if(fPt > fHighPtCut) nCh3GeV++;
1868 if(fPt > fVeryHighPtCut) nCh10GeV++;
1870 if(esdTrack->GetSign() == 0) nNeutr++;
1874 esdTrack->GetESDpid(prob);
1877 for(Int_t i = 0; i < AliPID::kSPECIES; i++) rcc += prob[i]*partFrac[i];
1878 if(rcc == 0.0) continue;
1881 for(Int_t i = 0; i < AliPID::kSPECIES; i++) w[i] = prob[i]*partFrac[i]/rcc;
1884 if ((w[4]>w[3])&&(w[4]>w[2])&&(w[4]>w[1])&&(w[4]>w[0])) nProtons++;
1886 if ((w[3]>w[4])&&(w[3]>w[2])&&(w[3]>w[1])&&(w[3]>w[0])) nKaons++;
1888 if ((w[2]>w[4])&&(w[2]>w[3])&&(w[2]>w[1])&&(w[2]>w[0])) nPions++;
1890 if ((w[0]>w[4])&&(w[0]>w[3])&&(w[0]>w[2])&&(w[0]>w[1])) {
1892 if(fPt > fLowPtCut) nEl1GeV++;
1893 if(fPt > fHighPtCut) nEl3GeV++;
1894 if(fPt > fVeryHighPtCut) nEl10GeV++;
1902 Int_t nMuonTracks = esd->GetNumberOfMuonTracks();
1903 // loop over all reconstructed tracks (also first track of combination)
1904 for (Int_t iTrack = 0; iTrack < nMuonTracks; iTrack++) {
1905 AliESDMuonTrack* muonTrack = esd->GetMuonTrack(iTrack);
1906 if (muonTrack == 0x0) continue;
1908 // Coordinates at vertex
1909 fZ = muonTrack->GetZ();
1910 fY = muonTrack->GetBendingCoor();
1911 fX = muonTrack->GetNonBendingCoor();
1913 fThetaX = muonTrack->GetThetaX();
1914 fThetaY = muonTrack->GetThetaY();
1916 fPyz = 1./TMath::Abs(muonTrack->GetInverseBendingMomentum());
1917 fPzRec = - fPyz / TMath::Sqrt(1.0 + TMath::Tan(fThetaY)*TMath::Tan(fThetaY));
1918 fPxRec = fPzRec * TMath::Tan(fThetaX);
1919 fPyRec = fPzRec * TMath::Tan(fThetaY);
1920 fCharge = Int_t(TMath::Sign(1.,muonTrack->GetInverseBendingMomentum()));
1922 //ChiSquare of the track if needed
1923 fChisquare = muonTrack->GetChi2()/(2.0 * muonTrack->GetNHit() - 5);
1924 fEnergy = TMath::Sqrt(fMUONMASS * fMUONMASS + fPxRec * fPxRec + fPyRec * fPyRec + fPzRec * fPzRec);
1925 fEPvector.SetPxPyPzE(fPxRec, fPyRec, fPzRec, fEnergy);
1927 // total number of muons inside a vertex cut
1928 if((TMath::Abs(fZ)<fZVertexCut) && (TMath::Sqrt(fY*fY+fX*fX)<fRhoVertexCut)) {
1930 if(fEPvector.Pt() > fLowPtCut) {
1932 if(fEPvector.Pt() > fHighPtCut) {
1934 if (fEPvector.Pt() > fVeryHighPtCut) {
1942 // Fill the event tags
1944 meanPt = meanPt/ntrack;
1946 evTag->SetEventId(iEventNumber+1);
1948 evTag->SetVertexX(vertexIn->GetXv());
1949 evTag->SetVertexY(vertexIn->GetYv());
1950 evTag->SetVertexZ(vertexIn->GetZv());
1951 evTag->SetVertexZError(vertexIn->GetZRes());
1953 evTag->SetVertexFlag(fVertexflag);
1955 evTag->SetT0VertexZ(esd->GetT0zVertex());
1957 evTag->SetTriggerMask(esd->GetTriggerMask());
1958 evTag->SetTriggerCluster(esd->GetTriggerCluster());
1960 evTag->SetZDCNeutron1Energy(esd->GetZDCN1Energy());
1961 evTag->SetZDCProton1Energy(esd->GetZDCP1Energy());
1962 evTag->SetZDCNeutron2Energy(esd->GetZDCN2Energy());
1963 evTag->SetZDCProton2Energy(esd->GetZDCP2Energy());
1964 evTag->SetZDCEMEnergy(esd->GetZDCEMEnergy());
1965 evTag->SetNumOfParticipants(esd->GetZDCParticipants());
1968 evTag->SetNumOfTracks(esd->GetNumberOfTracks());
1969 evTag->SetNumOfPosTracks(nPos);
1970 evTag->SetNumOfNegTracks(nNeg);
1971 evTag->SetNumOfNeutrTracks(nNeutr);
1973 evTag->SetNumOfV0s(esd->GetNumberOfV0s());
1974 evTag->SetNumOfCascades(esd->GetNumberOfCascades());
1975 evTag->SetNumOfKinks(esd->GetNumberOfKinks());
1976 evTag->SetNumOfPMDTracks(esd->GetNumberOfPmdTracks());
1978 evTag->SetNumOfProtons(nProtons);
1979 evTag->SetNumOfKaons(nKaons);
1980 evTag->SetNumOfPions(nPions);
1981 evTag->SetNumOfMuons(nMuons);
1982 evTag->SetNumOfElectrons(nElectrons);
1983 evTag->SetNumOfPhotons(nGamas);
1984 evTag->SetNumOfPi0s(nPi0s);
1985 evTag->SetNumOfNeutrons(nNeutrons);
1986 evTag->SetNumOfKaon0s(nK0s);
1988 evTag->SetNumOfChargedAbove1GeV(nCh1GeV);
1989 evTag->SetNumOfChargedAbove3GeV(nCh3GeV);
1990 evTag->SetNumOfChargedAbove10GeV(nCh10GeV);
1991 evTag->SetNumOfMuonsAbove1GeV(nMu1GeV);
1992 evTag->SetNumOfMuonsAbove3GeV(nMu3GeV);
1993 evTag->SetNumOfMuonsAbove10GeV(nMu10GeV);
1994 evTag->SetNumOfElectronsAbove1GeV(nEl1GeV);
1995 evTag->SetNumOfElectronsAbove3GeV(nEl3GeV);
1996 evTag->SetNumOfElectronsAbove10GeV(nEl10GeV);
1998 evTag->SetNumOfPHOSClusters(esd->GetNumberOfPHOSClusters());
1999 evTag->SetNumOfEMCALClusters(esd->GetNumberOfEMCALClusters());
2001 evTag->SetTotalMomentum(totalP);
2002 evTag->SetMeanPt(meanPt);
2003 evTag->SetMaxPt(maxPt);
2005 tag->SetRunId(iInitRunNumber);
2006 tag->AddEventTag(*evTag);
2008 if(fLastEvent == -1) lastEvent = (Int_t)b->GetEntries();
2009 else lastEvent = fLastEvent;
2015 sprintf(fileName, "Run%d.Event%d_%d.ESD.tag.root",
2016 tag->GetRunId(),fFirstEvent,lastEvent );
2017 AliInfo(Form("writing tags to file %s", fileName));
2018 AliDebug(1, Form("writing tags to file %s", fileName));
2020 TFile* ftag = TFile::Open(fileName, "recreate");
2029 //_____________________________________________________________________________
2030 void AliReconstruction::CreateAOD(TFile* esdFile)
2032 // do nothing for now
2038 void AliReconstruction::WriteAlignmentData(AliESD* esd)
2040 // Write space-points which are then used in the alignment procedures
2041 // For the moment only ITS, TRD and TPC
2043 // Load TOF clusters
2045 fLoader[3]->LoadRecPoints("read");
2046 TTree* tree = fLoader[3]->TreeR();
2048 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2051 fTracker[3]->LoadClusters(tree);
2053 Int_t ntracks = esd->GetNumberOfTracks();
2054 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2056 AliESDtrack *track = esd->GetTrack(itrack);
2059 for (Int_t iDet = 3; iDet >= 0; iDet--)
2060 nsp += track->GetNcls(iDet);
2062 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2063 track->SetTrackPointArray(sp);
2065 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2066 AliTracker *tracker = fTracker[iDet];
2067 if (!tracker) continue;
2068 Int_t nspdet = track->GetNcls(iDet);
2069 if (nspdet <= 0) continue;
2070 track->GetClusters(iDet,idx);
2074 while (isp < nspdet) {
2075 Bool_t isvalid = tracker->GetTrackPoint(idx[isp2],p); isp2++;
2076 const Int_t kNTPCmax = 159;
2077 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2078 if (!isvalid) continue;
2079 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2085 fTracker[3]->UnloadClusters();
2086 fLoader[3]->UnloadRecPoints();