1 #include "AliFMDAnalysisTaskGenerateCorrection.h"
2 #include "AliESDEvent.h"
6 #include "AliTrackReference.h"
8 #include "AliFMDAnaParameters.h"
9 #include "AliFMDStripIndex.h"
11 #include "AliMCParticle.h"
12 #include "AliMCEvent.h"
13 //#include "AliFMDGeometry.h"
15 #include "AliGenEventHeader.h"
16 #include "AliMultiplicity.h"
17 #include "AliHeader.h"
18 #include "AliFMDAnaCalibBackgroundCorrection.h"
19 #include "AliFMDAnaCalibEventSelectionEfficiency.h"
20 //#include "AliCDBManager.h"
21 //#include "AliCDBId.h"
22 //#include "AliCDBMetaData.h"
26 ClassImp(AliFMDAnalysisTaskGenerateCorrection)
28 //_____________________________________________________________________
29 AliFMDAnalysisTaskGenerateCorrection::AliFMDAnalysisTaskGenerateCorrection():
43 // Default constructor
45 //_____________________________________________________________________
46 AliFMDAnalysisTaskGenerateCorrection::AliFMDAnalysisTaskGenerateCorrection(const char* name):
47 AliAnalysisTaskSE(name),
61 DefineOutput(1, TList::Class());
62 DefineOutput(2, TList::Class());
63 DefineOutput(3, TH1F::Class());
64 DefineOutput(4, TList::Class());
66 //_____________________________________________________________________
67 void AliFMDAnalysisTaskGenerateCorrection::UserCreateOutputObjects()
69 // Create the output containers
72 std::cout<<"Creating output objects"<<std::endl;
73 for(Int_t v=0; v<fNvtxBins;v++) {
75 TH2F* hSPDhits = new TH2F(Form("hSPDhits_vtx%d",v),
76 Form("hSPDhits_vtx%d",v),
77 fNbinsEta, -6,6, 20, 0,2*TMath::Pi());
79 fListOfHits.Add(hSPDhits);
81 for(Int_t iring = 0; iring<2;iring++) {
82 Char_t ringChar = (iring == 0 ? 'I' : 'O');
83 Int_t nSec = (iring == 1 ? 40 : 20);
85 TH2F* hPrimary = new TH2F(Form("hPrimary_FMD_%c_vtx%d",ringChar,v),
86 Form("hPrimary_FMD_%c_vtx%d",ringChar,v),
87 fNbinsEta, -6,6, nSec, 0,2*TMath::Pi());
89 fListOfPrimaries.Add(hPrimary);
98 for(Int_t det =1; det<=3;det++) {
99 Int_t nRings = (det==1 ? 1 : 2);
100 for(Int_t ring = 0;ring<nRings;ring++) {
101 Int_t nSec = (ring == 1 ? 40 : 20);
102 Char_t ringChar = (ring == 0 ? 'I' : 'O');
103 TH1F* doubleHits = new TH1F(Form("DoubleHits_FMD%d%c",det,ringChar),
104 Form("DoubleHits_FMD%d%c",det,ringChar),fNbinsEta, -6,6);
105 TH1F* allHits = new TH1F(Form("allHits_FMD%d%c",det,ringChar),
106 Form("allHits_FMD%d%c",det,ringChar), fNbinsEta, -6,6);
110 fListOfHits.Add(allHits);
111 fListOfHits.Add(doubleHits);
113 for(Int_t v=0; v<fNvtxBins;v++) {
114 TH2F* hHits = new TH2F(Form("hHits_FMD%d%c_vtx%d", det,ringChar,v),
115 Form("hHits_FMD%d%c_vtx%d", det,ringChar,v),
116 fNbinsEta, -6,6, nSec, 0, 2*TMath::Pi());
118 fListOfHits.Add(hHits);
124 TH1F* hEventsSelected = new TH1F("EventsSelected","EventsSelected",fNvtxBins,0,fNvtxBins);
125 TH1F* hEventsAll = new TH1F("EventsAll","EventsAll",fNvtxBins,0,fNvtxBins);
126 TH1F* hEventsSelectedVtx = new TH1F("EventsSelectedVtx","EventsSelectedVtx",fNvtxBins,0,fNvtxBins);
127 TH1F* hEventsSelectedTrigger = new TH1F("EventsSelectedTrigger","EventsSelectedTrigger",fNvtxBins,0,fNvtxBins);
129 TH1F* hXvtx = new TH1F("hXvtx","x vertex distribution",100,-2,2);
130 TH1F* hYvtx = new TH1F("hYvtx","y vertex distribution",100,-2,2);
131 TH1F* hZvtx = new TH1F("hZvtx","z vertex distribution",4*fNvtxBins,-4*fZvtxCut,4*fZvtxCut);
133 fListOfPrimaries.Add(hXvtx);
134 fListOfPrimaries.Add(hYvtx);
135 fListOfPrimaries.Add(hZvtx);
137 hEventsSelected->Sumw2();
139 fListOfHits.Add(hEventsSelected);
140 fListOfHits.Add(hEventsSelectedVtx);
141 fListOfHits.Add(hEventsSelectedTrigger);
142 fListOfPrimaries.Add(hEventsAll);
144 // fListOfHits.Add(hTriggered);
145 // fListOfPrimaries.Add(hTriggeredAll);
147 fVertexBins.SetName("VertexBins");
148 fVertexBins.GetXaxis()->Set(fNvtxBins,-1*fZvtxCut,fZvtxCut);
151 //_____________________________________________________________________
152 void AliFMDAnalysisTaskGenerateCorrection::Init()
154 fLastTrackByStrip.Reset(-1);
158 //_____________________________________________________________________
159 void AliFMDAnalysisTaskGenerateCorrection::UserExec(Option_t */*option*/)
162 fLastTrackByStrip.Reset(-1);
163 fHitsByStrip.Reset(0);
164 AliMCEvent* mcevent = MCEvent();
166 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
169 AliESDEvent* esdevent = (AliESDEvent*)InputEvent();
170 Double_t esdvertex[3];
171 Bool_t vtxStatus = pars->GetVertex(esdevent,esdvertex);
173 AliMCParticle* particle = 0;
174 AliStack* stack = mcevent->Stack();
176 UShort_t det,sec,strip;
179 Int_t nTracks = mcevent->GetNumberOfTracks();
180 AliHeader* header = mcevent->Header();
181 AliGenEventHeader* genHeader = header->GenEventHeader();
184 genHeader->PrimaryVertex(vertex);
186 TH1F* hXvtx = (TH1F*)fListOfPrimaries.FindObject("hXvtx");
187 hXvtx->Fill(vertex.At(0));
188 TH1F* hYvtx = (TH1F*)fListOfPrimaries.FindObject("hYvtx");
189 hYvtx->Fill(vertex.At(1));
190 TH1F* hZvtx = (TH1F*)fListOfPrimaries.FindObject("hZvtx");
191 hZvtx->Fill(vertex.At(2));
194 if(TMath::Abs(vertex.At(2)) > fZvtxCut)
197 Double_t delta = 2*fZvtxCut/fNvtxBins;
198 Double_t vertexBinDouble = (vertex.At(2) + fZvtxCut) / delta;
199 Int_t vertexBin = (Int_t)vertexBinDouble;
201 // Vertex determination correction
202 TH1F* hEventsSelected = (TH1F*)fListOfHits.FindObject("EventsSelected");
203 TH1F* hEventsSelectedVtx = (TH1F*)fListOfHits.FindObject("EventsSelectedVtx");
204 TH1F* hEventsSelectedTrigger = (TH1F*)fListOfHits.FindObject("EventsSelectedTrigger");
205 TH1F* hEventsAll = (TH1F*)fListOfPrimaries.FindObject("EventsAll");
207 // TH1F* hTriggered = (TH1F*)fListOfHits.FindObject("Triggered");
208 // TH1F* hTriggeredAll = (TH1F*)fListOfPrimaries.FindObject("TriggeredAll");
210 Bool_t vtxFound = kTRUE;
214 Bool_t isTriggered = pars->IsEventTriggered(esdevent);
216 if(vtxFound && isTriggered) hEventsSelected->Fill(vertexBin);
218 if(vtxFound) hEventsSelectedVtx->Fill(vertexBin);
219 if(isTriggered) hEventsSelectedTrigger->Fill(vertexBin);
221 hEventsAll->Fill(vertexBin);
223 // if(!vtxFound || !isTriggered) return;
225 for(Int_t i = 0 ;i<nTracks;i++) {
226 particle = (AliMCParticle*) mcevent->GetTrack(i);
231 if(stack->IsPhysicalPrimary(i) && particle->Charge() != 0) {
234 TH2F* hPrimaryInner = (TH2F*)fListOfPrimaries.FindObject( Form("hPrimary_FMD_%c_vtx%d",'I',vertexBin));
235 TH2F* hPrimaryOuter = (TH2F*)fListOfPrimaries.FindObject( Form("hPrimary_FMD_%c_vtx%d",'O',vertexBin));
236 hPrimaryInner->Fill(particle->Eta(),particle->Phi());
237 hPrimaryOuter->Fill(particle->Eta(),particle->Phi());
240 for(Int_t j=0; j<particle->GetNumberOfTrackReferences();j++) {
242 AliTrackReference* ref = particle->GetTrackReference(j);
244 if(ref->DetectorId() != AliTrackReference::kFMD)
246 AliFMDStripIndex::Unpack(ref->UserId(),det,ring,sec,strip);
247 Float_t thisStripTrack = fLastTrackByStrip(det,ring,sec,strip);
248 if(particle->Charge() != 0 && i != thisStripTrack ) {
250 Float_t phi = pars->GetPhiFromSector(det,ring,sec);
251 Float_t eta = pars->GetEtaFromStrip(det,ring,sec,strip,vertex.At(2));
253 TH2F* hHits = (TH2F*)fListOfHits.FindObject(Form("hHits_FMD%d%c_vtx%d", det,ring,vertexBin));
254 hHits->Fill(eta,phi);
255 Float_t nstrips = (ring =='O' ? 256 : 512);
256 fHitsByStrip(det,ring,sec,strip) +=1;
257 TH1F* allHits = (TH1F*)fListOfHits.FindObject(Form("allHits_FMD%d%c",det,ring));
258 TH1F* doubleHits = (TH1F*)fListOfHits.FindObject(Form("DoubleHits_FMD%d%c",det,ring));
260 if(fHitsByStrip(det,ring,sec,strip) == 1)
263 doubleHits->Fill(eta);
265 fLastTrackByStrip(det,ring,sec,strip) = (Float_t)i;
267 fLastTrackByStrip(det,ring,sec,strip-1) = (Float_t)i;
268 if(strip < (nstrips - 1))
269 fLastTrackByStrip(det,ring,sec,strip+1) = (Float_t)i;
276 TH2F* hSPDMult = (TH2F*)fListOfHits.FindObject(Form("hSPDhits_vtx%d", vertexBin));
278 const AliMultiplicity* spdmult = esdevent->GetMultiplicity();
279 for(Int_t j = 0; j< spdmult->GetNumberOfTracklets();j++)
280 hSPDMult->Fill(spdmult->GetEta(j),spdmult->GetPhi(j));
282 for(Int_t j = 0; j< spdmult->GetNumberOfSingleClusters();j++)
283 hSPDMult->Fill(-TMath::Log(TMath::Tan(spdmult->GetThetaSingle(j)/2.)),spdmult->GetPhiSingle(j));
286 PostData(1, &fListOfHits);
287 PostData(2, &fListOfPrimaries);
288 PostData(3, &fVertexBins);
290 //_____________________________________________________________________
291 void AliFMDAnalysisTaskGenerateCorrection::Terminate(Option_t */*option*/)
293 /* TH1F* allHits = (TH1F*)fListOfHits.FindObject("allHits");
294 TH1F* doubleHits = (TH1F*)fListOfHits.FindObject("DoubleHits");
296 doubleHits->Divide(allHits);
297 GenerateCorrection();
298 PostData(1, &fListOfHits);
299 PostData(4, &fListOfCorrection);*/
302 //_____________________________________________________________________
303 void AliFMDAnalysisTaskGenerateCorrection::GenerateCorrection() {
305 fBackground = new AliFMDAnaCalibBackgroundCorrection();
306 fEventSelectionEff = new AliFMDAnaCalibEventSelectionEfficiency();
308 //TH1F* hTriggered = (TH1F*)fListOfHits.FindObject("Triggered");
309 //TH1F* hTriggeredAll = (TH1F*)fListOfPrimaries.FindObject("TriggeredAll");
311 TH1F* hEventsSelected = (TH1F*)fListOfHits.FindObject("EventsSelected");
312 TH1F* hEventsSelectedVtx = (TH1F*)fListOfHits.FindObject("EventsSelectedVtx");
313 TH1F* hEventsSelectedTrigger = (TH1F*)fListOfHits.FindObject("EventsSelectedTrigger");
314 TH1F* hEventsAll = (TH1F*)fListOfPrimaries.FindObject("EventsAll");
316 // hEventsAll->Divide(hEventsAll,hEventsSelected,1,1,"B");
317 hEventsSelectedVtx->Divide(hEventsAll);
318 hEventsSelectedTrigger->Divide(hEventsAll);
320 for(Int_t i = 1; i<=hEventsSelected->GetNbinsX(); i++) {
321 if(hEventsSelected->GetBinContent(i) == 0 )
323 Float_t b = hEventsSelected->GetBinContent(i);
324 Float_t db = hEventsSelected->GetBinError(i);
325 Float_t sum = hEventsAll->GetBinContent(i);
326 Float_t dsum = hEventsAll->GetBinError(i);
328 Float_t da = TMath::Sqrt(TMath::Power(db,2) + TMath::Power(dsum,2));
330 Float_t cor = sum / b;
331 Float_t ecor = TMath::Sqrt(TMath::Power(da,2) + TMath::Power(a/(b*db),2)) / b;
333 hEventsAll->SetBinContent(i,cor);
334 hEventsAll->SetBinError(i,ecor);
338 fEventSelectionEff->SetCorrection(hEventsAll);
340 for(Int_t det= 1; det <=3; det++) {
341 Int_t nRings = (det==1 ? 1 : 2);
343 for(Int_t iring = 0; iring<nRings; iring++) {
344 Char_t ring = (iring == 0 ? 'I' : 'O');
345 TH1F* allHits = (TH1F*)fListOfHits.FindObject(Form("allHits_FMD%d%c",det,ring));
346 TH1F* doubleHits = (TH1F*)fListOfHits.FindObject(Form("DoubleHits_FMD%d%c",det,ring));
347 allHits->Divide(doubleHits);
349 fBackground->SetDoubleHitCorrection(det,ring,allHits);
351 for(Int_t vertexBin=0;vertexBin<fNvtxBins ;vertexBin++) {
352 TH2F* hHits = (TH2F*)fListOfHits.FindObject(Form("hHits_FMD%d%c_vtx%d", det,ring,vertexBin));
353 TH2F* hPrimary = (TH2F*)fListOfPrimaries.FindObject( Form("hPrimary_FMD_%c_vtx%d",ring,vertexBin));
354 TH2F* hCorrection = (TH2F*)hHits->Clone(Form("FMD%d%c_vtxbin_%d_correction",det,ring,vertexBin));
355 hCorrection->Divide(hPrimary);
356 /*for(Int_t i = 1; i<=hCorrection->GetNbinsX();i++) {
357 for(Int_t j=1; j<=hCorrection->GetNbinsY();j++) {
358 if(hCorrection()->GetBinContent(i,j) == 0)
367 hCorrection->SetTitle(hCorrection->GetName());
368 fListOfCorrection.Add(hCorrection);
369 fBackground->SetBgCorrection(det,ring,vertexBin,hCorrection);
376 for(Int_t vertexBin=0;vertexBin<fNvtxBins ;vertexBin++) {
377 TH2F* hPrimary = (TH2F*)fListOfPrimaries.FindObject( Form("hPrimary_FMD_%c_vtx%d",'I',vertexBin));
378 TH2F* hSPDMult = (TH2F*)fListOfHits.FindObject(Form("hSPDhits_vtx%d", vertexBin));
379 if(!hSPDMult) continue;
381 TH2F* hCorrection = (TH2F*)hSPDMult->Clone(Form("SPD_vtxbin_%d_correction",vertexBin));
382 hCorrection->SetTitle(hCorrection->GetName());
383 fListOfCorrection.Add(hCorrection);
384 hCorrection->Divide(hPrimary);
385 fBackground->SetBgCorrection(0,'Q',vertexBin,hCorrection);
387 TH1F* hAlive = new TH1F(Form("hAliveSPD_vtxbin%d",vertexBin),Form("hAliveSPD_vtxbin%d",vertexBin),hSPDMult->GetNbinsX(),hSPDMult->GetXaxis()->GetXmin(), hSPDMult->GetXaxis()->GetXmax());
388 TH1F* hPresent = new TH1F(Form("hPresentSPD_vtxbin%d",vertexBin),Form("hPresentSPD_vtxbin%d",vertexBin),hSPDMult->GetNbinsX(),hSPDMult->GetXaxis()->GetXmin(), hSPDMult->GetXaxis()->GetXmax());
389 for(Int_t xx = 1; xx <=hSPDMult->GetNbinsX(); xx++) {
391 if(TMath::Abs(hCorrection->GetXaxis()->GetBinCenter(xx)) > 2)
393 for(Int_t yy = 1; yy <=hSPDMult->GetNbinsY(); yy++) {
394 if(hCorrection->GetBinContent(xx,yy) > 0.1)
395 hAlive->Fill(hCorrection->GetXaxis()->GetBinCenter(xx));
396 hPresent->Fill(hCorrection->GetXaxis()->GetBinCenter(xx));
400 TH1F* hDeadCorrection = (TH1F*)hAlive->Clone(Form("hSPDDeadCorrection_vtxbin%d",vertexBin));
401 hDeadCorrection->Divide(hPresent);
402 fBackground->SetSPDDeadCorrection(vertexBin,hDeadCorrection);
403 fListOfCorrection.Add(hDeadCorrection);
407 TAxis refAxis(fNvtxBins,-1*fZvtxCut,fZvtxCut);
408 fBackground->SetRefAxis(&refAxis);
411 //_____________________________________________________________________
412 void AliFMDAnalysisTaskGenerateCorrection::ReadFromFile(const Char_t* filename, Bool_t storeInOCDB, Int_t /*runNo*/) {
414 TFile infile(filename);
415 TH1F* hVertex = (TH1F*)infile.Get("VertexBins");
416 fZvtxCut = hVertex->GetXaxis()->GetXmax();
417 fNvtxBins = hVertex->GetXaxis()->GetNbins();
418 fVertexBins.SetName("VertexBins");
419 fVertexBins.GetXaxis()->Set(fNvtxBins,-1*fZvtxCut,fZvtxCut);
421 TList* listOfHits = (TList*)infile.Get("Hits");
422 TList* listOfPrim = (TList*)infile.Get("Primaries");
424 TH1F* hEventsSelected = (TH1F*)listOfHits->FindObject("EventsSelected");
425 TH1F* hEventsSelectedVtx = (TH1F*)listOfHits->FindObject("EventsSelectedVtx");
426 TH1F* hEventsSelectedTrigger = (TH1F*)listOfHits->FindObject("EventsSelectedTrigger");
427 TH1F* hEventsAll = (TH1F*)listOfPrim->FindObject("EventsAll");
429 fListOfHits.Add(hEventsSelected);
430 fListOfHits.Add(hEventsSelectedVtx);
431 fListOfHits.Add(hEventsSelectedTrigger);
432 fListOfPrimaries.Add(hEventsAll);
434 TH1F* hXvtx = (TH1F*)listOfPrim->FindObject("hXvtx");
435 TH1F* hYvtx = (TH1F*)listOfPrim->FindObject("hYvtx");
436 TH1F* hZvtx = (TH1F*)listOfPrim->FindObject("hZvtx");
437 fListOfPrimaries.Add(hXvtx);
438 fListOfPrimaries.Add(hYvtx);
439 fListOfPrimaries.Add(hZvtx);
441 for(Int_t det =1; det<=3;det++)
443 Int_t nRings = (det==1 ? 1 : 2);
444 for(Int_t ring = 0;ring<nRings;ring++)
446 Char_t ringChar = (ring == 0 ? 'I' : 'O');
447 TH1F* allHits = (TH1F*)listOfHits->FindObject(Form("allHits_FMD%d%c",det,ringChar));
448 TH1F* doubleHits = (TH1F*)listOfHits->FindObject(Form("DoubleHits_FMD%d%c",det,ringChar));
449 fListOfHits.Add(allHits);
450 fListOfHits.Add(doubleHits);
451 for(Int_t v=0; v<fNvtxBins;v++)
454 TH2F* hHits = (TH2F*)listOfHits->FindObject(Form("hHits_FMD%d%c_vtx%d", det,ringChar,v));
455 fListOfHits.Add(hHits);
459 for(Int_t v=0; v<fNvtxBins;v++) {
460 TH2F* hSPDHits = (TH2F*)listOfHits->FindObject(Form("hSPDhits_vtx%d", v));
461 fListOfHits.Add(hSPDHits);
463 for(Int_t iring = 0; iring<2;iring++) {
464 Char_t ringChar = (iring == 0 ? 'I' : 'O');
467 TH2F* hPrimary = (TH2F*)listOfPrim->FindObject( Form("hPrimary_FMD_%c_vtx%d",ringChar,v));
468 fListOfPrimaries.Add(hPrimary);
472 GenerateCorrection();
474 TFile fout("backgroundFromFile.root","recreate");
476 fListOfPrimaries.Write();
477 fListOfCorrection.Write();
481 AliFMDAnaParameters* pars = AliFMDAnaParameters::Instance();
483 TFile fbg(pars->GetPath(pars->GetBackgroundID()),"RECREATE");
484 fBackground->Write(AliFMDAnaParameters::GetBackgroundID());
486 TFile feselect(pars->GetPath(pars->GetEventSelectionEffID()),"RECREATE");
487 fEventSelectionEff->Write(AliFMDAnaParameters::GetEventSelectionEffID());
496 //_____________________________________________________________________