Added AliRsnAction, fix for AliRsnPIDRange, lego_train macros updated
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / macros / lego_train / RsnConfig.C
1 #ifndef __CINT__
2 #include <AliAnalysisManager.h>
3 #include <PWGLF/RESONANCES/AliRsnCutPrimaryVertex.h>
4 #include <PWGLF/RESONANCES/AliRsnValuePair.h>
5 #include <PWGLF/RESONANCES/AliRsnListOutput.h>
6 #include <PWGLF/RESONANCES/AliRsnPairDef.h>
7 #include <PWGLF/RESONANCES/AliRsnLoopPair.h>
8 #include <PWGLF/RESONANCES/AliRsnAnalysisTask.h>
9 #include <PWGLF/RESONANCES/AliRsnLoopDaughter.h>
10 #include <PWGLF/RESONANCES/AliRsnValueDaughter.h>
11 #include <PWGLF/RESONANCES/AliRsnMiniAnalysisTask.h>
12 #include <PWGLF/RESONANCES/AliRsnCutMiniPair.h>
13 #include <PWGLF/RESONANCES/AliRsnInputHandler.h>
14 #include <PWGLF/RESONANCES/AliRsnMiniMonitor.h>
15 #include <PWGLF/RESONANCES/AliRsnValueEvent.h>
16 #include <AliRsnMiniMonitorTask.h>
17 #endif
18
19 Bool_t RsnConfig(AliAnalysisTaskSE *task,Bool_t isMC,Bool_t isMixing,AliRsnInputHandler *rsnIH=0,TList *listRsn=0) {
20
21    if (!task) return kFALSE;
22
23    if (!listRsn) {
24       return kFALSE;
25    }
26    Bool_t valid;
27    Int_t isRsnMini = AliAnalysisManager::GetGlobalInt("rsnUseMiniPackage",valid);
28    TString rsnCutOptCommon = AliAnalysisManager::GetGlobalStr("rsnLegoTrainCommonCutOption",valid);
29    Int_t cutIndex = 0;
30    Int_t numOfCuts = 0;
31
32    // set commol eventCuts
33
34    if (!RsnLoadMacroFromConfig("AddRsnCommonEventCuts.C")) return kFALSE;
35    AliRsnCutSet *commonEventCuts = AddRsnCommonEventCuts(task);
36
37    if (!RsnLoadMacroFromConfig("AddRsnCommonPairCuts.C")) return kFALSE;
38    AliRsnCutSet *commonPairCuts = AddRsnCommonPairCuts();
39
40    TIter next(listRsn);
41    TNamed *rsnObj=0;
42    TString rsnName,rsnNameOpt,rsnNameOptFull,rsnCutName,rsnCutOpt,rsnCutNameOptFull;
43    while ((rsnObj = (TNamed *)next())) {
44       GetOptionFromString(rsnObj->GetName(),rsnName,rsnNameOpt);
45       rsnNameOptFull=rsnName;
46       if (!rsnNameOpt.IsNull()) rsnNameOptFull += Form("_%s",rsnNameOpt.Data());
47
48       GetOptionFromString(rsnObj->GetTitle(),rsnCutName,rsnCutOpt);
49       rsnCutNameOptFull=rsnCutName;
50       if (!rsnCutOpt.IsNull())rsnCutNameOptFull += Form("_%s",rsnCutOpt.Data());
51
52       if (!rsnCutOptCommon.IsNull()) {
53          if (!rsnCutOpt.IsNull()) rsnCutOpt += "_";
54          rsnCutOpt += rsnCutOptCommon.Data();
55       }
56
57       if (!RsnLoadMacroFromConfig(Form("AddRsnDaughterCuts%s.C",rsnCutName.Data()))) return kFALSE;
58       if (!RsnLoadMacroFromConfig(Form("AddRsnPairs%s.C",rsnName.Data()))) return kFALSE;
59
60       rsnNameOptFull.ToLower();
61       rsnName.ToLower();
62       // add cuts
63       if (!rsnName.CompareTo("phi")) {
64          numOfCuts = gROOT->ProcessLine(Form("AddRsnDaughterCuts%s(AliPID::kKaon,AliPID::kKaon,\"%s\",%d,(AliRsnInputHandler*)%p,(AliAnalysisTaskSE*)%p)",rsnCutName.Data(), rsnCutOpt.Data(),isRsnMini,rsnIH, task));
65          if (numOfCuts) {
66             if (rsnNameOpt.Contains("mon")) AddParticleMonitor(task,isMC,cutIndex,commonEventCuts,commonPairCuts,Form("%s_%s_K",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
67             AddRsnPairsPhi(task,isMC,isMixing,AliPID::kKaon,cutIndex,AliPID::kKaon,cutIndex,commonEventCuts,commonPairCuts,Form("%s_%s",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
68             cutIndex+=numOfCuts;
69          }
70       } else if (!rsnName.CompareTo("kstar")) {
71          numOfCuts = gROOT->ProcessLine(Form("AddRsnDaughterCuts%s(AliPID::kKaon,AliPID::kPion,\"%s\",%d,(AliRsnInputHandler*)%p,(AliAnalysisTaskSE*)%p)",rsnCutName.Data(), rsnCutOpt.Data(),isRsnMini,rsnIH,task));
72          if (numOfCuts) {
73             if (rsnNameOpt.Contains("mon")) AddParticleMonitor(task,isMC,cutIndex,commonEventCuts,commonPairCuts,Form("%s_%s_K",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
74             if (rsnNameOpt.Contains("mon")) AddParticleMonitor(task,isMC,cutIndex+1,commonEventCuts,commonPairCuts,Form("%s_%s_pi",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
75             AddRsnPairsKStar(task,isMC,isMixing,AliPID::kKaon,cutIndex,AliPID::kPion,cutIndex+1,commonEventCuts,commonPairCuts,Form("%s_%s",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
76             cutIndex+=numOfCuts;
77          }
78       } else if (!rsnName.CompareTo("rho")) {
79          numOfCuts = gROOT->ProcessLine(Form("AddRsnDaughterCuts%s(AliPID::kPion,AliPID::kPion,\"%s\",%d,(AliRsnInputHandler*)%p,(AliAnalysisTaskSE*)%p)",rsnCutName.Data(), rsnCutOpt.Data(),isRsnMini,rsnIH,task));
80          if (numOfCuts) {
81             if (rsnNameOpt.Contains("mon")) AddParticleMonitor(task,isMC,cutIndex,commonEventCuts,commonPairCuts,Form("%s_%s_pi",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
82             AddRsnPairsRho(task,isMC,isMixing,AliPID::kPion,cutIndex,AliPID::kPion,cutIndex,commonEventCuts,commonPairCuts,Form("%s_%s",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
83             cutIndex+=numOfCuts;
84          }
85       } else if (!rsnName.CompareTo("lambda")) {
86          numOfCuts = gROOT->ProcessLine(Form("AddRsnDaughterCuts%s(AliPID::kProton,AliPID::kKaon,\"%s\",%d,(AliRsnInputHandler*)%p,(AliAnalysisTaskSE*)%p)",rsnCutName.Data(), rsnCutOpt.Data(),isRsnMini,rsnIH,task));
87          if (numOfCuts) {
88             if (rsnNameOpt.Contains("mon")) AddParticleMonitor(task,isMC,cutIndex,commonEventCuts,commonPairCuts,Form("%s_%s_p",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
89             if (rsnNameOpt.Contains("mon")) AddParticleMonitor(task,isMC,cutIndex+1,commonEventCuts,commonPairCuts,Form("%s_%s_K",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
90             AddRsnPairsLambda(task,isMC,isMixing,AliPID::kProton,cutIndex,AliPID::kKaon,cutIndex+1,commonEventCuts,commonPairCuts,Form("%s_%s",rsnNameOptFull.Data(),rsnCutNameOptFull.Data()));
91             cutIndex+=numOfCuts;
92          }
93       } else {
94          Printf("Error : Particle %s is not supported !!!!",rsnName.Data());
95          return kFALSE;
96       }
97
98    }
99
100    return kTRUE;
101 }
102
103 Bool_t RsnLoadMacroFromConfig(TString macro,TString path="") {
104
105    Bool_t valid;
106    TString lego_path = AliAnalysisManager::GetGlobalStr("rsnLegoTrainPath",valid);
107    if (!valid) lego_path = "$ALICE_ROOT/PWGLF/RESONANCES/macros/lego_train";
108
109    if (!gSystem->AccessPathName(macro.Data())) {
110       gROOT->LoadMacro(macro.Data());
111       Printf("Macro loaded from %s/%s ...",gSystem->pwd(),macro.Data());
112       return kTRUE;
113    }
114
115    if (!gSystem->AccessPathName(gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())))) {
116       gROOT->LoadMacro(gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())));
117       Printf("Macro loaded from %s ...",gSystem->ExpandPathName(Form("%s/%s",lego_path.Data(),macro.Data())));
118       return kTRUE;
119    }
120
121    Printf("Error loading %s",macro.Data());
122
123    return kFALSE;
124 }
125
126 void GetOptionFromString(TString str,TString &outStr1,TString &outStr2,TString d=":") {
127    //   TStringO
128    TObjArray *tokens = str.Tokenize(d.Data());
129    TObjString *objStr =  (TObjString *)tokens->At(0);
130    if (!objStr) {
131       outStr1 = "err";
132       outStr2 = "";
133       return;
134    }
135    outStr1 = objStr->GetString();
136
137    objStr =  (TObjString *) tokens->At(1);
138    if (!objStr) {
139       outStr2 = "";
140       return;
141    }
142    outStr2 = objStr->GetString();
143
144 }
145
146 Bool_t AddPair(AliAnalysisTaskSE *task, Bool_t isMC,Bool_t isMixing, AliPID::EParticleType pType1,Int_t listID1, AliPID::EParticleType pType2,Int_t listID2, Int_t pdgMother,Double_t massMother, AliRsnCutSet *commonEventCuts=0,AliRsnCutSet *commonPairCuts=0, TString name = "") {
147
148    Bool_t valid;
149    Int_t useMCMomentum = AliAnalysisManager::GetGlobalInt("rsnUseMCMomentum",valid);
150
151    Bool_t typeSame = (pType1 == pType2);
152
153    //    Printf("------------- id1=%d id2=%d",listID1,listID2);
154
155    TList *listLoops = new TList;
156
157    // pair definition
158    AliRsnPairDef  *pairDefPM         = new AliRsnPairDef((AliRsnDaughter::ESpecies)pType1, '+', (AliRsnDaughter::ESpecies)pType2, '-', pdgMother, massMother);
159    AliRsnPairDef  *pairDefMP         = new AliRsnPairDef((AliRsnDaughter::ESpecies)pType1, '-', (AliRsnDaughter::ESpecies)pType2, '+', pdgMother, massMother);
160    AliRsnPairDef  *pairDefPP         = new AliRsnPairDef((AliRsnDaughter::ESpecies)pType1, '+', (AliRsnDaughter::ESpecies)pType2, '+', pdgMother, massMother);
161    AliRsnPairDef  *pairDefMM         = new AliRsnPairDef((AliRsnDaughter::ESpecies)pType1, '-', (AliRsnDaughter::ESpecies)pType2, '-', pdgMother, massMother);
162
163    // loop object creation
164    AliRsnLoopPair *lp = 0;
165
166    // sets +-
167    lp = new AliRsnLoopPair(Form("%s_PM", name.Data()), pairDefPM, kFALSE);
168    listLoops->Add(lp);
169
170    if (!typeSame) {
171       lp = new AliRsnLoopPair(Form("%s_MP", name.Data()), pairDefMP, kFALSE);
172       listLoops->Add(lp);
173    }
174
175    // sets +- TRUE pairs
176    if (isMC) {
177       lp = new AliRsnLoopPair(Form("%s_PM_TRUE", name.Data()), pairDefPM, kFALSE);
178       lp->SetOnlyTrue(kTRUE);
179       lp->SetCheckDecay(kTRUE);
180       listLoops->Add(lp);
181       if (!typeSame) {
182          lp = new AliRsnLoopPair(Form("%s_MP_TRUE", name.Data()), pairDefMP, kFALSE);
183          lp->SetOnlyTrue(kTRUE);
184          lp->SetCheckDecay(kTRUE);
185          listLoops->Add(lp);
186       }
187       // sets +- TRUE paris (MC is used for momentum)
188       lp = new AliRsnLoopPair(Form("%s_PM_TRUE_MC", name.Data()), pairDefPM, kFALSE);
189       lp->SetTrueMC(kTRUE);
190       listLoops->Add(lp);
191       if (!typeSame) {
192          // sets +- TRUE paris (MC is used for momentum)
193          lp = new AliRsnLoopPair(Form("%s_MP_TRUE_MC", name.Data()), pairDefMP, kFALSE);
194          lp->SetTrueMC(kTRUE);
195          listLoops->Add(lp);
196       }
197    }
198
199    // sets ++
200    lp = new AliRsnLoopPair(Form("%s_PP", name.Data()), pairDefPP, kFALSE);
201    listLoops->Add(lp);
202
203    // sets --
204    lp = new AliRsnLoopPair(Form("%s_MM", name.Data()), pairDefMM, kFALSE);
205    listLoops->Add(lp);
206
207    if (isMixing) {
208       // sets +- Mixing (NOT mini)
209       lp = new AliRsnLoopPair(Form("%s_PM", name.Data()), pairDefPM, kTRUE);
210       listLoops->Add(lp);
211
212       // sets -+ Mixing (NOT mini)
213       lp = new AliRsnLoopPair(Form("%s_MP", name.Data()), pairDefMP, kTRUE);
214       listLoops->Add(lp);
215
216       // sets ++ Mixing (NOT mini)
217       lp = new AliRsnLoopPair(Form("%s_PP", name.Data()), pairDefPP, kTRUE);
218       listLoops->Add(lp);
219
220       // sets -- Mixing (NOT mini)
221       lp = new AliRsnLoopPair(Form("%s_MM", name.Data()), pairDefMM, kTRUE);
222       listLoops->Add(lp);
223    }
224
225
226    // loops over all AliRsnLoops and sets everything (don't touch it if you don't know what you are doing)
227    TIter next(listLoops);
228    while ((lp = (AliRsnLoopPair *)next.Next())) {
229       lp->SetListID(0, listID1);
230       lp->SetListID(1, listID2);
231       lp->SetMCRefInfo(useMCMomentum);
232       if (commonPairCuts) lp->SetPairCuts(commonPairCuts);
233       if (commonEventCuts) lp->SetEventCuts(commonEventCuts);
234       if (name.Contains("phi")) AddPairOutputPhi(lp);
235       else if (name.Contains("kstar")) AddPairOutputKStar(lp);
236       else continue;
237       ((AliRsnAnalysisTask *)task)->AddLoop(lp);
238    }
239    return kTRUE;
240 }
241
242 void AddMonitorOutput(TObjArray *mon=0,TString opt="",AliRsnLoopDaughter *lm=0)
243 {
244
245    Bool_t valid;
246    Int_t useMCMon = AliAnalysisManager::GetGlobalInt("rsnUseMCMonitoring",valid);
247 //     if (useMCMon) return;
248
249    // dEdx tpc
250    AliRsnValueDaughter *axisMomTPC = new AliRsnValueDaughter("pTPC", AliRsnValueDaughter::kPtpc);
251    AliRsnValueDaughter *axisSigTPC = new AliRsnValueDaughter("sTPC", AliRsnValueDaughter::kTPCsignal);
252    axisMomTPC->SetBins(0.0,5.0,0.01);
253    axisSigTPC->SetBins(0.0,500.0,2.0);
254
255    // output: 2D histogram of TPC signal vs. TPC momentum
256    AliRsnListOutput *outMonitordEdxTPC = new AliRsnListOutput("dEdx", AliRsnListOutput::kHistoDefault);
257    outMonitordEdxTPC->AddValue(axisMomTPC);
258    outMonitordEdxTPC->AddValue(axisSigTPC);
259
260    // add outputs to loop
261    if (mon) mon->Add(outMonitordEdxTPC);
262    if (lm) lm->AddOutput(outMonitordEdxTPC);
263
264    // dEdx tpc
265    AliRsnValueDaughter *axisMomTPCForTOF = new AliRsnValueDaughter("pTPC", AliRsnValueDaughter::kPtpc);
266    AliRsnValueDaughter *axisSigTOF = new AliRsnValueDaughter("sTOF", AliRsnValueDaughter::kTOFsignal);
267    axisMomTPCForTOF->SetBins(0.0,5.0,0.01);
268    axisSigTOF->SetBins(0.0,500.0,2.0);
269
270    // output: 2D histogram of TPC signal vs. TPC momentum
271    AliRsnListOutput *outMonitordEdxTOF = new AliRsnListOutput("Edx", AliRsnListOutput::kHistoDefault);
272    outMonitordEdxTOF->AddValue(axisMomTPCForTOF);
273    outMonitordEdxTOF->AddValue(axisSigTOF);
274
275    // add outputs to loop
276    if (mon) mon->Add(outMonitordEdxTOF);
277    if (lm) lm->AddOutput(outMonitordEdxTOF);
278
279
280    // Momentum
281    AliRsnValueDaughter *axisMomP = new AliRsnValueDaughter("p", AliRsnValueDaughter::kP);
282    axisMomP->SetBins(0.0,5.0,0.01);
283
284    // output: 2D histogram of TPC signal vs. TPC momentum
285    AliRsnListOutput *outMonitorP = new AliRsnListOutput("P", AliRsnListOutput::kHistoDefault);
286    outMonitorP->AddValue(axisMomP);
287
288    // add outputs to loop
289    if (mon) mon->Add(outMonitorP);
290    if (lm) lm->AddOutput(outMonitorP);
291
292
293    if (useMCMon) {
294       AliRsnValueDaughter *axisMomPMC = new AliRsnValueDaughter("pMC", AliRsnValueDaughter::kP);
295       axisMomPMC->SetUseMCInfo(kTRUE);
296       axisMomPMC->SetBins(0.0,5.0,0.01);
297
298       // output: 2D histogram of TPC signal vs. TPC momentum
299       AliRsnListOutput *outMonitorPMC = new AliRsnListOutput("PMC", AliRsnListOutput::kHistoDefault);
300       outMonitorPMC->AddValue(axisMomPMC);
301
302       // add outputs to loop
303       if (mon) mon->Add(outMonitorPMC);
304       if (lm) lm->AddOutput(outMonitorPMC);
305    }
306
307
308    // Momentum Pt
309    AliRsnValueDaughter *axisMomPt = new AliRsnValueDaughter("pt", AliRsnValueDaughter::kPt);
310    axisMomPt->SetBins(0.0,5.0,0.01);
311
312    // output: 2D histogram of TPC signal vs. TPC momentum
313    AliRsnListOutput *outMonitorPt = new AliRsnListOutput("Pt", AliRsnListOutput::kHistoDefault);
314    outMonitorPt->AddValue(axisMomPt);
315
316    // add outputs to loop
317    if (mon) mon->Add(outMonitorPt);
318    if (lm) lm->AddOutput(outMonitorPt);
319    if (useMCMon) {
320       // Momentum Pt
321       AliRsnValueDaughter *axisMomPtMC = new AliRsnValueDaughter("ptMC", AliRsnValueDaughter::kPt);
322       axisMomPtMC->SetUseMCInfo(kTRUE);
323       axisMomPtMC->SetBins(0.0,5.0,0.01);
324
325       // output: 2D histogram of TPC signal vs. TPC momentum
326       AliRsnListOutput *outMonitorPtMC = new AliRsnListOutput("PtMC", AliRsnListOutput::kHistoDefault);
327       outMonitorPtMC->AddValue(axisMomPtMC);
328
329       // add outputs to loop
330       if (mon) mon->Add(outMonitorPtMC);
331       if (lm) lm->AddOutput(outMonitorPtMC);
332    }
333
334    // Eta
335    AliRsnValueDaughter *axisMomEta = new AliRsnValueDaughter("eta", AliRsnValueDaughter::kEta);
336    axisMomEta->SetBins(-1.0,1.0,0.01);
337
338    // output: 2D histogram of TPC signal vs. TPC momentum
339    AliRsnListOutput *outMonitorEta = new AliRsnListOutput("Eta", AliRsnListOutput::kHistoDefault);
340    outMonitorEta->AddValue(axisMomEta);
341
342    // add outputs to loop
343    if (mon) mon->Add(outMonitorEta);
344    if (lm) lm->AddOutput(outMonitorEta);
345
346    if (useMCMon) {
347       // Eta
348       AliRsnValueDaughter *axisMomEtaMC = new AliRsnValueDaughter("etaMC", AliRsnValueDaughter::kEta);
349       axisMomEtaMC->SetUseMCInfo(kTRUE);
350       axisMomEtaMC->SetBins(-1.0,1.0,0.01);
351
352       // output: 2D histogram of TPC signal vs. TPC momentum
353       AliRsnListOutput *outMonitorEtaMC = new AliRsnListOutput("EtaMC", AliRsnListOutput::kHistoDefault);
354       outMonitorEtaMC->AddValue(axisMomEtaMC);
355
356       // add outputs to loop
357       if (mon) mon->Add(outMonitorEtaMC);
358       if (lm) lm->AddOutput(outMonitorEtaMC);
359    }
360    // kTOFnsigmaK
361    AliRsnValueDaughter *axisTPCnsigmaK = new AliRsnValueDaughter("K", AliRsnValueDaughter::kTPCnsigmaK);
362    axisTPCnsigmaK->SetBins(1001,-100,100);
363
364    // output: 2D histogram of TPC signal vs. TPC momentum
365    AliRsnListOutput *outMonitorTPCnsigmaK = new AliRsnListOutput("TPC_nsigma", AliRsnListOutput::kHistoDefault);
366    outMonitorTPCnsigmaK->AddValue(axisTPCnsigmaK);
367
368    // add outputs to loop
369    if (mon) mon->Add(outMonitorTPCnsigmaK);
370    if (lm) lm->AddOutput(outMonitorTPCnsigmaK);
371
372    // kTPCnsigmaPi
373    AliRsnValueDaughter *axisTPCnsigmaPi = new AliRsnValueDaughter("pi", AliRsnValueDaughter::kTPCnsigmaPi);
374    axisTPCnsigmaPi->SetBins(1001,-100,100);
375
376    // output: 2D histogram of TPC signal vs. TPC momentum
377    AliRsnListOutput *outMonitorTPCnsigmaPi = new AliRsnListOutput("TPC_nsigma", AliRsnListOutput::kHistoDefault);
378    outMonitorTPCnsigmaPi->AddValue(axisTPCnsigmaPi);
379
380    // add outputs to loop
381    if (mon) mon->Add(outMonitorTPCnsigmaPi);
382    if (lm) lm->AddOutput(outMonitorTPCnsigmaPi);
383
384    // kTPCnsigmaP
385    AliRsnValueDaughter *axisTPCnsigmaP = new AliRsnValueDaughter("p", AliRsnValueDaughter::kTPCnsigmaP);
386    axisTPCnsigmaP->SetBins(1001,-100,100);
387
388    // output: 2D histogram of TPC signal vs. TPC momentum
389    AliRsnListOutput *outMonitorTPCnsigmaP = new AliRsnListOutput("TPC_nsigma", AliRsnListOutput::kHistoDefault);
390    outMonitorTPCnsigmaP->AddValue(axisTPCnsigmaP);
391
392    // add outputs to loop
393    if (mon) mon->Add(outMonitorTPCnsigmaP);
394    if (lm) lm->AddOutput(outMonitorTPCnsigmaP);
395
396
397    if (!opt.Contains("NoTOFSIGMA")) {
398
399       // kTOFnsigmaK
400       AliRsnValueDaughter *axisTOFnsigmaK = new AliRsnValueDaughter("K", AliRsnValueDaughter::kTOFnsigmaK);
401       axisTOFnsigmaK->SetBins(1001,-100,100);
402
403       // output: 2D histogram of TPC signal vs. TPC momentum
404       AliRsnListOutput *outMonitorTOFnsigmaK = new AliRsnListOutput("TOF_nsigma", AliRsnListOutput::kHistoDefault);
405       outMonitorTOFnsigmaK->AddValue(axisTOFnsigmaK);
406
407       // add outputs to loop
408       if (mon) mon->Add(outMonitorTOFnsigmaK);
409       if (lm) lm->AddOutput(outMonitorTOFnsigmaK);
410
411       // kTOFnsigmaPi
412       AliRsnValueDaughter *axisTOFnsigmaPi = new AliRsnValueDaughter("pi", AliRsnValueDaughter::kTOFnsigmaPi);
413       axisTOFnsigmaPi->SetBins(1001,-100,100);
414
415       // output: 2D histogram of TPC signal vs. TPC momentum
416       AliRsnListOutput *outMonitorTOFnsigmaPi = new AliRsnListOutput("TOF_nsigma", AliRsnListOutput::kHistoDefault);
417       outMonitorTOFnsigmaPi->AddValue(axisTOFnsigmaPi);
418
419       // add outputs to loop
420       if (mon) mon->Add(outMonitorTOFnsigmaPi);
421       if (lm) lm->AddOutput(outMonitorTOFnsigmaPi);
422
423       // kTOFnsigmaP
424       AliRsnValueDaughter *axisTOFnsigmaP = new AliRsnValueDaughter("p", AliRsnValueDaughter::kTOFnsigmaP);
425       axisTOFnsigmaP->SetBins(1001,-100,100);
426
427       // output: 2D histogram of TPC signal vs. TPC momentum
428       AliRsnListOutput *outMonitorTOFnsigmaP = new AliRsnListOutput("TOF_nsigma", AliRsnListOutput::kHistoDefault);
429       outMonitorTOFnsigmaP->AddValue(axisTOFnsigmaP);
430
431       // add outputs to loop
432       if (mon) mon->Add(outMonitorTOFnsigmaP);
433       if (lm) lm->AddOutput(outMonitorTOFnsigmaP);
434    }
435
436
437    AliRsnListOutput *outMonitorPTvsMult = new AliRsnListOutput("PTvsMult",AliRsnListOutput::kHistoDefault);
438    AliRsnValueDaughter *vd1 = new AliRsnValueDaughter("pt",AliRsnValueDaughter::kPt);
439    vd1->SetBins(0.0,5.0,0.01);
440    outMonitorPTvsMult->AddValue(vd1);
441
442    AliRsnValueEvent *ve1 = new AliRsnValueEvent("mult",AliRsnValueEvent::kMult);
443    ve1->SetBins(0.0,100.0,1);
444    outMonitorPTvsMult->AddValue(ve1);
445    if (mon) mon->Add(outMonitorPTvsMult);
446    if (lm) lm->AddOutput(outMonitorPTvsMult);
447
448    
449 //    if (lm) lm->SetTrueMC(kTRUE);
450 }
451
452 void AddMonitorOutputMini(AliRsnMiniMonitorTask *task,Int_t listID1,TString name = "",Char_t charge='0')
453 {
454    TString chargeName="all";
455    if ( charge == '+' ) chargeName = "pos";
456    if ( charge == '-' ) chargeName = "neg";
457
458    AliRsnMiniMonitor *mondEdx = task->CreateMonitor(Form("%s_dEdx_pTPC_%s", name.Data(),chargeName.Data()),AliRsnMiniMonitor::kdEdxTPCvsP, listID1);
459    mondEdx->SetCharge(charge);
460    AliRsnMiniMonitor *monPt = task->CreateMonitor(Form("%s_Pt_%s", name.Data(),chargeName.Data()),AliRsnMiniMonitor::kTrackPt, listID1);
461    monPt->SetCharge(charge);
462 }
463
464 void AddParticleMonitor(AliAnalysisTaskSE *task, Bool_t isMC, Int_t listID1,AliRsnCutSet *commonEventCuts=0,AliRsnCutSet *cutPair=0,TString name = "")
465 {
466    Bool_t valid;
467    Int_t isRsnMini = AliAnalysisManager::GetGlobalInt("rsnUseMiniPackage",valid);
468    Int_t useMCMon = AliAnalysisManager::GetGlobalInt("rsnUseMCMonitoring",valid);
469
470    if (isRsnMini) {
471 //       Printf("Monitoring by mini is not supported now. It will be soon !!!");
472 //       return ;
473       AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
474       AliRsnMiniMonitorTask *monTask = new AliRsnMiniMonitorTask(name.Data(),useMCMon);
475       AddMonitorOutputMini(monTask,listID1,name);
476 //       AddMonitorOutputMini(monTask,listID1,name,'+');
477 //       AddMonitorOutputMini(monTask,listID1,name,'-');
478       mgr->AddTask(monTask);
479       // connect input container according to source choice
480       mgr->ConnectInput(monTask, 0, mgr->GetCommonInputContainer());
481
482       // create paths for the output in the common file
483       TString commonPath = AliAnalysisManager::GetCommonFileName();
484
485       // create containers for output
486       AliAnalysisDataContainer *output = mgr->CreateContainer(Form("RsnMonMini%s", name.Data()), TList::Class(), AliAnalysisManager::kOutputContainer, commonPath.Data());
487
488       mgr->ConnectOutput(monTask, 1, output);
489
490
491
492    } else {
493
494       TList *listLoops = new TList;
495       // monitor definition
496       AliRsnDaughterDef *tracksAll = new AliRsnDaughterDef(AliRsnDaughter::kTrack /*'+' or '-'*/);
497 // //       AliRsnDaughterDef *tracksPos = new AliRsnDaughterDef(AliRsnDaughter::kTrack,'+');
498 // //       AliRsnDaughterDef *tracksNeg = new AliRsnDaughterDef(AliRsnDaughter::kTrack,'-');
499 //
500       AliRsnLoopDaughter *lm =0;
501 //       // loop object
502       listLoops->Add(new AliRsnLoopDaughter(Form("ALL_%s", name.Data()), listID1, tracksAll));
503 //
504 // //       listLoops->Add(new AliRsnLoopDaughter(Form("%s_pos", name.Data()), listID1, tracksPos));
505 // //       listLoops->Add(new AliRsnLoopDaughter(Form("%s_neg", name.Data()), listID1, tracksNeg));
506 //
507       TIter next(listLoops);
508       while ((lm = (AliRsnLoopDaughter *)next.Next())) {
509 //          if (commonEventCuts) lm->SetEventCuts(commonEventCuts);
510          AddMonitorOutput(0,"mc_loop",lm);
511          ((AliRsnAnalysisTask *)task)->AddLoop(lm);
512       }
513    }
514 }
515