1 /**************************************************************************
2 * Copyright(c) 1998-2000, 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 **************************************************************************/
20 #include <AliRunLoader.h>
21 #include "AliRunDigitizer.h"
22 #include <AliLoader.h>
24 #include "AliITSupgradeDigitizer.h"
25 #include "AliITSDigitUpgrade.h"
26 #include "AliITSupgrade.h"
27 #include "AliITSsegmentationUpgrade.h"
28 #include <TObjArray.h>
29 #include <TClonesArray.h>
31 extern TRandom *gRandom;
33 ClassImp(AliITSupgradeDigitizer)
35 void AliITSupgradeDigitizer::SetConfiguration(TArrayD xcell, TArrayD zcell)
38 if(xcell.GetSize()!=zcell.GetSize()) AliError(" !! The # of X cells and Z cells differ !!");
40 fNlayers = xcell.GetSize();
43 AliError("* Only 9 layers can be be filled ...Exiting!!! *");
47 fNxCells.Set(fNlayers);
48 fNzCells.Set(fNlayers);
49 for(Int_t i=0; i<fNlayers; i++){
50 fNxCells.AddAt(xcell.At(i),i);
51 fNzCells.AddAt(zcell.At(i),i);
54 //______________________________________________________________________________
55 void AliITSupgradeDigitizer::Exec(Option_t*)
57 // This method is responsible for merging sdigits to a list of digits
58 // Disintegration leeds to the fact that one hit affects several neighbouring pads,
59 // which means that the same pad might be affected by few hits.
61 AliDebug(1,Form("Start with %i input(s) for event %i",fManager->GetNinputs(),fManager->GetOutputEventNr()));
64 AliITSsegmentationUpgrade *s = new AliITSsegmentationUpgrade();
65 SetConfiguration(s->GetFullCellSizeX(),s->GetFullCellSizeZ());
67 //First we read all sdigits from all inputs
68 AliRunLoader *pInRunLoader=0;//in and out Run loaders
69 AliLoader *pITSLoader=0;//in and out ITS loaders
71 TClonesArray sdigits[10];
72 for(Int_t i=0; i<fNlayers; i++) sdigits[i].SetClass("AliITSDigitUpgrade");//tmp storage for sdigits sum up from all input files
75 Int_t total[10]={0,0,0,0,0,0,0,0,0,0};
76 for(Int_t inFileN=0;inFileN<fManager->GetNinputs();inFileN++){//files loop
78 pInRunLoader = AliRunLoader::GetRunLoader(fManager->GetInputFolderName(inFileN)); //get run loader from current input
79 pITSLoader = pInRunLoader->GetLoader("ITSLoader");
81 continue; //no ITS in this input, check the next input
82 AliDebug(1,"no ITS lodader, checking in the other input \n");
85 if (!pInRunLoader->GetAliRun()) pInRunLoader->LoadgAlice();
86 AliITSupgrade* pITS=(AliITSupgrade*)pInRunLoader->GetAliRun()->GetDetector("ITS");
88 pITSLoader->LoadSDigits();
90 pITSLoader->TreeS()->GetEntry(0); //take list of ITS sdigits from current input
92 for(Int_t is=0;is<pITS->SDigitsList()->GetEntries();is++){
94 //collect sdigits from current input
95 for(Int_t ientr =0; ientr < ((TClonesArray*)pITS->SDigitsList()->At(is))->GetEntries(); ientr++){
96 AliITSDigitUpgrade *pSDig=(AliITSDigitUpgrade*)((TClonesArray*)pITS->SDigitsList()->At(is))->At(ientr);
97 pSDig->AddTidOffset(fManager->GetMask(inFileN)); // -> To be introduced for merging (apply TID shift since all inputs count tracks independently starting from 0)
98 new((sdigits[is])[total[is]++]) AliITSDigitUpgrade(*pSDig);
102 pITSLoader->UnloadSDigits();
103 pITS->SDigitsReset(); //close current input and reset
106 AliRunLoader *pOutRunLoader = AliRunLoader::GetRunLoader(fManager->GetOutputFolderName()); //open output stream (only 1 possible)
107 AliLoader *pOutITSLoader = pOutRunLoader->GetLoader("ITSLoader");
108 AliRun *pArun = pOutRunLoader->GetAliRun();
109 AliITSupgrade *pOutITS = (AliITSupgrade*)pArun->GetDetector("ITS");
110 pOutITSLoader->MakeTree("D"); pOutITS->MakeBranch("D"); //create TreeD in output stream
111 pOutITS->SetTreeAddress();
113 Sdigits2Digits(sdigits,pOutITS->DigitsList());
115 pOutITSLoader->TreeD()->Fill(); //fill the output tree with the list of digits
116 pOutITSLoader->WriteDigits("OVERWRITE"); //serialize them to file
118 for(Int_t i=0; i< fNlayers; i++) sdigits[i].Clear(); //remove all tmp sdigits
119 pOutITSLoader->UnloadDigits();
120 pOutITS->DigitsReset();
122 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123 void AliITSupgradeDigitizer::Sdigits2Digits(TClonesArray *pSDigitList,TObjArray *pDigitList)
125 TClonesArray *pLst[100]; Int_t iCnt[100];
127 for(Int_t i=0;i<fNlayers;i++){
128 pLst[i]=(TClonesArray*)(*pDigitList)[i];
129 iCnt[i]=0; if(pLst[i]->GetEntries()!=0) AliErrorClass("Some of digits lists is not empty"); //in principle those lists should be empty
132 //AliInfo("starting loop over gli sdigits to create the digits");
136 Int_t tids[3]={-1,-1,-1};
138 Float_t elossID[3]={-1.,-1.,-1.};
139 //AliInfo("starting layers");
140 AliDebug(1,"starting loop over layers");
142 for(Int_t ilay=0;ilay<fNlayers;ilay++){
144 AliITSDigitUpgrade *tmpdig=0x0;
145 pSDigitList[ilay].Sort();
148 AliDebug(1,"starting loop over sdigits to create digits");
149 for(Int_t isdigentr=0; isdigentr<pSDigitList[ilay].GetEntries(); isdigentr++){
150 tmpdig = (AliITSDigitUpgrade*)(pSDigitList[ilay].At(isdigentr) ) ;
151 if(tmpdig->GetPixId()==pixid && tmpdig->GetModule()==module) {
154 tids[iNdigPart-1] = tmpdig->GetTrack(0);
155 elossID[iNdigPart-1] = tmpdig->GetSignal();
157 eloss+=tmpdig->GetSignal();
158 nele+=tmpdig->GetNelectrons();
161 AliITSDigitUpgrade digit(pixid,eloss);
163 digit.SetNelectrons(nele);
164 digit.SetLayer(ilay);
165 digit.SetModule(module);
167 digit.SetSignalID(elossID);
168 if(isdigentr!=0) new((*pLst[ilay])[iCnt[ilay]++]) AliITSDigitUpgrade(digit);
169 eloss = tmpdig->GetSignal();
170 nele = tmpdig->GetNelectrons();
171 pixid=tmpdig->GetPixId();
172 tids[0]=tmpdig->GetTrack(0);
174 elossID[0]=tmpdig->GetSignal();
175 elossID[1]=elossID[2]=-1;
176 module=tmpdig->GetModule();
179 if(!tmpdig) AliDebug(1,"\n \n---------> tmpdig is null...break is expected ! \n");
180 else AliDebug(1," tmpdig exists \n");
183 tmpdig->SetSignal(eloss);
184 tmpdig->SetPixId(pixid);
185 tmpdig->SetTids(tids);
186 tmpdig->SetSignalID(elossID);
187 tmpdig->SetNelectrons(nele);
188 tmpdig->SetLayer(ilay);
189 tmpdig->SetModule(module);
190 //cout<<" tmpdigit : pixid "<< pixid<< " tids "<< tids << " nele " << nele << " ilay "<<ilay<<endl;
191 new((*pLst[ilay])[iCnt[ilay]++]) AliITSDigitUpgrade(*tmpdig);
193 AliDebug(1,"ending loop over sdigits to create digits");
196 AliDebug(1,"ending loop over layers");