]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDigitizer.cxx
removing temporary file
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizer.cxx
index b2d1be67710a770f1c86a2737f258f7e8d852c7b..85f14baeb1dd5ee66a6243865b7706b88a7a5733 100644 (file)
 
 /*
 $Log$
-*/
+Revision 1.10  2002/03/13 07:55:04  jchudoba
+Correction of the errourness last commit.
+
+Revision 1.8  2002/02/13 09:03:24  jchudoba
+Remove some deletes from dtor, those objects are deleted earlier in Exec() method (where they are created)
+
+Revision 1.7  2001/11/22 11:15:41  jchudoba
+Proper deletion of arrays (thanks to Rene Brun)
+
+Revision 1.6  2001/11/02 12:55:45  jchudoba
+cleanup of the code, add const to Get methods
+
+Revision 1.4  2001/10/18 14:44:09  jchudoba
+Define constant MAXTRACKS for maximum number of tracks associated with 1 digit
+
+Revision 1.3  2001/10/04 20:01:54  jchudoba
+changes for TTask implementation, some other small editing
 
+Revision 1.2  2001/07/28 10:46:04  hristov
+AliRunDigitizer.h included; typos corrected
+
+Revision 1.1  2001/07/27 15:41:01  jchudoba
+merging/digitization classes
+
+*/
 #include <TTree.h> 
-#include <TVector.h>
 #include <TObjArray.h>
 #include <TFile.h>
 #include <TDirectory.h>
-#include <iostream.h>
+#include <Riostream.h>
 
 #include "AliMUONDigitizer.h"
 #include "AliMUONConstants.h"
 #include "AliMUONChamber.h"
-#include "AliHitMap.h"
 #include "AliMUONHitMapA1.h"
 #include "AliMUON.h"
 #include "AliMUONHit.h"
@@ -36,6 +57,7 @@ $Log$
 #include "AliMUONTransientDigit.h"
 #include "AliRun.h"
 #include "AliPDG.h"
+#include "AliRunDigitizer.h"
 
 ClassImp(AliMUONDigitizer)
 
@@ -43,7 +65,10 @@ ClassImp(AliMUONDigitizer)
 AliMUONDigitizer::AliMUONDigitizer() :AliDigitizer()
 {
 // Default ctor - don't use it
-  cerr<<"Error: AliMUONDigitizer default ctor must not be used"<<endl;
+  fHits = 0;
+  fPadHits = 0;
+  fHitMap = 0;
+  fTDList = 0;
 }
 
 //___________________________________________
