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"
59 ClassImp(AliFMDBackgroundCorrection)
60 //_____________________________________________________________________
61 AliFMDBackgroundCorrection::AliFMDBackgroundCorrection() :
66 //_____________________________________________________________________
67 AliFMDBackgroundCorrection::AliFMDInputBG::AliFMDInputBG() :
86 //_____________________________________________________________________
88 void AliFMDBackgroundCorrection::GenerateBackgroundCorrection(Int_t nvtxbins,
94 const Char_t* filename,
98 TGrid::Connect("alien:",0,0,"t");
102 AliCDBManager::Instance()->SetDefaultStorage("alien://Folder=/alice/data/2008/LHC08d/OCDB/");
103 AliCDBManager::Instance()->SetRun(runNo);
105 #if defined(__CINT__)
106 gSystem->Load("liblhapdf");
107 gSystem->Load("libEGPythia6");
108 gSystem->Load("libpythia6");
109 gSystem->Load("libAliPythia6");
110 gSystem->Load("libgeant321");
114 //Setting up the geometry
115 //-----------------------------------------------
116 if (AliGeomManager::GetGeometry() == NULL)
117 AliGeomManager::LoadGeometry();
119 AliFMDGeometry* geo = AliFMDGeometry::Instance();
121 geo->InitTransformations();
125 AliInfo("Processing hits and primaries ");
128 input.SetVtxCutZ(zvtxcut);
129 input.SetNvtxBins(nvtxbins);
130 input.SetNbinsEta(nBinsEta);
133 AliInfo(Form("Found %d primaries and %d hits.", input.GetNprim(),input.GetNhits()));
135 TObjArray* hitArray = input.GetHits();
136 TObjArray* primaryArray = input.GetPrimaries();
137 fCorrectionArray.SetName("FMD_bg_correction");
138 fCorrectionArray.SetOwner();
140 TList* primaryList = new TList();
141 primaryList->SetName("primaries");
142 TList* hitList = new TList();
143 hitList->SetName("hits");
144 TList* corrList = new TList();
145 corrList->SetName("corrections");
147 AliFMDAnaCalibBackgroundCorrection* background = new AliFMDAnaCalibBackgroundCorrection();
149 for(Int_t det= 1; det <=3; det++) {
150 Int_t nRings = (det==1 ? 1 : 2);
152 TObjArray* detArrayCorrection = new TObjArray();
153 detArrayCorrection->SetName(Form("FMD%d",det));
154 fCorrectionArray.AddAtAndExpand(detArrayCorrection,det);
157 for(Int_t iring = 0; iring<nRings; iring++) {
158 TObjArray* primRingArray = (TObjArray*)primaryArray->At(iring);
159 Char_t ringChar = (iring == 0 ? 'I' : 'O');
160 TObjArray* vtxArrayCorrection = new TObjArray();
161 vtxArrayCorrection->SetName(Form("FMD%d%c",det,ringChar));
162 detArrayCorrection->AddAtAndExpand(vtxArrayCorrection,iring);
164 for(Int_t vertexBin=0;vertexBin<nvtxbins;vertexBin++) {
165 TObjArray* detArray = (TObjArray*)hitArray->At(det);
166 TObjArray* vtxArray = (TObjArray*)detArray->At(iring);
167 TH2F* hHits = (TH2F*)vtxArray->At(vertexBin);
169 TH2F* hPrimary = (TH2F*)primRingArray->At(vertexBin);
170 primaryList->Add(hPrimary);
171 TH2F* hCorrection = (TH2F*)hHits->Clone(Form("FMD%d%c_vtxbin_%d_correction",det,ringChar,vertexBin));
172 corrList->Add(hCorrection);
173 hCorrection->SetTitle(hCorrection->GetName());
174 hCorrection->Divide(hPrimary);
175 vtxArrayCorrection->AddAtAndExpand(hCorrection,vertexBin);
176 background->SetBgCorrection(det,ringChar,vertexBin,hCorrection);
182 TAxis refAxis(nvtxbins,-1*zvtxcut,zvtxcut);
184 background->SetRefAxis(&refAxis);
186 TFile* fout = new TFile(filename,"RECREATE");
187 refAxis.Write("vertexbins");
190 primaryList->Write();
192 //fout->mkdir("Hits");
195 //fout->mkdir("Primaries");
196 //fout->cd("Primaries");
197 //primaryArray->Write();
198 //fout->mkdir("Correction");
199 //fout->cd("Correction");
200 //fCorrectionArray.Write();
202 TObjArray* container = new TObjArray();
203 container->SetOwner();
204 container->AddAtAndExpand(&refAxis,0);
205 container->AddAtAndExpand(&fCorrectionArray,1);
206 container->AddAtAndExpand(hitArray,2);
207 container->AddAtAndExpand(primaryArray,3);
211 AliCDBManager* cdb = AliCDBManager::Instance();
212 cdb->SetDefaultStorage("local://$ALICE_ROOT");
213 AliCDBId id(AliFMDAnaParameters::GetBackgroundPath(),runNo,endRunNo);
215 AliCDBMetaData* meta = new AliCDBMetaData;
216 meta->SetResponsible(gSystem->GetUserInfo()->fRealName.Data());
217 meta->SetAliRootVersion(gROOT->GetVersion());
218 meta->SetBeamPeriod(1);
219 meta->SetComment("Background Correction for FMD");
220 meta->SetProperty("key1", background );
221 cdb->Put(background, id, meta);
229 //_____________________________________________________________________
230 void AliFMDBackgroundCorrection::Simulate(Int_t nEvents) {
234 TGrid::Connect("alien:",0,0,"t");
235 sim.SetDefaultStorage("alien://Folder=/alice/data/2008/LHC08d/OCDB/");
236 sim.SetConfigFile("Config.C");
237 sim.SetRunQA("FMD:");
240 sim.RunSimulation(nEvents);
246 //_____________________________________________________________________
247 Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::ProcessTrack(Int_t i , TParticle* p, AliFMDHit* h) {
249 AliGenEventHeader* genHeader = fLoader->GetHeader()->GenEventHeader();
251 genHeader->PrimaryVertex(vertex);
253 if(TMath::Abs(vertex.At(2)) > fZvtxCut)
256 Double_t delta = 2*fZvtxCut/fNvtxBins;
257 Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
258 Int_t vertexBin = (Int_t)vertexBinDouble;
261 if(h->Q() != 0 && (i != fPrevTrack || h->Detector() != fPrevDetector || h->Ring() != fPrevRing)) {
263 Int_t det = h->Detector();
264 Char_t ring = h->Ring();
265 // if(h->Detector() == 3)
266 // std::cout<<"Detected a hit in " <<"FMD"<<det<<ring<<" ! "<<std::endl;
268 Int_t iring = (ring == 'I' ? 0 : 1);
270 TObjArray* detArray = (TObjArray*)fHitArray.At(det);
271 TObjArray* vtxArray = (TObjArray*)detArray->At(iring);
272 TH2F* hHits = (TH2F*)vtxArray->At(vertexBin);
274 Float_t phi = TMath::ATan2(h->Py(),h->Px());
276 phi = phi+2*TMath::Pi();
277 Float_t theta = TMath::ATan2(TMath::Sqrt(TMath::Power(h->X(),2)+TMath::Power(h->Y(),2)),h->Z()+vertex.At(2));
278 Float_t eta = -1*TMath::Log(TMath::Tan(0.5*theta));
279 hHits->Fill(eta,phi);
285 if(p && i != fPrevTrack) {
287 TDatabasePDG* pdgDB = TDatabasePDG::Instance();
288 TParticlePDG* pdgPart = pdgDB->GetParticle(p->GetPdgCode());
289 Float_t charge = (pdgPart ? pdgPart->Charge() : 0);
290 Float_t phi = TMath::ATan2(p->Py(),p->Px());
293 phi = phi+2*TMath::Pi();
296 Bool_t primary = (charge!=0)&&(TMath::Abs(p->Vx() - vertex.At(0))<0.1)&&(TMath::Abs(p->Vy() - vertex.At(1))<0.1)&&(TMath::Abs(p->Vz() - vertex.At(2))<0.1);
299 TObjArray* innerArray = (TObjArray*)fPrimaryArray.At(0);
300 TObjArray* outerArray = (TObjArray*)fPrimaryArray.At(1);
302 TH2F* hPrimaryInner = (TH2F*)innerArray->At(vertexBin);
303 TH2F* hPrimaryOuter = (TH2F*)outerArray->At(vertexBin);
304 hPrimaryInner->Fill(p->Eta(),phi);
305 hPrimaryOuter->Fill(p->Eta(),phi);
314 //_____________________________________________________________________
315 Bool_t AliFMDBackgroundCorrection::AliFMDInputBG::Init() {
317 fPrimaryArray.SetOwner();
318 fPrimaryArray.SetName("FMD_primary");
320 for(Int_t iring = 0; iring<2;iring++) {
321 Char_t ringChar = (iring == 0 ? 'I' : 'O');
322 TObjArray* ringArray = new TObjArray();
323 ringArray->SetName(Form("FMD_%c",ringChar));
324 fPrimaryArray.AddAtAndExpand(ringArray,iring);
325 Int_t nSec = (iring == 1 ? 40 : 20);
326 for(Int_t v=0; v<fNvtxBins;v++) {
328 TH2F* hPrimary = new TH2F(Form("hPrimary_FMD_%c_vtx%d",ringChar,v),
329 Form("hPrimary_FMD_%c_vtx%d",ringChar,v),
330 fNbinsEta, -6,6, nSec, 0,2*TMath::Pi());
332 ringArray->AddAtAndExpand(hPrimary,v);
337 fHitArray.SetOwner();
338 fHitArray.SetName("FMD_hits");
340 for(Int_t det =1; det<=3;det++)
342 TObjArray* detArrayHits = new TObjArray();
343 detArrayHits->SetName(Form("FMD%d",det));
344 fHitArray.AddAtAndExpand(detArrayHits,det);
345 Int_t nRings = (det==1 ? 1 : 2);
346 for(Int_t ring = 0;ring<nRings;ring++)
348 Int_t nSec = (ring == 1 ? 40 : 20);
349 Char_t ringChar = (ring == 0 ? 'I' : 'O');
350 TObjArray* vtxArrayHits = new TObjArray();
351 vtxArrayHits->SetName(Form("FMD%d%c",det,ringChar));
352 detArrayHits->AddAtAndExpand(vtxArrayHits,ring);
353 for(Int_t v=0; v<fNvtxBins;v++)
356 TH2F* hHits = new TH2F(Form("hHits_FMD%d%c_vtx%d",det,ringChar,v),
357 Form("hHits_FMD%d%c_vtx%d",det,ringChar,v),
358 fNbinsEta, -6,6, nSec, 0, 2*TMath::Pi());
360 vtxArrayHits->AddAtAndExpand(hHits,v);