]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/RESONANCES/AliRsnAnalysisSE.cxx
Major upgrade to the package, in order to speed-up the execution and remove some...
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisSE.cxx
index 32b2e9feeb2c1ef2e469cbfe939fa910049be0dc..cce2d73c6ca85ab112706d2ec2bde5bc61f6d25e 100644 (file)
 //
 // Class AliRsnAnalysisSE
 //
-// TODO
+// Virtual Class derivated from AliRsnVAnalysisTaskSE which will be base class
+// for all RSN SE tasks
 //
 // authors: Martin Vala (martin.vala@cern.ch)
 //          Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
 //
 
 #include <Riostream.h>
-
-#include <TSystem.h>
-#include <TFile.h>
-#include <TFolder.h>
-#include <TROOT.h>
-
-#include "AliLog.h"
-
-#include "AliAnalysisManager.h"
-#include "AliRsnPairMgr.h"
-#include "AliRsnEventBuffer.h"
-
-#include "AliMCEventHandler.h"
+#include <TList.h>
 #include "AliESDEvent.h"
+#include "AliMCEvent.h"
+#include "AliAODEvent.h"
 
+#include "AliRsnCutSet.h"
+#include "AliRsnVATProcessInfo.h"
 #include "AliRsnAnalysisSE.h"
 
 ClassImp(AliRsnAnalysisSE)
 
-//________________________________________________________________________
-AliRsnAnalysisSE::AliRsnAnalysisSE(const char * name, Int_t bufferSize) :
-  AliRsnAnalysisTaskSEBase(name),
-  fDoesMixing(kFALSE),
-  fMixingNum(0),
-  fMixingCut(0x0),
-  fPairMgrs(0),
+//_____________________________________________________________________________
+AliRsnAnalysisSE::AliRsnAnalysisSE(const char *name, Bool_t useKine) :
+  AliRsnVAnalysisTaskSE(name, useKine),
+  fRsnAnalysisManager(),
+  fEventCuts(0x0),
   fOutList(0x0),
-  fBuffer(0x0),
-  fBufferSize(bufferSize)
+  fZeroEventPercentWarning(50),
+  fUseZeroEventWarning(kTRUE)
 {
 //
-// Default constructor
+// Default constructor.
 //
 
-  InitIOVars();
-  DefineOutput(1, TList::Class());
-}
-
-//________________________________________________________________________
-AliRsnAnalysisSE::~AliRsnAnalysisSE()
-{
-//
-// Destructor
-//
+  DefineOutput(2, TList::Class());
+  AliDebug(AliLog::kDebug+2,"->");
 }
 
-//________________________________________________________________________
-void AliRsnAnalysisSE::InitIOVars()
+//_____________________________________________________________________________
+AliRsnAnalysisSE::AliRsnAnalysisSE(const AliRsnAnalysisSE& copy) :
+  AliRsnVAnalysisTaskSE(copy),
+  fRsnAnalysisManager(copy.fRsnAnalysisManager),
+  fEventCuts(copy.fEventCuts),
+  fOutList(0x0),
+  fZeroEventPercentWarning(copy.fZeroEventPercentWarning),
+  fUseZeroEventWarning(copy.fUseZeroEventWarning)
 {
 //
-// Init input output values
+// Copy constructor.
 //
 
-  AliRsnAnalysisTaskSEBase::InitIOVars();
-
-  fBuffer = 0;
-  fOutList = 0;
+  AliDebug(AliLog::kDebug+2,"<-");
+  AliDebug(AliLog::kDebug+2,"->");
 }
 
-//________________________________________________________________________
-void AliRsnAnalysisSE::UserCreateOutputObjects()
+//_____________________________________________________________________________
+void AliRsnAnalysisSE::RsnUserCreateOutputObjects()
 {
 //
-// UserCreateOutputObjects() of AliAnalysisTaskSE
+// Creation of output objects.
+// These are created through the utility methods in the analysis manager,
+// which produces a list of histograms for each specified set of pairs.
+// Each of these lists is added to the main list of this task.
 //
 
-  OpenFile(0);
-  fOutList = new TList();
-  fOutList->SetOwner();
-  AliRsnPair *def=0;
-  AliRsnPairMgr *mgr=0;
-  //TList *listTmp;
-  fDoesMixing = kFALSE;
-  for (Int_t iMgr=0 ;iMgr< fPairMgrs.GetEntries();iMgr++)
-  {
-    mgr = (AliRsnPairMgr *) fPairMgrs.At(iMgr);
-    if (!mgr) continue;
-    //listTmp = new TList();
-    //listTmp->SetName(mgr->GetName());
-    for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++)
-    {
-      def = (AliRsnPair *) mgr->GetPairs()->At(i);
-      if (def)
-      {
-        //listTmp->Add(def->GenerateHistograms(mgr->GetName()));
-        def->GenerateHistograms(mgr->GetName(), fOutList);
-        if (def->IsMixed()) fDoesMixing = kTRUE;
-      }
-    }
-    //fOutList->Add(listTmp);
-  }
+  AliDebug(AliLog::kDebug+2,"<-");
 
