]>
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 | /* | |
17 | $Log$ | |
18 | Revision 1.7 2002/10/14 14:57:32 hristov | |
19 | Merging the VirtualMC branch to the main development branch (HEAD) | |
20 | ||
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 | ||
27 | Revision 1.5 2001/01/26 19:58:48 hristov | |
28 | Major upgrade of AliRoot code | |
29 | ||
30 | Revision 1.4 2001/01/17 10:50:50 hristov | |
31 | Corrections to destructors | |
32 | ||
33 | Revision 1.3 2000/12/18 14:16:31 alibrary | |
34 | HP compatibility fix | |
35 | ||
36 | Revision 1.2 2000/12/18 11:33:48 alibrary | |
37 | New call frequence histograms per module and volume | |
38 | ||
39 | Revision 1.1 2000/11/30 07:12:48 alibrary | |
40 | Introducing new Rndm and QA classes | |
41 | ||
42 | */ | |
43 | ||
44 | /////////////////////////////////////////////////////////////////////////////// | |
45 | // // | |
46 | // // | |
47 | /////////////////////////////////////////////////////////////////////////////// | |
48 | ||
49 | ||
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" | |
61 | #include "TPad.h" | |
62 | #include "TExec.h" | |
63 | #include "TPaveLabel.h" | |
64 | #include "TCanvas.h" | |
65 | ||
66 | #include "AliMCQA.h" | |
67 | #include "AliRun.h" | |
68 | #include "AliModule.h" | |
69 | #include "AliMC.h" | |
70 | ||
71 | ClassImp(AliMCQA) | |
72 | ||
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) | |
85 | { | |
86 | // | |
87 | // Default constructor | |
88 | // | |
89 | } | |
90 | ||
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) | |
123 | { | |
124 | // | |
125 | // Constructor, creates the list of lists of histograms | |
126 | // | |
127 | TList *list; | |
128 | TH1F* h; | |
129 | Int_t i; | |
130 | ||
131 | TObjArray &hist = *fQAList; | |
132 | ||
133 | char title[100]; | |
134 | // | |
135 | TObjArray &mods = *(gAlice->Modules()); | |
136 | TList *dir = gDirectory->GetList(); | |
137 | for (i=0; i<ndets; i++) { | |
138 | hist[i] = list = new TList(); | |
139 | AliModule *mod = dynamic_cast<AliModule*>(mods[i]); | |
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 | ||
164 | // | |
165 | // Global QA histograms | |
166 | // | |
167 | ||
168 | fQAHist->Add(new TH1F("hMCVcalls","Monte Carlo calls per volume", | |
169 | fNvolumes, 0.5, fNvolumes+0.5)); | |
170 | h = dynamic_cast<TH1F*>(dir->FindObject("hMCVcalls")); | |
171 | h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddVolumeName()")); | |
172 | dir->Remove(dir->FindObject("hMCVcalls")); | |
173 | // | |
174 | // Build list of volume names | |
175 | // | |
176 | for(i=0;i<fNvolumes;++i) { | |
177 | AliModule *mod = dynamic_cast<AliModule*> | |
178 | ((*gAlice->Modules())[gAlice->DetFromMate(gMC->VolId2Mate(i+1))]); | |
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)); | |
184 | h = dynamic_cast<TH1F*>(dir->FindObject("hMCMcalls")); | |
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 | // | |
191 | for(i=0;i<fNdets;++i) | |
192 | (*fModNames)[i]= | |
193 | new TNamed((dynamic_cast<AliModule*>((*gAlice->Modules())[i]))->GetName(),""); | |
194 | } | |
195 | ||
196 | //_______________________________________________________________________ | |
197 | void AliMCQA::Copy(AliMCQA &) const | |
198 | { | |
199 | Fatal("Copy ctor","Not implemented!\n"); | |
200 | } | |
201 | ||
202 | //_______________________________________________________________________ | |
203 | AliMCQA::~AliMCQA() { | |
204 | gROOT->GetListOfBrowsables()->Remove(this); | |
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 | } | |
225 | delete [] fDetDone; | |
226 | delete fMPaveLabel; | |
227 | delete fVPaveLabel; | |
228 | } | |
229 | ||
230 | //_______________________________________________________________________ | |
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 | // | |
238 | TH1 *hist; | |
239 | // | |
240 | // Global histos first | |
241 | // | |
242 | TIter global(fQAHist); | |
243 | while((hist = dynamic_cast<TH1*>(global()))) | |
244 | b->Add(hist,hist->GetTitle()); | |
245 | // | |
246 | // Module histograms now | |
247 | // | |
248 | TIter next(fQAList); | |
249 | TList *histos; | |
250 | while((histos = dynamic_cast<TList*>(next()))) { | |
251 | TIter next1(histos); | |
252 | while((hist = dynamic_cast<TH1*>(next1()))) | |
253 | b->Add(hist,hist->GetTitle()); | |
254 | } | |
255 | } | |
256 | ||
257 | //_______________________________________________________________________ | |
258 | void AliMCQA::PreTrack() | |
259 | { | |
260 | // | |
261 | // Called before each track | |
262 | // | |
263 | fOldId=-1; | |
264 | for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0; | |
265 | } | |
266 | ||
267 | //_______________________________________________________________________ | |
268 | void AliMCQA::StepManager(Int_t id) | |
269 | { | |
270 | // | |
271 | // Called at each step | |
272 | // | |
273 | TH1F *hist; | |
274 | Int_t copy; | |
275 | // | |
276 | // Fill Global histograms first | |
277 | // | |
278 | ||
279 | ||
280 | static TH1F* mcvcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCVcalls")); | |
281 | mcvcalls->Fill(gMC->CurrentVolID(copy)); | |
282 | static TH1F* mcmcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCMcalls")); | |
283 | mcmcalls->Fill(id); | |
284 | ||
285 | // | |
286 | // Now the step manager histograms | |
287 | // | |
288 | if(fOldId != id) { | |
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; | |
324 | gMC->TrackMomentum(p); | |
325 | gMC->TrackPosition(x); | |
326 | Double_t energy = TMath::Max(p[3]-mass,1.e-12); | |
327 | if(fOldId > -1) { | |
328 | if(!fDetDone[fOldId] && !gMC->IsNewTrack()) { | |
329 | TList *histold = dynamic_cast<TList*>((*fQAList)[fOldId]); | |
330 | hist = dynamic_cast<TH1F*>(histold->FindObject("hEnOut")); | |
331 | hist->Fill(TMath::Log10(energy)); | |
332 | hist = dynamic_cast<TH1F*>(histold->FindObject("hZOut")); | |
333 | hist->Fill(x[2]); | |
334 | fDetDone[fOldId]=1; | |
335 | } | |
336 | } | |
337 | if(!fDetDone[id] && !gMC->IsNewTrack()) { | |
338 | TList *histnew = dynamic_cast<TList*>((*fQAList)[id]); | |
339 | hist = dynamic_cast<TH1F*>(histnew->FindObject("hEnIn")); | |
340 | hist->Fill(TMath::Log10(energy)); | |
341 | hist = dynamic_cast<TH1F*>(histnew->FindObject("hZIn")); | |
342 | hist->Fill(x[2]); | |
343 | } | |
344 | fOldId=id; | |
345 | } | |
346 | } | |
347 | ||
348 | //_______________________________________________________________________ | |
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 | ||
363 | //_______________________________________________________________________ | |
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 | ||
378 | //_______________________________________________________________________ | |
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 | ||
399 | //_______________________________________________________________________ | |
400 | Int_t AliMCQA::GetHBin(const char* hname) | |
401 | { | |
402 | // | |
403 | // Get the bin where the cursor is | |
404 | // | |
405 | TList *dir = gDirectory->GetList(); | |
406 | TH1 *h=dynamic_cast<TH1*>(dir->FindObject(hname)); | |
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 | ||
416 | //_______________________________________________________________________ | |
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]; | |
428 | strcpy(lab,dynamic_cast<TNamed*>((*fModNames)[binx-1])->GetName()); | |
429 | fMPaveLabel->SetLabel(lab); | |
430 | ||
431 | gPad->Modified(); | |
432 | gPad->Update(); | |
433 | } | |
434 | } | |
435 | ||
436 | //_______________________________________________________________________ | |
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]; | |
448 | sprintf(lab,"%s: %s",dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetName(), | |
449 | dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetTitle()); | |
450 | fVPaveLabel->SetLabel(lab); | |
451 | ||
452 | gPad->Modified(); | |
453 | gPad->Update(); | |
454 | } | |
455 | } | |
456 | ||
457 |