AliPhysics  41af4b0 (41af4b0)
RunMuonQA.C
Go to the documentation of this file.
1 //--------------------------------------------------------------------------
2 // Base macro for submitting muon QA analysis.
3 //
4 // It needs the following libraries:
5 // - libSTEERBase
6 // - libESD
7 // - libAOD
8 // - libANALYSIS
9 // - libANALYSISalice
10 // - libCORRFW
11 // - libPWGmuon
12 // - libPWGPPMUONlite
13 // The macro reads ESDs and store outputs in standard output file (AnalysisResults.root)
14 //
15 // Author: Philippe Pillot / Cynthia Hadjidakis
16 //--------------------------------------------------------------------------
17 
19 
20 void RunMuonQA(TString inputFileName = "AliESDs.root", Bool_t isMC = kFALSE,
21  Bool_t selectEvent = kTRUE, Bool_t selectMatched = kTRUE,
22  Bool_t applyAccCut = kTRUE, Short_t selectCharge = 0)
23 {
24  TStopwatch timer;
25  timer.Start();
26 
27  // Check runing mode
28  Int_t mode = GetMode(inputFileName);
29  if(mode < 0){
30  Error("RunMuonQA","Please provide either an ESD root file or a collection of ESDs.");
31  return;
32  }
33 
34  // Load common libraries
35  //gSystem->Load("libVMC");
36  //gSystem->Load("libTree");
37  //gSystem->Load("libPhysics");
38  //gSystem->Load("libMinuit");
39  //gSystem->Load("libXMLParser");
40  //gSystem->Load("libGui");
41  //gSystem->Load("libSTEERBase");
42  //gSystem->Load("libESD");
43  //gSystem->Load("libAOD");
44  //gSystem->Load("libANALYSIS");
45  //gSystem->Load("libANALYSISalice");
46  //gSystem->Load("libCORRFW");
47  //gSystem->Load("libPWGmuon");
48  //gSystem->Load("libPWGPPMUONlite");
49 
50  // Create input chain
51  TChain* chain = CreateChain(inputFileName);
52  if (!chain) return;
53 
54  // Create the analysis manager
55  AliAnalysisManager *mgr = new AliAnalysisManager("MuonQAAnalysis");
56 
57  // ESD input handler
58  AliESDInputHandler* esdH = new AliESDInputHandler();
59  esdH->SetReadFriends(kFALSE);
60  mgr->SetInputEventHandler(esdH);
61 
62  // event selection
63  gROOT->LoadMacro("$ALICE_PHYSICS/OADB/macros/AddTaskPhysicsSelection.C");
64  AliPhysicsSelectionTask* physicsSelection = AddTaskPhysicsSelection(isMC);
65  if(!physicsSelection) {
66  Error("RunMuonQA","AliPhysicsSelectionTask not created!");
67  return;
68  }
69 
70  // Muon QA analysis
71  gROOT->LoadMacro("$ALICE_PHYSICS/PWGPP/PilotTrain/AddTaskMuonQA.C");
72 
73  // Create and configure task
74  AliAnalysisTaskMuonQA *muonQA = AddTaskMuonQA(selectEvent,selectMatched,applyAccCut,selectCharge);
75  if (!muonQA) {
76  Error("RunMuonQA", "Muon QA task not created!");
77  return;
78  }
79 
80  // Enable debug printouts
81  // mgr->SetDebugLevel(2);
82 
83  // start local analysis
84  if (mgr->InitAnalysis()) {
85  mgr->PrintStatus();
86  mgr->StartAnalysis("local", chain);
87  }
88 
89  timer.Stop();
90  timer.Print();
91 }
92 
93 //______________________________________________________________________________
94 Int_t GetMode(TString inputFileName)
95 {
96  if ( inputFileName.EndsWith(".xml") ) return kInteractif_xml;
97  else if ( inputFileName.EndsWith(".txt") ) return kInteractif_ESDList;
98  else if ( inputFileName.EndsWith(".root") ) return kLocal;
99  return -1;
100 }
101 
102 //______________________________________________________________________________
103 TChain* CreateChainFromCollection(const char *xmlfile)
104 {
105  // Create a chain from the collection of tags.
106  TAlienCollection* coll = TAlienCollection::Open(xmlfile);
107  if (!coll) {
108  ::Error("CreateChainFromTags", "Cannot create an AliEn collection from %s", xmlfile);
109  return NULL;
110  }
111 
112  TGridResult* tagResult = coll->GetGridResult("",kFALSE,kFALSE);
113  AliTagAnalysis *tagAna = new AliTagAnalysis("ESD");
114  tagAna->ChainGridTags(tagResult);
115 
116  AliRunTagCuts *runCuts = new AliRunTagCuts();
117  AliLHCTagCuts *lhcCuts = new AliLHCTagCuts();
118  AliDetectorTagCuts *detCuts = new AliDetectorTagCuts();
119  AliEventTagCuts *evCuts = new AliEventTagCuts();
120 
121  // Check if the cuts configuration file was provided
122  if (!gSystem->AccessPathName("ConfigureCuts.C")) {
123  gROOT->LoadMacro("ConfigureCuts.C");
124  ConfigureCuts(runCuts, lhcCuts, detCuts, evCuts);
125  }
126 
127  TChain *chain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evCuts);
128  if (!chain || !chain->GetNtrees()) return NULL;
129  chain->ls();
130  return chain;
131 }
132 
133 //______________________________________________________________________________
134 TChain* CreateChainFromFile(const char *rootfile)
135 {
136  // Create a chain using the root file.
137  TChain* chain = new TChain("esdTree");
138  chain->Add(rootfile);
139  if (!chain->GetNtrees()) return NULL;
140  chain->ls();
141  return chain;
142 }
143 
144 //______________________________________________________________________________
145 TChain* CreateChainFromESDList(const char *esdList)
146 {
147  // Create a chain using tags from the run list.
148  TChain* chain = new TChain("esdTree");
149  ifstream inFile(esdList);
150  TString inFileName;
151  if (inFile.is_open()) {
152  while (! inFile.eof() ) {
153  inFileName.ReadLine(inFile,kFALSE);
154  if(!inFileName.EndsWith(".root")) continue;
155  chain->Add(inFileName.Data());
156  }
157  }
158  inFile.close();
159  if (!chain->GetNtrees()) return NULL;
160  chain->ls();
161  return chain;
162 }
163 
164 //______________________________________________________________________________
165 TChain* CreateChain(TString inputFileName)
166 {
167  printf("*******************************\n");
168  printf("*** Getting the Chain ***\n");
169  printf("*******************************\n");
170  Int_t mode = GetMode(inputFileName);
171  if(mode == kInteractif_xml) return CreateChainFromCollection(inputFileName.Data());
172  else if (mode == kInteractif_ESDList) return CreateChainFromESDList(inputFileName.Data());
173  else if (mode == kLocal) return CreateChainFromFile(inputFileName.Data());
174  else return NULL;
175 }
176 
TChain * CreateChainFromFile(const char *rootfile)
Definition: RunMuonQA.C:134
TSystem * gSystem
Quality assurance of MUON ESDs.
int Int_t
Definition: External.C:63
TChain * CreateChainFromCollection(const char *xmlfile)
Definition: RunMuonQA.C:103
TChain * CreateChainFromESDList(const char *esdList)
Definition: RunMuonQA.C:145
void RunMuonQA(TString inputFileName="AliESDs.root", Bool_t isMC=kFALSE, Bool_t selectEvent=kTRUE, Bool_t selectMatched=kTRUE, Bool_t applyAccCut=kTRUE, Short_t selectCharge=0)
Definition: RunMuonQA.C:20
TChain * CreateChain(TString inputFileName)
Definition: RunMuonQA.C:165
Int_t mode
Definition: anaM.C:41
Int_t GetMode(TString inputFileName)
Definition: RunMuonQA.C:94
short Short_t
Definition: External.C:23
Bool_t isMC
bool Bool_t
Definition: External.C:53