]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONData.cxx
Testing null pointers in AliMUONData
[u/mrichter/AliRoot.git] / MUON / AliMUONData.cxx
index 3636309f432112fcd885d046f369b678054d9071..0640d1c8a6304c213abd022a175c69882a5b6a46 100644 (file)
@@ -1,14 +1,32 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
 
+/* $Id$ */
 
 //Root includes
-
+#include "TNamed.h"
 //AliRoot includes
+#include "AliLoader.h" 
+#include "AliMUONConstants.h"
 #include "AliMUONData.h"
 #include "AliMUONDigit.h"
 #include "AliMUONHit.h"
 #include "AliMUONLocalTrigger.h"
 #include "AliMUONGlobalTrigger.h"
 #include "AliMUONRawCluster.h"
+#include "AliMUONTrack.h"
 
 ClassImp(AliMUONData)
  
@@ -21,7 +39,9 @@ AliMUONData::AliMUONData():TNamed()
   fNdigits       = 0x0;
   fRawClusters   = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
   fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
-  fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch       
+  fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
+  fRecTracks     = 0x0;       
+  fSplitLevel    = 0;
 //default constructor
 }
 //_____________________________________________________________________________
@@ -29,24 +49,40 @@ AliMUONData::AliMUONData(AliLoader * loader, const char* name, const char* title
   TNamed(name,title)
 {
   fLoader        = loader;
-  fHits          = new TClonesArray("AliMUONHit",1000);
+  fHits          = 0x0;    // One event in treeH per primary track
+  fDigits        = 0x0;  // One event in treeH per detection plane
+  fNdigits       = 0x0;
+  fRawClusters   = 0x0; //One event in TreeR/RawclusterBranch per tracking detection plane
+  fGlobalTrigger = 0x0; //! List of Global Trigger 1st event in TreeR/GlobalTriggerBranch
+  fLocalTrigger  = 0x0;  //! List of Local Trigger, 1st event in TreeR/LocalTriggerBranch
+  fRecTracks     = 0x0;    
   fNhits         = 0;
-  fDigits        = new TObjArray(AliMUONConstants::NCh());
-  fNdigits       = new Int_t[AliMUONConstants::NCh()];
-  for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
-    fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
-    fNdigits[iDetectionPlane]=0;
-  }
-  fRawClusters   = new TObjArray(AliMUONConstants::NTrackingCh());
-  fNrawclusters  = new Int_t[AliMUONConstants::NTrackingCh()];
-  for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
-    fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane); 
-    fNrawclusters[iDetectionPlane]=0;
-  }
-  fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
   fNglobaltrigger =0;
-  fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);   
   fNlocaltrigger = 0;
+  fNrectracks    = 0;  
+  fSplitLevel    = 0;
+//   fHits          = new TClonesArray("AliMUONHit",1000);
+//   fNhits         = 0;
+//   fDigits        = new TObjArray(AliMUONConstants::NCh());
+//   fNdigits       = new Int_t[AliMUONConstants::NCh()];
+//   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NCh() ;iDetectionPlane++) {
+//     fDigits->AddAt(new TClonesArray("AliMUONDigit",10000),iDetectionPlane); 
+//     fNdigits[iDetectionPlane]=0;
+//   }
+//   fRawClusters   = new TObjArray(AliMUONConstants::NTrackingCh());
+//   fNrawclusters  = new Int_t[AliMUONConstants::NTrackingCh()];
+//   for (Int_t iDetectionPlane=0; iDetectionPlane<AliMUONConstants::NTrackingCh();iDetectionPlane++) {
+//     fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),iDetectionPlane); 
+//     fNrawclusters[iDetectionPlane]=0;
+//   }
+//   fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1);    
+//   fNglobaltrigger =0;
+//   fLocalTrigger  = new TClonesArray("AliMUONLocalTrigger",234);   
+//   fNlocaltrigger = 0;
+//   fRecTracks     = new TClonesArray("AliMUONTrack", 10);
+//   fNrectracks    = 0; // really needed or GetEntriesFast sufficient ????
+
+
   //default constructor
 }
 //_____________________________________________________________________________
@@ -78,6 +114,10 @@ AliMUONData::~AliMUONData()
     fLocalTrigger->Delete();
     delete fLocalTrigger;
   }
+  if (fRecTracks){
+    fRecTracks->Delete();
+    delete fRecTracks;
+  }
   //detructor 
 }
 //_____________________________________________________________________________
