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