LCOV - code coverage report
Current view: top level - STEER/ESD - AliESDEvent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 629 1399 45.0 %
Date: 2016-06-14 17:26:59 Functions: 55 95 57.9 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       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             :  **************************************************************************/
      15             : 
      16             : /* $Id: AliESDEvent.cxx 64008 2013-08-28 13:09:59Z hristov $ */
      17             : 
      18             : //-----------------------------------------------------------------
      19             : //           Implementation of the AliESDEvent class
      20             : //   This is the class to deal with during the physics analysis of data.
      21             : //   It also ensures the backward compatibility with the old ESD format.
      22             : /*
      23             :    AliESDEvent *ev= new AliESDEvent();
      24             :    ev->ReadFromTree(esdTree);
      25             :    ...
      26             :     for (Int_t i=0; i<nev; i++) {
      27             :       esdTree->GetEntry(i);
      28             :       if(ev->GetAliESDOld())ev->CopyFromOldESD();
      29             : */
      30             : //   The AliESDInputHandler does this automatically for you
      31             : //
      32             : // Origin: Christian Klein-Boesing, CERN, Christian.Klein-Boesing@cern.ch
      33             : //-----------------------------------------------------------------
      34             : 
      35             : #include "TList.h"
      36             : #include "TRefArray.h"
      37             : #include <TNamed.h>
      38             : #include <TROOT.h>
      39             : #include <TInterpreter.h>
      40             : 
      41             : #include "event.h"
      42             : #include "AliESDEvent.h"
      43             : #include "AliESDfriend.h"
      44             : #include "AliESDVZERO.h"
      45             : #include "AliESDFMD.h"
      46             : #include "AliESD.h"
      47             : #include "AliESDMuonTrack.h"
      48             : #include "AliESDMuonCluster.h"
      49             : #include "AliESDMuonPad.h"
      50             : #include "AliESDMuonGlobalTrack.h"       // AU
      51             : #include "AliESDPmdTrack.h"
      52             : #include "AliESDTrdTrack.h"
      53             : #include "AliESDVertex.h"
      54             : #include "AliESDcascade.h"
      55             : #include "AliESDPmdTrack.h"
      56             : #include "AliESDTrdTrigger.h"
      57             : #include "AliESDTrdTrack.h"
      58             : #include "AliESDTrdTracklet.h"
      59             : #include "AliESDVertex.h"
      60             : #include "AliVertexerTracks.h"
      61             : #include "AliESDcascade.h"
      62             : #include "AliESDkink.h"
      63             : #include "AliESDtrack.h"
      64             : #include "AliESDHLTtrack.h"
      65             : #include "AliESDCaloCluster.h"
      66             : #include "AliESDCaloCells.h"
      67             : #include "AliESDv0.h"
      68             : #include "AliESDFMD.h"
      69             : #include "AliESDVZERO.h"
      70             : #include "AliMultiplicity.h"
      71             : #include "AliRawDataErrorLog.h"
      72             : #include "AliLog.h"
      73             : #include "AliESDACORDE.h"
      74             : #include "AliESDAD.h"
      75             : #include "AliESDHLTDecision.h"
      76             : #include "AliCentrality.h"
      77             : #include "AliESDCosmicTrack.h"
      78             : #include "AliTriggerConfiguration.h"
      79             : #include "AliTriggerClass.h"
      80             : #include "AliTriggerCluster.h"
      81             : #include "AliEventplane.h"
      82             : 
      83         172 : ClassImp(AliESDEvent)
      84             : 
      85             : // here we define the names, some classes are no TNamed, therefore the classnames 
      86             : // are the Names
      87             :   const char* AliESDEvent::fgkESDListName[kESDListN] = {"AliESDRun",
      88             :                                                         "AliESDHeader",
      89             :                                                         "AliESDZDC",
      90             :                                                         "AliESDFMD",
      91             :                                                         "AliESDVZERO",
      92             :                                                         "AliESDTZERO",
      93             :                                                         "TPCVertex",
      94             :                                                         "SPDVertex",
      95             :                                                         "PrimaryVertex",
      96             :                                                         "AliMultiplicity",
      97             :                                                         "PHOSTrigger",
      98             :                                                         "EMCALTrigger",
      99             :                                                         "SPDPileupVertices",
     100             :                                                         "TrkPileupVertices",
     101             :                                                         "Tracks",
     102             :                                                         "MuonTracks",
     103             :                                                         "MuonClusters",
     104             :                                                         "MuonPads",
     105             :                                                         "MuonGlobalTracks",      // AU
     106             :                                                         "PmdTracks",
     107             :                                                         "AliESDTrdTrigger",
     108             :                                                         "TrdTracks",
     109             :                                                         "TrdTracklets",
     110             :                                                         "V0s",
     111             :                                                         "Cascades",
     112             :                                                         "Kinks",
     113             :                                                         "CaloClusters",
     114             :                                                         "EMCALCells",
     115             :                                                         "PHOSCells",
     116             :                                                         "AliRawDataErrorLogs",
     117             :                                                         "AliESDACORDE",
     118             :                                                         "AliESDAD",
     119             :                                                         "AliTOFHeader",
     120             :                                                         "CosmicTracks",
     121             :                                                         "AliESDTOFCluster",
     122             :                                                         "AliESDTOFHit",
     123             :                                                         "AliESDTOFMatch",
     124             :                                                         "AliESDFIT"};
     125             : 
     126             : 
     127             : //______________________________________________________________________________
     128             : AliESDEvent::AliESDEvent():
     129          18 :   AliVEvent(),
     130          54 :   fESDObjects(new TList()),
     131          18 :   fESDRun(0),
     132          18 :   fHeader(0),
     133          18 :   fESDZDC(0),
     134          18 :   fESDFMD(0),
     135          18 :   fESDVZERO(0),
     136          18 :   fESDTZERO(0),
     137          18 :   fESDFIT(0),
     138          18 :   fTPCVertex(0),
     139          18 :   fSPDVertex(0),
     140          18 :   fPrimaryVertex(0),
     141          18 :   fSPDMult(0),
     142          18 :   fPHOSTrigger(0),
     143          18 :   fEMCALTrigger(0),
     144          18 :   fESDACORDE(0),
     145          18 :   fESDAD(0),
     146          18 :   fTrdTrigger(0),
     147          18 :   fSPDPileupVertices(0),
     148          18 :   fTrkPileupVertices(0),
     149          18 :   fTracks(0),
     150          18 :   fMuonTracks(0),
     151          18 :   fMuonClusters(0),
     152          18 :   fMuonPads(0),
     153          18 :   fMuonGlobalTracks(0),    // AU
     154          18 :   fPmdTracks(0),
     155          18 :   fTrdTracks(0),
     156          18 :   fTrdTracklets(0),
     157          18 :   fV0s(0),  
     158          18 :   fCascades(0),
     159          18 :   fKinks(0),
     160          18 :   fCaloClusters(0),
     161          18 :   fEMCALCells(0), fPHOSCells(0),
     162          18 :   fCosmicTracks(0),
     163          18 :   fESDTOFClusters(0),
     164          18 :   fESDTOFHits(0),
     165          18 :   fESDTOFMatches(0),
     166          18 :   fErrorLogs(0),
     167          18 :   fOldMuonStructure(kFALSE),
     168          18 :   fESDOld(0),
     169          18 :   fESDFriendOld(0),
     170          18 :   fConnected(kFALSE),
     171          18 :   fUseOwnList(kFALSE),
     172          18 :   fTracksConnected(kFALSE),
     173          18 :   fTOFHeader(0),
     174          18 :   fCentrality(0),
     175          18 :   fEventplane(0),
     176          18 :   fNTPCFriend2Store(0),
     177          18 :   fDetectorStatus(0xFFFFFFFF),
     178          18 :   fDAQDetectorPattern(0xFFFF),
     179          18 :   fDAQAttributes(0xFFFF),
     180          18 :   fNTPCClusters(0)
     181          90 : {
     182          36 : }
     183             : 
     184             : //______________________________________________________________________________
     185             : AliESDEvent::AliESDEvent(const AliESDEvent& esd):
     186           0 :   AliVEvent(esd),
     187           0 :   fESDObjects(new TList()),
     188           0 :   fESDRun(new AliESDRun(*esd.fESDRun)),
     189           0 :   fHeader(new AliESDHeader(*esd.fHeader)),
     190           0 :   fESDZDC(new AliESDZDC(*esd.fESDZDC)),
     191           0 :   fESDFMD(new AliESDFMD(*esd.fESDFMD)),
     192           0 :   fESDVZERO(new AliESDVZERO(*esd.fESDVZERO)),
     193           0 :   fESDTZERO(new AliESDTZERO(*esd.fESDTZERO)),
     194           0 :   fESDFIT(new AliESDFIT(*esd.fESDFIT)),
     195           0 :   fTPCVertex(new AliESDVertex(*esd.fTPCVertex)),
     196           0 :   fSPDVertex(new AliESDVertex(*esd.fSPDVertex)),
     197           0 :   fPrimaryVertex(new AliESDVertex(*esd.fPrimaryVertex)),
     198           0 :   fSPDMult(new AliMultiplicity(*esd.fSPDMult)),
     199           0 :   fPHOSTrigger(new AliESDCaloTrigger(*esd.fPHOSTrigger)),
     200           0 :   fEMCALTrigger(new AliESDCaloTrigger(*esd.fEMCALTrigger)),
     201           0 :   fESDACORDE(new AliESDACORDE(*esd.fESDACORDE)),
     202           0 :   fESDAD(new AliESDAD(*esd.fESDAD)),
     203           0 :   fTrdTrigger(new AliESDTrdTrigger(*esd.fTrdTrigger)),
     204           0 :   fSPDPileupVertices(new TClonesArray(*esd.fSPDPileupVertices)),
     205           0 :   fTrkPileupVertices(new TClonesArray(*esd.fTrkPileupVertices)),
     206           0 :   fTracks(new TClonesArray(*esd.fTracks)),
     207           0 :   fMuonTracks(new TClonesArray(*esd.fMuonTracks)),
     208           0 :   fMuonClusters(new TClonesArray(*esd.fMuonClusters)),
     209           0 :   fMuonPads(new TClonesArray(*esd.fMuonPads)),
     210           0 :   fMuonGlobalTracks(new TClonesArray(*esd.fMuonGlobalTracks)),     // AU
     211           0 :   fPmdTracks(new TClonesArray(*esd.fPmdTracks)),
     212           0 :   fTrdTracks(new TClonesArray(*esd.fTrdTracks)),
     213           0 :   fTrdTracklets(new TClonesArray(*esd.fTrdTracklets)),
     214           0 :   fV0s(new TClonesArray(*esd.fV0s)),  
     215           0 :   fCascades(new TClonesArray(*esd.fCascades)),
     216           0 :   fKinks(new TClonesArray(*esd.fKinks)),
     217           0 :   fCaloClusters(new TClonesArray(*esd.fCaloClusters)),
     218           0 :   fEMCALCells(new AliESDCaloCells(*esd.fEMCALCells)),
     219           0 :   fPHOSCells(new AliESDCaloCells(*esd.fPHOSCells)),
     220           0 :   fCosmicTracks(new TClonesArray(*esd.fCosmicTracks)),
     221           0 :   fESDTOFClusters(esd.fESDTOFClusters ? new TClonesArray(*esd.fESDTOFClusters) : 0),
     222           0 :   fESDTOFHits(esd.fESDTOFHits ? new TClonesArray(*esd.fESDTOFHits) : 0),
     223           0 :   fESDTOFMatches(esd.fESDTOFMatches ? new TClonesArray(*esd.fESDTOFMatches) : 0),
     224           0 :   fErrorLogs(new TClonesArray(*esd.fErrorLogs)),
     225           0 :   fOldMuonStructure(esd.fOldMuonStructure),
     226           0 :   fESDOld(esd.fESDOld ? new AliESD(*esd.fESDOld) : 0),
     227           0 :   fESDFriendOld(esd.fESDFriendOld ? new AliESDfriend(*esd.fESDFriendOld) : 0),
     228           0 :   fConnected(esd.fConnected),
     229           0 :   fUseOwnList(esd.fUseOwnList),
     230           0 :   fTracksConnected(kFALSE),
     231           0 :   fTOFHeader(new AliTOFHeader(*esd.fTOFHeader)),
     232           0 :   fCentrality(new AliCentrality(*esd.fCentrality)),
     233           0 :   fEventplane(new AliEventplane(*esd.fEventplane)),
     234           0 :   fNTPCFriend2Store(esd.fNTPCFriend2Store),
     235           0 :   fDetectorStatus(esd.fDetectorStatus),
     236           0 :   fDAQDetectorPattern(esd.fDAQDetectorPattern),
     237           0 :   fDAQAttributes(esd.fDAQAttributes),
     238           0 :   fNTPCClusters(esd.fNTPCClusters)
     239           0 : {
     240           0 :   printf("copying ESD event...\n");   // AU
     241             :   // CKB init in the constructor list and only add here ...
     242           0 :   AddObject(fESDRun);
     243           0 :   AddObject(fHeader);
     244           0 :   AddObject(fESDZDC);
     245           0 :   AddObject(fESDFMD);
     246           0 :   AddObject(fESDVZERO);
     247           0 :   AddObject(fESDTZERO);
     248           0 :   AddObject(fTPCVertex);
     249           0 :   AddObject(fSPDVertex);
     250           0 :   AddObject(fPrimaryVertex);
     251           0 :   AddObject(fSPDMult);
     252           0 :   AddObject(fPHOSTrigger);
     253           0 :   AddObject(fEMCALTrigger);
     254           0 :   AddObject(fTrdTrigger);
     255           0 :   AddObject(fSPDPileupVertices);
     256           0 :   AddObject(fTrkPileupVertices);
     257           0 :   AddObject(fTracks);
     258           0 :   AddObject(fMuonTracks);
     259           0 :   AddObject(fMuonGlobalTracks);    // AU
     260           0 :   AddObject(fPmdTracks);
     261           0 :   AddObject(fTrdTracks);
     262           0 :   AddObject(fTrdTracklets);
     263           0 :   AddObject(fV0s);
     264           0 :   AddObject(fCascades);
     265           0 :   AddObject(fKinks);
     266           0 :   AddObject(fCaloClusters);
     267           0 :   AddObject(fEMCALCells);
     268           0 :   AddObject(fPHOSCells);
     269           0 :   AddObject(fCosmicTracks);
     270           0 :   AddObject(fESDTOFClusters);
     271           0 :   AddObject(fESDTOFHits);
     272           0 :   AddObject(fESDTOFMatches);
     273           0 :   AddObject(fErrorLogs);
     274           0 :   AddObject(fESDACORDE);
     275           0 :   AddObject(fESDAD);
     276           0 :   AddObject(fTOFHeader);
     277           0 :   AddObject(fMuonClusters);
     278           0 :   AddObject(fMuonPads);
     279             :   //
     280           0 :   AddObject(fESDFIT);
     281           0 :   GetStdContent();
     282           0 :   ConnectTracks();
     283             : 
     284           0 : }
     285             : 
     286             : //______________________________________________________________________________
     287             : AliESDEvent & AliESDEvent::operator=(const AliESDEvent& source) {
     288             : 
     289             :   // Assignment operator
     290           4 :   printf("operator = ESD\n");
     291           2 :   if(&source == this) return *this;
     292           2 :   AliVEvent::operator=(source);
     293             : 
     294             :   // This assumes that the list is already created
     295             :   // and that the virtual void Copy(Tobject&) function
     296             :   // is correctly implemented in the derived class
     297             :   // otherwise only TObject::Copy() will be used
     298             : 
     299             : 
     300             : 
     301           2 :   if((fESDObjects->GetSize()==0)&&(source.fESDObjects->GetSize()>=kESDListN)){
     302             :     // We cover the case that we do not yet have the 
     303             :     // standard content but the source has it
     304           0 :     CreateStdContent();
     305           0 :   }
     306             : 
     307           2 :   TIter next(source.GetList());
     308             :   TObject *its = 0;
     309           2 :   TString name;
     310         112 :   while ((its = next())) {
     311         108 :     name.Form("%s", its->GetName());
     312         108 :     TObject *mine = fESDObjects->FindObject(name.Data());
     313          54 :     if(!mine){
     314           4 :       TClass* pClass=TClass::GetClass(its->ClassName());
     315           2 :       if (!pClass) {
     316           0 :         AliWarning(Form("Can not find class description for entry %s (%s)\n",
     317             :                         its->ClassName(), name.Data()));
     318           0 :         continue;
     319             :       }
     320             : 
     321           4 :       mine=(TObject*)pClass->New();
     322           2 :       if(!mine){
     323             :       // not in this: can be added to list
     324           0 :         AliWarning(Form("%s:%d Could not find %s for copying \n",
     325             :                         (char*)__FILE__,__LINE__,name.Data()));
     326           0 :         continue;
     327             :       }  
     328           4 :       if(mine->InheritsFrom("TNamed")){
     329           0 :         ((TNamed*)mine)->SetName(name);
     330             :       }
     331           4 :       else if(mine->InheritsFrom("TCollection")){
     332           0 :         if(mine->InheritsFrom("TClonesArray")) {
     333           0 :           TClonesArray* tcits = dynamic_cast<TClonesArray*>(its);
     334           0 :           if (tcits)
     335           0 :             dynamic_cast<TClonesArray*>(mine)->SetClass(tcits->GetClass());
     336           0 :         }
     337           0 :         dynamic_cast<TCollection*>(mine)->SetName(name);
     338             :       }
     339          10 :       AliDebug(1, Form("adding object %s of type %s", mine->GetName(), mine->ClassName()));
     340           2 :       AddObject(mine);
     341           2 :     }  
     342             :    
     343         108 :     if(!its->InheritsFrom("TCollection")){
     344             :       // simple objects
     345          32 :       its->Copy(*mine);
     346             :     }
     347          44 :     else if(its->InheritsFrom("TClonesArray")){
     348             :       // Create or expand the tclonesarray pointers
     349             :       // so we can directly copy to the object
     350          22 :       TClonesArray *itstca = (TClonesArray*)its;
     351          22 :       TClonesArray *minetca = (TClonesArray*)mine;
     352             : 
     353             :       // this leaves the capacity of the TClonesArray the same
     354             :       // except for a factor of 2 increase when size > capacity
     355             :       // does not release any memory occupied by the tca
     356          44 :       minetca->ExpandCreate(itstca->GetEntriesFast());
     357          66 :       for(int i = 0;i < itstca->GetEntriesFast();++i){
     358             :         // copy 
     359           0 :         TObject *minetcaobj = minetca->At(i);
     360           0 :         TObject *itstcaobj = itstca->At(i);
     361             :         // no need to delete first
     362             :         // pointers within the class should be handled by Copy()...
     363             :         // Can there be Empty slots?
     364           0 :         itstcaobj->Copy(*minetcaobj);
     365             :       }
     366          22 :     }
     367             :     else{
     368           0 :       AliWarning(Form("%s:%d cannot copy TCollection \n",
     369             :                       (char*)__FILE__,__LINE__));
     370             :     }
     371          54 :   }
     372             : 
     373           2 :   fOldMuonStructure = source.fOldMuonStructure;
     374             :   
     375           2 :   fCentrality = source.fCentrality;
     376           2 :   fEventplane = source.fEventplane;
     377           2 :   fConnected  = source.fConnected;
     378           2 :   fUseOwnList = source.fUseOwnList;
     379             : 
     380           2 :   fDetectorStatus = source.fDetectorStatus;
     381           2 :   fDAQDetectorPattern = source.fDAQDetectorPattern;
     382           2 :   fDAQAttributes = source.fDAQAttributes;
     383           2 :   fNTPCClusters = source.fNTPCClusters;
     384             : 
     385           2 :   fNTPCFriend2Store = source.fNTPCFriend2Store;
     386           2 :   fTracksConnected = kFALSE;
     387           2 :   ConnectTracks();
     388             :   return *this;
     389           4 : }
     390             : 
     391             : 
     392             : //______________________________________________________________________________
     393             : AliESDEvent::~AliESDEvent()
     394          60 : {
     395             :   //
     396             :   // Standard destructor
     397             :   //
     398             : 
     399             :   // everthing on the list gets deleted automatically
     400             : 
     401             :   
     402          20 :   if(fESDObjects&&!fConnected)
     403             :     {
     404          16 :       delete fESDObjects;
     405           8 :       fESDObjects = 0;
     406           8 :     }
     407          10 :   if (fCentrality) delete fCentrality;
     408          10 :   if (fEventplane) delete fEventplane;
     409             :   
     410             : 
     411          30 : }
     412             : 
     413             : void AliESDEvent::Copy(TObject &obj) const {
     414             : 
     415             :   // interface to TOBject::Copy
     416             :   // Copies the content of this into obj!
     417             :   // bascially obj = *this
     418             : 
     419           0 :   if(this==&obj)return;
     420           0 :   AliESDEvent *robj = dynamic_cast<AliESDEvent*>(&obj);
     421           0 :   if(!robj)return; // not an AliESEvent
     422           0 :   *robj = *this;
     423           0 :   return;
     424           0 : }
     425             : 
     426             : //______________________________________________________________________________
     427             : void AliESDEvent::Reset()
     428             : {
     429             : 
     430             :   // Handle the cases
     431             :   // Std content + Non std content
     432             :   // Reset the standard contents
     433          74 :   ResetStdContent(); 
     434          37 :   fDetectorStatus = 0xFFFFFFFF;
     435          37 :   fDAQDetectorPattern = 0xFFFF;
     436          37 :   fDAQAttributes = 0xFFFF;
     437          37 :   fNTPCClusters = 0;
     438             :   //  reset for the old data without AliESDEvent...
     439          37 :   if(fESDOld)fESDOld->Reset();
     440          37 :   if(fESDFriendOld){
     441           0 :     fESDFriendOld->~AliESDfriend();
     442           0 :     new (fESDFriendOld) AliESDfriend();
     443             :   }
     444             :   // 
     445             : 
     446          37 :   if(fESDObjects->GetSize()>kESDListN){
     447             :     // we have non std content
     448             :     // this also covers esdfriends
     449         188 :     for(int i = kESDListN;i < fESDObjects->GetSize();++i){
     450          57 :       TObject *pObject = fESDObjects->At(i);
     451             :       // TClonesArrays
     452          57 :       if(pObject->InheritsFrom(TClonesArray::Class())){
     453           0 :         ((TClonesArray*)pObject)->Delete();
     454           0 :       }
     455          57 :       else if(!pObject->InheritsFrom(TCollection::Class())){
     456          57 :         TClass *pClass = TClass::GetClass(pObject->ClassName());
     457         114 :         if (pClass && pClass->GetListOfMethods()->FindObject("Clear")) {
     458          51 :           AliDebug(1, Form("Clear for object %s class %s", pObject->GetName(), pObject->ClassName()));
     459          17 :           pObject->Clear();
     460          17 :         }
     461             :         else {
     462         120 :           AliDebug(1, Form("ResetWithPlacementNew for object %s class %s", pObject->GetName(), pObject->ClassName()));
     463          40 :           ResetWithPlacementNew(pObject);
     464             :         }
     465          57 :       }
     466             :       else{
     467           0 :         AliWarning(Form("No reset for %s \n",
     468             :                         pObject->ClassName()));
     469             :       }
     470             :     }
     471          37 :   }
     472             : 
     473          37 : }
     474             : 
     475             : //______________________________________________________________________________
     476             : Bool_t AliESDEvent::ResetWithPlacementNew(TObject *pObject){
     477             :   //
     478             :   // funtion to reset using the already allocated space
     479             :   //
     480          80 :   Long_t dtoronly = TObject::GetDtorOnly();
     481          40 :   TClass *pClass = TClass::GetClass(pObject->ClassName()); 
     482          40 :   TObject::SetDtorOnly(pObject);
     483          80 :   delete pObject;
     484             :   // Recreate with placement new
     485          40 :   pClass->New(pObject);
     486             :   // Restore the state.
     487          40 :   TObject::SetDtorOnly((void*)dtoronly);
     488          40 :   return kTRUE;
     489             : }
     490             : 
     491             : //______________________________________________________________________________
     492             : void AliESDEvent::ResetStdContent()
     493             : {
     494             :   // Reset the standard contents
     495         107 :   if(fESDRun) fESDRun->Reset();
     496          70 :   if(fHeader) fHeader->Reset();
     497          45 :   if(fCentrality) fCentrality->Reset();
     498          45 :   if(fEventplane) fEventplane->Reset();
     499          70 :   if(fESDZDC) fESDZDC->Reset();
     500          37 :   if(fESDFMD) {
     501          33 :     fESDFMD->Clear();
     502          33 :   }
     503          37 :   if(fESDVZERO){
     504             :     // reset by callin d'to /c'tor keep the pointer
     505          33 :     fESDVZERO->~AliESDVZERO();
     506          33 :     new (fESDVZERO) AliESDVZERO();
     507             :   }  
     508          37 :   if(fESDACORDE){
     509          33 :     fESDACORDE->~AliESDACORDE();
     510          33 :     new (fESDACORDE) AliESDACORDE();    
     511             :   } 
     512             : 
     513          37 :   if(fESDAD){
     514          33 :     fESDAD->~AliESDAD();
     515          33 :     new (fESDAD) AliESDAD();    
     516             :   } 
     517             : 
     518          70 :   if(fESDFIT) fESDFIT->Reset(); 
     519             : 
     520          70 :   if(fESDTZERO) fESDTZERO->Reset(); 
     521             :   // CKB no clear/reset implemented
     522          37 :   if(fTPCVertex){
     523          33 :     fTPCVertex->~AliESDVertex();
     524          33 :     new (fTPCVertex) AliESDVertex();
     525          33 :     fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
     526          33 :   }
     527          37 :   if(fSPDVertex){
     528          33 :     fSPDVertex->~AliESDVertex();
     529          33 :     new (fSPDVertex) AliESDVertex();
     530          33 :     fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
     531          33 :   }
     532          37 :   if(fPrimaryVertex){
     533          33 :     fPrimaryVertex->~AliESDVertex();
     534          33 :     new (fPrimaryVertex) AliESDVertex();
     535          33 :     fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
     536          33 :   }
     537          37 :   if(fSPDMult){
     538          33 :     fSPDMult->~AliMultiplicity();
     539          33 :     new (fSPDMult) AliMultiplicity();
     540             :   }
     541          37 :   if(fTOFHeader){
     542          33 :     fTOFHeader->~AliTOFHeader();
     543          33 :     new (fTOFHeader) AliTOFHeader();
     544             :     //fTOFHeader->SetName(fgkESDListName[kTOFHeader]);
     545             :   }
     546          37 :   if (fTrdTrigger) {
     547          35 :     fTrdTrigger->~AliESDTrdTrigger();
     548          35 :     new (fTrdTrigger) AliESDTrdTrigger();
     549             :   }
     550             :         
     551          70 :   if(fPHOSTrigger)fPHOSTrigger->DeAllocate(); 
     552          70 :   if(fEMCALTrigger)fEMCALTrigger->DeAllocate(); 
     553          70 :   if(fSPDPileupVertices)fSPDPileupVertices->Delete();
     554          70 :   if(fTrkPileupVertices)fTrkPileupVertices->Delete();
     555          37 :   fTracksConnected = kFALSE;
     556          70 :   if(fTracks)fTracks->Delete();
     557          70 :   if(fMuonTracks)fMuonTracks->Clear("C");
     558          70 :   if(fMuonClusters)fMuonClusters->Clear("C");
     559          70 :   if(fMuonPads)fMuonPads->Clear("C");
     560          70 :   if(fMuonGlobalTracks)fMuonGlobalTracks->Clear("C");     // AU
     561          70 :   if(fPmdTracks)fPmdTracks->Delete();
     562          70 :   if(fTrdTracks)fTrdTracks->Delete();
     563          70 :   if(fTrdTracklets)fTrdTracklets->Delete();
     564          70 :   if(fV0s)fV0s->Delete();
     565          70 :   if(fCascades)fCascades->Delete();
     566          70 :   if(fKinks)fKinks->Delete();
     567          70 :   if(fCaloClusters)fCaloClusters->Delete();
     568          70 :   if(fPHOSCells)fPHOSCells->DeleteContainer();
     569          70 :   if(fEMCALCells)fEMCALCells->DeleteContainer();
     570          70 :   if(fCosmicTracks)fCosmicTracks->Delete();
     571          70 :   if(fESDTOFClusters)fESDTOFClusters->Clear();
     572          70 :   if(fESDTOFHits)fESDTOFHits->Clear();
     573          70 :   if(fESDTOFMatches)fESDTOFMatches->Clear();
     574          70 :   if(fErrorLogs) fErrorLogs->Delete();
     575             : 
     576             :   // don't reset fconnected fConnected and the list
     577             : 
     578          37 : }
     579             : 
     580             : 
     581             : //______________________________________________________________________________
     582             : Int_t AliESDEvent::AddV0(const AliESDv0 *v) {
     583             :   //
     584             :   // Add V0
     585             :   //
     586          56 :   TClonesArray &fv = *fV0s;
     587          28 :   Int_t idx=fV0s->GetEntriesFast();
     588          28 :   new(fv[idx]) AliESDv0(*v);
     589          28 :   return idx;
     590           0 : }  
     591             : 
     592             : //______________________________________________________________________________
     593             : Bool_t AliESDEvent::IsDetectorInTriggerCluster(TString detector, AliTriggerConfiguration* trigConf) const {
     594             :   // Check if a given detector was read-out in the analyzed event
     595           0 :   const TObjArray& classesArray=trigConf->GetClasses();
     596           0 :   ULong64_t trigMask=GetTriggerMask();
     597           0 :   ULong64_t trigMaskNext50=GetTriggerMaskNext50();
     598           0 :   Int_t nclasses = classesArray.GetEntriesFast();
     599           0 :   for(Int_t iclass=0; iclass < nclasses; iclass++ ) {
     600           0 :     AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
     601           0 :     ULong64_t classMask=trclass->GetMask();
     602           0 :     ULong64_t classMaskNext50=trclass->GetMaskNext50();
     603           0 :     if(trigMask & classMask){
     604           0 :       TString detList=trclass->GetCluster()->GetDetectorsInCluster();
     605           0 :       if(detList.Contains(detector.Data())){
     606           0 :         return kTRUE;
     607             :       }
     608           0 :     }
     609           0 :     if(trigMaskNext50 & classMaskNext50){
     610           0 :       TString detList=trclass->GetCluster()->GetDetectorsInCluster();
     611           0 :       if(detList.Contains(detector.Data())){
     612           0 :         return kTRUE;
     613             :       }
     614           0 :     }
     615           0 :   }
     616           0 :   return kFALSE; 
     617           0 : }
     618             : //______________________________________________________________________________
     619             : void AliESDEvent::Print(Option_t *) const 
     620             : {
     621             :   //
     622             :   // Print header information of the event
     623             :   //
     624           0 :   printf("ESD run information\n");
     625           0 :   printf("Event # in file %d Bunch crossing # %d Orbit # %d Period # %d Run # %d Trigger %lld %lld Magnetic field %f \n",
     626           0 :          GetEventNumberInFile(),
     627           0 :          GetBunchCrossNumber(),
     628           0 :          GetOrbitNumber(),
     629           0 :          GetPeriodNumber(),
     630           0 :          GetRunNumber(),
     631           0 :          GetTriggerMask(),
     632           0 :          GetTriggerMaskNext50(),
     633           0 :          GetMagneticField() );
     634           0 :   if (fPrimaryVertex)
     635           0 :     printf("Vertex: (%.4f +- %.4f, %.4f +- %.4f, %.4f +- %.4f) cm\n",
     636           0 :            fPrimaryVertex->GetX(), fPrimaryVertex->GetXRes(),
     637           0 :            fPrimaryVertex->GetY(), fPrimaryVertex->GetYRes(),
     638           0 :            fPrimaryVertex->GetZ(), fPrimaryVertex->GetZRes());
     639           0 :   printf("Mean vertex in RUN: X=%.4f Y=%.4f Z=%.4f cm\n",
     640           0 :          GetDiamondX(),GetDiamondY(),GetDiamondZ());
     641           0 :   if(fSPDMult)
     642           0 :     printf("SPD Multiplicity. Number of tracklets %d \n",
     643           0 :            fSPDMult->GetNumberOfTracklets());
     644           0 :   printf("Number of pileup primary vertices reconstructed with SPD %d\n", 
     645           0 :          GetNumberOfPileupVerticesSPD());
     646           0 :   printf("Number of pileup primary vertices reconstructed using the tracks %d\n",
     647           0 :          GetNumberOfPileupVerticesTracks());
     648           0 :   printf("Number of tracks: \n");
     649           0 :   printf("                 charged   %d\n", GetNumberOfTracks());
     650           0 :   printf("                 muon      %d\n", GetNumberOfMuonTracks());
     651           0 :   printf("                 glob muon %d\n", GetNumberOfMuonGlobalTracks());    // AU
     652           0 :   printf("                 pmd       %d\n", GetNumberOfPmdTracks());
     653           0 :   printf("                 trd       %d\n", GetNumberOfTrdTracks());
     654           0 :   printf("                 trd trkl  %d\n", GetNumberOfTrdTracklets());
     655           0 :   printf("                 v0        %d\n", GetNumberOfV0s());
     656           0 :   printf("                 cascades  %d\n", GetNumberOfCascades());
     657           0 :   printf("                 kinks     %d\n", GetNumberOfKinks());
     658           0 :   if(fPHOSCells)printf("                 PHOSCells %d\n", fPHOSCells->GetNumberOfCells());
     659           0 :   else printf("                 PHOSCells not in the Event\n");
     660           0 :   if(fEMCALCells)printf("                 EMCALCells %d\n", fEMCALCells->GetNumberOfCells());
     661           0 :   else printf("                 EMCALCells not in the Event\n");
     662           0 :   printf("                 CaloClusters %d\n", GetNumberOfCaloClusters());
     663           0 :   printf("                 FMD       %s\n", (fESDFMD ? "yes" : "no"));
     664           0 :   printf("                 VZERO     %s\n", (fESDVZERO ? "yes" : "no"));
     665           0 :   printf("                 muClusters %d\n", fMuonClusters ? fMuonClusters->GetEntriesFast() : 0);
     666           0 :   printf("                 muPad     %d\n", fMuonPads ? fMuonPads->GetEntriesFast() : 0);
     667           0 :   if (fCosmicTracks) printf("                 Cosmics   %d\n",  GetNumberOfCosmicTracks());
     668             :         
     669           0 :   TObject* pHLTDecision=GetHLTTriggerDecision();
     670           0 :   printf("HLT trigger decision: %s\n", pHLTDecision?pHLTDecision->GetOption():"not available");
     671           0 :   if (pHLTDecision) pHLTDecision->Print("compact");
     672             : 
     673             :   return;
     674           0 : }
     675             : 
     676             : //______________________________________________________________________________
     677             : void AliESDEvent::SetESDfriend(const AliESDfriend *ev) const 
     678             : {
     679             : //
     680             : // Attaches the complementary info to the ESD
     681             : //
     682          16 :   if (!ev) return;
     683             : 
     684             :   // to be sure that we set the tracks also
     685             :   // in case of old esds 
     686             :   // if(fESDOld)CopyFromOldESD();
     687             : 
     688           8 :   Int_t ntrkF=ev->GetNumberOfTracks();
     689           8 :   if (ev->GetESDIndicesStored()) { // new format: sparse friends
     690           0 :     for (Int_t i=0; i<ntrkF; i++) {
     691           0 :       AliESDfriendTrack *f=ev->GetTrack(i);
     692           0 :       int esdid = f->GetESDtrackID();
     693           0 :       AliESDtrack* esdt = GetTrack(esdid);
     694           0 :       if (!esdt) {AliFatalF("ESDfriendTrack %d points on non-existing ESDtrack %d",i,esdid);}
     695           0 :       if (esdt->GetFriendNotStored()) {AliFatalF("ESDtrack %d did not store the friend, but ESDfriendTrack %d points on it",esdid,i);}
     696           0 :       esdt->SetFriendTrack(f);
     697             :     }
     698           0 :   }
     699             :   else {
     700          16 :     for (Int_t i=0; i<ntrkF; i++) { // old format: 1 to 1 correspondence
     701           0 :       const AliESDfriendTrack *f=ev->GetTrack(i);
     702           0 :       if (!f) {AliFatal(Form("NULL pointer for ESD track %d",i));}
     703           0 :       GetTrack(i)->SetFriendTrack(f);
     704             :     }
     705             :   }
     706          16 : }
     707             : 
     708             : //______________________________________________________________________________
     709             : Bool_t  AliESDEvent::RemoveKink(Int_t rm) const 
     710             : {
     711             : // ---------------------------------------------------------
     712             : // Remove a kink candidate and references to it from ESD,
     713             : // if this candidate does not come from a reconstructed decay
     714             : // Not yet implemented...
     715             : // ---------------------------------------------------------
     716           0 :   Int_t last=GetNumberOfKinks()-1;
     717           0 :   if ((rm<0)||(rm>last)) return kFALSE;
     718           0 :   TClonesArray &a=*fKinks;
     719           0 :   AliESDkink* kink = GetKink(rm);
     720             :   // release kink indices from ESDtracks
     721           0 :   for (int i=2;i--;) {
     722           0 :     AliESDtrack* trc = GetTrack(kink->GetIndex(i));
     723           0 :     int indK[3]={0,0,0},restK=0;
     724           0 :     for (int j=0;j<3;j++) {
     725           0 :       int ind = trc->GetKinkIndex(j);
     726           0 :       if (!ind) break;
     727           0 :       if (TMath::Abs(ind)!=rm+1) indK[restK++] = ind;
     728           0 :     }
     729           0 :     trc->SetKinkIndexes(indK);
     730           0 :   }
     731             :   //
     732           0 :   a.RemoveAt(rm);
     733           0 :   if (rm==last) return kTRUE;
     734           0 :   kink = GetKink(last);
     735           0 :   new (a[rm]) AliESDkink(*kink);
     736             :   // 
     737             :   // update references on the moved kink
     738           0 :   for (int i=2;i--;) {
     739           0 :     AliESDtrack* trc = GetTrack(kink->GetIndex(i));
     740           0 :     int indK[3]={0,0,0},restK=0;
     741           0 :     for (int j=0;j<3;j++) {
     742           0 :       int ind = trc->GetKinkIndex(j);
     743           0 :       if (!ind) break;
     744             :       int lastI = last+1;
     745           0 :       if (ind==lastI) indK[j] = lastI;
     746           0 :       else if (ind==-lastI) indK[j] = -lastI;
     747           0 :     }
     748           0 :     trc->SetKinkIndexes(indK);
     749           0 :   }
     750             :   //
     751           0 :   return kTRUE;
     752           0 : }
     753             : 
     754             : //______________________________________________________________________________
     755             : Bool_t  AliESDEvent::RemoveV0(Int_t rm) const 
     756             : {
     757             : // ---------------------------------------------------------
     758             : // Remove a V0 candidate and references to it from ESD,
     759             : // if this candidate does not come from a reconstructed decay
     760             : // ---------------------------------------------------------
     761           4 :   Int_t last=GetNumberOfV0s()-1;
     762           4 :   if ((rm<0)||(rm>last)) return kFALSE;
     763             : 
     764           2 :   AliESDv0 *v0=GetV0(rm);
     765           2 :   Int_t idxP=v0->GetPindex(), idxN=v0->GetNindex();
     766             : 
     767           2 :   v0=GetV0(last);
     768           2 :   Int_t lastIdxP=v0->GetPindex(), lastIdxN=v0->GetNindex();
     769             : 
     770             :   Int_t used=0;
     771             : 
     772             :   /* // RS if it is, so what? Cascade has complete information
     773             :   // Check if this V0 comes from a reconstructed decay
     774             :   Int_t ncs=GetNumberOfCascades();
     775             :   for (Int_t n=0; n<ncs; n++) {
     776             :     AliESDcascade *cs=GetCascade(n);
     777             : 
     778             :     Int_t csIdxP=cs->GetPindex();
     779             :     Int_t csIdxN=cs->GetNindex();
     780             : 
     781             :     if (idxP==csIdxP)
     782             :        if (idxN==csIdxN) return kFALSE;
     783             : 
     784             :     if (csIdxP==lastIdxP)
     785             :        if (csIdxN==lastIdxN) used++;
     786             :   }
     787             :   */ 
     788             : 
     789             :   //Replace the removed V0 with the last V0 
     790           2 :   TClonesArray &a=*fV0s;
     791           2 :   delete a.RemoveAt(rm);
     792             : 
     793           2 :   if (rm==last) return kTRUE;
     794             : 
     795             :   //v0 is pointing to the last V0 candidate... 
     796           2 :   new (a[rm]) AliESDv0(*v0);
     797           2 :   delete a.RemoveAt(last);
     798             : 
     799             :   /* 
     800             :      // RS: why do we need to remap indices of the tracks when just the V0 is removed?
     801             : 
     802             :   if (!used) return kTRUE;
     803             :   
     804             : 
     805             :   // Remap the indices of the daughters of reconstructed decays
     806             :   for (Int_t n=0; n<ncs; n++) {
     807             :     AliESDcascade *cs=GetCascade(n);
     808             : 
     809             : 
     810             :     Int_t csIdxP=cs->GetPindex();
     811             :     Int_t csIdxN=cs->GetNindex();
     812             : 
     813             :     if (csIdxP==lastIdxP)
     814             :       if (csIdxN==lastIdxN) {
     815             :          cs->AliESDv0::SetIndex(1,idxP);
     816             :          cs->AliESDv0::SetIndex(0,idxN);
     817             :          used--;
     818             :          if (!used) return kTRUE;
     819             :       }
     820             :   }
     821             :   */
     822           2 :   return kTRUE;
     823           2 : }
     824             : 
     825             : //______________________________________________________________________________
     826             : AliESDfriendTrack*  AliESDEvent::RemoveTrack(Int_t rm) const 
     827             : {
     828             : // ---------------------------------------------------------
     829             : // Remove a track and references to it from ESD,
     830             : // if this track does not come from a reconstructed decay
     831             : // ---------------------------------------------------------
     832          20 :   Int_t last=GetNumberOfTracks()-1;
     833          20 :   if ((rm<0)||(rm>last)) return 0;
     834             : 
     835             :   Int_t used=0;
     836             : 
     837             :   // Check if this track comes from the reconstructed primary vertices
     838          20 :   if (fTPCVertex && fTPCVertex->GetStatus()) {
     839          10 :      UShort_t *primIdx=fTPCVertex->GetIndices();
     840          10 :      Int_t n=fTPCVertex->GetNIndices();
     841         122 :      while (n--) {
     842         102 :        Int_t idx=Int_t(primIdx[n]);
     843         102 :        if (rm==idx) return 0;
     844         102 :        if (idx==last) used++; 
     845         102 :      }
     846          10 :   }
     847          20 :   if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
     848          10 :      UShort_t *primIdx=fPrimaryVertex->GetIndices();
     849          10 :      Int_t n=fPrimaryVertex->GetNIndices();
     850         122 :      while (n--) {
     851         102 :        Int_t idx=Int_t(primIdx[n]);
     852         102 :        if (rm==idx) return 0;
     853         112 :        if (idx==last) used++; 
     854         102 :      }
     855          10 :   }
     856             :   
     857             :   // Check if this track comes from a reconstructed decay
     858          10 :   Int_t nv0=GetNumberOfV0s();
     859          86 :   for (Int_t n=0; n<nv0; n++) {
     860          28 :     AliESDv0 *v0=GetV0(n);
     861             : 
     862          28 :     Int_t idx=v0->GetNindex();
     863          28 :     if (rm==idx) return 0;
     864          28 :     if (idx==last) used++;
     865             : 
     866          28 :     idx=v0->GetPindex();
     867          28 :     if (rm==idx) return 0;
     868          28 :     if (idx==last) used++;
     869          28 :   }
     870             : 
     871          10 :   Int_t ncs=GetNumberOfCascades();
     872          30 :   for (Int_t n=0; n<ncs; n++) {
     873           0 :     AliESDcascade *cs=GetCascade(n);
     874             : 
     875           0 :     Int_t idx=cs->GetIndex();
     876           0 :     if (rm==idx) return 0;
     877           0 :     if (idx==last) used++;
     878             : 
     879           0 :     AliESDv0 *v0=cs;
     880           0 :     idx=v0->GetNindex();
     881           0 :     if (rm==idx) return 0;
     882           0 :     if (idx==last) used++;
     883             : 
     884           0 :     idx=v0->GetPindex();
     885           0 :     if (rm==idx) return 0;
     886           0 :     if (idx==last) used++;
     887           0 :   }
     888             : 
     889          10 :   Int_t nkn=GetNumberOfKinks();
     890             :   /*RS
     891             :   for (Int_t n=0; n<nkn; n++) {
     892             :     AliESDkink *kn=GetKink(n);
     893             : 
     894             :     Int_t idx=kn->GetIndex(0);
     895             :     if (rm==idx) return 0;
     896             :     if (idx==last) used++;
     897             : 
     898             :     idx=kn->GetIndex(1);
     899             :     if (rm==idx) return 0;
     900             :     if (idx==last) used++;
     901             :   }
     902             :   */
     903             :   // Check if this track is associated with a CaloCluster
     904          10 :   Int_t ncl=GetNumberOfCaloClusters();
     905             : 
     906         146 :   for (Int_t n=0; n<ncl; n++) {
     907          58 :     AliESDCaloCluster *cluster=GetCaloCluster(n);
     908          58 :     TArrayI *arr=cluster->GetTracksMatched();
     909          58 :     Int_t s=arr->GetSize();
     910         146 :     while (s--) {
     911          30 :       Int_t idx=arr->At(s);
     912          30 :       if (rm==idx) return 0;
     913          30 :       if (idx==last) used++;     
     914          30 :     }
     915          58 :   }
     916             : 
     917             : 
     918             :   // from here on we remove the track
     919             :   //
     920             :   //Replace the removed track with the last track 
     921          10 :   TClonesArray &a=*fTracks;
     922          10 :   AliESDtrack* trm = GetTrack(rm);
     923          10 :   trm->SuppressTOFMatches(); // remove reference to this track from stored TOF clusters
     924          10 :   AliESDfriendTrack* trfKeep = (AliESDfriendTrack*)trm->GetFriendTrack(); // friend should be cleaned in the reco
     925          10 :   trm->ReleaseESDfriendTrack();
     926          10 :   a.RemoveAt(rm);
     927             :   //
     928          10 :   if (rm==last) return trfKeep;
     929             : 
     930          10 :   AliESDtrack *t=GetTrack(last);
     931          10 :   if (!t) {AliFatal(Form("NULL pointer for ESD track %d",last));}
     932          10 :   t->SetID(rm);
     933             :   //
     934             :   // RS: we need to transfer the eventual friend track pointer, w/o creating a clone
     935          10 :   AliESDfriendTrack* tfr = (AliESDfriendTrack*)t->GetFriendTrack();
     936          10 :   t->ReleaseESDfriendTrack(); // nullify friend pointer
     937          10 :   AliESDtrack* trMove = new (a[rm]) AliESDtrack(*t);
     938          10 :   trMove->SetFriendTrackPointer(tfr);
     939          10 :   trMove->SetFriendTrackID(trm->GetFriendTrackID());
     940          10 :   trMove->SetFriendNotStored(tfr==0);
     941          10 :   tfr->SetESDtrackID(rm);
     942          10 :   delete a.RemoveAt(last);
     943             : 
     944          10 :   if (!used) return trfKeep;
     945             :   
     946             : 
     947             :   // Remap the indices of the tracks used for the primary vertex reconstruction
     948          20 :   if (fTPCVertex && fTPCVertex->GetStatus()) {
     949          10 :      UShort_t *primIdx=fTPCVertex->GetIndices();
     950          10 :      Int_t n=fTPCVertex->GetNIndices();
     951         122 :      while (n--) {
     952         102 :        Int_t idx=Int_t(primIdx[n]);
     953         102 :        if (idx==last) {
     954           0 :           primIdx[n]=Short_t(rm); 
     955           0 :           used--;
     956           0 :           if (!used) return trfKeep;
     957             :        }
     958         102 :      }
     959          10 :   }  
     960          20 :   if (fPrimaryVertex && fPrimaryVertex->GetStatus()) {
     961          10 :      UShort_t *primIdx=fPrimaryVertex->GetIndices();
     962          10 :      Int_t n=fPrimaryVertex->GetNIndices();
     963          24 :      while (n--) {
     964          14 :        Int_t idx=Int_t(primIdx[n]);
     965          14 :        if (idx==last) {
     966          10 :           primIdx[n]=Short_t(rm); 
     967          10 :           used--;
     968          20 :           if (!used) return trfKeep;
     969             :        }
     970           4 :      }
     971           0 :   }  
     972             : 
     973             :   // Remap the indices of the daughters of reconstructed decays
     974           0 :   for (Int_t n=0; n<nv0; n++) {
     975           0 :     AliESDv0 *v0=GetV0(n);
     976           0 :     if (v0->GetIndex(0)==last) {
     977           0 :        v0->SetIndex(0,rm);
     978           0 :        used--;
     979           0 :        if (!used) return trfKeep;
     980             :     }
     981           0 :     if (v0->GetIndex(1)==last) {
     982           0 :        v0->SetIndex(1,rm);
     983           0 :        used--;
     984           0 :        if (!used) return trfKeep;
     985             :     }
     986           0 :   }
     987             : 
     988           0 :   for (Int_t n=0; n<ncs; n++) {
     989           0 :     AliESDcascade *cs=GetCascade(n);
     990           0 :     if (cs->GetIndex()==last) {
     991           0 :        cs->SetIndex(rm);
     992           0 :        used--;
     993           0 :        if (!used) return trfKeep;
     994             :     }
     995           0 :     AliESDv0 *v0=cs;
     996           0 :     if (v0->GetIndex(0)==last) {
     997           0 :        v0->SetIndex(0,rm);
     998           0 :        used--;
     999           0 :        if (!used) return trfKeep;
    1000             :     }
    1001           0 :     if (v0->GetIndex(1)==last) {
    1002           0 :        v0->SetIndex(1,rm);
    1003           0 :        used--;
    1004           0 :        if (!used) return trfKeep;
    1005             :     }
    1006           0 :   }
    1007             : 
    1008           0 :   for (Int_t n=0; n<nkn; n++) {
    1009           0 :     AliESDkink *kn=GetKink(n);
    1010           0 :     if (kn->GetIndex(0)==last) {
    1011           0 :        kn->SetIndex(rm,0);
    1012           0 :        used--;
    1013           0 :        if (!used) return trfKeep;
    1014             :     }
    1015           0 :     if (kn->GetIndex(1)==last) {
    1016           0 :        kn->SetIndex(rm,1);
    1017           0 :        used--;
    1018           0 :        if (!used) return trfKeep;
    1019             :     }
    1020           0 :   }
    1021             : 
    1022             :   // Remap the indices of the tracks accosicated with CaloClusters
    1023           0 :   for (Int_t n=0; n<ncl; n++) {
    1024           0 :     AliESDCaloCluster *cluster=GetCaloCluster(n);
    1025           0 :     TArrayI *arr=cluster->GetTracksMatched();
    1026           0 :     Int_t s=arr->GetSize();
    1027           0 :     while (s--) {
    1028           0 :       Int_t idx=arr->At(s);
    1029           0 :       if (idx==last) {
    1030           0 :          arr->AddAt(rm,s);
    1031           0 :          used--; 
    1032           0 :          if (!used) return trfKeep;
    1033             :       }
    1034           0 :     }
    1035           0 :   }
    1036             : 
    1037           0 :   return trfKeep;
    1038          10 : }
    1039             : 
    1040             : //______________________________________________________________________________
    1041             : Bool_t AliESDEvent::Clean(Float_t *cleanPars, TObjArray* tracks2destroy) 
    1042             : {
    1043             :   //
    1044             :   // Remove the data which are not needed for the physics analysis.
    1045             :   //
    1046             :   // 1) Cleaning the V0 candidates
    1047             :   //    ---------------------------
    1048             :   //    If the cosine of the V0 pointing angle "csp" and 
    1049             :   //    the DCA between the daughter tracks "dca" does not satisfy 
    1050             :   //    the conditions 
    1051             :   //
    1052             :   //     csp > cleanPars[1] + dca/cleanPars[0]*(1.- cleanPars[1])
    1053             :   //
    1054             :   //    an attempt to remove this V0 candidate from ESD is made.
    1055             :   //
    1056             :   //    The V0 candidate gets removed if it does not belong to any 
    1057             :   //    recosntructed cascade decay
    1058             :   //
    1059             :   //    12.11.2007, optimal values: cleanPars[0]=0.5, cleanPars[1]=0.999
    1060             :   //
    1061             :   // 2) Cleaning the tracks
    1062             :   //    ----------------------
    1063             :   //    If track's transverse parameter is larger than cleanPars[2]
    1064             :   //                       OR
    1065             :   //    track's longitudinal parameter is larger than cleanPars[3]
    1066             :   //    an attempt to remove this track from ESD is made.
    1067             :   //
    1068             :   //    The track gets removed if it does not come 
    1069             :   //    from a reconstructed decay
    1070             :   //
    1071             :   Bool_t rc=kFALSE;
    1072             : 
    1073          16 :   Float_t dcaMax=cleanPars[0];
    1074           8 :   Float_t cspMin=cleanPars[1];
    1075             : 
    1076           8 :   Int_t nV0s=GetNumberOfV0s();
    1077          72 :   for (Int_t i=nV0s-1; i>=0; i--) {
    1078          28 :     AliESDv0 *v0=GetV0(i);
    1079             : 
    1080          28 :     Float_t dca=v0->GetDcaV0Daughters();
    1081          28 :     Float_t csp=v0->GetV0CosineOfPointingAngle();
    1082          28 :     Float_t cspcut=cspMin + dca/dcaMax*(1.-cspMin);
    1083          54 :     if (csp > cspcut) continue;
    1084           4 :     if (RemoveV0(i)) rc=kTRUE;
    1085           2 :   }
    1086             : 
    1087             : 
    1088           8 :   Float_t dmax=cleanPars[2], zmax=cleanPars[3];
    1089             : 
    1090           8 :   const AliESDVertex *vertex=GetPrimaryVertexSPD();
    1091           8 :   Bool_t vtxOK=vertex->GetStatus();
    1092             : 
    1093           8 :   tracks2destroy->Clear();
    1094             : 
    1095           8 :   Int_t nTracks=GetNumberOfTracks();
    1096         320 :   for (Int_t i=nTracks-1; i>=0; i--) {
    1097         152 :     AliESDtrack *track=GetTrack(i);
    1098         152 :     if (!track) {AliFatal(Form("NULL pointer for ESD track %d",i));}
    1099         152 :     Float_t xy,z; track->GetImpactParameters(xy,z);
    1100         448 :     if ((TMath::Abs(xy) > dmax) || (vtxOK && (TMath::Abs(z) > zmax))) {
    1101          10 :       AliESDfriendTrack *remTr = RemoveTrack(i);
    1102          10 :       if (remTr) {
    1103             :         rc=kTRUE;
    1104          10 :         tracks2destroy->Add(remTr);
    1105          10 :       }
    1106          10 :     }
    1107         152 :   }
    1108             : 
    1109           8 :   return rc;
    1110             : }
    1111             : 
    1112             : //______________________________________________________________________________
    1113             : Char_t  AliESDEvent::AddPileupVertexSPD(const AliESDVertex *vtx) 
    1114             : {
    1115             :     // Add a pileup primary vertex reconstructed with SPD
    1116           0 :     TClonesArray &ftr = *fSPDPileupVertices;
    1117           0 :     Char_t n=Char_t(ftr.GetEntriesFast());
    1118           0 :     AliESDVertex *vertex = new(ftr[n]) AliESDVertex(*vtx);
    1119           0 :     vertex->SetID(n);
    1120           0 :     return n;
    1121           0 : }
    1122             : 
    1123             : //______________________________________________________________________________
    1124             : Char_t  AliESDEvent::AddPileupVertexTracks(const AliESDVertex *vtx) 
    1125             : {
    1126             :     // Add a pileup primary vertex reconstructed with SPD
    1127           0 :     TClonesArray &ftr = *fTrkPileupVertices;
    1128           0 :     Char_t n=Char_t(ftr.GetEntriesFast());
    1129           0 :     AliESDVertex *vertex = new(ftr[n]) AliESDVertex(*vtx);
    1130           0 :     vertex->SetID(n);
    1131           0 :     return n;
    1132           0 : }
    1133             : 
    1134             : //______________________________________________________________________________
    1135             : Int_t  AliESDEvent::AddTrack(const AliESDtrack *t) 
    1136             : {
    1137             :     // Add track
    1138         304 :     TClonesArray &ftr = *fTracks;
    1139         152 :     AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack(*t);
    1140         152 :     track->SetID(fTracks->GetEntriesFast()-1);
    1141         152 :     track->SetESDEvent(this);
    1142         152 :     return  track->GetID();    
    1143           0 : }
    1144             : 
    1145             : //______________________________________________________________________________
    1146             : AliESDtrack*  AliESDEvent::NewTrack() 
    1147             : {
    1148             :     // Add a new track
    1149           0 :     TClonesArray &ftr = *fTracks;
    1150           0 :     AliESDtrack * track = new(ftr[fTracks->GetEntriesFast()])AliESDtrack();
    1151           0 :     track->SetID(fTracks->GetEntriesFast()-1);
    1152           0 :     track->SetESDEvent(this);
    1153           0 :     return  track;
    1154           0 : }
    1155             : 
    1156             : //______________________________________________________________________________
    1157             : Bool_t AliESDEvent::MoveMuonObjects() 
    1158             : {
    1159             :   // move MUON clusters and pads to the new ESD structure in needed.
    1160             :   // to ensure backward compatibility
    1161             :   
    1162         648 :   if (!fOldMuonStructure) return kTRUE;
    1163             :   
    1164           0 :   if (!fMuonTracks || !fMuonClusters || !fMuonPads) return kFALSE;
    1165             :   
    1166             :   Bool_t reset = kTRUE;
    1167             :   Bool_t containTrackerData = kFALSE;
    1168           0 :   for (Int_t i = 0; i < fMuonTracks->GetEntriesFast(); i++) {
    1169             :     
    1170           0 :     AliESDMuonTrack *track = (AliESDMuonTrack*) fMuonTracks->UncheckedAt(i);
    1171             :     
    1172           0 :     if (track->ContainTrackerData()) containTrackerData = kTRUE;
    1173           0 :     else continue;
    1174             :     
    1175           0 :     if (!track->IsOldTrack()) continue;
    1176             :     
    1177             :     // remove objects connected to previous event if needed
    1178           0 :     if (reset) {
    1179           0 :       if (fMuonClusters->GetEntriesFast() > 0) fMuonClusters->Clear("C");
    1180           0 :       if (fMuonPads->GetEntriesFast() > 0) fMuonPads->Clear("C");
    1181             :       reset = kFALSE;
    1182           0 :     }
    1183             :     
    1184           0 :     track->MoveClustersToESD(*this);
    1185             :     
    1186           0 :   }
    1187             :   
    1188             :   // remove objects connected to previous event if needed
    1189           0 :   if (!containTrackerData) {
    1190           0 :     if (fMuonClusters->GetEntriesFast() > 0) fMuonClusters->Clear("C");
    1191           0 :     if (fMuonPads->GetEntriesFast() > 0) fMuonPads->Clear("C");
    1192             :   }
    1193             :   
    1194             :   return kTRUE;
    1195         216 : }
    1196             : 
    1197             : //______________________________________________________________________________
    1198             : AliESDMuonTrack* AliESDEvent::GetMuonTrack(Int_t i)
    1199             : {
    1200             :   // get the MUON track at the position i in the internal array of track
    1201         108 :   if (!fMuonTracks) return 0x0;
    1202          54 :   if (!MoveMuonObjects()) return 0x0;
    1203          54 :   AliESDMuonTrack *track = (AliESDMuonTrack*) fMuonTracks->UncheckedAt(i);
    1204          54 :   track->SetESDEvent(this);
    1205             :   return track;
    1206          54 : }
    1207             : 
    1208             : //______________________________________________________________________________
    1209             : AliESDMuonGlobalTrack* AliESDEvent::GetMuonGlobalTrack(Int_t i)                      // AU
    1210             : {
    1211             :   // get the MUON+MFT track at the position i in the internal array of track
    1212           0 :   if (!fMuonGlobalTracks) return 0x0;
    1213           0 :   AliESDMuonGlobalTrack *track = (AliESDMuonGlobalTrack*) fMuonGlobalTracks->UncheckedAt(i);
    1214           0 :   track->SetESDEvent(this);
    1215             :   return track;
    1216           0 : }
    1217             : 
    1218             : //______________________________________________________________________________
    1219             : void AliESDEvent::AddMuonTrack(const AliESDMuonTrack *t) 
    1220             : {
    1221             :   // add a MUON track
    1222           0 :   TClonesArray &fmu = *fMuonTracks;
    1223           0 :   AliESDMuonTrack *track = new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack(*t);
    1224           0 :   track->MoveClustersToESD(*this);
    1225           0 : }
    1226             : 
    1227             : //______________________________________________________________________________
    1228             : void AliESDEvent::AddMuonGlobalTrack(const AliESDMuonGlobalTrack *t)                             // AU
    1229             : {
    1230             :   // add a MUON+MFT track
    1231           0 :   TClonesArray &fmu = *fMuonGlobalTracks;
    1232           0 :   new (fmu[fMuonGlobalTracks->GetEntriesFast()]) AliESDMuonGlobalTrack(*t);
    1233           0 : }
    1234             : 
    1235             : //______________________________________________________________________________
    1236             : 
    1237             : AliESDMuonTrack* AliESDEvent::NewMuonTrack() 
    1238             : {
    1239             :   // create a new MUON track at the end of the internal array of track
    1240          36 :   TClonesArray &fmu = *fMuonTracks;
    1241          36 :   return new(fmu[fMuonTracks->GetEntriesFast()]) AliESDMuonTrack();
    1242           0 : }
    1243             : 
    1244             : //______________________________________________________________________________
    1245             : AliESDMuonGlobalTrack* AliESDEvent::NewMuonGlobalTrack()                                         // AU
    1246             : {
    1247             :   // create a new MUON+MFT track at the end of the internal array of track
    1248           0 :   TClonesArray &fmu = *fMuonGlobalTracks;
    1249           0 :   return new(fmu[fMuonGlobalTracks->GetEntriesFast()]) AliESDMuonGlobalTrack();
    1250           0 : }
    1251             : 
    1252             : //______________________________________________________________________________
    1253             : Int_t AliESDEvent::GetNumberOfMuonClusters()
    1254             : {
    1255             :   // get the number of MUON clusters
    1256           0 :   if (!fMuonClusters) return 0;
    1257           0 :   if (!MoveMuonObjects()) return 0;
    1258           0 :   return fMuonClusters->GetEntriesFast();
    1259           0 : }
    1260             : 
    1261             : //______________________________________________________________________________
    1262             : AliESDMuonCluster* AliESDEvent::GetMuonCluster(Int_t i)
    1263             : {
    1264             :   // get the MUON cluster at the position i in the internal array of cluster
    1265           0 :   if (!fMuonClusters) return 0x0;
    1266           0 :   if (!MoveMuonObjects()) return 0x0;
    1267           0 :   return (AliESDMuonCluster*) fMuonClusters->UncheckedAt(i);
    1268           0 : }
    1269             : 
    1270             : //______________________________________________________________________________
    1271             : AliESDMuonCluster* AliESDEvent::FindMuonCluster(UInt_t clusterId)
    1272             : {
    1273             :   // find the MUON cluster with this Id in the internal array of cluster
    1274         324 :   if (!fMuonClusters) return 0x0;
    1275         162 :   if (!MoveMuonObjects()) return 0x0;
    1276        3606 :   for (Int_t i = 0; i < fMuonClusters->GetEntriesFast(); i++) {
    1277        1560 :     AliESDMuonCluster *cluster = (AliESDMuonCluster*) fMuonClusters->UncheckedAt(i);
    1278        1560 :     if (cluster->GetUniqueID() == clusterId) return cluster;
    1279        1560 :   }
    1280         162 :   return 0x0;
    1281         162 : }
    1282             : 
    1283             : //______________________________________________________________________________
    1284             : AliESDMuonCluster* AliESDEvent::NewMuonCluster() 
    1285             : {
    1286             :   // create a new MUON cluster at the end of the internal array of cluster
    1287         324 :   TClonesArray &fmu = *fMuonClusters;
    1288         324 :   return new(fmu[fMuonClusters->GetEntriesFast()]) AliESDMuonCluster();
    1289           0 : }
    1290             : 
    1291             : //______________________________________________________________________________
    1292             : Int_t AliESDEvent::GetNumberOfMuonPads()
    1293             : {
    1294             :   // get the number of MUON pads
    1295           0 :   if (!fMuonPads) return 0;
    1296           0 :   if (!MoveMuonObjects()) return 0;
    1297           0 :   return fMuonPads->GetEntriesFast();
    1298           0 : }
    1299             : 
    1300             : //______________________________________________________________________________
    1301             : AliESDMuonPad* AliESDEvent::GetMuonPad(Int_t i)
    1302             : {
    1303             :   // get the MUON pad at the position i in the internal array of pad
    1304           0 :   if (!fMuonPads) return 0x0;
    1305           0 :   if (!MoveMuonObjects()) return 0x0;
    1306           0 :   return (AliESDMuonPad*) fMuonPads->UncheckedAt(i);
    1307           0 : }
    1308             : 
    1309             : //______________________________________________________________________________
    1310             : AliESDMuonPad* AliESDEvent::FindMuonPad(UInt_t padId)
    1311             : {
    1312             :   // find the MUON pad with this Id in the internal array of pad
    1313           0 :   if (!fMuonPads) return 0x0;
    1314           0 :   if (!MoveMuonObjects()) return 0x0;
    1315           0 :   for (Int_t i = 0; i < fMuonPads->GetEntriesFast(); i++) {
    1316           0 :     AliESDMuonPad *pad = (AliESDMuonPad*) fMuonPads->UncheckedAt(i);
    1317           0 :     if (pad->GetUniqueID() == padId) return pad;
    1318           0 :   }
    1319           0 :   return 0x0;
    1320           0 : }
    1321             : 
    1322             : //______________________________________________________________________________
    1323             : AliESDMuonPad* AliESDEvent::NewMuonPad() 
    1324             : {
    1325             :   // create a new MUON pad at the end of the internal array of pad
    1326           0 :   TClonesArray &fmu = *fMuonPads;
    1327           0 :   return new(fmu[fMuonPads->GetEntriesFast()]) AliESDMuonPad();
    1328           0 : }
    1329             : 
    1330             : //______________________________________________________________________________
    1331             : void AliESDEvent::AddPmdTrack(const AliESDPmdTrack *t) 
    1332             : {
    1333         344 :   TClonesArray &fpmd = *fPmdTracks;
    1334         172 :   new(fpmd[fPmdTracks->GetEntriesFast()]) AliESDPmdTrack(*t);
    1335         172 : }
    1336             : 
    1337             : //______________________________________________________________________________
    1338             : void AliESDEvent::SetTrdTrigger(const AliESDTrdTrigger *t)
    1339             : {
    1340          16 :   *fTrdTrigger = *t;
    1341           8 : }
    1342             : 
    1343             : //______________________________________________________________________________
    1344             : void AliESDEvent::AddTrdTrack(const AliESDTrdTrack *t) 
    1345             : {
    1346        4638 :   TClonesArray &ftrd = *fTrdTracks;
    1347        2319 :   new(ftrd[fTrdTracks->GetEntriesFast()]) AliESDTrdTrack(*t);
    1348        2319 : }
    1349             : 
    1350             : //______________________________________________________________________________
    1351             : void AliESDEvent::AddTrdTracklet(const AliESDTrdTracklet *trkl)
    1352             : {
    1353           0 :   new ((*fTrdTracklets)[fTrdTracklets->GetEntriesFast()]) AliESDTrdTracklet(*trkl);
    1354           0 : }
    1355             : 
    1356             : //______________________________________________________________________________
    1357             : void AliESDEvent::AddTrdTracklet(UInt_t trackletWord, Short_t hcid, Int_t label)
    1358             : {
    1359        1438 :   new ((*fTrdTracklets)[fTrdTracklets->GetEntriesFast()]) AliESDTrdTracklet(trackletWord, hcid, label);
    1360         719 : }
    1361             : 
    1362             : //______________________________________________________________________________
    1363             : Int_t AliESDEvent::AddKink(const AliESDkink *c) 
    1364             : {
    1365             :   // Add kink
    1366           8 :   TClonesArray &fk = *fKinks;
    1367           4 :   AliESDkink * kink = new(fk[fKinks->GetEntriesFast()]) AliESDkink(*c);
    1368           4 :   kink->SetID(fKinks->GetEntriesFast()); // CKB different from the other imps..
    1369           4 :   return fKinks->GetEntriesFast()-1;
    1370           0 : }
    1371             : 
    1372             : 
    1373             : //______________________________________________________________________________
    1374             : void AliESDEvent::AddCascade(const AliESDcascade *c) 
    1375             : {
    1376           0 :   TClonesArray &fc = *fCascades;
    1377           0 :   new(fc[fCascades->GetEntriesFast()]) AliESDcascade(*c);
    1378           0 : }
    1379             : 
    1380             : //______________________________________________________________________________
    1381             : void AliESDEvent::AddCosmicTrack(const AliESDCosmicTrack *t) 
    1382             : {
    1383           0 :   TClonesArray &ft = *fCosmicTracks;
    1384           0 :   new(ft[fCosmicTracks->GetEntriesFast()]) AliESDCosmicTrack(*t);
    1385           0 : } 
    1386             : 
    1387             : 
    1388             : //______________________________________________________________________________
    1389             : Int_t AliESDEvent::AddCaloCluster(const AliESDCaloCluster *c) 
    1390             : {
    1391             :   // Add calocluster
    1392          86 :   TClonesArray &fc = *fCaloClusters;
    1393          43 :   AliESDCaloCluster *clus = new(fc[fCaloClusters->GetEntriesFast()]) AliESDCaloCluster(*c);
    1394          43 :   clus->SetID(fCaloClusters->GetEntriesFast()-1);
    1395          43 :   return fCaloClusters->GetEntriesFast()-1;
    1396           0 : }
    1397             : 
    1398             : 
    1399             : //______________________________________________________________________________
    1400             : void  AliESDEvent::AddRawDataErrorLog(const AliRawDataErrorLog *log) const {
    1401          54 :   TClonesArray &errlogs = *fErrorLogs;
    1402          27 :   new(errlogs[errlogs.GetEntriesFast()])  AliRawDataErrorLog(*log);
    1403          27 : }
    1404             : 
    1405             : //______________________________________________________________________________
    1406             : void AliESDEvent::SetZDCData(const AliESDZDC * obj)
    1407             : { 
    1408             :   // use already allocated space
    1409          16 :   if(fESDZDC)
    1410           8 :     *fESDZDC = *obj;
    1411           8 : }
    1412             : 
    1413             : //______________________________________________________________________________
    1414             : void  AliESDEvent::SetPrimaryVertexTPC(const AliESDVertex *vertex) 
    1415             : {
    1416             :   // Set the TPC vertex
    1417             :   // use already allocated space
    1418          16 :   if(fTPCVertex){
    1419           8 :     *fTPCVertex = *vertex;
    1420           8 :     fTPCVertex->SetName(fgkESDListName[kTPCVertex]);
    1421           8 :   }
    1422           8 : }
    1423             : 
    1424             : //______________________________________________________________________________
    1425             : void  AliESDEvent::SetPrimaryVertexSPD(const AliESDVertex *vertex) 
    1426             : {
    1427             :   // Set the SPD vertex
    1428             :   // use already allocated space
    1429          16 :   if(fSPDVertex){
    1430           8 :     *fSPDVertex = *vertex;
    1431           8 :     fSPDVertex->SetName(fgkESDListName[kSPDVertex]);
    1432           8 :   }
    1433           8 : }
    1434             : 
    1435             : //______________________________________________________________________________
    1436             : void  AliESDEvent::SetPrimaryVertexTracks(const AliESDVertex *vertex) 
    1437             : {
    1438             :   // Set the primary vertex reconstructed using he ESD tracks.
    1439             :   // use already allocated space
    1440          16 :   if(fPrimaryVertex){
    1441           8 :     *fPrimaryVertex = *vertex;
    1442           8 :     fPrimaryVertex->SetName(fgkESDListName[kPrimaryVertex]);
    1443           8 :   }
    1444           8 : }
    1445             : 
    1446             : //______________________________________________________________________________
    1447             : const AliESDVertex * AliESDEvent::GetPrimaryVertex() const 
    1448             : {
    1449             :   //
    1450             :   // Get the "best" available reconstructed primary vertex.
    1451             :   //
    1452         454 :   if(fPrimaryVertex){
    1453         430 :     if (fPrimaryVertex->GetStatus()) return fPrimaryVertex;
    1454             :   }
    1455          24 :   if(fSPDVertex){
    1456          48 :     if (fSPDVertex->GetStatus()) return fSPDVertex;
    1457             :   }
    1458           0 :   if(fTPCVertex) return fTPCVertex;
    1459             :   
    1460           0 :   AliWarning("No primary vertex available. Returning the \"default\"...");
    1461           0 :   return fSPDVertex;
    1462         227 : }
    1463             : 
    1464             : //______________________________________________________________________________
    1465             : AliESDVertex * AliESDEvent::PrimaryVertexTracksUnconstrained() const 
    1466             : {
    1467             :   //
    1468             :   // Removes diamond constraint from fPrimaryVertex (reconstructed with tracks)
    1469             :   // Returns a AliESDVertex which has to be deleted by the user
    1470             :   //
    1471           0 :   if(!fPrimaryVertex) {
    1472           0 :     AliWarning("No primary vertex from tracks available.");
    1473           0 :     return 0;
    1474             :   }
    1475           0 :   if(!fPrimaryVertex->GetStatus()) {
    1476           0 :     AliWarning("No primary vertex from tracks available.");
    1477           0 :     return 0;
    1478             :   }
    1479             : 
    1480           0 :   AliVertexerTracks vertexer(GetMagneticField());
    1481           0 :   Float_t diamondxyz[3]={(Float_t)GetDiamondX(),(Float_t)GetDiamondY(),0.};
    1482           0 :   Float_t diamondcovxy[3]; GetDiamondCovXY(diamondcovxy);
    1483           0 :   Float_t diamondcov[6]={diamondcovxy[0],diamondcovxy[1],diamondcovxy[2],0.,0.,7.};
    1484             :   AliESDVertex *vertex = 
    1485           0 :     (AliESDVertex*)vertexer.RemoveConstraintFromVertex(fPrimaryVertex,diamondxyz,diamondcov);
    1486             : 
    1487             :   return vertex;
    1488           0 : }
    1489             : 
    1490             : //______________________________________________________________________________
    1491             : void AliESDEvent::SetMultiplicity(const AliMultiplicity *mul) 
    1492             : {
    1493             :   // Set the SPD Multiplicity
    1494          16 :   if(fSPDMult){
    1495           8 :     *fSPDMult = *mul;
    1496           8 :   }
    1497           8 : }
    1498             : 
    1499             : 
    1500             : //______________________________________________________________________________
    1501             : void AliESDEvent::SetFMDData(AliESDFMD * obj) 
    1502             : { 
    1503             :   // use already allocated space
    1504          16 :   if(fESDFMD){
    1505           8 :     *fESDFMD = *obj;
    1506           8 :   }
    1507           8 : }
    1508             : 
    1509             : //______________________________________________________________________________
    1510             : void AliESDEvent::SetVZEROData(const AliESDVZERO * obj)
    1511             : { 
    1512             :   // use already allocated space
    1513          16 :   if(fESDVZERO)
    1514           8 :     *fESDVZERO = *obj;
    1515           8 : }
    1516             : 
    1517             : //______________________________________________________________________________
    1518             : void AliESDEvent::SetTZEROData(const AliESDTZERO * obj)
    1519             : { 
    1520             :   // use already allocated space
    1521          32 :   if(fESDTZERO)
    1522          16 :     *fESDTZERO = *obj;
    1523          16 : }
    1524             : 
    1525             : //______________________________________________________________________________
    1526             : void AliESDEvent::SetFITData(const AliESDFIT * obj)
    1527             : { 
    1528             :   // use already allocated space
    1529           0 :   if(fESDFIT)
    1530           0 :     *fESDFIT = *obj;
    1531           0 : }
    1532             : 
    1533             : 
    1534             : //______________________________________________________________________________
    1535             : void AliESDEvent::SetACORDEData(AliESDACORDE * obj)
    1536             : {
    1537          16 :   if(fESDACORDE)
    1538           8 :     *fESDACORDE = *obj;
    1539           8 : }
    1540             : 
    1541             : //______________________________________________________________________________
    1542             : void AliESDEvent::SetADData(AliESDAD * obj)
    1543             : {
    1544           0 :   if(fESDAD)
    1545           0 :     *fESDAD = *obj;
    1546           0 : }
    1547             : 
    1548             : //______________________________________________________________________________
    1549             : void AliESDEvent::GetESDfriend(AliESDfriend *ev)
    1550             : {
    1551             :   //
    1552             :   // Extracts the complementary info from the ESD
    1553             :   // RS: instead of cloning full objects, create shallow copies of friend tracks
    1554             :   //
    1555           8 :   if (!ev) return;
    1556             : 
    1557           4 :   Int_t ntrk=GetNumberOfTracks();
    1558             :   int nfadd = 0;
    1559         150 :   for (Int_t i=0; i<ntrk; i++) {
    1560          71 :     AliESDtrack *t=GetTrack(i);
    1561          71 :     if (!t) {AliFatal(Form("NULL pointer for ESD track %d",i));}
    1562          71 :     if (t->GetFriendNotStored()) continue; // skip this one
    1563          71 :     AliESDfriendTrack *f = (AliESDfriendTrack*)t->GetFriendTrack();
    1564          71 :     AliESDfriendTrack *fcopy = ev->AddTrack(f,kTRUE); // create shallow copy
    1565          71 :     fcopy->SetESDtrackID(i);
    1566          71 :     t->SetFriendTrackID(nfadd);
    1567          71 :     f->SetESDtrackID(nfadd++);
    1568          71 :   }
    1569           4 :   AliESDfriend *fr = (AliESDfriend*)(const_cast<AliESDEvent*>(this)->FindFriend());
    1570           8 :   if (fr) ev->SetVZEROfriend(fr->GetVZEROfriend());
    1571           4 :   ev->SetESDIndicesStored(kTRUE);
    1572           8 : }
    1573             : 
    1574             : //______________________________________________________________________________
    1575             : void AliESDEvent::AddObject(TObject* obj) 
    1576             : {
    1577             :   // Add an object to the list of object.
    1578             :   // Please be aware that in order to increase performance you should
    1579             :   // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
    1580         316 :   fESDObjects->SetOwner(kTRUE);
    1581         158 :   fESDObjects->AddLast(obj);
    1582         158 : }
    1583             : 
    1584             : //______________________________________________________________________________
    1585             : void AliESDEvent::GetStdContent() 
    1586             : {
    1587             :   // set pointers for standard content
    1588             :   // get by name much safer and not a big overhead since not called very often
    1589             :  
    1590          20 :   fESDRun = (AliESDRun*)fESDObjects->FindObject(fgkESDListName[kESDRun]);
    1591          10 :   fHeader = (AliESDHeader*)fESDObjects->FindObject(fgkESDListName[kHeader]);
    1592          10 :   fESDZDC = (AliESDZDC*)fESDObjects->FindObject(fgkESDListName[kESDZDC]);
    1593          10 :   fESDFMD = (AliESDFMD*)fESDObjects->FindObject(fgkESDListName[kESDFMD]);
    1594          10 :   fESDVZERO = (AliESDVZERO*)fESDObjects->FindObject(fgkESDListName[kESDVZERO]);
    1595          10 :   fESDTZERO = (AliESDTZERO*)fESDObjects->FindObject(fgkESDListName[kESDTZERO]);
    1596          10 :   fESDFIT = (AliESDFIT*)fESDObjects->FindObject(fgkESDListName[kESDFIT]);
    1597          10 :   fTPCVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kTPCVertex]);
    1598          10 :   fSPDVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kSPDVertex]);
    1599          10 :   fPrimaryVertex = (AliESDVertex*)fESDObjects->FindObject(fgkESDListName[kPrimaryVertex]);
    1600          10 :   fSPDMult =       (AliMultiplicity*)fESDObjects->FindObject(fgkESDListName[kSPDMult]);
    1601          10 :   fPHOSTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fgkESDListName[kPHOSTrigger]);
    1602          10 :   fEMCALTrigger = (AliESDCaloTrigger*)fESDObjects->FindObject(fgkESDListName[kEMCALTrigger]);
    1603          10 :   fSPDPileupVertices = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kSPDPileupVertices]);
    1604          10 :   fTrkPileupVertices = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrkPileupVertices]);
    1605          10 :   fTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTracks]);
    1606          10 :   fMuonTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonTracks]);
    1607          10 :   fMuonClusters = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonClusters]);
    1608          10 :   fMuonPads = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonPads]);
    1609          10 :   fMuonGlobalTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kMuonGlobalTracks]);         // AU
    1610          10 :   fPmdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kPmdTracks]);
    1611          10 :   fTrdTrigger = (AliESDTrdTrigger*)fESDObjects->FindObject(fgkESDListName[kTrdTrigger]);
    1612          10 :   fTrdTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrdTracks]);
    1613          10 :   fTrdTracklets = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTrdTracklets]);
    1614          10 :   fV0s = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kV0s]);
    1615          10 :   fCascades = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCascades]);
    1616          10 :   fKinks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kKinks]);
    1617          10 :   fCaloClusters = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCaloClusters]);
    1618          10 :   fEMCALCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kEMCALCells]);
    1619          10 :   fPHOSCells = (AliESDCaloCells*)fESDObjects->FindObject(fgkESDListName[kPHOSCells]);
    1620          10 :   fErrorLogs = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kErrorLogs]);
    1621          10 :   fESDACORDE = (AliESDACORDE*)fESDObjects->FindObject(fgkESDListName[kESDACORDE]);
    1622          10 :   fESDAD = (AliESDAD*)fESDObjects->FindObject(fgkESDListName[kESDAD]);
    1623          10 :   fTOFHeader = (AliTOFHeader*)fESDObjects->FindObject(fgkESDListName[kTOFHeader]);
    1624          10 :   fCosmicTracks = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kCosmicTracks]);
    1625          10 :   fESDTOFClusters = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTOFclusters]);
    1626          10 :   fESDTOFHits = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTOFhit]);
    1627          10 :   fESDTOFMatches = (TClonesArray*)fESDObjects->FindObject(fgkESDListName[kTOFmatch]);
    1628          10 : }
    1629             : 
    1630             : //______________________________________________________________________________
    1631             : void AliESDEvent::SetStdNames(){
    1632             :   // Set the names of the standard contents
    1633             :   // 
    1634           8 :   if(fESDObjects->GetEntries()>=kESDListN){
    1635         312 :     for(int i = 0;i < fESDObjects->GetEntries() && i<kESDListN;i++){
    1636         152 :       TObject *fObj = fESDObjects->At(i);
    1637         152 :       if(fObj->InheritsFrom("TNamed")){
    1638          36 :         ((TNamed*)fObj)->SetName(fgkESDListName[i]);
    1639          36 :       }
    1640         116 :       else if(fObj->InheritsFrom("TClonesArray")){
    1641          76 :         ((TClonesArray*)fObj)->SetName(fgkESDListName[i]);
    1642          76 :       }
    1643             :     }
    1644           4 :   }
    1645             :   else{
    1646           0 :      AliWarning("Std Entries missing");
    1647             :   }
    1648           4 : } 
    1649             : 
    1650             : //______________________________________________________________________________
    1651             : void AliESDEvent::CreateStdContent(Bool_t bUseThisList){
    1652           0 :   fUseOwnList = bUseThisList;
    1653           0 :   CreateStdContent();
    1654           0 : }
    1655             : 
    1656             : //______________________________________________________________________________
    1657             : void AliESDEvent::CreateStdContent() 
    1658             : {
    1659             :   // create the standard AOD content and set pointers
    1660             : 
    1661             :   // create standard objects and add them to the TList of objects
    1662           8 :   if (fESDObjects->GetEntries()>=kESDListN) {
    1663           0 :     AliInfoF("StdContent has %d entries, will not create new ones",fESDObjects->GetEntries());
    1664           0 :     return;
    1665             :   }
    1666           8 :   AddObject(new AliESDRun());
    1667           8 :   AddObject(new AliESDHeader());
    1668           8 :   AddObject(new AliESDZDC());
    1669           8 :   AddObject(new AliESDFMD());
    1670           8 :   AddObject(new AliESDVZERO());
    1671           8 :   AddObject(new AliESDTZERO());
    1672           8 :   AddObject(new AliESDVertex());
    1673           8 :   AddObject(new AliESDVertex());
    1674           8 :   AddObject(new AliESDVertex());
    1675           8 :   AddObject(new AliMultiplicity());
    1676           8 :   AddObject(new AliESDCaloTrigger());
    1677           8 :   AddObject(new AliESDCaloTrigger());
    1678           8 :   AddObject(new TClonesArray("AliESDVertex",0));
    1679           8 :   AddObject(new TClonesArray("AliESDVertex",0));
    1680           8 :   AddObject(new TClonesArray("AliESDtrack",0));
    1681           8 :   AddObject(new TClonesArray("AliESDMuonTrack",0));
    1682           8 :   AddObject(new TClonesArray("AliESDMuonCluster",0));
    1683           8 :   AddObject(new TClonesArray("AliESDMuonPad",0));
    1684           8 :   AddObject(new TClonesArray("AliESDMuonGlobalTrack",0));   // AU
    1685           8 :   AddObject(new TClonesArray("AliESDPmdTrack",0));
    1686           8 :   AddObject(new AliESDTrdTrigger());
    1687           8 :   AddObject(new TClonesArray("AliESDTrdTrack",0));
    1688           8 :   AddObject(new TClonesArray("AliESDTrdTracklet",0));
    1689           8 :   AddObject(new TClonesArray("AliESDv0",0));
    1690           8 :   AddObject(new TClonesArray("AliESDcascade",0));
    1691           8 :   AddObject(new TClonesArray("AliESDkink",0));
    1692           8 :   AddObject(new TClonesArray("AliESDCaloCluster",0));
    1693           8 :   AddObject(new AliESDCaloCells());
    1694           8 :   AddObject(new AliESDCaloCells());
    1695           8 :   AddObject(new TClonesArray("AliRawDataErrorLog",0));
    1696           8 :   AddObject(new AliESDACORDE()); 
    1697           8 :   AddObject(new AliESDAD()); 
    1698           8 :   AddObject(new AliTOFHeader());
    1699           8 :   AddObject(new TClonesArray("AliESDCosmicTrack",0));
    1700           8 :   AddObject(new TClonesArray("AliESDTOFCluster",0));
    1701           8 :   AddObject(new TClonesArray("AliESDTOFHit",0));
    1702           8 :   AddObject(new TClonesArray("AliESDTOFMatch",0));
    1703           8 :   AddObject(new AliESDFIT());   
    1704             :   // check the order of the indices against enum...
    1705             : 
    1706             :   // set names
    1707           4 :   SetStdNames();
    1708             :   // read back pointers
    1709           4 :   GetStdContent();
    1710           8 : }
    1711             : 
    1712             : //______________________________________________________________________________
    1713             : void AliESDEvent::CompleteStdContent() 
    1714             : {
    1715             :   // Create missing standard objects and add them to the TList of objects
    1716             :   //
    1717             :   // Add cosmic tracks for cases where esd files were created 
    1718             :   // before adding them to the std content
    1719           8 :   if (!fESDObjects->FindObject(fgkESDListName[kCosmicTracks])) {
    1720           0 :     TClonesArray* cosmics = new TClonesArray("AliESDCosmicTrack",0);
    1721           0 :     fESDObjects->AddAt(cosmics, kCosmicTracks);
    1722           0 :     fESDObjects->SetOwner(kTRUE);
    1723           0 :   }
    1724             :   // Add new MUON containers if missing (for backward compatibility)
    1725           4 :   if (!fESDObjects->FindObject(fgkESDListName[kMuonClusters])) {
    1726           0 :     TClonesArray* muonClusters = new TClonesArray("AliESDMuonCluster",0);
    1727           0 :     muonClusters->SetName(fgkESDListName[kMuonClusters]);
    1728           0 :     fESDObjects->AddAt(muonClusters, kMuonClusters);
    1729           0 :     fESDObjects->SetOwner(kTRUE);
    1730           0 :   }
    1731           4 :   if (!fESDObjects->FindObject(fgkESDListName[kMuonPads])) {
    1732           0 :     TClonesArray* muonPads = new TClonesArray("AliESDMuonPad",0);
    1733           0 :     muonPads->SetName(fgkESDListName[kMuonPads]);
    1734           0 :     fESDObjects->AddAt(muonPads, kMuonPads);
    1735           0 :     fESDObjects->SetOwner(kTRUE);
    1736           0 :   }
    1737           4 : }
    1738             : 
    1739             : //______________________________________________________________________________
    1740             : TObject* AliESDEvent::FindListObject(const char *name) const {
    1741             : //
    1742             : // Find object with name "name" in the list of branches
    1743             : //
    1744          92 :   if(fESDObjects){
    1745          46 :     return fESDObjects->FindObject(name);
    1746             :   }
    1747           0 :   return 0;
    1748          46 : } 
    1749             : 
    1750             : //______________________________________________________________________________
    1751             : Int_t AliESDEvent::GetPHOSClusters(TRefArray *clusters) const
    1752             : {
    1753             :   // fills the provided TRefArray with all found phos clusters
    1754             :   
    1755          16 :   clusters->Clear();
    1756             :   
    1757             :   AliESDCaloCluster *cl = 0;
    1758         102 :   for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
    1759             :     
    1760          43 :     if ( (cl = GetCaloCluster(i)) ) {
    1761          43 :       if (cl->IsPHOS()){
    1762          10 :         clusters->Add(cl);
    1763          30 :         AliDebug(1,Form("IsPHOS cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
    1764             :       }
    1765             :     }
    1766             :   }
    1767           8 :   return clusters->GetEntriesFast();
    1768             : }
    1769             : 
    1770             : //______________________________________________________________________________
    1771             : Int_t AliESDEvent::GetEMCALClusters(TRefArray *clusters) const
    1772             : {
    1773             :   // fills the provided TRefArray with all found emcal clusters
    1774             : 
    1775          16 :   clusters->Clear();
    1776             : 
    1777             :   AliESDCaloCluster *cl = 0;
    1778         102 :   for (Int_t i = 0; i < GetNumberOfCaloClusters(); i++) {
    1779             : 
    1780          43 :     if ( (cl = GetCaloCluster(i)) ) {
    1781          43 :       if (cl->IsEMCAL()){
    1782          33 :         clusters->Add(cl);
    1783          99 :         AliDebug(1,Form("IsEMCAL cluster %d Size: %d \n",i,clusters->GetEntriesFast()));
    1784             :       }
    1785             :     }
    1786             :   }
    1787           8 :   return clusters->GetEntriesFast();
    1788             : }
    1789             : 
    1790             : //______________________________________________________________________________
    1791             : void AliESDEvent::WriteToTree(TTree* tree) const {
    1792             :   // Book the branches as in TTree::Branch(TCollection*)
    1793             :   // but add a "." at the end of top level branches which are
    1794             :   // not a TClonesArray
    1795             : 
    1796             : 
    1797           8 :   TString branchname;
    1798           4 :   TIter next(fESDObjects);
    1799             :   const Int_t kSplitlevel = 99; // default value in TTree::Branch()
    1800             :   const Int_t kBufsize = 32000; // default value in TTree::Branch()
    1801             :   TObject *obj = 0;
    1802             : 
    1803         324 :   while ((obj = next())) {
    1804         312 :     branchname.Form("%s", obj->GetName());
    1805         312 :     if(branchname.CompareTo("AliESDfriend")==0)branchname = "ESDfriend.";
    1806         468 :     if ((kSplitlevel > 1) &&  !obj->InheritsFrom(TClonesArray::Class())) {
    1807         240 :       if(!branchname.EndsWith("."))branchname += ".";
    1808             :     }
    1809         468 :     if (!tree->FindBranch(branchname)) {
    1810             :       // For the custom streamer to be called splitlevel
    1811             :       // has to be negative, only needed for HLT
    1812         624 :       Int_t splitLevel = (TString(obj->ClassName()) == "AliHLTGlobalTriggerDecision") ? -1 : kSplitlevel - 1;
    1813         624 :       tree->Bronch(branchname, obj->ClassName(), fESDObjects->GetObjectRef(obj),kBufsize, splitLevel);
    1814         156 :     }
    1815             :   }
    1816             : 
    1817           4 :   tree->Branch("fDetectorStatus",(void*)&fDetectorStatus,"fDetectorStatus/l");
    1818           4 :   tree->Branch("fDAQDetectorPattern",(void*)&fDAQDetectorPattern,"fDAQDetectorPattern/i");
    1819           4 :   tree->Branch("fDAQAttributes",(void*)&fDAQAttributes,"fDAQAttributes/i");
    1820           4 :   tree->Branch("fNTPCClusters",(void*)&fNTPCClusters,"fNTPCClusters/I");
    1821           4 : }
    1822             : 
    1823             : //______________________________________________________________________________
    1824             : void AliESDEvent::ReadFromTree(TTree *tree, Option_t* opt){
    1825             : //
    1826             : // Connect the ESDEvent to a tree
    1827             : //
    1828           8 :   if(!tree){
    1829           0 :     AliWarning("AliESDEvent::ReadFromTree() Zero Pointer to Tree \n");
    1830           0 :     return;
    1831             :   }
    1832             :   // load the TTree
    1833           6 :   if(!tree->GetTree())tree->LoadTree(0);
    1834             : 
    1835             :   // if we find the "ESD" branch on the tree we do have the old structure
    1836           4 :   if(tree->GetBranch("ESD")) {
    1837           0 :     fOldMuonStructure = kFALSE;
    1838           0 :     char ** address  = (char **)(tree->GetBranch("ESD")->GetAddress());
    1839             :     // do we have the friend branch
    1840           0 :     TBranch * esdFB = tree->GetBranch("ESDfriend.");
    1841             :     char ** addressF = 0;
    1842           0 :     if(esdFB)addressF = (char **)(esdFB->GetAddress());
    1843           0 :     if (!address) {
    1844           0 :       AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
    1845           0 :       tree->SetBranchAddress("ESD",       &fESDOld);
    1846           0 :       if(esdFB){
    1847           0 :         tree->SetBranchAddress("ESDfriend.",&fESDFriendOld);
    1848           0 :       }
    1849             :     } else {
    1850           0 :       AliInfo("AliESDEvent::ReadFromTree() Reading old Tree");
    1851           0 :       AliInfo("Branch already connected. Using existing branch address.");
    1852           0 :       fESDOld       = (AliESD*)       (*address);
    1853             :       // addressF can still be 0, since branch needs to switched on
    1854           0 :       if(addressF)fESDFriendOld = (AliESDfriend*) (*addressF);
    1855             :     }
    1856             :                                        
    1857             :     //  have already connected the old ESD structure... ?
    1858             :     // reuse also the pointer of the AlliESDEvent
    1859             :     // otherwise create new ones
    1860           0 :     TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
    1861             :   
    1862           0 :     if(connectedList){
    1863             :       // If connected use the connected list of objects
    1864           0 :       if(fESDObjects!= connectedList){
    1865             :         // protect when called twice 
    1866           0 :         fESDObjects->Delete();
    1867           0 :         fESDObjects = connectedList;
    1868           0 :       }
    1869           0 :       GetStdContent(); 
    1870             : 
    1871             :       
    1872             :       // The pointer to the friend changes when called twice via InitIO
    1873             :       // since AliESDEvent is deleted
    1874           0 :       TObject* oldf = FindListObject("AliESDfriend");
    1875             :       TObject* newf = 0;
    1876           0 :       if(addressF){
    1877           0 :         newf = (TObject*)*addressF;
    1878           0 :       }
    1879           0 :       if(newf!=0&&oldf!=newf){
    1880             :         // remove the old reference
    1881             :         // Should we also delete it? Or is this handled in TTree I/O
    1882             :         // since it is created by the first SetBranchAddress
    1883           0 :         fESDObjects->Remove(oldf);
    1884             :         // add the new one 
    1885           0 :         fESDObjects->Add(newf);
    1886           0 :       }
    1887             :       
    1888           0 :       fConnected = true;
    1889             :       return;
    1890             :     }
    1891             :     // else...    
    1892           0 :     CreateStdContent(); // create for copy
    1893             :     // if we have the esdfriend add it, so we always can access it via the userinfo
    1894           0 :     if(fESDFriendOld)AddObject(fESDFriendOld);
    1895             :     // we are not owner of the list objects 
    1896             :     // must not delete it
    1897           0 :     fESDObjects->SetOwner(kTRUE);
    1898           0 :     fESDObjects->SetName("ESDObjectsConnectedToTree");
    1899           0 :     tree->GetUserInfo()->Add(fESDObjects);
    1900           0 :     fConnected = true;
    1901           0 :     return;
    1902             :   }
    1903             :   
    1904             : 
    1905           4 :     delete fESDOld;
    1906           4 :     fESDOld = 0;
    1907             :   // Try to find AliESDEvent
    1908             :   AliESDEvent *esdEvent = 0;
    1909           4 :   esdEvent = (AliESDEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliESDEvent");
    1910           4 :   if(esdEvent){   
    1911             :       // Check if already connected to tree
    1912           4 :     esdEvent->Reset();
    1913           4 :     TList* connectedList = (TList*) (tree->GetUserInfo()->FindObject("ESDObjectsConnectedToTree"));
    1914             : 
    1915             :     
    1916           4 :     if (connectedList && (strcmp(opt, "reconnect"))) {
    1917             :       // If connected use the connected list if objects
    1918           0 :       fESDObjects->Delete();
    1919           0 :       fESDObjects = connectedList;
    1920           0 :       tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus); //PH probably redundant
    1921           0 :       tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
    1922           0 :       tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
    1923           0 :       GetStdContent(); 
    1924           0 :       fOldMuonStructure = fESDObjects->TestBit(BIT(23));
    1925           0 :       fConnected = true;
    1926           0 :       return;
    1927             :     }
    1928             : 
    1929             :     // Connect to tree
    1930             :     // prevent a memory leak when reading back the TList
    1931             :     // if (!(strcmp(opt, "reconnect"))) fESDObjects->Delete();
    1932             :     
    1933           4 :     if(!fUseOwnList){
    1934             :       // create a new TList from the UserInfo TList... 
    1935             :       // copy constructor does not work...
    1936           4 :       fESDObjects = (TList*)(esdEvent->GetList()->Clone());
    1937           4 :       fESDObjects->SetOwner(kTRUE);
    1938           4 :     }
    1939           0 :     else if ( fESDObjects->GetEntries()==0){
    1940             :       // at least create the std content if we want to read to our list
    1941           0 :       CreateStdContent(); 
    1942           0 :     }
    1943             : 
    1944             :     // in principle
    1945             :     // we only need new things in the list if we do no already have it..
    1946             :     // TODO just add new entries
    1947           4 :     CompleteStdContent();
    1948             : 
    1949           4 :     if(fESDObjects->GetEntries()<kESDListN){
    1950           0 :       AliWarning(Form("AliESDEvent::ReadFromTree() TList contains less than the standard contents %d < %d \n",
    1951             :                       fESDObjects->GetEntries(),kESDListN));
    1952           0 :     }
    1953             :     // set the branch addresses
    1954           4 :     fOldMuonStructure = kFALSE;
    1955           4 :     TIter next(fESDObjects);
    1956             :     TNamed *el;
    1957         492 :     while((el=(TNamed*)next())){
    1958         320 :       TString bname(el->GetName());
    1959         320 :       if(bname.CompareTo("AliESDfriend")==0)
    1960             :         {
    1961             :           // AliESDfriend does not have a name ...
    1962           4 :             TBranch *br = tree->GetBranch("ESDfriend.");
    1963           4 :             if (br) tree->SetBranchAddress("ESDfriend.",fESDObjects->GetObjectRef(el));
    1964           4 :         }
    1965             :       else{
    1966             :         // check if branch exists under this Name
    1967         312 :         TBranch *br = tree->GetBranch(bname.Data());
    1968         156 :         if(br){
    1969         228 :           tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
    1970             :         }
    1971             :         else{
    1972         240 :           br = tree->GetBranch(Form("%s.",bname.Data()));
    1973          80 :           if(br){
    1974         320 :             tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
    1975             :           }
    1976             :           else{
    1977           0 :             AliWarning(Form("AliESDEvent::ReadFromTree() No Branch found with Name %s or %s.",bname.Data(),bname.Data()));
    1978           0 :             if (bname == fgkESDListName[kMuonClusters]) {
    1979           0 :               fOldMuonStructure = kTRUE;
    1980           0 :             }
    1981             :           }
    1982             : 
    1983             :         }
    1984             :       }
    1985         160 :     }
    1986           4 :     tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus);
    1987           4 :     tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
    1988           4 :     tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
    1989             : 
    1990           4 :     GetStdContent();
    1991             :     // when reading back we are not owner of the list 
    1992             :     // must not delete it
    1993           4 :     fESDObjects->SetOwner(kTRUE);
    1994           4 :     fESDObjects->SetName("ESDObjectsConnectedToTree");
    1995           4 :     fESDObjects->SetBit(BIT(23), fOldMuonStructure);
    1996             :     // we are not owner of the list objects 
    1997             :     // must not delete it
    1998           8 :     tree->GetUserInfo()->Add(fESDObjects);
    1999           8 :     tree->GetUserInfo()->SetOwner(kFALSE);
    2000           4 :     fConnected = true;
    2001           4 :   }// no esdEvent -->
    2002             :   else {
    2003             :     // we can't get the list from the user data, create standard content
    2004             :     // and set it by hand (no ESDfriend at the moment
    2005           0 :     CreateStdContent();
    2006           0 :     fOldMuonStructure = kFALSE;
    2007           0 :     TIter next(fESDObjects);
    2008             :     TNamed *el;
    2009           0 :     while((el=(TNamed*)next())){
    2010           0 :       TString bname(el->GetName());    
    2011           0 :       TBranch *br = tree->GetBranch(bname.Data());
    2012           0 :       if(br){
    2013           0 :         tree->SetBranchAddress(bname.Data(),fESDObjects->GetObjectRef(el));
    2014             :       }
    2015             :       else{
    2016           0 :         br = tree->GetBranch(Form("%s.",bname.Data()));
    2017           0 :         if(br){
    2018           0 :           tree->SetBranchAddress(Form("%s.",bname.Data()),fESDObjects->GetObjectRef(el));
    2019             :         }
    2020           0 :         else if (bname == fgkESDListName[kMuonClusters]) {
    2021           0 :           fOldMuonStructure = kTRUE;
    2022           0 :         }
    2023             :       }
    2024           0 :     }
    2025           0 :     tree->SetBranchAddress("fDetectorStatus",&fDetectorStatus);
    2026           0 :     tree->SetBranchAddress("fDAQDetectorPattern",&fDAQDetectorPattern);
    2027           0 :     tree->SetBranchAddress("fDAQAttributes",&fDAQAttributes);
    2028             : 
    2029           0 :     GetStdContent();
    2030             :     // when reading back we are not owner of the list 
    2031             :     // must not delete it
    2032           0 :     fESDObjects->SetOwner(kTRUE);
    2033           0 :   }
    2034           8 : }
    2035             : 
    2036             : //______________________________________________________________________________
    2037             : void AliESDEvent::CopyFromOldESD()
    2038             : {
    2039             :   // Method which copies over everthing from the old esd structure to the 
    2040             :   // new  
    2041           0 :   if(fESDOld){
    2042           0 :     ResetStdContent();
    2043             :      // Run
    2044           0 :     SetRunNumber(fESDOld->GetRunNumber());
    2045           0 :     SetPeriodNumber(fESDOld->GetPeriodNumber());
    2046           0 :     SetMagneticField(fESDOld->GetMagneticField());
    2047             :   
    2048             :     // leave out diamond ...
    2049             :     // SetDiamond(const AliESDVertex *vertex) { fESDRun->SetDiamond(vertex);}
    2050             : 
    2051             :     // header
    2052           0 :     SetTriggerMask(fESDOld->GetTriggerMask());
    2053           0 :     SetOrbitNumber(fESDOld->GetOrbitNumber());
    2054           0 :     SetTimeStamp(fESDOld->GetTimeStamp());
    2055           0 :     SetEventType(fESDOld->GetEventType());
    2056           0 :     SetEventNumberInFile(fESDOld->GetEventNumberInFile());
    2057           0 :     SetBunchCrossNumber(fESDOld->GetBunchCrossNumber());
    2058           0 :     SetTriggerCluster(fESDOld->GetTriggerCluster());
    2059             : 
    2060             :     // ZDC
    2061             : 
    2062           0 :     SetZDC(fESDOld->GetZDCN1Energy(),
    2063           0 :            fESDOld->GetZDCP1Energy(),
    2064           0 :            fESDOld->GetZDCEMEnergy(),
    2065             :            0,
    2066           0 :            fESDOld->GetZDCN2Energy(),
    2067           0 :            fESDOld->GetZDCP2Energy(),
    2068           0 :            fESDOld->GetZDCParticipants(),
    2069             :            0,
    2070             :            0,
    2071             :            0,
    2072             :            0,
    2073             :            0,
    2074             :            0);
    2075             : 
    2076             :     // FMD
    2077             :     
    2078           0 :     if(fESDOld->GetFMDData())SetFMDData(fESDOld->GetFMDData());
    2079             : 
    2080             :     // T0
    2081             : 
    2082           0 :     SetT0zVertex(fESDOld->GetT0zVertex());
    2083           0 :     SetT0(fESDOld->GetT0());
    2084             :     //  leave amps out
    2085             : 
    2086             :     // VZERO
    2087           0 :     if (fESDOld->GetVZEROData()) SetVZEROData(fESDOld->GetVZEROData());
    2088             : 
    2089           0 :     if(fESDOld->GetVertex())SetPrimaryVertexSPD(fESDOld->GetVertex());
    2090             : 
    2091           0 :     if(fESDOld->GetPrimaryVertex())SetPrimaryVertexTracks(fESDOld->GetPrimaryVertex());
    2092             : 
    2093           0 :     if(fESDOld->GetMultiplicity())SetMultiplicity(fESDOld->GetMultiplicity());
    2094             : 
    2095           0 :     for(int i = 0;i<fESDOld->GetNumberOfTracks();i++){
    2096           0 :       AddTrack(fESDOld->GetTrack(i));
    2097             :     }
    2098             : 
    2099           0 :     for(int i = 0;i<fESDOld->GetNumberOfMuonTracks();i++){
    2100           0 :       AddMuonTrack(fESDOld->GetMuonTrack(i));
    2101             :     }
    2102             : 
    2103           0 :     for(int i = 0;i<fESDOld->GetNumberOfPmdTracks();i++){
    2104           0 :       AddPmdTrack(fESDOld->GetPmdTrack(i));
    2105             :     }
    2106             : 
    2107           0 :     for(int i = 0;i<fESDOld->GetNumberOfTrdTracks();i++){
    2108           0 :       AddTrdTrack(fESDOld->GetTrdTrack(i));
    2109             :     }
    2110             : 
    2111           0 :     for(int i = 0;i<fESDOld->GetNumberOfV0s();i++){
    2112           0 :       AddV0(fESDOld->GetV0(i));
    2113             :     }
    2114             : 
    2115           0 :     for(int i = 0;i<fESDOld->GetNumberOfCascades();i++){
    2116           0 :       AddCascade(fESDOld->GetCascade(i));
    2117             :     }
    2118             : 
    2119           0 :     for(int i = 0;i<fESDOld->GetNumberOfKinks();i++){
    2120           0 :       AddKink(fESDOld->GetKink(i));
    2121             :     }
    2122             : 
    2123             : 
    2124           0 :     for(int i = 0;i<fESDOld->GetNumberOfCaloClusters();i++){
    2125           0 :       AddCaloCluster(fESDOld->GetCaloCluster(i));
    2126             :     }
    2127             :           
    2128           0 :   }// if fesdold
    2129           0 : }
    2130             : 
    2131             : //______________________________________________________________________________
    2132             : Bool_t AliESDEvent::IsEventSelected(const char *trigExpr) const
    2133             : {
    2134             :   // Check if the event satisfies the trigger
    2135             :   // selection expression trigExpr.
    2136             :   // trigExpr can be any logical expression
    2137             :   // of the trigger classes defined in AliESDRun
    2138             :   // In case of wrong syntax return kTRUE.
    2139             :   // Modified by rl for 100 classes - to be tested
    2140             : 
    2141           0 :   TString expr(trigExpr);
    2142           0 :   if (expr.IsNull()) return kTRUE;
    2143             : 
    2144           0 :   ULong64_t mask = GetTriggerMask();
    2145           0 :   for(Int_t itrig = 0; itrig < AliESDRun::kNTriggerClasses/2; itrig++) {
    2146           0 :     if (mask & (1ull << itrig)) {
    2147           0 :       expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig),"1");
    2148             :     }
    2149             :     else {
    2150           0 :       expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig),"0");
    2151             :     }
    2152             :   }
    2153           0 :   ULong64_t maskNext50 = GetTriggerMaskNext50();
    2154           0 :   for(Int_t itrig = 0; itrig < AliESDRun::kNTriggerClasses/2; itrig++) {
    2155           0 :     if (maskNext50 & (1ull << itrig)) {
    2156           0 :       expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig+50),"1");
    2157             :     }
    2158             :     else {
    2159           0 :       expr.ReplaceAll(GetESDRun()->GetTriggerClass(itrig+50),"0");
    2160             :     }
    2161             :   }
    2162             : 
    2163           0 :   Int_t error;
    2164           0 :   if ((gROOT->ProcessLineFast(expr.Data(),&error) == 0) &&
    2165           0 :       (error == TInterpreter::kNoError)) {
    2166           0 :     return kFALSE;
    2167             :   }
    2168             : 
    2169           0 :   return kTRUE;
    2170             : 
    2171           0 : }
    2172             : 
    2173             : //______________________________________________________________________________
    2174             : TObject*  AliESDEvent::GetHLTTriggerDecision() const
    2175             : {
    2176             :   // get the HLT trigger decission object
    2177             : 
    2178             :   // cast away const'nes because the FindListObject method
    2179             :   // is not const
    2180             :   AliESDEvent* pNonConst=const_cast<AliESDEvent*>(this);
    2181           0 :   return pNonConst->FindListObject("HLTGlobalTrigger");
    2182             : }
    2183             : 
    2184             : TString   AliESDEvent::GetHLTTriggerDescription() const
    2185             : {
    2186             :   // get the HLT trigger decission description
    2187           0 :   TString description;
    2188           0 :   TObject* pDecision=GetHLTTriggerDecision();
    2189           0 :   if (pDecision) {
    2190           0 :     description=pDecision->GetTitle();
    2191             :   }
    2192             : 
    2193             :   return description;
    2194           0 : }
    2195             : 
    2196             : //______________________________________________________________________________
    2197             : Bool_t    AliESDEvent::IsHLTTriggerFired(const char* name) const
    2198             : {
    2199             :   // get the HLT trigger decission description
    2200           0 :   TObject* pDecision=GetHLTTriggerDecision();
    2201           0 :   if (!pDecision) return kFALSE;
    2202             : 
    2203           0 :   Option_t* option=pDecision->GetOption();
    2204           0 :   if (option==NULL || *option!='1') return kFALSE;
    2205             : 
    2206           0 :   if (name) {
    2207           0 :     TString description=GetHLTTriggerDescription();
    2208           0 :     Int_t index=description.Index(name);
    2209           0 :     if (index<0) return kFALSE;
    2210           0 :     index+=strlen(name);
    2211           0 :     if (index>=description.Length()) return kFALSE;
    2212           0 :     if (description[index]!=0 && description[index]!=' ') return kFALSE;
    2213           0 :   }
    2214           0 :   return kTRUE;
    2215           0 : }
    2216             : 
    2217             : //______________________________________________________________________________
    2218             : Bool_t  AliESDEvent::IsPileupFromSPD(Int_t minContributors, 
    2219             :                                      Double_t minZdist, 
    2220             :                                      Double_t nSigmaZdist, 
    2221             :                                      Double_t nSigmaDiamXY, 
    2222             :                                      Double_t nSigmaDiamZ) const{
    2223             :   //
    2224             :   // This function checks if there was a pile up
    2225             :   // reconstructed with SPD
    2226             :   //
    2227           0 :   Int_t nc1=fSPDVertex->GetNContributors();
    2228           0 :   if(nc1<1) return kFALSE;
    2229           0 :   Int_t nPileVert=GetNumberOfPileupVerticesSPD();
    2230           0 :   if(nPileVert==0) return kFALSE;
    2231             :   
    2232           0 :   for(Int_t i=0; i<nPileVert;i++){
    2233           0 :     const AliESDVertex* pv=GetPileupVertexSPD(i);
    2234           0 :     Int_t nc2=pv->GetNContributors();
    2235           0 :     if(nc2>=minContributors){
    2236           0 :       Double_t z1=fSPDVertex->GetZ();
    2237           0 :       Double_t z2=pv->GetZ();
    2238           0 :       Double_t distZ=TMath::Abs(z2-z1);
    2239           0 :       Double_t distZdiam=TMath::Abs(z2-GetDiamondZ());
    2240           0 :       Double_t cutZdiam=nSigmaDiamZ*TMath::Sqrt(GetSigma2DiamondZ());
    2241           0 :       if(GetSigma2DiamondZ()<0.0001)cutZdiam=99999.; //protection for missing z diamond information
    2242           0 :       if(distZ>minZdist && distZdiam<cutZdiam){
    2243           0 :         Double_t x2=pv->GetX();
    2244           0 :         Double_t y2=pv->GetY();
    2245           0 :         Double_t distXdiam=TMath::Abs(x2-GetDiamondX());
    2246           0 :         Double_t distYdiam=TMath::Abs(y2-GetDiamondY());
    2247           0 :         Double_t cov1[6],cov2[6];       
    2248           0 :         fSPDVertex->GetCovarianceMatrix(cov1);
    2249           0 :         pv->GetCovarianceMatrix(cov2);
    2250           0 :         Double_t errxDist=TMath::Sqrt(cov2[0]+GetSigma2DiamondX());
    2251           0 :         Double_t erryDist=TMath::Sqrt(cov2[2]+GetSigma2DiamondY());
    2252           0 :         Double_t errzDist=TMath::Sqrt(cov1[5]+cov2[5]);
    2253           0 :         Double_t cutXdiam=nSigmaDiamXY*errxDist;
    2254           0 :         if(GetSigma2DiamondX()<0.0001)cutXdiam=99999.; //protection for missing diamond information
    2255           0 :         Double_t cutYdiam=nSigmaDiamXY*erryDist;
    2256           0 :         if(GetSigma2DiamondY()<0.0001)cutYdiam=99999.; //protection for missing diamond information
    2257           0 :         if( (distXdiam<cutXdiam) && (distYdiam<cutYdiam) && (distZ>nSigmaZdist*errzDist) ){
    2258           0 :           return kTRUE;
    2259             :         }
    2260           0 :       }
    2261           0 :     }
    2262           0 :   }
    2263           0 :   return kFALSE;
    2264           0 : }
    2265             : 
    2266             : //______________________________________________________________________________
    2267             : void AliESDEvent::EstimateMultiplicity(Int_t &tracklets, Int_t &trITSTPC, Int_t &trITSSApure, Double_t eta, Bool_t useDCAFlag,Bool_t useV0Flag) const
    2268             : {
    2269             :   //
    2270             :   // calculates 3 estimators for the multiplicity in the -eta:eta range
    2271             :   // tracklets   : using SPD tracklets only
    2272             :   // trITSTPC    : using TPC/ITS + complementary ITS SA tracks + tracklets from clusters not used by tracks
    2273             :   // trITSSApure : using ITS standalone tracks + tracklets from clusters not used by tracks
    2274             :   // if useDCAFlag is true: account for the ESDtrack flag marking the tracks with large DCA
    2275             :   // if useV0Flag  is true: account for the ESDtrack flag marking conversion and K0's V0s
    2276             : 
    2277           0 :   AliWarning("This obsolete method will be eliminated soon. Use AliESDtrackCuts::GetReferenceMultiplicity");
    2278             : 
    2279           0 :   tracklets = trITSSApure = trITSTPC = 0;
    2280           0 :   int ntr = fSPDMult ? fSPDMult->GetNumberOfTracklets() : 0;
    2281             :   //
    2282             :   // count tracklets
    2283           0 :   for (int itr=ntr;itr--;) { 
    2284           0 :     if (TMath::Abs(fSPDMult->GetEta(itr))>eta) continue;
    2285           0 :     tracklets++;
    2286           0 :     if (fSPDMult->FreeClustersTracklet(itr,0)) trITSTPC++;    // not used in ITS/TPC or ITS_SA track
    2287           0 :     if (fSPDMult->FreeClustersTracklet(itr,1)) trITSSApure++; // not used in ITS_SA_Pure track
    2288             :   }
    2289             :   //
    2290             :   // count real tracks
    2291           0 :   ntr = GetNumberOfTracks();
    2292           0 :   for (int itr=ntr;itr--;) {
    2293           0 :     AliESDtrack *t = GetTrack(itr);
    2294           0 :     if (!t) {AliFatal(Form("NULL pointer for ESD track %d",itr));}
    2295           0 :     if (TMath::Abs(t->Eta())>eta) continue;
    2296           0 :     if (!t->IsOn(AliESDtrack::kITSin)) continue;
    2297           0 :     if (useDCAFlag && t->IsOn(AliESDtrack::kMultSec))  continue;
    2298           0 :     if (useV0Flag  && t->IsOn(AliESDtrack::kMultInV0)) continue;    
    2299           0 :     if (t->IsOn(AliESDtrack::kITSpureSA)) trITSSApure++;
    2300           0 :     else                                  trITSTPC++;
    2301           0 :   }
    2302             :   //
    2303           0 : }
    2304             : 
    2305             : //______________________________________________________________________________
    2306             : Bool_t AliESDEvent::IsPileupFromSPDInMultBins() const {
    2307           0 :     Int_t nTracklets=GetMultiplicity()->GetNumberOfTracklets();
    2308           0 :     if(nTracklets<20) return IsPileupFromSPD(3,0.8);
    2309           0 :     else if(nTracklets<50) return IsPileupFromSPD(4,0.8);
    2310           0 :     else return IsPileupFromSPD(5,0.8);
    2311           0 : }
    2312             : 
    2313             : //______________________________________________________________________________
    2314             : void  AliESDEvent::SetTOFHeader(const AliTOFHeader *header)
    2315             : {
    2316             :   //
    2317             :   // Set the TOF event_time
    2318             :   //
    2319             : 
    2320          16 :   if (fTOFHeader) {
    2321           8 :     *fTOFHeader=*header;
    2322             :     //fTOFHeader->SetName(fgkESDListName[kTOFHeader]);
    2323           8 :   }
    2324             :   else {
    2325             :     // for analysis of reconstructed events
    2326             :     // when this information is not avaliable
    2327           0 :     fTOFHeader = new AliTOFHeader(*header);
    2328             :     //AddObject(fTOFHeader);
    2329             :   }
    2330             : 
    2331           8 : }
    2332             : 
    2333             : //______________________________________________________________________________
    2334             : AliCentrality* AliESDEvent::GetCentrality()
    2335             : {
    2336          36 :     if (!fCentrality) fCentrality = new AliCentrality();
    2337          16 :     return  fCentrality;
    2338           0 : }
    2339             : 
    2340             : //______________________________________________________________________________
    2341             : AliEventplane* AliESDEvent::GetEventplane()
    2342             : {
    2343          36 :     if (!fEventplane) fEventplane = new AliEventplane();
    2344          16 :     return  fEventplane;
    2345           0 : }
    2346             : 
    2347             : //______________________________________________________________________________
    2348             : Float_t AliESDEvent::GetVZEROEqMultiplicity(Int_t i) const
    2349             : {
    2350             :   // Get VZERO Multiplicity for channel i
    2351             :   // Themethod uses the equalization factors
    2352             :   // stored in the ESD-run object in order to
    2353             :   // get equal multiplicities within a VZERO rins (1/8 of VZERO)
    2354           0 :   if (!fESDVZERO || !fESDRun) return -1;
    2355             : 
    2356           0 :   Int_t ring = i/8;
    2357             :   Float_t factorSum = 0;
    2358           0 :   for(Int_t j = 8*ring; j < (8*ring+8); ++j) {
    2359           0 :     factorSum += fESDRun->GetVZEROEqFactors(j);
    2360             :   }
    2361           0 :   Float_t factor = fESDRun->GetVZEROEqFactors(i)*8./factorSum;
    2362             : 
    2363           0 :   return (fESDVZERO->GetMultiplicity(i)/factor);
    2364           0 : }
    2365             : 
    2366             : //______________________________________________________________________________
    2367             : void AliESDEvent::SetTOFcluster(Int_t ntofclusters,AliESDTOFCluster *cluster,Int_t *mapping)
    2368             : {
    2369             :   // Reset TClonesArray of TOF clusters
    2370           0 :   if (!fESDTOFClusters) {
    2371           0 :     AliError("fESDTOFClusters is not initialized");
    2372           0 :     return;
    2373             :   }
    2374           0 :   fESDTOFClusters->Clear();
    2375             :   
    2376           0 :   Int_t goodhit[20000];
    2377           0 :   if(mapping){
    2378           0 :     for(Int_t i=0;i < 20000;i++){
    2379           0 :       goodhit[i] = 0;
    2380             :     }
    2381           0 :   }
    2382             : 
    2383           0 :   for(Int_t i=0;i < ntofclusters;i++){
    2384             :     
    2385           0 :     if(cluster[i].GetNMatchableTracks() || !mapping){
    2386           0 :       if(mapping)
    2387           0 :         mapping[i] = fESDTOFClusters->GetEntriesFast();
    2388             :       
    2389             :       // update TClonesArray
    2390           0 :       TClonesArray &ftr = *fESDTOFClusters;
    2391           0 :       AliESDTOFCluster *clusterTBW = new(ftr[fESDTOFClusters->GetEntriesFast()])AliESDTOFCluster(cluster[i]);
    2392             : 
    2393           0 :       if(mapping){
    2394             :         // loop over hit in the cluster
    2395           0 :         for(Int_t k=0;k < clusterTBW->GetNTOFhits();k++){
    2396           0 :           Int_t ipos = clusterTBW->GetHitIndex(k);
    2397           0 :           goodhit[ipos] = 1; // hit should be kept
    2398             :         }
    2399           0 :       }
    2400           0 :     }
    2401             :   }
    2402             : 
    2403           0 :   if(mapping){
    2404           0 :     AliInfo(Form("TOF cluster before of matching = %i , after = %i\n",ntofclusters,fESDTOFClusters->GetEntriesFast()));
    2405           0 :     Int_t hitnewpos[20000]={0};
    2406           0 :     Int_t nhitOriginal = fESDTOFHits->GetEntries();
    2407           0 :     for(Int_t i=0;i < fESDTOFHits->GetEntries();i++){
    2408           0 :       if(goodhit[i]){
    2409           0 :         hitnewpos[i] = i;
    2410           0 :       }
    2411             :       else{ // remove hit and decrease the hit array
    2412           0 :         TClonesArray &a=*fESDTOFHits;
    2413           0 :         Int_t lastpos = fESDTOFHits->GetEntries()-1;
    2414             : 
    2415           0 :         if(i == lastpos)
    2416           0 :           delete a.RemoveAt(i);
    2417             :         else{
    2418           0 :           Int_t nhitBefore = fESDTOFHits->GetEntries();
    2419           0 :           for(Int_t k=nhitBefore-1;k>i;k--){ // find the last good track
    2420           0 :             if(!goodhit[k]){ // remove track
    2421           0 :               delete a.RemoveAt(k);
    2422           0 :               if(k-i==1) delete a.RemoveAt(i);
    2423             :             }
    2424             :             else{ // replace last one to the "i"
    2425           0 :               AliESDTOFHit *last = (AliESDTOFHit *) fESDTOFHits->At(k);
    2426           0 :               delete a.RemoveAt(i);
    2427           0 :               new (a[i]) AliESDTOFHit(*last);
    2428           0 :               delete a.RemoveAt(k);
    2429           0 :               hitnewpos[k] = i;
    2430             :               k = 0;
    2431             :             }
    2432             :           }
    2433             :         }
    2434             :       }
    2435             :     }
    2436             : 
    2437             :     // remap cluster to hits
    2438           0 :     for(Int_t i=0;i < fESDTOFClusters->GetEntries();i++){
    2439           0 :       AliESDTOFCluster *cl = (AliESDTOFCluster *) fESDTOFClusters->At(i);
    2440             :       // loop over hit in the cluster
    2441           0 :       for(Int_t k=0;k < cl->GetNTOFhits();k++){
    2442           0 :         cl->SetHitIndex(k,hitnewpos[cl->GetHitIndex(k)]);
    2443             :       }
    2444             :     }
    2445           0 :     AliInfo(Form("TOF hit before of matching = %i , after = %i\n",nhitOriginal,fESDTOFHits->GetEntriesFast()));
    2446           0 :   } // end mapping
    2447             : 
    2448           0 : }
    2449             : 
    2450             : //______________________________________________________________________________
    2451             : void AliESDEvent::SetTOFcluster(Int_t ntofclusters,AliESDTOFCluster *cluster[],Int_t *mapping)
    2452             : {    
    2453             :   // Reset TClonesArray of TOF clusters
    2454           0 :   if(fESDTOFClusters)fESDTOFClusters->Delete();
    2455             :    
    2456           0 :   Int_t goodhit[20000];
    2457           0 :   if(mapping){
    2458           0 :     for(Int_t i=0;i < 20000;i++){
    2459           0 :       goodhit[i] = 0;
    2460             :     }
    2461           0 :   }
    2462             :       
    2463           0 :   for(Int_t i=0;i < ntofclusters;i++){
    2464             : 
    2465           0 :     if(cluster[i]->GetNMatchableTracks() || !mapping){
    2466           0 :       if(mapping)
    2467           0 :         mapping[i] = fESDTOFClusters->GetEntriesFast();
    2468             :         
    2469             :       // update TClonesArray
    2470           0 :       TClonesArray &ftr = *fESDTOFClusters;
    2471           0 :       AliESDTOFCluster *clusterTBW = new(ftr[fESDTOFClusters->GetEntriesFast()])AliESDTOFCluster(*(cluster[i]));
    2472             : 
    2473           0 :       if(mapping){
    2474             :         // loop over hit in the cluster
    2475           0 :         for(Int_t k=0;k < clusterTBW->GetNTOFhits();k++){
    2476           0 :           Int_t ipos = clusterTBW->GetHitIndex(k);
    2477           0 :           goodhit[ipos] = 1; // hit should be kept
    2478             :         }
    2479           0 :       }
    2480           0 :     }
    2481             :   }
    2482             : 
    2483           0 :   if(mapping){
    2484           0 :     AliInfo(Form("TOF cluster before of matching = %i , after = %i\n",ntofclusters,fESDTOFClusters->GetEntriesFast()));
    2485           0 :     Int_t hitnewpos[20000]={0};
    2486           0 :     Int_t nhitOriginal = fESDTOFHits->GetEntries();
    2487           0 :     for(Int_t i=0;i < fESDTOFHits->GetEntries();i++){
    2488           0 :       if(goodhit[i]){
    2489           0 :         hitnewpos[i] = i;
    2490           0 :       }
    2491             :       else{ // remove hit and decrease the hit array
    2492           0 :         TClonesArray &a=*fESDTOFHits;
    2493           0 :         Int_t lastpos = fESDTOFHits->GetEntries()-1;
    2494             : 
    2495           0 :         if(i == lastpos)
    2496           0 :           delete a.RemoveAt(i);
    2497             :         else{
    2498           0 :           Int_t nhitBefore = fESDTOFHits->GetEntries();
    2499           0 :           for(Int_t k=nhitBefore-1;k>i;k--){ // find the last good track
    2500           0 :             if(!goodhit[k]){ // remove track
    2501           0 :               delete a.RemoveAt(k);
    2502           0 :               if(k-i==1) delete a.RemoveAt(i);
    2503             :             }
    2504             :             else{ // replace last one to the "i"
    2505           0 :               AliESDTOFHit *last = (AliESDTOFHit *) fESDTOFHits->At(k);
    2506           0 :               delete a.RemoveAt(i);
    2507           0 :               new (a[i]) AliESDTOFHit(*last);
    2508           0 :               delete a.RemoveAt(k);
    2509           0 :               hitnewpos[k] = i;
    2510             :               k = 0;
    2511             :             }
    2512             :           }
    2513             :         }
    2514             :       }
    2515             :     }
    2516             : 
    2517             :     // remap cluster to hits
    2518           0 :     for(Int_t i=0;i < fESDTOFClusters->GetEntries();i++){
    2519           0 :       AliESDTOFCluster *cl = (AliESDTOFCluster *) fESDTOFClusters->At(i);
    2520             :       // loop over hit in the cluster
    2521           0 :       for(Int_t k=0;k < cl->GetNTOFhits();k++){
    2522           0 :         cl->SetHitIndex(k,hitnewpos[cl->GetHitIndex(k)]);
    2523             :       }
    2524             :     }
    2525           0 :     AliInfo(Form("TOF hit before of matching = %i , after = %i\n",nhitOriginal,fESDTOFHits->GetEntriesFast()));
    2526           0 :   } // end mapping
    2527             : 
    2528           0 : }
    2529             : 
    2530             : //______________________________________________________________________________
    2531             : void AliESDEvent::ConnectTracks() {
    2532             : // Connect tracks to this event
    2533          40 :   if (fTracksConnected || !fTracks || !fTracks->GetEntriesFast()) return;
    2534             :   AliESDtrack *track;
    2535           8 :   TIter next(fTracks);
    2536         450 :   while ((track=(AliESDtrack*)next())) track->SetESDEvent(this);
    2537             :   //
    2538             :   // The same for TOF clusters
    2539           8 :   if (fESDTOFClusters) {
    2540             :     AliESDTOFCluster *clus;
    2541           8 :     TIter nextTOF(fESDTOFClusters);
    2542         352 :     while ((clus=(AliESDTOFCluster*)nextTOF())) clus->SetEvent((AliVEvent *) this);
    2543           8 :   }
    2544           8 :   fTracksConnected = kTRUE;
    2545             :   //
    2546          18 : }
    2547             : 
    2548             : //______________________________________________________________________________
    2549             : AliESDfriend* AliESDEvent::FindFriend() const 
    2550             : { 
    2551          24 :   return static_cast<AliESDfriend*>(FindListObject("AliESDfriend")); 
    2552             : }
    2553             : 
    2554           0 : AliVEvent::EDataLayoutType AliESDEvent::GetDataLayoutType() const {return AliVEvent::kESD;}
    2555             : 
    2556             : //______________________________________________________________________________
    2557             : Bool_t AliESDEvent::IsIncompleteDAQ() 
    2558             : {
    2559             :   // check if DAQ has set the incomplete event attributes
    2560          12 :   return (fDAQAttributes&ATTR_2_B(ATTR_INCOMPLETE_EVENT))!=0 
    2561           8 :     ||   (fDAQAttributes&ATTR_2_B(ATTR_FLUSHED_EVENT))!=0;
    2562             :     
    2563             : }
    2564             : 
    2565             : //______________________________________________________________________________
    2566             : UInt_t AliESDEvent::GetTimeStampCTP() const
    2567             : {
    2568             :   // calculate/return CTP time stamp in the approximation of BC=25ns
    2569           0 :   const AliTimeStamp* ctp0 = GetCTPStart();
    2570             :   UInt_t tCTP = 0;
    2571           0 :   if ( !ctp0 || !(tCTP=ctp0->GetSeconds()) ) return GetTimeStamp(); // N/A
    2572             :   // subtract from current orbit the orbit at CTP SOR
    2573           0 :   Long64_t span=(GetPeriodNumber()<<24)+GetOrbitNumber()-ctp0->GetOrbit();
    2574           0 :   tCTP += span*3564*25/1000000000;
    2575             :   return tCTP;
    2576           0 : }
    2577             : 
    2578             : //______________________________________________________________________________
    2579             : UInt_t AliESDEvent::GetTimeStampCTPBCCorr() const
    2580             : {
    2581             :   // calculate/return CTP time stamp in the approximation of BC=25ns
    2582           0 :   const AliTimeStamp* ctp0 = GetCTPStart();
    2583             :   const double kBCLHC = 1./40.079e6;
    2584             :   UInt_t tCTP = 0;
    2585           0 :   if ( !ctp0 || !(tCTP=ctp0->GetSeconds()) ) return GetTimeStamp(); // N/A
    2586             :   // subtract from current orbit the orbit at CTP SOR
    2587           0 :   Long64_t span=(GetPeriodNumber()<<24)+GetOrbitNumber()-ctp0->GetOrbit();
    2588           0 :   tCTP += span*3564*kBCLHC;
    2589             :   return tCTP;
    2590           0 : }

Generated by: LCOV version 1.11