@@ -51,14 +76,11 @@ AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager)
     :AliDigitizer(manager)
 {
 // ctor which should be used
-  fManager = manager;
   fHitMap  = 0;
   fTDList  = 0;
-  fTrH1    = 0;
   fHits    = 0;
-  fPadHits    = 0;
-  fTrList     = 0;
-  fAddress    = 0; 
+  fPadHits = 0;
+  fDebug   = 0; 
   if (GetDebug()>2) 
     cerr<<"AliMUONDigitizer::AliMUONDigitizer"
        <<"(AliRunDigitizer* manager) was processed"<<endl;
@@ -68,79 +90,61 @@ AliMUONDigitizer::AliMUONDigitizer(AliRunDigitizer* manager)
 AliMUONDigitizer::~AliMUONDigitizer()
 {
 // Destructor
-  if (fTrH1)       delete fTrH1;
   if (fHits)       delete fHits;
   if (fPadHits)    delete fPadHits;
-  if (fHitMap)     delete fHitMap;
-  if (fTDList)     delete fTDList;
-  if (fTrList)     delete fTrList;
-  if (fAddress)    delete fAddress; 
 }
 
 //------------------------------------------------------------------------
-Bool_t AliMUONDigitizer::Exists(const AliMUONPadHit *mergable)
+Bool_t AliMUONDigitizer::Exists(const AliMUONPadHit *padhit) const
 {
-  AliMUONPadHit *padhit = (AliMUONPadHit*) mergable;
   return (fHitMap[fNch]->TestHit(padhit->PadX(),padhit->PadY()));
 }
 
 //------------------------------------------------------------------------
-void AliMUONDigitizer::Update(AliMUONPadHit *mergable)
+void AliMUONDigitizer::Update(AliMUONPadHit *padhit)
 {
-  AliMUONPadHit *padhit = (AliMUONPadHit*) mergable;    
-  AliMUONTransientDigit* pdigit;
-  Int_t ipx      = padhit->PadX();        // pad number on X
-  Int_t ipy      = padhit->PadY();        // pad number on Y
-  Int_t iqpad    = Int_t(padhit->QPad()); // charge per pad
-
-  pdigit = (AliMUONTransientDigit*) fHitMap[fNch]->GetHit(ipx, ipy);
-  // update charge
-  //
-  (*pdigit).AddSignal(iqpad);
-  (*pdigit).AddPhysicsSignal(iqpad);           
-  // update list of tracks
-  //
-  TObjArray* fTrList = (TObjArray*)pdigit->TrackList();
-  Int_t lastEntry = fTrList->GetLast();
-  TVector *pTrack = (TVector*)fTrList->At(lastEntry);
-  TVector &ptrk   = *pTrack;
-  TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]);
-  Int_t lastTrack = Int_t(ptrk(0));
-
-  if (trinfo(0) != kBgTag) {
-    if (lastTrack == fTrack) {
-      Int_t lastCharge = Int_t(ptrk(1));
-      lastCharge += iqpad;
-      fTrList->RemoveAt(lastEntry);
-      trinfo(1) = lastCharge;
-      fTrList->AddAt(&trinfo,lastEntry);
+    AliMUONTransientDigit *pdigit = 
+      static_cast<AliMUONTransientDigit*>(
+      fHitMap[fNch]->GetHit(padhit->PadX(),padhit->PadY()));
+
+    // update charge
+    //
+    Int_t iqpad    = padhit->QPad();        // charge per pad
+    pdigit->AddSignal(iqpad);
+    pdigit->AddPhysicsSignal(iqpad);           
+
+    // update list of tracks
+    //
+    Int_t track, charge;    
+    track = fTrack+fMask;
+    if (fSignal) {
+      charge = iqpad;
     } else {
-      fTrList->Add(&trinfo);
+      charge = kBgTag;
     }
-  } else {
-    if (lastTrack != -1) fTrList->Add(&trinfo);
-  }
+    pdigit->UpdateTrackList(track,charge);
 }
 
 //------------------------------------------------------------------------
-void AliMUONDigitizer::CreateNew(AliMUONPadHit *mergable)
+void AliMUONDigitizer::CreateNew(AliMUONPadHit *padhit)
 {
 // Create new AliMUONTransientDigit and add it to the fTDList
 
-  AliMUONPadHit *padhit = (AliMUONPadHit*) mergable;    
-  AliMUONTransientDigit* pdigit;
-
-  Int_t ipx      = padhit->PadX();       // pad number on X
-  Int_t ipy      = padhit->PadY();       // pad number on Y
   fTDList->AddAtAndExpand(
     new AliMUONTransientDigit(fNch,fDigits),fCounter);
-  fHitMap[fNch]->SetHit(ipx, ipy, fCounter);
-  fCounter++;
-  pdigit = (AliMUONTransientDigit*)fTDList->At(fTDList->GetLast());
+  fHitMap[fNch]->SetHit(padhit->PadX(),padhit->PadY(),fCounter);
+  AliMUONTransientDigit* pdigit = 
+    (AliMUONTransientDigit*)fTDList->Last();
   // list of tracks
-  TObjArray *fTrList = (TObjArray*)pdigit->TrackList();
-  TVector &trinfo    = *((TVector*) (*fAddress)[fCountadr-1]);
-  fTrList->Add(&trinfo);
+  Int_t track, charge;    
+  track = fTrack+fMask;
+  if (fSignal) {
+    charge = padhit->QPad();
+  } else {
+    charge = kBgTag;
+  }
+  pdigit->AddToTrackList(track,charge);
+  fCounter++;
 }
 
 
