]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSDigitizer.cxx
New ITS SDigit merging with region of interest cut. Update for changes in
[u/mrichter/AliRoot.git] / ITS / AliITSDigitizer.cxx
index 85bad4529395002c0e39a42168153e96bb32ae23..1733fd43dca8313dfa4842989fd5c1e9d304f044 100644 (file)
  
 /*
 $Log$
+Revision 1.2  2002/03/15 17:26:40  nilsen
+New SDigit version of ITS Digitizer.
+
 Revision 1.1  2001/11/27 16:27:28  nilsen
 Adding AliITSDigitizer class to do merging and digitization . Based on the
 TTask method. AliITSDigitizer class added to the Makefile and ITSLinkDef.h
 file. The following files required minor changes. AliITS, added functions
 SetHitsAddressBranch, MakeBranchInTreeD and modified MakeBranchD.
-AliITSsimulationSDD.cxx needed a Tree indepenent way of returning back to
+AliITSsimulationSDD.cxx needed a Tree independent way of returning back to
 the original Root Directory in function Compress1D. Now it uses gDirectory.
 
 Revision 1.2  2002/03/01  E. Lopez
-Diditization changed to start from SDigits instead of Hits.
+Digitization changed to start from SDigits instead of Hits.
 The SDigits are reading as TClonesArray of AliITSpListItem
 */
 
@@ -33,6 +36,7 @@ The SDigits are reading as TClonesArray of AliITSpListItem
 #include <TObjArray.h>
 #include <TTree.h>
 #include <TBranch.h>
+#include <TFile.h>
 
 #include <AliRun.h>
 #include <AliRunDigitizer.h>
