]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - JETAN/AliJetFinder.cxx
Ignoring smell subdet
[u/mrichter/AliRoot.git] / JETAN / AliJetFinder.cxx
index 7b866dd2f97792556250150eb4ed37b5c9b9fa20..02416cc4b6c0e9303d56dcf9f4410967a76893db 100644 (file)
  * about the suitability of this software for any purpose. It is          *
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
-  
+   
+/* $Id$ */
+
 //---------------------------------------------------------------------
 // Jet finder base class
 // manages the search for jets 
-// Author: jgcn@mda.cinvestav.mx
+// Authors: jgcn@mda.cinvestav.mx
+//          andreas.morsch@cern.ch
 //---------------------------------------------------------------------
 
 #include <Riostream.h>
 #include <TFile.h>
-#include "AliGenPythiaEventHeader.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 "AliHeader.h"
-
+#include "AliAODEvent.h"
 
 ClassImp(AliJetFinder)
 
-////////////////////////////////////////////////////////////////////////
-
-AliJetFinder::AliJetFinder()
+AliJetFinder::AliJetFinder():
+    fTreeJ(0),
+    fPlotMode(kFALSE),
+    fJets(0),
+    fGenJets(0),
+    fLeading(0),
+    fReader(0x0),
+    fHeader(0x0),
+    fAODjets(0x0),
+    fNAODjets(0),
+    fPlots(0x0),
+    fOut(0x0)
+    
 {
-  //
   // Constructor
-  //
-  fOut     = 0x0;
   fJets    = new AliJet();
   fGenJets = new AliJet();
   fLeading = new AliLeading();
-  fReader  = 0x0;
-  fPlots   = 0x0;
-  SetPlotMode(kFALSE);
+  fAODjets = 0;
 }
 
-
 ////////////////////////////////////////////////////////////////////////
 
 AliJetFinder::~AliJetFinder()
 {
-  //
   // destructor
-  //
-
   // here reset and delete jets
   fJets->ClearJets();
   delete fJets;
@@ -72,56 +76,45 @@ AliJetFinder::~AliJetFinder()
   delete fOut;
   // reset and delete control plots
   if (fPlots) delete fPlots;
-  // delete fLeading;
 }
 
-
 ////////////////////////////////////////////////////////////////////////
 
-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");
 }
 
-
 ////////////////////////////////////////////////////////////////////////
 
 void AliJetFinder::PrintJets()
 {
-//
-// Print jet information
+  // Print jet information
   cout << " Jets found with jet algorithm:" << endl;
   fJets->PrintJets();
   cout << " Jets found by pythia:" << endl;
   fGenJets->PrintJets();
 }
 
-
 ////////////////////////////////////////////////////////////////////////
 
 void AliJetFinder::SetPlotMode(Bool_t b)
 {
-// Sets the plotting mode
+  // Sets the plotting mode
   fPlotMode=b;
   if (b && !fPlots) fPlots = new AliJetControlPlots(); 
 }
 
 ////////////////////////////////////////////////////////////////////////
-
-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);
-  TTree* jetT = new TTree(hname,"AliJet");
-  jetT->Branch("FoundJet",&fJets,1000);
-  jetT->Branch("GenJet",&fGenJets,1000);
-  jetT->Branch("LeadingPart",&fLeading,1000);
-  jetT->Fill();
-  jetT->Write(hname);
-  delete jetT;
+    // 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;
 }
 
 ////////////////////////////////////////////////////////////////////////
@@ -129,69 +122,55 @@ 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();
 }
 
-
 ////////////////////////////////////////////////////////////////////////
 
