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