]>
Commit | Line | Data |
---|---|---|
eaad8c01 | 1 | // |
2 | // Process ESD tracks - | |
3 | // Extract TPC tracks - write them to tree | |
4 | // | |
5 | /* | |
6 | .L AnalyzeESDtracks.C+ | |
7 | .L AliGenInfo.C+ | |
a2411279 | 8 | AnalyzeESDtracks(567); // process tracks |
eaad8c01 | 9 | // Tracks are written to the file "TPCtracks.root" |
10 | // Now yo can analyze it | |
11 | TFile fesd("AliESDs.root"); | |
12 | TTree * treeE = (TTree*)fesd.Get("esdTree"); | |
13 | TFile f("TPCtracks.root") | |
14 | TTree * tree =(TTree*)f.Get("Tracks"); | |
15 | AliComparisonDraw comp; | |
16 | comp->fTree = tree; | |
17 | ||
18 | */ | |
19 | ||
20 | // | |
21 | ||
22 | /* | |
23 | .L AnalyzeESDtracks.C+ | |
24 | .L AliGenInfo.C+ | |
25 | ||
a2411279 | 26 | //AnalyzeESDtracks(567); |
eaad8c01 | 27 | |
28 | ||
29 | TFile fesd("AliESDs.root"); | |
30 | TTree * treeE = (TTree*)fesd.Get("esdTree"); | |
31 | TFile f("TPCtracks.root") | |
32 | TTree * tree =(TTree*)f.Get("Tracks"); | |
33 | AliComparisonDraw comp; | |
34 | comp->fTree = tree; | |
35 | ||
36 | TFile fs("TPCsignal.root"); | |
37 | TTree *treeB =(TTree*)fs.Get("SignalB"); | |
38 | TTree *treeN =(TTree*)fs.Get("SignalN"); | |
39 | TTree *treeS =(TTree*)fs.Get("Signal"); | |
40 | TTree *treef =(TTree*)fs.Get("Fit"); | |
41 | ||
42 | ||
43 | FitSignals(treeB,"Max-Median>100&&RMS06<2.5") | |
44 | TFile ffit("FitSignal.root"); | |
45 | TTree * treeF = (TTree*)ffit->Get("Fit"); | |
46 | ||
47 | ||
48 | TChain chaincl("TreeR","TreeR") | |
49 | chaincl.Add("TPC.RecPoints.root/Event0/TreeR") | |
50 | chaincl.Add("TPC.RecPoints1.root/Event1/TreeR") | |
51 | chaincl.Add("TPC.RecPoints2.root/Event2/TreeR") | |
52 | chaincl.Add("TPC.RecPoints3.root/Event3/TreeR") | |
53 | ||
54 | */ | |
55 | ||
56 | ||
57 | ||
58 | #include "TObject.h" | |
59 | #include "TFile.h" | |
60 | #include "TTree.h" | |
a82f6396 | 61 | #include "TChain.h" |
eaad8c01 | 62 | #include "TBranch.h" |
63 | #include "TTreeStream.h" | |
64 | #include "TEventList.h" | |
65 | #include "TCut.h" | |
66 | #include "TFitter.h" | |
67 | #include "TMatrixD.h" | |
663296cb | 68 | #include "TRobustEstimator.h" |
eaad8c01 | 69 | |
70 | #include "AliLog.h" | |
71 | #include "AliMagF.h" | |
72 | ||
73 | #include "AliESD.h" | |
74 | #include "AliESDfriend.h" | |
75 | #include "AliESDtrack.h" | |
76 | #include "AliTracker.h" | |
77 | #include "AliTPCseed.h" | |
78 | #include "AliTPCclusterMI.h" | |
663296cb | 79 | #include "AliTPCParamSR.h" |
80 | #include "AliTPCROC.h" | |
81 | ||
82 | ||
eaad8c01 | 83 | #include "TTreeStream.h" |
84 | #include "TF1.h" | |
85 | #include "TGraph.h" | |
86 | #include "AliSignalProcesor.h" | |
87 | #include "TCanvas.h" | |
88 | ||
89 | ||
663296cb | 90 | void FitSignals(TTree * treeB, TCut cut="Max-Median>150&&RMS06<2&&abs(Median-Mean09)<0.5", Int_t maxS=100); |
ba6ac751 | 91 | void LaserCalib(TTreeSRedirector & cstream, TTree * chain, Float_t tmin, Float_t tmax, Float_t fraction=0.7); |
de31eda2 | 92 | |
a82f6396 | 93 | void AnalyzeESDtracks(Int_t run){ |
eaad8c01 | 94 | // |
95 | // output redirect | |
a2411279 | 96 | TTreeSRedirector * pcstream = new TTreeSRedirector("TPCtracks.root"); |
97 | TTreeSRedirector &cstream = *pcstream; | |
eaad8c01 | 98 | // |
99 | // dummy magnetic field | |
100 | AliMagF mag("aaa","aaa",1,1,10); | |
101 | AliTracker::SetFieldMap(&mag,kTRUE); | |
102 | TFile f("AliESDs.root"); | |
103 | TTree * tree =(TTree*)f.Get("esdTree"); | |
104 | AliESD * esd =0; | |
105 | tree->SetBranchAddress("ESD",&esd); | |
106 | AliESDfriend *evf=0; | |
107 | tree->AddFriend("esdFriendTree","AliESDfriends.root"); | |
108 | tree->SetBranchAddress("ESDfriend",&evf); | |
109 | ||
110 | Int_t nevents = tree->GetEntries(); | |
111 | TClonesArray *clusters = new TClonesArray("AliTPCclusterMI",160); | |
112 | for (Int_t irow=0; irow<160; irow++){ | |
113 | new ((*clusters)[irow]) AliTPCclusterMI; // iitial dummy clusters | |
114 | } | |
115 | ||
116 | for (Int_t ievent=0; ievent<nevents; ievent++){ | |
117 | tree->GetEntry(ievent); | |
118 | if (!esd) continue; | |
119 | if (!evf) continue; | |
120 | esd->SetESDfriend(evf); //Attach the friend to the ESD | |
121 | for (Int_t itrack =0; itrack<esd->GetNumberOfTracks(); itrack++){ | |
122 | // Int_t itrack = 0; | |
123 | if (esd->GetTrack(itrack)->GetFriendTrack()==0) continue; | |
124 | AliESDtrack * etrack = esd->GetTrack(itrack); | |
125 | AliESDfriendTrack * ftrack = (AliESDfriendTrack *)esd->GetTrack(itrack)->GetFriendTrack(); | |
126 | AliTPCseed * seed = (AliTPCseed*)(ftrack->GetCalibObject(0)); | |
127 | if (!seed) continue; | |
128 | for (Int_t irow=0; irow<160; irow++){ | |
129 | if (seed->GetClusterFast(irow)){ | |
130 | AliTPCclusterMI * cl = new ((*clusters)[irow]) AliTPCclusterMI(*(seed->GetClusterFast(irow))); | |
131 | cl->SetLabel(itrack,0); | |
132 | } | |
133 | else{ | |
134 | AliTPCclusterMI * cl = (AliTPCclusterMI*)clusters->At(irow); | |
135 | cl->SetX(0); cl->SetY(0); cl->SetZ(0); cl->SetQ(0); cl->SetLabel(-1,0); | |
136 | } | |
137 | } | |
138 | Float_t dEdx = seed->GetdEdx(); | |
139 | Float_t dEdxI = seed->CookdEdx(0.05,0.6,0,77); | |
140 | Float_t dEdxO = seed->CookdEdx(0.05,0.6,78,155); | |
141 | Int_t ncl = seed->GetNumberOfClusters(); | |
142 | cstream<<"Tracks"<< | |
143 | "Run="<<run<< | |
a82f6396 | 144 | "Ncl="<<ncl<< |
eaad8c01 | 145 | "Event="<<ievent<< |
146 | "dEdx="<<dEdx<< | |
147 | "dEdxI="<<dEdxI<< | |
148 | "dEdxO="<<dEdxO<< | |
149 | "Track.="<<seed<< | |
150 | "Etrack.="<<etrack<< | |
151 | "Cl.="<<clusters<< | |
152 | "\n"; | |
153 | } | |
154 | } | |
a2411279 | 155 | delete pcstream; |
a82f6396 | 156 | // |
157 | // Fit signal part | |
158 | // | |
159 | TFile fs("TPCsignal.root"); | |
160 | TTree *treeB =(TTree*)fs.Get("SignalB"); | |
663296cb | 161 | // |
162 | // Fit central electrode part | |
163 | // | |
164 | TTreeSRedirector * pcestream = new TTreeSRedirector("TimeRoot.root"); | |
165 | TTree * treece = (TTree*)fs.Get("Signalce"); | |
166 | if (tree) { | |
ba6ac751 | 167 | LaserCalib(*pcestream, treece, 900,1000, 0.7); |
663296cb | 168 | delete pcestream; |
169 | } | |
ba6ac751 | 170 | FitSignals(treeB,"Max-Median>150&&RMS06<1.0&&RMS09<1.5&&abs(Median-Mean09)<0.2&&abs(Mean06-Mean09)<0.2",1000); |
663296cb | 171 | // |
eaad8c01 | 172 | } |
173 | ||
174 | ||
663296cb | 175 | void FitSignals(TTree * treeB, TCut cut, Int_t max){ |
eaad8c01 | 176 | AliSignalProcesor proc; |
177 | TF1 * f1 = proc.GetAsymGauss(); | |
178 | TTreeSRedirector cstream("FitSignal.root"); | |
179 | TFile *f = cstream.GetFile(); | |
180 | ||
181 | char lname[100]; | |
182 | sprintf(lname,"Fit%s", cut.GetTitle()); | |
183 | TEventList *list = new TEventList(lname,lname); | |
184 | sprintf(lname,">>Fit%s", cut.GetTitle()); | |
185 | treeB->Draw(lname,cut); | |
186 | treeB->SetEventList(list); | |
663296cb | 187 | Int_t nFits=0; |
eaad8c01 | 188 | for (Int_t ievent=0; ievent<list->GetN(); ievent++){ |
663296cb | 189 | if (nFits>max) break; |
190 | if (nFits%50==0) printf("%d\n",nFits); | |
eaad8c01 | 191 | char ename[100]; |
192 | sprintf(ename,"Fit%d", ievent); | |
193 | Double_t nsample = treeB->Draw("Graph.fY-Mean09:Graph.fX","","",1,ievent); | |
194 | Double_t * signal = treeB->GetV1(); | |
195 | Double_t * time = treeB->GetV2(); | |
196 | Double_t maxpos =0; | |
197 | Double_t max = 0; | |
198 | for (Int_t ipos = 0; ipos<nsample; ipos++){ | |
199 | if (signal[ipos]>max){ | |
200 | max = signal[ipos]; | |
201 | maxpos = ipos; | |
202 | } | |
203 | } | |
204 | ||
205 | Int_t first = TMath::Max(maxpos-10,0.); | |
206 | Int_t last = TMath::Min(maxpos+60, nsample); | |
207 | // | |
208 | f->cd(); | |
209 | TH1F his(ename,ename,last-first,first,last); | |
210 | for (Int_t ipos=0; ipos<last-first; ipos++){ | |
211 | his.SetBinContent(ipos+1,signal[ipos+first]); | |
212 | } | |
213 | treeB->Draw("Sector:Row:Pad","","",1,ievent); | |
214 | Double_t sector = treeB->GetV1()[0]; | |
215 | Double_t row = treeB->GetV2()[0]; | |
216 | Double_t pad = treeB->GetV3()[0]; | |
217 | // TGraph graph(last-first,&time[first],&signal[first]); | |
218 | f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2); | |
219 | // TH1F * his = (TH1F*)graph.GetHistogram(); | |
220 | his.Fit(f1,"q"); | |
221 | his.Write(ename); | |
222 | gPad->Clear(); | |
223 | his.Draw(); | |
224 | gPad->Update(); | |
225 | Double_t params[6]; | |
226 | for (Int_t ipar=0; ipar<6; ipar++) params[ipar] = f1->GetParameters()[ipar]; | |
227 | Double_t chi2 = TFitter::GetFitter()->Chisquare(6,params); | |
228 | TMatrixD cov(6,6); | |
229 | cov.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix()); | |
230 | // | |
231 | // tail cancellation | |
232 | // | |
233 | Double_t x0[1000]; | |
234 | Double_t x1[1000]; | |
235 | Double_t x2[1000]; | |
236 | for (Int_t ipos=0; ipos<last-first; ipos++){ | |
237 | x0[ipos] = signal[ipos+first]; | |
238 | } | |
239 | proc.TailCancelationALTRO1(x0,x1,0.85*0.339,0.09,last-first); | |
240 | proc.TailCancelationALTRO1(x1,x2,0.85,0.789,last-first); | |
241 | // | |
242 | sprintf(ename,"Cancel1_%d", ievent); | |
243 | TH1F his1(ename,ename,last-first,first,last); | |
244 | for (Int_t ipos=0; ipos<last-first; ipos++){ | |
245 | his1.SetBinContent(ipos+1,x1[ipos]); | |
246 | } | |
247 | his1.Write(ename); | |
248 | sprintf(ename,"Cancel2_%d", ievent); | |
249 | TH1F his2(ename,ename,last-first,first,last); | |
250 | for (Int_t ipos=0; ipos<last-first; ipos++){ | |
251 | his2.SetBinContent(ipos+1,x1[ipos]); | |
252 | } | |
253 | f1->SetParameters(0.75*max,maxpos,1.1,0.8,0.25,0.2); | |
254 | his2.Fit(f1,"q"); | |
255 | his2.Write(ename); | |
256 | Double_t params2[6]; | |
257 | for (Int_t ipar=0; ipar<6; ipar++) params2[ipar] = f1->GetParameters()[ipar]; | |
258 | Double_t chi22 = TFitter::GetFitter()->Chisquare(6,params2); | |
259 | TMatrixD cov2(6,6); | |
260 | cov2.SetMatrixArray(TFitter::GetFitter()->GetCovarianceMatrix()); | |
261 | ||
262 | TGraph gr0(last-first, &time[first],x0); | |
263 | TGraph gr1(last-first, &time[first],x1); | |
264 | TGraph gr2(last-first, &time[first],x2); | |
265 | // | |
266 | cstream<<"Fit"<< | |
267 | "Sector="<<sector<< | |
268 | "Row="<<row<< | |
269 | "Pad="<<pad<< | |
270 | "First="<<first<< | |
271 | "Max="<<max<< | |
272 | "MaxPos="<<maxpos<< | |
273 | "chi2="<<chi2<< | |
274 | "chi22="<<chi22<< | |
275 | "Cov="<<&cov<< | |
276 | "Cov2="<<&cov2<< | |
277 | "gr0.="<<&gr0<< | |
278 | "gr1.="<<&gr1<< | |
279 | "gr2.="<<&gr2<< | |
280 | "p0="<<params[0]<< | |
281 | "p1="<<params[1]<< | |
282 | "p2="<<params[2]<< | |
283 | "p3="<<params[3]<< | |
284 | "p4="<<params[4]<< | |
285 | "p5="<<params[5]<< | |
286 | "p02="<<params2[0]<< | |
287 | "p12="<<params2[1]<< | |
288 | "p22="<<params2[2]<< | |
289 | "p32="<<params2[3]<< | |
290 | "p42="<<params2[4]<< | |
291 | "p52="<<params2[5]<< | |
292 | "\n"; | |
293 | // delete his; | |
663296cb | 294 | nFits++; |
eaad8c01 | 295 | } |
296 | ||
297 | } | |
a82f6396 | 298 | |
299 | ||
663296cb | 300 | void LaserCalib(TTreeSRedirector & cstream, TTree * chain, Float_t tmin, Float_t tmax, Float_t fraction){ |
301 | // | |
302 | // | |
303 | // | |
ba6ac751 | 304 | const Double_t kMaxDelta=10; |
663296cb | 305 | AliTPCParamSR param; |
306 | param.Update(); | |
307 | TFile fce("TPCsignal.root"); | |
308 | TTree * treece =(TTree*)fce.Get("Signalce"); | |
309 | if (chain) treece=chain; | |
310 | // | |
311 | TBranch * brsector = treece->GetBranch("Sector"); | |
312 | TBranch * brpad = treece->GetBranch("Pad"); | |
313 | TBranch * brrow = treece->GetBranch("Row"); | |
314 | // | |
315 | TBranch * brtime = treece->GetBranch("Time"); | |
316 | TBranch * brrms = treece->GetBranch("RMS06"); | |
317 | TBranch * brmax = treece->GetBranch("Max"); | |
318 | TBranch * brsum = treece->GetBranch("Qsum"); | |
319 | ||
320 | Int_t sector, pad, row=0; | |
321 | Double_t time=0, rms=0, qMax=0, qSum=0; | |
322 | brsector->SetAddress(§or); | |
323 | brrow->SetAddress(&row); | |
324 | brpad->SetAddress(&pad); | |
325 | ||
326 | brtime->SetAddress(&time); | |
327 | brrms->SetAddress(&rms); | |
328 | brmax->SetAddress(&qMax); | |
329 | brsum->SetAddress(&qSum); | |
330 | ||
331 | ||
332 | brsector->GetEntry(0); | |
333 | // | |
334 | Int_t firstSector = sector; | |
335 | Int_t lastSector = sector; | |
336 | Int_t fentry = 0; | |
337 | Int_t lentry = 0; | |
338 | // | |
339 | // find time offset for differnt events | |
340 | // | |
341 | Int_t count = 0; | |
342 | Double_t padTimes[500000]; | |
343 | TRobustEstimator restim; | |
344 | Double_t meanS[72], sigmaS[72]; | |
345 | Int_t firstS[72], lastS[72]; | |
346 | Double_t sectorsID[72]; | |
347 | for (Int_t isector=0;isector<72; isector++){ | |
348 | firstS[isector]=-1; | |
349 | lastS[isector] =-1; | |
350 | }; | |
ba6ac751 | 351 | TH1F hisT("hisT","hisT",100,tmin,tmax); |
352 | treece->Draw("Time>>hisT",""); | |
353 | Float_t cbin = hisT.GetBinCenter(hisT.GetMaximumBin()); | |
663296cb | 354 | |
355 | for (Int_t ientry=0; ientry<treece->GetEntriesFast(); ientry++){ | |
356 | treece->GetEvent(ientry); | |
357 | // | |
358 | if (sector!=lastSector && sector==firstSector){ | |
359 | //if (sector!=lastSector){ | |
360 | lentry = ientry; | |
361 | printf("\nEvent\t%d\tFirst\t%d\tLast\t%d\t%d\n",count, fentry, lentry, lentry-fentry); | |
362 | // | |
363 | // | |
364 | Int_t ngood=0; | |
365 | for (Int_t ientry2=fentry; ientry2<lentry; ientry2++){ | |
366 | // brtime->GetEvent(ientry2); | |
367 | // brsector->GetEvent(ientry2); | |
368 | treece->GetEvent(ientry2); | |
ba6ac751 | 369 | if (time>tmin&&time<tmax && TMath::Abs(time-cbin)<kMaxDelta){ |
663296cb | 370 | padTimes[ngood]=time; |
371 | ngood++; | |
372 | if (firstS[sector]<0) firstS[sector]= ngood; | |
373 | if (firstS[sector]>=0) lastS[sector] = ngood; | |
374 | } | |
375 | } | |
376 | // | |
377 | // | |
378 | Double_t mean,sigma; | |
ba6ac751 | 379 | restim.EvaluateUni(ngood,padTimes,mean, sigma,int(float(ngood)*fraction)); |
663296cb | 380 | printf("Event\t%d\t%f\t%f\n",count, mean, sigma); |
381 | for (Int_t isector=0; isector<72; isector++){ | |
382 | sectorsID[isector]=sector; | |
383 | if (firstS[isector]>=0 &&lastS[isector]>=0 && lastS[isector]>firstS[isector] ){ | |
384 | Int_t ngoodS = lastS[isector]-firstS[isector]; | |
385 | restim.EvaluateUni(ngoodS, &padTimes[firstS[isector]],meanS[isector], | |
ba6ac751 | 386 | sigmaS[isector],int(float(ngoodS)*fraction)); |
663296cb | 387 | } |
388 | } | |
389 | TGraph graphM(72,sectorsID,meanS); | |
390 | TGraph graphS(72,sectorsID,sigmaS); | |
391 | cstream<<"TimeS"<< | |
ba6ac751 | 392 | "CBin="<<cbin<< |
663296cb | 393 | "Event="<<count<< |
ba6ac751 | 394 | "GM="<<&graphM<< |
395 | "GS="<<&graphS<< | |
663296cb | 396 | "\n"; |
397 | ||
398 | ||
399 | for (Int_t ientry2=fentry; ientry2<lentry-1; ientry2++){ | |
400 | treece->GetEvent(ientry2); | |
401 | Double_t x = param.GetPadRowRadii(sector,row); | |
402 | Int_t maxpad = AliTPCROC::Instance()->GetNPads(sector,row); | |
403 | Double_t y = (pad - 2.5 - 0.5*maxpad)*param.GetPadPitchWidth(sector); | |
404 | Double_t alpha = TMath::DegToRad()*(10.+20.*(sector%18)); | |
405 | Double_t gx = x*TMath::Cos(alpha)-y*TMath::Sin(alpha); | |
406 | Double_t gy = y*TMath::Cos(alpha)+x*TMath::Sin(alpha); | |
407 | ||
408 | Int_t npadS = lastS[sector]-firstS[sector]; | |
409 | cstream<<"Time"<< | |
410 | "Event="<<count<< | |
ba6ac751 | 411 | "CBin="<<cbin<< |
663296cb | 412 | "x="<<x<< |
413 | "y="<<y<< | |
414 | "gx="<<gx<< | |
415 | "gy="<<gy<< | |
416 | "Sector="<<sector<< | |
417 | "Row="<<row<< | |
418 | "Pad="<<pad<< | |
419 | "Time="<<time<< | |
420 | "RMS="<<rms<< | |
421 | "Time0="<<mean<< | |
422 | "Sigma0="<<sigma<< | |
423 | "TimeS0="<<meanS[sector]<< | |
424 | "SigmaS0="<<sigmaS[sector]<< | |
425 | "npad0="<<ngood<< | |
426 | "npadS="<<npadS<< | |
427 | "Max="<<qMax<< | |
428 | "Sum="<<qSum<< | |
429 | "\n"; | |
430 | } | |
431 | treece->GetEvent(ientry); | |
432 | fentry = ientry; | |
433 | count++; | |
434 | for (Int_t isector=0;isector<72; isector++){ | |
435 | firstS[isector]=-1; | |
436 | lastS[isector] =-1; | |
437 | } | |
438 | } | |
439 | lastSector=sector; | |
440 | } | |
441 | } | |
442 | ||
443 | ||
444 | ||
a82f6396 | 445 | |
446 | TChain *MakeChainCL(Int_t first, Int_t last){ | |
447 | TChain *chaincl = new TChain("TreeR","TreeR"); | |
448 | // | |
449 | char fname[100]; | |
450 | for (Int_t i=first;i<last; i++){ | |
451 | if (i>0) sprintf(fname,"TPC.RecPoints%d.root/Event%d/TreeR",i,i); | |
452 | if (i==0) sprintf(fname,"TPC.RecPoints.root/Event%d/TreeR",i); | |
453 | chaincl->Add(fname); | |
454 | } | |
455 | return chaincl; | |
456 | } | |
457 | ||
458 | TTree* GetTree(Int_t ievent){ | |
459 | char fname[100]; | |
460 | char tname[100]; | |
461 | if (ievent>0) sprintf(fname,"TPC.RecPoints%d.root",ievent); | |
462 | if (ievent==0) sprintf(fname,"TPC.RecPoints.root"); | |
463 | sprintf(tname,"Event%d/TreeR",ievent); | |
464 | TFile * f = new TFile(fname); | |
465 | TTree * tree = (TTree*)f->Get(tname); | |
466 | return tree; | |
467 | ||
468 | } |