KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVFAZIAReconDataAnalyser.cpp
Go to the documentation of this file.
1 /*
2 $Id: KVFAZIAReconDataAnalyser.cpp,v 1.4 2007/11/15 14:59:45 franklan Exp $
3 $Revision: 1.4 $
4 $Date: 2007/11/15 14:59:45 $
5 */
6 
7 //Created by KVClassFactory on Wed Apr 5 23:50:04 2006
8 //Author: Eric Bonnet
9 
10 #include "KVBase.h"
12 #include "KVFAZIADBRun.h"
13 #include "KVDataAnalysisTask.h"
14 #include "KVDataSet.h"
15 #include "TChain.h"
16 #include "TObjString.h"
17 #include "TChain.h"
18 #include "KVAvailableRunsFile.h"
19 #include "KVFAZIA.h"
20 #include "KVEventSelector.h"
21 
22 using namespace std;
23 
26 // For analysing reconstructed FAZIA data
27 //
29 
32 
34 {
35  //Default constructor
36  theTree = 0;
37  fLinkRawData = kFALSE;
38 }
39 
40 
41 
44 
45 KVFAZIAReconDataAnalyser::~KVFAZIAReconDataAnalyser()
46 {
47  //Destructor
48 }
49 
50 
51 
52 
55 
57 {
58  //Run the interactive analysis
59  if (gDataSet != GetDataSet()) GetDataSet()->cd();
60 
61  KVEventSelector es;
62  es.SetOption(GetUserClassOptions());
63  es.ParseOptions();
64  fLinkRawData = es.IsOptGiven("ReadRawData");
65 
66  //loop over runs
67  GetRunList().Begin();
68  while (!GetRunList().End()) {
69  fRunNumber = GetRunList().Next();
70  Info("SubmitTask", "treatment of run# %d", fRunNumber);
71  ProcessRun();
72  }
73 }
74 
75 
76 
85 
87 {
88  // Perform treatment of a given run
89  // Before processing each run, after opening the associated file, user's InitRun() method is called.
90  // After each run, user's EndRun() is called.
91  // For each event of each run, user's Analysis() method is called.
92  //
93  // For further customisation, the pre/post-methods are called just before and just after
94  // each of these methods (preInitRun(), postAnalysis(), etc. etc.)
95  TString fullPathToRunfile = gDataSet->GetFullPathToRunfile(GetDataType(), fRunNumber);
96  TFile* f = gDataSet->OpenRunfile<TFile>(GetDataType(), fRunNumber);
97  if (!(f && !f->IsZombie())) {
98  Error("ProcessRun", "file %s does not exist or is made zombie", fullPathToRunfile.Data());
99  return;
100  }
101 
102  theTree = (TTree*)f->Get("ReconstructedEvents");
103 
104  TFile* ffriend = 0;
105  if (fLinkRawData) {
106  fullPathToRunfile = gDataSet->GetFullPathToRunfile("raw", fRunNumber);
107  ffriend = gDataSet->OpenRunfile<TFile>("raw", fRunNumber);
108  if (!(ffriend && !ffriend->IsZombie())) {
109  Warning("ProcessRun", "file %s does not exist or is made zombie\n Reading of raw data is not possible", fullPathToRunfile.Data());
110  }
111  else {
112  theTree->AddFriend("FAZIA", ffriend);
113  }
114  }
115 
116  TString option("");
117  // Add any user-defined options
118  if (GetUserClassOptions() != "") {
119  if (option != "")
120  option += ",";
121  option += GetUserClassOptions();
122  }
123 
124  Info("SubmitTask", "Beginning TTree::Process... Option=%s", option.Data());
125  if (GetNbEventToRead()) {
126  theTree->Process(GetUserClass(), option.Data(), GetNbEventToRead());
127  }
128  else {
129  theTree->Process(GetUserClass(), option.Data());
130  }
131 
132  if (ffriend && ffriend->IsOpen())
133  ffriend->Close();
134  f->Close();
135 
136 }
137 
138 
139 // fSelector = 0;
140 //
141 // //if (theChain) delete theChain;
142 // theChain = new TChain("ReconstructedEvents");
143 // theChain->SetDirectory(0); // we handle delete
144 //
145 // //if (theFriendChain) delete theFriendChain;
146 // if (fLinkRawData) {
147 // theFriendChain = new TChain("FAZIA");
148 // theFriendChain->SetDirectory(0); // we handle delete
149 // } else {
150 // theFriendChain = 0;
151 // }
152 //
153 // fRunList.Begin();
154 // Int_t run;
155 //
156 // // open and add to TChain all required files
157 // // we force the opening of the files to avoid problems with xrootd which sometimes
158 // // seems to have a little difficulty
159 // while (!fRunList.End()) {
160 // run = fRunList.Next();
161 //
162 // //Add run file
163 // TString fullPathToRunfile = gDataSet->GetFullPathToRunfile(fDataType.Data(), run);
164 // cout << "Opening file " << fullPathToRunfile << endl;
165 // TFile* f = (TFile*)gDataSet->OpenRunfile(fDataType.Data(), run);
166 // cout << "Adding file " << fullPathToRunfile;
167 // cout << " to the TChain." << endl;
168 // theChain->Add(fullPathToRunfile);
169 // if (f && !f->IsZombie()) {
170 // // update run infos in available runs file if necessary
171 // KVAvailableRunsFile* ARF = gDataSet->GetAvailableRunsFile(fDataType.Data());
172 // if (ARF->InfosNeedUpdate(run, gSystem->BaseName(fullPathToRunfile))) {
173 // if (!((TTree*)f->Get("ReconstructedEvents"))) {
174 // Error("SubmitTask", "No tree named ReconstructedEvents is present in the current file");
175 // delete theChain;
176 // return;
177 // }
178 // TEnv* treeInfos = (TEnv*)((TTree*)f->Get("ReconstructedEvents"))->GetUserInfo()->FindObject("TEnv");
179 // if (treeInfos) {
180 // TString kvversion = treeInfos->GetValue("KVBase::GetKVVersion()", "");
181 // TString username = treeInfos->GetValue("gSystem->GetUserInfo()->fUser", "");
182 // if (kvversion != "") ARF->UpdateInfos(run, gSystem->BaseName(fullPathToRunfile), kvversion, username);
183 // } else {
184 // Info("SubmitTask", "No TEnv object associated to the tree");
185 // }
186 // }
187 // }
188 //
189 // //Add run file
190 // if (theFriendChain) {
191 // fullPathToRunfile = gDataSet->GetFullPathToRunfile("raw", run);
192 // cout << "Opening file " << fullPathToRunfile << endl;
193 // f = (TFile*)gDataSet->OpenRunfile("raw", run);
194 // cout << "Adding file " << fullPathToRunfile;
195 // cout << " to the friend TChain." << endl;
196 // theFriendChain->Add(fullPathToRunfile);
197 // }
198 // }
199 //
200 // if (theFriendChain) theChain->AddFriend("FAZIA");
201 //
202 // TotalEntriesToRead = theChain->GetEntries();
203 // TString option("");
204 // if (fDataSelector.Length()) {
205 // option.Form("DataSelector=%s", fDataSelector.Data());
206 // cout << "Data Selector : " << fDataSelector.Data() << endl;
207 // }
208 //
209 // // Add any user-defined options
210 // if (GetUserClassOptions() != "") {
211 // option += ",";
212 // option += GetUserClassOptions();
213 // }
214 //
215 // fSelector = (TSelector*)GetInstanceOfUserClass();
216 //
217 // if (!fSelector || !fSelector->InheritsFrom("TSelector")) {
218 // cout << "The selector \"" << GetUserClass() << "\" is not valid." << endl;
219 // cout << "Process aborted." << endl;
220 // } else {
221 // SafeDelete(fSelector);
222 // Info("SubmitTask", "Beginning TChain::Process...%s %s", GetUserClass(), option.Data());
223 // if (nbEventToRead) {
224 // theChain->Process(GetUserClass(), option.Data(), nbEventToRead);
225 // } else {
226 // theChain->Process(GetUserClass(), option.Data());
227 // }
228 // }
229 //
230 // if (theFriendChain) {
231 // theChain->RemoveFriend(theFriendChain);
232 // delete theFriendChain;
233 // theFriendChain = 0;
234 // }
235 // delete theChain;
236 // theChain = 0;
237 // fSelector = 0; //deleted by TChain/TTreePlayer
238 
239 
240 
241 
248 
250 {
251  // Called by currently-processed KVFAZIASelector before user's InitAnalysis() method.
252  // We build the multidetector for the current dataset in case informations on
253  // detector are needed e.g. to define histograms in InitAnalysis().
254  // Note that at this stage we are not analysing a given run, so the parameters
255  // of the array are not set (they will be set in preInitRun()).
256 
257  Info("preInitAnalysis", "Appel");
258  if (gDataSet && !gMultiDetArray) {
259  Info("preInitAnalysis", "Building of FAZIA array");
261  }
262 
263 }
264 
265 
266 
267 
272 
274 {
275  // Called by currently-processed KVFAZIASelector when a new file in the TChain is opened.
276  // We call gFazia->SetParameters for the current run.
277 
278  // Infos on currently read file/tree are printed.
279 
280  Info("preInitRun", "Appel");
281  gMultiDetArray->SetParameters(fRunNumber);
282 }
283 
284 
285 
290 
292 {
293  // Called by currently-processed KVFAZIASelector after reading a new event
294  // and just before calling user analysis
295  // Set acquisition trigger multiplicity as minimum multiplicity for acceptable event
296  gMultiDetArray->SetMinimumOKMultiplicity(fEventSelector->GetEvent());
297 }
298 
299 
300 
KVDataSet * gDataSet
Definition: KVDataSet.cpp:29
KVMultiDetArray * gMultiDetArray
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define f(i)
const Bool_t kFALSE
FileType * OpenRunfile(const Char_t *type, Int_t run)
Definition: KVDataSet.h:338
TString GetFullPathToRunfile(const Char_t *type, Int_t run) const
Definition: KVDataSet.cpp:888
General purpose analysis class for TTree containing KVEvent objects.
Bool_t IsOptGiven(const Char_t *option)
virtual void ParseOptions()
Pilot analysis of reconstructed FAZIA data.
void SubmitTask()
Run the interactive analysis.
virtual void SetMinimumOKMultiplicity(KVEvent *) const
virtual void SetParameters(UInt_t n, Bool_t physics_parameters_only=kFALSE)
static KVMultiDetArray * MakeMultiDetector(const Char_t *dataset_name, Int_t run=-1, TString classname="KVMultiDetArray")
virtual Bool_t IsOpen() const
void Close(Option_t *option="") override
virtual const char * GetName() const
R__ALWAYS_INLINE Bool_t IsZombie() const
virtual void SetOption(const char *option)
const char * Data() const
BinData::ErrorType GetDataType(const TGraph *gr, DataOptions &fitOpt)
void Info(const char *location, const char *va_(fmt),...)
void Error(const char *location, const char *va_(fmt),...)
void Warning(const char *location, const char *va_(fmt),...)
void End()