]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackList.cxx
Rulechecker-complying update from P.Ganoti (pganoti@phys.uoa.gr)
[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>
81b4050b 81#include <qaRec/macros/AliTRDperformanceTrain.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;
2a9a70dc 275 for(Int_t it=2; it<NTRDQATASKS; it++){
db16b708 276 TClass c(fgkTRDtaskClassName[it]);
277 task = (AliTRDrecoTask*)c.New();
50db8cc0 278 task->SetMCdata(kFALSE);
db16b708 279 if(!(fPlots = task->GetPlotFunctors())){
50db8cc0 280 //AliWarning(Form("No Plot functors defined for task \"%s\"", fgkTRDtaskClassName[it]));
db16b708 281 delete task;
282 continue;
283 }
284 if(!(task->Histos())){
50db8cc0 285 //AliWarning(Form("No Ref Histograms defined for task \"%s\"", fgkTRDtaskClassName[it]));
db16b708 286 delete task;
287 continue;
288 }
289
290 // export task to CINT and add functions
291 gROOT->ProcessLine(Form("%s* %s = (%s*)0x%lx;", fgkTRDtaskClassName[it], task->GetName(), fgkTRDtaskClassName[it], (void*)task));
292 TIter iter(fPlots); TMethodCall *m = 0x0;
293 while((m = dynamic_cast<TMethodCall*>(iter()))){
294 AddMacroFast("", Form("%s->%s", task->GetName(), m->GetMethodName()), kSingleTrackHisto);
295 }
296 }
caaf90d2 297}
298
8e27fca1 299//______________________________________________________
2670605d 300Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TList* procIterator)
caaf90d2 301{
2670605d 302 // Uses the procIterator (for the selected process macros) to apply the selected macros to the data.
16db6074 303 // Returns kTRUE on success, otherwise kFALSE. If there no process macros selected, kTRUE is returned
304 // (this is no error!).
2670605d 305 // The single track process macros are applied to all selected tracks.
306 // The selIterator (for the selected selection macros) will be used to apply the correlated tracks selection
307 // macros to all track pairs (whereby BOTH tracks have to be selected, otherwise they will be skipped).
308 // All track pairs that have been selected by ALL correlated tracks selection macros will be processed by
309 // the correlated tracks process macros.
16db6074 310
ea24e1bc 311 // No process macros need to be processed
2670605d 312 if (procIterator->GetEntries() <= 0) return kTRUE;
ea24e1bc 313
314 // Clear root
db16b708 315 // A.B. gROOT->Reset();
ea24e1bc 316
317 // Clear old data and re-allocate
db16b708 318 if (fDataTree == 0x0){
319 TDirectory *cwd = gDirectory;
320 fDataTree = new TTreeSRedirector(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")));
321 cwd->cd();
322 }
323 if (!fDataTree){
324 Error("Apply process macros", Form("File \"/tmp/TRD.TrackListMacroData_%s.root\" could not be accessed properly!", gSystem->Getenv("USER")));
ea24e1bc 325 return kFALSE;
326 }
327
db16b708 328 if (fDataFromMacroList != 0) {
e007877e 329 fDataFromMacroList->Delete();
330 delete fDataFromMacroList;
331 }
ea24e1bc 332 fDataFromMacroList = new TList();
e007877e 333 fDataFromMacroList->TCollection::SetOwner(kTRUE);
ea24e1bc 334
335 fHistoDataSelected = 0;
336
8e27fca1 337
38a30030 338 TMacroData* macro = 0;
339
6e26c99d 340 TString* procCmds = 0;
38a30030 341 AliEveTRDTrackListMacroType* mProcType = 0;
db16b708 342 if (procIterator->GetEntries() > 0) {
6e26c99d 343 procCmds = new TString[procIterator->GetEntries()];
38a30030 344 mProcType = new AliEveTRDTrackListMacroType[procIterator->GetEntries()];
345 }
2670605d 346
6e26c99d 347 TString* selCmds = 0;
38a30030 348 AliEveTRDTrackListMacroType* mSelType = 0;
db16b708 349 if (selIterator->GetEntries() > 0) {
6e26c99d 350 selCmds = new TString[selIterator->GetEntries()];
38a30030 351 mSelType = new AliEveTRDTrackListMacroType[selIterator->GetEntries()];
352 }
353
2670605d 354 Bool_t selectedByCorrSelMacro = kFALSE;
c413e8d4 355
8bdeb570 356 AliEveTRDTrackListMacroType macroType = kUnknown;
c413e8d4 357 Int_t numHistoMacros = 0;
358 TH1** histos = 0;
caaf90d2 359
e007877e 360 AliEveTRDTrack* track1 = 0;
361 AliEveTRDTrack* track2 = 0;
caaf90d2 362
2670605d 363 // Collect the commands for each process macro and add them to "data-from-list"
db16b708 364 for (Int_t i = 0; i < procIterator->GetEntries(); i++){
38a30030 365 macro = (TMacroData*)fMacroList->GetValue(procIterator->At(i)->GetTitle());
e007877e 366
db16b708 367 if (!macro){
38a30030 368 Error("Apply process macros",
db16b708 369 Form("Macro list is corrupted: Macro \"%s\" is not registered!",
370 procIterator->At(i)->GetTitle()));
38a30030 371 continue;
e007877e 372 }
38a30030 373
374#ifdef ALIEVETRDTRACKLIST_DEBUG
375 printf("AliEveTRDTrackList: Checking process macro: %s\n", macro->GetName());
376#endif
377
378 // Find the type of the process macro
379 macroType = macro->GetType();
db16b708 380 if (macroType == kSingleTrackHisto || macroType == kCorrelTrackHisto){
2670605d 381 mProcType[i] = macroType;
8bdeb570 382 numHistoMacros++;
383 // Create the command
6e26c99d 384 procCmds[i] = macro->GetCmd();
8bdeb570 385
386 // Add to "data-from-list" -> Mark as a histo macro with the substring "(histo macro)"
38a30030 387 fDataFromMacroList->Add(new TObjString(Form("%s (histo macro)", macro->GetName())));
db16b708 388 } else if (macroType == kSingleTrackAnalyse || macroType == kCorrelTrackAnalyse) {
2670605d 389 mProcType[i] = macroType;
c413e8d4 390 // Create the command
6e26c99d 391 procCmds[i] = macro->GetCmd();
8bdeb570 392
393 // Add to "data-from-list"
38a30030 394 fDataFromMacroList->Add(new TObjString(macro->GetName()));
db16b708 395 } else {
8bdeb570 396 Error("Apply process macros",
db16b708 397 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a process macro!",
398 macro->GetPath(), macro->GetName()));
2670605d 399 mProcType[i] = kUnknown;
400 }
401 }
402
403 // Collect the commands for each selection macro and add them to "data-from-list"
db16b708 404 for (Int_t i = 0; i < selIterator->GetEntries(); i++){
38a30030 405 macro = (TMacroData*)fMacroList->GetValue(selIterator->At(i)->GetTitle());
406
db16b708 407 if (!macro){
38a30030 408 Error("Apply process macros",
db16b708 409 Form("Macro list is corrupted: Macro \"%s\" is not registered!",
410 selIterator->At(i)->GetTitle()));
38a30030 411 continue;
2670605d 412 }
38a30030 413
414#ifdef ALIEVETRDTRACKLIST_DEBUG
415 printf("AliEveTRDTrackList: Checking selection macro: %s\n", macro->GetName());
416#endif
2670605d 417
418 // Find the type of the process macro
38a30030 419 macroType = macro->GetType();
420
2670605d 421 // Single track select macro
db16b708 422 if (macroType == kSingleTrackSelect) {
2670605d 423 // Has already been processed by ApplySTSelectionMacros(...)
424 mSelType[i] = macroType;
425 }
426 // Correlated tracks select macro
db16b708 427 else if (macroType == kCorrelTrackSelect) {
2670605d 428 mSelType[i] = macroType;
429
430 // Create the command
6e26c99d 431 selCmds[i] = macro->GetCmd();
db16b708 432 } else {
2670605d 433 Error("Apply process macros",
db16b708 434 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a selection macro!",
435 macro->GetPath(), macro->GetName()));
38a30030 436 mSelType[i] = kUnknown;
c413e8d4 437 }
8e27fca1 438 }
c413e8d4 439
440 // Allocate memory for the histograms
441 if (numHistoMacros > 0) histos = new TH1*[numHistoMacros];
db16b708 442 for (Int_t i = 0; i < numHistoMacros; i++) histos[i] = 0x0;
38a30030 443
caaf90d2 444
db16b708 445 //////////////////////////////////
446 // WALK THROUGH THE LIST OF TRACKS
447 //////////////////////////////////
448 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter){
449 if(!(track1 = dynamic_cast<AliEveTRDTrack*>(*iter))) continue;
450
caaf90d2 451 // Skip tracks that have not been selected
e007877e 452 if (!track1->GetRnrState()) continue;
38a30030 453
caaf90d2 454 // Cast to AliTRDtrackV1
db16b708 455 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)0x%xl;", track1));
e007877e 456 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
caaf90d2 457
458 // Collect data for each macro
db16b708 459 for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries(); i++){
e007877e 460 // Single track histo
db16b708 461 if (mProcType[i] == kSingleTrackHisto){
462 histos[histoIndex++] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
463 // Correlated tracks histo
464 } else if (mProcType[i] == kCorrelTrackHisto) {
e007877e 465 // Loop over all pairs behind the current one - together with the other loop this will be a loop
466 // over all pairs. We have a pair of tracks, if and only if both tracks of the pair are selected (Rnr-state)
467 // and are not equal.
2670605d 468 // The correlated tracks process macro will applied to all pairs that will be additionally selected by
469 // all correlated tracks selection macros.
e007877e 470 TEveElement::List_i iter2 = iter;
471 iter2++;
472 for ( ; iter2 != this->EndChildren(); ++iter2)
473 {
db16b708 474 if(!(track2 = dynamic_cast<AliEveTRDTrack*>(*iter2))) continue;
e007877e 475
e007877e 476 // Skip tracks that have not been selected
477 if (!track2->GetRnrState()) continue;
478
e007877e 479 // Cast to AliTRDtrackV1
db16b708 480 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)0x%xl;", track2));
e007877e 481 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_2 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
482
2670605d 483 // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
484 selectedByCorrSelMacro = kTRUE;
db16b708 485 for (Int_t j = 0; j < selIterator->GetEntries(); j++){
486 if (mSelType[j] == kCorrelTrackSelect){
2670605d 487 selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
488 if (!selectedByCorrSelMacro) break;
489 }
490 }
491
492 // If the pair has not been selected by the correlated tracks selection macros, skip it!
493 if (!selectedByCorrSelMacro) continue;
494
db16b708 495 histos[histoIndex] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
e007877e 496 }
497 histoIndex++;
498 }
499 // Single track analyse
db16b708 500 else if (mProcType[i] == kSingleTrackAnalyse) {
c413e8d4 501 // Create data pointers in CINT, execute the macro and get the data
502 gROOT->ProcessLineSync("Double_t* results = 0;");
503 gROOT->ProcessLineSync("Int_t n = 0;");
2670605d 504 gROOT->ProcessLineSync(procCmds[i]);
c413e8d4 505 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
506 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
507
db16b708 508 if (results == 0) {
2670605d 509 Error("Apply macros", Form("Error reading data from macro \"%s\"", procIterator->At(i)->GetTitle()));
c413e8d4 510 continue;
511 }
db16b708 512 for (Int_t resInd = 0; resInd < nResults; resInd++){
c413e8d4 513 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
514 }
caaf90d2 515
c413e8d4 516 delete results;
517 results = 0;
518 }
e007877e 519 // Correlated tracks analyse
db16b708 520 else if (mProcType[i] == kCorrelTrackAnalyse){
e007877e 521 // Loop over all pairs behind the current one - together with the other loop this will be a loop
522 // over all pairs. We have a pair of tracks, if and only if both tracks of the pair are selected (Rnr-state)
523 // and are not equal.
2670605d 524 // The correlated tracks process macro will applied to all pairs that will be additionally selected by
525 // all correlated tracks selection macros.
e007877e 526 TEveElement::List_i iter2 = iter;
527 iter2++;
38a30030 528
db16b708 529 for ( ; iter2 != this->EndChildren(); ++iter2) {
530 if(!(track2 = dynamic_cast<AliEveTRDTrack*>(*iter2))) continue;
38a30030 531
e007877e 532 // Skip tracks that have not been selected
533 if (!track2->GetRnrState()) continue;
38a30030 534
e007877e 535 // Cast to AliTRDtrackV1
db16b708 536 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)0x%xl;", track2));
e007877e 537 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_2 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
538
2670605d 539 // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
540 selectedByCorrSelMacro = kTRUE;
db16b708 541 for (Int_t j = 0; j < selIterator->GetEntries(); j++) {
542 if (mSelType[j] == kCorrelTrackSelect) {
2670605d 543 selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
544 if (!selectedByCorrSelMacro) break;
545 }
546 }
547
548 // If the pair has not been selected by the correlated tracks selection macros, skip it!
549 if (!selectedByCorrSelMacro) continue;
550
e007877e 551 // Create data pointers in CINT, execute the macro and get the data
552 gROOT->ProcessLineSync("Double_t* results = 0;");
553 gROOT->ProcessLineSync("Int_t n = 0;");
2670605d 554 gROOT->ProcessLineSync(procCmds[i]);
e007877e 555 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
556 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
38a30030 557
db16b708 558 if (results == 0) {
2670605d 559 Error("Apply macros", Form("Error reading data from macro \"%s\"", procIterator->At(i)->GetTitle()));
e007877e 560 continue;
561 }
db16b708 562 for (Int_t resInd = 0; resInd < nResults; resInd++) {
e007877e 563 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
564 }
565
566 delete results;
567 results = 0;
568 }
569 }
caaf90d2 570 }
571 }
caaf90d2 572
db16b708 573 for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries() && histoIndex < numHistoMacros; i++) {
574 if (mProcType[i] == kSingleTrackHisto || mProcType[i] == kCorrelTrackHisto) {
5715955a 575 // Might be empty (e.g. no tracks have been selected)!
db16b708 576 if (histos[histoIndex]) {
5715955a 577 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << histos[histoIndex] << (Char_t*)"\n";
578 }
579 histoIndex++;
580 }
c413e8d4 581 }
582
583 if (fDataTree != 0) delete fDataTree;
caaf90d2 584 fDataTree = 0;
585
2670605d 586 if (procCmds != 0) delete [] procCmds;
38a30030 587 procCmds = 0;
2670605d 588 if (mProcType != 0) delete mProcType;
589 mProcType = 0;
590
591 if (selCmds != 0) delete [] selCmds;
38a30030 592 selCmds = 0;
2670605d 593 if (mSelType != 0) delete mSelType;
594 mSelType = 0;
c413e8d4 595
596 if (histos != 0) delete [] histos;
597 histos = 0;
8e27fca1 598
caaf90d2 599 // Clear root
db16b708 600 // A.B. gROOT->Reset();
caaf90d2 601
4f6473f6 602 // If there is data, select the first data set
2670605d 603 if (procIterator->GetEntries() > 0) SETBIT(fHistoDataSelected, 0);
4f6473f6 604
e007877e 605 // Now the data is stored in "/tmp/TRD.TrackListMacroData_$USER.root"
caaf90d2 606 // The editor will access this file to display the data
ea24e1bc 607 return kTRUE;
caaf90d2 608}
609
8e27fca1 610//______________________________________________________
2670605d 611void AliEveTRDTrackList::ApplySTSelectionMacros(const TList* iterator)
caaf90d2 612{
16db6074 613 // Uses the iterator (for the selected selection macros) to apply the selected macros to the data.
614 // The rnr-states of the tracks are set according to the result of the macro calls (kTRUE, if all
615 // macros return kTRUE for this track, otherwise: kFALSE).
2670605d 616 // "ST" stands for "single track". This means that only single track selection macros are applied.
617 // Correlated tracks selection macros will be used inside the call of ApplyProcessMacros(...)!
16db6074 618
38a30030 619 TMacroData* macro = 0;
e007877e 620 AliEveTRDTrackListMacroType macroType = kUnknown;
621 AliEveTRDTrack* track1 = 0;
caaf90d2 622 Bool_t selectedByMacro = kFALSE;
623
624 // Clear root
db16b708 625 // A.B. gROOT->Reset();
caaf90d2 626
4f6473f6 627 // Select all tracks at first. A track is then deselect, if at least one selection macro
628 // returns kFALSE for this track
e007877e 629 // Enable all tracks (Note: EnableListElements(..) will call "ElementChanged", which will cause unforeseen behavior!)
db16b708 630 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter) ((TEveElement*)(*iter))->SetRnrState(kTRUE);
4f6473f6 631 SetRnrState(kTRUE);
632
db16b708 633 for (Int_t i = 0; i < iterator->GetEntries(); i++){
38a30030 634 macro = (TMacroData*)fMacroList->GetValue(iterator->At(i)->GetTitle());
4f6473f6 635
db16b708 636 if (!macro){
38a30030 637 Error("Apply selection macros",
638 Form("Macro list is corrupted: Macro \"%s\" is not registered!", iterator->At(i)->GetTitle()));
639 continue;
640 }
caaf90d2 641
642#ifdef ALIEVETRDTRACKLIST_DEBUG
38a30030 643 printf("AliEveTRDTrackList: Applying selection macro: %s\n", macro->GetName());
caaf90d2 644#endif
caaf90d2 645
e007877e 646 // Determine macro type
38a30030 647 macroType = macro->GetType();
caaf90d2 648
e007877e 649 // Single track select macro
db16b708 650 if (macroType == kSingleTrackSelect){
e007877e 651 // Walk through the list of tracks
652 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
653 {
654 track1 = dynamic_cast<AliEveTRDTrack*>(*iter);
655
656 if (!track1) continue;
657
658 // If the track has already been deselected, nothing is to do here
659 if (!track1->GetRnrState()) continue;
660
e007877e 661 // Cast to AliTRDtrackV1
db16b708 662 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)0x%xl;", track1));
38a30030 663 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
664 selectedByMacro = (Bool_t)gROOT->ProcessLineSync(macro->GetCmd());
e007877e 665 track1->SetRnrState(selectedByMacro && track1->GetRnrState());
666 }
667 }
668 // Correlated tracks select macro
db16b708 669 else if (macroType == kCorrelTrackSelect){
2670605d 670 // Will be processed in ApplyProcessMacros(...)
671 continue;
db16b708 672 } else {
e007877e 673 Error("Apply selection macros",
db16b708 674 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a selection macro!",
675 macro->GetPath(), macro->GetName()));
e007877e 676 }
caaf90d2 677 }
678
679 // Clear root
db16b708 680 // A.B. gROOT->Reset();
caaf90d2 681}
682
8bdeb570 683//______________________________________________________
38a30030 684AliEveTRDTrackList::AliEveTRDTrackListMacroType AliEveTRDTrackList::GetMacroType(const Char_t* name, Bool_t UseList) const
8bdeb570 685{
38a30030 686 // Returns the type of the corresponding macro.
16db6074 687 // If "UseList" is kTRUE, the type will be looked up in the internal list (very fast). But if this list
688 // does not exist, you have to use kFALSE for this parameter. Then the type will be determined by the
689 // prototype! NOTE: It is assumed that the macro has been compiled! If not, the return value is not
690 // predictable, but normally will be kUnknown.
38a30030 691 // Note: AddMacro(Fast) will update the internal list and RemoveMacros respectively.
16db6074 692
8bdeb570 693 AliEveTRDTrackListMacroType type = kUnknown;
694
38a30030 695 // Re-do the check of the macro type
db16b708 696 if (!UseList){
e007877e 697 // Single track select macro or single track histo macro?
8bdeb570 698 TFunction* f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*", kTRUE);
699 if (f != 0x0)
700 {
701 // Some additional check (is the parameter EXACTLY of the desired type?)
702 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0)
703 {
e007877e 704 // Single track select macro?
8bdeb570 705 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
706 {
e007877e 707 type = kSingleTrackSelect;
8bdeb570 708 }
e007877e 709 // single track histo macro?
8bdeb570 710 else if (!strcmp(f->GetReturnTypeName(), "TH1*"))
711 {
e007877e 712 type = kSingleTrackHisto;
8bdeb570 713 }
714 }
715 }
e007877e 716 // Single track analyse macro?
8bdeb570 717 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE))
718 != 0x0)
719 {
720 if (!strcmp(f->GetReturnTypeName(), "void"))
721 {
722 // Some additional check (are the parameters EXACTLY of the desired type?)
723 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
724 strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 &&
725 strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0)
726 {
e007877e 727 type = kSingleTrackAnalyse;
728 }
729 }
730 }
731 // Correlated tracks select macro or correlated tracks histo macro?
732 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, const AliTRDtrackV1*", kTRUE))
733 != 0x0)
734 {
735 // Some additional check (is the parameter EXACTLY of the desired type?)
736 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
737 strstr(f->GetMangledName(), "cOconstsPAliTRDtrackV1mUsP") != 0x0)
738 {
739 // Single track select macro?
740 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
741 {
742 type = kCorrelTrackSelect;
743 }
744 // single track histo macro?
745 else if (!strcmp(f->GetReturnTypeName(), "TH1*"))
746 {
747 type = kCorrelTrackHisto;
748 }
749 }
750 }
751 // Correlated tracks analyse macro?
752 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name,
753 "const AliTRDtrackV1*, const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE))
754 != 0x0)
755 {
756 if (!strcmp(f->GetReturnTypeName(), "void"))
757 {
758 // Some additional check (is the parameter EXACTLY of the desired type?)
759 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
760 strstr(f->GetMangledName(), "cOconstsPAliTRDtrackV1mUsP") != 0x0 &&
761 strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 &&
762 strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0)
763 {
764 type = kCorrelTrackAnalyse;
8bdeb570 765 }
766 }
767 }
768 }
769 // Use list to look up the macro type
770 else
771 {
38a30030 772 TMacroData* macro = 0;
773 macro = (TMacroData*)fMacroList->GetValue(name);
774 if (macro == 0) return kUnknown;
8bdeb570 775
38a30030 776 type = macro->GetType();
8bdeb570 777 switch (type)
778 {
e007877e 779 case kSingleTrackSelect:
780 case kSingleTrackAnalyse:
781 case kSingleTrackHisto:
782 case kCorrelTrackSelect:
783 case kCorrelTrackAnalyse:
784 case kCorrelTrackHisto:
8bdeb570 785 break;
786 default:
787 type = kUnknown;
788 break;
789 }
790 }
791
792 return type;
793}
794
8e27fca1 795//______________________________________________________
38a30030 796void AliEveTRDTrackList::RemoveSelectedMacros(const TList* iterator)
caaf90d2 797{
38a30030 798 // Uses the iterator (for the selected macros) to remove the selected macros from
16db6074 799 // the corresponding list.
800
38a30030 801 TObject* key = 0;
802 TPair* entry = 0;
caaf90d2 803 for (Int_t i = 0; i < iterator->GetEntries(); i++)
804 {
38a30030 805 entry = (TPair*)fMacroList->FindObject(iterator->At(i)->GetTitle());
8bdeb570 806
38a30030 807 if (entry == 0)
808 {
809 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Macro \"%s\" not found in list!",
810 iterator->At(i)->GetTitle()));
811 continue;
812 }
813 key = entry->Key();
caaf90d2 814
38a30030 815 if (key == 0)
816 {
817 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Key for macro \"%s\" not found in list!",
818 iterator->At(i)->GetTitle()));
819 continue;
820 }
821
822 // Key and value will be deleted, too, since fMacroList is the owner of them
823 Bool_t rem = fMacroList->DeleteEntry(key);
8bdeb570 824
38a30030 825 if (rem)
826 {
827#ifdef ALIEVETRDTRACKLIST_DEBUG
828 printf("AliEveTRDTrackList::RemoveSelectedMacros(): Removed macro: %s\n", iterator->At(i)->GetTitle());
829#endif
830 }
831 else
832 {
833 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Macro \"%s\" could not be removed from the list!",
834 iterator->At(i)->GetTitle()));
835 }
caaf90d2 836 }
2ef0687e 837}
4f6473f6 838
ecbbe371 839//______________________________________________________
840void AliEveTRDTrackList::UpdateTrackStyle(AliEveTRDTrack::AliEveTRDTrackState s, UChar_t ss)
841{
16db6074 842 // Updates the track style and sets this style for each track.
843
8bdeb570 844 switch(s)
845 {
e007877e 846 case AliEveTRDTrack::kSource:
847 SETBIT(fSelectedStyle, AliEveTRDTrack::kSource);
848 break;
849 case AliEveTRDTrack::kPID:
850 CLRBIT(fSelectedStyle, AliEveTRDTrack::kSource);
851 switch(ss)
852 {
9443fb9d 853 case AliTRDpidUtil::kLQ:
e007877e 854 CLRBIT(fSelectedStyle, AliEveTRDTrack::kPID);
855 break;
9443fb9d 856 case AliTRDpidUtil::kNN:
e007877e 857 SETBIT(fSelectedStyle, AliEveTRDTrack::kPID);
858 break;
859 }
860 break;
861 case AliEveTRDTrack::kTrackCosmics:
862 SETBIT(fSelectedStyle, AliEveTRDTrack::kTrackCosmics);
863 break;
864 case AliEveTRDTrack::kTrackModel:
865 CLRBIT(fSelectedStyle, AliEveTRDTrack::kTrackCosmics);
866 switch(ss)
867 {
868 case AliEveTRDTrack::kRieman:
869 CLRBIT(fSelectedStyle, AliEveTRDTrack::kTrackModel);
870 break;
871 case AliEveTRDTrack::kKalman:
12896fe5 872 //AliWarning("Kalman fit under testing for the moment.");
873 SETBIT(fSelectedStyle, AliEveTRDTrack::kTrackModel);
e007877e 874 break;
875 }
876 break;
ecbbe371 877 }
878
879
ecbbe371 880 // Walk through the list of tracks
881 AliEveTRDTrack* track = 0x0;
8bdeb570 882 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
883 {
ecbbe371 884 if (!(track = dynamic_cast<AliEveTRDTrack*>(*iter))) continue;
885
886 track->SetStatus(fSelectedStyle);
887 }
888}