LCOV - code coverage report
Current view: top level - STEER/STEERBase - AliMixedEvent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 195 0.5 %
Date: 2016-06-14 17:26:59 Functions: 1 23 4.3 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-2007, 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$ */
      17             : 
      18             : 
      19             : //-------------------------------------------------------------------------
      20             : //                          Class AliMixedEvent
      21             : // VEvent which is the container of several VEvents 
      22             : // Use Case: Event Mixing     
      23             : // Origin: Andreas Morsch, CERN, Andreas.Morsch@cern.ch 
      24             : //-------------------------------------------------------------------------
      25             : 
      26             : 
      27             : #include "AliMixedEvent.h"
      28             : #include "AliExternalTrackParam.h"
      29             : #include "TVector3.h"
      30             : #include "AliVVertex.h"
      31             : #include <TMath.h>
      32             : #include <TMatrix.h>
      33             : #include <TMatrixD.h>
      34             : #include "AliLog.h"
      35             : #include "AliVCaloCells.h"
      36             : 
      37             : 
      38         176 : ClassImp(AliMixedEvent)
      39             : 
      40             : 
      41             : AliMixedEvent::AliMixedEvent() :
      42           0 :   AliVEvent(),
      43           0 :   fEventList(),
      44           0 :   fNEvents(0),       
      45           0 :   fNumberOfTracks(0),
      46           0 :   fNumberOfCaloClusters(0), 
      47           0 :   fNumberOfPHOSCells(0), 
      48           0 :   fNumberOfEMCALCells(0),
      49           0 :   fNTracksCumul(0),
      50           0 :   fNCaloClustersCumul(0),
      51           0 :   fNPHOSCellsCumul(0), 
      52           0 :   fNEMCALCellsCumul(0), 
      53           0 :   fPHOSCells(NULL), 
      54           0 :   fEMCALCells(NULL), 
      55           0 :   fMeanVertex(0)
      56           0 : {
      57             :     // Default constructor
      58           0 : }
      59             : 
      60             : AliMixedEvent::AliMixedEvent(const AliMixedEvent& Evnt) :
      61           0 :   AliVEvent(Evnt),
      62           0 :   fEventList(),
      63           0 :   fNEvents(0),
      64           0 :   fNumberOfTracks(0),
      65           0 :   fNumberOfCaloClusters(0), 
      66           0 :   fNumberOfPHOSCells(0), 
      67           0 :   fNumberOfEMCALCells(0),
      68           0 :   fNTracksCumul(0),
      69           0 :   fNCaloClustersCumul(0),
      70           0 :   fNPHOSCellsCumul(0), 
      71           0 :   fNEMCALCellsCumul(0), 
      72           0 :   fPHOSCells(NULL), 
      73           0 :   fEMCALCells(NULL), 
      74           0 :   fMeanVertex(0)
      75           0 : { } // Copy constructor
      76             : 
      77             : AliMixedEvent& AliMixedEvent::operator=(const AliMixedEvent& vEvnt)
      78             : { 
      79             : // Assignment operator
      80           0 :     if (this!=&vEvnt) { 
      81           0 :     AliVEvent::operator=(vEvnt); 
      82           0 : }
      83             :   
      84           0 :   return *this; 
      85             : }
      86             : 
      87             : AliMixedEvent::~AliMixedEvent() 
      88           0 : {
      89             :     // dtor
      90           0 :   Reset();
      91           0 :   delete fPHOSCells ; 
      92           0 :   delete fEMCALCells ; 
      93           0 : } 
      94             : 
      95             : 
      96             : void AliMixedEvent::AddEvent(AliVEvent* evt)
      97             : {
      98             :     // Add a new event to the list
      99           0 :     fEventList.AddLast(evt);
     100           0 : }
     101             : 
     102             : 
     103             : void AliMixedEvent::Init()
     104             : {
     105             :     // Initialize meta information
     106           0 :   fNEvents = fEventList.GetEntries();
     107           0 :   fNTracksCumul = new Int_t[fNEvents];
     108           0 :   fNumberOfTracks = 0;
     109           0 :   fNCaloClustersCumul = new Int_t[fNEvents];
     110           0 :   fNumberOfCaloClusters = 0;
     111           0 :   fNumberOfPHOSCells    = 0;  
     112           0 :   fNumberOfEMCALCells   = 0; 
     113           0 :   fNPHOSCellsCumul  = new Int_t[fNEvents];
     114           0 :   fNEMCALCellsCumul = new Int_t[fNEvents];
     115             : 
     116           0 :   TIter next(&fEventList);
     117             :   AliVEvent* event;
     118             :   Int_t iev = 0;
     119             :     
     120           0 :   while((event = (AliVEvent*)next())) {
     121           0 :     fNTracksCumul[iev] = fNumberOfTracks;
     122           0 :     fNumberOfTracks += (event->GetNumberOfTracks());
     123           0 :     fNCaloClustersCumul[iev] = fNumberOfCaloClusters;
     124           0 :     fNumberOfCaloClusters += event->GetNumberOfCaloClusters(); 
     125           0 :     fNPHOSCellsCumul[iev] = fNumberOfPHOSCells;
     126           0 :     if (event->GetPHOSCells()) 
     127           0 :       fNumberOfPHOSCells += event->GetPHOSCells()->GetNumberOfCells(); 
     128           0 :     fNEMCALCellsCumul[iev] = fNumberOfEMCALCells;
     129           0 :     if (event->GetEMCALCells()) 
     130           0 :       fNumberOfEMCALCells += event->GetEMCALCells()->GetNumberOfCells(); 
     131           0 :     iev++ ;  
     132             :   }
     133             : 
     134           0 :   next.Reset() ; 
     135             :   Short_t phosPos = 0, emcalPos = 0; 
     136             :   Int_t firstPHOSEvent  = kTRUE;
     137             :   Int_t firstEMCALEvent = kTRUE;
     138             :   
     139           0 :   while((event = (AliVEvent*)next())) {
     140           0 :     AliVCaloCells * phosCells = event->GetPHOSCells() ; 
     141           0 :     if (phosCells) {
     142             :       
     143             :       //Create the container
     144           0 :       if(firstPHOSEvent)
     145             :       {
     146           0 :         if(!fPHOSCells) fPHOSCells = phosCells->CopyCaloCells(kFALSE) ;// Just recover the first event type:  ESD/AOD
     147           0 :         else fPHOSCells->DeleteContainer(); //delete the previous container 
     148             :         //Now create a new container with the adequate size
     149           0 :         fPHOSCells->SetType(AliVCaloCells::kPHOSCell) ; 
     150           0 :         fPHOSCells->CreateContainer(fNumberOfPHOSCells) ;
     151             :         firstPHOSEvent=kFALSE;
     152             : 
     153           0 :       }//First event
     154             : 
     155           0 :       Int_t ncells = event->GetPHOSCells()->GetNumberOfCells() ;
     156           0 :       for (Int_t icell = 0; icell < ncells; icell++) {
     157           0 :           fPHOSCells->SetCell(phosPos++, phosCells->GetCellNumber(icell), phosCells->GetAmplitude(icell), 
     158           0 :                               phosCells->GetTime(icell),phosCells->GetMCLabel(icell),phosCells->GetEFraction(icell)) ; 
     159             :       }
     160             :      
     161           0 :     }// phos cells
     162             :     
     163           0 :     AliVCaloCells * emcalCells = event->GetEMCALCells() ; 
     164           0 :     if (emcalCells) {
     165             :       
     166             :       //Create the container
     167           0 :       if(firstEMCALEvent)
     168             :       {
     169           0 :         if(!fEMCALCells)fEMCALCells = emcalCells->CopyCaloCells(kFALSE) ; // Just recover the first event type:  ESD/AOD
     170           0 :         else fEMCALCells->DeleteContainer();       // delete the previous container
     171             :         //Now create a new container with the adequate size
     172           0 :         fEMCALCells->SetType(AliVCaloCells::kEMCALCell) ; 
     173           0 :         fEMCALCells->CreateContainer(fNumberOfEMCALCells) ;
     174             :         firstEMCALEvent=kFALSE;
     175           0 :       }//First event
     176             :       
     177           0 :       Int_t ncells = emcalCells->GetNumberOfCells() ;
     178           0 :       for (Int_t icell = 0; icell < ncells; icell++) {
     179           0 :           fEMCALCells->SetCell(emcalPos++, emcalCells->GetCellNumber(icell), emcalCells->GetAmplitude(icell), 
     180           0 :                                emcalCells->GetTime(icell),emcalCells->GetMCLabel(icell),emcalCells->GetEFraction(icell)) ; 
     181             :       }
     182           0 :     }//EMCAL cells
     183             :   }//while event
     184             :   
     185           0 : }
     186             : 
     187             : AliVParticle* AliMixedEvent::GetTrack(Int_t i) const
     188             : {
     189             :     // Return track # i
     190           0 :     Int_t iEv  = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
     191           0 :     while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
     192             : 
     193           0 :     Int_t irel = i - fNTracksCumul[iEv];
     194           0 :     AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
     195           0 :     return (evt->GetTrack(irel));
     196             : }
     197             : 
     198             : AliVCluster* AliMixedEvent::GetCaloCluster(Int_t i) const
     199             : {
     200             :     // Return calo cluster # i
     201           0 :   Int_t iEv  = TMath::BinarySearch(fNEvents, fNCaloClustersCumul, i);
     202           0 :   while((iEv < (fNEvents - 1)) && (fNCaloClustersCumul[iEv] == fNCaloClustersCumul[iEv+1])) {iEv++;}
     203             :   
     204           0 :   Int_t irel = i - fNCaloClustersCumul[iEv];
     205           0 :   AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
     206           0 :   return (evt->GetCaloCluster(irel));
     207             : }
     208             : 
     209             : const AliVVertex* AliMixedEvent::GetEventVertex(Int_t i) const
     210             : {
     211             :     // Return vertex of track # i
     212           0 :     Int_t iEv  = TMath::BinarySearch(fNEvents, fNTracksCumul, i);
     213           0 :     while((iEv < (fNEvents - 1)) && (fNTracksCumul[iEv] == fNTracksCumul[iEv+1])) {iEv++;}
     214           0 :     AliVEvent* evt = (AliVEvent*) (fEventList.At(iEv));
     215           0 :     return (evt->GetPrimaryVertex());
     216             : }
     217             : 
     218             : const AliVVertex* AliMixedEvent::GetVertexOfEvent(Int_t i) const
     219             : {
     220             :     // Return vertex of event # i
     221           0 :   if (i > fNEvents)
     222           0 :     AliFatal(Form("%d events in buffer, event %d requested", fNEvents, i)) ;  
     223           0 :   AliVEvent* evt = (AliVEvent*) (fEventList.At(i));
     224           0 :   return (evt->GetPrimaryVertex());
     225             : }
     226             : 
     227             : void AliMixedEvent::Reset()
     228             : {
     229             :     // Reset the event
     230           0 :   fEventList.Clear();
     231           0 :   fNEvents = 0;
     232           0 :   fNumberOfTracks = 0;
     233           0 :   fNumberOfCaloClusters = 0;
     234           0 :   fNumberOfPHOSCells = 0;
     235           0 :   fNumberOfEMCALCells = 0;
     236           0 :   if (fNTracksCumul) {
     237           0 :     delete[]  fNTracksCumul;
     238           0 :     fNTracksCumul = 0;
     239           0 :   }
     240           0 :   if (fNCaloClustersCumul) {
     241           0 :     delete[]  fNCaloClustersCumul;
     242           0 :     fNCaloClustersCumul = 0;
     243           0 :   }
     244           0 :   if (fNPHOSCellsCumul) {
     245           0 :     delete[]  fNPHOSCellsCumul;
     246           0 :     fNPHOSCellsCumul = 0;
     247           0 :   }
     248           0 :   if (fNEMCALCellsCumul) {
     249           0 :     delete[]  fNEMCALCellsCumul;
     250           0 :     fNEMCALCellsCumul = 0;
     251           0 :   }
     252             :   
     253           0 :   if (fPHOSCells) {      
     254           0 :     fPHOSCells->DeleteContainer();    
     255           0 :   }      
     256           0 :   if (fEMCALCells) {     
     257           0 :     fEMCALCells->DeleteContainer();   
     258           0 :   }
     259             :   
     260           0 : }
     261             : 
     262             : Int_t AliMixedEvent::EventIndex(Int_t itrack) const
     263             : {
     264             :   // Return the event index for track #itrack
     265           0 :   return  TMath::BinarySearch(fNEvents, fNTracksCumul, itrack);
     266             : }
     267             : 
     268             : Int_t AliMixedEvent::EventIndexForCaloCluster(Int_t icluster) const
     269             : {
     270             :     // Return the event index for track #itrack
     271           0 :   return  TMath::BinarySearch(fNEvents, fNCaloClustersCumul, icluster);
     272             : }
     273             : 
     274             : Int_t AliMixedEvent::EventIndexForPHOSCell(Int_t icell) const
     275             : {
     276             :     // Return the event index for track #itrack
     277           0 :   return  TMath::BinarySearch(fNEvents, fNPHOSCellsCumul, icell);
     278             : }
     279             : 
     280             : Int_t AliMixedEvent::EventIndexForEMCALCell(Int_t icell) const
     281             : {
     282             :     // Return the event index for track #itrack
     283           0 :   return  TMath::BinarySearch(fNEvents, fNEMCALCellsCumul, icell);
     284             : }
     285             : 
     286             : Bool_t AliMixedEvent::ComputeVtx(const TObjArray *vertices, Double_t *pos,Double_t *sig,Int_t *nContributors)  {
     287             : //
     288             : // Calculate the mean vertex psoitions from events in the buffer
     289             :  
     290           0 :     Int_t nentries = vertices->GetEntriesFast();
     291           0 :     Double_t sum[3]={0.,0.,0.};
     292           0 :     Double_t sumsigma[6]={0.,0.,0.,0.,0.,0.};
     293             : 
     294             :     
     295           0 :     for(Int_t ivtx = 0; ivtx < nentries; ivtx++){
     296           0 :         AliVVertex *vtx=(AliVVertex*)vertices->UncheckedAt(ivtx);
     297           0 :         Double_t covariance[6];
     298           0 :         vtx->GetCovarianceMatrix(covariance);
     299           0 :         Double_t vtxPos[3];
     300           0 :         vtx->GetXYZ(vtxPos);
     301           0 :         if(TMath::Abs(covariance[0])<1.e-13) {
     302           0 :         return kFALSE;
     303             :         }else{
     304           0 :         sum[0]+=vtxPos[0]*(1./covariance[0]);
     305           0 :         sumsigma[0]+=(1./covariance[0]);
     306             :         }
     307           0 :         if(TMath::Abs(covariance[2])<1.e-13) {
     308           0 :         return kFALSE;
     309             :         }else{
     310           0 :         sum[1]+=vtxPos[1]*(1./covariance[2]);
     311           0 :         sumsigma[2]+=(1./covariance[2]);
     312             :         }
     313           0 :         if(TMath::Abs(covariance[5])<1.e-13) {
     314           0 :         return kFALSE;
     315             :         }else{
     316           0 :         sum[2]+=vtxPos[2]*(1./covariance[5]);
     317           0 :         sumsigma[5]+=(1./covariance[5]);
     318             :         }
     319           0 :         if(TMath::Abs(covariance[1])<1.e-13) {
     320           0 :          sumsigma[1]+=0.;
     321           0 :         }else{
     322           0 :         sumsigma[1]+=(1./covariance[1]);
     323             :         }
     324           0 :         if(TMath::Abs(covariance[3])<1.e-13) {
     325           0 :         sumsigma[3]+=0.;
     326           0 :         }else{
     327           0 :         sumsigma[3]+=(1./covariance[3]);
     328             :         }
     329           0 :         if(TMath::Abs(covariance[4])<1.e-13) {
     330           0 :         sumsigma[4]+=0.;
     331           0 :         }else{
     332           0 :         sumsigma[4]+=(1./covariance[4]);
     333             :         }
     334             : 
     335           0 :      nContributors[0]=nContributors[0]+vtx->GetNContributors();
     336           0 :     }
     337             :     
     338           0 :     for(Int_t i=0;i<3;i++){
     339           0 :         if(TMath::Abs(sumsigma[i])<1.e-13) continue;
     340           0 :         pos[i]=sum[i]/sumsigma[i];
     341           0 :     }
     342           0 :     for(Int_t i2=0;i2<3;i2++){
     343           0 :         if(TMath::Abs(sumsigma[i2])<1.e-13) {sig[i2]=0.; continue;}
     344           0 :         sig[i2]=1./sumsigma[i2];
     345           0 :     }
     346           0 :     return kTRUE;
     347           0 : }
     348             : 
     349             : 
     350             : Double_t AliMixedEvent::GetMagneticField() const
     351             : {
     352             :     // Return magnetic field of the first event in the list
     353           0 :     if (fEventList.GetEntries() == 0) return -999.;
     354             :     
     355           0 :     AliVEvent* evt = (AliVEvent*) (fEventList.At(0));
     356           0 :     return evt->GetMagneticField();
     357           0 : }
     358             : 
     359             : AliVEvent::EDataLayoutType AliMixedEvent::GetDataLayoutType() const
     360             : {
     361           0 :   return AliVEvent::kMixed;
     362             : }

Generated by: LCOV version 1.11