Updates.
[u/mrichter/AliRoot.git] / PWG1 / ITS / AliAnalysisTaskSPD.cxx
CommitLineData
4587ea58 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
16
17//-----------------------------------------------------------------------
18// Author : A. Mastroserio
19//-----------------------------------------------------------------------
20
21
22#ifndef ALIANALYSISTASKSPD_CXX
23#define ALIANALYSISTASKSPD_CXX
24
25#include "AliAnalysisTaskSPD.h"
26#include "TClonesArray.h"
27#include "TBranch.h"
28#include "TH1I.h"
29#include "TH2D.h"
30#include "TFile.h"
31#include "AliSPDUtils.h"
32#include "AliESDEvent.h"
33#include "TChain.h"
34#include "AliLog.h"
35#include "AliESDInputHandlerRP.h"
36#include "AliAnalysisManager.h"
37#include "AliMultiplicity.h"
38#include "AliCDBPath.h"
39#include "AliCDBManager.h"
40#include "AliCDBEntry.h"
41#include "AliCDBStorage.h"
42#include "AliGeomManager.h"
43#include "AliITSRecPoint.h"
44#include "AliITSsegmentationSPD.h"
45ClassImp(AliAnalysisTaskSPD)
46 //__________________________________________________________________________
47 AliAnalysisTaskSPD::AliAnalysisTaskSPD() :
48 fSegSPD(0x0),
49 fOutput(0x0),
50 fRunNb(999),
51 fOCDBLocation("local://$ALICE_ROOT/OCDB")
52{
53 //
54 //Default ctor
55 //
56}
57//___________________________________________________________________________
58AliAnalysisTaskSPD::AliAnalysisTaskSPD(const Char_t* name) :
59 AliAnalysisTaskSE(name),
60 fSegSPD(0x0),
61 fOutput(0x0),
62 fRunNb(999),
63 fOCDBLocation("local://$ALICE_ROOT/OCDB")
64{
65 //
66 // Constructor. Initialization of Inputs and Outputs
67 //
68 Info("AliAnalysisTaskSPD","Calling Constructor");
69
70 DefineOutput(1,TList::Class());
71 //
72}
73
74//___________________________________________________________________________
75AliAnalysisTaskSPD& AliAnalysisTaskSPD::operator=(const AliAnalysisTaskSPD& c)
76{
77 //
78 // Assignment operator
79 //
80 if (this!=&c) {
81 AliAnalysisTaskSE::operator=(c) ;
82 fSegSPD = c.fSegSPD ;
83 fOutput = c.fOutput ;
84 fRunNb = c.fRunNb;
85 fOCDBLocation = c.fOCDBLocation;
4587ea58 86 }
87 return *this;
88}
89
90//___________________________________________________________________________
91AliAnalysisTaskSPD::AliAnalysisTaskSPD(const AliAnalysisTaskSPD& c) :
92 AliAnalysisTaskSE(c),
93 fSegSPD(c.fSegSPD),
94 fOutput(c.fOutput),
95 fRunNb(c.fRunNb),
96 fOCDBLocation(c.fOCDBLocation)
97{
98 //
99 // Copy Constructor
100 //
101
102}
103
104//___________________________________________________________________________
105AliAnalysisTaskSPD::~AliAnalysisTaskSPD() {
106 //
107 //destructor
108 //
59c31cc1 109
4587ea58 110 Info("~AliAnalysisTaskSPD","Calling Destructor");
59c31cc1 111 if (AliAnalysisManager::GetAnalysisManager()->IsProofMode()) return;
112 if (fSegSPD) delete fSegSPD ;
4587ea58 113 if (fOutput) {
114 delete fOutput;
115 fOutput = 0;
116 }
117}
118//___________________________________________________________________________
119void AliAnalysisTaskSPD::UserCreateOutputObjects() {
120
121 Info("CreateOutputObjects","CreateOutputObjects of task %s", GetName());
122 if(fRunNb!=999){
123 LoadGeometryFromOCDB();
124 }
125 fSegSPD = new AliITSsegmentationSPD();
126
127 //slot #1
128 OpenFile(1);
129 fOutput = new TList();
9ea163ca 130 fOutput->SetOwner();
131
4587ea58 132 //
133 // Booking rec points related histograms
134 //0
59c31cc1 135 TH2D *hLocalMapL1 = new TH2D("hLocalMapL1"," Local coordinates - Layer 1",330,-16.5,16.5,205,-0.5,40.5); // safe limits for local coordinates in a module : z = -4,4, x = -1,1;
4587ea58 136 hLocalMapL1->SetXTitle("direction Z [cm]");
137 hLocalMapL1->SetYTitle("direction X [cm]");
138 fOutput->AddLast(hLocalMapL1);
139 //1
59c31cc1 140 TH2D *hLocalMapL2 = new TH2D("hLocalMapL2"," Local coordinates - Layer 2",330,-16.5,16.5,405,-0.5,80.5);
4587ea58 141 hLocalMapL2->SetXTitle("direction Z [cm]");
142 hLocalMapL2->SetYTitle("direction X [cm]");
143 fOutput->AddLast(hLocalMapL2);
144 //2
145 TH1F *hClusterModYield = new TH1F("hClusterModYield","Cluster yield in modules",241,-0.5,240.5);
146 hClusterModYield->SetXTitle("module number");
147 fOutput->AddLast(hClusterModYield);
148 // 3
149 TH1F *hClusterYield = new TH1F("hClusterYield","Cluster yield per chip",1200,-0.5,1199.5) ;
150 hClusterYield->SetXTitle("chip key");
151 fOutput->AddLast(hClusterYield);
152 //4
153 TH1F *hClusterYieldOnline = new TH1F("hClusterYieldOnline","Cluster yield per chip (online coord eq*60+hs*10+chip)",1200,-0.5,1199.5) ;
154 hClusterYieldOnline->SetXTitle("chip");
155 fOutput->AddLast(hClusterYieldOnline);
156 //5
157 TH1F *hFiredChip = new TH1F("hFiredChip","Fired chip (at least one cluster)",1200,-0.5,1199.5);
158 hFiredChip->SetXTitle("chip key");
159 fOutput->AddLast(hFiredChip);
160 //6
161 TH1F *hFOFiredChip = new TH1F("hFOFiredChip","FO Fired chip ",1200,-0.5,1199.5);
162 hFOFiredChip->SetXTitle("chip key");
163 fOutput->AddLast(hFOFiredChip);
164 //7
165 TH1F *hFOgood = new TH1F("hFOgood"," FO-good (at least one cluster) ",1200,-0.5,1199.5);
ce972512 166 hFOgood->SetXTitle("chip key");
4587ea58 167 fOutput->AddLast(hFOgood);
ce972512 168 //8
169 TH2F *hFOgoodPerBC = new TH2F("hFOgoodPerBCmod4"," FO-good signals in BCmod4 ",1200,-0.5,1199.5,4,-0.5,3.5);
170 hFOgoodPerBC->SetXTitle("chip key");
171 fOutput->AddLast(hFOgoodPerBC);
172 //9
173 TH2F *hFiredChipsPerBC = new TH2F("hFiredChipsPerBCmod4"," fired chips in BCmod4 ",1200,-0.5,1199.5,4,-0.5,3.5);
174 hFiredChipsPerBC->SetXTitle("chip key");
175 fOutput->AddLast(hFiredChipsPerBC);
176 //10
4587ea58 177 TH1F *hFOnoisy = new TH1F("hFOnoisy","FO-noisy (no cluster)",1200,-0.5,1199.5);
ce972512 178 hFOnoisy->SetXTitle("chip key");
4587ea58 179 fOutput->AddLast(hFOnoisy);
180
181 //
182 // Booking ESD related histograms
183 //
184
ce972512 185 // 11
9ea163ca 186 TH1I *hTracklets = new TH1I("hNtracklets","Tracklet distribution",500,0,500);
ce972512 187 hTracklets->SetXTitle("# Tracklets");
4587ea58 188 fOutput->AddLast(hTracklets);
ce972512 189 //12
4587ea58 190 TH2F *hSPDphivsSPDeta= new TH2F("hSPDphivsSPDeta", "Tracklets - #varphi vs #eta",120,-3.,3,360,0.,2*TMath::Pi());
191 hSPDphivsSPDeta->GetXaxis()->SetTitle("Pseudorapidity #eta");
192 hSPDphivsSPDeta->GetYaxis()->SetTitle("#varphi [rad]");
193 fOutput->AddLast(hSPDphivsSPDeta);
ce972512 194 //13
4587ea58 195 TH1F *hSPDphiZpos= new TH1F("hSPDphiZpos", "Tracklets - #varphi (Z>0)",360,0.,2*TMath::Pi());
196 hSPDphiZpos->SetXTitle("#varphi [rad]");
197 fOutput->AddLast(hSPDphiZpos);
ce972512 198 //14
4587ea58 199 TH1F *hSPDphiZneg= new TH1F("hSPDphiZneg", "Tracklets - #varphi (Z<0)",360,0.,2*TMath::Pi());
200 hSPDphiZneg->SetXTitle("#varphi [rad]");
201 fOutput->AddLast(hSPDphiZneg);
ce972512 202 //15
4587ea58 203 TH1F *hVertexZ = new TH1F("hVertexZ","Vertex Z distribution",300,-15,15);
204 hVertexZ->SetXTitle("Z Vertex [cm]");
205 fOutput->AddLast(hVertexZ);
ce972512 206 //16
59c31cc1 207 TH2F *hTracklVsClu1 = new TH2F("hTrackVsClu1","Tracklet Vs Clusters Layer 1",100,0,8000,300,0,12000);
208 hTracklVsClu1->SetXTitle("clusters SPD Layer 1");
209 hTracklVsClu1->SetYTitle("tracklets");
210 fOutput->AddLast(hTracklVsClu1);
211 //17
212 TH2F *hTracklVsClu2 = new TH2F("hTrackVsClu2","Tracklet Vs Clusters Layer 2",100,0,8000,300,0,12000);
213 hTracklVsClu2->SetXTitle("clusters SPD Layer 2");
214 hTracklVsClu2->SetYTitle("tracklets");
215 fOutput->AddLast(hTracklVsClu2);
216 //18
4587ea58 217 TH1I *hEventsProcessed = new TH1I("hEventsProcessed","Number of processed events",1,0,1) ;
218 fOutput->AddLast(hEventsProcessed);
59c31cc1 219
220 PostData(1,fOutput);
4587ea58 221}
222//_________________________________________________
223void AliAnalysisTaskSPD::UserExec(Option_t *)
224{
225 //
226 // Main loop function
227 //
4587ea58 228 AliESDInputHandlerRP *hand = dynamic_cast<AliESDInputHandlerRP*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
229 if(!hand) {
230 printf("No AliESDInputHandlerRP \n");
231 return;
232 }
233
234 AliESDEvent *ESD = hand->GetEvent();
235 if(!ESD) {
236 printf("No AliESDEvent \n");
237 return;
238 }
3c9441f1 239
240 Bool_t recP = kTRUE;
4587ea58 241 TTree * treeRP = hand->GetTreeR("ITS");
242 if(!treeRP) {
3c9441f1 243 //AliWarning("No ITS RecPoints tree ");
244 recP=kFALSE;
4587ea58 245 }
246
3c9441f1 247
248
249 // ESD related histograms
250
251 const AliESDVertex *vertex = ESD->GetPrimaryVertexSPD();
252 const AliMultiplicity *mult = ESD->GetMultiplicity();
253
254 // Event selection
255 if(!vertex) return;
256 if(!vertex->GetStatus()) return;
257 if(vertex->GetNContributors() < 1) return;
258
59c31cc1 259 ((TH1I*)fOutput->At(18))->Fill(0);
3c9441f1 260
261 ((TH1I*)fOutput->At(11))->Fill(mult->GetNumberOfTracklets());
262 UInt_t bc = (UInt_t)ESD->GetBunchCrossNumber();
263 for(Int_t iChipKey=0; iChipKey < 1200; iChipKey++){
264 if(mult->TestFiredChipMap(iChipKey)) {
265 ((TH1F*)fOutput->At(5))->Fill(iChipKey);
266 if(bc>0)((TH2F*)fOutput->At(9))->Fill(iChipKey,bc%4);
267 }
268 if(mult->TestFastOrFiredChips(iChipKey)) ((TH1F*)fOutput->At(6))->Fill(iChipKey);
269 if(mult->TestFastOrFiredChips(iChipKey) && mult->TestFiredChipMap(iChipKey)) {
270 ((TH1F*)fOutput->At(7))->Fill(iChipKey);
271 if(bc>0) ((TH2F*)fOutput->At(8))->Fill(iChipKey,bc%4);
272
273 }
274 if(mult->TestFastOrFiredChips(iChipKey) && !mult->TestFiredChipMap(iChipKey)) ((TH1F*)fOutput->At(10))->Fill(iChipKey);
275 }
276
277
278 Double_t vtxPos[3] = {999, 999, 999};
279 if(vertex){
280 vertex->GetXYZ(vtxPos);
281
282 ((TH1F*)fOutput->At(15))->Fill(vtxPos[2]);
59c31cc1 283
284 ((TH2F*)fOutput->At(16))->Fill(mult->GetNumberOfITSClusters(0),mult->GetNumberOfTracklets());
285 ((TH2F*)fOutput->At(17))->Fill(mult->GetNumberOfITSClusters(1),mult->GetNumberOfTracklets());
3c9441f1 286
287 for(Int_t iTracklet =0; iTracklet < mult->GetNumberOfTracklets(); iTracklet++){
4587ea58 288
3c9441f1 289 Float_t phiTr= mult->GetPhi(iTracklet);
290 Float_t etaTr =mult->GetEta(iTracklet);
291
292 ((TH2F*)fOutput->At(12))->Fill(etaTr,phiTr);
293
294 // Z pos or Z neg
295 Float_t z = vtxPos[2] + 3.9 / TMath::Tan(2 * TMath::ATan(TMath::Exp(- etaTr)));
296 if(z>0) ((TH1F*)fOutput->At(13))->Fill(phiTr);
297 else ((TH1F*)fOutput->At(14))->Fill(phiTr);
298 }
299 }
300
301
302 if(recP){
4587ea58 303 // RecPoints info
304
305 TClonesArray statITSrec("AliITSRecPoint");
306 TClonesArray *ITSCluster = &statITSrec;
307 TBranch* branch=treeRP->GetBranch("ITSRecPoints");
308 if(!branch) {
309 printf("NO treeRP branch available. Exiting...\n");
310 return;
311 }
312
313 branch->SetAddress(&ITSCluster);
314
4587ea58 315 for(Int_t iMod=0;iMod<240;iMod++){
316 branch->GetEvent(iMod);
317 Int_t nrecp = statITSrec.GetEntries();
318 if(nrecp>0) ((TH1F*)fOutput->At(2))->Fill(iMod,nrecp);
319
320 for(Int_t irec=0;irec<nrecp;irec++) {
321 AliITSRecPoint *recp = (AliITSRecPoint*)statITSrec.At(irec);
322 Int_t lay=recp->GetLayer();
323 if(lay>1) continue;
324
325 // ---- Filling maps (local coordinates rearranged) -----
326 Float_t local[3]={-1,-1};
327 local[1]=recp->GetDetLocalX();
328 local[0]=recp->GetDetLocalZ();
329 Int_t eq = AliSPDUtils::GetOnlineEqIdFromOffline(iMod);
330 Int_t hs = AliSPDUtils::GetOnlineHSFromOffline(iMod);
331 Int_t row, col;
332 fSegSPD->LocalToDet(0.5,local[0],row,col);
333 Int_t chip = AliSPDUtils::GetOnlineChipFromOffline(iMod,col);
334
335 Double_t locx, locz, equip;
336 Double_t corrlocz =0;
337 if(lay==0) corrlocz=local[0];
338 else corrlocz = -local[0];
339 // rearranging local geometry
340 if(eq<10) equip=eq;
341 else equip=eq-10;
342 if(eq<10){
343 if(chip<5) locz =corrlocz +8 +4;
344 else locz = corrlocz+4;
345 } else {
346 if(chip<5) locz = corrlocz-8-4;
347 else locz = corrlocz-4;
348 }
349 // filling maps
350 if(lay==0){
351 locx = (local[1]+1) + hs*2 +equip*4;
352 ((TH2D*)fOutput->At(0))->Fill(locz,locx);
353
354 } else {
355 locx = (local[1]+1) + (hs-2)*2 +equip*8;
356 ((TH2D*)fOutput->At(1))->Fill(locz,locx);
357 }
358 // ---- End Filling maps (local coordinates rearranged) -----
359
4587ea58 360 ((TH1F*)fOutput->At(3))->Fill(AliSPDUtils::GetOfflineChipKeyFromOnline(eq,hs,chip));
361 ((TH1F*)fOutput->At(4))->Fill(eq*60+hs*10+chip);
362
363 }
364 }
3c9441f1 365 }// end if rec points are available
4587ea58 366
4587ea58 367
368
4587ea58 369
370 /* PostData(0) is taken care of by AliAnalysisTaskSE */
371 PostData(1,fOutput) ;
372
373}
374
375
376//___________________________________________________________________________
377void AliAnalysisTaskSPD::Terminate(Option_t*)
378{
379 // The Terminate() function is the last function to be called during
380 // a query. It always runs on the client, it can be used to present
381 // the results graphically or save the results to file.
382
4587ea58 383 AliAnalysisTaskSE::Terminate();
384}
385
386
387
388//___________________________________________________________________________
389void AliAnalysisTaskSPD::LoadGeometryFromOCDB(){
390 //method to get the gGeomanager
391 // it is called at the CreatedOutputObject stage
392 // to comply with the CAF environment
393 AliCDBManager *man = AliCDBManager::Instance();
394 man->SetDefaultStorage(fOCDBLocation.Data());
395 man->SetRun(fRunNb);
396 AliCDBEntry* obj = man->Get(AliCDBPath("GRP", "Geometry", "Data"));
06482779 397 if (obj)
398 AliGeomManager::SetGeometry((TGeoManager*)obj->GetObject());
4587ea58 399 AliGeomManager::GetNalignable("ITS");
400 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
401}
402
403
404#endif