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,""),
49 // Input slot #0 works with an Ntuple
50 DefineInput(0, TChain::Class());
51 // Output slot #0 writes into a TH1 container
52 DefineOutput(0, TObjArray::Class()) ;
55 //______________________________________________________________________________
56 AliFMDQATask::~AliFMDQATask()
60 fOutputContainer->Clear() ;
61 delete fOutputContainer ;
71 //______________________________________________________________________________
72 void AliFMDQATask::ConnectInputData(const Option_t*)
74 // Initialisation of branch container and histograms
76 AliInfo(Form("*** Initialization of %s", GetName())) ;
79 fChain = dynamic_cast<TChain *>(GetInputData(0)) ;
81 AliError(Form("Input 0 for %s not found\n", GetName()));
85 // One should first check if the branch address was taken by some other task
86 char ** address = (char **)GetBranchAddress(0, "ESD");
88 fESD = (AliESD*)(*address);
91 SetBranchAddress(0, "ESD", &fESD);
95 //________________________________________________________________________
96 void AliFMDQATask::CreateOutputObjects()
102 fhFMD1i = new TH1D("FMD1i", "FMD1i", 100, -0.5, 3);
103 fhFMD2i = new TH1D("FMD2i", "FMD2i", 100, -0.5, 3);
104 fhFMD2o = new TH1D("FMD2o", "FMD2o", 100, -0.5, 3);
105 fhFMD3i = new TH1D("FMD3i", "FMD3i", 100, -0.5, 3);
106 fhFMD3o = new TH1D("FMD3o", "FMD3o", 100, -0.5, 3);
108 // create output container
110 fOutputContainer = new TObjArray(5) ;
111 fOutputContainer->SetName(GetName()) ;
113 fOutputContainer->AddAt(fhFMD1i, 0) ;
114 fOutputContainer->AddAt(fhFMD2i, 1) ;
115 fOutputContainer->AddAt(fhFMD2o, 2) ;
116 fOutputContainer->AddAt(fhFMD3i, 3) ;
117 fOutputContainer->AddAt(fhFMD3o, 4) ;
120 //______________________________________________________________________________
121 void AliFMDQATask::Exec(Option_t *)
123 // Processing of one event
125 Long64_t entry = fChain->GetReadEntry() ;
128 AliError("fESD is not connected to the input!") ;
132 TFile * currentFile = (dynamic_cast<TChain *>(fChain))->GetFile() ;
133 if ( !((entry-1)%100) )
134 AliInfo(Form("%s ----> Processing event # %lld", currentFile->GetName(), entry)) ;
136 // ************************ FMD *************************************
137 AliESDFMD * fmd = fESD->GetFMDData() ;
139 AliError("No FMD found in ESD") ;
142 fmd->CheckNeedUShort(currentFile);
143 Int_t nFMD1 = 0, nFMD2i = 0, nFMD2o = 0, nFMD3i = 0, nFMD3o = 0 ;
145 UShort_t detector = 1 ;
146 for(detector = 1 ; detector <= fmd->MaxDetectors() ; detector++) {
149 for(sector = 0 ;sector < fmd->MaxSectors() ; sector++) {
151 for(strip = 0 ; strip < fmd->MaxStrips(); strip++) {
152 if(fmd->Multiplicity(detector, ring, sector, strip) != AliESDFMD::kInvalidMult)
153 RingSelector(detector, ring, fmd->Multiplicity(detector, ring, sector, strip)) ;
154 if( (fmd->Multiplicity(detector, ring, sector, strip) == AliESDFMD::kInvalidMult) && detector == 2 )
156 if( (fmd->Multiplicity(detector, ring, sector, strip)==AliESDFMD::kInvalidMult) && detector == 3 )
161 for(sector = 0; sector < fmd->MaxSectors(); sector++) {
163 for(strip = 0 ; strip < fmd->MaxStrips() ; strip++) {
164 if(fmd->Multiplicity(detector, ring, sector, strip) != AliESDFMD::kInvalidMult)
165 RingSelector(detector, ring, fmd->Multiplicity(detector, ring, sector, strip));
166 if( (fmd->Multiplicity(detector, ring, sector, strip) == AliESDFMD::kInvalidMult) && detector == 1 )
168 if( (fmd->Multiplicity(detector, ring, sector, strip) == AliESDFMD::kInvalidMult) && detector == 2 )
170 if( (fmd->Multiplicity(detector, ring, sector, strip) == AliESDFMD::kInvalidMult) && detector == 3 )
177 AliWarning(Form("number of missing strips in FMD1i too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
179 AliWarning(Form("number of missing strips in FMD2i too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
181 AliWarning(Form("number of missing strips in FMD2o too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
183 AliWarning(Form("number of missing strips in FMD3i too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
185 AliWarning(Form("number of missing strips in FMD3o too high in event number %lld in file", entry, fChain->GetCurrentFile()->GetName())) ;
187 PostData(0, fOutputContainer);
190 //______________________________________________________________________________
191 void AliFMDQATask::Terminate(Option_t *)
193 // Processing when the event loop is ended
195 fOutputContainer = (TObjArray*)GetOutputData(0);
196 if ( ! fOutputContainer )
199 fhFMD1i = (TH1D*)fOutputContainer->At(0);
200 fhFMD2i = (TH1D*)fOutputContainer->At(1);
201 fhFMD2o = (TH1D*)fOutputContainer->At(2);
202 fhFMD3i = (TH1D*)fOutputContainer->At(3);
203 fhFMD3o = (TH1D*)fOutputContainer->At(4);
205 TCanvas * cFMD1 = new TCanvas("cFMD1", "FMD ESD Test", 400, 10, 600, 700);
206 cFMD1->Divide(3, 2) ;
223 cFMD1->Print("FMD.eps") ;
225 Bool_t rv1i = TestHisto(fhFMD1i) ;
226 Bool_t rv2i = TestHisto(fhFMD2i) ;
227 Bool_t rv2o = TestHisto(fhFMD2o) ;
228 Bool_t rv3i = TestHisto(fhFMD2i) ;
229 Bool_t rv3o = TestHisto(fhFMD2o) ;
231 if ( !(rv1i * rv2i * rv2o * rv3i * rv3o) )
232 AliWarning("Possible problem in file !!! Check output!") ;
237 sprintf(line, ".!tar -zcvf %s.tar.gz *.eps", GetName()) ;
238 gROOT->ProcessLine(line);
239 sprintf(line, ".!rm -fR *.eps");
240 gROOT->ProcessLine(line);
242 AliInfo(Form("!!! All the eps files are in %s.tar.gz !!! \n", GetName())) ;
245 //______________________________________________________________________________
246 void AliFMDQATask::RingSelector(const UShort_t detector, const Char_t ring, const Float_t mult) const
248 // fill the histograms for each ring in each detector layer
250 if(ring == 'I' && detector == 1)
251 fhFMD1i->Fill(mult) ;
252 if(ring == 'I' && detector == 2)
253 fhFMD2i->Fill(mult) ;
254 if(ring == 'O' && detector == 2)
255 fhFMD2o ->Fill(mult) ;
256 if(ring == 'I' && detector == 3)
257 fhFMD3i ->Fill(mult) ;
258 if(ring == 'O' && detector == 3)
259 fhFMD3o ->Fill(mult) ;
261 //______________________________________________________________________________
262 Bool_t AliFMDQATask::TestHisto(TH1D * hTest) const
264 // analyses the histogram with a Landau function
266 Float_t chiMax = 3, chiLow=0.5 ;
271 FitAll(hTest, chiSq, ndf, mpv, chiMax, chiLow);
273 if( (chiSq > chiMax || chiSq < chiLow) || mpv < 0.6 || mpv > 1 ) {
275 FitAll(hTest, chiSq, ndf, mpv, chiMax, chiLow) ;
278 Bool_t ret = kFALSE ;
279 Char_t * test = "not OK";
280 Char_t * test2 = "not OK";
282 if(chiSq < chiMax && chiSq > chiLow)
284 if(mpv > 0.6 && mpv < 1)
287 if(test == "OK" && test2 == "OK")
290 if(test == "not OK" || test2 == "not OK") {
291 AliWarning("Bad fit results") ;
292 printf("Detector : %s\n", hTest->GetName()) ;
293 printf("Landau fit Chi Square / NDF = %f / %d which is %s\n", chiSq*ndf, ndf, test) ;
294 printf("Landau fit MPV is: %f which is %s\n", mpv, test2) ;
298 //______________________________________________________________________________
299 void AliFMDQATask::FitAll(TH1D* hTest, Float_t &chiSq, Int_t &ndf, Float_t &mpv, Float_t chiMax, Float_t chiLow ) const
301 // fit a histogram with a Landau distribution and returns chi square
303 Float_t fitMax = hTest->GetXaxis()->GetXmax() ;
306 hTmp.SetAxisRange(0.4,fitMax) ;
307 Int_t maxBin = hTmp.GetMaximumBin();
308 Float_t max = hTmp.GetBinCenter(maxBin);
310 hTest->Fit("landau", "QOI", "", max-0.3, fitMax) ;
311 TF1* fitfunc = hTest->GetFunction("landau") ;
312 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
313 mpv = fitfunc->GetParameter(1) ;
314 ndf = fitfunc->GetNDF() ;
316 if( ( chiSq > chiMax || chiSq < chiLow ) || ( mpv < 0.6 || mpv > 1 ) ) {
317 hTest->Fit("landau", "QOI", "", max-0.2, fitMax) ;
318 fitfunc = hTest->GetFunction("landau") ;
319 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
320 mpv = fitfunc->GetParameter(1) ;
321 ndf = fitfunc->GetNDF() ;
323 if( ( chiSq >chiMax || chiSq < chiLow ) || ( mpv < 0.6 || mpv > 1 ) ) {
324 hTest->Fit("landau", "QOI", "", max-0.1, fitMax) ;
325 fitfunc = hTest->GetFunction("landau") ;
326 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
327 mpv = fitfunc->GetParameter(1) ;
328 ndf = fitfunc->GetNDF() ;
330 if( ( chiSq > chiMax || chiSq <chiLow ) || ( mpv < 0.6 || mpv > 1 ) ) {
331 hTest->Fit("landau", "QOI", "", max, fitMax) ;
332 fitfunc = hTest->GetFunction("landau") ;
333 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
334 mpv = fitfunc->GetParameter(1) ;
335 ndf = fitfunc->GetNDF();
337 if( ( chiSq > chiMax || chiSq < chiLow ) || ( mpv < 0.6 ||mpv > 1 ) ) {
338 hTest->Fit("landau", "QOI", "", max+0.1, fitMax) ;
339 fitfunc = hTest->GetFunction("landau") ;
340 chiSq = fitfunc->GetChisquare() / fitfunc->GetNDF() ;
341 mpv = fitfunc->GetParameter(1) ;
342 ndf = fitfunc->GetNDF() ;