]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - JETAN/AliAnalysisTaskJets.cxx
Bug fix for the case of more than 30 timebins
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskJets.cxx
index d185bb47878078bdb3f3e5e5b67c33d995745b3a..cd40523f55cf9944be1caac16d6b594b2e91a175 100644 (file)
@@ -14,7 +14,7 @@
  **************************************************************************/
 
 /* $Id$ */
+#include <Riostream.h> 
 #include <TROOT.h>
 #include <TSystem.h>
 #include <TInterpreter.h>
 #include "AliAnalysisTaskJets.h"
 #include "AliAnalysisManager.h"
 #include "AliJetFinder.h"
+#include "AliJetHeader.h"
+#include "AliJetReader.h"
+#include "AliJetReaderHeader.h"
 #include "AliJetHistos.h"
 #include "AliESDEvent.h"
 #include "AliESD.h"
 #include "AliAODEvent.h"
+#include "AliAODJetEventBackground.h"
 #include "AliAODHandler.h"
 #include "AliMCEventHandler.h"
 #include "AliESDInputHandler.h"
@@ -41,74 +45,166 @@ ClassImp(AliAnalysisTaskJets)
 ////////////////////////////////////////////////////////////////////////
 
 AliAnalysisTaskJets::AliAnalysisTaskJets():
-    AliAnalysisTaskSE(),
-    fJetFinder(0x0),
-    fTree(0x0),
-    fHistos(0x0),
-    fListOfHistos(0x0)
+  AliAnalysisTaskSE(),
+  fConfigFile("ConfigJetAnalysis.C"),
+  fNonStdBranch(""), 
+  fJetFinder(0x0),
+  fHistos(0x0),
+  fListOfHistos(0x0),
+  fChain(0x0),
+  fOpt(0)
 {
   // Default constructor
 }
 
 AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name):
-    AliAnalysisTaskSE(name),
-    fJetFinder(0x0),
-    fTree(0x0),
-    fHistos(0x0),
-    fListOfHistos(0x0)
+  AliAnalysisTaskSE(name),
+  fConfigFile("ConfigJetAnalysis.C"),
+  fNonStdBranch(""),
+  fJetFinder(0x0),
+  fHistos(0x0),
+  fListOfHistos(0x0),
+  fChain(0x0),
+  fOpt(0)
 {
   // Default constructor
-    DefineOutput(1, TList::Class());
+  DefineOutput(1, TList::Class());
 }
 
-void AliAnalysisTaskJets::UserCreateOutputObjects()
+AliAnalysisTaskJets::AliAnalysisTaskJets(const char* name, TChain* chain):
+  AliAnalysisTaskSE(name),
+  fConfigFile("ConfigJetAnalysis.C"),
+  fNonStdBranch(""),
+  fJetFinder(0x0),
+  fHistos(0x0),
+  fListOfHistos(0x0),
+  fChain(chain),
+  fOpt(0)
 {
-// Create the output container
-//
-    if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
-//  Connec default AOD to jet finder
+  // Default constructor
+  DefineOutput(1, TList::Class());
+}
 
-    fJetFinder->ConnectAOD(AODEvent());
-//
-//  Histograms
-    OpenFile(1);
-    fListOfHistos = new TList();
-    fHistos       = new AliJetHistos();
-    fHistos->AddHistosToList(fListOfHistos);
+//----------------------------------------------------------------
+void AliAnalysisTaskJets::UserCreateOutputObjects()
+{
+  // Create the output container
+  //
+  if (fDebug > 1) printf("AnalysisTaskJets::CreateOutPutData() \n");
+  
+  if(fNonStdBranch.Length()==0)
+    {
+      //  Connec default AOD to jet finder
+      // create a new branch for the background
+      if(!AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName())){
+       AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
+       evBkg->SetName(AliAODJetEventBackground::StdBranchName());
+       AddAODBranch("AliAODJetEventBackground",&evBkg);
+      }
+      fJetFinder->ConnectAOD(AODEvent());
+    }
+  else
+    {
+      // Create a new branch for jets...
+      // how is this reset? -> cleared in the UserExec....
+      // Can this be handled by the framework?
+      TClonesArray *tca = new TClonesArray("AliAODJet", 0);
+      tca->SetName(fNonStdBranch);
+      AddAODBranch("TClonesArray",&tca);
+      if(!AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()))){
+       AliAODJetEventBackground* evBkg = new AliAODJetEventBackground();
+       evBkg->SetName(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data()));
+       AddAODBranch("AliAODJetEventBackground",&evBkg);
+      }
+      fJetFinder->ConnectAODNonStd(AODEvent(), fNonStdBranch.Data()); 
+    }
+
+
+  // Histograms
+  OpenFile(1);
+  fListOfHistos = new TList();
+  fHistos       = new AliJetHistos();
+  fHistos->AddHistosToList(fListOfHistos);
+  
+  // Add the JetFinderInformation to the Outputlist
+  AliJetHeader *fH = fJetFinder->GetHeader();
+  
+  // Compose a characteristic output name
+  // with the name of the output branch
+  if(fH) {
+    if(fNonStdBranch.Length()==0) {
+      fH->SetName("AliJetHeader_jets");
+    }
+    else {
+      fH->SetName(Form("AliJetHeader_%s",fNonStdBranch.Data()));
+    }
+  }
+  OutputTree()->GetUserInfo()->Add(fH);
 }
 
