]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/PartCorrBase/AliAnalysisTaskCounter.cxx
Remove events with wrong LED firing when clusterizing, valid at least for LHC11a
[u/mrichter/AliRoot.git] / PWG4 / PartCorrBase / AliAnalysisTaskCounter.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /* $Id: $ */
16
17 //_________________________________________________________________________
18 // Count events with different selections
19 //
20 // It produces a histogram with the number of events with 9 bins:
21 // 0: all events (that passed the physics selection if it was on)
22 // 1: same but cross check that event pointer did exist
23 // 2: passes vertex cut
24 // 3: passes track number cut, tracks for eta < 0.8
25 // 4: 3 && 2
26 // 5: pass VAND
27 // 6: 5 && 2
28 // 7: 5 && 3
29 // 8: 5 && 3 && 2
30 // 9: not pileup from SPD
31 // 10: Good vertex
32 // 11: 10 && 5
33 // 12: 10 && 3
34 // 13: 10 && 2
35 // 14: 10 && 2 && 3 && 5
36 // 15: 10 && 9
37 // 16: 9  && 5
38 //
39 // Author: Gustavo Conesa Balbastre (LPSC)
40 //         
41 //_________________________________________________________________________
42
43 #include "TH2F.h"
44 #include "AliAODHeader.h"
45 #include "AliTriggerAnalysis.h"
46 #include "AliESDEvent.h"
47 #include "AliESDtrackCuts.h"
48 #include "AliAnalysisManager.h"
49 #include "AliInputEventHandler.h"
50
51 #include "AliAnalysisTaskCounter.h"
52 ClassImp(AliAnalysisTaskCounter)
53
54 //________________________________________________________________________
55 AliAnalysisTaskCounter::AliAnalysisTaskCounter(const char *name) 
56 : AliAnalysisTaskSE(name), 
57   fZVertexCut(10.),
58   fTrackMultEtaCut(0.8),
59   fCaloFilterPatch(kFALSE),
60   fOutputContainer(0x0), 
61   fESDtrackCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
62   fTriggerAnalysis (new AliTriggerAnalysis),
63   fhNEvents(0),
64   fhXVertex(0),fhYVertex(0),fhZVertex(0),
65   fhXGoodVertex(0),fhYGoodVertex(0),fhZGoodVertex(0)
66 {
67   //ctor
68   DefineOutput(1, TList::Class());
69 }
70
71 //________________________________________________________________________
72 AliAnalysisTaskCounter::AliAnalysisTaskCounter() 
73   : AliAnalysisTaskSE("DefaultAnalysis_AliAnalysisTaskCounter"),
74     fZVertexCut(10.),
75     fTrackMultEtaCut(0.8),
76     fCaloFilterPatch(kFALSE),
77     fOutputContainer(0x0), 
78     fESDtrackCuts(AliESDtrackCuts::GetStandardITSTPCTrackCuts2010()),
79     fTriggerAnalysis (new AliTriggerAnalysis),
80     fhNEvents(0),
81     fhXVertex(0),fhYVertex(0),fhZVertex(0),
82     fhXGoodVertex(0),fhYGoodVertex(0),fhZGoodVertex(0)
83 {
84   // ctor
85   DefineOutput(1, TList::Class());
86 }
87
88 //__________________________________________________
89 AliAnalysisTaskCounter::~AliAnalysisTaskCounter()
90 {
91   //Destructor
92   if(fOutputContainer){
93     fOutputContainer->Delete() ; 
94     delete fOutputContainer ;
95   }
96   
97   if(fESDtrackCuts)    delete fESDtrackCuts;
98   if(fTriggerAnalysis) delete fTriggerAnalysis;
99   
100 }
101
102
103 //-------------------------------------------------------------------
104 void AliAnalysisTaskCounter::UserCreateOutputObjects()
105 {
106   // Init histograms
107   
108   fOutputContainer = new TList();
109   
110   fhZVertex     = new TH1F("hZVertex", " Z vertex distribution"   , 200 , -50 , 50  ) ;
111   fhZVertex->SetXTitle("v_{z} (cm)");
112   fOutputContainer->Add(fhZVertex);
113
114   fhZGoodVertex     = new TH1F("hZGoodVertex", " Good Z vertex distribution"   , 200 , -50 , 50  ) ;
115   fhZGoodVertex->SetXTitle("v_{z} (cm)");
116   fOutputContainer->Add(fhZGoodVertex);
117   
118   fhXVertex     = new TH1F("hXVertex", " X vertex distribution"   , 200 , -2 , 2  ) ;
119   fhXVertex->SetXTitle("v_{x} (cm)");
120   fOutputContainer->Add(fhXVertex);
121   
122   fhXGoodVertex     = new TH1F("hXGoodVertex", " Good X vertex distribution"   , 200 , -2 , 2  ) ;
123   fhXGoodVertex->SetXTitle("v_{x} (cm)");
124   fOutputContainer->Add(fhXGoodVertex);
125   
126   fhYVertex     = new TH1F("hYVertex", " Y vertex distribution"   , 200 , -2 , 2  ) ;
127   fhYVertex->SetXTitle("v_{y} (cm)");
128   fOutputContainer->Add(fhYVertex);
129   
130   fhYGoodVertex     = new TH1F("hYGoodVertex", " Good Y vertex distribution"   , 200 , -2 , 2  ) ;
131   fhYGoodVertex->SetXTitle("v_{y} (cm)");
132   fOutputContainer->Add(fhYGoodVertex);
133   
134   
135   fhNEvents = new TH1I("hNEvents", "Number of analyzed events", 20, 0, 20) ;
136   fhNEvents->SetXTitle("Selection");
137   fhNEvents->SetYTitle("# events");
138   fhNEvents->GetXaxis()->SetBinLabel(1 ,"1  = PS");
139   fhNEvents->GetXaxis()->SetBinLabel(2 ,"2  = 1  & ESD");
140   fhNEvents->GetXaxis()->SetBinLabel(3 ,"3  = 2  & |Z|<10");
141   fhNEvents->GetXaxis()->SetBinLabel(4 ,"4  = 2  & |eta|<0.8");
142   fhNEvents->GetXaxis()->SetBinLabel(5 ,"5  = 3  & 4");
143   fhNEvents->GetXaxis()->SetBinLabel(6 ,"6  = 2  & V0AND");
144   fhNEvents->GetXaxis()->SetBinLabel(7 ,"7  = 3  & 6");
145   fhNEvents->GetXaxis()->SetBinLabel(8 ,"8  = 4  & 6");
146   fhNEvents->GetXaxis()->SetBinLabel(9 ,"9  = 5  & 6");
147   fhNEvents->GetXaxis()->SetBinLabel(10,"10 = 2  & not pileup");
148   fhNEvents->GetXaxis()->SetBinLabel(11,"11 = 2  & good vertex");
149   fhNEvents->GetXaxis()->SetBinLabel(12,"12 = 3  & 11");
150   fhNEvents->GetXaxis()->SetBinLabel(13,"13 = 4  & 11");
151   fhNEvents->GetXaxis()->SetBinLabel(14,"14 = 6  & 11");
152   fhNEvents->GetXaxis()->SetBinLabel(15,"15 = 9  & 11");
153   fhNEvents->GetXaxis()->SetBinLabel(16,"16 = 10 & 11");
154   fhNEvents->GetXaxis()->SetBinLabel(17,"17 = 6  & 10");
155   fhNEvents->GetXaxis()->SetBinLabel(17,"17 = 1  & |Z|<50");  
156   fhNEvents->GetXaxis()->SetBinLabel(18,"18 = Reject EMCAL");
157   fhNEvents->GetXaxis()->SetBinLabel(19,"19 = 18 & 2");
158   fhNEvents->GetXaxis()->SetBinLabel(20,"20 = 18 & |Z|<50");
159
160   fOutputContainer->Add(fhNEvents);
161
162   fOutputContainer->SetOwner(kTRUE);
163   
164   PostData(1,fOutputContainer);
165   
166 }
167
168 //________________________________________________________________________
169 void AliAnalysisTaskCounter::UserExec(Option_t *) 
170 {
171   // Main loop
172   // Called for each event
173   
174   //printf("___ Event __ %d __\n",(Int_t)Entry());
175   
176   fhNEvents->Fill(0.5);  
177   
178   AliVEvent * event = InputEvent();
179   if (!event) {
180     printf("AliAnalysisTaskCounter::UserExec() - ERROR: event not available \n");
181     return;
182   }
183   AliESDEvent * esdevent = dynamic_cast<AliESDEvent*> (event);
184
185   fhNEvents->Fill(1.5);  
186     
187   //Initialize bools
188   Bool_t bSelectVZ    = kFALSE;
189   Bool_t bV0AND       = kFALSE; 
190   Bool_t bPileup      = kFALSE;
191   Bool_t bGoodV       = kFALSE;
192   Bool_t bSelectTrack = kFALSE;   
193   Int_t  trackMult    = 0;
194   
195   //---------------------------------
196   //Get the primary vertex, cut on Z
197   //---------------------------------
198   Double_t v[3];
199   event->GetPrimaryVertex()->GetXYZ(v) ;
200   fhXVertex->Fill(v[0]);
201   fhYVertex->Fill(v[1]);
202   fhZVertex->Fill(v[2]);
203   
204   if(TMath::Abs(v[2]) < fZVertexCut) {
205     bSelectVZ=kTRUE;
206     fhNEvents->Fill(2.5);  
207   }
208   //else printf("Vertex out %f \n",v[2]);
209   
210
211   //--------------------------------------------------
212   //Tweak for calorimeter only productions
213   //--------------------------------------------------
214   if(fCaloFilterPatch && !esdevent){ 
215     if(event->GetNumberOfCaloClusters() > 0) {
216       AliVCluster * calo = event->GetCaloCluster(0);
217       if(calo->GetNLabels() == 4){
218         Int_t * selection = calo->GetLabels();
219         bPileup   = selection[0];
220         bGoodV    = selection[1]; 
221         bV0AND    = selection[2]; 
222         trackMult = selection[3];
223         //if(selection[0] || selection[1] || selection[2])
224         //printf(" pu %d, gv %d, v0 %d, track mult %d\n ", selection[0], selection[1], selection[2], selection[3]);
225         if(trackMult > 0 )  
226           bSelectTrack = kFALSE;
227       } else {
228         //First filtered AODs, track multiplicity stored there.  
229         trackMult = (Int_t) ((AliAODHeader*)fInputEvent->GetHeader())->GetCentrality();
230       }
231     }else{//at least one cluster
232         //printf("AliAnalysisTaskCounter::UserExec() - No clusters in event\n");
233         //Remove events with  vertex (0,0,0), bad vertex reconstruction
234         if(TMath::Abs(v[0]) < 1.e-6 && TMath::Abs(v[1]) < 1.e-6 && TMath::Abs(v[2]) < 1.e-6) bGoodV = kFALSE;
235       
236         //First filtered AODs, track multiplicity stored there.  
237         trackMult = (Int_t) ((AliAODHeader*)fInputEvent->GetHeader())->GetCentrality();
238     }
239   }
240   else {
241     //--------------------------------------------------
242     //Count tracks, cut on number of tracks in eta < 0.8
243     //--------------------------------------------------
244     Int_t nTracks   = event->GetNumberOfTracks() ;
245     for (Int_t itrack =  0; itrack <  nTracks; itrack++) {////////////// track loop
246       AliVTrack * track = (AliVTrack*)event->GetTrack(itrack) ; // retrieve track from esd
247       
248       //Only for ESDs
249       if(esdevent && !fESDtrackCuts->AcceptTrack((AliESDtrack*)track)) continue;
250       
251       //Do not count tracks out of acceptance cut
252       if(TMath::Abs(track->Eta())< fTrackMultEtaCut) trackMult++;
253     }
254   }
255   
256   //printf("AliAnalysisTaskCounter::UserExec() - Track Mult %d \n",trackMult);
257   
258   //--------------------------------------------------
259   // At least one track
260   //--------------------------------------------------
261   if (trackMult > 0) {
262     bSelectTrack = kTRUE; 
263                   fhNEvents->Fill(3.5);
264     if(bSelectVZ) fhNEvents->Fill(4.5);
265   }
266   
267   //---------------------------------
268   // V0AND
269   //---------------------------------
270   if(esdevent && !fCaloFilterPatch) bV0AND = fTriggerAnalysis->IsOfflineTriggerFired(esdevent, AliTriggerAnalysis::kV0AND);
271   //else if(aodevent  && !fCaloFilterPatch) bV0AND = //FIXME FOR AODs
272   
273   if(bV0AND)
274   {
275                                     fhNEvents->Fill(5.5);
276     if (bSelectVZ)                  fhNEvents->Fill(6.5);
277     if (bSelectTrack)               fhNEvents->Fill(7.5);
278     if (bSelectVZ &&  bSelectTrack) fhNEvents->Fill(8.5);
279   }
280   
281   //---------------------------------
282   // Pileup
283   //---------------------------------
284   if(!fCaloFilterPatch)
285     bPileup = event->IsPileupFromSPD(3, 0.8, 3., 2., 5.); //Default values, if not it does not compile
286   //bPileup = event->IsPileupFromSPD(); 
287   if (!bPileup){
288                 fhNEvents->Fill(9.5);
289     if(bV0AND)  fhNEvents->Fill(16.5);
290   }
291   
292   //---------------------------------
293   // Good vertex
294   //---------------------------------
295   if(esdevent && !fCaloFilterPatch) bGoodV = CheckForPrimaryVertex();
296   if(bGoodV) 
297   {
298     fhXGoodVertex->Fill(v[0]);
299     fhYGoodVertex->Fill(v[1]);
300     fhZGoodVertex->Fill(v[2]);
301     
302                      fhNEvents->Fill(10.5);
303     if(bSelectVZ)    fhNEvents->Fill(11.5);
304     if(bSelectTrack) fhNEvents->Fill(12.5);
305     if(bV0AND)       fhNEvents->Fill(13.5);
306     if(bSelectVZ && bSelectTrack && bV0AND)    
307                      fhNEvents->Fill(14.5); 
308     if(!bPileup)     fhNEvents->Fill(15.5); 
309   }
310
311   //printf("AliAnalysisTaskCounter::UserExec() : z vertex %d, good vertex %d, v0and %d, pile up %d, track mult %d\n ", bSelectVZ, bGoodV, bV0AND, bPileup, trackMult);
312   
313   // Events that could be rejected in EMCAL
314   for (Int_t i = 0; i < InputEvent()->GetNumberOfCaloClusters(); i++)
315   {
316     AliVCluster *clus = InputEvent()->GetCaloCluster(i);
317     if(clus->IsEMCAL()){    
318       
319       if ((clus->E() > 500 && clus->GetNCells() > 200 ) || clus->GetNCells() > 300)  {
320         //printf("Counter: Reject event with cluster: E %f, ncells %d\n",clus->E(),clus->GetNCells());
321                          fhNEvents->Fill(17.5); 
322         if(bSelectVZ)    fhNEvents->Fill(18.5);
323         if(TMath::Abs(v[2]) < 50.)  fhNEvents->Fill(19.5); 
324         break;
325       }
326         
327     }
328   }
329   
330   PostData(1,fOutputContainer);
331
332 }
333
334 //____________________________________________________________________________
335 Bool_t AliAnalysisTaskCounter::CheckForPrimaryVertex(){
336   //Check if the vertex was well reconstructed, copy from V0Reader of conversion group
337   //It only works for ESDs
338   
339   AliESDEvent * event = dynamic_cast<AliESDEvent*> (InputEvent());
340   if(!event) return 0;
341   
342   if(event->GetPrimaryVertexTracks()->GetNContributors() > 0) {
343     return 1;
344   }
345   
346   if(event->GetPrimaryVertexTracks()->GetNContributors() < 1) {
347     // SPD vertex
348     if(event->GetPrimaryVertexSPD()->GetNContributors() > 0) {
349       //cout<<"spd vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
350       return 1;
351       
352     }
353     if(event->GetPrimaryVertexSPD()->GetNContributors() < 1) {
354       //      cout<<"bad vertex type::"<< fESDEvent->GetPrimaryVertex()->GetName() << endl;
355       return 0;
356     }
357   }
358   return 0;
359   //return fInputEvent->GetPrimaryVertex()->GetNContributors()>0;
360 }
361
362
363
364 //_____________________________________________________
365 void AliAnalysisTaskCounter::FinishTaskOutput()
366 {
367   // Put in the output some event summary histograms
368   
369   AliAnalysisManager *am = AliAnalysisManager::GetAnalysisManager();
370   AliInputEventHandler *inputH = dynamic_cast<AliInputEventHandler*>(am->GetInputEventHandler());
371   if (!inputH) return; 
372   TH2F *histStat = dynamic_cast<TH2F*>(inputH->GetStatistics()); 
373   TH2F *histBin0 = dynamic_cast<TH2F*>(inputH->GetStatistics("BIN0"));
374   
375   if(histStat)
376     fOutputContainer->Add(histStat);
377   else
378     printf("AliAnalysisTaskCounter::FinishTaskOutput() - Stat histogram not available check, \n if ESDs, that AliPhysicsSelection was on, \n if AODs, if EventStat_temp.root exists \n");
379
380   if(histBin0)
381     fOutputContainer->Add(histBin0); 
382   
383 }