]>
Commit | Line | Data |
---|---|---|
65fb704d | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | /* | |
17 | $Log$ | |
e2afb3b6 | 18 | Revision 1.7 2002/10/14 14:57:32 hristov |
19 | Merging the VirtualMC branch to the main development branch (HEAD) | |
20 | ||
b9d0a01d | 21 | Revision 1.6.6.1 2002/10/12 21:41:00 hristov |
22 | Remove the object from the list of browsables | |
23 | ||
24 | Revision 1.6 2001/12/05 08:31:25 hristov | |
25 | Destructor corrected, thanks to R.Brun | |
26 | ||
e1b78510 | 27 | Revision 1.5 2001/01/26 19:58:48 hristov |
28 | Major upgrade of AliRoot code | |
29 | ||
2ab0c725 | 30 | Revision 1.4 2001/01/17 10:50:50 hristov |
31 | Corrections to destructors | |
32 | ||
e460afec | 33 | Revision 1.3 2000/12/18 14:16:31 alibrary |
34 | HP compatibility fix | |
35 | ||
af2e514f | 36 | Revision 1.2 2000/12/18 11:33:48 alibrary |
37 | New call frequence histograms per module and volume | |
38 | ||
8409d8c9 | 39 | Revision 1.1 2000/11/30 07:12:48 alibrary |
40 | Introducing new Rndm and QA classes | |
41 | ||
65fb704d | 42 | */ |
43 | ||
44 | /////////////////////////////////////////////////////////////////////////////// | |
45 | // // | |
46 | // // | |
47 | /////////////////////////////////////////////////////////////////////////////// | |
48 | ||
8409d8c9 | 49 | |
65fb704d | 50 | #include <strings.h> |
51 | ||
52 | #include "TObjArray.h" | |
53 | #include "TH1.h" | |
54 | #include "TList.h" | |
55 | #include "TROOT.h" | |
56 | #include "TBrowser.h" | |
57 | #include "TMath.h" | |
58 | #include "TLorentzVector.h" | |
59 | #include "TDatabasePDG.h" | |
60 | #include "TMath.h" | |
8409d8c9 | 61 | #include "TPad.h" |
62 | #include "TExec.h" | |
63 | #include "TPaveLabel.h" | |
64 | #include "TCanvas.h" | |
65fb704d | 65 | |
66 | #include "AliMCQA.h" | |
67 | #include "AliRun.h" | |
68 | #include "AliModule.h" | |
69 | #include "AliMC.h" | |
70 | ||
71 | ClassImp(AliMCQA) | |
72 | ||
e2afb3b6 | 73 | //_______________________________________________________________________ |
74 | AliMCQA::AliMCQA(): | |
75 | fNdets(0), | |
76 | fNvolumes(0), | |
77 | fQAList(0), | |
78 | fOldId(0), | |
79 | fDetDone(0), | |
80 | fQAHist(0), | |
81 | fVolNames(0), | |
82 | fModNames(0), | |
83 | fMPaveLabel(0), | |
84 | fVPaveLabel(0) | |
8409d8c9 | 85 | { |
86 | // | |
87 | // Default constructor | |
88 | // | |
89 | } | |
90 | ||
e2afb3b6 | 91 | //_______________________________________________________________________ |
92 | AliMCQA::AliMCQA(const AliMCQA &qa): | |
93 | TObject(qa), | |
94 | fNdets(0), | |
95 | fNvolumes(0), | |
96 | fQAList(0), | |
97 | fOldId(0), | |
98 | fDetDone(0), | |
99 | fQAHist(0), | |
100 | fVolNames(0), | |
101 | fModNames(0), | |
102 | fMPaveLabel(0), | |
103 | fVPaveLabel(0) | |
104 | { | |
105 | // | |
106 | // Copy constructor | |
107 | // | |
108 | qa.Copy(*this); | |
109 | } | |
110 | ||
111 | //_______________________________________________________________________ | |
112 | AliMCQA::AliMCQA(Int_t ndets): | |
113 | fNdets(ndets), | |
114 | fNvolumes(gMC->NofVolumes()), | |
115 | fQAList(new TObjArray(ndets)), | |
116 | fOldId(0), | |
117 | fDetDone(new Int_t[ndets]), | |
118 | fQAHist(new TObjArray(2)), | |
119 | fVolNames(new TObjArray(fNvolumes)), | |
120 | fModNames(new TObjArray(fNdets)), | |
121 | fMPaveLabel(0), | |
122 | fVPaveLabel(0) | |
65fb704d | 123 | { |
124 | // | |
125 | // Constructor, creates the list of lists of histograms | |
126 | // | |
127 | TList *list; | |
8409d8c9 | 128 | TH1F* h; |
af2e514f | 129 | Int_t i; |
8409d8c9 | 130 | |
65fb704d | 131 | TObjArray &hist = *fQAList; |
132 | ||
133 | char title[100]; | |
134 | // | |
135 | TObjArray &mods = *(gAlice->Modules()); | |
65fb704d | 136 | TList *dir = gDirectory->GetList(); |
af2e514f | 137 | for (i=0; i<ndets; i++) { |
65fb704d | 138 | hist[i] = list = new TList(); |
e2afb3b6 | 139 | AliModule *mod = dynamic_cast<AliModule*>(mods[i]); |
65fb704d | 140 | |
141 | // Energy Spectrum | |
142 | sprintf(title,"Spectrum entering: %s ",mod->GetName()); | |
143 | list->Add(new TH1F("hEnIn",strcat(title,mod->GetTitle()),100,-4,2)); | |
144 | dir->Remove(dir->FindObject("hEnIn")); | |
145 | ||
146 | sprintf(title,"Spectrum exiting: %s ",mod->GetName()); | |
147 | list->Add(new TH1F("hEnOut",strcat(title,mod->GetTitle()),100,-4,2)); | |
148 | dir->Remove(dir->FindObject("hEnOut")); | |
149 | ||
150 | // Z position | |
151 | sprintf(title,"Z coordinate entering: %s ",mod->GetName()); | |
152 | list->Add(new TH1F("hZIn",strcat(title,mod->GetTitle()),100, | |
153 | mod->ZMin(),mod->ZMax())); | |
154 | dir->Remove(dir->FindObject("hZIn")); | |
155 | ||
156 | sprintf(title,"Z coordinate exiting: %s ",mod->GetName()); | |
157 | list->Add(new TH1F("hZOut",strcat(title,mod->GetTitle()),100, | |
158 | mod->ZMin(),mod->ZMax())); | |
159 | dir->Remove(dir->FindObject("hZOut")); | |
160 | } | |
161 | // | |
162 | gROOT->GetListOfBrowsables()->Add(this,"AliMCQA"); | |
163 | ||
8409d8c9 | 164 | // |
165 | // Global QA histograms | |
166 | // | |
8409d8c9 | 167 | |
168 | fQAHist->Add(new TH1F("hMCVcalls","Monte Carlo calls per volume", | |
169 | fNvolumes, 0.5, fNvolumes+0.5)); | |
e2afb3b6 | 170 | h = dynamic_cast<TH1F*>(dir->FindObject("hMCVcalls")); |
8409d8c9 | 171 | h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddVolumeName()")); |
172 | dir->Remove(dir->FindObject("hMCVcalls")); | |
173 | // | |
174 | // Build list of volume names | |
175 | // | |
8409d8c9 | 176 | for(i=0;i<fNvolumes;++i) { |
e2afb3b6 | 177 | AliModule *mod = dynamic_cast<AliModule*> |
178 | ((*gAlice->Modules())[gAlice->DetFromMate(gMC->VolId2Mate(i+1))]); | |
8409d8c9 | 179 | (*fVolNames)[i]=new TNamed(gMC->VolName(i+1),mod->GetName()); |
180 | } | |
181 | ||
182 | fQAHist->Add(new TH1F("hMCMcalls","Monte Carlo calls per module", | |
183 | fNdets, -0.5, fNdets-0.5)); | |
e2afb3b6 | 184 | h = dynamic_cast<TH1F*>(dir->FindObject("hMCMcalls")); |
8409d8c9 | 185 | h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()")); |
186 | ||
187 | dir->Remove(dir->FindObject("hMCMcalls")); | |
188 | // | |
189 | // Build list of module names | |
190 | // | |
8409d8c9 | 191 | for(i=0;i<fNdets;++i) |
192 | (*fModNames)[i]= | |
e2afb3b6 | 193 | new TNamed((dynamic_cast<AliModule*>((*gAlice->Modules())[i]))->GetName(),""); |
65fb704d | 194 | } |
195 | ||
e2afb3b6 | 196 | //_______________________________________________________________________ |
197 | void AliMCQA::Copy(AliMCQA &) const | |
198 | { | |
199 | Fatal("Copy ctor","Not implemented!\n"); | |
200 | } | |
e460afec | 201 | |
e2afb3b6 | 202 | //_______________________________________________________________________ |
e460afec | 203 | AliMCQA::~AliMCQA() { |
b9d0a01d | 204 | gROOT->GetListOfBrowsables()->Remove(this); |
e460afec | 205 | if (fQAList) { |
206 | fQAList->Delete(); | |
207 | delete fQAList; | |
208 | fQAList=0; | |
209 | } | |
210 | if (fQAHist) { | |
211 | fQAHist->Delete(); | |
212 | delete fQAHist; | |
213 | fQAHist=0; | |
214 | } | |
215 | if (fVolNames) { | |
216 | fVolNames->Delete(); | |
217 | delete fVolNames; | |
218 | fVolNames=0; | |
219 | } | |
220 | if (fModNames) { | |
221 | fModNames->Delete(); | |
222 | delete fModNames; | |
223 | fModNames=0; | |
224 | } | |
e1b78510 | 225 | delete [] fDetDone; |
226 | delete fMPaveLabel; | |
227 | delete fVPaveLabel; | |
e460afec | 228 | } |
229 | ||
e2afb3b6 | 230 | //_______________________________________________________________________ |
65fb704d | 231 | void AliMCQA::Browse(TBrowser *b) |
232 | { | |
233 | // | |
234 | // Called when the item "Run" is clicked on the left pane | |
235 | // of the Root browser. | |
236 | // It displays the Root Trees and all detectors. | |
237 | // | |
8409d8c9 | 238 | TH1 *hist; |
239 | // | |
240 | // Global histos first | |
241 | // | |
242 | TIter global(fQAHist); | |
e2afb3b6 | 243 | while((hist = dynamic_cast<TH1*>(global()))) |
8409d8c9 | 244 | b->Add(hist,hist->GetTitle()); |
245 | // | |
246 | // Module histograms now | |
247 | // | |
65fb704d | 248 | TIter next(fQAList); |
249 | TList *histos; | |
e2afb3b6 | 250 | while((histos = dynamic_cast<TList*>(next()))) { |
65fb704d | 251 | TIter next1(histos); |
e2afb3b6 | 252 | while((hist = dynamic_cast<TH1*>(next1()))) |
65fb704d | 253 | b->Add(hist,hist->GetTitle()); |
65fb704d | 254 | } |
255 | } | |
256 | ||
e2afb3b6 | 257 | //_______________________________________________________________________ |
65fb704d | 258 | void AliMCQA::PreTrack() |
259 | { | |
8409d8c9 | 260 | // |
261 | // Called before each track | |
262 | // | |
65fb704d | 263 | fOldId=-1; |
264 | for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0; | |
265 | } | |
266 | ||
e2afb3b6 | 267 | //_______________________________________________________________________ |
65fb704d | 268 | void AliMCQA::StepManager(Int_t id) |
269 | { | |
8409d8c9 | 270 | // |
271 | // Called at each step | |
272 | // | |
273 | TH1F *hist; | |
274 | Int_t copy; | |
275 | // | |
276 | // Fill Global histograms first | |
277 | // | |
2ab0c725 | 278 | |
279 | ||
e2afb3b6 | 280 | static TH1F* mcvcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCVcalls")); |
2ab0c725 | 281 | mcvcalls->Fill(gMC->CurrentVolID(copy)); |
e2afb3b6 | 282 | static TH1F* mcmcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCMcalls")); |
2ab0c725 | 283 | mcmcalls->Fill(id); |
284 | ||
8409d8c9 | 285 | // |
286 | // Now the step manager histograms | |
287 | // | |
65fb704d | 288 | if(fOldId != id) { |
2ab0c725 | 289 | static Double_t mpi0=0; |
290 | static Double_t mpip=0; | |
291 | static Double_t mpim=0; | |
292 | static Double_t mep=0; | |
293 | static Double_t mem=0; | |
294 | Double_t mass=0; | |
295 | Int_t num = gMC->TrackPid(); | |
296 | ||
297 | switch (num) { | |
298 | case 111: | |
299 | if (mpi0==0) mpi0=gAlice->PDGDB()->GetParticle(num)->Mass(); | |
300 | mass=mpi0; | |
301 | break; | |
302 | case 211: | |
303 | if (mpip==0) mpip=gAlice->PDGDB()->GetParticle(num)->Mass(); | |
304 | mass=mpip; | |
305 | break; | |
306 | case -211: | |
307 | if (mpim==0) mpim=gAlice->PDGDB()->GetParticle(num)->Mass(); | |
308 | mass=mpim; | |
309 | break; | |
310 | case 11: | |
311 | if (mep==0) mep=gAlice->PDGDB()->GetParticle(num)->Mass(); | |
312 | mass=mep; | |
313 | break; | |
314 | case -11: | |
315 | if (mem==0) mem=gAlice->PDGDB()->GetParticle(num)->Mass(); | |
316 | mass=mem; | |
317 | break; | |
318 | default: | |
319 | mass =gAlice->PDGDB()->GetParticle(num)->Mass(); | |
320 | break; | |
321 | } | |
322 | ||
323 | static TLorentzVector p, x; | |
65fb704d | 324 | gMC->TrackMomentum(p); |
325 | gMC->TrackPosition(x); | |
2ab0c725 | 326 | Double_t energy = TMath::Max(p[3]-mass,1.e-12); |
65fb704d | 327 | if(fOldId > -1) { |
328 | if(!fDetDone[fOldId] && !gMC->IsNewTrack()) { | |
e2afb3b6 | 329 | TList *histold = dynamic_cast<TList*>((*fQAList)[fOldId]); |
330 | hist = dynamic_cast<TH1F*>(histold->FindObject("hEnOut")); | |
65fb704d | 331 | hist->Fill(TMath::Log10(energy)); |
e2afb3b6 | 332 | hist = dynamic_cast<TH1F*>(histold->FindObject("hZOut")); |
65fb704d | 333 | hist->Fill(x[2]); |
334 | fDetDone[fOldId]=1; | |
335 | } | |
336 | } | |
337 | if(!fDetDone[id] && !gMC->IsNewTrack()) { | |
e2afb3b6 | 338 | TList *histnew = dynamic_cast<TList*>((*fQAList)[id]); |
339 | hist = dynamic_cast<TH1F*>(histnew->FindObject("hEnIn")); | |
65fb704d | 340 | hist->Fill(TMath::Log10(energy)); |
e2afb3b6 | 341 | hist = dynamic_cast<TH1F*>(histnew->FindObject("hZIn")); |
65fb704d | 342 | hist->Fill(x[2]); |
343 | } | |
344 | fOldId=id; | |
345 | } | |
346 | } | |
8409d8c9 | 347 | |
e2afb3b6 | 348 | //_______________________________________________________________________ |
8409d8c9 | 349 | void AliMCQA::AddModuleName() |
350 | { | |
351 | // | |
352 | // Add function DrawModuleName to the module frequency histogram pad | |
353 | // | |
354 | static TVirtualPad* oldpad=0; | |
355 | if(oldpad!=gPad) { | |
356 | gPad->GetCanvas()->FeedbackMode(kTRUE); | |
357 | if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawModuleName()"); | |
358 | DrawPaveLabel(fMPaveLabel); | |
359 | oldpad=gPad; | |
360 | } | |
361 | } | |
362 | ||
e2afb3b6 | 363 | //_______________________________________________________________________ |
8409d8c9 | 364 | void AliMCQA::AddVolumeName() |
365 | { | |
366 | // | |
367 | // Add function DrawVolumeName to the volume frequency histogram pad | |
368 | // | |
369 | static TVirtualPad* oldpad=0; | |
370 | if(oldpad!=gPad) { | |
371 | gPad->GetCanvas()->FeedbackMode(kTRUE); | |
372 | if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawVolumeName()"); | |
373 | DrawPaveLabel(fVPaveLabel); | |
374 | oldpad=gPad; | |
375 | } | |
376 | } | |
377 | ||
e2afb3b6 | 378 | //_______________________________________________________________________ |
8409d8c9 | 379 | void AliMCQA::DrawPaveLabel(TPaveLabel *&pv) |
380 | { | |
381 | // | |
382 | // Draws the PaveLabel with the meaning of the bin | |
383 | // | |
384 | float uxmin = gPad->GetUxmin(); | |
385 | float uxmax = gPad->GetUxmax(); | |
386 | float uymin = gPad->GetUymin(); | |
387 | float uymax = gPad->GetUymax(); | |
388 | float lx = uxmax-uxmin; | |
389 | float ly = uymax-uymin; | |
390 | ||
391 | if(pv) delete pv; | |
392 | pv | |
393 | = new TPaveLabel(uxmin+0.05*lx,uymax-(0.05+0.1)*ly, | |
394 | uxmin+(0.05+0.2)*lx,uymax-0.05*ly, | |
395 | ""); | |
396 | pv->Draw(); | |
397 | } | |
398 | ||
e2afb3b6 | 399 | //_______________________________________________________________________ |
8409d8c9 | 400 | Int_t AliMCQA::GetHBin(const char* hname) |
401 | { | |
402 | // | |
403 | // Get the bin where the cursor is | |
404 | // | |
405 | TList *dir = gDirectory->GetList(); | |
e2afb3b6 | 406 | TH1 *h=dynamic_cast<TH1*>(dir->FindObject(hname)); |
8409d8c9 | 407 | |
408 | ||
409 | int px = gPad->GetEventX(); | |
410 | Float_t upx = gPad->AbsPixeltoX(px); | |
411 | Float_t x = gPad->PadtoX(upx); | |
412 | ||
413 | return h->GetXaxis()->FindBin(x); | |
414 | } | |
415 | ||
e2afb3b6 | 416 | //_______________________________________________________________________ |
8409d8c9 | 417 | void AliMCQA::DrawModuleName() |
418 | { | |
419 | // | |
420 | // Writes the name of the module of the bin where the cursor is | |
421 | // | |
422 | TObject *select = gPad->GetSelected(); | |
423 | if(!select) return; | |
424 | ||
425 | Int_t binx = GetHBin("hMCMcalls"); | |
426 | if(0<binx && binx<=fNdets) { | |
427 | char lab[15]; | |
e2afb3b6 | 428 | strcpy(lab,dynamic_cast<TNamed*>((*fModNames)[binx-1])->GetName()); |
8409d8c9 | 429 | fMPaveLabel->SetLabel(lab); |
430 | ||
431 | gPad->Modified(); | |
432 | gPad->Update(); | |
433 | } | |
434 | } | |
435 | ||
e2afb3b6 | 436 | //_______________________________________________________________________ |
8409d8c9 | 437 | void AliMCQA::DrawVolumeName() |
438 | { | |
439 | // | |
440 | // Writes the name of the volume:module of the bin where the cursor is | |
441 | // | |
442 | TObject *select = gPad->GetSelected(); | |
443 | if(!select) return; | |
444 | ||
445 | Int_t binx = GetHBin("hMCVcalls"); | |
446 | if(0<binx && binx<=fNvolumes) { | |
447 | char lab[20]; | |
e2afb3b6 | 448 | sprintf(lab,"%s: %s",dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetName(), |
449 | dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetTitle()); | |
8409d8c9 | 450 | fVPaveLabel->SetLabel(lab); |
451 | ||
452 | gPad->Modified(); | |
453 | gPad->Update(); | |
454 | } | |
455 | } | |
456 | ||
457 |