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) :
71 AliFMDInput("galice.root"),
93 //_____________________________________________________________________
95 void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(Bool_t from_hits,
102 const Char_t* filename,
106 const Char_t* infilename) {
108 //TGrid::Connect("alien:",0,0,"t");
112 //AliCDBManager::Instance()->SetDefaultStorage("alien://Folder=/alice/data/2008/LHC08d/OCDB/");
113 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT");
114 AliCDBManager::Instance()->SetRun(runNo);
116 #if defined(__CINT__)
117 gSystem->Load("liblhapdf");
118 gSystem->Load("libEGPythia6");
119 gSystem->Load("libpythia6");
120 gSystem->Load("libAliPythia6");
121 gSystem->Load("libgeant321");
126 //Setting up the geometry
127 //-----------------------------------------------
128 if (AliGeomManager::GetGeometry() == NULL)
129 AliGeomManager::LoadGeometry();
131 AliFMDGeometry* geo = AliFMDGeometry::Instance();
133 geo->InitTransformations();
135 AliInfo("Processing hits and primaries ");
137 AliFMDInputBG input(from_hits);
141 input.SetVtxCutZ(zvtxcut);
142 input.SetNvtxBins(nvtxbins);
143 input.SetNbinsEta(nBinsEta);
147 AliInfo(Form("Found %d primaries and %d hits.", input.GetNprim(),input.GetNhits()));
148 TObjArray* hitArray ;
149 TObjArray* primaryArray;
151 TFile* infile = TFile::Open(infilename);
152 hitArray = new TObjArray();
153 primaryArray = new TObjArray();
155 for(Int_t det =1; det<=3;det++)
157 TObjArray* detArrayHits = new TObjArray();
158 detArrayHits->SetName(Form("FMD%d",det));
159 hitArray->AddAtAndExpand(detArrayHits,det);
160 Int_t nRings = (det==1 ? 1 : 2);
161 for(Int_t ring = 0;ring<nRings;ring++)
164 Char_t ringChar = (ring == 0 ? 'I' : 'O');
165 TObjArray* vtxArrayHits = new TObjArray();
166 vtxArrayHits->SetName(Form("FMD%d%c",det,ringChar));
167 detArrayHits->AddAtAndExpand(vtxArrayHits,ring);
168 for(Int_t v=0; v<nvtxbins;v++)
171 TH2F* hHits = (TH2F*)infile->Get(Form("hHits_FMD%d%c_vtx%d",det,ringChar,v));
174 vtxArrayHits->AddAtAndExpand(hHits,v);
181 for(Int_t iring = 0; iring<2;iring++) {
182 Char_t ringChar = (iring == 0 ? 'I' : 'O');
183 TObjArray* ringArray = new TObjArray();
184 ringArray->SetName(Form("FMD_%c",ringChar));
185 primaryArray->AddAtAndExpand(ringArray,iring);
186 for(Int_t v=0; v<nvtxbins;v++) {
188 TH2F* hPrimary = (TH2F*)infile->Get(Form("hPrimary_FMD_%c_vtx%d",ringChar,v));
189 ringArray->AddAtAndExpand(hPrimary,v);
196 hitArray = input.GetHits();
197 primaryArray = input.GetPrimaries();
199 fCorrectionArray.SetName("FMD_bg_correction");
200 fCorrectionArray.SetOwner();
202 TList* primaryList = new TList();
203 primaryList->SetName("primaries");
205 TList* hitList = new TList();
206 hitList->SetName("hits");
207 TList* corrList = new TList();
208 corrList->SetName("corrections");
210 AliFMDAnaCalibBackgroundCorrection* background = new AliFMDAnaCalibBackgroundCorrection();
212 for(Int_t det= 1; det <=3; det++) {
213 Int_t nRings = (det==1 ? 1 : 2);
215 TObjArray* detArrayCorrection = new TObjArray();
216 detArrayCorrection->SetName(Form("FMD%d",det));
217 fCorrectionArray.AddAtAndExpand(detArrayCorrection,det);
220 for(Int_t iring = 0; iring<nRings; iring++) {
221 TObjArray* primRingArray = (TObjArray*)primaryArray->At(iring);
222 Char_t ringChar = (iring == 0 ? 'I' : 'O');
223 TObjArray* vtxArrayCorrection = new TObjArray();
224 vtxArrayCorrection->SetName(Form("FMD%d%c",det,ringChar));
225 detArrayCorrection->AddAtAndExpand(vtxArrayCorrection,iring);
227 for(Int_t vertexBin=0;vertexBin<nvtxbins;vertexBin++) {
228 TObjArray* detArray = (TObjArray*)hitArray->At(det);
229 TObjArray* vtxArray = (TObjArray*)detArray->At(iring);
230 TH2F* hHits = (TH2F*)vtxArray->At(vertexBin);
232 TH2F* hPrimary = (TH2F*)primRingArray->At(vertexBin);
233 primaryList->Add(hPrimary);
234 TH2F* hCorrection = (TH2F*)hHits->Clone(Form("FMD%d%c_vtxbin_%d_correction",det,ringChar,vertexBin));
235 hCorrection->Divide(hPrimary);
236 corrList->Add(hCorrection);
237 hCorrection->SetTitle(hCorrection->GetName());
238 vtxArrayCorrection->AddAtAndExpand(hCorrection,vertexBin);
239 background->SetBgCorrection(det,ringChar,vertexBin,hCorrection);
245 TAxis refAxis(nvtxbins,-1*zvtxcut,zvtxcut);
247 TFile* infile = TFile::Open(infilename);
248 TAxis* refaxis = (TAxis*)infile->Get("vertexbins");
249 background->SetRefAxis(refaxis);
252 else background->SetRefAxis(&refAxis);
254 TFile* fout = new TFile(filename,"RECREATE");
255 refAxis.Write("vertexbins");
258 primaryList->Write();
261 TObjArray* container = new TObjArray();
262 container->SetOwner();
263 container->AddAtAndExpand(&refAxis,0);
264 container->AddAtAndExpand(&fCorrectionArray,1);
265 container->AddAtAndExpand(hitArray,2);
266 container->AddAtAndExpand(primaryArray,3);
270 AliCDBManager* cdb = AliCDBManager::Instance();
271 cdb->SetDefaultStorage("local://$ALICE_ROOT");
272 AliCDBId id(AliFMDAnaParameters::GetBackgroundPath(),runNo,endRunNo);
274 AliCDBMetaData* meta = new AliCDBMetaData;
275 meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data());
276 meta->SetAliRootVersion(gROOT->GetVersion());
277 meta->SetBeamPeriod(1);
278 meta->SetComment("Background Correction for FMD");
279 meta->SetProperty("key1", background );
280 cdb->Put(background, id, meta);
289 //_____________________________________________________________________
290 void AliFMDBackgroundCorrection::Simulate(Int_t nEvents) {
294 TGrid::Connect("alien:",0,0,"t");
295 sim.SetDefaultStorage("alien://Folder=/alice/data/2008/LHC08d/OCDB/");
296 sim.SetConfigFile("Config.C");
297 sim.SetRunQA("FMD:");
300 sim.RunSimulation(nEvents);
306 //_____________________________________________________________________
308 AliFMDBackgroundCorrection::AliFMDInputBG::ProcessHit(AliFMDHit* h,
314 Bool_t retval = ProcessEvent(h->Detector(),
323 //_____________________________________________________________________
325 AliFMDBackgroundCorrection::AliFMDInputBG::ProcessTrackRef(AliTrackReference* tr,
330 UShort_t det,sec,strip;
332 AliFMDStripIndex::Unpack(tr->UserId(),det,ring,sec,strip);
333 Int_t nTrack = tr->GetTrack();
334 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
335 TParticlePDG* pdgPart = pdgDB->GetParticle(p->GetPdgCode());
336 Float_t charge = (pdgPart ? pdgPart->Charge() : 0);
337 Bool_t retval = ProcessEvent(det,ring,sec,strip,nTrack,charge);
341 //_____________________________________________________________________
343 AliFMDBackgroundCorrection::AliFMDInputBG::ProcessEvent(UShort_t det,
351 AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
353 genHeader->PrimaryVertex(vertex);
355 if(TMath::Abs(vertex.At(2)) > fZvtxCut)
358 Double_t delta = 2 * fZvtxCut / fNvtxBins;
359 Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
360 Int_t vertexBin = Int_t(vertexBinDouble);
363 (nTrack != fPrevTrack ||
364 det != fPrevDetector ||
365 ring != fPrevRing) ||
368 AliFMDGeometry* fmdgeo = AliFMDGeometry::Instance();
369 fmdgeo->Detector2XYZ(det,ring,sec,strip,x,y,z);
371 Int_t iring = (ring == 'I' ? 0 : 1);
373 TObjArray* detArray = (TObjArray*)fHitArray.At(det);
374 TObjArray* vtxArray = (TObjArray*)detArray->At(iring);
375 TH2F* hHits = (TH2F*)vtxArray->At(vertexBin);
377 Float_t phi = TMath::ATan2(y,x);
378 if(phi<0) phi = phi+2*TMath::Pi();
379 Float_t r = TMath::Sqrt(TMath::Power(x,2)+TMath::Power(y,2));
380 Float_t theta = TMath::ATan2(r,z-vertex.At(2));
381 Float_t eta = -1*TMath::Log(TMath::Tan(0.5*theta));
382 hHits->Fill(eta,phi);
396 //_____________________________________________________________________
397 Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Init()
399 fPrimaryArray.SetOwner();
400 fPrimaryArray.SetName("FMD_primary");
402 for(Int_t iring = 0; iring<2;iring++) {
403 Char_t ringChar = (iring == 0 ? 'I' : 'O');
404 TObjArray* ringArray = new TObjArray();
405 ringArray->SetName(Form("FMD_%c",ringChar));
406 fPrimaryArray.AddAtAndExpand(ringArray,iring);
407 Int_t nSec = (iring == 1 ? 40 : 20);
408 for(Int_t v=0; v<fNvtxBins;v++) {
410 TH2F* hPrimary = new TH2F(Form("hPrimary_FMD_%c_vtx%d",ringChar,v),
411 Form("hPrimary_FMD_%c_vtx%d",ringChar,v),
412 fNbinsEta, -6,6, nSec, 0,2*TMath::Pi());
414 ringArray->AddAtAndExpand(hPrimary,v);
419 fHitArray.SetOwner();
420 fHitArray.SetName("FMD_hits");
422 for(Int_t det =1; det<=3;det++) {
423 TObjArray* detArrayHits = new TObjArray();
424 detArrayHits->SetName(Form("FMD%d",det));
425 fHitArray.AddAtAndExpand(detArrayHits,det);
426 Int_t nRings = (det==1 ? 1 : 2);
427 for(Int_t ring = 0;ring<nRings;ring++) {
428 Int_t nSec = (ring == 1 ? 40 : 20);
429 Char_t ringChar = (ring == 0 ? 'I' : 'O');
430 TObjArray* vtxArrayHits = new TObjArray();
431 vtxArrayHits->SetName(Form("FMD%d%c",det,ringChar));
432 detArrayHits->AddAtAndExpand(vtxArrayHits,ring);
433 for(Int_t v=0; v<fNvtxBins;v++) {
434 TH2F* hHits = new TH2F(Form("hHits_FMD%d%c_vtx%d", det,ringChar,v),
435 Form("hHits_FMD%d%c_vtx%d", det,ringChar,v),
436 fNbinsEta, -6,6, nSec, 0, 2*TMath::Pi());
438 vtxArrayHits->AddAtAndExpand(hHits,v);
448 //_____________________________________________________________________
450 Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Begin(Int_t event )
453 Bool_t retVal = AliFMDInput::Begin(event);
454 AliStack* partStack = fLoader->Stack();
455 Int_t nTracks = partStack->GetNtrack();
456 AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
458 genHeader->PrimaryVertex(vertex);
460 if(TMath::Abs(vertex.At(2)) > fZvtxCut)
463 Double_t delta = 2*fZvtxCut/fNvtxBins;
464 Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
465 Int_t vertexBin = (Int_t)vertexBinDouble;
467 for(Int_t j=0;j<nTracks;j++) {
468 TParticle* p = partStack->Particle(j);
469 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
470 TParticlePDG* pdgPart = pdgDB->GetParticle(p->GetPdgCode());
471 Float_t charge = (pdgPart ? pdgPart->Charge() : 0);
472 Float_t phi = TMath::ATan2(p->Py(),p->Px());
474 if(phi<0) phi = phi+2*TMath::Pi();
475 if(p->Theta() == 0) continue;
476 Float_t eta = -1*TMath::Log(TMath::Tan(0.5*p->Theta()));
478 Bool_t primary = partStack->IsPhysicalPrimary(j);
479 //(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);
480 if(primary && charge !=0) {
483 TObjArray* innerArray = (TObjArray*)fPrimaryArray.At(0);
484 TObjArray* outerArray = (TObjArray*)fPrimaryArray.At(1);
486 TH2F* hPrimaryInner = (TH2F*)innerArray->At(vertexBin);
487 TH2F* hPrimaryOuter = (TH2F*)outerArray->At(vertexBin);
488 hPrimaryInner->Fill(eta,phi);
489 hPrimaryOuter->Fill(eta,phi);
495 //_____________________________________________________________________