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 random noise to FO signals
752 if (all || det[0]) { // SPD present
753 fDetTypeSim->ProcessNoiseForFastOr();
756 // Add Fast-OR signals to event (only one object per event)
757 if (all || det[0]) { // SPD present
758 fDetTypeSim->WriteFOSignals();
762 fLoader->TreeD()->GetEntries();
763 fLoader->TreeD()->AutoSave();
765 fLoader->TreeD()->Reset();
767 //_____________________________________________________________________
768 void AliITS::Hits2PreDigits(){
769 // Turn hits into SDigits
772 Error("Hits2SDigits","fDetTypeSim is 0!");
776 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
777 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
780 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
784 //______________________________________________________________________
785 void AliITS::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
786 Option_t *option,Option_t *opt,
787 const char *filename){
788 // Keep galice.root for signal and name differently the file for
789 // background when add! otherwise the track info for signal will be lost !
790 // the condition below will disappear when the geom class will be
791 // initialized for all versions - for the moment it is only for v5 !
792 // 7 is the SDD beam test version.
794 // Int_t evnt Event to be processed.
795 // Int_t bgrev Background Hit tree number.
796 // Int_t nmodules Not used.
797 // Option_t *option String indicating if merging hits or not. To
798 // merge hits set equal to "Add". Otherwise no
799 // background hits are considered.
800 // Test_t *filename File name containing the background hits..
808 Error("HitsToPreDigits","fDetTypeSim is null!");
811 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
812 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
815 Error("HitsToPreDigits","fGeom is null!");
816 return; // need transformations to do digitization.
818 AliITSgeom *geom = GetITSgeom();
820 const char *all = strstr(opt,"All");
821 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
823 static Bool_t setDef=kTRUE;
824 if (setDef) SetDefaultSimulation();
828 InitModules(size,nmodules);
829 FillModules(evNumber,bgrev,nmodules,option,filename);
832 AliITSsimulation *sim = 0;
833 AliITSmodule *mod = 0;
835 for(module=0;module<geom->GetIndexMax();module++){
836 id = geom->GetModuleType(module);
837 if (!all && !det[id]) continue;
838 sim = (AliITSsimulation*)GetSimulationModel(id);
840 Error("HitsToPreDigits","The simulation class was not "
841 "instanciated for module %d type %s!",module,
842 geom->GetModuleTypeName(module));
845 mod = (AliITSmodule *)fITSmodules->At(module);
846 sim->SDigitiseModule(mod,module,evNumber);
847 // fills all branches - wasted disk space
848 fLoader->TreeS()->Fill();
849 fDetTypeSim->ResetSDigits();
855 fLoader->TreeS()->GetEntries();
856 fLoader->TreeS()->AutoSave();
857 fLoader->WriteSDigits("OVERWRITE");
859 fLoader->TreeS()->Reset();
862 //_____________________________________________________________________
863 void AliITS::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
864 Option_t *opt0,Option_t *opt1,
866 // keep galice.root for signal and name differently the file for
867 // background when add! otherwise the track info for signal will be lost !
868 // the condition below will disappear when the geom class will be
869 // initialized for all versions - for the moment it is only for v5 !
871 // Int_t evnt Event to be processed.
872 // Int_t bgrev Background Hit tree number.
873 // Int_t size Size used by InitModules. See InitModules.
874 // Option_t *opt0 Option passed to FillModules. See FillModules.
875 // Option_t *opt1 String indicating if merging hits or not. To
876 // merge hits set equal to "Add". Otherwise no
877 // background hits are considered.
878 // Test_t *flnm File name containing the background hits..
887 Error("HitsToPreDigits","fGeom is null!");
888 return; // need transformations to do digitization.
890 AliITSgeom *geom = GetITSgeom();
892 AliITSLoader *pITSloader = (AliITSLoader*)fLoader;
894 const char *all = strstr(opt1,"All");
895 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
898 InitModules(size,nmodules);
899 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
901 AliITSsimulation *sim = 0;
902 AliITSmodule *mod = 0;
905 TTree *lTR = pITSloader->TreeR();
907 pITSloader->MakeTree("R");
908 lTR = pITSloader->TreeR();
911 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
912 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
913 branch->SetAddress(&ptarray);
914 //m.b. : this change is nothing but a nice way to make sure
916 for(module=0;module<geom->GetIndexMax();module++){
917 id = geom->GetModuleType(module);
918 if (!all && !det[id]) continue;
919 sim = (AliITSsimulation*)GetSimulationModel(id);
921 Error("HitsToFastPoints","The simulation class was not "
922 "instantiated for module %d type %s!",module,
923 geom->GetModuleTypeName(module));
926 mod = (AliITSmodule *)fITSmodules->At(module);
927 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
933 fLoader->WriteRecPoints("OVERWRITE");
936 //_____________________________________________________________________
937 Int_t AliITS::Hits2Clusters(TTree *hTree, TTree *cTree) {
938 //------------------------------------------------------------
939 // This function creates ITS clusters
940 //------------------------------------------------------------
942 Error("HitsToPreDigits","fGeom is null!");
943 return 1; // need transformations to do digitization.
945 AliITSgeom *geom=GetITSgeom();
946 Int_t mmax=geom->GetIndexMax();
948 InitModules(-1,mmax);
949 FillModules(hTree,0);
951 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
952 TBranch *branch=cTree->GetBranch("ITSRecPoints");
953 if (!branch) cTree->Branch("ITSRecPoints",&points);
954 else branch->SetAddress(&points);
956 AliITSsimulationFastPoints sim;
958 for (Int_t m=0; m<mmax; m++) {
959 AliITSmodule *mod=GetModule(m);
960 sim.CreateFastRecPoints(mod,m,gRandom,points);
961 ncl+=points->GetEntriesFast();
966 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
974 //_____________________________________________________________________
975 void AliITS::CheckLabels(Int_t lab[3]) const {
976 //------------------------------------------------------------
977 // Tries to find mother's labels
978 //------------------------------------------------------------
980 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
982 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
983 for (Int_t i=0;i<3;i++){
984 Int_t label = lab[i];
985 if (label>=0 && label<ntracks) {
986 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
987 if (part->P() < 0.005) {
988 Int_t m=part->GetFirstMother();
992 if (part->GetStatusCode()>0) {
1002 //______________________________________________________________________
1003 void AliITS::SDigitsToDigits(Option_t *opt){
1004 // Standard Summable digits to Digits function.
1010 AliError("fDetTypeSim is 0!");
1014 const char *all = strstr(opt,"All");
1015 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1018 // Reset Fast-OR signals for this event
1019 fDetTypeSim->ResetFOSignals();
1021 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1023 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1024 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1026 // Add random noise to FO signals
1027 if (all || det[0]) { // SPD present
1028 fDetTypeSim->ProcessNoiseForFastOr();
1030 // Add Fast-OR signals to event (only one object per event)
1031 if (all || det[0]) { // SPD present
1032 fDetTypeSim->WriteFOSignals();
1036 //______________________________________________________________________
1037 void AliITS::ResetDigits(){
1038 // Reset number of digits and the digits array for the ITS detector.
1044 Error("ResetDigits","fDetTypeSim is 0!");
1048 fDetTypeSim->ResetDigits();
1052 //______________________________________________________________________
1053 void AliITS::ResetDigits(Int_t branch){
1054 // Reset number of digits and the digits array for this branch.
1061 Error("ResetDigits","fDetTypeSim is 0!");
1065 fDetTypeSim->ResetDigits(branch);
1068 //______________________________________________________________________
1069 void AliITS::AddSumDigit(AliITSpListItem &sdig){
1070 // Adds the a module full of summable digits to the summable digits tree.
1072 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1079 Error("AddSumDigit","fDetTypeSim is 0!");
1082 fDetTypeSim->AddSumDigit(sdig);
1085 //______________________________________________________________________
1086 void AliITS::AddSimDigit(Int_t branch, AliITSdigit *d){
1087 // Add a simulated digit.
1089 // Int_t id Detector type number.
1090 // AliITSdigit *d Digit to be added to the Digits Tree. See
1098 Error("AddSimDigit","fDetTypeSim is 0!");
1101 fDetTypeSim->AddSimDigit(branch,d);
1104 //______________________________________________________________________
1105 void AliITS::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1106 Int_t *hits,Float_t *charges, Int_t sigexpanded){
1107 // Add a simulated digit to the list.
1109 // Int_t id Detector type number.
1110 // Float_t phys Physics indicator. See AliITSdigits.h
1111 // Int_t *digits Integer array containing the digits info. See
1113 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1114 // containing the track numbers that contributed to
1116 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1117 // containing the hit numbers, from AliITSmodule, that
1118 // contributed to this digit.
1119 // Float_t *charge Floating point array of the signals contributed
1120 // to this digit by each track.
1127 Error("AddSimDigit","fDetTypeSim is 0!");
1130 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1133 //______________________________________________________________________
1134 void AliITS::Digits2Raw(){
1135 // convert digits of the current event to raw data
1138 Error("Digits2Raw","fDetTypeSim is 0!");
1141 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1143 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1144 fDetTypeSim->GetLoader()->LoadDigits();
1145 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1147 Error("Digits2Raw", "no digits tree");
1150 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1152 // Get the FO signals for this event
1153 AliITSFOSignalsSPD* foSignals = NULL;
1154 AliRunLoader* runLoader = AliRunLoader::Instance();
1155 AliITSLoader* itsLoader = (AliITSLoader*) runLoader->GetLoader("ITSLoader");
1157 AliError("ITS loader is NULL.");
1160 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1161 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1162 if(!foSignals) AliError("FO signals not retrieved");
1165 Bool_t deleteFOsignalsLater = kFALSE;
1167 AliError("FO signals not available. No FO bits will be written.");
1168 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1169 deleteFOsignalsLater = kTRUE;
1173 AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1174 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1175 AliITSDDLRawData rawWriter;
1177 rawWriter.SetSDDRawFormat(rawSDD);
1181 // 2: txt files with digits
1182 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1183 //it is highly suggested to use this mode only for debugging digits files
1184 //reasonably small, because otherwise the size of the txt files can reach
1185 //quickly several MB wasting time and disk space.
1186 rawWriter.SetVerbose(0);
1188 //SILICON PIXEL DETECTOR
1189 AliDebug(1,"Formatting raw data for SPD");
1190 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1191 if(deleteFOsignalsLater) delete foSignals;
1193 //SILICON DRIFT DETECTOR
1194 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1195 rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1197 //SILICON STRIP DETECTOR
1198 AliDebug(1,"Formatting raw data for SSD");
1199 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1201 fLoader->UnloadDigits();
1203 //______________________________________________________________________
1204 AliLoader* AliITS::MakeLoader(const char* topfoldername){
1205 //builds ITSgetter (AliLoader type)
1206 //if detector wants to use castomized getter, it must overload this method
1208 AliDebug(1,Form("Creating AliITSLoader. Top folder is %s.",
1210 fLoader = new AliITSLoader(GetName(),topfoldername);
1213 //______________________________________________________________________
1214 Bool_t AliITS::Raw2SDigits(AliRawReader* rawReader)
1217 // Converts RAW data to SDigits
1222 Int_t size = AliITSgeomTGeo::GetNModules();
1224 fModA = new TClonesArray*[size];
1225 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1227 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1229 Error("Open","Can not get ITS loader from Run Loader");
1234 tree = loader->TreeS();
1236 loader->MakeTree("S");
1237 tree = loader->TreeS();
1240 // Array for SDigits
1243 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1245 TClonesArray& aSDigits = *fpSDigits;
1246 Int_t bufsize = 32000;
1247 tree->Branch("ITS", &fpSDigits, bufsize);
1252 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1254 AliWarning("Set AliITS defaults");
1256 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1258 npx = segSPD->Npx();
1259 Double_t thr, sigma;
1261 AliITSRawStreamSPD inputSPD(rawReader);
1263 Bool_t next = inputSPD.Next();
1266 Int_t module = inputSPD.GetModuleID();
1267 Int_t column = inputSPD.GetColumn();
1268 Int_t row = inputSPD.GetRow();
1269 Int_t index = npx * column + row;
1271 if (module >= size) continue;
1273 last = (fModA[module])->GetEntries();
1274 TClonesArray& dum = *fModA[module];
1275 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1277 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1284 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1285 npx = segSDD->Npx();
1286 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1287 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1288 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1290 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1291 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1292 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1293 Bool_t isZeroSupp=cal->GetZeroSupp();
1295 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1297 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
1301 AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1302 inputSDD->SetDDLModuleMap(ddlmap);
1303 while(inputSDD->Next()){
1304 if(inputSDD->IsCompletedModule()==kFALSE &&
1305 inputSDD->IsCompletedDDL()==kFALSE){
1307 Int_t module = inputSDD->GetModuleID();
1308 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1309 Int_t time = inputSDD->GetCoord2();
1310 Int_t signal10 = inputSDD->GetSignal();
1311 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1313 if (module >= size) continue;
1314 last = fModA[module]->GetEntries();
1315 TClonesArray& dum = *fModA[module];
1316 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1317 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1326 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1327 npx = segSSD->Npx();
1328 AliITSRawStreamSSD inputSSD(rawReader);
1330 Bool_t next = inputSSD.Next();
1333 Int_t module = inputSSD.GetModuleID();
1334 if(module<0)AliError(Form("Invalid SSD module %d \n",module));
1335 if(module<0)continue;
1336 Int_t side = inputSSD.GetSideFlag();
1337 Int_t strip = inputSSD.GetStrip();
1338 Int_t signal = inputSSD.GetSignal();
1339 Int_t index = npx * side + strip;
1341 if (module >= size) continue;
1343 last = fModA[module]->GetEntries();
1344 TClonesArray& dum = *fModA[module];
1345 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1348 AliITSpListItem* sdig = 0;
1350 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1351 Double_t adcToEv = 1.;
1352 for (Int_t mod = 0; mod < size; mod++)
1355 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1356 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1358 Int_t nsdig = fModA[mod]->GetEntries();
1359 for (Int_t ie = 0; ie < nsdig; ie++) {
1360 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
1361 Double_t digsig = sdig->GetSignal();
1362 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1363 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
1364 Float_t sig = sdig->GetSignalAfterElect();
1365 if(mod>=firstssd) sig*=adcToEv;
1367 sdig = (AliITSpListItem*)aSDigits[ie];
1368 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1374 fModA[mod]->Clear();
1376 loader->WriteSDigits("OVERWRITE");
1380 //______________________________________________________________________
1381 void AliITS::UpdateInternalGeometry(){
1382 //reads new geometry from TGeo
1383 // AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1385 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1387 AliITSInitGeometry initgeom;
1388 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1391 //______________________________________________________________________
1392 AliTriggerDetector* AliITS::CreateTriggerDetector() const {
1393 // create an AliITSTrigger object (and set trigger conditions as input)
1394 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());