+//----------------------------------------------------------------
 void AliAnalysisTaskJets::Init()
 {
-    // Initialization
-    if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
-
-    // Call configuration file
-    gROOT->LoadMacro("ConfigJetAnalysis.C");
+  // Initialization
+  if (fDebug > 1) printf("AnalysisTaskJets::Init() \n");
+  
+  // Call configuration file
+  if (fConfigFile.Length()) {
+    gROOT->LoadMacro(fConfigFile);
     fJetFinder = (AliJetFinder*) gInterpreter->ProcessLine("ConfigJetAnalysis()");
-    // Initialise Jet Analysis
-    fJetFinder->Init();
-    // Write header information to local file
-    fJetFinder->WriteHeaders();
+  }
+  AliJetReaderHeader *header = (AliJetReaderHeader*)fJetFinder->GetReader()->GetReaderHeader();
+  fOpt = header->GetDetector();
+
+  // Initialise Jet Analysis
+  if(fOpt == 0) fJetFinder->Init();
+  else fJetFinder->InitTask(fChain); // V2
+  
+  // Write header information to local file
+  fJetFinder->WriteHeaders();
 }
 
-    
-
-
-
+//----------------------------------------------------------------
 void AliAnalysisTaskJets::UserExec(Option_t */*option*/)
 {
-// Execute analysis for current event
-//
-    
-    fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
-    fJetFinder->ProcessEvent();
-
-    // Fill control histos
-    fHistos->FillHistos(AODEvent()->GetJets());
-    // Post the data
-    PostData(1, fListOfHistos);
+  // Execute analysis for current event
+  //
+  // Fill control histos
+  TClonesArray* jarray = 0;
+  AliAODJetEventBackground*  evBkg;
+
+  if(fNonStdBranch.Length()==0) {
+    jarray = AODEvent()->GetJets();
+    evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(AliAODJetEventBackground::StdBranchName()));
+    evBkg->Reset();
+  }
+  else {
+    jarray = dynamic_cast<TClonesArray*>(AODEvent()->FindListObject(fNonStdBranch.Data()));
+    jarray->Delete();    // this is our responsibility, clear before filling again
+    evBkg = (AliAODJetEventBackground*)(AODEvent()->FindListObject(Form("%s_%s",AliAODJetEventBackground::StdBranchName(),fNonStdBranch.Data())));
+    evBkg->Reset();
+  }
+  if (dynamic_cast<AliAODEvent*>(InputEvent()) !=  0) {
+      fJetFinder->GetReader()->SetInputEvent(InputEvent(), InputEvent(), MCEvent());
+  } else {
+      fJetFinder->GetReader()->SetInputEvent(InputEvent(), AODEvent(), MCEvent());
+  }
+  
+  
+
+  if(fOpt==0) fJetFinder->ProcessEvent();
+  else fJetFinder->ProcessEvent2();    // V2
+  // Fill control histos
+  fHistos->FillHistos(jarray);
+
+  // Post the data
+  PostData(1, fListOfHistos);
 }
 
+
+//*************************************************************
+
 void AliAnalysisTaskJets::Terminate(Option_t */*option*/)
 {
 // Terminate analysis