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 "AliITSsimulationSDD.h"
91 #include "AliITSCalibrationSDD.h"
92 #include "AliITSCalibrationSSD.h"
93 #include "AliITSsegmentationSSD.h"
94 #include "AliITSRawStreamSPD.h"
95 #include "AliITSRawStreamSSD.h"
96 #include "AliITSRawStreamSDD.h"
97 #include "AliRawReader.h"
100 #include "AliITSInitGeometry.h"
101 #include "AliITSFOSignalsSPD.h"
105 //______________________________________________________________________
106 AliITS::AliITS() : AliDetector(),
119 // Default initializer for ITS
120 // The default constructor of the AliITS class. In addition to
121 // creating the AliITS class it zeros the variables fIshunt (a member
122 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
123 // fIdSens, and fIdName. The AliDetector default constructor
126 // SetDetectors(); // default to fOpt="All". This variable not written out.
127 //PH SetMarkerColor(kRed);
129 //______________________________________________________________________
130 AliITS::AliITS(const Char_t *title):
131 AliDetector("ITS",title),
144 // The standard Constructor for the ITS class.
145 // It also zeros the variables
146 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
147 // the pointers fIdSens and fIdName. To help in displaying hits via the
148 // ROOT macro display.C AliITS also sets the marker color to red. The
149 // variables passes with this constructor, const char *name and *title,
150 // are used by the constructor of AliDetector class. See AliDetector
151 // class for a description of these parameters and its constructor
154 // Char_t *title Simulation title for the ITS
160 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
161 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
162 //fNhits=0; //done in AliDetector(name,title)
163 SetDetectors(); // default to fOpt="All". This variable not written out.
164 fDetTypeSim = new AliITSDetTypeSim();
165 //PH SetMarkerColor(kRed);
166 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
167 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
169 //______________________________________________________________________
170 AliITS::AliITS(const char *name, const char *title):
171 AliDetector(name,title),
184 // The standard Constructor for the ITS class.
185 // It also zeros the variables
186 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
187 // the pointers fIdSens and fIdName. To help in displaying hits via the
188 // ROOT macro display.C AliITS also sets the marker color to red. The
189 // variables passes with this constructor, const char *name and *title,
190 // are used by the constructor of AliDetector class. See AliDetector
191 // class for a description of these parameters and its constructor
194 fHits = new TClonesArray("AliITShit",1560);
195 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
196 //fNhits=0; //done in AliDetector(name,title)
198 SetDetectors(); // default to fOpt="All". This variable not written out.
200 fDetTypeSim = new AliITSDetTypeSim();
201 //PH SetMarkerColor(kRed);
202 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
203 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
206 //______________________________________________________________________
208 // Default destructor for ITS.
209 // The default destructor of the AliITS class. In addition to deleting
210 // the AliITS class it deletes the memory pointed to by
211 // fIdSens, fIdName, fDetTypeSim and it's contents.
225 this->ClearModules();
228 }// end if fITSmodules!=0
230 delete[] fIdName; // Array of TStrings
234 size = GetITSgeom()->GetIndexMax();
244 for(Int_t j=0; j<size; j++){
256 //______________________________________________________________________
257 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
258 // Creates the AliITSDigitizer in a standard way for use via AliModule.
259 // This function can not be included in the .h file because of problems
260 // with the order of inclusion (recursive).
262 // AliRunDigitizer *manager The Manger class for Digitization
266 // A new AliITSRunDigitizer (cast as a AliDigitizer).
268 return new AliITSDigitizer(manager);
270 //______________________________________________________________________
272 // Initializer ITS after it has been built
273 // This routine initializes the AliITS class. It is intended to be
274 // called from the Init function in AliITSv?. Besides displaying a banner
275 // indicating that it has been called it initializes the array fIdSens
276 // and sets the default segmentation, response, digit and raw cluster
277 // classes therefore it should be called after a call to CreateGeometry.
286 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
289 //______________________________________________________________________
290 void AliITS::SetDefaults(){
291 // sets the default segmentation, response, digit and raw cluster classes.
298 AliInfoClass("AliITS::Setting Defaults");
300 Error("SetDefaults()","fDetTypeSim is 0!");
304 fDetTypeSim->SetDefaults();
305 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
308 //______________________________________________________________________
309 void AliITS::SetDefaultSimulation(){
310 // sets the default simulation.
318 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
322 fDetTypeSim->SetDefaultSimulation();
323 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
328 //______________________________________________________________________
329 void AliITS::MakeBranch(Option_t* option){
330 // Creates Tree branches for the ITS.
332 // Option_t *option String of Tree types S,D, and/or R.
333 // const char *file String of the file name where these branches
334 // are to be stored. If blank then these branches
335 // are written to the same tree as the Hits were
342 Error("MakeBranch","fDetTypeSim is 0!");
346 Bool_t cH = (strstr(option,"H")!=0);
347 Bool_t cS = (strstr(option,"S")!=0);
348 Bool_t cD = (strstr(option,"D")!=0);
350 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
351 AliDetector::MakeBranch(option);
353 if(cS) MakeBranchS(0);
354 if(cD) MakeBranchD(0);
358 //___________________________________________________________________
359 void AliITS::MakeBranchS(const char* fl){
361 // Creates Tree Branch for the ITS summable digits.
363 // cont char *fl File name where SDigits branch is to be written
364 // to. If blank it write the SDigits to the same
365 // file in which the Hits were found.
369 Error("MakeBranchS","fDetTypeSim is 0!");
371 Int_t buffersize = 4000;
374 // only one branch for SDigits.
375 sprintf(branchname,"%s",GetName());
377 if(fLoader->TreeS()){
378 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
379 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
382 //______________________________________________________________________
383 void AliITS::MakeBranchD(const char* file){
385 //Make branch for digits
387 Warning("MakeBranchD","fDetTypeSim is 0!");
390 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
391 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
392 MakeBranchInTreeD(fLoader->TreeD(),file);
395 //___________________________________________________________________
396 void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
397 // Creates Tree branches for the ITS.
400 Error("MakeBranchS","fDetTypeSim is 0!");
402 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
403 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
405 const Char_t *det[3] = {"SPD","SDD","SSD"};
406 const Char_t* digclass;
407 Int_t buffersize = 4000;
408 Char_t branchname[30];
410 if(!fDetTypeSim->GetDigits()){
411 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
413 for(Int_t i=0;i<fgkNTYPES;i++){
414 digclass = fDetTypeSim->GetDigitClassName(i);
415 TString classn = digclass;
416 if(!((fDetTypeSim->GetDigits())->At(i))){
417 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
420 if(fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
421 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
422 TObjArray* dig = DigitsAddress(i);
423 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
427 //______________________________________________________________________
428 void AliITS::SetTreeAddress(){
429 // Set branch address for the Trees.
438 Error("SetTreeAddress","fDetTypeSim is 0!");
442 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
443 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
445 TTree *treeS = fLoader->TreeS();
446 TTree *treeD = fLoader->TreeD();
447 if (fLoader->TreeH() && (fHits == 0x0)) {
448 fHits = new TClonesArray("AliITShit", 1560);
450 AliDetector::SetTreeAddress();
452 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
453 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
455 //______________________________________________________________________
456 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
458 // The function to add information to the AliITShit class. See the
459 // AliITShit class for a full description. This function allocates the
460 // necessary new space for the hit information and passes the variable
461 // track, and the pointers *vol and *hits to the AliITShit constructor
464 // Int_t track Track number which produced this hit.
465 // Int_t *vol Array of Integer Hit information. See AliITShit.h
466 // Float_t *hits Array of Floating Hit information. see AliITShit.h
471 TClonesArray &lhits = *fHits;
472 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
475 //______________________________________________________________________
476 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
477 Option_t *option, const char *filename){
478 // fill the modules with the sorted by module hits; add hits from
479 // background if option=Add.
481 static TTree *trH1; //Tree with background hits
482 static Bool_t first=kTRUE;
484 const char *addBgr = strstr(option,"Add");
486 evnt = nmodules; // Dummy use of variables to remove warnings
489 file=new TFile(filename);
494 // Get Hits Tree header from file
495 if(trH1) delete trH1;
499 sprintf(treeName,"TreeH%d",bgrev);
500 trH1 = (TTree*)gDirectory->Get(treeName);
502 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
504 // Set branch addresses
507 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
510 FillModules(trH1,10000000); // Default mask 10M.
511 TTree *fAli=fLoader->GetRunLoader()->TreeK();
513 if (fAli) fileAli =fAli->GetCurrentFile();
519 //______________________________________________________________________
520 void AliITS::FillModules(TTree *treeH, Int_t mask) {
521 // fill the modules with the sorted by module hits;
522 // can be called many times to do a merging
524 // TTree *treeH The tree containing the hits to be copied into
526 // Int_t mask The track number mask to indecate which file
527 // this hits came from.
535 Error("FillModules","Tree is NULL");
537 Int_t lay,lad,det,index;
541 sprintf(branchname,"%s",GetName());
542 TBranch *branch = treeH->GetBranch(branchname);
544 Error("FillModules","%s branch in TreeH not found",branchname);
547 branch->SetAddress(&fHits);
548 Int_t nTracks =(Int_t) treeH->GetEntries();
550 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
552 Int_t nBytes = treeH->GetEvent(iPrimTrack);
553 if (nBytes <= 0) continue;
554 Int_t nHits = fHits->GetEntriesFast();
555 for(h=0; h<nHits; h++){
556 itsHit = (AliITShit *)fHits->UncheckedAt(h);
557 itsHit->GetDetectorID(lay,lad,det);
559 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
561 index=det-1; // This should not be used.
562 } // end if [You must have fITSgeom for this to work!]
563 mod = GetModule(index);
564 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
565 mod->AddHit(itsHit,iPrimTrack,h);
566 } // end loop over hits
567 } // end loop over tracks
570 //______________________________________________________________________
571 Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
572 // Initialize the modules array.
574 // Int_t size Size of array of the number of modules to be
575 // created. If size <=0 then the number of modules
576 // is gotten from AliITSgeom class kept in fITSgeom.
578 // Int_t &nmodules The number of modules existing.
583 fITSmodules->Delete();
585 } // end fir fITSmoudles
588 Error("InitModules","fDetTypeSim is null!");
591 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
593 Int_t nl,indexMAX,index;
595 if(size<=0){ // default to using data stored in AliITSgeom
596 if(fDetTypeSim->GetITSgeom()==0) {
597 Error("InitModules","fITSgeom not defined");
599 } // end if fITSgeom==0
600 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
601 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
603 fITSmodules = new TObjArray(indexMAX);
604 for(index=0;index<indexMAX;index++){
605 fITSmodules->AddAt( new AliITSmodule(index),index);
608 fITSmodules = new TObjArray(size);
609 for(index=0;index<size;index++) {
610 fITSmodules->AddAt( new AliITSmodule(index),index);
617 //______________________________________________________________________
618 void AliITS::Hits2SDigits(){
619 // Standard Hits to summable Digits function.
627 Error("Hits2SDigits","fDetTypeSim is null!");
632 fLoader->LoadHits("read");
633 fLoader->LoadSDigits("recreate");
634 AliRunLoader* rl = fLoader->GetRunLoader();
635 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
636 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
638 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
639 // Do the Hits to Digits operation. Use Standard input values.
640 // Event number from file, no background hit merging , use size from
641 // AliITSgeom class, option="All", input from this file only.
642 rl->GetEvent(iEvent);
643 if (!fLoader->TreeS()) fLoader->MakeTree("S");
646 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
649 fLoader->UnloadHits();
650 fLoader->UnloadSDigits();
653 //______________________________________________________________________
654 void AliITS::Hits2Digits(){
656 //Conversion from hits to digits
658 Error("Hits2SDigits","fDetTypeSim is 0!");
662 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
663 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
666 fLoader->LoadHits("read");
667 fLoader->LoadDigits("recreate");
668 AliRunLoader* rl = fLoader->GetRunLoader();
669 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
670 rl->GetEvent(iEvent);
671 if (!fLoader->TreeD()) fLoader->MakeTree("D");
674 HitsToDigits(iEvent,0,-1," ",fOpt," ");
677 fLoader->UnloadHits();
678 fLoader->UnloadDigits();
682 //______________________________________________________________________
683 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
684 Option_t *option,Option_t *opt,
685 const char *filename){
686 // Keep galice.root for signal and name differently the file for
687 // background when add! otherwise the track info for signal will be lost !
688 // the condition below will disappear when the geom class will be
689 // initialized for all versions - for the moment it is only for v5 !
690 // 7 is the SDD beam test version.
692 // Int_t evnt Event to be processed.
693 // Int_t bgrev Background Hit tree number.
694 // Int_t nmodules Not used.
695 // Option_t *option String indicating if merging hits or not. To
696 // merge hits set equal to "Add". Otherwise no
697 // background hits are considered.
698 // Test_t *filename File name containing the background hits..
705 Error("HitsToDigits","fDetTypeSim is null!");
708 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
709 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
710 if(!GetITSgeom()) return; // need transformations to do digitization.
711 AliITSgeom *geom = GetITSgeom();
713 const char *all = strstr(opt,"All");
714 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
716 static Bool_t setDef=kTRUE;
717 if (setDef) SetDefaultSimulation();
721 InitModules(size,nmodules);
722 FillModules(evNumber,bgrev,nmodules,option,filename);
724 // Reset Fast-OR signals for this event
725 fDetTypeSim->ResetFOSignals();
727 AliITSsimulation *sim = 0;
728 AliITSmodule *mod = 0;
730 for(Int_t module=0;module<geom->GetIndexMax();module++){
731 id = geom->GetModuleType(module);
732 if (!all && !det[id]) continue;
733 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
735 Error("HitsToDigits","The simulation class was not "
736 "instanciated for module %d type %s!",module,
737 geom->GetModuleTypeName(module));
740 mod = (AliITSmodule *)fITSmodules->At(module);
741 sim->DigitiseModule(mod,module,evNumber);
742 // fills all branches - wasted disk space
743 fLoader->TreeD()->Fill();
749 // Add random noise to FO signals
750 if (all || det[0]) { // SPD present
751 fDetTypeSim->ProcessNoiseForFastOr();
754 // Add Fast-OR signals to event (only one object per event)
755 if (all || det[0]) { // SPD present
756 fDetTypeSim->WriteFOSignals();
760 fLoader->TreeD()->GetEntries();
761 fLoader->TreeD()->AutoSave();
763 fLoader->TreeD()->Reset();
765 //_____________________________________________________________________
766 void AliITS::Hits2PreDigits(){
767 // Turn hits into SDigits
770 Error("Hits2SDigits","fDetTypeSim is 0!");
774 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
775 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
778 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
782 //______________________________________________________________________
783 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
784 Option_t *option,Option_t *opt,
785 const char *filename){
786 // Keep galice.root for signal and name differently the file for
787 // background when add! otherwise the track info for signal will be lost !
788 // the condition below will disappear when the geom class will be
789 // initialized for all versions - for the moment it is only for v5 !
790 // 7 is the SDD beam test version.
792 // Int_t evnt Event to be processed.
793 // Int_t bgrev Background Hit tree number.
794 // Int_t nmodules Not used.
795 // Option_t *option String indicating if merging hits or not. To
796 // merge hits set equal to "Add". Otherwise no
797 // background hits are considered.
798 // Test_t *filename File name containing the background hits..
806 Error("HitsToPreDigits","fDetTypeSim is null!");
809 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
810 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
813 Error("HitsToPreDigits","fGeom is null!");
814 return; // need transformations to do digitization.
816 AliITSgeom *geom = GetITSgeom();
818 const char *all = strstr(opt,"All");
819 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
821 static Bool_t setDef=kTRUE;
822 if (setDef) SetDefaultSimulation();
826 InitModules(size,nmodules);
827 FillModules(evNumber,bgrev,nmodules,option,filename);
830 AliITSsimulation *sim = 0;
831 AliITSmodule *mod = 0;
833 for(module=0;module<geom->GetIndexMax();module++){
834 id = geom->GetModuleType(module);
835 if (!all && !det[id]) continue;
836 sim = (AliITSsimulation*)GetSimulationModel(id);
838 Error("HitsToPreDigits","The simulation class was not "
839 "instanciated for module %d type %s!",module,
840 geom->GetModuleTypeName(module));
843 mod = (AliITSmodule *)fITSmodules->At(module);
844 sim->SDigitiseModule(mod,module,evNumber);
845 // fills all branches - wasted disk space
846 fLoader->TreeS()->Fill();
847 fDetTypeSim->ResetSDigits();
853 fLoader->TreeS()->GetEntries();
854 fLoader->TreeS()->AutoSave();
855 fLoader->WriteSDigits("OVERWRITE");
857 fLoader->TreeS()->Reset();
860 //_____________________________________________________________________
861 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
862 Option_t *opt0,Option_t *opt1,
864 // keep galice.root for signal and name differently the file for
865 // background when add! otherwise the track info for signal will be lost !
866 // the condition below will disappear when the geom class will be
867 // initialized for all versions - for the moment it is only for v5 !
869 // Int_t evnt Event to be processed.
870 // Int_t bgrev Background Hit tree number.
871 // Int_t size Size used by InitModules. See InitModules.
872 // Option_t *opt0 Option passed to FillModules. See FillModules.
873 // Option_t *opt1 String indicating if merging hits or not. To
874 // merge hits set equal to "Add". Otherwise no
875 // background hits are considered.
876 // Test_t *flnm File name containing the background hits..
885 Error("HitsToPreDigits","fGeom is null!");
886 return; // need transformations to do digitization.
888 AliITSgeom *geom = GetITSgeom();
890 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
892 const char *all = strstr(opt1,"All");
893 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
896 InitModules(size,nmodules);
897 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
899 AliITSsimulation *sim = 0;
900 AliITSmodule *mod = 0;
903 TTree *lTR = pITSloader->TreeR();
905 pITSloader->MakeTree("R");
906 lTR = pITSloader->TreeR();
909 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
910 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
911 branch->SetAddress(&ptarray);
912 //m.b. : this change is nothing but a nice way to make sure
914 for(module=0;module<geom->GetIndexMax();module++){
915 id = geom->GetModuleType(module);
916 if (!all && !det[id]) continue;
917 sim = (AliITSsimulation*)GetSimulationModel(id);
919 Error("HitsToFastPoints","The simulation class was not "
920 "instantiated for module %d type %s!",module,
921 geom->GetModuleTypeName(module));
924 mod = (AliITSmodule *)fITSmodules->At(module);
925 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
931 fLoader->WriteRecPoints("OVERWRITE");
934 //_____________________________________________________________________
935 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
936 //------------------------------------------------------------
937 // This function creates ITS clusters
938 //------------------------------------------------------------
940 Error("HitsToPreDigits","fGeom is null!");
941 return 1; // need transformations to do digitization.
943 AliITSgeom *geom=GetITSgeom();
944 Int_t mmax=geom->GetIndexMax();
946 InitModules(-1,mmax);
947 FillModules(hTree,0);
949 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
950 TBranch *branch=cTree->GetBranch("ITSRecPoints");
951 if (!branch) cTree->Branch("ITSRecPoints",&points);
952 else branch->SetAddress(&points);
954 AliITSsimulationFastPoints sim;
956 for (Int_t m=0; m<mmax; m++) {
957 AliITSmodule *mod=GetModule(m);
958 sim.CreateFastRecPoints(mod,m,gRandom,points);
959 ncl+=points->GetEntriesFast();
964 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
972 //_____________________________________________________________________
973 void AliITS::CheckLabels(Int_t lab[3]) const {
974 //------------------------------------------------------------
975 // Tries to find mother's labels
976 //------------------------------------------------------------
978 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
980 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
981 for (Int_t i=0;i<3;i++){
982 Int_t label = lab[i];
983 if (label>=0 && label<ntracks) {
984 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
985 if (part->P() < 0.005) {
986 Int_t m=part->GetFirstMother();
990 if (part->GetStatusCode()>0) {
1000 //______________________________________________________________________
1001 void AliITS::SDigitsToDigits(Option_t *opt){
1002 // Standard Summable digits to Digits function.
1008 AliError("fDetTypeSim is 0!");
1012 const char *all = strstr(opt,"All");
1013 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1016 // Reset Fast-OR signals for this event
1017 fDetTypeSim->ResetFOSignals();
1019 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1021 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1022 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1024 // Add random noise to FO signals
1025 if (all || det[0]) { // SPD present
1026 fDetTypeSim->ProcessNoiseForFastOr();
1028 // Add Fast-OR signals to event (only one object per event)
1029 if (all || det[0]) { // SPD present
1030 fDetTypeSim->WriteFOSignals();
1034 //______________________________________________________________________
1035 void AliITS::ResetDigits(){
1036 // Reset number of digits and the digits array for the ITS detector.
1042 Error("ResetDigits","fDetTypeSim is 0!");
1046 fDetTypeSim->ResetDigits();
1050 //______________________________________________________________________
1051 void AliITS::ResetDigits(Int_t branch){
1052 // Reset number of digits and the digits array for this branch.
1059 Error("ResetDigits","fDetTypeSim is 0!");
1063 fDetTypeSim->ResetDigits(branch);
1066 //______________________________________________________________________
1067 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1068 // Adds the a module full of summable digits to the summable digits tree.
1070 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1077 Error("AddSumDigit","fDetTypeSim is 0!");
1080 fDetTypeSim->AddSumDigit(sdig);
1083 //______________________________________________________________________
1084 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1085 // Add a simulated digit.
1087 // Int_t id Detector type number.
1088 // AliITSdigit *d Digit to be added to the Digits Tree. See
1096 Error("AddSimDigit","fDetTypeSim is 0!");
1099 fDetTypeSim->AddSimDigit(branch,d);
1102 //______________________________________________________________________
1103 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1104 Int_t *hits,Float_t *charges, Int_t sigexpanded){
1105 // Add a simulated digit to the list.
1107 // Int_t id Detector type number.
1108 // Float_t phys Physics indicator. See AliITSdigits.h
1109 // Int_t *digits Integer array containing the digits info. See
1111 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1112 // containing the track numbers that contributed to
1114 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1115 // containing the hit numbers, from AliITSmodule, that
1116 // contributed to this digit.
1117 // Float_t *charge Floating point array of the signals contributed
1118 // to this digit by each track.
1125 Error("AddSimDigit","fDetTypeSim is 0!");
1128 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1131 //______________________________________________________________________
1132 void AliITS::Digits2Raw(){
1133 // convert digits of the current event to raw data
1136 Error("Digits2Raw","fDetTypeSim is 0!");
1139 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1141 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1142 fDetTypeSim->GetLoader()->LoadDigits();
1143 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1145 Error("Digits2Raw", "no digits tree");
1148 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1150 // Get the FO signals for this event
1151 AliITSFOSignalsSPD* foSignals = NULL;
1152 AliRunLoader* runLoader = AliRunLoader::Instance();
1153 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1155 AliError("ITS loader is NULL.");
1158 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1159 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1160 if(!foSignals) AliError("FO signals not retrieved");
1163 Bool_t deleteFOsignalsLater = kFALSE;
1165 AliError("FO signals not available. No FO bits will be written.");
1166 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1167 deleteFOsignalsLater = kTRUE;
1171 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1172 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1173 AliITSDDLRawData rawWriter;
1175 rawWriter.SetSDDRawFormat(rawSDD);
1179 // 2: txt files with digits
1180 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1181 //it is highly suggested to use this mode only for debugging digits files
1182 //reasonably small, because otherwise the size of the txt files can reach
1183 //quickly several MB wasting time and disk space.
1184 rawWriter.SetVerbose(0);
1186 //SILICON PIXEL DETECTOR
1187 AliDebug(1,"Formatting raw data for SPD");
1188 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1189 if(deleteFOsignalsLater) delete foSignals;
1191 //SILICON DRIFT DETECTOR
1192 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1193 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1195 //SILICON STRIP DETECTOR
1196 AliDebug(1,"Formatting raw data for SSD");
1197 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1199 fLoader->UnloadDigits();
1201 //______________________________________________________________________
1202 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1203 //builds ITSgetter (AliLoader type)
1204 //if detector wants to use castomized getter, it must overload this method
1206 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1208 fLoader = new AliITSLoader(GetName(),topfoldername);
1211 //______________________________________________________________________
1212 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1215 // Converts RAW data to SDigits
1220 Int_t size = GetITSgeom()->GetIndexMax();
1222 fModA = new TClonesArray*[size];
1223 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1225 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1227 Error("Open","Can not get ITS loader from Run Loader");
1232 tree = loader->TreeS();
1234 loader->MakeTree("S");
1235 tree = loader->TreeS();
1238 // Array for SDigits
1241 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1243 TClonesArray& aSDigits = *fpSDigits;
1244 Int_t bufsize = 32000;
1245 tree->Branch("ITS", &fpSDigits, bufsize);
1250 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1252 AliWarning("Set AliITS defaults");
1254 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1256 npx = segSPD->Npx();
1257 Double_t thr, sigma;
1259 AliITSRawStreamSPD inputSPD(rawReader);
1261 Bool_t next = inputSPD.Next();
1264 Int_t module = inputSPD.GetModuleID();
1265 Int_t column = inputSPD.GetColumn();
1266 Int_t row = inputSPD.GetRow();
1267 Int_t index = npx * column + row;
1269 if (module >= size) continue;
1271 last = (fModA[module])->GetEntries();
1272 TClonesArray& dum = *fModA[module];
1273 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1275 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1282 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1283 npx = segSDD->Npx();
1284 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1285 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1286 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1288 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1289 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1290 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1291 Bool_t isZeroSupp=cal->GetZeroSupp();
1293 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1295 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
1299 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1300 inputSDD->SetDDLModuleMap(ddlmap);
1301 while(inputSDD->Next()){
1302 if(inputSDD->IsCompletedModule()==kFALSE &&
1303 inputSDD->IsCompletedDDL()==kFALSE){
1305 Int_t module = inputSDD->GetModuleID();
1306 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1307 Int_t time = inputSDD->GetCoord2();
1308 Int_t signal10 = inputSDD->GetSignal();
1309 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1311 if (module >= size) continue;
1312 last = fModA[module]->GetEntries();
1313 TClonesArray& dum = *fModA[module];
1314 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1315 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1324 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1325 npx = segSSD->Npx();
1326 AliITSRawStreamSSD inputSSD(rawReader);
1328 Bool_t next = inputSSD.Next();
1331 Int_t module = inputSSD.GetModuleID();
1332 Int_t side = inputSSD.GetSideFlag();
1333 Int_t strip = inputSSD.GetStrip();
1334 Int_t signal = inputSSD.GetSignal();
1335 Int_t index = npx * side + strip;
1337 if (module >= size) continue;
1339 last = fModA[module]->GetEntries();
1340 TClonesArray& dum = *fModA[module];
1341 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1344 AliITSpListItem* sdig = 0;
1346 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1347 Double_t adcToEv = 1.;
1348 for (Int_t mod = 0; mod < size; mod++)
1351 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1352 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1354 Int_t nsdig = fModA[mod]->GetEntries();
1355 for (Int_t ie = 0; ie < nsdig; ie++) {
1356 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
1357 Int_t digsig = sdig->GetSignal();
1358 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1359 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
1360 Float_t sig = sdig->GetSignalAfterElect();
1361 if(mod>=firstssd) sig*=adcToEv;
1363 sdig = (AliITSpListItem*)aSDigits[ie];
1364 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1370 fModA[mod]->Clear();
1372 loader->WriteSDigits("OVERWRITE");
1376 //______________________________________________________________________
1377 void AliITS::UpdateInternalGeometry(){
1378 //reads new geometry from TGeo
1379 // AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1381 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1383 if(version==kvPPRasymmFMD) minor=2; // default minor version for this geom.
1384 AliITSInitGeometry initgeom;
1385 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1388 //______________________________________________________________________
1389 AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1390 // create an AliITSTrigger object (and set trigger conditions as input)
1391 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());