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>
38 #include <TPaveLabel.h>
42 #include "AliModule.h"
47 //_______________________________________________________________________
61 // Default constructor
65 //_______________________________________________________________________
66 AliMCQA::AliMCQA(const AliMCQA &qa):
85 //_______________________________________________________________________
86 AliMCQA::AliMCQA(Int_t ndets):
88 fNvolumes(gMC->NofVolumes()),
89 fQAList(new TObjArray(ndets)),
91 fDetDone(new Int_t[ndets]),
92 fQAHist(new TObjArray(2)),
93 fVolNames(new TObjArray(fNvolumes)),
94 fModNames(new TObjArray(fNdets)),
99 // Constructor, creates the list of lists of histograms
105 TObjArray &hist = *fQAList;
109 TObjArray &mods = *(gAlice->Modules());
110 TList *dir = gDirectory->GetList();
111 for (i=0; i<ndets; i++) {
112 hist[i] = list = new TList();
113 AliModule *mod = dynamic_cast<AliModule*>(mods[i]);
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"));
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"));
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"));
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"));
136 gROOT->GetListOfBrowsables()->Add(this,"AliMCQA");
139 // Global QA histograms
142 fQAHist->Add(new TH1F("hMCVcalls","Monte Carlo calls per volume",
143 fNvolumes, 0.5, fNvolumes+0.5));
144 h = dynamic_cast<TH1F*>(dir->FindObject("hMCVcalls"));
145 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddVolumeName()"));
146 dir->Remove(dir->FindObject("hMCVcalls"));
148 // Build list of volume names
150 for(i=0;i<fNvolumes;++i) {
151 AliModule *mod = dynamic_cast<AliModule*>
152 ((*gAlice->Modules())[gAlice->DetFromMate(gMC->VolId2Mate(i+1))]);
153 (*fVolNames)[i]=new TNamed(gMC->VolName(i+1),mod->GetName());
156 fQAHist->Add(new TH1F("hMCMcalls","Monte Carlo calls per module",
157 fNdets, -0.5, fNdets-0.5));
158 h = dynamic_cast<TH1F*>(dir->FindObject("hMCMcalls"));
159 h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()"));
161 dir->Remove(dir->FindObject("hMCMcalls"));
163 // Build list of module names
165 for(i=0;i<fNdets;++i)
167 new TNamed((dynamic_cast<AliModule*>((*gAlice->Modules())[i]))->GetName(),"");
170 //_______________________________________________________________________
171 void AliMCQA::Copy(AliMCQA &) const
173 Fatal("Copy ctor","Not implemented!\n");
176 //_______________________________________________________________________
182 gROOT->GetListOfBrowsables()->Remove(this);
183 //if program crashes here - it probobly means that
184 //one of added browsables was deleted and not removed previously from that list
212 //_______________________________________________________________________
213 void AliMCQA::Browse(TBrowser *b)
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.
222 // Global histos first
224 TIter global(fQAHist);
225 while((hist = dynamic_cast<TH1*>(global())))
226 b->Add(hist,hist->GetTitle());
228 // Module histograms now
232 while((histos = dynamic_cast<TList*>(next()))) {
234 while((hist = dynamic_cast<TH1*>(next1())))
235 b->Add(hist,hist->GetTitle());
239 //_______________________________________________________________________
240 void AliMCQA::PreTrack()
243 // Called before each track
246 for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0;
249 //_______________________________________________________________________
250 void AliMCQA::StepManager(Int_t id)
253 // Called at each step
258 // Fill Global histograms first
262 static TH1F* mcvcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCVcalls"));
263 mcvcalls->Fill(gMC->CurrentVolID(copy));
264 static TH1F* mcmcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCMcalls"));
268 // Now the step manager histograms
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;
277 Int_t num = gMC->TrackPid();
281 if (mpi0==0) mpi0=gAlice->PDGDB()->GetParticle(num)->Mass();
285 if (mpip==0) mpip=gAlice->PDGDB()->GetParticle(num)->Mass();
289 if (mpim==0) mpim=gAlice->PDGDB()->GetParticle(num)->Mass();
293 if (mep==0) mep=gAlice->PDGDB()->GetParticle(num)->Mass();
297 if (mem==0) mem=gAlice->PDGDB()->GetParticle(num)->Mass();
301 mass =gAlice->PDGDB()->GetParticle(num)->Mass();
305 static TLorentzVector p, x;
306 gMC->TrackMomentum(p);
307 gMC->TrackPosition(x);
308 Double_t energy = TMath::Max(p[3]-mass,1.e-12);
310 if(!fDetDone[fOldId] && !gMC->IsNewTrack()) {
311 TList *histold = dynamic_cast<TList*>((*fQAList)[fOldId]);
312 hist = dynamic_cast<TH1F*>(histold->FindObject("hEnOut"));
313 hist->Fill(TMath::Log10(energy));
314 hist = dynamic_cast<TH1F*>(histold->FindObject("hZOut"));
319 if(!fDetDone[id] && !gMC->IsNewTrack()) {
320 TList *histnew = dynamic_cast<TList*>((*fQAList)[id]);
321 hist = dynamic_cast<TH1F*>(histnew->FindObject("hEnIn"));
322 hist->Fill(TMath::Log10(energy));
323 hist = dynamic_cast<TH1F*>(histnew->FindObject("hZIn"));
330 //_______________________________________________________________________
331 void AliMCQA::AddModuleName()
334 // Add function DrawModuleName to the module frequency histogram pad
336 static TVirtualPad* oldpad=0;
338 gPad->GetCanvas()->FeedbackMode(kTRUE);
339 if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawModuleName()");
340 DrawPaveLabel(fMPaveLabel);
345 //_______________________________________________________________________
346 void AliMCQA::AddVolumeName()
349 // Add function DrawVolumeName to the volume frequency histogram pad
351 static TVirtualPad* oldpad=0;
353 gPad->GetCanvas()->FeedbackMode(kTRUE);
354 if(gPad) gPad->AddExec("ex","gAlice->GetMCQA()->DrawVolumeName()");
355 DrawPaveLabel(fVPaveLabel);
360 //_______________________________________________________________________
361 void AliMCQA::DrawPaveLabel(TPaveLabel *&pv)
364 // Draws the PaveLabel with the meaning of the bin
366 float uxmin = gPad->GetUxmin();
367 float uxmax = gPad->GetUxmax();
368 float uymin = gPad->GetUymin();
369 float uymax = gPad->GetUymax();
370 float lx = uxmax-uxmin;
371 float ly = uymax-uymin;
375 = new TPaveLabel(uxmin+0.05*lx,uymax-(0.05+0.1)*ly,
376 uxmin+(0.05+0.2)*lx,uymax-0.05*ly,
381 //_______________________________________________________________________
382 Int_t AliMCQA::GetHBin(const char* hname)
385 // Get the bin where the cursor is
387 TList *dir = gDirectory->GetList();
388 TH1 *h=dynamic_cast<TH1*>(dir->FindObject(hname));
391 int px = gPad->GetEventX();
392 Float_t upx = gPad->AbsPixeltoX(px);
393 Float_t x = gPad->PadtoX(upx);
395 return h->GetXaxis()->FindBin(x);
398 //_______________________________________________________________________
399 void AliMCQA::DrawModuleName()
402 // Writes the name of the module of the bin where the cursor is
404 TObject *select = gPad->GetSelected();
407 Int_t binx = GetHBin("hMCMcalls");
408 if(0<binx && binx<=fNdets) {
410 strcpy(lab,dynamic_cast<TNamed*>((*fModNames)[binx-1])->GetName());
411 fMPaveLabel->SetLabel(lab);
418 //_______________________________________________________________________
419 void AliMCQA::DrawVolumeName()
422 // Writes the name of the volume:module of the bin where the cursor is
424 TObject *select = gPad->GetSelected();
427 Int_t binx = GetHBin("hMCVcalls");
428 if(0<binx && binx<=fNvolumes) {
430 sprintf(lab,"%s: %s",dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetName(),
431 dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetTitle());
432 fVPaveLabel->SetLabel(lab);