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