-  TH1I *hUsed = new TH1I("hRsnUsed", "skipped and used events in this analysis", 2, 0, 2);
-  fOutList->Add(hUsed);
+  fOutList = new TList;
+  fRsnAnalysisManager.InitAllPairs(fOutList);
+  
+  AliError("\n\n***LIST***\n\n");
+  fOutList->Print();
+
+  PostData(2, fOutList);
 
-  fBuffer = new AliRsnEventBuffer(fBufferSize);
+  AliDebug(AliLog::kDebug+2,"->");
 }
 
-//________________________________________________________________________
-void AliRsnAnalysisSE::UserExec(Option_t *)
+//_____________________________________________________________________________
+void AliRsnAnalysisSE::RsnUserExec(Option_t*)
 {
 //
-// UserExec() of AliAnalysisTaskSE
+// Execution of the analysis task.
+// Recovers the input event and processes it with all included pair objects.
 //
 
-  static UInt_t eventID = 0;
-
-  if (fEntry++ % 100 == 0) cout << "[" << GetName() << "] : processing entry " << fEntry-1 << endl;
-
-  TH1I *h = (TH1I*)fOutList->FindObject("hRsnUsed");
+  AliDebug(AliLog::kDebug+2,"<-");
+  
+  fTaskInfo.SetEventUsed(kFALSE);
 
-  AliRsnEvent *curEvent = GetRsnEventFromInputType();
-  if (curEvent) {
-    curEvent->SetUniqueID(eventID++);
-    ProcessEventAnalysis(curEvent);
-    PostEventProcess();
-    h->Fill(1);
+  if (fESDEvent) {
+    AliDebug(AliLog::kDebug+1, Form("fESDEvent is %p", fESDEvent));
+    AliDebug(AliLog::kDebug, Form("ESD tracks %d", fESDEvent->GetNumberOfTracks()));
   }
-  else {
-    h->Fill(0);
+  if (fMCEvent) {
+    AliDebug(AliLog::kDebug+1, Form("fMCEvent is %p", fMCEvent));
+    AliDebug(AliLog::kDebug, Form("MC tracks %d", fMCEvent->GetNumberOfTracks()));
+  }
+  if (fAODEventIn) {
+    AliDebug(AliLog::kDebug+1, Form("fAODEventIn is %p", fAODEventIn));
+    AliDebug(AliLog::kDebug, Form("AOD(in) tracks %d", fAODEventIn->GetNumberOfTracks()));
+  }
+  if (fAODEventOut) {
+    AliDebug(AliLog::kDebug+1, Form("fAODEventOut if %p", fAODEventOut));
+    AliDebug(AliLog::kDebug, Form("AOD(out) tracks %d", fAODEventOut->GetNumberOfTracks()));
   }
 
-  PostData(1, fOutList);
-}
-
-//________________________________________________________________________
-void AliRsnAnalysisSE::Terminate(Option_t *)
-{
-//
-// Terminate() of AliAnalysisTask
-//
-
-  fOutList = dynamic_cast<TList*>(GetOutputData(1));
-  if (!fOutList) { AliError("At end of analysis, output list is NULL"); return; }
-  //fOutList->Print();
-}
-
-//________________________________________________________________________
-void AliRsnAnalysisSE::ProcessEventAnalysis(AliRsnEvent *curEvent)
-{
-//
-// Process of one event
-//
-
-  // Adds event to Event Buffer
-  fBuffer->AddEvent(curEvent);
-  Int_t index = fBuffer->GetEventsBufferIndex();
-
-  Int_t nmatches;
-  TArrayI matched(0);
-  if (fDoesMixing) matched = FindGoodMatches(index, nmatches);
-
-  // loop over all Pair managers
-  AliRsnPairMgr *mgr=0;
-  for (Int_t iMgr=0 ;iMgr< fPairMgrs.GetEntries();iMgr++)
-  {
-    mgr = (AliRsnPairMgr *) fPairMgrs.At(iMgr);
-    AliRsnPair *pair=0;
-    for (Int_t i=0;i< mgr->GetPairs()->GetEntriesFast();i++)
+  // Removing empty events
+  if (fRsnEvent.GetMultiplicity()<=0) {
+    AliDebug(AliLog::kDebug, "Zero event!!! Skipping ...");
+    fTaskInfo.SetEventUsed(kFALSE);
+    if (fUseZeroEventWarning)
     {
-      pair = (AliRsnPair *) mgr->GetPairs()->At(i);
-      if (!pair->IsMixed()) {
-        pair->ProcessPair(curEvent, 0);
-      }
-      else {
-        Int_t j, iev;
-        for (j = 0; j < matched.GetSize(); j++) {
-          iev = matched[j];
-          if (iev < 0) continue;
-          AliRsnEvent *evmatch = fBuffer->GetEvent(iev);
-          pair->ProcessPair(curEvent, evmatch);
-          if (!pair->IsPairEqual()) pair->ProcessPair(evmatch, curEvent);
-        }
-      }
+      TH1I *hist = (TH1I*)fInfoList->FindObject(fTaskInfo.GetEventHistogramName());
+      if (!hist) return;
+      Double_t zeroEventPercent = 0.0;
+      if (hist->Integral() > 1) zeroEventPercent = (Double_t)hist->GetBinContent(1) / hist->Integral() * 100;
+      if ((zeroEventPercent>fZeroEventPercentWarning)&&(fEntry>100))
+        AliWarning(Form("%3.2f%% Events are with zero tracks (CurrentEvent=%d)!!!",zeroEventPercent,fEntry));
     }
+    return;
   }
-}
 
-//________________________________________________________________________
-void AliRsnAnalysisSE::PostEventProcess(const Short_t & index)
-{
-//
-// Post process of one event
-//
-
-  if (fInputType[index] != kRSN) return;
-
-  if (fBuffer->GetDeleteBufferWhenReset() == kFALSE) {
-    fRSN[index] = (AliRsnEvent*) fBuffer->GetNextEvent();
-    SetBranchAddress(0 , "rsnEvents", &fRSN[index]);
+  // if general event cuts are added to the task (recommended)
+  // they are checked here on the RSN event interface and,
+  // if the event does not pass them, it is skipped and ProcessInfo
+  // is updated accordingly
+  if (fEventCuts) {
+    if (!fEventCuts->IsSelected(&fRsnEvent)) {
+      fTaskInfo.SetEventUsed(kFALSE);
+      return;
+    }
   }
-}
 
-//________________________________________________________________________
-void  AliRsnAnalysisSE::AddPairMgr(AliRsnPairMgr * pairmgr)
-{
-  fPairMgrs.Add(pairmgr);
-}
+  // if cuts are passed or not cuts were defined,
+  // update the task info...
+  fTaskInfo.SetEventUsed(kTRUE);
 
-//________________________________________________________________________
-void AliRsnAnalysisSE::AddPairMgrFromConfig(TString configfile,TString analysisName)
-{
-  gROOT->LoadMacro(configfile.Data());
-
-  configfile.ReplaceAll(".C","");
-
-  analysisName.ReplaceAll("_","-");
-  
-  AliRsnPairMgr *mgrRsn = (AliRsnPairMgr *) gROOT->ProcessLine(Form("%s(\"%s\");", configfile.Data(),analysisName.Data()));
-  if (!mgrRsn) return;
+  // the virtual class has already sorted tracks in the PID index
+  // so we need here just to call the execution of analysis
+  fRsnAnalysisManager.ProcessAllPairs(&fRsnEvent, &fRsnEvent);
+  PostData(2, fOutList);
 
-  fPairMgrs.Add(mgrRsn);
+  AliDebug(AliLog::kDebug+2,"->");
 }
 
-//________________________________________________________________________
-TArrayI AliRsnAnalysisSE::FindGoodMatches(Int_t iRef, Int_t &foundMatches)
-{
-  // initialize the output array to the size of required mixed events
-  // and initialize all members to -1
-  Int_t i;
-  TArrayI matched(fMixingNum);
-  for (i = 0; i < fMixingNum; i++) matched[i] = -1;
-  foundMatches = 0;
 
-  // starts from the position behind the reference index
-  // and goes backward; if it reaches the value 0, stops
-  AliRsnEvent *refEvent = fBuffer->GetEvent(iRef);
-  if (!refEvent) return matched;
-  AliRsnEvent *matchEvent = 0x0;
-  Int_t checkIndex;
-  for (checkIndex = iRef - 1; ; checkIndex--) {
-    if (checkIndex < 0) checkIndex = fBuffer->GetEventsBufferSize() - 1;
-    if (checkIndex == iRef) break;
-    matchEvent = fBuffer->GetEvent(checkIndex);
-    if (!matchEvent) continue;
-    if (fMixingCut) {
-      if (!fMixingCut->IsSelected(AliRsnCut::kMixEvent, refEvent, matchEvent)) continue;
-    }
-    // assign to current array slot the matched event
-    // and increment current slot and stops if it exceeds array size
-    matched[foundMatches++] = checkIndex;
-    if (foundMatches >= fMixingNum) break;
-  }
+//_____________________________________________________________________________
+void AliRsnAnalysisSE::RsnTerminate(Option_t*)
+{
+//
+// Termination.
+// Could be added some monitor histograms here.
+//
 
-  // returns the current index value,
-  // which is also the number of matched events found
-  return matched;
+  AliDebug(AliLog::kDebug+2,"<-");
+  AliDebug(AliLog::kDebug+2,"->");
 }
+