]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSDigitizer.cxx
FO signals are propagated from SDigits to Digits (A.MAstroserio)
[u/mrichter/AliRoot.git] / ITS / AliITSDigitizer.cxx
index dbd798e413f2aa600143beff557a4b62b99274a9..014f4a7fb8c47ab8734fc85d6ee844c7518374d0 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
  
-/*
-$Log$
-Revision 1.6  2002/10/22 14:45:34  alibrary
-Introducing Riostream.h
-
-Revision 1.5  2002/10/14 14:57:00  hristov
-Merging the VirtualMC branch to the main development branch (HEAD)
-
-Revision 1.3.4.1  2002/06/10 17:51:14  hristov
-Merged with v3-08-02
-
-Revision 1.4  2002/04/24 22:08:12  nilsen
-New ITS Digitizer/merger with two macros. One to make SDigits (old way) and
-one to run the  merger (modified for Jiri).
-
-Revision 1.3  2002/03/25 10:48:55  nilsen
-New ITS SDigit merging with region of interest cut. Update for changes in
-AliDigitizer. Additional optimization should be done.
-
-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 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
-Digitization changed to start from SDigits instead of Hits.
-The SDigits are reading as TClonesArray of AliITSpListItem
-*/
+/* $Id$ */
+///////////////////////////////////////////////////////////////////////////
+//Piotr.Skowronski@cern.ch :                                             //
+//Corrections applied in order to compile (only)                         // 
+//   with new I/O and folder structure                                   //
+//To be implemented correctly by responsible                             //
+//                                                                       //
+//  Class used to steer                                                  //
+//  the digitization for ITS                                             //
+//                                                                       //
+///////////////////////////////////////////////////////////////////////////
 
 #include <stdlib.h>
-#include <Riostream.h>
-#include <TObjArray.h>
+#include <TClonesArray.h>
 #include <TTree.h>
 #include <TBranch.h>
-#include <TFile.h>
-
-#include <AliRun.h>
-#include <AliRunDigitizer.h>
 
+#include "AliRun.h"
+#include "AliRunLoader.h"
+#include "AliLoader.h"
+#include "AliLog.h"
+#include "AliRunDigitizer.h"
 #include "AliITSDigitizer.h"
-#include "AliITSpList.h"
-#include "AliITSmodule.h"
-#include "AliITSsimulation.h"
-#include "AliITSDetType.h"
 #include "AliITSgeom.h"
+#include "AliITSgeomTGeo.h"
+#include "AliITSsimulation.h"
 
 ClassImp(AliITSDigitizer)
 
 //______________________________________________________________________
