]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDBackgroundCorrection.cxx
Updated surveyed TPC laser tracks (Jens)
[u/mrichter/AliRoot.git] / FMD / AliFMDBackgroundCorrection.cxx
CommitLineData
df0d5480 1/**************************************************************************
2 * Copyright(c) 2004, 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// Thil class computes background corrections for the FMD. The correction is computed
17// in eta,phi cells and the objects stored can be put into alien to use with analysis.
18// It is based on the AliFMDInput class that is used to loop over hits and primaries.
19//
20// Author: Hans Hjersing Dalsgaard, NBI, hans.dalsgaard@cern.ch
21//
22//
23
24#include "AliSimulation.h"
25#include "TStopwatch.h"
26#include "iostream"
27#include "TGrid.h"
28#include "AliRunLoader.h"
29#include "AliGeomManager.h"
30#include "AliFMDGeometry.h"
31#include "AliStack.h"
32#include "TParticle.h"
33#include "TDatabasePDG.h"
34#include "TParticlePDG.h"
35#include "AliRun.h"
36#include "AliFMDBackgroundCorrection.h"
37#include "TSystem.h"
38#include "AliCDBManager.h"
39#include "TTree.h"
40#include "TClonesArray.h"
41#include "TBranch.h"
42#include "AliFMDHit.h"
43#include "AliLoader.h"
44#include "AliFMD.h"
45#include "TH2F.h"
46#include "AliGenEventHeader.h"
47#include "AliHeader.h"
48#include "TFile.h"
49#include "TAxis.h"
50#include "AliCDBId.h"
51#include "AliCDBMetaData.h"
52#include "TROOT.h"
53#include "AliFMDParameters.h"
54#include "AliLog.h"
26c8b5ff 55#include "TList.h"
8dc823cc 56#include "AliFMDAnaParameters.h"
b82e76e0 57#include "AliFMDAnaCalibBackgroundCorrection.h"
08d168d9 58#include "AliTrackReference.h"
59#include "AliFMDStripIndex.h"
df0d5480 60
61ClassImp(AliFMDBackgroundCorrection)
62//_____________________________________________________________________
63AliFMDBackgroundCorrection::AliFMDBackgroundCorrection() :
64 TNamed(),
ca3af5d9 65 fCorrectionArray(),
66 fPrimaryList()
df0d5480 67{}
68
69//_____________________________________________________________________
08d168d9 70AliFMDBackgroundCorrection::AliFMDInputBG::AliFMDInputBG(Bool_t hits_not_trackref) :
df0d5480 71 AliFMDInput(),
8dc823cc 72 fPrimaryArray(),
73 fHitArray(),
df0d5480 74 fPrim(0),
75 fHits(0),
76 fZvtxCut(0),
77 fNvtxBins(0),
78 fPrevTrack(-1),
79 fPrevDetector(-1),
80 fPrevRing('Q'),
81 fNbinsEta(100)
82{
83 AddLoad(kTracks);
08d168d9 84 if(hits_not_trackref)
85 AddLoad(kHits);
86 else
87 AddLoad(kTrackRefs);
df0d5480 88 AddLoad(kKinematics);
89 AddLoad(kHeader);
90}
91
92//_____________________________________________________________________
93
08d168d9 94void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(Bool_t from_hits,
95 const Int_t nvtxbins,
df0d5480 96 Float_t zvtxcut,
ca3af5d9 97 const Int_t nBinsEta,
df0d5480 98 Bool_t storeInAlien,
99 Int_t runNo,
100 Int_t endRunNo,
101 const Char_t* filename,
102 Bool_t simulate,
109e97cd 103 Int_t nEvents,
104 Bool_t inFile,
105 const Char_t* infilename) {
df0d5480 106
ca3af5d9 107 //TGrid::Connect("alien:",0,0,"t");
df0d5480 108 if(simulate)
109 Simulate(nEvents);
110 else {
ca3af5d9 111 //AliCDBManager::Instance()->SetDefaultStorage("alien://Folder=/alice/data/2008/LHC08d/OCDB/");
112 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
df0d5480 113 AliCDBManager::Instance()->SetRun(runNo);
114
115#if defined(__CINT__)
116 gSystem->Load("liblhapdf");
117 gSystem->Load("libEGPythia6");
118 gSystem->Load("libpythia6");
119 gSystem->Load("libAliPythia6");
120 gSystem->Load("libgeant321");
121#endif
ca3af5d9 122 //
df0d5480 123 }
124
125 //Setting up the geometry
126 //-----------------------------------------------
127 if (AliGeomManager::GetGeometry() == NULL)
128 AliGeomManager::LoadGeometry();
129
130 AliFMDGeometry* geo = AliFMDGeometry::Instance();
131 geo->Init();
132 geo->InitTransformations();
ca3af5d9 133
df0d5480 134 AliInfo("Processing hits and primaries ");
135
08d168d9 136 AliFMDInputBG input(from_hits);
df0d5480 137
109e97cd 138 if(!inFile) {
139
140 input.SetVtxCutZ(zvtxcut);
141 input.SetNvtxBins(nvtxbins);
142 input.SetNbinsEta(nBinsEta);
143 input.Run();
144 }
df0d5480 145
109e97cd 146 AliInfo(Form("Found %d primaries and %d hits.", input.GetNprim(),input.GetNhits()));
147 TObjArray* hitArray ;
148 TObjArray* primaryArray;
149 if(inFile) {
150 TFile* infile = TFile::Open(infilename);
151 hitArray = new TObjArray();
152 primaryArray = new TObjArray();
153
154 for(Int_t det =1; det<=3;det++)
155 {
156 TObjArray* detArrayHits = new TObjArray();
157 detArrayHits->SetName(Form("FMD%d",det));
158 hitArray->AddAtAndExpand(detArrayHits,det);
159 Int_t nRings = (det==1 ? 1 : 2);
160 for(Int_t ring = 0;ring<nRings;ring++)
161 {
162
163 Char_t ringChar = (ring == 0 ? 'I' : 'O');
164 TObjArray* vtxArrayHits = new TObjArray();
165 vtxArrayHits->SetName(Form("FMD%d%c",det,ringChar));
166 detArrayHits->AddAtAndExpand(vtxArrayHits,ring);
167 for(Int_t v=0; v<nvtxbins;v++)
168 {
169
170 TH2F* hHits = (TH2F*)infile->Get(Form("hHits_FMD%d%c_vtx%d",det,ringChar,v));
171
172
173 vtxArrayHits->AddAtAndExpand(hHits,v);
174
175 }
176 }
177
178 }
179
180 for(Int_t iring = 0; iring<2;iring++) {
181 Char_t ringChar = (iring == 0 ? 'I' : 'O');
182 TObjArray* ringArray = new TObjArray();
183 ringArray->SetName(Form("FMD_%c",ringChar));
184 primaryArray->AddAtAndExpand(ringArray,iring);
185 for(Int_t v=0; v<nvtxbins;v++) {
186
187 TH2F* hPrimary = (TH2F*)infile->Get(Form("hPrimary_FMD_%c_vtx%d",ringChar,v));
188 ringArray->AddAtAndExpand(hPrimary,v);
189 }
190 }
191
192
193 }
194 else {
195 hitArray = input.GetHits();
196 primaryArray = input.GetPrimaries();
197 }
df0d5480 198 fCorrectionArray.SetName("FMD_bg_correction");
199 fCorrectionArray.SetOwner();
ca3af5d9 200
201 TList* primaryList = new TList();
26c8b5ff 202 primaryList->SetName("primaries");
ca3af5d9 203
26c8b5ff 204 TList* hitList = new TList();
205 hitList->SetName("hits");
206 TList* corrList = new TList();
207 corrList->SetName("corrections");
109e97cd 208
b82e76e0 209 AliFMDAnaCalibBackgroundCorrection* background = new AliFMDAnaCalibBackgroundCorrection();
210
df0d5480 211 for(Int_t det= 1; det <=3; det++) {
212 Int_t nRings = (det==1 ? 1 : 2);
213
214 TObjArray* detArrayCorrection = new TObjArray();
215 detArrayCorrection->SetName(Form("FMD%d",det));
216 fCorrectionArray.AddAtAndExpand(detArrayCorrection,det);
217
218
219 for(Int_t iring = 0; iring<nRings; iring++) {
220 TObjArray* primRingArray = (TObjArray*)primaryArray->At(iring);
221 Char_t ringChar = (iring == 0 ? 'I' : 'O');
222 TObjArray* vtxArrayCorrection = new TObjArray();
223 vtxArrayCorrection->SetName(Form("FMD%d%c",det,ringChar));
224 detArrayCorrection->AddAtAndExpand(vtxArrayCorrection,iring);
225
226 for(Int_t vertexBin=0;vertexBin<nvtxbins;vertexBin++) {
227 TObjArray* detArray = (TObjArray*)hitArray->At(det);
228 TObjArray* vtxArray = (TObjArray*)detArray->At(iring);
229 TH2F* hHits = (TH2F*)vtxArray->At(vertexBin);
26c8b5ff 230 hitList->Add(hHits);
df0d5480 231 TH2F* hPrimary = (TH2F*)primRingArray->At(vertexBin);
26c8b5ff 232 primaryList->Add(hPrimary);
df0d5480 233 TH2F* hCorrection = (TH2F*)hHits->Clone(Form("FMD%d%c_vtxbin_%d_correction",det,ringChar,vertexBin));
ca3af5d9 234 hCorrection->Divide(hPrimary);
26c8b5ff 235 corrList->Add(hCorrection);
8dc823cc 236 hCorrection->SetTitle(hCorrection->GetName());
df0d5480 237 vtxArrayCorrection->AddAtAndExpand(hCorrection,vertexBin);
b82e76e0 238 background->SetBgCorrection(det,ringChar,vertexBin,hCorrection);
df0d5480 239 }
240
241 }
242 }
243
244 TAxis refAxis(nvtxbins,-1*zvtxcut,zvtxcut);
109e97cd 245 if(inFile) {
246 TFile* infile = TFile::Open(infilename);
247 TAxis* refaxis = (TAxis*)infile->Get("vertexbins");
248 background->SetRefAxis(refaxis);
249
250 }
251 else background->SetRefAxis(&refAxis);
df0d5480 252
8dc823cc 253 TFile* fout = new TFile(filename,"RECREATE");
df0d5480 254 refAxis.Write("vertexbins");
26c8b5ff 255
256 hitList->Write();
257 primaryList->Write();
258 corrList->Write();
ca3af5d9 259
8dc823cc 260 TObjArray* container = new TObjArray();
261 container->SetOwner();
262 container->AddAtAndExpand(&refAxis,0);
263 container->AddAtAndExpand(&fCorrectionArray,1);
264 container->AddAtAndExpand(hitArray,2);
265 container->AddAtAndExpand(primaryArray,3);
b82e76e0 266
267
df0d5480 268 if(storeInAlien) {
269 AliCDBManager* cdb = AliCDBManager::Instance();
270 cdb->SetDefaultStorage("local://$ALICE_ROOT");
8dc823cc 271 AliCDBId id(AliFMDAnaParameters::GetBackgroundPath(),runNo,endRunNo);
df0d5480 272
273 AliCDBMetaData* meta = new AliCDBMetaData;
274 meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data());
275 meta->SetAliRootVersion(gROOT->GetVersion());
276 meta->SetBeamPeriod(1);
277 meta->SetComment("Background Correction for FMD");
b82e76e0 278 meta->SetProperty("key1", background );
279 cdb->Put(background, id, meta);
df0d5480 280
281 }
282
8dc823cc 283 fout->Close();
284
df0d5480 285
ca3af5d9 286 }
287
df0d5480 288//_____________________________________________________________________
289void AliFMDBackgroundCorrection::Simulate(Int_t nEvents) {
290
291 AliSimulation sim ;
292 sim.SetRunNumber(0);
293 TGrid::Connect("alien:",0,0,"t");
294 sim.SetDefaultStorage("alien://Folder=/alice/data/2008/LHC08d/OCDB/");
295 sim.SetConfigFile("Config.C");
296 sim.SetRunQA("FMD:");
297 TStopwatch timer;
298 timer.Start();
299 sim.RunSimulation(nEvents);
300 timer.Stop();
301 timer.Print();
302
303}
304
305//_____________________________________________________________________
faf80567 306Bool_t
307AliFMDBackgroundCorrection::AliFMDInputBG::ProcessHit(AliFMDHit* h,
308 TParticle* /*p*/)
309{
df0d5480 310
08d168d9 311 if(!h)
312 return kTRUE;
faf80567 313 Bool_t retval = ProcessEvent(h->Detector(),
314 h->Ring(),
315 h->Sector()
316 ,h->Strip(),
317 h->Track(),
318 h->Q());
08d168d9 319
320 return retval;
321}
322//_____________________________________________________________________
faf80567 323Bool_t
324AliFMDBackgroundCorrection::AliFMDInputBG::ProcessTrackRef(AliTrackReference* tr,
325 TParticle* p)
326{
08d168d9 327 if(!tr)
328 return kTRUE;
329 UShort_t det,sec,strip;
330 Char_t ring;
331 AliFMDStripIndex::Unpack(tr->UserId(),det,ring,sec,strip);
faf80567 332 Int_t nTrack = tr->GetTrack();
333 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
08d168d9 334 TParticlePDG* pdgPart = pdgDB->GetParticle(p->GetPdgCode());
faf80567 335 Float_t charge = (pdgPart ? pdgPart->Charge() : 0);
336 Bool_t retval = ProcessEvent(det,ring,sec,strip,nTrack,charge);
08d168d9 337 return retval;
338
339}
340//_____________________________________________________________________
faf80567 341Bool_t
342AliFMDBackgroundCorrection::AliFMDInputBG::ProcessEvent(UShort_t det,
343 Char_t ring,
344 UShort_t sec,
345 UShort_t strip,
346 Int_t nTrack,
347 Float_t charge)
08d168d9 348{
349
df0d5480 350 AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
351 TArrayF vertex;
352 genHeader->PrimaryVertex(vertex);
353
354 if(TMath::Abs(vertex.At(2)) > fZvtxCut)
355 return kTRUE;
356
faf80567 357 Double_t delta = 2 * fZvtxCut / fNvtxBins;
df0d5480 358 Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
faf80567 359 Int_t vertexBin = Int_t(vertexBinDouble);
df0d5480 360
faf80567 361 if(charge != 0 &&
362 (nTrack != fPrevTrack ||
363 det != fPrevDetector ||
364 ring != fPrevRing)) {
08d168d9 365 Double_t x,y,z;
366 AliFMDGeometry* fmdgeo = AliFMDGeometry::Instance();
367 fmdgeo->Detector2XYZ(det,ring,sec,strip,x,y,z);
368
369 Int_t iring = (ring == 'I' ? 0 : 1);
370
371 TObjArray* detArray = (TObjArray*)fHitArray.At(det);
372 TObjArray* vtxArray = (TObjArray*)detArray->At(iring);
373 TH2F* hHits = (TH2F*)vtxArray->At(vertexBin);
374
faf80567 375 Float_t phi = TMath::ATan2(y,x);
376 if(phi<0) phi = phi+2*TMath::Pi();
377 Float_t r = TMath::Sqrt(TMath::Power(x,2)+TMath::Power(y,2));
378 Float_t theta = TMath::ATan2(r,z+vertex.At(2));
379 Float_t eta = -1*TMath::Log(TMath::Tan(0.5*theta));
08d168d9 380 hHits->Fill(eta,phi);
381 fHits++;
382 fPrevDetector = det;
383 fPrevRing = ring;
384 }
ca3af5d9 385
08d168d9 386 fPrevTrack = nTrack;
df0d5480 387 return kTRUE;
08d168d9 388
df0d5480 389}
390
391//_____________________________________________________________________
faf80567 392Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Init()
393{
df0d5480 394 fPrimaryArray.SetOwner();
395 fPrimaryArray.SetName("FMD_primary");
396
397 for(Int_t iring = 0; iring<2;iring++) {
398 Char_t ringChar = (iring == 0 ? 'I' : 'O');
399 TObjArray* ringArray = new TObjArray();
400 ringArray->SetName(Form("FMD_%c",ringChar));
401 fPrimaryArray.AddAtAndExpand(ringArray,iring);
402 Int_t nSec = (iring == 1 ? 40 : 20);
403 for(Int_t v=0; v<fNvtxBins;v++) {
404
405 TH2F* hPrimary = new TH2F(Form("hPrimary_FMD_%c_vtx%d",ringChar,v),
406 Form("hPrimary_FMD_%c_vtx%d",ringChar,v),
407 fNbinsEta, -6,6, nSec, 0,2*TMath::Pi());
b82e76e0 408 hPrimary->Sumw2();
df0d5480 409 ringArray->AddAtAndExpand(hPrimary,v);
410 }
411 }
412
413
414 fHitArray.SetOwner();
415 fHitArray.SetName("FMD_hits");
416
faf80567 417 for(Int_t det =1; det<=3;det++) {
418 TObjArray* detArrayHits = new TObjArray();
419 detArrayHits->SetName(Form("FMD%d",det));
420 fHitArray.AddAtAndExpand(detArrayHits,det);
421 Int_t nRings = (det==1 ? 1 : 2);
422 for(Int_t ring = 0;ring<nRings;ring++) {
423 Int_t nSec = (ring == 1 ? 40 : 20);
424 Char_t ringChar = (ring == 0 ? 'I' : 'O');
425 TObjArray* vtxArrayHits = new TObjArray();
426 vtxArrayHits->SetName(Form("FMD%d%c",det,ringChar));
427 detArrayHits->AddAtAndExpand(vtxArrayHits,ring);
428 for(Int_t v=0; v<fNvtxBins;v++) {
429 TH2F* hHits = new TH2F(Form("hHits_FMD%d%c_vtx%d", det,ringChar,v),
430 Form("hHits_FMD%d%c_vtx%d", det,ringChar,v),
431 fNbinsEta, -6,6, nSec, 0, 2*TMath::Pi());
432 hHits->Sumw2();
433 vtxArrayHits->AddAtAndExpand(hHits,v);
434
435 }
df0d5480 436 }
faf80567 437 }
df0d5480 438
df0d5480 439 AliFMDInput::Init();
440
df0d5480 441 return kTRUE;
442}
ca3af5d9 443//_____________________________________________________________________
444
faf80567 445Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Begin(Int_t event )
446{
df0d5480 447
faf80567 448 Bool_t retVal = AliFMDInput::Begin(event);
449 AliStack* partStack = fLoader->Stack();
450 Int_t nTracks = partStack->GetNtrack();
ca3af5d9 451 AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
452 TArrayF vertex;
453 genHeader->PrimaryVertex(vertex);
454
455 if(TMath::Abs(vertex.At(2)) > fZvtxCut)
456 return kTRUE;
457
faf80567 458 Double_t delta = 2*fZvtxCut/fNvtxBins;
ca3af5d9 459 Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
faf80567 460 Int_t vertexBin = (Int_t)vertexBinDouble;
461
462 for(Int_t j=0;j<nTracks;j++) {
463 TParticle* p = partStack->Particle(j);
464 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
465 TParticlePDG* pdgPart = pdgDB->GetParticle(p->GetPdgCode());
466 Float_t charge = (pdgPart ? pdgPart->Charge() : 0);
467 Float_t phi = TMath::ATan2(p->Py(),p->Px());
468
469 if(phi<0) phi = phi+2*TMath::Pi();
470 if(p->Theta() == 0) continue;
471 Float_t eta = -1*TMath::Log(TMath::Tan(0.5*p->Theta()));
472
473 Bool_t primary = partStack->IsPhysicalPrimary(j);
474 //(charge!=0)&&(TMath::Abs(p->Vx() - vertex.At(0))<0.01)&&(TMath::Abs(p->Vy() - vertex.At(1))<0.01)&&(TMath::Abs(p->Vz() - vertex.At(2))<0.01);
475 if(primary && charge !=0) {
476
477 fPrim++;
478 TObjArray* innerArray = (TObjArray*)fPrimaryArray.At(0);
479 TObjArray* outerArray = (TObjArray*)fPrimaryArray.At(1);
480
481 TH2F* hPrimaryInner = (TH2F*)innerArray->At(vertexBin);
482 TH2F* hPrimaryOuter = (TH2F*)outerArray->At(vertexBin);
483 hPrimaryInner->Fill(eta,phi);
484 hPrimaryOuter->Fill(eta,phi);
485 }
486 }
109e97cd 487
ca3af5d9 488 return retVal;
489}
490//_____________________________________________________________________
491//
492// EOF
493//
df0d5480 494
495