]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackList.cxx
remove warning by histogram recreation
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDTrackList.cxx
CommitLineData
38a30030 1// Author: Benjamin Hess 25/09/2008
2670605d 2
3/*************************************************************************
4 * Copyright (C) 2008, Alexandru Bercuci, Benjamin Hess. *
5 * All rights reserved. *
6 *************************************************************************/
7
16db6074 8//////////////////////////////////////////////////////////////////////////
9// //
2670605d 10// AliEveTRDTrackList //
11// //
16db6074 12// An AliEveTRDTrackList is, in principal, a TEveElementList with some //
13// sophisticated features. You can add macros to this list, which then //
14// can be applied to the list of tracks (these tracks can be added to //
15// the list in the same way as for the TEveElementList). In general, //
16// please use AddMacro(...) for this purpose. //
17// Macros that are no longer needed can be removed from the list via //
38a30030 18// RemoveSelectedMacros(...).This function takes an iterator of the //
19// list of macros that are to be removed. //
16db6074 20// be removed. An entry looks like: //
38a30030 21// The data for each macro consists of path, name, type and the command //
22// that will be used to apply the macro. This stuff is stored in a map //
23// which takes the macro name for the key and the above mentioned data //
24// in a TMacroData-object for the value. //
25// You can get the macro type via GetMacroType(...). //
2670605d 26// With ApplySTSelectionMacros(...) or ApplyProcessMacros(...) //
16db6074 27// respectively you can apply the macros to the track list via //
38a30030 28// iterators (same style like for RemoveSelectedMacros(...)(cf. above)).//
16db6074 29// Selection macros (de-)select macros according to a selection rule //
30// by setting the rnr-state of the tracks. //
31// If multiple selection macros are applied, a track is selected, if //
32// all selection macros select the track. //
33// Process macros create data or histograms, which will be stored in //
34// a temporary file. The editor of this class will access this file //
35// and draw all the stuff within it's DrawHistos() function. The file //
36// will be deleted by the destructor. //
37// //
38// Currently, the following macro types are supported: //
39// Selection macros: //
40// Bool_t YourMacro(const AliTRDtrackV1*); //
41// Bool_t YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*); //
42// //
43// Process macros: //
44// void YourMacro(const AliTRDtrackV1*, Double_t*&, Int_t&); //
45// void YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*, //
46// Double_t*&, Int_t&); //
47// TH1* YourMacro(const AliTRDtrackV1*); //
48// TH1* YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*); //
49// //
38a30030 50// The macros which take 2 tracks are applied to all track pairs //
51// (whereby BOTH tracks of the pair have to be selected by the single //
52// track selection macros and have to be unequal, otherwise they will //
53// be skipped) that have been selected by ALL correlated tracks //
54// selection macros. The selection macros with 2 tracks do NOT affect //
55// process macros that process only a single track! //
16db6074 56//////////////////////////////////////////////////////////////////////////
57
58
caaf90d2 59// Uncomment to display debugging infos
60//#define ALIEVETRDTRACKLIST_DEBUG
61
caaf90d2 62#include <TFile.h>
63#include <TFunction.h>
c413e8d4 64#include <TH1.h>
caaf90d2 65#include <TList.h>
8bdeb570 66#include <TMap.h>
caaf90d2 67#include <TObjString.h>
68#include <TROOT.h>
69#include <TSystem.h>
70#include <TTree.h>
71#include <TTreeStream.h>
db16b708 72#include <TMethodCall.h>
73
74#include <AliTRDReconstructor.h>
75
76#include <EveDet/AliEveTRDTrackList.h>
77#include <EveDet/AliEveTRDTrackList.h>
78#include <EveDet/AliEveTRDTrackListEditor.h>
79
80#include <qaRec/AliTRDrecoTask.h>
81#include <qaRec/run.h>
ecbbe371 82
2ef0687e 83ClassImp(AliEveTRDTrackList)
84
85///////////////////////////////////////////////////////////
86///////////// AliEveTRDTrackList ////////////////////////
87///////////////////////////////////////////////////////////
8bdeb570 88AliEveTRDTrackList::AliEveTRDTrackList(const Text_t* n, const Text_t* t, Bool_t doColor):
89 TEveElementList(n, t, doColor),
1e536dd4 90 fEditor(0x0),
91 fDataFromMacroList(0x0),
92 fMacroList(0x0),
93 fDataTree(0x0),
8bdeb570 94 fHistoDataSelected(0),
95 fMacroListSelected(0),
8bdeb570 96 fSelectedTab(1), // Standard tab: "Apply macros" (index 1)
1e536dd4 97 fSelectedStyle(0)
2ef0687e 98{
16db6074 99 // Creates the AliEveTRDTrackList.
100
caaf90d2 101 // Only accept childs of type AliEveTRDTrack
2ef0687e 102 SetChildClass(AliEveTRDTrack::Class());
103
e007877e 104 // Allocate memory for the lists and declare them as owners of their contents
caaf90d2 105 fDataFromMacroList = new TList();
e007877e 106 fDataFromMacroList->TCollection::SetOwner(kTRUE);
caaf90d2 107
38a30030 108 fMacroList = new TMap();
e007877e 109 // Set map to owner of it's objects to delete them, if they are removed from the map
38a30030 110 fMacroList->SetOwnerKeyValue(kTRUE, kTRUE);
8bdeb570 111
ecbbe371 112 // Set the build directory for AClic
1e536dd4 113 if(gSystem->AccessPathName(Form("%s/.trdQArec" , gSystem->Getenv("HOME")))) gSystem->Exec("mkdir $HOME/.trdQArec");
114 gSystem->SetBuildDir(Form("%s/.trdQArec", gSystem->Getenv("HOME")));
caaf90d2 115
db16b708 116 AddStandardContent();
caaf90d2 117}
118
8e27fca1 119//______________________________________________________
caaf90d2 120AliEveTRDTrackList::~AliEveTRDTrackList()
121{
16db6074 122 // Frees allocated memory (lists etc.).
123
38a30030 124 // Let the editor know that the list will be destroyed -> The editor will save the data
125 if (fEditor != 0)
caaf90d2 126 {
38a30030 127 fEditor->SaveMacroList(fMacroList);
128 fEditor = 0;
caaf90d2 129 }
38a30030 130
caaf90d2 131 if (fDataFromMacroList != 0)
132 {
c413e8d4 133 fDataFromMacroList->Delete();
caaf90d2 134 delete fDataFromMacroList;
135 fDataFromMacroList = 0;
136 }
137 if (fDataTree != 0)
138 {
139 delete fDataTree;
140 fDataTree = 0;
141 }
38a30030 142 if (fMacroList != 0)
8bdeb570 143 {
38a30030 144 fMacroList->DeleteAll();
145 delete fMacroList;
146 fMacroList = 0;
8bdeb570 147 }
ecbbe371 148 // Note: gSystem->AccessPathName(...) returns kTRUE, if the access FAILED!
149 if(!gSystem->AccessPathName(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER"))))
150 gSystem->Exec(Form("rm /tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")));
caaf90d2 151}
152
8e27fca1 153//______________________________________________________
c413e8d4 154Int_t AliEveTRDTrackList::AddMacro(const Char_t* path, const Char_t* nameC, Bool_t forceReload)
caaf90d2 155{
16db6074 156 // Checks, if the file exists and if the signature is correct.
157 // If these criteria are fullfilled, the library for this macro is built
158 // and the macro is added to the corresponding list.
159 // Supported macro types:
160 // Selection macros:
161 // Bool_t YourMacro(const AliTRDtrackV1*)
162 // Bool_t YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)
163 //
164 // Process macros:
165 // void YourMacro(const AliTRDtrackV1*, Double_t*&, Int_t&)
166 // void YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*,
167 // Double_t*&, Int_t&)
168 // TH1* YourMacro(const AliTRDtrackV1*)
38a30030 169 // TH1* YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)
caaf90d2 170
4f6473f6 171 Char_t pathname[fkMaxMacroPathNameLength];
172 memset(pathname, '\0', sizeof(Char_t) * fkMaxMacroPathNameLength);
caaf90d2 173
174 // Expand the path and create the pathname
175 Char_t* systemPath = gSystem->ExpandPathName(path);
176 sprintf(pathname, "%s/%s", systemPath, nameC);
177 delete systemPath;
178 systemPath = 0;
179
180 // Delete ".C" from filename
4f6473f6 181 Char_t name[fkMaxMacroNameLength];
182 memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength);
183
184 for (UInt_t ind = 0; ind < fkMaxMacroNameLength && ind < strlen(nameC) - 2; ind++) name[ind] = nameC[ind];
caaf90d2 185
186 // Check, if files exists
db16b708 187 FILE* fp = 0x0;
188 if((fp = fopen(pathname, "rb"))){
caaf90d2 189 fclose(fp);
db16b708 190 fp = 0x0;
191 } else return NOT_EXIST_ERROR;
38a30030 192
caaf90d2 193 // Clean up root, load the desired macro and then check the type of the macro
db16b708 194 // A.B. gROOT->Reset();
c413e8d4 195
db16b708 196 gROOT->ProcessLineSync(Form(".L %s+%c", pathname, forceReload ? '+' : ' '));
caaf90d2 197
38a30030 198 AliEveTRDTrackListMacroType type = GetMacroType(name, kFALSE);
caaf90d2 199
4f6473f6 200 // Clean up again
db16b708 201 // A.B. gROOT->Reset();
4f6473f6 202
caaf90d2 203 // Has not the correct signature!
38a30030 204 if (type == kUnknown) return SIGNATURE_ERROR;
caaf90d2 205
caaf90d2 206 // Only add macro, if it is not already in the list
db16b708 207 Int_t returnValue = WARNING;
208 if(fMacroList->GetValue(name) == 0) {
209 returnValue = AddMacroFast(path, name, type) ? SUCCESS : ERROR;
caaf90d2 210 }
caaf90d2 211 return returnValue;
212}
c413e8d4 213
214//______________________________________________________
38a30030 215Bool_t AliEveTRDTrackList::AddMacroFast(const Char_t* path, const Char_t* name, AliEveTRDTrackListMacroType type)
c413e8d4 216{
38a30030 217 // Adds a macro (path/name) to the corresponding list. No checks are performed (file exist,
218 // macro already in list/map, signature correct), no libraries are created!
219 // You can use this function only, if the macro has been added successfully before
220 // (and then maybe was removed). The function is very fast. On success kTRUE is returned, otherwise: kFALSE;
221
222 Bool_t success = kFALSE;
16db6074 223
8bdeb570 224 switch (type)
c413e8d4 225 {
e007877e 226 case kSingleTrackSelect:
227 case kCorrelTrackSelect:
e007877e 228 case kSingleTrackAnalyse:
229 case kSingleTrackHisto:
230 case kCorrelTrackAnalyse:
231 case kCorrelTrackHisto:
38a30030 232 fMacroList->Add(new TObjString(name), new TMacroData(name, path, type));
8bdeb570 233
234 // We do not know, where the element has been inserted - deselect this list
235 fMacroListSelected = 0;
38a30030 236
237 success = kTRUE;
238
239#ifdef ALIEVETRDTRACKLIST_DEBUG
240 // Successfull add will only be displayed in debug mode
241 printf("AliEveTRDTrackList::AddMacroFast: Added macro \"%s/%s\" to the corresponding list\n", path, name);
242#endif
243
8bdeb570 244 break;
c413e8d4 245
38a30030 246 default:
247 // Error will always be displayed
248 printf("AliEveTRDTrackList::AddMacroFast: ERROR: Could not add macro \"%s/%s\" to the corresponding list\n",
249 path, name);
16db6074 250
38a30030 251 success = kFALSE;
caaf90d2 252
38a30030 253 break;
c413e8d4 254 }
38a30030 255
256 return success;
caaf90d2 257}
c413e8d4 258
8e27fca1 259//______________________________________________________
db16b708 260void AliEveTRDTrackList::AddStandardContent()
caaf90d2 261{
38a30030 262 // Adds standard macros to the macro list.
16db6074 263
caaf90d2 264 // Add your standard macros here, e.g.:
8bdeb570 265 // To add a macro use:
caaf90d2 266 // AddMacro("$(ALICE_ROOT)/myFolder", "myMacroName.C");
267 // -> If the file does not exist, nothing happens. So if you want to handle this,
268 // use the return value of AddMacro (NOT_EXIST_ERROR is returned, if file does not exist)
5715955a 269 // (-> You can also check for other return values (see AddMacro(...)))
db16b708 270
271 if(gSystem->Load("libANALYSIS.so")<0) return;
272 if(gSystem->Load("libTRDqaRec.so")<0) return;
273 AliTRDrecoTask *task = 0x0;
274 TList *fPlots = 0x0;
275 for(Int_t it=0; it<NTRDTASKS; it++){
276 TClass c(fgkTRDtaskClassName[it]);
277 task = (AliTRDrecoTask*)c.New();
278 if(!(fPlots = task->GetPlotFunctors())){
279 AliWarning(Form("No Plot functors defined for task \"%s\"", fgkTRDtaskClassName[it]));
280 delete task;
281 continue;
282 }
283 if(!(task->Histos())){
284 AliWarning(Form("No Ref Histograms defined for task \"%s\"", fgkTRDtaskClassName[it]));
285 delete task;
286 continue;
287 }
288
289 // export task to CINT and add functions
290 gROOT->ProcessLine(Form("%s* %s = (%s*)0x%lx;", fgkTRDtaskClassName[it], task->GetName(), fgkTRDtaskClassName[it], (void*)task));
291 TIter iter(fPlots); TMethodCall *m = 0x0;
292 while((m = dynamic_cast<TMethodCall*>(iter()))){
293 AddMacroFast("", Form("%s->%s", task->GetName(), m->GetMethodName()), kSingleTrackHisto);
294 }
295 }
caaf90d2 296}
297
8e27fca1 298//______________________________________________________
2670605d 299Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TList* procIterator)
caaf90d2 300{
2670605d 301 // Uses the procIterator (for the selected process macros) to apply the selected macros to the data.
16db6074 302 // Returns kTRUE on success, otherwise kFALSE. If there no process macros selected, kTRUE is returned
303 // (this is no error!).
2670605d 304 // The single track process macros are applied to all selected tracks.
305 // The selIterator (for the selected selection macros) will be used to apply the correlated tracks selection
306 // macros to all track pairs (whereby BOTH tracks have to be selected, otherwise they will be skipped).
307 // All track pairs that have been selected by ALL correlated tracks selection macros will be processed by
308 // the correlated tracks process macros.
16db6074 309
ea24e1bc 310 // No process macros need to be processed
2670605d 311 if (procIterator->GetEntries() <= 0) return kTRUE;
ea24e1bc 312
313 // Clear root
db16b708 314 // A.B. gROOT->Reset();
ea24e1bc 315
316 // Clear old data and re-allocate
db16b708 317 if (fDataTree == 0x0){
318 TDirectory *cwd = gDirectory;
319 fDataTree = new TTreeSRedirector(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")));
320 cwd->cd();
321 }
322 if (!fDataTree){
323 Error("Apply process macros", Form("File \"/tmp/TRD.TrackListMacroData_%s.root\" could not be accessed properly!", gSystem->Getenv("USER")));
ea24e1bc 324 return kFALSE;
325 }
326
db16b708 327 if (fDataFromMacroList != 0) {
e007877e 328 fDataFromMacroList->Delete();
329 delete fDataFromMacroList;
330 }
ea24e1bc 331 fDataFromMacroList = new TList();
e007877e 332 fDataFromMacroList->TCollection::SetOwner(kTRUE);
ea24e1bc 333
334 fHistoDataSelected = 0;
335
8e27fca1 336
38a30030 337 TMacroData* macro = 0;
338
339 Char_t** procCmds = 0;
340 AliEveTRDTrackListMacroType* mProcType = 0;
db16b708 341 if (procIterator->GetEntries() > 0) {
38a30030 342 procCmds = new Char_t*[procIterator->GetEntries()];
343 mProcType = new AliEveTRDTrackListMacroType[procIterator->GetEntries()];
344 }
2670605d 345
38a30030 346 Char_t** selCmds = 0;
347 AliEveTRDTrackListMacroType* mSelType = 0;
db16b708 348 if (selIterator->GetEntries() > 0) {
38a30030 349 selCmds = new Char_t*[selIterator->GetEntries()];
350 mSelType = new AliEveTRDTrackListMacroType[selIterator->GetEntries()];
351 }
352
2670605d 353 Bool_t selectedByCorrSelMacro = kFALSE;
c413e8d4 354
8bdeb570 355 AliEveTRDTrackListMacroType macroType = kUnknown;
c413e8d4 356 Int_t numHistoMacros = 0;
357 TH1** histos = 0;
caaf90d2 358
e007877e 359 AliEveTRDTrack* track1 = 0;
360 AliEveTRDTrack* track2 = 0;
caaf90d2 361
2670605d 362 // Collect the commands for each process macro and add them to "data-from-list"
db16b708 363 for (Int_t i = 0; i < procIterator->GetEntries(); i++){
2670605d 364 procCmds[i] = new Char_t[(fkMaxMacroPathNameLength + fkMaxApplyCommandLength)];
365 memset(procCmds[i], '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength));
8e27fca1 366
38a30030 367 macro = (TMacroData*)fMacroList->GetValue(procIterator->At(i)->GetTitle());
e007877e 368
db16b708 369 if (!macro){
38a30030 370 Error("Apply process macros",
db16b708 371 Form("Macro list is corrupted: Macro \"%s\" is not registered!",
372 procIterator->At(i)->GetTitle()));
38a30030 373 continue;
e007877e 374 }
38a30030 375
376#ifdef ALIEVETRDTRACKLIST_DEBUG
377 printf("AliEveTRDTrackList: Checking process macro: %s\n", macro->GetName());
378#endif
379
380 // Find the type of the process macro
381 macroType = macro->GetType();
db16b708 382 if (macroType == kSingleTrackHisto || macroType == kCorrelTrackHisto){
2670605d 383 mProcType[i] = macroType;
8bdeb570 384 numHistoMacros++;
385 // Create the command
38a30030 386 sprintf(procCmds[i], macro->GetCmd());
8bdeb570 387
388 // Add to "data-from-list" -> Mark as a histo macro with the substring "(histo macro)"
38a30030 389 fDataFromMacroList->Add(new TObjString(Form("%s (histo macro)", macro->GetName())));
db16b708 390 } else if (macroType == kSingleTrackAnalyse || macroType == kCorrelTrackAnalyse) {
2670605d 391 mProcType[i] = macroType;
c413e8d4 392 // Create the command
38a30030 393 sprintf(procCmds[i], macro->GetCmd());
8bdeb570 394
395 // Add to "data-from-list"
38a30030 396 fDataFromMacroList->Add(new TObjString(macro->GetName()));
db16b708 397 } else {
8bdeb570 398 Error("Apply process macros",
db16b708 399 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a process macro!",
400 macro->GetPath(), macro->GetName()));
2670605d 401 mProcType[i] = kUnknown;
402 }
403 }
404
405 // Collect the commands for each selection macro and add them to "data-from-list"
db16b708 406 for (Int_t i = 0; i < selIterator->GetEntries(); i++){
2670605d 407 selCmds[i] = new Char_t[(fkMaxMacroPathNameLength + fkMaxApplyCommandLength)];
408 memset(selCmds[i], '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength));
409
38a30030 410 macro = (TMacroData*)fMacroList->GetValue(selIterator->At(i)->GetTitle());
411
db16b708 412 if (!macro){
38a30030 413 Error("Apply process macros",
db16b708 414 Form("Macro list is corrupted: Macro \"%s\" is not registered!",
415 selIterator->At(i)->GetTitle()));
38a30030 416 continue;
2670605d 417 }
38a30030 418
419#ifdef ALIEVETRDTRACKLIST_DEBUG
420 printf("AliEveTRDTrackList: Checking selection macro: %s\n", macro->GetName());
421#endif
2670605d 422
423 // Find the type of the process macro
38a30030 424 macroType = macro->GetType();
425
2670605d 426 // Single track select macro
db16b708 427 if (macroType == kSingleTrackSelect) {
2670605d 428 // Has already been processed by ApplySTSelectionMacros(...)
429 mSelType[i] = macroType;
430 }
431 // Correlated tracks select macro
db16b708 432 else if (macroType == kCorrelTrackSelect) {
2670605d 433 mSelType[i] = macroType;
434
435 // Create the command
38a30030 436 sprintf(selCmds[i], macro->GetCmd());
db16b708 437 } else {
2670605d 438 Error("Apply process macros",
db16b708 439 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a selection macro!",
440 macro->GetPath(), macro->GetName()));
38a30030 441 mSelType[i] = kUnknown;
c413e8d4 442 }
8e27fca1 443 }
c413e8d4 444
445 // Allocate memory for the histograms
446 if (numHistoMacros > 0) histos = new TH1*[numHistoMacros];
db16b708 447 for (Int_t i = 0; i < numHistoMacros; i++) histos[i] = 0x0;
38a30030 448
caaf90d2 449
db16b708 450 //////////////////////////////////
451 // WALK THROUGH THE LIST OF TRACKS
452 //////////////////////////////////
453 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter){
454 if(!(track1 = dynamic_cast<AliEveTRDTrack*>(*iter))) continue;
455
caaf90d2 456 // Skip tracks that have not been selected
e007877e 457 if (!track1->GetRnrState()) continue;
38a30030 458
caaf90d2 459 // Cast to AliTRDtrackV1
db16b708 460 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)0x%xl;", track1));
e007877e 461 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
caaf90d2 462
463 // Collect data for each macro
db16b708 464 for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries(); i++){
e007877e 465 // Single track histo
db16b708 466 if (mProcType[i] == kSingleTrackHisto){
467 histos[histoIndex++] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
468 // Correlated tracks histo
469 } else if (mProcType[i] == kCorrelTrackHisto) {
e007877e 470 // Loop over all pairs behind the current one - together with the other loop this will be a loop
471 // over all pairs. We have a pair of tracks, if and only if both tracks of the pair are selected (Rnr-state)
472 // and are not equal.
2670605d 473 // The correlated tracks process macro will applied to all pairs that will be additionally selected by
474 // all correlated tracks selection macros.
e007877e 475 TEveElement::List_i iter2 = iter;
476 iter2++;
477 for ( ; iter2 != this->EndChildren(); ++iter2)
478 {
db16b708 479 if(!(track2 = dynamic_cast<AliEveTRDTrack*>(*iter2))) continue;
e007877e 480
e007877e 481 // Skip tracks that have not been selected
482 if (!track2->GetRnrState()) continue;
483
e007877e 484 // Cast to AliTRDtrackV1
db16b708 485 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)0x%xl;", track2));
e007877e 486 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_2 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
487
2670605d 488 // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
489 selectedByCorrSelMacro = kTRUE;
db16b708 490 for (Int_t j = 0; j < selIterator->GetEntries(); j++){
491 if (mSelType[j] == kCorrelTrackSelect){
2670605d 492 selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
493 if (!selectedByCorrSelMacro) break;
494 }
495 }
496
497 // If the pair has not been selected by the correlated tracks selection macros, skip it!
498 if (!selectedByCorrSelMacro) continue;
499
db16b708 500 histos[histoIndex] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
e007877e 501 }
502 histoIndex++;
503 }
504 // Single track analyse
db16b708 505 else if (mProcType[i] == kSingleTrackAnalyse) {
c413e8d4 506 // Create data pointers in CINT, execute the macro and get the data
507 gROOT->ProcessLineSync("Double_t* results = 0;");
508 gROOT->ProcessLineSync("Int_t n = 0;");
2670605d 509 gROOT->ProcessLineSync(procCmds[i]);
c413e8d4 510 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
511 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
512
db16b708 513 if (results == 0) {
2670605d 514 Error("Apply macros", Form("Error reading data from macro \"%s\"", procIterator->At(i)->GetTitle()));
c413e8d4 515 continue;
516 }
db16b708 517 for (Int_t resInd = 0; resInd < nResults; resInd++){
c413e8d4 518 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
519 }
caaf90d2 520
c413e8d4 521 delete results;
522 results = 0;
523 }
e007877e 524 // Correlated tracks analyse
db16b708 525 else if (mProcType[i] == kCorrelTrackAnalyse){
e007877e 526 // Loop over all pairs behind the current one - together with the other loop this will be a loop
527 // over all pairs. We have a pair of tracks, if and only if both tracks of the pair are selected (Rnr-state)
528 // and are not equal.
2670605d 529 // The correlated tracks process macro will applied to all pairs that will be additionally selected by
530 // all correlated tracks selection macros.
e007877e 531 TEveElement::List_i iter2 = iter;
532 iter2++;
38a30030 533
db16b708 534 for ( ; iter2 != this->EndChildren(); ++iter2) {
535 if(!(track2 = dynamic_cast<AliEveTRDTrack*>(*iter2))) continue;
38a30030 536
e007877e 537 // Skip tracks that have not been selected
538 if (!track2->GetRnrState()) continue;
38a30030 539
e007877e 540 // Cast to AliTRDtrackV1
db16b708 541 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)0x%xl;", track2));
e007877e 542 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_2 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
543
2670605d 544 // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
545 selectedByCorrSelMacro = kTRUE;
db16b708 546 for (Int_t j = 0; j < selIterator->GetEntries(); j++) {
547 if (mSelType[j] == kCorrelTrackSelect) {
2670605d 548 selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
549 if (!selectedByCorrSelMacro) break;
550 }
551 }
552
553 // If the pair has not been selected by the correlated tracks selection macros, skip it!
554 if (!selectedByCorrSelMacro) continue;
555
e007877e 556 // Create data pointers in CINT, execute the macro and get the data
557 gROOT->ProcessLineSync("Double_t* results = 0;");
558 gROOT->ProcessLineSync("Int_t n = 0;");
2670605d 559 gROOT->ProcessLineSync(procCmds[i]);
e007877e 560 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
561 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
38a30030 562
db16b708 563 if (results == 0) {
2670605d 564 Error("Apply macros", Form("Error reading data from macro \"%s\"", procIterator->At(i)->GetTitle()));
e007877e 565 continue;
566 }
db16b708 567 for (Int_t resInd = 0; resInd < nResults; resInd++) {
e007877e 568 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
569 }
570
571 delete results;
572 results = 0;
573 }
574 }
caaf90d2 575 }
576 }
caaf90d2 577
db16b708 578 for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries() && histoIndex < numHistoMacros; i++) {
579 if (mProcType[i] == kSingleTrackHisto || mProcType[i] == kCorrelTrackHisto) {
5715955a 580 // Might be empty (e.g. no tracks have been selected)!
db16b708 581 if (histos[histoIndex]) {
5715955a 582 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << histos[histoIndex] << (Char_t*)"\n";
583 }
584 histoIndex++;
585 }
c413e8d4 586 }
587
588 if (fDataTree != 0) delete fDataTree;
caaf90d2 589 fDataTree = 0;
590
2670605d 591 if (procCmds != 0) delete [] procCmds;
38a30030 592 procCmds = 0;
2670605d 593 if (mProcType != 0) delete mProcType;
594 mProcType = 0;
595
596 if (selCmds != 0) delete [] selCmds;
38a30030 597 selCmds = 0;
2670605d 598 if (mSelType != 0) delete mSelType;
599 mSelType = 0;
c413e8d4 600
601 if (histos != 0) delete [] histos;
602 histos = 0;
8e27fca1 603
caaf90d2 604 // Clear root
db16b708 605 // A.B. gROOT->Reset();
caaf90d2 606
4f6473f6 607 // If there is data, select the first data set
2670605d 608 if (procIterator->GetEntries() > 0) SETBIT(fHistoDataSelected, 0);
4f6473f6 609
e007877e 610 // Now the data is stored in "/tmp/TRD.TrackListMacroData_$USER.root"
caaf90d2 611 // The editor will access this file to display the data
ea24e1bc 612 return kTRUE;
caaf90d2 613}
614
8e27fca1 615//______________________________________________________
2670605d 616void AliEveTRDTrackList::ApplySTSelectionMacros(const TList* iterator)
caaf90d2 617{
16db6074 618 // Uses the iterator (for the selected selection macros) to apply the selected macros to the data.
619 // The rnr-states of the tracks are set according to the result of the macro calls (kTRUE, if all
620 // macros return kTRUE for this track, otherwise: kFALSE).
2670605d 621 // "ST" stands for "single track". This means that only single track selection macros are applied.
622 // Correlated tracks selection macros will be used inside the call of ApplyProcessMacros(...)!
16db6074 623
38a30030 624 TMacroData* macro = 0;
e007877e 625 AliEveTRDTrackListMacroType macroType = kUnknown;
626 AliEveTRDTrack* track1 = 0;
caaf90d2 627 Bool_t selectedByMacro = kFALSE;
628
629 // Clear root
db16b708 630 // A.B. gROOT->Reset();
caaf90d2 631
4f6473f6 632 // Select all tracks at first. A track is then deselect, if at least one selection macro
633 // returns kFALSE for this track
e007877e 634 // Enable all tracks (Note: EnableListElements(..) will call "ElementChanged", which will cause unforeseen behavior!)
db16b708 635 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter) ((TEveElement*)(*iter))->SetRnrState(kTRUE);
4f6473f6 636 SetRnrState(kTRUE);
637
db16b708 638 for (Int_t i = 0; i < iterator->GetEntries(); i++){
38a30030 639 macro = (TMacroData*)fMacroList->GetValue(iterator->At(i)->GetTitle());
4f6473f6 640
db16b708 641 if (!macro){
38a30030 642 Error("Apply selection macros",
643 Form("Macro list is corrupted: Macro \"%s\" is not registered!", iterator->At(i)->GetTitle()));
644 continue;
645 }
caaf90d2 646
647#ifdef ALIEVETRDTRACKLIST_DEBUG
38a30030 648 printf("AliEveTRDTrackList: Applying selection macro: %s\n", macro->GetName());
caaf90d2 649#endif
caaf90d2 650
e007877e 651 // Determine macro type
38a30030 652 macroType = macro->GetType();
caaf90d2 653
e007877e 654 // Single track select macro
db16b708 655 if (macroType == kSingleTrackSelect){
e007877e 656 // Walk through the list of tracks
657 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
658 {
659 track1 = dynamic_cast<AliEveTRDTrack*>(*iter);
660
661 if (!track1) continue;
662
663 // If the track has already been deselected, nothing is to do here
664 if (!track1->GetRnrState()) continue;
665
e007877e 666 // Cast to AliTRDtrackV1
db16b708 667 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)0x%xl;", track1));
38a30030 668 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
669 selectedByMacro = (Bool_t)gROOT->ProcessLineSync(macro->GetCmd());
e007877e 670 track1->SetRnrState(selectedByMacro && track1->GetRnrState());
671 }
672 }
673 // Correlated tracks select macro
db16b708 674 else if (macroType == kCorrelTrackSelect){
2670605d 675 // Will be processed in ApplyProcessMacros(...)
676 continue;
db16b708 677 } else {
e007877e 678 Error("Apply selection macros",
db16b708 679 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a selection macro!",
680 macro->GetPath(), macro->GetName()));
e007877e 681 }
caaf90d2 682 }
683
684 // Clear root
db16b708 685 // A.B. gROOT->Reset();
caaf90d2 686}
687
8bdeb570 688//______________________________________________________
38a30030 689AliEveTRDTrackList::AliEveTRDTrackListMacroType AliEveTRDTrackList::GetMacroType(const Char_t* name, Bool_t UseList) const
8bdeb570 690{
38a30030 691 // Returns the type of the corresponding macro.
16db6074 692 // If "UseList" is kTRUE, the type will be looked up in the internal list (very fast). But if this list
693 // does not exist, you have to use kFALSE for this parameter. Then the type will be determined by the
694 // prototype! NOTE: It is assumed that the macro has been compiled! If not, the return value is not
695 // predictable, but normally will be kUnknown.
38a30030 696 // Note: AddMacro(Fast) will update the internal list and RemoveMacros respectively.
16db6074 697
8bdeb570 698 AliEveTRDTrackListMacroType type = kUnknown;
699
38a30030 700 // Re-do the check of the macro type
db16b708 701 if (!UseList){
e007877e 702 // Single track select macro or single track histo macro?
8bdeb570 703 TFunction* f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*", kTRUE);
704 if (f != 0x0)
705 {
706 // Some additional check (is the parameter EXACTLY of the desired type?)
707 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0)
708 {
e007877e 709 // Single track select macro?
8bdeb570 710 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
711 {
e007877e 712 type = kSingleTrackSelect;
8bdeb570 713 }
e007877e 714 // single track histo macro?
8bdeb570 715 else if (!strcmp(f->GetReturnTypeName(), "TH1*"))
716 {
e007877e 717 type = kSingleTrackHisto;
8bdeb570 718 }
719 }
720 }
e007877e 721 // Single track analyse macro?
8bdeb570 722 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE))
723 != 0x0)
724 {
725 if (!strcmp(f->GetReturnTypeName(), "void"))
726 {
727 // Some additional check (are the parameters EXACTLY of the desired type?)
728 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
729 strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 &&
730 strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0)
731 {
e007877e 732 type = kSingleTrackAnalyse;
733 }
734 }
735 }
736 // Correlated tracks select macro or correlated tracks histo macro?
737 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, const AliTRDtrackV1*", kTRUE))
738 != 0x0)
739 {
740 // Some additional check (is the parameter EXACTLY of the desired type?)
741 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
742 strstr(f->GetMangledName(), "cOconstsPAliTRDtrackV1mUsP") != 0x0)
743 {
744 // Single track select macro?
745 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
746 {
747 type = kCorrelTrackSelect;
748 }
749 // single track histo macro?
750 else if (!strcmp(f->GetReturnTypeName(), "TH1*"))
751 {
752 type = kCorrelTrackHisto;
753 }
754 }
755 }
756 // Correlated tracks analyse macro?
757 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name,
758 "const AliTRDtrackV1*, const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE))
759 != 0x0)
760 {
761 if (!strcmp(f->GetReturnTypeName(), "void"))
762 {
763 // Some additional check (is the parameter EXACTLY of the desired type?)
764 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
765 strstr(f->GetMangledName(), "cOconstsPAliTRDtrackV1mUsP") != 0x0 &&
766 strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 &&
767 strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0)
768 {
769 type = kCorrelTrackAnalyse;
8bdeb570 770 }
771 }
772 }
773 }
774 // Use list to look up the macro type
775 else
776 {
38a30030 777 TMacroData* macro = 0;
778 macro = (TMacroData*)fMacroList->GetValue(name);
779 if (macro == 0) return kUnknown;
8bdeb570 780
38a30030 781 type = macro->GetType();
8bdeb570 782 switch (type)
783 {
e007877e 784 case kSingleTrackSelect:
785 case kSingleTrackAnalyse:
786 case kSingleTrackHisto:
787 case kCorrelTrackSelect:
788 case kCorrelTrackAnalyse:
789 case kCorrelTrackHisto:
8bdeb570 790 break;
791 default:
792 type = kUnknown;
793 break;
794 }
795 }
796
797 return type;
798}
799
8e27fca1 800//______________________________________________________
38a30030 801void AliEveTRDTrackList::RemoveSelectedMacros(const TList* iterator)
caaf90d2 802{
38a30030 803 // Uses the iterator (for the selected macros) to remove the selected macros from
16db6074 804 // the corresponding list.
805
38a30030 806 TObject* key = 0;
807 TPair* entry = 0;
caaf90d2 808 for (Int_t i = 0; i < iterator->GetEntries(); i++)
809 {
38a30030 810 entry = (TPair*)fMacroList->FindObject(iterator->At(i)->GetTitle());
8bdeb570 811
38a30030 812 if (entry == 0)
813 {
814 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Macro \"%s\" not found in list!",
815 iterator->At(i)->GetTitle()));
816 continue;
817 }
818 key = entry->Key();
caaf90d2 819
38a30030 820 if (key == 0)
821 {
822 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Key for macro \"%s\" not found in list!",
823 iterator->At(i)->GetTitle()));
824 continue;
825 }
826
827 // Key and value will be deleted, too, since fMacroList is the owner of them
828 Bool_t rem = fMacroList->DeleteEntry(key);
8bdeb570 829
38a30030 830 if (rem)
831 {
832#ifdef ALIEVETRDTRACKLIST_DEBUG
833 printf("AliEveTRDTrackList::RemoveSelectedMacros(): Removed macro: %s\n", iterator->At(i)->GetTitle());
834#endif
835 }
836 else
837 {
838 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Macro \"%s\" could not be removed from the list!",
839 iterator->At(i)->GetTitle()));
840 }
caaf90d2 841 }
2ef0687e 842}
4f6473f6 843
ecbbe371 844//______________________________________________________
845void AliEveTRDTrackList::UpdateTrackStyle(AliEveTRDTrack::AliEveTRDTrackState s, UChar_t ss)
846{
16db6074 847 // Updates the track style and sets this style for each track.
848
8bdeb570 849 switch(s)
850 {
e007877e 851 case AliEveTRDTrack::kSource:
852 SETBIT(fSelectedStyle, AliEveTRDTrack::kSource);
853 break;
854 case AliEveTRDTrack::kPID:
855 CLRBIT(fSelectedStyle, AliEveTRDTrack::kSource);
856 switch(ss)
857 {
858 case AliTRDReconstructor::kLQPID:
859 CLRBIT(fSelectedStyle, AliEveTRDTrack::kPID);
860 break;
861 case AliTRDReconstructor::kNNPID:
862 SETBIT(fSelectedStyle, AliEveTRDTrack::kPID);
863 break;
864 }
865 break;
866 case AliEveTRDTrack::kTrackCosmics:
867 SETBIT(fSelectedStyle, AliEveTRDTrack::kTrackCosmics);
868 break;
869 case AliEveTRDTrack::kTrackModel:
870 CLRBIT(fSelectedStyle, AliEveTRDTrack::kTrackCosmics);
871 switch(ss)
872 {
873 case AliEveTRDTrack::kRieman:
874 CLRBIT(fSelectedStyle, AliEveTRDTrack::kTrackModel);
875 break;
876 case AliEveTRDTrack::kKalman:
12896fe5 877 //AliWarning("Kalman fit under testing for the moment.");
878 SETBIT(fSelectedStyle, AliEveTRDTrack::kTrackModel);
e007877e 879 break;
880 }
881 break;
ecbbe371 882 }
883
884
ecbbe371 885 // Walk through the list of tracks
886 AliEveTRDTrack* track = 0x0;
8bdeb570 887 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
888 {
ecbbe371 889 if (!(track = dynamic_cast<AliEveTRDTrack*>(*iter))) continue;
890
891 track->SetStatus(fSelectedStyle);
892 }
893}