]> git.uio.no Git - u/mrichter/AliRoot.git/blob - doc/Distributed-Analysis/Interactive.tex
- AliMUONRecoParam.cxx:
[u/mrichter/AliRoot.git] / doc / Distributed-Analysis / Interactive.tex
1 %________________________________________________________
2 \section{Interactive analysis with GRID ESDs}
3 \label{Note:INTERACTIVE}
4
5 Once the first step described in Section \ref{Note:LOCAL} was successful and we are satisfied from both the code and the results, we are ready to validate our code on a larger data sample. In this section we will describe how we can analyze interactively (that is sitting in from of a terminal and getting back the results in our screen) files that are stored in the Grid. We will once again concentrate in the case where we use the \tag\ \cite{Note:RefAlienTutorial,Note:RefEventTagWeb}.
6
7 The first thing that we need to create is a collection of tag files by querying the file catalog (for details on this process the reader should look either in the example of section \ref{Note:FLOW} or in \cite{Note:RefFileCatalogMetadataNote,Note:RefFileCatalogMetadataWeb}). These tag files, which are registered in the Grid, are the official ones created as a last step of the reconstruction code \cite{Note:RefEventTagNote}. Once we have a valid xml collection, we launch a ROOT session, we setup the {\ttfamily par file} (the way to do this has been described in detail in section \ref{Note:FLOW}), we apply some selection criteria and we query the \tag which returns the desired events in the proper format (TChain along with the associated list of events that satisfy our cuts). The following lines give a snapshot of how a typical code should look like:
8
9 \vspace{0.5 cm}
10 \textbf{Usage of AliRunTagCuts and AliEventTagCuts classes}
11 \begin{lstlisting}[language=C++]
12   // Case where the tag files are stored in the file catalog
13   // tag.xml is the xml collection of tag files that was produced 
14   // by querying the file catalog.
15   TGrid::Connect("alien://"); 
16   TAlienCollection* coll = TAlienCollection::Open("tag.xml");
17   TGridResult* tagResult = coll->GetGridResult("");
18
19   // Create a RunTagCut object
20   AliRunTagCuts *runCutsObj = new AliRunTagCuts();
21   runCutsObj->SetRunId(340);
22
23   // Create an EventTagCut object
24   AliEventTagCuts *evCutsObj = new AliEventTagCuts();
25   evCutsObj->SetMultiplicityRange(2, 100);
26
27   // Create a new AliTagAnalysis object and chain the grid stored tags
28   AliTagAnalysis *tagAna = new AliTagAnalysis(); 
29   tagAna->ChainGridTags(tagResult);
30
31   // Cast the output of the query to a TChain
32   TChain *analysisChain = tagAna->QueryTags(runCutsObj, evCutsObj);
33
34   // Process the chain with a manager
35   AliAnalysisManager *mgr = new AliAnalysisManager();
36   AliAnalysisTask *task1 = new AliAnalysisTaskPt("TaskPt");
37   mgr->AddTask(task1);
38
39   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1", 
40   TChain::Class(),AliAnalysisManager::kInputContainer);
41   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("chist1", 
42   TH1::Class(),AliAnalysisManager::kOutputContainer);
43   mgr->ConnectInput(task1,0,cinput1);
44   mgr->ConnectOutput(task1,0,coutput1);
45   cinput1->SetData(analysisChain);
46   
47   if (mgr->InitAnalysis()) {
48     mgr->PrintStatus();
49     analysisChain->Process(mgr);
50   }
51 \end{lstlisting}
52
53 \vspace{0.5 cm}
54 \textbf{Usage of string statements}
55 \begin{lstlisting}[language=C++]
56   // Case where the tag files are stored in the file catalog
57   // tag.xml is the xml collection of tag files that was produced 
58   // by querying the file catalog.
59   TGrid::Connect("alien://"); 
60   TAlienCollection* coll = TAlienCollection::Open("tag.xml");
61   TGridResult* tagResult = coll->GetGridResult("");
62
63   //Usage of string statements//
64   const char* runCutsStr = "fAliceRunId == 340";
65   const char* evCutsStr = "fEventTag.fNumberOfTracks >= 2 &&
66   fEventTag.fNumberOfTracks <= 100";
67
68   // Create a new AliTagAnalysis object and chain the grid stored tags
69   AliTagAnalysis *tagAna = new AliTagAnalysis(); 
70   tagAna->ChainGridTags(tagResult);
71
72   // Cast the output of the query to a TChain
73   TChain *analysisChain = tagAna->QueryTags(runCutsStr, evCutsStr);
74
75   // Process the chain with a manager
76   AliAnalysisManager *mgr = new AliAnalysisManager();
77   AliAnalysisTask *task1 = new AliAnalysisTaskPt("TaskPt");
78   mgr->AddTask(task1);
79
80   AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1",
81   TChain::Class(),AliAnalysisManager::kInputContainer);
82   AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("chist1", 
83   TH1::Class(),AliAnalysisManager::kOutputContainer);
84   mgr->ConnectInput(task1,0,cinput1);
85   mgr->ConnectOutput(task1,0,coutput1);
86   cinput1->SetData(analysisChain);
87   
88   if (mgr->InitAnalysis()) {
89     mgr->PrintStatus();
90     analysisChain->Process(mgr);
91   }
92 \end{lstlisting}
93
94
95 \noindent We will now review the previous lines. Since we would like to access Grid stored files we have to connect to the API server using the corresponding ROOT classes:\\
96 \\
97 {\ttfamily TGrid::Connect("alien://");}\\
98
99 Then we create a {\ttfamily TAlienCollection} object by opening the xml file (tag.xml) and we convert it to a {\ttfamily TGridResult}:\\
100 \\
101 {\ttfamily TAlienCollection* coll = TAlienCollection::Open("tag.xml");}\\
102 {\ttfamily TGridResult* tagResult = coll->GetGridResult("");}\\
103
104 \noindent where \textbf{tag.xml} is the name of the file (which is stored in the working directory) having the collection of tag files. 
105
106 The difference of the two cases is located in the way we apply the event tag cuts. In the first case, we create an {\ttfamily AliRunTagCuts} and an {\ttfamily AliEventTagCuts} object and impose our criteria at the run and event level of the \tag, while in the second we use the string statements to do so. The corresponding lines have already been descibe in the previous section. 
107
108
109 Regardless of the way we define our cuts, we need to initialize an {\ttfamily AliTagAnalysis} object and chain the GRID stored tags by providing as an argument to the {\ttfamily ChainGridTags} function the {\ttfamily TGridResult} we had created before:\\
110 \\
111 {\ttfamily AliTagAnalysis *tagAna = new AliTagAnalysis();}\\
112 {\ttfamily tagAna->ChainGridTags(tagResult);}\\
113
114 We then query the \tag, using the imposed selection criteria and we end up having the chain of ESD files along with the associated event list (list of the events that fulfill the criteria):\\
115 \\
116 {\ttfamily TChain *analysisChain = tagAna->QueryTags(runCutsObj, evCutsObj);}\\
117 \noindent, for the first case (usage of objects), or: \\
118 \\
119 {\ttfamily TChain *analysisChain = tagAna->QueryTags(runCutsStr, evCutsStr);}\\
120 \noindent, for the second case (usage of sting statements).
121
122 Finally we process this {\ttfamily TChain} by invoking our implemented task using a manager:\\
123 \\
124 {\ttfamily  AliAnalysisManager *mgr = new AliAnalysisManager();}\\
125 {\ttfamily  AliAnalysisTask *task1 = new AliAnalysisTaskPt("TaskPt");}\\
126 {\ttfamily  mgr->AddTask(task1);}\\
127 {\ttfamily  AliAnalysisDataContainer *cinput1 = mgr->CreateContainer("cchain1", TChain::Class(),AliAnalysisManager::kInputContainer);}\\
128 {\ttfamily  AliAnalysisDataContainer *coutput1 = mgr->CreateContainer("chist1", TH1::Class(),AliAnalysisManager::kOutputContainer);}\\
129 {\ttfamily  mgr->ConnectInput(task1,0,cinput1);}\\
130 {\ttfamily  mgr->ConnectOutput(task1,0,coutput1);}\\
131 {\ttfamily  cinput1->SetData(analysisChain);}\\  
132 {\ttfamily  if (mgr->InitAnalysis()) {mgr->PrintStatus();analysisChain->Process(mgr);}}\\
133
134 All the needed files to run this example can be found inside the PWG2 module of AliRoot under the AnalysisMacros/Interactive directory.
135