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 **************************************************************************/
16 /* $Id: AliTRDCalibraExbAltFit.cxx 46327 2011-01-10 13:29:56Z cblume $ */
18 ////////////////////////////////////////////////////////////////////////////
20 // AliTRDCalibraExbAltFit //
22 // Does the ExB calibration by applying a quadratic fit //
25 // R. Bailhache (R.Bailhache@gsi.de) //
27 ////////////////////////////////////////////////////////////////////////////
30 #include <TObjArray.h>
35 #include <TLinearFitter.h>
37 #include <TTreeStream.h>
41 #include "AliTRDCalibraExbAltFit.h"
43 ClassImp(AliTRDCalibraExbAltFit) /*FOLD00*/
45 //_____________________________________________________________________
46 AliTRDCalibraExbAltFit::AliTRDCalibraExbAltFit() : /*FOLD00*/
49 fFitterHistoArray(540),
54 // default constructor
57 //_____________________________________________________________________
58 AliTRDCalibraExbAltFit::AliTRDCalibraExbAltFit(const AliTRDCalibraExbAltFit &ped) : /*FOLD00*/
60 fVersion(ped.fVersion),
61 fFitterHistoArray(540),
68 for (Int_t idet = 0; idet < 540; idet++){
70 const TVectorD *vectorE = (TVectorD*)ped.fFitterEArray.UncheckedAt(idet);
71 const TVectorD *vectorP = (TVectorD*)ped.fFitterPArray.UncheckedAt(idet);
72 const TH2S *hped = (TH2S*)ped.fFitterHistoArray.UncheckedAt(idet);
74 if ( vectorE != 0x0 ) fFitterEArray.AddAt(new TVectorD(*vectorE), idet);
75 if ( vectorP != 0x0 ) fFitterPArray.AddAt(new TVectorD(*vectorP), idet);
77 TH2S *hNew = (TH2S *)hped->Clone();
78 //hNew->SetDirectory(0);
79 fFitterHistoArray.AddAt(hNew,idet);
83 //_____________________________________________________________________
84 AliTRDCalibraExbAltFit::AliTRDCalibraExbAltFit(const TObjArray &obja) : /*FOLD00*/
87 fFitterHistoArray(540),
92 // constructor from a TObjArray
94 for (Int_t idet = 0; idet < 540; idet++){
95 const TH2S *hped = (TH2S*)obja.UncheckedAt(idet);
97 TH2S *hNew = (TH2S *)hped->Clone();
98 //hNew->SetDirectory(0);
99 fFitterHistoArray.AddAt(hNew,idet);
103 //_____________________________________________________________________
104 AliTRDCalibraExbAltFit& AliTRDCalibraExbAltFit::operator = (const AliTRDCalibraExbAltFit &source)
107 // assignment operator
109 if (&source == this) return *this;
110 new (this) AliTRDCalibraExbAltFit(source);
114 //_____________________________________________________________________
115 AliTRDCalibraExbAltFit::~AliTRDCalibraExbAltFit() /*FOLD00*/
120 fFitterHistoArray.SetOwner();
121 fFitterPArray.SetOwner();
122 fFitterEArray.SetOwner();
124 fFitterHistoArray.Delete();
125 fFitterPArray.Delete();
126 fFitterEArray.Delete();
129 //_____________________________________________________________________________
130 void AliTRDCalibraExbAltFit::Copy(TObject &c) const
136 AliTRDCalibraExbAltFit& target = (AliTRDCalibraExbAltFit &) c;
138 // Copy only the histos
139 for (Int_t idet = 0; idet < 540; idet++){
140 if(fFitterHistoArray.UncheckedAt(idet)){
141 TH2S *hped1 = (TH2S *)target.GetFitterHisto(idet,kTRUE);
142 //hped1->SetDirectory(0);
143 hped1->Add((const TH2S *)fFitterHistoArray.UncheckedAt(idet));
150 //_____________________________________________________________________________
151 Long64_t AliTRDCalibraExbAltFit::Merge(const TCollection* list)
153 // Merge list of objects (needed by PROOF)
161 TIterator* iter = list->MakeIterator();
164 // collection of generated histograms
166 while((obj = iter->Next()) != 0)
168 AliTRDCalibraExbAltFit* entry = dynamic_cast<AliTRDCalibraExbAltFit*>(obj);
169 if (entry == 0) continue;
171 // Copy only the histos
172 for (Int_t idet = 0; idet < 540; idet++){
173 if(entry->GetFitterHisto(idet)){
174 TH2S *hped1 = (TH2S *)GetFitterHisto(idet,kTRUE);
175 Double_t entriesa = hped1->GetEntries();
176 Double_t entriesb = ((TH2S *)entry->GetFitterHisto(idet))->GetEntries();
177 if((entriesa + entriesb) < 5*32767) hped1->Add(entry->GetFitterHisto(idet));
186 //_____________________________________________________________________
187 void AliTRDCalibraExbAltFit::Add(const AliTRDCalibraExbAltFit *ped)
195 for (Int_t idet = 0; idet < 540; idet++){
196 const TH2S *hped = (TH2S*)ped->GetFitterHistoNoForce(idet);
197 //printf("idet %d\n",idet);
200 TH2S *hped1 = (TH2S *)GetFitterHisto(idet,kTRUE);
201 Double_t entriesa = hped1->GetEntries();
202 Double_t entriesb = hped->GetEntries();
203 if((entriesa + entriesb) < 5*32767) hped1->Add(hped);
207 //______________________________________________________________________________________
208 TH2S* AliTRDCalibraExbAltFit::GetFitterHisto(Int_t detector, Bool_t force)
211 // return pointer to TH2F histo
212 // if force is true create a new histo if it doesn't exist allready
214 if ( !force || fFitterHistoArray.UncheckedAt(detector) )
215 return (TH2S*)fFitterHistoArray.UncheckedAt(detector);
217 return GetFitterHistoForce(detector);
220 //______________________________________________________________________________________
221 TH2S* AliTRDCalibraExbAltFit::GetFitterHistoForce(Int_t detector)
224 // return pointer to TH2F histo
225 // if NULL create a new histo if it doesn't exist allready
227 if (fFitterHistoArray.UncheckedAt(detector))
228 return (TH2S*)fFitterHistoArray.UncheckedAt(detector);
230 // if we are forced and TLinearFitter doesn't yes exist create it
233 TString name("LFEXB");
238 TH2S *lfdv = new TH2S((const Char_t *)name,(const Char_t *) name,
239 30, -TMath::DegToRad()*45, TMath::DegToRad()*45,
241 lfdv->SetXTitle("tan(phi_{track})");
242 lfdv->SetYTitle("rms");
243 lfdv->SetZTitle("Number of tracklets");
245 lfdv->SetDirectory(0);
247 fFitterHistoArray.AddAt(lfdv,detector);
250 //______________________________________________________________________________________
251 Bool_t AliTRDCalibraExbAltFit::GetParam(Int_t detector, TVectorD *param)
254 // return param for this detector
256 if ( fFitterPArray.UncheckedAt(detector) ){
257 const TVectorD *vectorP = (TVectorD*)fFitterPArray.UncheckedAt(detector);
258 if(!param) param = new TVectorD(vectorP->GetNoElements());
259 for(Int_t k = 0; k < vectorP->GetNoElements(); k++){
260 (*param)[k] = (*vectorP)[k];
267 //______________________________________________________________________________________
268 Bool_t AliTRDCalibraExbAltFit::GetError(Int_t detector, TVectorD *error)
271 // return error for this detector
273 if ( fFitterEArray.UncheckedAt(detector) ){
274 const TVectorD *vectorE = (TVectorD*)fFitterEArray.UncheckedAt(detector);
275 if(!error) error = new TVectorD(vectorE->GetNoElements());
276 for(Int_t k = 0; k < vectorE->GetNoElements(); k++){
277 (*error)[k] = (*vectorE)[k];
284 //______________________________________________________________________________________
285 void AliTRDCalibraExbAltFit::Update(Int_t detector, Float_t tnp, Float_t pars1)
288 // Fill the 2D histos for debugging
291 TH2S *h = ((TH2S *) GetFitterHisto(detector,kTRUE));
292 Double_t nbentries = h->GetEntries();
293 if(nbentries < 5*32767) h->Fill(tnp,pars1);
296 //____________Functions fit Online CH2d________________________________________
297 void AliTRDCalibraExbAltFit::FillPEArray()
300 // Fill fFitterPArray and fFitterEArray from inside
304 Int_t *arrayI = new Int_t[540];
305 for(Int_t k = 0; k< 540; k++){
310 for(Int_t cb = 0; cb < 540; cb++){
311 const TH2S *fitterhisto = (TH2S*)fFitterHistoArray.UncheckedAt(cb);
312 //printf("Processing the detector cb %d we find %d\n",cb, (Bool_t) fitterhisto);
314 if ( fitterhisto != 0 ){
317 TAxis *xaxis = fitterhisto->GetXaxis();
318 TAxis *yaxis = fitterhisto->GetYaxis();
319 TLinearFitter fitter = TLinearFitter(3,"pol2");
321 Double_t integral = fitterhisto->Integral();
322 //printf("Integral is %f\n",integral);
323 Bool_t securitybreaking = kFALSE;
324 if(TMath::Abs(integral-1199) < 0.00001) securitybreaking = kTRUE;
325 for(Int_t ibinx = 0; ibinx < fitterhisto->GetNbinsX(); ibinx++){
326 for(Int_t ibiny = 0; ibiny < fitterhisto->GetNbinsY(); ibiny++){
327 if(fitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){
328 Double_t x = xaxis->GetBinCenter(ibinx+1);
329 Double_t y = yaxis->GetBinCenter(ibiny+1);
331 for(Int_t k = 0; k < (Int_t)fitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){
332 if(!securitybreaking){
333 fitter.AddPoint(&x,y);
337 if(arrayI[cb]< 1198){
338 fitter.AddPoint(&x,y);
348 //printf("Find %d entries for the detector %d\n",arrayI[cb],cb);
352 TVectorD *par = new TVectorD(3);
353 TVectorD pare = TVectorD(2);
354 TVectorD *parE = new TVectorD(3);
356 if((fitter.EvalRobust(0.8)==0)) {
357 //if((fitter.Eval()==0)) {
358 //printf("Take the param\n");
359 fitter.GetParameters(*par);
361 //fitter.GetErrors(*pare);
362 //Float_t ppointError = TMath::Sqrt(TMath::Abs(fitter.GetChisquare())/arrayI[cb]);
363 //(*parE)[0] = pare[0]*ppointError;
364 //(*parE)[1] = pare[1]*ppointError;
367 (*parE)[2] = (Double_t) arrayI[cb];
368 fFitterPArray.AddAt(par,cb);
369 fFitterEArray.AddAt(parE,cb);
374 //printf("Finish\n");
377 //delete fitterhisto;