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