]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/muon/AliAnalysisTaskTrigChEff.cxx
Update of Single Muon analysis to be included in the official ESD->AOD analysis train...
[u/mrichter/AliRoot.git] / PWG3 / muon / AliAnalysisTaskTrigChEff.cxx
1 #define AliAnalysisTaskTrigChEff_cxx
2
3 // ROOT includes
4 #include "TChain.h"
5 #include "TH1.h"
6 #include "TCanvas.h"
7 #include "TROOT.h"
8 #include "TString.h"
9 #include "TList.h"
10
11 // STEER includes
12 #include "AliLog.h"
13
14 #include "AliESDEvent.h"
15 #include "AliESDMuonTrack.h"
16 #include "AliESDInputHandler.h"
17
18 // ANALYSIS includes
19 #include "AliAnalysisTask.h"
20 #include "AliAnalysisDataSlot.h"
21 #include "AliAnalysisManager.h"
22 #include "AliAnalysisTaskTrigChEff.h"
23
24 ClassImp(AliAnalysisTaskTrigChEff)
25
26 //________________________________________________________________________
27 AliAnalysisTaskTrigChEff::AliAnalysisTaskTrigChEff(const char *name) :
28   AliAnalysisTask(name,""), 
29   fESD(0),
30   fUseGhosts(kFALSE),
31   fList(0)
32 {
33   //
34   /// Constructor.
35   //
36   // Input slot #0 works with an Ntuple
37   DefineInput(0, TChain::Class());
38   // Output slot #0 writes into a TObjArray container
39   DefineOutput(0,  TList::Class());
40 }
41
42 //___________________________________________________________________________
43 void AliAnalysisTaskTrigChEff::ConnectInputData(Option_t *) {
44   //
45   /// Connect ESD here
46   /// Called once
47   //
48
49   TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
50   if (!tree) {
51     Printf("ERROR: Could not read chain from input slot 0");
52   } else {
53     // Disable all branches and enable only the needed ones
54     // The next two lines are different when data produced as AliESDEvent is read
55     tree->SetBranchStatus("*", kFALSE);
56     tree->SetBranchStatus("MuonTracks.*", kTRUE);
57
58     AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
59       
60     if (!esdH) {
61       Printf("ERROR: Could not get ESDInputHandler");
62     } else
63       fESD = esdH->GetEvent();
64   }
65 }
66
67 //___________________________________________________________________________
68 void AliAnalysisTaskTrigChEff::CreateOutputObjects() {
69   //
70   /// Create histograms
71   /// Called once
72   //
73   Printf("   CreateOutputObjects of task %s\n", GetName());
74
75   TString cathCode[2] = {"bendPlane", "nonBendPlane"};
76   TString countTypeName[2] = {"CountInCh", "NonCountInCh"};
77
78   const Char_t* yAxisTitle = "counts";
79
80   const Int_t kNboards = 234; //AliMpConstants::NofLocalBoards();
81   const Int_t kFirstTrigCh = 11;//AliMpConstants::NofTrackingChambers()+1;
82
83   Int_t chamberBins = kNchambers;
84   Float_t chamberLow = kFirstTrigCh-0.5, chamberHigh = kFirstTrigCh+kNchambers-0.5;
85   const Char_t* chamberName = "chamber";
86
87   Int_t slatBins = kNslats;
88   Float_t slatLow = 0-0.5, slatHigh = kNslats-0.5;
89   const Char_t* slatName = "slat";
90
91   Int_t boardBins = kNboards;
92   Float_t boardLow = 1-0.5, boardHigh = kNboards+1.-0.5;
93   const Char_t* boardName = "board";
94
95   Int_t angleBins = 140;
96   Float_t angleLow = -35., angleHigh = 35.;
97   const Char_t* angleNameX = "#theta_{x} (deg)";
98   const Char_t* angleNameY = "#theta_{y} (deg)";
99
100   TString baseName, histoName;
101   fList = new TList();
102
103   TH1F* histo;
104
105   histo = new TH1F("nTracksInSlat", "Num. of tracks used for efficiency calculation", 
106                    slatBins, slatLow, slatHigh);
107   histo->GetXaxis()->SetTitle(slatName);
108   histo->GetYaxis()->SetTitle("num of used tracks");
109
110   fList->AddAt(histo, kHtracksInSlat);
111
112   histo = new TH1F("nTracksInBoard", "Num. of tracks used for efficiency calculation", 
113                    boardBins, boardLow, boardHigh);
114   histo->GetXaxis()->SetTitle(boardName);
115   histo->GetYaxis()->SetTitle("num of used tracks");
116
117   fList->AddAt(histo, kHtracksInBoard);
118
119   for(Int_t hType=0; hType<kNcounts; hType++){
120     Int_t hindex = (hType==0) ? kHchamberAllEff : kHchamberNonEff;
121     for(Int_t cath=0; cath<kNcathodes; cath++){
122       histoName = Form("%sChamber%s", cathCode[cath].Data(), countTypeName[hType].Data());
123       histo = new TH1F(histoName, histoName,
124                        chamberBins, chamberLow, chamberHigh);
125       histo->GetXaxis()->SetTitle(chamberName);
126       histo->GetYaxis()->SetTitle(yAxisTitle);
127         
128       fList->AddAt(histo, hindex + cath);
129     } // loop on cath
130   } // loop on counts
131
132   for(Int_t hType=0; hType<kNcounts; hType++){
133     Int_t hindex = (hType==0) ? kHslatAllEff : kHslatNonEff;
134     for(Int_t cath=0; cath<kNcathodes; cath++){
135       for(Int_t ch=0; ch<kNchambers; ch++){
136         Int_t chCath = GetPlane(cath, ch);
137         histoName = Form("%sSlat%s%i", cathCode[cath].Data(), countTypeName[hType].Data(), kFirstTrigCh+ch);
138         histo = new TH1F(histoName, histoName,
139                          slatBins, slatLow, slatHigh);
140         histo->GetXaxis()->SetTitle(slatName);
141         histo->GetYaxis()->SetTitle(yAxisTitle);
142
143         fList->AddAt(histo, hindex + chCath);
144       } // loop on chamber
145     } // loop on cath
146   } // loop on counts
147
148   for(Int_t hType=0; hType<kNcounts; hType++){
149     Int_t hindex = (hType==0) ? kHboardAllEff : kHboardNonEff;
150     for(Int_t cath=0; cath<kNcathodes; cath++){
151       for(Int_t ch=0; ch<kNchambers; ch++){
152         Int_t chCath = GetPlane(cath, ch);
153         histoName = Form("%sBoard%s%i", cathCode[cath].Data(), countTypeName[hType].Data(), kFirstTrigCh+ch);
154         histo = new TH1F(histoName, histoName,
155                          boardBins, boardLow, boardHigh);
156         histo->GetXaxis()->SetTitle(boardName);
157         histo->GetYaxis()->SetTitle(yAxisTitle);
158
159         fList->AddAt(histo, hindex + chCath);
160       } // loop on chamber
161     } // loop on cath
162   } // loop on counts
163
164   histo = new TH1F("thetaX", "Angular distribution",
165                    angleBins, angleLow, angleHigh);
166   histo->GetXaxis()->SetTitle(angleNameX);
167   histo->GetYaxis()->SetTitle("entries");
168   fList->AddAt(histo, kHthetaX);
169
170   histo = new TH1F("thetaY", "Angular distribution",
171                    angleBins, angleLow, angleHigh);
172   histo->GetXaxis()->SetTitle(angleNameY);
173   histo->GetYaxis()->SetTitle("entries");
174   fList->AddAt(histo, kHthetaY);
175
176 }
177
178 //________________________________________________________________________
179 void AliAnalysisTaskTrigChEff::Exec(Option_t *) {
180   //
181   /// Main loop
182   /// Called for each event
183   //
184   Int_t nTracks = 0, board = 0;
185   UShort_t pattern = 0;
186   AliESDMuonTrack *esdTrack = 0x0;
187
188   const Float_t kRadToDeg = 180./TMath::Pi();
189
190   if (!fESD) {
191     Printf("ERROR: fESD not available");
192     return;
193   }
194   nTracks = fESD->GetNumberOfMuonTracks();
195
196   // Object declaration
197   const Int_t kFirstTrigCh = 11; //AliMpConstants::NofTrackingChambers()+1;
198
199   for (Int_t itrack = 0; itrack < nTracks; itrack++) {
200     esdTrack = fESD->GetMuonTrack(itrack);
201     pattern =  esdTrack->GetHitsPatternInTrigCh();
202     board = esdTrack->LoCircuit();
203
204     if ( ! esdTrack->ContainTrackerData() && ! fUseGhosts ) continue;
205
206     Int_t effFlag = AliESDMuonTrack::GetEffFlag(pattern);
207
208     if(effFlag < AliESDMuonTrack::kChEff) continue; // Track not good for efficiency calculation
209
210     ((TH1F*)fList->At(kHthetaX))->Fill(esdTrack->GetThetaX() * kRadToDeg);
211     ((TH1F*)fList->At(kHthetaY))->Fill(esdTrack->GetThetaY() * kRadToDeg);
212
213     Int_t slat = AliESDMuonTrack::GetSlatOrInfo(pattern);
214
215     if(effFlag >= AliESDMuonTrack::kSlatEff) ((TH1F*)fList->At(kHtracksInSlat))->Fill(slat);
216     if(effFlag >= AliESDMuonTrack::kBoardEff) ((TH1F*)fList->At(kHtracksInBoard))->Fill(board);
217
218     for(Int_t cath=0; cath<kNcathodes; cath++){
219       Int_t ineffCh = -1;
220       for(Int_t ich=0; ich<kNchambers; ich++){
221         if(!AliESDMuonTrack::IsChamberHit(pattern, cath, ich)){
222           ineffCh = ich;
223           break;
224         }
225       }
226
227       Int_t nChambers = kNchambers;
228       for(Int_t ch=0; ch<nChambers; ch++){
229         Int_t whichType = kAllChEff;
230         Int_t currCh = ch;
231         if(ineffCh>=0){
232           whichType = kChNonEff;
233           currCh = ineffCh;
234           nChambers = -1;
235         }
236
237         Int_t iChamber = kFirstTrigCh + currCh;
238         Int_t hindex = (whichType==kAllChEff) ? kHchamberAllEff : kHchamberNonEff;
239         ((TH1F*)fList->At(hindex + cath))->Fill(iChamber);
240
241         if(effFlag < AliESDMuonTrack::kSlatEff) continue; // Track crossed different slats
242         Int_t chCath = GetPlane(cath, currCh);
243         hindex = (whichType==kAllChEff) ? kHslatAllEff : kHslatNonEff;
244         ((TH1F*)fList->At(hindex + chCath))->Fill(slat);
245
246         if(effFlag < AliESDMuonTrack::kBoardEff) continue; // Track crossed different boards
247         hindex = (whichType==kAllChEff) ? kHboardAllEff : kHboardNonEff;
248         ((TH1F*)fList->At(hindex + chCath))->Fill(board);
249       } // loop on chambers
250     } // loop on cathodes
251   }
252
253   // Post final data. It will be written to a file with option "RECREATE"
254   PostData(0, fList);
255 }
256
257 //________________________________________________________________________
258 void AliAnalysisTaskTrigChEff::Terminate(Option_t *) {
259   //
260   /// Draw result to the screen
261   /// Called once at the end of the query.
262   //
263   if (!gROOT->IsBatch()) {
264     TCanvas *can[kNcathodes];
265     TH1F *num = 0x0;
266     TH1F *den = 0x0;
267     for(Int_t cath=0; cath<kNcathodes; cath++){
268       TString canName = Form("can%i",cath);
269       can[cath] = new TCanvas(canName.Data(),canName.Data(),10*(1+cath),10*(1+cath),310,310);
270       can[cath]->SetFillColor(10); can[cath]->SetHighLightColor(10);
271       can[cath]->SetLeftMargin(0.15); can[cath]->SetBottomMargin(0.15);  
272       can[cath]->Divide(2,2);
273       for(Int_t ch=0; ch<kNchambers; ch++){
274         Int_t chCath = GetPlane(cath, ch);
275         num = (TH1F*)(fList->At(kHboardAllEff + chCath)->Clone());
276         den = (TH1F*)(fList->At(kHboardNonEff + chCath)->Clone());
277         den->Add(num);
278         num->Divide(den);
279         can[cath]->cd(ch+1);
280         num->DrawCopy("E");
281       }
282     }
283   }
284 }