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 "AliRawReader.h"
97 #include "AliITSInitGeometry.h"
98 #include "AliITSFOSignalsSPD.h"
102 //______________________________________________________________________
103 AliITS::AliITS() : AliDetector(),
114 // Default initializer for ITS
115 // The default constructor of the AliITS class. In addition to
116 // creating the AliITS class it zeros the variables fIshunt (a member
117 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
118 // fIdSens, and fIdName. The AliDetector default constructor
121 // SetDetectors(); // default to fOpt="All". This variable not written out.
122 //PH SetMarkerColor(kRed);
124 //______________________________________________________________________
125 AliITS::AliITS(const Char_t *title):
126 AliDetector("ITS",title),
137 // The standard Constructor for the ITS class.
138 // It also zeros the variables
139 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
140 // the pointers fIdSens and fIdName. To help in displaying hits via the
141 // ROOT macro display.C AliITS also sets the marker color to red. The
142 // variables passes with this constructor, const char *name and *title,
143 // are used by the constructor of AliDetector class. See AliDetector
144 // class for a description of these parameters and its constructor
147 // Char_t *title Simulation title for the ITS
153 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
154 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
155 //fNhits=0; //done in AliDetector(name,title)
156 SetDetectors(); // default to fOpt="All". This variable not written out.
157 fDetTypeSim = new AliITSDetTypeSim();
158 //PH SetMarkerColor(kRed);
159 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
160 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
162 //______________________________________________________________________
163 AliITS::AliITS(const char *name, const char *title):
164 AliDetector(name,title),
175 // The standard Constructor for the ITS class.
176 // It also zeros the variables
177 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
178 // the pointers fIdSens and fIdName. To help in displaying hits via the
179 // ROOT macro display.C AliITS also sets the marker color to red. The
180 // variables passes with this constructor, const char *name and *title,
181 // are used by the constructor of AliDetector class. See AliDetector
182 // class for a description of these parameters and its constructor
185 fHits = new TClonesArray("AliITShit",1560);
186 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
187 //fNhits=0; //done in AliDetector(name,title)
189 SetDetectors(); // default to fOpt="All". This variable not written out.
191 fDetTypeSim = new AliITSDetTypeSim();
192 //PH SetMarkerColor(kRed);
193 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
194 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
197 //______________________________________________________________________
199 // Default destructor for ITS.
200 // The default destructor of the AliITS class. In addition to deleting
201 // the AliITS class it deletes the memory pointed to by
202 // fIdSens, fIdName, fDetTypeSim and it's contents.
216 this->ClearModules();
219 }// end if fITSmodules!=0
221 delete[] fIdName; // Array of TStrings
233 //______________________________________________________________________
234 AliDigitizer* AliITS::CreateDigitizer(AliRunDigitizer* manager)const{
235 // Creates the AliITSDigitizer in a standard way for use via AliModule.
236 // This function can not be included in the .h file because of problems
237 // with the order of inclusion (recursive).
239 // AliRunDigitizer *manager The Manger class for Digitization
243 // A new AliITSRunDigitizer (cast as a AliDigitizer).
245 return new AliITSDigitizer(manager);
247 //______________________________________________________________________
249 // Initializer ITS after it has been built
250 // This routine initializes the AliITS class. It is intended to be
251 // called from the Init function in AliITSv?. Besides displaying a banner
252 // indicating that it has been called it initializes the array fIdSens
253 // and sets the default segmentation, response, digit and raw cluster
254 // classes therefore it should be called after a call to CreateGeometry.
263 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
266 //______________________________________________________________________
267 void AliITS::SetDefaults(){
268 // sets the default segmentation, response, digit and raw cluster classes.
275 AliInfoClass("AliITS::Setting Defaults");
277 Error("SetDefaults()","fDetTypeSim is 0!");
281 fDetTypeSim->SetDefaults();
282 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
285 //______________________________________________________________________
286 void AliITS::SetDefaultSimulation(){
287 // sets the default simulation.
295 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
299 fDetTypeSim->SetDefaultSimulation();
300 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
305 //______________________________________________________________________
306 void AliITS::MakeBranch(Option_t* option){
307 // Creates Tree branches for the ITS.
309 // Option_t *option String of Tree types S,D, and/or R.
310 // const char *file String of the file name where these branches
311 // are to be stored. If blank then these branches
312 // are written to the same tree as the Hits were
319 Error("MakeBranch","fDetTypeSim is 0!");
323 Bool_t cH = (strstr(option,"H")!=0);
324 Bool_t cS = (strstr(option,"S")!=0);
325 Bool_t cD = (strstr(option,"D")!=0);
327 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
328 AliDetector::MakeBranch(option);
330 if(cS) MakeBranchS(0);
331 if(cD) MakeBranchD(0);
335 //___________________________________________________________________
336 void AliITS::MakeBranchS(const char* fl){
338 // Creates Tree Branch for the ITS summable digits.
340 // cont char *fl File name where SDigits branch is to be written
341 // to. If blank it write the SDigits to the same
342 // file in which the Hits were found.
346 Error("MakeBranchS","fDetTypeSim is 0!");
348 Int_t buffersize = 4000;
351 // only one branch for SDigits.
352 sprintf(branchname,"%s",GetName());
354 if(fLoader->TreeS()){
355 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
356 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
359 //______________________________________________________________________
360 void AliITS::MakeBranchD(const char* file){
362 //Make branch for digits
364 Warning("MakeBranchD","fDetTypeSim is 0!");
367 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
368 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
369 MakeBranchInTreeD(fLoader->TreeD(),file);
372 //___________________________________________________________________
373 void AliITS:: MakeBranchInTreeD(TTree* treeD, const char* file){
374 // Creates Tree branches for the ITS.
377 Error("MakeBranchS","fDetTypeSim is 0!");
379 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
380 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
382 const Char_t *det[3] = {"SPD","SDD","SSD"};
383 const Char_t* digclass;
384 Int_t buffersize = 4000;
385 Char_t branchname[30];
387 if(!fDetTypeSim->GetDigits()){
388 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
390 for(Int_t i=0;i<fgkNTYPES;i++){
391 digclass = fDetTypeSim->GetDigitClassName(i);
392 TString classn = digclass;
393 if(!((fDetTypeSim->GetDigits())->At(i))){
394 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
397 if(fgkNTYPES==3) sprintf(branchname,"%sDigits%s",GetName(),det[i]);
398 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
399 TObjArray* dig = DigitsAddress(i);
400 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
404 //______________________________________________________________________
405 void AliITS::SetTreeAddress(){
406 // Set branch address for the Trees.
415 Error("SetTreeAddress","fDetTypeSim is 0!");
419 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
420 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
422 TTree *treeS = fLoader->TreeS();
423 TTree *treeD = fLoader->TreeD();
424 if (fLoader->TreeH() && (fHits == 0x0)) {
425 fHits = new TClonesArray("AliITShit", 1560);
427 AliDetector::SetTreeAddress();
429 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
430 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
432 //______________________________________________________________________
433 void AliITS::AddHit(Int_t track, Int_t *vol, Float_t *hits){
435 // The function to add information to the AliITShit class. See the
436 // AliITShit class for a full description. This function allocates the
437 // necessary new space for the hit information and passes the variable
438 // track, and the pointers *vol and *hits to the AliITShit constructor
441 // Int_t track Track number which produced this hit.
442 // Int_t *vol Array of Integer Hit information. See AliITShit.h
443 // Float_t *hits Array of Floating Hit information. see AliITShit.h
448 TClonesArray &lhits = *fHits;
449 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
452 //______________________________________________________________________
453 void AliITS::FillModules(Int_t evnt,Int_t bgrev,Int_t nmodules,
454 Option_t *option, const char *filename){
455 // fill the modules with the sorted by module hits; add hits from
456 // background if option=Add.
458 static TTree *trH1; //Tree with background hits
459 static Bool_t first=kTRUE;
461 const char *addBgr = strstr(option,"Add");
463 evnt = nmodules; // Dummy use of variables to remove warnings
466 file=new TFile(filename);
471 // Get Hits Tree header from file
472 if(trH1) delete trH1;
476 sprintf(treeName,"TreeH%d",bgrev);
477 trH1 = (TTree*)gDirectory->Get(treeName);
479 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
481 // Set branch addresses
484 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
487 FillModules(trH1,10000000); // Default mask 10M.
488 TTree *fAli=fLoader->GetRunLoader()->TreeK();
490 if (fAli) fileAli =fAli->GetCurrentFile();
496 //______________________________________________________________________
497 void AliITS::FillModules(TTree *treeH, Int_t mask) {
498 // fill the modules with the sorted by module hits;
499 // can be called many times to do a merging
501 // TTree *treeH The tree containing the hits to be copied into
503 // Int_t mask The track number mask to indecate which file
504 // this hits came from.
512 Error("FillModules","Tree is NULL");
514 Int_t lay,lad,det,index;
518 sprintf(branchname,"%s",GetName());
519 TBranch *branch = treeH->GetBranch(branchname);
521 Error("FillModules","%s branch in TreeH not found",branchname);
524 branch->SetAddress(&fHits);
525 Int_t nTracks =(Int_t) treeH->GetEntries();
527 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
529 Int_t nBytes = treeH->GetEvent(iPrimTrack);
530 if (nBytes <= 0) continue;
531 Int_t nHits = fHits->GetEntriesFast();
532 for(h=0; h<nHits; h++){
533 itsHit = (AliITShit *)fHits->UncheckedAt(h);
534 itsHit->GetDetectorID(lay,lad,det);
536 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
538 index=det-1; // This should not be used.
539 } // end if [You must have fITSgeom for this to work!]
540 mod = GetModule(index);
541 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
542 mod->AddHit(itsHit,iPrimTrack,h);
543 } // end loop over hits
544 } // end loop over tracks
547 //______________________________________________________________________
548 Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
549 // Initialize the modules array.
551 // Int_t size Size of array of the number of modules to be
552 // created. If size <=0 then the number of modules
553 // is gotten from AliITSgeom class kept in fITSgeom.
555 // Int_t &nmodules The number of modules existing.
560 fITSmodules->Delete();
562 } // end fir fITSmoudles
565 Error("InitModules","fDetTypeSim is null!");
568 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
570 Int_t nl,indexMAX,index;
572 if(size<=0){ // default to using data stored in AliITSgeom
573 if(fDetTypeSim->GetITSgeom()==0) {
574 Error("InitModules","fITSgeom not defined");
576 } // end if fITSgeom==0
577 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
578 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
580 fITSmodules = new TObjArray(indexMAX);
581 for(index=0;index<indexMAX;index++){
582 fITSmodules->AddAt( new AliITSmodule(index),index);
585 fITSmodules = new TObjArray(size);
586 for(index=0;index<size;index++) {
587 fITSmodules->AddAt( new AliITSmodule(index),index);
594 //______________________________________________________________________
595 void AliITS::Hits2SDigits(){
596 // Standard Hits to summable Digits function.
604 Error("Hits2SDigits","fDetTypeSim is null!");
609 fLoader->LoadHits("read");
610 fLoader->LoadSDigits("recreate");
611 AliRunLoader* rl = fLoader->GetRunLoader();
612 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
613 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
615 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
616 // Do the Hits to Digits operation. Use Standard input values.
617 // Event number from file, no background hit merging , use size from
618 // AliITSgeom class, option="All", input from this file only.
619 rl->GetEvent(iEvent);
620 if (!fLoader->TreeS()) fLoader->MakeTree("S");
623 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
626 fLoader->UnloadHits();
627 fLoader->UnloadSDigits();
630 //______________________________________________________________________
631 void AliITS::Hits2Digits(){
633 //Conversion from hits to digits
635 Error("Hits2SDigits","fDetTypeSim is 0!");
639 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
640 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
643 fLoader->LoadHits("read");
644 fLoader->LoadDigits("recreate");
645 AliRunLoader* rl = fLoader->GetRunLoader();
646 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
647 rl->GetEvent(iEvent);
648 if (!fLoader->TreeD()) fLoader->MakeTree("D");
651 HitsToDigits(iEvent,0,-1," ",fOpt," ");
654 fLoader->UnloadHits();
655 fLoader->UnloadDigits();
659 //______________________________________________________________________
660 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
661 Option_t *option,Option_t *opt,
662 const char *filename){
663 // Keep galice.root for signal and name differently the file for
664 // background when add! otherwise the track info for signal will be lost !
665 // the condition below will disappear when the geom class will be
666 // initialized for all versions - for the moment it is only for v5 !
667 // 7 is the SDD beam test version.
669 // Int_t evnt Event to be processed.
670 // Int_t bgrev Background Hit tree number.
671 // Int_t nmodules Not used.
672 // Option_t *option String indicating if merging hits or not. To
673 // merge hits set equal to "Add". Otherwise no
674 // background hits are considered.
675 // Test_t *filename File name containing the background hits..
682 Error("HitsToDigits","fDetTypeSim is null!");
685 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
686 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
687 if(!GetITSgeom()) return; // need transformations to do digitization.
688 AliITSgeom *geom = GetITSgeom();
690 const char *all = strstr(opt,"All");
691 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
693 static Bool_t setDef=kTRUE;
694 if (setDef) SetDefaultSimulation();
698 InitModules(size,nmodules);
699 FillModules(evNumber,bgrev,nmodules,option,filename);
701 // Reset Fast-OR signals for this event
702 fDetTypeSim->ResetFOSignals();
704 AliITSsimulation *sim = 0;
705 AliITSmodule *mod = 0;
707 for(Int_t module=0;module<geom->GetIndexMax();module++){
708 id = geom->GetModuleType(module);
709 if (!all && !det[id]) continue;
710 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
712 Error("HitsToDigits","The simulation class was not "
713 "instanciated for module %d type %s!",module,
714 geom->GetModuleTypeName(module));
717 mod = (AliITSmodule *)fITSmodules->At(module);
718 sim->DigitiseModule(mod,module,evNumber);
719 // fills all branches - wasted disk space
720 fLoader->TreeD()->Fill();
726 // Add random noise to FO signals
727 if (all || det[0]) { // SPD present
728 fDetTypeSim->ProcessNoiseForFastOr();
731 // Add Fast-OR signals to event (only one object per event)
732 if (all || det[0]) { // SPD present
733 fDetTypeSim->WriteFOSignals();
737 fLoader->TreeD()->GetEntries();
738 fLoader->TreeD()->AutoSave();
740 fLoader->TreeD()->Reset();
742 //_____________________________________________________________________
743 void AliITS::Hits2PreDigits(){
744 // Turn hits into SDigits
747 Error("Hits2SDigits","fDetTypeSim is 0!");
751 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
752 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
755 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
759 //______________________________________________________________________
760 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
761 Option_t *option,Option_t *opt,
762 const char *filename){
763 // Keep galice.root for signal and name differently the file for
764 // background when add! otherwise the track info for signal will be lost !
765 // the condition below will disappear when the geom class will be
766 // initialized for all versions - for the moment it is only for v5 !
767 // 7 is the SDD beam test version.
769 // Int_t evnt Event to be processed.
770 // Int_t bgrev Background Hit tree number.
771 // Int_t nmodules Not used.
772 // Option_t *option String indicating if merging hits or not. To
773 // merge hits set equal to "Add". Otherwise no
774 // background hits are considered.
775 // Test_t *filename File name containing the background hits..
783 Error("HitsToPreDigits","fDetTypeSim is null!");
786 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
787 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
790 Error("HitsToPreDigits","fGeom is null!");
791 return; // need transformations to do digitization.
793 AliITSgeom *geom = GetITSgeom();
795 const char *all = strstr(opt,"All");
796 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
798 static Bool_t setDef=kTRUE;
799 if (setDef) SetDefaultSimulation();
803 InitModules(size,nmodules);
804 FillModules(evNumber,bgrev,nmodules,option,filename);
807 AliITSsimulation *sim = 0;
808 AliITSmodule *mod = 0;
810 for(module=0;module<geom->GetIndexMax();module++){
811 id = geom->GetModuleType(module);
812 if (!all && !det[id]) continue;
813 sim = (AliITSsimulation*)GetSimulationModel(id);
815 Error("HitsToPreDigits","The simulation class was not "
816 "instanciated for module %d type %s!",module,
817 geom->GetModuleTypeName(module));
820 mod = (AliITSmodule *)fITSmodules->At(module);
821 sim->SDigitiseModule(mod,module,evNumber);
822 // fills all branches - wasted disk space
823 fLoader->TreeS()->Fill();
824 fDetTypeSim->ResetSDigits();
830 fLoader->TreeS()->GetEntries();
831 fLoader->TreeS()->AutoSave();
832 fLoader->WriteSDigits("OVERWRITE");
834 fLoader->TreeS()->Reset();
837 //_____________________________________________________________________
838 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
839 Option_t *opt0,Option_t *opt1,
841 // keep galice.root for signal and name differently the file for
842 // background when add! otherwise the track info for signal will be lost !
843 // the condition below will disappear when the geom class will be
844 // initialized for all versions - for the moment it is only for v5 !
846 // Int_t evnt Event to be processed.
847 // Int_t bgrev Background Hit tree number.
848 // Int_t size Size used by InitModules. See InitModules.
849 // Option_t *opt0 Option passed to FillModules. See FillModules.
850 // Option_t *opt1 String indicating if merging hits or not. To
851 // merge hits set equal to "Add". Otherwise no
852 // background hits are considered.
853 // Test_t *flnm File name containing the background hits..
862 Error("HitsToPreDigits","fGeom is null!");
863 return; // need transformations to do digitization.
865 AliITSgeom *geom = GetITSgeom();
867 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
869 const char *all = strstr(opt1,"All");
870 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
873 InitModules(size,nmodules);
874 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
876 AliITSsimulation *sim = 0;
877 AliITSmodule *mod = 0;
880 TTree *lTR = pITSloader->TreeR();
882 pITSloader->MakeTree("R");
883 lTR = pITSloader->TreeR();
886 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
887 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
888 branch->SetAddress(&ptarray);
889 //m.b. : this change is nothing but a nice way to make sure
891 for(module=0;module<geom->GetIndexMax();module++){
892 id = geom->GetModuleType(module);
893 if (!all && !det[id]) continue;
894 sim = (AliITSsimulation*)GetSimulationModel(id);
896 Error("HitsToFastPoints","The simulation class was not "
897 "instanciated for module %d type %x!",module,
898 geom->GetModuleTypeName(module));
901 mod = (AliITSmodule *)fITSmodules->At(module);
902 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
908 fLoader->WriteRecPoints("OVERWRITE");
911 //_____________________________________________________________________
912 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
913 //------------------------------------------------------------
914 // This function creates ITS clusters
915 //------------------------------------------------------------
917 Error("HitsToPreDigits","fGeom is null!");
918 return 1; // need transformations to do digitization.
920 AliITSgeom *geom=GetITSgeom();
921 Int_t mmax=geom->GetIndexMax();
923 InitModules(-1,mmax);
924 FillModules(hTree,0);
926 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
927 TBranch *branch=cTree->GetBranch("ITSRecPoints");
928 if (!branch) cTree->Branch("ITSRecPoints",&points);
929 else branch->SetAddress(&points);
931 AliITSsimulationFastPoints sim;
933 for (Int_t m=0; m<mmax; m++) {
934 AliITSmodule *mod=GetModule(m);
935 sim.CreateFastRecPoints(mod,m,gRandom,points);
936 ncl+=points->GetEntriesFast();
941 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
949 //_____________________________________________________________________
950 void AliITS::CheckLabels(Int_t lab[3]) const {
951 //------------------------------------------------------------
952 // Tries to find mother's labels
953 //------------------------------------------------------------
955 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
957 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
958 for (Int_t i=0;i<3;i++){
959 Int_t label = lab[i];
960 if (label>=0 && label<ntracks) {
961 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
962 if (part->P() < 0.005) {
963 Int_t m=part->GetFirstMother();
967 if (part->GetStatusCode()>0) {
977 //______________________________________________________________________
978 void AliITS::SDigitsToDigits(Option_t *opt){
979 // Standard Summable digits to Digits function.
985 AliError("fDetTypeSim is 0!");
989 const char *all = strstr(opt,"All");
990 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
993 // Reset Fast-OR signals for this event
994 fDetTypeSim->ResetFOSignals();
996 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
998 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
999 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1001 // Add random noise to FO signals
1002 if (all || det[0]) { // SPD present
1003 fDetTypeSim->ProcessNoiseForFastOr();
1005 // Add Fast-OR signals to event (only one object per event)
1006 if (all || det[0]) { // SPD present
1007 fDetTypeSim->WriteFOSignals();
1011 //______________________________________________________________________
1012 void AliITS::ResetDigits(){
1013 // Reset number of digits and the digits array for the ITS detector.
1019 Error("ResetDigits","fDetTypeSim is 0!");
1023 fDetTypeSim->ResetDigits();
1027 //______________________________________________________________________
1028 void AliITS::ResetDigits(Int_t branch){
1029 // Reset number of digits and the digits array for this branch.
1036 Error("ResetDigits","fDetTypeSim is 0!");
1040 fDetTypeSim->ResetDigits(branch);
1043 //______________________________________________________________________
1044 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1045 // Adds the a module full of summable digits to the summable digits tree.
1047 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1054 Error("AddSumDigit","fDetTypeSim is 0!");
1057 fDetTypeSim->AddSumDigit(sdig);
1060 //______________________________________________________________________
1061 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1062 // Add a simulated digit.
1064 // Int_t id Detector type number.
1065 // AliITSdigit *d Digit to be added to the Digits Tree. See
1073 Error("AddSimDigit","fDetTypeSim is 0!");
1076 fDetTypeSim->AddSimDigit(branch,d);
1079 //______________________________________________________________________
1080 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1081 Int_t *hits,Float_t *charges, Int_t sigexpanded){
1082 // Add a simulated digit to the list.
1084 // Int_t id Detector type number.
1085 // Float_t phys Physics indicator. See AliITSdigits.h
1086 // Int_t *digits Integer array containing the digits info. See
1088 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1089 // containing the track numbers that contributed to
1091 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1092 // containing the hit numbers, from AliITSmodule, that
1093 // contributed to this digit.
1094 // Float_t *charge Floating point array of the signals contributed
1095 // to this digit by each track.
1102 Error("AddSimDigit","fDetTypeSim is 0!");
1105 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1108 //______________________________________________________________________
1109 void AliITS::Digits2Raw(){
1110 // convert digits of the current event to raw data
1113 Error("Digits2Raw","fDetTypeSim is 0!");
1116 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1118 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1119 fDetTypeSim->GetLoader()->LoadDigits();
1120 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1122 Error("Digits2Raw", "no digits tree");
1125 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1127 // Get the FO signals for this event
1128 AliITSFOSignalsSPD* foSignals = NULL;
1129 AliRunLoader* runLoader = AliRunLoader::Instance();
1130 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1132 AliError("ITS loader is NULL.");
1135 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1136 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1137 if(!foSignals) AliError("FO signals not retrieved");
1140 Bool_t deleteFOsignalsLater = kFALSE;
1142 AliError("FO signals not available. No FO bits will be written.");
1143 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1144 deleteFOsignalsLater = kTRUE;
1148 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1149 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1150 AliITSDDLRawData rawWriter;
1152 rawWriter.SetSDDRawFormat(rawSDD);
1156 // 2: txt files with digits
1157 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1158 //it is highly suggested to use this mode only for debugging digits files
1159 //reasonably small, because otherwise the size of the txt files can reach
1160 //quickly several MB wasting time and disk space.
1161 rawWriter.SetVerbose(0);
1163 //SILICON PIXEL DETECTOR
1164 AliDebug(1,"Formatting raw data for SPD");
1165 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1166 if(deleteFOsignalsLater) delete foSignals;
1168 //SILICON DRIFT DETECTOR
1169 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1170 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1172 //SILICON STRIP DETECTOR
1173 AliDebug(1,"Formatting raw data for SSD");
1174 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1176 fLoader->UnloadDigits();
1178 //______________________________________________________________________
1179 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1180 //builds ITSgetter (AliLoader type)
1181 //if detector wants to use castomized getter, it must overload this method
1183 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1185 fLoader = new AliITSLoader(GetName(),topfoldername);
1188 //______________________________________________________________________
1189 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1192 // Converts RAW data to SDigits
1197 Int_t size = GetITSgeom()->GetIndexMax();
1198 TClonesArray** modA = new TClonesArray*[size];
1199 for (Int_t mod = 0; mod < size; mod++) modA[mod] = new TClonesArray("AliITSpListItem", 10000);
1201 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1203 Error("Open","Can not get ITS loader from Run Loader");
1208 tree = loader->TreeS();
1210 loader->MakeTree("S");
1211 tree = loader->TreeS();
1214 // Array for SDigits
1216 TClonesArray aSDigits("AliITSpListItem",10000), *itsSDigits=&aSDigits;
1217 Int_t bufsize = 32000;
1218 tree->Branch("ITS", &itsSDigits, bufsize);
1223 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1225 AliWarning("Set AliITS defaults");
1227 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1229 npx = segSPD->Npx();
1230 Double_t thr, sigma;
1232 AliITSRawStreamSPD inputSPD(rawReader);
1234 Bool_t next = inputSPD.Next();
1237 Int_t module = inputSPD.GetModuleID();
1238 Int_t column = inputSPD.GetColumn();
1239 Int_t row = inputSPD.GetRow();
1240 Int_t index = npx * column + row;
1242 if (module >= size) continue;
1244 last = (modA[module])->GetEntries();
1245 TClonesArray& dum = *modA[module];
1246 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1248 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1255 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1256 npx = segSDD->Npx();
1257 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1258 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1259 inputSDD->SetDDLModuleMap(ddlmap);
1261 Bool_t next = inputSDD->Next();
1264 if(inputSDD->IsCompletedModule()==kFALSE &&
1265 inputSDD->IsCompletedDDL()==kFALSE){
1267 Int_t module = inputSDD->GetModuleID();
1268 Int_t anode = inputSDD->GetCoord1();
1269 Int_t time = inputSDD->GetCoord2();
1270 Int_t signal10 = inputSDD->GetSignal();
1271 Int_t index = npx * anode + time;
1273 if (module >= size) continue;
1274 last = modA[module]->GetEntries();
1275 TClonesArray& dum = *modA[module];
1276 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1277 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1286 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1287 npx = segSSD->Npx();
1288 AliITSRawStreamSSD inputSSD(rawReader);
1290 Bool_t next = inputSSD.Next();
1293 Int_t module = inputSSD.GetModuleID();
1294 Int_t side = inputSSD.GetSideFlag();
1295 Int_t strip = inputSSD.GetStrip();
1296 Int_t signal = inputSSD.GetSignal();
1297 Int_t index = npx * side + strip;
1299 if (module >= size) continue;
1301 last = modA[module]->GetEntries();
1302 TClonesArray& dum = *modA[module];
1303 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1306 AliITSpListItem* sdig = 0;
1308 for (Int_t mod = 0; mod < size; mod++)
1310 Int_t nsdig = modA[mod]->GetEntries();
1311 for (Int_t ie = 0; ie < nsdig; ie++) {
1312 sdig = (AliITSpListItem*) (modA[mod]->At(ie));
1313 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), sdig->GetSignal());
1314 Float_t sig = sdig->GetSignalAfterElect();
1316 sdig = (AliITSpListItem*)aSDigits[ie];
1317 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1325 loader->WriteSDigits("OVERWRITE");
1331 //______________________________________________________________________
1332 void AliITS::UpdateInternalGeometry(){
1334 //reads new geometry from TGeo
1335 // AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1337 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1339 if(version==kvPPRasymmFMD) minor=2; // default minor version for this geom.
1340 AliITSInitGeometry initgeom;
1341 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1344 //______________________________________________________________________
1345 AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1346 // create an AliITSTrigger object (and set trigger conditions as input)
1347 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());