]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG3/muon/AliAnalysisTaskTrigChEff.cxx
Adding Id to PWG3 classes for better tracking of the coverity defect fixes (Ivana)
[u/mrichter/AliRoot.git] / PWG3 / muon / AliAnalysisTaskTrigChEff.cxx
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
16 /* $Id$ */
17
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
33 #define AliAnalysisTaskTrigChEff_cxx
34
35 // ROOT includes
36 #include "TH1.h"
37 #include "TH2.h"
38 #include "TCanvas.h"
39 #include "TROOT.h"
40 #include "TString.h"
41 #include "TList.h"
42 #include "TGraphAsymmErrors.h"
43
44 // STEER includes
45 #include "AliLog.h"
46 #include "AliESDEvent.h"
47 #include "AliESDMuonTrack.h"
48
49 // ANALYSIS includes
50 #include "AliAnalysisTaskSE.h"
51
52 #include "AliAnalysisTaskTrigChEff.h"
53
54 ClassImp(AliAnalysisTaskTrigChEff)
55
56 //________________________________________________________________________
57 AliAnalysisTaskTrigChEff::AliAnalysisTaskTrigChEff(const char *name) :
58   AliAnalysisTaskSE(name), 
59   fUseGhosts(kFALSE),
60   fList(0)
61 {
62   //
63   /// Constructor.
64   //
65   // Output slot #1 writes into a TObjArray container
66   DefineOutput(1,  TList::Class());
67 }
68
69 //________________________________________________________________________
70 AliAnalysisTaskTrigChEff::~AliAnalysisTaskTrigChEff()
71 {
72   delete fList;
73 }
74
75 //_________________________________________________________________________
76 void AliAnalysisTaskTrigChEff::UserCreateOutputObjects() {
77   //
78   /// Create histograms
79   /// Called once
80   //
81
82   TString countTypeName[kNcounts] = {"bendPlane", "nonBendPlane","bothPlanes", "allTracks"};
83
84   const Char_t* yAxisTitle = "counts";
85
86   const Int_t kNboards = 234; //AliMpConstants::NofLocalBoards();
87   const Int_t kFirstTrigCh = 11;//AliMpConstants::NofTrackingChambers()+1;
88
89   Int_t chamberBins = kNchambers;
90   Float_t chamberLow = kFirstTrigCh-0.5, chamberHigh = kFirstTrigCh+kNchambers-0.5;
91   const Char_t* chamberName = "chamber";
92
93   Int_t slatBins = kNslats;
94   Float_t slatLow = 0-0.5, slatHigh = kNslats-0.5;
95   const Char_t* slatName = "slat";
96
97   Int_t boardBins = kNboards;
98   Float_t boardLow = 1-0.5, boardHigh = kNboards+1.-0.5;
99   const Char_t* boardName = "board";
100
101   TString baseName, histoName, histoTitle;
102   fList = new TList();
103
104   TH1F* histo;
105   TH2F* histo2D;
106
107   Int_t histoIndex = -1;
108
109   for(Int_t icount=0; icount<kNcounts; icount++){
110     histoName = Form("%sCountChamber", countTypeName[icount].Data());
111     histo = new TH1F(histoName, histoName,
112                      chamberBins, chamberLow, chamberHigh);
113     histo->GetXaxis()->SetTitle(chamberName);
114     histo->GetYaxis()->SetTitle(yAxisTitle);
115     histoIndex = GetHistoIndex(kHchamberEff, icount);
116     fList->AddAt(histo, histoIndex);
117   } // loop on counts
118
119   for(Int_t icount=0; icount<kNcounts; icount++){
120     for(Int_t ch=0; ch<kNchambers; ch++){
121       histoName = Form("%sCountSlatCh%i", countTypeName[icount].Data(), kFirstTrigCh+ch);
122       histo = new TH1F(histoName, histoName,
123                        slatBins, slatLow, slatHigh);
124       histo->GetXaxis()->SetTitle(slatName);
125       histo->GetYaxis()->SetTitle(yAxisTitle);
126       histoIndex = GetHistoIndex(kHslatEff, icount, ch);
127       fList->AddAt(histo, histoIndex);
128     } // loop on chamber
129   } // loop on counts
130
131   for(Int_t icount=0; icount<kNcounts; icount++){
132     for(Int_t ch=0; ch<kNchambers; ch++){
133       histoName = Form("%sCountBoardCh%i", countTypeName[icount].Data(), kFirstTrigCh+ch);
134       histo = new TH1F(histoName, histoName,
135                        boardBins, boardLow, boardHigh);
136       histo->GetXaxis()->SetTitle(boardName);
137       histo->GetYaxis()->SetTitle(yAxisTitle);
138       histoIndex = GetHistoIndex(kHboardEff, icount, ch);
139       fList->AddAt(histo, histoIndex);
140     } // loop on chamber
141   } // loop on counts
142
143   histo2D = new TH2F("checkRejectedBoard", "Rejected tracks motivation", 
144                      4, 20.5, 24.5, boardBins, boardLow, boardHigh);
145   histo2D->GetXaxis()->SetBinLabel(1,"Many pads");
146   histo2D->GetXaxis()->SetBinLabel(2,"Few pads");
147   histo2D->GetXaxis()->SetBinLabel(3,"Outside geom");
148   histo2D->GetXaxis()->SetBinLabel(4,"Tracker track");
149   histo2D->GetYaxis()->SetTitle(boardName);
150   histoIndex = GetHistoIndex(kHcheckBoard);
151   fList->AddAt(histo2D, histoIndex);
152 }
153
154 //________________________________________________________________________
155 void AliAnalysisTaskTrigChEff::UserExec(Option_t *) {
156   //
157   /// Main loop
158   /// Called for each event
159   //
160   AliESDEvent* esdEvent = dynamic_cast<AliESDEvent*> (InputEvent());
161
162   if (!esdEvent) {
163     Printf("ERROR: esdEvent not available\n");
164     return;
165   }
166
167   Int_t slat = 0, board = 0;
168   UShort_t pattern = 0;
169   AliESDMuonTrack *esdTrack = 0x0;
170
171   Int_t nTracks = esdEvent->GetNumberOfMuonTracks();
172
173   const Int_t kFirstTrigCh = 11; //AliMpConstants::NofTrackingChambers()+1;
174
175   TArrayI othersEfficient(kNchambers);
176   Int_t histoIndex = -1;
177
178   for (Int_t itrack = 0; itrack < nTracks; itrack++) {
179     esdTrack = esdEvent->GetMuonTrack(itrack);
180
181     if ( ! esdTrack->ContainTrackerData() && ! fUseGhosts ) continue;
182
183     pattern =  esdTrack->GetHitsPatternInTrigCh();
184     Int_t effFlag = AliESDMuonTrack::GetEffFlag(pattern);
185
186     board = esdTrack->LoCircuit();
187
188     if(effFlag < AliESDMuonTrack::kChEff) {
189       histoIndex = GetHistoIndex(kHcheckBoard);
190       ((TH2F*)fList->At(histoIndex))->Fill(AliESDMuonTrack::GetSlatOrInfo(pattern), board);
191       continue; // Track not good for efficiency calculation
192     }
193
194     othersEfficient.Reset(1);
195     for(Int_t cath=0; cath<kNcathodes; cath++){
196       for(Int_t ich=0; ich<kNchambers; ich++){
197         if( ! AliESDMuonTrack::IsChamberHit(pattern, cath, ich)){
198           for(Int_t jch=0; jch<kNchambers; jch++){
199             if ( jch != ich) {
200               othersEfficient[jch] = 0;
201             }
202           } // loop on other chambers
203           break;
204         } // if chamber not efficient
205       } // loop on chambers
206     } // loop on cathodes
207
208     Bool_t rejectTrack = kTRUE;
209     for (Int_t ich=0; ich<kNchambers; ich++){
210       if ( othersEfficient[ich] > 0 ){
211         rejectTrack = kFALSE;
212         break;
213       }
214     }
215
216     if ( rejectTrack ) continue;
217
218     slat = AliESDMuonTrack::GetSlatOrInfo(pattern);
219
220     for(Int_t ch=0; ch<kNchambers; ch++){
221       if ( ! othersEfficient[ch] )
222         continue; // Reject track if the info of the chamber under study 
223                   // is necessary to create the track itself
224
225       Int_t iChamber = kFirstTrigCh + ch;
226
227       Bool_t hitsBend = AliESDMuonTrack::IsChamberHit(pattern, 0, ch);
228       Bool_t hitsNonBend = AliESDMuonTrack::IsChamberHit(pattern, 1, ch);
229
230       Bool_t fillHisto[kNcounts] = {
231         hitsBend,
232         hitsNonBend,
233         ( hitsBend && hitsNonBend ),
234         kTRUE
235       };
236
237       for (Int_t icount=0; icount<kNcounts; icount++){
238         if ( ! fillHisto[icount] ) continue;
239
240         histoIndex = GetHistoIndex(kHchamberEff, icount);
241         ((TH1F*)fList->At(histoIndex))->Fill(iChamber);
242
243         if(effFlag < AliESDMuonTrack::kSlatEff) continue; // Track crossed different slats
244         histoIndex = GetHistoIndex(kHslatEff, icount, ch);
245         ((TH1F*)fList->At(histoIndex))->Fill(slat);
246
247         if(effFlag < AliESDMuonTrack::kBoardEff) continue; // Track crossed different boards
248         histoIndex = GetHistoIndex(kHboardEff, icount, ch);
249         ((TH1F*)fList->At(histoIndex))->Fill(board);
250       } // loop on chambers
251     } // loop on count types
252   } // loop on tracks
253
254   // Post final data. It will be written to a file with option "RECREATE"
255   PostData(1, fList);
256 }
257
258 //________________________________________________________________________
259 void AliAnalysisTaskTrigChEff::Terminate(Option_t *) {
260   //
261   /// Draw result to the screen
262   /// Called once at the end of the query.
263   //
264   if ( gROOT->IsBatch() ) return;
265   fList = dynamic_cast<TList*> (GetOutputData(1));
266
267   if (!fList) return;
268
269   TCanvas *can;
270   TH1F *num = 0x0;
271   TH1F *den = 0x0;
272   TGraphAsymmErrors* effGraph = 0x0;
273   TString baseName[3] = {"Chamber", "RPC", "Board"};
274   Int_t baseIndex[3] = {kHchamberEff, kHslatEff, kHboardEff};
275   TString effName[kNcounts-1] = {"BendPlane", "NonBendPlane", "BothPlanes"};
276   Int_t histoIndexNum = -1, histoIndexDen = -1;
277   for (Int_t itype=0; itype<3; itype++) {
278     for(Int_t icount=0; icount<kNcounts-1; icount++){
279       TString canName = Form("efficiencyPer%s_%s",baseName[itype].Data(),effName[icount].Data());
280       can = new TCanvas(canName.Data(),canName.Data(),10*(1+kNcounts*itype+icount),10*(1+kNcounts*itype+icount),310,310);
281       can->SetFillColor(10); can->SetHighLightColor(10);
282       can->SetLeftMargin(0.15); can->SetBottomMargin(0.15);  
283       if ( itype > 0 )
284         can->Divide(2,2);
285
286       for(Int_t ch=0; ch<kNchambers; ch++){
287         histoIndexNum = GetHistoIndex(baseIndex[itype], icount, ch);
288         histoIndexDen = GetHistoIndex(baseIndex[itype], kAllTracks, ch);
289         num = (TH1F*)(fList->At(histoIndexNum));
290         den = (TH1F*)(fList->At(histoIndexDen));
291         effGraph = new TGraphAsymmErrors(num, den);
292         effGraph->GetYaxis()->SetRangeUser(0., 1.1);
293         effGraph->GetYaxis()->SetTitle("Efficiency");
294         effGraph->GetXaxis()->SetTitle(baseName[itype].Data());
295         can->cd(ch+1);
296         effGraph->Draw("AP");
297         if ( itype == 0 ) break;
298       } // loop on chamber
299     } // loop on count types
300   } // loop on histo
301 }
302
303 //________________________________________________________________________
304 Int_t
305 AliAnalysisTaskTrigChEff::GetHistoIndex(Int_t histoType, Int_t countType, 
306                                         Int_t chamber)
307 {
308   //
309   /// Return the index of the histogram in the list
310   //
311   switch ( histoType ) {
312   case kHchamberEff:
313     return 0 + countType;
314   case kHslatEff:
315     return 4 + kNchambers*countType + chamber;
316   case kHboardEff:
317     return 20 + kNchambers*countType + chamber;
318   case kHcheckBoard:
319     return 36;
320   }
321
322   /*
323   const Int_t kNhistosPlaneCorr = 38;
324
325   switch ( histoType ){
326   case kHtracksInSlat:
327     return 0 + planeCorrelation*kNhistosPlaneCorr;
328   case kHtracksInBoard:
329     return 1 + planeCorrelation*kNhistosPlaneCorr;
330   case kHchamberEff:
331     return 2 + kNcathodes*countType + cathode
332       + planeCorrelation*kNhistosPlaneCorr;
333   case kHslatEff:
334     return 6 + kNchambers*kNcathodes*countType 
335       + kNchambers*cathode + chamber
336       + planeCorrelation*kNhistosPlaneCorr;
337   case kHboardEff:
338     return 22 + kNchambers*kNcathodes*countType 
339       + kNchambers*cathode + chamber
340       + planeCorrelation*kNhistosPlaneCorr;
341   case kHcheckBoard:
342     return 0 + 2*kNhistosPlaneCorr;
343   }
344   */
345   return -1;
346 }