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 **************************************************************************/
17 // TRD dEdx recon utils
24 // lu@physi.uni-heidelberg.de
33 #include "THnSparse.h"
37 #include "TObjArray.h"
39 #include "TStopwatch.h"
42 #include "TTreeStream.h"
45 #include "AliCDBMetaData.h"
46 #include "AliCDBStorage.h"
47 #include "AliESDEvent.h"
48 #include "AliESDfriendTrack.h"
49 #include "AliESDtrack.h"
50 #include "AliTRDcalibDB.h"
51 #include "AliTRDCalROC.h"
52 #include "AliTRDtrackV1.h"
54 #include "AliTRDdEdxBaseUtils.h"
55 #include "AliTRDdEdxReconUtils.h"
59 Int_t AliTRDdEdxReconUtils::ApplyCalib(const Int_t nc0, TVectorD *arrayQ, TVectorD *arrayX, const TObjArray *cobj)
62 //apply calibration on arrayQ
64 if(!cobj){ printf("AliTRDdEdxReconUtils::ApplyCalib error gain array null!!\n"); exit(1);}
66 TVectorD tmpq(arrayQ->GetNrows());
67 TVectorD tmpx(arrayX->GetNrows());
70 const TVectorD * gain = (TVectorD*) cobj->At(0);
71 for(Int_t ii=0; ii<nc0; ii++){
72 const Double_t dq = (*arrayQ)[ii];
73 const Int_t xx = (Int_t)(*arrayX)[ii];
74 const Double_t gg = (*gain)[xx];
91 Double_t AliTRDdEdxReconUtils::ToyCook(const Bool_t kinvq, Int_t &ncluster, TVectorD *arrayQ, TVectorD *arrayX, const TObjArray *cobj)
94 //template for cookdedx
98 ncluster = ApplyCalib(ncluster, arrayQ, arrayX, cobj);
101 printf("AliTRDdEdxReconUtils::ToyCook arrayQ arrayX null, applycalib can not be applied!\n"); exit(1);
105 Double_t lowFrac =-999, highFrac = -999;
107 lowFrac = AliTRDdEdxBaseUtils::Q1Frac(); highFrac = 0.99;
110 lowFrac = 0.01; highFrac = AliTRDdEdxBaseUtils::Q0Frac();
113 Double_t meanQ = AliTRDdEdxBaseUtils::TruncatedMean(ncluster, arrayQ->GetMatrixArray(), lowFrac, highFrac);
123 Double_t AliTRDdEdxReconUtils::CombineddEdx(const Bool_t kinvq, Int_t &concls, TVectorD *coarrayQ, TVectorD *coarrayX, const Int_t tpcncls, const TVectorD *tpcarrayQ, const TVectorD *tpcarrayX, const Int_t trdncls, const TVectorD *trdarrayQ, const TVectorD *trdarrayX)
126 //combine tpc and trd dedx
129 for(Int_t iq=0; iq<tpcncls; iq++){
130 (*coarrayQ)[iq]=(*tpcarrayQ)[iq];
131 if(tpcarrayX && trdarrayX && coarrayX){
132 (*coarrayX)[iq]=(*tpcarrayX)[iq];
135 for(Int_t iq=0; iq<trdncls; iq++){
136 (*coarrayQ)[tpcncls+iq]=(*trdarrayQ)[iq];
137 if(tpcarrayX && trdarrayX && coarrayX){
138 (*coarrayX)[tpcncls+iq]=159+(*trdarrayX)[iq];
142 concls=trdncls+tpcncls;
144 const Double_t coQ = ToyCook(kinvq, concls, coarrayQ, coarrayX);
149 Double_t AliTRDdEdxReconUtils::GetPadGain(const Int_t det, const Int_t icol, const Int_t irow)
152 //get pad calibration
154 AliTRDcalibDB* calibration = AliTRDcalibDB::Instance();
156 printf("AliTRDdEdxReconUtils::GetPadCalib No AliTRDcalibDB instance available\n"); exit(1);
158 AliTRDCalROC * calGainFactorROC = calibration->GetGainFactorROC(det);
159 if(!calGainFactorROC){
160 printf("AliTRDdEdxReconUtils::GetPadCalib no calGainFactorROC!\n"); exit(1);
163 Double_t padgain = -999;
165 icol < calGainFactorROC->GetNcols() &&
167 irow < calGainFactorROC->GetNrows()){
168 padgain = calGainFactorROC->GetValue(icol, irow);
170 printf("AliTRDdEdxReconUtils::GetPadGain padgain 0! %f %f -- %d %d %d -- %d %d\n", padgain, EPSILON, det, icol, irow, calGainFactorROC->GetNcols(), calGainFactorROC->GetNrows()); exit(1);
174 //printf("\nAliTRDdEdxReconUtils::GetPadGain warning!! indices out of range %d %d %d -- %d %d\n\n", det, icol, irow, calGainFactorROC->GetNcols(), calGainFactorROC->GetNrows() );
180 Double_t AliTRDdEdxReconUtils::GetRNDClusterQ(AliTRDcluster *cl, const Double_t baseline)
183 //get cluter q from GetRawQ, apply baseline and Kr pad-calibration
186 const Int_t det = cl->GetDetector();
187 const Int_t pad3col = cl->GetPadCol();
188 const Int_t padrow = cl->GetPadRow();
190 Double_t rndqsum = 0;
191 for(Int_t ii=0; ii<7; ii++){
192 if(cl->GetSignals()[ii] < EPSILON){//bad pad marked by electronics
196 const Int_t icol = pad3col+(ii-3);
197 const Double_t padgain = GetPadGain(det, icol, padrow);
198 if(padgain<0){//indices out of range, pad3col near boundary case
202 const Double_t rndsignal = (cl->GetSignals()[ii] - baseline )/(AliTRDdEdxBaseUtils::IsPadGainOn()? padgain : 1);
204 //sum it anyway even if signal below baseline, as long as the total is positive
205 rndqsum += rndsignal;
211 Double_t AliTRDdEdxReconUtils::GetClusterQ(const Bool_t kinvq, const AliTRDseedV1 * seed, const Int_t itb)
217 AliTRDcluster *cl = 0x0;
219 const Double_t baseline = 10;
221 //GetRNDClusterQ(cl)>0 ensures that the total sum of q is above baseline*NsignalPhysical.
222 cl = seed->GetClusters(itb); if(cl && GetRNDClusterQ(cl, baseline)>0 ) dq+= GetRNDClusterQ(cl, baseline);
223 cl = seed->GetClusters(itb+AliTRDseedV1::kNtb); if(cl && GetRNDClusterQ(cl, baseline)>0 ) dq+= GetRNDClusterQ(cl, baseline);
225 dq /= AliTRDdEdxBaseUtils::Getdldx(seed);
227 dq /= AliTRDdEdxBaseUtils::QScale();
238 Int_t AliTRDdEdxReconUtils::GetArrayClusterQ(const Bool_t kinvq, TVectorD *arrayQ, TVectorD *arrayX, const AliTRDtrackV1 *trdtrack, Int_t timeBin0, Int_t timeBin1, Int_t tstep)
242 //(if kinvq, return 1/q array), size of array must be larger than 31*6
244 if(!arrayQ || arrayQ->GetNrows()< (AliTRDseedV1::kNtb*AliTRDtrackV1::kNplane)){
245 printf("AliTRDdEdxReconUtils::GetArrayClusterQ error arrayQ null or size too small! %d\n", arrayQ? arrayQ->GetNrows() : -999); exit(1);
247 if(!arrayX || arrayX->GetNrows()< (AliTRDseedV1::kNtb*AliTRDtrackV1::kNplane)){
248 printf("AliTRDdEdxReconUtils::GetArrayClusterQ error arrayX null or size too small! %d\n", arrayX? arrayX->GetNrows() : -999); exit(1);
251 const Int_t mintb = 0;
252 const Int_t maxtb = AliTRDseedV1::kNtb-1;
253 if(timeBin0<mintb) timeBin0=mintb;
254 if(timeBin1>maxtb) timeBin1=maxtb;
255 if(tstep<=0) tstep=1;
262 for(Int_t ichamber=0; ichamber < AliTRDtrackV1::kNplane; ichamber++){
263 const AliTRDseedV1 * seed = trdtrack->GetTracklet(ichamber);
267 const Int_t det = seed->GetDetector();
269 for(Int_t itb=timeBin0; itb<=timeBin1; itb+=tstep){
270 const Double_t dq = GetClusterQ(kinvq, seed, itb);
274 const Int_t gtb = det * AliTRDseedV1::kNtb + itb;
283 for(Int_t iq=0; iq<tbN; iq++){
287 (*arrayQ)[ncls] = tbQ[iq];
288 (*arrayX)[ncls] = tbBin[iq];
293 static Int_t kprint = 100;
295 printf("\nAliTRDdEdxReconUtils::GetArrayClusterQ raw cluster-Q\n");
296 for(Int_t iq=0; iq<ncls; iq++){
297 const Int_t ichamber = AliTRDdEdxBaseUtils::ToLayer((*arrayX)[iq]);
298 const AliTRDseedV1 * seed = trdtrack->GetTracklet(ichamber);
300 printf("error seed null!!\n"); exit(1);
302 const Double_t rawq = (*arrayQ)[iq] * 45. * AliTRDdEdxBaseUtils::Getdldx(seed);
303 printf("esdid=%d; chamber=%d; timebin=%d; rawq= %.3f; myq[%d]= %e;\n", trdtrack->GetESDid(), ichamber, AliTRDdEdxBaseUtils::ToTimeBin((*arrayX)[iq]), rawq, iq, (*arrayQ)[iq]);
312 Int_t AliTRDdEdxReconUtils::UpdateArrayX(const Int_t ncls, TVectorD* arrayX)
315 //arrayX det*Ntb+itb -> itb
318 TVectorD countChamber(6);
319 for(Int_t ii = 0; ii<ncls; ii++){
320 const Int_t xx = (Int_t)(*arrayX)[ii];
321 const Int_t idet = AliTRDdEdxBaseUtils::ToDetector(xx);
323 const Double_t ich = AliTRDgeometry::GetLayer(idet);
324 const Double_t itb = AliTRDdEdxBaseUtils::ToTimeBin(xx);
325 (*arrayX)[ii] = ich*AliTRDseedV1::kNtb+itb;
327 countChamber[ich] = 1;
330 const Double_t nch = countChamber.Sum();