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