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 // The input data of a detector can be replaced by the corresponding HLT //
105 // data by calling (usual detector string) //
106 // SetUseHLTData("..."); //
108 // For debug purposes the method SetCheckPointLevel can be used. If the //
109 // argument is greater than 0, files with ESD events will be written after //
110 // selected steps of the reconstruction for each event: //
111 // level 1: after tracking and after filling of ESD (final) //
112 // level 2: in addition after each tracking step //
113 // level 3: in addition after the filling of ESD for each detector //
114 // If a final check point file exists for an event, this event will be //
115 // skipped in the reconstruction. The tracking and the filling of ESD for //
116 // a detector will be skipped as well, if the corresponding check point //
117 // file exists. The ESD event will then be loaded from the file instead. //
119 ///////////////////////////////////////////////////////////////////////////////
126 #include <TPluginManager.h>
127 #include <TGeoManager.h>
128 #include <TLorentzVector.h>
131 #include <TObjArray.h>
133 #include "AliReconstruction.h"
134 #include "AliCodeTimer.h"
135 #include "AliReconstructor.h"
137 #include "AliRunLoader.h"
139 #include "AliRawReaderFile.h"
140 #include "AliRawReaderDate.h"
141 #include "AliRawReaderRoot.h"
142 #include "AliRawEventHeaderBase.h"
143 #include "AliESDEvent.h"
144 #include "AliESDMuonTrack.h"
145 #include "AliESDfriend.h"
146 #include "AliESDVertex.h"
147 #include "AliESDcascade.h"
148 #include "AliESDkink.h"
149 #include "AliESDtrack.h"
150 #include "AliESDCaloCluster.h"
151 #include "AliESDCaloCells.h"
152 #include "AliMultiplicity.h"
153 #include "AliTracker.h"
154 #include "AliVertexer.h"
155 #include "AliVertexerTracks.h"
156 #include "AliV0vertexer.h"
157 #include "AliCascadeVertexer.h"
158 #include "AliHeader.h"
159 #include "AliGenEventHeader.h"
161 #include "AliESDpid.h"
162 #include "AliESDtrack.h"
163 #include "AliESDPmdTrack.h"
165 #include "AliESDTagCreator.h"
166 #include "AliAODTagCreator.h"
168 #include "AliGeomManager.h"
169 #include "AliTrackPointArray.h"
170 #include "AliCDBManager.h"
171 #include "AliCDBStorage.h"
172 #include "AliCDBEntry.h"
173 #include "AliAlignObj.h"
175 #include "AliCentralTrigger.h"
176 #include "AliTriggerConfiguration.h"
177 #include "AliTriggerClass.h"
178 #include "AliCTPRawStream.h"
180 #include "AliQADataMakerRec.h"
181 #include "AliGlobalQADataMaker.h"
183 #include "AliQADataMakerSteer.h"
185 #include "AliPlaneEff.h"
187 #include "AliSysInfo.h" // memory snapshots
188 #include "AliRawHLTManager.h"
191 ClassImp(AliReconstruction)
194 //_____________________________________________________________________________
195 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
197 //_____________________________________________________________________________
198 AliReconstruction::AliReconstruction(const char* gAliceFilename,
199 const char* name, const char* title) :
202 fUniformField(kTRUE),
203 fRunVertexFinder(kTRUE),
204 fRunVertexFinderTracks(kTRUE),
205 fRunHLTTracking(kFALSE),
206 fRunMuonTracking(kFALSE),
208 fRunCascadeFinder(kTRUE),
209 fStopOnError(kFALSE),
210 fWriteAlignmentData(kFALSE),
211 fWriteESDfriend(kFALSE),
213 fFillTriggerESD(kTRUE),
221 fRunLocalReconstruction("ALL"),
224 fUseTrackingErrorsForAlignment(""),
225 fGAliceFileName(gAliceFilename),
230 fNumberOfEventsPerFile(1),
233 fLoadAlignFromCDB(kTRUE),
234 fLoadAlignData("ALL"),
240 fParentRawReader(NULL),
243 fDiamondProfile(NULL),
244 fDiamondProfileTPC(NULL),
245 fMeanVertexConstraint(kTRUE),
249 fAlignObjArray(NULL),
252 fInitCDBCalled(kFALSE),
253 fSetRunNumberFromDataCalled(kFALSE),
257 fSameQACycle(kFALSE),
259 fRunPlaneEff(kFALSE),
271 fIsNewRunLoader(kFALSE)
273 // create reconstruction object with default parameters
275 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
276 fReconstructor[iDet] = NULL;
277 fLoader[iDet] = NULL;
278 fTracker[iDet] = NULL;
279 fQADataMaker[iDet] = NULL;
280 fQACycles[iDet] = 999999;
282 fQADataMaker[fgkNDetectors]=NULL; //Global QA
286 //_____________________________________________________________________________
287 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
290 fUniformField(rec.fUniformField),
291 fRunVertexFinder(rec.fRunVertexFinder),
292 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
293 fRunHLTTracking(rec.fRunHLTTracking),
294 fRunMuonTracking(rec.fRunMuonTracking),
295 fRunV0Finder(rec.fRunV0Finder),
296 fRunCascadeFinder(rec.fRunCascadeFinder),
297 fStopOnError(rec.fStopOnError),
298 fWriteAlignmentData(rec.fWriteAlignmentData),
299 fWriteESDfriend(rec.fWriteESDfriend),
300 fWriteAOD(rec.fWriteAOD),
301 fFillTriggerESD(rec.fFillTriggerESD),
303 fCleanESD(rec.fCleanESD),
304 fV0DCAmax(rec.fV0DCAmax),
305 fV0CsPmin(rec.fV0CsPmin),
309 fRunLocalReconstruction(rec.fRunLocalReconstruction),
310 fRunTracking(rec.fRunTracking),
311 fFillESD(rec.fFillESD),
312 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
313 fGAliceFileName(rec.fGAliceFileName),
315 fEquipIdMap(rec.fEquipIdMap),
316 fFirstEvent(rec.fFirstEvent),
317 fLastEvent(rec.fLastEvent),
318 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
321 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
322 fLoadAlignData(rec.fLoadAlignData),
323 fESDPar(rec.fESDPar),
324 fUseHLTData(rec.fUseHLTData),
328 fParentRawReader(NULL),
331 fDiamondProfile(NULL),
332 fDiamondProfileTPC(NULL),
333 fMeanVertexConstraint(rec.fMeanVertexConstraint),
337 fAlignObjArray(rec.fAlignObjArray),
338 fCDBUri(rec.fCDBUri),
340 fInitCDBCalled(rec.fInitCDBCalled),
341 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
343 fRunGlobalQA(rec.fRunGlobalQA),
344 fInLoopQA(rec.fInLoopQA),
345 fSameQACycle(rec.fSameQACycle),
346 fRunPlaneEff(rec.fRunPlaneEff),
358 fIsNewRunLoader(rec.fIsNewRunLoader)
362 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
363 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
365 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
366 fReconstructor[iDet] = NULL;
367 fLoader[iDet] = NULL;
368 fTracker[iDet] = NULL;
369 fQADataMaker[iDet] = NULL;
370 fQACycles[iDet] = rec.fQACycles[iDet];
372 fQADataMaker[fgkNDetectors]=NULL; //Global QA
373 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
374 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
378 //_____________________________________________________________________________
379 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
381 // assignment operator
383 this->~AliReconstruction();
384 new(this) AliReconstruction(rec);
388 //_____________________________________________________________________________
389 AliReconstruction::~AliReconstruction()
395 fSpecCDBUri.Delete();
397 AliCodeTimer::Instance()->Print();
400 //_____________________________________________________________________________
401 void AliReconstruction::InitCDB()
403 // activate a default CDB storage
404 // First check if we have any CDB storage set, because it is used
405 // to retrieve the calibration and alignment constants
407 if (fInitCDBCalled) return;
408 fInitCDBCalled = kTRUE;
410 AliCDBManager* man = AliCDBManager::Instance();
411 if (man->IsDefaultStorageSet())
413 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
414 AliWarning("Default CDB storage has been already set !");
415 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
416 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
417 fCDBUri = man->GetDefaultStorage()->GetURI();
420 if (fCDBUri.Length() > 0)
422 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
423 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
424 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
426 fCDBUri="local://$ALICE_ROOT";
427 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
428 AliWarning("Default CDB storage not yet set !!!!");
429 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
430 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
433 man->SetDefaultStorage(fCDBUri);
436 // Now activate the detector specific CDB storage locations
437 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
438 TObject* obj = fSpecCDBUri[i];
440 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
441 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
442 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
443 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
448 //_____________________________________________________________________________
449 void AliReconstruction::SetDefaultStorage(const char* uri) {
450 // Store the desired default CDB storage location
451 // Activate it later within the Run() method
457 //_____________________________________________________________________________
458 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
459 // Store a detector-specific CDB storage location
460 // Activate it later within the Run() method
462 AliCDBPath aPath(calibType);
463 if(!aPath.IsValid()){
464 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
465 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
466 if(!strcmp(calibType, fgkDetectorName[iDet])) {
467 aPath.SetPath(Form("%s/*", calibType));
468 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
472 if(!aPath.IsValid()){
473 AliError(Form("Not a valid path or detector: %s", calibType));
478 // // check that calibType refers to a "valid" detector name
479 // Bool_t isDetector = kFALSE;
480 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
481 // TString detName = fgkDetectorName[iDet];
482 // if(aPath.GetLevel0() == detName) {
483 // isDetector = kTRUE;
489 // AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
493 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
494 if (obj) fSpecCDBUri.Remove(obj);
495 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
499 //_____________________________________________________________________________
500 Bool_t AliReconstruction::SetRunNumberFromData()
502 // The method is called in Run() in order
503 // to set a correct run number.
504 // In case of raw data reconstruction the
505 // run number is taken from the raw data header
507 if (fSetRunNumberFromDataCalled) return kTRUE;
508 fSetRunNumberFromDataCalled = kTRUE;
510 AliCDBManager* man = AliCDBManager::Instance();
512 if(man->GetRun() > 0) {
513 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
517 AliError("No run loader is found !");
520 // read run number from gAlice
521 if(fRunLoader->GetAliRun())
522 AliCDBManager::Instance()->SetRun(fRunLoader->GetHeader()->GetRun());
525 if(fRawReader->NextEvent()) {
526 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
527 fRawReader->RewindEvents();
530 if(man->GetRun() > 0) {
531 AliWarning("No raw events is found ! Using settings in AliCDBManager !");
536 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
542 AliError("Neither gAlice nor RawReader objects are found !");
552 //_____________________________________________________________________________
553 void AliReconstruction::SetCDBLock() {
554 // Set CDB lock: from now on it is forbidden to reset the run number
555 // or the default storage or to activate any further storage!
557 AliCDBManager::Instance()->SetLock(1);
560 //_____________________________________________________________________________
561 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
563 // Read the alignment objects from CDB.
564 // Each detector is supposed to have the
565 // alignment objects in DET/Align/Data CDB path.
566 // All the detector objects are then collected,
567 // sorted by geometry level (starting from ALIC) and
568 // then applied to the TGeo geometry.
569 // Finally an overlaps check is performed.
571 // Load alignment data from CDB and fill fAlignObjArray
572 if(fLoadAlignFromCDB){
574 TString detStr = detectors;
575 TString loadAlObjsListOfDets = "";
577 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
578 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
579 loadAlObjsListOfDets += fgkDetectorName[iDet];
580 loadAlObjsListOfDets += " ";
581 } // end loop over detectors
582 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
583 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
585 // Check if the array with alignment objects was
586 // provided by the user. If yes, apply the objects
587 // to the present TGeo geometry
588 if (fAlignObjArray) {
589 if (gGeoManager && gGeoManager->IsClosed()) {
590 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
591 AliError("The misalignment of one or more volumes failed!"
592 "Compare the list of simulated detectors and the list of detector alignment data!");
597 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
603 delete fAlignObjArray; fAlignObjArray=0;
608 //_____________________________________________________________________________
609 void AliReconstruction::SetGAliceFile(const char* fileName)
611 // set the name of the galice file
613 fGAliceFileName = fileName;
616 //_____________________________________________________________________________
617 void AliReconstruction::SetInput(const char* input)
619 // In case the input string starts with 'mem://', we run in an online mode
620 // and AliRawReaderDateOnline object is created. In all other cases a raw-data
621 // file is assumed. One can give as an input:
622 // mem://: - events taken from DAQ monitoring libs online
624 // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
628 //_____________________________________________________________________________
629 void AliReconstruction::SetOption(const char* detector, const char* option)
631 // set options for the reconstruction of a detector
633 TObject* obj = fOptions.FindObject(detector);
634 if (obj) fOptions.Remove(obj);
635 fOptions.Add(new TNamed(detector, option));
638 //_____________________________________________________________________________
639 Bool_t AliReconstruction::Run(const char* input)
642 AliCodeTimerAuto("");
644 if (!InitRun(input)) return kFALSE;
646 //******* The loop over events
648 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
649 (fRawReader && fRawReader->NextEvent())) {
650 if (!RunEvent(iEvent)) return kFALSE;
654 if (!FinishRun()) return kFALSE;
659 //_____________________________________________________________________________
660 Bool_t AliReconstruction::InitRun(const char* input)
662 // Initialize all the stuff before
663 // going into the event loop
664 // If the second argument is given, the first one is ignored and
665 // the reconstruction works in an online mode
666 AliCodeTimerAuto("");
668 // Overwrite the previous setting
669 if (input) fInput = input;
671 // set the input in case of raw data
672 fRawReader = AliRawReader::Create(fInput.Data());
674 AliInfo("Reconstruction will run over digits");
676 if (!fEquipIdMap.IsNull() && fRawReader)
677 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
679 if (!fUseHLTData.IsNull()) {
680 // create the RawReaderHLT which performs redirection of HLT input data for
681 // the specified detectors
682 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
684 fParentRawReader=fRawReader;
685 fRawReader=pRawReader;
687 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
691 AliSysInfo::AddStamp("Start");
692 // get the run loader
693 if (!InitRunLoader()) return kFALSE;
694 AliSysInfo::AddStamp("LoadLoader");
696 // Initialize the CDB storage
699 AliSysInfo::AddStamp("LoadCDB");
701 // Set run number in CDBManager (if it is not already set by the user)
702 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
704 // Set CDB lock: from now on it is forbidden to reset the run number
705 // or the default storage or to activate any further storage!
708 // Import ideal TGeo geometry and apply misalignment
710 TString geom(gSystem->DirName(fGAliceFileName));
711 geom += "/geometry.root";
712 AliGeomManager::LoadGeometry(geom.Data());
713 if (!gGeoManager) if (fStopOnError) return kFALSE;
716 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
717 AliSysInfo::AddStamp("LoadGeom");
720 AliQADataMakerSteer qas ;
721 if (fRunQA && fRawReader) {
722 qas.Run(fRunLocalReconstruction, fRawReader) ;
723 fSameQACycle = kTRUE ;
725 // checking the QA of previous steps
729 // local reconstruction
730 if (!fRunLocalReconstruction.IsNull()) {
731 if (!RunLocalReconstruction(fRunLocalReconstruction)) {
732 if (fStopOnError) {CleanUp(); return kFALSE;}
738 if (fRunVertexFinder && !CreateVertexer()) {
744 AliSysInfo::AddStamp("Vertexer");
747 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
753 AliSysInfo::AddStamp("LoadTrackers");
755 // get the possibly already existing ESD file and tree
756 fesd = new AliESDEvent(); fhltesd = new AliESDEvent();
757 if (!gSystem->AccessPathName("AliESDs.root")){
758 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
759 ffileOld = TFile::Open("AliESDs.old.root");
760 if (ffileOld && ffileOld->IsOpen()) {
761 ftreeOld = (TTree*) ffileOld->Get("esdTree");
762 if (ftreeOld)fesd->ReadFromTree(ftreeOld);
763 fhlttreeOld = (TTree*) ffileOld->Get("HLTesdTree");
764 if (fhlttreeOld) fhltesd->ReadFromTree(fhlttreeOld);
768 // create the ESD output file and tree
769 ffile = TFile::Open("AliESDs.root", "RECREATE");
770 ffile->SetCompressionLevel(2);
771 if (!ffile->IsOpen()) {
772 AliError("opening AliESDs.root failed");
773 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
776 ftree = new TTree("esdTree", "Tree with ESD objects");
777 fesd = new AliESDEvent();
778 fesd->CreateStdContent();
779 fesd->WriteToTree(ftree);
781 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
782 fhltesd = new AliESDEvent();
783 fhltesd->CreateStdContent();
784 fhltesd->WriteToTree(fhlttree);
787 delete esd; delete hltesd;
788 esd = NULL; hltesd = NULL;
790 // create the branch with ESD additions
794 if (fWriteESDfriend) {
795 fesdf = new AliESDfriend();
796 TBranch *br=ftree->Branch("ESDfriend.","AliESDfriend", &fesdf);
797 br->SetFile("AliESDfriends.root");
798 fesd->AddObject(fesdf);
802 // Get the GRP CDB entry
803 AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
806 fGRPList = dynamic_cast<TList*> (entryGRP->GetObject());
808 AliError("No GRP entry found in OCDB!");
811 // Get the diamond profile from OCDB
812 AliCDBEntry* entry = AliCDBManager::Instance()
813 ->Get("GRP/Calib/MeanVertex");
816 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
818 AliError("No diamond profile found in OCDB!");
822 entry = AliCDBManager::Instance()
823 ->Get("GRP/Calib/MeanVertexTPC");
826 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
828 AliError("No diamond profile found in OCDB!");
831 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
832 if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
834 if (fRawReader) fRawReader->RewindEvents();
837 gSystem->GetProcInfo(&ProcInfo);
838 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
841 //Initialize the QA and start of cycle for out-of-cycle QA
843 TString detStr(fFillESD);
844 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
845 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
846 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
848 AliInfo(Form("Initializing the QA data maker for %s",
849 fgkDetectorName[iDet]));
850 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
851 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
853 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
854 qadm->StartOfCycle(AliQA::kESDS,"same");
858 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
859 AliInfo(Form("Initializing the global QA data maker"));
861 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
862 AliTracker::SetResidualsArray(arr);
863 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
865 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
866 qadm->StartOfCycle(AliQA::kESDS, "same");
870 fSameQACycle = kTRUE;
873 //Initialize the Plane Efficiency framework
874 if (fRunPlaneEff && !InitPlaneEff()) {
875 if(fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
881 //_____________________________________________________________________________
882 Bool_t AliReconstruction::RunEvent(Int_t iEvent)
884 // run the reconstruction over a single event
885 // The event loop is steered in Run method
887 AliCodeTimerAuto("");
889 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
890 fRunLoader->SetEventNumber(iEvent);
891 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
893 //?? fRunLoader->MakeTree("H");
894 fRunLoader->TreeE()->Fill();
897 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
898 // copy old ESD to the new one
900 fesd->ReadFromTree(ftreeOld);
901 ftreeOld->GetEntry(iEvent);
905 fesd->ReadFromTree(fhlttreeOld);
906 fhlttreeOld->GetEntry(iEvent);
912 AliInfo(Form("processing event %d", iEvent));
914 //Start of cycle for the in-loop QA
917 TString detStr(fFillESD);
918 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
919 if (!IsSelected(fgkDetectorName[iDet], detStr))
921 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
924 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
925 qadm->StartOfCycle(AliQA::kESDS, "same") ;
928 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
929 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
930 qadm->StartOfCycle(AliQA::kESDS, "same");
935 fRunLoader->GetEvent(iEvent);
938 sprintf(aFileName, "ESD_%d.%d_final.root",
939 fRunLoader->GetHeader()->GetRun(),
940 fRunLoader->GetHeader()->GetEventNrInRun());
941 if (!gSystem->AccessPathName(aFileName)) return kTRUE;
943 // local signle event reconstruction
944 if (!fRunLocalReconstruction.IsNull()) {
945 if (!RunLocalEventReconstruction(fRunLocalReconstruction)) {
946 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
950 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
951 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
952 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
953 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
955 // Set magnetic field from the tracker
956 fesd->SetMagneticField(AliTracker::GetBz());
957 fhltesd->SetMagneticField(AliTracker::GetBz());
961 // Fill raw-data error log into the ESD
962 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
965 if (fRunVertexFinder) {
966 if (!ReadESD(fesd, "vertex")) {
967 if (!RunVertexFinder(fesd)) {
968 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
970 if (fCheckPointLevel > 0) WriteESD(fesd, "vertex");
975 if (!fRunTracking.IsNull()) {
976 if (fRunHLTTracking) {
977 fhltesd->SetPrimaryVertexSPD(fesd->GetVertex());
978 if (!RunHLTTracking(fhltesd)) {
979 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
985 if (!fRunTracking.IsNull()) {
986 if (fRunMuonTracking) {
987 if (!RunMuonTracking(fesd)) {
988 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
994 if (!fRunTracking.IsNull()) {
995 if (!ReadESD(fesd, "tracking")) {
996 if (!RunTracking(fesd)) {
997 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
999 if (fCheckPointLevel > 0) WriteESD(fesd, "tracking");
1004 if (!fFillESD.IsNull()) {
1005 if (!FillESD(fesd, fFillESD)) {
1006 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1010 // fill Event header information from the RawEventHeader
1011 if (fRawReader){FillRawEventHeaderESD(fesd);}
1014 AliESDpid::MakePID(fesd);
1015 if (fCheckPointLevel > 1) WriteESD(fesd, "PID");
1017 if (fFillTriggerESD) {
1018 if (!ReadESD(fesd, "trigger")) {
1019 if (!FillTriggerESD(fesd)) {
1020 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1022 if (fCheckPointLevel > 1) WriteESD(fesd, "trigger");
1029 // Propagate track to the beam pipe (if not laready done by ITS)
1031 const Int_t ntracks = fesd->GetNumberOfTracks();
1032 const Double_t kBz = fesd->GetMagneticField();
1033 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1036 UShort_t *selectedIdx=new UShort_t[ntracks];
1038 for (Int_t itrack=0; itrack<ntracks; itrack++){
1039 const Double_t kMaxStep = 5; //max step over the material
1042 AliESDtrack *track = fesd->GetTrack(itrack);
1043 if (!track) continue;
1045 AliExternalTrackParam *tpcTrack =
1046 (AliExternalTrackParam *)track->GetTPCInnerParam();
1050 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
1055 Int_t n=trkArray.GetEntriesFast();
1056 selectedIdx[n]=track->GetID();
1057 trkArray.AddLast(tpcTrack);
1060 if (track->GetX() < kRadius) continue;
1063 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1065 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kRadius);
1070 // Improve the reconstructed primary vertex position using the tracks
1072 TObject *obj = fOptions.FindObject("ITS");
1074 TString optITS = obj->GetTitle();
1075 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
1076 fRunVertexFinderTracks=kFALSE;
1078 if (fRunVertexFinderTracks) {
1079 // TPC + ITS primary vertex
1080 ftVertexer->SetITSrefitRequired();
1081 if(fDiamondProfile && fMeanVertexConstraint) {
1082 ftVertexer->SetVtxStart(fDiamondProfile);
1084 ftVertexer->SetConstraintOff();
1086 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
1088 if (pvtx->GetStatus()) {
1089 fesd->SetPrimaryVertex(pvtx);
1090 for (Int_t i=0; i<ntracks; i++) {
1091 AliESDtrack *t = fesd->GetTrack(i);
1092 t->RelateToVertex(pvtx, kBz, kRadius);
1097 // TPC-only primary vertex
1098 ftVertexer->SetITSrefitNotRequired();
1099 if(fDiamondProfileTPC && fMeanVertexConstraint) {
1100 ftVertexer->SetVtxStart(fDiamondProfileTPC);
1102 ftVertexer->SetConstraintOff();
1104 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
1106 if (pvtx->GetStatus()) {
1107 fesd->SetPrimaryVertexTPC(pvtx);
1108 Int_t nsel=trkArray.GetEntriesFast();
1109 for (Int_t i=0; i<nsel; i++) {
1110 AliExternalTrackParam *t =
1111 (AliExternalTrackParam *)trkArray.UncheckedAt(i);
1112 t->PropagateToDCA(pvtx, kBz, kRadius);
1118 delete[] selectedIdx;
1120 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
1125 AliV0vertexer vtxer;
1126 vtxer.Tracks2V0vertices(fesd);
1128 if (fRunCascadeFinder) {
1130 AliCascadeVertexer cvtxer;
1131 cvtxer.V0sTracks2CascadeVertices(fesd);
1136 if (fCleanESD) CleanESD(fesd);
1140 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1141 if (qadm) qadm->Exec(AliQA::kESDS, fesd);
1145 if (fWriteESDfriend) {
1146 fesdf->~AliESDfriend();
1147 new (fesdf) AliESDfriend(); // Reset...
1148 fesd->GetESDfriend(fesdf);
1155 if (fCheckPointLevel > 0) WriteESD(fesd, "final");
1158 if (fWriteESDfriend) {
1159 fesdf->~AliESDfriend();
1160 new (fesdf) AliESDfriend(); // Reset...
1163 ProcInfo_t ProcInfo;
1164 gSystem->GetProcInfo(&ProcInfo);
1165 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
1168 // End of cycle for the in-loop QA
1171 RunQA(fFillESD.Data(), fesd);
1172 TString detStr(fFillESD);
1173 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1174 if (!IsSelected(fgkDetectorName[iDet], detStr))
1176 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1179 qadm->EndOfCycle(AliQA::kRECPOINTS);
1180 qadm->EndOfCycle(AliQA::kESDS);
1185 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1187 qadm->EndOfCycle(AliQA::kRECPOINTS);
1188 qadm->EndOfCycle(AliQA::kESDS);
1197 //_____________________________________________________________________________
1198 Bool_t AliReconstruction::FinishRun()
1201 // Called after the exit
1202 // from the event loop
1203 AliCodeTimerAuto("");
1205 if (fIsNewRunLoader) { // galice.root didn't exist
1206 fRunLoader->WriteHeader("OVERWRITE");
1207 fRunLoader->CdGAFile();
1208 fRunLoader->Write(0, TObject::kOverwrite);
1211 ftree->GetUserInfo()->Add(fesd);
1212 fhlttree->GetUserInfo()->Add(fhltesd);
1214 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1215 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1217 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1218 cdbMapCopy->SetOwner(1);
1219 cdbMapCopy->SetName("cdbMap");
1220 TIter iter(cdbMap->GetTable());
1223 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1224 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1225 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1226 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1229 TList *cdbListCopy = new TList();
1230 cdbListCopy->SetOwner(1);
1231 cdbListCopy->SetName("cdbList");
1233 TIter iter2(cdbList);
1236 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
1237 cdbListCopy->Add(new TObjString(id->ToString().Data()));
1240 ftree->GetUserInfo()->Add(cdbMapCopy);
1241 ftree->GetUserInfo()->Add(cdbListCopy);
1244 if(fESDPar.Contains("ESD.par")){
1245 AliInfo("Attaching ESD.par to Tree");
1246 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
1247 ftree->GetUserInfo()->Add(fn);
1253 if (fWriteESDfriend)
1254 ftree->SetBranchStatus("ESDfriend*",0);
1255 // we want to have only one tree version number
1256 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1259 // Finish with Plane Efficiency evaluation: before of CleanUp !!!
1260 if (fRunPlaneEff && !FinishPlaneEff()) {
1261 AliWarning("Finish PlaneEff evaluation failed");
1265 CleanUp(ffile, ffileOld);
1268 AliWarning("AOD creation not supported anymore during reconstruction. See ANALYSIS/AliAnalysisTaskESDfilter.cxx instead.");
1271 // Create tags for the events in the ESD tree (the ESD tree is always present)
1272 // In case of empty events the tags will contain dummy values
1273 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
1274 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPList);
1276 AliWarning("AOD tag creation not supported anymore during reconstruction.");
1279 //Finish QA and end of cycle for out-of-loop QA
1282 AliQADataMakerSteer qas;
1283 qas.Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS, fSameQACycle);
1285 qas.Run(fRunTracking.Data(), AliQA::kESDS, fSameQACycle);
1287 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1289 qadm->EndOfCycle(AliQA::kRECPOINTS);
1290 qadm->EndOfCycle(AliQA::kESDS);
1297 // Cleanup of CDB manager: cache and active storages!
1298 AliCDBManager::Instance()->ClearCache();
1304 //_____________________________________________________________________________
1305 Bool_t AliReconstruction::RunLocalReconstruction(const TString& /*detectors*/)
1307 // run the local reconstruction
1308 static Int_t eventNr=0;
1309 AliCodeTimerAuto("")
1311 // AliCDBManager* man = AliCDBManager::Instance();
1312 // Bool_t origCache = man->GetCacheFlag();
1314 // TString detStr = detectors;
1315 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1316 // if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1317 // AliReconstructor* reconstructor = GetReconstructor(iDet);
1318 // if (!reconstructor) continue;
1319 // if (reconstructor->HasLocalReconstruction()) continue;
1321 // AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1322 // AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1324 // AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1325 // AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1327 // man->SetCacheFlag(kTRUE);
1328 // TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
1329 // man->GetAll(calibPath); // entries are cached!
1331 // AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1333 // if (fRawReader) {
1334 // fRawReader->RewindEvents();
1335 // reconstructor->Reconstruct(fRunLoader, fRawReader);
1337 // reconstructor->Reconstruct(fRunLoader);
1340 // AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1341 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
1343 // // unload calibration data
1344 // man->UnloadFromCache(calibPath);
1345 // //man->ClearCache();
1348 // man->SetCacheFlag(origCache);
1350 // if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1351 // AliError(Form("the following detectors were not found: %s",
1353 // if (fStopOnError) return kFALSE;
1360 //_____________________________________________________________________________
1361 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1363 // run the local reconstruction
1365 static Int_t eventNr=0;
1366 AliCodeTimerAuto("")
1368 TString detStr = detectors;
1369 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1370 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1371 AliReconstructor* reconstructor = GetReconstructor(iDet);
1372 if (!reconstructor) continue;
1373 AliLoader* loader = fLoader[iDet];
1375 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1378 // conversion of digits
1379 if (fRawReader && reconstructor->HasDigitConversion()) {
1380 AliInfo(Form("converting raw data digits into root objects for %s",
1381 fgkDetectorName[iDet]));
1382 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1383 fgkDetectorName[iDet]));
1384 loader->LoadDigits("update");
1385 loader->CleanDigits();
1386 loader->MakeDigitsContainer();
1387 TTree* digitsTree = loader->TreeD();
1388 reconstructor->ConvertDigits(fRawReader, digitsTree);
1389 loader->WriteDigits("OVERWRITE");
1390 loader->UnloadDigits();
1392 // local reconstruction
1393 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1394 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1395 loader->LoadRecPoints("update");
1396 loader->CleanRecPoints();
1397 loader->MakeRecPointsContainer();
1398 TTree* clustersTree = loader->TreeR();
1399 if (fRawReader && !reconstructor->HasDigitConversion()) {
1400 reconstructor->Reconstruct(fRawReader, clustersTree);
1402 loader->LoadDigits("read");
1403 TTree* digitsTree = loader->TreeD();
1405 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1406 if (fStopOnError) return kFALSE;
1408 reconstructor->Reconstruct(digitsTree, clustersTree);
1410 loader->UnloadDigits();
1413 // In-loop QA for local reconstrucion
1414 if (fRunQA && fInLoopQA) {
1415 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1418 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1420 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1422 qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
1425 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1429 loader->WriteRecPoints("OVERWRITE");
1430 loader->UnloadRecPoints();
1431 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1434 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1435 AliError(Form("the following detectors were not found: %s",
1437 if (fStopOnError) return kFALSE;
1443 //_____________________________________________________________________________
1444 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
1446 // run the barrel tracking
1448 AliCodeTimerAuto("")
1450 AliESDVertex* vertex = NULL;
1451 Double_t vtxPos[3] = {0, 0, 0};
1452 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1453 TArrayF mcVertex(3);
1454 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1455 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1456 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1460 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1461 AliInfo("running the ITS vertex finder");
1462 if (fLoader[0]) fLoader[0]->LoadRecPoints();
1463 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
1464 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
1466 AliWarning("Vertex not found");
1467 vertex = new AliESDVertex();
1468 vertex->SetName("default");
1471 vertex->SetName("reconstructed");
1475 AliInfo("getting the primary vertex from MC");
1476 vertex = new AliESDVertex(vtxPos, vtxErr);
1480 vertex->GetXYZ(vtxPos);
1481 vertex->GetSigmaXYZ(vtxErr);
1483 AliWarning("no vertex reconstructed");
1484 vertex = new AliESDVertex(vtxPos, vtxErr);
1486 esd->SetPrimaryVertexSPD(vertex);
1487 // if SPD multiplicity has been determined, it is stored in the ESD
1488 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1489 if(mult)esd->SetMultiplicity(mult);
1491 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1492 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1499 //_____________________________________________________________________________
1500 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1502 // run the HLT barrel tracking
1504 AliCodeTimerAuto("")
1507 AliError("Missing runLoader!");
1511 AliInfo("running HLT tracking");
1513 // Get a pointer to the HLT reconstructor
1514 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1515 if (!reconstructor) return kFALSE;
1518 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1519 TString detName = fgkDetectorName[iDet];
1520 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1521 reconstructor->SetOption(detName.Data());
1522 AliTracker *tracker = reconstructor->CreateTracker();
1524 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1525 if (fStopOnError) return kFALSE;
1529 Double_t vtxErr[3]={0.005,0.005,0.010};
1530 const AliESDVertex *vertex = esd->GetVertex();
1531 vertex->GetXYZ(vtxPos);
1532 tracker->SetVertex(vtxPos,vtxErr);
1534 fLoader[iDet]->LoadRecPoints("read");
1535 TTree* tree = fLoader[iDet]->TreeR();
1537 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1540 tracker->LoadClusters(tree);
1542 if (tracker->Clusters2Tracks(esd) != 0) {
1543 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1547 tracker->UnloadClusters();
1555 //_____________________________________________________________________________
1556 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1558 // run the muon spectrometer tracking
1560 AliCodeTimerAuto("")
1563 AliError("Missing runLoader!");
1566 Int_t iDet = 7; // for MUON
1568 AliInfo("is running...");
1570 // Get a pointer to the MUON reconstructor
1571 AliReconstructor *reconstructor = GetReconstructor(iDet);
1572 if (!reconstructor) return kFALSE;
1575 TString detName = fgkDetectorName[iDet];
1576 AliDebug(1, Form("%s tracking", detName.Data()));
1577 AliTracker *tracker = reconstructor->CreateTracker();
1579 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1584 fLoader[iDet]->LoadRecPoints("read");
1586 tracker->LoadClusters(fLoader[iDet]->TreeR());
1588 Int_t rv = tracker->Clusters2Tracks(esd);
1592 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1596 fLoader[iDet]->UnloadRecPoints();
1598 tracker->UnloadClusters();
1606 //_____________________________________________________________________________
1607 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1609 // run the barrel tracking
1610 static Int_t eventNr=0;
1611 AliCodeTimerAuto("")
1613 AliInfo("running tracking");
1615 //Fill the ESD with the T0 info (will be used by the TOF)
1616 if (fReconstructor[11] && fLoader[11]) {
1617 fLoader[11]->LoadRecPoints("READ");
1618 TTree *treeR = fLoader[11]->TreeR();
1619 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1622 // pass 1: TPC + ITS inwards
1623 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1624 if (!fTracker[iDet]) continue;
1625 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1628 fLoader[iDet]->LoadRecPoints("read");
1629 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
1630 TTree* tree = fLoader[iDet]->TreeR();
1632 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1635 fTracker[iDet]->LoadClusters(tree);
1636 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1638 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1639 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1642 if (fCheckPointLevel > 1) {
1643 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1645 // preliminary PID in TPC needed by the ITS tracker
1647 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1648 AliESDpid::MakePID(esd);
1650 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
1653 // pass 2: ALL backwards
1655 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1656 if (!fTracker[iDet]) continue;
1657 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1660 if (iDet > 1) { // all except ITS, TPC
1662 fLoader[iDet]->LoadRecPoints("read");
1663 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
1664 tree = fLoader[iDet]->TreeR();
1666 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1669 fTracker[iDet]->LoadClusters(tree);
1670 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1674 if (iDet>1) // start filling residuals for the "outer" detectors
1675 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1677 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1678 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1681 if (fCheckPointLevel > 1) {
1682 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1686 if (iDet > 2) { // all except ITS, TPC, TRD
1687 fTracker[iDet]->UnloadClusters();
1688 fLoader[iDet]->UnloadRecPoints();
1690 // updated PID in TPC needed by the ITS tracker -MI
1692 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1693 AliESDpid::MakePID(esd);
1695 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1697 //stop filling residuals for the "outer" detectors
1698 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
1700 // write space-points to the ESD in case alignment data output
1702 if (fWriteAlignmentData)
1703 WriteAlignmentData(esd);
1705 // pass 3: TRD + TPC + ITS refit inwards
1707 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1708 if (!fTracker[iDet]) continue;
1709 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1712 if (iDet<2) // start filling residuals for TPC and ITS
1713 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1715 if (fTracker[iDet]->RefitInward(esd) != 0) {
1716 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1719 // run postprocessing
1720 if (fTracker[iDet]->PostProcess(esd) != 0) {
1721 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
1724 if (fCheckPointLevel > 1) {
1725 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1727 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1729 fTracker[iDet]->UnloadClusters();
1730 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
1731 fLoader[iDet]->UnloadRecPoints();
1732 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
1734 // stop filling residuals for TPC and ITS
1735 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
1741 //_____________________________________________________________________________
1742 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1744 // Remove the data which are not needed for the physics analysis.
1747 Int_t nTracks=esd->GetNumberOfTracks();
1748 Int_t nV0s=esd->GetNumberOfV0s();
1750 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
1752 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
1753 Bool_t rc=esd->Clean(cleanPars);
1755 nTracks=esd->GetNumberOfTracks();
1756 nV0s=esd->GetNumberOfV0s();
1758 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
1763 //_____________________________________________________________________________
1764 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1766 // fill the event summary data
1768 AliCodeTimerAuto("")
1769 static Int_t eventNr=0;
1770 TString detStr = detectors;
1772 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1773 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1774 AliReconstructor* reconstructor = GetReconstructor(iDet);
1775 if (!reconstructor) continue;
1776 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1777 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1778 TTree* clustersTree = NULL;
1779 if (fLoader[iDet]) {
1780 fLoader[iDet]->LoadRecPoints("read");
1781 clustersTree = fLoader[iDet]->TreeR();
1782 if (!clustersTree) {
1783 AliError(Form("Can't get the %s clusters tree",
1784 fgkDetectorName[iDet]));
1785 if (fStopOnError) return kFALSE;
1788 if (fRawReader && !reconstructor->HasDigitConversion()) {
1789 reconstructor->FillESD(fRawReader, clustersTree, esd);
1791 TTree* digitsTree = NULL;
1792 if (fLoader[iDet]) {
1793 fLoader[iDet]->LoadDigits("read");
1794 digitsTree = fLoader[iDet]->TreeD();
1796 AliError(Form("Can't get the %s digits tree",
1797 fgkDetectorName[iDet]));
1798 if (fStopOnError) return kFALSE;
1801 reconstructor->FillESD(digitsTree, clustersTree, esd);
1802 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1804 if (fLoader[iDet]) {
1805 fLoader[iDet]->UnloadRecPoints();
1808 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1812 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1813 AliError(Form("the following detectors were not found: %s",
1815 if (fStopOnError) return kFALSE;
1817 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
1822 //_____________________________________________________________________________
1823 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1825 // Reads the trigger decision which is
1826 // stored in Trigger.root file and fills
1827 // the corresponding esd entries
1829 AliCodeTimerAuto("")
1831 AliInfo("Filling trigger information into the ESD");
1833 AliCentralTrigger *aCTP = NULL;
1836 AliCTPRawStream input(fRawReader);
1837 if (!input.Next()) {
1838 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1841 esd->SetTriggerMask(input.GetClassMask());
1842 esd->SetTriggerCluster(input.GetClusterMask());
1844 aCTP = new AliCentralTrigger();
1845 TString configstr("");
1846 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
1847 AliError("No trigger configuration found in OCDB! The trigger classes information will no be stored in ESD!");
1853 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1855 if (!runloader->LoadTrigger()) {
1856 aCTP = runloader->GetTrigger();
1857 esd->SetTriggerMask(aCTP->GetClassMask());
1858 esd->SetTriggerCluster(aCTP->GetClusterMask());
1861 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1866 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1871 // Now fill the trigger class names into AliESDRun object
1872 AliTriggerConfiguration *config = aCTP->GetConfiguration();
1874 AliError("No trigger configuration has been found! The trigger classes information will no be stored in ESD!");
1875 if (fRawReader) delete aCTP;
1879 const TObjArray& classesArray = config->GetClasses();
1880 Int_t nclasses = classesArray.GetEntriesFast();
1881 for( Int_t j=0; j<nclasses; j++ ) {
1882 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
1883 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
1884 esd->SetTriggerClass(trclass->GetName(),trindex);
1887 if (fRawReader) delete aCTP;
1895 //_____________________________________________________________________________
1896 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1899 // Filling information from RawReader Header
1902 AliInfo("Filling information from RawReader Header");
1903 esd->SetBunchCrossNumber(0);
1904 esd->SetOrbitNumber(0);
1905 esd->SetPeriodNumber(0);
1906 esd->SetTimeStamp(0);
1907 esd->SetEventType(0);
1908 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1911 const UInt_t *id = eventHeader->GetP("Id");
1912 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1913 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1914 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1916 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1917 esd->SetEventType((eventHeader->Get("Type")));
1924 //_____________________________________________________________________________
1925 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
1927 // check whether detName is contained in detectors
1928 // if yes, it is removed from detectors
1930 // check if all detectors are selected
1931 if ((detectors.CompareTo("ALL") == 0) ||
1932 detectors.BeginsWith("ALL ") ||
1933 detectors.EndsWith(" ALL") ||
1934 detectors.Contains(" ALL ")) {
1939 // search for the given detector
1940 Bool_t result = kFALSE;
1941 if ((detectors.CompareTo(detName) == 0) ||
1942 detectors.BeginsWith(detName+" ") ||
1943 detectors.EndsWith(" "+detName) ||
1944 detectors.Contains(" "+detName+" ")) {
1945 detectors.ReplaceAll(detName, "");
1949 // clean up the detectors string
1950 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
1951 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
1952 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
1957 //_____________________________________________________________________________
1958 Bool_t AliReconstruction::InitRunLoader()
1960 // get or create the run loader
1962 if (gAlice) delete gAlice;
1965 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
1966 // load all base libraries to get the loader classes
1967 TString libs = gSystem->GetLibraries();
1968 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1969 TString detName = fgkDetectorName[iDet];
1970 if (detName == "HLT") continue;
1971 if (libs.Contains("lib" + detName + "base.so")) continue;
1972 gSystem->Load("lib" + detName + "base.so");
1974 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
1976 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
1980 fRunLoader->CdGAFile();
1981 if (gFile->GetKey(AliRunLoader::GetGAliceName())) {
1982 if (fRunLoader->LoadgAlice() == 0) {
1983 gAlice = fRunLoader->GetAliRun();
1984 AliTracker::SetFieldMap(gAlice->Field(),fUniformField);
1987 if (!gAlice && !fRawReader) {
1988 AliError(Form("no gAlice object found in file %s",
1989 fGAliceFileName.Data()));
1994 //PH This is a temporary fix to give access to the kinematics
1995 //PH that is needed for the labels of ITS clusters
1996 fRunLoader->LoadHeader();
1997 fRunLoader->LoadKinematics();
1999 } else { // galice.root does not exist
2001 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
2005 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2006 AliConfig::GetDefaultEventFolderName(),
2009 AliError(Form("could not create run loader in file %s",
2010 fGAliceFileName.Data()));
2014 fIsNewRunLoader = kTRUE;
2015 fRunLoader->MakeTree("E");
2017 if (fNumberOfEventsPerFile > 0)
2018 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2020 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
2026 //_____________________________________________________________________________
2027 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
2029 // get the reconstructor object and the loader for a detector
2031 if (fReconstructor[iDet]) return fReconstructor[iDet];
2033 // load the reconstructor object
2034 TPluginManager* pluginManager = gROOT->GetPluginManager();
2035 TString detName = fgkDetectorName[iDet];
2036 TString recName = "Ali" + detName + "Reconstructor";
2037 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT")) return NULL;
2039 AliReconstructor* reconstructor = NULL;
2040 // first check if a plugin is defined for the reconstructor
2041 TPluginHandler* pluginHandler =
2042 pluginManager->FindHandler("AliReconstructor", detName);
2043 // if not, add a plugin for it
2044 if (!pluginHandler) {
2045 AliDebug(1, Form("defining plugin for %s", recName.Data()));
2046 TString libs = gSystem->GetLibraries();
2047 if (libs.Contains("lib" + detName + "base.so") ||
2048 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2049 pluginManager->AddHandler("AliReconstructor", detName,
2050 recName, detName + "rec", recName + "()");
2052 pluginManager->AddHandler("AliReconstructor", detName,
2053 recName, detName, recName + "()");
2055 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2057 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2058 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
2060 if (reconstructor) {
2061 TObject* obj = fOptions.FindObject(detName.Data());
2062 if (obj) reconstructor->SetOption(obj->GetTitle());
2063 reconstructor->Init();
2064 fReconstructor[iDet] = reconstructor;
2067 // get or create the loader
2068 if (detName != "HLT") {
2069 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2070 if (!fLoader[iDet]) {
2071 AliConfig::Instance()
2072 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2074 // first check if a plugin is defined for the loader
2076 pluginManager->FindHandler("AliLoader", detName);
2077 // if not, add a plugin for it
2078 if (!pluginHandler) {
2079 TString loaderName = "Ali" + detName + "Loader";
2080 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2081 pluginManager->AddHandler("AliLoader", detName,
2082 loaderName, detName + "base",
2083 loaderName + "(const char*, TFolder*)");
2084 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2086 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2088 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2089 fRunLoader->GetEventFolder());
2091 if (!fLoader[iDet]) { // use default loader
2092 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2094 if (!fLoader[iDet]) {
2095 AliWarning(Form("couldn't get loader for %s", detName.Data()));
2096 if (fStopOnError) return NULL;
2098 fRunLoader->AddLoader(fLoader[iDet]);
2099 fRunLoader->CdGAFile();
2100 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2101 fRunLoader->Write(0, TObject::kOverwrite);
2106 return reconstructor;
2109 //_____________________________________________________________________________
2110 Bool_t AliReconstruction::CreateVertexer()
2112 // create the vertexer
2115 AliReconstructor* itsReconstructor = GetReconstructor(0);
2116 if (itsReconstructor) {
2117 fVertexer = itsReconstructor->CreateVertexer();
2120 AliWarning("couldn't create a vertexer for ITS");
2121 if (fStopOnError) return kFALSE;
2127 //_____________________________________________________________________________
2128 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
2130 // create the trackers
2132 TString detStr = detectors;
2133 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2134 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2135 AliReconstructor* reconstructor = GetReconstructor(iDet);
2136 if (!reconstructor) continue;
2137 TString detName = fgkDetectorName[iDet];
2138 if (detName == "HLT") {
2139 fRunHLTTracking = kTRUE;
2142 if (detName == "MUON") {
2143 fRunMuonTracking = kTRUE;
2148 fTracker[iDet] = reconstructor->CreateTracker();
2149 if (!fTracker[iDet] && (iDet < 7)) {
2150 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2151 if (fStopOnError) return kFALSE;
2153 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
2159 //_____________________________________________________________________________
2160 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
2162 // delete trackers and the run loader and close and delete the file
2164 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2165 delete fReconstructor[iDet];
2166 fReconstructor[iDet] = NULL;
2167 fLoader[iDet] = NULL;
2168 delete fTracker[iDet];
2169 fTracker[iDet] = NULL;
2170 // delete fQADataMaker[iDet];
2171 // fQADataMaker[iDet] = NULL;
2176 if (ftVertexer) delete ftVertexer;
2179 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
2180 delete fDiamondProfile;
2181 fDiamondProfile = NULL;
2182 delete fDiamondProfileTPC;
2183 fDiamondProfileTPC = NULL;
2193 if (fParentRawReader) delete fParentRawReader;
2194 fParentRawReader=NULL;
2204 gSystem->Unlink("AliESDs.old.root");
2209 //_____________________________________________________________________________
2211 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
2213 // read the ESD event from a file
2215 if (!esd) return kFALSE;
2217 sprintf(fileName, "ESD_%d.%d_%s.root",
2218 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
2219 if (gSystem->AccessPathName(fileName)) return kFALSE;
2221 AliInfo(Form("reading ESD from file %s", fileName));
2222 AliDebug(1, Form("reading ESD from file %s", fileName));
2223 TFile* file = TFile::Open(fileName);
2224 if (!file || !file->IsOpen()) {
2225 AliError(Form("opening %s failed", fileName));
2232 esd = (AliESDEvent*) file->Get("ESD");
2241 //_____________________________________________________________________________
2242 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
2244 // write the ESD event to a file
2248 sprintf(fileName, "ESD_%d.%d_%s.root",
2249 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
2251 AliDebug(1, Form("writing ESD to file %s", fileName));
2252 TFile* file = TFile::Open(fileName, "recreate");
2253 if (!file || !file->IsOpen()) {
2254 AliError(Form("opening %s failed", fileName));
2263 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2265 // Write space-points which are then used in the alignment procedures
2266 // For the moment only ITS, TRD and TPC
2268 // Load TOF clusters
2270 fLoader[3]->LoadRecPoints("read");
2271 TTree* tree = fLoader[3]->TreeR();
2273 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2276 fTracker[3]->LoadClusters(tree);
2278 Int_t ntracks = esd->GetNumberOfTracks();
2279 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2281 AliESDtrack *track = esd->GetTrack(itrack);
2284 for (Int_t iDet = 3; iDet >= 0; iDet--)
2285 nsp += track->GetNcls(iDet);
2287 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2288 track->SetTrackPointArray(sp);
2290 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2291 AliTracker *tracker = fTracker[iDet];
2292 if (!tracker) continue;
2293 Int_t nspdet = track->GetNcls(iDet);
2294 if (nspdet <= 0) continue;
2295 track->GetClusters(iDet,idx);
2299 while (isp2 < nspdet) {
2301 TString dets = fgkDetectorName[iDet];
2302 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2303 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2304 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2305 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
2306 isvalid = tracker->GetTrackPointTrackingError(idx[isp2],p,track);
2308 isvalid = tracker->GetTrackPoint(idx[isp2],p);
2311 const Int_t kNTPCmax = 159;
2312 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2313 if (!isvalid) continue;
2314 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2320 fTracker[3]->UnloadClusters();
2321 fLoader[3]->UnloadRecPoints();
2325 //_____________________________________________________________________________
2326 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2328 // The method reads the raw-data error log
2329 // accumulated within the rawReader.
2330 // It extracts the raw-data errors related to
2331 // the current event and stores them into
2332 // a TClonesArray inside the esd object.
2334 if (!fRawReader) return;
2336 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2338 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2340 if (iEvent != log->GetEventNumber()) continue;
2342 esd->AddRawDataErrorLog(log);
2347 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString fName){
2348 // Dump a file content into a char in TNamed
2350 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2351 Int_t kBytes = (Int_t)in.tellg();
2352 printf("Size: %d \n",kBytes);
2355 char* memblock = new char [kBytes];
2356 in.seekg (0, ios::beg);
2357 in.read (memblock, kBytes);
2359 TString fData(memblock,kBytes);
2360 fn = new TNamed(fName,fData);
2361 printf("fData Size: %d \n",fData.Sizeof());
2362 printf("fName Size: %d \n",fName.Sizeof());
2363 printf("fn Size: %d \n",fn->Sizeof());
2367 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2373 void AliReconstruction::TNamedToFile(TTree* fTree, TString fName){
2374 // This is not really needed in AliReconstruction at the moment
2375 // but can serve as a template
2377 TList *fList = fTree->GetUserInfo();
2378 TNamed *fn = (TNamed*)fList->FindObject(fName.Data());
2379 printf("fn Size: %d \n",fn->Sizeof());
2381 TString fTmp(fn->GetName()); // to be 100% sure in principle fName also works
2382 const char* cdata = fn->GetTitle();
2383 printf("fTmp Size %d\n",fTmp.Sizeof());
2385 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2386 printf("calculated size %d\n",size);
2387 ofstream out(fName.Data(),ios::out | ios::binary);
2388 out.write(cdata,size);
2393 //_____________________________________________________________________________
2394 AliQADataMakerRec * AliReconstruction::GetQADataMaker(Int_t iDet)
2396 // get the quality assurance data maker object and the loader for a detector
2398 if (fQADataMaker[iDet])
2399 return fQADataMaker[iDet];
2401 AliQADataMakerRec * qadm = NULL;
2402 if (iDet == fgkNDetectors) { //Global QA
2403 qadm = new AliGlobalQADataMaker();
2404 fQADataMaker[iDet] = qadm;
2408 // load the QA data maker object
2409 TPluginManager* pluginManager = gROOT->GetPluginManager();
2410 TString detName = fgkDetectorName[iDet];
2411 TString qadmName = "Ali" + detName + "QADataMakerRec";
2412 if (gAlice && !gAlice->GetDetector(detName) && (detName != "HLT"))
2415 // first check if a plugin is defined for the quality assurance data maker
2416 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
2417 // if not, add a plugin for it
2418 if (!pluginHandler) {
2419 AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2420 TString libs = gSystem->GetLibraries();
2421 if (libs.Contains("lib" + detName + "base.so") ||
2422 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2423 pluginManager->AddHandler("AliQADataMakerRec", detName,
2424 qadmName, detName + "qadm", qadmName + "()");
2426 pluginManager->AddHandler("AliQADataMakerRec", detName,
2427 qadmName, detName, qadmName + "()");
2429 pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
2431 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2432 qadm = (AliQADataMakerRec *) pluginHandler->ExecPlugin(0);
2435 fQADataMaker[iDet] = qadm;
2440 //_____________________________________________________________________________
2441 Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
2443 // run the Quality Assurance data producer
2445 AliCodeTimerAuto("")
2446 TString detStr = detectors;
2447 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2448 if (!IsSelected(fgkDetectorName[iDet], detStr))
2450 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
2453 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2454 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2456 qadm->Exec(AliQA::kESDS, esd) ;
2459 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2461 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2462 AliError(Form("the following detectors were not found: %s",
2472 //_____________________________________________________________________________
2473 void AliReconstruction::CheckQA()
2475 // check the QA of SIM for this run and remove the detectors
2476 // with status Fatal
2478 TString newRunLocalReconstruction ;
2479 TString newRunTracking ;
2480 TString newFillESD ;
2482 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2483 TString detName(AliQA::GetDetName(iDet)) ;
2484 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2485 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
2486 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
2488 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2489 fRunLocalReconstruction.Contains("ALL") ) {
2490 newRunLocalReconstruction += detName ;
2491 newRunLocalReconstruction += " " ;
2493 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2494 fRunTracking.Contains("ALL") ) {
2495 newRunTracking += detName ;
2496 newRunTracking += " " ;
2498 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2499 fFillESD.Contains("ALL") ) {
2500 newFillESD += detName ;
2505 fRunLocalReconstruction = newRunLocalReconstruction ;
2506 fRunTracking = newRunTracking ;
2507 fFillESD = newFillESD ;
2510 //_____________________________________________________________________________
2511 Int_t AliReconstruction::GetDetIndex(const char* detector)
2513 // return the detector index corresponding to detector
2515 for (index = 0; index < fgkNDetectors ; index++) {
2516 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2521 //_____________________________________________________________________________
2522 Bool_t AliReconstruction::FinishPlaneEff() {
2524 // Here execute all the necessary operationis, at the end of the tracking phase,
2525 // in case that evaluation of PlaneEfficiencies was required for some detector.
2526 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
2528 // This Preliminary version works only FOR ITS !!!!!
2529 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2532 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2535 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2536 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
2537 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2538 if(fTracker[iDet]) {
2539 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2540 ret=planeeff->WriteIntoCDB();
2541 if(planeeff->GetCreateHistos()) {
2542 TString name="PlaneEffHisto";
2543 name+=fgkDetectorName[iDet];
2545 ret*=planeeff->WriteHistosToFile(name,"RECREATE");
2551 //_____________________________________________________________________________
2552 Bool_t AliReconstruction::InitPlaneEff() {
2554 // Here execute all the necessary operations, before of the tracking phase,
2555 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2556 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2557 // which should be updated/recalculated.
2559 // This Preliminary version will work only FOR ITS !!!!!
2560 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2563 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2565 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));