- if(energy > 0){ //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
- emcCells.SetCell(idignew,dig->GetId(),energy, time);
+
+ if(energy > 0) //Digits tagged as bad (dead, hot, not alive) are set to 0 in calibrate, remove them
+ {
+ // Only for MC
+ // Get the label of the primary particle that generated the cell
+ // Assign the particle that deposited more energy
+ Int_t nprimaries = dig->GetNprimary() ;
+ Int_t digLabel =-1 ;
+ Float_t edep =-1.;
+ if ( nprimaries > 0 )
+ {
+ Int_t jndex ;
+ for ( jndex = 0 ; jndex < nprimaries ; jndex++ ) { // all primaries in digit
+
+ if(edep < dig->GetDEParent(jndex+1))
+ {
+ digLabel = dig->GetIparent (jndex+1);
+ edep = dig->GetDEParent(jndex+1);
+ }
+
+ } // all primaries in digit
+ } // select primary label
+
+ emcCells.SetCell(idignew,dig->GetId(),energy, time,digLabel);