Removing the tasks from the digitization (Ruben)
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUpg.cxx
CommitLineData
29998a6e 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id: AliITSUpg.cxx $ */
17
18
19///////////////////////////////////////////////////////////////////////////////
20// //
21// An overview of the basic philosophy of the ITS code development //
22// and analysis is show in the figure below. //
23//Begin_Html //
24/*
25<img src="picts/ITS/ITS_Analysis_schema.gif">
26</pre>
27<br clear=left>
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>.
31</font>
32<pre>
33*/
34//End_Html
35//
36// AliITSUpg. Inner Traking System base class.
37// This class contains the base procedures for the Inner Tracking System
38//
39//Begin_Html
40/*
41<img src="picts/ITS/AliITS_Class_Diagram.gif">
42</pre>
43<br clear=left>
44<font size=+2 color=red>
45<p>This show the class diagram of the different elements that are part of
46the AliITS class.
47</font>
48<pre>
49*/
50//End_Html
51//
52// Version: 0
53// Written by Rene Brun, Federico Carminati, and Roberto Barbera
54//
55// Version: 1
56// Modified and documented by Bjorn S. Nilsen
57// July 11 1999
58//
59// Version: 2
60// Modified and documented by A. Bologna
61// October 18 1999
62//
63// AliITSUpg is the general base class for the ITS. Also see AliDetector for
64// futher information.
65//
66///////////////////////////////////////////////////////////////////////////////
67
68#include <stdlib.h>
69#include <TClonesArray.h>
70#include <TFile.h>
71#include <TParticle.h>
72#include <TString.h>
73#include <TTree.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"
86#include "AliMC.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"
99#include "AliRun.h"
100#include "AliLog.h"
101#include "AliITSInitGeometryUpg.h"
102#include "AliITSFOSignalsSPD.h"
103
104ClassImp(AliITSUpg)
105
106//______________________________________________________________________
107AliITSUpg::AliITSUpg() : AliDetector(),
108fDetTypeSim(0),
109fEuclidOut(0),
110fOpt("All"),
111fIdN(0),
112fIdSens(0),
113fIdName(0),
114fITSmodules(0),
115fTiming(kFALSE),
116fSimuParam(0),
117fModA(0),
118fpSDigits(0)
119{
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
125 // is also called.
126
127// SetDetectors(); // default to fOpt="All". This variable not written out.
128//PH SetMarkerColor(kRed);
129}
130//______________________________________________________________________
131AliITSUpg::AliITSUpg(const Char_t *title):
132 AliDetector("ITS",title),
133 fDetTypeSim(0),
134 fEuclidOut(0),
135 fOpt("All"),
136 fIdN(0),
137 fIdSens(0),
138 fIdName(0),
139 fITSmodules(0),
140 fTiming(kFALSE),
141 fSimuParam(0),
142 fModA(0),
143 fpSDigits(0)
144{
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
153 // functions.
154 // Inputs:
155 // Char_t *title Simulation title for the ITS
156 // Outputs:
157 // none.
158 // Return:
159 // none.
160
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);
169}
170//______________________________________________________________________
171AliITSUpg::AliITSUpg(const char *name, const char *title):
172 AliDetector(name,title),
173 fDetTypeSim(0),
174 fEuclidOut(0),
175 fOpt("All"),
176 fIdN(0),
177 fIdSens(0),
178 fIdName(0),
179 fITSmodules(0),
180 fTiming(kFALSE),
181 fSimuParam(0),
182 fModA(0),
183 fpSDigits(0)
184{
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
193 // functions.
194
195 fHits = new TClonesArray("AliITShit",1560);
196 if(gAlice->GetMCApp()) gAlice->GetMCApp()->AddHitList(fHits);
197 //fNhits=0; //done in AliDetector(name,title)
198
199 SetDetectors(); // default to fOpt="All". This variable not written out.
200
201 fDetTypeSim = new AliITSDetTypeSim();
202 //PH SetMarkerColor(kRed);
203 if(!fLoader) MakeLoader(AliConfig::GetDefaultEventFolderName());
204 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
205
206}
207//______________________________________________________________________
208AliITSUpg::~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.
213 // Inputs:
214 // none.
215 // Outputs:
216 // none.
217 // Return:
218 // none.
219
220 if (fHits) {
221 fHits->Delete();
222 delete fHits;
223 fHits=0;
224 }
225 if(fITSmodules) {
226 this->ClearModules();
227 delete fITSmodules;
228 fITSmodules = 0;
229 }// end if fITSmodules!=0
230
231 delete[] fIdName; // Array of TStrings
232 delete[] fIdSens;
233 Int_t size = AliITSgeomTGeo::GetNModules();
234 if (fDetTypeSim){
235 delete fDetTypeSim;
236 fDetTypeSim = 0;
237 }
238 if(fSimuParam){
239 delete fSimuParam;
240 fSimuParam=0;
241 }
242 if(fModA){
243 if(size>0){
244 for(Int_t j=0; j<size; j++){
245 fModA[j]->Delete();
246 delete fModA[j];
247 }
248 }
249 delete []fModA;
250 }
251 if(fpSDigits){
252 fpSDigits->Delete();
253 delete fpSDigits;
254 }
255}
256
257//______________________________________________________________________
f21fc003 258AliDigitizer* AliITSUpg::CreateDigitizer(AliDigitizationInput* manager)const{
29998a6e 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).
262 // Inputs:
f21fc003 263 // AliDigitizationInput *manager The Manger class for Digitization
29998a6e 264 // Output:
265 // none.
266 // Return:
267 // A new AliITSRunDigitizer (cast as a AliDigitizer).
268
269 return new AliITSDigitizer(manager);
270}
271//______________________________________________________________________
272void 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.
279 // Inputs:
280 // none.
281 // Outputs:
282 // none.
283 // Return:
284 // none.
285 Int_t i;
286 // Array of TStrings
287 if(gMC) for(i=0;i<fIdN;i++) fIdSens[i] = gMC->VolId(fIdName[i]);
288
289}
290//______________________________________________________________________
291void AliITSUpg::SetDefaults(){
292 // sets the default segmentation, response, digit and raw cluster classes.
293 // Inputs:
294 // none.
295 // Outputs:
296 // none.
297 // Return:
298 // none.
299 AliInfoClass("AliITSUpg::Setting Defaults");
300 if(!fDetTypeSim) {
301 Error("SetDefaults()","fDetTypeSim is 0!");
302 return;
303 }
304
305 fDetTypeSim->SetDefaults();
306 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
307
308}
309//______________________________________________________________________
310void AliITSUpg::SetDefaultSimulation(){
311 // sets the default simulation.
312 // Inputs:
313 // none.
314 // Outputs:
315 // none.
316 // Return:
317 // none.
318 if(!fDetTypeSim) {
319 Error("SetDefaultSimulation()","fDetTypeSim is 0!");
320 return;
321 }
322
323 fDetTypeSim->SetDefaultSimulation();
324 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
325
326}
327
328
329//______________________________________________________________________
330void AliITSUpg::MakeBranch(Option_t* option){
331 // Creates Tree branches for the ITS.
332 // Inputs:
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
337 // read from.
338 // Outputs:
339 // none.
340 // Return:
341 // none.
342 if(!fDetTypeSim) {
343 Error("MakeBranch","fDetTypeSim is 0!");
344 return;
345 }
346
347 Bool_t cH = (strstr(option,"H")!=0);
348 Bool_t cS = (strstr(option,"S")!=0);
349 Bool_t cD = (strstr(option,"D")!=0);
350
351 if(cH && (fHits == 0x0)) fHits = new TClonesArray("AliITShit", 1560);
352 AliDetector::MakeBranch(option);
353
354 if(cS) MakeBranchS(0);
355 if(cD) MakeBranchD(0);
356
357
358}
359//___________________________________________________________________
360void AliITSUpg::MakeBranchS(const char* fl){
361
362 // Creates Tree Branch for the ITS summable digits.
363 // Inputs:
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.
367
368
369 if(!fDetTypeSim){
370 Error("MakeBranchS","fDetTypeSim is 0!");
371 }
372 Int_t buffersize = 4000;
373 char branchname[31];
374
375 // only one branch for SDigits.
376 snprintf(branchname,30,"%s",GetName());
377
378 if(fLoader->TreeS()){
379 TClonesArray* sdig = (TClonesArray*)fDetTypeSim->GetSDigits();
380 MakeBranchInTree(fLoader->TreeS(),branchname,&sdig,buffersize,fl);
381 }
382}
383//______________________________________________________________________
384void AliITSUpg::MakeBranchD(const char* file){
385
386 //Make branch for digits
387 if(!fDetTypeSim) {
388 Warning("MakeBranchD","fDetTypeSim is 0!");
389 return;
390 }
391 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
392 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
393 MakeBranchInTreeD(fLoader->TreeD(),file);
394}
395
396//___________________________________________________________________
397void AliITSUpg:: MakeBranchInTreeD(TTree* treeD, const char* file){
398 // Creates Tree branches for the ITS.
399
400 if(!fDetTypeSim){
401 Error("MakeBranchS","fDetTypeSim is 0!");
402 }
403 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
404 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
405
406 const Char_t *det[3] = {"SPD","SDD","SSD"};
407 const Char_t* digclass;
408 Int_t buffersize = 4000;
409 Char_t branchname[31];
410
411 if(!fDetTypeSim->GetDigits()){
412 fDetTypeSim->SetDigits(new TObjArray(fgkNTYPES));
413 }
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);
419 }
420 else ResetDigits(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);
425 }
426
427}
428//______________________________________________________________________
429void AliITSUpg::SetTreeAddress(){
430 // Set branch address for the Trees.
431 // Inputs:
432 // none.
433 // Outputs:
434 // none.
435 // Return:
436 // none.
437
438 if(!fDetTypeSim) {
439 Error("SetTreeAddress","fDetTypeSim is 0!");
440 return;
441 }
442
443 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
444 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
445
446 TTree *treeS = fLoader->TreeS();
447 TTree *treeD = fLoader->TreeD();
448 if (fLoader->TreeH() && (fHits == 0x0)) {
449 fHits = new TClonesArray("AliITShit", 1560);
450 }
451 AliDetector::SetTreeAddress();
452
453 fDetTypeSim->SetTreeAddressS(treeS, (Char_t*)GetName());
454 fDetTypeSim->SetTreeAddressD(treeD, (Char_t*)GetName());
455}
456//______________________________________________________________________
457void AliITSUpg::AddHit(Int_t track, Int_t *vol, Float_t *hits){
458 // Add an ITS hit
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
463 // function.
464 // Inputs:
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
468 // Outputs:
469 // none.
470 // Return:
471 // none.
472 TClonesArray &lhits = *fHits;
473 new(lhits[fNhits++]) AliITShit(fIshunt,track,vol,hits);
474}
475
476//______________________________________________________________________
477void 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.
481
482 static TTree *trH1; //Tree with background hits
483 static Bool_t first=kTRUE;
484 static TFile *file;
485 const char *addBgr = strstr(option,"Add");
486
487 if (addBgr ) {
488 if(first) {
489 file=new TFile(filename);
490 } // end if first
491 first=kFALSE;
492 file->cd();
493 file->ls();
494 // Get Hits Tree header from file
495 if(trH1) delete trH1;
496 trH1=0;
497
498 char treeName[21];
499 snprintf(treeName,20,"TreeH%d",bgrev);
500 trH1 = (TTree*)gDirectory->Get(treeName);
501 if (!trH1) {
502 Error("FillModules","cannot find Hits Tree for event:%d",bgrev);
503 } // end if !trH1
504 // Set branch addresses
505 } // end if addBgr
506
507 FillModules(fLoader->TreeH(),0); // fill from this file's tree.
508
509 if (addBgr ) {
510 FillModules(trH1,10000000); // Default mask 10M.
511 TTree *fAli=fLoader->GetRunLoader()->TreeK();
512 TFile *fileAli=0;
513 if (fAli) {
514 fileAli =fAli->GetCurrentFile();
515 fileAli->cd();
516 }
517 } // end if add
518
519
520}
521//______________________________________________________________________
522void 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
525 // Inputs:
526 // TTree *treeH The tree containing the hits to be copied into
527 // the modules.
528 // Int_t mask The track number mask to indecate which file
529 // this hits came from.
530 // Outputs:
531 // none.
532 // Return:
533 // none.
534
535 if (treeH == 0x0)
536 {
537 AliError("Tree H is NULL");
538 return;
539 }
540 Int_t lay,lad,det,index;
541 AliITShit *itsHit=0;
542 AliITSmodule *mod=0;
543 char branchname[21];
544 snprintf(branchname,20,"%s",GetName());
545 TBranch *branch = treeH->GetBranch(branchname);
546 if (!branch) {
547 Error("FillModules","%s branch in TreeH not found",branchname);
548 return;
549 } // end if !branch
550 branch->SetAddress(&fHits);
551 Int_t nTracks =(Int_t) treeH->GetEntries();
552 Int_t iPrimTrack,h;
553 for(iPrimTrack=0; iPrimTrack<nTracks; iPrimTrack++){
554 ResetHits();
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);
561 if (GetITSgeom()) {
562 index = GetITSgeom()->GetModuleIndex(lay,lad,det);
563 } else {
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
571}
572
573//______________________________________________________________________
574Bool_t AliITSUpg::InitModules(Int_t size,Int_t &nmodules){
575 // Initialize the modules array.
576 // Inputs:
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.
580 // Outputs:
581 // Int_t &nmodules The number of modules existing.
582 // Return:
583 // none.
584
585 if(fITSmodules){
586 fITSmodules->Delete();
587 delete fITSmodules;
588 } // end fir fITSmoudles
589
590 if(!fDetTypeSim) {
591 Error("InitModules","fDetTypeSim is null!");
592 return kFALSE;
593 }
594 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
595
596 Int_t nl,indexMAX,index;
597
598 if(size<=0){ // default to using data stored in AliITSgeom
599 if(fDetTypeSim->GetITSgeom()==0) {
600 Error("InitModules","fITSgeom not defined");
601 return kFALSE;
602 } // end if fITSgeom==0
603 nl = fDetTypeSim->GetITSgeom()->GetNlayers();
604 indexMAX = fDetTypeSim->GetITSgeom()->GetIndexMax();
605 nmodules = indexMAX;
606 fITSmodules = new TObjArray(indexMAX);
607 for(index=0;index<indexMAX;index++){
608 fITSmodules->AddAt( new AliITSmodule(index),index);
609 } // end for index
610 }else{
611 fITSmodules = new TObjArray(size);
612 for(index=0;index<size;index++) {
613 fITSmodules->AddAt( new AliITSmodule(index),index);
614 } // end for index
615
616 nmodules = size;
617 } // end i size<=0
618 return kTRUE;
619}
620//______________________________________________________________________
621void AliITSUpg::Hits2SDigits(){
622 // Standard Hits to summable Digits function.
623 // Inputs:
624 // none.
625 // Outputs:
626 // none.
627
628
629 if(!fDetTypeSim) {
630 Error("Hits2SDigits","fDetTypeSim is null!");
631 return;
632 }
633
634 SetDefaults();
635 fLoader->LoadHits("read");
636 fLoader->LoadSDigits("recreate");
637 AliRunLoader* rl = fLoader->GetRunLoader();
638 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
639 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
640
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");
647 MakeBranch("S");
648 SetTreeAddress();
649 HitsToPreDigits(iEvent,0,-1," ",fOpt," ");
650 } // end for iEvent
651
652 fLoader->UnloadHits();
653 fLoader->UnloadSDigits();
654
655}
656//______________________________________________________________________
657void AliITSUpg::Hits2Digits(){
658
659 //Conversion from hits to digits
660 if(!fDetTypeSim) {
661 Error("Hits2SDigits","fDetTypeSim is 0!");
662 return;
663 }
664
665 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
666 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
667 SetDefaults();
668
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");
675 MakeBranch("D");
676 SetTreeAddress();
677 HitsToDigits(iEvent,0,-1," ",fOpt," ");
678 }
679
680 fLoader->UnloadHits();
681 fLoader->UnloadDigits();
682
683}
684
685//______________________________________________________________________
686void 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.
694 // Inputs:
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..
702 // Outputs:
703 // none.
704 // Return:
705 // none.
706
707 if(!fDetTypeSim) {
708 Error("HitsToDigits","fDetTypeSim is null!");
709 return;
710 }
711 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
712 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
713 if(!GetITSgeom()) return; // need transformations to do digitization.
714 AliITSgeom *geom = GetITSgeom();
715
716 const char *all = strstr(opt,"All");
717 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
718 strstr(opt,"SSD")};
719 static Bool_t setDef=kTRUE;
720 if (setDef) SetDefaultSimulation();
721 setDef=kFALSE;
722
723 Int_t nmodules;
724 InitModules(size,nmodules);
725 FillModules(evNumber,bgrev,nmodules,option,filename);
726
727 // Reset Fast-OR signals for this event
728// fDetTypeSim->ResetFOSignals();
729
730 AliITSsimulation *sim = 0;
731 AliITSmodule *mod = 0;
732 Int_t id;
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);
737 if (!sim) {
738 Error("HitsToDigits","The simulation class was not "
739 "instanciated for module %d type %s!",module,
740 geom->GetModuleTypeName(module));
741 exit(1);
742 } // end if !sim
743 mod = (AliITSmodule *)fITSmodules->At(module);
744 sim->DigitiseModule(mod,module,evNumber);
745 // fills all branches - wasted disk space
746 fLoader->TreeD()->Fill();
747 ResetDigits();
748 } // end for module
749
750 ClearModules();
751
752 // Add Fast-OR signals to event (only one object per event)
753 if (all || det[0]) { // SPD present
754 WriteFOSignals();
755 }
756
757 fLoader->TreeD()->GetEntries();
758 fLoader->TreeD()->AutoSave();
759 // reset tree
760 fLoader->TreeD()->Reset();
761}
762//_____________________________________________________________________
763void AliITSUpg::Hits2PreDigits(){
764 // Turn hits into SDigits
765
766 if(!fDetTypeSim) {
767 Error("Hits2SDigits","fDetTypeSim is 0!");
768 return;
769 }
770
771 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
772 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
773 SetDefaults();
774
775 HitsToPreDigits(fLoader->GetRunLoader()->GetEventNumber(),
776 0,-1," ",fOpt," ");
777}
778
779//______________________________________________________________________
780void 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.
788 // Inputs:
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..
796 // Outputs:
797 // none.
798 // Return:
799 // none.
800
801
802 if(!fDetTypeSim) {
803 Error("HitsToPreDigits","fDetTypeSim is null!");
804 return;
805 }
806 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
807 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
808
809 if(!GetITSgeom()){
810 Error("HitsToPreDigits","fGeom is null!");
811 return; // need transformations to do digitization.
812 }
813 AliITSgeom *geom = GetITSgeom();
814
815 const char *all = strstr(opt,"All");
816 const char *det[3] = {strstr(opt,"SPD"),strstr(opt,"SDD"),
817 strstr(opt,"SSD")};
818 static Bool_t setDef=kTRUE;
819 if (setDef) SetDefaultSimulation();
820 setDef=kFALSE;
821
822 Int_t nmodules;
823 InitModules(size,nmodules);
824 FillModules(evNumber,bgrev,nmodules,option,filename);
825
826
827 AliITSsimulation *sim = 0;
828 AliITSmodule *mod = 0;
829 Int_t id,module;
830 for(module=0;module<geom->GetIndexMax();module++){
831 id = geom->GetModuleType(module);
832 if (!all && !det[id]) continue;
833 sim = (AliITSsimulation*)GetSimulationModel(id);
834 if (!sim) {
835 Error("HitsToPreDigits","The simulation class was not "
836 "instanciated for module %d type %s!",module,
837 geom->GetModuleTypeName(module));
838 exit(1);
839 } // end if !sim
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();
845 } // end for module
846
847 ClearModules();
848
849
850 fLoader->TreeS()->GetEntries();
851 fLoader->TreeS()->AutoSave();
852 fLoader->WriteSDigits("OVERWRITE");
853 // reset tree
854 fLoader->TreeS()->Reset();
855}
856
857//_____________________________________________________________________
858void AliITSUpg::HitsToFastRecPoints(Int_t evNumber,Int_t bgrev,Int_t size,
859 Option_t *opt0,Option_t *opt1,
860 const char *flnm){
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 !
865 // Inputs:
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..
874 // Outputs:
875 // none.
876 // Return:
877 // none.
878
879
880
881 if(!GetITSgeom()){
882 Error("HitsToPreDigits","fGeom is null!");
883 return; // need transformations to do digitization.
884 }
885 AliITSgeom *geom = GetITSgeom();
886
887 AliITSLoaderUpg *pITSloader = (AliITSLoaderUpg*)fLoader;
888
889 const char *all = strstr(opt1,"All");
890 const char *det[3] ={strstr(opt1,"SPD"),strstr(opt1,"SDD"),
891 strstr(opt1,"SSD")};
892 Int_t nmodules;
893 InitModules(size,nmodules);
894 FillModules(evNumber,bgrev,nmodules,opt0,flnm);
895
896 AliITSsimulation *sim = 0;
897 AliITSmodule *mod = 0;
898 Int_t id,module;
899
900 TTree *lTR = pITSloader->TreeR();
901 if(!lTR) {
902 pITSloader->MakeTree("R");
903 lTR = pITSloader->TreeR();
904 }
905
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
910 //the CPU goes up !
911 for(module=0;module<geom->GetIndexMax();module++){
912 id = geom->GetModuleType(module);
913 if (!all && !det[id]) continue;
914 sim = (AliITSsimulation*)GetSimulationModel(id);
915 if (!sim) {
916 Error("HitsToFastPoints","The simulation class was not "
917 "instantiated for module %d type %s!",module,
918 geom->GetModuleTypeName(module));
919 exit(1);
920 } // end if !sim
921 mod = (AliITSmodule *)fITSmodules->At(module);
922 sim->CreateFastRecPoints(mod,module,gRandom,ptarray);
923 lTR->Fill();
924 ptarray->Clear();
925 } // end for module
926
927 ClearModules();
928 fLoader->WriteRecPoints("OVERWRITE");
929 delete ptarray;
930}
931//_____________________________________________________________________
932Int_t AliITSUpg::Hits2Clusters(TTree *hTree, TTree *cTree) {
933 //------------------------------------------------------------
934 // This function creates ITS clusters
935 //------------------------------------------------------------
936 if(!GetITSgeom()){
937 Error("HitsToPreDigits","fGeom is null!");
938 return 1; // need transformations to do digitization.
939 }
940 AliITSgeom *geom=GetITSgeom();
941 Int_t mmax=geom->GetIndexMax();
942
943 InitModules(-1,mmax);
944 FillModules(hTree,0);
945
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);
950
951 AliITSsimulationFastPoints sim;
952 Int_t ncl=0;
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();
957 cTree->Fill();
958 points->Clear();
959 }
960
961 AliDebug(1,Form("Number of found fast clusters : %d",ncl));
962
963 //cTree->Write();
964
965 delete points;
966 return 0;
967}
968
969//_____________________________________________________________________
970void AliITSUpg::CheckLabels(Int_t lab[3]) const {
971 //------------------------------------------------------------
972 // Tries to find mother's labels
973 //------------------------------------------------------------
974
975 if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
976
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();
984 if (m<0) {
985 continue;
986 }
987 if (part->GetStatusCode()>0) {
988 continue;
989 }
990 lab[i]=m;
991 }
992 }
993 }
994
995}
996
997//______________________________________________________________________
998void AliITSUpg::SDigitsToDigits(Option_t *opt){
999 // Standard Summable digits to Digits function.
1000 // Inputs:
1001 // none.
1002 // Outputs:
1003 // none.
1004 if (!fDetTypeSim) {
1005 AliError("fDetTypeSim is 0!");
1006 return;
1007 }
1008 const char *all = strstr(opt,"All");
1009 const char *det[3] ={strstr(opt,"SPD"),strstr(opt,"SDD"),
1010 strstr(opt,"SSD")};
1011
1012 // Reset Fast-OR signals for this event
1013// fDetTypeSim->ResetFOSignals();
1014
1015 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1016 SetDefaults();
1017 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1018 fDetTypeSim->SDigitsToDigits(opt,(Char_t*)GetName());
1019
1020 // Add Fast-OR signals to event (only one object per event)
1021 if (all || det[0]) { // SPD present
1022 WriteFOSignals();
1023 }
1024}
1025
1026//______________________________________________________________________
1027void AliITSUpg::ResetDigits(){
1028 // Reset number of digits and the digits array for the ITS detector.
1029 // Inputs:
1030 // none.
1031 // Outputs:
1032 // none.
1033 if(!fDetTypeSim) {
1034 Error("ResetDigits","fDetTypeSim is 0!");
1035 return;
1036 }
1037
1038 fDetTypeSim->ResetDigits();
1039
1040
1041}
1042//______________________________________________________________________
1043void AliITSUpg::ResetDigits(Int_t branch){
1044 // Reset number of digits and the digits array for this branch.
1045 // Inputs:
1046 // none.
1047 // Outputs:
1048 // none.
1049
1050 if(!fDetTypeSim) {
1051 Error("ResetDigits","fDetTypeSim is 0!");
1052 return;
1053 }
1054
1055 fDetTypeSim->ResetDigits(branch);
1056
1057}
1058//______________________________________________________________________
1059void AliITSUpg::AddSumDigit(AliITSpListItem &sdig){
1060 // Adds the a module full of summable digits to the summable digits tree.
1061 // Inputs:
1062 // AliITSpListItem &sdig SDigit to be added to SDigits tree.
1063 // Outputs:
1064 // none.
1065 // Return:
1066 // none.
1067
1068 if(!fDetTypeSim) {
1069 Error("AddSumDigit","fDetTypeSim is 0!");
1070 return;
1071 }
1072 fDetTypeSim->AddSumDigit(sdig);
1073
1074}
1075//______________________________________________________________________
1076void AliITSUpg::AddSimDigit(Int_t branch, AliITSdigit *d){
1077 // Add a simulated digit.
1078 // Inputs:
1079 // Int_t id Detector type number.
1080 // AliITSdigit *d Digit to be added to the Digits Tree. See
1081 // AliITSdigit.h
1082 // Outputs:
1083 // none.
1084 // Return:
1085 // none.
1086
1087 if(!fDetTypeSim) {
1088 Error("AddSimDigit","fDetTypeSim is 0!");
1089 return;
1090 }
1091 fDetTypeSim->AddSimDigit(branch,d);
1092
1093}
1094//______________________________________________________________________
1095void 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.
1098 // Inputs:
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
1102 // AliITSdigit.h
1103 // Int_t *tracks Integer array [AliITSdigitS?D::GetNTracks()]
1104 // containing the track numbers that contributed to
1105 // this digit.
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.
1111 // Outputs:
1112 // none.
1113 // Return:
1114 // none.
1115
1116 if(!fDetTypeSim) {
1117 Error("AddSimDigit","fDetTypeSim is 0!");
1118 return;
1119 }
1120 fDetTypeSim->AddSimDigit(branch,phys,digits,tracks,hits,charges,sigexpanded);
1121
1122}
1123//______________________________________________________________________
1124void AliITSUpg::Digits2Raw(){
1125 // convert digits of the current event to raw data
1126
1127 if(!fDetTypeSim) {
1128 Error("Digits2Raw","fDetTypeSim is 0!");
1129 return;
1130 }
1131 fDetTypeSim->SetLoader((AliITSLoader*)fLoader);
1132 SetDefaults();
1133 if(fSimuParam) fDetTypeSim->SetSimuParam(fSimuParam);
1134 fDetTypeSim->GetLoader()->LoadDigits();
1135 TTree* digits = fDetTypeSim->GetLoader()->TreeD();
1136 if (!digits) {
1137 Error("Digits2Raw", "no digits tree");
1138 return;
1139 }
1140 fDetTypeSim->SetTreeAddressD(digits,(Char_t*)GetName());
1141
1142 // Get the FO signals for this event
1143 AliITSFOSignalsSPD* foSignals = NULL;
1144 AliRunLoader* runLoader = AliRunLoader::Instance();
1145 AliITSLoaderUpg* itsLoader = (AliITSLoaderUpg*) runLoader->GetLoader("ITSLoader");
1146 if (!itsLoader) {
1147 AliError("ITS loader is NULL.");
1148 }
1149 else {
1150 if(!itsLoader->TreeD()) AliError(" !!! No TreeD available !!!");
1151 foSignals = (AliITSFOSignalsSPD*)itsLoader->TreeD()->GetUserInfo()->FindObject("AliITSFOSignalsSPD");
1152 if(!foSignals) AliError("FO signals not retrieved");
1153 }
1154
1155 Bool_t deleteFOsignalsLater = kFALSE;
1156 if (!foSignals) {
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;
1160 }
1161
1162
1163// AliITSDDLModuleMapSDD* ddlsdd=fDetTypeSim->GetDDLModuleMapSDD();
1164 Char_t rawSDD=fDetTypeSim->GetSimuParam()->GetSDDRawDataFormat();
1165 AliITSDDLRawData rawWriter;
1166
1167 rawWriter.SetSDDRawFormat(rawSDD);
1168 //Verbose level
1169 // 0: Silent
1170 // 1: cout messages
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);
1177
1178 //SILICON PIXEL DETECTOR
1179 AliDebug(1,"Formatting raw data for SPD");
1180 rawWriter.RawDataSPD(digits->GetBranch("ITSDigitsSPD"),foSignals);
1181 if(deleteFOsignalsLater) delete foSignals;
1182
1183 //SILICON DRIFT DETECTOR
1184 AliDebug(1,Form("Formatting raw data for SDD - Format code =%d",rawSDD));
1185// rawWriter.RawDataSDD(digits->GetBranch("ITSDigitsSDD"),ddlsdd);
1186
1187 //SILICON STRIP DETECTOR
1188 AliDebug(1,"Formatting raw data for SSD");
1189 rawWriter.RawDataSSD(digits->GetBranch("ITSDigitsSSD"));
1190
1191 fLoader->UnloadDigits();
1192}
1193//______________________________________________________________________
1194AliLoader* AliITSUpg::MakeLoader(const char* topfoldername){
1195 //builds ITSgetter (AliLoader type)
1196 //if detector wants to use castomized getter, it must overload this method
1197
1198 AliDebug(1,Form("Creating AliITSLoaderUpg. Top folder is %s.",
1199 topfoldername));
1200 fLoader = new AliITSLoaderUpg(GetName(),topfoldername);
1201 return fLoader;
1202}
1203//______________________________________________________________________
1204Bool_t AliITSUpg::Raw2SDigits(AliRawReader* rawReader)
1205{
1206 //
1207 // Converts RAW data to SDigits
1208 //
1209 // Get TreeS
1210 //
1211 Int_t last = -1;
1212 Int_t size = AliITSgeomTGeo::GetNModules();
1213 if(!fModA) {
1214 fModA = new TClonesArray*[size];
1215 for (Int_t mod = 0; mod < size; mod++) fModA[mod] = new TClonesArray("AliITSpListItem", 10000);
1216 }
1217 AliLoader* loader = (AliRunLoader::Instance())->GetLoader("ITSLoader");
1218 if (!loader){
1219 Error("Open","Can not get ITS loader from Run Loader");
1220 return kFALSE;
1221 }
1222
1223 TTree* tree = 0;
1224 tree = loader->TreeS();
1225 if (!tree){
1226 loader->MakeTree("S");
1227 tree = loader->TreeS();
1228 }
1229 //
1230 // Array for SDigits
1231 //
1232 if(!fpSDigits){
1233 fpSDigits = new TClonesArray("AliITSpListItem",10000);
1234 }
1235 TClonesArray& aSDigits = *fpSDigits;
1236 Int_t bufsize = 32000;
1237 tree->Branch("ITS", &fpSDigits, bufsize);
1238 Int_t npx = 0;
1239 //
1240 // SPD
1241 //
1242 AliITSsegmentationSPD* segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1243 if(!segSPD){
1244 AliWarning("Set AliITS defaults");
1245 SetDefaults();
1246 segSPD = (AliITSsegmentationSPD*) fDetTypeSim->GetSegmentationModel(0);
1247 }
1248 npx = segSPD->Npx();
1249 Double_t thr, sigma;
1250
1251 AliITSRawStreamSPD inputSPD(rawReader);
1252 while(1){
1253 Bool_t next = inputSPD.Next();
1254 if (!next) break;
1255
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;
1260
1261 if (module >= size) continue;
1262
1263 last = (fModA[module])->GetEntries();
1264 TClonesArray& dum = *fModA[module];
1265 fDetTypeSim->GetSimuParam()->SPDThresholds(module,thr,sigma);
1266 thr += 1.;
1267 new (dum[last]) AliITSpListItem(-1, -1, module, index, thr);
1268 }
1269 rawReader->Reset();
1270
1271 //
1272 // SDD
1273 //
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);
1279
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();
1284 if(isZeroSupp){
1285 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,cal->GetZSLowThreshold(iSid));
1286 }else{
1287 for(Int_t iSid=0; iSid<2; iSid++) inputSDD->SetZeroSuppLowThreshold(iMod-firstSDD,iSid,0);
1288 }
1289 }
1290
1291// AliITSDDLModuleMapSDD* ddlmap=fDetTypeSim->GetDDLModuleMapSDD();
1292// inputSDD->SetDDLModuleMap(ddlmap);
1293 while(inputSDD->Next()){
1294 if(inputSDD->IsCompletedModule()==kFALSE &&
1295 inputSDD->IsCompletedDDL()==kFALSE){
1296
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);
1302
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));
1308 }
1309 }
1310 delete inputSDD;
1311 rawReader->Reset();
1312
1313 //
1314 // SSD
1315 //
1316 AliITSsegmentationSSD* segSSD = (AliITSsegmentationSSD*) fDetTypeSim->GetSegmentationModel(2);
1317 npx = segSSD->Npx();
1318 AliITSRawStreamSSD inputSSD(rawReader);
1319 while(1){
1320 Bool_t next = inputSSD.Next();
1321 if (!next) break;
1322
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;
1330
1331 if (module >= size) continue;
1332
1333 last = fModA[module]->GetEntries();
1334 TClonesArray& dum = *fModA[module];
1335 new (dum[last]) AliITSpListItem(-1, -1, module, index, Double_t(signal));
1336 }
1337 rawReader->Reset();
1338 AliITSpListItem* sdig = 0;
1339
1340 Int_t firstssd = GetITSgeom()->GetStartDet(kSSD);
1341 Double_t adcToEv = 1.;
1342 for (Int_t mod = 0; mod < size; mod++)
1343 {
1344 if(mod>=firstssd) {
1345 AliITSCalibrationSSD* calssd = (AliITSCalibrationSSD*)fDetTypeSim->GetCalibrationModel(mod);
1346 adcToEv = 1./calssd->GetSSDDEvToADC(1.);
1347 }
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;
1356 if (sig > 0.) {
1357 sdig = (AliITSpListItem*)aSDigits[ie];
1358 sdig->AddSignalAfterElect(mod, sdig->GetIndex(), Double_t(sig));
1359 }
1360 }
1361
1362 tree->Fill();
1363 aSDigits.Clear();
1364 fModA[mod]->Clear();
1365 }
1366 loader->WriteSDigits("OVERWRITE");
1367 return kTRUE;
1368}
1369
1370//______________________________________________________________________
1371void AliITSUpg::UpdateInternalGeometry(){
1372 //reads new geometry from TGeo
1373// AliDebug(1,"Delete ITSgeom and create a new one reading TGeo");
1374
1375 AliITSVersion_t version = (AliITSVersion_t)IsVersion();
1376 Int_t minor = 0;
1377 AliITSInitGeometryUpg initgeom;
1378 AliITSgeom* geom = initgeom.CreateAliITSgeom(version,minor);
1379 SetITSgeom(geom);
1380}
1381//______________________________________________________________________
1382AliTriggerDetector* AliITSUpg::CreateTriggerDetector() const {
1383 // create an AliITSTrigger object (and set trigger conditions as input)
1384 return new AliITSTrigger(fDetTypeSim->GetTriggerConditions());
1385}
1386//______________________________________________________________________
1387void AliITSUpg::WriteFOSignals(){
1388// This method write FO signals in Digits tree both in Hits2Digits
1389// or SDigits2Digits
1390
1391// fDetTypeSim->ProcessNoiseForFastOr();
1392 fDetTypeSim->WriteFOSignals();
1393}