@@ -86,7 +126,7 @@ void AliMUONData::AddDigit(Int_t id, Int_t *tracks, Int_t *charges, Int_t *digit
   //
   // Add a MUON digit to the list of Digits of the detection plane id
   //
-  TClonesArray &ldigits = * Digits(id,0) ; 
+  TClonesArray &ldigits = * Digits(id) ; 
   new(ldigits[fNdigits[id]++]) AliMUONDigit(tracks,charges,digits);
 }
 //_____________________________________________________________________________
@@ -112,6 +152,20 @@ void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber,
                                  phi, length, destep);
 }
 //____________________________________________________________________________
+void AliMUONData::AddHit(Int_t fIshunt, Int_t track, Int_t iChamber, 
+                        Int_t idpart, Float_t X, Float_t Y, Float_t Z, 
+                        Float_t tof, Float_t momentum, Float_t theta, 
+                        Float_t phi, Float_t length, Float_t destep,
+                        Float_t Xref,Float_t Yref,Float_t Zref)
+{
+  TClonesArray &lhits = *fHits;
+  new(lhits[fNhits++]) AliMUONHit(fIshunt, track, iChamber, 
+                                 idpart, X, Y, Z, 
+                                 tof, momentum, theta, 
+                                 phi, length, destep,
+                                 Xref,Yref,Zref);
+}
+//____________________________________________________________________________
 void AliMUONData::AddLocalTrigger(Int_t *localtr)
 {
   // add a MUON Local Trigger to the list
@@ -127,7 +181,117 @@ void AliMUONData::AddRawCluster(Int_t id, const AliMUONRawCluster& c)
   TClonesArray &lrawcl = *((TClonesArray*) fRawClusters->At(id));
   new(lrawcl[fNrawclusters[id]++]) AliMUONRawCluster(c);
 }
+//_____________________________________________________________________________
+void AliMUONData::AddRecTrack(const AliMUONTrack& track)
+{
+  //
+  // Add a MUON rectrack
+  //
+  TClonesArray &lrectracks = *fRecTracks;
+  new(lrectracks[fNrectracks++]) AliMUONTrack(track);
+}
+//____________________________________________________________________________
+TClonesArray*  AliMUONData::Digits(Int_t DetectionPlane) 
+{
+  if (fDigits)
+    return ( (TClonesArray*) fDigits->At(DetectionPlane) );
+  else
+    return NULL;
+}
+//____________________________________________________________________________
+Bool_t   AliMUONData::IsRawClusterBranchesInTree()
+{
+  if (TreeR()==0x0) {
+    Error("TreeR","No treeR in memory");
+    return kFALSE;
+  }
+  else {
+     char branchname[30];
+     sprintf(branchname,"%sRawClusters1",GetName());
+     TBranch * branch = 0x0;
+     branch = TreeR()->GetBranch(branchname);
+     if (branch)  return kTRUE;
+     else return kFALSE;    
+  }
+}
 //____________________________________________________________________________
+Bool_t   AliMUONData::IsTriggerBranchesInTree()
+{
+ if (TreeR()==0x0) {
+    Error("TreeR","No treeR in memory");
+    return kFALSE;
+  }
+  else {
+     char branchname[30];
+     sprintf(branchname,"%sLocalTrigger",GetName());
+     TBranch * branch = 0x0;
+     branch = TreeR()->GetBranch(branchname);
+     if (branch)  return kTRUE;
+     else return kFALSE;    
+  }
+}
+//____________________________________________________________________________
+void AliMUONData::Fill(Option_t* option)
+{
+  // Method to fill the trees
+  const char *cH   = strstr(option,"H");
+  const char *cD   = strstr(option,"D");   // Digits branches in TreeD
+  const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
+  const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
+  const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
+  //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
+  
+  char branchname[30];
+  TBranch * branch = 0x0;
+
+  //
+  // Filling TreeH
+  if ( TreeH() && cH ) {
+    TreeH()->Fill();
+  }  
+  //
+  // Filling TreeD
+  if ( TreeD() && cD) {
+    TreeD()->Fill();
+  }
+
+  //
+  // filling rawclusters
+  if ( TreeR()  && cRC ) {
+    if ( IsTriggerBranchesInTree() ) {
+      // Branch per branch filling
+      for (int i=0; i<AliMUONConstants::NTrackingCh(); i++) {
+       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
+       branch = TreeR()->GetBranch(branchname);
+       branch->Fill();
+      }
+    }
+    else  TreeR()->Fill();
+  }
+  
+ //
+  // filling trigger 
+  if ( TreeR()  && cGLT) {
+    if (IsRawClusterBranchesInTree()) {
+      // Branch per branch filling
+      sprintf(branchname,"%sLocalTrigger",GetName());
+      branch = TreeR()->GetBranch(branchname); 
+      branch->Fill();
+      sprintf(branchname,"%sGlobalTrigger",GetName());
+      branch = TreeR()->GetBranch(branchname);
+      branch->Fill();
+    }
+    else  TreeR()->Fill();
+  }
+  //
+  // filling tracks
+  if ( TreeT() && cRT ) {
+    sprintf(branchname,"%sTrack",GetName());  
+    branch = TreeT()->GetBranch(branchname);
+    branch->Fill();
+  }
+}
+//_____________________________________________________________________________
 void AliMUONData::MakeBranch(Option_t* option)
 {
   //
@@ -155,7 +319,7 @@ void AliMUONData::MakeBranch(Option_t* option)
       Info("MakeBranch","Branch %s is already in tree.",GetName());
       return ;
     }
