]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITS.cxx
Changes by Massimo Masera to allow the TTree of clusters to be written to a
[u/mrichter/AliRoot.git] / ITS / AliITS.cxx
index 13f6f325a311576ba0df12375bed008b05d921c5..e357a1c26d80dd3e3e10b5fb7f133389398caa7f 100644 (file)
 
 /*
 $Log$
+Revision 1.69  2002/05/05 21:06:55  nilsen
+Added GetSimulationMoel, and fixed up SetDefaultSimulation to do the
+proper initilization when a simulation has already been defined.
+
+Revision 1.68  2002/05/02 18:51:53  nilsen
+AliITS.h
+   Method MakeBranchR has now a second argument, with a default value:
+       Option_t *opt=" ". Opt="Fast" is to create a separate branch
+       for fast points in TreeR
+   New method MakeBranchRF: it a separate branch in TreeR for Fast Points
+
+AliITS.cxx
+1) TTree->Write() replaced with TTree->AutoSave for TreeS, TreeD and
+   TreeR
+2) Changes in MakeBranchR to allow the creation of a special branch
+   for fast points
+
+Revision 1.67  2002/03/15 17:22:51  nilsen
+Intoduced SDigits2Digits and SDigitsToDigits functions.
+
+Revision 1.66  2001/11/28 01:35:45  nilsen
+Using standard constructors instead of default constructors for Clusterfinder,
+Response, and FastSimulator.
+
+Revision 1.65  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
+the original Root Directory in function Compress1D. Now it uses gDirectory.
+
+Revision 1.64  2001/11/19 16:17:02  nilsen
+Applyed fixes to bugs found by Rene Brun. With many thanks. Some additonal
+bugs found by Rene require more work to fix. Will be fixed soon.
+
 Revision 1.63  2001/10/24 21:16:34  nilsen
 Removed some dead code and improved comments/documntation.
 
@@ -255,7 +291,6 @@ the AliITS class.
 #include <TString.h>
 
 #include "AliMC.h"
-#include "AliRun.h"
 #include "AliHeader.h"
 
 #include "AliITS.h"
@@ -303,7 +338,8 @@ AliITS::AliITS() : AliDetector() {
     fEuclidOut  = 0;
     fITSgeom    = 0;
     fITSmodules = 0;
-    SetDetectors(); // default to fOpt="All". This variable not written out.
+    fOpt        = "All";
+//    SetDetectors(); // default to fOpt="All". This variable not written out.
 
     fIdN        = 0;
     fIdName     = 0;
@@ -533,7 +569,7 @@ void AliITS::SetDefaults(){
     // SDD
     iDetType=DetType(1); 
     if (!iDetType->GetResponseModel()) {
-       SetResponseModel(1,new AliITSresponseSDD()); 
+       SetResponseModel(1,new AliITSresponseSDD("simulated")); 
     } // end if
     AliITSresponse *resp1=iDetType->GetResponseModel();
     if (!iDetType->GetSegmentationModel()) {
@@ -553,7 +589,7 @@ void AliITS::SetDefaults(){
        SetSegmentationModel(2,seg2); 
     } // end if
     if (!iDetType->GetResponseModel()) {
-       SetResponseModel(2,new AliITSresponseSSD()); 
+       SetResponseModel(2,new AliITSresponseSSD("simulated"));
     } // end if
     const char *kData2=(iDetType->GetResponseModel())->DataType();
     if (strstr(kData2,"real")) {
@@ -576,29 +612,57 @@ void AliITS::SetDefaultSimulation(){
     //      none.
 
     AliITSDetType *iDetType;
+    AliITSsimulation *sim;
     iDetType=DetType(0);
-    if (!iDetType->GetSimulationModel()) {
+    sim = iDetType->GetSimulationModel();
+    if (!sim) {
        AliITSsegmentation *seg0=
            (AliITSsegmentation*)iDetType->GetSegmentationModel();
        AliITSresponse *res0 = (AliITSresponse*)iDetType->GetResponseModel();
        AliITSsimulationSPD *sim0=new AliITSsimulationSPD(seg0,res0);
        SetSimulationModel(0,sim0);
+    }else{ // simulation exists, make sure it is set up properly.
+       ((AliITSsimulationSPD*)sim)->Init(
+           (AliITSsegmentationSPD*) iDetType->GetSegmentationModel(),
+           (AliITSresponseSPD*) iDetType->GetResponseModel());
+//     if(sim->GetResponseModel()==0) sim->SetResponseModel(
+//         (AliITSresponse*)iDetType->GetResponseModel());
+//     if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
+//         (AliITSsegmentation*)iDetType->GetSegmentationModel());
     } // end if
     iDetType=DetType(1);
-    if (!iDetType->GetSimulationModel()) {
+    sim = iDetType->GetSimulationModel();
+    if (!sim) {
        AliITSsegmentation *seg1=
            (AliITSsegmentation*)iDetType->GetSegmentationModel();
        AliITSresponse *res1 = (AliITSresponse*)iDetType->GetResponseModel();
        AliITSsimulationSDD *sim1=new AliITSsimulationSDD(seg1,res1);
        SetSimulationModel(1,sim1);
+    }else{ // simulation exists, make sure it is set up properly.
+       ((AliITSsimulationSDD*)sim)->Init(
+           (AliITSsegmentationSDD*) iDetType->GetSegmentationModel(),
+           (AliITSresponseSDD*) iDetType->GetResponseModel());
+//     if(sim->GetResponseModel()==0) sim->SetResponseModel(
+//         (AliITSresponse*)iDetType->GetResponseModel());
+//     if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
+//         (AliITSsegmentation*)iDetType->GetSegmentationModel());
     } //end if
     iDetType=DetType(2);
-    if (!iDetType->GetSimulationModel()) {
+    sim = iDetType->GetSimulationModel();
+    if (!sim) {
        AliITSsegmentation *seg2=
            (AliITSsegmentation*)iDetType->GetSegmentationModel();
        AliITSresponse *res2 = (AliITSresponse*)iDetType->GetResponseModel();
        AliITSsimulationSSD *sim2=new AliITSsimulationSSD(seg2,res2);
        SetSimulationModel(2,sim2);
+    }else{ // simulation exists, make sure it is set up properly.
+       ((AliITSsimulationSSD*)sim)->Init(
+           (AliITSsegmentationSSD*) iDetType->GetSegmentationModel(),
+           (AliITSresponseSSD*) iDetType->GetResponseModel());
+//     if(sim->GetResponseModel()==0) sim->SetResponseModel(
+//         (AliITSresponse*)iDetType->GetResponseModel());
+//     if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
+//         (AliITSsegmentation*)iDetType->GetSegmentationModel());
     } // end if
 }
 //______________________________________________________________________
@@ -662,15 +726,18 @@ void AliITS::MakeBranch(Option_t* option, const char *file){
     //      none.
     // Return:
     //      none.
-    const char *cS = strstr(option,"S");
-    const char *cD = strstr(option,"D");
-    const char *cR = strstr(option,"R");
+    Bool_t cS = (strstr(option,"S")!=0);
+    Bool_t cD = (strstr(option,"D")!=0);
+    Bool_t cR = (strstr(option,"R")!=0);
+    Bool_t cRF = (strstr(option,"RF")!=0);
+    if(cRF)cR = kFALSE;
 
     AliDetector::MakeBranch(option,file);
 
     if(cS) MakeBranchS(file);
     if(cD) MakeBranchD(file);
     if(cR) MakeBranchR(file);
+    if(cRF) MakeBranchRF(file);
 }
 //______________________________________________________________________
 void AliITS::SetTreeAddress(){
@@ -989,9 +1056,10 @@ void AliITS::SetTreeAddressS(TTree *treeS){
     if (branch) branch->SetAddress(&fSDigits);
 }
 //______________________________________________________________________
-void AliITS::MakeBranchD(const char *file){
+void AliITS::MakeBranchInTreeD(TTree *treeD,const char *file){
     // Creates Tree branches for the ITS.
     // Inputs:
+    //      TTree     *treeD Pointer to the Digits Tree.
     //      cont char *file  File name where Digits branch is to be written
     //                       to. If blank it write the SDigits to the same
     //                       file in which the Hits were found.
@@ -1017,8 +1085,8 @@ void AliITS::MakeBranchD(const char *file){
     for (i=0; i<kNTYPES ;i++) {
        if (kNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
        else  sprintf(branchname,"%sDigits%d",GetName(),i+1);      
-       if (fDtype && gAlice->TreeD()) {
-           MakeBranchInTree(gAlice->TreeD()
+       if (fDtype && treeD) {
+           MakeBranchInTree(treeD
                             branchname, &((*fDtype)[i]),buffersize,file);
        } // end if
     } // end for i
@@ -1061,7 +1129,7 @@ void AliITS::Hits2SDigits(){
     // Outputs:
     //      none.
 
-    return; // Using Hits in place of the larger sDigits.
+//    return; // Using Hits in place of the larger sDigits.
     AliHeader *header=gAlice->GetHeader(); // Get event number from this file.
     // Do the Hits to Digits operation. Use Standard input values.
     // Event number from file, no background hit merging , use size from
@@ -1083,14 +1151,68 @@ void AliITS::Hits2PreDigits(){
     HitsToPreDigits(header->GetEvent(),0,-1," ",fOpt," ");
 }
 //______________________________________________________________________
-void AliITS::SDigits2Digits(){
+void AliITS::SDigitsToDigits(Option_t *opt){
     // Standard Summable digits to Digits function.
     // Inputs:
     //      none.
     // Outputs:
     //      none.
+    char name[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+
+    if(!GetITSgeom()) return; // need transformations to do digitization.
+    AliITSgeom *geom = GetITSgeom();
+
+    const char *all = strstr(opt,"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;
+    static Bool_t setDef=kTRUE;
+    if (setDef) SetDefaultSimulation();
+    setDef=kFALSE;
+
+    AliITSsimulation *sim      = 0;
+    AliITSDetType    *iDetType = 0;
+    TTree            *trees    = gAlice->TreeS();
+    if( !(trees && this->GetSDigits()) ){
+       Error("SDigits2Digits","Error: No trees or SDigits. Returning.");
+       return;
+    } // end if
+    sprintf( name, "%s", this->GetName() );
+    TBranch *brchSDigits = trees->GetBranch( name );
+    
+    Int_t id,module;
+    for(module=0;module<geom->GetIndexMax();module++){
+       id       = geom->GetModuleType(module);
+        if (!all && !det[id]) continue;
+       iDetType = DetType(id);
+       sim      = (AliITSsimulation*)iDetType->GetSimulationModel();
+       if (!sim) {
+           Error("SDigit2Digits",
+                 "The simulation class was not instanciated!");
+           exit(1);
+       } // end if !sim
+       sim->InitSimulationModule(module,gAlice->GetEvNumber());
+//
+       // add summable digits to module
+       this->GetSDigits()->Clear();
+       brchSDigits->GetEvent(module);
+       sim->AddSDigitsToModule(GetSDigits(),0);
+//
+        // Digitise current module sum(SDigits)->Digits
+        sim->FinishSDigitiseModule();
+
+        // fills all branches - wasted disk space
+        gAlice->TreeD()->Fill();
+        this->ResetDigits();
+    } // end for module
+
+    gAlice->TreeD()->GetEntries();
 
-    Hits2Digits();
+    gAlice->TreeD()->AutoSave();
+    // reset tree
+    gAlice->TreeD()->Reset();
+    
 }
 //______________________________________________________________________
 void AliITS::Hits2Digits(){
@@ -1127,7 +1249,9 @@ void AliITS::HitsToSDigits(Int_t evNumber,Int_t bgrev,Int_t size,
     //      none.
     // Return:
     //      none.
-    return; // using Hits instead of the larger sdigits.
+//    return; // using Hits instead of the larger sdigits.
+
+    HitsToPreDigits(evNumber,bgrev,size,option,opt,filename);
 }
 //______________________________________________________________________
 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
@@ -1188,10 +1312,7 @@ void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
     ClearModules();
 
     gAlice->TreeS()->GetEntries();
-
-    char hname[30];
-    sprintf(hname,"TreeS%d",evNumber);
-    gAlice->TreeS()->Write(hname,TObject::kOverwrite);
+    gAlice->TreeS()->AutoSave();
     // reset tree
     gAlice->TreeS()->Reset();
 }
@@ -1254,10 +1375,7 @@ void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
     ClearModules();
 
     gAlice->TreeD()->GetEntries();
-
-    char hname[30];
-    sprintf(hname,"TreeD%d",evNumber);
-    gAlice->TreeD()->Write(hname,TObject::kOverwrite);
+    gAlice->TreeD()->AutoSave();
     // reset tree
     gAlice->TreeD()->Reset();
 }
@@ -1397,7 +1515,9 @@ void AliITS::MakeTreeC(Option_t *option){
     //      none.
     // Return:
     //      none.
-
+  TDirectory *cwd = gDirectory;
+  TFile *fileRecPoints = gAlice->GetTreeRFile();
+  if(fileRecPoints)fileRecPoints->cd();
     const char *optC = strstr(option,"C");
     if (optC && !fTreeC) fTreeC = new TTree("TC","Clusters in ITS");
     else return;
@@ -1421,6 +1541,7 @@ void AliITS::MakeTreeC(Option_t *option){
            TreeC()->Branch(branchname,&((*fCtype)[i]), buffersize);
        } // end if fCtype && fTreeC
     } // end for i
+    cwd->cd();
 }
 //______________________________________________________________________
 void AliITS::GetTreeC(Int_t event){
@@ -1441,7 +1562,13 @@ void AliITS::GetTreeC(Int_t event){
     } // end if fTreeC
 
     sprintf(treeName,"TreeC%d",event);
-    fTreeC = (TTree*)gDirectory->Get(treeName);
+    TFile *fileRecPoints = gAlice->GetTreeRFile();
+    if(!fileRecPoints){
+      fTreeC = (TTree*)gDirectory->Get(treeName);
+    }
+    else {
+      fTreeC = (TTree*)fileRecPoints->Get(treeName);
+    }
 
     TBranch *branch;
 
@@ -1516,7 +1643,7 @@ void AliITS::ResetClusters(Int_t i){
     if (fNctype)  fNctype[i]=0;
 }
 //______________________________________________________________________
-void AliITS::MakeBranchR(const char *file){
+void AliITS::MakeBranchR(const char *file, Option_t *opt){
     // Creates Tree branches for the ITS Reconstructed points.
     // Inputs:
     //      cont char *file  File name where RecPoints branch is to be written
@@ -1530,7 +1657,12 @@ void AliITS::MakeBranchR(const char *file){
     char branchname[30];
 
     // only one branch for rec points for all detector types
-    sprintf(branchname,"%sRecPoints",GetName());
+    Bool_t oFast= (strstr(opt,"Fast")!=0);
+    if(oFast){
+      sprintf(branchname,"%sRecPointsF",GetName());
+    } else {
+      sprintf(branchname,"%sRecPoints",GetName());
+    }
     if (fRecPoints && gAlice->TreeR()) {
        MakeBranchInTree(gAlice->TreeR(),branchname,&fRecPoints,buffsz,file);
     } // end if
@@ -1550,7 +1682,16 @@ void AliITS::SetTreeAddressR(TTree *treeR){
     TBranch *branch;
     sprintf(branchname,"%sRecPoints",GetName());
     branch = treeR->GetBranch(branchname);
-    if (branch) branch->SetAddress(&fRecPoints);
+    if (branch) {
+      branch->SetAddress(&fRecPoints);
+    }
+    else {
+      sprintf(branchname,"%sRecPointsF",GetName());
+      branch = treeR->GetBranch(branchname);
+      if (branch) {
+        branch->SetAddress(&fRecPoints);
+      }
+    }
 }
 //______________________________________________________________________
 void AliITS::AddRecPoint(const AliITSRecPoint &r){
@@ -1616,15 +1757,15 @@ void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
        } // end if !sim
        mod      = (AliITSmodule *)fITSmodules->At(module);
        sim->CreateFastRecPoints(mod,module,gRandom);
-       gAlice->TreeR()->Fill(); 
+    // gAlice->TreeR()->Fill(); 
+    TBranch *br=gAlice->TreeR()->GetBranch("ITSRecPointsF");
+    br->Fill();
        ResetRecPoints();
     } // end for module
 
     ClearModules();
 
-    char hname[30];
-    sprintf(hname,"TreeR%d",evNumber);
-    gAlice->TreeR()->Write(hname,TObject::kOverwrite);
+    gAlice->TreeR()->AutoSave();
     // reset tree
     gAlice->TreeR()->Reset();
 }
@@ -1670,7 +1811,6 @@ void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt){
     setRec=kFALSE;
 
     TTree *treeC=TreeC();
-
     AliITSClusterFinder *rec     = 0;
     AliITSDetType      *iDetType = 0;
     Int_t id,module,first=0;
@@ -1691,7 +1831,7 @@ void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt){
        else gAlice->TreeD()->GetEvent(lastentry+(module-first));
        Int_t ndigits = itsDigits->GetEntriesFast();
        if (ndigits) rec->FindRawClusters(module);
-       gAlice->TreeR()->Fill(); 
+    gAlice->TreeR()->Fill(); 
        ResetRecPoints();
        treeC->Fill();
        ResetClusters();
@@ -1699,15 +1839,11 @@ void AliITS::DigitsToRecPoints(Int_t evNumber,Int_t lastentry,Option_t *opt){
 
     gAlice->TreeR()->GetEntries();
     treeC->GetEntries();
-
-    char hname[30];
-    sprintf(hname,"TreeR%d",evNumber);
-    gAlice->TreeR()->Write(hname,TObject::kOverwrite);
+    gAlice->TreeR()->AutoSave();
     // reset tree
     gAlice->TreeR()->Reset();
 
-    sprintf(hname,"TreeC%d",evNumber);
-    treeC->Write(hname,TObject::kOverwrite);
+    treeC->AutoSave();
     treeC->Reset();
 }
 //______________________________________________________________________