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