]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Replaced dynamic array alocation by static array size, not to fragment memory
authorkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 18 Sep 2009 14:51:21 +0000 (14:51 +0000)
committerkleinb <kleinb@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 18 Sep 2009 14:51:21 +0000 (14:51 +0000)
PWG4/JetTasks/AliAnalysisHelperJetTasks.cxx
PWG4/JetTasks/AliAnalysisHelperJetTasks.h

index 20008803c67041067bb00d8b1dfecd43b03f5d4c..0c3e072beb18ef3b36896a1300109d501e32afa0 100644 (file)
@@ -79,8 +79,8 @@ void AliAnalysisHelperJetTasks::PrintStack(AliMCEvent *mcEvent,Int_t iFirst,Int_
 
 
 
-void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &nGenJets,
-                                              AliAODJet *recJets,const Int_t &nRecJets,
+void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &kGenJets,
+                                              AliAODJet *recJets,const Int_t &kRecJets,
                                               Int_t *iGenIndex,Int_t *iRecIndex,
                                               Int_t iDebug,Float_t maxDist){
 
@@ -95,6 +95,7 @@ void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &n
   // and check if there is no other rec which is closer
   // Caveat: Close low energy/split jets may disturb this correlation
 
+
   // Idea: search in two directions generated e.g (a--e) and rec (1--3)
   // Fill a matrix with Flags (1 for closest rec jet, 2 for closest rec jet
   // in the end we have something like this
@@ -112,17 +113,26 @@ void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &n
   //  d      c
   //        3     e
   // Only entries with "3" match from both sides
+
+  // In case we have more jets than kmaxjets only the 
+  // first kmaxjets are searched
+  // all other are -1
+  // use kMaxJets for a test not to fragemnt the memory...
+
+  for(int i = 0;i < kGenJets;++i)iGenIndex[i] = -1;
+  for(int j = 0;j < kRecJets;++j)iRecIndex[j] = -1;
+
+
   
   const int kMode = 3;
 
-  
+  const Int_t nGenJets = TMath::Min(kMaxJets,kGenJets);
+  const Int_t nRecJets = TMath::Min(kMaxJets,kRecJets);
 
   if(nRecJets==0||nGenJets==0)return;
 
-  for(int i = 0;i < nGenJets;++i)iGenIndex[i] = -1;
-  for(int j = 0;j < nRecJets;++j)iRecIndex[j] = -1;
-
-  UShort_t *iFlag = new UShort_t[nGenJets*nRecJets];
+  // UShort_t *iFlag = new UShort_t[nGenJets*nRecJets];
+  UShort_t iFlag[kMaxJets*kMaxJets];
   for(int i = 0;i < nGenJets;++i){
     for(int j = 0;j < nRecJets;++j){
       iFlag[i*nGenJets+j] = 0;
@@ -191,9 +201,6 @@ void AliAnalysisHelperJetTasks::GetClosestJets(AliAODJet *genJets,const Int_t &n
     }
     if(iDebug>1)printf("\n");
   }
-
-  delete [] iFlag;
-
 }
 
 
index e913b39bc060f66da9c571340d96152917eb8d3b..c182b74e42970caf88e8f78bde49a31d269eaaed 100644 (file)
@@ -17,16 +17,16 @@ class AliAnalysisHelperJetTasks : public TObject {
   static AliGenPythiaEventHeader*  GetPythiaEventHeader(AliMCEvent *mcEvent);
   static void PrintStack(AliMCEvent *mcEvent,Int_t iFirst = 0,Int_t iLast = 0,Int_t iMaxPrint = 10);
   static void GetClosestJets(AliAODJet *genJets,
-                            const Int_t &nGenJets,
+                            const Int_t &kGenJets,
                             AliAODJet *recJets,
-                            const Int_t &nRecJets,
+                            const Int_t &kRecJets,
                             Int_t *iGenIndex,
                             Int_t *iRecIndex,
                             Int_t iDebug, Float_t maxDist = 0.5);
 
   static void MergeOutput(char* cFiles, char* cList = "pwg4spec"); // Merges the files in the input text file  needs the two histograms fh1PtHard_Trials, fh1Xsec and the name of the input list
   
-
+  enum {kMaxJets = 6}; //  needed for array size not to fragemnt memory on the heap by many new/delete 
   private:
   
   ClassDef(AliAnalysisHelperJetTasks, 1)