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