@@ -59,6 +63,8 @@ AliITSDigitizer::AliITSDigitizer() : AliDigitizer(){
 
     fITS    = 0;
     fActive = 0;
+    fRoif   = -1;
+    fRoiifile = 0;
 }
 //______________________________________________________________________
 AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr){
@@ -74,16 +80,24 @@ AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr){
     if(!gAlice) {
        fITS = 0;
        fActive = 0;
+       fRoif   = -1;
+       fRoiifile = 0;
        return;
     } // end if
     fITS = (AliITS *)(gAlice->GetDetector("ITS"));
     if(!fITS){
        fActive = 0;
+       fRoif   = -1;
+       fRoiifile = 0;
        return;
     } else if(fITS->GetITSgeom()){
        fActive = new Bool_t[fITS->GetITSgeom()->GetIndexMax()];
+       fRoif   = -1;
+       fRoiifile = 0;
     } else{
        fActive = 0;
+       fRoif   = -1;
+       fRoiifile = 0;
        return;
     } // end if
     // fActive needs to be set to a default all kTRUE value
@@ -103,21 +117,86 @@ AliITSDigitizer::~AliITSDigitizer(){
     if(fActive) delete[] fActive;
 }
 //______________________________________________________________________
+Bool_t AliITSDigitizer::Init(const char *filename){
+    // Initialization 
+    // Inputs:
+    //      none.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+     
+//    TFile *file = (TFile*)gROOT->GetListOfFiles()->FindObject(filename);
+//    if (file) {file->Close(); delete file;}
+    TFile *file = new TFile(filename);
+    if (!file->IsOpen()) {
+        Error("Init","Can't open %s!",filename);
+        return kFALSE;
+    } // end if !file 
+    if (gAlice) delete gAlice;
+    gAlice = (AliRun*)file->Get("gAlice");
+    if (!gAlice) {
+        Error("Init","AliRun object not found on file");
+        return kFALSE;
+    } // end if !gAlice
+
+    this->Init();
+    delete gAlice;
+    gAlice=0;
+    return kTRUE;
+}
+//______________________________________________________________________
 Bool_t AliITSDigitizer::Init(){
-    // Iniliztion 
+    // Initialization 
     // Inputs:
     //      none.
     // Outputs:
     //      none.
     // Return:
+
     //      none.
+//    TTree *ts;
+
+    if(!gAlice) {
+       fITS      = 0;
+       fActive   = 0;
+       fRoif     = -1;
+       fRoiifile = 0;
+//     cout << "init !gAlice"<<endl;
+       return kFALSE;
+    } // end if
+    fITS = (AliITS *)(gAlice->GetDetector("ITS"));
+    if(!fITS){
+       fActive   = 0;
+       fRoif     = -1;
+       fRoiifile = 0;
+//     cout << "init !fITS"<<endl;
+       return kFALSE;
+    } else if(fITS->GetITSgeom()){
+       fActive = new Bool_t[fITS->GetITSgeom()->GetIndexMax()];
+    } else{
+       fActive = 0;
+       fRoif   = -1;
+       fRoiifile = 0;
+//     cout << "init !fITS-GetITSgeom()"<<endl;
+       return kFALSE;
+    } // end if
+    // fActive needs to be set to a default all kTRUE value
+    for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fActive[i] = kTRUE;
+/*
+    if(fRoif>=0 && fRoiifile>=0 && fRoiifile<GetManager()->GetNinputs()){
+       ts = GetManager()->GetInputTreeS(fRoiifile);
+       cout << "calling SetByReionOfInterest"<<endl;
+       SetByRegionOfInterest(ts);
+    } // end if
+*/
     return kTRUE;
 }
 //______________________________________________________________________
 void AliITSDigitizer::Exec(Option_t* opt){
-    // Main digitizing function. 
+    // Main digitization function. 
     // Inputs:
-    //      Option_t * opt   list of subdetector to digitize. =0 all.
+    //      Option_t * opt   list of sub detector to digitize. =0 all.
     // Outputs:
     //      none.
     // Return:
@@ -133,7 +212,7 @@ void AliITSDigitizer::Exec(Option_t* opt){
     AliITSDetType    *iDetType = 0;
     static Bool_t    setDef    = kTRUE;
 
-    if( !fITS ) fITS = (AliITS*)(gAlice->GetDetector("ITS"));
+    if(!fITS) fITS = (AliITS*)(gAlice->GetDetector("ITS"));
     if(!fITS){
        Error("Exec","The ITS not found. aborting.");
        return;
@@ -154,24 +233,25 @@ void AliITSDigitizer::Exec(Option_t* opt){
     
     // Digitize 
     fITS->MakeBranchInTreeD( GetManager()->GetTreeD() );
+    if(fRoif!=-1)SetByRegionOfInterest(GetManager()->GetInputTreeS(fRoiifile));
 
     for( Int_t module=0; module<size; module++ ){
-       if(fActive) if(!fActive[module]) continue;
+       if(fActive && fRoif!=-1) if(!fActive[module]) continue;
         Int_t id = fITS->GetITSgeom()->GetModuleType( module );
         if( !all && !det[id] ) continue;
         iDetType = fITS->DetType( id );
         sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
-        if( !sim ) {
+        if(!sim) {
             Error( "Exec", "The simulation class was not instanciated!" );
             exit(1);
         } // end if !sim
-        
+
         // Fill the module with the sum of SDigits
         sim->InitSimulationModule( module, event );
-       cout << "Module=" << module;
+//     cout << "Module=" << module;
         for( Int_t ifiles=0; ifiles<nfiles; ifiles++ ){
-           cout <<" ifiles=" << ifiles;
-            TTree *treeS = GetManager()->GetInputTreeS( ifiles );
+//         cout <<" ifiles=" << ifiles;
+            TTree *treeS = GetManager()->GetInputTreeS(ifiles);
             if( !(treeS && fITS->GetSDigits()) ) continue;   
             TBranch *brchSDigits = treeS->GetBranch( name );
             if( brchSDigits ) {
@@ -187,15 +267,15 @@ void AliITSDigitizer::Exec(Option_t* opt){
             brchSDigits->GetEvent( module );
             sim->AddSDigitsToModule( sdig, mask );    
         } // end for ifiles
-       cout << " end ifiles loop" << endl;
-        // Digitise current module sum(SDigits)->Digits
+//     cout << " end ifiles loop" << endl;
+        // Digitize current module sum(SDigits)->Digits
         sim->FinishSDigitiseModule();
 
         // fills all branches - wasted disk space
         GetManager()->GetTreeD()->Fill();
         fITS->ResetDigits();
     } // end for module
-    cout << "end modules loop"<<endl;
+//    cout << "end modules loop"<<endl;
  
     GetManager()->GetTreeD()->GetEntries();
     GetManager()->GetTreeD()->Write( 0, TObject::kOverwrite );
@@ -205,3 +285,50 @@ void AliITSDigitizer::Exec(Option_t* opt){
     sdig->Clear();
     delete sdig;
 }
+//______________________________________________________________________
+void AliITSDigitizer::SetByRegionOfInterest(TTree *ts){
+    // Scans through the ITS branch of the SDigits tree, ts, for modules
+    // which have SDigits in them. For these modules, a flag is set to
+    // digitize only these modules. The value of fRoif determines how many
+    // neighboring modules will also be turned on. fRoif=0 will turn on only
+    // those modules with SDigits in them. fRoif=1 will turn on, in addition,
+    // those modules that are +-1 module from the one with the SDigits. And
+    // So on. This last feature is not supported yet.
+    // Inputs:
+    //      TTree *ts  The tree in which the existing SDigits will define the
+    //                 region of interest.
+    // Outputs:
+    //      none.
+    // Return:
+    //      none.
+    Int_t m,nm;
+    if(gAlice==0 && ts==0) return;
+    if(ts==0) ts = gAlice->TreeS();
+    TBranch *brchSDigits = ts->GetBranch(fITS->GetName());
+    TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
+//    cout << "Region of Interest ts="<<ts<<" brchSDigits="<<brchSDigits<<" sdig="<<sdig<<endl;
+
+    if( brchSDigits ) {
+       brchSDigits->SetAddress( &sdig ); 
+    } else {
+       Error( "SetByRegionOfInterest","branch ITS not found in TreeS");
+       return;
+    } // end if brchSDigits
+
+    nm = fITS->GetITSgeom()->GetIndexMax();
+    for(m=0;m<nm;m++){
+//     cout << " fActive["<<m<<"]=";
+       fActive[m] = kFALSE; // Not active by default
+       sdig->Clear();
+       brchSDigits->GetEvent(m);
+       if(sdig->GetLast()>=0){ // activate the necessary modules
+           if(fRoif>=0){
+               fActive[m] = kTRUE;
+//             cout << "kTRUE";
+           } // end if
+       } // end if.
+//     cout << endl;
+    } // end for m
+    sdig->Clear();
+    delete sdig;
+}