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