]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDrawData.cxx
Ssemi-final version of TRD raw data simulation
[u/mrichter/AliRoot.git] / TRD / AliTRDrawData.cxx
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$ */
17
18 ///////////////////////////////////////////////////////////////////////////////
19 //                                                                           //
20 //  TRD raw data conversion class                                            //
21 //                                                                           //
22 ///////////////////////////////////////////////////////////////////////////////
23
24 #include <Riostream.h>
25 #include <TMath.h>
26
27 #include "AliDAQ.h"
28 #include "AliRawDataHeader.h"
29 #include "AliRawReader.h"
30 #include "AliLog.h"
31
32 #include "AliTRDrawData.h"
33 #include "AliTRDdigitsManager.h"
34 #include "AliTRDgeometry.h"
35 #include "AliTRDdataArrayI.h"
36 #include "AliTRDRawStream.h"
37
38 #include "AliTRDcalibDB.h"
39 #include "AliFstream.h"
40
41 #include "AliTRDSignalIndex.h"
42
43 #include "AliTRDfeeParam.h"
44 #include "AliTRDmcmSim.h"
45
46 ClassImp(AliTRDrawData)
47
48 //_____________________________________________________________________________
49 AliTRDrawData::AliTRDrawData()
50   :TObject()
51   ,fGeo(NULL)
52   ,fFee(NULL)
53   ,fNumberOfDDLs(0)
54 {
55   //
56   // Default constructor
57   //
58   fFee = AliTRDfeeParam::Instance();
59   fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
60 }
61
62 //_____________________________________________________________________________
63 AliTRDrawData::AliTRDrawData(const AliTRDrawData &r)
64   :TObject(r)
65   ,fGeo(NULL)
66   ,fFee(NULL)
67   ,fNumberOfDDLs(0)
68 {
69   //
70   // Copy constructor
71   //
72   fFee = AliTRDfeeParam::Instance();
73   fNumberOfDDLs = AliDAQ::NumberOfDdls("TRD");
74 }
75
76 //_____________________________________________________________________________
77 AliTRDrawData::~AliTRDrawData()
78 {
79   //
80   // Destructor
81   //
82 }
83
84 //_____________________________________________________________________________
85 Bool_t AliTRDrawData::Digits2Raw(TTree *digitsTree, TTree *tracks )
86 {
87   //
88   // Initialize necessary parameters and call one
89   // of the raw data simulator selected by SetRawVersion.
90   //
91   // Currently tracklet output is not spported yet and it
92   // will be supported in higher version simulator.
93   //
94
95   AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
96
97   if (!digitsManager->ReadDigits(digitsTree)) {
98     delete digitsManager;
99     return kFALSE;
100   }
101
102   if (tracks != NULL) {
103     delete digitsManager;
104     AliError("Tracklet input is not supported yet.");
105     return kFALSE;
106   }
107
108   fGeo = new AliTRDgeometry();
109
110   if (!AliTRDcalibDB::Instance()) {
111     AliError("Could not get calibration object");
112     delete fGeo;
113     delete digitsManager;
114     return kFALSE;
115   }
116
117   Int_t retval = kTRUE;
118   Int_t rv     = fFee->GetRAWversion();
119
120   // Call appropriate Raw Simulator
121   if ( rv > 0 && rv <= 3 ) retval = Digits2Raw(digitsManager); 
122   else {
123     retval = kFALSE;
124     AliWarning(Form("Unsupported raw version (%d).", rv));
125   }
126
127   // Cleanup
128   delete fGeo;
129   delete digitsManager;
130
131   return retval;
132
133 }
134
135 //_____________________________________________________________________________
136 Bool_t AliTRDrawData::Digits2Raw(AliTRDdigitsManager *digitsManager)
137 {
138   //
139   // Raw data simulator for all versions > 0. This is prepared for real data.
140   // This version simulate only raw data with ADC data and not with tracklet.
141   //
142
143   const Int_t kMaxHcWords = (fGeo->TBmax()/3)*fGeo->ADCmax()*fGeo->MCMmax()*fGeo->ROBmaxC1()/2 + 100 + 20;
144
145   // Buffer to temporary store half chamber data
146   UInt_t     *hc_buffer   = new UInt_t[kMaxHcWords];
147
148   // sect is same as iDDL, so I use only sect here.
149   for (Int_t sect = 0; sect < fGeo->Nsect(); sect++) { 
150
151     char name[1024];
152     sprintf(name,"TRD_%d.ddl",sect + AliTRDRawStream::kDDLOffset);
153
154     AliFstream* of = new AliFstream(name);
155
156     // Write a dummy data header
157     AliRawDataHeader  header;  // the event header
158     UInt_t hpos = of->Tellp();
159     of->WriteBuffer((char *) (& header), sizeof(header));
160
161     // Reset payload byte size (payload does not include header).
162     Int_t npayloadbyte = 0;
163
164     // GTU common data header (5x4 bytes per super module, shows link mask)
165     for( Int_t cham = 0; cham < fGeo->Ncham(); cham++ ) {
166       UInt_t GtuCdh = (UInt_t)(0xe << 28);
167       for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) {
168         Int_t iDet = fGeo->GetDetector(plan, cham, sect);
169         // If chamber status is ok, we assume that the optical link is also OK.
170         // This is shown in the GTU link mask.
171         if ( AliTRDcalibDB::Instance()->GetChamberStatus(iDet) )
172           GtuCdh = GtuCdh | (3 << (2*plan));
173       }
174       of->WriteBuffer((char *) (& GtuCdh), sizeof(GtuCdh));
175       npayloadbyte += 4;
176     }
177
178     // Prepare chamber data
179     for( Int_t cham = 0; cham < fGeo->Ncham(); cham++) {
180       for( Int_t plan = 0; plan < fGeo->Nplan(); plan++) {
181
182         Int_t iDet = fGeo->GetDetector(plan,cham,sect);
183
184         // Get the digits array
185         AliTRDdataArrayI *digits = digitsManager->GetDigits(iDet);
186         digits->Expand();
187
188         Int_t hcwords = 0;
189         Int_t rv = fFee->GetRAWversion();
190
191         // Process A side of the chamber
192         if ( rv >= 1 && rv <= 2 ) hcwords = ProduceHcDataV1andV2(digits,0,iDet,hc_buffer,kMaxHcWords);
193         if ( rv == 3 )            hcwords = ProduceHcDataV3     (digits,0,iDet,hc_buffer,kMaxHcWords);
194
195         of->WriteBuffer((char *) hc_buffer, hcwords*4);
196         npayloadbyte += hcwords*4;
197
198         // Process B side of the chamber
199         if ( rv >= 1 && rv <= 2 ) hcwords = ProduceHcDataV1andV2(digits,1,iDet,hc_buffer,kMaxHcWords);
200         if ( rv >= 3 )            hcwords = ProduceHcDataV3     (digits,1,iDet,hc_buffer,kMaxHcWords);
201
202         of->WriteBuffer((char *) hc_buffer, hcwords*4);
203         npayloadbyte += hcwords*4;
204       }
205     }
206
207     // Complete header
208     header.fSize = UInt_t(of->Tellp()) - hpos;
209     header.SetAttribute(0);  // Valid data
210     of->Seekp(hpos);         // Rewind to header position
211     of->WriteBuffer((char *) (& header), sizeof(header));
212     delete of;
213   }
214
215   delete [] hc_buffer;
216   return kTRUE;
217
218 }
219
220 //_____________________________________________________________________________
221 Int_t AliTRDrawData::ProduceHcDataV1andV2(AliTRDdataArrayI *digits, Int_t side
222                                         , Int_t det, UInt_t *buf, Int_t maxSize)
223 {
224   //
225   // This function simulates: 1) SM-I commissiong data Oct. 06 (Raw Version == 1).
226   //                          2) Full Raw Production Version   (Raw Version == 2)
227   //
228   // Produce half chamber data (= an ORI data) for the given chamber (det) and side (side)
229   // where
230   //
231   //   side=0 means A side with ROB positions 0, 2, 4, 6.
232   //   side=1 means B side with ROB positions 1, 3, 5, 7.
233   //
234   // Chamber type (C0 orC1) is determined by "det" automatically.
235   // Appropriate size of buffer (*buf) must be prepared prior to calling this function.
236   // Pointer to the buffer and its size must be given to "buf" and "maxSize".
237   // Return value is the number of valid data filled in the buffer in unit of 32 bits
238   // UInt_t words.
239   // If buffer size if too small, the data is truncated with the buffer size however
240   // the function will finish without crash (this behaviour is similar to the MCM).
241   //
242
243   Int_t          nw = 0;                       // Number of written    words
244   Int_t          of = 0;                       // Number of overflowed words
245   Int_t        plan = fGeo->GetPlane( det );   // Plane
246   Int_t        cham = fGeo->GetChamber( det ); // Chamber
247   Int_t        sect = fGeo->GetSector( det );  // Sector (=iDDL)
248   Int_t        nRow = fGeo->GetRowMax( plan, cham, sect );
249   Int_t        nCol = fGeo->GetColMax( plan );
250   const Int_t nTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
251   Int_t      kCtype = 0;                       // Chamber type (0:C0, 1:C1)
252   Int_t         iEv = 0xA;                     // Event ID. Now fixed to 10, how do I get event id?
253   UInt_t          x = 0;                       // General used number
254   Int_t          rv = fFee->GetRAWversion();
255
256   // Check the nCol and nRow.
257   if ((nCol == 144) && 
258       (nRow == 16 || nRow == 12)) {
259     kCtype = (nRow-12) / 4;
260   } 
261   else {
262     AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
263                  ,nRow,nCol));
264     return 0;
265   }
266
267   AliDebug(1,Form("Producing raw data for sect=%d plan=%d cham=%d side=%d"
268                  ,sect,plan,cham,side));
269
270   // Tracklet should be processed here but not implemented yet
271
272   // Write end of tracklet marker
273   if (nw < maxSize) {
274     buf[nw++] = kEndoftrackletmarker;
275   } 
276   else {
277     of++;
278   }
279
280   // Half Chamber header
281   if      ( rv == 1 ) {
282     // Now it is the same version as used in SM-I commissioning.
283     Int_t  dcs = det+100;      // DCS Serial (in simulation, it is meaningless
284     x = (dcs<<20) | (sect<<15) | (plan<<12) | (cham<<9) | (side<<8) | 1;
285     if (nw < maxSize) {
286       buf[nw++] = x; 
287     }
288     else {
289       of++;
290     }
291   } 
292   else if ( rv == 2 ) {
293     // h[0] (there are 3 HC header)
294     Int_t minorv = 0;      // The minor version number
295     Int_t add    = 1;      // The number of additional header words to follow
296     x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (plan<<6) | (cham<<3) | (side<<2) | 1;
297     if (nw < maxSize) {
298       buf[nw++] = x; 
299     }
300     else {
301       of++;
302     }
303     // h[1]
304     Int_t bc_ctr   = 99; // bunch crossing counter. Here it is set to 99 always for no reason
305     Int_t pt_ctr   = 15; // pretrigger counter. Here it is set to 15 always for no reason
306     Int_t pt_phase = 11; // pretrigger phase. Here it is set to 11 always for no reason
307     x = (bc_ctr<<16) | (pt_ctr<<12) | (pt_phase<<8) | ((nTBin-1)<<2) | 1;
308     if (nw < maxSize) {
309       buf[nw++] = x; 
310     }
311     else {
312       of++;
313     }
314     // h[2]
315     Int_t ped_setup       = 1;    // Pedestal filter setup (0:1). Here it is always 1 for no reason
316     Int_t gain_setup      = 1;    // Gain filter setup (0:1). Here it is always 1 for no reason
317     Int_t tail_setup      = 1;    // Tail filter setup (0:1). Here it is always 1 for no reason
318     Int_t xt_setup        = 0;    // Cross talk filter setup (0:1). Here it is always 0 for no reason
319     Int_t nonlin_setup    = 0;    // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
320     Int_t bypass_setup    = 0;    // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
321     Int_t common_additive = 10;   // Digital filter common additive (0:63). Here it is always 10 for no reason
322     x = (ped_setup<<31) | (gain_setup<<30) | (tail_setup<<29) | (xt_setup<<28) | (nonlin_setup<<27)
323       | (bypass_setup<<26) | (common_additive<<20) | 1;
324     if (nw < maxSize) {
325       buf[nw++] = x; 
326     }
327     else {
328       of++;
329     }
330   }
331
332   // Scan for ROB and MCM
333   for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) {
334     Int_t iRob = iRobRow * 2 + side;
335     for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
336       Int_t padrow = iRobRow * 4 + iMcm / 4;
337
338       // MCM header
339       x = ((iRob * fGeo->MCMmax() + iMcm) << 24) | ((iEv % 0x100000) << 4) | 0xC;
340       if (nw < maxSize) {
341         buf[nw++] = x; 
342       }
343       else {
344         of++;
345       }
346
347       // ADC data
348       for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
349         Int_t padcol = fGeo->GetPadColFromADC(iRob, iMcm, iAdc);
350         UInt_t aa = !(iAdc & 1) + 2;
351         UInt_t *a = new UInt_t[nTBin+2];
352         // 3 timebins are packed into one 32 bits word
353         for (Int_t iT = 0; iT < nTBin; iT+=3) { 
354           if ((padcol >=    0) && (padcol <  nCol)) {
355             a[iT  ] = ((iT    ) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT    ) : 0;
356             a[iT+1] = ((iT + 1) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 1) : 0;
357             a[iT+2] = ((iT + 2) < nTBin ) ? digits->GetDataUnchecked(padrow,padcol,iT + 2) : 0; 
358           } 
359           else {
360             a[iT] = a[iT+1] = a[iT+2] = 0; // This happenes at the edge of chamber (should be pedestal! How?)
361           }
362           x = (a[iT+2] << 22) | (a[iT+1] << 12) | (a[iT] << 2) | aa;
363           if (nw < maxSize) {
364             buf[nw++] = x; 
365           }
366           else {
367             of++;
368           }
369         }
370         // Diagnostics
371         Float_t avg = 0;
372         Float_t rms = 0;
373         for (Int_t iT = 0; iT < nTBin; iT++) {
374           avg += (Float_t) (a[iT]);
375         }
376         avg /= (Float_t) nTBin;
377         for (Int_t iT = 0; iT < nTBin; iT++) {
378           rms += ((Float_t) (a[iT]) - avg) * ((Float_t) (a[iT]) - avg);
379         }
380         rms = TMath::Sqrt(rms / (Float_t) nTBin);
381         if (rms > 1.7) {
382           AliDebug(2,Form("Large RMS (>1.7)  (ROB,MCM,ADC)=(%02d,%02d,%02d), avg=%03.1f, rms=%03.1f"
383                           ,iRob,iMcm,iAdc,avg,rms));
384         }
385         delete [] a;
386       }
387     }
388   }
389
390   // Write end of raw data marker
391   if (nw < maxSize) {
392     buf[nw++] = kEndofrawdatamarker; 
393   }
394   else {
395     of++;
396   }
397   if (of != 0) {
398     AliWarning("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
399   }
400
401   return nw;
402
403 }
404
405
406 //_____________________________________________________________________________
407 Int_t AliTRDrawData::ProduceHcDataV3(AliTRDdataArrayI *digits, Int_t side
408                                      , Int_t det, UInt_t *buf, Int_t maxSize)
409 {
410   //
411   // This function simulates: Raw Version == 3 (Zero Suppression Prototype)
412   //
413
414   Int_t          nw = 0;                       // Number of written    words
415   Int_t          of = 0;                       // Number of overflowed words
416   Int_t        plan = fGeo->GetPlane( det );   // Plane
417   Int_t        cham = fGeo->GetChamber( det ); // Chamber
418   Int_t        sect = fGeo->GetSector( det );  // Sector (=iDDL)
419   Int_t        nRow = fGeo->GetRowMax( plan, cham, sect );
420   Int_t        nCol = fGeo->GetColMax( plan );
421   const Int_t nTBin = AliTRDcalibDB::Instance()->GetNumberOfTimeBins();
422   Int_t      kCtype = 0;                       // Chamber type (0:C0, 1:C1)
423   Int_t         iEv = 0xA;                     // Event ID. Now fixed to 10, how do I get event id?
424   UInt_t          x = 0;                       // General used number
425   Int_t          rv = fFee->GetRAWversion();
426
427   // Check the nCol and nRow.
428   if ((nCol == 144) && 
429       (nRow == 16 || nRow == 12)) {
430     kCtype = (nRow-12) / 4;
431   } 
432   else {
433     AliError(Form("This type of chamber is not supported (nRow=%d, nCol=%d)."
434                  ,nRow,nCol));
435     return 0;
436   }
437
438   AliDebug(1,Form("Producing raw data for sect=%d plan=%d cham=%d side=%d"
439                  ,sect,plan,cham,side));
440
441   // Tracklet should be processed here but not implemented yet
442
443   // Write end of tracklet marker
444   if (nw < maxSize) {
445     buf[nw++] = kEndoftrackletmarker;
446   } 
447   else {
448     of++;
449   }
450
451   // Half Chamber header
452   // h[0] (there are 3 HC header)
453   Int_t minorv = 0;    // The minor version number
454   Int_t add    = 1;    // The number of additional header words to follow
455   x = (1<<31) | (rv<<24) | (minorv<<17) | (add<<14) | (sect<<9) | (plan<<6) | (cham<<3) | (side<<2) | 1;
456   if (nw < maxSize) {
457     buf[nw++] = x; 
458   }
459   else {
460     of++;
461   }
462   // h[1]
463   Int_t bc_ctr   = 99; // bunch crossing counter. Here it is set to 99 always for no reason
464   Int_t pt_ctr   = 15; // pretrigger counter. Here it is set to 15 always for no reason
465   Int_t pt_phase = 11; // pretrigger phase. Here it is set to 11 always for no reason
466   x = (bc_ctr<<16) | (pt_ctr<<12) | (pt_phase<<8) | ((nTBin-1)<<2) | 1;
467   if (nw < maxSize) {
468     buf[nw++] = x; 
469   }
470   else {
471     of++;
472   }
473   // h[2]
474   Int_t ped_setup       = 1;  // Pedestal filter setup (0:1). Here it is always 1 for no reason
475   Int_t gain_setup      = 1;  // Gain filter setup (0:1). Here it is always 1 for no reason
476   Int_t tail_setup      = 1;  // Tail filter setup (0:1). Here it is always 1 for no reason
477   Int_t xt_setup        = 0;  // Cross talk filter setup (0:1). Here it is always 0 for no reason
478   Int_t nonlin_setup    = 0;  // Nonlinearity filter setup (0:1). Here it is always 0 for no reason
479   Int_t bypass_setup    = 0;  // Filter bypass (for raw data) setup (0:1). Here it is always 0 for no reason
480   Int_t common_additive = 10; // Digital filter common additive (0:63). Here it is always 10 for no reason
481   x = (ped_setup<<31) | (gain_setup<<30) | (tail_setup<<29) | (xt_setup<<28) | (nonlin_setup<<27)
482     | (bypass_setup<<26) | (common_additive<<20) | 1;
483   if (nw < maxSize) {
484     buf[nw++] = x; 
485   }
486   else {
487     of++;
488   }
489
490   AliTRDmcmSim *mcm = new AliTRDmcmSim();
491
492   // Scan for ROB and MCM
493   for (Int_t iRobRow = 0; iRobRow < (kCtype + 3); iRobRow++ ) {
494     Int_t iRob = iRobRow * 2 + side;
495     for (Int_t iMcm = 0; iMcm < fGeo->MCMmax(); iMcm++ ) {
496
497       mcm->Init( det, iRob, iMcm );
498       Int_t padrow = mcm->GetRow();
499
500       // Copy ADC data to MCM simulator
501       for (Int_t iAdc = 0; iAdc < 21; iAdc++ ) {
502         Int_t padcol = mcm->GetCol( iAdc );
503         if ((padcol >=    0) && (padcol <  nCol)) {
504           for (Int_t iT = 0; iT < nTBin; iT++) { 
505             mcm->SetData( iAdc, iT, digits->GetDataUnchecked( padrow, padcol, iT) );
506           } 
507         } else {  // this means it is out of chamber, and masked ADC
508           mcm->SetDataPedestal( iAdc );
509         }
510       }
511       // Simulate process in MCM
512       mcm->Filter();     // Apply filter
513       mcm->ZSMapping();  // Calculate zero suppression mapping
514
515       // Write MCM data to buffer
516       Int_t temp_nw =  mcm->ProduceRawStream( &buf[nw], maxSize - nw );
517       if( temp_nw < 0 ) {
518         of += temp_nw;
519         nw += maxSize - nw;
520         AliError(Form("Buffer overflow detected. Please increase the buffer size and recompile."));
521       } else {
522         nw += temp_nw;
523       }
524     }
525   }
526
527   // Write end of raw data marker
528   if (nw < maxSize) {
529     buf[nw++] = kEndofrawdatamarker; 
530   }
531   else {
532     of++;
533   }
534   if (of != 0) {
535     AliWarning("Buffer overflow. Data is truncated. Please increase buffer size and recompile.");
536   }
537
538   return nw;
539
540 }
541
542 //_____________________________________________________________________________
543 AliTRDdigitsManager *AliTRDrawData::Raw2Digits(AliRawReader *rawReader)
544 {
545   //
546   // Vx of the raw data reading
547   //
548
549   AliTRDdataArrayI *digits = 0;
550   AliTRDdataArrayI *track0 = 0;
551   AliTRDdataArrayI *track1 = 0;
552   AliTRDdataArrayI *track2 = 0; 
553
554   AliTRDSignalIndex *indexes = 0;
555   // Create the digits manager
556   AliTRDdigitsManager* digitsManager = new AliTRDdigitsManager();
557   digitsManager->CreateArrays();
558
559   AliTRDRawStream input(rawReader);
560   input.SetRawVersion( fFee->GetRAWversion() );
561   input.Init();
562
563   // Loop through the digits
564   Int_t lastdet = -1;
565   Int_t det    = 0;
566   Int_t it = 0;
567   while (input.Next()) 
568     {
569
570       det    = input.GetDet();
571
572       if (det != lastdet) 
573         {       
574         
575           lastdet = det;
576
577           if (digits) digits->Compress(1,0);
578           if (track0) track0->Compress(1,0);
579           if (track1) track1->Compress(1,0);
580           if (track2) track2->Compress(1,0);
581         
582           // Add a container for the digits of this detector
583           digits = digitsManager->GetDigits(det);
584           track0 = digitsManager->GetDictionary(det,0);
585           track1 = digitsManager->GetDictionary(det,1);
586           track2 = digitsManager->GetDictionary(det,2);
587
588           // Allocate memory space for the digits buffer
589           if (digits->GetNtime() == 0) 
590             {
591               digits->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
592               track0->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
593               track1->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
594               track2->Allocate(input.GetMaxRow(),input.GetMaxCol(), input.GetNumberOfTimeBins());
595             }
596
597           indexes = digitsManager->GetIndexes(det);
598           indexes->SetSM(input.GetSM());
599           indexes->SetStack(input.GetStack());
600           indexes->SetLayer(input.GetLayer());
601           indexes->SetDetNumber(det);
602           if (indexes->IsAllocated() == kFALSE)
603             indexes->Allocate(input.GetMaxRow(), input.GetMaxCol(), input.GetNumberOfTimeBins());
604         }
605     
606       for (it = 0; it < 3; it++)
607         {
608           if ( input.GetTimeBin() + it < input.GetNumberOfTimeBins() )
609             {
610               if (input.GetSignals()[it] > 0)
611                 {
612                   digits->SetDataUnchecked(input.GetRow(), input.GetCol(),
613                                            input.GetTimeBin() + it, input.GetSignals()[it]);
614
615                   indexes->AddIndexTBin(input.GetRow(), input.GetCol(),
616                                         input.GetTimeBin() + it);
617                   track0->SetDataUnchecked(input.GetRow(), input.GetCol(),
618                                            input.GetTimeBin() + it, 0);
619                   track1->SetDataUnchecked(input.GetRow(), input.GetCol(),
620                                            input.GetTimeBin() + it, 0);
621                   track2->SetDataUnchecked(input.GetRow(), input.GetCol(),
622                                            input.GetTimeBin() + it, 0);
623                 }
624             }
625         }
626   }
627
628   if (digits) digits->Compress(1,0);
629   if (track0) track0->Compress(1,0);
630   if (track1) track1->Compress(1,0);
631   if (track2) track2->Compress(1,0);
632
633   return digitsManager;
634
635 }