1 /**************************************************************************
2 * Copyright(c) 2004, 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 // 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.
20 // Author: Hans Hjersing Dalsgaard, NBI, hans.dalsgaard@cern.ch
24 #include "AliSimulation.h"
25 #include "TStopwatch.h"
28 #include "AliRunLoader.h"
29 #include "AliGeomManager.h"
30 #include "AliFMDGeometry.h"
32 #include "TParticle.h"
33 #include "TDatabasePDG.h"
34 #include "TParticlePDG.h"
36 #include "AliFMDBackgroundCorrection.h"
38 #include "AliCDBManager.h"
40 #include "TClonesArray.h"
42 #include "AliFMDHit.h"
43 #include "AliLoader.h"
46 #include "AliGenEventHeader.h"
47 #include "AliHeader.h"
51 #include "AliCDBMetaData.h"
53 #include "AliFMDParameters.h"
56 #include "AliFMDAnaParameters.h"
57 #include "AliFMDAnaCalibBackgroundCorrection.h"
58 #include "AliTrackReference.h"
59 #include "AliFMDStripIndex.h"
61 ClassImp(AliFMDBackgroundCorrection)
62 //_____________________________________________________________________
63 AliFMDBackgroundCorrection::AliFMDBackgroundCorrection() :
69 //_____________________________________________________________________
70 AliFMDBackgroundCorrection::AliFMDInputBG::AliFMDInputBG(Bool_t hits_not_trackref) :
92 //_____________________________________________________________________
94 void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(Bool_t from_hits,
101 const Char_t* filename,
105 const Char_t* infilename) {
107 //TGrid::Connect("alien:",0,0,"t");
111 //AliCDBManager::Instance()->SetDefaultStorage("alien://Folder=/alice/data/2008/LHC08d/OCDB/");
112 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
113 AliCDBManager::Instance()->SetRun(runNo);
115 #if defined(__CINT__)
116 gSystem->Load("liblhapdf");
117 gSystem->Load("libEGPythia6");
118 gSystem->Load("libpythia6");
119 gSystem->Load("libAliPythia6");
120 gSystem->Load("libgeant321");
125 //Setting up the geometry
126 //-----------------------------------------------
127 if (AliGeomManager::GetGeometry() == NULL)
128 AliGeomManager::LoadGeometry();
130 AliFMDGeometry* geo = AliFMDGeometry::Instance();
132 geo->InitTransformations();
134 AliInfo("Processing hits and primaries ");
136 AliFMDInputBG input(from_hits);
140 input.SetVtxCutZ(zvtxcut);
141 input.SetNvtxBins(nvtxbins);
142 input.SetNbinsEta(nBinsEta);
146 AliInfo(Form("Found %d primaries and %d hits.", input.GetNprim(),input.GetNhits()));
147 TObjArray* hitArray ;
148 TObjArray* primaryArray;
150 TFile* infile = TFile::Open(infilename);
151 hitArray = new TObjArray();
152 primaryArray = new TObjArray();
154 for(Int_t det =1; det<=3;det++)
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++)
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++)
170 TH2F* hHits = (TH2F*)infile->Get(Form("hHits_FMD%d%c_vtx%d",det,ringChar,v));
173 vtxArrayHits->AddAtAndExpand(hHits,v);
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++) {
187 TH2F* hPrimary = (TH2F*)infile->Get(Form("hPrimary_FMD_%c_vtx%d",ringChar,v));
188 ringArray->AddAtAndExpand(hPrimary,v);
195 hitArray = input.GetHits();
196 primaryArray = input.GetPrimaries();
198 fCorrectionArray.SetName("FMD_bg_correction");
199 fCorrectionArray.SetOwner();
201 TList* primaryList = new TList();
202 primaryList->SetName("primaries");
204 TList* hitList = new TList();
205 hitList->SetName("hits");
206 TList* corrList = new TList();
207 corrList->SetName("corrections");
209 AliFMDAnaCalibBackgroundCorrection* background = new AliFMDAnaCalibBackgroundCorrection();
211 for(Int_t det= 1; det <=3; det++) {
212 Int_t nRings = (det==1 ? 1 : 2);
214 TObjArray* detArrayCorrection = new TObjArray();
215 detArrayCorrection->SetName(Form("FMD%d",det));
216 fCorrectionArray.AddAtAndExpand(detArrayCorrection,det);
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);
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);
231 TH2F* hPrimary = (TH2F*)primRingArray->At(vertexBin);
232 primaryList->Add(hPrimary);
233 TH2F* hCorrection = (TH2F*)hHits->Clone(Form("FMD%d%c_vtxbin_%d_correction",det,ringChar,vertexBin));
234 hCorrection->Divide(hPrimary);
235 corrList->Add(hCorrection);
236 hCorrection->SetTitle(hCorrection->GetName());
237 vtxArrayCorrection->AddAtAndExpand(hCorrection,vertexBin);
238 background->SetBgCorrection(det,ringChar,vertexBin,hCorrection);
244 TAxis refAxis(nvtxbins,-1*zvtxcut,zvtxcut);
246 TFile* infile = TFile::Open(infilename);
247 TAxis* refaxis = (TAxis*)infile->Get("vertexbins");
248 background->SetRefAxis(refaxis);
251 else background->SetRefAxis(&refAxis);
253 TFile* fout = new TFile(filename,"RECREATE");
254 refAxis.Write("vertexbins");
257 primaryList->Write();
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);
269 AliCDBManager* cdb = AliCDBManager::Instance();
270 cdb->SetDefaultStorage("local://$ALICE_ROOT");
271 AliCDBId id(AliFMDAnaParameters::GetBackgroundPath(),runNo,endRunNo);
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");
278 meta->SetProperty("key1", background );
279 cdb->Put(background, id, meta);
288 //_____________________________________________________________________
289 void AliFMDBackgroundCorrection::Simulate(Int_t nEvents) {
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:");
299 sim.RunSimulation(nEvents);
305 //_____________________________________________________________________
307 AliFMDBackgroundCorrection::AliFMDInputBG::ProcessHit(AliFMDHit* h,
313 Bool_t retval = ProcessEvent(h->Detector(),
322 //_____________________________________________________________________
324 AliFMDBackgroundCorrection::AliFMDInputBG::ProcessTrackRef(AliTrackReference* tr,
329 UShort_t det,sec,strip;
331 AliFMDStripIndex::Unpack(tr->UserId(),det,ring,sec,strip);
332 Int_t nTrack = tr->GetTrack();
333 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
334 TParticlePDG* pdgPart = pdgDB->GetParticle(p->GetPdgCode());
335 Float_t charge = (pdgPart ? pdgPart->Charge() : 0);
336 Bool_t retval = ProcessEvent(det,ring,sec,strip,nTrack,charge);
340 //_____________________________________________________________________
342 AliFMDBackgroundCorrection::AliFMDInputBG::ProcessEvent(UShort_t det,
350 AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
352 genHeader->PrimaryVertex(vertex);
354 if(TMath::Abs(vertex.At(2)) > fZvtxCut)
357 Double_t delta = 2 * fZvtxCut / fNvtxBins;
358 Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
359 Int_t vertexBin = Int_t(vertexBinDouble);
362 (nTrack != fPrevTrack ||
363 det != fPrevDetector ||
364 ring != fPrevRing)) {
366 AliFMDGeometry* fmdgeo = AliFMDGeometry::Instance();
367 fmdgeo->Detector2XYZ(det,ring,sec,strip,x,y,z);
369 Int_t iring = (ring == 'I' ? 0 : 1);
371 TObjArray* detArray = (TObjArray*)fHitArray.At(det);
372 TObjArray* vtxArray = (TObjArray*)detArray->At(iring);
373 TH2F* hHits = (TH2F*)vtxArray->At(vertexBin);
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));
380 hHits->Fill(eta,phi);
391 //_____________________________________________________________________
392 Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Init()
394 fPrimaryArray.SetOwner();
395 fPrimaryArray.SetName("FMD_primary");
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++) {
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());
409 ringArray->AddAtAndExpand(hPrimary,v);
414 fHitArray.SetOwner();
415 fHitArray.SetName("FMD_hits");
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());
433 vtxArrayHits->AddAtAndExpand(hHits,v);
443 //_____________________________________________________________________
445 Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Begin(Int_t event )
448 Bool_t retVal = AliFMDInput::Begin(event);
449 AliStack* partStack = fLoader->Stack();
450 Int_t nTracks = partStack->GetNtrack();
451 AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
453 genHeader->PrimaryVertex(vertex);
455 if(TMath::Abs(vertex.At(2)) > fZvtxCut)
458 Double_t delta = 2*fZvtxCut/fNvtxBins;
459 Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
460 Int_t vertexBin = (Int_t)vertexBinDouble;
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());
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()));
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) {
478 TObjArray* innerArray = (TObjArray*)fPrimaryArray.At(0);
479 TObjArray* outerArray = (TObjArray*)fPrimaryArray.At(1);
481 TH2F* hPrimaryInner = (TH2F*)innerArray->At(vertexBin);
482 TH2F* hPrimaryOuter = (TH2F*)outerArray->At(vertexBin);
483 hPrimaryInner->Fill(eta,phi);
484 hPrimaryOuter->Fill(eta,phi);
490 //_____________________________________________________________________