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>
134 #include "AliReconstruction.h"
135 #include "AliCodeTimer.h"
136 #include "AliReconstructor.h"
138 #include "AliRunLoader.h"
140 #include "AliRawReaderFile.h"
141 #include "AliRawReaderDate.h"
142 #include "AliRawReaderRoot.h"
143 #include "AliRawEventHeaderBase.h"
144 #include "AliESDEvent.h"
145 #include "AliESDMuonTrack.h"
146 #include "AliESDfriend.h"
147 #include "AliESDVertex.h"
148 #include "AliESDcascade.h"
149 #include "AliESDkink.h"
150 #include "AliESDtrack.h"
151 #include "AliESDCaloCluster.h"
152 #include "AliESDCaloCells.h"
153 #include "AliMultiplicity.h"
154 #include "AliTracker.h"
155 #include "AliVertexer.h"
156 #include "AliVertexerTracks.h"
157 #include "AliV0vertexer.h"
158 #include "AliCascadeVertexer.h"
159 #include "AliHeader.h"
160 #include "AliGenEventHeader.h"
162 #include "AliESDpid.h"
163 #include "AliESDtrack.h"
164 #include "AliESDPmdTrack.h"
166 #include "AliESDTagCreator.h"
167 #include "AliAODTagCreator.h"
169 #include "AliGeomManager.h"
170 #include "AliTrackPointArray.h"
171 #include "AliCDBManager.h"
172 #include "AliCDBStorage.h"
173 #include "AliCDBEntry.h"
174 #include "AliAlignObj.h"
176 #include "AliCentralTrigger.h"
177 #include "AliTriggerConfiguration.h"
178 #include "AliTriggerClass.h"
179 #include "AliCTPRawStream.h"
181 #include "AliQADataMakerRec.h"
182 #include "AliGlobalQADataMaker.h"
184 #include "AliQADataMakerSteer.h"
186 #include "AliPlaneEff.h"
188 #include "AliSysInfo.h" // memory snapshots
189 #include "AliRawHLTManager.h"
191 #include "AliMagWrapCheb.h"
193 ClassImp(AliReconstruction)
196 //_____________________________________________________________________________
197 const char* AliReconstruction::fgkDetectorName[AliReconstruction::fgkNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE", "HLT"};
199 //_____________________________________________________________________________
200 AliReconstruction::AliReconstruction(const char* gAliceFilename,
201 const char* name, const char* title) :
204 fUniformField(kFALSE),
205 fRunVertexFinder(kTRUE),
206 fRunVertexFinderTracks(kTRUE),
207 fRunHLTTracking(kFALSE),
208 fRunMuonTracking(kFALSE),
210 fRunCascadeFinder(kTRUE),
211 fStopOnError(kFALSE),
212 fWriteAlignmentData(kFALSE),
213 fWriteESDfriend(kFALSE),
215 fFillTriggerESD(kTRUE),
223 fRunLocalReconstruction("ALL"),
226 fUseTrackingErrorsForAlignment(""),
227 fGAliceFileName(gAliceFilename),
232 fNumberOfEventsPerFile(1),
235 fLoadAlignFromCDB(kTRUE),
236 fLoadAlignData("ALL"),
242 fParentRawReader(NULL),
245 fDiamondProfile(NULL),
246 fDiamondProfileTPC(NULL),
247 fMeanVertexConstraint(kTRUE),
251 fAlignObjArray(NULL),
254 fInitCDBCalled(kFALSE),
255 fSetRunNumberFromDataCalled(kFALSE),
259 fSameQACycle(kFALSE),
261 fRunPlaneEff(kFALSE),
273 fIsNewRunLoader(kFALSE),
276 // create reconstruction object with default parameters
278 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
279 fReconstructor[iDet] = NULL;
280 fLoader[iDet] = NULL;
281 fTracker[iDet] = NULL;
282 fQADataMaker[iDet] = NULL;
283 fQACycles[iDet] = 999999;
285 fQADataMaker[fgkNDetectors]=NULL; //Global QA
289 //_____________________________________________________________________________
290 AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
293 fUniformField(rec.fUniformField),
294 fRunVertexFinder(rec.fRunVertexFinder),
295 fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
296 fRunHLTTracking(rec.fRunHLTTracking),
297 fRunMuonTracking(rec.fRunMuonTracking),
298 fRunV0Finder(rec.fRunV0Finder),
299 fRunCascadeFinder(rec.fRunCascadeFinder),
300 fStopOnError(rec.fStopOnError),
301 fWriteAlignmentData(rec.fWriteAlignmentData),
302 fWriteESDfriend(rec.fWriteESDfriend),
303 fWriteAOD(rec.fWriteAOD),
304 fFillTriggerESD(rec.fFillTriggerESD),
306 fCleanESD(rec.fCleanESD),
307 fV0DCAmax(rec.fV0DCAmax),
308 fV0CsPmin(rec.fV0CsPmin),
312 fRunLocalReconstruction(rec.fRunLocalReconstruction),
313 fRunTracking(rec.fRunTracking),
314 fFillESD(rec.fFillESD),
315 fUseTrackingErrorsForAlignment(rec.fUseTrackingErrorsForAlignment),
316 fGAliceFileName(rec.fGAliceFileName),
318 fEquipIdMap(rec.fEquipIdMap),
319 fFirstEvent(rec.fFirstEvent),
320 fLastEvent(rec.fLastEvent),
321 fNumberOfEventsPerFile(rec.fNumberOfEventsPerFile),
324 fLoadAlignFromCDB(rec.fLoadAlignFromCDB),
325 fLoadAlignData(rec.fLoadAlignData),
326 fESDPar(rec.fESDPar),
327 fUseHLTData(rec.fUseHLTData),
331 fParentRawReader(NULL),
334 fDiamondProfile(NULL),
335 fDiamondProfileTPC(NULL),
336 fMeanVertexConstraint(rec.fMeanVertexConstraint),
340 fAlignObjArray(rec.fAlignObjArray),
341 fCDBUri(rec.fCDBUri),
343 fInitCDBCalled(rec.fInitCDBCalled),
344 fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
346 fRunGlobalQA(rec.fRunGlobalQA),
347 fInLoopQA(rec.fInLoopQA),
348 fSameQACycle(rec.fSameQACycle),
349 fRunPlaneEff(rec.fRunPlaneEff),
361 fIsNewRunLoader(rec.fIsNewRunLoader),
366 for (Int_t i = 0; i < rec.fOptions.GetEntriesFast(); i++) {
367 if (rec.fOptions[i]) fOptions.Add(rec.fOptions[i]->Clone());
369 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
370 fReconstructor[iDet] = NULL;
371 fLoader[iDet] = NULL;
372 fTracker[iDet] = NULL;
373 fQADataMaker[iDet] = NULL;
374 fQACycles[iDet] = rec.fQACycles[iDet];
376 fQADataMaker[fgkNDetectors]=NULL; //Global QA
377 for (Int_t i = 0; i < rec.fSpecCDBUri.GetEntriesFast(); i++) {
378 if (rec.fSpecCDBUri[i]) fSpecCDBUri.Add(rec.fSpecCDBUri[i]->Clone());
382 //_____________________________________________________________________________
383 AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
385 // assignment operator
387 this->~AliReconstruction();
388 new(this) AliReconstruction(rec);
392 //_____________________________________________________________________________
393 AliReconstruction::~AliReconstruction()
399 fSpecCDBUri.Delete();
401 AliCodeTimer::Instance()->Print();
404 //_____________________________________________________________________________
405 void AliReconstruction::InitCDB()
407 // activate a default CDB storage
408 // First check if we have any CDB storage set, because it is used
409 // to retrieve the calibration and alignment constants
411 if (fInitCDBCalled) return;
412 fInitCDBCalled = kTRUE;
414 AliCDBManager* man = AliCDBManager::Instance();
415 if (man->IsDefaultStorageSet())
417 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
418 AliWarning("Default CDB storage has been already set !");
419 AliWarning(Form("Ignoring the default storage declared in AliReconstruction: %s",fCDBUri.Data()));
420 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
421 fCDBUri = man->GetDefaultStorage()->GetURI();
424 if (fCDBUri.Length() > 0)
426 AliDebug(2,"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
427 AliDebug(2, Form("Default CDB storage is set to: %s", fCDBUri.Data()));
428 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
430 fCDBUri="local://$ALICE_ROOT";
431 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
432 AliWarning("Default CDB storage not yet set !!!!");
433 AliWarning(Form("Setting it now to: %s", fCDBUri.Data()));
434 AliWarning("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
437 man->SetDefaultStorage(fCDBUri);
440 // Now activate the detector specific CDB storage locations
441 for (Int_t i = 0; i < fSpecCDBUri.GetEntriesFast(); i++) {
442 TObject* obj = fSpecCDBUri[i];
444 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
445 AliDebug(2, Form("Specific CDB storage for %s is set to: %s",obj->GetName(),obj->GetTitle()));
446 AliDebug(2, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
447 man->SetSpecificStorage(obj->GetName(), obj->GetTitle());
452 //_____________________________________________________________________________
453 void AliReconstruction::SetDefaultStorage(const char* uri) {
454 // Store the desired default CDB storage location
455 // Activate it later within the Run() method
461 //_____________________________________________________________________________
462 void AliReconstruction::SetSpecificStorage(const char* calibType, const char* uri) {
463 // Store a detector-specific CDB storage location
464 // Activate it later within the Run() method
466 AliCDBPath aPath(calibType);
467 if(!aPath.IsValid()){
468 // if calibType is not wildcard but it is a valid detector, add "/*" to make it a valid path
469 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
470 if(!strcmp(calibType, fgkDetectorName[iDet])) {
471 aPath.SetPath(Form("%s/*", calibType));
472 AliInfo(Form("Path for specific storage set to %s", aPath.GetPath().Data()));
476 if(!aPath.IsValid()){
477 AliError(Form("Not a valid path or detector: %s", calibType));
482 // // check that calibType refers to a "valid" detector name
483 // Bool_t isDetector = kFALSE;
484 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
485 // TString detName = fgkDetectorName[iDet];
486 // if(aPath.GetLevel0() == detName) {
487 // isDetector = kTRUE;
493 // AliError(Form("Not a valid detector: %s", aPath.GetLevel0().Data()));
497 TObject* obj = fSpecCDBUri.FindObject(aPath.GetPath().Data());
498 if (obj) fSpecCDBUri.Remove(obj);
499 fSpecCDBUri.Add(new TNamed(aPath.GetPath().Data(), uri));
503 //_____________________________________________________________________________
504 Bool_t AliReconstruction::SetRunNumberFromData()
506 // The method is called in Run() in order
507 // to set a correct run number.
508 // In case of raw data reconstruction the
509 // run number is taken from the raw data header
511 if (fSetRunNumberFromDataCalled) return kTRUE;
512 fSetRunNumberFromDataCalled = kTRUE;
514 AliCDBManager* man = AliCDBManager::Instance();
516 if(man->GetRun() > 0) {
517 AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
521 AliError("No run loader is found !");
524 // read run number from gAlice
525 if(fRunLoader->GetAliRun())
526 AliCDBManager::Instance()->SetRun(fRunLoader->GetHeader()->GetRun());
529 if(fRawReader->NextEvent()) {
530 AliCDBManager::Instance()->SetRun(fRawReader->GetRunNumber());
531 fRawReader->RewindEvents();
534 if(man->GetRun() > 0) {
535 AliWarning("No raw events is found ! Using settings in AliCDBManager !");
540 AliWarning("Neither raw events nor settings in AliCDBManager are found !");
546 AliError("Neither gAlice nor RawReader objects are found !");
556 //_____________________________________________________________________________
557 void AliReconstruction::SetCDBLock() {
558 // Set CDB lock: from now on it is forbidden to reset the run number
559 // or the default storage or to activate any further storage!
561 AliCDBManager::Instance()->SetLock(1);
564 //_____________________________________________________________________________
565 Bool_t AliReconstruction::MisalignGeometry(const TString& detectors)
567 // Read the alignment objects from CDB.
568 // Each detector is supposed to have the
569 // alignment objects in DET/Align/Data CDB path.
570 // All the detector objects are then collected,
571 // sorted by geometry level (starting from ALIC) and
572 // then applied to the TGeo geometry.
573 // Finally an overlaps check is performed.
575 // Load alignment data from CDB and fill fAlignObjArray
576 if(fLoadAlignFromCDB){
578 TString detStr = detectors;
579 TString loadAlObjsListOfDets = "";
581 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
582 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
583 loadAlObjsListOfDets += fgkDetectorName[iDet];
584 loadAlObjsListOfDets += " ";
585 } // end loop over detectors
586 loadAlObjsListOfDets.Prepend("GRP "); //add alignment objects for non-sensitive modules
587 AliGeomManager::ApplyAlignObjsFromCDB(loadAlObjsListOfDets.Data());
589 // Check if the array with alignment objects was
590 // provided by the user. If yes, apply the objects
591 // to the present TGeo geometry
592 if (fAlignObjArray) {
593 if (gGeoManager && gGeoManager->IsClosed()) {
594 if (AliGeomManager::ApplyAlignObjsToGeom(*fAlignObjArray) == kFALSE) {
595 AliError("The misalignment of one or more volumes failed!"
596 "Compare the list of simulated detectors and the list of detector alignment data!");
601 AliError("Can't apply the misalignment! gGeoManager doesn't exist or it is still opened!");
607 delete fAlignObjArray; fAlignObjArray=0;
612 //_____________________________________________________________________________
613 void AliReconstruction::SetGAliceFile(const char* fileName)
615 // set the name of the galice file
617 fGAliceFileName = fileName;
620 //_____________________________________________________________________________
621 void AliReconstruction::SetInput(const char* input)
623 // In case the input string starts with 'mem://', we run in an online mode
624 // and AliRawReaderDateOnline object is created. In all other cases a raw-data
625 // file is assumed. One can give as an input:
626 // mem://: - events taken from DAQ monitoring libs online
628 // mem://<filename> - emulation of the above mode (via DATE monitoring libs)
632 //_____________________________________________________________________________
633 void AliReconstruction::SetOption(const char* detector, const char* option)
635 // set options for the reconstruction of a detector
637 TObject* obj = fOptions.FindObject(detector);
638 if (obj) fOptions.Remove(obj);
639 fOptions.Add(new TNamed(detector, option));
642 //_____________________________________________________________________________
643 Bool_t AliReconstruction::Run(const char* input)
646 AliCodeTimerAuto("");
648 if (!InitRun(input)) return kFALSE;
650 //******* The loop over events
652 while ((iEvent < fRunLoader->GetNumberOfEvents()) ||
653 (fRawReader && fRawReader->NextEvent())) {
654 if (!RunEvent(iEvent)) return kFALSE;
658 if (!FinishRun()) return kFALSE;
663 //_____________________________________________________________________________
664 Bool_t AliReconstruction::InitRun(const char* input)
666 // Initialize all the stuff before
667 // going into the event loop
668 // If the second argument is given, the first one is ignored and
669 // the reconstruction works in an online mode
670 AliCodeTimerAuto("");
672 // Overwrite the previous setting
673 if (input) fInput = input;
675 // set the input in case of raw data
676 fRawReader = AliRawReader::Create(fInput.Data());
678 AliInfo("Reconstruction will run over digits");
680 if (!fEquipIdMap.IsNull() && fRawReader)
681 fRawReader->LoadEquipmentIdsMap(fEquipIdMap);
683 if (!fUseHLTData.IsNull()) {
684 // create the RawReaderHLT which performs redirection of HLT input data for
685 // the specified detectors
686 AliRawReader* pRawReader=AliRawHLTManager::CreateRawReaderHLT(fRawReader, fUseHLTData.Data());
688 fParentRawReader=fRawReader;
689 fRawReader=pRawReader;
691 AliError(Form("can not create Raw Reader for HLT input %s", fUseHLTData.Data()));
695 AliSysInfo::AddStamp("Start");
696 // get the run loader
697 if (!InitRunLoader()) return kFALSE;
698 AliSysInfo::AddStamp("LoadLoader");
700 // Initialize the CDB storage
703 AliSysInfo::AddStamp("LoadCDB");
705 // Set run number in CDBManager (if it is not already set by the user)
706 if (!SetRunNumberFromData()) if (fStopOnError) return kFALSE;
708 // Set CDB lock: from now on it is forbidden to reset the run number
709 // or the default storage or to activate any further storage!
712 // Import ideal TGeo geometry and apply misalignment
714 TString geom(gSystem->DirName(fGAliceFileName));
715 geom += "/geometry.root";
716 AliGeomManager::LoadGeometry(geom.Data());
717 if (!gGeoManager) if (fStopOnError) return kFALSE;
720 if (!MisalignGeometry(fLoadAlignData)) if (fStopOnError) return kFALSE;
721 AliSysInfo::AddStamp("LoadGeom");
724 // Get the GRP CDB entry
725 AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
728 fGRPData = dynamic_cast<TMap*>(entryGRP->GetObject());
731 AliError("No GRP entry found in OCDB!");
736 // Magnetic field map
737 if (!AliTracker::GetFieldMap()) {
738 // Construct the field map out of the information retrieved from GRP.
740 // For the moment, this is a dummy piece of code.
741 // The actual map is expected to be already created in rec.C !
745 Int_t map=AliMagWrapCheb::k5kG;
746 Bool_t dipoleON=kTRUE;
749 TObjString *l3Current=
750 dynamic_cast<TObjString*>(fGRPData->GetValue("fL3Current"));
752 AliError("GRP/GRP/Data entry: missing value for the L3 current !");
755 TObjString *l3Polarity=
756 dynamic_cast<TObjString*>(fGRPData->GetValue("fL3Polarity"));
758 AliError("GRP/GRP/Data entry: missing value for the L3 polarity !");
763 TObjString *diCurrent=
764 dynamic_cast<TObjString*>(fGRPData->GetValue("fDipoleCurrent"));
766 AliError("GRP/GRP/Data entry: missing value for the dipole current !");
769 TObjString *diPolarity=
770 dynamic_cast<TObjString*>(fGRPData->GetValue("fDipolePolarity"));
772 AliError("GRP/GRP/Data entry: missing value for the dipole polarity !");
778 new AliMagWrapCheb("Maps","Maps",2,factor,10.,map,dipoleON);
779 AliTracker::SetFieldMap(field,fUniformField);
782 AliFatal("Please, provide the field map ! Crashing deliberately...");
787 // Get the diamond profile from OCDB
788 AliCDBEntry* entry = AliCDBManager::Instance()
789 ->Get("GRP/Calib/MeanVertex");
792 fDiamondProfile = dynamic_cast<AliESDVertex*> (entry->GetObject());
794 AliError("No diamond profile found in OCDB!");
798 entry = AliCDBManager::Instance()
799 ->Get("GRP/Calib/MeanVertexTPC");
802 fDiamondProfileTPC = dynamic_cast<AliESDVertex*> (entry->GetObject());
804 AliError("No diamond profile found in OCDB!");
807 ftVertexer = new AliVertexerTracks(AliTracker::GetBz());
808 if(fDiamondProfile && fMeanVertexConstraint) ftVertexer->SetVtxStart(fDiamondProfile);
811 if (fRunVertexFinder && !CreateVertexer()) {
817 AliSysInfo::AddStamp("Vertexer");
820 if (!fRunTracking.IsNull() && !CreateTrackers(fRunTracking)) {
826 AliSysInfo::AddStamp("LoadTrackers");
828 // get the possibly already existing ESD file and tree
829 fesd = new AliESDEvent(); fhltesd = new AliESDEvent();
830 if (!gSystem->AccessPathName("AliESDs.root")){
831 gSystem->CopyFile("AliESDs.root", "AliESDs.old.root", kTRUE);
832 ffileOld = TFile::Open("AliESDs.old.root");
833 if (ffileOld && ffileOld->IsOpen()) {
834 ftreeOld = (TTree*) ffileOld->Get("esdTree");
835 if (ftreeOld)fesd->ReadFromTree(ftreeOld);
836 fhlttreeOld = (TTree*) ffileOld->Get("HLTesdTree");
837 if (fhlttreeOld) fhltesd->ReadFromTree(fhlttreeOld);
841 // create the ESD output file and tree
842 ffile = TFile::Open("AliESDs.root", "RECREATE");
843 ffile->SetCompressionLevel(2);
844 if (!ffile->IsOpen()) {
845 AliError("opening AliESDs.root failed");
846 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
849 ftree = new TTree("esdTree", "Tree with ESD objects");
850 fesd = new AliESDEvent();
851 fesd->CreateStdContent();
852 fesd->WriteToTree(ftree);
854 fhlttree = new TTree("HLTesdTree", "Tree with HLT ESD objects");
855 fhltesd = new AliESDEvent();
856 fhltesd->CreateStdContent();
857 fhltesd->WriteToTree(fhlttree);
860 if (fWriteESDfriend) {
861 fesdf = new AliESDfriend();
862 TBranch *br=ftree->Branch("ESDfriend.","AliESDfriend", &fesdf);
863 br->SetFile("AliESDfriends.root");
864 fesd->AddObject(fesdf);
869 if (fRawReader) fRawReader->RewindEvents();
872 gSystem->GetProcInfo(&ProcInfo);
873 AliInfo(Form("Current memory usage %d %d", ProcInfo.fMemResident, ProcInfo.fMemVirtual));
877 AliQADataMakerSteer qas ;
878 if (fRunQA && fRawReader) {
879 qas.Run(fRunLocalReconstruction, fRawReader) ;
880 fSameQACycle = kTRUE ;
882 //Initialize the QA and start of cycle for out-of-cycle QA
884 // TString detStr(fFillESD);
885 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
886 // if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
887 // AliQADataMakerRec *qadm = GetQADataMaker(iDet);
888 // if (!qadm) continue;
889 // AliInfo(Form("Initializing the QA data maker for %s",
890 // fgkDetectorName[iDet]));
891 // qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
892 // qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
894 // qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
895 // qadm->StartOfCycle(AliQA::kESDS,"same");
899 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
900 AliInfo(Form("Initializing the global QA data maker"));
902 qadm->Init(AliQA::kRECPOINTS, AliCDBManager::Instance()->GetRun());
903 AliTracker::SetResidualsArray(arr);
904 qadm->Init(AliQA::kESDS, AliCDBManager::Instance()->GetRun());
906 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
907 qadm->StartOfCycle(AliQA::kESDS, "same");
911 fSameQACycle = kTRUE;
914 //Initialize the Plane Efficiency framework
915 if (fRunPlaneEff && !InitPlaneEff()) {
916 if(fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
919 if (strcmp(gProgName,"alieve") == 0)
920 fRunAliEVE = InitAliEVE();
925 //_____________________________________________________________________________
926 Bool_t AliReconstruction::RunEvent(Int_t iEvent)
928 // run the reconstruction over a single event
929 // The event loop is steered in Run method
931 AliCodeTimerAuto("");
933 if (iEvent >= fRunLoader->GetNumberOfEvents()) {
934 fRunLoader->SetEventNumber(iEvent);
935 fRunLoader->GetHeader()->Reset(fRawReader->GetRunNumber(),
937 //?? fRunLoader->MakeTree("H");
938 fRunLoader->TreeE()->Fill();
941 if ((iEvent < fFirstEvent) || ((fLastEvent >= 0) && (iEvent > fLastEvent))) {
942 // copy old ESD to the new one
944 fesd->ReadFromTree(ftreeOld);
945 ftreeOld->GetEntry(iEvent);
949 fhltesd->ReadFromTree(fhlttreeOld);
950 fhlttreeOld->GetEntry(iEvent);
956 AliInfo(Form("processing event %d", iEvent));
958 //Start of cycle for the in-loop QA
961 TString detStr(fFillESD);
962 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
963 if (!IsSelected(fgkDetectorName[iDet], detStr))
965 AliQADataMakerRec *qadm = GetQADataMaker(iDet);
968 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
969 qadm->StartOfCycle(AliQA::kESDS, "same") ;
972 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
973 qadm->StartOfCycle(AliQA::kRECPOINTS, fSameQACycle);
974 qadm->StartOfCycle(AliQA::kESDS, "same");
979 fRunLoader->GetEvent(iEvent);
982 sprintf(aFileName, "ESD_%d.%d_final.root",
983 fRunLoader->GetHeader()->GetRun(),
984 fRunLoader->GetHeader()->GetEventNrInRun());
985 if (!gSystem->AccessPathName(aFileName)) return kTRUE;
987 // local single event reconstruction
988 if (!fRunLocalReconstruction.IsNull()) {
989 TString detectors=fRunLocalReconstruction;
990 // run HLT event reconstruction first
991 // ;-( IsSelected changes the string
992 if (IsSelected("HLT", detectors) &&
993 !RunLocalEventReconstruction("HLT")) {
994 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
996 detectors=fRunLocalReconstruction;
997 detectors.ReplaceAll("HLT", "");
998 if (!RunLocalEventReconstruction(detectors)) {
999 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1003 fesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1004 fhltesd->SetRunNumber(fRunLoader->GetHeader()->GetRun());
1005 fesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1006 fhltesd->SetEventNumberInFile(fRunLoader->GetHeader()->GetEventNrInRun());
1008 // Set magnetic field from the tracker
1009 fesd->SetMagneticField(AliTracker::GetBz());
1010 fhltesd->SetMagneticField(AliTracker::GetBz());
1014 // Fill raw-data error log into the ESD
1015 if (fRawReader) FillRawDataErrorLog(iEvent,fesd);
1018 if (fRunVertexFinder) {
1019 if (!ReadESD(fesd, "vertex")) {
1020 if (!RunVertexFinder(fesd)) {
1021 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1023 if (fCheckPointLevel > 0) WriteESD(fesd, "vertex");
1028 if (!fRunTracking.IsNull()) {
1029 if (fRunMuonTracking) {
1030 if (!RunMuonTracking(fesd)) {
1031 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1037 if (!fRunTracking.IsNull()) {
1038 if (!ReadESD(fesd, "tracking")) {
1039 if (!RunTracking(fesd)) {
1040 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1042 if (fCheckPointLevel > 0) WriteESD(fesd, "tracking");
1047 if (!fFillESD.IsNull()) {
1048 TString detectors=fFillESD;
1049 // run HLT first and on hltesd
1050 // ;-( IsSelected changes the string
1051 if (IsSelected("HLT", detectors) &&
1052 !FillESD(fhltesd, "HLT")) {
1053 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1056 // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
1057 if (detectors.Contains("ALL")) {
1059 for (Int_t idet=0; idet<fgkNDetectors; ++idet){
1060 detectors += fgkDetectorName[idet];
1064 detectors.ReplaceAll("HLT", "");
1065 if (!FillESD(fesd, detectors)) {
1066 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1070 // fill Event header information from the RawEventHeader
1071 if (fRawReader){FillRawEventHeaderESD(fesd);}
1074 AliESDpid::MakePID(fesd);
1075 if (fCheckPointLevel > 1) WriteESD(fesd, "PID");
1077 if (fFillTriggerESD) {
1078 if (!ReadESD(fesd, "trigger")) {
1079 if (!FillTriggerESD(fesd)) {
1080 if (fStopOnError) {CleanUp(ffile, ffileOld); return kFALSE;}
1082 if (fCheckPointLevel > 1) WriteESD(fesd, "trigger");
1089 // Propagate track to the beam pipe (if not already done by ITS)
1091 const Int_t ntracks = fesd->GetNumberOfTracks();
1092 const Double_t kBz = fesd->GetMagneticField();
1093 const Double_t kRadius = 2.8; //something less than the beam pipe radius
1096 UShort_t *selectedIdx=new UShort_t[ntracks];
1098 for (Int_t itrack=0; itrack<ntracks; itrack++){
1099 const Double_t kMaxStep = 5; //max step over the material
1102 AliESDtrack *track = fesd->GetTrack(itrack);
1103 if (!track) continue;
1105 AliExternalTrackParam *tpcTrack =
1106 (AliExternalTrackParam *)track->GetTPCInnerParam();
1110 PropagateTrackTo(tpcTrack,kRadius,track->GetMass(),kMaxStep,kTRUE);
1115 Int_t n=trkArray.GetEntriesFast();
1116 selectedIdx[n]=track->GetID();
1117 trkArray.AddLast(tpcTrack);
1120 if (track->GetX() < kRadius) continue;
1123 PropagateTrackTo(track,kRadius,track->GetMass(),kMaxStep,kTRUE);
1125 track->RelateToVertex(fesd->GetPrimaryVertexSPD(), kBz, kRadius);
1130 // Improve the reconstructed primary vertex position using the tracks
1132 TObject *obj = fOptions.FindObject("ITS");
1134 TString optITS = obj->GetTitle();
1135 if (optITS.Contains("cosmics") || optITS.Contains("COSMICS"))
1136 fRunVertexFinderTracks=kFALSE;
1138 if (fRunVertexFinderTracks) {
1139 // TPC + ITS primary vertex
1140 ftVertexer->SetITSrefitRequired();
1141 if(fDiamondProfile && fMeanVertexConstraint) {
1142 ftVertexer->SetVtxStart(fDiamondProfile);
1144 ftVertexer->SetConstraintOff();
1146 AliESDVertex *pvtx=ftVertexer->FindPrimaryVertex(fesd);
1148 if (pvtx->GetStatus()) {
1149 fesd->SetPrimaryVertex(pvtx);
1150 for (Int_t i=0; i<ntracks; i++) {
1151 AliESDtrack *t = fesd->GetTrack(i);
1152 t->RelateToVertex(pvtx, kBz, kRadius);
1157 // TPC-only primary vertex
1158 ftVertexer->SetITSrefitNotRequired();
1159 if(fDiamondProfileTPC && fMeanVertexConstraint) {
1160 ftVertexer->SetVtxStart(fDiamondProfileTPC);
1162 ftVertexer->SetConstraintOff();
1164 pvtx=ftVertexer->FindPrimaryVertex(&trkArray,selectedIdx);
1166 if (pvtx->GetStatus()) {
1167 fesd->SetPrimaryVertexTPC(pvtx);
1168 Int_t nsel=trkArray.GetEntriesFast();
1169 for (Int_t i=0; i<nsel; i++) {
1170 AliExternalTrackParam *t =
1171 (AliExternalTrackParam *)trkArray.UncheckedAt(i);
1172 t->PropagateToDCA(pvtx, kBz, kRadius);
1178 delete[] selectedIdx;
1180 if(fDiamondProfile) fesd->SetDiamond(fDiamondProfile);
1185 AliV0vertexer vtxer;
1186 vtxer.Tracks2V0vertices(fesd);
1188 if (fRunCascadeFinder) {
1190 AliCascadeVertexer cvtxer;
1191 cvtxer.V0sTracks2CascadeVertices(fesd);
1196 if (fCleanESD) CleanESD(fesd);
1200 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1201 if (qadm) qadm->Exec(AliQA::kESDS, fesd);
1205 if (fWriteESDfriend) {
1206 fesdf->~AliESDfriend();
1207 new (fesdf) AliESDfriend(); // Reset...
1208 fesd->GetESDfriend(fesdf);
1216 if (fRunAliEVE) RunAliEVE();
1218 if (fCheckPointLevel > 0) WriteESD(fesd, "final");
1221 if (fWriteESDfriend) {
1222 fesdf->~AliESDfriend();
1223 new (fesdf) AliESDfriend(); // Reset...
1226 ProcInfo_t ProcInfo;
1227 gSystem->GetProcInfo(&ProcInfo);
1228 AliInfo(Form("Event %d -> Current memory usage %d %d",iEvent, ProcInfo.fMemResident, ProcInfo.fMemVirtual));
1231 // End of cycle for the in-loop QA
1234 RunQA(fFillESD.Data(), fesd);
1235 TString detStr(fFillESD);
1236 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1237 if (!IsSelected(fgkDetectorName[iDet], detStr))
1239 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1242 qadm->EndOfCycle(AliQA::kRECPOINTS);
1243 qadm->EndOfCycle(AliQA::kESDS);
1248 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1250 qadm->EndOfCycle(AliQA::kRECPOINTS);
1251 qadm->EndOfCycle(AliQA::kESDS);
1260 //_____________________________________________________________________________
1261 Bool_t AliReconstruction::FinishRun()
1264 // Called after the exit
1265 // from the event loop
1266 AliCodeTimerAuto("");
1268 if (fIsNewRunLoader) { // galice.root didn't exist
1269 fRunLoader->WriteHeader("OVERWRITE");
1270 fRunLoader->CdGAFile();
1271 fRunLoader->Write(0, TObject::kOverwrite);
1274 ftree->GetUserInfo()->Add(fesd);
1275 fhlttree->GetUserInfo()->Add(fhltesd);
1277 const TMap *cdbMap = AliCDBManager::Instance()->GetStorageMap();
1278 const TList *cdbList = AliCDBManager::Instance()->GetRetrievedIds();
1280 TMap *cdbMapCopy = new TMap(cdbMap->GetEntries());
1281 cdbMapCopy->SetOwner(1);
1282 cdbMapCopy->SetName("cdbMap");
1283 TIter iter(cdbMap->GetTable());
1286 while((pair = dynamic_cast<TPair*> (iter.Next()))){
1287 TObjString* keyStr = dynamic_cast<TObjString*> (pair->Key());
1288 TObjString* valStr = dynamic_cast<TObjString*> (pair->Value());
1289 cdbMapCopy->Add(new TObjString(keyStr->GetName()), new TObjString(valStr->GetName()));
1292 TList *cdbListCopy = new TList();
1293 cdbListCopy->SetOwner(1);
1294 cdbListCopy->SetName("cdbList");
1296 TIter iter2(cdbList);
1299 while((id = dynamic_cast<AliCDBId*> (iter2.Next()))){
1300 cdbListCopy->Add(new TObjString(id->ToString().Data()));
1303 ftree->GetUserInfo()->Add(cdbMapCopy);
1304 ftree->GetUserInfo()->Add(cdbListCopy);
1307 if(fESDPar.Contains("ESD.par")){
1308 AliInfo("Attaching ESD.par to Tree");
1309 TNamed *fn = CopyFileToTNamed(fESDPar.Data(),"ESD.par");
1310 ftree->GetUserInfo()->Add(fn);
1316 if (fWriteESDfriend)
1317 ftree->SetBranchStatus("ESDfriend*",0);
1318 // we want to have only one tree version number
1319 ftree->Write(ftree->GetName(),TObject::kOverwrite);
1322 // Finish with Plane Efficiency evaluation: before of CleanUp !!!
1323 if (fRunPlaneEff && !FinishPlaneEff()) {
1324 AliWarning("Finish PlaneEff evaluation failed");
1328 CleanUp(ffile, ffileOld);
1331 AliWarning("AOD creation not supported anymore during reconstruction. See ANALYSIS/AliAnalysisTaskESDfilter.cxx instead.");
1334 // Create tags for the events in the ESD tree (the ESD tree is always present)
1335 // In case of empty events the tags will contain dummy values
1336 AliESDTagCreator *esdtagCreator = new AliESDTagCreator();
1337 esdtagCreator->CreateESDTags(fFirstEvent,fLastEvent,fGRPData);
1339 AliWarning("AOD tag creation not supported anymore during reconstruction.");
1342 //Finish QA and end of cycle for out-of-loop QA
1345 AliQADataMakerSteer qas;
1346 qas.Run(fRunLocalReconstruction.Data(), AliQA::kRECPOINTS, fSameQACycle);
1348 qas.Run(fRunLocalReconstruction.Data(), AliQA::kESDS, fSameQACycle);
1350 AliQADataMakerRec *qadm = GetQADataMaker(AliQA::kGLOBAL);
1352 qadm->EndOfCycle(AliQA::kRECPOINTS);
1353 qadm->EndOfCycle(AliQA::kESDS);
1360 // Cleanup of CDB manager: cache and active storages!
1361 AliCDBManager::Instance()->ClearCache();
1367 //_____________________________________________________________________________
1368 Bool_t AliReconstruction::RunLocalReconstruction(const TString& /*detectors*/)
1370 // run the local reconstruction
1371 static Int_t eventNr=0;
1372 AliCodeTimerAuto("")
1374 // AliCDBManager* man = AliCDBManager::Instance();
1375 // Bool_t origCache = man->GetCacheFlag();
1377 // TString detStr = detectors;
1378 // for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1379 // if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1380 // AliReconstructor* reconstructor = GetReconstructor(iDet);
1381 // if (!reconstructor) continue;
1382 // if (reconstructor->HasLocalReconstruction()) continue;
1384 // AliCodeTimerStart(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1385 // AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1387 // AliCodeTimerStart(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1388 // AliInfo(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1390 // man->SetCacheFlag(kTRUE);
1391 // TString calibPath = Form("%s/Calib/*", fgkDetectorName[iDet]);
1392 // man->GetAll(calibPath); // entries are cached!
1394 // AliCodeTimerStop(Form("Loading calibration data from OCDB for %s", fgkDetectorName[iDet]));
1396 // if (fRawReader) {
1397 // fRawReader->RewindEvents();
1398 // reconstructor->Reconstruct(fRunLoader, fRawReader);
1400 // reconstructor->Reconstruct(fRunLoader);
1403 // AliCodeTimerStop(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1404 // AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr));
1406 // // unload calibration data
1407 // man->UnloadFromCache(calibPath);
1408 // //man->ClearCache();
1411 // man->SetCacheFlag(origCache);
1413 // if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1414 // AliError(Form("the following detectors were not found: %s",
1416 // if (fStopOnError) return kFALSE;
1423 //_____________________________________________________________________________
1424 Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
1426 // run the local reconstruction
1428 static Int_t eventNr=0;
1429 AliCodeTimerAuto("")
1431 TString detStr = detectors;
1432 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1433 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1434 AliReconstructor* reconstructor = GetReconstructor(iDet);
1435 if (!reconstructor) continue;
1436 AliLoader* loader = fLoader[iDet];
1437 // Matthias April 2008: temporary fix to run HLT reconstruction
1438 // although the HLT loader is missing
1439 if (strcmp(fgkDetectorName[iDet], "HLT")==0) {
1441 reconstructor->Reconstruct(fRawReader, NULL);
1444 reconstructor->Reconstruct(dummy, NULL);
1449 AliWarning(Form("No loader is defined for %s!",fgkDetectorName[iDet]));
1452 // conversion of digits
1453 if (fRawReader && reconstructor->HasDigitConversion()) {
1454 AliInfo(Form("converting raw data digits into root objects for %s",
1455 fgkDetectorName[iDet]));
1456 AliCodeTimerAuto(Form("converting raw data digits into root objects for %s",
1457 fgkDetectorName[iDet]));
1458 loader->LoadDigits("update");
1459 loader->CleanDigits();
1460 loader->MakeDigitsContainer();
1461 TTree* digitsTree = loader->TreeD();
1462 reconstructor->ConvertDigits(fRawReader, digitsTree);
1463 loader->WriteDigits("OVERWRITE");
1464 loader->UnloadDigits();
1466 // local reconstruction
1467 AliInfo(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1468 AliCodeTimerAuto(Form("running reconstruction for %s", fgkDetectorName[iDet]));
1469 loader->LoadRecPoints("update");
1470 loader->CleanRecPoints();
1471 loader->MakeRecPointsContainer();
1472 TTree* clustersTree = loader->TreeR();
1473 if (fRawReader && !reconstructor->HasDigitConversion()) {
1474 reconstructor->Reconstruct(fRawReader, clustersTree);
1476 loader->LoadDigits("read");
1477 TTree* digitsTree = loader->TreeD();
1479 AliError(Form("Can't get the %s digits tree", fgkDetectorName[iDet]));
1480 if (fStopOnError) return kFALSE;
1482 reconstructor->Reconstruct(digitsTree, clustersTree);
1484 loader->UnloadDigits();
1487 // In-loop QA for local reconstrucion
1488 if (fRunQA && fInLoopQA) {
1489 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
1492 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1494 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1496 qadm->Exec(AliQA::kRECPOINTS, clustersTree) ;
1499 //(Form("Running QA data maker for %s", fgkDetectorName[iDet]));
1503 loader->WriteRecPoints("OVERWRITE");
1504 loader->UnloadRecPoints();
1505 AliSysInfo::AddStamp(Form("LRec%s_%d",fgkDetectorName[iDet],eventNr), iDet,1,eventNr);
1508 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1509 AliError(Form("the following detectors were not found: %s",
1511 if (fStopOnError) return kFALSE;
1517 //_____________________________________________________________________________
1518 Bool_t AliReconstruction::RunVertexFinder(AliESDEvent*& esd)
1520 // run the barrel tracking
1522 AliCodeTimerAuto("")
1524 AliESDVertex* vertex = NULL;
1525 Double_t vtxPos[3] = {0, 0, 0};
1526 Double_t vtxErr[3] = {0.07, 0.07, 0.1};
1527 TArrayF mcVertex(3);
1528 if (fRunLoader->GetHeader() && fRunLoader->GetHeader()->GenEventHeader()) {
1529 fRunLoader->GetHeader()->GenEventHeader()->PrimaryVertex(mcVertex);
1530 for (Int_t i = 0; i < 3; i++) vtxPos[i] = mcVertex[i];
1534 if(fDiamondProfile) fVertexer->SetVtxStart(fDiamondProfile);
1535 AliInfo("running the ITS vertex finder");
1536 if (fLoader[0]) fLoader[0]->LoadRecPoints();
1537 vertex = fVertexer->FindVertexForCurrentEvent(fRunLoader->GetEventNumber());
1538 if (fLoader[0]) fLoader[0]->UnloadRecPoints();
1540 AliWarning("Vertex not found");
1541 vertex = new AliESDVertex();
1542 vertex->SetName("default");
1545 vertex->SetName("reconstructed");
1549 AliInfo("getting the primary vertex from MC");
1550 vertex = new AliESDVertex(vtxPos, vtxErr);
1554 vertex->GetXYZ(vtxPos);
1555 vertex->GetSigmaXYZ(vtxErr);
1557 AliWarning("no vertex reconstructed");
1558 vertex = new AliESDVertex(vtxPos, vtxErr);
1560 esd->SetPrimaryVertexSPD(vertex);
1561 // if SPD multiplicity has been determined, it is stored in the ESD
1562 AliMultiplicity *mult = fVertexer->GetMultiplicity();
1563 if(mult)esd->SetMultiplicity(mult);
1565 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1566 if (fTracker[iDet]) fTracker[iDet]->SetVertex(vtxPos, vtxErr);
1573 //_____________________________________________________________________________
1574 Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
1576 // run the HLT barrel tracking
1578 AliCodeTimerAuto("")
1581 AliError("Missing runLoader!");
1585 AliInfo("running HLT tracking");
1587 // Get a pointer to the HLT reconstructor
1588 AliReconstructor *reconstructor = GetReconstructor(fgkNDetectors-1);
1589 if (!reconstructor) return kFALSE;
1592 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1593 TString detName = fgkDetectorName[iDet];
1594 AliDebug(1, Form("%s HLT tracking", detName.Data()));
1595 reconstructor->SetOption(detName.Data());
1596 AliTracker *tracker = reconstructor->CreateTracker();
1598 AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
1599 if (fStopOnError) return kFALSE;
1603 Double_t vtxErr[3]={0.005,0.005,0.010};
1604 const AliESDVertex *vertex = esd->GetVertex();
1605 vertex->GetXYZ(vtxPos);
1606 tracker->SetVertex(vtxPos,vtxErr);
1608 fLoader[iDet]->LoadRecPoints("read");
1609 TTree* tree = fLoader[iDet]->TreeR();
1611 AliError(Form("Can't get the %s cluster tree", detName.Data()));
1614 tracker->LoadClusters(tree);
1616 if (tracker->Clusters2Tracks(esd) != 0) {
1617 AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
1621 tracker->UnloadClusters();
1629 //_____________________________________________________________________________
1630 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
1632 // run the muon spectrometer tracking
1634 AliCodeTimerAuto("")
1637 AliError("Missing runLoader!");
1640 Int_t iDet = 7; // for MUON
1642 AliInfo("is running...");
1644 // Get a pointer to the MUON reconstructor
1645 AliReconstructor *reconstructor = GetReconstructor(iDet);
1646 if (!reconstructor) return kFALSE;
1649 TString detName = fgkDetectorName[iDet];
1650 AliDebug(1, Form("%s tracking", detName.Data()));
1651 AliTracker *tracker = reconstructor->CreateTracker();
1653 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
1658 fLoader[iDet]->LoadRecPoints("read");
1660 tracker->LoadClusters(fLoader[iDet]->TreeR());
1662 Int_t rv = tracker->Clusters2Tracks(esd);
1666 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1670 fLoader[iDet]->UnloadRecPoints();
1672 tracker->UnloadClusters();
1680 //_____________________________________________________________________________
1681 Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd)
1683 // run the barrel tracking
1684 static Int_t eventNr=0;
1685 AliCodeTimerAuto("")
1687 AliInfo("running tracking");
1689 //Fill the ESD with the T0 info (will be used by the TOF)
1690 if (fReconstructor[11] && fLoader[11]) {
1691 fLoader[11]->LoadRecPoints("READ");
1692 TTree *treeR = fLoader[11]->TreeR();
1693 GetReconstructor(11)->FillESD((TTree *)NULL,treeR,esd);
1696 // pass 1: TPC + ITS inwards
1697 for (Int_t iDet = 1; iDet >= 0; iDet--) {
1698 if (!fTracker[iDet]) continue;
1699 AliDebug(1, Form("%s tracking", fgkDetectorName[iDet]));
1702 fLoader[iDet]->LoadRecPoints("read");
1703 AliSysInfo::AddStamp(Form("RLoadCluster%s_%d",fgkDetectorName[iDet],eventNr),iDet,1, eventNr);
1704 TTree* tree = fLoader[iDet]->TreeR();
1706 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1709 fTracker[iDet]->LoadClusters(tree);
1710 AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1712 if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
1713 AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
1716 if (fCheckPointLevel > 1) {
1717 WriteESD(esd, Form("%s.tracking", fgkDetectorName[iDet]));
1719 // preliminary PID in TPC needed by the ITS tracker
1721 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1722 AliESDpid::MakePID(esd);
1724 AliSysInfo::AddStamp(Form("Tracking0%s_%d",fgkDetectorName[iDet],eventNr), iDet,3,eventNr);
1727 // pass 2: ALL backwards
1729 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1730 if (!fTracker[iDet]) continue;
1731 AliDebug(1, Form("%s back propagation", fgkDetectorName[iDet]));
1734 if (iDet > 1) { // all except ITS, TPC
1736 fLoader[iDet]->LoadRecPoints("read");
1737 AliSysInfo::AddStamp(Form("RLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,1, eventNr);
1738 tree = fLoader[iDet]->TreeR();
1740 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[iDet]));
1743 fTracker[iDet]->LoadClusters(tree);
1744 AliSysInfo::AddStamp(Form("TLoadCluster0%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
1748 if (iDet>1) // start filling residuals for the "outer" detectors
1749 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1751 if (fTracker[iDet]->PropagateBack(esd) != 0) {
1752 AliError(Form("%s backward propagation failed", fgkDetectorName[iDet]));
1755 if (fCheckPointLevel > 1) {
1756 WriteESD(esd, Form("%s.back", fgkDetectorName[iDet]));
1760 if (iDet > 2) { // all except ITS, TPC, TRD
1761 fTracker[iDet]->UnloadClusters();
1762 fLoader[iDet]->UnloadRecPoints();
1764 // updated PID in TPC needed by the ITS tracker -MI
1766 GetReconstructor(1)->FillESD((TTree*)NULL, (TTree*)NULL, esd);
1767 AliESDpid::MakePID(esd);
1769 AliSysInfo::AddStamp(Form("Tracking1%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1771 //stop filling residuals for the "outer" detectors
1772 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
1774 // write space-points to the ESD in case alignment data output
1776 if (fWriteAlignmentData)
1777 WriteAlignmentData(esd);
1779 // pass 3: TRD + TPC + ITS refit inwards
1781 for (Int_t iDet = 2; iDet >= 0; iDet--) {
1782 if (!fTracker[iDet]) continue;
1783 AliDebug(1, Form("%s inward refit", fgkDetectorName[iDet]));
1786 if (iDet<2) // start filling residuals for TPC and ITS
1787 if (fRunGlobalQA) AliTracker::SetFillResiduals(kTRUE);
1789 if (fTracker[iDet]->RefitInward(esd) != 0) {
1790 AliError(Form("%s inward refit failed", fgkDetectorName[iDet]));
1793 // run postprocessing
1794 if (fTracker[iDet]->PostProcess(esd) != 0) {
1795 AliError(Form("%s postprocessing failed", fgkDetectorName[iDet]));
1798 if (fCheckPointLevel > 1) {
1799 WriteESD(esd, Form("%s.refit", fgkDetectorName[iDet]));
1801 AliSysInfo::AddStamp(Form("Tracking2%s_%d",fgkDetectorName[iDet],eventNr), iDet,3, eventNr);
1803 fTracker[iDet]->UnloadClusters();
1804 AliSysInfo::AddStamp(Form("TUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,4, eventNr);
1805 fLoader[iDet]->UnloadRecPoints();
1806 AliSysInfo::AddStamp(Form("RUnloadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,5, eventNr);
1808 // stop filling residuals for TPC and ITS
1809 if (fRunGlobalQA) AliTracker::SetFillResiduals(kFALSE);
1815 //_____________________________________________________________________________
1816 Bool_t AliReconstruction::CleanESD(AliESDEvent *esd){
1818 // Remove the data which are not needed for the physics analysis.
1821 Int_t nTracks=esd->GetNumberOfTracks();
1822 Int_t nV0s=esd->GetNumberOfV0s();
1824 (Form("Number of ESD tracks and V0s before cleaning: %d %d",nTracks,nV0s));
1826 Float_t cleanPars[]={fV0DCAmax,fV0CsPmin,fDmax,fZmax};
1827 Bool_t rc=esd->Clean(cleanPars);
1829 nTracks=esd->GetNumberOfTracks();
1830 nV0s=esd->GetNumberOfV0s();
1832 (Form("Number of ESD tracks and V0s after cleaning %d %d",nTracks,nV0s));
1837 //_____________________________________________________________________________
1838 Bool_t AliReconstruction::FillESD(AliESDEvent*& esd, const TString& detectors)
1840 // fill the event summary data
1842 AliCodeTimerAuto("")
1843 static Int_t eventNr=0;
1844 TString detStr = detectors;
1846 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1847 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
1848 AliReconstructor* reconstructor = GetReconstructor(iDet);
1849 if (!reconstructor) continue;
1850 if (!ReadESD(esd, fgkDetectorName[iDet])) {
1851 AliDebug(1, Form("filling ESD for %s", fgkDetectorName[iDet]));
1852 TTree* clustersTree = NULL;
1853 if (fLoader[iDet]) {
1854 fLoader[iDet]->LoadRecPoints("read");
1855 clustersTree = fLoader[iDet]->TreeR();
1856 if (!clustersTree) {
1857 AliError(Form("Can't get the %s clusters tree",
1858 fgkDetectorName[iDet]));
1859 if (fStopOnError) return kFALSE;
1862 if (fRawReader && !reconstructor->HasDigitConversion()) {
1863 reconstructor->FillESD(fRawReader, clustersTree, esd);
1865 TTree* digitsTree = NULL;
1866 if (fLoader[iDet]) {
1867 fLoader[iDet]->LoadDigits("read");
1868 digitsTree = fLoader[iDet]->TreeD();
1870 AliError(Form("Can't get the %s digits tree",
1871 fgkDetectorName[iDet]));
1872 if (fStopOnError) return kFALSE;
1875 reconstructor->FillESD(digitsTree, clustersTree, esd);
1876 if (fLoader[iDet]) fLoader[iDet]->UnloadDigits();
1878 if (fLoader[iDet]) {
1879 fLoader[iDet]->UnloadRecPoints();
1882 if (fCheckPointLevel > 2) WriteESD(esd, fgkDetectorName[iDet]);
1886 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
1887 AliError(Form("the following detectors were not found: %s",
1889 if (fStopOnError) return kFALSE;
1891 AliSysInfo::AddStamp(Form("FillESD%d",eventNr), 0,1, eventNr);
1896 //_____________________________________________________________________________
1897 Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
1899 // Reads the trigger decision which is
1900 // stored in Trigger.root file and fills
1901 // the corresponding esd entries
1903 AliCodeTimerAuto("")
1905 AliInfo("Filling trigger information into the ESD");
1907 AliCentralTrigger *aCTP = NULL;
1910 AliCTPRawStream input(fRawReader);
1911 if (!input.Next()) {
1912 AliError("No valid CTP (trigger) DDL raw data is found ! The trigger information is not stored in the ESD !");
1915 esd->SetTriggerMask(input.GetClassMask());
1916 esd->SetTriggerCluster(input.GetClusterMask());
1918 aCTP = new AliCentralTrigger();
1919 TString configstr("");
1920 if (!aCTP->LoadConfiguration(configstr)) { // Load CTP config from OCDB
1921 AliError("No trigger configuration found in OCDB! The trigger classes information will no be stored in ESD!");
1927 AliRunLoader *runloader = AliRunLoader::GetRunLoader();
1929 if (!runloader->LoadTrigger()) {
1930 aCTP = runloader->GetTrigger();
1931 esd->SetTriggerMask(aCTP->GetClassMask());
1932 esd->SetTriggerCluster(aCTP->GetClusterMask());
1935 AliWarning("No trigger can be loaded! The trigger information is not stored in the ESD !");
1940 AliError("No run loader is available! The trigger information is not stored in the ESD !");
1945 // Now fill the trigger class names into AliESDRun object
1946 AliTriggerConfiguration *config = aCTP->GetConfiguration();
1948 AliError("No trigger configuration has been found! The trigger classes information will no be stored in ESD!");
1949 if (fRawReader) delete aCTP;
1953 const TObjArray& classesArray = config->GetClasses();
1954 Int_t nclasses = classesArray.GetEntriesFast();
1955 for( Int_t j=0; j<nclasses; j++ ) {
1956 AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At( j );
1957 Int_t trindex = (Int_t)TMath::Log2(trclass->GetMask());
1958 esd->SetTriggerClass(trclass->GetName(),trindex);
1961 if (fRawReader) delete aCTP;
1969 //_____________________________________________________________________________
1970 Bool_t AliReconstruction::FillRawEventHeaderESD(AliESDEvent*& esd)
1973 // Filling information from RawReader Header
1976 AliInfo("Filling information from RawReader Header");
1977 esd->SetBunchCrossNumber(0);
1978 esd->SetOrbitNumber(0);
1979 esd->SetPeriodNumber(0);
1980 esd->SetTimeStamp(0);
1981 esd->SetEventType(0);
1982 const AliRawEventHeaderBase * eventHeader = fRawReader->GetEventHeader();
1985 const UInt_t *id = eventHeader->GetP("Id");
1986 esd->SetBunchCrossNumber((id)[1]&0x00000fff);
1987 esd->SetOrbitNumber((((id)[0]<<20)&0xf00000)|(((id)[1]>>12)&0xfffff));
1988 esd->SetPeriodNumber(((id)[0]>>4)&0x0fffffff);
1990 esd->SetTimeStamp((eventHeader->Get("Timestamp")));
1991 esd->SetEventType((eventHeader->Get("Type")));
1998 //_____________________________________________________________________________
1999 Bool_t AliReconstruction::IsSelected(TString detName, TString& detectors) const
2001 // check whether detName is contained in detectors
2002 // if yes, it is removed from detectors
2004 // check if all detectors are selected
2005 if ((detectors.CompareTo("ALL") == 0) ||
2006 detectors.BeginsWith("ALL ") ||
2007 detectors.EndsWith(" ALL") ||
2008 detectors.Contains(" ALL ")) {
2013 // search for the given detector
2014 Bool_t result = kFALSE;
2015 if ((detectors.CompareTo(detName) == 0) ||
2016 detectors.BeginsWith(detName+" ") ||
2017 detectors.EndsWith(" "+detName) ||
2018 detectors.Contains(" "+detName+" ")) {
2019 detectors.ReplaceAll(detName, "");
2023 // clean up the detectors string
2024 while (detectors.Contains(" ")) detectors.ReplaceAll(" ", " ");
2025 while (detectors.BeginsWith(" ")) detectors.Remove(0, 1);
2026 while (detectors.EndsWith(" ")) detectors.Remove(detectors.Length()-1, 1);
2031 //_____________________________________________________________________________
2032 Bool_t AliReconstruction::InitRunLoader()
2034 // get or create the run loader
2036 if (gAlice) delete gAlice;
2039 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
2040 // load all base libraries to get the loader classes
2041 TString libs = gSystem->GetLibraries();
2042 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2043 TString detName = fgkDetectorName[iDet];
2044 if (detName == "HLT") continue;
2045 if (libs.Contains("lib" + detName + "base.so")) continue;
2046 gSystem->Load("lib" + detName + "base.so");
2048 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
2050 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
2055 fRunLoader->CdGAFile();
2056 fRunLoader->LoadgAlice();
2058 //PH This is a temporary fix to give access to the kinematics
2059 //PH that is needed for the labels of ITS clusters
2060 fRunLoader->LoadHeader();
2061 fRunLoader->LoadKinematics();
2063 } else { // galice.root does not exist
2065 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
2069 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data(),
2070 AliConfig::GetDefaultEventFolderName(),
2073 AliError(Form("could not create run loader in file %s",
2074 fGAliceFileName.Data()));
2078 fIsNewRunLoader = kTRUE;
2079 fRunLoader->MakeTree("E");
2081 if (fNumberOfEventsPerFile > 0)
2082 fRunLoader->SetNumberOfEventsPerFile(fNumberOfEventsPerFile);
2084 fRunLoader->SetNumberOfEventsPerFile((UInt_t)-1);
2090 //_____________________________________________________________________________
2091 AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
2093 // get the reconstructor object and the loader for a detector
2095 if (fReconstructor[iDet]) return fReconstructor[iDet];
2097 // load the reconstructor object
2098 TPluginManager* pluginManager = gROOT->GetPluginManager();
2099 TString detName = fgkDetectorName[iDet];
2100 TString recName = "Ali" + detName + "Reconstructor";
2102 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT")) return NULL;
2104 AliReconstructor* reconstructor = NULL;
2105 // first check if a plugin is defined for the reconstructor
2106 TPluginHandler* pluginHandler =
2107 pluginManager->FindHandler("AliReconstructor", detName);
2108 // if not, add a plugin for it
2109 if (!pluginHandler) {
2110 AliDebug(1, Form("defining plugin for %s", recName.Data()));
2111 TString libs = gSystem->GetLibraries();
2112 if (libs.Contains("lib" + detName + "base.so") ||
2113 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2114 pluginManager->AddHandler("AliReconstructor", detName,
2115 recName, detName + "rec", recName + "()");
2117 pluginManager->AddHandler("AliReconstructor", detName,
2118 recName, detName, recName + "()");
2120 pluginHandler = pluginManager->FindHandler("AliReconstructor", detName);
2122 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2123 reconstructor = (AliReconstructor*) pluginHandler->ExecPlugin(0);
2125 if (reconstructor) {
2126 TObject* obj = fOptions.FindObject(detName.Data());
2127 if (obj) reconstructor->SetOption(obj->GetTitle());
2128 reconstructor->Init();
2129 fReconstructor[iDet] = reconstructor;
2132 // get or create the loader
2133 if (detName != "HLT") {
2134 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
2135 if (!fLoader[iDet]) {
2136 AliConfig::Instance()
2137 ->CreateDetectorFolders(fRunLoader->GetEventFolder(),
2139 // first check if a plugin is defined for the loader
2141 pluginManager->FindHandler("AliLoader", detName);
2142 // if not, add a plugin for it
2143 if (!pluginHandler) {
2144 TString loaderName = "Ali" + detName + "Loader";
2145 AliDebug(1, Form("defining plugin for %s", loaderName.Data()));
2146 pluginManager->AddHandler("AliLoader", detName,
2147 loaderName, detName + "base",
2148 loaderName + "(const char*, TFolder*)");
2149 pluginHandler = pluginManager->FindHandler("AliLoader", detName);
2151 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2153 (AliLoader*) pluginHandler->ExecPlugin(2, detName.Data(),
2154 fRunLoader->GetEventFolder());
2156 if (!fLoader[iDet]) { // use default loader
2157 fLoader[iDet] = new AliLoader(detName, fRunLoader->GetEventFolder());
2159 if (!fLoader[iDet]) {
2160 AliWarning(Form("couldn't get loader for %s", detName.Data()));
2161 if (fStopOnError) return NULL;
2163 fRunLoader->AddLoader(fLoader[iDet]);
2164 fRunLoader->CdGAFile();
2165 if (gFile && !gFile->IsWritable()) gFile->ReOpen("UPDATE");
2166 fRunLoader->Write(0, TObject::kOverwrite);
2171 return reconstructor;
2174 //_____________________________________________________________________________
2175 Bool_t AliReconstruction::CreateVertexer()
2177 // create the vertexer
2180 AliReconstructor* itsReconstructor = GetReconstructor(0);
2181 if (itsReconstructor) {
2182 fVertexer = itsReconstructor->CreateVertexer();
2185 AliWarning("couldn't create a vertexer for ITS");
2186 if (fStopOnError) return kFALSE;
2192 //_____________________________________________________________________________
2193 Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
2195 // create the trackers
2197 TString detStr = detectors;
2198 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2199 if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2200 AliReconstructor* reconstructor = GetReconstructor(iDet);
2201 if (!reconstructor) continue;
2202 TString detName = fgkDetectorName[iDet];
2203 if (detName == "HLT") {
2204 fRunHLTTracking = kTRUE;
2207 if (detName == "MUON") {
2208 fRunMuonTracking = kTRUE;
2213 fTracker[iDet] = reconstructor->CreateTracker();
2214 if (!fTracker[iDet] && (iDet < 7)) {
2215 AliWarning(Form("couldn't create a tracker for %s", detName.Data()));
2216 if (fStopOnError) return kFALSE;
2218 AliSysInfo::AddStamp(Form("LTracker%s",fgkDetectorName[iDet]), iDet,0);
2224 //_____________________________________________________________________________
2225 void AliReconstruction::CleanUp(TFile* file, TFile* fileOld)
2227 // delete trackers and the run loader and close and delete the file
2229 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2230 delete fReconstructor[iDet];
2231 fReconstructor[iDet] = NULL;
2232 fLoader[iDet] = NULL;
2233 delete fTracker[iDet];
2234 fTracker[iDet] = NULL;
2235 // delete fQADataMaker[iDet];
2236 // fQADataMaker[iDet] = NULL;
2241 if (ftVertexer) delete ftVertexer;
2244 if(!(AliCDBManager::Instance()->GetCacheFlag())) {
2245 delete fDiamondProfile;
2246 fDiamondProfile = NULL;
2247 delete fDiamondProfileTPC;
2248 fDiamondProfileTPC = NULL;
2258 if (fParentRawReader) delete fParentRawReader;
2259 fParentRawReader=NULL;
2269 gSystem->Unlink("AliESDs.old.root");
2274 //_____________________________________________________________________________
2276 Bool_t AliReconstruction::ReadESD(AliESDEvent*& esd, const char* recStep) const
2278 // read the ESD event from a file
2280 if (!esd) return kFALSE;
2282 sprintf(fileName, "ESD_%d.%d_%s.root",
2283 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
2284 if (gSystem->AccessPathName(fileName)) return kFALSE;
2286 AliInfo(Form("reading ESD from file %s", fileName));
2287 AliDebug(1, Form("reading ESD from file %s", fileName));
2288 TFile* file = TFile::Open(fileName);
2289 if (!file || !file->IsOpen()) {
2290 AliError(Form("opening %s failed", fileName));
2297 esd = (AliESDEvent*) file->Get("ESD");
2306 //_____________________________________________________________________________
2307 void AliReconstruction::WriteESD(AliESDEvent* esd, const char* recStep) const
2309 // write the ESD event to a file
2313 sprintf(fileName, "ESD_%d.%d_%s.root",
2314 esd->GetRunNumber(), esd->GetEventNumberInFile(), recStep);
2316 AliDebug(1, Form("writing ESD to file %s", fileName));
2317 TFile* file = TFile::Open(fileName, "recreate");
2318 if (!file || !file->IsOpen()) {
2319 AliError(Form("opening %s failed", fileName));
2328 void AliReconstruction::WriteAlignmentData(AliESDEvent* esd)
2330 // Write space-points which are then used in the alignment procedures
2331 // For the moment only ITS, TRD and TPC
2333 // Load TOF clusters
2335 fLoader[3]->LoadRecPoints("read");
2336 TTree* tree = fLoader[3]->TreeR();
2338 AliError(Form("Can't get the %s cluster tree", fgkDetectorName[3]));
2341 fTracker[3]->LoadClusters(tree);
2343 Int_t ntracks = esd->GetNumberOfTracks();
2344 for (Int_t itrack = 0; itrack < ntracks; itrack++)
2346 AliESDtrack *track = esd->GetTrack(itrack);
2349 for (Int_t iDet = 3; iDet >= 0; iDet--)
2350 nsp += track->GetNcls(iDet);
2352 AliTrackPointArray *sp = new AliTrackPointArray(nsp);
2353 track->SetTrackPointArray(sp);
2355 for (Int_t iDet = 3; iDet >= 0; iDet--) {
2356 AliTracker *tracker = fTracker[iDet];
2357 if (!tracker) continue;
2358 Int_t nspdet = track->GetNcls(iDet);
2359 if (nspdet <= 0) continue;
2360 track->GetClusters(iDet,idx);
2364 while (isp2 < nspdet) {
2366 TString dets = fgkDetectorName[iDet];
2367 if ((fUseTrackingErrorsForAlignment.CompareTo(dets) == 0) ||
2368 fUseTrackingErrorsForAlignment.BeginsWith(dets+" ") ||
2369 fUseTrackingErrorsForAlignment.EndsWith(" "+dets) ||
2370 fUseTrackingErrorsForAlignment.Contains(" "+dets+" ")) {
2371 isvalid = tracker->GetTrackPointTrackingError(idx[isp2],p,track);
2373 isvalid = tracker->GetTrackPoint(idx[isp2],p);
2376 const Int_t kNTPCmax = 159;
2377 if (iDet==1 && isp2>kNTPCmax) break; // to be fixed
2378 if (!isvalid) continue;
2379 sp->AddPoint(isptrack,&p); isptrack++; isp++;
2385 fTracker[3]->UnloadClusters();
2386 fLoader[3]->UnloadRecPoints();
2390 //_____________________________________________________________________________
2391 void AliReconstruction::FillRawDataErrorLog(Int_t iEvent, AliESDEvent* esd)
2393 // The method reads the raw-data error log
2394 // accumulated within the rawReader.
2395 // It extracts the raw-data errors related to
2396 // the current event and stores them into
2397 // a TClonesArray inside the esd object.
2399 if (!fRawReader) return;
2401 for(Int_t i = 0; i < fRawReader->GetNumberOfErrorLogs(); i++) {
2403 AliRawDataErrorLog *log = fRawReader->GetErrorLog(i);
2405 if (iEvent != log->GetEventNumber()) continue;
2407 esd->AddRawDataErrorLog(log);
2412 TNamed* AliReconstruction::CopyFileToTNamed(TString fPath,TString pName){
2413 // Dump a file content into a char in TNamed
2415 in.open(fPath.Data(),ios::in | ios::binary|ios::ate);
2416 Int_t kBytes = (Int_t)in.tellg();
2417 printf("Size: %d \n",kBytes);
2420 char* memblock = new char [kBytes];
2421 in.seekg (0, ios::beg);
2422 in.read (memblock, kBytes);
2424 TString fData(memblock,kBytes);
2425 fn = new TNamed(pName,fData);
2426 printf("fData Size: %d \n",fData.Sizeof());
2427 printf("pName Size: %d \n",pName.Sizeof());
2428 printf("fn Size: %d \n",fn->Sizeof());
2432 AliInfo(Form("Could not Open %s\n",fPath.Data()));
2438 void AliReconstruction::TNamedToFile(TTree* fTree, TString pName){
2439 // This is not really needed in AliReconstruction at the moment
2440 // but can serve as a template
2442 TList *fList = fTree->GetUserInfo();
2443 TNamed *fn = (TNamed*)fList->FindObject(pName.Data());
2444 printf("fn Size: %d \n",fn->Sizeof());
2446 TString fTmp(fn->GetName()); // to be 100% sure in principle pName also works
2447 const char* cdata = fn->GetTitle();
2448 printf("fTmp Size %d\n",fTmp.Sizeof());
2450 int size = fn->Sizeof()-fTmp.Sizeof()-sizeof(UChar_t)-sizeof(Int_t); // see dfinition of TString::SizeOf()...
2451 printf("calculated size %d\n",size);
2452 ofstream out(pName.Data(),ios::out | ios::binary);
2453 out.write(cdata,size);
2458 //_____________________________________________________________________________
2459 AliQADataMakerRec * AliReconstruction::GetQADataMaker(Int_t iDet)
2461 // get the quality assurance data maker object and the loader for a detector
2463 if (fQADataMaker[iDet])
2464 return fQADataMaker[iDet];
2466 AliQADataMakerRec * qadm = NULL;
2467 if (iDet == fgkNDetectors) { //Global QA
2468 qadm = new AliGlobalQADataMaker();
2469 fQADataMaker[iDet] = qadm;
2473 // load the QA data maker object
2474 TPluginManager* pluginManager = gROOT->GetPluginManager();
2475 TString detName = fgkDetectorName[iDet];
2476 TString qadmName = "Ali" + detName + "QADataMakerRec";
2477 if (!fIsNewRunLoader && !fRunLoader->GetLoader(detName+"Loader") && (detName != "HLT"))
2480 // first check if a plugin is defined for the quality assurance data maker
2481 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
2482 // if not, add a plugin for it
2483 if (!pluginHandler) {
2484 AliDebug(1, Form("defining plugin for %s", qadmName.Data()));
2485 TString libs = gSystem->GetLibraries();
2486 if (libs.Contains("lib" + detName + "base.so") ||
2487 (gSystem->Load("lib" + detName + "base.so") >= 0)) {
2488 pluginManager->AddHandler("AliQADataMakerRec", detName,
2489 qadmName, detName + "qadm", qadmName + "()");
2491 pluginManager->AddHandler("AliQADataMakerRec", detName,
2492 qadmName, detName, qadmName + "()");
2494 pluginHandler = pluginManager->FindHandler("AliQADataMakerRec", detName);
2496 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
2497 qadm = (AliQADataMakerRec *) pluginHandler->ExecPlugin(0);
2500 fQADataMaker[iDet] = qadm;
2505 //_____________________________________________________________________________
2506 Bool_t AliReconstruction::RunQA(const char* detectors, AliESDEvent *& esd)
2508 // run the Quality Assurance data producer
2510 AliCodeTimerAuto("")
2511 TString detStr = detectors;
2512 for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2513 if (!IsSelected(fgkDetectorName[iDet], detStr))
2515 AliQADataMakerRec * qadm = GetQADataMaker(iDet);
2518 AliCodeTimerStart(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2519 AliInfo(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2521 qadm->Exec(AliQA::kESDS, esd) ;
2524 AliCodeTimerStop(Form("running quality assurance data maker for %s", fgkDetectorName[iDet]));
2526 if ((detStr.CompareTo("ALL") != 0) && !detStr.IsNull()) {
2527 AliError(Form("the following detectors were not found: %s",
2537 //_____________________________________________________________________________
2538 void AliReconstruction::CheckQA()
2540 // check the QA of SIM for this run and remove the detectors
2541 // with status Fatal
2543 TString newRunLocalReconstruction ;
2544 TString newRunTracking ;
2545 TString newFillESD ;
2547 for (Int_t iDet = 0; iDet < AliQA::kNDET; iDet++) {
2548 TString detName(AliQA::GetDetName(iDet)) ;
2549 AliQA * qa = AliQA::Instance(AliQA::DETECTORINDEX_t(iDet)) ;
2550 if ( qa->IsSet(AliQA::DETECTORINDEX_t(iDet), AliQA::kSIM, AliQA::kFATAL)) {
2551 AliInfo(Form("QA status for %s in Hits and/or SDIGITS and/or Digits was Fatal; No reconstruction performed", detName.Data())) ;
2553 if ( fRunLocalReconstruction.Contains(AliQA::GetDetName(iDet)) ||
2554 fRunLocalReconstruction.Contains("ALL") ) {
2555 newRunLocalReconstruction += detName ;
2556 newRunLocalReconstruction += " " ;
2558 if ( fRunTracking.Contains(AliQA::GetDetName(iDet)) ||
2559 fRunTracking.Contains("ALL") ) {
2560 newRunTracking += detName ;
2561 newRunTracking += " " ;
2563 if ( fFillESD.Contains(AliQA::GetDetName(iDet)) ||
2564 fFillESD.Contains("ALL") ) {
2565 newFillESD += detName ;
2570 fRunLocalReconstruction = newRunLocalReconstruction ;
2571 fRunTracking = newRunTracking ;
2572 fFillESD = newFillESD ;
2575 //_____________________________________________________________________________
2576 Int_t AliReconstruction::GetDetIndex(const char* detector)
2578 // return the detector index corresponding to detector
2580 for (index = 0; index < fgkNDetectors ; index++) {
2581 if ( strcmp(detector, fgkDetectorName[index]) == 0 )
2586 //_____________________________________________________________________________
2587 Bool_t AliReconstruction::FinishPlaneEff() {
2589 // Here execute all the necessary operationis, at the end of the tracking phase,
2590 // in case that evaluation of PlaneEfficiencies was required for some detector.
2591 // E.g., write into a DataBase file the PlaneEfficiency which have been evaluated.
2593 // This Preliminary version works only FOR ITS !!!!!
2594 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2597 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2600 //for (Int_t iDet = 0; iDet < fgkNDetectors; iDet++) {
2601 for (Int_t iDet = 0; iDet < 1; iDet++) { // for the time being only ITS
2602 //if (!IsSelected(fgkDetectorName[iDet], detStr)) continue;
2603 if(fTracker[iDet]) {
2604 AliPlaneEff *planeeff=fTracker[iDet]->GetPlaneEff();
2605 ret=planeeff->WriteIntoCDB();
2606 if(planeeff->GetCreateHistos()) {
2607 TString name="PlaneEffHisto";
2608 name+=fgkDetectorName[iDet];
2610 ret*=planeeff->WriteHistosToFile(name,"RECREATE");
2616 //_____________________________________________________________________________
2617 Bool_t AliReconstruction::InitPlaneEff() {
2619 // Here execute all the necessary operations, before of the tracking phase,
2620 // for the evaluation of PlaneEfficiencies, in case required for some detectors.
2621 // E.g., read from a DataBase file a first evaluation of the PlaneEfficiency
2622 // which should be updated/recalculated.
2624 // This Preliminary version will work only FOR ITS !!!!!
2625 // other detectors (TOF,TRD, etc. have to develop their specific codes)
2628 // Return: kTRUE if all operations have been done properly, kFALSE otherwise
2630 AliWarning(Form("Implementation of this method not yet done !! Method return kTRUE"));
2634 //_____________________________________________________________________________
2635 Bool_t AliReconstruction::InitAliEVE()
2637 // This method should be called only in case
2638 // AliReconstruction is run
2639 // within the alieve environment.
2640 // It will initialize AliEVE in a way
2641 // so that it can visualize event processed
2642 // by AliReconstruction.
2643 // The return flag shows whenever the
2644 // AliEVE initialization was successful or not.
2647 macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
2648 AliInfo(Form("Loading AliEVE macro: %s",macroStr.Data()));
2649 if (gROOT->LoadMacro(macroStr.Data()) != 0) return kFALSE;
2651 gROOT->ProcessLine("if (!gAliEveEvent) {gAliEveEvent = new AliEveEventManager();gAliEveEvent->SetAutoLoad(kTRUE);gAliEveEvent->AddNewEventCommand(\"alieve_online_on_new_event()\");gEve->AddEvent(gAliEveEvent);};");
2652 gROOT->ProcessLine("alieve_online_init()");
2657 //_____________________________________________________________________________
2658 void AliReconstruction::RunAliEVE()
2660 // Runs AliEVE visualisation of
2661 // the current event.
2662 // Should be executed only after
2663 // successful initialization of AliEVE.
2665 AliInfo("Running AliEVE...");
2666 gROOT->ProcessLine(Form("gAliEveEvent->SetEvent((AliRunLoader*)%p,(AliRawReader*)%p,(AliESDEvent*)%p);",fRunLoader,fRawReader,fesd));
2667 gROOT->ProcessLine("gAliEveEvent->StartStopAutoLoadTimer();");