]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliMCQA.cxx
i) Modifying the GetInputChain function - removing the AliXMLCollection::OverlapColle...
[u/mrichter/AliRoot.git] / STEER / AliMCQA.cxx
index 0083fdd410f4b2924a525bdc6c6ef8399550bcb2..e8c15e3bb870814360ffd565d55fcec9619a130e 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.5  2001/01/26 19:58:48  hristov
-Major upgrade of AliRoot code
-
-Revision 1.4  2001/01/17 10:50:50  hristov
-Corrections to destructors
-
-Revision 1.3  2000/12/18 14:16:31  alibrary
-HP compatibility fix
-
-Revision 1.2  2000/12/18 11:33:48  alibrary
-New call frequence histograms per module and volume
-
-Revision 1.1  2000/11/30 07:12:48  alibrary
-Introducing new Rndm and QA classes
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
+// Quality Assurance class                                                   //
+// Provides standard histograms for every element of the detector            //
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
 
 #include <strings.h>
 
-#include "TObjArray.h"
-#include "TH1.h"
-#include "TList.h"
-#include "TROOT.h"
-#include "TBrowser.h"
-#include "TMath.h"
-#include "TLorentzVector.h"
-#include "TDatabasePDG.h"
-#include "TMath.h"
-#include "TPad.h"
-#include "TExec.h"
-#include "TPaveLabel.h"
-#include "TCanvas.h"
-
+#include <TBrowser.h>
+#include <TCanvas.h>
+#include <TDatabasePDG.h>
+#include <TExec.h>
+#include <TH1.h>
+#include <TList.h>
+#include <TLorentzVector.h>
+#include <TMath.h>
+#include <TObjArray.h>
+#include <TPaveLabel.h>
+#include <TROOT.h>
+#include <TVirtualMC.h>
+
+#include "AliLog.h"
+#include "AliMC.h"
 #include "AliMCQA.h"
-#include "AliRun.h"
 #include "AliModule.h"
-#include "AliMC.h"
+#include "AliRun.h"
 
 ClassImp(AliMCQA)
 
-
-//_____________________________________________________________________________
-AliMCQA::AliMCQA() : fQAList(0), fDetDone(0), fQAHist(0), fVolNames(0),
-                    fModNames(0),fMPaveLabel(0),fVPaveLabel(0)
+//_______________________________________________________________________
+AliMCQA::AliMCQA():
+  fNdets(0),
+  fNvolumes(0),
+  fQAList(0),
+  fOldId(0),
+  fDetDone(0),
+  fQAHist(0),
+  fVolNames(0),
+  fModNames(0),
+  fMPaveLabel(0),
+  fVPaveLabel(0)
 {
   //
   // Default constructor
   //
 }
 
