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