1 #if !defined(__CINT__) || defined(__MAKECINT__)
7 #include "TObjString.h"
12 #include "TParameter.h"
13 #include "TFileMerger.h"
14 #include "THashList.h"
17 #include "AliAnalysisManager.h"
18 #include "AliAnalysisAlien.h"
19 #include "AliESDInputHandler.h"
20 #include "AliCounterCollection.h"
41 TString libName =
"libPWGPPMUONlite";
42 TString getLib = gSystem->GetLibraries(libName.Data(),
"",kFALSE);
43 if ( getLib.IsNull() ) gSystem->Load(libName.Data());
50 AliAnalysisAlien *plugin =
new AliAnalysisAlien();
53 plugin->SetRunMode(
"terminate");
56 plugin->SetAdditionalLibs(
"libCORRFW.so libPWGHFbase.so libPWGmuon.so libPWGPPMUONlite.so");
58 plugin->SetAdditionalRootLibs(
"libXMLParser.so libGui.so libProofPlayer.so");
60 plugin->AddIncludePath(
"-I.");
61 plugin->AddIncludePath(
"-I$ALICE_PHYSICS/PWGPP/MUON/lite");
72 void terminateQA ( TString outfilename =
"QAresults.root", Bool_t isMC = kFALSE, UInt_t force = 0, UInt_t mask = (
trackQA|
trigQA) )
82 AliAnalysisManager* mgr =
new AliAnalysisManager(
"testAnalysis");
83 mgr->SetCommonFileName(outfilename.Data());
84 mgr->SetGridHandler(alienHandler);
87 AliESDInputHandler* esdH =
new AliESDInputHandler();
88 esdH->SetReadFriends(kFALSE);
89 mgr->SetInputEventHandler(esdH);
91 TString trigOutName =
"trigChEff_ANY_Apt_allTrig.root";
92 if ( ( force &
trigQA ) == 0 ) {
93 if ( gSystem->AccessPathName(trigOutName) == 0 ) {
94 printf(
"Terminate already done for trigger. Skip\n");
98 if ( ( force &
trackQA ) == 0 ) {
99 TFile* file = TFile::Open(outfilename.Data());
100 TKey* key = file->FindKeyAny(
"general2");
102 printf(
"Terminate already done for tracker. Skip\n");
110 if ( mask & trigQA ) {
111 gROOT->LoadMacro(
"$ALICE_PHYSICS/PWGPP/macros/AddTaskMTRchamberEfficiency.C");
113 TString physSelName =
"PhysSelPass";
114 if ( isMC ) physSelName +=
",PhysSelReject";
115 trigChEffTask->SetTerminateOptions(physSelName,
"ANY",
"-5_105",Form(
"FORCEBATCH NoSelMatchApt FromTrg %s?%s?ANY?-5_105?NoSelMatchAptFromTrg",trigOutName.Data(),physSelName.Data()));
117 if ( mask & trackQA ) {
118 gROOT->LoadMacro(
"$ALICE_PHYSICS/PWGPP/PilotTrain/AddTaskMuonQA.C");
119 Bool_t selectPhysics = ( isMC ) ? kFALSE : kTRUE;
141 if ( ! mgr->InitAnalysis()) {
142 printf(
"Fatal: Cannot initialize analysis\n");
146 mgr->StartAnalysis(
"grid terminate");
153 if ( filename.BeginsWith(
"alien://") )
return filename;
154 TString dirName = gSystem->DirName(filename);
155 TString baseName = gSystem->BaseName(filename);
156 TString currDir = gSystem->pwd();
157 gSystem->cd(dirName);
158 TString fullDir = gSystem->pwd();
159 gSystem->cd(currDir);
160 TString fullPath = fullDir.Data();
161 if ( ! fullDir.EndsWith(
"/") ) fullPath.Append(
"/");
162 fullPath += baseName;
169 TString baseName = gSystem->BaseName(filename);
170 Int_t idx = baseName.Index(
"#");
171 if ( idx > 0 ) baseName.Remove(0,idx+1);
179 TDirectory *savdir = gDirectory;
180 TDirectory *adir = savdir->mkdir(source->GetName());
184 TIter nextkey(source->GetListOfKeys());
185 while ((key = (TKey*)nextkey())) {
186 const char *classname = key->GetClassName();
187 TClass *cl = gROOT->GetClass(classname);
189 if (cl->InheritsFrom(TDirectory::Class())) {
190 source->cd(key->GetName());
191 TDirectory *subdir = gDirectory;
195 }
else if (cl->InheritsFrom(TTree::Class())) {
196 TTree *T = (TTree*)source->Get(key->GetName());
198 TTree *newT = T->CloneTree(-1,
"fast");
202 TObject *obj = key->ReadObj();
204 obj->Write(obj->GetName(),TObject::kSingleKey);
208 adir->SaveSelf(kTRUE);
214 Bool_t
GetQAInfo (
const char* qaFileName, TString dirNames =
"MUON_QA MTR_ChamberEffMap MUON.TrigEfficiencyMap MUON.TriggerEfficiencyMap" )
221 if ( inFullPath == outFullPath ) {
222 printf(
"Warning: input and output are same file!\n");
226 if ( inFullPath.BeginsWith(
"alien") && ! gGrid ) TGrid::Connect(
"alien://");
228 TObjArray* dirList = dirNames.Tokenize(
" ");
229 TFile* outFile = TFile::Open(outFilename,
"RECREATE");
230 TFile* inFile = TFile::Open(qaFileName);
231 for ( Int_t idir=0; idir<dirList->GetEntries(); idir++ ) {
233 TObject* obj = inFile->Get(dirList->At(idir)->GetName());
234 if ( ! obj )
continue;
236 CopyDir(static_cast<TDirectory*>(obj));
250 TObjArray* arr = fileList.Tokenize(
" ");
251 THashList triggerList;
252 triggerList.SetOwner();
253 Bool_t hasOverlap = kFALSE;
254 for ( Int_t iarr=0; iarr<arr->GetEntries(); iarr++ ) {
255 TFile* file = TFile::Open(arr->At(iarr)->GetName());
256 AliCounterCollection* eventCounters = (AliCounterCollection*)file->FindObjectAny(
"eventCounters");
257 if ( eventCounters ) {
258 TString listFromContainer = eventCounters->GetKeyWords(
"trigger");
259 TObjArray* trigArr = listFromContainer.Tokenize(
",");
260 for ( Int_t itrig=0; itrig<trigArr->GetEntries(); itrig++ ) {
261 TString currTrig = trigArr->At(itrig)->GetName();
262 if ( triggerList.FindObject(currTrig.Data()) ) {
263 if ( currTrig !=
"ANY" ) {
264 printf(
"Warning: duplicated trigger %s\n", currTrig.Data());
268 else triggerList.Add(
new TObjString(currTrig));
283 TObjArray* arr = fileList.Tokenize(
" ");
285 fm.OutputFile(outFilename.Data());
286 for ( Int_t iarr=0; iarr<arr->GetEntries(); iarr++ ) {
287 fm.AddFile(arr->At(iarr)->GetName());
294 Bool_t
AddTreeVariable ( TList& parList,
const char* varName,
char varType, Float_t val )
296 if ( varType ==
'D' ) varType =
'F';
297 TString parName = Form(
"%s/%c",varName,varType);
298 if ( varType ==
'F' ) {
299 parList.Add(
new TParameter<float>(parName,val));
301 else if ( varType ==
'I' ) {
302 parList.Add(
new TParameter<int>(parName,(Int_t)val));
305 printf(
"Error: variable type %c not accepted", varType);
315 Int_t nVars = parList.GetEntries();
316 TArrayI varInt(nVars);
317 TArrayF varFloat(nVars);
318 for ( Int_t ivar=0; ivar<nVars; ivar++ ) {
319 TObject* obj = parList.At(ivar);
320 TString varName = obj->GetName();
321 TString branchName = varName;
322 branchName.Remove(varName.Length()-2);
323 if ( varName.EndsWith(
"F") ) {
324 varFloat[ivar] = ((TParameter<float>*)obj)->GetVal();
325 tree->Branch(branchName.Data(),&varFloat[ivar],varName.Data());
327 else if ( varName.EndsWith(
"I") ) {
328 varInt[ivar] = (Int_t)((TParameter<int>*)obj)->GetVal();
329 tree->Branch(branchName.Data(),&varInt[ivar],varName.Data());
339 TString trigOutName =
"trigChEff_ANY_Apt_allTrig.root";
340 if ( gSystem->AccessPathName(trigOutName.Data()) ) trigOutName = filename;
341 TFile* file = TFile::Open(filename.Data());
342 TList* inList = (TList*)file->FindObjectAny(
"triggerChamberEff");
343 TString hChNames[] = {
"bendPlaneCountChamber",
"nonBendPlaneCountChamber",
"allTracksCountChamber"};
344 Int_t nHistos =
sizeof(hChNames)/
sizeof(hChNames[0]);
345 for ( Int_t ihisto=0; ihisto<nHistos; ihisto++ ) {
346 TH1* histo = (TH1*)inList->FindObject(hChNames[ihisto].Data());
347 for ( Int_t ibin=1; ibin<=4; ibin++ ) {
348 Double_t currVal = ( histo ) ? histo->GetBinContent(ibin) : 0.;
349 AddTreeVariable(parList, Form(
"%s%i",hChNames[ihisto].Data(),ibin),
'F',currVal);
359 if ( ! isOk )
return;
363 if ( inFilename.Contains(
"barrel") ) {
364 TString outerInFilename(qaFile);
365 outerInFilename.ReplaceAll(
"barrel",
"outer");
370 fileList +=
" " + inFilename;
373 inFilename =
"QAresults.root";
374 printf(
"Merged files: %s => %s\n",fileList.Data(),inFilename.Data());
376 gSystem->Exec(Form(
"rm %s",fileList.Data()));
390 TFile* outFile = TFile::Open(
"trending.root",
"RECREATE");
391 TTree* tree =
new TTree(
"trending",
"trending");
TString GetFullPath(TString filename)
void AddTrigVars(TString filename, TList &parList)
void CopyDir(TDirectory *source)
Quality assurance of MUON ESDs.
void FillTree(TTree *tree, TList &parList)
TString GetBaseName(TString filename)
AliAnalysisAlien * CreateAlienHandler()
void terminateQA(TString outfilename="QAresults.root", Bool_t isMC=kFALSE, UInt_t force=0, UInt_t mask=(trackQA|trigQA))
void MakeTrend(const char *qaFile, Int_t runNumber, Bool_t isMC=kFALSE, UInt_t force=trigQA, UInt_t mask=(trackQA|trigQA))
Bool_t CheckMergedOverlap(TString fileList)
Bool_t AddTreeVariable(TList &parList, const char *varName, char varType, Float_t val)
Bool_t GetMergedQAInfo(TString fileList, TString outFilename="QAresults.root")
Bool_t GetQAInfo(const char *qaFileName, TString dirNames="MUON_QA MTR_ChamberEffMap MUON.TrigEfficiencyMap MUON.TriggerEfficiencyMap")