]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnSimpleAnalysis.cxx
Package revised - New AnalysisTask's - Added more functions
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnSimpleAnalysis.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 //-------------------------------------------------------------------------
17 //                     Class AliRsnSimpleAnalysis
18 //-------------------------------------------------------------------------
19 // This class is a manager to process one or more pair analysis with a
20 // given event sample, specified as a TTree passed to this object.
21 // Each single pair analysis must be defined with its specifications, like
22 // histogram binning, cuts and everything else.
23 // This class utiliy consists in defining a unique event sample which is
24 // used for all pairs analysis, and all kinds of event mixing (if required).
25 // All histograms computed in a single execution, are then saved into a file.
26 // This object contains a two TObjArray's:
27 //  - one to contain single event pair analysis objects (signal, like-sign)
28 //  - one to contain all event-mixing pair analysis objects
29 // When a new pair is added, it must be then specified in what container it
30 // must be placed, in order to avoid meaningless results.
31 //
32 // author: A. Pulvirenti
33 // email : alberto.pulvirenti@ct.infn.it
34 //-------------------------------------------------------------------------
35
36 #include <TH1.h>
37 #include <TH2.h>
38 #include <TTree.h>
39 #include <TFile.h>
40 #include <TArray.h>
41 #include <TClonesArray.h>
42
43 #include "AliLog.h"
44 #include "AliRsnPID.h"
45 #include "AliRsnDaughter.h"
46 #include "AliRsnEvent.h"
47 #include "AliRsnEventBuffer.h"
48 #include "AliRsnSimpleFunction.h"
49 #include "AliRsnSimpleAnalyzer.h"
50 #include "AliRsnSimpleAnalysis.h"
51
52 ClassImp(AliRsnSimpleAnalysis)
53
54 //_____________________________________________________________________________
55 AliRsnSimpleAnalysis::AliRsnSimpleAnalysis(AliRsnSimpleAnalyzer *ana, AliRsnPID *pid) :
56     TObject(),
57     fInitialized(kFALSE),
58     fStep(1000),
59     fTree(0x0),
60     fPID(pid),
61     fAnalyzer(ana)
62 {
63 //
64 // Constructor
65 // Initializes all pointers and collections to NULL.
66 //
67
68   strcpy(fFileName, "default.root");
69 }
70
71
72 //_____________________________________________________________________________
73 void AliRsnSimpleAnalysis::Clear(Option_t* /*option*/)
74 {
75 //
76 // Clear heap
77 //
78 }
79
80 //_____________________________________________________________________________
81 void AliRsnSimpleAnalysis::SetEventsTree(TTree *tree)
82 {
83 //
84 // Set the tree containing the events to be processed.
85 // Counts also the number of events and stores it in a private datamember.
86 // This can avoid the time-wasting entries count in a long TChain.
87 //
88   fTree = tree;
89   AliInfo(Form("Total number of events to be processed: %d", fTree->GetEntries()));
90 }
91
92 //_____________________________________________________________________________
93 Bool_t AliRsnSimpleAnalysis::Initialize()
94 {
95 //
96 // Various initialization processes
97 //
98   // check process objects
99   if (!fAnalyzer)
100   {
101     AliError("Analyzer not initialized");
102     return kFALSE;
103   }
104
105   // initialize analyzer
106   fAnalyzer->Init();
107
108   // at the end, update flag for initialization
109   fInitialized = kTRUE;
110
111   return kTRUE;
112 }
113
114 //_____________________________________________________________________________
115 Stat_t AliRsnSimpleAnalysis::Process()
116 {
117 //
118 // Computes all invariant mass distributions defined in the AliRsnPair objects collected.
119 // Depending on the kind of background evaluation method, computes also this one.
120 //
121
122   // check initialization
123   if (!fInitialized)
124   {
125     AliError("Analysis not initialized. Use method 'Initialize()'");
126     return 0.0;
127   }
128
129   // set cursor object
130   AliRsnEvent *event = 0x0;
131   fTree->SetBranchAddress("rsnEvents", &event);
132
133   // output counter
134   Stat_t nPairs = 0.0;
135
136   // loop on events
137   Int_t i, nEvents = (Int_t)fTree->GetEntries();
138   for (i = 0; i < nEvents; i++)
139   {
140     // message
141     if ((i % fStep) == 0) AliInfo(Form("Processing event %d", i));
142     // get entry
143     fTree->GetEntry(i);
144     if (!event) continue;
145     fPID->Process(event);
146     fAnalyzer->Process(event);
147   }
148
149   return nPairs;
150 }
151
152 //_____________________________________________________________________________
153 void AliRsnSimpleAnalysis::SaveOutput() const
154 {
155 //
156 // Writes histograms in current directory
157 //
158   TFile *file = TFile::Open(fFileName, "RECREATE");
159   AliRsnSimpleFunction *pair = 0;
160   TH1D *h1D = 0;
161   TH2D *h2D = 0;
162   TObjArrayIter pairIterator(fAnalyzer->GetSingle());
163   while ((pair = (AliRsnSimpleFunction*)pairIterator.Next()))
164   {
165     h1D = pair->GetHistogram1D();
166     h2D = pair->GetHistogram2D();
167     if (h1D) h1D->Write();
168     if (h2D) h2D->Write();
169   }
170   if (fAnalyzer->GetMix() && !fAnalyzer->GetMix()->IsEmpty())
171   {
172     TObjArrayIter mixIterator(fAnalyzer->GetMix());
173     while ((pair = (AliRsnSimpleFunction*)mixIterator.Next()))
174     {
175       h1D = pair->GetHistogram1D();
176       h2D = pair->GetHistogram2D();
177       if (h1D) h1D->Write();
178       if (h2D) h2D->Write();
179     }
180   }
181   file->Close();
182 }