-void AliJetFinder::GetGenJets()
-{
-// Get the generated jet information from mc header
-  AliHeader* alih = fReader->GetAliHeader(); 
-  if (alih == 0) return;
-  AliGenEventHeader * genh = alih->GenEventHeader();
-  if (genh == 0) return;
-  Int_t nj =((AliGenPythiaEventHeader*)genh)->NTriggerJets(); 
-  Int_t* m = new Int_t[nj];
-  Int_t* k = new Int_t[nj];
-  for (Int_t i=0; i< nj; i++) {
-    Float_t p[4];
-    ((AliGenPythiaEventHeader*)genh)->TriggerJet(i,p);
-    fGenJets->AddJet(p[0],p[1],p[2],p[3]);
-    m[i]=1;
-    k[i]=i;
-  }
-  fGenJets->SetNinput(nj);
-  fGenJets->SetMultiplicities(m);
-  fGenJets->SetInJet(k);
-}
-
-////////////////////////////////////////////////////////////////////////
 
 void AliJetFinder::Run()
 {
-  // do some initialization
+  // Do some initialization
   Init();
-
   // connect files
   fReader->OpenInputFiles();
 
   // write headers
-  if (fOut) {
-      fOut->cd();
-      WriteRHeaderToFile();
-      WriteJHeaderToFile();
-  }
-
+  WriteHeaders();
   // loop over events
-  Int_t nFirst,nLast;
+  Int_t nFirst, nLast, option, debug, arrayInitialised; 
   nFirst = fReader->GetReaderHeader()->GetFirstEvent();
-  nLast = fReader->GetReaderHeader()->GetLastEvent();
+  nLast  = fReader->GetReaderHeader()->GetLastEvent();
+
+  option = fReader->GetReaderHeader()->GetDetector();
+  debug  = fReader->GetReaderHeader()->GetDebug();
+  arrayInitialised = fReader->GetArrayInitialised();
+
   // loop over events
   for (Int_t i=nFirst;i<nLast;i++) {
       fReader->FillMomentumArray(i);
       fLeading->FindLeading(fReader);
-      GetGenJets();
-      FindJets();
-      if (fOut) WriteJetsToFile(i);
-      if (fPlots) fPlots->FillHistos(fJets,fReader);
+      fReader->GetGenJets(fGenJets);
+
+      if (option == 0) { // TPC with fMomentumArray
+         if(debug > 1) 
+             printf("In FindJetsTPC() routine: find jets with fMomentumArray !!!\n");
+         FindJetsTPC();
+      } else {
+          if(debug > 1) printf("In FindJets() routine: find jets with fUnitArray !!!\n");
+          FindJets();
+      }
+      if (fOut) {
+         fOut->cd();
+      }
+      
+      if (fPlots) fPlots->FillHistos(fJets);
       fLeading->Reset();
       fGenJets->ClearJets();
       Reset();
   } 
+
   // write out
   if (fPlots) {
       fPlots->Normalize();
@@ -204,3 +183,75 @@ void AliJetFinder::Run()
   }
 }
 
+
+//
+// The following methods have been added to allow for event steering from the outside
+//
+
+void AliJetFinder::ConnectTree(TTree* tree, TObject* data)
+{
+    // Connect the input file
+    fReader->ConnectTree(tree, data);
+}
+
+void AliJetFinder::WriteHeaders()
+{
+    // Write the Headers
+    TFile* f = new TFile("jets_local.root", "recreate");
+    WriteRHeaderToFile();
+    WriteJHeaderToFile();
+    f->Close();
+}
+
+
+Bool_t AliJetFinder::ProcessEvent(Long64_t entry)
+{
+//
+// Process one event
+//
+    Int_t debug  = fReader->GetReaderHeader()->GetDebug();
+    if (debug > 0) printf("<<<<< Processing Event %5d >>>>> \n", (Int_t) entry);
+    
+    Bool_t ok = fReader->FillMomentumArray(entry);
+    if (!ok) return kFALSE;
+
+    // Leading particles
+    fLeading->FindLeading(fReader);
+    // Jets
+    FindJets();
+
+    if (fPlots) fPlots->FillHistos(fJets);
+    fLeading->Reset();
+    fGenJets->ClearJets();
+    Reset();  
+    return kTRUE;
+}
+
+void AliJetFinder::FinishRun()
+{
+    // Finish a run
+    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();
+}