1 // Author: Benjamin Hess 23/09/2008
3 /*************************************************************************
4 * Copyright (C) 2008, Alexandru Bercuci, Benjamin Hess. *
5 * All rights reserved. *
6 *************************************************************************/
8 //////////////////////////////////////////////////////////////////////////
10 // AliEveTRDTrackList //
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 //
18 // RemoveSelectionMacros(...) or RemoveProcessMacros(...) respectively. //
19 // This function takes an iterator of the list of entries that are to //
20 // be removed. An entry looks like: //
21 // "MacroName.C (Path: MacroPath)". This is the way, the information //
22 // about a macro is stored in the AliEveTRDTrackList. If you have path //
23 // and name of a macro, use MakeMacroEntry(...) to get the corresponding//
24 // entry. The type of the macros is stored in a map. You can get the //
25 // macro type via GetMacroType(...). //
26 // With ApplySTSelectionMacros(...) or ApplyProcessMacros(...) //
27 // respectively you can apply the macros to the track list via //
28 // iterators (same style like for RemoveProcessMacros(...) (cf. above)).//
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. //
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*); //
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*); //
50 // The macros which take 2 tracks are applied to all pairs //
51 // fullfilling the selection criteria. //
52 //////////////////////////////////////////////////////////////////////////
55 // Uncomment to display debugging infos
56 //#define ALIEVETRDTRACKLIST_DEBUG
58 #include "AliEveTRDTrackList.h"
60 #include <AliTRDReconstructor.h>
62 #include <TFunction.h>
66 #include <TObjString.h>
70 #include <TTreeStream.h>
72 ClassImp(AliEveTRDTrackList)
74 ///////////////////////////////////////////////////////////
75 ///////////// AliEveTRDTrackList ////////////////////////
76 ///////////////////////////////////////////////////////////
77 AliEveTRDTrackList::AliEveTRDTrackList(const Text_t* n, const Text_t* t, Bool_t doColor):
78 TEveElementList(n, t, doColor),
81 fDataFromMacroList(0),
84 fHistoDataSelected(0),
85 fMacroListSelected(0),
86 fMacroSelListSelected(0),
87 fSelectedTab(1), // Standard tab: "Apply macros" (index 1)
90 // Creates the AliEveTRDTrackList.
92 // Only accept childs of type AliEveTRDTrack
93 SetChildClass(AliEveTRDTrack::Class());
95 // Allocate memory for the lists and declare them as owners of their contents
96 fMacroList = new TList();
97 fMacroList->TCollection::SetOwner(kTRUE);
98 fMacroSelList = new TList();
99 fMacroSelList->TCollection::SetOwner(kTRUE);
100 fDataFromMacroList = new TList();
101 fDataFromMacroList->TCollection::SetOwner(kTRUE);
103 fMacroTypes = new TMap();
104 // Set map to owner of it's objects to delete them, if they are removed from the map
105 fMacroTypes->SetOwnerKeyValue(kTRUE, kTRUE);
107 // Set the build directory for AClic
108 gSystem->SetBuildDir("$HOME/.trdQArec");
113 //______________________________________________________
114 AliEveTRDTrackList::~AliEveTRDTrackList()
116 // Frees allocated memory (lists etc.).
120 fMacroList->Delete();
124 if (fMacroSelList != 0)
126 fMacroSelList->Delete();
127 delete fMacroSelList;
130 if (fDataFromMacroList != 0)
132 fDataFromMacroList->Delete();
133 delete fDataFromMacroList;
134 fDataFromMacroList = 0;
141 if (fMacroTypes != 0)
143 fMacroTypes->DeleteAll();
147 // Note: gSystem->AccessPathName(...) returns kTRUE, if the access FAILED!
148 if(!gSystem->AccessPathName(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER"))))
149 gSystem->Exec(Form("rm /tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")));
152 //______________________________________________________
153 Int_t AliEveTRDTrackList::AddMacro(const Char_t* path, const Char_t* nameC, Bool_t forceReload)
155 // Checks, if the file exists and if the signature is correct.
156 // If these criteria are fullfilled, the library for this macro is built
157 // and the macro is added to the corresponding list.
158 // Supported macro types:
160 // Bool_t YourMacro(const AliTRDtrackV1*)
161 // Bool_t YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)
164 // void YourMacro(const AliTRDtrackV1*, Double_t*&, Int_t&)
165 // void YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*,
166 // Double_t*&, Int_t&)
167 // TH1* YourMacro(const AliTRDtrackV1*)
168 // TH1* YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*)
170 // The macros which take 2 tracks are applied to all pairs
171 // fullfilling the selection criteria.
173 Char_t* entryName = MakeMacroEntry(path, nameC);
175 Char_t pathname[fkMaxMacroPathNameLength];
176 memset(pathname, '\0', sizeof(Char_t) * fkMaxMacroPathNameLength);
178 // Expand the path and create the pathname
179 Char_t* systemPath = gSystem->ExpandPathName(path);
180 sprintf(pathname, "%s/%s", systemPath, nameC);
184 // Delete ".C" from filename
185 Char_t name[fkMaxMacroNameLength];
186 memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength);
188 for (UInt_t ind = 0; ind < fkMaxMacroNameLength && ind < strlen(nameC) - 2; ind++) name[ind] = nameC[ind];
190 // Check, if files exists
193 fp = fopen(pathname, "rb");
201 if (entryName != 0) delete entryName;
204 return NOT_EXIST_ERROR;
207 // Clean up root, load the desired macro and then check the type of the macro
210 if (forceReload) gROOT->ProcessLineSync(Form(".L %s++", pathname));
211 else gROOT->ProcessLineSync(Form(".L %s+", pathname));
213 AliEveTRDTrackListMacroType type = GetMacroType(entryName, kFALSE);
218 // Has not the correct signature!
219 if (type == kUnknown)
221 if (entryName != 0) delete entryName;
223 return SIGNATURE_ERROR;
226 Int_t returnValue = WARNING;
228 // Only add macro, if it is not already in the list
229 if ((type == kSingleTrackAnalyse || type == kSingleTrackHisto
230 || type == kCorrelTrackAnalyse || type == kCorrelTrackHisto) && fMacroList->FindObject(entryName) == 0)
232 fMacroList->Add(new TObjString(entryName));
235 fMacroTypes->Add(new TObjString(entryName), new TObjString(Form("%d", type)));
237 // We do not know, where the element has been inserted - deselect this list
238 fMacroListSelected = 0;
240 returnValue = SUCCESS;
242 else if ((type == kSingleTrackSelect || type == kCorrelTrackSelect) && fMacroSelList->FindObject(entryName) == 0)
244 fMacroSelList->Add(new TObjString(entryName));
245 fMacroSelList->Sort();
247 fMacroTypes->Add(new TObjString(entryName), new TObjString(Form("%d", type)));
249 // We do not know, where the element has been inserted - deselect this list
250 fMacroSelListSelected = 0;
252 returnValue = SUCCESS;
254 else returnValue = WARNING;
256 if (entryName != 0) delete entryName;
262 //______________________________________________________
263 void AliEveTRDTrackList::AddMacroFast(const Char_t* entry, AliEveTRDTrackListMacroType type)
265 // Adds an entry to the corresponding list (cf. overloaded function).
269 case kSingleTrackSelect:
270 case kCorrelTrackSelect:
271 fMacroSelList->Add(new TObjString(entry));
272 fMacroSelList->Sort();
274 fMacroTypes->Add(new TObjString(entry), new TObjString(Form("%d", type)));
276 // We do not know, where the element has been inserted - deselect this list
277 fMacroSelListSelected = 0;
280 case kSingleTrackAnalyse:
281 case kSingleTrackHisto:
282 case kCorrelTrackAnalyse:
283 case kCorrelTrackHisto:
284 fMacroList->Add(new TObjString(entry));
287 fMacroTypes->Add(new TObjString(entry), new TObjString(Form("%d", type)));
289 // We do not know, where the element has been inserted - deselect this list
290 fMacroListSelected = 0;
293 Error("AliEveTRDTrackList::AddMacroFast", Form("Unknown macro type for entry \"%s\"!", entry));
298 //______________________________________________________
299 void AliEveTRDTrackList::AddMacroFast(const Char_t* path, const Char_t* name, AliEveTRDTrackListMacroType type)
301 // Adds a macro (path/name) to the list associated with the "type" parameter.
302 // No checks are performed (fast) and no libraries are loaded.
303 // Do use only, if library already exists!
305 Char_t* entry = MakeMacroEntry(path, name);
308 AddMacroFast(entry, type);
310 #ifdef ALIEVETRDTRACKLIST_DEBUG
311 // Successfull add will only be displayed in debug mode
312 printf("#AliEveTRDTrackList::AddMacroFast: Added macro \"%s/%s\" to the corresponding list\n", path, name);
320 // Error will always be displayed
321 printf("#AliEveTRDTrackList::AddMacroFast: ERROR: Could not add macro \"%s/%s\" to the corresponding list\n",
326 //______________________________________________________
327 void AliEveTRDTrackList::AddStandardMacros()
329 // Adds standard macros to the lists.
331 // Add your standard macros here, e.g.:
332 // To add a macro use:
333 // AddMacro("$(ALICE_ROOT)/myFolder", "myMacroName.C");
334 // -> If the file does not exist, nothing happens. So if you want to handle this,
335 // use the return value of AddMacro (NOT_EXIST_ERROR is returned, if file does not exist)
336 // (-> You can also check for other return values (see AddMacro(...)))
337 AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "clusterSelection.C");
338 AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "chargeDistr.C");
339 AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "clusterResiduals.C");
340 AddMacro("$(ALICE_ROOT)/TRD/qaRec/macros", "PH.C");
343 //______________________________________________________
344 Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TList* procIterator)
346 // Uses the procIterator (for the selected process macros) to apply the selected macros to the data.
347 // Returns kTRUE on success, otherwise kFALSE. If there no process macros selected, kTRUE is returned
348 // (this is no error!).
349 // The single track process macros are applied to all selected tracks.
350 // The selIterator (for the selected selection macros) will be used to apply the correlated tracks selection
351 // macros to all track pairs (whereby BOTH tracks have to be selected, otherwise they will be skipped).
352 // All track pairs that have been selected by ALL correlated tracks selection macros will be processed by
353 // the correlated tracks process macros.
355 // No process macros need to be processed
356 if (procIterator->GetEntries() <= 0) return kTRUE;
361 // Clear old data and re-allocate
362 if (fDataTree == 0) fDataTree = new TTreeSRedirector(Form("/tmp/TRD.TrackListMacroData_%s.root",
363 gSystem->Getenv("USER")));
366 Error("Apply process macros", Form("File \"/tmp/TRD.TrackListMacroData_%s.root\" could not be accessed properly!",
367 gSystem->Getenv("USER")));
371 if (fDataFromMacroList != 0)
373 fDataFromMacroList->Delete();
374 delete fDataFromMacroList;
376 fDataFromMacroList = new TList();
377 fDataFromMacroList->TCollection::SetOwner(kTRUE);
379 fHistoDataSelected = 0;
382 Char_t name[fkMaxMacroNameLength];
383 Char_t** procCmds = new Char_t*[procIterator->GetEntries()];
384 Char_t** selCmds = new Char_t*[selIterator->GetEntries()];
385 AliEveTRDTrackListMacroType* mProcType = new AliEveTRDTrackListMacroType[procIterator->GetEntries()];
386 AliEveTRDTrackListMacroType* mSelType = new AliEveTRDTrackListMacroType[selIterator->GetEntries()];
388 Bool_t selectedByCorrSelMacro = kFALSE;
390 AliEveTRDTrackListMacroType macroType = kUnknown;
391 Int_t numHistoMacros = 0;
394 AliEveTRDTrack* track1 = 0;
395 AliEveTRDTrack* track2 = 0;
396 TH1* returnedHist = 0x0;
398 // Collect the commands for each process macro and add them to "data-from-list"
399 for (Int_t i = 0; i < procIterator->GetEntries(); i++)
401 memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength);
403 procCmds[i] = new Char_t[(fkMaxMacroPathNameLength + fkMaxApplyCommandLength)];
404 memset(procCmds[i], '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength));
406 #ifdef ALIEVETRDTRACKLIST_DEBUG
407 printf("AliEveTRDTrackList: Applying process macro: %s\n", procIterator->At(i)->GetTitle());
411 sscanf(procIterator->At(i)->GetTitle(), "%s (Path: %*s)", name);
413 // Delete ".C" at the end
414 // -> Note: Physical address pointer, do NOT delete. / Changes "name" as well!
415 Char_t* dotC = (Char_t*)strrchr(name, '.');
423 // Find the type of the process macro
424 macroType = GetMacroType(procIterator->At(i)->GetTitle(), kTRUE);
425 if (macroType == kSingleTrackHisto)
427 mProcType[i] = macroType;
429 // Create the command
430 sprintf(procCmds[i], "%s(automaticTrackV1_1);", name);
432 // Add to "data-from-list" -> Mark as a histo macro with the substring "(histo macro)"
433 fDataFromMacroList->Add(new TObjString(Form("%s (histo macro)", name)));
435 else if (macroType == kSingleTrackAnalyse)
437 mProcType[i] = macroType;
438 // Create the command
439 sprintf(procCmds[i], "%s(automaticTrackV1_1, results, n);", name);
441 // Add to "data-from-list"
442 fDataFromMacroList->Add(new TObjString(name));
444 else if (macroType == kCorrelTrackHisto)
446 mProcType[i] = macroType;
448 // Create the command
449 sprintf(procCmds[i], "%s(automaticTrackV1_1, automaticTrackV1_2);", name);
451 // Add to "data-from-list" -> Mark as a histo macro with the substring "(histo macro)"
452 fDataFromMacroList->Add(new TObjString(Form("%s (histo macro)", name)));
454 else if (macroType == kCorrelTrackAnalyse)
456 mProcType[i] = macroType;
457 // Create the command
458 sprintf(procCmds[i], "%s(automaticTrackV1_1, automaticTrackV1_2, results, n);", name);
460 // Add to "data-from-list"
461 fDataFromMacroList->Add(new TObjString(name));
465 Error("Apply process macros",
466 Form("Process macro list corrupted: Macro \"%s\" is not registered as a process macro!", name));
467 mProcType[i] = kUnknown;
471 // Collect the commands for each selection macro and add them to "data-from-list"
472 for (Int_t i = 0; i < selIterator->GetEntries(); i++)
474 memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength);
476 selCmds[i] = new Char_t[(fkMaxMacroPathNameLength + fkMaxApplyCommandLength)];
477 memset(selCmds[i], '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength));
479 #ifdef ALIEVETRDTRACKLIST_DEBUG
480 printf("AliEveTRDTrackList: Applying selection macro (correlated tracks): %s\n", selIterator->At(i)->GetTitle());
484 sscanf(selIterator->At(i)->GetTitle(), "%s (Path: %*s)", name);
486 // Delete ".C" at the end
487 // -> Note: Physical address pointer, do NOT delete. / Changes "name" as well!
488 Char_t* dotC = (Char_t*)strrchr(name, '.');
496 // Find the type of the process macro
497 macroType = GetMacroType(selIterator->At(i)->GetTitle(), kTRUE);
498 // Single track select macro
499 if (macroType == kSingleTrackSelect)
501 // Has already been processed by ApplySTSelectionMacros(...)
502 mSelType[i] = macroType;
504 // Correlated tracks select macro
505 else if (macroType == kCorrelTrackSelect)
507 mSelType[i] = macroType;
509 // Create the command
510 sprintf(selCmds[i], "%s(automaticTrackV1_1, automaticTrackV1_2);", name);
514 Error("Apply process macros",
515 Form("Selection macro list corrupted: Macro \"%s\" is not registered as a selection macro!", name));
516 mProcType[i] = kUnknown;
520 // Allocate memory for the histograms
521 if (numHistoMacros > 0) histos = new TH1*[numHistoMacros];
522 for (Int_t i = 0; i < numHistoMacros; i++) histos[i] = 0;
524 // Walk through the list of tracks
525 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
527 track1 = dynamic_cast<AliEveTRDTrack*>(*iter);
529 if (!track1) continue;
531 // Skip tracks that have not been selected
532 if (!track1->GetRnrState()) continue;
534 track1->ExportToCINT((Text_t*)"automaticTrack");
535 // Cast to AliTRDtrackV1
536 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
538 // Collect data for each macro
539 for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries(); i++)
541 // Single track histo
542 if (mProcType[i] == kSingleTrackHisto)
544 returnedHist = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
545 if (returnedHist != 0x0)
547 if (histos[histoIndex] == 0) histos[histoIndex] = returnedHist;
550 histos[histoIndex]->Add((const TH1*)returnedHist);
557 // Correlated tracks histo
558 else if (mProcType[i] == kCorrelTrackHisto)
560 // Loop over all pairs behind the current one - together with the other loop this will be a loop
561 // over all pairs. We have a pair of tracks, if and only if both tracks of the pair are selected (Rnr-state)
562 // and are not equal.
563 // The correlated tracks process macro will applied to all pairs that will be additionally selected by
564 // all correlated tracks selection macros.
565 TEveElement::List_i iter2 = iter;
567 for ( ; iter2 != this->EndChildren(); ++iter2)
569 track2 = dynamic_cast<AliEveTRDTrack*>(*iter2);
571 if (!track2) continue;
573 // Skip tracks that have not been selected
574 if (!track2->GetRnrState()) continue;
576 track2->ExportToCINT((Text_t*)"automaticTrack");
577 // Cast to AliTRDtrackV1
578 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_2 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
580 // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
581 selectedByCorrSelMacro = kTRUE;
582 for (Int_t j = 0; j < selIterator->GetEntries(); j++)
584 if (mSelType[j] == kCorrelTrackSelect)
586 selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
587 if (!selectedByCorrSelMacro) break;
591 // If the pair has not been selected by the correlated tracks selection macros, skip it!
592 if (!selectedByCorrSelMacro) continue;
594 returnedHist = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
595 if (returnedHist != 0x0)
597 if (histos[histoIndex] == 0) histos[histoIndex] = returnedHist;
600 histos[histoIndex]->Add((const TH1*)returnedHist);
609 // Single track analyse
610 else if (mProcType[i] == kSingleTrackAnalyse)
612 // Create data pointers in CINT, execute the macro and get the data
613 gROOT->ProcessLineSync("Double_t* results = 0;");
614 gROOT->ProcessLineSync("Int_t n = 0;");
615 gROOT->ProcessLineSync(procCmds[i]);
616 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
617 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
621 Error("Apply macros", Form("Error reading data from macro \"%s\"", procIterator->At(i)->GetTitle()));
624 for (Int_t resInd = 0; resInd < nResults; resInd++)
626 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
632 // Correlated tracks analyse
633 else if (mProcType[i] == kCorrelTrackAnalyse)
635 // Loop over all pairs behind the current one - together with the other loop this will be a loop
636 // over all pairs. We have a pair of tracks, if and only if both tracks of the pair are selected (Rnr-state)
637 // and are not equal.
638 // The correlated tracks process macro will applied to all pairs that will be additionally selected by
639 // all correlated tracks selection macros.
640 TEveElement::List_i iter2 = iter;
642 for ( ; iter2 != this->EndChildren(); ++iter2)
644 track2 = dynamic_cast<AliEveTRDTrack*>(*iter2);
646 if (!track2) continue;
648 // Skip tracks that have not been selected
649 if (!track2->GetRnrState()) continue;
651 track2->ExportToCINT((Text_t*)"automaticTrack");
652 // Cast to AliTRDtrackV1
653 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_2 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
655 // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
656 selectedByCorrSelMacro = kTRUE;
657 for (Int_t j = 0; j < selIterator->GetEntries(); j++)
659 if (mSelType[j] == kCorrelTrackSelect)
661 selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
662 if (!selectedByCorrSelMacro) break;
666 // If the pair has not been selected by the correlated tracks selection macros, skip it!
667 if (!selectedByCorrSelMacro) continue;
669 // Create data pointers in CINT, execute the macro and get the data
670 gROOT->ProcessLineSync("Double_t* results = 0;");
671 gROOT->ProcessLineSync("Int_t n = 0;");
672 gROOT->ProcessLineSync(procCmds[i]);
673 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
674 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
678 Error("Apply macros", Form("Error reading data from macro \"%s\"", procIterator->At(i)->GetTitle()));
681 for (Int_t resInd = 0; resInd < nResults; resInd++)
683 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
693 for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries() && histoIndex < numHistoMacros; i++)
695 if (mProcType[i] == kSingleTrackHisto || mProcType[i] == kCorrelTrackHisto)
697 // Might be empty (e.g. no tracks have been selected)!
698 if (histos[histoIndex] != 0)
700 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << histos[histoIndex] << (Char_t*)"\n";
706 if (fDataTree != 0) delete fDataTree;
709 if (procCmds != 0) delete [] procCmds;
710 if (mProcType != 0) delete mProcType;
713 if (selCmds != 0) delete [] selCmds;
714 if (mSelType != 0) delete mSelType;
717 if (histos != 0) delete [] histos;
723 // If there is data, select the first data set
724 if (procIterator->GetEntries() > 0) SETBIT(fHistoDataSelected, 0);
726 // Now the data is stored in "/tmp/TRD.TrackListMacroData_$USER.root"
727 // The editor will access this file to display the data
731 //______________________________________________________
732 void AliEveTRDTrackList::ApplySTSelectionMacros(const TList* iterator)
734 // Uses the iterator (for the selected selection macros) to apply the selected macros to the data.
735 // The rnr-states of the tracks are set according to the result of the macro calls (kTRUE, if all
736 // macros return kTRUE for this track, otherwise: kFALSE).
737 // "ST" stands for "single track". This means that only single track selection macros are applied.
738 // Correlated tracks selection macros will be used inside the call of ApplyProcessMacros(...)!
740 Char_t name[fkMaxMacroNameLength];
741 Char_t cmd[(fkMaxMacroNameLength + fkMaxApplyCommandLength)];
743 AliEveTRDTrackListMacroType macroType = kUnknown;
744 AliEveTRDTrack* track1 = 0;
745 Bool_t selectedByMacro = kFALSE;
750 // Select all tracks at first. A track is then deselect, if at least one selection macro
751 // returns kFALSE for this track
752 // Enable all tracks (Note: EnableListElements(..) will call "ElementChanged", which will cause unforeseen behavior!)
753 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
755 ((TEveElement*)(*iter))->SetRnrState(kTRUE);
759 for (Int_t i = 0; i < iterator->GetEntries(); i++)
762 memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength);
763 memset(cmd, '\0', sizeof(Char_t) * (fkMaxMacroNameLength + fkMaxApplyCommandLength));
765 #ifdef ALIEVETRDTRACKLIST_DEBUG
766 printf("AliEveTRDTrackList: Applying selection macro: %s\n", iterator->At(i)->GetTitle());
770 sscanf(iterator->At(i)->GetTitle(), "%s (Path: %*s)", name);
771 // Delete ".C" at the end
772 // -> Note: Physical address pointer, do NOT delete. / Changes "name" as well!
773 Char_t* dotC = (Char_t*)strrchr(name, '.');
781 // Determine macro type
782 macroType = GetMacroType(iterator->At(i)->GetTitle(), kTRUE);
784 // Single track select macro
785 if (macroType == kSingleTrackSelect)
787 // Create the command
788 sprintf(cmd, "%s(automaticTrackV1);", name);
790 // Walk through the list of tracks
791 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
793 track1 = dynamic_cast<AliEveTRDTrack*>(*iter);
795 if (!track1) continue;
797 // If the track has already been deselected, nothing is to do here
798 if (!track1->GetRnrState()) continue;
800 track1->ExportToCINT((Text_t*)"automaticTrack");
801 // Cast to AliTRDtrackV1
802 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
803 selectedByMacro = (Bool_t)gROOT->ProcessLineSync(cmd);
804 track1->SetRnrState(selectedByMacro && track1->GetRnrState());
807 // Correlated tracks select macro
808 else if (macroType == kCorrelTrackSelect)
810 // Will be processed in ApplyProcessMacros(...)
815 Error("Apply selection macros",
816 Form("Selection macro list corrupted: Macro \"%s\" is not registered as a selection macro!", name));
824 //______________________________________________________
825 AliEveTRDTrackList::AliEveTRDTrackListMacroType AliEveTRDTrackList::GetMacroType(const Char_t* entry, Bool_t UseList) const
827 // Returns the type of the macro of the corresponding entry (i.e. "macro.C (Path: path)").
828 // If you have only the name and the path, you can simply use MakeMacroEntry.
829 // If "UseList" is kTRUE, the type will be looked up in the internal list (very fast). But if this list
830 // does not exist, you have to use kFALSE for this parameter. Then the type will be determined by the
831 // prototype! NOTE: It is assumed that the macro has been compiled! If not, the return value is not
832 // predictable, but normally will be kUnknown.
833 // Note: AddMacro(Fast) will update the internal list and RemoveProcess(/Selection)Macros respectively.
835 AliEveTRDTrackListMacroType type = kUnknown;
837 // Re do the check of the macro type
840 Char_t name[fkMaxMacroNameLength];
842 memset(name, '\0', sizeof(Char_t) * fkMaxMacroNameLength);
845 sscanf(entry, "%s (Path: %*s)", name);
847 // Delete ".C" at the end
848 // -> Note: Physical address pointer, do NOT delete. / Changes "name" as well!
849 Char_t* dotC = (Char_t*)strrchr(name, '.');
857 // Single track select macro or single track histo macro?
858 TFunction* f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*", kTRUE);
861 // Some additional check (is the parameter EXACTLY of the desired type?)
862 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0)
864 // Single track select macro?
865 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
867 type = kSingleTrackSelect;
869 // single track histo macro?
870 else if (!strcmp(f->GetReturnTypeName(), "TH1*"))
872 type = kSingleTrackHisto;
876 // Single track analyse macro?
877 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE))
880 if (!strcmp(f->GetReturnTypeName(), "void"))
882 // Some additional check (are the parameters EXACTLY of the desired type?)
883 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
884 strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 &&
885 strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0)
887 type = kSingleTrackAnalyse;
891 // Correlated tracks select macro or correlated tracks histo macro?
892 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, const AliTRDtrackV1*", kTRUE))
895 // Some additional check (is the parameter EXACTLY of the desired type?)
896 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
897 strstr(f->GetMangledName(), "cOconstsPAliTRDtrackV1mUsP") != 0x0)
899 // Single track select macro?
900 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
902 type = kCorrelTrackSelect;
904 // single track histo macro?
905 else if (!strcmp(f->GetReturnTypeName(), "TH1*"))
907 type = kCorrelTrackHisto;
911 // Correlated tracks analyse macro?
912 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name,
913 "const AliTRDtrackV1*, const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE))
916 if (!strcmp(f->GetReturnTypeName(), "void"))
918 // Some additional check (is the parameter EXACTLY of the desired type?)
919 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
920 strstr(f->GetMangledName(), "cOconstsPAliTRDtrackV1mUsP") != 0x0 &&
921 strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 &&
922 strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0)
924 type = kCorrelTrackAnalyse;
929 // Use list to look up the macro type
932 TObjString* objEntry = 0;
933 objEntry = (TObjString*)fMacroTypes->GetValue(entry);
934 if (objEntry == 0) return kUnknown;
936 type = (AliEveTRDTrackListMacroType)objEntry->GetString().Atoi();
939 case kSingleTrackSelect:
940 case kSingleTrackAnalyse:
941 case kSingleTrackHisto:
942 case kCorrelTrackSelect:
943 case kCorrelTrackAnalyse:
944 case kCorrelTrackHisto:
955 //______________________________________________________
956 Char_t* AliEveTRDTrackList::MakeMacroEntry(const Char_t* path, const Char_t* name) const
958 // Constructs an entry for the macro lists with path and name.
960 Char_t* entry = new Char_t[(fkMaxMacroPathNameLength + 30)];
961 memset(entry, '\0', sizeof(Char_t) * (fkMaxMacroPathNameLength + 30));
963 Char_t* systemPath = gSystem->ExpandPathName(path);
964 sprintf(entry, "%s (Path: %s)", name, systemPath);
971 //______________________________________________________
972 void AliEveTRDTrackList::RemoveProcessMacros(const TList* iterator)
974 // Uses the iterator (for the selected process macros) to remove the process macros from
975 // the corresponding list.
978 for (Int_t i = 0; i < iterator->GetEntries(); i++)
980 // Key and value will be deleted, too, since fMacroTypes is the owner of them
981 fMacroTypes->DeleteEntry(fMacroTypes->FindObject(iterator->At(i)->GetTitle()));
983 obj = (TObjString*)fMacroList->Remove(fMacroList->FindObject(iterator->At(i)->GetTitle()));
984 if (obj != 0) delete obj;
989 //______________________________________________________
990 void AliEveTRDTrackList::RemoveSelectionMacros(const TList* iterator)
992 // Uses the iterator (for the selected selection macros) to remove the selection macros from
993 // the corresponding list.
996 for (Int_t i = 0; i < iterator->GetEntries(); i++)
998 // Key and value will be deleted, too, since fMacroTypes is the owner of them
999 fMacroTypes->DeleteEntry(fMacroTypes->FindObject(iterator->At(i)->GetTitle()));
1001 obj = (TObjString*)fMacroSelList->Remove(fMacroSelList->FindObject(iterator->At(i)->GetTitle()));
1002 if (obj != 0) delete obj;
1007 //______________________________________________________
1008 void AliEveTRDTrackList::UpdateTrackStyle(AliEveTRDTrack::AliEveTRDTrackState s, UChar_t ss)
1010 // Updates the track style and sets this style for each track.
1014 case AliEveTRDTrack::kSource:
1015 SETBIT(fSelectedStyle, AliEveTRDTrack::kSource);
1017 case AliEveTRDTrack::kPID:
1018 CLRBIT(fSelectedStyle, AliEveTRDTrack::kSource);
1021 case AliTRDReconstructor::kLQPID:
1022 CLRBIT(fSelectedStyle, AliEveTRDTrack::kPID);
1024 case AliTRDReconstructor::kNNPID:
1025 SETBIT(fSelectedStyle, AliEveTRDTrack::kPID);
1029 case AliEveTRDTrack::kTrackCosmics:
1030 SETBIT(fSelectedStyle, AliEveTRDTrack::kTrackCosmics);
1032 case AliEveTRDTrack::kTrackModel:
1033 CLRBIT(fSelectedStyle, AliEveTRDTrack::kTrackCosmics);
1036 case AliEveTRDTrack::kRieman:
1037 CLRBIT(fSelectedStyle, AliEveTRDTrack::kTrackModel);
1039 case AliEveTRDTrack::kKalman:
1040 AliWarning("Kalman fit under testing for the moment.");
1041 //SETBIT(fSelectedStyle, AliEveTRDTrack::kTrackModel);
1048 // Walk through the list of tracks
1049 AliEveTRDTrack* track = 0x0;
1050 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
1052 if (!(track = dynamic_cast<AliEveTRDTrack*>(*iter))) continue;
1054 track->SetStatus(fSelectedStyle);