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),
55 // default constructor
58 //_____________________________________________________________________
59 AliTRDCalibraExbAltFit::AliTRDCalibraExbAltFit(const AliTRDCalibraExbAltFit &ped) : /*FOLD00*/
61 fVersion(ped.fVersion),
62 fFitterHistoArray(540),
70 for (Int_t idet = 0; idet < 540; idet++){
72 const TVectorD *vectorE = (TVectorD*)ped.fFitterEArray.UncheckedAt(idet);
73 const TVectorD *vectorP = (TVectorD*)ped.fFitterPArray.UncheckedAt(idet);
74 const TH2S *hped = (TH2S*)ped.fFitterHistoArray.UncheckedAt(idet);
76 if ( vectorE != 0x0 ) fFitterEArray.AddAt(new TVectorD(*vectorE), idet);
77 if ( vectorP != 0x0 ) fFitterPArray.AddAt(new TVectorD(*vectorP), idet);
79 TH2S *hNew = (TH2S *)hped->Clone();
80 //hNew->SetDirectory(0);
81 fFitterHistoArray.AddAt(hNew,idet);
85 //_____________________________________________________________________
86 AliTRDCalibraExbAltFit::AliTRDCalibraExbAltFit(const TObjArray &obja) : /*FOLD00*/
89 fFitterHistoArray(540),
95 // constructor from a TObjArray
97 for (Int_t idet = 0; idet < 540; idet++){
98 const TH2S *hped = (TH2S*)obja.UncheckedAt(idet);
100 TH2S *hNew = (TH2S *)hped->Clone();
101 //hNew->SetDirectory(0);
102 fFitterHistoArray.AddAt(hNew,idet);
106 //_____________________________________________________________________
107 AliTRDCalibraExbAltFit& AliTRDCalibraExbAltFit::operator = (const AliTRDCalibraExbAltFit &source)
110 // assignment operator
112 if (&source == this) return *this;
113 new (this) AliTRDCalibraExbAltFit(source);
117 //_____________________________________________________________________
118 AliTRDCalibraExbAltFit::~AliTRDCalibraExbAltFit() /*FOLD00*/
123 fFitterHistoArray.SetOwner();
124 fFitterPArray.SetOwner();
125 fFitterEArray.SetOwner();
127 fFitterHistoArray.Delete();
128 fFitterPArray.Delete();
129 fFitterEArray.Delete();
132 //_____________________________________________________________________________
133 void AliTRDCalibraExbAltFit::Copy(TObject &c) const
139 AliTRDCalibraExbAltFit& target = (AliTRDCalibraExbAltFit &) c;
141 // Copy only the histos
142 for (Int_t idet = 0; idet < 540; idet++){
143 if(fFitterHistoArray.UncheckedAt(idet)){
144 TH2S *hped1 = (TH2S *)target.GetFitterHisto(idet,kTRUE);
145 //hped1->SetDirectory(0);
146 hped1->Add((const TH2S *)fFitterHistoArray.UncheckedAt(idet));
153 //_____________________________________________________________________________
154 Long64_t AliTRDCalibraExbAltFit::Merge(const TCollection* list)
156 // Merge list of objects (needed by PROOF)
164 TIterator* iter = list->MakeIterator();
167 // collection of generated histograms
169 while((obj = iter->Next()) != 0)
171 AliTRDCalibraExbAltFit* entry = dynamic_cast<AliTRDCalibraExbAltFit*>(obj);
172 if (entry == 0) continue;
174 // Copy only the histos
175 for (Int_t idet = 0; idet < 540; idet++){
176 if(entry->GetFitterHisto(idet)){
177 TH2S *hped1 = (TH2S *)GetFitterHisto(idet,kTRUE);
178 Double_t entriesa = hped1->GetEntries();
179 Double_t entriesb = ((TH2S *)entry->GetFitterHisto(idet))->GetEntries();
180 if((entriesa + entriesb) < 5*32767) hped1->Add(entry->GetFitterHisto(idet));
189 //_____________________________________________________________________
190 void AliTRDCalibraExbAltFit::Add(const AliTRDCalibraExbAltFit *ped)
198 for (Int_t idet = 0; idet < 540; idet++){
199 const TH2S *hped = (TH2S*)ped->GetFitterHistoNoForce(idet);
200 //printf("idet %d\n",idet);
203 TH2S *hped1 = (TH2S *)GetFitterHisto(idet,kTRUE);
204 Double_t entriesa = hped1->GetEntries();
205 Double_t entriesb = hped->GetEntries();
206 if((entriesa + entriesb) < 5*32767) hped1->Add(hped);
210 //______________________________________________________________________________________
211 TH2S* AliTRDCalibraExbAltFit::GetFitterHisto(Int_t detector, Bool_t force)
214 // return pointer to TH2F histo
215 // if force is true create a new histo if it doesn't exist allready
217 if ( !force || fFitterHistoArray.UncheckedAt(detector) )
218 return (TH2S*)fFitterHistoArray.UncheckedAt(detector);
220 return GetFitterHistoForce(detector);
223 //______________________________________________________________________________________
224 TH2S* AliTRDCalibraExbAltFit::GetFitterHistoForce(Int_t detector)
227 // return pointer to TH2F histo
228 // if NULL create a new histo if it doesn't exist allready
230 if (fFitterHistoArray.UncheckedAt(detector))
231 return (TH2S*)fFitterHistoArray.UncheckedAt(detector);
233 // if we are forced and TLinearFitter doesn't yes exist create it
236 TString name("LFEXB");
241 TH2S *lfdv = new TH2S((const Char_t *)name,(const Char_t *) name,
242 30, -TMath::DegToRad()*45, TMath::DegToRad()*45,
244 lfdv->SetXTitle("tan(phi_{track})");
245 lfdv->SetYTitle("rms");
246 lfdv->SetZTitle("Number of tracklets");
248 lfdv->SetDirectory(0);
250 fFitterHistoArray.AddAt(lfdv,detector);
253 //______________________________________________________________________________________
254 Bool_t AliTRDCalibraExbAltFit::GetParam(Int_t detector, TVectorD *param)
257 // return param for this detector
259 if ( fFitterPArray.UncheckedAt(detector) ){
260 const TVectorD *vectorP = (TVectorD*)fFitterPArray.UncheckedAt(detector);
261 if(!param) param = new TVectorD(vectorP->GetNoElements());
262 for(Int_t k = 0; k < vectorP->GetNoElements(); k++){
263 (*param)[k] = (*vectorP)[k];
270 //______________________________________________________________________________________
271 Bool_t AliTRDCalibraExbAltFit::GetError(Int_t detector, TVectorD *error)
274 // return error for this detector
276 if ( fFitterEArray.UncheckedAt(detector) ){
277 const TVectorD *vectorE = (TVectorD*)fFitterEArray.UncheckedAt(detector);
278 if(!error) error = new TVectorD(vectorE->GetNoElements());
279 for(Int_t k = 0; k < vectorE->GetNoElements(); k++){
280 (*error)[k] = (*vectorE)[k];
287 //______________________________________________________________________________________
288 void AliTRDCalibraExbAltFit::Update(Int_t detector, Float_t tnp, Float_t pars1)
291 // Fill the 2D histos for debugging
294 TH2S *h = ((TH2S *) GetFitterHisto(detector,kTRUE));
295 Double_t nbentries = h->GetEntries();
296 if(nbentries < 5*32767) h->Fill(tnp,pars1);
299 //____________Functions fit Online CH2d________________________________________
300 void AliTRDCalibraExbAltFit::FillPEArray()
303 // Fill fFitterPArray and fFitterEArray from inside
307 Int_t *arrayI = new Int_t[540];
308 for(Int_t k = 0; k< 540; k++){
313 for(Int_t cb = 0; cb < 540; cb++){
314 const TH2S *fitterhisto = (TH2S*)fFitterHistoArray.UncheckedAt(cb);
315 //printf("Processing the detector cb %d we find %d\n",cb, (Bool_t) fitterhisto);
317 if ( fitterhisto != 0 ){
320 TAxis *xaxis = fitterhisto->GetXaxis();
321 TAxis *yaxis = fitterhisto->GetYaxis();
322 TLinearFitter fitter = TLinearFitter(3,"pol2");
324 Double_t integral = fitterhisto->Integral();
325 //printf("Integral is %f\n",integral);
326 Bool_t securitybreaking = kFALSE;
327 if(TMath::Abs(integral-1199) < 0.00001) securitybreaking = kTRUE;
328 for(Int_t ibinx = 0; ibinx < fitterhisto->GetNbinsX(); ibinx++){
329 for(Int_t ibiny = 0; ibiny < fitterhisto->GetNbinsY(); ibiny++){
330 if(fitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){
331 Double_t x = xaxis->GetBinCenter(ibinx+1);
332 Double_t y = yaxis->GetBinCenter(ibiny+1);
334 for(Int_t k = 0; k < (Int_t)fitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){
335 if(!securitybreaking){
336 fitter.AddPoint(&x,y);
340 if(arrayI[cb]< 1198){
341 fitter.AddPoint(&x,y);
351 //printf("Find %d entries for the detector %d\n",arrayI[cb],cb);
355 TVectorD *par = new TVectorD(3);
356 TVectorD pare = TVectorD(2);
357 TVectorD *parE = new TVectorD(3);
359 //if((fitter.EvalRobust(0.8)==0)) {
360 //if((fitter.EvalRobust()==0)) {
361 if(((fRobustFit) && (fitter.EvalRobust(0.8)==0)) || ((!fRobustFit) && (fitter.Eval()==0))) {
362 //if((fitter.Eval()==0)) {
363 //printf("Take the param\n");
364 fitter.GetParameters(*par);
366 //fitter.GetErrors(*pare);
367 //Float_t ppointError = TMath::Sqrt(TMath::Abs(fitter.GetChisquare())/arrayI[cb]);
368 //(*parE)[0] = pare[0]*ppointError;
369 //(*parE)[1] = pare[1]*ppointError;
372 (*parE)[2] = (Double_t) arrayI[cb];
373 fFitterPArray.AddAt(par,cb);
374 fFitterEArray.AddAt(parE,cb);
379 //printf("Finish\n");
382 //delete fitterhisto;