-    branch = TreeH()->Branch(branchname,&fHits,kBufferSize);
+    branch = TreeH()->Branch(branchname,&fHits,kBufferSize,fSplitLevel);
     Info("MakeBranch","Making Branch %s for hits \n",branchname);
   }  
   
@@ -182,8 +346,8 @@ void AliMUONData::MakeBranch(Option_t* option)
        Info("MakeBranch","Branch %s is already in tree.",GetName());
        return;
       }
-      TClonesArray * digits = Digits(iDetectionPlane,0); 
-      branch = TreeD()->Branch(branchname, &digits, kBufferSize);
+      TClonesArray * digits = Digits(iDetectionPlane); 
+      branch = TreeD()->Branch(branchname, &digits, kBufferSize,1);
       Info("MakeBranch","Making Branch %s for digits in detection plane %d\n",branchname,iDetectionPlane+1);
       }
   }
@@ -195,7 +359,7 @@ void AliMUONData::MakeBranch(Option_t* option)
     if (fRawClusters == 0x0) {
       fRawClusters = new TObjArray(AliMUONConstants::NTrackingCh());
       for (Int_t i=0; i<AliMUONConstants::NTrackingCh();i++) {
-       fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",10000),i); 
+       fRawClusters->AddAt(new TClonesArray("AliMUONRawCluster",1000),i); 
       }
     }
 
@@ -214,7 +378,7 @@ void AliMUONData::MakeBranch(Option_t* option)
        Info("MakeBranch","Branch %s is already in tree.",GetName());
        return;
       }
-      branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize);
+      branch = TreeR()->Branch(branchname, &((*fRawClusters)[i]),kBufferSize,fSplitLevel);
       Info("MakeBranch","Making Branch %s for rawcluster in detection plane %d\n",branchname,i+1);
     }
   }
@@ -227,7 +391,7 @@ void AliMUONData::MakeBranch(Option_t* option)
     branch = 0x0;
     
     if (fGlobalTrigger == 0x0) {
-      fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",1); 
+      fGlobalTrigger = new TClonesArray("AliMUONGlobalTrigger",fSplitLevel); 
       fNglobaltrigger = 0;
     }
     branch = TreeR()->GetBranch(branchname);
@@ -235,7 +399,7 @@ void AliMUONData::MakeBranch(Option_t* option)
       Info("MakeBranch","Branch %s is already in tree.",GetName());
       return ;
     }
-    branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize);
+    branch = TreeR()->Branch(branchname, &fGlobalTrigger, kBufferSize,fSplitLevel);
     Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);
     
     //
@@ -253,18 +417,35 @@ void AliMUONData::MakeBranch(Option_t* option)
       Info("MakeBranch","Branch %s is already in tree.",GetName());
       return;
     }
-    branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize);
+    branch = TreeR()->Branch(branchname, &fLocalTrigger, kBufferSize,fSplitLevel);
     Info("MakeBranch", "Making Branch %s for Global Trigger\n",branchname);  
   }
   
-  if (TreeR() && cRT ) {
-    Info("MakeBranch","Making Branch for TreeT is not yet ready. \n");
-  }
-  if (TreeR() && cRP ) {
+  if (TreeT() && cRT ) {
+    if (fRecTracks == 0x0)  fRecTracks = new TClonesArray("AliMUONTrack",10);
+    fNrectracks = 0;
+    sprintf(branchname,"%sTrack",GetName());  
+    branch = TreeT()->GetBranch(branchname);
+    if (branch) {  
+      Info("MakeBranch","Branch %s is already in tree.",GetName());
+      return ;
+    }
+    branch = TreeT()->Branch(branchname,&fRecTracks,kBufferSize);
+    Info("MakeBranch","Making Branch %s for tracks \n",branchname);
+  }  
+
+  if (TreeP() && cRP ) {
     Info("MakeBranch","Making Branch for TreeP is not yet ready. \n");
   }
 }
