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
232 Int_t size = AliITSgeomTGeo::GetNModules();
243 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 snprintf(branchname,30,"%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[31];
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) snprintf(branchname,30,"%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");
488 file=new TFile(filename);
493 // Get Hits Tree header from file
494 if(trH1) delete trH1;
498 snprintf(treeName,20,"TreeH%d",bgrev);
499 trH1 = (TTree*)gDirectory->Get(treeName);
501 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
503 // Set branch addresses
506 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
509 FillModules(trH1,10000000); // Default mask 10M.
510 TTree *fAli=fLoader->GetRunLoader()->TreeK();
513 fileAli =fAli->GetCurrentFile();
520 //______________________________________________________________________
521 void AliITS::FillModules(TTree *treeH, Int_t mask) {
522 // fill the modules with the sorted by module hits;
523 // can be called many times to do a merging
525 // TTree *treeH The tree containing the hits to be copied into
527 // Int_t mask The track number mask to indecate which file
528 // this hits came from.
536 AliError("Tree H is NULL");
539 Int_t lay,lad,det,index;
543 snprintf(branchname,20,"%s",GetName());
544 TBranch *branch = treeH->GetBranch(branchname);
546 Error("FillModules","%s branch in TreeH not found",branchname);
549 branch->SetAddress(&fHits);
550 Int_t nTracks =(Int_t) treeH->GetEntries();
552 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
554 Int_t nBytes = treeH->GetEvent(iPrimTrack);
555 if (nBytes <= 0) continue;
556 Int_t nHits = fHits->GetEntriesFast();
557 for(h=0; h<nHits; h++){
558 itsHit = (AliITShit *)fHits->UncheckedAt(h);
559 itsHit->GetDetectorID(lay,lad,det);
561 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
563 index=det-1; // This should not be used.
564 } // end if [You must have fITSgeom for this to work!]
565 mod = GetModule(index);
566 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
567 mod->AddHit(itsHit,iPrimTrack,h);
568 } // end loop over hits
569 } // end loop over tracks
572 //______________________________________________________________________
573 Bool_t AliITS::InitModules(Int_t size,Int_t &nmodules){
574 // Initialize the modules array.
576 // Int_t size Size of array of the number of modules to be
577 // created. If size <=0 then the number of modules
578 // is gotten from AliITSgeom class kept in fITSgeom.
580 // Int_t &nmodules The number of modules existing.
585 fITSmodules->Delete();
587 } // end fir fITSmoudles
590 Error("InitModules","fDetTypeSim is null!");
593 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
595 Int_t nl,indexMAX,index;
597 if(size<=0){ // default to using data stored in AliITSgeom
598 if(fDetTypeSim->GetITSgeom()==0) {
599 Error("InitModules","fITSgeom not defined");
601 } // end if fITSgeom==0
602 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
603 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
605 fITSmodules = new TObjArray(indexMAX);
606 for(index=0;index<indexMAX;index++){
607 fITSmodules->AddAt( new AliITSmodule(index),index);
610 fITSmodules = new TObjArray(size);
611 for(index=0;index<size;index++) {
612 fITSmodules->AddAt( new AliITSmodule(index),index);
619 //______________________________________________________________________
620 void AliITS::Hits2SDigits(){
621 // Standard Hits to summable Digits function.
629 Error("Hits2SDigits","fDetTypeSim is null!");
634 fLoader->LoadHits("read");
635 fLoader->LoadSDigits("recreate");
636 AliRunLoader* rl = fLoader->GetRunLoader();
637 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
638 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
640 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
641 // Do the Hits to Digits operation. Use Standard input values.
642 // Event number from file, no background hit merging , use size from
643 // AliITSgeom class, option="All", input from this file only.
644 rl->GetEvent(iEvent);
645 if (!fLoader->TreeS()) fLoader->MakeTree("S");
648 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
651 fLoader->UnloadHits();
652 fLoader->UnloadSDigits();
655 //______________________________________________________________________
656 void AliITS::Hits2Digits(){
658 //Conversion from hits to digits
660 Error("Hits2SDigits","fDetTypeSim is 0!");
664 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
665 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
668 fLoader->LoadHits("read");
669 fLoader->LoadDigits("recreate");
670 AliRunLoader* rl = fLoader->GetRunLoader();
671 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
672 rl->GetEvent(iEvent);
673 if (!fLoader->TreeD()) fLoader->MakeTree("D");
676 HitsToDigits(iEvent,0,-1," ",fOpt," ");
679 fLoader->UnloadHits();
680 fLoader->UnloadDigits();
684 //______________________________________________________________________
685 void AliITS::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
686 Option_t *option,Option_t *opt,
687 const char *filename){
688 // Keep galice.root for signal and name differently the file for
689 // background when add! otherwise the track info for signal will be lost !
690 // the condition below will disappear when the geom class will be
691 // initialized for all versions - for the moment it is only for v5 !
692 // 7 is the SDD beam test version.
694 // Int_t evnt Event to be processed.
695 // Int_t bgrev Background Hit tree number.
696 // Int_t nmodules Not used.
697 // Option_t *option String indicating if merging hits or not. To
698 // merge hits set equal to "Add". Otherwise no
699 // background hits are considered.
700 // Test_t *filename File name containing the background hits..
707 Error("HitsToDigits","fDetTypeSim is null!");
710 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
711 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
712 if(!GetITSgeom()) return; // need transformations to do digitization.
713 AliITSgeom *geom = GetITSgeom();
715 const char *all = strstr(opt,"All");
716 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
718 static Bool_t setDef=kTRUE;
719 if (setDef) SetDefaultSimulation();
723 InitModules(size,nmodules);
724 FillModules(evNumber,bgrev,nmodules,option,filename);
726 // Reset Fast-OR signals for this event
727 fDetTypeSim->ResetFOSignals();
729 AliITSsimulation *sim = 0;
730 AliITSmodule *mod = 0;
732 for(Int_t module=0;module<geom->GetIndexMax();module++){
733 id = geom->GetModuleType(module);
734 if (!all && !det[id]) continue;
735 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
737 Error("HitsToDigits","The simulation class was not "
738 "instanciated for module %d type %s!",module,
739 geom->GetModuleTypeName(module));
742 mod = (AliITSmodule *)fITSmodules->At(module);
743 sim->DigitiseModule(mod,module,evNumber);
744 // fills all branches - wasted disk space
745 fLoader->TreeD()->Fill();
751 // Add Fast-OR signals to event (only one object per event)
752 if (all || det[0]) { // SPD present
756 fLoader->TreeD()->GetEntries();
757 fLoader->TreeD()->AutoSave();
759 fLoader->TreeD()->Reset();
761 //_____________________________________________________________________
762 void AliITS::Hits2PreDigits(){
763 // Turn hits into SDigits
766 Error("Hits2SDigits","fDetTypeSim is 0!");
770 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
771 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
774 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
778 //______________________________________________________________________
779 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
780 Option_t *option,Option_t *opt,
781 const char *filename){
782 // Keep galice.root for signal and name differently the file for
783 // background when add! otherwise the track info for signal will be lost !
784 // the condition below will disappear when the geom class will be
785 // initialized for all versions - for the moment it is only for v5 !
786 // 7 is the SDD beam test version.
788 // Int_t evnt Event to be processed.
789 // Int_t bgrev Background Hit tree number.
790 // Int_t nmodules Not used.
791 // Option_t *option String indicating if merging hits or not. To
792 // merge hits set equal to "Add". Otherwise no
793 // background hits are considered.
794 // Test_t *filename File name containing the background hits..
802 Error("HitsToPreDigits","fDetTypeSim is null!");
805 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
806 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
809 Error("HitsToPreDigits","fGeom is null!");
810 return; // need transformations to do digitization.
812 AliITSgeom *geom = GetITSgeom();
814 const char *all = strstr(opt,"All");
815 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
817 static Bool_t setDef=kTRUE;
818 if (setDef) SetDefaultSimulation();
822 InitModules(size,nmodules);
823 FillModules(evNumber,bgrev,nmodules,option,filename);
826 AliITSsimulation *sim = 0;
827 AliITSmodule *mod = 0;
829 for(module=0;module<geom->GetIndexMax();module++){
830 id = geom->GetModuleType(module);
831 if (!all && !det[id]) continue;
832 sim = (AliITSsimulation*)GetSimulationModel(id);
834 Error("HitsToPreDigits","The simulation class was not "
835 "instanciated for module %d type %s!",module,
836 geom->GetModuleTypeName(module));
839 mod = (AliITSmodule *)fITSmodules->At(module);
840 sim->SDigitiseModule(mod,module,evNumber);
841 // fills all branches - wasted disk space
842 fLoader->TreeS()->Fill();
843 fDetTypeSim->ResetSDigits();
849 fLoader->TreeS()->GetEntries();
850 fLoader->TreeS()->AutoSave();
851 fLoader->WriteSDigits("OVERWRITE");
853 fLoader->TreeS()->Reset();
856 //_____________________________________________________________________
857 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
858 Option_t *opt0,Option_t *opt1,
860 // keep galice.root for signal and name differently the file for
861 // background when add! otherwise the track info for signal will be lost !
862 // the condition below will disappear when the geom class will be
863 // initialized for all versions - for the moment it is only for v5 !
865 // Int_t evnt Event to be processed.
866 // Int_t bgrev Background Hit tree number.
867 // Int_t size Size used by InitModules. See InitModules.
868 // Option_t *opt0 Option passed to FillModules. See FillModules.
869 // Option_t *opt1 String indicating if merging hits or not. To
870 // merge hits set equal to "Add". Otherwise no
871 // background hits are considered.
872 // Test_t *flnm File name containing the background hits..
881 Error("HitsToPreDigits","fGeom is null!");
882 return; // need transformations to do digitization.
884 AliITSgeom *geom = GetITSgeom();
886 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
888 const char *all = strstr(opt1,"All");
889 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
892 InitModules(size,nmodules);
893 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
895 AliITSsimulation *sim = 0;
896 AliITSmodule *mod = 0;
899 TTree *lTR = pITSloader->TreeR();
901 pITSloader->MakeTree("R");
902 lTR = pITSloader->TreeR();
905 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
906 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
907 branch->SetAddress(&ptarray);
908 //m.b. : this change is nothing but a nice way to make sure
910 for(module=0;module<geom->GetIndexMax();module++){
911 id = geom->GetModuleType(module);
912 if (!all && !det[id]) continue;
913 sim = (AliITSsimulation*)GetSimulationModel(id);
915 Error("HitsToFastPoints","The simulation class was not "
916 "instantiated for module %d type %s!",module,
917 geom->GetModuleTypeName(module));
920 mod = (AliITSmodule *)fITSmodules->At(module);
921 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
927 fLoader->WriteRecPoints("OVERWRITE");
930 //_____________________________________________________________________
931 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
932 //------------------------------------------------------------
933 // This function creates ITS clusters
934 //------------------------------------------------------------
936 Error("HitsToPreDigits","fGeom is null!");
937 return 1; // need transformations to do digitization.
939 AliITSgeom *geom=GetITSgeom();
940 Int_t mmax=geom->GetIndexMax();
942 InitModules(-1,mmax);
943 FillModules(hTree,0);
945 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
946 TBranch *branch=cTree->GetBranch("ITSRecPoints");
947 if (!branch) cTree->Branch("ITSRecPoints",&points);
948 else branch->SetAddress(&points);
950 AliITSsimulationFastPoints sim;
952 for (Int_t m=0; m<mmax; m++) {
953 AliITSmodule *mod=GetModule(m);
954 sim.CreateFastRecPoints(mod,m,gRandom,points);
955 ncl+=points->GetEntriesFast();
960 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
968 //_____________________________________________________________________
969 void AliITS::CheckLabels(Int_t lab[3]) const {
970 //------------------------------------------------------------
971 // Tries to find mother's labels
972 //------------------------------------------------------------
974 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
976 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
977 for (Int_t i=0;i<3;i++){
978 Int_t label = lab[i];
979 if (label>=0 && label<ntracks) {
980 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
981 if (part->P() < 0.005) {
982 Int_t m=part->GetFirstMother();
986 if (part->GetStatusCode()>0) {
996 //______________________________________________________________________
997 void AliITS::SDigitsToDigits(Option_t *opt){
998 // Standard Summable digits to Digits function.
1004 AliError("fDetTypeSim is 0!");
1007 const char *all = strstr(opt,"All");
1008 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1011 // Reset Fast-OR signals for this event
1012 fDetTypeSim->ResetFOSignals();
1014 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1016 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1017 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1019 // Add Fast-OR signals to event (only one object per event)
1020 if (all || det[0]) { // SPD present
1025 //______________________________________________________________________
1026 void AliITS::ResetDigits(){
1027 // Reset number of digits and the digits array for the ITS detector.
1033 Error("ResetDigits","fDetTypeSim is 0!");
1037 fDetTypeSim->ResetDigits();
1041 //______________________________________________________________________
1042 void AliITS::ResetDigits(Int_t branch){
1043 // Reset number of digits and the digits array for this branch.
1050 Error("ResetDigits","fDetTypeSim is 0!");
1054 fDetTypeSim->ResetDigits(branch);
1057 //______________________________________________________________________
1058 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1059 // Adds the a module full of summable digits to the summable digits tree.
1061 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1068 Error("AddSumDigit","fDetTypeSim is 0!");
1071 fDetTypeSim->AddSumDigit(sdig);
1074 //______________________________________________________________________
1075 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1076 // Add a simulated digit.
1078 // Int_t id Detector type number.
1079 // AliITSdigit *d Digit to be added to the Digits Tree. See
1087 Error("AddSimDigit","fDetTypeSim is 0!");
1090 fDetTypeSim->AddSimDigit(branch,d);
1093 //______________________________________________________________________
1094 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1095 Int_t *hits,Float_t *charges, Int_t sigexpanded){
1096 // Add a simulated digit to the list.
1098 // Int_t id Detector type number.
1099 // Float_t phys Physics indicator. See AliITSdigits.h
1100 // Int_t *digits Integer array containing the digits info. See
1102 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1103 // containing the track numbers that contributed to
1105 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1106 // containing the hit numbers, from AliITSmodule, that
1107 // contributed to this digit.
1108 // Float_t *charge Floating point array of the signals contributed
1109 // to this digit by each track.
1116 Error("AddSimDigit","fDetTypeSim is 0!");
1119 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1122 //______________________________________________________________________
1123 void AliITS::Digits2Raw(){
1124 // convert digits of the current event to raw data
1127 Error("Digits2Raw","fDetTypeSim is 0!");
1130 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1132 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1133 fDetTypeSim->GetLoader()->LoadDigits();
1134 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1136 Error("Digits2Raw", "no digits tree");
1139 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1141 // Get the FO signals for this event
1142 AliITSFOSignalsSPD* foSignals = NULL;
1143 AliRunLoader* runLoader = AliRunLoader::Instance();
1144 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1146 AliError("ITS loader is NULL.");
1149 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1150 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1151 if(!foSignals) AliError("FO signals not retrieved");
1154 Bool_t deleteFOsignalsLater = kFALSE;
1156 AliError("FO signals not available. No FO bits will be written.");
1157 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1158 deleteFOsignalsLater = kTRUE;
1162 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1163 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1164 AliITSDDLRawData rawWriter;
1166 rawWriter.SetSDDRawFormat(rawSDD);
1170 // 2: txt files with digits
1171 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1172 //it is highly suggested to use this mode only for debugging digits files
1173 //reasonably small, because otherwise the size of the txt files can reach
1174 //quickly several MB wasting time and disk space.
1175 rawWriter.SetVerbose(0);
1177 //SILICON PIXEL DETECTOR
1178 AliDebug(1,"Formatting raw data for SPD");
1179 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1180 if(deleteFOsignalsLater) delete foSignals;
1182 //SILICON DRIFT DETECTOR
1183 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1184 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1186 //SILICON STRIP DETECTOR
1187 AliDebug(1,"Formatting raw data for SSD");
1188 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1190 fLoader->UnloadDigits();
1192 //______________________________________________________________________
1193 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1194 //builds ITSgetter (AliLoader type)
1195 //if detector wants to use castomized getter, it must overload this method
1197 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1199 fLoader = new AliITSLoader(GetName(),topfoldername);
1202 //______________________________________________________________________
1203 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1206 // Converts RAW data to SDigits
1211 Int_t size = AliITSgeomTGeo::GetNModules();
1213 fModA = new TClonesArray*[size];
1214 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1216 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1218 Error("Open","Can not get ITS loader from Run Loader");
1223 tree = loader->TreeS();
1225 loader->MakeTree("S");
1226 tree = loader->TreeS();
1229 // Array for SDigits
1232 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1234 TClonesArray& aSDigits = *fpSDigits;
1235 Int_t bufsize = 32000;
1236 tree->Branch("ITS", &fpSDigits, bufsize);
1241 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1243 AliWarning("Set AliITS defaults");
1245 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1247 npx = segSPD->Npx();
1248 Double_t thr, sigma;
1250 AliITSRawStreamSPD inputSPD(rawReader);
1252 Bool_t next = inputSPD.Next();
1255 Int_t module = inputSPD.GetModuleID();
1256 Int_t column = inputSPD.GetColumn();
1257 Int_t row = inputSPD.GetRow();
1258 Int_t index = npx * column + row;
1260 if (module >= size) continue;
1262 last = (fModA[module])->GetEntries();
1263 TClonesArray& dum = *fModA[module];
1264 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1266 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1273 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1274 npx = segSDD->Npx();
1275 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1276 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1277 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1279 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1280 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1281 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1282 Bool_t isZeroSupp=cal->GetZeroSupp();
1284 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1286 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
1290 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1291 inputSDD->SetDDLModuleMap(ddlmap);
1292 while(inputSDD->Next()){
1293 if(inputSDD->IsCompletedModule()==kFALSE &&
1294 inputSDD->IsCompletedDDL()==kFALSE){
1296 Int_t module = inputSDD->GetModuleID();
1297 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1298 Int_t time = inputSDD->GetCoord2();
1299 Int_t signal10 = inputSDD->GetSignal();
1300 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1302 if (module >= size) continue;
1303 last = fModA[module]->GetEntries();
1304 TClonesArray& dum = *fModA[module];
1305 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1306 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1315 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1316 npx = segSSD->Npx();
1317 AliITSRawStreamSSD inputSSD(rawReader);
1319 Bool_t next = inputSSD.Next();
1322 Int_t module = inputSSD.GetModuleID();
1323 if(module<0)AliError(Form("Invalid SSD module %d \n",module));
1324 if(module<0)continue;
1325 Int_t side = inputSSD.GetSideFlag();
1326 Int_t strip = inputSSD.GetStrip();
1327 Int_t signal = inputSSD.GetSignal();
1328 Int_t index = npx * side + strip;
1330 if (module >= size) continue;
1332 last = fModA[module]->GetEntries();
1333 TClonesArray& dum = *fModA[module];
1334 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1337 AliITSpListItem* sdig = 0;
1339 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1340 Double_t adcToEv = 1.;
1341 for (Int_t mod = 0; mod < size; mod++)
1344 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1345 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1347 Int_t nsdig = fModA[mod]->GetEntries();
1348 for (Int_t ie = 0; ie < nsdig; ie++) {
1349 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
1350 Double_t digsig = sdig->GetSignal();
1351 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1352 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
1353 Float_t sig = sdig->GetSignalAfterElect();
1354 if(mod>=firstssd) sig*=adcToEv;
1356 sdig = (AliITSpListItem*)aSDigits[ie];
1357 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1363 fModA[mod]->Clear();
1365 loader->WriteSDigits("OVERWRITE");
1369 //______________________________________________________________________
1370 void AliITS::UpdateInternalGeometry(){
1371 //reads new geometry from TGeo
1372 // AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1374 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1376 AliITSInitGeometry initgeom;
1377 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1380 //______________________________________________________________________
1381 AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1382 // create an AliITSTrigger object (and set trigger conditions as input)
1383 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1385 //______________________________________________________________________
1386 void AliITS::WriteFOSignals(){
1387 // This method write FO signals in Digits tree both in Hits2Digits
1388 // or SDigits2Digits
1390 fDetTypeSim->ProcessNoiseForFastOr();
1391 fDetTypeSim->WriteFOSignals();