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(),
113 // Default initializer for ITS
114 // The default constructor of the AliITS class. In addition to
115 // creating the AliITS class it zeros the variables fIshunt (a member
116 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
117 // fIdSens, and fIdName. The AliDetector default constructor
120 // SetDetectors(); // default to fOpt="All". This variable not written out.
121 //PH SetMarkerColor(kRed);
123 //______________________________________________________________________
124 AliITS::AliITS(const Char_t *title):AliDetector("ITS",title),
134 // The standard Constructor for the ITS class.
135 // It also zeros the variables
136 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
137 // the pointers fIdSens and fIdName. To help in displaying hits via the
138 // ROOT macro display.C AliITS also sets the marker color to red. The
139 // variables passes with this constructor, const char *name and *title,
140 // are used by the constructor of AliDetector class. See AliDetector
141 // class for a description of these parameters and its constructor
144 // Char_t *title Simulation title for the ITS
150 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
151 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
152 //fNhits=0; //done in AliDetector(name,title)
153 SetDetectors(); // default to fOpt="All". This variable not written out.
154 fDetTypeSim = new AliITSDetTypeSim();
155 //PH SetMarkerColor(kRed);
156 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
157 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
159 //______________________________________________________________________
160 AliITS::AliITS(const char *name, const char *title):AliDetector(name,title),
170 // The standard Constructor for the ITS class.
171 // It also zeros the variables
172 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
173 // the pointers fIdSens and fIdName. To help in displaying hits via the
174 // ROOT macro display.C AliITS also sets the marker color to red. The
175 // variables passes with this constructor, const char *name and *title,
176 // are used by the constructor of AliDetector class. See AliDetector
177 // class for a description of these parameters and its constructor
180 fHits = new TClonesArray("AliITShit",1560);
181 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
182 //fNhits=0; //done in AliDetector(name,title)
184 SetDetectors(); // default to fOpt="All". This variable not written out.
186 fDetTypeSim = new AliITSDetTypeSim();
188 //PH SetMarkerColor(kRed);
189 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
190 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
193 //______________________________________________________________________
195 // Default destructor for ITS.
196 // The default destructor of the AliITS class. In addition to deleting
197 // the AliITS class it deletes the memory pointed to by
198 // fIdSens, fIdName, fDetTypeSim and it's contents.
212 this->ClearModules();
215 }// end if fITSmodules!=0
217 delete[] fIdName; // Array of TStrings
225 //______________________________________________________________________
226 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
227 // Creates the AliITSDigitizer in a standard way for use via AliModule.
228 // This function can not be included in the .h file because of problems
229 // with the order of inclusion (recursive).
231 // AliRunDigitizer *manager The Manger class for Digitization
235 // A new AliITSRunDigitizer (cast as a AliDigitizer).
237 return new AliITSDigitizer(manager);
239 //______________________________________________________________________
241 // Initializer ITS after it has been built
242 // This routine initializes the AliITS class. It is intended to be
243 // called from the Init function in AliITSv?. Besides displaying a banner
244 // indicating that it has been called it initializes the array fIdSens
245 // and sets the default segmentation, response, digit and raw cluster
246 // classes therefore it should be called after a call to CreateGeometry.
257 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
262 //______________________________________________________________________
263 void AliITS::SetDefaults(){
264 // sets the default segmentation, response, digit and raw cluster classes.
271 AliInfoClass("AliITS::Setting Defaults");
274 Error("SetDefaults()","fDetTypeSim is 0!");
278 fDetTypeSim->SetDefaults();
282 //______________________________________________________________________
283 void AliITS::SetDefaultSimulation(){
284 // sets the default simulation.
292 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
296 fDetTypeSim->SetDefaultSimulation();
301 //______________________________________________________________________
302 void AliITS::MakeBranch(Option_t* option){
303 // Creates Tree branches for the ITS.
305 // Option_t *option String of Tree types S,D, and/or R.
306 // const char *file String of the file name where these branches
307 // are to be stored. If blank then these branches
308 // are written to the same tree as the Hits were
315 Error("MakeBranch","fDetTypeSim is 0!");
319 Bool_t cH = (strstr(option,"H")!=0);
320 Bool_t cS = (strstr(option,"S")!=0);
321 Bool_t cD = (strstr(option,"D")!=0);
323 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
324 AliDetector::MakeBranch(option);
326 if(cS) MakeBranchS(0);
327 if(cD) MakeBranchD(0);
331 //___________________________________________________________________
332 void AliITS::MakeBranchS(const char* fl){
334 // Creates Tree Branch for the ITS summable digits.
336 // cont char *fl File name where SDigits branch is to be written
337 // to. If blank it write the SDigits to the same
338 // file in which the Hits were found.
342 Error("MakeBranchS","fDetTypeSim is 0!");
344 Int_t buffersize = 4000;
347 // only one branch for SDigits.
348 sprintf(branchname,"%s",GetName());
350 if(fLoader->TreeS()){
351 if(fDetTypeSim->GetSDigits()==0x0) fDetTypeSim->SetSDigits(new TClonesArray("AliITSpListItem",1000));
352 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
353 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
356 //______________________________________________________________________
357 void AliITS::MakeBranchD(const char* file){
359 //Make branch for digits
361 Warning("MakeBranchD","fDetTypeSim is 0!");
364 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
365 MakeBranchInTreeD(fLoader->TreeD(),file);
368 //___________________________________________________________________
369 void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
370 // Creates Tree branches for the ITS.
373 Error("MakeBranchS","fDetTypeSim is 0!");
375 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
377 const Char_t *det[3] = {"SPD","SDD","SSD"};
379 Int_t buffersize = 4000;
380 Char_t branchname[30];
382 if(!fDetTypeSim->GetDigits()){
383 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
385 for(Int_t i=0;i<fgkNTYPES;i++){
386 digclass = fDetTypeSim->GetDigitClassName(i);
387 TString classn = digclass;
388 if(!((fDetTypeSim->GetDigits())->At(i))){
389 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
392 if(fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
393 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
394 TObjArray* dig = DigitsAddress(i);
395 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
399 //______________________________________________________________________
400 void AliITS::SetTreeAddress(){
401 // Set branch address for the Trees.
410 Error("SetTreeAddress","fDetTypeSim is 0!");
414 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
416 TTree *treeS = fLoader->TreeS();
417 TTree *treeD = fLoader->TreeD();
418 if (fLoader->TreeH() && (fHits == 0x0)) {
419 fHits = new TClonesArray("AliITShit", 1560);
421 AliDetector::SetTreeAddress();
423 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
424 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
426 //______________________________________________________________________
427 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
429 // The function to add information to the AliITShit class. See the
430 // AliITShit class for a full description. This function allocates the
431 // necessary new space for the hit information and passes the variable
432 // track, and the pointers *vol and *hits to the AliITShit constructor
435 // Int_t track Track number which produced this hit.
436 // Int_t *vol Array of Integer Hit information. See AliITShit.h
437 // Float_t *hits Array of Floating Hit information. see AliITShit.h
442 TClonesArray &lhits = *fHits;
443 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
446 //______________________________________________________________________
447 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
448 Option_t *option, const char *filename){
449 // fill the modules with the sorted by module hits; add hits from
450 // background if option=Add.
452 static TTree *trH1; //Tree with background hits
453 static Bool_t first=kTRUE;
455 const char *addBgr = strstr(option,"Add");
457 evnt = nmodules; // Dummy use of variables to remove warnings
460 file=new TFile(filename);
465 // Get Hits Tree header from file
466 if(trH1) delete trH1;
470 sprintf(treeName,"TreeH%d",bgrev);
471 trH1 = (TTree*)gDirectory->Get(treeName);
473 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
475 // Set branch addresses
478 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
481 FillModules(trH1,10000000); // Default mask 10M.
482 TTree *fAli=fLoader->GetRunLoader()->TreeK();
484 if (fAli) fileAli =fAli->GetCurrentFile();
492 //______________________________________________________________________
493 void AliITS::FillModules(TTree *treeH, Int_t mask) {
494 // fill the modules with the sorted by module hits;
495 // can be called many times to do a merging
497 // TTree *treeH The tree containing the hits to be copied into
499 // Int_t mask The track number mask to indecate which file
500 // this hits came from.
508 Error("FillModules","Tree is NULL");
510 Int_t lay,lad,det,index;
514 sprintf(branchname,"%s",GetName());
515 TBranch *branch = treeH->GetBranch(branchname);
517 Error("FillModules","%s branch in TreeH not found",branchname);
520 branch->SetAddress(&fHits);
521 Int_t nTracks =(Int_t) treeH->GetEntries();
523 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
525 Int_t nBytes = treeH->GetEvent(iPrimTrack);
526 if (nBytes <= 0) continue;
527 Int_t nHits = fHits->GetEntriesFast();
528 for(h=0; h<nHits; h++){
529 itsHit = (AliITShit *)fHits->UncheckedAt(h);
530 itsHit->GetDetectorID(lay,lad,det);
532 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
534 index=det-1; // This should not be used.
535 } // end if [You must have fITSgeom for this to work!]
536 mod = GetModule(index);
537 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
538 mod->AddHit(itsHit,iPrimTrack,h);
539 } // end loop over hits
540 } // end loop over tracks
543 //______________________________________________________________________
544 void AliITS::InitModules(Int_t size,Int_t &nmodules){
545 // Initialize the modules array.
547 // Int_t size Size of array of the number of modules to be
548 // created. If size <=0 then the number of modules
549 // is gotten from AliITSgeom class kept in fITSgeom.
551 // Int_t &nmodules The number of modules existing.
556 fITSmodules->Delete();
558 } // end fir fITSmoudles
561 Error("InitModules","fDetTypeSim is null!");
565 Int_t nl,indexMAX,index;
567 if(size<=0){ // default to using data stored in AliITSgeom
568 if(fDetTypeSim->GetITSgeom()==0) {
569 Error("InitModules","fITSgeom not defined");
571 } // end if fITSgeom==0
572 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
573 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
575 fITSmodules = new TObjArray(indexMAX);
576 for(index=0;index<indexMAX;index++){
577 fITSmodules->AddAt( new AliITSmodule(index),index);
580 fITSmodules = new TObjArray(size);
581 for(index=0;index<size;index++) {
582 fITSmodules->AddAt( new AliITSmodule(index),index);
588 //______________________________________________________________________
589 void AliITS::Hits2SDigits(){
590 // Standard Hits to summable Digits function.
598 Error("Hits2SDigits","fDetTypeSim is null!");
604 fLoader->LoadHits("read");
605 fLoader->LoadSDigits("recreate");
606 AliRunLoader* rl = fLoader->GetRunLoader();
607 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
608 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
609 // Do the Hits to Digits operation. Use Standard input values.
610 // Event number from file, no background hit merging , use size from
611 // AliITSgeom class, option="All", input from this file only.
612 rl->GetEvent(iEvent);
613 if (!fLoader->TreeS()) fLoader->MakeTree("S");
616 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
619 fLoader->UnloadHits();
620 fLoader->UnloadSDigits();
623 //______________________________________________________________________
624 void AliITS::Hits2Digits(){
626 //Conversion from hits to digits
628 Error("Hits2SDigits","fDetTypeSim is 0!");
632 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
635 fLoader->LoadHits("read");
636 fLoader->LoadDigits("recreate");
637 AliRunLoader* rl = fLoader->GetRunLoader();
638 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
639 rl->GetEvent(iEvent);
640 if (!fLoader->TreeD()) fLoader->MakeTree("D");
643 HitsToDigits(iEvent,0,-1," ",fOpt," ");
646 fLoader->UnloadHits();
647 fLoader->UnloadDigits();
651 //______________________________________________________________________
652 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
653 Option_t *option,Option_t *opt,
654 const char *filename){
655 // Keep galice.root for signal and name differently the file for
656 // background when add! otherwise the track info for signal will be lost !
657 // the condition below will disappear when the geom class will be
658 // initialized for all versions - for the moment it is only for v5 !
659 // 7 is the SDD beam test version.
661 // Int_t evnt Event to be processed.
662 // Int_t bgrev Background Hit tree number.
663 // Int_t nmodules Not used.
664 // Option_t *option String indicating if merging hits or not. To
665 // merge hits set equal to "Add". Otherwise no
666 // background hits are considered.
667 // Test_t *filename File name containing the background hits..
674 Error("HitsToDigits","fDetTypeSim is null!");
677 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
678 if(!GetITSgeom()) return; // need transformations to do digitization.
679 AliITSgeom *geom = GetITSgeom();
681 const char *all = strstr(opt,"All");
682 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
684 static Bool_t setDef=kTRUE;
685 if (setDef) SetDefaultSimulation();
689 InitModules(size,nmodules);
690 FillModules(evNumber,bgrev,nmodules,option,filename);
692 AliITSsimulation *sim = 0;
693 AliITSmodule *mod = 0;
695 for(Int_t module=0;module<geom->GetIndexMax();module++){
696 id = geom->GetModuleType(module);
697 if (!all && !det[id]) continue;
698 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
700 Error("HitsToDigits","The simulation class was not "
701 "instanciated for module %d type %s!",module,
702 geom->GetModuleTypeName(module));
705 mod = (AliITSmodule *)fITSmodules->At(module);
706 sim->DigitiseModule(mod,module,evNumber);
707 // fills all branches - wasted disk space
708 fLoader->TreeD()->Fill();
714 fLoader->TreeD()->GetEntries();
715 fLoader->TreeD()->AutoSave();
717 fLoader->TreeD()->Reset();
719 //_____________________________________________________________________
720 void AliITS::Hits2PreDigits(){
721 // Turn hits into SDigits
724 Error("Hits2SDigits","fDetTypeSim is 0!");
728 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
731 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
735 //______________________________________________________________________
736 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
737 Option_t *option,Option_t *opt,
738 const char *filename){
739 // Keep galice.root for signal and name differently the file for
740 // background when add! otherwise the track info for signal will be lost !
741 // the condition below will disappear when the geom class will be
742 // initialized for all versions - for the moment it is only for v5 !
743 // 7 is the SDD beam test version.
745 // Int_t evnt Event to be processed.
746 // Int_t bgrev Background Hit tree number.
747 // Int_t nmodules Not used.
748 // Option_t *option String indicating if merging hits or not. To
749 // merge hits set equal to "Add". Otherwise no
750 // background hits are considered.
751 // Test_t *filename File name containing the background hits..
759 Error("HitsToPreDigits","fDetTypeSim is null!");
762 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
765 Error("HitsToPreDigits","fGeom is null!");
766 return; // need transformations to do digitization.
768 AliITSgeom *geom = GetITSgeom();
770 const char *all = strstr(opt,"All");
771 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
773 static Bool_t setDef=kTRUE;
774 if (setDef) SetDefaultSimulation();
778 InitModules(size,nmodules);
779 FillModules(evNumber,bgrev,nmodules,option,filename);
782 AliITSsimulation *sim = 0;
783 AliITSmodule *mod = 0;
785 for(module=0;module<geom->GetIndexMax();module++){
786 id = geom->GetModuleType(module);
787 if (!all && !det[id]) continue;
788 sim = (AliITSsimulation*)GetSimulationModel(id);
790 Error("HitsToPreDigits","The simulation class was not "
791 "instanciated for module %d type %s!",module,
792 geom->GetModuleTypeName(module));
795 mod = (AliITSmodule *)fITSmodules->At(module);
796 sim->SDigitiseModule(mod,module,evNumber);
797 // fills all branches - wasted disk space
798 fLoader->TreeS()->Fill();
799 fDetTypeSim->ResetSDigits();
805 fLoader->TreeS()->GetEntries();
806 fLoader->TreeS()->AutoSave();
807 fLoader->WriteSDigits("OVERWRITE");
809 fLoader->TreeS()->Reset();
812 //_____________________________________________________________________
813 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
814 Option_t *opt0,Option_t *opt1,
816 // keep galice.root for signal and name differently the file for
817 // background when add! otherwise the track info for signal will be lost !
818 // the condition below will disappear when the geom class will be
819 // initialized for all versions - for the moment it is only for v5 !
821 // Int_t evnt Event to be processed.
822 // Int_t bgrev Background Hit tree number.
823 // Int_t size Size used by InitModules. See InitModules.
824 // Option_t *opt0 Option passed to FillModules. See FillModules.
825 // Option_t *opt1 String indicating if merging hits or not. To
826 // merge hits set equal to "Add". Otherwise no
827 // background hits are considered.
828 // Test_t *flnm File name containing the background hits..
837 Error("HitsToPreDigits","fGeom is null!");
838 return; // need transformations to do digitization.
840 AliITSgeom *geom = GetITSgeom();
842 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
844 const char *all = strstr(opt1,"All");
845 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
848 InitModules(size,nmodules);
849 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
851 AliITSsimulation *sim = 0;
852 AliITSmodule *mod = 0;
855 TTree *lTR = pITSloader->TreeR();
857 pITSloader->MakeTree("R");
858 lTR = pITSloader->TreeR();
861 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
862 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
863 branch->SetAddress(&ptarray);
864 //m.b. : this change is nothing but a nice way to make sure
866 for(module=0;module<geom->GetIndexMax();module++){
867 id = geom->GetModuleType(module);
868 if (!all && !det[id]) continue;
869 sim = (AliITSsimulation*)GetSimulationModel(id);
871 Error("HitsToFastPoints","The simulation class was not "
872 "instanciated for module %d type %x!",module,
873 geom->GetModuleTypeName(module));
876 mod = (AliITSmodule *)fITSmodules->At(module);
877 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
882 fLoader->WriteRecPoints("OVERWRITE");
885 //_____________________________________________________________________
886 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
887 //------------------------------------------------------------
888 // This function creates ITS clusters
889 //------------------------------------------------------------
891 Error("HitsToPreDigits","fGeom is null!");
892 return 1; // need transformations to do digitization.
894 AliITSgeom *geom=GetITSgeom();
895 Int_t mmax=geom->GetIndexMax();
897 InitModules(-1,mmax);
898 FillModules(hTree,0);
900 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
901 TBranch *branch=cTree->GetBranch("ITSRecPoints");
902 if (!branch) cTree->Branch("ITSRecPoints",&points);
903 else branch->SetAddress(&points);
905 AliITSsimulationFastPoints sim;
907 for (Int_t m=0; m<mmax; m++) {
908 AliITSmodule *mod=GetModule(m);
909 sim.CreateFastRecPoints(mod,m,gRandom,points);
910 ncl+=points->GetEntriesFast();
915 Info("Hits2Clusters","Number of found fast clusters : %d",ncl);
923 //_____________________________________________________________________
924 void AliITS::CheckLabels(Int_t lab[3]) const {
925 //------------------------------------------------------------
926 // Tries to find mother's labels
927 //------------------------------------------------------------
929 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
931 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
932 for (Int_t i=0;i<3;i++){
933 Int_t label = lab[i];
934 if (label>=0 && label<ntracks) {
935 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
936 if (part->P() < 0.005) {
937 Int_t m=part->GetFirstMother();
941 if (part->GetStatusCode()>0) {
951 //______________________________________________________________________
952 void AliITS::SDigitsToDigits(Option_t *opt){
953 // Standard Summable digits to Digits function.
959 Error("SDigitsToSDigits","fDetTypeSim is 0!");
963 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
965 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
969 //______________________________________________________________________
970 void AliITS::ResetDigits(){
971 // Reset number of digits and the digits array for the ITS detector.
977 Error("ResetDigits","fDetTypeSim is 0!");
981 fDetTypeSim->ResetDigits();
985 //______________________________________________________________________
986 void AliITS::ResetDigits(Int_t branch){
987 // Reset number of digits and the digits array for this branch.
994 Error("ResetDigits","fDetTypeSim is 0!");
998 fDetTypeSim->ResetDigits(branch);
1001 //______________________________________________________________________
1002 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1003 // Adds the a module full of summable digits to the summable digits tree.
1005 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1012 Error("AddSumDigit","fDetTypeSim is 0!");
1015 fDetTypeSim->AddSumDigit(sdig);
1018 //______________________________________________________________________
1019 void AliITS::AddRealDigit(Int_t branch, Int_t *digits){
1020 // Add a real digit - as coming from data.
1022 // Int_t id Detector type number.
1023 // Int_t *digits Integer array containing the digits info. See
1031 Error("AddRealDigit","fDetTypeSim is 0!");
1034 fDetTypeSim->AddRealDigit(branch,digits);
1037 //______________________________________________________________________
1038 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1039 // Add a simulated digit.
1041 // Int_t id Detector type number.
1042 // AliITSdigit *d Digit to be added to the Digits Tree. See
1050 Error("AddSimDigit","fDetTypeSim is 0!");
1053 fDetTypeSim->AddSimDigit(branch,d);
1056 //______________________________________________________________________
1057 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1058 Int_t *hits,Float_t *charges){
1059 // Add a simulated digit to the list.
1061 // Int_t id Detector type number.
1062 // Float_t phys Physics indicator. See AliITSdigits.h
1063 // Int_t *digits Integer array containing the digits info. See
1065 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1066 // containing the track numbers that contributed to
1068 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1069 // containing the hit numbers, from AliITSmodule, that
1070 // contributed to this digit.
1071 // Float_t *charge Floating point array of the signals contributed
1072 // to this digit by each track.
1079 Error("AddSimDigit","fDetTypeSim is 0!");
1082 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges);
1085 //______________________________________________________________________
1086 void AliITS::Digits2Raw(){
1087 // convert digits of the current event to raw data
1090 Error("Digits2Raw","fDetTypeSim is 0!");
1093 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1095 fDetTypeSim->GetLoader()->LoadDigits();
1096 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1098 Error("Digits2Raw", "no digits tree");
1101 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1103 AliITSDDLRawData rawWriter;
1107 // 2: txt files with digits
1108 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1109 //it is highly suggested to use this mode only for debugging digits files
1110 //reasonably small, because otherwise the size of the txt files can reach
1111 //quickly several MB wasting time and disk space.
1112 rawWriter.SetVerbose(0);
1114 //SILICON PIXEL DETECTOR
1115 Info("Digits2Raw", "Formatting raw data for SPD");
1116 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"));
1118 //SILICON DRIFT DETECTOR
1119 Info("Digits2Raw", "Formatting raw data for SDD");
1120 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"));
1122 //SILICON STRIP DETECTOR
1123 Info("Digits2Raw", "Formatting raw data for SSD");
1124 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1126 fLoader->UnloadDigits();
1128 //______________________________________________________________________
1129 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1130 //builds ITSgetter (AliLoader type)
1131 //if detector wants to use castomized getter, it must overload this method
1133 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1135 fLoader = new AliITSLoader(GetName(),topfoldername);
1139 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1142 // Converts RAW data to SDigits
1147 Int_t size = GetITSgeom()->GetIndexMax();
1148 TClonesArray** modA = new TClonesArray*[size];
1149 for (Int_t mod = 0; mod < size; mod++) modA[mod] = new TClonesArray("AliITSpListItem", 10000);
1151 AliLoader* loader = (gAlice->GetRunLoader())->GetLoader("ITSLoader");
1154 Error("Open","Can not get ITS loader from Run Loader");
1159 tree = loader->TreeS();
1162 loader->MakeTree("S");
1163 tree = loader->TreeS();
1166 // Array for SDigits
1168 TClonesArray aSDigits("AliITSpListItem",10000), *itsSDigits=&aSDigits;
1169 Int_t bufsize = 32000;
1170 tree->Branch("ITS", &itsSDigits, bufsize);
1175 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1176 npx = segSPD->Npx();
1177 Double_t thr, sigma;
1179 AliITSRawStreamSPD inputSPD(rawReader);
1181 Bool_t next = inputSPD.Next();
1184 Int_t module = inputSPD.GetModuleID();
1185 Int_t column = inputSPD.GetColumn();
1186 Int_t row = inputSPD.GetRow();
1187 Int_t index = npx * column + row;
1189 if (module >= size) continue;
1191 last = (modA[module])->GetEntries();
1192 TClonesArray& dum = *modA[module];
1193 fDetTypeSim->GetCalibrationModel(module)->Thresholds(thr,sigma);
1195 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1202 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1203 npx = segSDD->Npx();
1204 AliITSRawStreamSDD inputSDD(rawReader);
1206 Bool_t next = inputSDD.Next();
1209 Int_t module = inputSDD.GetModuleID();
1210 Int_t anode = inputSDD.GetAnode();
1211 Int_t time = inputSDD.GetTime();
1212 Int_t signal = inputSDD.GetSignal();
1213 Int_t index = npx * anode + time;
1215 if (module >= size) continue;
1217 AliITSresponseSDD *resSDD = (AliITSresponseSDD*) fDetTypeSim->GetResponse(1);
1218 Int_t signal10 = resSDD->Convert8to10(signal); // signal is a 8 bit value (if the compression is active)
1220 last = modA[module]->GetEntries();
1221 TClonesArray& dum = *modA[module];
1222 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1223 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1231 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1232 npx = segSSD->Npx();
1233 AliITSRawStreamSSD inputSSD(rawReader);
1235 Bool_t next = inputSSD.Next();
1238 Int_t module = inputSSD.GetModuleID();
1239 Int_t side = inputSSD.GetSideFlag();
1240 Int_t strip = inputSSD.GetStrip();
1241 Int_t signal = inputSSD.GetSignal();
1242 Int_t index = npx * side + strip;
1244 if (module >= size) continue;
1246 last = modA[module]->GetEntries();
1247 TClonesArray& dum = *modA[module];
1248 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1251 AliITSpListItem* sdig = 0;
1253 for (Int_t mod = 0; mod < size; mod++)
1255 Int_t nsdig = modA[mod]->GetEntries();
1256 for (Int_t ie = 0; ie < nsdig; ie++) {
1257 sdig = (AliITSpListItem*) (modA[mod]->At(ie));
1258 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), sdig->GetSignal());
1259 Float_t sig = sdig->GetSignalAfterElect();
1261 sdig = (AliITSpListItem*)aSDigits[ie];
1262 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1270 loader->WriteSDigits("OVERWRITE");
1276 //______________________________________________________________________
1277 void AliITS::UpdateInternalGeometry(){
1279 //reads new geometry from TGeo
1280 // AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1282 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1284 if(version==kvPPRasymmFMD) minor=2; // default minor version for this geom.
1285 AliITSInitGeometry initgeom;
1286 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);