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 "AliITSsegmentationSSD.h"
93 #include "AliITSRawStreamSPD.h"
94 #include "AliITSRawStreamSSD.h"
95 #include "AliITSRawStreamSDD.h"
96 #include "AliRawReader.h"
99 #include "AliITSInitGeometry.h"
100 #include "AliITSFOSignalsSPD.h"
104 //______________________________________________________________________
105 AliITS::AliITS() : AliDetector(),
116 // Default initializer for ITS
117 // The default constructor of the AliITS class. In addition to
118 // creating the AliITS class it zeros the variables fIshunt (a member
119 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
120 // fIdSens, and fIdName. The AliDetector default constructor
123 // SetDetectors(); // default to fOpt="All". This variable not written out.
124 //PH SetMarkerColor(kRed);
126 //______________________________________________________________________
127 AliITS::AliITS(const Char_t *title):
128 AliDetector("ITS",title),
139 // The standard Constructor for the ITS class.
140 // It also zeros the variables
141 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
142 // the pointers fIdSens and fIdName. To help in displaying hits via the
143 // ROOT macro display.C AliITS also sets the marker color to red. The
144 // variables passes with this constructor, const char *name and *title,
145 // are used by the constructor of AliDetector class. See AliDetector
146 // class for a description of these parameters and its constructor
149 // Char_t *title Simulation title for the ITS
155 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
156 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
157 //fNhits=0; //done in AliDetector(name,title)
158 SetDetectors(); // default to fOpt="All". This variable not written out.
159 fDetTypeSim = new AliITSDetTypeSim();
160 //PH SetMarkerColor(kRed);
161 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
162 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
164 //______________________________________________________________________
165 AliITS::AliITS(const char *name, const char *title):
166 AliDetector(name,title),
177 // The standard Constructor for the ITS class.
178 // It also zeros the variables
179 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
180 // the pointers fIdSens and fIdName. To help in displaying hits via the
181 // ROOT macro display.C AliITS also sets the marker color to red. The
182 // variables passes with this constructor, const char *name and *title,
183 // are used by the constructor of AliDetector class. See AliDetector
184 // class for a description of these parameters and its constructor
187 fHits = new TClonesArray("AliITShit",1560);
188 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
189 //fNhits=0; //done in AliDetector(name,title)
191 SetDetectors(); // default to fOpt="All". This variable not written out.
193 fDetTypeSim = new AliITSDetTypeSim();
194 //PH SetMarkerColor(kRed);
195 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
196 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
199 //______________________________________________________________________
201 // Default destructor for ITS.
202 // The default destructor of the AliITS class. In addition to deleting
203 // the AliITS class it deletes the memory pointed to by
204 // fIdSens, fIdName, fDetTypeSim and it's contents.
218 this->ClearModules();
221 }// end if fITSmodules!=0
223 delete[] fIdName; // Array of TStrings
235 //______________________________________________________________________
236 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
237 // Creates the AliITSDigitizer in a standard way for use via AliModule.
238 // This function can not be included in the .h file because of problems
239 // with the order of inclusion (recursive).
241 // AliRunDigitizer *manager The Manger class for Digitization
245 // A new AliITSRunDigitizer (cast as a AliDigitizer).
247 return new AliITSDigitizer(manager);
249 //______________________________________________________________________
251 // Initializer ITS after it has been built
252 // This routine initializes the AliITS class. It is intended to be
253 // called from the Init function in AliITSv?. Besides displaying a banner
254 // indicating that it has been called it initializes the array fIdSens
255 // and sets the default segmentation, response, digit and raw cluster
256 // classes therefore it should be called after a call to CreateGeometry.
265 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
268 //______________________________________________________________________
269 void AliITS::SetDefaults(){
270 // sets the default segmentation, response, digit and raw cluster classes.
277 AliInfoClass("AliITS::Setting Defaults");
279 Error("SetDefaults()","fDetTypeSim is 0!");
283 fDetTypeSim->SetDefaults();
284 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
287 //______________________________________________________________________
288 void AliITS::SetDefaultSimulation(){
289 // sets the default simulation.
297 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
301 fDetTypeSim->SetDefaultSimulation();
302 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
307 //______________________________________________________________________
308 void AliITS::MakeBranch(Option_t* option){
309 // Creates Tree branches for the ITS.
311 // Option_t *option String of Tree types S,D, and/or R.
312 // const char *file String of the file name where these branches
313 // are to be stored. If blank then these branches
314 // are written to the same tree as the Hits were
321 Error("MakeBranch","fDetTypeSim is 0!");
325 Bool_t cH = (strstr(option,"H")!=0);
326 Bool_t cS = (strstr(option,"S")!=0);
327 Bool_t cD = (strstr(option,"D")!=0);
329 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
330 AliDetector::MakeBranch(option);
332 if(cS) MakeBranchS(0);
333 if(cD) MakeBranchD(0);
337 //___________________________________________________________________
338 void AliITS::MakeBranchS(const char* fl){
340 // Creates Tree Branch for the ITS summable digits.
342 // cont char *fl File name where SDigits branch is to be written
343 // to. If blank it write the SDigits to the same
344 // file in which the Hits were found.
348 Error("MakeBranchS","fDetTypeSim is 0!");
350 Int_t buffersize = 4000;
353 // only one branch for SDigits.
354 sprintf(branchname,"%s",GetName());
356 if(fLoader->TreeS()){
357 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
358 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
361 //______________________________________________________________________
362 void AliITS::MakeBranchD(const char* file){
364 //Make branch for digits
366 Warning("MakeBranchD","fDetTypeSim is 0!");
369 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
370 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
371 MakeBranchInTreeD(fLoader->TreeD(),file);
374 //___________________________________________________________________
375 void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
376 // Creates Tree branches for the ITS.
379 Error("MakeBranchS","fDetTypeSim is 0!");
381 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
382 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
384 const Char_t *det[3] = {"SPD","SDD","SSD"};
385 const Char_t* digclass;
386 Int_t buffersize = 4000;
387 Char_t branchname[30];
389 if(!fDetTypeSim->GetDigits()){
390 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
392 for(Int_t i=0;i<fgkNTYPES;i++){
393 digclass = fDetTypeSim->GetDigitClassName(i);
394 TString classn = digclass;
395 if(!((fDetTypeSim->GetDigits())->At(i))){
396 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
399 if(fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
400 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
401 TObjArray* dig = DigitsAddress(i);
402 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
406 //______________________________________________________________________
407 void AliITS::SetTreeAddress(){
408 // Set branch address for the Trees.
417 Error("SetTreeAddress","fDetTypeSim is 0!");
421 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
422 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
424 TTree *treeS = fLoader->TreeS();
425 TTree *treeD = fLoader->TreeD();
426 if (fLoader->TreeH() && (fHits == 0x0)) {
427 fHits = new TClonesArray("AliITShit", 1560);
429 AliDetector::SetTreeAddress();
431 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
432 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
434 //______________________________________________________________________
435 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
437 // The function to add information to the AliITShit class. See the
438 // AliITShit class for a full description. This function allocates the
439 // necessary new space for the hit information and passes the variable
440 // track, and the pointers *vol and *hits to the AliITShit constructor
443 // Int_t track Track number which produced this hit.
444 // Int_t *vol Array of Integer Hit information. See AliITShit.h
445 // Float_t *hits Array of Floating Hit information. see AliITShit.h
450 TClonesArray &lhits = *fHits;
451 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
454 //______________________________________________________________________
455 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
456 Option_t *option, const char *filename){
457 // fill the modules with the sorted by module hits; add hits from
458 // background if option=Add.
460 static TTree *trH1; //Tree with background hits
461 static Bool_t first=kTRUE;
463 const char *addBgr = strstr(option,"Add");
465 evnt = nmodules; // Dummy use of variables to remove warnings
468 file=new TFile(filename);
473 // Get Hits Tree header from file
474 if(trH1) delete trH1;
478 sprintf(treeName,"TreeH%d",bgrev);
479 trH1 = (TTree*)gDirectory->Get(treeName);
481 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
483 // Set branch addresses
486 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
489 FillModules(trH1,10000000); // Default mask 10M.
490 TTree *fAli=fLoader->GetRunLoader()->TreeK();
492 if (fAli) fileAli =fAli->GetCurrentFile();
498 //______________________________________________________________________
499 void AliITS::FillModules(TTree *treeH, Int_t mask) {
500 // fill the modules with the sorted by module hits;
501 // can be called many times to do a merging
503 // TTree *treeH The tree containing the hits to be copied into
505 // Int_t mask The track number mask to indecate which file
506 // this hits came from.
514 Error("FillModules","Tree is NULL");
516 Int_t lay,lad,det,index;
520 sprintf(branchname,"%s",GetName());
521 TBranch *branch = treeH->GetBranch(branchname);
523 Error("FillModules","%s branch in TreeH not found",branchname);
526 branch->SetAddress(&fHits);
527 Int_t nTracks =(Int_t) treeH->GetEntries();
529 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
531 Int_t nBytes = treeH->GetEvent(iPrimTrack);
532 if (nBytes <= 0) continue;
533 Int_t nHits = fHits->GetEntriesFast();
534 for(h=0; h<nHits; h++){
535 itsHit = (AliITShit *)fHits->UncheckedAt(h);
536 itsHit->GetDetectorID(lay,lad,det);
538 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
540 index=det-1; // This should not be used.
541 } // end if [You must have fITSgeom for this to work!]
542 mod = GetModule(index);
543 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
544 mod->AddHit(itsHit,iPrimTrack,h);
545 } // end loop over hits
546 } // end loop over tracks
549 //______________________________________________________________________
550 Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
551 // Initialize the modules array.
553 // Int_t size Size of array of the number of modules to be
554 // created. If size <=0 then the number of modules
555 // is gotten from AliITSgeom class kept in fITSgeom.
557 // Int_t &nmodules The number of modules existing.
562 fITSmodules->Delete();
564 } // end fir fITSmoudles
567 Error("InitModules","fDetTypeSim is null!");
570 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
572 Int_t nl,indexMAX,index;
574 if(size<=0){ // default to using data stored in AliITSgeom
575 if(fDetTypeSim->GetITSgeom()==0) {
576 Error("InitModules","fITSgeom not defined");
578 } // end if fITSgeom==0
579 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
580 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
582 fITSmodules = new TObjArray(indexMAX);
583 for(index=0;index<indexMAX;index++){
584 fITSmodules->AddAt( new AliITSmodule(index),index);
587 fITSmodules = new TObjArray(size);
588 for(index=0;index<size;index++) {
589 fITSmodules->AddAt( new AliITSmodule(index),index);
596 //______________________________________________________________________
597 void AliITS::Hits2SDigits(){
598 // Standard Hits to summable Digits function.
606 Error("Hits2SDigits","fDetTypeSim is null!");
611 fLoader->LoadHits("read");
612 fLoader->LoadSDigits("recreate");
613 AliRunLoader* rl = fLoader->GetRunLoader();
614 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
615 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
617 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
618 // Do the Hits to Digits operation. Use Standard input values.
619 // Event number from file, no background hit merging , use size from
620 // AliITSgeom class, option="All", input from this file only.
621 rl->GetEvent(iEvent);
622 if (!fLoader->TreeS()) fLoader->MakeTree("S");
625 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
628 fLoader->UnloadHits();
629 fLoader->UnloadSDigits();
632 //______________________________________________________________________
633 void AliITS::Hits2Digits(){
635 //Conversion from hits to digits
637 Error("Hits2SDigits","fDetTypeSim is 0!");
641 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
642 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
645 fLoader->LoadHits("read");
646 fLoader->LoadDigits("recreate");
647 AliRunLoader* rl = fLoader->GetRunLoader();
648 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
649 rl->GetEvent(iEvent);
650 if (!fLoader->TreeD()) fLoader->MakeTree("D");
653 HitsToDigits(iEvent,0,-1," ",fOpt," ");
656 fLoader->UnloadHits();
657 fLoader->UnloadDigits();
661 //______________________________________________________________________
662 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
663 Option_t *option,Option_t *opt,
664 const char *filename){
665 // Keep galice.root for signal and name differently the file for
666 // background when add! otherwise the track info for signal will be lost !
667 // the condition below will disappear when the geom class will be
668 // initialized for all versions - for the moment it is only for v5 !
669 // 7 is the SDD beam test version.
671 // Int_t evnt Event to be processed.
672 // Int_t bgrev Background Hit tree number.
673 // Int_t nmodules Not used.
674 // Option_t *option String indicating if merging hits or not. To
675 // merge hits set equal to "Add". Otherwise no
676 // background hits are considered.
677 // Test_t *filename File name containing the background hits..
684 Error("HitsToDigits","fDetTypeSim is null!");
687 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
688 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
689 if(!GetITSgeom()) return; // need transformations to do digitization.
690 AliITSgeom *geom = GetITSgeom();
692 const char *all = strstr(opt,"All");
693 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
695 static Bool_t setDef=kTRUE;
696 if (setDef) SetDefaultSimulation();
700 InitModules(size,nmodules);
701 FillModules(evNumber,bgrev,nmodules,option,filename);
703 // Reset Fast-OR signals for this event
704 fDetTypeSim->ResetFOSignals();
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 // Add random noise to FO signals
729 if (all || det[0]) { // SPD present
730 fDetTypeSim->ProcessNoiseForFastOr();
733 // Add Fast-OR signals to event (only one object per event)
734 if (all || det[0]) { // SPD present
735 fDetTypeSim->WriteFOSignals();
739 fLoader->TreeD()->GetEntries();
740 fLoader->TreeD()->AutoSave();
742 fLoader->TreeD()->Reset();
744 //_____________________________________________________________________
745 void AliITS::Hits2PreDigits(){
746 // Turn hits into SDigits
749 Error("Hits2SDigits","fDetTypeSim is 0!");
753 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
754 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
757 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
761 //______________________________________________________________________
762 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
763 Option_t *option,Option_t *opt,
764 const char *filename){
765 // Keep galice.root for signal and name differently the file for
766 // background when add! otherwise the track info for signal will be lost !
767 // the condition below will disappear when the geom class will be
768 // initialized for all versions - for the moment it is only for v5 !
769 // 7 is the SDD beam test version.
771 // Int_t evnt Event to be processed.
772 // Int_t bgrev Background Hit tree number.
773 // Int_t nmodules Not used.
774 // Option_t *option String indicating if merging hits or not. To
775 // merge hits set equal to "Add". Otherwise no
776 // background hits are considered.
777 // Test_t *filename File name containing the background hits..
785 Error("HitsToPreDigits","fDetTypeSim is null!");
788 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
789 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
792 Error("HitsToPreDigits","fGeom is null!");
793 return; // need transformations to do digitization.
795 AliITSgeom *geom = GetITSgeom();
797 const char *all = strstr(opt,"All");
798 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
800 static Bool_t setDef=kTRUE;
801 if (setDef) SetDefaultSimulation();
805 InitModules(size,nmodules);
806 FillModules(evNumber,bgrev,nmodules,option,filename);
809 AliITSsimulation *sim = 0;
810 AliITSmodule *mod = 0;
812 for(module=0;module<geom->GetIndexMax();module++){
813 id = geom->GetModuleType(module);
814 if (!all && !det[id]) continue;
815 sim = (AliITSsimulation*)GetSimulationModel(id);
817 Error("HitsToPreDigits","The simulation class was not "
818 "instanciated for module %d type %s!",module,
819 geom->GetModuleTypeName(module));
822 mod = (AliITSmodule *)fITSmodules->At(module);
823 sim->SDigitiseModule(mod,module,evNumber);
824 // fills all branches - wasted disk space
825 fLoader->TreeS()->Fill();
826 fDetTypeSim->ResetSDigits();
832 fLoader->TreeS()->GetEntries();
833 fLoader->TreeS()->AutoSave();
834 fLoader->WriteSDigits("OVERWRITE");
836 fLoader->TreeS()->Reset();
839 //_____________________________________________________________________
840 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
841 Option_t *opt0,Option_t *opt1,
843 // keep galice.root for signal and name differently the file for
844 // background when add! otherwise the track info for signal will be lost !
845 // the condition below will disappear when the geom class will be
846 // initialized for all versions - for the moment it is only for v5 !
848 // Int_t evnt Event to be processed.
849 // Int_t bgrev Background Hit tree number.
850 // Int_t size Size used by InitModules. See InitModules.
851 // Option_t *opt0 Option passed to FillModules. See FillModules.
852 // Option_t *opt1 String indicating if merging hits or not. To
853 // merge hits set equal to "Add". Otherwise no
854 // background hits are considered.
855 // Test_t *flnm File name containing the background hits..
864 Error("HitsToPreDigits","fGeom is null!");
865 return; // need transformations to do digitization.
867 AliITSgeom *geom = GetITSgeom();
869 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
871 const char *all = strstr(opt1,"All");
872 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
875 InitModules(size,nmodules);
876 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
878 AliITSsimulation *sim = 0;
879 AliITSmodule *mod = 0;
882 TTree *lTR = pITSloader->TreeR();
884 pITSloader->MakeTree("R");
885 lTR = pITSloader->TreeR();
888 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
889 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
890 branch->SetAddress(&ptarray);
891 //m.b. : this change is nothing but a nice way to make sure
893 for(module=0;module<geom->GetIndexMax();module++){
894 id = geom->GetModuleType(module);
895 if (!all && !det[id]) continue;
896 sim = (AliITSsimulation*)GetSimulationModel(id);
898 Error("HitsToFastPoints","The simulation class was not "
899 "instanciated for module %d type %x!",module,
900 geom->GetModuleTypeName(module));
903 mod = (AliITSmodule *)fITSmodules->At(module);
904 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
910 fLoader->WriteRecPoints("OVERWRITE");
913 //_____________________________________________________________________
914 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
915 //------------------------------------------------------------
916 // This function creates ITS clusters
917 //------------------------------------------------------------
919 Error("HitsToPreDigits","fGeom is null!");
920 return 1; // need transformations to do digitization.
922 AliITSgeom *geom=GetITSgeom();
923 Int_t mmax=geom->GetIndexMax();
925 InitModules(-1,mmax);
926 FillModules(hTree,0);
928 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
929 TBranch *branch=cTree->GetBranch("ITSRecPoints");
930 if (!branch) cTree->Branch("ITSRecPoints",&points);
931 else branch->SetAddress(&points);
933 AliITSsimulationFastPoints sim;
935 for (Int_t m=0; m<mmax; m++) {
936 AliITSmodule *mod=GetModule(m);
937 sim.CreateFastRecPoints(mod,m,gRandom,points);
938 ncl+=points->GetEntriesFast();
943 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
951 //_____________________________________________________________________
952 void AliITS::CheckLabels(Int_t lab[3]) const {
953 //------------------------------------------------------------
954 // Tries to find mother's labels
955 //------------------------------------------------------------
957 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
959 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
960 for (Int_t i=0;i<3;i++){
961 Int_t label = lab[i];
962 if (label>=0 && label<ntracks) {
963 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
964 if (part->P() < 0.005) {
965 Int_t m=part->GetFirstMother();
969 if (part->GetStatusCode()>0) {
979 //______________________________________________________________________
980 void AliITS::SDigitsToDigits(Option_t *opt){
981 // Standard Summable digits to Digits function.
987 AliError("fDetTypeSim is 0!");
991 const char *all = strstr(opt,"All");
992 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
995 // Reset Fast-OR signals for this event
996 fDetTypeSim->ResetFOSignals();
998 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1000 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1001 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1003 // Add random noise to FO signals
1004 if (all || det[0]) { // SPD present
1005 fDetTypeSim->ProcessNoiseForFastOr();
1007 // Add Fast-OR signals to event (only one object per event)
1008 if (all || det[0]) { // SPD present
1009 fDetTypeSim->WriteFOSignals();
1013 //______________________________________________________________________
1014 void AliITS::ResetDigits(){
1015 // Reset number of digits and the digits array for the ITS detector.
1021 Error("ResetDigits","fDetTypeSim is 0!");
1025 fDetTypeSim->ResetDigits();
1029 //______________________________________________________________________
1030 void AliITS::ResetDigits(Int_t branch){
1031 // Reset number of digits and the digits array for this branch.
1038 Error("ResetDigits","fDetTypeSim is 0!");
1042 fDetTypeSim->ResetDigits(branch);
1045 //______________________________________________________________________
1046 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1047 // Adds the a module full of summable digits to the summable digits tree.
1049 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1056 Error("AddSumDigit","fDetTypeSim is 0!");
1059 fDetTypeSim->AddSumDigit(sdig);
1062 //______________________________________________________________________
1063 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1064 // Add a simulated digit.
1066 // Int_t id Detector type number.
1067 // AliITSdigit *d Digit to be added to the Digits Tree. See
1075 Error("AddSimDigit","fDetTypeSim is 0!");
1078 fDetTypeSim->AddSimDigit(branch,d);
1081 //______________________________________________________________________
1082 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1083 Int_t *hits,Float_t *charges, Int_t sigexpanded){
1084 // Add a simulated digit to the list.
1086 // Int_t id Detector type number.
1087 // Float_t phys Physics indicator. See AliITSdigits.h
1088 // Int_t *digits Integer array containing the digits info. See
1090 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1091 // containing the track numbers that contributed to
1093 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1094 // containing the hit numbers, from AliITSmodule, that
1095 // contributed to this digit.
1096 // Float_t *charge Floating point array of the signals contributed
1097 // to this digit by each track.
1104 Error("AddSimDigit","fDetTypeSim is 0!");
1107 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1110 //______________________________________________________________________
1111 void AliITS::Digits2Raw(){
1112 // convert digits of the current event to raw data
1115 Error("Digits2Raw","fDetTypeSim is 0!");
1118 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1120 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1121 fDetTypeSim->GetLoader()->LoadDigits();
1122 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1124 Error("Digits2Raw", "no digits tree");
1127 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1129 // Get the FO signals for this event
1130 AliITSFOSignalsSPD* foSignals = NULL;
1131 AliRunLoader* runLoader = AliRunLoader::Instance();
1132 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1134 AliError("ITS loader is NULL.");
1137 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1138 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1139 if(!foSignals) AliError("FO signals not retrieved");
1142 Bool_t deleteFOsignalsLater = kFALSE;
1144 AliError("FO signals not available. No FO bits will be written.");
1145 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1146 deleteFOsignalsLater = kTRUE;
1150 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1151 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1152 AliITSDDLRawData rawWriter;
1154 rawWriter.SetSDDRawFormat(rawSDD);
1158 // 2: txt files with digits
1159 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1160 //it is highly suggested to use this mode only for debugging digits files
1161 //reasonably small, because otherwise the size of the txt files can reach
1162 //quickly several MB wasting time and disk space.
1163 rawWriter.SetVerbose(0);
1165 //SILICON PIXEL DETECTOR
1166 AliDebug(1,"Formatting raw data for SPD");
1167 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1168 if(deleteFOsignalsLater) delete foSignals;
1170 //SILICON DRIFT DETECTOR
1171 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1172 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1174 //SILICON STRIP DETECTOR
1175 AliDebug(1,"Formatting raw data for SSD");
1176 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1178 fLoader->UnloadDigits();
1180 //______________________________________________________________________
1181 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1182 //builds ITSgetter (AliLoader type)
1183 //if detector wants to use castomized getter, it must overload this method
1185 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1187 fLoader = new AliITSLoader(GetName(),topfoldername);
1190 //______________________________________________________________________
1191 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1194 // Converts RAW data to SDigits
1199 Int_t size = GetITSgeom()->GetIndexMax();
1200 TClonesArray** modA = new TClonesArray*[size];
1201 for (Int_t mod = 0; mod < size; mod++) modA[mod] = new TClonesArray("AliITSpListItem", 10000);
1203 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1205 Error("Open","Can not get ITS loader from Run Loader");
1210 tree = loader->TreeS();
1212 loader->MakeTree("S");
1213 tree = loader->TreeS();
1216 // Array for SDigits
1218 TClonesArray aSDigits("AliITSpListItem",10000), *itsSDigits=&aSDigits;
1219 Int_t bufsize = 32000;
1220 tree->Branch("ITS", &itsSDigits, bufsize);
1225 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1227 AliWarning("Set AliITS defaults");
1229 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1231 npx = segSPD->Npx();
1232 Double_t thr, sigma;
1234 AliITSRawStreamSPD inputSPD(rawReader);
1236 Bool_t next = inputSPD.Next();
1239 Int_t module = inputSPD.GetModuleID();
1240 Int_t column = inputSPD.GetColumn();
1241 Int_t row = inputSPD.GetRow();
1242 Int_t index = npx * column + row;
1244 if (module >= size) continue;
1246 last = (modA[module])->GetEntries();
1247 TClonesArray& dum = *modA[module];
1248 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1250 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1257 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1258 npx = segSDD->Npx();
1259 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1260 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1261 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1263 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1264 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1265 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1266 Bool_t isZeroSupp=cal->GetZeroSupp();
1268 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1270 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
1274 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1275 inputSDD->SetDDLModuleMap(ddlmap);
1276 while(inputSDD->Next()){
1277 if(inputSDD->IsCompletedModule()==kFALSE &&
1278 inputSDD->IsCompletedDDL()==kFALSE){
1280 Int_t module = inputSDD->GetModuleID();
1281 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1282 Int_t time = inputSDD->GetCoord2();
1283 Int_t signal10 = inputSDD->GetSignal();
1284 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1286 if (module >= size) continue;
1287 last = modA[module]->GetEntries();
1288 TClonesArray& dum = *modA[module];
1289 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1290 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1299 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1300 npx = segSSD->Npx();
1301 AliITSRawStreamSSD inputSSD(rawReader);
1303 Bool_t next = inputSSD.Next();
1306 Int_t module = inputSSD.GetModuleID();
1307 Int_t side = inputSSD.GetSideFlag();
1308 Int_t strip = inputSSD.GetStrip();
1309 Int_t signal = inputSSD.GetSignal();
1310 Int_t index = npx * side + strip;
1312 if (module >= size) continue;
1314 last = modA[module]->GetEntries();
1315 TClonesArray& dum = *modA[module];
1316 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1319 AliITSpListItem* sdig = 0;
1321 for (Int_t mod = 0; mod < size; mod++)
1323 Int_t nsdig = modA[mod]->GetEntries();
1324 for (Int_t ie = 0; ie < nsdig; ie++) {
1325 sdig = (AliITSpListItem*) (modA[mod]->At(ie));
1326 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), sdig->GetSignal());
1327 Float_t sig = sdig->GetSignalAfterElect();
1329 sdig = (AliITSpListItem*)aSDigits[ie];
1330 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1338 loader->WriteSDigits("OVERWRITE");
1344 //______________________________________________________________________
1345 void AliITS::UpdateInternalGeometry(){
1347 //reads new geometry from TGeo
1348 // AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1350 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1352 if(version==kvPPRasymmFMD) minor=2; // default minor version for this geom.
1353 AliITSInitGeometry initgeom;
1354 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1357 //______________________________________________________________________
1358 AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1359 // create an AliITSTrigger object (and set trigger conditions as input)
1360 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());