]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliMCQA.cxx
Adding AliMUONLog class (Laurent)
[u/mrichter/AliRoot.git] / STEER / AliMCQA.cxx
CommitLineData
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
47ClassImp(AliMCQA)
48
e2afb3b6 49//_______________________________________________________________________
50AliMCQA::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//_______________________________________________________________________
68AliMCQA::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//_______________________________________________________________________
88AliMCQA::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) {
e1d5bc9a 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 }
8409d8c9 162 }
163
164 fQAHist->Add(new TH1F("hMCMcalls","Monte Carlo calls per module",
165 fNdets, -0.5, fNdets-0.5));
e2afb3b6 166 h = dynamic_cast<TH1F*>(dir->FindObject("hMCMcalls"));
e1d5bc9a 167 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()"));
8409d8c9 168
169 dir->Remove(dir->FindObject("hMCMcalls"));
170 //
171 // Build list of module names
172 //
8409d8c9 173 for(i=0;i<fNdets;++i)
174 (*fModNames)[i]=
e2afb3b6 175 new TNamed((dynamic_cast<AliModule*>((*gAlice->Modules())[i]))->GetName(),"");
65fb704d 176}
177
e2afb3b6 178//_______________________________________________________________________
6c4904c2 179void AliMCQA::Copy(TObject &) const
e2afb3b6 180{
21bf7095 181 AliFatal("Not implemented!");
e2afb3b6 182}
e460afec 183
e2afb3b6 184//_______________________________________________________________________
116cbefd 185AliMCQA::~AliMCQA()
88cb7938 186 {
116cbefd 187 //
188 // Destructor
189 //
b9d0a01d 190 gROOT->GetListOfBrowsables()->Remove(this);
88cb7938 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
e460afec 195 if (fQAList) {
196 fQAList->Delete();
197 delete fQAList;
88cb7938 198 fQAList = 0;
e460afec 199 }
200 if (fQAHist) {
201 fQAHist->Delete();
202 delete fQAHist;
88cb7938 203 fQAHist = 0;
e460afec 204 }
205 if (fVolNames) {
206 fVolNames->Delete();
207 delete fVolNames;
88cb7938 208 fVolNames = 0;
e460afec 209 }
210 if (fModNames) {
211 fModNames->Delete();
212 delete fModNames;
88cb7938 213 fModNames = 0;
e460afec 214 }
e1b78510 215 delete [] fDetDone;
216 delete fMPaveLabel;
217 delete fVPaveLabel;
e460afec 218}
219
e2afb3b6 220//_______________________________________________________________________
65fb704d 221void 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 //
8409d8c9 228 TH1 *hist;
229 //
230 // Global histos first
231 //
232 TIter global(fQAHist);
e2afb3b6 233 while((hist = dynamic_cast<TH1*>(global())))
8409d8c9 234 b->Add(hist,hist->GetTitle());
235 //
236 // Module histograms now
237 //
65fb704d 238 TIter next(fQAList);
239 TList *histos;
e2afb3b6 240 while((histos = dynamic_cast<TList*>(next()))) {
65fb704d 241 TIter next1(histos);
e2afb3b6 242 while((hist = dynamic_cast<TH1*>(next1())))
65fb704d 243 b->Add(hist,hist->GetTitle());
65fb704d 244 }
245}
246
e2afb3b6 247//_______________________________________________________________________
65fb704d 248void AliMCQA::PreTrack()
249{
8409d8c9 250 //
251 // Called before each track
252 //
65fb704d 253 fOldId=-1;
254 for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0;
255}
256
e2afb3b6 257//_______________________________________________________________________
65fb704d 258void AliMCQA::StepManager(Int_t id)
259{
8409d8c9 260 //
261 // Called at each step
262 //
263 TH1F *hist;
264 Int_t copy;
265 //
266 // Fill Global histograms first
267 //
2ab0c725 268
269
e2afb3b6 270 static TH1F* mcvcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCVcalls"));
2ab0c725 271 mcvcalls->Fill(gMC->CurrentVolID(copy));
e2afb3b6 272 static TH1F* mcmcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCMcalls"));
2ab0c725 273 mcmcalls->Fill(id);
274
8409d8c9 275 //
276 // Now the step manager histograms
277 //
65fb704d 278 if(fOldId != id) {
2ab0c725 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;
60da8409 284 Double_t mass = 0;
2ab0c725 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:
60da8409 309 if (gAlice->PDGDB()->GetParticle(num))
310 mass = gAlice->PDGDB()->GetParticle(num)->Mass();
2ab0c725 311 break;
312 }
313
314 static TLorentzVector p, x;
65fb704d 315 gMC->TrackMomentum(p);
316 gMC->TrackPosition(x);
2ab0c725 317 Double_t energy = TMath::Max(p[3]-mass,1.e-12);
65fb704d 318 if(fOldId > -1) {
319 if(!fDetDone[fOldId] && !gMC->IsNewTrack()) {
e2afb3b6 320 TList *histold = dynamic_cast<TList*>((*fQAList)[fOldId]);
321 hist = dynamic_cast<TH1F*>(histold->FindObject("hEnOut"));
65fb704d 322 hist->Fill(TMath::Log10(energy));
e2afb3b6 323 hist = dynamic_cast<TH1F*>(histold->FindObject("hZOut"));
65fb704d 324 hist->Fill(x[2]);
325 fDetDone[fOldId]=1;
326 }
327 }
328 if(!fDetDone[id] && !gMC->IsNewTrack()) {
e2afb3b6 329 TList *histnew = dynamic_cast<TList*>((*fQAList)[id]);
330 hist = dynamic_cast<TH1F*>(histnew->FindObject("hEnIn"));
65fb704d 331 hist->Fill(TMath::Log10(energy));
e2afb3b6 332 hist = dynamic_cast<TH1F*>(histnew->FindObject("hZIn"));
65fb704d 333 hist->Fill(x[2]);
334 }
335 fOldId=id;
336 }
337}
8409d8c9 338
e2afb3b6 339//_______________________________________________________________________
8409d8c9 340void 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
e2afb3b6 354//_______________________________________________________________________
8409d8c9 355void 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
e2afb3b6 369//_______________________________________________________________________
8409d8c9 370void 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
e2afb3b6 390//_______________________________________________________________________
8409d8c9 391Int_t AliMCQA::GetHBin(const char* hname)
392{
393 //
394 // Get the bin where the cursor is
395 //
396 TList *dir = gDirectory->GetList();
e2afb3b6 397 TH1 *h=dynamic_cast<TH1*>(dir->FindObject(hname));
8409d8c9 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
e2afb3b6 407//_______________________________________________________________________
8409d8c9 408void 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];
e2afb3b6 419 strcpy(lab,dynamic_cast<TNamed*>((*fModNames)[binx-1])->GetName());
8409d8c9 420 fMPaveLabel->SetLabel(lab);
421
422 gPad->Modified();
423 gPad->Update();
424 }
425}
426
e2afb3b6 427//_______________________________________________________________________
8409d8c9 428void 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];
e2afb3b6 439 sprintf(lab,"%s: %s",dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetName(),
440 dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetTitle());
8409d8c9 441 fVPaveLabel->SetLabel(lab);
442
443 gPad->Modified();
444 gPad->Update();
445 }
446}
447
448