coverity + some patch for pp
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowCommon / AliFlowEventSimple.cxx
index f969a4a..285a583 100644 (file)
@@ -112,6 +112,7 @@ AliFlowEventSimple::AliFlowEventSimple(const AliFlowEventSimple& anEvent):
 AliFlowEventSimple& AliFlowEventSimple::operator=(const AliFlowEventSimple& anEvent)
 {
   //assignment operator
+  if (&anEvent==this) return *this; //check self-assignment
   if (fTrackCollection) fTrackCollection->Delete();
   delete fTrackCollection;
   fTrackCollection = (TObjArray*)(anEvent.fTrackCollection)->Clone(); //deep copy
@@ -134,9 +135,9 @@ AliFlowEventSimple::~AliFlowEventSimple()
   //destructor
   if (fTrackCollection) fTrackCollection->Delete();
   delete fTrackCollection;
-  if (fNumberOfTracksWrap) delete fNumberOfTracksWrap;
-  if (fNumberOfRPsWrap) delete fNumberOfRPsWrap;
-  if (fMCReactionPlaneAngleWrap) delete fMCReactionPlaneAngleWrap;
+  delete fNumberOfTracksWrap;
+  delete fNumberOfRPsWrap;
+  delete fMCReactionPlaneAngleWrap;
 }
 
 //-----------------------------------------------------------------------
@@ -181,8 +182,13 @@ AliFlowTrackSimple* AliFlowEventSimple::GetTrack(Int_t i)
 //-----------------------------------------------------------------------
 void AliFlowEventSimple::AddTrack( AliFlowTrackSimple* track )
 {
-  //add a track
-  fTrackCollection->AddLast(track);
+  //add a track, delete the old one if necessary
+  if (fNumberOfTracks < fTrackCollection->GetEntriesFast())
+  {
+    TObject* o = fTrackCollection->At(fNumberOfTracks);
+    if (o) delete o;
+  }
+  fTrackCollection->AddAtAndExpand(track,fNumberOfTracks);
   fNumberOfTracks++;
 }
 
@@ -196,7 +202,7 @@ AliFlowVector AliFlowEventSimple::GetQ(Int_t n, TList *weightsList, Bool_t usePh
   vQ.Set(0.,0.);
 
   Int_t iOrder = n;
-  Double_t iUsedTracks = 0;
+  Double_t sumOfWeights = 0.;
   Double_t dPhi = 0.;
   Double_t dPt = 0.;
   Double_t dEta = 0.;
@@ -279,7 +285,7 @@ AliFlowVector AliFlowEventSimple::GetQ(Int_t n, TList *weightsList, Bool_t usePh
         dQY += dWeight*wPhi*wPt*wEta*TMath::Sin(iOrder*dPhi);
 
         // weighted multiplicity:
-        iUsedTracks += dWeight*wPhi*wPt*wEta;
+        sumOfWeights += dWeight*wPhi*wPt*wEta;
 
       } // end of if (pTrack->InRPSelection())
     } // end of if (pTrack)
@@ -290,7 +296,7 @@ AliFlowVector AliFlowEventSimple::GetQ(Int_t n, TList *weightsList, Bool_t usePh
   } // loop over particles
 
   vQ.Set(dQX,dQY);
-  vQ.SetMult(iUsedTracks);
+  vQ.SetMult(sumOfWeights);
 
   return vQ;
 
@@ -305,7 +311,7 @@ void AliFlowEventSimple::Get2Qsub(AliFlowVector* Qarray, Int_t n, TList *weights
   Double_t dQY = 0.;
 
   Int_t iOrder = n;
-  Double_t iUsedTracks = 0;
+  Double_t sumOfWeights = 0.;
   Double_t dPhi = 0.;
   Double_t dPt  = 0.;
   Double_t dEta = 0.;
@@ -417,7 +423,7 @@ void AliFlowEventSimple::Get2Qsub(AliFlowVector* Qarray, Int_t n, TList *weights
             dQY += dWeight*dWphi*dWpt*dWeta*TMath::Sin(iOrder*dPhi);
 
             // weighted multiplicity:
-            iUsedTracks+=dWeight*dWphi*dWpt*dWeta;
+            sumOfWeights+=dWeight*dWphi*dWpt*dWeta;
 
           } // end of subevent
         } // end of if (pTrack->InRPSelection())
@@ -428,9 +434,9 @@ void AliFlowEventSimple::Get2Qsub(AliFlowVector* Qarray, Int_t n, TList *weights
       }
     } // loop over particles
     Qarray[s].Set(dQX,dQY);
-    Qarray[s].SetMult(iUsedTracks);
+    Qarray[s].SetMult(sumOfWeights);
     //reset
-    iUsedTracks = 0;
+    sumOfWeights = 0.;
     dQX = 0.;
     dQY = 0.;
   }
@@ -462,6 +468,7 @@ void AliFlowEventSimple::Print(Option_t *option) const
 //-----------------------------------------------------------------------
 void AliFlowEventSimple::Browse(TBrowser *b)
 {
+  //browse in TBrowser
   if (!b) return;
   if (!fNumberOfTracksWrap)
   {
@@ -705,7 +712,7 @@ void AliFlowEventSimple::AddV2( TF1* ptDepV2 )
 }
 
 //_____________________________________________________________________________
-void AliFlowEventSimple::TagRP( AliFlowTrackSimpleCuts* cuts )
+void AliFlowEventSimple::TagRP( const AliFlowTrackSimpleCuts* cuts )
 {
   //tag tracks as reference particles (RPs)
   for (Int_t i=0; i<fNumberOfTracks; i++)
@@ -727,7 +734,7 @@ void AliFlowEventSimple::TagRP( AliFlowTrackSimpleCuts* cuts )
 }
 
 //_____________________________________________________________________________
-void AliFlowEventSimple::TagPOI( AliFlowTrackSimpleCuts* cuts )
+void AliFlowEventSimple::TagPOI( const AliFlowTrackSimpleCuts* cuts )
 {
   //tag tracks as particles of interest (POIs)
   for (Int_t i=0; i<fNumberOfTracks; i++)
@@ -769,9 +776,11 @@ Int_t AliFlowEventSimple::CleanUpDeadTracks()
   for (Int_t i=0; i<fNumberOfTracks; i++)
   {
     AliFlowTrackSimple* track = static_cast<AliFlowTrackSimple*>(fTrackCollection->At(i));
-    if (track->IsDead()) {delete track;ncleaned++;}
+    if (!track) continue;
+    if (track->IsDead()) {delete track;track=NULL;ncleaned++;}
   }
   fTrackCollection->Compress(); //clean up empty slots
+  fNumberOfTracks-=ncleaned; //update number of tracks
   return ncleaned;
 }
 
@@ -788,3 +797,16 @@ TF1* AliFlowEventSimple::SimplePtSpectrum()
   //return a standard pt spectrum, user has to clean up!
   return new TF1("StandardPtSpectrum","x*TMath::Exp(-pow(0.13957*0.13957+x*x,0.5)/0.4)",0.1,10.);
 }
+
+//_____________________________________________________________________________
+void AliFlowEventSimple::ClearFast()
+{
+  //clear the counter without deleting allocated objects so they can be reused
+  fReferenceMultiplicity = 0;
+  fNumberOfTracks = 0;
+  fNumberOfRPs = 0;
+  fMCReactionPlaneAngle = 0.0;
+  fMCReactionPlaneAngleIsSet = kFALSE;
+  fAfterBurnerPrecision = 0.001;
+  fUserModified = kFALSE;
+}