Help about writing information in a TClonesArray

Hi,

I have a class called "ActarPadSignal" for pad signals of a kind of detector. I use the following function to calculate the information for each pad and store them in a TClonesArray:
driftManager::CalculatePadsWithCharge(projectionOnPadPlane* pro, TClonesArray* clo){

// some other lines here ...

      thePadSignal[iterOnPads]->SetInitTime(pro->GetTimePre());
      thePadSignal[iterOnPads]->SetFinalTime(pro->GetTimePost());
      thePadSignal[iterOnPads]->SetSigmaTime(pro->GetSigmaLongAtPadPlane());
      thePadSignal[iterOnPads]->SetChargeDeposited(charge);
      thePadSignal[iterOnPads]->SetEventID(pro->GetTrack()->GetEventID());
      thePadSignal[iterOnPads]->SetRunID(pro->GetTrack()->GetRunID());

      new((*clo)[iterOnPads])ActarPadSignal(*thePadSignal[iterOnPads]);
      thePadSignal[iterOnPads]->Reset();

}

The above function “CalculatePadsWithCharge” is called in a macro with the following structure:


  TTree* digiTree = new TTree("digiTree","digiEvent Tree");

  TClonesArray* padSignalCA;
  padSignalCA = new TClonesArray("ActarPadSignal",50);
  digiTree->Branch("padSignals",&padSignalCA);

  projectionOnPadPlane* projection= new projectionOnPadPlane();

  Int_t nevents=0;
  Int_t stridesPerEvent=0;

  if(numberOfEvents)    nevents = numberOfEvents;
  else   nevents = eventTree->GetEntries();

  Int_t nb = 0;

  for(Int_t i=0;i<nevents;i++){ // for each event
    simpleTrackCA->Clear();

    nb += eventTree->GetEvent(i);

    stridesPerEvent = simpleTrackCA->GetEntries();
    if(stridesPerEvent>0) {

    //Clear the ClonesArray before filling it
    padSignalCA->Clear();

    for(Int_t h=0;h<stridesPerEvent;h++){
       localTrack = (ActarSimSimpleTrack*)simpleTrackCA->At(h);
       projection->SetTrack(localTrack);

       if(theDriftManager.CalculatePositionAfterDrift(projection))
            theDriftManager.CalculatePadsWithCharge(projection,padSignalCA);
      }
    digiTree->Fill();
    }

For each event there are several strides, and for each stride we call the “theDriftManager.CalculatePadsWithCharge” method above and save the pad signals in the TClonesArray “padSignalCA”. The problem is that it seems only the information with the LAST stride is saved in the padSignalCA. Could anyone help to see how to store the information for all the strides?

Thanks in advance!

Pang

Hi,

How are you incrementing ‘iterOnPads’ ?

Cheers,
Philippe

Dear Philippe,

Thank you for your question, which give me some hope :slight_smile:

The block of the codes corresponding to the increment of "iterOnPads" is the following:

  // calculate the number of pads with signals for a certain stride: numberOfPadsWithSignals here...

  if( numberOfPadsWithSignal>0) {
    ActarPadSignal** thePadSignal;
    thePadSignal = new ActarPadSignal*[numberOfPadsWithSignal];

    Double_t phiPad, xPad, zPad;

    for(Int_t iterOnPads=0;iterOnPads<numberOfPadsWithSignal;iterOnPads++){
      padUnderTest = padsGeo->CalculatePad(rowList[iterOnPads],columnList[iterOnPads]);
      centerPad = padsGeo->CoordinatesCenterOfPad(padUnderTest);

      phiPad = centerPad.Phi();
      xPad = centerPad.X();
      zPad = centerPad.Z();

      Double_t padSizeTmp = padsGeo->GetPadSize()/2.;
      charge = f2->Integral(zPad-padSizeTmp,zPad+padSizeTmp,xPad-padSizeTmp,xPad+padSizeTmp);
// in this integration, the x, and y values should be relative to the center pad.

      //Let us create and fill as many padSignals as pads in the event
      thePadSignal[iterOnPads] = new ActarPadSignal();
      thePadSignal[iterOnPads]->SetPadNumber(padUnderTest);
      thePadSignal[iterOnPads]->SetPadRow(rowList[iterOnPads]);
      thePadSignal[iterOnPads]->SetPadColumn(columnList[iterOnPads]);
      thePadSignal[iterOnPads]->SetNumberOfStrides(1); //to solve
      thePadSignal[iterOnPads]->SetInitTime(pro->GetTimePre());
      thePadSignal[iterOnPads]->SetFinalTime(pro->GetTimePost());
      thePadSignal[iterOnPads]->SetSigmaTime(pro->GetSigmaLongAtPadPlane());
      thePadSignal[iterOnPads]->SetChargeDeposited(charge);
      thePadSignal[iterOnPads]->SetEventID(pro->GetTrack()->GetEventID());
      thePadSignal[iterOnPads]->SetRunID(pro->GetTrack()->GetRunID());

      new((*clo)[iterOnPads])ActarPadSignal(*thePadSignal[iterOnPads]);
      thePadSignal[iterOnPads]->Reset();

    }
//     tree->Fill();

    delete f2;

//     for (Int_t i=0;i<numberOfPadsWithSignal;i++) delete thePadSignal[i];
//     delete thePadSignal;

  }

Thanks,

Pang

[quote]The problem is that it seems only the information with the LAST stride is saved in the padSignalCA.[/quote]This is indeed what your code does.

You have (as far as I can tell):for(Int_t h=0;h<stridesPerEvent;h++){ ... for(Int_t iterOnPads=0;iterOnPads<numberOfPadsWithSignal;iterOnPads++){ new((*clo)[iterOnPads])ActarPadSignal(*thePadSignal[iterOnPads]); So for each stride, you always write from 0 to numberOfPadsWithSignal in the TClonesArray. If the intent was to accumulated all the stride in the same array, you ought to do something like:new((*clo)[nubmerofpadsbeforethisloopstarted + iterOnPads])ActarPadSignal(*thePadSignal[iterOnPads]);

Cheers,
Philippe.

Thank you very much Philippe!

My problem is solved :slight_smile:

Pang