]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/dielectron/AliDielectronDebugTree.cxx
Added protection (Francesco)
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronDebugTree.cxx
CommitLineData
572b0139 1/*************************************************************************
2* Copyright(c) 1998-2009, 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// Dielectron DebugTree //
18// //
19// //
20/*
21register variables from the variable manager. The output will be written
22to a tree
23
24NOTE: Please use with extream care! Only for debugging and test purposes!!!
25
26*/
27// //
28///////////////////////////////////////////////////////////////////////////
29
30#include <TFile.h>
5d9f368a 31#include <TTree.h>
572b0139 32#include <TTreeStream.h>
5d9f368a 33#include <TObjString.h>
572b0139 34#include <TString.h>
35
36#include <AliAnalysisManager.h>
5d9f368a 37#include <AliESDInputHandler.h>
38#include <AliESDEvent.h>
39#include <AliVTrack.h>
572b0139 40
8df8e382 41#include "AliDielectron.h"
42#include "AliDielectronMC.h"
572b0139 43#include "AliDielectronPair.h"
44
45#include "AliDielectronDebugTree.h"
46
47ClassImp(AliDielectronDebugTree)
48
49AliDielectronDebugTree::AliDielectronDebugTree() :
50 TNamed(),
51 fFileName("jpsi_debug.root"),
52 fNVars(0),
53 fNVarsLeg(0),
8df8e382 54 fStreamer(0x0),
55 fDielectron(0x0)
572b0139 56{
57 //
58 // Default Constructor
59 //
60 for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues;++i){
61 fVariables[i]=0;
62 fVariablesLeg[i]=0;
63 }
64}
65
66//______________________________________________
67AliDielectronDebugTree::AliDielectronDebugTree(const char* name, const char* title) :
68 TNamed(name, title),
69 fFileName("jpsi_debug.root"),
70 fNVars(0),
71 fNVarsLeg(0),
8df8e382 72 fStreamer(0x0),
73 fDielectron(0x0)
572b0139 74{
75 //
76 // Named Constructor
77 //
78 for (Int_t i=0; i<AliDielectronVarManager::kNMaxValues;++i){
79 fVariables[i]=0;
80 fVariablesLeg[i]=0;
81 }
82}
83
84//______________________________________________
85AliDielectronDebugTree::~AliDielectronDebugTree()
86{
87 //
88 // Default Destructor
89 //
90 if (fStreamer){
91 fStreamer->GetFile()->Write();
92 delete fStreamer;
93 }
94}
95
96//______________________________________________
97void AliDielectronDebugTree::Fill(AliDielectronPair *pair)
98{
99 //
100 // Fill configured variables to the tree
101 //
102
103 //is there anything to fill
104 if (fNVars==0&&fNVarsLeg==0) return;
105
106 //only in local mode!!!
107 AliAnalysisManager *man=AliAnalysisManager::GetAnalysisManager();
61d106d3 108 if (!man) return;
109 if (man->GetAnalysisType()!=AliAnalysisManager::kLocalAnalysis) return;
572b0139 110
5d9f368a 111 //Get File and event information
0e2f178c 112 TObjString fileName;
5d9f368a 113 Int_t eventInFile=-1;
8df8e382 114 Int_t runNumber=-1;
5d9f368a 115
116 TTree *t=man->GetTree();
117 if (t) {
118 TFile *file=t->GetCurrentFile();
0e2f178c 119 if (file) fileName.SetString(file->GetName());
5d9f368a 120 }
572b0139 121
5d9f368a 122 AliESDInputHandler *han=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler());
123 if (han){
124 AliESDEvent *ev=dynamic_cast<AliESDEvent*>(han->GetEvent());
125 eventInFile=ev->GetEventNumberInFile();
8df8e382 126 runNumber=ev->GetRunNumber();
5d9f368a 127 }
128
129 if (!fStreamer) fStreamer=new TTreeSRedirector(fFileName.Data());
130 Int_t id1=static_cast<AliVTrack*>(pair->GetFirstDaughter())->GetID();
131 Int_t id2=static_cast<AliVTrack*>(pair->GetSecondDaughter())->GetID();
132 //Fill Event information
133 (*fStreamer) << "Pair"
0e2f178c 134 << "File.=" << &fileName
5d9f368a 135 << "EventInFile=" << eventInFile
8df8e382 136 << "Run=" << runNumber
5d9f368a 137 << "Leg1_ID=" << id1
138 << "Leg2_ID=" << id2;
139
8df8e382 140 //Fill MC information
141 Bool_t hasMC=AliDielectronMC::Instance()->HasMC();
142 if (hasMC){
143 Int_t pdg=443;
144 if (fDielectron) pdg=fDielectron->GetMotherPdg();
145 Bool_t isMotherMC = AliDielectronMC::Instance()->IsMotherPdg(pair,pdg);
146 (*fStreamer) << "Pair"
147 << "mcTruth=" << isMotherMC;
148 }
5d9f368a 149
572b0139 150 Int_t var=0;
151 Double_t values[AliDielectronVarManager::kNMaxValues];
152 Double_t valuesLeg1[AliDielectronVarManager::kNMaxValues];
153 Double_t valuesLeg2[AliDielectronVarManager::kNMaxValues];
154// fill pair values
155 if (fNVars>0){
156 AliDielectronVarManager::Fill(pair,values);
157
158 for (Int_t i=0; i<fNVars; ++i){
159 var=fVariables[i];
160 (*fStreamer) << "Pair"
161 << Form("%s=",AliDielectronVarManager::GetValueName(var))
162 << values[var];
163 }
164 }
165
166 if (fNVarsLeg>0){
167 //leg1
168 AliDielectronVarManager::Fill(pair->GetFirstDaughter(),valuesLeg1);
169 //leg2
170 AliDielectronVarManager::Fill(pair->GetSecondDaughter(),valuesLeg2);
171
172 for (Int_t i=0; i<fNVarsLeg; ++i){
173 var=fVariablesLeg[i];
174 (*fStreamer) << "Pair"
175 << Form("Leg1_%s=",AliDielectronVarManager::GetValueName(var))
176 << valuesLeg1[var]
177 << Form("Leg2_%s=",AliDielectronVarManager::GetValueName(var))
178 << valuesLeg2[var];
179 }
180
181 }
182
183 (*fStreamer) << "Pair" << "\n";
184
185
186}
187
188//______________________________________________
189void AliDielectronDebugTree::DeleteStreamer()
190{
191 //
192 // delete the streamer
193 //
194 if (!fStreamer) return;
195 delete fStreamer;
196 fStreamer=0x0;
197
198}
199
200//______________________________________________
201void AliDielectronDebugTree::WriteTree()
202{
203 //
204 // Write file
205 //
206 if (!fStreamer) return;
207 fStreamer->GetFile()->Write();
208}