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