1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
19 ///////////////////////////////////////////////////////////////////////////////
21 // An overview of the basic philosophy of the ITS code development //
22 // and analysis is show in the figure below. //
25 <img src="picts/ITS/ITS_Analysis_schema.gif">
28 <font size=+2 color=red>
29 <p>Roberto Barbera is in charge of the ITS Offline code (1999).
30 <a href="mailto:roberto.barbera@ct.infn.it">Roberto Barbera</a>.
36 // AliITS. Inner Traking System base class.
37 // This class contains the base procedures for the Inner Tracking System
41 <img src="picts/ITS/AliITS_Class_Diagram.gif">
44 <font size=+2 color=red>
45 <p>This show the class diagram of the different elements that are part of
53 // Written by Rene Brun, Federico Carminati, and Roberto Barbera
56 // Modified and documented by Bjorn S. Nilsen
60 // Modified and documented by A. Bologna
63 // AliITS is the general base class for the ITS. Also see AliDetector for
64 // futher information.
66 ///////////////////////////////////////////////////////////////////////////////
69 #include <TClonesArray.h>
71 #include <TParticle.h>
74 #include <TVirtualMC.h>
75 #include "AliDetector.h"
77 #include "AliITSDetTypeSim.h"
78 #include "AliITSDDLRawData.h"
79 #include "AliITSLoader.h"
80 #include "AliITShit.h"
81 #include "AliITSmodule.h"
82 #include "AliITSpListItem.h"
83 #include "AliITSsimulation.h"
84 #include "AliITSsimulationFastPoints.h"
86 #include "AliITSDigitizer.h"
87 #include "AliITSRecPoint.h"
88 #include "AliITSsegmentationSPD.h"
89 #include "AliITSsegmentationSDD.h"
90 #include "AliITSsegmentationSSD.h"
91 #include "AliITSRawStreamSPD.h"
92 #include "AliITSRawStreamSSD.h"
93 #include "AliITSRawStreamSDD.h"
94 #include "AliITSresponseSDD.h"
95 #include "AliRawReader.h"
98 #include "AliITSInitGeometry.h"
102 //______________________________________________________________________
103 AliITS::AliITS() : AliDetector(){
104 // Default initializer for ITS
105 // The default constructor of the AliITS class. In addition to
106 // creating the AliITS class it zeros the variables fIshunt (a member
107 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
108 // fIdSens, and fIdName. The AliDetector default constructor
116 fIshunt = 0; // not zeroed in AliDetector.
121 // SetDetectors(); // default to fOpt="All". This variable not written out.
122 SetMarkerColor(kRed);
124 //______________________________________________________________________
125 AliITS::AliITS(const char *name, const char *title):AliDetector(name,title){
126 // The standard Constructor for the ITS class.
127 // It also zeros the variables
128 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
129 // the pointers fIdSens and fIdName. To help in displaying hits via the
130 // ROOT macro display.C AliITS also sets the marker color to red. The
131 // variables passes with this constructor, const char *name and *title,
132 // are used by the constructor of AliDetector class. See AliDetector
133 // class for a description of these parameters and its constructor
141 fHits = new TClonesArray("AliITShit",1560);
142 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
146 fIshunt = 0; // not zeroed in AliDetector
147 // Not done in AliDetector.
150 SetDetectors(); // default to fOpt="All". This variable not written out.
155 fDetTypeSim = new AliITSDetTypeSim();
157 SetMarkerColor(kRed);
158 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
159 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
162 //______________________________________________________________________
164 // Default destructor for ITS.
165 // The default destructor of the AliITS class. In addition to deleting
166 // the AliITS class it deletes the memory pointed to by
167 // fIdSens, fIdName, fDetTypeSim and it's contents.
181 this->ClearModules();
184 }// end if fITSmodules!=0
186 delete[] fIdName; // Array of TStrings
194 //______________________________________________________________________
195 AliITS::AliITS(const AliITS &source) : AliDetector(source){
196 // Copy constructor. This is a function which is not allowed to be
197 // done to the ITS. It exits with an error.
199 // AliITS &source An AliITS class.
205 if(this==&source) return;
206 Error("Copy constructor",
207 "You are not allowed to make a copy of the AliITS");
210 //______________________________________________________________________
211 AliITS& AliITS::operator=(const AliITS &source){
212 // Assignment operator. This is a function which is not allowed to be
213 // done to the ITS. It exits with an error.
215 // AliITS &source An AliITS class.
221 if(this==&source) return *this;
222 Error("operator=","You are not allowed to make a copy of the AliITS");
224 return *this; //fake return
226 //______________________________________________________________________
227 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
228 // Creates the AliITSDigitizer in a standard way for use via AliModule.
229 // This function can not be included in the .h file because of problems
230 // with the order of inclusion (recursive).
232 // AliRunDigitizer *manager The Manger class for Digitization
236 // A new AliITSRunDigitizer (cast as a AliDigitizer).
238 return new AliITSDigitizer(manager);
240 //______________________________________________________________________
242 // Initializer ITS after it has been built
243 // This routine initializes the AliITS class. It is intended to be
244 // called from the Init function in AliITSv?. Besides displaying a banner
245 // indicating that it has been called it initializes the array fIdSens
246 // and sets the default segmentation, response, digit and raw cluster
247 // classes therefore it should be called after a call to CreateGeometry.
258 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
263 //______________________________________________________________________
264 void AliITS::WriteGeometry(){
266 //Writes ITS geometry on gAlice
268 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
269 AliRunLoader* rl = fLoader->GetRunLoader();
271 AliITSgeom* geom = GetITSgeom();
276 //______________________________________________________________________
277 void AliITS::SetDefaults(){
278 // sets the default segmentation, response, digit and raw cluster classes.
285 AliInfoClass("AliITS::Setting Defaults");
288 Error("SetDefaults()","fDetTypeSim is 0!");
292 fDetTypeSim->SetDefaults();
296 //______________________________________________________________________
297 void AliITS::SetDefaultSimulation(){
298 // sets the default simulation.
306 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
310 fDetTypeSim->SetDefaultSimulation();
315 //______________________________________________________________________
316 void AliITS::MakeBranch(Option_t* option){
317 // Creates Tree branches for the ITS.
319 // Option_t *option String of Tree types S,D, and/or R.
320 // const char *file String of the file name where these branches
321 // are to be stored. If blank then these branches
322 // are written to the same tree as the Hits were
329 Error("MakeBranch","fDetTypeSim is 0!");
333 Bool_t cH = (strstr(option,"H")!=0);
334 Bool_t cS = (strstr(option,"S")!=0);
335 Bool_t cD = (strstr(option,"D")!=0);
337 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
338 AliDetector::MakeBranch(option);
340 if(cS) MakeBranchS(0);
341 if(cD) MakeBranchD(0);
345 //___________________________________________________________________
346 void AliITS::MakeBranchS(const char* fl){
348 // Creates Tree Branch for the ITS summable digits.
350 // cont char *fl File name where SDigits branch is to be written
351 // to. If blank it write the SDigits to the same
352 // file in which the Hits were found.
356 Error("MakeBranchS","fDetTypeSim is 0!");
358 Int_t buffersize = 4000;
361 // only one branch for SDigits.
362 sprintf(branchname,"%s",GetName());
364 if(fLoader->TreeS()){
365 if(fDetTypeSim->GetSDigits()==0x0) fDetTypeSim->SetSDigits(new TClonesArray("AliITSpListItem",1000));
366 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
367 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
370 //______________________________________________________________________
371 void AliITS::MakeBranchD(const char* file){
373 //Make branch for digits
375 Warning("MakeBranchD","fDetTypeSim is 0!");
378 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
379 MakeBranchInTreeD(fLoader->TreeD(),file);
382 //___________________________________________________________________
383 void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
384 // Creates Tree branches for the ITS.
387 Error("MakeBranchS","fDetTypeSim is 0!");
389 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
391 const Char_t *det[3] = {"SPD","SDD","SSD"};
393 Int_t buffersize = 4000;
394 Char_t branchname[30];
396 if(!fDetTypeSim->GetDigits()){
397 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
399 for(Int_t i=0;i<fgkNTYPES;i++){
400 digclass = fDetTypeSim->GetDigitClassName(i);
401 TString classn = digclass;
402 if(!((fDetTypeSim->GetDigits())->At(i))){
403 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
406 if(fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
407 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
408 TObjArray* dig = DigitsAddress(i);
409 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
413 //______________________________________________________________________
414 void AliITS::SetTreeAddress(){
415 // Set branch address for the Trees.
424 Error("SetTreeAddress","fDetTypeSim is 0!");
428 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
430 TTree *treeS = fLoader->TreeS();
431 TTree *treeD = fLoader->TreeD();
432 if (fLoader->TreeH() && (fHits == 0x0)) {
433 fHits = new TClonesArray("AliITShit", 1560);
435 AliDetector::SetTreeAddress();
437 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
438 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
440 //______________________________________________________________________
441 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
443 // The function to add information to the AliITShit class. See the
444 // AliITShit class for a full description. This function allocates the
445 // necessary new space for the hit information and passes the variable
446 // track, and the pointers *vol and *hits to the AliITShit constructor
449 // Int_t track Track number which produced this hit.
450 // Int_t *vol Array of Integer Hit information. See AliITShit.h
451 // Float_t *hits Array of Floating Hit information. see AliITShit.h
456 TClonesArray &lhits = *fHits;
457 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
460 //______________________________________________________________________
461 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
462 Option_t *option, const char *filename){
463 // fill the modules with the sorted by module hits; add hits from
464 // background if option=Add.
466 static TTree *trH1; //Tree with background hits
467 static Bool_t first=kTRUE;
469 const char *addBgr = strstr(option,"Add");
471 evnt = nmodules; // Dummy use of variables to remove warnings
474 file=new TFile(filename);
479 // Get Hits Tree header from file
480 if(trH1) delete trH1;
484 sprintf(treeName,"TreeH%d",bgrev);
485 trH1 = (TTree*)gDirectory->Get(treeName);
487 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
489 // Set branch addresses
492 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
495 FillModules(trH1,10000000); // Default mask 10M.
496 TTree *fAli=fLoader->GetRunLoader()->TreeK();
498 if (fAli) fileAli =fAli->GetCurrentFile();
506 //______________________________________________________________________
507 void AliITS::FillModules(TTree *treeH, Int_t mask) {
508 // fill the modules with the sorted by module hits;
509 // can be called many times to do a merging
511 // TTree *treeH The tree containing the hits to be copied into
513 // Int_t mask The track number mask to indecate which file
514 // this hits came from.
522 Error("FillModules","Tree is NULL");
524 Int_t lay,lad,det,index;
528 sprintf(branchname,"%s",GetName());
529 TBranch *branch = treeH->GetBranch(branchname);
531 Error("FillModules","%s branch in TreeH not found",branchname);
534 branch->SetAddress(&fHits);
535 Int_t nTracks =(Int_t) treeH->GetEntries();
537 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
539 Int_t nBytes = treeH->GetEvent(iPrimTrack);
540 if (nBytes <= 0) continue;
541 Int_t nHits = fHits->GetEntriesFast();
542 for(h=0; h<nHits; h++){
543 itsHit = (AliITShit *)fHits->UncheckedAt(h);
544 itsHit->GetDetectorID(lay,lad,det);
546 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
548 index=det-1; // This should not be used.
549 } // end if [You must have fITSgeom for this to work!]
550 mod = GetModule(index);
551 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
552 mod->AddHit(itsHit,iPrimTrack,h);
553 } // end loop over hits
554 } // end loop over tracks
557 //______________________________________________________________________
558 void AliITS::InitModules(Int_t size,Int_t &nmodules){
559 // Initialize the modules array.
561 // Int_t size Size of array of the number of modules to be
562 // created. If size <=0 then the number of modules
563 // is gotten from AliITSgeom class kept in fITSgeom.
565 // Int_t &nmodules The number of modules existing.
570 fITSmodules->Delete();
572 } // end fir fITSmoudles
575 Error("InitModules","fDetTypeSim is null!");
579 Int_t nl,indexMAX,index;
581 if(size<=0){ // default to using data stored in AliITSgeom
582 if(fDetTypeSim->GetITSgeom()==0) {
583 Error("InitModules","fITSgeom not defined");
585 } // end if fITSgeom==0
586 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
587 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
589 fITSmodules = new TObjArray(indexMAX);
590 for(index=0;index<indexMAX;index++){
591 fITSmodules->AddAt( new AliITSmodule(index),index);
594 fITSmodules = new TObjArray(size);
595 for(index=0;index<size;index++) {
596 fITSmodules->AddAt( new AliITSmodule(index),index);
602 //______________________________________________________________________
603 void AliITS::Hits2SDigits(){
604 // Standard Hits to summable Digits function.
612 Error("Hits2SDigits","fDetTypeSim is null!");
618 fLoader->LoadHits("read");
619 fLoader->LoadSDigits("recreate");
620 AliRunLoader* rl = fLoader->GetRunLoader();
621 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
622 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
623 // Do the Hits to Digits operation. Use Standard input values.
624 // Event number from file, no background hit merging , use size from
625 // AliITSgeom class, option="All", input from this file only.
626 rl->GetEvent(iEvent);
627 if (!fLoader->TreeS()) fLoader->MakeTree("S");
630 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
633 fLoader->UnloadHits();
634 fLoader->UnloadSDigits();
637 //______________________________________________________________________
638 void AliITS::Hits2Digits(){
640 //Conversion from hits to digits
642 Error("Hits2SDigits","fDetTypeSim is 0!");
646 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
649 fLoader->LoadHits("read");
650 fLoader->LoadDigits("recreate");
651 AliRunLoader* rl = fLoader->GetRunLoader();
652 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
653 rl->GetEvent(iEvent);
654 if (!fLoader->TreeD()) fLoader->MakeTree("D");
657 HitsToDigits(iEvent,0,-1," ",fOpt," ");
660 fLoader->UnloadHits();
661 fLoader->UnloadDigits();
665 //______________________________________________________________________
666 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
667 Option_t *option,Option_t *opt,
668 const char *filename){
669 // Keep galice.root for signal and name differently the file for
670 // background when add! otherwise the track info for signal will be lost !
671 // the condition below will disappear when the geom class will be
672 // initialized for all versions - for the moment it is only for v5 !
673 // 7 is the SDD beam test version.
675 // Int_t evnt Event to be processed.
676 // Int_t bgrev Background Hit tree number.
677 // Int_t nmodules Not used.
678 // Option_t *option String indicating if merging hits or not. To
679 // merge hits set equal to "Add". Otherwise no
680 // background hits are considered.
681 // Test_t *filename File name containing the background hits..
688 Error("HitsToDigits","fDetTypeSim is null!");
691 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
692 if(!GetITSgeom()) return; // need transformations to do digitization.
693 AliITSgeom *geom = GetITSgeom();
695 const char *all = strstr(opt,"All");
696 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
698 static Bool_t setDef=kTRUE;
699 if (setDef) SetDefaultSimulation();
703 InitModules(size,nmodules);
704 FillModules(evNumber,bgrev,nmodules,option,filename);
706 AliITSsimulation *sim = 0;
707 AliITSmodule *mod = 0;
709 for(Int_t module=0;module<geom->GetIndexMax();module++){
710 id = geom->GetModuleType(module);
711 if (!all && !det[id]) continue;
712 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
714 Error("HitsToDigits","The simulation class was not "
715 "instanciated for module %d type %s!",module,
716 geom->GetModuleTypeName(module));
719 mod = (AliITSmodule *)fITSmodules->At(module);
720 sim->DigitiseModule(mod,module,evNumber);
721 // fills all branches - wasted disk space
722 fLoader->TreeD()->Fill();
728 fLoader->TreeD()->GetEntries();
729 fLoader->TreeD()->AutoSave();
731 fLoader->TreeD()->Reset();
733 //_____________________________________________________________________
734 void AliITS::Hits2PreDigits(){
735 // Turn hits into SDigits
738 Error("Hits2SDigits","fDetTypeSim is 0!");
742 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
745 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
749 //______________________________________________________________________
750 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
751 Option_t *option,Option_t *opt,
752 const char *filename){
753 // Keep galice.root for signal and name differently the file for
754 // background when add! otherwise the track info for signal will be lost !
755 // the condition below will disappear when the geom class will be
756 // initialized for all versions - for the moment it is only for v5 !
757 // 7 is the SDD beam test version.
759 // Int_t evnt Event to be processed.
760 // Int_t bgrev Background Hit tree number.
761 // Int_t nmodules Not used.
762 // Option_t *option String indicating if merging hits or not. To
763 // merge hits set equal to "Add". Otherwise no
764 // background hits are considered.
765 // Test_t *filename File name containing the background hits..
773 Error("HitsToPreDigits","fDetTypeSim is null!");
776 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
779 Error("HitsToPreDigits","fGeom is null!");
780 return; // need transformations to do digitization.
782 AliITSgeom *geom = GetITSgeom();
784 const char *all = strstr(opt,"All");
785 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
787 static Bool_t setDef=kTRUE;
788 if (setDef) SetDefaultSimulation();
792 InitModules(size,nmodules);
793 FillModules(evNumber,bgrev,nmodules,option,filename);
796 AliITSsimulation *sim = 0;
797 AliITSmodule *mod = 0;
799 for(module=0;module<geom->GetIndexMax();module++){
800 id = geom->GetModuleType(module);
801 if (!all && !det[id]) continue;
802 sim = (AliITSsimulation*)GetSimulationModel(id);
804 Error("HitsToPreDigits","The simulation class was not "
805 "instanciated for module %d type %s!",module,
806 geom->GetModuleTypeName(module));
809 mod = (AliITSmodule *)fITSmodules->At(module);
810 sim->SDigitiseModule(mod,module,evNumber);
811 // fills all branches - wasted disk space
812 fLoader->TreeS()->Fill();
813 fDetTypeSim->ResetSDigits();
819 fLoader->TreeS()->GetEntries();
820 fLoader->TreeS()->AutoSave();
821 fLoader->WriteSDigits("OVERWRITE");
823 fLoader->TreeS()->Reset();
826 //_____________________________________________________________________
827 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
828 Option_t *opt0,Option_t *opt1,
830 // keep galice.root for signal and name differently the file for
831 // background when add! otherwise the track info for signal will be lost !
832 // the condition below will disappear when the geom class will be
833 // initialized for all versions - for the moment it is only for v5 !
835 // Int_t evnt Event to be processed.
836 // Int_t bgrev Background Hit tree number.
837 // Int_t size Size used by InitModules. See InitModules.
838 // Option_t *opt0 Option passed to FillModules. See FillModules.
839 // Option_t *opt1 String indicating if merging hits or not. To
840 // merge hits set equal to "Add". Otherwise no
841 // background hits are considered.
842 // Test_t *flnm File name containing the background hits..
851 Error("HitsToPreDigits","fGeom is null!");
852 return; // need transformations to do digitization.
854 AliITSgeom *geom = GetITSgeom();
856 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
858 const char *all = strstr(opt1,"All");
859 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
862 InitModules(size,nmodules);
863 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
865 AliITSsimulation *sim = 0;
866 AliITSmodule *mod = 0;
869 TTree *lTR = pITSloader->TreeR();
871 pITSloader->MakeTree("R");
872 lTR = pITSloader->TreeR();
875 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
876 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
877 branch->SetAddress(&ptarray);
878 //m.b. : this change is nothing but a nice way to make sure
880 for(module=0;module<geom->GetIndexMax();module++){
881 id = geom->GetModuleType(module);
882 if (!all && !det[id]) continue;
883 sim = (AliITSsimulation*)GetSimulationModel(id);
885 Error("HitsToFastPoints","The simulation class was not "
886 "instanciated for module %d type %x!",module,
887 geom->GetModuleTypeName(module));
890 mod = (AliITSmodule *)fITSmodules->At(module);
891 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
896 fLoader->WriteRecPoints("OVERWRITE");
899 //_____________________________________________________________________
900 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
901 //------------------------------------------------------------
902 // This function creates ITS clusters
903 //------------------------------------------------------------
905 Error("HitsToPreDigits","fGeom is null!");
906 return 1; // need transformations to do digitization.
908 AliITSgeom *geom=GetITSgeom();
909 Int_t mmax=geom->GetIndexMax();
911 InitModules(-1,mmax);
912 FillModules(hTree,0);
914 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
915 TBranch *branch=cTree->GetBranch("ITSRecPoints");
916 if (!branch) cTree->Branch("ITSRecPoints",&points);
917 else branch->SetAddress(&points);
919 AliITSsimulationFastPoints sim;
921 for (Int_t m=0; m<mmax; m++) {
922 AliITSmodule *mod=GetModule(m);
923 sim.CreateFastRecPoints(mod,m,gRandom,points);
924 ncl+=points->GetEntriesFast();
929 Info("Hits2Clusters","Number of found fast clusters : %d",ncl);
937 //_____________________________________________________________________
938 void AliITS::CheckLabels(Int_t lab[3]) const {
939 //------------------------------------------------------------
940 // Tries to find mother's labels
941 //------------------------------------------------------------
943 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
945 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
946 for (Int_t i=0;i<3;i++){
947 Int_t label = lab[i];
948 if (label>=0 && label<ntracks) {
949 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
950 if (part->P() < 0.005) {
951 Int_t m=part->GetFirstMother();
955 if (part->GetStatusCode()>0) {
965 //______________________________________________________________________
966 void AliITS::SDigitsToDigits(Option_t *opt){
967 // Standard Summable digits to Digits function.
973 Error("SDigitsToSDigits","fDetTypeSim is 0!");
977 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
979 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
983 //______________________________________________________________________
984 void AliITS::ResetDigits(){
985 // Reset number of digits and the digits array for the ITS detector.
991 Error("ResetDigits","fDetTypeSim is 0!");
995 fDetTypeSim->ResetDigits();
999 //______________________________________________________________________
1000 void AliITS::ResetDigits(Int_t branch){
1001 // Reset number of digits and the digits array for this branch.
1008 Error("ResetDigits","fDetTypeSim is 0!");
1012 fDetTypeSim->ResetDigits(branch);
1015 //______________________________________________________________________
1016 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1017 // Adds the a module full of summable digits to the summable digits tree.
1019 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1026 Error("AddSumDigit","fDetTypeSim is 0!");
1029 fDetTypeSim->AddSumDigit(sdig);
1032 //______________________________________________________________________
1033 void AliITS::AddRealDigit(Int_t branch, Int_t *digits){
1034 // Add a real digit - as coming from data.
1036 // Int_t id Detector type number.
1037 // Int_t *digits Integer array containing the digits info. See
1045 Error("AddRealDigit","fDetTypeSim is 0!");
1048 fDetTypeSim->AddRealDigit(branch,digits);
1051 //______________________________________________________________________
1052 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1053 // Add a simulated digit.
1055 // Int_t id Detector type number.
1056 // AliITSdigit *d Digit to be added to the Digits Tree. See
1064 Error("AddSimDigit","fDetTypeSim is 0!");
1067 fDetTypeSim->AddSimDigit(branch,d);
1070 //______________________________________________________________________
1071 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1072 Int_t *hits,Float_t *charges){
1073 // Add a simulated digit to the list.
1075 // Int_t id Detector type number.
1076 // Float_t phys Physics indicator. See AliITSdigits.h
1077 // Int_t *digits Integer array containing the digits info. See
1079 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1080 // containing the track numbers that contributed to
1082 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1083 // containing the hit numbers, from AliITSmodule, that
1084 // contributed to this digit.
1085 // Float_t *charge Floating point array of the signals contributed
1086 // to this digit by each track.
1093 Error("AddSimDigit","fDetTypeSim is 0!");
1096 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges);
1099 //______________________________________________________________________
1100 void AliITS::Digits2Raw(){
1101 // convert digits of the current event to raw data
1104 Error("Digits2Raw","fDetTypeSim is 0!");
1107 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1109 fDetTypeSim->GetLoader()->LoadDigits();
1110 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1112 Error("Digits2Raw", "no digits tree");
1115 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1117 AliITSDDLRawData rawWriter;
1121 // 2: txt files with digits
1122 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1123 //it is highly suggested to use this mode only for debugging digits files
1124 //reasonably small, because otherwise the size of the txt files can reach
1125 //quickly several MB wasting time and disk space.
1126 rawWriter.SetVerbose(0);
1128 //SILICON PIXEL DETECTOR
1129 Info("Digits2Raw", "Formatting raw data for SPD");
1130 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"));
1132 //SILICON DRIFT DETECTOR
1133 Info("Digits2Raw", "Formatting raw data for SDD");
1134 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"));
1136 //SILICON STRIP DETECTOR
1137 Info("Digits2Raw", "Formatting raw data for SSD");
1138 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1140 fLoader->UnloadDigits();
1142 //______________________________________________________________________
1143 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1144 //builds ITSgetter (AliLoader type)
1145 //if detector wants to use castomized getter, it must overload this method
1147 Info("MakeLoader","Creating AliITSLoader. Top folder is %s.",
1149 fLoader = new AliITSLoader(GetName(),topfoldername);
1153 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1156 // Converts RAW data to SDigits
1161 Int_t size = GetITSgeom()->GetIndexMax();
1162 TClonesArray** modA = new TClonesArray*[size];
1163 for (Int_t mod = 0; mod < size; mod++) modA[mod] = new TClonesArray("AliITSpListItem", 10000);
1165 AliLoader* loader = (gAlice->GetRunLoader())->GetLoader("ITSLoader");
1168 Error("Open","Can not get ITS loader from Run Loader");
1173 tree = loader->TreeS();
1176 loader->MakeTree("S");
1177 tree = loader->TreeS();
1180 // Array for SDigits
1182 TClonesArray aSDigits("AliITSpListItem",10000), *itsSDigits=&aSDigits;
1183 Int_t bufsize = 32000;
1184 tree->Branch("ITS", &itsSDigits, bufsize);
1189 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1190 npx = segSPD->Npx();
1191 Double_t thr, sigma;
1193 AliITSRawStreamSPD inputSPD(rawReader);
1195 Bool_t next = inputSPD.Next();
1198 Int_t module = inputSPD.GetModuleID();
1199 Int_t column = inputSPD.GetColumn();
1200 Int_t row = inputSPD.GetRow();
1201 Int_t index = npx * column + row;
1203 if (module >= size) continue;
1205 last = (modA[module])->GetEntries();
1206 TClonesArray& dum = *modA[module];
1207 fDetTypeSim->GetCalibrationModel(module)->Thresholds(thr,sigma);
1209 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1216 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1217 npx = segSDD->Npx();
1218 AliITSRawStreamSDD inputSDD(rawReader);
1220 Bool_t next = inputSDD.Next();
1223 Int_t module = inputSDD.GetModuleID();
1224 Int_t anode = inputSDD.GetAnode();
1225 Int_t time = inputSDD.GetTime();
1226 Int_t signal = inputSDD.GetSignal();
1227 Int_t index = npx * anode + time;
1229 if (module >= size) continue;
1231 AliITSresponseSDD *resSDD = (AliITSresponseSDD*) fDetTypeSim->GetResponse(1);
1232 Int_t signal10 = resSDD->Convert8to10(signal); // signal is a 8 bit value (if the compression is active)
1234 last = modA[module]->GetEntries();
1235 TClonesArray& dum = *modA[module];
1236 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1237 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1245 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1246 npx = segSSD->Npx();
1247 AliITSRawStreamSSD inputSSD(rawReader);
1249 Bool_t next = inputSSD.Next();
1252 Int_t module = inputSSD.GetModuleID();
1253 Int_t side = inputSSD.GetSideFlag();
1254 Int_t strip = inputSSD.GetStrip();
1255 Int_t signal = inputSSD.GetSignal();
1256 Int_t index = npx * side + strip;
1258 if (module >= size) continue;
1260 last = modA[module]->GetEntries();
1261 TClonesArray& dum = *modA[module];
1262 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1265 AliITSpListItem* sdig = 0;
1267 for (Int_t mod = 0; mod < size; mod++)
1269 Int_t nsdig = modA[mod]->GetEntries();
1270 for (Int_t ie = 0; ie < nsdig; ie++) {
1271 sdig = (AliITSpListItem*) (modA[mod]->At(ie));
1272 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), sdig->GetSignal());
1273 Float_t sig = sdig->GetSignalAfterElect();
1275 sdig = (AliITSpListItem*)aSDigits[ie];
1276 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1284 loader->WriteSDigits("OVERWRITE");
1290 //______________________________________________________________________
1291 void AliITS::UpdateInternalGeometry(){
1293 Info("UpdateInternalGeometry", "Delete ITSgeom and create a new one reading TGeo");
1294 AliITSInitGeometry *initgeom = new AliITSInitGeometry("AliITSvPPRasymmFMD",2);
1295 AliITSgeom* geom = initgeom->CreateAliITSgeom();
1298 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
1299 AliRunLoader* rl = fLoader->GetRunLoader();
1301 geom->Write(0,kOverwrite);