]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/dielectron/AliDielectronDebugTree.cxx
Major update of the framework
[u/mrichter/AliRoot.git] / PWG3 / dielectron / AliDielectronDebugTree.cxx
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 /*
21 register variables from the variable manager. The output will be written
22 to a tree
23
24 NOTE: Please use with extream care! Only for debugging and test purposes!!!
25
26 */
27 //                                                                       //
28 ///////////////////////////////////////////////////////////////////////////
29
30 #include <TFile.h>
31 #include <TTree.h>
32 #include <TTreeStream.h>
33 #include <TObjString.h>
34 #include <TString.h>
35
36 #include <AliAnalysisManager.h>
37 #include <AliESDInputHandler.h>
38 #include <AliESDEvent.h>
39 #include <AliVTrack.h>
40
41 #include "AliDielectron.h"
42 #include "AliDielectronMC.h"
43 #include "AliDielectronPair.h"
44
45 #include "AliDielectronDebugTree.h"
46
47 ClassImp(AliDielectronDebugTree)
48
49 AliDielectronDebugTree::AliDielectronDebugTree() :
50   TNamed(),
51   fFileName("jpsi_debug.root"),
52   fNVars(0),
53   fNVarsLeg(0),
54   fStreamer(0x0),
55   fDielectron(0x0)
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 //______________________________________________
67 AliDielectronDebugTree::AliDielectronDebugTree(const char* name, const char* title) :
68   TNamed(name, title),
69   fFileName("jpsi_debug.root"),
70   fNVars(0),
71   fNVarsLeg(0),
72   fStreamer(0x0),
73   fDielectron(0x0)
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 //______________________________________________
85 AliDielectronDebugTree::~AliDielectronDebugTree()
86 {
87   //
88   // Default Destructor
89   //
90   if (fStreamer){
91     fStreamer->GetFile()->Write();
92     delete fStreamer;
93   }
94 }
95
96 //______________________________________________
97 void 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();
108   if (!man) return;
109   if (man->GetAnalysisType()!=AliAnalysisManager::kLocalAnalysis) return;
110   
111   //Get File and event information
112   TObjString fileName;
113   Int_t eventInFile=-1;
114   Int_t runNumber=-1;
115   
116   TTree *t=man->GetTree();
117   if (t) {
118     TFile *file=t->GetCurrentFile();
119     if (file) fileName.SetString(file->GetName());
120   }
121
122   AliESDInputHandler *han=dynamic_cast<AliESDInputHandler*>(man->GetInputEventHandler());
123   if (han){
124     AliESDEvent *ev=dynamic_cast<AliESDEvent*>(han->GetEvent());
125     eventInFile=ev->GetEventNumberInFile();
126     runNumber=ev->GetRunNumber();
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"
134     << "File.="       << &fileName
135     << "EventInFile=" << eventInFile
136     << "Run="         << runNumber
137     << "Leg1_ID="     << id1
138     << "Leg2_ID="     << id2;
139   
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   }
149   
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 //______________________________________________
189 void AliDielectronDebugTree::DeleteStreamer()
190 {
191   //
192   // delete the streamer
193   //
194   if (!fStreamer) return;
195   delete fStreamer;
196   fStreamer=0x0;
197
198 }
199
200 //______________________________________________
201 void AliDielectronDebugTree::WriteTree()
202 {
203   //
204   // Write file
205   //
206   if (!fStreamer) return;
207   fStreamer->GetFile()->Write();
208 }