]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/TRD/AliTRDpwg1Helper.cxx
add identifiers between MC and no MC data for histo titles
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDpwg1Helper.cxx
1 ////////////////////////////////////////////////////////////////////////////
2 //                                                                        //
3 //  Helper class for PWG1 TRD train                                       //
4 //                                                                        //
5 //  Authors:                                                              //
6 //    Markus Fasel <M.Fasel@gsi.de>                                       //
7 //                                                                        //
8 ////////////////////////////////////////////////////////////////////////////
9
10 #include <Rtypes.h>
11 #include <TError.h>
12 #include <TObjArray.h>
13 #include <TObjString.h>
14 #include <TRandom.h>
15 #include <TString.h>
16 #include <TSystem.h>
17
18 #include <cstring>
19 #include <fstream>
20
21 #include "AliTRDpwg1Helper.h"
22
23 const Char_t * AliTRDpwg1Helper::fgkTRDtaskClassName[AliTRDpwg1Helper::kNTRDTASKS] = {
24   "AliTRDcheckESD"
25   ,"AliTRDinfoGen"
26   ,"AliTRDcheckDET"
27   ,"AliTRDefficiency"
28   ,"AliTRDresolution"
29   ,"AliTRDcheckPID"
30   ,"AliTRDv0Monitor"
31   ,"AliTRDcalibration"
32   ,"AliTRDefficiencyMC"
33   ,"AliTRDalignmentTask"
34   ,"AliTRDpidRefMaker"
35   ,"AliTRDclusterResolution"
36   ,"AliTRDmultiplicity"
37 };
38
39 const Char_t * AliTRDpwg1Helper::fgkTRDtaskOpt[AliTRDpwg1Helper::kNTRDTASKS+1] = {
40   "ESD"
41   ,"GEN"
42   ,"DET"
43   ,"EFF"
44   ,"RES"
45   ,"PID"
46   ,"V0"
47   ,"CAL"
48   ,"EFFC"
49   ,"ALGN"
50   ,"PIDR"
51   ,"CLRES"
52   ,"MULT"
53   ,"ALL"
54 };
55
56 //______________________________________________________
57 Bool_t AliTRDpwg1Helper::DoTask(Int_t idx, Int_t map)
58 {
59   return TESTBIT(map, idx);
60 }
61
62 //______________________________________________________
63 Int_t AliTRDpwg1Helper::ParseOptions(Char_t *trd)
64 {
65 // Parse space separated options.
66 // Possible options are:
67 //      "ALL" : [default] all performance (no calibration) tasks
68 // ------- Performance tasks ----------
69 //     "ESD"  : Basic TRD Detector checks on ESD only (no TRD tracks analysed)
70 //     "DET"  : Basic TRD Detector checks
71 //     "RES"  : TRD tracking Resolution
72 //     "EFF"  : TRD Tracking Efficiency
73 //     "PID"  : TRD PID - pion efficiency
74 //     "V0"   : monitor V0 performance for use in TRD PID calibration
75 // ------- Calibration tasks ----------
76 //     "EFFC" : TRD Tracking Efficiency Combined (barrel + stand alone) - only in case of simulations
77 //     "MULT"  : TRD single track selection
78 //     "CLRES": clusters Resolution
79 //     "CAL"  : TRD calibration
80 //     "ALGN" : TRD alignment
81 //     "PIDR" : TRD PID - reference data
82 // ------- SPECIAL OPTIONS -----------
83 //     "NOFR" : Data set does not have AliESDfriends.root
84 //     "NOMC" : Data set does not have Monte Carlo Informations (default have MC),
85
86   Int_t fSteerTask = 0;
87   TObjArray *tasksArray = TString(trd).Tokenize(" ");
88   for(Int_t isel = 0; isel < tasksArray->GetEntriesFast(); isel++){
89     TString s = (dynamic_cast<TObjString *>(tasksArray->UncheckedAt(isel)))->String();
90     if(s.CompareTo("ALL") == 0){
91       for(Int_t itask = 0; itask < kNTRDQATASKS; itask++) SETBIT(fSteerTask, itask);
92       continue;
93     } else if(s.CompareTo("NOMC") == 0 || s.CompareTo("NOFR") == 0){
94       continue; // taken care by special functions
95     } else { 
96       Bool_t foundOpt = kFALSE;  
97       for(Int_t itask = 0; itask < kNTRDTASKS; itask++){
98         if(s.CompareTo(fgkTRDtaskOpt[itask]) != 0) continue;
99         SETBIT(fSteerTask, itask); 
100         if(itask>1) SETBIT(fSteerTask, kInfoGen);
101         foundOpt = kTRUE;
102         break;
103       }
104       if(!foundOpt) Info("ParseOptions()", Form("TRD task %s not implemented (yet).", s.Data()));
105     }
106   }
107   // extra rules for calibration tasks
108   if(TESTBIT(fSteerTask, kCalibration)) SETBIT(fSteerTask, kCheckDET);
109   if(TESTBIT(fSteerTask, kMultiplicity)) SETBIT(fSteerTask, kEfficiency);
110   if(TESTBIT(fSteerTask, kEfficiencyMC)) SETBIT(fSteerTask, kEfficiency);
111   if(TESTBIT(fSteerTask, kClErrParam)) SETBIT(fSteerTask, kResolution);
112   if(TESTBIT(fSteerTask, kAlignment)) SETBIT(fSteerTask, kResolution);
113   if(TESTBIT(fSteerTask, kPIDRefMaker)) SETBIT(fSteerTask, kCheckPID);
114   if(TESTBIT(fSteerTask, kV0Monitor)) SETBIT(fSteerTask, kCheckPID);
115
116   return fSteerTask;
117
118 }
119
120 //______________________________________________________
121 void AliTRDpwg1Helper::MergeProd(const Char_t *mark, const Char_t *files, const Int_t nBatch = 20)
122 {
123 // Merge Output files named "mark" from list in "files"
124
125   Char_t lMERGE[8]; sprintf(lMERGE, "%d.lst", (Int_t)gRandom->Uniform(9999.));
126   Char_t lPURGE[8]; sprintf(lPURGE, "%d.lst", (Int_t)gRandom->Uniform(9999.));
127   gSystem->Exec("mkdir -p merge; rm -rf merge/*");
128
129   // purge file list
130   std::string filename;
131   std::ifstream file(files);
132   Int_t iline(0);
133   while(getline(file, filename)){
134     if(Int_t(filename.find(mark)) < 0) continue;
135     gSystem->Exec(Form("echo %s >> %s", filename.c_str(), lPURGE));
136     iline++;
137   }
138   Int_t nBatches(iline/nBatch);
139
140   for(Int_t ibatch(0); ibatch<nBatches; ibatch++){
141     Int_t first(ibatch*nBatch);
142     if(!gSystem->Exec(Form("root.exe -b -q \'$ALICE_ROOT/PWG1/TRD/macros/mergeBatch.C(\"%s\", \"%s\", %d, %d)\'", mark, lPURGE, nBatch, first))) continue;
143     gSystem->Exec(Form("mv %d_%s merge/", first, mark));
144     gSystem->Exec(Form("echo %s/merge/%d_%s >> %s", gSystem->ExpandPathName("$PWD"), first, mark, lMERGE));
145   }
146   gSystem->Exec(Form("root.exe -b -q \'$ALICE_ROOT/PWG1/TRD/macros/mergeBatch.C(\"%s\", \"%s\", %d, 0, kFALSE, kTRUE)\'", mark, lMERGE, nBatches));
147   gSystem->Exec(Form("mv 0_%s %s", mark, mark));
148   
149   gSystem->Exec(Form("rm -rfv %s %s merge", lMERGE, lPURGE));
150 }
151
152 //______________________________________________________
153 Int_t AliTRDpwg1Helper::GetTaskIndex(const Char_t *name)
154 {
155 //  Give index in TRD train of task class "name"
156   for(Int_t it(0); it<kNTRDTASKS; it++){
157     if(strcmp(fgkTRDtaskClassName[it], name)==0) return it;
158   }
159   return -1;
160 }
161
162 //______________________________________________________
163 Bool_t AliTRDpwg1Helper::HasReadMCData(Char_t *opt)
164 {
165 // Use MC data option
166   return !(Bool_t)strstr(opt, "NOMC");
167 }
168
169 //____________________________________________
170 Bool_t AliTRDpwg1Helper::HasReadFriendData(Char_t *opt)
171 {
172 // Use friends data option
173   return !(Bool_t)strstr(opt, "NOFR");
174 }
175