]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EVE/EveDet/AliEveTRDTrackList.cxx
update to AliTRDpwg1Helper class by Markus
[u/mrichter/AliRoot.git] / EVE / EveDet / AliEveTRDTrackList.cxx
CommitLineData
c1869a7c 1// Author: Benjamin Hess 29/01/2010
2670605d 2
3/*************************************************************************
c1869a7c 4 * Copyright (C) 2009-2010, Alexandru Bercuci, Benjamin Hess. *
2670605d 5 * All rights reserved. *
6 *************************************************************************/
7
c1869a7c 8
16db6074 9//////////////////////////////////////////////////////////////////////////
10// //
2670605d 11// AliEveTRDTrackList //
12// //
16db6074 13// An AliEveTRDTrackList is, in principal, a TEveElementList with some //
14// sophisticated features. You can add macros to this list, which then //
15// can be applied to the list of tracks (these tracks can be added to //
16// the list in the same way as for the TEveElementList). In general, //
17// please use AddMacro(...) for this purpose. //
18// Macros that are no longer needed can be removed from the list via //
38a30030 19// RemoveSelectedMacros(...).This function takes an iterator of the //
20// list of macros that are to be removed. //
16db6074 21// be removed. An entry looks like: //
38a30030 22// The data for each macro consists of path, name, type and the command //
23// that will be used to apply the macro. This stuff is stored in a map //
24// which takes the macro name for the key and the above mentioned data //
25// in a TMacroData-object for the value. //
26// You can get the macro type via GetMacroType(...). //
2670605d 27// With ApplySTSelectionMacros(...) or ApplyProcessMacros(...) //
16db6074 28// respectively you can apply the macros to the track list via //
38a30030 29// iterators (same style like for RemoveSelectedMacros(...)(cf. above)).//
16db6074 30// Selection macros (de-)select macros according to a selection rule //
31// by setting the rnr-state of the tracks. //
32// If multiple selection macros are applied, a track is selected, if //
33// all selection macros select the track. //
34// Process macros create data or histograms, which will be stored in //
35// a temporary file. The editor of this class will access this file //
36// and draw all the stuff within it's DrawHistos() function. The file //
37// will be deleted by the destructor. //
38// //
39// Currently, the following macro types are supported: //
40// Selection macros: //
41// Bool_t YourMacro(const AliTRDtrackV1*); //
42// Bool_t YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*); //
43// //
44// Process macros: //
45// void YourMacro(const AliTRDtrackV1*, Double_t*&, Int_t&); //
46// void YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*, //
47// Double_t*&, Int_t&); //
48// TH1* YourMacro(const AliTRDtrackV1*); //
49// TH1* YourMacro(const AliTRDtrackV1*, const AliTRDtrackV1*); //
50// //
38a30030 51// The macros which take 2 tracks are applied to all track pairs //
52// (whereby BOTH tracks of the pair have to be selected by the single //
53// track selection macros and have to be unequal, otherwise they will //
54// be skipped) that have been selected by ALL correlated tracks //
55// selection macros. The selection macros with 2 tracks do NOT affect //
56// process macros that process only a single track! //
16db6074 57//////////////////////////////////////////////////////////////////////////
58
59
caaf90d2 60// Uncomment to display debugging infos
61//#define ALIEVETRDTRACKLIST_DEBUG
62
caaf90d2 63#include <TFile.h>
64#include <TFunction.h>
c413e8d4 65#include <TH1.h>
caaf90d2 66#include <TList.h>
8bdeb570 67#include <TMap.h>
caaf90d2 68#include <TObjString.h>
69#include <TROOT.h>
70#include <TSystem.h>
71#include <TTree.h>
72#include <TTreeStream.h>
db16b708 73#include <TMethodCall.h>
74
75#include <AliTRDReconstructor.h>
76
db16b708 77#include <EveDet/AliEveTRDTrackList.h>
78#include <EveDet/AliEveTRDTrackListEditor.h>
79
5964947f 80#include <../PWG1/TRD/AliTRDrecoTask.h>
99535225 81#include <../PWG1/TRD/AliTRDpwg1Helper.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
00dc25ef 198 // We need this line... otherwise, in some cases, there will be problems concerning ACLIC
199 gROOT->ProcessLineSync(Form(".L %s", pathname));
200
38a30030 201 AliEveTRDTrackListMacroType type = GetMacroType(name, kFALSE);
caaf90d2 202
4f6473f6 203 // Clean up again
db16b708 204 // A.B. gROOT->Reset();
4f6473f6 205
caaf90d2 206 // Has not the correct signature!
38a30030 207 if (type == kUnknown) return SIGNATURE_ERROR;
caaf90d2 208
caaf90d2 209 // Only add macro, if it is not already in the list
db16b708 210 Int_t returnValue = WARNING;
211 if(fMacroList->GetValue(name) == 0) {
212 returnValue = AddMacroFast(path, name, type) ? SUCCESS : ERROR;
caaf90d2 213 }
caaf90d2 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//______________________________________________________
db16b708 263void AliEveTRDTrackList::AddStandardContent()
caaf90d2 264{
38a30030 265 // Adds standard macros to the macro list.
16db6074 266
99535225 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(...)))
db16b708 273
a6a6a16e 274 const Char_t *libs[] = {"libANALYSIS.so", "libANALYSISalice.so", "libTENDER.so", "libPWG1.so"};
22604c13 275 Int_t nlibs = static_cast<Int_t>(sizeof(libs)/sizeof(Char_t *));
276 for(Int_t ilib=0; ilib<nlibs; ilib++){
277 if(gSystem->Load(libs[ilib]) >= 0) continue;
278 AliError(Form("Fail loading %s.", libs[ilib]));
279 return;
280 }
281
99535225 282 const Char_t *fgkTRDPWG1taskClassName[AliTRDpwg1Helper::kNTRDQATASKS] = {
283 "AliTRDcheckESD"
284 ,"AliTRDinfoGen"
285 ,"AliTRDcheckDET"
286 ,"AliTRDefficiency"
287 ,"AliTRDresolution"
288 ,"AliTRDcheckPID"
289 ,"AliTRDv0Monitor"
290 };
291 AliTRDrecoTask *task(NULL);
292 TList *fPlots(NULL);
293 for(Int_t it=2; it<AliTRDpwg1Helper::kNTRDQATASKS; it++){
294 TClass c(fgkTRDPWG1taskClassName[it]);
db16b708 295 task = (AliTRDrecoTask*)c.New();
50db8cc0 296 task->SetMCdata(kFALSE);
db16b708 297 if(!(fPlots = task->GetPlotFunctors())){
50db8cc0 298 //AliWarning(Form("No Plot functors defined for task \"%s\"", fgkTRDtaskClassName[it]));
db16b708 299 delete task;
300 continue;
301 }
302 if(!(task->Histos())){
50db8cc0 303 //AliWarning(Form("No Ref Histograms defined for task \"%s\"", fgkTRDtaskClassName[it]));
db16b708 304 delete task;
305 continue;
306 }
307
308 // export task to CINT and add functions
99535225 309 gROOT->ProcessLine(Form("%s* %s = (%s*)%p;", fgkTRDPWG1taskClassName[it], task->GetName(), fgkTRDPWG1taskClassName[it], (void*)task));
db16b708 310 TIter iter(fPlots); TMethodCall *m = 0x0;
311 while((m = dynamic_cast<TMethodCall*>(iter()))){
312 AddMacroFast("", Form("%s->%s", task->GetName(), m->GetMethodName()), kSingleTrackHisto);
313 }
314 }
caaf90d2 315}
316
99535225 317
8e27fca1 318//______________________________________________________
2670605d 319Bool_t AliEveTRDTrackList::ApplyProcessMacros(const TList* selIterator, const TList* procIterator)
caaf90d2 320{
2670605d 321 // Uses the procIterator (for the selected process macros) to apply the selected macros to the data.
16db6074 322 // Returns kTRUE on success, otherwise kFALSE. If there no process macros selected, kTRUE is returned
323 // (this is no error!).
2670605d 324 // The single track process macros are applied to all selected tracks.
325 // The selIterator (for the selected selection macros) will be used to apply the correlated tracks selection
326 // macros to all track pairs (whereby BOTH tracks have to be selected, otherwise they will be skipped).
327 // All track pairs that have been selected by ALL correlated tracks selection macros will be processed by
328 // the correlated tracks process macros.
16db6074 329
ea24e1bc 330 // No process macros need to be processed
2670605d 331 if (procIterator->GetEntries() <= 0) return kTRUE;
ea24e1bc 332
333 // Clear root
db16b708 334 // A.B. gROOT->Reset();
ea24e1bc 335
336 // Clear old data and re-allocate
db16b708 337 if (fDataTree == 0x0){
338 TDirectory *cwd = gDirectory;
339 fDataTree = new TTreeSRedirector(Form("/tmp/TRD.TrackListMacroData_%s.root", gSystem->Getenv("USER")));
340 cwd->cd();
341 }
342 if (!fDataTree){
343 Error("Apply process macros", Form("File \"/tmp/TRD.TrackListMacroData_%s.root\" could not be accessed properly!", gSystem->Getenv("USER")));
ea24e1bc 344 return kFALSE;
345 }
346
db16b708 347 if (fDataFromMacroList != 0) {
e007877e 348 fDataFromMacroList->Delete();
349 delete fDataFromMacroList;
350 }
ea24e1bc 351 fDataFromMacroList = new TList();
e007877e 352 fDataFromMacroList->TCollection::SetOwner(kTRUE);
ea24e1bc 353
354 fHistoDataSelected = 0;
355
8e27fca1 356
38a30030 357 TMacroData* macro = 0;
358
d52fea52 359 TString* procCmds = 0;
38a30030 360 AliEveTRDTrackListMacroType* mProcType = 0;
db16b708 361 if (procIterator->GetEntries() > 0) {
d52fea52 362 procCmds = new TString[procIterator->GetEntries()];
38a30030 363 mProcType = new AliEveTRDTrackListMacroType[procIterator->GetEntries()];
364 }
2670605d 365
a0987c46 366 TString* selCmds(NULL);
38a30030 367 AliEveTRDTrackListMacroType* mSelType = 0;
db16b708 368 if (selIterator->GetEntries() > 0) {
d52fea52 369 selCmds = new TString[selIterator->GetEntries()];
38a30030 370 mSelType = new AliEveTRDTrackListMacroType[selIterator->GetEntries()];
371 }
372
2670605d 373 Bool_t selectedByCorrSelMacro = kFALSE;
c413e8d4 374
8bdeb570 375 AliEveTRDTrackListMacroType macroType = kUnknown;
c413e8d4 376 Int_t numHistoMacros = 0;
377 TH1** histos = 0;
caaf90d2 378
a0987c46 379 AliEveTRDTrack* track1(NULL);
380 AliEveTRDTrack* track2(NULL);
caaf90d2 381
2670605d 382 // Collect the commands for each process macro and add them to "data-from-list"
db16b708 383 for (Int_t i = 0; i < procIterator->GetEntries(); i++){
38a30030 384 macro = (TMacroData*)fMacroList->GetValue(procIterator->At(i)->GetTitle());
e007877e 385
db16b708 386 if (!macro){
38a30030 387 Error("Apply process macros",
db16b708 388 Form("Macro list is corrupted: Macro \"%s\" is not registered!",
389 procIterator->At(i)->GetTitle()));
38a30030 390 continue;
e007877e 391 }
38a30030 392
393#ifdef ALIEVETRDTRACKLIST_DEBUG
394 printf("AliEveTRDTrackList: Checking process macro: %s\n", macro->GetName());
395#endif
396
397 // Find the type of the process macro
398 macroType = macro->GetType();
db16b708 399 if (macroType == kSingleTrackHisto || macroType == kCorrelTrackHisto){
2670605d 400 mProcType[i] = macroType;
8bdeb570 401 numHistoMacros++;
402 // Create the command
d52fea52 403 procCmds[i] = macro->GetCmd();
8bdeb570 404
405 // Add to "data-from-list" -> Mark as a histo macro with the substring "(histo macro)"
38a30030 406 fDataFromMacroList->Add(new TObjString(Form("%s (histo macro)", macro->GetName())));
db16b708 407 } else if (macroType == kSingleTrackAnalyse || macroType == kCorrelTrackAnalyse) {
2670605d 408 mProcType[i] = macroType;
c413e8d4 409 // Create the command
d52fea52 410 procCmds[i] = macro->GetCmd();
8bdeb570 411
412 // Add to "data-from-list"
38a30030 413 fDataFromMacroList->Add(new TObjString(macro->GetName()));
db16b708 414 } else {
8bdeb570 415 Error("Apply process macros",
db16b708 416 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a process macro!",
417 macro->GetPath(), macro->GetName()));
2670605d 418 mProcType[i] = kUnknown;
419 }
420 }
421
422 // Collect the commands for each selection macro and add them to "data-from-list"
db16b708 423 for (Int_t i = 0; i < selIterator->GetEntries(); i++){
38a30030 424 macro = (TMacroData*)fMacroList->GetValue(selIterator->At(i)->GetTitle());
425
db16b708 426 if (!macro){
38a30030 427 Error("Apply process macros",
db16b708 428 Form("Macro list is corrupted: Macro \"%s\" is not registered!",
429 selIterator->At(i)->GetTitle()));
38a30030 430 continue;
2670605d 431 }
38a30030 432
433#ifdef ALIEVETRDTRACKLIST_DEBUG
434 printf("AliEveTRDTrackList: Checking selection macro: %s\n", macro->GetName());
435#endif
2670605d 436
437 // Find the type of the process macro
38a30030 438 macroType = macro->GetType();
439
2670605d 440 // Single track select macro
db16b708 441 if (macroType == kSingleTrackSelect) {
2670605d 442 // Has already been processed by ApplySTSelectionMacros(...)
443 mSelType[i] = macroType;
444 }
445 // Correlated tracks select macro
db16b708 446 else if (macroType == kCorrelTrackSelect) {
2670605d 447 mSelType[i] = macroType;
448
449 // Create the command
d52fea52 450 selCmds[i] = macro->GetCmd();
db16b708 451 } else {
2670605d 452 Error("Apply process macros",
db16b708 453 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a selection macro!",
454 macro->GetPath(), macro->GetName()));
38a30030 455 mSelType[i] = kUnknown;
c413e8d4 456 }
8e27fca1 457 }
c413e8d4 458
459 // Allocate memory for the histograms
460 if (numHistoMacros > 0) histos = new TH1*[numHistoMacros];
db16b708 461 for (Int_t i = 0; i < numHistoMacros; i++) histos[i] = 0x0;
38a30030 462
caaf90d2 463
db16b708 464 //////////////////////////////////
465 // WALK THROUGH THE LIST OF TRACKS
466 //////////////////////////////////
467 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter){
468 if(!(track1 = dynamic_cast<AliEveTRDTrack*>(*iter))) continue;
469
caaf90d2 470 // Skip tracks that have not been selected
e007877e 471 if (!track1->GetRnrState()) continue;
38a30030 472
caaf90d2 473 // Cast to AliTRDtrackV1
c51e9ba0 474 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)%p;", (void*)track1));
e007877e 475 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
caaf90d2 476
477 // Collect data for each macro
db16b708 478 for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries(); i++){
e007877e 479 // Single track histo
db16b708 480 if (mProcType[i] == kSingleTrackHisto){
481 histos[histoIndex++] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
482 // Correlated tracks histo
483 } else if (mProcType[i] == kCorrelTrackHisto) {
e007877e 484 // Loop over all pairs behind the current one - together with the other loop this will be a loop
485 // over all pairs. We have a pair of tracks, if and only if both tracks of the pair are selected (Rnr-state)
486 // and are not equal.
00dc25ef 487 // The correlated tracks process macro will be applied to all pairs that will be additionally selected by
2670605d 488 // all correlated tracks selection macros.
e007877e 489 TEveElement::List_i iter2 = iter;
490 iter2++;
491 for ( ; iter2 != this->EndChildren(); ++iter2)
492 {
db16b708 493 if(!(track2 = dynamic_cast<AliEveTRDTrack*>(*iter2))) continue;
e007877e 494
e007877e 495 // Skip tracks that have not been selected
496 if (!track2->GetRnrState()) continue;
497
e007877e 498 // Cast to AliTRDtrackV1
c51e9ba0 499 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)%p;", (void*)track2));
e007877e 500 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_2 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
501
2670605d 502 // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
503 selectedByCorrSelMacro = kTRUE;
db16b708 504 for (Int_t j = 0; j < selIterator->GetEntries(); j++){
505 if (mSelType[j] == kCorrelTrackSelect){
2670605d 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
db16b708 514 histos[histoIndex] = (TH1*)gROOT->ProcessLineSync(procCmds[i]);
e007877e 515 }
516 histoIndex++;
517 }
518 // Single track analyse
db16b708 519 else if (mProcType[i] == kSingleTrackAnalyse) {
c413e8d4 520 // Create data pointers in CINT, execute the macro and get the data
521 gROOT->ProcessLineSync("Double_t* results = 0;");
522 gROOT->ProcessLineSync("Int_t n = 0;");
2670605d 523 gROOT->ProcessLineSync(procCmds[i]);
c413e8d4 524 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
525 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
526
db16b708 527 if (results == 0) {
2670605d 528 Error("Apply macros", Form("Error reading data from macro \"%s\"", procIterator->At(i)->GetTitle()));
c413e8d4 529 continue;
530 }
db16b708 531 for (Int_t resInd = 0; resInd < nResults; resInd++){
c413e8d4 532 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
533 }
caaf90d2 534
c413e8d4 535 delete results;
536 results = 0;
537 }
e007877e 538 // Correlated tracks analyse
db16b708 539 else if (mProcType[i] == kCorrelTrackAnalyse){
e007877e 540 // Loop over all pairs behind the current one - together with the other loop this will be a loop
541 // over all pairs. We have a pair of tracks, if and only if both tracks of the pair are selected (Rnr-state)
542 // and are not equal.
00dc25ef 543 // The correlated tracks process macro will be applied to all pairs that will be additionally selected by
2670605d 544 // all correlated tracks selection macros.
e007877e 545 TEveElement::List_i iter2 = iter;
546 iter2++;
38a30030 547
db16b708 548 for ( ; iter2 != this->EndChildren(); ++iter2) {
549 if(!(track2 = dynamic_cast<AliEveTRDTrack*>(*iter2))) continue;
38a30030 550
e007877e 551 // Skip tracks that have not been selected
552 if (!track2->GetRnrState()) continue;
38a30030 553
e007877e 554 // Cast to AliTRDtrackV1
c51e9ba0 555 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)%p;", (void*)track2));
e007877e 556 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_2 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
557
2670605d 558 // Select track by default (so it will be processed, if there are no correlated tracks selection macros!)
559 selectedByCorrSelMacro = kTRUE;
db16b708 560 for (Int_t j = 0; j < selIterator->GetEntries(); j++) {
561 if (mSelType[j] == kCorrelTrackSelect) {
2670605d 562 selectedByCorrSelMacro = (Bool_t)gROOT->ProcessLineSync(selCmds[j]);
563 if (!selectedByCorrSelMacro) break;
564 }
565 }
566
567 // If the pair has not been selected by the correlated tracks selection macros, skip it!
568 if (!selectedByCorrSelMacro) continue;
569
e007877e 570 // Create data pointers in CINT, execute the macro and get the data
571 gROOT->ProcessLineSync("Double_t* results = 0;");
572 gROOT->ProcessLineSync("Int_t n = 0;");
2670605d 573 gROOT->ProcessLineSync(procCmds[i]);
e007877e 574 Double_t* results = (Double_t*)gROOT->ProcessLineSync("results;");
575 Int_t nResults = (Int_t)gROOT->ProcessLineSync("n;");
38a30030 576
db16b708 577 if (results == 0) {
2670605d 578 Error("Apply macros", Form("Error reading data from macro \"%s\"", procIterator->At(i)->GetTitle()));
e007877e 579 continue;
580 }
db16b708 581 for (Int_t resInd = 0; resInd < nResults; resInd++) {
e007877e 582 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << results[resInd] << (Char_t*)"\n";
583 }
584
585 delete results;
586 results = 0;
587 }
588 }
caaf90d2 589 }
590 }
caaf90d2 591
db16b708 592 for (Int_t i = 0, histoIndex = 0; i < procIterator->GetEntries() && histoIndex < numHistoMacros; i++) {
593 if (mProcType[i] == kSingleTrackHisto || mProcType[i] == kCorrelTrackHisto) {
5715955a 594 // Might be empty (e.g. no tracks have been selected)!
db16b708 595 if (histos[histoIndex]) {
5715955a 596 (*fDataTree) << Form("TrackData%d", i) << Form("Macro%d=", i) << histos[histoIndex] << (Char_t*)"\n";
597 }
598 histoIndex++;
599 }
c413e8d4 600 }
601
602 if (fDataTree != 0) delete fDataTree;
caaf90d2 603 fDataTree = 0;
604
2670605d 605 if (procCmds != 0) delete [] procCmds;
38a30030 606 procCmds = 0;
4ce766eb 607 if (mProcType != 0) delete [] mProcType;
2670605d 608 mProcType = 0;
609
610 if (selCmds != 0) delete [] selCmds;
38a30030 611 selCmds = 0;
63424920 612 if (mSelType != 0) delete [] mSelType;
2670605d 613 mSelType = 0;
c413e8d4 614
615 if (histos != 0) delete [] histos;
616 histos = 0;
8e27fca1 617
caaf90d2 618 // Clear root
db16b708 619 // A.B. gROOT->Reset();
caaf90d2 620
4f6473f6 621 // If there is data, select the first data set
2670605d 622 if (procIterator->GetEntries() > 0) SETBIT(fHistoDataSelected, 0);
4f6473f6 623
e007877e 624 // Now the data is stored in "/tmp/TRD.TrackListMacroData_$USER.root"
caaf90d2 625 // The editor will access this file to display the data
ea24e1bc 626 return kTRUE;
caaf90d2 627}
628
8e27fca1 629//______________________________________________________
2670605d 630void AliEveTRDTrackList::ApplySTSelectionMacros(const TList* iterator)
caaf90d2 631{
16db6074 632 // Uses the iterator (for the selected selection macros) to apply the selected macros to the data.
633 // The rnr-states of the tracks are set according to the result of the macro calls (kTRUE, if all
634 // macros return kTRUE for this track, otherwise: kFALSE).
2670605d 635 // "ST" stands for "single track". This means that only single track selection macros are applied.
636 // Correlated tracks selection macros will be used inside the call of ApplyProcessMacros(...)!
16db6074 637
38a30030 638 TMacroData* macro = 0;
e007877e 639 AliEveTRDTrackListMacroType macroType = kUnknown;
640 AliEveTRDTrack* track1 = 0;
caaf90d2 641 Bool_t selectedByMacro = kFALSE;
642
643 // Clear root
db16b708 644 // A.B. gROOT->Reset();
caaf90d2 645
00dc25ef 646 // Select all tracks at first. A track is then deselected, if at least one selection macro
647 // returns kFALSE for this track.
648 // Enable all tracks (Note: EnableListElements(..) will call "ElementChanged", which will cause unforeseen behaviour!)
db16b708 649 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter) ((TEveElement*)(*iter))->SetRnrState(kTRUE);
4f6473f6 650 SetRnrState(kTRUE);
651
db16b708 652 for (Int_t i = 0; i < iterator->GetEntries(); i++){
38a30030 653 macro = (TMacroData*)fMacroList->GetValue(iterator->At(i)->GetTitle());
4f6473f6 654
db16b708 655 if (!macro){
38a30030 656 Error("Apply selection macros",
657 Form("Macro list is corrupted: Macro \"%s\" is not registered!", iterator->At(i)->GetTitle()));
658 continue;
659 }
caaf90d2 660
661#ifdef ALIEVETRDTRACKLIST_DEBUG
38a30030 662 printf("AliEveTRDTrackList: Applying selection macro: %s\n", macro->GetName());
caaf90d2 663#endif
caaf90d2 664
e007877e 665 // Determine macro type
38a30030 666 macroType = macro->GetType();
caaf90d2 667
e007877e 668 // Single track select macro
db16b708 669 if (macroType == kSingleTrackSelect){
e007877e 670 // Walk through the list of tracks
671 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
672 {
673 track1 = dynamic_cast<AliEveTRDTrack*>(*iter);
674
675 if (!track1) continue;
676
677 // If the track has already been deselected, nothing is to do here
678 if (!track1->GetRnrState()) continue;
679
e007877e 680 // Cast to AliTRDtrackV1
c51e9ba0 681 gROOT->ProcessLineSync(Form("AliEveTRDTrack *automaticTrack = (AliEveTRDTrack*)%p;", (void*)track1));
38a30030 682 gROOT->ProcessLineSync("AliTRDtrackV1* automaticTrackV1_1 = (AliTRDtrackV1*)automaticTrack->GetUserData();");
683 selectedByMacro = (Bool_t)gROOT->ProcessLineSync(macro->GetCmd());
e007877e 684 track1->SetRnrState(selectedByMacro && track1->GetRnrState());
685 }
686 }
687 // Correlated tracks select macro
db16b708 688 else if (macroType == kCorrelTrackSelect){
2670605d 689 // Will be processed in ApplyProcessMacros(...)
690 continue;
db16b708 691 } else {
e007877e 692 Error("Apply selection macros",
db16b708 693 Form("Macro list corrupted: Macro \"%s/%s.C\" is not registered as a selection macro!",
694 macro->GetPath(), macro->GetName()));
e007877e 695 }
caaf90d2 696 }
697
698 // Clear root
db16b708 699 // A.B. gROOT->Reset();
caaf90d2 700}
701
8bdeb570 702//______________________________________________________
38a30030 703AliEveTRDTrackList::AliEveTRDTrackListMacroType AliEveTRDTrackList::GetMacroType(const Char_t* name, Bool_t UseList) const
8bdeb570 704{
38a30030 705 // Returns the type of the corresponding macro.
16db6074 706 // If "UseList" is kTRUE, the type will be looked up in the internal list (very fast). But if this list
707 // does not exist, you have to use kFALSE for this parameter. Then the type will be determined by the
708 // prototype! NOTE: It is assumed that the macro has been compiled! If not, the return value is not
709 // predictable, but normally will be kUnknown.
38a30030 710 // Note: AddMacro(Fast) will update the internal list and RemoveMacros respectively.
16db6074 711
8bdeb570 712 AliEveTRDTrackListMacroType type = kUnknown;
713
38a30030 714 // Re-do the check of the macro type
db16b708 715 if (!UseList){
e007877e 716 // Single track select macro or single track histo macro?
8bdeb570 717 TFunction* f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*", kTRUE);
718 if (f != 0x0)
719 {
720 // Some additional check (is the parameter EXACTLY of the desired type?)
721 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0)
722 {
e007877e 723 // Single track select macro?
8bdeb570 724 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
725 {
e007877e 726 type = kSingleTrackSelect;
8bdeb570 727 }
e007877e 728 // single track histo macro?
8bdeb570 729 else if (!strcmp(f->GetReturnTypeName(), "TH1*"))
730 {
e007877e 731 type = kSingleTrackHisto;
8bdeb570 732 }
733 }
734 }
e007877e 735 // Single track analyse macro?
8bdeb570 736 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE))
737 != 0x0)
738 {
739 if (!strcmp(f->GetReturnTypeName(), "void"))
740 {
741 // Some additional check (are the parameters EXACTLY of the desired type?)
742 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
743 strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 &&
744 strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0)
745 {
e007877e 746 type = kSingleTrackAnalyse;
747 }
748 }
749 }
750 // Correlated tracks select macro or correlated tracks histo macro?
751 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name, "const AliTRDtrackV1*, const AliTRDtrackV1*", kTRUE))
752 != 0x0)
753 {
754 // Some additional check (is the parameter EXACTLY of the desired type?)
755 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
756 strstr(f->GetMangledName(), "cOconstsPAliTRDtrackV1mUsP") != 0x0)
757 {
00dc25ef 758 // Correlated track select macro?
e007877e 759 if (!strcmp(f->GetReturnTypeName(), "Bool_t"))
760 {
761 type = kCorrelTrackSelect;
762 }
00dc25ef 763 // Correlated track histo macro?
e007877e 764 else if (!strcmp(f->GetReturnTypeName(), "TH1*"))
765 {
766 type = kCorrelTrackHisto;
767 }
768 }
769 }
770 // Correlated tracks analyse macro?
771 else if ((f = gROOT->GetGlobalFunctionWithPrototype(name,
772 "const AliTRDtrackV1*, const AliTRDtrackV1*, Double_t*&, Int_t&", kTRUE))
773 != 0x0)
774 {
775 if (!strcmp(f->GetReturnTypeName(), "void"))
776 {
777 // Some additional check (is the parameter EXACTLY of the desired type?)
778 if (strstr(f->GetMangledName(), "oPconstsPAliTRDtrackV1mUsP") != 0x0 &&
779 strstr(f->GetMangledName(), "cOconstsPAliTRDtrackV1mUsP") != 0x0 &&
780 strstr(f->GetMangledName(), "cODouble_tmUaNsP") != 0x0 &&
781 strstr(f->GetMangledName(), "cOInt_taNsP") != 0x0)
782 {
783 type = kCorrelTrackAnalyse;
8bdeb570 784 }
785 }
786 }
787 }
788 // Use list to look up the macro type
789 else
790 {
38a30030 791 TMacroData* macro = 0;
792 macro = (TMacroData*)fMacroList->GetValue(name);
793 if (macro == 0) return kUnknown;
8bdeb570 794
38a30030 795 type = macro->GetType();
8bdeb570 796 switch (type)
797 {
e007877e 798 case kSingleTrackSelect:
799 case kSingleTrackAnalyse:
800 case kSingleTrackHisto:
801 case kCorrelTrackSelect:
802 case kCorrelTrackAnalyse:
803 case kCorrelTrackHisto:
8bdeb570 804 break;
805 default:
806 type = kUnknown;
807 break;
808 }
809 }
810
811 return type;
812}
813
8e27fca1 814//______________________________________________________
38a30030 815void AliEveTRDTrackList::RemoveSelectedMacros(const TList* iterator)
caaf90d2 816{
38a30030 817 // Uses the iterator (for the selected macros) to remove the selected macros from
16db6074 818 // the corresponding list.
819
38a30030 820 TObject* key = 0;
821 TPair* entry = 0;
caaf90d2 822 for (Int_t i = 0; i < iterator->GetEntries(); i++)
823 {
38a30030 824 entry = (TPair*)fMacroList->FindObject(iterator->At(i)->GetTitle());
8bdeb570 825
38a30030 826 if (entry == 0)
827 {
828 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Macro \"%s\" not found in list!",
829 iterator->At(i)->GetTitle()));
830 continue;
831 }
832 key = entry->Key();
caaf90d2 833
38a30030 834 if (key == 0)
835 {
836 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Key for macro \"%s\" not found in list!",
837 iterator->At(i)->GetTitle()));
838 continue;
839 }
840
841 // Key and value will be deleted, too, since fMacroList is the owner of them
842 Bool_t rem = fMacroList->DeleteEntry(key);
8bdeb570 843
38a30030 844 if (rem)
845 {
846#ifdef ALIEVETRDTRACKLIST_DEBUG
847 printf("AliEveTRDTrackList::RemoveSelectedMacros(): Removed macro: %s\n", iterator->At(i)->GetTitle());
848#endif
849 }
850 else
851 {
852 Error("AliEveTRDTrackList::RemoveSelectedMacros", Form("Macro \"%s\" could not be removed from the list!",
853 iterator->At(i)->GetTitle()));
854 }
caaf90d2 855 }
2ef0687e 856}
4f6473f6 857
ecbbe371 858//______________________________________________________
859void AliEveTRDTrackList::UpdateTrackStyle(AliEveTRDTrack::AliEveTRDTrackState s, UChar_t ss)
860{
16db6074 861 // Updates the track style and sets this style for each track.
862
8bdeb570 863 switch(s)
864 {
e007877e 865 case AliEveTRDTrack::kSource:
866 SETBIT(fSelectedStyle, AliEveTRDTrack::kSource);
867 break;
868 case AliEveTRDTrack::kPID:
869 CLRBIT(fSelectedStyle, AliEveTRDTrack::kSource);
870 switch(ss)
871 {
9443fb9d 872 case AliTRDpidUtil::kLQ:
e007877e 873 CLRBIT(fSelectedStyle, AliEveTRDTrack::kPID);
874 break;
9443fb9d 875 case AliTRDpidUtil::kNN:
e007877e 876 SETBIT(fSelectedStyle, AliEveTRDTrack::kPID);
877 break;
878 }
879 break;
880 case AliEveTRDTrack::kTrackCosmics:
881 SETBIT(fSelectedStyle, AliEveTRDTrack::kTrackCosmics);
882 break;
883 case AliEveTRDTrack::kTrackModel:
884 CLRBIT(fSelectedStyle, AliEveTRDTrack::kTrackCosmics);
885 switch(ss)
886 {
887 case AliEveTRDTrack::kRieman:
888 CLRBIT(fSelectedStyle, AliEveTRDTrack::kTrackModel);
889 break;
890 case AliEveTRDTrack::kKalman:
12896fe5 891 //AliWarning("Kalman fit under testing for the moment.");
892 SETBIT(fSelectedStyle, AliEveTRDTrack::kTrackModel);
e007877e 893 break;
894 }
895 break;
ecbbe371 896 }
897
898
ecbbe371 899 // Walk through the list of tracks
900 AliEveTRDTrack* track = 0x0;
8bdeb570 901 for (TEveElement::List_i iter = this->BeginChildren(); iter != this->EndChildren(); ++iter)
902 {
ecbbe371 903 if (!(track = dynamic_cast<AliEveTRDTrack*>(*iter))) continue;
904
905 track->SetStatus(fSelectedStyle);
906 }
907}