1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 // Analysis task to produce trees of lightweight events
17 // evgeny.kryshen@cern.ch
20 #include "AliAnalysisTaskCFTree.h"
21 #include "AliCFParticle.h"
22 #include "AliAnalysisManager.h"
23 #include "AliInputEventHandler.h"
24 #include "AliESDEvent.h"
25 #include "AliAODEvent.h"
26 #include "AliMCEvent.h"
27 #include "AliHeader.h"
28 #include "AliESDHeader.h"
29 #include "AliAODHeader.h"
30 #include "AliAODMCHeader.h"
31 #include "AliGenEventHeader.h"
32 #include "AliGenCocktailEventHeader.h"
33 #include "AliAODTrack.h"
34 #include "AliESDtrack.h"
35 #include "AliMCParticle.h"
36 #include "AliAODMCParticle.h"
37 #include "AliExternalTrackParam.h"
38 #include "AliCentrality.h"
39 #include "AliAnalysisFilter.h"
40 #include "AliPIDResponse.h"
41 #include "AliTPCPIDResponse.h"
49 #include "TClonesArray.h"
50 ClassImp(AliAnalysisTaskCFTree)
52 //-----------------------------------------------------------------------------
53 AliAnalysisTaskCFTree::AliAnalysisTaskCFTree(const char* name) :
54 AliAnalysisTask(name,""),
60 fHybridConstrainedMask(0),
61 fTPConlyConstrainedMask(0),
64 fEventStatistics(0x0),
75 fSelectBit(AliVEvent::kMB),
78 fCentralityMethod("V0M"),
79 fTrackFilterBit(0xffffffff),
82 fSharedClusterCut(0.4),
84 fFoundFractionCut(0.8)
86 Info("AliAnalysisTaskCFTree","Calling Constructor");
87 DefineInput(0,TChain::Class());
88 DefineOutput(0,TList::Class());
89 DefineOutput(1,TTree::Class());
91 //-----------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
95 void AliAnalysisTaskCFTree::ConnectInputData(Option_t* /*option*/){
96 fInputHandler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
97 fMcHandler = dynamic_cast<AliInputEventHandler*> (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
99 //-----------------------------------------------------------------------------
102 //-----------------------------------------------------------------------------
103 void AliAnalysisTaskCFTree::CreateOutputObjects(){
104 fListOfHistos = new TList();
105 fListOfHistos->SetOwner();
106 fEventStatistics = new TH1I("fEventStatistics","",10,0,10);
107 fEventStatistics->SetBit(TH1::kCanRebin);
109 fListOfHistos->Add(fEventStatistics);
111 fParticles = new TClonesArray("AliCFParticle",2000);
112 // create file-resident tree
113 TDirectory *owd = gDirectory;
115 fTree = new TTree("events","events");
117 fTree->Branch("cent",&fCentrality);
118 fTree->Branch("zvtx",&fZvtx);
119 fTree->Branch("field",&fField);
120 fTree->Branch("run",&fRunNumber);
121 fTree->Branch("period",&fPeriod);
122 fTree->Branch("orbit",&fOrbit);
123 fTree->Branch("bc",&fBc);
124 fTree->Branch("mask",&fSelectMask);
125 fTree->Branch("particles",&fParticles);
126 PostData(0,fListOfHistos);
129 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
133 void AliAnalysisTaskCFTree::Exec(Option_t *){
136 fEventStatistics->Fill("before cuts",1);
138 AliVEvent* event = fInputHandler->GetEvent();
140 fEventStatistics->Fill("after event check",1);
142 fPIDResponse = fInputHandler->GetPIDResponse();
144 fSelectMask = fInputHandler->IsEventSelected();
145 if (!(fSelectMask & fSelectBit)) return;
146 fEventStatistics->Fill("after trigger selection",1);
147 fRunNumber = event->GetRunNumber();
148 fPeriod = event->GetPeriodNumber();
149 fOrbit = event->GetOrbitNumber();
150 fBc = event->GetBunchCrossNumber();
151 fField = event->GetMagneticField();
152 fCentrality = event->GetCentrality()->GetCentralityPercentile(fCentralityMethod);
154 if (fMode==0){ // Data analysis
155 const AliVVertex* vertex = event->GetPrimaryVertex();
157 fZvtx = vertex->GetZ();
158 TString name(vertex->GetName());
159 if (name.CompareTo("PrimaryVertex") && name.CompareTo("SPDVertex")) return; // Reject TPC only vertex
160 fEventStatistics->Fill("after rejection of TPC only vertex",1);
161 if (TMath::Abs(fZvtx) >= fZVertexCut || vertex->GetNContributors()<fnTracksVertex) return;
162 fEventStatistics->Fill("after vertex selection",1);
164 for (Int_t ipart=0;ipart<event->GetNumberOfTracks();ipart++){
165 AliVTrack* track = (AliVTrack*) event->GetTrack(ipart);
166 if (!track) continue;
167 UInt_t mask = GetFilterMap(track);
168 if (!(mask & fTrackFilterBit)) continue;
170 if (track->InheritsFrom("AliAODTrack")) AddTrack(track,mask,0);
171 else if (track->InheritsFrom("AliESDtrack")) {
172 if (mask) AddTrack(track,mask,1);
173 if (mask & fHybridConstrainedMask) AddTrack(track,mask,2);
174 if (mask & fTPConlyConstrainedMask) AddTrack(track,mask,3);
178 else { // MC analysis
179 AliMCEvent* mcEvent = 0;
180 TClonesArray* mcTracks = 0;
184 mcEvent = fMcHandler ? fMcHandler->MCEvent() : 0;
185 mcTracks = (TClonesArray*) event->FindListObject(AliAODMCParticle::StdBranchName());
187 if (!mcEvent && !mcTracks) { printf("No mc object found\n"); return; }
188 fEventStatistics->Fill("after mc objects check",1);
191 AliHeader* header = (AliHeader*) mcEvent->Header();
192 AliGenCocktailEventHeader* cocktailHeader = dynamic_cast<AliGenCocktailEventHeader*> (header->GenEventHeader());
193 AliGenEventHeader* mcHeader = dynamic_cast<AliGenEventHeader*> (cocktailHeader ? cocktailHeader->GetHeaders()->First() : header->GenEventHeader());
194 nProduced = mcEvent->GetNumberOfTracks();
195 nPrimGen = mcHeader->NProduced();
196 fZvtx = mcEvent->GetPrimaryVertex()->GetZ();
197 } else if (mcTracks) {
198 AliAODMCHeader* mcHeader = (AliAODMCHeader*) event->FindListObject(AliAODMCHeader::StdBranchName());
199 nProduced = mcTracks->GetEntriesFast();
200 nPrimGen = mcHeader->GetCocktailHeaders() ? mcHeader->GetCocktailHeader(0)->NProduced() : nProduced;
201 fZvtx = mcHeader->GetVtxZ();
203 fEventStatistics->Fill("after mc header check",1);
205 if (TMath::Abs(fZvtx)>fZVertexCut) return;
206 fEventStatistics->Fill("after MC vertex cut",1);
208 const AliVVertex* vertex = event->GetPrimaryVertex();
210 fEventStatistics->Fill("after check for vertex object",1);
211 TString name(vertex->GetName());
212 if (name.CompareTo("PrimaryVertex") && name.CompareTo("SPDVertex")) fZvtx=1000; // Reject TPC only vertex
213 fEventStatistics->Fill("after rejection of TPC only vertex",1);
214 if (vertex->GetNContributors()<fnTracksVertex) fZvtx=-1000;
215 fEventStatistics->Fill("after check for vertex contributors",1);
217 UInt_t* masks = new UInt_t[nProduced];
218 for (Int_t i=0;i<nProduced;i++) masks[i]=0;
220 // Loop over reconstructed tracks to set masks
221 for (Int_t ipart=0;ipart<event->GetNumberOfTracks();ipart++){
222 AliVTrack* part = (AliVTrack*) event->GetTrack(ipart);
224 Int_t label = TMath::Abs(part->GetLabel());
225 if (label>=nProduced) continue;
226 masks[label] |= GetFilterMap(part);
229 // Loop over mc tracks to be stored
230 for (Int_t ipart=0;ipart<nProduced;ipart++){
231 AliVParticle* part = 0;
232 Bool_t isPrimary = 0;
233 if (mcTracks) { // AOD analysis
234 AliAODMCParticle* particle = (AliAODMCParticle*) mcTracks->At(ipart);
235 if (!particle) continue;
236 // skip injected signals
237 AliAODMCParticle* mother = particle;
238 while (!mother->IsPrimary()) mother = (AliAODMCParticle*) mcTracks->At(mother->GetMother());
239 if (mother->GetLabel()>=nPrimGen) continue;
242 isPrimary = particle->IsPhysicalPrimary();
243 } else { // ESD analysis
244 AliMCParticle* particle = (AliMCParticle*) mcEvent->GetTrack(ipart);
245 if (!particle) continue;
246 // skip injected signals
247 AliMCParticle* mother = particle;
248 while (mother->GetMother()>=0) mother = (AliMCParticle*) mcEvent->GetTrack(mother->GetMother());
249 if (mother->GetLabel()>=nPrimGen) continue;
252 isPrimary = mcEvent->IsPhysicalPrimary(ipart);
255 // store only primaries and all reconstructed (non-zero mask)
256 Int_t mask = masks[ipart];
257 if (isPrimary) mask |= (1 << 30);
264 PostData(0,fListOfHistos);
267 //-----------------------------------------------------------------------------
270 //-----------------------------------------------------------------------------
271 UInt_t AliAnalysisTaskCFTree::GetFilterMap(AliVParticle* particle){
273 if (particle->InheritsFrom("AliAODTrack")) {
274 AliAODTrack* part = (AliAODTrack*) particle;
275 mask = part->GetFilterMap();
276 Double_t nCrossedRaws = part->GetTPCNCrossedRows();
277 Double_t nFindableClusters = part->GetTPCNclsF();
278 Double_t nSharedClusters = part->GetTPCnclsS();
279 Double_t nClusters = part->GetTPCncls();
280 Bool_t itsRefit = part->GetStatus() & AliVTrack::kITSrefit;
281 if (nCrossedRaws/nFindableClusters > fFoundFractionCut) mask |= (1 << 26);
282 if (nCrossedRaws>fCrossedRowsCut) mask |= (1 << 27);
283 if (itsRefit) mask |= (1 << 28);
284 if (nSharedClusters/nClusters<=fSharedClusterCut) mask |= (1 << 29);
285 if (part->GetLabel()<0) mask |= (1 << 31);
286 } else if (particle->InheritsFrom("AliESDtrack")){
287 AliESDtrack* part = (AliESDtrack*) particle;
288 if (!fTrackFilter) AliFatal("Track filter undefined");
289 mask |= fTrackFilter->IsSelected(part);
294 //-----------------------------------------------------------------------------
297 //-----------------------------------------------------------------------------
298 AliCFParticle* AliAnalysisTaskCFTree::AddTrack(AliVParticle* part, UInt_t mask, UInt_t flag){
300 // skip neutral mc particles
301 Char_t charge = part->Charge();
302 if (charge==0) return NULL;
305 Float_t pt=0,eta=0,phi=0;
306 if (flag==0 || flag==1){ // AOD, MC or Global ESD tracks
310 if (flag==1) mask &= (~fHybridConstrainedMask) & (~fTPConlyConstrainedMask);
312 else if (flag==2) { // Hybrid constrained tracks (ESD)
313 AliESDtrack* track = (AliESDtrack*) part;
314 const AliExternalTrackParam* param = track->GetConstrainedParam();
318 mask &= fHybridConstrainedMask;
320 else if (flag==3) { // TPC only constrained tracks (ESD)
321 AliESDtrack* track = (AliESDtrack*) part;
322 AliESDtrack tpcTrack;
323 if (!track->FillTPCOnlyTrack(tpcTrack)) return NULL;
324 AliExternalTrackParam param;
325 const AliESDVertex* vtxSPD = ((AliESDEvent*) fInputHandler->GetEvent())->GetPrimaryVertexSPD();
326 if (!tpcTrack.RelateToVertexTPC(vtxSPD,fField,1.e30,¶m)) return NULL;
330 mask &= fTPConlyConstrainedMask;
334 if (pt < fPtMin || TMath::Abs(eta) > fTrackEtaCut) return NULL;
336 return new ((*fParticles)[fParticles->GetEntriesFast()]) AliCFParticle(pt,eta,phi,charge,mask);