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 ////////////////////////////////////////////////////////////////////////////
19 // Gain calibration using tracks
22 // 1.) Inner TPC gain alignement - (parabolic) parameterization (inside of one sector)
23 // 2.) Angular and z-position correction (parabolic) parameterization
24 // 3.) Sector gain alignment
26 // Following histograms are accumulated
27 // a.) Simple 1D histograms per chamber
28 // b.) Profile histograms per chamber - local x dependence
29 // c.) 2D Profile histograms - local x - fi dependence
31 // To get the gain map - the simple solution - use the histograms - is not enough
32 // The resulting mean amplitude map depends strongly on the track topology
33 // These dependence can be reduced, taking into account angular effect, and diffusion effect
34 // Using proper fit modeles
39 // === Calibration class for gain calibration using tracks ===
43 // A 6-parametric parabolic function
45 // G(x, y) = p0 + p1*x + p2*y + p3*x^2 + p4*y^2 + p5 * x*y
47 // is fitted to the maximum charge values or total charge values of
48 // all the clusters contained in the tracks that are added to this
49 // object. This fit is performed for each read out chamber, in fact even
50 // for each type of pad sizes (thus for one segment, which consists of
51 // an IROC and an OROC, there are three fitters used, corresponding to
52 // the three pad sizes). The coordinate origin is at the center of the
53 // particular pad size region on each ROC.
55 // Because of the Landau nature of the charge deposition we use
56 // different "types" of fitters instead of one to minimize the effect
57 // of the long Landau tail. The difference between the fitters is only
58 // the charge value, that is put into them, i.e. the charge is subject
59 // to a transformation. At this point we use three different fit types:
61 // a) simple: the charge is put in as it is
62 // b) sqrt: the square root of the charge is put into the fitter
63 // c) log: fgkM * Log(1+q/fgkM) is put into the fitter, with
64 // q being the untransformed charge and fgkM=25
66 // The results of the fits may be visualized and further used by
67 // creating an AliTPCCalROC or AliTPCCalPad. You may specify to undo
68 // the transformation and/or to normalize to the pad size.
70 // Not every track you add to this object is actually used for
71 // calibration. There are some cuts and conditions to exclude bad
72 // tracks, e.g. a pt cut to cut out tracks with too much charge
73 // deposition or a cut on edge clusters which are not fully
74 // registered and don't give a usable signal.
76 // 2) Interface / usage
77 // ====================
78 // For each track to be added you need to call Process().
79 // This method expects an AliTPCseed, which contains the necessary
80 // cluster information. At the moment of writing this information
81 // is stored in an AliESDfriend corresponding to an AliESD.
82 // You may also call AddTrack() if you don't want the cuts and
83 // other quality conditions to kick in (thus forcing the object to
84 // accept the track) or AddCluster() for adding single clusters.
85 // Call one of the Evaluate functions to evaluate the fitter(s) and
86 // to retrieve the fit parameters, erros and so on. You can also
87 // do this later on by using the different Getters.
89 // The visualization methods CreateFitCalPad() and CreateFitCalROC()
90 // are straight forward to use.
92 // Note: If you plan to write this object to a ROOT file, make sure
93 // you evaluate all the fitters *before* writing, because due
94 // to a bug in the fitter component writing fitters doesn't
95 // work properly (yet). Be aware that you cannot re-evaluate
96 // the fitters after loading this object from file.
97 // (This will be gone for a new ROOT version > v5-17-05)
100 // In order to debug some numerical algorithm all data data which are used for
101 // fitters can be stored in the debug streamers. In case of fitting roblems the
102 // errors and tendencies can be checked.
110 ////////////////////////////////////////////////////////////////////////////
114 gSystem->Load("libANALYSIS");
115 gSystem->Load("libSTAT");
116 gSystem->Load("libTPCcalib");
118 TFile fcalib("CalibObjects.root");
119 TObjArray * array = (TObjArray*)fcalib.Get("TPCCalib");
120 AliTPCcalibTracksGain * gain = ( AliTPCcalibTracksGain *)array->FindObject("calibTracksGain");
123 // Angular and drift correction
125 AliTPCClusterParam *param = new AliTPCClusterParam;param->SetInstance(param);
126 gain->UpdateClusterParam(param);
127 TF2 fdrty("fdrty","AliTPCClusterParam::SQnorm(0,0,x,y,0)",0,1,0,1)
130 // Make visual Tree - compare with Kr calibration
132 AliTPCCalPad * gain010 = gain->CreateFitCalPad(0,kTRUE,0); gain010->SetName("CGain010");
133 AliTPCCalPad * gain110 = gain->CreateFitCalPad(1,kTRUE,0); gain110->SetName("CGain110");
134 AliTPCCalPad * gain210 = gain->CreateFitCalPad(2,kTRUE,0); gain210->SetName("CGain210");
135 TFile fkr("/u/miranov/GainMap.root");
136 AliTPCCalPad *gainKr = fkr.Get("GainMap"); fkr->SetName("KrGain");
138 AliTPCPreprocessorOnline * preprocesor = new AliTPCPreprocessorOnline;
139 preprocesor->AddComponent(gain010);
140 preprocesor->AddComponent(gain110);
141 preprocesor->AddComponent(gain210);
142 preprocesor->AddComponent(gainKr);
143 preprocesor->DumpToFile("cosmicGain.root");
147 // Simple session using the debug streamers
150 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros");
151 gROOT->LoadMacro("$ALICE_ROOT/TPC/macros/AliXRDPROOFtoolkit.cxx+")
152 AliXRDPROOFtoolkit tool;
154 TChain * chain0 = tool.MakeChain("gain.txt","dEdx",0,1000000);
155 TChain * chain1 = tool.MakeChain("gain.txt","Track",0,1000000);
156 TChain * chain2 = tool.MakeChain("gain.txt","TrackG",0,1000000);
161 chain2->SetAlias("k1","1/0.855");
162 chain2->SetAlias("k0","1/0.9928");
163 chain2->SetAlias("k2","1/1.152");
171 #include <TPDGCode.h>
174 #include "TMatrixD.h"
175 #include "TTreeStream.h"
177 #include "AliTPCParamSR.h"
178 #include "AliTPCClusterParam.h"
179 #include "AliTrackPointArray.h"
181 #include "AliTPCcalibTracksGain.h"
184 #include <TLinearFitter.h>
185 #include <TTreeStream.h>
187 #include <TCollection.h>
188 #include <TIterator.h>
189 #include <TProfile.h>
190 #include <TProfile2D.h>
197 #include "AliMathBase.h"
199 #include "AliTPCROC.h"
200 #include "AliTPCParamSR.h"
201 #include "AliTPCCalROC.h"
202 #include "AliTPCCalPad.h"
203 #include "AliTPCClusterParam.h"
205 #include "AliTracker.h"
207 #include "AliESDtrack.h"
208 #include "AliESDfriend.h"
209 #include "AliESDfriendTrack.h"
210 #include "AliTPCseed.h"
211 #include "AliTPCclusterMI.h"
212 #include "AliTPCcalibTracksCuts.h"
213 #include "AliTPCFitPad.h"
214 #include "TStatToolkit.h"
220 #include "AliESDEvent.h"
224 TFile f("TPCCalibTracksGain.root")
226 gSystem->Load("libPWG1.so")
232 TString * str = comp.FitPlane("Cl.fQ/dedxQ.fElements[0]","Cl.fY++Cl.fX","Cl.fDetector<36",chi2,vec,mat)
236 ClassImp(AliTPCcalibTracksGain)
238 const Bool_t AliTPCcalibTracksGain::fgkUseTotalCharge = kTRUE;
239 const Double_t AliTPCcalibTracksGain::fgkM = 25.;
240 const char* AliTPCcalibTracksGain::fgkDebugStreamFileName = "TPCCalibTracksGain.root";
241 AliTPCParamSR* AliTPCcalibTracksGain::fgTPCparam = new AliTPCParamSR();
243 AliTPCcalibTracksGain::AliTPCcalibTracksGain() :
245 fCuts(0), // cuts that are used for sieving the tracks used for calibration
246 fGainMap(0), // gain map to be applied
248 // Simple Array of histograms
250 fArrayQM(0), // Qmax normalized
251 fArrayQT(0), // Qtot normalized
252 fProfileArrayQM(0), // Qmax normalized versus local X
253 fProfileArrayQT(0), // Qtot normalized versus local X
254 fProfileArrayQM2D(0), // Qmax normalized versus local X and phi
255 fProfileArrayQT2D(0), // Qtot normalized versus local X and phi
259 fSimpleFitter(0), // simple fitter for short pads
260 fSqrtFitter(0), // sqrt fitter for medium pads
261 fLogFitter(0), // log fitter for long pads
263 fFitter0M(0), // fitting of the atenuation, angular correction, and mean chamber gain
264 fFitter1M(0), // fitting of the atenuation, angular correction, and mean chamber gain
265 fFitter2M(0), // fitting of the atenuation, angular correction, and mean chamber gain
266 fFitter0T(0), // fitting of the atenuation, angular correction, and mean chamber gain
267 fFitter1T(0), // fitting of the atenuation, angular correction, and mean chamber gain
268 fFitter2T(0), // fitting of the atenuation, angular correction, and mean chamber gain
270 fDFitter0M(0), // fitting of the atenuation, angular correction
271 fDFitter1M(0), // fitting of the atenuation, angular correction
272 fDFitter2M(0), // fitting of the atenuation, angular correction
273 fDFitter0T(0), // fitting of the atenuation, angular correction
274 fDFitter1T(0), // fitting of the atenuation, angular correction
275 fDFitter2T(0), // fitting of the atenuation, angular correction
277 fSingleSectorFitter(0), // just for debugging
281 fTotalTracks(0), // just for debugging
282 fAcceptedTracks(0), // just for debugging
283 fDebugCalPadRaw(0), // just for debugging
284 fDebugCalPadCorr(0) // just for debugging
288 // Default constructor.
292 AliTPCcalibTracksGain::AliTPCcalibTracksGain(const AliTPCcalibTracksGain& obj) :
293 AliTPCcalibBase(obj),
294 fCuts(obj.fCuts), // cuts that are used for sieving the tracks used for calibration
295 fGainMap(new AliTPCCalPad(*(obj.fGainMap))), // gain map to be applied
296 fArrayQM(0), // Qmax normalized
297 fArrayQT(0), // Qtot normalized
301 fProfileArrayQM(obj.fProfileArrayQM), // Qmax normalized versus local X
302 fProfileArrayQT(obj.fProfileArrayQT), // Qtot normalized versus local X
303 fProfileArrayQM2D(obj.fProfileArrayQM2D), // Qmax normalized versus local X and phi
304 fProfileArrayQT2D(obj.fProfileArrayQT2D), // Qtot normalized versus local X and phi
308 fSimpleFitter(obj.fSimpleFitter), // simple fitter for short pads
309 fSqrtFitter(obj.fSqrtFitter), // sqrt fitter for medium pads
310 fLogFitter(obj.fLogFitter), // log fitter for long pads
311 fFitter0M(obj.fFitter0M),
312 fFitter1M(obj.fFitter1M),
313 fFitter2M(obj.fFitter2M),
314 fFitter0T(obj.fFitter0T),
315 fFitter1T(obj.fFitter1T),
316 fFitter2T(obj.fFitter2T),
318 fDFitter0M(obj.fDFitter0M),
319 fDFitter1M(obj.fDFitter1M),
320 fDFitter2M(obj.fDFitter2M),
321 fDFitter0T(obj.fDFitter0T),
322 fDFitter1T(obj.fDFitter1T),
323 fDFitter2T(obj.fDFitter2T),
324 fSingleSectorFitter(obj.fSingleSectorFitter), // just for debugging
328 fTotalTracks(obj.fTotalTracks), // just for debugging
329 fAcceptedTracks(obj.fAcceptedTracks), // just for debugging
330 fDebugCalPadRaw(obj.fDebugCalPadRaw), // just for debugging
331 fDebugCalPadCorr(obj.fDebugCalPadCorr) // just for debugging
339 AliTPCcalibTracksGain& AliTPCcalibTracksGain::operator=(const AliTPCcalibTracksGain& rhs) {
341 // Assignment operator.
345 TNamed::operator=(rhs);
346 fDebugCalPadRaw = new AliTPCCalPad(*(rhs.fDebugCalPadRaw));
347 fDebugCalPadCorr = new AliTPCCalPad(*(rhs.fDebugCalPadCorr));
348 fSimpleFitter = new AliTPCFitPad(*(rhs.fSimpleFitter));
349 fSqrtFitter = new AliTPCFitPad(*(rhs.fSqrtFitter));
350 fLogFitter = new AliTPCFitPad(*(rhs.fLogFitter));
351 fSingleSectorFitter = new AliTPCFitPad(*(rhs.fSingleSectorFitter));
352 fCuts = new AliTPCcalibTracksCuts(*(rhs.fCuts));
353 fGainMap = new AliTPCCalPad(*(rhs.fGainMap));
358 AliTPCcalibTracksGain::AliTPCcalibTracksGain(const char* name, const char* title, AliTPCcalibTracksCuts* cuts, TNamed* /*debugStreamPrefix*/, AliTPCcalibTracksGain* prevIter) :
360 fCuts(0), // cuts that are used for sieving the tracks used for calibration
361 fGainMap(0), // gain map to be applied
362 fArrayQM(0), // Qmax normalized
363 fArrayQT(0), // Qtot normalized
367 fProfileArrayQM(0), // Qmax normalized versus local X
368 fProfileArrayQT(0), // Qtot normalized versus local X
369 fProfileArrayQM2D(0), // Qmax normalized versus local X and phi
370 fProfileArrayQT2D(0), // Qtot normalized versus local X and phi
374 fSimpleFitter(0), // simple fitter for short pads
375 fSqrtFitter(0), // sqrt fitter for medium pads
376 fLogFitter(0), // log fitter for long pads
377 fFitter0M(0), // fitting of the atenuation, angular correction, and mean chamber gain
378 fFitter1M(0), // fitting of the atenuation, angular correction, and mean chamber gain
379 fFitter2M(0), // fitting of the atenuation, angular correction, and mean chamber gain
380 fFitter0T(0), // fitting of the atenuation, angular correction, and mean chamber gain
381 fFitter1T(0), // fitting of the atenuation, angular correction, and mean chamber gain
382 fFitter2T(0), // fitting of the atenuation, angular correction, and mean chamber gain
384 fDFitter0M(0), // fitting of the atenuation, angular correction
385 fDFitter1M(0), // fitting of the atenuation, angular correction
386 fDFitter2M(0), // fitting of the atenuation, angular correction
387 fDFitter0T(0), // fitting of the atenuation, angular correction
388 fDFitter1T(0), // fitting of the atenuation, angular correction
389 fDFitter2T(0), // fitting of the atenuation, angular correction
390 fSingleSectorFitter(0), // just for debugging
394 fTotalTracks(0), // just for debugging
395 fAcceptedTracks(0), // just for debugging
396 fDebugCalPadRaw(0), // just for debugging
397 fDebugCalPadCorr(0) // just for debugging
403 this->SetNameTitle(name, title);
406 // Fitter initialization
408 fSimpleFitter = new AliTPCFitPad(8, "hyp7", "");
409 fSqrtFitter = new AliTPCFitPad(8, "hyp7", "");
410 fLogFitter = new AliTPCFitPad(8, "hyp7", "");
411 fSingleSectorFitter = new AliTPCFitPad(8, "hyp7", "");
413 fFitter0M = new TLinearFitter(45,"hyp44");
414 fFitter1M = new TLinearFitter(45,"hyp44");
415 fFitter2M = new TLinearFitter(45,"hyp44");
416 fFitter0T = new TLinearFitter(45,"hyp44");
417 fFitter1T = new TLinearFitter(45,"hyp44");
418 fFitter2T = new TLinearFitter(45,"hyp44");
420 fDFitter0M = new TLinearFitter(10,"hyp9");
421 fDFitter1M = new TLinearFitter(10,"hyp9");
422 fDFitter2M = new TLinearFitter(10,"hyp9");
423 fDFitter0T = new TLinearFitter(10,"hyp9");
424 fDFitter1T = new TLinearFitter(10,"hyp9");
425 fDFitter2T = new TLinearFitter(10,"hyp9");
428 fFitter0M->StoreData(kFALSE);
429 fFitter1M->StoreData(kFALSE);
430 fFitter2M->StoreData(kFALSE);
431 fFitter0T->StoreData(kFALSE);
432 fFitter1T->StoreData(kFALSE);
433 fFitter2T->StoreData(kFALSE);
435 fDFitter0M->StoreData(kFALSE);
436 fDFitter1M->StoreData(kFALSE);
437 fDFitter2M->StoreData(kFALSE);
438 fDFitter0T->StoreData(kFALSE);
439 fDFitter1T->StoreData(kFALSE);
440 fDFitter2T->StoreData(kFALSE);
443 // Add profile histograms -JUST for visualization - Not used for real calibration
446 fArrayQM=new TObjArray(73); // Qmax normalized
447 fArrayQT=new TObjArray(73); // Qtot normalized
448 fProfileArrayQM = new TObjArray(37); // Qmax normalized versus local X
449 fProfileArrayQT = new TObjArray(37); // Qtot normalized versus local X
450 fProfileArrayQM2D = new TObjArray(37); // Qmax normalized versus local X and phi
451 fProfileArrayQT2D = new TObjArray(37); // Qtot normalized versus local X and phi
453 for (Int_t i=0; i<73; i++){
454 sprintf(hname,"QM_%d",i);
455 fArrayQM->AddAt(new TH1F(hname,hname,200,0,1000),i);
456 sprintf(hname,"QT_%d",i);
457 fArrayQT->AddAt(new TH1F(hname,hname,200,0,1000),i);
460 for (Int_t i=0; i<37;i++){
461 sprintf(hname,"QMvsx_%d",i);
462 fProfileArrayQM->AddAt(new TProfile(hname,hname,50,89,250),i);
463 sprintf(hname,"QTvsx_%d",i);
464 fProfileArrayQT->AddAt(new TProfile(hname,hname,50,89,250),i);
465 sprintf(hname,"QM2D_%d",i);
466 fProfileArrayQM2D->AddAt(new TProfile2D(hname,hname,50,89,250,10,-0.15,0.15),i);
467 sprintf(hname,"QT2D_%d",i);
468 fProfileArrayQT2D->AddAt(new TProfile2D(hname,hname,50,89,250,10,-0.15,0.15),i);
471 // just for debugging -counters
475 fDebugCalPadRaw = new AliTPCCalPad("DebugCalPadRaw", "All clusters simply added up before correction");
476 fDebugCalPadCorr = new AliTPCCalPad("DebugCalPadCorr", "All clusters simply added up after correction");
477 // this will be gone for the a new ROOT version > v5-17-05
478 for (UInt_t i = 0; i < 36; i++) {
479 fNShortClusters[i] = 0;
480 fNMediumClusters[i] = 0;
481 fNLongClusters[i] = 0;
485 AliTPCcalibTracksGain::~AliTPCcalibTracksGain() {
490 Info("Destructor","");
491 if (fSimpleFitter) delete fSimpleFitter;
492 if (fSqrtFitter) delete fSqrtFitter;
493 if (fLogFitter) delete fLogFitter;
494 if (fSingleSectorFitter) delete fSingleSectorFitter;
496 if (fDebugCalPadRaw) delete fDebugCalPadRaw;
497 if (fDebugCalPadCorr) delete fDebugCalPadCorr;
500 void AliTPCcalibTracksGain::Terminate(){
502 // Evaluate fitters and close the debug stream.
503 // Also move or copy the debug stream, if a debugStreamPrefix is provided.
507 AliTPCcalibBase::Terminate();
512 void AliTPCcalibTracksGain::Process(AliTPCseed* seed) {
514 // Main method to be called when a new seed is supposed to be processed
515 // and be used for gain calibration. Its quality is checked before it
521 if (!fCuts->AcceptTrack(seed)) return;
525 static Bool_t doinit= kTRUE;
527 fSimpleFitter = new AliTPCFitPad(8, "hyp7", "");
528 fSqrtFitter = new AliTPCFitPad(8, "hyp7", "");
529 fLogFitter = new AliTPCFitPad(8, "hyp7", "");
530 fSingleSectorFitter = new AliTPCFitPad(8, "hyp7", "");
532 fFitter0M = new TLinearFitter(45,"hyp44");
533 fFitter1M = new TLinearFitter(45,"hyp44");
534 fFitter2M = new TLinearFitter(45,"hyp44");
535 fFitter0T = new TLinearFitter(45,"hyp44");
536 fFitter1T = new TLinearFitter(45,"hyp44");
537 fFitter2T = new TLinearFitter(45,"hyp44");
539 fDFitter0M = new TLinearFitter(10,"hyp9");
540 fDFitter1M = new TLinearFitter(10,"hyp9");
541 fDFitter2M = new TLinearFitter(10,"hyp9");
542 fDFitter0T = new TLinearFitter(10,"hyp9");
543 fDFitter1T = new TLinearFitter(10,"hyp9");
544 fDFitter2T = new TLinearFitter(10,"hyp9");
553 Long64_t AliTPCcalibTracksGain::Merge(TCollection *list) {
555 // Merge() merges the results of all AliTPCcalibTracksGain objects contained in
556 // list, thus allowing a distributed computation of several files, e.g. on PROOF.
557 // The merged results are merged with the data members of the AliTPCcalibTracksGain
558 // object used for calling the Merge method.
559 // The return value is 0 /*the total number of tracks used for calibration*/ if the merge
560 // is successful, otherwise it is -1.
563 if (!list || list->IsEmpty()) return -1;
565 if (!fSimpleFitter) fSimpleFitter = new AliTPCFitPad(8, "hyp7", "");
566 if (!fSqrtFitter) fSqrtFitter = new AliTPCFitPad(8, "hyp7", "");
567 if (!fLogFitter) fLogFitter = new AliTPCFitPad(8, "hyp7", "");
568 if (!fSingleSectorFitter) fSingleSectorFitter = new AliTPCFitPad(8, "hyp7", "");
571 // just for debugging
572 if (!fDebugCalPadRaw) fDebugCalPadRaw = new AliTPCCalPad("DebugCalPadRaw", "All clusters simply added up before correction");
573 if (!fDebugCalPadCorr) fDebugCalPadCorr = new AliTPCCalPad("DebugCalPadCorr", "All clusters simply added up after correction");
575 TIterator* iter = list->MakeIterator();
576 AliTPCcalibTracksGain* cal = 0;
578 while ((cal = (AliTPCcalibTracksGain*)iter->Next())) {
579 if (!cal->InheritsFrom(AliTPCcalibTracksGain::Class())) {
580 Error("Merge","Attempt to add object of class %s to a %s", cal->ClassName(), this->ClassName());
589 Float_t AliTPCcalibTracksGain::GetGain(AliTPCclusterMI* cl){
591 // Return local gain at cluster position
594 if(!fGainMap) return factor;
596 AliTPCCalROC * roc = fGainMap->GetCalROC(cl->GetDetector());
597 Int_t irow = cl->GetRow();
599 if (irow < 63) { // IROC
600 factor = roc->GetValue(irow, TMath::Nint(cl->GetPad()));
602 factor = roc->GetValue(irow - 63, TMath::Nint(cl->GetPad()));
605 if (factor<0.1) factor=0.1;
610 Float_t AliTPCcalibTracksGain::GetMaxNorm(AliTPCclusterMI * cl){
612 // Get normalized amplituded if the gain map provided
614 return cl->GetMax()/GetGain(cl);
618 Float_t AliTPCcalibTracksGain::GetQNorm(AliTPCclusterMI * cl){
620 // Get normalized amplituded if the gain map provided
622 return cl->GetQ()/GetGain(cl);
627 void AliTPCcalibTracksGain::Add(AliTPCcalibTracksGain* cal) {
629 // Adds another AliTPCcalibTracksGain object to this object.
632 fSimpleFitter->Add(cal->fSimpleFitter);
633 fSqrtFitter->Add(cal->fSqrtFitter);
634 fLogFitter->Add(cal->fLogFitter);
635 fSingleSectorFitter->Add(cal->fSingleSectorFitter);
639 fFitter0M->Add(cal->fFitter0M);
640 fFitter1M->Add(cal->fFitter1M);
641 fFitter2M->Add(cal->fFitter2M);
642 fFitter0T->Add(cal->fFitter0T);
643 fFitter1T->Add(cal->fFitter1T);
644 fFitter2T->Add(cal->fFitter2T);
646 fDFitter0M->Add(cal->fDFitter0M);
647 fDFitter1M->Add(cal->fDFitter1M);
648 fDFitter2M->Add(cal->fDFitter2M);
649 fDFitter0T->Add(cal->fDFitter0T);
650 fDFitter1T->Add(cal->fDFitter1T);
651 fDFitter2T->Add(cal->fDFitter2T);
656 for (Int_t i=0; i<73; i++){
658 his = (TH1F*)fArrayQM->At(i);
659 hism = (TH1F*)cal->fArrayQM->At(i);
660 if (his && hism) his->Add(hism);
661 his = (TH1F*)fArrayQT->At(i);
662 hism = (TH1F*)cal->fArrayQT->At(i);
663 if (his && hism) his->Add(hism);
667 for (Int_t i=0; i<37; i++){
669 his = (TProfile*)fProfileArrayQM->At(i);
670 hism = (TProfile*)cal->fProfileArrayQM->At(i);
671 if (his && hism) his->Add(hism);
672 his = (TProfile*)fProfileArrayQT->At(i);
673 hism = (TProfile*)cal->fProfileArrayQT->At(i);
674 if (his && hism) his->Add(hism);
678 for (Int_t i=0; i<37; i++){
679 TProfile2D *his,*hism;
680 his = (TProfile2D*)fProfileArrayQM2D->At(i);
681 hism = (TProfile2D*)cal->fProfileArrayQM2D->At(i);
682 if (his && hism) his->Add(hism);
683 his = (TProfile2D*)fProfileArrayQT2D->At(i);
684 hism = (TProfile2D*)cal->fProfileArrayQT2D->At(i);
685 if (his && hism) his->Add(hism);
688 // this will be gone for the a new ROOT version > v5-17-05
689 for (UInt_t iSegment = 0; iSegment < 36; iSegment++) {
690 fNShortClusters[iSegment] += cal->fNShortClusters[iSegment];
691 fNMediumClusters[iSegment] += cal->fNMediumClusters[iSegment];
692 fNLongClusters[iSegment] += cal->fNLongClusters[iSegment];
695 // just for debugging, remove me
696 fTotalTracks += cal->fTotalTracks;
697 fAcceptedTracks += cal->fAcceptedTracks;
698 fDebugCalPadRaw->Add(cal->fDebugCalPadRaw);
699 fDebugCalPadCorr->Add(cal->fDebugCalPadCorr);
703 void AliTPCcalibTracksGain::AddTrack(AliTPCseed* seed) {
705 // The clusters making up the track (seed) are added to various fit functions.
706 // See AddCluster(...) for more detail.
711 // simple histograming part
712 for (Int_t i=0; i<159; i++){
713 AliTPCclusterMI* cluster = seed->GetClusterPointer(i);
714 if (cluster) AddCluster(cluster);
718 void AliTPCcalibTracksGain::AddCluster(AliTPCclusterMI* cluster){
720 // Adding cluster information to the simple histograms
721 // No correction, fittings are applied
724 Float_t kThreshold=5;
725 if (cluster->GetX()<=0) return;
726 if (cluster->GetQ()<=kThreshold) return;
729 Int_t sector = cluster->GetDetector();
732 if (his) his->Fill(GetQNorm(cluster));
734 if (his) his->Fill(GetQNorm(cluster));
736 if (his) his->Fill(GetMaxNorm(cluster));
738 if (his) his->Fill(GetMaxNorm(cluster));
742 prof = GetProfileQT(sector);
743 if (prof) prof->Fill(cluster->GetX(),GetQNorm(cluster));
744 prof = GetProfileQT(-1);
745 if (prof) prof->Fill(cluster->GetX(),GetQNorm(cluster));
746 prof = GetProfileQM(sector);
747 if (prof) prof->Fill(cluster->GetX(),GetMaxNorm(cluster));
748 prof = GetProfileQM(-1);
749 if (prof) prof->Fill(cluster->GetX(),GetMaxNorm(cluster));
751 Float_t phi = cluster->GetY()/cluster->GetX();
753 prof2 = GetProfileQT2D(sector);
754 if (prof2) prof2->Fill(cluster->GetX(),phi,GetQNorm(cluster));
755 prof2 = GetProfileQT2D(-1);
756 if (prof2) prof2->Fill(cluster->GetX(),phi,GetQNorm(cluster));
757 prof2 = GetProfileQM2D(sector);
758 if (prof2) prof2->Fill(cluster->GetX(),phi,GetMaxNorm(cluster));
759 prof2 = GetProfileQM2D(-1);
760 if (prof2) prof2->Fill(cluster->GetX(),phi,GetMaxNorm(cluster));
767 void AliTPCcalibTracksGain::AddCluster(AliTPCclusterMI* cluster, Float_t /*momenta*/, Float_t/* mdedx*/, Int_t padType,
768 Float_t xcenter, TVectorD& dedxQ, TVectorD& /*dedxM*/, Float_t /*fraction*/, Float_t fraction2, Float_t dedge,
769 TVectorD& /*parY*/, TVectorD& /*parZ*/, TVectorD& meanPos) {
771 // Adds cluster to the appropriate fitter for later analysis.
772 // The charge used for the fit is the maximum charge for this specific cluster or the
773 // accumulated charge per cluster, depending on the value of fgkUseTotalCharge.
774 // Depending on the pad size where the cluster is registered, the value will be put in
775 // the appropriate fitter. Furthermore, for each pad size three different types of fitters
776 // are used. The fit functions are the same for all fitters (parabolic functions), but the value
777 // added to each fitter is different. The simple fitter gets the charge plugged in as is, the sqrt fitter
778 // gets the square root of the charge, and the log fitter gets fgkM*(1+q/fgkM), where q is the original charge
782 Float_t kfraction = 0.7;
786 // Where to put selection on threshold?
787 // Defined by the Q/dEdxT variable - see debug streamer:
789 // Debug stream variables: (Where tu cut ?)
790 // chain0->Draw("Cl.fQ/dedxQ.fElements[1]>>his(100,0,3)","fraction2<0.6&&dedge>3","",1000000);
792 // chain0->Draw("Cl.fMax/dedxM.fElements[1]>>his(100,0,3)","fraction2<0.6&&dedge>3","",1000000)
794 // chain0->Draw("Cl.fQ/dedxQ.fElements[2]>>his(100,0,3)","fraction2<0.7&&dedge>3","",1000000)
796 // chain0->Draw("Cl.fMax/dedxM.fElements[2]>>his(100,0,3)","fraction2<0.7&&dedge>3","",1000000)
798 // chain0->Draw("Cl.fQ/dedxQ.fElements[3]>>his(100,0,3)","fraction2<0.8&&dedge>3","",1000000)
801 // chain0->Draw("Cl.fQ/dedxQ.fElements[4]>>his(100,0,3)","fraction2<0.9&&dedge>3","",1000000)
804 // Fraction choosen 0.7
807 Error("AddCluster", "Cluster not valid.");
811 if (dedge < kedge) return;
812 if (fraction2 > kfraction) return;
814 //Int_t padType = GetPadType(cluster->GetX());
816 //Double_t centerPad[2] = {0};
817 //AliTPCFitPad::GetPadRegionCenterLocal(padType, centerPad);
818 //xx[0] = cluster->GetX() - centerPad[0];
819 //xx[1] = cluster->GetY() - centerPad[1];
820 xx[0] = cluster->GetX() - xcenter;
821 xx[1] = cluster->GetY();
822 xx[2] = xx[0] * xx[0];
823 xx[3] = xx[1] * xx[1];
824 xx[4] = xx[0] * xx[1];
825 xx[5] = TMath::Abs(cluster->GetZ()) - TMath::Abs(meanPos[4]);
826 xx[6] = xx[5] * xx[5];
828 // Update profile histograms
834 Int_t segment = cluster->GetDetector() % 36;
835 Double_t q = fgkUseTotalCharge ? ((Double_t)(GetQNorm(cluster))) : ((Double_t)(GetMaxNorm(cluster))); // note: no normalization to pad size!
837 // just for debugging
840 GetRowPad(cluster->GetX(), cluster->GetY(), row, pad);
841 fDebugCalPadRaw->GetCalROC(cluster->GetDetector())->SetValue(row, pad, q + fDebugCalPadRaw->GetCalROC(cluster->GetDetector())->GetValue(row, pad));
843 // correct charge by normalising to mean charge per track
846 // just for debugging
847 fDebugCalPadCorr->GetCalROC(cluster->GetDetector())->SetValue(row, pad, q + fDebugCalPadCorr->GetCalROC(cluster->GetDetector())->GetValue(row, pad));
849 Double_t sqrtQ = TMath::Sqrt(q);
850 Double_t logQ = fgkM * TMath::Log(1 + q / fgkM);
851 TLinearFitter * fitter =0;
853 fitter = fSimpleFitter->GetFitter(segment, padType);
854 fitter->AddPoint(xx, q);
856 fitter = fSqrtFitter->GetFitter(segment, padType);
857 fitter->AddPoint(xx, sqrtQ);
859 fitter = fLogFitter->GetFitter(segment, padType);
860 fitter->AddPoint(xx, logQ);
862 fitter=fSingleSectorFitter->GetFitter(0, padType);
863 fitter->AddPoint(xx, q);
865 // this will be gone for the a new ROOT version > v5-17-05
866 if (padType == kShortPads)
867 fNShortClusters[segment]++;
868 if (padType == kMediumPads)
869 fNMediumClusters[segment]++;
870 if (padType == kLongPads)
871 fNLongClusters[segment]++;
874 void AliTPCcalibTracksGain::Evaluate(Bool_t robust, Double_t frac) {
876 // Evaluates all fitters contained in this object.
877 // If the robust option is set to kTRUE a robust fit is performed with frac as
878 // the minimal fraction of good points (see TLinearFitter::EvalRobust for details).
879 // Beware: Robust fitting is much slower!
882 fSimpleFitter->Evaluate(robust, frac);
883 fSqrtFitter->Evaluate(robust, frac);
884 fLogFitter->Evaluate(robust, frac);
885 fSingleSectorFitter->Evaluate(robust, frac);
901 AliTPCCalPad* AliTPCcalibTracksGain::CreateFitCalPad(UInt_t fitType, Bool_t undoTransformation, Bool_t normalizeToPadSize) {
903 // Creates the calibration object AliTPCcalPad using fitted parameterization
906 for (UInt_t iSector = 0; iSector < 72; iSector++)
907 tpc.Add(CreateFitCalROC(iSector, fitType, undoTransformation, normalizeToPadSize));
908 return new AliTPCCalPad(&tpc);
911 AliTPCCalROC* AliTPCcalibTracksGain::CreateFitCalROC(UInt_t sector, UInt_t fitType, Bool_t undoTransformation, Bool_t normalizeToPadSize) {
913 // Create the AliTPCCalROC with the values per pad
914 // sector - sector of interest
920 GetParameters(sector % 36, 0, fitType, par);
921 return CreateFitCalROC(sector, 0, par, fitType, undoTransformation, normalizeToPadSize);
924 GetParameters(sector % 36, 1, fitType, par);
925 AliTPCCalROC* roc1 = CreateFitCalROC(sector, 1, par, fitType, undoTransformation, normalizeToPadSize);
926 GetParameters(sector % 36, 2, fitType, par);
927 AliTPCCalROC* roc2 = CreateFitCalROC(sector, 2, par, fitType, undoTransformation, normalizeToPadSize);
928 AliTPCCalROC* roc3 = CreateCombinedCalROC(roc1, roc2);
935 AliTPCCalROC* AliTPCcalibTracksGain::CreateFitCalROC(UInt_t sector, UInt_t padType, TVectorD &fitParam, UInt_t fitType, Bool_t undoTransformation, Bool_t normalizeToPadSize) {
937 // This function is essentially a copy of AliTPCCalROC::CreateGlobalFitCalROC(...), with the
938 // modifications, that the center of the region of same pad size is used as the origin
939 // of the fit function instead of the center of the ROC.
940 // The possibility of a linear fit is removed as well because it is not needed.
941 // Only values for pads with the given pad size are calculated, the rest is 0.
942 // Set undoTransformation for undoing the transformation that was applied to the
943 // charge values before they were put into the fitter (thus allowing comparison to the original
944 // charge values). For fitType use 0 for the simple fitter, 1 for the sqrt fitter, 2 for the log fitter.
945 // If normalizeToPadSize is true, the values are normalized to the pad size.
946 // Please be aware, that you even need to specify the fitType if you want to normalize to the pad size without
947 // undoing the transformation (because normalizing involves undoing the trafo first, then normalizing, then
948 // applying the trafo again).
949 // Please note: The normalization to the pad size is a simple linear scaling with the pad length, which
950 // actually doesn't describe reality!
954 Double_t centerPad[2] = {0};
955 Float_t localXY[3] = {0};
956 AliTPCROC* tpcROC = AliTPCROC::Instance();
957 if ((padType == 0 && sector >= tpcROC->GetNInnerSector()) || (padType > 0 && sector < tpcROC->GetNInnerSector()) || sector >= tpcROC->GetNSector())
959 AliTPCCalROC* lROCfitted = new AliTPCCalROC(sector);
960 //tpcROC->GetPositionLocal(sector, lROCfitted->GetNrows()/2, lROCfitted->GetNPads(lROCfitted->GetNrows()/2)/2, centerPad); // use this instead of the switch statement if you want to calculate the center of the ROC and not the center of the regions with the same pad size
966 endRow = lROCfitted->GetNrows();
974 endRow = lROCfitted->GetNrows();
978 AliTPCFitPad::GetPadRegionCenterLocal(padType, centerPad);
980 for (UInt_t irow = startRow; irow < endRow; irow++) {
981 for (UInt_t ipad = 0; ipad < lROCfitted->GetNPads(irow); ipad++) {
982 tpcROC->GetPositionLocal(sector, irow, ipad, localXY); // calculate position localXY by pad and row number
983 dlx = localXY[0] - centerPad[0];
984 dly = localXY[1] - centerPad[1];
985 value = fitParam[0] + fitParam[1]*dlx + fitParam[2]*dly + fitParam[3]*dlx*dlx + fitParam[4]*dly*dly + fitParam[5]*dlx*dly;
987 // Let q' = value be the transformed value without any pad size corrections,
988 // let T be the transformation and let l be the pad size
989 // 1) don't undo transformation, don't normalize: return q'
990 // 2) undo transformation, don't normalize: return T^{-1} q'
991 // 3) undo transformation, normalize: return (T^{-1} q') / l
992 // 4) don't undo transformation, normalize: return T((T^{-1} q') / l)
993 if (!undoTransformation && !normalizeToPadSize) {/* value remains unchanged */} // (1)
994 else { // (2), (3), (4)
997 case 0: /* value remains unchanged */ break;
998 case 1: value = value * value; break;
999 case 2: value = (TMath::Exp(value / fgkM) - 1) * fgkM; break;
1000 default: Error("CreateFitCalROC", "Wrong fit type."); break;
1002 if (normalizeToPadSize) value /= GetPadLength(localXY[0]); // (3)
1004 if (!undoTransformation && normalizeToPadSize) { // (4)
1007 case 0: /* value remains unchanged */ break;
1008 case 1: value = TMath::Sqrt(value); break;
1009 case 2: value = fgkM * TMath::Log(1 + value / fgkM); break;
1010 default: Error("CreateFitCalROC", "Wrong fit type."); break;
1013 lROCfitted->SetValue(irow, ipad, value);
1019 AliTPCCalROC* AliTPCcalibTracksGain::CreateCombinedCalROC(const AliTPCCalROC* roc1, const AliTPCCalROC* roc2) {
1021 // Combines the medium pad size values of roc1 with the long pad size values of roc2 into a new
1022 // AliTPCCalROC. Returns a null pointer if any one of the ROCs is an IROC; issues a warning message
1023 // if the sectors of roc1 and roc2 don't match, but still continue and use the sector of roc1 as the
1024 // sector of the new ROC.
1027 if (!roc1 || !roc2) return 0;
1028 if ((Int_t)(roc1->GetSector()) < fgTPCparam->GetNInnerSector()) return 0;
1029 if ((Int_t)(roc2->GetSector()) < fgTPCparam->GetNInnerSector()) return 0;
1030 if (roc1->GetSector() != roc2->GetSector()) Warning("CreateCombinedCalROC", "Sector number mismatch.");
1031 AliTPCCalROC* roc = new AliTPCCalROC(roc1->GetSector());
1033 for (UInt_t iRow = 0; iRow < 64; iRow++) {
1034 for (UInt_t iPad = 0; iPad < roc->GetNPads(iRow); iPad++)
1035 roc->SetValue(iRow, iPad, roc1->GetValue(iRow, iPad));
1037 for (UInt_t iRow = 64; iRow < roc->GetNrows(); iRow++) {
1038 for (UInt_t iPad = 0; iPad < roc->GetNPads(iRow); iPad++)
1039 roc->SetValue(iRow, iPad, roc2->GetValue(iRow, iPad));
1044 Bool_t AliTPCcalibTracksGain::GetParameters(UInt_t segment, UInt_t padType, UInt_t fitType, TVectorD &fitParam) {
1046 // Puts the fit parameters for the specified segment (IROC & OROC), padType and fitType
1047 // into the fitParam TVectorD (which should contain 8 elements).
1048 // padType is one of kShortPads, kMediumPads, kLongPads. fitType is one of kSimpleFitter, kSqrtFitter, kLogFitter.
1049 // Note: The fitter has to be evaluated first!
1051 TLinearFitter * fitter = GetFitter(segment, padType, fitType);
1054 fitter->GetParameters(fitParam);
1057 Error("AliTPCcalibTracksGain::GetParameters",
1058 Form("Fitter%d_%d_%d not availble", segment, padType, fitType));
1064 void AliTPCcalibTracksGain::GetErrors(UInt_t segment, UInt_t padType, UInt_t fitType, TVectorD &fitError) {
1066 // Puts the fit parameter errors for the specified segment (IROC & OROC), padType and fitType
1067 // into the fitError TVectorD (which should contain 8 elements).
1068 // padType is one of kShortPads, kMediumPads, kLongPads. fitType is one of kSimpleFitter, kSqrtFitter, kLogFitter.
1069 // Note: The fitter has to be evaluated first!
1072 GetFitter(segment, padType, fitType)->GetErrors(fitError);
1073 fitError *= TMath::Sqrt(GetRedChi2(segment, padType, fitType));
1076 Double_t AliTPCcalibTracksGain::GetRedChi2(UInt_t segment, UInt_t padType, UInt_t fitType) {
1078 // Returns the reduced chi^2 value for the specified segment, padType and fitType.
1079 // padType is one of kShortPads, kMediumPads, kLongPads. fitType is one of kSimpleFitter, kSqrtFitter, kLogFitter.
1080 // Note: The fitter has to be evaluated first!
1083 // this will be gone for the a new ROOT version > v5-17-05
1084 Int_t lNClusters = 0;
1087 lNClusters = fNShortClusters[segment];
1090 lNClusters = fNMediumClusters[segment];
1093 lNClusters = fNLongClusters[segment];
1096 return GetFitter(segment, padType, fitType)->GetChisquare()/(lNClusters - 8);
1099 void AliTPCcalibTracksGain::GetCovarianceMatrix(UInt_t segment, UInt_t padType, UInt_t fitType, TMatrixD& covMatrix) {
1101 // Returns the covariance matrix for the specified segment, padType, fitType.
1102 // padType is one of kShortPads, kMediumPads, kLongPads. fitType is one of kSimpleFitter, kSqrtFitter, kLogFitter.
1105 GetFitter(segment, padType, fitType)->GetCovarianceMatrix(covMatrix);
1108 TLinearFitter* AliTPCcalibTracksGain::GetFitter(UInt_t segment, UInt_t padType, UInt_t fitType) {
1110 // Returns the TLinearFitter object for the specified segment, padType, fitType.
1111 // padType is one of kShortPads, kMediumPads, kLongPads. fitType is one of kSimpleFitter, kSqrtFitter, kLogFitter.
1116 return fSimpleFitter->GetFitter(segment, padType);
1118 return fSqrtFitter->GetFitter(segment, padType);
1120 return fLogFitter->GetFitter(segment, padType);
1122 return fSingleSectorFitter->GetFitter(0, padType);
1127 Double_t AliTPCcalibTracksGain::GetPadLength(Double_t lx) {
1129 // The function returns 0.75 for an IROC, 1. for an OROC at medium pad size position,
1130 // 1.5 for an OROC at long pad size position, -1 if out of bounds.
1133 Double_t irocLow = fgTPCparam->GetPadRowRadiiLow(0) - fgTPCparam->GetInnerPadPitchLength()/2;
1134 Double_t irocUp = fgTPCparam->GetPadRowRadiiLow(fgTPCparam->GetNRowLow()-1) + fgTPCparam->GetInnerPadPitchLength()/2;
1135 Double_t orocLow1 = fgTPCparam->GetPadRowRadiiUp(0) - fgTPCparam->GetOuter1PadPitchLength()/2;
1136 Double_t orocUp1 = fgTPCparam->GetPadRowRadiiUp(fgTPCparam->GetNRowUp1()-1) + fgTPCparam->GetOuter1PadPitchLength()/2;
1137 Double_t orocLow2 = fgTPCparam->GetPadRowRadiiUp(fgTPCparam->GetNRowUp1()) - fgTPCparam->GetOuter2PadPitchLength()/2;
1138 Double_t orocUp2 = fgTPCparam->GetPadRowRadiiUp(fgTPCparam->GetNRowUp()-1) + fgTPCparam->GetOuter2PadPitchLength()/2;
1141 if (lx >= irocLow && lx <= irocUp) return 0.75;
1142 // if OROC medium pads
1143 if (lx >= orocLow1 && lx <= orocUp1) return 1.;
1144 // if OROC long pads
1145 if (lx >= orocLow2 && lx <= orocUp2) return 1.5;
1150 Int_t AliTPCcalibTracksGain::GetPadType(Double_t lx) {
1152 // The function returns 0 for an IROC, 1 for an OROC at medium pad size position,
1153 // 2 for an OROC at long pad size position, -1 if out of bounds.
1156 if (GetPadLength(lx) == 0.75) return 0;
1157 else if (GetPadLength(lx) == 1.) return 1;
1158 else if (GetPadLength(lx) == 1.5) return 2;
1162 // ONLY FOR DEBUGGING PURPOSES - REMOVE ME WHEN NOT NEEDED ANYMORE
1163 Bool_t AliTPCcalibTracksGain::GetRowPad(Double_t lx, Double_t ly, Int_t& row, Int_t& pad) {
1165 // Calculate the row and pad number when the local coordinates are given.
1166 // Returns kFALSE if the position is out of range, otherwise return kTRUE.
1167 // WARNING: This function is preliminary and probably isn't very accurate!!
1170 Double_t irocLow = fgTPCparam->GetPadRowRadiiLow(0) - fgTPCparam->GetInnerPadPitchLength()/2;
1171 //Double_t irocUp = fgTPCparam->GetPadRowRadiiLow(fgTPCparam->GetNRowLow()-1) + fgTPCparam->GetInnerPadPitchLength()/2;
1172 Double_t orocLow1 = fgTPCparam->GetPadRowRadiiUp(0) - fgTPCparam->GetOuter1PadPitchLength()/2;
1173 //Double_t orocUp1 = fgTPCparam->GetPadRowRadiiUp(fgTPCparam->GetNRowUp1()-1) + fgTPCparam->GetOuter1PadPitchLength()/2;
1174 Double_t orocLow2 = fgTPCparam->GetPadRowRadiiUp(fgTPCparam->GetNRowUp1()) - fgTPCparam->GetOuter2PadPitchLength()/2;
1175 //Double_t orocUp2 = fgTPCparam->GetPadRowRadiiUp(fgTPCparam->GetNRowUp()-1) + fgTPCparam->GetOuter2PadPitchLength()/2;
1177 if (GetPadType(lx) == 0) {
1178 row = (Int_t)((lx - irocLow) / fgTPCparam->GetInnerPadPitchLength());
1179 pad = (Int_t)((ly + fgTPCparam->GetYInner(row)) / fgTPCparam->GetInnerPadPitchWidth());
1180 } else if (GetPadType(lx) == 1) {
1181 row = (Int_t)((lx - orocLow1) / fgTPCparam->GetOuter1PadPitchLength());
1182 pad = (Int_t)((ly + fgTPCparam->GetYOuter(row)) / fgTPCparam->GetOuterPadPitchWidth());
1183 } else if (GetPadType(lx) == 2) {
1184 row = fgTPCparam->GetNRowUp1() + (Int_t)((lx - orocLow2) / fgTPCparam->GetOuter2PadPitchLength());
1185 pad = (Int_t)((ly + fgTPCparam->GetYOuter(row)) / fgTPCparam->GetOuterPadPitchWidth());
1191 void AliTPCcalibTracksGain::DumpTrack(AliTPCseed* track) {
1193 // Dump track information to the debug stream
1203 TVectorD meanPos[3];
1206 for (Int_t ipad = 0; ipad < 3; ipad++) {
1207 dedxM[ipad].ResizeTo(5);
1208 dedxQ[ipad].ResizeTo(5);
1209 parY[ipad].ResizeTo(3);
1210 parZ[ipad].ResizeTo(3);
1211 meanPos[ipad].ResizeTo(6);
1212 Bool_t isOK = GetDedx(track, ipad, rows, sector[ipad], npoints[ipad], dedxM[ipad], dedxQ[ipad], parY[ipad], parZ[ipad], meanPos[ipad]);
1214 AddTracklet(sector[ipad],ipad, dedxQ[ipad], dedxM[ipad], parY[ipad], parZ[ipad], meanPos[ipad] );
1218 TTreeSRedirector * cstream = GetDebugStreamer();
1220 (*cstream) << "Track" <<
1221 "Track.=" << track << // track information
1226 if ( GetStreamLevel()>1 && count>1){
1227 (*cstream) << "TrackG" <<
1228 "Track.=" << track << // track information
1230 // info for pad type 0
1231 "sector0="<<sector[0]<<
1232 "npoints0="<<npoints[0]<<
1233 "dedxM0.="<<&dedxM[0]<<
1234 "dedxQ0.="<<&dedxQ[0]<<
1235 "parY0.="<<&parY[0]<<
1236 "parZ0.="<<&parZ[0]<<
1237 "meanPos0.="<<&meanPos[0]<<
1239 // info for pad type 1
1240 "sector1="<<sector[1]<<
1241 "npoints1="<<npoints[1]<<
1242 "dedxM1.="<<&dedxM[1]<<
1243 "dedxQ1.="<<&dedxQ[1]<<
1244 "parY1.="<<&parY[1]<<
1245 "parZ1.="<<&parZ[1]<<
1246 "meanPos1.="<<&meanPos[1]<<
1248 // info for pad type 2
1249 "sector2="<<sector[2]<<
1250 "npoints2="<<npoints[2]<<
1251 "dedxM2.="<<&dedxM[2]<<
1252 "dedxQ2.="<<&dedxQ[2]<<
1253 "parY2.="<<&parY[2]<<
1254 "parZ2.="<<&parZ[2]<<
1255 "meanPos2.="<<&meanPos[2]<<
1262 Bool_t AliTPCcalibTracksGain::GetDedx(AliTPCseed* track, Int_t padType, Int_t* /*rows*/,
1263 Int_t §or, Int_t& npoints,
1264 TVectorD &dedxM, TVectorD &dedxQ,
1265 TVectorD &parY, TVectorD &parZ, TVectorD&meanPos)
1268 // GetDedx for given sector for given track
1269 // padType - type of pads
1272 static TLinearFitter fitY(2, "pol1");
1273 static TLinearFitter fitZ(2, "pol1");
1274 fitY.StoreData(kFALSE);
1275 fitZ.StoreData(kFALSE);
1278 Int_t firstRow = 0, lastRow = 0;
1280 Float_t xcenter = 0;
1281 const Float_t ktany = TMath::Tan(TMath::DegToRad() * 10);
1282 const Float_t kedgey = 4.;
1285 lastRow = fgTPCparam->GetNRowLow();
1289 firstRow = fgTPCparam->GetNRowLow();
1290 lastRow = fgTPCparam->GetNRowLow() + fgTPCparam->GetNRowUp1();
1294 firstRow = fgTPCparam->GetNRowLow() + fgTPCparam->GetNRowUp1();
1295 lastRow = fgTPCparam->GetNRowLow() + fgTPCparam->GetNRowUp();
1298 minRow = (lastRow - firstRow) / 2;
1301 Int_t nclusters = 0;
1302 Int_t nclustersNE = 0; // number of not edge clusters
1303 Int_t lastSector = -1;
1304 Float_t amplitudeQ[100];
1305 Float_t amplitudeM[100];
1313 for (Int_t iCluster = firstRow; iCluster < lastRow; iCluster++) {
1314 AliTPCclusterMI* cluster = track->GetClusterPointer(iCluster);
1316 Int_t detector = cluster->GetDetector() ;
1317 if (lastSector == -1) lastSector = detector;
1318 if (lastSector != detector) continue;
1319 amplitudeQ[nclusters] = GetQNorm(cluster);
1320 amplitudeM[nclusters] = GetMaxNorm(cluster);
1321 rowIn[nclusters] = iCluster;
1323 Double_t dx = cluster->GetX() - xcenter;
1324 Double_t y = cluster->GetY();
1325 Double_t z = cluster->GetZ();
1326 fitY.AddPoint(&dx, y);
1327 fitZ.AddPoint(&dx, z);
1334 if (TMath::Abs(cluster->GetY()) < cluster->GetX()*ktany - kedgey) nclustersNE++;
1338 if (nclusters < minRow / 2) return kFALSE;
1339 if (nclustersNE < minRow / 2) return kFALSE;
1340 for (Int_t i = 0; i < 6; i++) meanPos[i] /= Double_t(nclusters);
1343 fitY.GetParameters(parY);
1344 fitZ.GetParameters(parZ);
1346 // calculate truncated mean
1348 TMath::Sort(nclusters, amplitudeQ, index, kFALSE);
1353 for (Int_t i = 0; i < 5; i++) {
1362 for (Int_t i = 0; i < nclusters; i++) {
1363 Int_t rowSorted = rowIn[index[i]];
1364 AliTPCclusterMI* cluster = track->GetClusterPointer(rowSorted);
1366 if (TMath::Abs(cluster->GetY()) > cluster->GetX()*ktany - kedgey) continue; //don't take edge clusters
1368 if (inonEdge < nclustersNE * 0.5) {
1370 dedxQ[0] += amplitudeQ[index[i]];
1371 dedxM[0] += amplitudeM[index[i]];
1373 if (inonEdge < nclustersNE * 0.6) {
1375 dedxQ[1] += amplitudeQ[index[i]];
1376 dedxM[1] += amplitudeM[index[i]];
1378 if (inonEdge < nclustersNE * 0.7) {
1380 dedxQ[2] += amplitudeQ[index[i]];
1381 dedxM[2] += amplitudeM[index[i]];
1383 if (inonEdge < nclustersNE * 0.8) {
1385 dedxQ[3] += amplitudeQ[index[i]];
1386 dedxM[3] += amplitudeM[index[i]];
1388 if (inonEdge < nclustersNE * 0.9) {
1390 dedxQ[4] += amplitudeQ[index[i]];
1391 dedxM[4] += amplitudeM[index[i]];
1394 for (Int_t i = 0; i < 5; i++) {
1395 dedxQ[i] /= ndedx[i];
1396 dedxM[i] /= ndedx[i];
1398 TTreeSRedirector * cstream = GetDebugStreamer();
1400 Float_t momenta = track->GetP();
1401 Float_t mdedx = track->GetdEdx();
1402 for (Int_t i = 0; i < nclusters; i++) {
1403 Int_t rowSorted = rowIn[index[i]];
1404 AliTPCclusterMI* cluster = track->GetClusterPointer(rowSorted);
1406 printf("Problem\n");
1409 if (TMath::Abs(cluster->GetY()) < cluster->GetX()*ktany - kedgey) inonEdge++;
1410 Float_t dedge = cluster->GetX()*ktany - TMath::Abs(cluster->GetY());
1411 Float_t fraction = Float_t(i) / Float_t(nclusters);
1412 Float_t fraction2 = Float_t(inonEdge) / Float_t(nclustersNE);
1414 AddCluster(cluster, momenta, mdedx, padType, xcenter, dedxQ, dedxM, fraction, fraction2, dedge, parY, parZ, meanPos);
1415 Float_t gain = GetGain(cluster);
1416 if (cstream) (*cstream) << "dEdx" <<
1417 "Cl.=" << cluster << // cluster of interest
1418 "gain="<<gain<< // gain at cluster position
1419 "P=" << momenta << // track momenta
1420 "dedx=" << mdedx << // mean dedx - corrected for angle
1421 "IPad=" << padType << // pad type 0..2
1422 "xc=" << xcenter << // x center of chamber
1423 "dedxQ.=" << &dedxQ << // dedxQ - total charge
1424 "dedxM.=" << &dedxM << // dedxM - maximal charge
1425 "fraction=" << fraction << // fraction - order in statistic (0,1)
1426 "fraction2=" << fraction2 << // fraction - order in statistic (0,1)
1427 "dedge=" << dedge << // distance to the edge
1428 "parY.=" << &parY << // line fit
1429 "parZ.=" << &parZ << // line fit
1430 "meanPos.=" << &meanPos << // mean position (dx, dx^2, y,y^2, z, z^2)
1434 if (cstream) (*cstream) << "dEdxT" <<
1435 "P=" << momenta << // track momenta
1436 "npoints="<<inonEdge<< // number of points
1437 "sector="<<lastSector<< // sector number
1438 "dedx=" << mdedx << // mean dedx - corrected for angle
1439 "IPad=" << padType << // pad type 0..2
1440 "xc=" << xcenter << // x center of chamber
1441 "dedxQ.=" << &dedxQ << // dedxQ - total charge
1442 "dedxM.=" << &dedxM << // dedxM - maximal charge
1443 "parY.=" << &parY << // line fit
1444 "parZ.=" << &parZ << // line fit
1445 "meanPos.=" << &meanPos << // mean position (dx, dx^2, y,y^2, z, z^2)
1448 sector = lastSector;
1453 void AliTPCcalibTracksGain::AddTracklet(UInt_t sector, UInt_t padType,TVectorD &dedxQ, TVectorD &dedxM,TVectorD& parY, TVectorD& parZ, TVectorD& meanPos){
1455 // Add measured point - dedx to the fitter
1458 //chain->SetAlias("dr","(250-abs(meanPos.fElements[4]))/250");
1459 //chain->SetAlias("tz","(0+abs(parZ.fElements[1]))");
1460 //chain->SetAlias("ty","(0+abs(parY.fElements[1]))");
1461 //chain->SetAlias("corrg","sqrt((1+ty^2)*(1+tz^2))");
1462 //expession fast - TString *strq0 = toolkit.FitPlane(chain,"dedxQ.fElements[2]","dr++ty++tz++dr*ty++dr*tz++ty*tz++ty^2++tz^2","IPad==0",chi2,npoints,param,covar,0,100000);
1466 // z and angular part
1469 xxx[0] = (250.-TMath::Abs(meanPos[4]))/250.;
1470 xxx[1] = TMath::Abs(parY[1]);
1471 xxx[2] = TMath::Abs(parZ[1]);
1472 xxx[3] = xxx[0]*xxx[1];
1473 xxx[4] = xxx[0]*xxx[2];
1474 xxx[5] = xxx[1]*xxx[2];
1475 xxx[6] = xxx[0]*xxx[0];
1476 xxx[7] = xxx[1]*xxx[1];
1477 xxx[8] = xxx[2]*xxx[2];
1481 Int_t tsector = sector%36;
1482 for (Int_t i=0;i<35;i++){
1483 xxx[9+i]=(i==tsector)?1:0;
1485 TLinearFitter *fitterM = fFitter0M;
1486 if (padType==1) fitterM=fFitter1M;
1487 if (padType==2) fitterM=fFitter2M;
1488 fitterM->AddPoint(xxx,dedxM[1]);
1490 TLinearFitter *fitterT = fFitter0T;
1491 if (padType==1) fitterT = fFitter1T;
1492 if (padType==2) fitterT = fFitter2T;
1493 fitterT->AddPoint(xxx,dedxQ[1]);
1495 TLinearFitter *dfitterM = fDFitter0M;
1496 if (padType==1) dfitterM=fDFitter1M;
1497 if (padType==2) dfitterM=fDFitter2M;
1498 dfitterM->AddPoint(xxx,dedxM[1]);
1500 TLinearFitter *dfitterT = fDFitter0T;
1501 if (padType==1) dfitterT = fDFitter1T;
1502 if (padType==2) dfitterT = fDFitter2T;
1503 dfitterT->AddPoint(xxx,dedxQ[1]);
1507 TGraph *AliTPCcalibTracksGain::CreateAmpGraph(Int_t ipad, Bool_t qmax){
1509 // create the amplitude graph
1510 // The normalized amplitudes are extrapolated to the 0 angle (y,z) and 0 drift length
1515 if (ipad==0) fFitter0M->GetParameters(vec);
1516 if (ipad==1) fFitter1M->GetParameters(vec);
1517 if (ipad==2) fFitter2M->GetParameters(vec);
1519 if (ipad==0) fFitter0T->GetParameters(vec);
1520 if (ipad==1) fFitter1T->GetParameters(vec);
1521 if (ipad==2) fFitter2T->GetParameters(vec);
1526 for (Int_t i=0;i<35;i++){
1528 amp[i]=vec[10+i]+vec[0];
1531 Float_t mean = TMath::Mean(36,amp);
1532 for (Int_t i=0;i<36;i++){
1534 amp[i]=(amp[i]-mean)/mean;
1536 TGraph *gr = new TGraph(36,sec,amp);
1541 void AliTPCcalibTracksGain::UpdateClusterParam(AliTPCClusterParam* clparam){
1543 // SetQ normalization parameters
1545 // void SetQnorm(Int_t ipad, Int_t itype, TVectorD * norm);
1556 fDFitter0T->GetParameters(vec);
1557 clparam->SetQnorm(0,0,&vec);
1558 fDFitter1T->GetParameters(vec);
1559 clparam->SetQnorm(1,0,&vec);
1560 fDFitter2T->GetParameters(vec);
1561 clparam->SetQnorm(2,0,&vec);
1563 fDFitter0M->GetParameters(vec);
1564 clparam->SetQnorm(0,1,&vec);
1565 fDFitter1M->GetParameters(vec);
1566 clparam->SetQnorm(1,1,&vec);
1567 fDFitter2M->GetParameters(vec);
1568 clparam->SetQnorm(2,1,&vec);
1574 void AliTPCcalibTracksGain::Analyze(){
1582 TVectorD * AliTPCcalibTracksGain::MakeQPosNorm(TTree * chain0, Int_t ipad, Bool_t isMax, Int_t maxPoints, Int_t verbose){
1585 // chain0 - the tree with information -Debug stream
1589 // isMax - kFALSE - total charge param
1590 // kTRUE - Max charge param
1592 // maxPoints - number of points for fit
1601 // Make Q normalization as function of following parameters
1602 // 1 - dp - relative pad position
1603 // 2 - dt - relative time position
1604 // 3 - di - drift length (norm to 1);
1605 // 4 - dq0 - Tot/Max charge
1606 // 5 - dq1 - Max/Tot charge
1607 // 6 - sy - sigma y - shape
1608 // 7 - sz - sigma z - shape
1610 // Coeficient of Taylor expansion fitted
1611 // Fit parameters returned as TVectorD
1612 // Fit parameters to be used in corresponding correction function
1613 // in AliTPCclusterParam
1616 TStatToolkit toolkit;
1621 TCut cutA("dedge>3&&fraction2<0.7");
1622 chain0->SetAlias("dp","((Cl.fPad-int(Cl.fPad)-0.5)/0.5)");
1623 chain0->SetAlias("dt","((Cl.fTimeBin-int(Cl.fTimeBin)-0.5)/0.5)");
1624 chain0->SetAlias("di","(sqrt(1.-abs(Cl.fZ)/250.))");
1625 chain0->SetAlias("dq0","(0.2*(Cl.fQ+2)/(Cl.fMax+2))");
1626 chain0->SetAlias("dq1","(5*(Cl.fMax+2)/(Cl.fQ+2))");
1627 chain0->SetAlias("sy","(0.32/sqrt(0.01^2+Cl.fSigmaY2))");
1628 chain0->SetAlias("sz","(0.32/sqrt(0.01^2+Cl.fSigmaZ2))");
1631 fstring+="dp++"; //1
1632 fstring+="dt++"; //2
1633 fstring+="dp*dp++"; //3
1634 fstring+="dt*dt++"; //4
1635 fstring+="dt*dt*dt++"; //5
1636 fstring+="dp*dt++"; //6
1637 fstring+="dp*dt*dt++"; //7
1638 fstring+="(dq0)++"; //8
1639 fstring+="(dq1)++"; //9
1642 fstring+="dp*dp*(di)++"; //10
1643 fstring+="dt*dt*(di)++"; //11
1644 fstring+="dp*dp*sy++"; //12
1645 fstring+="dt*sz++"; //13
1646 fstring+="dt*dt*sz++"; //14
1647 fstring+="dt*dt*dt*sz++"; //15
1649 fstring+="dp*dp*1*sy*sz++"; //16
1650 fstring+="dt*sy*sz++"; //17
1651 fstring+="dt*dt*sy*sz++"; //18
1652 fstring+="dt*dt*dt*sy*sz++"; //19
1654 fstring+="dp*dp*(dq0)++"; //20
1655 fstring+="dt*1*(dq0)++"; //21
1656 fstring+="dt*dt*(dq0)++"; //22
1657 fstring+="dt*dt*dt*(dq0)++"; //23
1659 fstring+="dp*dp*(dq1)++"; //24
1660 fstring+="dt*(dq1)++"; //25
1661 fstring+="dt*dt*(dq1)++"; //26
1662 fstring+="dt*dt*dt*(dq1)++"; //27
1665 if (isMax) var = "Cl.fMax/gain/dedxM.fElements[2]";
1666 if (!isMax) var = "Cl.fQ/gain/dedxQ.fElements[2]";
1667 TString cutP="IPad==";
1670 TString *strq0 = toolkit.FitPlane(chain0,var.Data(),fstring.Data(), cutP.Data()+cutA, chi2,npoints,fitParam,covMatrix,-1,0,maxPoints);
1674 printf("Chi2/npoints = %f",TMath::Sqrt(chi2/npoints));
1675 printf("\nFit function\n:%s\n",strq0->Data());
1677 TVectorD *vec = new TVectorD(fitParam);
1681 void AliTPCcalibTracksGain::MakeQPosNormAll(TTree * chain, AliTPCClusterParam * param, Int_t maxPoints, Int_t verbose){
1683 // Fill the content of the of the AliTPCclusterParam
1684 // with fitted values of corrections
1693 Position correction fit:
1695 TStatToolkit toolkit;
1701 TCut cutA("dedge>3&&fraction2<0.7");
1702 chain0->SetAlias("dp","((Cl.fPad-int(Cl.fPad)-0.5)/0.5)");
1703 chain0->SetAlias("dt","((Cl.fTimeBin-int(Cl.fTimeBin)-0.5)/0.5)");
1704 chain0->SetAlias("di","(sqrt(1.-abs(Cl.fZ)/250.))");
1705 chain0->SetAlias("dq0","(0.2*(Cl.fQ+2)/(Cl.fMax+2))");
1706 chain0->SetAlias("dq1","(5*(Cl.fMax+2)/(Cl.fQ+2))");
1707 chain0->SetAlias("sy","(0.2/sqrt(0.01^2+Cl.fSigmaY2))");
1708 chain0->SetAlias("sz","(0.2/sqrt(0.01^2+Cl.fSigmaZ2))");
1712 fstring+="dp++"; //1
1713 fstring+="dt++"; //2
1714 fstring+="dp*dp++"; //3
1715 fstring+="dt*dt++"; //4
1716 fstring+="dt*dt*dt++"; //5
1717 fstring+="dp*dt++"; //6
1718 fstring+="dp*dt*dt++"; //7
1719 fstring+="(dq0)++"; //8
1720 fstring+="(dq1)++"; //9
1723 fstring+="dp*dp*(di)++"; //10
1724 fstring+="dt*dt*(di)++"; //11
1725 fstring+="dp*dp*sy++"; //12
1726 fstring+="dt*sz++"; //13
1727 fstring+="dt*dt*sz++"; //14
1728 fstring+="dt*dt*dt*sz++"; //15
1730 fstring+="dp*dp*1*sy*sz++"; //16
1731 fstring+="dt*sy*sz++"; //17
1732 fstring+="dt*dt*sy*sz++"; //18
1733 fstring+="dt*dt*dt*sy*sz++"; //19
1735 fstring+="dp*dp*(dq0)++"; //20
1736 fstring+="dt*1*(dq0)++"; //21
1737 fstring+="dt*dt*(dq0)++"; //22
1738 fstring+="dt*dt*dt*(dq0)++"; //23
1740 fstring+="dp*dp*(dq1)++"; //24
1741 fstring+="dt*(dq1)++"; //25
1742 fstring+="dt*dt*(dq1)++"; //26
1743 fstring+="dt*dt*dt*(dq1)++"; //27
1746 TString *strq0 = toolkit.FitPlane(chain0,"Cl.fMax/gain/dedxM.fElements[2]",fstring->Data(), "IPad==0"+cutA, chi2,npoints,fitParam,covMatrix,-1,0,200000);
1747 TString *strqt0 = toolkit.FitPlane(chain0,"Cl.fQ/gain/dedxQ.fElements[2]",fstring->Data(), "IPad==0"+cutA, chi2,npoints,fitParam,covMatrix,-1,0,200000);
1749 chain0->SetAlias("qcorM0",strq0->Data());
1750 chain0->SetAlias("qcorT0",strqt0->Data());
1751 //chain0->SetAlias("mmqcorM0","min(max(qcorM0,0.75),1.15)");
1752 chain0->Draw("(Cl.fMax/gain/dedxM.fElements[2]):min(max(qcorM0,0.75),1.15)","IPad==0"+cutA,"prof",100000)
1757 sigma fit with shape 0.2257
1761 qmax sigma fit 0.2702
1762 qmax sigma fit+ratio 0.2638