]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - JETAN/AliJetFinder.cxx
fix memory leak and funny multiplicity
[u/mrichter/AliRoot.git] / JETAN / AliJetFinder.cxx
index 31f886b1fb560b2a6f414c0174d3063b69bae01d..d8cb7ba9e12b27e465d8a6190b658081956591c5 100644 (file)
 
 #include <Riostream.h>
 #include <TFile.h>
+#include <TClonesArray.h>
+
 #include "AliJetFinder.h"
 #include "AliJet.h"
+#include "AliAODJet.h"
 #include "AliJetReader.h"
 #include "AliJetReaderHeader.h"
 #include "AliJetControlPlots.h"
 #include "AliLeading.h"
+#include "AliAODEvent.h"
 
 ClassImp(AliJetFinder)
 
 AliJetFinder::AliJetFinder():
-    fJetT(0),
+    fTreeJ(0),
     fPlotMode(kFALSE),
     fJets(0),
     fGenJets(0),
     fLeading(0),
     fReader(0x0),
     fHeader(0x0),
+    fAODjets(0x0),
+    fNAODjets(0),
     fPlots(0x0),
     fOut(0x0)
     
@@ -49,6 +55,7 @@ AliJetFinder::AliJetFinder():
   fJets    = new AliJet();
   fGenJets = new AliJet();
   fLeading = new AliLeading();
+  fAODjets = 0;
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -69,14 +76,17 @@ AliJetFinder::~AliJetFinder()
   delete fOut;
   // reset and delete control plots
   if (fPlots) delete fPlots;
+  if ( fLeading )
+      delete fLeading;
+  fLeading = NULL;
 }
 
 ////////////////////////////////////////////////////////////////////////
 
-void AliJetFinder::SetOutputFile(const char *name)
+void AliJetFinder::SetOutputFile(const char */*name*/)
 {
-  // opens output file 
-  fOut = new TFile(name,"recreate");
+  //  opens output file 
+  //  fOut = new TFile(name,"recreate");
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -100,20 +110,14 @@ void AliJetFinder::SetPlotMode(Bool_t b)
 }
 
 ////////////////////////////////////////////////////////////////////////
-
-void AliJetFinder::WriteJetsToFile(Int_t i)
+TTree* AliJetFinder::MakeTreeJ(char* name)
 {
-  // Writes the jets to file
-  fOut->cd();
-  char hname[30];
-  sprintf(hname,"TreeJ%d",i);
-  fJetT = new TTree(hname,"AliJet");
-  fJetT->Branch("FoundJet",&fJets,1000);
-  fJetT->Branch("GenJet",&fGenJets,1000);
-  fJetT->Branch("LeadingPart",&fLeading,1000);
-  fJetT->Fill();
-  fJetT->Write(hname);
-  delete fJetT;
+    // Create the tree for reconstructed jets
+    fTreeJ = new TTree(name, "AliJet");
+    fTreeJ->Branch("FoundJet",   &fJets,   1000);
+    fTreeJ->Branch("GenJet",     &fGenJets,1000);
+    fTreeJ->Branch("LeadingPart",&fLeading,1000);
+    return fTreeJ;
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -121,9 +125,8 @@ void AliJetFinder::WriteJetsToFile(Int_t i)
 void AliJetFinder::WriteRHeaderToFile()
 {
   // write reader header
-  fOut->cd();
-  AliJetReaderHeader *rh = fReader->GetReaderHeader();
-  rh->Write();
+    AliJetReaderHeader *rh = fReader->GetReaderHeader();
+    rh->Write();
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -149,7 +152,7 @@ void AliJetFinder::Run()
 
   // loop over events
   for (Int_t i=nFirst;i<nLast;i++) {
-      fReader->FillMomentumArray(i);
+      fReader->FillMomentumArray();
       fLeading->FindLeading(fReader);
       fReader->GetGenJets(fGenJets);
 
@@ -161,7 +164,10 @@ void AliJetFinder::Run()
           if(debug > 1) printf("In FindJets() routine: find jets with fUnitArray !!!\n");
           FindJets();
       }
-      if (fOut) WriteJetsToFile(i);
+      if (fOut) {
+         fOut->cd();
+      }
+      
       if (fPlots) fPlots->FillHistos(fJets);
       fLeading->Reset();
       fGenJets->ClearJets();
@@ -185,34 +191,35 @@ void AliJetFinder::Run()
 // The following methods have been added to allow for event steering from the outside
 //
 
-void AliJetFinder::ConnectTree(TTree* tree)
+void AliJetFinder::ConnectTree(TTree* tree, TObject* data)
 {
     // Connect the input file
-    fReader->ConnectTree(tree);
+    fReader->ConnectTree(tree, data);
 }
 
 void AliJetFinder::WriteHeaders()
 {
     // Write the Headers
-    if (fOut) {
-       fOut->cd();
-       WriteRHeaderToFile();
-       WriteJHeaderToFile();
-    }
+    TFile* f = new TFile("jets_local.root", "recreate");
+    WriteRHeaderToFile();
+    WriteJHeaderToFile();
+    f->Close();
 }
 
 
-Bool_t AliJetFinder::ProcessEvent(Long64_t entry)
+Bool_t AliJetFinder::ProcessEvent()
 {
 //
 // Process one event
 //
-    printf("<<<<< Processing Event %5d >>>>> \n", (Int_t) entry);
-    Bool_t ok = fReader->FillMomentumArray(entry);
+    Bool_t ok = fReader->FillMomentumArray();
     if (!ok) return kFALSE;
+
+    // Leading particles
     fLeading->FindLeading(fReader);
+    // Jets
     FindJets();
-    if (fOut)   WriteJetsToFile(entry);
+
     if (fPlots) fPlots->FillHistos(fJets);
     fLeading->Reset();
     fGenJets->ClearJets();
@@ -223,16 +230,35 @@ Bool_t AliJetFinder::ProcessEvent(Long64_t entry)
 void AliJetFinder::FinishRun()
 {
     // Finish a run
-  if (fPlots) {
-      fPlots->Normalize();
-      fPlots->PlotHistos();
-      if (fOut) {
-         fOut->cd();
-         fPlots->Write();
-         fOut->Close();
-      }   
-  } else {
-      if (fOut) fOut->Close();
-  }
+    if (fPlots) {
+       fPlots->Normalize();
+       fPlots->PlotHistos();
+    }
+    
+    if (fOut) {
+        fOut->cd();
+        if (fPlots) {
+            fPlots->Write();
+        }
+        fOut->Close();
+    }
+}
+
+void AliJetFinder::AddJet(AliAODJet p)
+{
+  // Add new jet to the list
+  new ((*fAODjets)[fNAODjets++]) AliAODJet(p);
+}
+
+void AliJetFinder::ConnectAOD(AliAODEvent* aod)
+{
+// Connect to the AOD
+    fAODjets = aod->GetJets();
 }
 
+void AliJetFinder::ConnectAODNonStd(AliAODEvent* aod,const char *bname)
+{
+
+  fAODjets = dynamic_cast<TClonesArray*>(aod->FindListObject(bname));
+  // how is this is reset? Cleared?
+}