]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/JetTasks/AliAnalyseLeadingTrackUE.cxx
635c1d1b37fa9a03087217b1c67fd7f19c3d44aa
[u/mrichter/AliRoot.git] / PWG4 / JetTasks / AliAnalyseLeadingTrackUE.cxx
1 /*************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: A.Abrahantes, E.Lopez, S.Vallero                               *
5  * Version 1.0                                                            *
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 //#include <TBranch.h>
16 //#include <TCanvas.h>
17 //#include <TChain.h>
18 //#include <TFile.h>
19 //#include <TH1F.h>
20 //#include <TH1I.h>
21 //#include <TH2F.h>
22 #include <TList.h>
23 //#include <TLorentzVector.h>
24 #include <TMath.h>
25 #include <TObjArray.h>
26 #include <TObject.h>
27 //#include <TProfile.h>
28 //#include <TRandom.h>
29 //#include <TSystem.h>
30 //#include <TTree.h>
31 #include <TVector3.h>
32
33 #include "AliAnalyseLeadingTrackUE.h"
34 //#include "AliAnalysisTask.h"
35
36 //#include "AliAnalysisHelperJetTasks.h"
37 //#include "AliAnalysisManager.h"
38 #include "AliAODEvent.h"
39 //#include "AliAODHandler.h"
40 //#include "AliAODJet.h"
41 #include "AliAODMCParticle.h"
42 #include "AliAODTrack.h"
43 #include "AliESDEvent.h"
44 #include "AliESDtrack.h"
45 #include "AliESDtrackCuts.h"
46 //#include "AliGenPythiaEventHeader.h"
47 #include "AliInputEventHandler.h"
48 //#include "AliKFVertex.h"
49 //#include "AliLog.h"
50 #include "AliMCEvent.h"
51 #include "AliVParticle.h"
52
53 #include "AliAnalysisManager.h"
54 #include "AliMCEventHandler.h"
55 #include "AliStack.h"
56
57
58 ////////////////////////////////////////////////
59 //--------------------------------------------- 
60 // Class for transverse regions analysis
61 //---------------------------------------------
62 ////////////////////////////////////////////////
63
64
65 using namespace std;
66
67 ClassImp(AliAnalyseLeadingTrackUE)
68
69 //-------------------------------------------------------------------
70 AliAnalyseLeadingTrackUE::AliAnalyseLeadingTrackUE() :
71   TObject(),
72   fDebug(0),
73   fFilterBit(16),
74   fOnlyHadrons(kFALSE),
75   fTrackEtaCut(0.8),
76   fTrackPtMin(0),
77   fEsdTrackCuts(0x0), 
78   fEsdTrackCutsSPD(0x0), 
79   fEsdTrackCutsSDD(0x0) 
80 {
81   // constructor
82 }
83
84
85 //-------------------------------------------------------------------
86 AliAnalyseLeadingTrackUE & AliAnalyseLeadingTrackUE::operator = (const AliAnalyseLeadingTrackUE & /*source*/)
87 {
88   // assignment operator
89   return *this;
90 }
91
92
93 //-------------------------------------------------------------------
94 AliAnalyseLeadingTrackUE::~AliAnalyseLeadingTrackUE()
95 {
96
97   //clear memory
98   
99 }
100
101
102 //____________________________________________________________________
103 Bool_t AliAnalyseLeadingTrackUE::ApplyCuts(TObject* track)
104 {
105   
106   // select track according to set of cuts
107   if (!fEsdTrackCuts->IsSelected(track) )return kFALSE;
108   if (fEsdTrackCutsSPD && fEsdTrackCutsSDD && !fEsdTrackCutsSPD->IsSelected(track) && fEsdTrackCutsSDD->IsSelected(track)) return kFALSE;
109
110   return kTRUE;
111 }
112
113
114 //____________________________________________________________________
115 void AliAnalyseLeadingTrackUE::DefineESDCuts(Int_t /*filterbit*/){
116   
117   // Reproduces the cuts of the corresponding bit in the ESD->AOD filtering
118   // (see $ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C)
119
120   if (fFilterBit == 128)
121   {
122     fEsdTrackCuts = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts();
123     fEsdTrackCuts->SetMinNClustersTPC(70);
124   }
125   else
126   {
127     fEsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010();
128     fEsdTrackCuts->SetClusterRequirementITS(AliESDtrackCuts::kSPD, AliESDtrackCuts::kNone);
129
130     // Add SPD requirement 
131     fEsdTrackCutsSPD = new AliESDtrackCuts("SPD", "Require 1 cluster in SPD");
132     fEsdTrackCutsSPD->SetClusterRequirementITS(AliESDtrackCuts::kSPD,AliESDtrackCuts::kAny);
133
134     // Add SDD requirement 
135     fEsdTrackCutsSDD = new AliESDtrackCuts("SDD", "Require 1 cluster in first layer SDD");
136     fEsdTrackCutsSDD->SetClusterRequirementITS(AliESDtrackCuts::kSDD,AliESDtrackCuts::kFirst);
137   }
138 }
139
140 //____________________________________________________________________
141 TObjArray*  AliAnalyseLeadingTrackUE::FindLeadingObjects(TObject *obj)
142 {
143
144   // Returns an array of charged particles (or jets) ordered according to their pT.
145
146   Int_t nTracks = NParticles(obj);
147
148
149   if( !nTracks ) return 0;
150  
151   // Define array of AliVParticle objects
152   TObjArray* tracks = new TObjArray(nTracks);
153
154   // Loop over tracks or jets
155   for (Int_t ipart=0; ipart<nTracks; ++ipart) {
156         AliVParticle* part = ParticleWithCuts( obj, ipart );
157         if (!part) continue;
158         // Accept leading-tracks in a limited pseudo-rapidity range     
159         if( TMath::Abs(part->Eta()) > fTrackEtaCut ) continue;
160         tracks->AddLast( part );
161         }
162   // Order tracks by pT 
163   QSortTracks( *tracks, 0, tracks->GetEntriesFast() );
164
165   nTracks = tracks->GetEntriesFast();
166   if( !nTracks ) return 0;
167
168   return tracks;
169   }
170
171
172 //-------------------------------------------------------------------
173 TObjArray* AliAnalyseLeadingTrackUE::GetAcceptedParticles(TObject* obj, TObject* arrayMC, Bool_t onlyprimaries, Int_t particleSpecies, Bool_t useEtaPtCuts)
174 {
175   // Returns an array of particles that pass the cuts, if arrayMC is given each reconstructed particle is replaced by its corresponding MC particles, depending on the parameter onlyprimaries only for primaries 
176   // particleSpecies: -1 all particles are returned
177   //                  0 (pions) 1 (kaons) 2 (protons) 3 (others) particles
178
179   Int_t nTracks = NParticles(obj);
180   TObjArray* tracks = new TObjArray;
181   
182   // for TPC only tracks
183   if (fFilterBit == 128 && obj->InheritsFrom("AliESDEvent"))
184     tracks->SetOwner(kTRUE);
185  
186   // Loop over tracks or jets
187   for (Int_t ipart=0; ipart<nTracks; ++ipart) {
188     AliVParticle* part = ParticleWithCuts( obj, ipart, onlyprimaries, particleSpecies );
189     if (!part) continue;
190     
191     if (useEtaPtCuts)
192       if (TMath::Abs(part->Eta()) > fTrackEtaCut || part->Pt() < fTrackPtMin)
193         continue;
194     
195     if (arrayMC && arrayMC->InheritsFrom("TClonesArray") && obj->InheritsFrom("AliAODEvent")) {
196       Int_t label = ((AliAODTrack*)part)->GetLabel();
197       // re-define part as the matched MC particle
198       part = (AliAODMCParticle*)ParticleWithCuts(arrayMC, TMath::Abs(label),onlyprimaries, particleSpecies);
199       if (!part)continue;
200     }
201     
202     tracks->Add(part);
203   }
204
205   return tracks;
206 }
207
208 //-------------------------------------------------------------------
209 TObjArray* AliAnalyseLeadingTrackUE::GetMinMaxRegion(TList *transv1, TList *transv2)
210 {
211   
212  // Returns two lists of particles, one for MIN and one for MAX region
213   Double_t sumpT1 = 0.;
214   Double_t sumpT2 = 0.;
215
216   Int_t particles1 = transv1->GetEntries();
217   Int_t particles2 = transv2->GetEntries();
218   
219   // Loop on transverse region 1
220   for (Int_t i=0; i<particles1; i++){
221         AliVParticle *part = (AliVParticle*)transv1->At(i);
222         sumpT1 +=  part->Pt();
223         }
224
225   // Loop on transverse region 2
226   for (Int_t i=0; i<particles2; i++){
227         AliVParticle *part = (AliVParticle*)transv2->At(i);
228         sumpT2 +=  part->Pt();
229         }
230
231   TObjArray *regionParticles = new TObjArray;
232   if ( sumpT2 >= sumpT1 ){
233         regionParticles->AddLast(transv1); // MIN
234         regionParticles->AddLast(transv2); // MAX 
235   }else {
236         regionParticles->AddLast(transv2); // MIN
237         regionParticles->AddLast(transv1); // MAX
238         }
239
240  return regionParticles;
241 }
242
243 //-------------------------------------------------------------------
244 Int_t  AliAnalyseLeadingTrackUE::NParticles(TObject* obj)
245 {
246  
247   //Returns the number of particles in AliAODMCParticle array  or AliAODTracks or AliESDTracks 
248
249   Int_t nTracks;
250   
251   if (obj->InheritsFrom("TClonesArray")){ // MC particles
252         TClonesArray *arrayMC = static_cast<TClonesArray*>(obj);
253         nTracks = arrayMC->GetEntriesFast();
254   }else if (obj->InheritsFrom("TObjArray")){ // list of AliVParticle
255         TObjArray *array = static_cast<TObjArray*>(obj);
256         nTracks = array->GetEntriesFast();
257   }else if (obj->InheritsFrom("AliAODEvent")){  // RECO AOD tracks
258         AliAODEvent *aodEvent = static_cast<AliAODEvent*>(obj);
259         nTracks = aodEvent->GetNTracks();
260   }else if (obj->InheritsFrom("AliESDEvent")){  // RECO ESD tracks
261         AliESDEvent *esdEvent = static_cast<AliESDEvent*>(obj);
262         nTracks = esdEvent->GetNumberOfTracks();
263   }else if (obj->InheritsFrom("AliMCEvent")){  // RECO ESD tracks
264         AliMCEvent *mcEvent = static_cast<AliMCEvent*>(obj);
265         nTracks = mcEvent->GetNumberOfTracks();
266   }else {
267         if (fDebug > 1) AliFatal(" Analysis type not defined !!! ");
268         return 0;
269         }
270   
271   return nTracks;
272 }
273
274
275 //-------------------------------------------------------------------
276 AliVParticle*  AliAnalyseLeadingTrackUE::ParticleWithCuts(TObject* obj, Int_t ipart, Bool_t onlyprimaries, Int_t particleSpecies)
277 {
278   // Returns track or MC particle at position "ipart" if passes selection criteria
279   // particleSpecies: -1 all particles are returned
280   //                  0 (pions) 1 (kaons) 2 (protons) 3 (others) particles
281   AliVParticle *part=0;
282   
283   if (obj->InheritsFrom("TClonesArray")){ // AOD-MC PARTICLE
284         TClonesArray *arrayMC = static_cast<TClonesArray*>(obj);
285         part = (AliVParticle*)arrayMC->At( ipart );
286         if (!part)return 0;
287         // eventually only primaries
288         if (onlyprimaries && !( ((AliAODMCParticle*)part)->IsPhysicalPrimary()) )return 0;
289         // eventually only hadrons
290         if (fOnlyHadrons){
291                 Int_t pdgCode = ((AliAODMCParticle*)part)->GetPdgCode();
292                 Bool_t isHadron = TMath::Abs(pdgCode)==211 ||  // Pion
293                                   TMath::Abs(pdgCode)==2212 || // Proton
294                                   TMath::Abs(pdgCode)==321;    // Kaon
295                 if (!isHadron) return 0;                                  
296                 }
297         if (particleSpecies != -1) {
298                 // find the primary mother
299                 AliVParticle* mother = part;
300                 while (!((AliAODMCParticle*)mother)->IsPhysicalPrimary())
301                 {
302                   if (((AliAODMCParticle*)mother)->GetMother() < 0)
303                   {
304                     mother = 0;
305                     break;
306                   }
307                     
308                   mother = (AliVParticle*) arrayMC->At(((AliAODMCParticle*)mother)->GetMother());
309                   if (!mother)
310                     break;
311                 }
312                 
313                 if (mother)
314                 {
315                   Int_t pdgCode = ((AliAODMCParticle*)mother)->GetPdgCode();
316                   if (particleSpecies == 0 && TMath::Abs(pdgCode)!=211)
317                           return 0;
318                   if (particleSpecies == 1 && TMath::Abs(pdgCode)!=321)
319                           return 0;
320                   if (particleSpecies == 2 && TMath::Abs(pdgCode)!=2212)
321                           return 0;
322                   if (particleSpecies == 3 && (TMath::Abs(pdgCode)==211 || TMath::Abs(pdgCode)==321 || TMath::Abs(pdgCode)==2212))
323                           return 0;
324                 }
325                 else
326                 {
327                   // if mother not found, accept particle only in case of particleSpecies == 3. To include it in all or no sample is no solution
328                   Printf("WARNING: No mother found for particle %d:", part->GetLabel());
329                   part->Print();
330   
331                   /*
332                   // this code prints the details of the mother that is missing in the AOD
333                   AliMCEventHandler* fMcHandler = dynamic_cast<AliMCEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
334   
335                   AliMCEvent* fMcEvent = fMcHandler->MCEvent();
336                   
337                   fMcEvent->Stack()->Particle(fMcEvent->Stack()->Particle(part->GetLabel())->GetMother(0))->Print();
338                   fMcEvent->Stack()->Particle(fMcEvent->Stack()->Particle(fMcEvent->Stack()->Particle(part->GetLabel())->GetMother(0))->GetMother(0))->Print();
339                   Printf("eta = %f", fMcEvent->Stack()->Particle(fMcEvent->Stack()->Particle(fMcEvent->Stack()->Particle(part->GetLabel())->GetMother(0))->GetMother(0))->Eta());
340                   */
341                   
342                   if (particleSpecies != 3)
343                     return 0;
344                 }
345         }
346   
347   }else if (obj->InheritsFrom("TObjArray")){ // list of AliVParticle
348         TObjArray *array = static_cast<TObjArray*>(obj);
349         part = (AliVParticle*)array->At( ipart );
350         if (!part)return 0;
351   }else if (obj->InheritsFrom("AliMCEvent")){ // MC PARTICLE
352         AliMCEvent* mcEvent =  static_cast<AliMCEvent*>(obj);
353         part = mcEvent->GetTrack( ipart );
354         if (!part) return 0;
355         // eventually only primaries
356         if (onlyprimaries && !( mcEvent->IsPhysicalPrimary(ipart)) )return 0;
357         // eventually only hadrons
358         //TO-DO
359         /*if (fOnlyHadrons){
360                 Int_t pdgCode =  part->GetPdgCode();
361                 Bool_t isHadron = TMath::Abs(pdgCode)==211 ||  // Pion
362                                   TMath::Abs(pdgCode)==2212 || // Proton
363                                   TMath::Abs(pdgCode)==321;    // Kaon
364                 if (!isHadron) return 0;                                  
365                 }
366         */
367
368   }else if (obj->InheritsFrom("AliAODEvent")){ // RECO AOD TRACKS
369         AliAODEvent *aodEvent = static_cast<AliAODEvent*>(obj);
370         part = aodEvent->GetTrack(ipart);
371         // track selection cuts
372         if ( !(((AliAODTrack*)part)->TestFilterBit(fFilterBit)) ) return 0; 
373         //if ( !(((AliAODTrack*)part)->TestFilterBit(fFilterBit)) && !(((AliAODTrack*)part)->TestFilterBit(32)) ) return 0; 
374         // only primary candidates
375         //if ( ((AliAODTrack*)part)->IsPrimaryCandidate() )return 0;
376         // eventually only hadrons
377         if (fOnlyHadrons){
378                 Bool_t isHadron = ((AliAODTrack*)part)->GetMostProbablePID()==AliAODTrack::kPion ||
379                                   ((AliAODTrack*)part)->GetMostProbablePID()==AliAODTrack::kKaon ||
380                                   ((AliAODTrack*)part)->GetMostProbablePID()==AliAODTrack::kProton;
381                 if (!isHadron) return 0;                                  
382                 }
383   
384   }else if (obj->InheritsFrom("AliESDEvent")){ // RECO ESD TRACKS
385         AliESDEvent *esdEvent = static_cast<AliESDEvent*>(obj);
386         part = esdEvent->GetTrack(ipart);
387         if (!part)return 0;
388         // track selection cuts
389         
390         if (!( ApplyCuts(part)) )
391          return 0; 
392         
393         if (fFilterBit == 128)
394         {
395           // create TPC only tracks constrained to the SPD vertex
396
397           const AliESDVertex *vtxSPD = esdEvent->GetPrimaryVertexSPD();
398
399           AliESDtrack* track = AliESDtrackCuts::GetTPCOnlyTrack(esdEvent, ipart);
400           if(!track) return 0;
401     
402           // laser warm up tracks
403           if (track->GetTPCsignal() < 10.)
404             return 0;
405     
406           if(track->Pt()>0.){
407             // only constrain tracks above threshold
408             AliExternalTrackParam exParam;
409             // take the B-feild from the ESD, no 3D fieldMap available at this point
410             Bool_t relate = kFALSE;
411             relate = track->RelateToVertex(vtxSPD,esdEvent->GetMagneticField(),kVeryBig,&exParam);
412             if(!relate)
413             {
414 //                 Printf("relating failed");
415               delete track;
416               return 0;
417             }
418             track->Set(exParam.GetX(),exParam.GetAlpha(),exParam.GetParameter(),exParam.GetCovariance());
419           }
420           
421           part = track;
422         }
423         
424         // eventually only hadrons
425         //TO-DO
426         /*if (fOnlyHadrons){
427                 Bool_t isHadron = ((AliAODTrack*)part)->GetMostProbablePID()==AliAODTrack::kPion ||
428                                   ((AliAODTrack*)part)->GetMostProbablePID()==AliAODTrack::kKaon ||
429                                   ((AliAODTrack*)part)->GetMostProbablePID()==AliAODTrack::kProton;
430                 if (!isHadron) return 0;                                  
431                 }
432         */      
433   }else {
434         if (fDebug > 1) AliFatal(" Analysis type not defined !!! ");
435         return 0;
436         }
437   
438   // only charged
439   if (!part->Charge())return 0;
440   
441   return part;
442 }
443
444
445 //-------------------------------------------------------------------
446 void  AliAnalyseLeadingTrackUE::QSortTracks(TObjArray &a, Int_t first, Int_t last)
447 {
448   // Sort array of TObjArray of tracks by Pt using a quicksort algorithm.
449   
450   static TObject *tmp;
451   static int i;           // "static" to save stack space
452   int j;
453   
454   while (last - first > 1) {
455     i = first;
456     j = last;
457     for (;;) {
458       while (++i < last && ((AliVParticle*)a[i])->Pt() > ((AliVParticle*)a[first])->Pt() )
459         ;
460       while (--j > first && ((AliVParticle*)a[j])->Pt() < ((AliVParticle*)a[first])->Pt() )
461         ;
462       if (i >= j)
463         break;
464       
465       tmp  = a[i];
466       a[i] = a[j];
467       a[j] = tmp;
468     }
469     if (j == first) {
470       ++first;
471       continue;
472     }
473     tmp = a[first];
474     a[first] = a[j];
475     a[j] = tmp;
476     if (j - first < last - (j + 1)) {
477       QSortTracks(a, first, j);
478       first = j + 1;   // QSortTracks(j + 1, last);
479     } else {
480       QSortTracks(a, j + 1, last);
481       last = j;        // QSortTracks(first, j);
482     }
483   }
484 }
485
486 //____________________________________________________________________
487 TObjArray*  AliAnalyseLeadingTrackUE::SortRegions(const AliVParticle* leading, TObject* obj, TObject* arrayMC, Bool_t onlyprimaries)
488 {
489
490   // Assign particles to towards, away or transverse regions.
491   // Returns a lists of particles for each region.
492
493   static const Double_t k60rad  = 60.*TMath::Pi()/180.;
494   static const Double_t k120rad = 120.*TMath::Pi()/180.;
495
496   // Define output lists of particles
497   TList *toward = new TList();
498   TList *away = new TList();
499   // Two transverse regions, for the moment those are not yet MIN and MAX!!! 
500   // MIN and MAX can be sorted in GetMinMaxRegion function
501   TList *transverse1 = new TList();
502   TList *transverse2 = new TList();
503   
504   TObjArray *regionParticles = new TObjArray;
505   regionParticles->SetOwner(kTRUE);
506   
507   regionParticles->AddLast(toward);
508   regionParticles->AddLast(away);
509   regionParticles->AddLast(transverse1);
510   regionParticles->AddLast(transverse2);
511   
512   if (!leading)
513     return regionParticles;
514  
515   // Switch to vector for leading particle
516   TVector3 leadVect(leading->Px(),leading->Py(),leading->Pz());
517   
518   Int_t nTracks = NParticles(obj);
519   if( !nTracks ) return 0;
520   // Loop over tracks 
521   for (Int_t ipart=0; ipart<nTracks; ++ipart) {
522         AliVParticle* part = ParticleWithCuts(obj, ipart);
523         if (!part)continue;
524         //Switch to vectors for particles 
525         TVector3 partVect(part->Px(), part->Py(), part->Pz());
526  
527         Int_t region = 0;
528         if( TMath::Abs(partVect.Eta()) > fTrackEtaCut ) continue;
529         // transverse regions
530         if (leadVect.DeltaPhi(partVect) < -k60rad && leadVect.DeltaPhi(partVect) > -k120rad )region = -1; //left
531         if (leadVect.DeltaPhi(partVect) > k60rad && leadVect.DeltaPhi(partVect) < k120rad ) region = 1;   //right
532
533         if (TMath::Abs(leadVect.DeltaPhi(partVect)) < k60rad ) region = 2;    //forward
534         if (TMath::Abs(leadVect.DeltaPhi(partVect)) > k120rad ) region = -2;  //backward
535         
536         // skip leading particle 
537         if (leading == part)
538           continue;
539         
540         if (!region)continue;
541         if (arrayMC && arrayMC->InheritsFrom("TClonesArray") && obj->InheritsFrom("AliAODEvent")){
542                 Int_t label = ((AliAODTrack*)part)->GetLabel();
543                 // re-define part as the matched MC particle
544                 part = (AliAODMCParticle*)ParticleWithCuts(arrayMC, TMath::Abs(label),onlyprimaries);
545                 if (!part)continue;
546                 // skip leading particle 
547                 if (leading == part)
548                   continue;
549                 }
550         if (arrayMC && arrayMC->InheritsFrom("AliMCEvent") && obj->InheritsFrom("AliESDEvent")){
551                 Int_t label = ((AliESDtrack*)part)->GetLabel();
552                 // look for the matched MC particle (but do not re-define part)
553                 if (!ParticleWithCuts(arrayMC, TMath::Abs(label),onlyprimaries)) continue;
554                 }
555
556         if ( region == 1 ) transverse1->Add(part);
557         if ( region == -1 ) transverse2->Add(part);
558         if ( region == 2 ) toward->Add(part);
559         if ( region == -2 ) away->Add(part);
560
561         }//end loop on tracks
562   
563   return regionParticles;
564   
565 }
566
567
568 //____________________________________________________________________
569 Bool_t  AliAnalyseLeadingTrackUE::TriggerSelection(const TObject* obj)
570 {
571   if (!obj) // MC
572     return kFALSE;
573
574   // Use AliPhysicsSelection to select good events, works for ESD and AOD
575   if (!(((AliInputEventHandler*)obj)->IsEventSelected()&(AliVEvent::kMB|AliVEvent::kUserDefined)))
576     return kFALSE;
577
578   return kTRUE;
579 }
580
581 //____________________________________________________________________
582 Bool_t  AliAnalyseLeadingTrackUE::VertexSelection(const TObject* obj, Int_t ntracks, Double_t zed)
583 {
584
585   //Require 1 vertex (no TPC stand-alone) with a minimum number of tracks and z-coordinate in a limited range
586   
587   if (obj->InheritsFrom("AliAODEvent")){ 
588         Int_t nVertex = ((AliAODEvent*)obj)->GetNumberOfVertices();
589         if( nVertex > 0 ) { 
590                 AliAODVertex* vertex = (AliAODVertex*)((AliAODEvent*)obj)->GetPrimaryVertex();
591                 Int_t nTracksPrim = vertex->GetNContributors();
592                 Double_t zVertex = vertex->GetZ();
593                 if (fDebug > 1)AliInfo(Form(" Vertex in = %f with %d particles by  %s data ...",zVertex,nTracksPrim,vertex->GetName()));
594                 // Reject TPC only vertex
595                 TString name(vertex->GetName());
596                 if (name.CompareTo("PrimaryVertex") && name.CompareTo("SPDVertex"))return kFALSE;
597
598                 // Select a quality vertex by number of tracks?
599                 if( nTracksPrim < ntracks || TMath::Abs(zVertex) > zed ) {
600                         if (fDebug > 1) AliInfo(" Primary-vertex Selection: event REJECTED ...");
601                         return kFALSE;
602                         }
603                 // TODO remove vertexer Z events with dispersion > 0.02: Doesn't work for AOD at present
604                 //if (strcmp(vertex->GetTitle(), "AliVertexerZ") == 0 && vertex->GetDispersion() > 0.02)
605                 //  return kFALSE;
606                 if (fDebug > 1) AliInfo(" Primary-vertex Selection: event ACCEPTED...");
607                 } else {
608                         if (fDebug > 1) AliInfo(" Primary-vertex Selection: event REJECTED ...");
609                         return kFALSE;
610                         }
611         }
612
613   if (obj->InheritsFrom("AliMCEvent"))
614   { 
615     if (TMath::Abs(((AliMCEvent*) obj)->GetPrimaryVertex()->GetZ()) > zed)
616     {
617       if (fDebug > 1) AliInfo(" Primary-vertex Selection: event (based on MC) REJECTED ...");
618       return kFALSE;
619     }
620   }
621
622   // ESD case for DCA studies
623   if (obj->InheritsFrom("AliESDEvent")){
624        AliESDVertex* vertex = (AliESDVertex*)((AliESDEvent*)obj)->GetPrimaryVertex();
625        if ( vertex){
626                Int_t nTracksPrim = vertex->GetNContributors();
627                Double_t zVertex = vertex->GetZ();
628                if (fDebug > 1)AliInfo(Form(" Vertex in = %f with %d particles by  %s data ...",zVertex,nTracksPrim,vertex->GetName()));
629                // Reject SPD or TPC only vertex
630                TString name(vertex->GetName());
631                if (name.CompareTo("PrimaryVertex") && name.CompareTo("SPDVertex"))return kFALSE;
632
633                // Select a quality vertex by number of tracks?
634                if( nTracksPrim < ntracks || TMath::Abs(zVertex) > zed ) {
635                        if (fDebug > 1) AliInfo(" Primary-vertex Selection: event REJECTED ...");
636                        return kFALSE;
637                        }
638                // TODO remove vertexer Z events with dispersion > 0.02: Doesn't work for AOD at present
639                 //if (strcmp(vertex->GetTitle(), "AliVertexerZ") == 0 && vertex->GetDispersion() > 0.02)
640                 //  return kFALSE;
641                if (fDebug > 1) AliInfo(" Primary-vertex Selection: event ACCEPTED...");
642                } else {
643                        if (fDebug > 1) AliInfo(" Primary-vertex Selection: event REJECTED ...");
644                        return kFALSE;
645                        }
646        }
647         
648   return kTRUE;
649 }