1 /**************************************************************************
2 * Copyright(c) 1998-2014, 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 /**************************************************************************
18 * This class constructs inclusive and isolated (based on charged tracks)
19 * invariant spectra. Isolated case uses a different efficiency where the
20 * contamination from cases where non-isolated particle appears as an
21 * isolated one due to finite detector efficiency is taken into account.
23 * contact: Sami Räsänen
24 * University of Jyväskylä, Finland
25 * sami.s.rasanen@jyu.fi
26 **************************************************************************/
28 // general + root classes
31 #include <TObjArray.h>
34 #include <AliAnalysisManager.h>
35 #include <AliInputEventHandler.h>
36 #include <AliAnalysisUtils.h>
37 #include <AliAODTrack.h>
38 #include <AliAODEvent.h>
41 #include <AliJCard.h> // this class at PWGCF / JCORRAN
42 #include "AliJXtHistos.h"
43 //#include "AliIsolatedEfficiency.h"
46 #include "AliXtAnalysis.h"
48 ClassImp(AliXtAnalysis)
50 //________________________________________________________________________
51 AliXtAnalysis::AliXtAnalysis()
52 : AliAnalysisTaskSE(),
61 fIsolatedChargedList(0x0),
70 //________________________________________________________________________
71 AliXtAnalysis::AliXtAnalysis(const char *name, const char * cardname)
72 : AliAnalysisTaskSE(name),
81 fIsolatedChargedList(0x0),
88 // All parameters of the analysis
89 fCard = new AliJCard(cardname);
91 cout << "debug: card created to address " << fCard << endl;
95 fAnaUtils = new AliAnalysisUtils();
96 fAnaUtils->SetUseOutOfBunchPileUp( kTRUE );
97 fAnaUtils->SetUseSPDCutInMultBins( kTRUE);
99 // Define input and output slots here
100 // Input slot #0 works with a TChain
101 DefineInput(0, TChain::Class());
102 // Output slot #0 writes into a TH1 container
103 DefineOutput(1, TList::Class());
104 // JHistos into TDirectory
105 DefineOutput(2, TDirectory::Class());
107 //________________________________________________________________________
108 AliXtAnalysis::AliXtAnalysis(const AliXtAnalysis& a)
109 : AliAnalysisTaskSE(a.GetName()),
110 fOutputList(a.fOutputList),
111 fAnaUtils(a.fAnaUtils),
113 fHistDir(a.fHistDir),
115 fhEvents(a.fhEvents),
116 //fEfficiency(a.fEfficiency),
117 fChargedList(a.fChargedList),
118 fIsolatedChargedList(a.fIsolatedChargedList),
126 fhEvents = (TH1D*) a.fhEvents->Clone(a.fhEvents->GetName());
128 //________________________________________________________________________
129 AliXtAnalysis& AliXtAnalysis::operator = (const AliXtAnalysis& ap){
130 // assignment operator
131 this->~AliXtAnalysis();
132 new(this) AliXtAnalysis(ap);
135 //________________________________________________________________________
136 AliXtAnalysis::~AliXtAnalysis() {
142 //delete fEfficiency;
145 delete fIsolatedChargedList;
147 //________________________________________________________________________
148 void AliXtAnalysis::UserCreateOutputObjects(){
152 cout<<"\n=============== CARD =============="<<endl;
154 cout<<"===================================\n"<<endl;
156 fhEvents = new TH1D("hEvents","events passing cuts", 11, -0.5, 10.5 );
157 fhEvents->SetXTitle( "0 - all, 1 - pileup, 2 - kMB selected, 3 - has vertex, 4 - good vertex, 5 - MB + good vertex, 6 - MB + good vertex + centrality" );
160 fOutputList = new TList();
161 fOutputList->SetOwner(kTRUE);
162 //for any MC track filled with MC pt
163 fOutputList->Add(fhEvents);
165 fChargedList = new TObjArray;
166 fChargedList->SetOwner(kTRUE);
167 fIsolatedChargedList = new TObjArray;
169 PostData(1, fOutputList);
171 bool orignalTH1AdddirectoryStatus=TH1::AddDirectoryStatus();
172 TH1::AddDirectory(kTRUE);
173 if( !orignalTH1AdddirectoryStatus ) cout<<"DEBUG : TH1::AddDirectory is turned on"<<endl;
174 //TFile * file2 = OpenFile(2);
177 fHistos = new AliJXtHistos(fCard);
178 fHistos->CreateXtHistos();
180 PostData(2, fHistDir);
181 TH1::AddDirectory( orignalTH1AdddirectoryStatus );
182 cout<<"DEBUG : TH1::AddDirectory get orignal Value = "<<( orignalTH1AdddirectoryStatus?"True":"False" )<<endl;
184 //fEfficiency = new AliJEfficiency();
188 //________________________________________________________________________
189 void AliXtAnalysis::UserExec(Option_t *) {
191 // Main loop - called for each event
194 if(fevt % 10000 == 0) cout << "Number of event scanned = "<< fevt << endl;
196 Int_t filterBit = AliAODTrack::kTrkGlobal; //fCard->Get("TrackFilterBit");
198 AliVEvent *event = InputEvent();
201 // check if the event was triggered or not and vertex
202 if( !IsGoodEvent( event ) ) return; // fZBin is set there
204 if(fDebugMode > 0) cout << "zvtx = " << fZVert << endl;
206 AliAODEvent* aodEvent = dynamic_cast<AliAODEvent*>(event);
207 if(!aodEvent) return;
209 // centrality - in case of pPb and PbPb, dictated by DataType in the card
211 if( fCard->Get("DataType") > 0.5 ){
212 AliCentrality *cent = event->GetCentrality();
214 fcent = cent->GetCentralityPercentile("V0M");
215 fCentBin = fCard->GetBin(kCentrType, fcent);;
216 //cout <<"Centrality = "<< fcent <<"\t"<< fCentBin << endl;
222 if(fCentBin<0) return;
224 Int_t nt = aodEvent->GetNumberOfTracks();
226 fHistos->FillCentralityHistos(fcent, fCentBin);
228 // clear them up for every event
229 fChargedList->Clear();
230 fIsolatedChargedList->Clear();
232 // Is there a better way than hard code this into card???
233 double sqrts = fCard->Get("Sqrts");
235 // Isolation method: 0 = relative, 1 = absolute
236 double isolMethod = fCard->Get("IsolationMethod");
238 // Minimum isolation pT that is considered
239 double minIsolationPt = fCard->Get("MinimumIsolatedPt");
241 // Dummy numbers; either of these is updated based on selected method (other is void)
242 double isolationFraction = 99999.;
243 double isolationThreshold = 99999.;
245 if( isolMethod > 0.5 ){
246 isolationThreshold = fCard->Get("IsolationThreshold"); // this is fixed threshold
248 isolationFraction = fCard->Get("IsolationFraction"); // fraction in pT, threshold updated later in a loop
252 double isolR = fCard->Get("IsolationRadius");
254 // Get good tracks to the list
255 for(Int_t it = 0; it < nt; it++) {
256 AliAODTrack *track = dynamic_cast<AliAODTrack*>(aodEvent->GetTrack(it));
257 if( !track ) continue;
258 if( !track->TestFilterBit(filterBit) ) continue;
259 double eta = track->Eta();
260 if( !fCard->IsInEtaRange( eta ) ) continue; // Do not use fiducial cut here
261 AliAODTrack *acceptedTrack = new AliAODTrack( *track );
262 double pT = acceptedTrack->Pt();
263 double xT = 2.*pT/sqrts;
264 double phi = acceptedTrack->Phi();
267 double effCorr = 1.0;
270 fHistos->FillInclusiveHistograms(pT, xT, eta, phi, effCorr, fCentBin);
272 // Add an accepted track into list of inclusive charged particles
273 fChargedList->Add( acceptedTrack );
276 // Check isolation of the found good tracks
277 Int_t nAcc = fChargedList->GetEntriesFast();
279 // Get eta range for fiducial cut
280 double etaRange = fCard->Get("EtaRange");
282 for( Int_t it = 0; it < nAcc; it++ ){
283 AliAODTrack *track = (AliAODTrack*)fChargedList->At(it);
284 // Fiducial eta cut for isolated particles
285 double eta = track->Eta();
286 if( abs(eta) > etaRange - isolR ) continue;
288 // To check the isolation with cone, use TLorentzVector -routines
289 TLorentzVector lvTrack = TLorentzVector( track->Px(), track->Py(), track->Pz(), track->P() );
291 // Set isolation threshold, if relative isolation
292 double pT = lvTrack.Pt();
293 if( pT < minIsolationPt ) continue;
294 if( isolMethod < 0.5 ) isolationThreshold = pT * isolationFraction; // here: relative isolation
298 for( Int_t ia = 0; ia < nAcc; ia++ ){
299 if( ia == it ) continue; // Do not count the particle itself
300 AliAODTrack *assocTrack = (AliAODTrack*)fChargedList->At(ia);
301 TLorentzVector lvAssoc = TLorentzVector( assocTrack->Px(), assocTrack->Py(), assocTrack->Pz(), assocTrack->P() );
302 if( lvTrack.DeltaR( lvAssoc ) < isolR ) sum += lvAssoc.Pt();
306 fHistos->FillInclusiveConeActivities(pT,sum); // efficiency correction?
308 // If the particle was isolated, fill histograms and the list
309 if( sum < isolationThreshold ){
311 double xT = 2.*pT/sqrts;
313 if( fDebugMode > 0 ){
314 cout << "DEBUG: isolated particle found " << endl;
315 cout << "fCentBin = " << fCentBin << ", pT = " << pT << ", xT = " << xT << " and eta = " << eta << endl;
318 fHistos->FillIsolatedConeActivities(pT, sum); // efficiency correction?
321 double effCorr = 1.0;
324 fHistos->FillIsolatedHistograms(pT, xT, eta, track->Phi(), effCorr, fCentBin);
326 // Add tracks to the isolated list
327 AliAODTrack *acceptedIsolatedTrack = new AliAODTrack( *track );
328 fIsolatedChargedList->Add( acceptedIsolatedTrack );
332 // For further analysis, there is now lists of all charged and isolated charged available, will be usefull.
336 //________________________________________________________________________
337 void AliXtAnalysis::Terminate(Option_t *)
339 cout<<"Successfully finished"<<endl;
341 //________________________________________________________________________
342 bool AliXtAnalysis::IsGoodEvent(AliVEvent *event) {
344 // This function checks that the event has the requested trigger
345 // and that the z-vertex is in given range
350 if(fAnaUtils->IsPileUpEvent(event)) {
353 Bool_t triggeredEventMB = kFALSE; //init
357 Bool_t triggerkMB = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & ( AliVEvent::kMB );
360 triggeredEventMB = kTRUE; //event triggered as minimum bias
363 //--------------------------------------------------------------
364 // check reconstructed vertex
365 int ncontributors = 0;
366 Bool_t goodRecVertex = kFALSE;
367 const AliVVertex *vtx = event->GetPrimaryVertex();
370 fZVert = vtx->GetZ();
371 fHistos->FillRawVertexHisto(fZVert);
372 ncontributors = vtx->GetNContributors();
373 if(ncontributors > 0){
374 if(fCard->VertInZRange(fZVert)) {
375 goodRecVertex = kTRUE;
377 fHistos->FillAcceptedVertexHisto(fZVert, fCentBin);
378 fZBin = fCard->GetBin(kZVertType, fZVert);
382 return triggerkMB && goodRecVertex;
384 //---------------------------------