1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
18 //_________________________________________________________________________
19 // An analysis task to check the FMD data in simulated data
21 //*-- Hans Hjersing Dalsgaard
22 //////////////////////////////////////////////////////////////////////////////
32 #include "AliFMDQATask.h"
36 //______________________________________________________________________________
37 AliFMDQATask::AliFMDQATask(const char *name) :
38 AliAnalysisTask(name,""),
48 // Input slot #0 works with an Ntuple
49 DefineInput(0, TChain::Class());
50 // Output slot #0 writes into a TH1 container
51 DefineOutput(0, TObjArray::Class()) ;
54 //______________________________________________________________________________
55 AliFMDQATask::~AliFMDQATask()
59 fOutputContainer->Clear() ;
60 delete fOutputContainer ;
70 //______________________________________________________________________________
71 void AliFMDQATask::ConnectInputData(const Option_t*)
73 // Initialisation of branch container and histograms
75 AliInfo(Form("*** Initialization of %s", GetName())) ;
78 fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
80 AliError(Form("Input 0 for %s not found\n", GetName()));
84 // One should first check if the branch address was taken by some other task
85 char ** address = (char **)GetBranchAddress(0, "ESD");
87 fESD = (AliESD*)(*address);
90 SetBranchAddress(0, "ESD", &fESD);
94 //________________________________________________________________________
95 void AliFMDQATask::CreateOutputObjects()
101 fhFMD1i = new TH1D("FMD1i", "FMD1i", 100, -0.5, 3);
102 fhFMD2i = new TH1D("FMD2i", "FMD2i", 100, -0.5, 3);
103 fhFMD2o = new TH1D("FMD2o", "FMD2o", 100, -0.5, 3);
104 fhFMD3i = new TH1D("FMD3i", "FMD3i", 100, -0.5, 3);
105 fhFMD3o = new TH1D("FMD3o", "FMD3o", 100, -0.5, 3);
107 // create output container
109 fOutputContainer = new TObjArray(5) ;
110 fOutputContainer->SetName(GetName()) ;
112 fOutputContainer->AddAt(fhFMD1i, 0) ;
113 fOutputContainer->AddAt(fhFMD2i, 1) ;
114 fOutputContainer->AddAt(fhFMD2o, 2) ;
115 fOutputContainer->AddAt(fhFMD3i, 3) ;
116 fOutputContainer->AddAt(fhFMD3o, 4) ;
119 //______________________________________________________________________________
120 void AliFMDQATask::Exec(Option_t *)
122 // Processing of one event
124 Long64_t entry = fChain->GetReadEntry() ;
127 AliError("fESD is not connected to the input!") ;
131 TFile * currentFile = (dynamic_cast<TChain *>(fChain))->GetFile() ;
132 if ( !((entry-1)%100) )
133 AliInfo(Form("%s ----> Processing event # %lld", currentFile->GetName(), entry)) ;
135 // ************************ FMD *************************************
136 AliESDFMD * fmd = fESD->GetFMDData() ;
138 AliError("No FMD found in ESD") ;
141 fmd->CheckNeedUShort(currentFile);
142 Int_t nFMD1 = 0, nFMD2i = 0, nFMD2o = 0, nFMD3i = 0, nFMD3o = 0 ;
144 UShort_t detector = 1 ;
145 for(detector = 1 ; detector <= fmd->MaxDetectors() ; detector++) {
148 for(sector = 0 ;sector < fmd->MaxSectors() ; sector++) {
150 for(strip = 0 ; strip < fmd->MaxStrips(); strip++) {
151 if(fmd->Multiplicity(detector, ring, sector, strip) != AliESDFMD::kInvalidMult)
152 RingSelector(detector, ring, fmd->Multiplicity(detector, ring, sector, strip)) ;
153 if( (fmd->Multiplicity(detector, ring, sector, strip) == AliESDFMD::kInvalidMult) && detector == 2 )
155 if( (fmd->Multiplicity(detector, ring, sector, strip)==AliESDFMD::kInvalidMult) && detector == 3 )
160 for(sector = 0; sector < fmd->MaxSectors(); sector++) {
162 for(strip = 0 ; strip < fmd->MaxStrips() ; strip++) {
163 if(fmd->Multiplicity(detector, ring, sector, strip) != AliESDFMD::kInvalidMult)
164 RingSelector(detector, ring, fmd->Multiplicity(detector, ring, sector, strip));
165 if( (fmd->Multiplicity(detector, ring, sector, strip) == AliESDFMD::kInvalidMult) && detector == 1 )
167 if( (fmd->Multiplicity(detector, ring, sector, strip) == AliESDFMD::kInvalidMult) && detector == 2 )
169 if( (fmd->Multiplicity(detector, ring, sector, strip) == AliESDFMD::kInvalidMult) && detector == 3 )
176 AliWarning(Form("number of missing strips in FMD1i too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
178 AliWarning(Form("number of missing strips in FMD2i too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
180 AliWarning(Form("number of missing strips in FMD2o too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
182 AliWarning(Form("number of missing strips in FMD3i too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
184 AliWarning(Form("number of missing strips in FMD3o too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
186 PostData(0, fOutputContainer);
189 //______________________________________________________________________________
190 void AliFMDQATask::Terminate(Option_t *)
192 // Processing when the event loop is ended
194 fOutputContainer = (TObjArray*)GetOutputData(0);
195 if ( ! fOutputContainer )
198 fhFMD1i = (TH1D*)fOutputContainer->At(0);
199 fhFMD2i = (TH1D*)fOutputContainer->At(1);
200 fhFMD2o = (TH1D*)fOutputContainer->At(2);
201 fhFMD3i = (TH1D*)fOutputContainer->At(3);
202 fhFMD3o = (TH1D*)fOutputContainer->At(4);
204 TCanvas * cFMD1 = new TCanvas("cFMD1", "FMD ESD Test", 400, 10, 600, 700);
205 cFMD1->Divide(3, 2) ;
222 cFMD1->Print("FMD.eps") ;
224 Bool_t rv1i = TestHisto(fhFMD1i) ;
225 Bool_t rv2i = TestHisto(fhFMD2i) ;
226 Bool_t rv2o = TestHisto(fhFMD2o) ;
227 Bool_t rv3i = TestHisto(fhFMD2i) ;
228 Bool_t rv3o = TestHisto(fhFMD2o) ;
230 if ( !(rv1i * rv2i * rv2o * rv3i * rv3o) )
231 AliWarning("Possible problem in file !!! Check output!") ;
236 sprintf(line, ".!tar -zcvf %s.tar.gz *.eps", GetName()) ;
237 gROOT->ProcessLine(line);
238 sprintf(line, ".!rm -fR *.eps");
239 gROOT->ProcessLine(line);
241 AliInfo(Form("!!! All the eps files are in %s.tar.gz !!! \n", GetName())) ;
244 //______________________________________________________________________________
245 void AliFMDQATask::RingSelector(const UShort_t detector, const Char_t ring, const Float_t mult) const
247 // fill the histograms for each ring in each detector layer
249 if(ring == 'I' && detector == 1)
250 fhFMD1i->Fill(mult) ;
251 if(ring == 'I' && detector == 2)
252 fhFMD2i->Fill(mult) ;
253 if(ring == 'O' && detector == 2)
254 fhFMD2o ->Fill(mult) ;
255 if(ring == 'I' && detector == 3)
256 fhFMD3i ->Fill(mult) ;
257 if(ring == 'O' && detector == 3)
258 fhFMD3o ->Fill(mult) ;
260 //______________________________________________________________________________
261 Bool_t AliFMDQATask::TestHisto(TH1D * hTest) const
263 // analyses the histogram with a Landau function
265 Float_t chiMax = 3, chiLow=0.5 ;
270 FitAll(hTest, chiSq, ndf, mpv, chiMax, chiLow);
272 if( (chiSq > chiMax || chiSq < chiLow) || mpv < 0.6 || mpv > 1 ) {
274 FitAll(hTest, chiSq, ndf, mpv, chiMax, chiLow) ;
277 Bool_t ret = kFALSE ;
278 Char_t * test = "not OK";
279 Char_t * test2 = "not OK";
281 if(chiSq < chiMax && chiSq > chiLow)
283 if(mpv > 0.6 && mpv < 1)
286 if(test == "OK" && test2 == "OK")
289 if(test == "not OK" || test2 == "not OK") {
290 AliWarning("Bad fit results") ;
291 printf("Detector : %s\n", hTest->GetName()) ;
292 printf("Landau fit Chi Square / NDF = %f / %d which is %s\n", chiSq*ndf, ndf, test) ;
293 printf("Landau fit MPV is: %f which is %s\n", mpv, test2) ;
297 //______________________________________________________________________________
298 void AliFMDQATask::FitAll(TH1D* hTest, Float_t &chiSq, Int_t &ndf, Float_t &mpv, Float_t chiMax, Float_t chiLow ) const
300 // fit a histogram with a Landau distribution and returns chi square
302 Float_t fitMax = hTest->GetXaxis()->GetXmax() ;
305 hTmp.SetAxisRange(0.4,fitMax) ;
306 Int_t maxBin = hTmp.GetMaximumBin();
307 Float_t max = hTmp.GetBinCenter(maxBin);
309 hTest->Fit("landau", "QOI", "", max-0.3, fitMax) ;
310 TF1* fitfunc = hTest->GetFunction("landau") ;
311 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
312 mpv = fitfunc->GetParameter(1) ;
313 ndf = fitfunc->GetNDF() ;
315 if( ( chiSq > chiMax || chiSq < chiLow ) || ( mpv < 0.6 || mpv > 1 ) ) {
316 hTest->Fit("landau", "QOI", "", max-0.2, fitMax) ;
317 fitfunc = hTest->GetFunction("landau") ;
318 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
319 mpv = fitfunc->GetParameter(1) ;
320 ndf = fitfunc->GetNDF() ;
322 if( ( chiSq >chiMax || chiSq < chiLow ) || ( mpv < 0.6 || mpv > 1 ) ) {
323 hTest->Fit("landau", "QOI", "", max-0.1, fitMax) ;
324 fitfunc = hTest->GetFunction("landau") ;
325 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
326 mpv = fitfunc->GetParameter(1) ;
327 ndf = fitfunc->GetNDF() ;
329 if( ( chiSq > chiMax || chiSq <chiLow ) || ( mpv < 0.6 || mpv > 1 ) ) {
330 hTest->Fit("landau", "QOI", "", max, fitMax) ;
331 fitfunc = hTest->GetFunction("landau") ;
332 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
333 mpv = fitfunc->GetParameter(1) ;
334 ndf = fitfunc->GetNDF();
336 if( ( chiSq > chiMax || chiSq < chiLow ) || ( mpv < 0.6 ||mpv > 1 ) ) {
337 hTest->Fit("landau", "QOI", "", max+0.1, fitMax) ;
338 fitfunc = hTest->GetFunction("landau") ;
339 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
340 mpv = fitfunc->GetParameter(1) ;
341 ndf = fitfunc->GetNDF() ;