-//_____________________________________________________________________________
-AliMCQA::AliMCQA(Int_t ndets) : fMPaveLabel(0),fVPaveLabel(0)
+//_______________________________________________________________________
+AliMCQA::AliMCQA(const AliMCQA &qa):
+  TObject(qa),
+  fNdets(0),
+  fNvolumes(0),
+  fQAList(0),
+  fOldId(0),
+  fDetDone(0),
+  fQAHist(0),
+  fVolNames(0),
+  fModNames(0),
+  fMPaveLabel(0),
+  fVPaveLabel(0)
+{
+  //
+  // Copy constructor
+  //
+  qa.Copy(*this);
+}
+
+//_______________________________________________________________________
+AliMCQA::AliMCQA(Int_t ndets):
+  fNdets(ndets),
+  fNvolumes(gMC->NofVolumes()),
+  fQAList(new TObjArray(ndets)),
+  fOldId(0),
+  fDetDone(new Int_t[ndets]),
+  fQAHist(new TObjArray(2)),
+  fVolNames(new TObjArray(fNvolumes)),
+  fModNames(new TObjArray(fNdets)),
+  fMPaveLabel(0),
+  fVPaveLabel(0)
 {
   //
   // Constructor, creates the list of lists of histograms
@@ -81,19 +104,15 @@ AliMCQA::AliMCQA(Int_t ndets) : fMPaveLabel(0),fVPaveLabel(0)
   TH1F* h;
   Int_t i;
   
-  fNdets=ndets;
-
-  fQAList = new TObjArray(ndets);
   TObjArray &hist = *fQAList;
 
   char title[100];
   //
   TObjArray &mods = *(gAlice->Modules());
-  AliModule *mod;
   TList *dir = gDirectory->GetList();
   for (i=0; i<ndets; i++) {
     hist[i] = list = new TList();
-    mod = (AliModule *) mods[i];
+    AliModule *mod = dynamic_cast<AliModule*>(mods[i]);
 
     // Energy Spectrum
     sprintf(title,"Spectrum entering: %s ",mod->GetName());
@@ -118,73 +137,87 @@ AliMCQA::AliMCQA(Int_t ndets) : fMPaveLabel(0),fVPaveLabel(0)
   //
   gROOT->GetListOfBrowsables()->Add(this,"AliMCQA");
 
-  fDetDone = new Int_t[fNdets];
-
   //
   // Global QA histograms
   //
-  fQAHist = new TObjArray(2);
-  fNvolumes=gMC->NofVolumes();
   
   fQAHist->Add(new TH1F("hMCVcalls","Monte Carlo calls per volume",
                        fNvolumes, 0.5, fNvolumes+0.5));
-  h = (TH1F*) dir->FindObject("hMCVcalls");
+  h = dynamic_cast<TH1F*>(dir->FindObject("hMCVcalls"));
   h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddVolumeName()"));
   dir->Remove(dir->FindObject("hMCVcalls"));
   //
   // Build list of volume names
   //
-  fVolNames=new TObjArray(fNvolumes);
+  AliMC * mc = gAlice->GetMCApp();
   for(i=0;i<fNvolumes;++i) {
-    AliModule *mod = (AliModule*)
-      (*gAlice->Modules())[gAlice->DetFromMate(gMC->VolId2Mate(i+1))];
-    (*fVolNames)[i]=new TNamed(gMC->VolName(i+1),mod->GetName());
+    Int_t mat = gMC->VolId2Mate(i+1);
+    if (mat > 0) {
+       AliModule *mod = dynamic_cast<AliModule*>
+           ((*gAlice->Modules())[mc->DetFromMate(gMC->VolId2Mate(i+1))]);
+       (*fVolNames)[i] = new TNamed(gMC->VolName(i+1),mod->GetName());
+    } else {
+       (*fVolNames)[i] = new TNamed(gMC->VolName(i+1), "Assembly");
+    }
   }
 
   fQAHist->Add(new TH1F("hMCMcalls","Monte Carlo calls per module",
                        fNdets, -0.5, fNdets-0.5));
-  h = (TH1F*) dir->FindObject("hMCMcalls");
-   h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()"));
+  h = dynamic_cast<TH1F*>(dir->FindObject("hMCMcalls"));
+  h->GetListOfFunctions()->Add(new TExec("ex","gAlice->GetMCQA()->AddModuleName()"));
 
   dir->Remove(dir->FindObject("hMCMcalls"));
   //
   // Build list of module names
   //
-  fModNames=new TObjArray(fNdets);
   for(i=0;i<fNdets;++i) 
     (*fModNames)[i]=
-      new TNamed(((AliModule *)(*gAlice->Modules())[i])->GetName(),"");
+      new TNamed((dynamic_cast<AliModule*>((*gAlice->Modules())[i]))->GetName(),"");
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
+void AliMCQA::Copy(TObject &) const
+{
+  AliFatal("Not implemented!");
+}
 
-AliMCQA::~AliMCQA() {
+//_______________________________________________________________________
+AliMCQA::~AliMCQA() 
+ {
+  //
+  // Destructor
+  //
+  gROOT->GetListOfBrowsables()->Remove(this);
+  //if program crashes here - it probobly means that 
+  //one of added browsables was deleted and not removed previously from that list
+  //skowron
+  
   if (fQAList) {
     fQAList->Delete();
     delete fQAList;
-    fQAList=0;
+    fQAList = 0;
   }
   if (fQAHist) {
     fQAHist->Delete();
     delete fQAHist;
-    fQAHist=0;
+    fQAHist = 0;
   }
   if (fVolNames) {
     fVolNames->Delete();
     delete fVolNames;
-    fVolNames=0;
+    fVolNames = 0;
   }
   if (fModNames) {
     fModNames->Delete();
     delete fModNames;
-    fModNames=0;
+    fModNames = 0;
   }
   delete [] fDetDone;
   delete fMPaveLabel;
   delete fVPaveLabel;
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliMCQA::Browse(TBrowser *b)
 {
   //
@@ -197,21 +230,21 @@ void AliMCQA::Browse(TBrowser *b)
   // Global histos first
   //
   TIter global(fQAHist);
-  while((hist = (TH1*)global())) 
+  while((hist = dynamic_cast<TH1*>(global())))
     b->Add(hist,hist->GetTitle());
   //
   // Module histograms now
   //
   TIter next(fQAList);
   TList *histos;
-  while((histos = (TList*)next())) {
+  while((histos = dynamic_cast<TList*>(next()))) {
     TIter next1(histos);
-    while((hist = (TH1*)next1())) 
+    while((hist = dynamic_cast<TH1*>(next1())))
       b->Add(hist,hist->GetTitle());
   }
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliMCQA::PreTrack()
 {
   //
@@ -221,7 +254,7 @@ void AliMCQA::PreTrack()
   for(Int_t i=0; i<fNdets; i++) fDetDone[i]=0;
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliMCQA::StepManager(Int_t id)
 {
   //
@@ -234,9 +267,9 @@ void AliMCQA::StepManager(Int_t id)
   //
 
 
-  static TH1F* mcvcalls = (TH1F*) fQAHist->FindObject("hMCVcalls");
+  static TH1F* mcvcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCVcalls"));
   mcvcalls->Fill(gMC->CurrentVolID(copy));
-  static TH1F* mcmcalls = (TH1F*) fQAHist->FindObject("hMCMcalls");
+  static TH1F* mcmcalls = dynamic_cast<TH1F*>(fQAHist->FindObject("hMCMcalls"));
   mcmcalls->Fill(id);
 
   //
@@ -248,7 +281,7 @@ void AliMCQA::StepManager(Int_t id)
     static  Double_t mpim=0;
     static  Double_t mep=0;
     static  Double_t mem=0;
-    Double_t mass=0;
+    Double_t mass = 0;
     Int_t num = gMC->TrackPid();
 
     switch (num) {
@@ -273,7 +306,8 @@ void AliMCQA::StepManager(Int_t id)
       mass=mem;
       break;
     default:
-      mass =gAlice->PDGDB()->GetParticle(num)->Mass();
+       if (gAlice->PDGDB()->GetParticle(num))
+           mass = gAlice->PDGDB()->GetParticle(num)->Mass();
       break; 
     }
 
@@ -283,26 +317,26 @@ void AliMCQA::StepManager(Int_t id)
     Double_t energy = TMath::Max(p[3]-mass,1.e-12);
     if(fOldId > -1) {
       if(!fDetDone[fOldId] && !gMC->IsNewTrack()) {
-       TList *histold = (TList*) (*fQAList)[fOldId];
-       hist = (TH1F*) histold->FindObject("hEnOut");
+       TList *histold = dynamic_cast<TList*>((*fQAList)[fOldId]);
+       hist = dynamic_cast<TH1F*>(histold->FindObject("hEnOut"));
        hist->Fill(TMath::Log10(energy));
-       hist = (TH1F*) histold->FindObject("hZOut");
+       hist = dynamic_cast<TH1F*>(histold->FindObject("hZOut"));
        hist->Fill(x[2]);
        fDetDone[fOldId]=1;
       }
     }
     if(!fDetDone[id] && !gMC->IsNewTrack()) {
-      TList *histnew = (TList*) (*fQAList)[id];
-      hist = (TH1F*) histnew->FindObject("hEnIn");
+      TList *histnew = dynamic_cast<TList*>((*fQAList)[id]);
+      hist = dynamic_cast<TH1F*>(histnew->FindObject("hEnIn"));
       hist->Fill(TMath::Log10(energy));
-      hist = (TH1F*) histnew->FindObject("hZIn");
+      hist = dynamic_cast<TH1F*>(histnew->FindObject("hZIn"));
       hist->Fill(x[2]);
     }
     fOldId=id;
   }
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliMCQA::AddModuleName()
 {
   //
@@ -317,7 +351,7 @@ void AliMCQA::AddModuleName()
   }
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliMCQA::AddVolumeName()
 {
   //
@@ -332,7 +366,7 @@ void AliMCQA::AddVolumeName()
   }
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliMCQA::DrawPaveLabel(TPaveLabel *&pv)
 {
   //
@@ -353,14 +387,14 @@ void AliMCQA::DrawPaveLabel(TPaveLabel *&pv)
   pv->Draw();
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 Int_t AliMCQA::GetHBin(const char* hname)
 {
   //
   // Get the bin where the cursor is
   //
   TList *dir = gDirectory->GetList();
-  TH1 *h=(TH1*)dir->FindObject(hname);
+  TH1 *h=dynamic_cast<TH1*>(dir->FindObject(hname));
   
 
   int px = gPad->GetEventX();
@@ -370,7 +404,7 @@ Int_t AliMCQA::GetHBin(const char* hname)
   return h->GetXaxis()->FindBin(x);
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliMCQA::DrawModuleName()
 {
   //
@@ -382,7 +416,7 @@ void AliMCQA::DrawModuleName()
   Int_t binx = GetHBin("hMCMcalls");
   if(0<binx && binx<=fNdets) {
     char lab[15];
-    strcpy(lab,((TNamed*)(*fModNames)[binx-1])->GetName());
+    strcpy(lab,dynamic_cast<TNamed*>((*fModNames)[binx-1])->GetName());
     fMPaveLabel->SetLabel(lab);
   
     gPad->Modified();
@@ -390,7 +424,7 @@ void AliMCQA::DrawModuleName()
   }
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliMCQA::DrawVolumeName()
 {
   //
@@ -402,8 +436,8 @@ void AliMCQA::DrawVolumeName()
   Int_t binx = GetHBin("hMCVcalls");
   if(0<binx && binx<=fNvolumes) {
     char lab[20];
-    sprintf(lab,"%s: %s",((TNamed*)(*fVolNames)[binx-1])->GetName(),
-           ((TNamed*)(*fVolNames)[binx-1])->GetTitle());
+    sprintf(lab,"%s: %s",dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetName(),
+           dynamic_cast<TNamed*>((*fVolNames)[binx-1])->GetTitle());
     fVPaveLabel->SetLabel(lab);
     
     gPad->Modified();