1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // Quality Assurance class //
21 // Provides standard histograms for every element of the detector //
23 ///////////////////////////////////////////////////////////////////////////////
30 #include <TDatabasePDG.h>
34 #include <TLorentzVector.h>
36 #include <TObjArray.h>
37 #include <TPaveLabel.h>
39 #include <TVirtualMC.h>
44 #include "AliModule.h"
49 //_______________________________________________________________________
63 // Default constructor
67 //_______________________________________________________________________
68 AliMCQA::AliMCQA(const AliMCQA &qa):
87 //_______________________________________________________________________
88 AliMCQA::AliMCQA(Int_t ndets):
90 fNvolumes(gMC->NofVolumes()),
91 fQAList(new TObjArray(ndets)),
93 fDetDone(new Int_t[ndets]),
94 fQAHist(new TObjArray(2)),
95 fVolNames(new TObjArray(fNvolumes)),
96 fModNames(new TObjArray(fNdets)),
101 // Constructor, creates the list of lists of histograms
107 TObjArray &hist = *fQAList;
111 TObjArray &mods = *(gAlice->Modules());
112 TList *dir = gDirectory->GetList();
113 for (i=0; i<ndets; i++) {
114 hist[i] = list = new TList();
115 AliModule *mod = dynamic_cast<AliModule*>(mods[i]);
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"));
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"));
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"));
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"));
138 gROOT->GetListOfBrowsables()->Add(this,"AliMCQA");
141 // Global QA histograms
144 fQAHist->Add(new TH1F("hMCVcalls","Monte Carlo calls per volume",
145 fNvolumes, 0.5, fNvolumes+0.5));
146 h = dynamic_cast<TH1F*>(dir->FindObject("hMCVcalls"));
147 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddVolumeName()"));
148 dir->Remove(dir->FindObject("hMCVcalls"));
150 // Build list of volume names
152 AliMC * mc = gAlice->GetMCApp();
153 for(i=0;i<fNvolumes;++i) {
154 Int_t mat = gMC->VolId2Mate(i+1);
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());
160 (*fVolNames)[i] = new TNamed(gMC->VolName(i+1), "Assembly");
164 fQAHist->Add(new TH1F("hMCMcalls","Monte Carlo calls per module",
165 fNdets, -0.5, fNdets-0.5));
166 h = dynamic_cast<TH1F*>(dir->FindObject("hMCMcalls"));
167 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()"));
169 dir->Remove(dir->FindObject("hMCMcalls"));
171 // Build list of module names
173 for(i=0;i<fNdets;++i)
175 new TNamed((dynamic_cast<AliModule*>((*gAlice->Modules())[i]))->GetName(),"");
178 //_______________________________________________________________________
179 void AliMCQA::Copy(TObject &) const
181 AliFatal("Not implemented!");
184 //_______________________________________________________________________
190 gROOT->GetListOfBrowsables()->Remove(this);
191 //if program crashes here - it probobly means that
192 //one of added browsables was deleted and not removed previously from that list
220 //_______________________________________________________________________
221 void AliMCQA::Browse(TBrowser *b)
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.
230 // Global histos first
232 TIter global(fQAHist);
233 while((hist = dynamic_cast<TH1*>(global())))
234 b->Add(hist,hist->GetTitle());
236 // Module histograms now
240 while((histos = dynamic_cast<TList*>(next()))) {
242 while((hist = dynamic_cast<TH1*>(next1())))
243 b->Add(hist,hist->GetTitle());
247 //_______________________________________________________________________
248 void AliMCQA::PreTrack()
251 // Called before each track
254 for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0;
257 //_______________________________________________________________________
258 void AliMCQA::StepManager(Int_t id)
261 // Called at each step
266 // Fill Global histograms first
270 static TH1F* mcvcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCVcalls"));
271 mcvcalls->Fill(gMC->CurrentVolID(copy));
272 static TH1F* mcmcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCMcalls"));
276 // Now the step manager histograms
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;
285 Int_t num = gMC->TrackPid();
289 if (mpi0==0) mpi0=gAlice->PDGDB()->GetParticle(num)->Mass();
293 if (mpip==0) mpip=gAlice->PDGDB()->GetParticle(num)->Mass();
297 if (mpim==0) mpim=gAlice->PDGDB()->GetParticle(num)->Mass();
301 if (mep==0) mep=gAlice->PDGDB()->GetParticle(num)->Mass();
305 if (mem==0) mem=gAlice->PDGDB()->GetParticle(num)->Mass();
309 if (gAlice->PDGDB()->GetParticle(num))
310 mass = gAlice->PDGDB()->GetParticle(num)->Mass();
314 static TLorentzVector p, x;
315 gMC->TrackMomentum(p);
316 gMC->TrackPosition(x);
317 Double_t energy = TMath::Max(p[3]-mass,1.e-12);
319 if(!fDetDone[fOldId] && !gMC->IsNewTrack()) {
320 TList *histold = dynamic_cast<TList*>((*fQAList)[fOldId]);
321 hist = dynamic_cast<TH1F*>(histold->FindObject("hEnOut"));
322 hist->Fill(TMath::Log10(energy));
323 hist = dynamic_cast<TH1F*>(histold->FindObject("hZOut"));
328 if(!fDetDone[id] && !gMC->IsNewTrack()) {
329 TList *histnew = dynamic_cast<TList*>((*fQAList)[id]);
330 hist = dynamic_cast<TH1F*>(histnew->FindObject("hEnIn"));
331 hist->Fill(TMath::Log10(energy));
332 hist = dynamic_cast<TH1F*>(histnew->FindObject("hZIn"));
339 //_______________________________________________________________________
340 void AliMCQA::AddModuleName()
343 // Add function DrawModuleName to the module frequency histogram pad
345 static TVirtualPad* oldpad=0;
347 gPad->GetCanvas()->FeedbackMode(kTRUE);
348 if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawModuleName()");
349 DrawPaveLabel(fMPaveLabel);
354 //_______________________________________________________________________
355 void AliMCQA::AddVolumeName()
358 // Add function DrawVolumeName to the volume frequency histogram pad
360 static TVirtualPad* oldpad=0;
362 gPad->GetCanvas()->FeedbackMode(kTRUE);
363 if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawVolumeName()");
364 DrawPaveLabel(fVPaveLabel);
369 //_______________________________________________________________________
370 void AliMCQA::DrawPaveLabel(TPaveLabel *&pv)
373 // Draws the PaveLabel with the meaning of the bin
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;
384 = new TPaveLabel(uxmin+0.05*lx,uymax-(0.05+0.1)*ly,
385 uxmin+(0.05+0.2)*lx,uymax-0.05*ly,
390 //_______________________________________________________________________
391 Int_t AliMCQA::GetHBin(const char* hname)
394 // Get the bin where the cursor is
396 TList *dir = gDirectory->GetList();
397 TH1 *h=dynamic_cast<TH1*>(dir->FindObject(hname));
400 int px = gPad->GetEventX();
401 Float_t upx = gPad->AbsPixeltoX(px);
402 Float_t x = gPad->PadtoX(upx);
404 return h->GetXaxis()->FindBin(x);
407 //_______________________________________________________________________
408 void AliMCQA::DrawModuleName()
411 // Writes the name of the module of the bin where the cursor is
413 TObject *select = gPad->GetSelected();
416 Int_t binx = GetHBin("hMCMcalls");
417 if(0<binx && binx<=fNdets) {
419 strcpy(lab,dynamic_cast<TNamed*>((*fModNames)[binx-1])->GetName());
420 fMPaveLabel->SetLabel(lab);
427 //_______________________________________________________________________
428 void AliMCQA::DrawVolumeName()
431 // Writes the name of the volume:module of the bin where the cursor is
433 TObject *select = gPad->GetSelected();
436 Int_t binx = GetHBin("hMCVcalls");
437 if(0<binx && binx<=fNvolumes) {
439 sprintf(lab,"%s: %s",dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetName(),
440 dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetTitle());
441 fVPaveLabel->SetLabel(lab);