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