]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODInputHandler.cxx
Optionally the log term of Rossi parameterization for mult.scattering can be
[u/mrichter/AliRoot.git] / STEER / AliAODInputHandler.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, 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 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     Event handler for AOD input 
20 //     Author: Andreas Morsch, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TSystem.h>
24 #include <TTree.h>
25 #include <TList.h>
26 #include <TNamed.h>
27 #include <TFile.h>
28 #include <TH2.h>
29
30 #include "AliAODInputHandler.h"
31 #include "AliAODEvent.h"
32 #include "AliVCuts.h"
33 #include "AliMCEvent.h"
34 #include "AliAODpidUtil.h"
35
36 ClassImp(AliAODInputHandler)
37
38 static Option_t *gAODDataType = "AOD";
39
40 //______________________________________________________________________________
41 AliAODInputHandler::AliAODInputHandler() :
42     AliInputEventHandler(),
43     fEvent(0),
44     fMCEvent(new AliMCEvent()),
45     fFriends(new TList()),
46     fAODpidUtil(0x0),
47     fMergeEvents(kFALSE),
48     fFriendsConnected(kFALSE),
49     fFileToMerge(0),
50     fTreeToMerge(0),
51     fAODEventToMerge(0),
52     fMergeOffset(0)
53 {
54   // Default constructor
55   fHistStatistics[0] = fHistStatistics[1] = NULL;
56 }
57
58 //______________________________________________________________________________
59 AliAODInputHandler::AliAODInputHandler(const char* name, const char* title):
60   AliInputEventHandler(name, title),
61   fEvent(0),
62   fMCEvent(new AliMCEvent()),
63   fFriends(new TList()),
64   fAODpidUtil(0x0),
65   fMergeEvents(kFALSE),
66   fFriendsConnected(kFALSE),
67   fFileToMerge(0),
68   fTreeToMerge(0),
69   fAODEventToMerge(0),
70   fMergeOffset(0)
71 {
72     // Constructor
73   fHistStatistics[0] = fHistStatistics[1] = NULL;
74 }
75
76 //______________________________________________________________________________
77 AliAODInputHandler::~AliAODInputHandler() 
78 {
79 // Destructor
80   fFriends->Delete();
81   if (fHistStatistics[0]) {
82     delete fHistStatistics[0];
83     fHistStatistics[0] = 0;
84   }
85   if (fHistStatistics[1]) {
86     delete fHistStatistics[1];
87     fHistStatistics[1] = 0;
88   }
89   delete fAODpidUtil;
90 }
91
92 //______________________________________________________________________________
93 Bool_t AliAODInputHandler::Init(TTree* tree, Option_t* opt)
94 {
95     // Initialisation necessary for each new tree
96     fTree = tree;
97     if (!fTree) return kFALSE;
98     fTree->GetEntries();
99     ConnectFriends();
100
101     SwitchOffBranches();
102     SwitchOnBranches();
103     
104     // Get pointer to AOD event
105     if (!fEvent) fEvent = new AliAODEvent();
106     
107     fEvent->ReadFromTree(fTree);
108     
109     if (fMixingHandler) fMixingHandler->Init(tree, opt);
110     
111     return kTRUE;
112 }
113
114 //______________________________________________________________________________
115 Bool_t AliAODInputHandler::BeginEvent(Long64_t entry)
116 {
117     // Begin event
118     TClonesArray* mcParticles = (TClonesArray*) (fEvent->FindListObject("mcparticles"));
119     if (mcParticles) fMCEvent->SetParticleArray(mcParticles);
120     if (fTreeToMerge) fTreeToMerge->GetEntry(entry + fMergeOffset);
121     
122     fIsSelectedResult = fEvent->GetHeader()->GetOfflineTrigger();
123
124     if (fMixingHandler) fMixingHandler->BeginEvent(entry);
125     
126     return kTRUE;
127 }
128
129 //______________________________________________________________________________
130 Bool_t AliAODInputHandler::Notify(const char* path)
131 {
132   // Notifaction of directory change
133   if (fMixingHandler) fMixingHandler->Notify(path);
134   if (!fFriendsConnected) {
135       ConnectFriends();
136       fEvent->ReadFromTree(fTree, "reconnect");
137   }
138   fFriendsConnected = kFALSE;
139     
140   TTree *ttree = fTree->GetTree();
141   if (!ttree) ttree = fTree;
142   TString statFname(ttree->GetCurrentFile()->GetName());
143   Int_t indarchive = statFname.Index("#");
144   if (indarchive<0) {
145      statFname = gSystem->DirName(statFname);
146      statFname += "/";
147   } else {
148      statFname.Remove(indarchive+1);
149   }   
150   statFname += "EventStat_temp.root";
151   TFile *statFile = 0;
152   if (IsCheckStatistics()) statFile = TFile::Open(statFname, "READ");
153   if (statFile) {
154      TList *list = (TList*)statFile->Get("cstatsout");
155      if (list) {
156         AliVCuts *physSel = (AliVCuts*)list->At(0);
157         if (physSel) {
158            TH2F *hAll = dynamic_cast<TH2F*>(physSel->GetStatistics("ALL"));
159            TH2F *hBin0 = dynamic_cast<TH2F*>(physSel->GetStatistics("BIN0"));
160            if (fHistStatistics[0] && hAll) {
161               TList tmplist;
162               tmplist.Add(hAll);
163               fHistStatistics[0]->Merge(&tmplist);
164               tmplist.Clear();
165               tmplist.Add(hBin0);
166               if (fHistStatistics[1] && hBin0) fHistStatistics[1]->Merge(&tmplist);
167            } else {
168              if (hAll && hBin0) {
169                 fHistStatistics[0] = static_cast<TH2F*>(hAll->Clone());
170                 fHistStatistics[1] = static_cast<TH2F*>(hBin0->Clone());
171                 fHistStatistics[0]->SetDirectory(0);
172                 fHistStatistics[1]->SetDirectory(0);
173              }   
174            }   
175         }
176         delete list;
177      }
178      delete statFile;
179   }
180   return kTRUE;
181 }
182
183 //______________________________________________________________________________
184 Bool_t AliAODInputHandler::FinishEvent()
185 {
186   // Finish event
187   if (fMixingHandler) fMixingHandler->FinishEvent();
188   return kTRUE;
189 }
190
191 //______________________________________________________________________________
192 void AliAODInputHandler::AddFriend(char* filename)
193 {
194     // Add a friend tree 
195     TNamed* obj = new TNamed(filename, filename);
196     fFriends->Add(obj);
197 }
198
199 //______________________________________________________________________________
200 Option_t *AliAODInputHandler::GetDataType() const
201 {
202 // Returns handled data type.
203    return gAODDataType;
204 }
205
206 //______________________________________________________________________________
207 TObject *AliAODInputHandler::GetStatistics(Option_t *option) const
208 {
209 // Get the statistics histogram(s) from the physics selection object. This
210 // should be called during FinishTaskOutput(). Option can be empty (default
211 // statistics histogram) or BIN0.
212    TString opt(option);
213    opt.ToUpper();
214    if (opt=="BIN0") return fHistStatistics[1];
215    return fHistStatistics[0];
216 }   
217
218 void AliAODInputHandler::ConnectFriends()
219 {
220     // Connect the friend trees 
221     if (!fMergeEvents) {
222         TIter next(fFriends);
223         TNamed* obj;
224         TString aodTreeFName,aodFriendTreeFName;
225         TTree *ttree = fTree->GetTree();
226         if (!ttree) ttree = fTree;
227         aodTreeFName = ttree->GetCurrentFile()->GetName();
228         
229         while((obj = (TNamed*)next())) {
230             aodFriendTreeFName = aodTreeFName;
231             aodFriendTreeFName.ReplaceAll("AliAOD.root",obj->GetName());
232             aodFriendTreeFName.ReplaceAll("AliAODs.root",obj->GetName());
233             ttree->AddFriend("aodTree", aodFriendTreeFName.Data());
234         }
235     } else {
236         // Friends have to be merged
237         TNamed* filename = (TNamed*) (fFriends->At(0));
238         fFileToMerge = new TFile(filename->GetName());
239         if (fFileToMerge) {
240             fFileToMerge->GetObject("aodTree", fTreeToMerge);
241             if (!fAODEventToMerge) fAODEventToMerge = new AliAODEvent();
242             fAODEventToMerge->ReadFromTree(fTreeToMerge);
243         }
244     }
245     fFriendsConnected = kTRUE;
246 }
247
248 //______________________________________________________________________________
249 void AliAODInputHandler::CreatePIDResponse(Bool_t isMC/*=kFALSE*/)
250 {
251   //
252   // create the pid response object if it does not exist yet
253   //
254   if (fAODpidUtil) return;
255   fAODpidUtil=new AliAODpidUtil(isMC);
256   
257 }
258