-
+//____________________________________________________________________________
+TClonesArray*  AliMUONData::RawClusters(Int_t DetectionPlane)
+{
+  if (fRawClusters) 
+    return ( (TClonesArray*) fRawClusters->At(DetectionPlane) );
+  else
+    return NULL;
+}
 //____________________________________________________________________________
 void AliMUONData::ResetDigits()
 {
@@ -303,6 +484,13 @@ void AliMUONData::ResetTrigger()
   fNlocaltrigger = 0;
   if (fLocalTrigger) fLocalTrigger->Clear();
 }
+//____________________________________________________________________________
+void AliMUONData::ResetRecTracks()
+{
+  // Reset tracks information
+  fNrectracks = 0;
+  if (fRecTracks) fRecTracks->Clear();
+}
 //_____________________________________________________________________________
 void AliMUONData::SetTreeAddress(Option_t* option)
 {
@@ -310,7 +498,7 @@ void AliMUONData::SetTreeAddress(Option_t* option)
   const char *cD   = strstr(option,"D");   // Digits branches in TreeD
   const char *cRC  = strstr(option,"RC");  // RawCluster branches in TreeR
   const char *cGLT = strstr(option,"GLT"); // Global and Local Trigger branches in TreeR
-  // const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
+  const char *cRT  = strstr(option,"RT");  // Reconstructed Track in TreeT
   //const char *cRP  = strstr(option,"RP");  // Reconstructed Particle in TreeP
   
   // Set branch address for the Hits, Digits, RawClusters, GlobalTrigger and LocalTrigger Tree.
@@ -327,7 +515,7 @@ void AliMUONData::SetTreeAddress(Option_t* option)
     sprintf(branchname,"%sHits",GetName());  
     branch = TreeH()->GetBranch(branchname);
     if (branch) {
-      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
+      //      Info("SetTreeAddress","(%s) Setting for Hits",GetName());
       branch->SetAddress(&fHits);
     }
     else { //can be invoked before branch creation
@@ -351,10 +539,12 @@ void AliMUONData::SetTreeAddress(Option_t* option)
   if (TreeD() && fDigits && cD) {
     for (int i=0; i<AliMUONConstants::NCh(); i++) {
       sprintf(branchname,"%sDigits%d",GetName(),i+1);
-      branch = TreeD()->GetBranch(branchname);
-      TClonesArray * digits = Digits(i,0);
-      if (branch) branch->SetAddress( &digits );
-      else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
+      if (fDigits) {
+       branch = TreeD()->GetBranch(branchname);
+       TClonesArray * digits = Digits(i);
+       if (branch) branch->SetAddress( &digits );
+       else Warning("SetTreeAddress","(%s) Failed for Digits Detection plane %d. Can not find branch in tree.",GetName(),i);
+      }
     }
   }
   
@@ -382,7 +572,7 @@ void AliMUONData::SetTreeAddress(Option_t* option)
       sprintf(branchname,"%sRawClusters%d",GetName(),i+1);
       if (fRawClusters) {
        branch = TreeR()->GetBranch(branchname);
-       if (branch) branch->SetAddress(&((*fRawClusters)[i]));
+       if (branch) branch->SetAddress( &((*fRawClusters)[i]) );
        else Warning("SetTreeAddress","(%s) Failed for RawClusters Detection plane %d. Can not find branch in tree.",GetName(),i);
       }
     }
@@ -399,5 +589,12 @@ void AliMUONData::SetTreeAddress(Option_t* option)
     if (branch) branch->SetAddress(&fGlobalTrigger);
     else Warning("SetTreeAddress","(%s) Failed for LocalTrigger. Can not find branch in tree.",GetName());
   }
+
+  if ( TreeT() && fRecTracks && cRT ) {
+    sprintf(branchname,"%sTrack",GetName());  
+    branch = TreeT()->GetBranch(branchname);
+    if (branch) branch->SetAddress(&fRecTracks);
+    else Warning("SetTreeAddress","(%s) Failed for Tracks. Can not find branch in tree.",GetName());
+  }
 }
 //_____________________________________________________________________________