]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGPP/MUON/lite/AliAnalysisTaskTrigChEff.cxx
Additional changes for HF-MUON
[u/mrichter/AliRoot.git] / PWGPP / MUON / lite / AliAnalysisTaskTrigChEff.cxx
CommitLineData
ebbabac1 1/**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
27de2dfb 16/* $Id$ */
17
ebbabac1 18//-----------------------------------------------------------------------------
19/// \class AliAnalysisTaskSingleMu
20/// Analysis task for single muons in the spectrometer.
21/// The output is a list of histograms.
22/// The macro class can run on AOD or ESDs.
23/// If Monte Carlo information is present, some basics checks are performed.
24///
25/// \author Diego Stocco
26//-----------------------------------------------------------------------------
27
28//----------------------------------------------------------------------------
29// Implementation of the class for trigger chamber efficiency determinaltion
30//----------------------------------------------------------------------------
31
32
59156747 33#define AliAnalysisTaskTrigChEff_cxx
34
35// ROOT includes
59156747 36#include "TH1.h"
6228ecd4 37#include "TH2.h"
59156747 38#include "TCanvas.h"
39#include "TROOT.h"
40#include "TString.h"
41#include "TList.h"
5623f0cb 42#include "TGraphAsymmErrors.h"
59156747 43
44// STEER includes
45#include "AliLog.h"
59156747 46#include "AliESDEvent.h"
47#include "AliESDMuonTrack.h"
6324068c 48#include "AliAnalysisManager.h"
59156747 49
59156747 50// ANALYSIS includes
ebbabac1 51#include "AliAnalysisTaskSE.h"
52
59156747 53#include "AliAnalysisTaskTrigChEff.h"
54
55ClassImp(AliAnalysisTaskTrigChEff)
56
6324068c 57//________________________________________________________________________
58AliAnalysisTaskTrigChEff::AliAnalysisTaskTrigChEff() :
59AliAnalysisTaskSE(),
60fUseGhosts(kFALSE),
61fList(0)
62{
63 //
64 /// Default constructor
65}
66
67
59156747 68//________________________________________________________________________
69AliAnalysisTaskTrigChEff::AliAnalysisTaskTrigChEff(const char *name) :
ebbabac1 70 AliAnalysisTaskSE(name),
73a0c99f 71 fUseGhosts(kFALSE),
59156747 72 fList(0)
73{
74 //
6324068c 75 /// Constructor
59156747 76 //
6324068c 77
ebbabac1 78 DefineOutput(1, TList::Class());
59156747 79}
80
b201705a 81//________________________________________________________________________
82AliAnalysisTaskTrigChEff::~AliAnalysisTaskTrigChEff()
83{
6324068c 84 if ( ! AliAnalysisManager::GetAnalysisManager()->IsProofMode() )
85 delete fList;
b201705a 86}
87
6228ecd4 88//_________________________________________________________________________
ebbabac1 89void AliAnalysisTaskTrigChEff::UserCreateOutputObjects() {
59156747 90 //
91 /// Create histograms
92 /// Called once
93 //
59156747 94
6228ecd4 95 TString countTypeName[kNcounts] = {"bendPlane", "nonBendPlane","bothPlanes", "allTracks"};
59156747 96
a6e0ebfe 97 const Char_t* yAxisTitle = "counts";
59156747 98
99 const Int_t kNboards = 234; //AliMpConstants::NofLocalBoards();
100 const Int_t kFirstTrigCh = 11;//AliMpConstants::NofTrackingChambers()+1;
101
102 Int_t chamberBins = kNchambers;
103 Float_t chamberLow = kFirstTrigCh-0.5, chamberHigh = kFirstTrigCh+kNchambers-0.5;
a6e0ebfe 104 const Char_t* chamberName = "chamber";
59156747 105
106 Int_t slatBins = kNslats;
107 Float_t slatLow = 0-0.5, slatHigh = kNslats-0.5;
a6e0ebfe 108 const Char_t* slatName = "slat";
59156747 109
110 Int_t boardBins = kNboards;
111 Float_t boardLow = 1-0.5, boardHigh = kNboards+1.-0.5;
a6e0ebfe 112 const Char_t* boardName = "board";
59156747 113
6228ecd4 114 TString baseName, histoName, histoTitle;
59156747 115 fList = new TList();
6324068c 116 fList->SetOwner();
59156747 117
118 TH1F* histo;
6228ecd4 119 TH2F* histo2D;
120
121 Int_t histoIndex = -1;
122
123 for(Int_t icount=0; icount<kNcounts; icount++){
124 histoName = Form("%sCountChamber", countTypeName[icount].Data());
125 histo = new TH1F(histoName, histoName,
126 chamberBins, chamberLow, chamberHigh);
127 histo->GetXaxis()->SetTitle(chamberName);
128 histo->GetYaxis()->SetTitle(yAxisTitle);
129 histoIndex = GetHistoIndex(kHchamberEff, icount);
130 fList->AddAt(histo, histoIndex);
131 } // loop on counts
59156747 132
6228ecd4 133 for(Int_t icount=0; icount<kNcounts; icount++){
134 for(Int_t ch=0; ch<kNchambers; ch++){
135 histoName = Form("%sCountSlatCh%i", countTypeName[icount].Data(), kFirstTrigCh+ch);
59156747 136 histo = new TH1F(histoName, histoName,
6228ecd4 137 slatBins, slatLow, slatHigh);
138 histo->GetXaxis()->SetTitle(slatName);
59156747 139 histo->GetYaxis()->SetTitle(yAxisTitle);
6228ecd4 140 histoIndex = GetHistoIndex(kHslatEff, icount, ch);
141 fList->AddAt(histo, histoIndex);
142 } // loop on chamber
59156747 143 } // loop on counts
144
6228ecd4 145 for(Int_t icount=0; icount<kNcounts; icount++){
146 for(Int_t ch=0; ch<kNchambers; ch++){
147 histoName = Form("%sCountBoardCh%i", countTypeName[icount].Data(), kFirstTrigCh+ch);
148 histo = new TH1F(histoName, histoName,
149 boardBins, boardLow, boardHigh);
150 histo->GetXaxis()->SetTitle(boardName);
151 histo->GetYaxis()->SetTitle(yAxisTitle);
152 histoIndex = GetHistoIndex(kHboardEff, icount, ch);
153 fList->AddAt(histo, histoIndex);
154 } // loop on chamber
59156747 155 } // loop on counts
73a0c99f 156
6228ecd4 157 histo2D = new TH2F("checkRejectedBoard", "Rejected tracks motivation",
158 4, 20.5, 24.5, boardBins, boardLow, boardHigh);
159 histo2D->GetXaxis()->SetBinLabel(1,"Many pads");
160 histo2D->GetXaxis()->SetBinLabel(2,"Few pads");
161 histo2D->GetXaxis()->SetBinLabel(3,"Outside geom");
162 histo2D->GetXaxis()->SetBinLabel(4,"Tracker track");
163 histo2D->GetYaxis()->SetTitle(boardName);
164 histoIndex = GetHistoIndex(kHcheckBoard);
165 fList->AddAt(histo2D, histoIndex);
6324068c 166
167 PostData(1, fList);
59156747 168}
169
170//________________________________________________________________________
ebbabac1 171void AliAnalysisTaskTrigChEff::UserExec(Option_t *) {
59156747 172 //
173 /// Main loop
174 /// Called for each event
175 //
ebbabac1 176 AliESDEvent* esdEvent = dynamic_cast<AliESDEvent*> (InputEvent());
177
178 if (!esdEvent) {
179 Printf("ERROR: esdEvent not available\n");
180 return;
181 }
182
183 Int_t slat = 0, board = 0;
59156747 184 UShort_t pattern = 0;
185 AliESDMuonTrack *esdTrack = 0x0;
59156747 186
ebbabac1 187 Int_t nTracks = esdEvent->GetNumberOfMuonTracks();
73a0c99f 188
59156747 189 const Int_t kFirstTrigCh = 11; //AliMpConstants::NofTrackingChambers()+1;
190
ebbabac1 191 TArrayI othersEfficient(kNchambers);
6228ecd4 192 Int_t histoIndex = -1;
ebbabac1 193
59156747 194 for (Int_t itrack = 0; itrack < nTracks; itrack++) {
ebbabac1 195 esdTrack = esdEvent->GetMuonTrack(itrack);
73a0c99f 196
197 if ( ! esdTrack->ContainTrackerData() && ! fUseGhosts ) continue;
59156747 198
ebbabac1 199 pattern = esdTrack->GetHitsPatternInTrigCh();
73a0c99f 200 Int_t effFlag = AliESDMuonTrack::GetEffFlag(pattern);
59156747 201
6228ecd4 202 board = esdTrack->LoCircuit();
59156747 203
6228ecd4 204 if(effFlag < AliESDMuonTrack::kChEff) {
205 histoIndex = GetHistoIndex(kHcheckBoard);
206 ((TH2F*)fList->At(histoIndex))->Fill(AliESDMuonTrack::GetSlatOrInfo(pattern), board);
207 continue; // Track not good for efficiency calculation
208 }
59156747 209
ebbabac1 210 othersEfficient.Reset(1);
211 for(Int_t cath=0; cath<kNcathodes; cath++){
212 for(Int_t ich=0; ich<kNchambers; ich++){
213 if( ! AliESDMuonTrack::IsChamberHit(pattern, cath, ich)){
214 for(Int_t jch=0; jch<kNchambers; jch++){
215 if ( jch != ich) {
216 othersEfficient[jch] = 0;
ebbabac1 217 }
218 } // loop on other chambers
219 break;
220 } // if chamber not efficient
221 } // loop on chambers
222 } // loop on cathodes
223
224 Bool_t rejectTrack = kTRUE;
225 for (Int_t ich=0; ich<kNchambers; ich++){
226 if ( othersEfficient[ich] > 0 ){
227 rejectTrack = kFALSE;
228 break;
229 }
230 }
231
232 if ( rejectTrack ) continue;
233
234 slat = AliESDMuonTrack::GetSlatOrInfo(pattern);
73a0c99f 235
6228ecd4 236 for(Int_t ch=0; ch<kNchambers; ch++){
237 if ( ! othersEfficient[ch] )
238 continue; // Reject track if the info of the chamber under study
239 // is necessary to create the track itself
59156747 240
6228ecd4 241 Int_t iChamber = kFirstTrigCh + ch;
ebbabac1 242
6228ecd4 243 Bool_t hitsBend = AliESDMuonTrack::IsChamberHit(pattern, 0, ch);
244 Bool_t hitsNonBend = AliESDMuonTrack::IsChamberHit(pattern, 1, ch);
73a0c99f 245
6228ecd4 246 Bool_t fillHisto[kNcounts] = {
247 hitsBend,
248 hitsNonBend,
249 ( hitsBend && hitsNonBend ),
250 kTRUE
251 };
252
253 for (Int_t icount=0; icount<kNcounts; icount++){
254 if ( ! fillHisto[icount] ) continue;
255
256 histoIndex = GetHistoIndex(kHchamberEff, icount);
257 ((TH1F*)fList->At(histoIndex))->Fill(iChamber);
59156747 258
73a0c99f 259 if(effFlag < AliESDMuonTrack::kSlatEff) continue; // Track crossed different slats
6228ecd4 260 histoIndex = GetHistoIndex(kHslatEff, icount, ch);
261 ((TH1F*)fList->At(histoIndex))->Fill(slat);
59156747 262
73a0c99f 263 if(effFlag < AliESDMuonTrack::kBoardEff) continue; // Track crossed different boards
6228ecd4 264 histoIndex = GetHistoIndex(kHboardEff, icount, ch);
265 ((TH1F*)fList->At(histoIndex))->Fill(board);
59156747 266 } // loop on chambers
6228ecd4 267 } // loop on count types
ebbabac1 268 } // loop on tracks
59156747 269
270 // Post final data. It will be written to a file with option "RECREATE"
ebbabac1 271 PostData(1, fList);
59156747 272}
273
274//________________________________________________________________________
275void AliAnalysisTaskTrigChEff::Terminate(Option_t *) {
276 //
277 /// Draw result to the screen
278 /// Called once at the end of the query.
279 //
5623f0cb 280 if ( gROOT->IsBatch() ) return;
281 fList = dynamic_cast<TList*> (GetOutputData(1));
282
6228ecd4 283 if (!fList) return;
284
5623f0cb 285 TCanvas *can;
286 TH1F *num = 0x0;
287 TH1F *den = 0x0;
288 TGraphAsymmErrors* effGraph = 0x0;
289 TString baseName[3] = {"Chamber", "RPC", "Board"};
6228ecd4 290 Int_t baseIndex[3] = {kHchamberEff, kHslatEff, kHboardEff};
291 TString effName[kNcounts-1] = {"BendPlane", "NonBendPlane", "BothPlanes"};
292 Int_t histoIndexNum = -1, histoIndexDen = -1;
5623f0cb 293 for (Int_t itype=0; itype<3; itype++) {
f86fc5df 294 for(Int_t icount=0; icount<kNcounts-1; icount++){
6228ecd4 295 TString canName = Form("efficiencyPer%s_%s",baseName[itype].Data(),effName[icount].Data());
296 can = new TCanvas(canName.Data(),canName.Data(),10*(1+kNcounts*itype+icount),10*(1+kNcounts*itype+icount),310,310);
5623f0cb 297 can->SetFillColor(10); can->SetHighLightColor(10);
298 can->SetLeftMargin(0.15); can->SetBottomMargin(0.15);
299 if ( itype > 0 )
300 can->Divide(2,2);
301
59156747 302 for(Int_t ch=0; ch<kNchambers; ch++){
6228ecd4 303 histoIndexNum = GetHistoIndex(baseIndex[itype], icount, ch);
304 histoIndexDen = GetHistoIndex(baseIndex[itype], kAllTracks, ch);
305 num = (TH1F*)(fList->At(histoIndexNum));
306 den = (TH1F*)(fList->At(histoIndexDen));
5623f0cb 307 effGraph = new TGraphAsymmErrors(num, den);
308 effGraph->GetYaxis()->SetRangeUser(0., 1.1);
309 effGraph->GetYaxis()->SetTitle("Efficiency");
310 effGraph->GetXaxis()->SetTitle(baseName[itype].Data());
311 can->cd(ch+1);
312 effGraph->Draw("AP");
313 if ( itype == 0 ) break;
314 } // loop on chamber
6228ecd4 315 } // loop on count types
5623f0cb 316 } // loop on histo
59156747 317}
6228ecd4 318
319//________________________________________________________________________
320Int_t
321AliAnalysisTaskTrigChEff::GetHistoIndex(Int_t histoType, Int_t countType,
322 Int_t chamber)
323{
324 //
325 /// Return the index of the histogram in the list
326 //
327 switch ( histoType ) {
328 case kHchamberEff:
329 return 0 + countType;
330 case kHslatEff:
331 return 4 + kNchambers*countType + chamber;
332 case kHboardEff:
333 return 20 + kNchambers*countType + chamber;
334 case kHcheckBoard:
335 return 36;
336 }
337
338 /*
339 const Int_t kNhistosPlaneCorr = 38;
340
341 switch ( histoType ){
342 case kHtracksInSlat:
343 return 0 + planeCorrelation*kNhistosPlaneCorr;
344 case kHtracksInBoard:
345 return 1 + planeCorrelation*kNhistosPlaneCorr;
346 case kHchamberEff:
347 return 2 + kNcathodes*countType + cathode
348 + planeCorrelation*kNhistosPlaneCorr;
349 case kHslatEff:
350 return 6 + kNchambers*kNcathodes*countType
351 + kNchambers*cathode + chamber
352 + planeCorrelation*kNhistosPlaneCorr;
353 case kHboardEff:
354 return 22 + kNchambers*kNcathodes*countType
355 + kNchambers*cathode + chamber
356 + planeCorrelation*kNhistosPlaneCorr;
357 case kHcheckBoard:
358 return 0 + 2*kNhistosPlaneCorr;
359 }
360 */
361 return -1;
362}