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 **************************************************************************/
16 /* $Id: AliITSUpg.cxx $ */
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 // AliITSUpg. 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 // AliITSUpg 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"
76 #include "AliITSUpg.h"
77 #include "AliITSDetTypeSim.h"
78 #include "AliITSDDLRawData.h"
79 #include "AliITSLoader.h"
80 #include "AliITSLoaderUpg.h"
81 #include "AliITShit.h"
82 #include "AliITSmodule.h"
83 #include "AliITSpListItem.h"
84 #include "AliITSsimulation.h"
85 #include "AliITSsimulationFastPoints.h"
87 #include "AliITSDigitizer.h"
88 #include "AliITSRecPoint.h"
89 #include "AliITSsegmentationSPD.h"
90 #include "AliITSsegmentationSDD.h"
91 #include "AliITSsimulationSDD.h"
92 #include "AliITSCalibrationSDD.h"
93 #include "AliITSCalibrationSSD.h"
94 #include "AliITSsegmentationSSD.h"
95 #include "AliITSRawStreamSPD.h"
96 #include "AliITSRawStreamSSD.h"
97 #include "AliITSRawStreamSDD.h"
98 #include "AliRawReader.h"
101 #include "AliITSInitGeometryUpg.h"
102 #include "AliITSFOSignalsSPD.h"
106 //______________________________________________________________________
107 AliITSUpg::AliITSUpg() : AliDetector(),
120 // Default initializer for ITS
121 // The default constructor of the AliITS class. In addition to
122 // creating the AliITS class it zeros the variables fIshunt (a member
123 // of AliDetector class), fEuclidOut, and fIdN, and zeros the pointers
124 // fIdSens, and fIdName. The AliDetector default constructor
127 // SetDetectors(); // default to fOpt="All". This variable not written out.
128 //PH SetMarkerColor(kRed);
130 //______________________________________________________________________
131 AliITSUpg::AliITSUpg(const Char_t *title):
132 AliDetector("ITS",title),
145 // The standard Constructor for the ITS class.
146 // It also zeros the variables
147 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
148 // the pointers fIdSens and fIdName. To help in displaying hits via the
149 // ROOT macro display.C AliITS also sets the marker color to red. The
150 // variables passes with this constructor, const char *name and *title,
151 // are used by the constructor of AliDetector class. See AliDetector
152 // class for a description of these parameters and its constructor
155 // Char_t *title Simulation title for the ITS
161 fHits = new TClonesArray("AliITShit",1560); // from AliDetector
162 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
163 //fNhits=0; //done in AliDetector(name,title)
164 SetDetectors(); // default to fOpt="All". This variable not written out.
165 fDetTypeSim = new AliITSDetTypeSim();
166 //PH SetMarkerColor(kRed);
167 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
168 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
170 //______________________________________________________________________
171 AliITSUpg::AliITSUpg(const char *name, const char *title):
172 AliDetector(name,title),
185 // The standard Constructor for the ITS class.
186 // It also zeros the variables
187 // fIshunt (a member of AliDetector class), fEuclidOut, and zeros
188 // the pointers fIdSens and fIdName. To help in displaying hits via the
189 // ROOT macro display.C AliITS also sets the marker color to red. The
190 // variables passes with this constructor, const char *name and *title,
191 // are used by the constructor of AliDetector class. See AliDetector
192 // class for a description of these parameters and its constructor
195 fHits = new TClonesArray("AliITShit",1560);
196 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
197 //fNhits=0; //done in AliDetector(name,title)
199 SetDetectors(); // default to fOpt="All". This variable not written out.
201 fDetTypeSim = new AliITSDetTypeSim();
202 //PH SetMarkerColor(kRed);
203 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
204 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
207 //______________________________________________________________________
208 AliITSUpg::~AliITSUpg(){
209 // Default destructor for ITS.
210 // The default destructor of the AliITS class. In addition to deleting
211 // the AliITS class it deletes the memory pointed to by
212 // fIdSens, fIdName, fDetTypeSim and it's contents.
226 this->ClearModules();
229 }// end if fITSmodules!=0
231 delete[] fIdName; // Array of TStrings
233 Int_t size = AliITSgeomTGeo::GetNModules();
244 for(Int_t j=0; j<size; j++){
257 //______________________________________________________________________
258 AliDigitizer* AliITSUpg::CreateDigitizer(AliRunDigitizer* manager)const{
259 // Creates the AliITSDigitizer in a standard way for use via AliModule.
260 // This function can not be included in the .h file because of problems
261 // with the order of inclusion (recursive).
263 // AliRunDigitizer *manager The Manger class for Digitization
267 // A new AliITSRunDigitizer (cast as a AliDigitizer).
269 return new AliITSDigitizer(manager);
271 //______________________________________________________________________
272 void AliITSUpg::Init(){
273 // Initializer ITS after it has been built
274 // This routine initializes the AliITS class. It is intended to be
275 // called from the Init function in AliITSv?. Besides displaying a banner
276 // indicating that it has been called it initializes the array fIdSens
277 // and sets the default segmentation, response, digit and raw cluster
278 // classes therefore it should be called after a call to CreateGeometry.
287 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
290 //______________________________________________________________________
291 void AliITSUpg::SetDefaults(){
292 // sets the default segmentation, response, digit and raw cluster classes.
299 AliInfoClass("AliITSUpg::Setting Defaults");
301 Error("SetDefaults()","fDetTypeSim is 0!");
305 fDetTypeSim->SetDefaults();
306 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
309 //______________________________________________________________________
310 void AliITSUpg::SetDefaultSimulation(){
311 // sets the default simulation.
319 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
323 fDetTypeSim->SetDefaultSimulation();
324 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
329 //______________________________________________________________________
330 void AliITSUpg::MakeBranch(Option_t* option){
331 // Creates Tree branches for the ITS.
333 // Option_t *option String of Tree types S,D, and/or R.
334 // const char *file String of the file name where these branches
335 // are to be stored. If blank then these branches
336 // are written to the same tree as the Hits were
343 Error("MakeBranch","fDetTypeSim is 0!");
347 Bool_t cH = (strstr(option,"H")!=0);
348 Bool_t cS = (strstr(option,"S")!=0);
349 Bool_t cD = (strstr(option,"D")!=0);
351 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
352 AliDetector::MakeBranch(option);
354 if(cS) MakeBranchS(0);
355 if(cD) MakeBranchD(0);
359 //___________________________________________________________________
360 void AliITSUpg::MakeBranchS(const char* fl){
362 // Creates Tree Branch for the ITS summable digits.
364 // cont char *fl File name where SDigits branch is to be written
365 // to. If blank it write the SDigits to the same
366 // file in which the Hits were found.
370 Error("MakeBranchS","fDetTypeSim is 0!");
372 Int_t buffersize = 4000;
375 // only one branch for SDigits.
376 snprintf(branchname,30,"%s",GetName());
378 if(fLoader->TreeS()){
379 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
380 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
383 //______________________________________________________________________
384 void AliITSUpg::MakeBranchD(const char* file){
386 //Make branch for digits
388 Warning("MakeBranchD","fDetTypeSim is 0!");
391 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
392 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
393 MakeBranchInTreeD(fLoader->TreeD(),file);
396 //___________________________________________________________________
397 void AliITSUpg:: MakeBranchInTreeD(TTree* treeD, const char* file){
398 // Creates Tree branches for the ITS.
401 Error("MakeBranchS","fDetTypeSim is 0!");
403 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
404 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
406 const Char_t *det[3] = {"SPD","SDD","SSD"};
407 const Char_t* digclass;
408 Int_t buffersize = 4000;
409 Char_t branchname[31];
411 if(!fDetTypeSim->GetDigits()){
412 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
414 for(Int_t i=0;i<fgkNTYPES;i++){
415 digclass = fDetTypeSim->GetDigitClassName(i);
416 TString classn = digclass;
417 if(!((fDetTypeSim->GetDigits())->At(i))){
418 (fDetTypeSim->GetDigits())->AddAt(new TClonesArray(classn.Data(),1000),i);
421 if(fgkNTYPES==3) snprintf(branchname,30,"%sDigits%s",GetName(),det[i]);
422 else sprintf(branchname,"%sDigits%d",GetName(),i+1);
423 TObjArray* dig = DigitsAddress(i);
424 if(GetDigits() && treeD) AliDetector::MakeBranchInTree(treeD,branchname, &dig,buffersize,file);
428 //______________________________________________________________________
429 void AliITSUpg::SetTreeAddress(){
430 // Set branch address for the Trees.
439 Error("SetTreeAddress","fDetTypeSim is 0!");
443 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
444 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
446 TTree *treeS = fLoader->TreeS();
447 TTree *treeD = fLoader->TreeD();
448 if (fLoader->TreeH() && (fHits == 0x0)) {
449 fHits = new TClonesArray("AliITShit", 1560);
451 AliDetector::SetTreeAddress();
453 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
454 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
456 //______________________________________________________________________
457 void AliITSUpg::AddHit(Int_t track, Int_t *vol, Float_t *hits){
459 // The function to add information to the AliITShit class. See the
460 // AliITShit class for a full description. This function allocates the
461 // necessary new space for the hit information and passes the variable
462 // track, and the pointers *vol and *hits to the AliITShit constructor
465 // Int_t track Track number which produced this hit.
466 // Int_t *vol Array of Integer Hit information. See AliITShit.h
467 // Float_t *hits Array of Floating Hit information. see AliITShit.h
472 TClonesArray &lhits = *fHits;
473 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
476 //______________________________________________________________________
477 void AliITSUpg::FillModules(Int_t /* evnt */,Int_t bgrev,Int_t /* nmodules */,
478 Option_t *option, const char *filename){
479 // fill the modules with the sorted by module hits; add hits from
480 // background if option=Add.
482 static TTree *trH1; //Tree with background hits
483 static Bool_t first=kTRUE;
485 const char *addBgr = strstr(option,"Add");
489 file=new TFile(filename);
494 // Get Hits Tree header from file
495 if(trH1) delete trH1;
499 snprintf(treeName,20,"TreeH%d",bgrev);
500 trH1 = (TTree*)gDirectory->Get(treeName);
502 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
504 // Set branch addresses
507 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
510 FillModules(trH1,10000000); // Default mask 10M.
511 TTree *fAli=fLoader->GetRunLoader()->TreeK();
514 fileAli =fAli->GetCurrentFile();
521 //______________________________________________________________________
522 void AliITSUpg::FillModules(TTree *treeH, Int_t mask) {
523 // fill the modules with the sorted by module hits;
524 // can be called many times to do a merging
526 // TTree *treeH The tree containing the hits to be copied into
528 // Int_t mask The track number mask to indecate which file
529 // this hits came from.
537 AliError("Tree H is NULL");
540 Int_t lay,lad,det,index;
544 snprintf(branchname,20,"%s",GetName());
545 TBranch *branch = treeH->GetBranch(branchname);
547 Error("FillModules","%s branch in TreeH not found",branchname);
550 branch->SetAddress(&fHits);
551 Int_t nTracks =(Int_t) treeH->GetEntries();
553 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
555 Int_t nBytes = treeH->GetEvent(iPrimTrack);
556 if (nBytes <= 0) continue;
557 Int_t nHits = fHits->GetEntriesFast();
558 for(h=0; h<nHits; h++){
559 itsHit = (AliITShit *)fHits->UncheckedAt(h);
560 itsHit->GetDetectorID(lay,lad,det);
562 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
564 index=det-1; // This should not be used.
565 } // end if [You must have fITSgeom for this to work!]
566 mod = GetModule(index);
567 itsHit->SetTrack(itsHit->GetTrack()+mask); // Set track mask.
568 mod->AddHit(itsHit,iPrimTrack,h);
569 } // end loop over hits
570 } // end loop over tracks
573 //______________________________________________________________________
574 Bool_t AliITSUpg::InitModules(Int_t size,Int_t &nmodules){
575 // Initialize the modules array.
577 // Int_t size Size of array of the number of modules to be
578 // created. If size <=0 then the number of modules
579 // is gotten from AliITSgeom class kept in fITSgeom.
581 // Int_t &nmodules The number of modules existing.
586 fITSmodules->Delete();
588 } // end fir fITSmoudles
591 Error("InitModules","fDetTypeSim is null!");
594 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
596 Int_t nl,indexMAX,index;
598 if(size<=0){ // default to using data stored in AliITSgeom
599 if(fDetTypeSim->GetITSgeom()==0) {
600 Error("InitModules","fITSgeom not defined");
602 } // end if fITSgeom==0
603 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
604 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
606 fITSmodules = new TObjArray(indexMAX);
607 for(index=0;index<indexMAX;index++){
608 fITSmodules->AddAt( new AliITSmodule(index),index);
611 fITSmodules = new TObjArray(size);
612 for(index=0;index<size;index++) {
613 fITSmodules->AddAt( new AliITSmodule(index),index);
620 //______________________________________________________________________
621 void AliITSUpg::Hits2SDigits(){
622 // Standard Hits to summable Digits function.
630 Error("Hits2SDigits","fDetTypeSim is null!");
635 fLoader->LoadHits("read");
636 fLoader->LoadSDigits("recreate");
637 AliRunLoader* rl = fLoader->GetRunLoader();
638 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
639 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
641 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
642 // Do the Hits to Digits operation. Use Standard input values.
643 // Event number from file, no background hit merging , use size from
644 // AliITSgeom class, option="All", input from this file only.
645 rl->GetEvent(iEvent);
646 if (!fLoader->TreeS()) fLoader->MakeTree("S");
649 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
652 fLoader->UnloadHits();
653 fLoader->UnloadSDigits();
656 //______________________________________________________________________
657 void AliITSUpg::Hits2Digits(){
659 //Conversion from hits to digits
661 Error("Hits2SDigits","fDetTypeSim is 0!");
665 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
666 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
669 fLoader->LoadHits("read");
670 fLoader->LoadDigits("recreate");
671 AliRunLoader* rl = fLoader->GetRunLoader();
672 for (Int_t iEvent = 0; iEvent < rl->GetNumberOfEvents(); iEvent++) {
673 rl->GetEvent(iEvent);
674 if (!fLoader->TreeD()) fLoader->MakeTree("D");
677 HitsToDigits(iEvent,0,-1," ",fOpt," ");
680 fLoader->UnloadHits();
681 fLoader->UnloadDigits();
685 //______________________________________________________________________
686 void AliITSUpg::HitsToDigits(Int_t evNumber,Int_t bgrev,Int_t size,
687 Option_t *option,Option_t *opt,
688 const char *filename){
689 // Keep galice.root for signal and name differently the file for
690 // background when add! otherwise the track info for signal will be lost !
691 // the condition below will disappear when the geom class will be
692 // initialized for all versions - for the moment it is only for v5 !
693 // 7 is the SDD beam test version.
695 // Int_t evnt Event to be processed.
696 // Int_t bgrev Background Hit tree number.
697 // Int_t nmodules Not used.
698 // Option_t *option String indicating if merging hits or not. To
699 // merge hits set equal to "Add". Otherwise no
700 // background hits are considered.
701 // Test_t *filename File name containing the background hits..
708 Error("HitsToDigits","fDetTypeSim is null!");
711 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
712 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
713 if(!GetITSgeom()) return; // need transformations to do digitization.
714 AliITSgeom *geom = GetITSgeom();
716 const char *all = strstr(opt,"All");
717 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
719 static Bool_t setDef=kTRUE;
720 if (setDef) SetDefaultSimulation();
724 InitModules(size,nmodules);
725 FillModules(evNumber,bgrev,nmodules,option,filename);
727 // Reset Fast-OR signals for this event
728 // fDetTypeSim->ResetFOSignals();
730 AliITSsimulation *sim = 0;
731 AliITSmodule *mod = 0;
733 for(Int_t module=0;module<geom->GetIndexMax();module++){
734 id = geom->GetModuleType(module);
735 if (!all && !det[id]) continue;
736 sim = (AliITSsimulation*)fDetTypeSim->GetSimulationModel(id);
738 Error("HitsToDigits","The simulation class was not "
739 "instanciated for module %d type %s!",module,
740 geom->GetModuleTypeName(module));
743 mod = (AliITSmodule *)fITSmodules->At(module);
744 sim->DigitiseModule(mod,module,evNumber);
745 // fills all branches - wasted disk space
746 fLoader->TreeD()->Fill();
752 // Add Fast-OR signals to event (only one object per event)
753 if (all || det[0]) { // SPD present
757 fLoader->TreeD()->GetEntries();
758 fLoader->TreeD()->AutoSave();
760 fLoader->TreeD()->Reset();
762 //_____________________________________________________________________
763 void AliITSUpg::Hits2PreDigits(){
764 // Turn hits into SDigits
767 Error("Hits2SDigits","fDetTypeSim is 0!");
771 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
772 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
775 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
779 //______________________________________________________________________
780 void AliITSUpg::HitsToPreDigits(Int_t evNumber,Int_t bgrev,Int_t size,
781 Option_t *option,Option_t *opt,
782 const char *filename){
783 // Keep galice.root for signal and name differently the file for
784 // background when add! otherwise the track info for signal will be lost !
785 // the condition below will disappear when the geom class will be
786 // initialized for all versions - for the moment it is only for v5 !
787 // 7 is the SDD beam test version.
789 // Int_t evnt Event to be processed.
790 // Int_t bgrev Background Hit tree number.
791 // Int_t nmodules Not used.
792 // Option_t *option String indicating if merging hits or not. To
793 // merge hits set equal to "Add". Otherwise no
794 // background hits are considered.
795 // Test_t *filename File name containing the background hits..
803 Error("HitsToPreDigits","fDetTypeSim is null!");
806 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
807 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
810 Error("HitsToPreDigits","fGeom is null!");
811 return; // need transformations to do digitization.
813 AliITSgeom *geom = GetITSgeom();
815 const char *all = strstr(opt,"All");
816 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
818 static Bool_t setDef=kTRUE;
819 if (setDef) SetDefaultSimulation();
823 InitModules(size,nmodules);
824 FillModules(evNumber,bgrev,nmodules,option,filename);
827 AliITSsimulation *sim = 0;
828 AliITSmodule *mod = 0;
830 for(module=0;module<geom->GetIndexMax();module++){
831 id = geom->GetModuleType(module);
832 if (!all && !det[id]) continue;
833 sim = (AliITSsimulation*)GetSimulationModel(id);
835 Error("HitsToPreDigits","The simulation class was not "
836 "instanciated for module %d type %s!",module,
837 geom->GetModuleTypeName(module));
840 mod = (AliITSmodule *)fITSmodules->At(module);
841 sim->SDigitiseModule(mod,module,evNumber);
842 // fills all branches - wasted disk space
843 fLoader->TreeS()->Fill();
844 fDetTypeSim->ResetSDigits();
850 fLoader->TreeS()->GetEntries();
851 fLoader->TreeS()->AutoSave();
852 fLoader->WriteSDigits("OVERWRITE");
854 fLoader->TreeS()->Reset();
857 //_____________________________________________________________________
858 void AliITSUpg::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
859 Option_t *opt0,Option_t *opt1,
861 // keep galice.root for signal and name differently the file for
862 // background when add! otherwise the track info for signal will be lost !
863 // the condition below will disappear when the geom class will be
864 // initialized for all versions - for the moment it is only for v5 !
866 // Int_t evnt Event to be processed.
867 // Int_t bgrev Background Hit tree number.
868 // Int_t size Size used by InitModules. See InitModules.
869 // Option_t *opt0 Option passed to FillModules. See FillModules.
870 // Option_t *opt1 String indicating if merging hits or not. To
871 // merge hits set equal to "Add". Otherwise no
872 // background hits are considered.
873 // Test_t *flnm File name containing the background hits..
882 Error("HitsToPreDigits","fGeom is null!");
883 return; // need transformations to do digitization.
885 AliITSgeom *geom = GetITSgeom();
887 AliITSLoaderUpg *pITSloader = (AliITSLoaderUpg*)fLoader;
889 const char *all = strstr(opt1,"All");
890 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
893 InitModules(size,nmodules);
894 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
896 AliITSsimulation *sim = 0;
897 AliITSmodule *mod = 0;
900 TTree *lTR = pITSloader->TreeR();
902 pITSloader->MakeTree("R");
903 lTR = pITSloader->TreeR();
906 TClonesArray* ptarray = new TClonesArray("AliITSRecPoint",1000);
907 TBranch* branch = (TBranch*)lTR->Branch("ITSRecPointsF",&ptarray);
908 branch->SetAddress(&ptarray);
909 //m.b. : this change is nothing but a nice way to make sure
911 for(module=0;module<geom->GetIndexMax();module++){
912 id = geom->GetModuleType(module);
913 if (!all && !det[id]) continue;
914 sim = (AliITSsimulation*)GetSimulationModel(id);
916 Error("HitsToFastPoints","The simulation class was not "
917 "instantiated for module %d type %s!",module,
918 geom->GetModuleTypeName(module));
921 mod = (AliITSmodule *)fITSmodules->At(module);
922 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
928 fLoader->WriteRecPoints("OVERWRITE");
931 //_____________________________________________________________________
932 Int_t AliITSUpg::Hits2Clusters(TTree *hTree, TTree *cTree) {
933 //------------------------------------------------------------
934 // This function creates ITS clusters
935 //------------------------------------------------------------
937 Error("HitsToPreDigits","fGeom is null!");
938 return 1; // need transformations to do digitization.
940 AliITSgeom *geom=GetITSgeom();
941 Int_t mmax=geom->GetIndexMax();
943 InitModules(-1,mmax);
944 FillModules(hTree,0);
946 TClonesArray *points = new TClonesArray("AliITSRecPoint",1000);
947 TBranch *branch=cTree->GetBranch("ITSRecPoints");
948 if (!branch) cTree->Branch("ITSRecPoints",&points);
949 else branch->SetAddress(&points);
951 AliITSsimulationFastPoints sim;
953 for (Int_t m=0; m<mmax; m++) {
954 AliITSmodule *mod=GetModule(m);
955 sim.CreateFastRecPoints(mod,m,gRandom,points);
956 ncl+=points->GetEntriesFast();
961 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
969 //_____________________________________________________________________
970 void AliITSUpg::CheckLabels(Int_t lab[3]) const {
971 //------------------------------------------------------------
972 // Tries to find mother's labels
973 //------------------------------------------------------------
975 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
977 Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
978 for (Int_t i=0;i<3;i++){
979 Int_t label = lab[i];
980 if (label>=0 && label<ntracks) {
981 TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
982 if (part->P() < 0.005) {
983 Int_t m=part->GetFirstMother();
987 if (part->GetStatusCode()>0) {
997 //______________________________________________________________________
998 void AliITSUpg::SDigitsToDigits(Option_t *opt){
999 // Standard Summable digits to Digits function.
1005 AliError("fDetTypeSim is 0!");
1008 const char *all = strstr(opt,"All");
1009 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1012 // Reset Fast-OR signals for this event
1013 // fDetTypeSim->ResetFOSignals();
1015 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1017 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1018 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1020 // Add Fast-OR signals to event (only one object per event)
1021 if (all || det[0]) { // SPD present
1026 //______________________________________________________________________
1027 void AliITSUpg::ResetDigits(){
1028 // Reset number of digits and the digits array for the ITS detector.
1034 Error("ResetDigits","fDetTypeSim is 0!");
1038 fDetTypeSim->ResetDigits();
1042 //______________________________________________________________________
1043 void AliITSUpg::ResetDigits(Int_t branch){
1044 // Reset number of digits and the digits array for this branch.
1051 Error("ResetDigits","fDetTypeSim is 0!");
1055 fDetTypeSim->ResetDigits(branch);
1058 //______________________________________________________________________
1059 void AliITSUpg::AddSumDigit(AliITSpListItem &sdig){
1060 // Adds the a module full of summable digits to the summable digits tree.
1062 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1069 Error("AddSumDigit","fDetTypeSim is 0!");
1072 fDetTypeSim->AddSumDigit(sdig);
1075 //______________________________________________________________________
1076 void AliITSUpg::AddSimDigit(Int_t branch, AliITSdigit *d){
1077 // Add a simulated digit.
1079 // Int_t id Detector type number.
1080 // AliITSdigit *d Digit to be added to the Digits Tree. See
1088 Error("AddSimDigit","fDetTypeSim is 0!");
1091 fDetTypeSim->AddSimDigit(branch,d);
1094 //______________________________________________________________________
1095 void AliITSUpg::AddSimDigit(Int_t branch,Float_t phys,Int_t *digits,Int_t *tracks,
1096 Int_t *hits,Float_t *charges, Int_t sigexpanded){
1097 // Add a simulated digit to the list.
1099 // Int_t id Detector type number.
1100 // Float_t phys Physics indicator. See AliITSdigits.h
1101 // Int_t *digits Integer array containing the digits info. See
1103 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1104 // containing the track numbers that contributed to
1106 // Int_t *hits Integer array [AliITSdigitS?D::GetNTracks()]
1107 // containing the hit numbers, from AliITSmodule, that
1108 // contributed to this digit.
1109 // Float_t *charge Floating point array of the signals contributed
1110 // to this digit by each track.
1117 Error("AddSimDigit","fDetTypeSim is 0!");
1120 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1123 //______________________________________________________________________
1124 void AliITSUpg::Digits2Raw(){
1125 // convert digits of the current event to raw data
1128 Error("Digits2Raw","fDetTypeSim is 0!");
1131 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1133 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1134 fDetTypeSim->GetLoader()->LoadDigits();
1135 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1137 Error("Digits2Raw", "no digits tree");
1140 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1142 // Get the FO signals for this event
1143 AliITSFOSignalsSPD* foSignals = NULL;
1144 AliRunLoader* runLoader = AliRunLoader::Instance();
1145 AliITSLoaderUpg* itsLoader = (AliITSLoaderUpg*) runLoader->GetLoader("ITSLoader");
1147 AliError("ITS loader is NULL.");
1150 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1151 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1152 if(!foSignals) AliError("FO signals not retrieved");
1155 Bool_t deleteFOsignalsLater = kFALSE;
1157 AliError("FO signals not available. No FO bits will be written.");
1158 foSignals = new AliITSFOSignalsSPD(); // make a temporary dummy signals object
1159 deleteFOsignalsLater = kTRUE;
1163 // AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1164 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1165 AliITSDDLRawData rawWriter;
1167 rawWriter.SetSDDRawFormat(rawSDD);
1171 // 2: txt files with digits
1172 //BE CAREFUL, verbose level 2 MUST be used only for debugging and
1173 //it is highly suggested to use this mode only for debugging digits files
1174 //reasonably small, because otherwise the size of the txt files can reach
1175 //quickly several MB wasting time and disk space.
1176 rawWriter.SetVerbose(0);
1178 //SILICON PIXEL DETECTOR
1179 AliDebug(1,"Formatting raw data for SPD");
1180 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1181 if(deleteFOsignalsLater) delete foSignals;
1183 //SILICON DRIFT DETECTOR
1184 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1185 // rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1187 //SILICON STRIP DETECTOR
1188 AliDebug(1,"Formatting raw data for SSD");
1189 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1191 fLoader->UnloadDigits();
1193 //______________________________________________________________________
1194 AliLoader* AliITSUpg::MakeLoader(const char* topfoldername){
1195 //builds ITSgetter (AliLoader type)
1196 //if detector wants to use castomized getter, it must overload this method
1198 AliDebug(1,Form("Creating AliITSLoaderUpg. Top folder is %s.",
1200 fLoader = new AliITSLoaderUpg(GetName(),topfoldername);
1203 //______________________________________________________________________
1204 Bool_t AliITSUpg::Raw2SDigits(AliRawReader* rawReader)
1207 // Converts RAW data to SDigits
1212 Int_t size = AliITSgeomTGeo::GetNModules();
1214 fModA = new TClonesArray*[size];
1215 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1217 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1219 Error("Open","Can not get ITS loader from Run Loader");
1224 tree = loader->TreeS();
1226 loader->MakeTree("S");
1227 tree = loader->TreeS();
1230 // Array for SDigits
1233 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1235 TClonesArray& aSDigits = *fpSDigits;
1236 Int_t bufsize = 32000;
1237 tree->Branch("ITS", &fpSDigits, bufsize);
1242 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1244 AliWarning("Set AliITS defaults");
1246 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1248 npx = segSPD->Npx();
1249 Double_t thr, sigma;
1251 AliITSRawStreamSPD inputSPD(rawReader);
1253 Bool_t next = inputSPD.Next();
1256 Int_t module = inputSPD.GetModuleID();
1257 Int_t column = inputSPD.GetColumn();
1258 Int_t row = inputSPD.GetRow();
1259 Int_t index = npx * column + row;
1261 if (module >= size) continue;
1263 last = (fModA[module])->GetEntries();
1264 TClonesArray& dum = *fModA[module];
1265 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1267 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1274 AliITSsegmentationSDD* segSDD = (AliITSsegmentationSDD*) fDetTypeSim->GetSegmentationModel(1);
1275 npx = segSDD->Npx();
1276 Int_t scalef=AliITSsimulationSDD::ScaleFourier(segSDD);
1277 Int_t firstSDD=AliITSgeomTGeo::GetModuleIndex(3,1,1);
1278 Int_t firstSSD=AliITSgeomTGeo::GetModuleIndex(5,1,1);
1280 AliITSRawStream* inputSDD=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader);
1281 for(Int_t iMod=firstSDD; iMod<firstSSD; iMod++){
1282 AliITSCalibrationSDD* cal = (AliITSCalibrationSDD*)fDetTypeSim->GetCalibrationModel(iMod);
1283 Bool_t isZeroSupp=cal->GetZeroSupp();
1285 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1287 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
1291 // AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1292 // inputSDD->SetDDLModuleMap(ddlmap);
1293 while(inputSDD->Next()){
1294 if(inputSDD->IsCompletedModule()==kFALSE &&
1295 inputSDD->IsCompletedDDL()==kFALSE){
1297 Int_t module = inputSDD->GetModuleID();
1298 Int_t anode = inputSDD->GetCoord1()+segSDD->NpzHalf()*inputSDD->GetChannel();
1299 Int_t time = inputSDD->GetCoord2();
1300 Int_t signal10 = inputSDD->GetSignal();
1301 Int_t index = AliITSpList::GetIndex(anode,time,scalef*npx);
1303 if (module >= size) continue;
1304 last = fModA[module]->GetEntries();
1305 TClonesArray& dum = *fModA[module];
1306 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal10));
1307 ((AliITSpListItem*) dum.At(last))->AddSignalAfterElect(module, index, Double_t(signal10));
1316 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1317 npx = segSSD->Npx();
1318 AliITSRawStreamSSD inputSSD(rawReader);
1320 Bool_t next = inputSSD.Next();
1323 Int_t module = inputSSD.GetModuleID();
1324 if(module<0)AliError(Form("Invalid SSD module %d \n",module));
1325 if(module<0)continue;
1326 Int_t side = inputSSD.GetSideFlag();
1327 Int_t strip = inputSSD.GetStrip();
1328 Int_t signal = inputSSD.GetSignal();
1329 Int_t index = npx * side + strip;
1331 if (module >= size) continue;
1333 last = fModA[module]->GetEntries();
1334 TClonesArray& dum = *fModA[module];
1335 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1338 AliITSpListItem* sdig = 0;
1340 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1341 Double_t adcToEv = 1.;
1342 for (Int_t mod = 0; mod < size; mod++)
1345 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1346 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1348 Int_t nsdig = fModA[mod]->GetEntries();
1349 for (Int_t ie = 0; ie < nsdig; ie++) {
1350 sdig = (AliITSpListItem*) (fModA[mod]->At(ie));
1351 Double_t digsig = sdig->GetSignal();
1352 if(mod>=firstssd) digsig*=adcToEv; // for SSD: convert back charge from ADC to electron
1353 new (aSDigits[ie]) AliITSpListItem(-1, -1, mod, sdig->GetIndex(), digsig);
1354 Float_t sig = sdig->GetSignalAfterElect();
1355 if(mod>=firstssd) sig*=adcToEv;
1357 sdig = (AliITSpListItem*)aSDigits[ie];
1358 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1364 fModA[mod]->Clear();
1366 loader->WriteSDigits("OVERWRITE");
1370 //______________________________________________________________________
1371 void AliITSUpg::UpdateInternalGeometry(){
1372 //reads new geometry from TGeo
1373 // AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1375 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1377 AliITSInitGeometryUpg initgeom;
1378 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1381 //______________________________________________________________________
1382 AliTriggerDetector* AliITSUpg::CreateTriggerDetector() const {
1383 // create an AliITSTrigger object (and set trigger conditions as input)
1384 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1386 //______________________________________________________________________
1387 void AliITSUpg::WriteFOSignals(){
1388 // This method write FO signals in Digits tree both in Hits2Digits
1389 // or SDigits2Digits
1391 // fDetTypeSim->ProcessNoiseForFastOr();
1392 fDetTypeSim->WriteFOSignals();