1 /*************************************************************************
2 * Copyright(c) 1998-2008, 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 ///////////////////////////////////////////////////////////////////////////
17 // Class AliSPDClustTask //
18 // Analysis task to produce data and MC histos needed for tracklets //
19 // dNdEta extraction in multiple bins in one go //
20 // Author: ruben.shahoyan@cern.ch //
21 ///////////////////////////////////////////////////////////////////////////
23 Important parameters to set:
24 1) make sure to initialize correct geometry in UserCreateOutputObjects
25 2) The cut on signal selection variable (delta, dphi ...) should be decided beforehand
35 #include "TObjArray.h"
36 #include "TGeoGlobalMagField.h"
38 #include "AliAnalysisManager.h"
40 #include "AliMultiplicity.h"
41 #include "AliESDEvent.h"
42 #include "AliESDInputHandler.h"
43 #include "AliESDInputHandlerRP.h"
44 #include "AliCDBPath.h"
45 #include "AliCDBManager.h"
46 #include "AliCDBEntry.h"
47 #include "AliCDBStorage.h"
48 #include "AliGeomManager.h"
50 #include "AliESDVZERO.h"
51 #include "AliESDZDC.h"
52 #include "AliRunLoader.h"
53 #include "AliMCEventHandler.h"
54 #include "AliMCEvent.h"
55 #include "AliMCParticle.h"
57 #include "AliGenEventHeader.h"
58 #include "AliCentrality.h"
59 #include "../ITS/AliITSRecPoint.h"
60 #include "../ITS/AliITSgeomTGeo.h"
61 #include "../ITS/AliITSMultReconstructor.h"
65 #include "AliPhysicsSelection.h"
66 #include "AliSPDClustTask.h"
67 #include "AliITSMultReconstructor.h"
68 #include "AliGenEventHeader.h"
69 #include "AliGenHijingEventHeader.h"
70 #include "AliGenDPMjetEventHeader.h"
71 #include "AliESDtrackCuts.h"
73 ClassImp(AliSPDClustTask)
76 //________________________________________________________________________
77 /*//Default constructor
78 AliSPDClustTask::AliSPDClustTask(const char *name)
79 : AliAnalysisTaskSE(name),
81 //________________________________________________________________________
82 AliSPDClustTask::AliSPDClustTask(const char *name)
83 : AliAnalysisTaskSE(name),
94 fScaleDTBySin2T(kFALSE),
95 fCutOnDThetaX(kFALSE),
100 fPhiOverlapCut(0.005),
102 fRemoveOverlaps(kFALSE),
117 DefineOutput(1, TList::Class());
119 SetScaleDThetaBySin2T();
130 //________________________________________________________________________
131 AliSPDClustTask::~AliSPDClustTask()
134 // histograms are in the output list and deleted when the output
135 // list is deleted by the TSelector dtor
136 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) { //RRR
137 printf("Deleteing output\n");
144 if (fhPtIn) delete fhPtIn;
148 //________________________________________________________________________
149 void AliSPDClustTask::UserCreateOutputObjects()
152 // OpenFile(1); fDontMerge = kTRUE;
155 fOutput = new TList();
158 AliCDBManager *man = AliCDBManager::Instance();
160 Bool_t newGeom = kTRUE;
161 man->SetDefaultStorage("alien://Folder=/alice/simulation/2008/v4-15-Release/Residual");
164 AliCDBEntry* obj = man->Get("GRP/Geometry/Data",130844,8);
165 AliGeomManager::SetGeometry((TGeoManager*) obj->GetObject());
166 if (!AliGeomManager::ApplyAlignObjsToGeom("ITS",130844,6,-1)) AliFatal("Failed to misalign geometry");
170 AliCDBEntry* obj = man->Get("GRP/Geometry/Data",130845,7);
171 AliGeomManager::SetGeometry((TGeoManager*) obj->GetObject());
172 if (!AliGeomManager::ApplyAlignObjsToGeom("ITS",130845,5,-1)) AliFatal("Failed to misalign geometry");
176 man->SetDefaultStorage("alien://Folder=/alice/data/2010/OCDB"); //man->SetRun(137366);
177 AliCDBEntry* obj = man->Get("GRP/Geometry/Data",137366);
178 AliGeomManager::SetGeometry((TGeoManager*) obj->GetObject());
179 if (!AliGeomManager::ApplyAlignObjsToGeom("ITS",137366,-1,-1)) AliFatal("Failed to misalign geometry");
183 fHistos = BookHistos();
184 for(Int_t i=0; i<fHistos->GetEntriesFast(); i++) {
186 fOutput->AddLast(fHistos->At(i));
190 PostData(1, fOutput);
194 //________________________________________________________________________
195 void AliSPDClustTask::UserExec(Option_t *)
200 AliAnalysisManager* anMan = AliAnalysisManager::GetAnalysisManager();
202 AliESDInputHandlerRP *handRP = (AliESDInputHandlerRP*)anMan->GetInputEventHandler();
203 if (!handRP) { AliError("No RP handler"); return; }
205 fRPTree = handRP->GetTreeR("ITS");
206 if (!fRPTree) { AliError(" Invalid ITS cluster tree !\n"); return; }
208 AliESDEvent *esd = handRP->GetEvent();
209 if (!esd) { AliError("No AliESDEvent"); return; }
211 AliMCEventHandler* eventHandler = 0;
216 eventHandler = (AliMCEventHandler*)anMan->GetMCtruthEventHandler();
217 if (!eventHandler) { AliError("Could not retrieve MC event handler"); return; }
218 fMCEvent = eventHandler->MCEvent();
219 if (!fMCEvent) { AliError("Could not retrieve MC event"); return; }
220 fStack = fMCEvent->Stack();
221 if (!fStack) { AliError("Stack not available"); return; }
224 const AliESDVertex* vtxESD = esd->GetPrimaryVertexSPD();
225 if (vtxESD->GetNContributors()<1) return;
227 // ------------------RS: Put here additional event selection if needed ------->>
228 // at the moment, I am just selecting on vertex
229 TString vtxTyp = vtxESD->GetTitle();
230 if (vtxTyp.Contains("vertexer: Z")) {
231 if (vtxESD->GetDispersion()>0.04) return;
232 if (vtxESD->GetZRes()>0.25) return;
235 if (vtxESD->GetZ()<fZVertexMin || vtxESD->GetZ()>fZVertexMax) return;
238 if (esd->IsPileupFromSPD(3,0.8)) return;
240 // ------------------RS: Put here additional event selection if needed -------<<
242 fVtx[0] = vtxESD->GetX();
243 fVtx[1] = vtxESD->GetY();
244 fVtx[2] = vtxESD->GetZ();
246 // do we need to initialize the field?
247 AliMagF* field = (AliMagF*)TGeoGlobalMagField::Instance()->GetField();
248 if (!field && !esd->InitMagneticField()) {printf("Failed to initialize the B field\n");return;}
250 AliStack *stack = NULL;
252 if (!fMCEvent) { AliError("Could not retrieve MC event"); return; }
253 stack = fMCEvent->Stack();
254 if (!stack) { AliError("ERROR: Could not get stack"); return; }
255 for (Int_t iPart = 0; iPart < stack->GetNtrack(); ++iPart) {
256 if (!stack->IsPhysicalPrimary(iPart)) continue;
257 TParticle* p = stack->Particle(iPart);
258 if (TMath::Abs(p->Y()) > 0.5) continue;
259 if (TMath::Abs(p->GetPdgCode()) != 211) continue;
260 TH1D *hPt = (TH1D*)fHistos->At(kHPt);
266 fMultReco->Reconstruct(fRPTree, fVtx);
267 // AliMultiplicity* mlt = fMultReco->GetMultiplicity();
275 //________________________________________________________________________
276 void AliSPDClustTask::Terminate(Option_t *)
278 Printf("Terminating...");
281 //_________________________________________________________________________
282 void AliSPDClustTask::InitMultReco()
284 // create mult reconstructor
285 if (fMultReco) delete fMultReco;
286 fMultReco = new AliITSMultReconstructor();
287 fMultReco->SetCreateClustersCopy(kTRUE);
288 fMultReco->SetScaleDThetaBySin2T(fScaleDTBySin2T);
289 fMultReco->SetNStdDev(fNStdDev);
290 fMultReco->SetPhiWindow( fDPhiWindow );
291 fMultReco->SetThetaWindow( fDThetaWindow );
292 fMultReco->SetPhiShift( fDPhiShift );
293 fMultReco->SetRemoveClustersFromOverlaps(fRemoveOverlaps);
294 fMultReco->SetPhiOverlapCut(fPhiOverlapCut);
295 fMultReco->SetZetaOverlapCut(fZetaOverlap);
296 fMultReco->SetHistOn(kFALSE);
300 //_________________________________________________________________________
301 TObjArray* AliSPDClustTask::BookHistos()
303 // book set of histos
305 TObjArray* histos = new TObjArray();
306 histos->SetOwner(kFALSE);
307 // this array contains histos stored at slots:
308 // 0-99 : tracklet related histos
309 // 100-199 : SPD1 clusters not used by tracklets
310 // 200-299 : SPD2 clusters not used by tracklets
311 // 300-399 : SPD1 clusters used by tracklets
312 // 400-499 : SPD2 clusters used by tracklets
314 int nEtaBins = int((fEtaMax-fEtaMin)/0.1);
315 if (nEtaBins<1) nEtaBins = 1;
317 // just an example: cluster type vs eta
318 for (int iused=0;iused<2;iused++) {
319 for (int spd=0;spd<2;spd++) {
320 TH2F* h = new TH2F(Form("clType_SPD%d_%s",spd,iused ? "used":"free"),
321 Form("clType SPD%d %s",spd,iused ? "used":"free"),
322 nEtaBins, fEtaMin,fEtaMax,
324 histos->AddAtAndExpand(h, kHClusters+iused*200+spd*100 + kClTypevsEta);
325 TH1F* hZ = new TH1F(Form("clZ_SPD%d_%s",spd,iused ? "used":"free"),
326 Form("clZ SPD%d %s",spd,iused ? "used":"free"),
328 histos->AddAtAndExpand(hZ, kHClusters+iused*200+spd*100 + kClZ);
329 TH1F* hEta = new TH1F(Form("clEta_SPD%d_%s",spd,iused ? "used":"free"),
330 Form("clEta SPD%d %s",spd,iused ? "used":"free"),
331 nEtaBins, fEtaMin,fEtaMax);
332 histos->AddAtAndExpand(hEta, kHClusters+iused*200+spd*100 + kClEta);
334 hZ = new TH1F(Form("clZ_pions_weighted_SPD%d_%s",spd,iused ? "used":"free"),
335 Form("clZ pions weighted SPD%d %s",spd,iused ? "used":"free"),
337 histos->AddAtAndExpand(hZ, kHClusters+iused*200+spd*100 + kClZPionsW);
338 hEta = new TH1F(Form("clEta_pions_weighted_SPD%d_%s",spd,iused ? "used":"free"),
339 Form("clEta pions weighted SPD%d %s",spd,iused ? "used":"free"),
340 nEtaBins, fEtaMin,fEtaMax);
341 histos->AddAtAndExpand(hEta, kHClusters+iused*200+spd*100 + kClEtaPionsW);
343 hZ = new TH1F(Form("clZ_pions_SPD%d_%s",spd,iused ? "used":"free"),
344 Form("clZ pions SPD%d %s",spd,iused ? "used":"free"),
346 histos->AddAtAndExpand(hZ, kHClusters+iused*200+spd*100 + kClZPions);
347 hEta = new TH1F(Form("clEta_pions_SPD%d_%s",spd,iused ? "used":"free"),
348 Form("clEta pions SPD%d %s",spd,iused ? "used":"free"),
349 nEtaBins, fEtaMin,fEtaMax);
350 histos->AddAtAndExpand(hEta, kHClusters+iused*200+spd*100 + kClEtaPions);
354 TH1D *hPt = new TH1D("hPt","Pions Pt spectra (MC)",fhPtIn->GetXaxis()->GetNbins(),fhPtIn->GetXaxis()->GetXbins()->GetArray());
355 histos->AddAtAndExpand(hPt, kHPt);
361 //_________________________________________________________________________
362 void AliSPDClustTask::FillHistos(AliStack *stack)
364 // fill info on clusters, separately on associated to tracklets and singles
365 const int kUsedBit = BIT(15);
367 // 0) --------- just in case: reset kUsedBit of clusters --->>>
368 for (int ilr=0;ilr<2;ilr++) {
369 for (int icl=fMultReco->GetNClustersLayer(ilr);icl--;) { // loop on clusters of layer
370 AliITSRecPoint *clus = fMultReco->GetRecPoint(ilr,icl);
372 AliError(Form("Failed to extract cluster %d of layer %d",icl,ilr));
375 clus->ResetBit(kUsedBit);
376 } // loop on clusters of layer
379 // 1) --------- mark used clusters by kUsedBit ------------>>>
380 int ntr = fMultReco->GetNTracklets();
381 for (int itr=ntr;itr--;) {
382 Float_t *trc = fMultReco->GetTracklet(itr);
383 AliITSRecPoint *cl0 = fMultReco->GetRecPoint(0,(int)trc[AliITSMultReconstructor::kClID1]); // cluster on SPD1
384 AliITSRecPoint *cl1 = fMultReco->GetRecPoint(1,(int)trc[AliITSMultReconstructor::kClID2]); // cluster on SPD1
387 AliError(Form("Failed to extract clusters associated with tracklet %d",itr));
390 cl0->SetBit(kUsedBit);
391 cl1->SetBit(kUsedBit);
394 // 2) --------- fill needed info for used and unuses clusters
398 for (int ilr=0;ilr<2;ilr++) { // loop on layers
399 int ncl = fMultReco->GetNClustersLayer(ilr);
400 for (int icl=ncl;icl--;) { // loop on clusters of layer
401 AliITSRecPoint *clus = fMultReco->GetRecPoint(ilr,icl); // extract the cluster to access clType
402 Float_t* clInfo = fMultReco->GetClusterOfLayer(ilr,icl); // we already have in the MultReco cluster params extracted and
403 // stored in the float array, see AliITSMultReconstructor
405 float phi = clInfo[AliITSMultReconstructor::kClPh];
406 float eta = -TMath::Log(TMath::Tan(clInfo[AliITSMultReconstructor::kClTh]/2));
407 float z = clInfo[AliITSMultReconstructor::kClZ];
409 int used = clus->TestBit(kUsedBit) ? 1:0;
411 // Annalisa, here you should fill the info on used/unused clusters
412 if (phi > 0 && phi < 1.6) {
413 h2d = (TH2F*)fHistos->At(kHClusters+used*200+ilr*100 + kClTypevsEta);
414 h2d->Fill(eta, clus->GetClusterType());
415 h1d = (TH1F*)fHistos->At(kHClusters+used*200+ilr*100 + kClZ);
417 h1d = (TH1F*)fHistos->At(kHClusters+used*200+ilr*100 + kClEta);
420 for(Int_t iLabel = 0; iLabel < 3; ++iLabel) {
421 Int_t clLabel = clus->GetLabel(iLabel);
422 if (clLabel <= 0) continue;
423 Int_t moLabel = FindMotherParticle(stack, clLabel);
424 if (moLabel <= 0) continue;
425 TParticle* p = stack->Particle(moLabel);
426 if (TMath::Abs(p->GetPdgCode()) != 211) continue;
427 Double_t weight = PtWeight(p->Pt());
428 h1d = (TH1F*)fHistos->At(kHClusters+used*200+ilr*100 + kClZPionsW);
430 h1d = (TH1F*)fHistos->At(kHClusters+used*200+ilr*100 + kClEtaPionsW);
431 h1d->Fill(eta,weight);
432 h1d = (TH1F*)fHistos->At(kHClusters+used*200+ilr*100 + kClZPions);
434 h1d = (TH1F*)fHistos->At(kHClusters+used*200+ilr*100 + kClEtaPions);
440 } // loop on clusters of layer
445 //________________________________________________________________________
446 void AliSPDClustTask::SetInput(const char *filename)
448 // Read pions Pt spectra
449 // from a local input file
451 AliInfo(Form("Reading input histograms from %s",filename));
453 TFile *fPt = TFile::Open("spectraCombine.root");
454 if (!fPt) { AliError("Failed to open input file"); return; }
455 TList *lPt = (TList*)fPt->Get("output");
456 fhPtIn = (TH1D*)lPt->FindObject("PionsPos_MB_combine_sum")->Clone("fhPtIn");
457 fhPtIn->SetDirectory(0);
462 //________________________________________________________________________
463 Int_t AliSPDClustTask::FindMotherParticle(AliStack* stack, Int_t i)
465 if(stack->IsPhysicalPrimary(i)) return i;
466 TParticle* p = stack->Particle(i);
467 Int_t imo = p->GetFirstMother();
469 // printf("imo = %d\n",imo);
473 AliInfo("particle is not a PhysPrim and has no mother");
476 return FindMotherParticle(stack, imo);
480 //________________________________________________________________________
481 Double_t AliSPDClustTask::PtWeight(Double_t pt)
486 return (1.71-0.71*pt/0.35);