@@ -156,18 +160,20 @@ Bool_t AliMUONDigitizer::Init()
 
 
 //------------------------------------------------------------------------
-void AliMUONDigitizer::Digitize()
+//void AliMUONDigitizer::Digitize()
+void AliMUONDigitizer::Exec(Option_t* option)
 {
 
-  // keep galice.root for signal and name differently the file for 
-  // background when add! otherwise the track info for signal will be lost !
-  
+  TString optionString = option;
+  if (optionString.Data() == "deb") {
+    cout<<"AliMUONDigitizer::Exec: called with option deb "<<endl;
+    fDebug = 3;
+  }
   AliMUONChamber*   iChamber;
   AliSegmentation*  segmentation;
   
   if (GetDebug()>2) cerr<<"   AliMUONDigitizer::Digitize() starts"<<endl;
   fTDList = new TObjArray;
-  if(!fAddress) fAddress = new TClonesArray("TVector",10000);
 
   AliMUON *pMUON  = (AliMUON *) gAlice->GetModule("MUON");
   if (!pMUON) {
@@ -176,35 +182,32 @@ void AliMUONDigitizer::Digitize()
     return;
   }
   pMUON->MakeBranchInTreeD(fManager->GetTreeD());
-  fHitMap= new AliHitMap* [AliMUONConstants::NCh()];
-  for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {fHitMap[i] = 0;}
+  fHitMap= new AliMUONHitMapA1* [AliMUONConstants::NCh()];
 
   //
   // loop over cathodes
   //
 
-  fCountadr = 0;
   for (int icat = 0; icat < 2; icat++) { 
     fCounter = 0;
-    Int_t * nmuon = new Int_t [AliMUONConstants::NCh()];
     for (Int_t i = 0; i < AliMUONConstants::NCh(); i++) {
       iChamber = &(pMUON->Chamber(i));
 //      if (!(iChamber->Nsec() == 1 && icat == 1)) {
        segmentation = iChamber->SegmentationModel(icat+1);
        fHitMap[i] = new AliMUONHitMapA1(segmentation, fTDList);
-       nmuon[i] = 0;
 //      }
     }
 
 
 // Loop over files to digitize
-       
+    fSignal = kTRUE;
     for (Int_t inputFile=0; inputFile<fManager->GetNinputs();
         inputFile++) {
 // Connect MUON branches
 
-      TBranch *branch = 0;
-      TBranch *branch2 = 0;
+      if (inputFile > 0 ) fSignal = kFALSE;
+      TBranch *branchHits = 0;
+      TBranch *branchPadHits = 0;
       TTree *treeH = fManager->GetInputTreeH(inputFile);
       if (GetDebug()>2) {
        cerr<<"   inputFile , cathode = "<<inputFile<<" "
@@ -212,24 +215,24 @@ void AliMUONDigitizer::Digitize()
        cerr<<"   treeH, fHits "<<treeH<<" "<<fHits<<endl;
       }
       if (treeH && fHits) {
-       branch = treeH->GetBranch("MUON");
-       if (branch) {
+       branchHits = treeH->GetBranch("MUON");
+       if (branchHits) {
          fHits->Clear();
-         branch->SetAddress(&fHits);
+         branchHits->SetAddress(&fHits);
        }
        else
-         Error("Digitize","branch MUON was not found");
+         Error("Exec","branch MUON was not found");
       }
-      if (GetDebug()>2) cerr<<"   branch = "<<branch<<endl;
+      if (GetDebug()>2) cerr<<"   branchHits = "<<branchHits<<endl;
 
       if (treeH && fPadHits) {
-       branch2 = treeH->GetBranch("MUONCluster");
-       if (branch2
-         branch2->SetAddress(&fPadHits);
+       branchPadHits = treeH->GetBranch("MUONCluster");
+       if (branchPadHits
+         branchPadHits->SetAddress(&fPadHits);
        else
-         Error("Digitize","branch MUONCluster was not found");
+         Error("Exec","branch MUONCluster was not found");
       }
-      if (GetDebug()>2) cerr<<"   branch2 = "<<branch2<<endl;
+      if (GetDebug()>2) cerr<<"   branchPadHits = "<<branchPadHits<<endl;
 
 //
 //   Loop over tracks
@@ -240,24 +243,24 @@ void AliMUONDigitizer::Digitize()
       for (fTrack = 0; fTrack < ntracks; fTrack++) {
        if (GetDebug()>2) cerr<<"   fTrack = "<<fTrack<<endl;
        fHits->Clear();
-       cerr<<" branch->GetEntry(fTrack) "<<branch->GetEntry(fTrack)<<endl;
-       cerr<<" branch2->GetEntry(fTrack) "<<branch2->GetEntry(fTrack)<<endl;
+       fPadHits->Clear();
+       branchHits->GetEntry(fTrack);
+       branchPadHits->GetEntry(fTrack);
        
 //
 //   Loop over hits
 
        AliMUONHit* mHit;
-       for(int i = 0; i < fHits->GetEntriesFast(); ++i) 
-       {       
-         mHit   = (AliMUONHit*) (*fHits)[i];
+       for(Int_t i = 0; i < fHits->GetEntriesFast(); ++i) {
+         mHit = static_cast<AliMUONHit*>(fHits->At(i));
          fNch = mHit->Chamber()-1;  // chamber number
-         iChamber = &(pMUON->Chamber(fNch));
          if (fNch > AliMUONConstants::NCh()-1) {
            cerr<<"AliMUONDigitizer: ERROR: "
                <<"fNch > AliMUONConstants::NCh()-1, fNch, NCh(): "
                <<fNch<<", "<< AliMUONConstants::NCh()<<endl;
            return;
          }
+         iChamber = &(pMUON->Chamber(fNch));
 //
 // Loop over pad hits
          for (AliMUONPadHit* mPad =
@@ -271,17 +274,7 @@ void AliMUONDigitizer::Digitize()
            Int_t iqpad    = Int_t(mPad->QPad());  // charge per pad
            if (cathode != (icat+1)) continue;
 
-           new((*fAddress)[fCountadr++]) TVector(2);
-
-           TVector &trinfo = *((TVector*) (*fAddress)[fCountadr-1]);
-           Int_t mask = fManager->GetMask(inputFile);
-           trinfo(0) = (Float_t)(fTrack + mask);  // tag background
-//                 trinfo(0) = (Float_t)fTrack;
-           if (inputFile == 0) {
-             trinfo(1) = (Float_t)iqpad;
-           } else {
-             trinfo(1) = kBgTag;
-           }
+           fMask = fManager->GetMask(inputFile);
            fDigits[0] = ipx;
            fDigits[1] = ipy;
            fDigits[2] = icat;
@@ -293,7 +286,7 @@ void AliMUONDigitizer::Digitize()
            }
            if (mHit->Particle() == kMuonPlus ||
                mHit->Particle() == kMuonMinus) {
-             fDigits[5] = (mPad->HitNumber()) + mask; 
+             fDigits[5] = (mPad->HitNumber()) + fMask; 
            } else fDigits[5] = -1;
 
            // build the list of fired pads and update the info, 
@@ -310,8 +303,8 @@ void AliMUONDigitizer::Digitize()
     } // end file loop
     if (GetDebug()>2) cerr<<"END OF FILE LOOP"<<endl;
 
-    Int_t tracks[10];
-    Int_t charges[10];
+    Int_t tracks[kMAXTRACKS];
+    Int_t charges[kMAXTRACKS];
     Int_t nentries = fTDList->GetEntriesFast();
        
     for (Int_t nent = 0; nent < nentries; nent++) {
@@ -334,35 +327,29 @@ void AliMUONDigitizer::Digitize()
       fDigits[4] = address->Physics();
       fDigits[5] = address->Hit();
            
-      TObjArray* fTrList = (TObjArray*)address->TrackList();
-      Int_t nptracks = fTrList->GetEntriesFast();
-
-      // this was changed to accomodate the real number of tracks
+      Int_t nptracks = address->GetNTracks();
 
-      if (nptracks > 10) {
-       cerr<<"Attention - nptracks > 10 "<<nptracks<<endl;
-       nptracks = 10;
+      if (nptracks > kMAXTRACKS) {
+       if (GetDebug() >0) {
+         cerr<<"AliMUONDigitizer: nptracks > 10 "<<nptracks;
+         cerr<<"reset to max value "<<kMAXTRACKS<<endl;
+       }
+       nptracks = kMAXTRACKS;
       }
       if (nptracks > 2 && GetDebug() >2) {
-       cerr<<"Attention - nptracks > 2 "<<nptracks<<endl;
+       cerr<<"AliMUONDigitizer: nptracks > 2 "<<nptracks<<endl;
        printf("cat,ich,ix,iy,q %d %d %d %d %d \n",icat,ich,fDigits[0],fDigits[1],q);
       }
       for (Int_t tr = 0; tr < nptracks; tr++) {
-       TVector *ppP = (TVector*)fTrList->At(tr);
-       if(!ppP ) {
-         cerr<<"Error: ppP = "<<ppP<<endl;
-         return;
-       }
-       TVector &pp  = *ppP;
-       tracks[tr]   = Int_t(pp(0));
-       charges[tr]  = Int_t(pp(1));
+       tracks[tr]   = address->GetTrack(tr);
+       charges[tr]  = address->GetCharge(tr);
       }      //end loop over list of tracks for one pad
       // Sort list of tracks according to charge
       if (nptracks > 1) {
        SortTracks(tracks,charges,nptracks);
       }
-      if (nptracks < 10 ) {
-       for (Int_t i = nptracks; i < 10; i++) {
+      if (nptracks < kMAXTRACKS ) {
+       for (Int_t i = nptracks; i < kMAXTRACKS; i++) {
          tracks[i]  = 0;
          charges[i] = 0;
        }
@@ -370,7 +357,6 @@ void AliMUONDigitizer::Digitize()
            
       // fill digits
       pMUON->AddDigits(ich,tracks,charges,fDigits);
-      // delete fTrList;
     }
 
     fManager->GetTreeD()->Fill();
@@ -385,23 +371,20 @@ void AliMUONDigitizer::Digitize()
        fHitMap[ii] = 0;
       }
     }
-    delete [] nmuon;    
   } //end loop over cathodes
   if (GetDebug()>2) 
-    cerr<<"DDDDD: writing the TreeD: "
+    cerr<<"AliMUONDigitizer::Exec: writing the TreeD: "
        <<fManager->GetTreeD()->GetName()<<endl;
-  fManager->GetTreeD()->Write();
+  fManager->GetTreeD()->Write(0,TObject::kOverwrite);
   delete [] fHitMap;
   delete fTDList;
     
-  if (fAddress)    fAddress->Delete();
   if (fHits)    fHits->Delete();
   if (fPadHits) fPadHits->Delete();
-  // gObjectTable->Print();
 }
 
 
-
+//------------------------------------------------------------------------
 void AliMUONDigitizer::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
 {
   //
@@ -455,29 +438,3 @@ void AliMUONDigitizer::SortTracks(Int_t *tracks,Int_t *charges,Int_t ntr)
     }
   }
 }
-
-
-/*
-void AliMUONDigitizer::MixWith(char* HeaderFile, char* SDigitsFile){
-//
-
-  if(HeaderFile == 0){
-    cout << "Specify  header file to merge"<< endl;
-    return;
-  }
-  
-  Int_t inputs;
-  for(inputs = 0; inputs < fNinputs ; inputs++){
-    if(strcmp(((TObjString *)fHeaderFiles->At(inputs))->GetString(),HeaderFile) == 0 ){
-      cout << "Entry already exists, do not add" << endl ;
-      return ;
-    }
-  }  
-  
-  fHeaderFiles->Expand(fNinputs+1) ;
-  new((*fHeaderFiles)[fNinputs]) TObjString(HeaderFile) ;
-
-  TFile * file ;
-  file = new TFile(((TObjString *) fHeaderFiles->At(fNinputs))->GetString()) ;  
-  file->cd() ;
-