-AliITSDigitizer::AliITSDigitizer() : AliDigitizer(){
+AliITSDigitizer::AliITSDigitizer() : AliDigitizer(),
+fITS(0),
+fModActive(0),
+fInit(kFALSE),
+fRoif(-1),
+fRoiifile(0),
+fFlagFirstEv(kTRUE){
     // Default constructor. Assign fITS since it is never written out from
     // here. 
     // Inputs:
@@ -77,15 +58,18 @@ AliITSDigitizer::AliITSDigitizer() : AliDigitizer(){
     //      none.
     // Return:
     //      A blank AliITSDigitizer class.
+  fModActive = new Bool_t[AliITSgeomTGeo::GetNModules()];
+  for(Int_t i=0;i<AliITSgeomTGeo::GetNModules();i++) fModActive[i] = kTRUE;
 
-    fITS      = 0;
-    fActive   = 0;
-    fRoif     = -1;
-    fRoiifile = 0;
-    fInit     = kFALSE;
 }
 //______________________________________________________________________
-AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr){
+AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr),
+fITS(0),
+fModActive(0),
+fInit(kFALSE),
+fRoif(-1),
+fRoiifile(0),
+fFlagFirstEv(kTRUE){
     // Standard constructor. Assign fITS since it is never written out from
     // here. 
     // Inputs:
@@ -94,13 +78,11 @@ AliITSDigitizer::AliITSDigitizer(AliRunDigitizer *mngr) : AliDigitizer(mngr){
     //      none.
     // Return:
     //      An AliItSDigitizer class.
-
-    fITS      = 0;
-    fActive   = 0;
-    fRoif     = -1;
-    fRoiifile = 0;
-    fInit     = kFALSE;
+  fModActive = new Bool_t[AliITSgeomTGeo::GetNModules()];
+  for(Int_t i=0;i<AliITSgeomTGeo::GetNModules();i++) fModActive[i] = kTRUE;
 }
+
+
 //______________________________________________________________________
 AliITSDigitizer::~AliITSDigitizer(){
     // Default destructor. 
@@ -110,9 +92,8 @@ AliITSDigitizer::~AliITSDigitizer(){
     //      none.
     // Return:
     //      none.
-
     fITS = 0; // don't delete fITS. Done else where.
-    if(fActive) delete[] fActive;
+    if(fModActive) delete[] fModActive;
 }
 //______________________________________________________________________
 Bool_t AliITSDigitizer::Init(){
@@ -139,33 +120,13 @@ Bool_t AliITSDigitizer::Init(){
        fInit     = kFALSE;
        Warning("Init","ITS not found");
        return fInit;
-    } else if(fITS->GetITSgeom()){
-       //cout << "fRoif,fRoiifile="<<fRoif<<" "<<fRoiifile<<endl;
-       fActive = new Bool_t[fITS->GetITSgeom()->GetIndexMax()];
-    } else{
+    } 
+    if(!fITS->GetITSgeom()){
        fRoiifile = 0;
        fInit     = kFALSE;
        Warning("Init","ITS geometry not found");
        return fInit;
     } // 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;
-/*  This will not work from Init. ts is aways returned as zero.
-    TTree *ts;
-    if(fRoif>=0 && fRoiifile>=0 && fRoiifile<GetManager()->GetNinputs()){
-       ts = GetManager()->GetInputTreeS(fRoiifile);
-       if(!ts){
-           if(!gAlice) ts = gAlice->TreeS();
-           if(!ts){
-               cout <<"The TTree TreeS needed to set by region not found."
-                   " No region of interest cut will be applied."<< endl;
-               return fInit;
-           } // end if
-       } // end if
-       cout << "calling SetByReionOfInterest ts="<< ts <<endl;
-       SetByRegionOfInterest(ts);
-    } // end if
-*/
     return fInit;
 }
 //______________________________________________________________________
@@ -178,73 +139,116 @@ void AliITSDigitizer::Exec(Option_t* opt){
     // Return:
     //      none.
 
-    char name[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-    char *all;
+  char name[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+    const char *all;
     const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
                           strstr(opt,"SSD")};
     if( !det[0] && !det[1] && !det[2] ) all = "All";
     else all = 0;
+    Int_t nfiles = GetManager()->GetNinputs();
+    Int_t event  = GetManager()->GetOutputEventNr();
     AliITSsimulation *sim      = 0;
-    AliITSDetType    *iDetType = 0;
-    static Bool_t    setDef    = kTRUE;
-
+    if(fFlagFirstEv){
+      fITS->SetDefaults();    
+      fITS->SetDefaultSimulation();
+      fFlagFirstEv=kFALSE;
+    }
     if(!fInit){
-       Error("Exec","Init not succesfull, aborting.");
+       Error("Exec","Init not successful, aborting.");
        return;
     } // end if
 
-    if( setDef ) fITS->SetDefaultSimulation();
-    setDef = kFALSE;
-    sprintf(name,"%s",fITS->GetName());
+    snprintf(name,20,"%s",fITS->GetName());
 
-    Int_t nfiles = GetManager()->GetNinputs();
-    Int_t event  = GetManager()->GetOutputEventNr();
     Int_t size   = fITS->GetITSgeom()->GetIndexMax();
     Int_t module,id,ifiles,mask;
     Bool_t lmod;
     Int_t *fl = new Int_t[nfiles];
     fl[0] = fRoiifile;
     mask = 1;
-    for(id=0;id<nfiles;id++) if(id!=fRoiifile){
-       // just in case fRoiifile!=0.
-       fl[mask] = id;
-       mask++;
-    } // end for,if
+    for(id=0;id<nfiles;id++) 
+     if(id!=fRoiifile)
+      {
+       // just in case fRoiifile!=0.
+        fl[mask] = id;
+        mask++;
+      } // end for,if
     TClonesArray * sdig = new TClonesArray( "AliITSpListItem",1000 );
     
+    TString loadname(name);
+    loadname+="Loader";
+    
+    AliRunLoader *inRL = 0x0, *outRL = 0x0;
+    AliLoader *ingime = 0x0, *outgime = 0x0;    
+    
+    outRL = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName());    
+    if ( outRL == 0x0)
+     {
+       Error("Exec","Can not get Output Run Loader");
+       delete [] fl;
+       return;
+     }
+    outRL->GetEvent(event);
+    outgime = outRL->GetLoader(loadname);
+    if ( outgime == 0x0)
+     {
+       Error("Exec","Can not get Output ITS Loader");
+       delete [] fl;
+       return;
+     }
+
+    outgime->LoadDigits("update");
+    if (outgime->TreeD() == 0x0) outgime->MakeTree("D");
+    
     // Digitize
-    fITS->MakeBranchInTreeD(GetManager()->GetTreeD());
-    if(fRoif!=0) Info("AliITSDigitizer","Region of Interest digitization selected");
-    else Info("AliITSDigitizer","No Region of Interest selected. Digitizing everything");
-    //cout <<"fActive="<<fActive<<" fRoif="<<fRoif;
-    if(fActive==0) fRoif = 0; // fActive array must be define for RIO cuts.
-    //cout <<" fRoif="<<fRoif<<endl;
+    fITS->MakeBranchInTreeD(outgime->TreeD());
+    if(fRoif!=0) {
+      AliDebug(1,"Region of Interest digitization selected");
+    }
+    else {
+      AliDebug(1,"No Region of Interest selected. Digitizing everything");
+    }
 
-    for(module=0; module<size; module++ ){
-       if(fRoif!=0) if(!fActive[module]) continue;
-        id = fITS->GetITSgeom()->GetModuleType(module);
-        if(!all && !det[id]) continue;
-        iDetType = fITS->DetType( id );
-        sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
-        if(!sim) {
+
+    for(ifiles=0; ifiles<nfiles; ifiles++ )
+     {
+       inRL =  AliRunLoader::GetRunLoader(fManager->GetInputFolderName(fl[ifiles]));
+       ingime = inRL->GetLoader(loadname);
+       if (ingime->TreeS() == 0x0) ingime->LoadSDigits();
+     }
+
+    for(module=0; module<size; module++ )
+     {
+       if(fRoif!=0) if(!fModActive[module]) continue;
+       id = fITS->GetITSgeom()->GetModuleType(module);
+       if(!all && !det[id]) continue;
+       sim      = (AliITSsimulation*)fITS->GetSimulationModel(id);
+       if(!sim) {
             Error( "Exec", "The simulation class was not instanciated!" );
             exit(1);
         } // end if !sim
-
-        // Fill the module with the sum of SDigits
+           // Fill the module with the sum of SDigits
         sim->InitSimulationModule(module, event);
        //cout << "Module=" << module;
-        for(ifiles=0; ifiles<nfiles; ifiles++ ){
-           if(fRoif!=0) if(!fActive[module]) continue;
-           //cout <<" fl[ifiles=" << ifiles << "]=" << fl[ifiles];
-            TTree *treeS = GetManager()->GetInputTreeS(fl[ifiles]);
-            if( !(treeS && fITS->GetSDigits()) ) continue;   
-            TBranch *brchSDigits = treeS->GetBranch( name );
-            if( brchSDigits ) {
+        for(ifiles=0; ifiles<nfiles; ifiles++ )
+         {
+           if(fRoif!=0) if(!fModActive[module]) continue;
+            
+           inRL =  AliRunLoader::GetRunLoader(fManager->GetInputFolderName(fl[ifiles]));
+           ingime = inRL->GetLoader(loadname);
+           
+           TTree *treeS = ingime->TreeS();
+           fITS->SetTreeAddress();
+           
+           if( !treeS  ) continue; 
+           TBranch *brchSDigits = treeS->GetBranch( name );
+           if( brchSDigits ) 
+            {
                 brchSDigits->SetAddress( &sdig ); 
             } else {
                 Error( "Exec", "branch ITS not found in TreeS, input file %d ",
                        ifiles );
+               delete [] fl;
                return;
             } // end if brchSDigits
             sdig->Clear();
@@ -252,29 +256,36 @@ void AliITSDigitizer::Exec(Option_t* opt){
             // add summable digits to module
             brchSDigits->GetEvent( module );
             lmod = sim->AddSDigitsToModule(sdig,mask);
-           if(ifiles==0){
-               fActive[module] = lmod;
-           } // end if
-           //cout << " fActive["<<module<<"]=";
-           //if(fActive[module]) cout << "kTRUE";
-           //else cout << "kFALSE";
+            if(fRegionOfInterest && (ifiles==0))
+             {
+               fModActive[module] = lmod;
+             } // end if
         } // end for ifiles
        //cout << " end ifiles loop" << endl;
         // Digitize current module sum(SDigits)->Digits
-        sim->FinishSDigitiseModule();
+       sim->FinishSDigitiseModule();
 
         // fills all branches - wasted disk space
-        GetManager()->GetTreeD()->Fill();
-        fITS->ResetDigits();
+        outgime->TreeD()->Fill();
+       fITS->ResetDigits();
     } // end for module
-    //cout << "end modules loop"<<endl;
-
-    GetManager()->GetTreeD()->AutoSave();
+    fITS->WriteFOSignals(); 
+    outgime->TreeD()->AutoSave();
+    outgime->WriteDigits("OVERWRITE");
+    outgime->UnloadDigits();
+    for(ifiles=0; ifiles<nfiles; ifiles++ )
+     {
+       inRL =  AliRunLoader::GetRunLoader(fManager->GetInputFolderName(fl[ifiles]));
+       ingime = inRL->GetLoader(loadname);
+       ingime->UnloadSDigits();
+     }
 
     delete[] fl;
     sdig->Clear();
     delete sdig;
-    for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fActive[i] = kTRUE;
+    for(Int_t i=0;i<fITS->GetITSgeom()->GetIndexMax();i++) fModActive[i] = kTRUE;
+    
+
     return;
 }
 //______________________________________________________________________
@@ -302,29 +313,28 @@ void AliITSDigitizer::SetByRegionOfInterest(TTree *ts){
     //cout << "Region of Interest ts="<<ts<<" brchSDigits="<<brchSDigits<<" sdig="<<sdig<<endl;
 
     if( brchSDigits ) {
-       brchSDigits->SetAddress( &sdig );
+      brchSDigits->SetAddress( &sdig );
     } else {
-       Error( "SetByRegionOfInterest","branch ITS not found in TreeS");
-       return;
+      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) for(i=0;i<sdig->GetLast();i++){
-           // activate the necessary modules
-           if(((AliITSpList*)sdig->At(m))->GetpListItem(i)->GetSignal()>0.0){ // Must have non zero signal.
-               fActive[m] = kTRUE;
-               break;
-           } // end if
-       } // end if. end for i.
-       //cout << fActive[m];
-       //cout << endl;
+      fModActive[m] = kFALSE; // Not active by default
+      sdig->Clear();
+      brchSDigits->GetEvent(m);
+      if(sdig->GetLast()>=0) for(i=0;i<sdig->GetLast();i++){
+          // activate the necessary modules
+          if(((AliITSpList*)sdig->At(m))->GetpListItem(i)->GetSignal()>0.0){ // Must have non zero signal.
+            fModActive[m] = kTRUE;
+            break;
+          } // end if
+      } // end if. end for i.
+      //cout << fModActive[m];
+      //cout << endl;
     } // end for m
-    Info("AliITSDigitizer","Digitization by Region of Interest selected");
+    AliDebug(1,"Digitization by Region of Interest selected");
     sdig->Clear();
     delete sdig;
     return;