SiliconData *MMMSiliconSort(float *ADC_import, int ntdc, int *TDC_channel_import, float *TDC_value_import) { SiliconData *si = new SiliconData(); //Loop over ADC and TDC events and do the following: //Check whether there are front-back coincidences for a detector and test the energies //Check to see whether there's a TDC event for the same channel as the front hit ADC - TDCs are apparently in single-hit mode. Don't need to worry about multihits //Calculate the theta and phi for the valid events multiTDC mTDC;// = new multiTDC(); mTDC.multiTDCSort(ntdc, TDC_channel_import, TDC_value_import); for(int k=0;k<mTDC.GetSize();k++)//Loop over all of the TDC values - there should only be a small number of these relative to the ADC values { if(MMMTDCFrontTest(mTDC.GetChannel(k))) { for(int l=0;l<mTDC.GetSize();l++)//Loop over all of the TDC values *again* but in this case, looking for the N sides { if(MMMTDCBackTest(mTDC.GetChannel(l)) && MMMTDCFrontBackTest(mTDC.GetChannel(k),mTDC.GetChannel(l))) { int DetNum = MMMTDCIdentifyDetector(mTDC.GetChannel(k),mTDC.GetChannel(l)); if(DetNum>0) { for(int i=MMMADCChannelLimits[DetNum-1][0];i<=MMMADCChannelLimits[DetNum-1][1];i++) { //Don't want to run for events w if(MMMADCTDCChannelTestPSide(i,mTDC.GetChannel(k)) && ADC_import[i]>0) { for(int j=MMMADCChannelLimits[DetNum-1][2];j<=MMMADCChannelLimits[DetNum-1][3];j++) { if(ADC_import[j]>0) { double energyi = MMMEnergyCalc(i,ADC_import[i]); double energyj = MMMEnergyCalc(j,ADC_import[j]); //Test whether the hits are in the front and back of the same detector and whether the energies are good if(MMMFrontBackTest(i,j,energyi,energyj,si) && MMMADCTDCChannelTestNSide(j,mTDC.GetChannel(l)) && 0.5*(energyi+energyj)>400) { si->SetEnergy(0.5*(energyi+energyj)); si->SetTheta(MMMThetaCalc(i)); si->SetPhi(MMMPhiCalc(j)); si->SetTime(mTDC.GetValue(k)); si->SetTimeFront(mTDC.GetValue(k)); si->SetTimeBack(mTDC.GetValue(l)); // printf("TDCOffsets index: %d\n",mTDC.GetChannel(k)-6*128-64); si->SetOffsetTime(mTDC.GetValue(k) - TDCOffsets[mTDC.GetChannel(k)-6*128-64]); si->SetDetectorHit(MMMDetHitNumber(i,j)); si->SetADCChannelFront(i); si->SetADCChannelBack(j); si->SetStripFront(MMMStripFront(i)); si->SetStripBack(MMMStripBack(j)); si->SetTDCChannelFront(mTDC.GetChannel(k)); si->SetTDCChannelBack(mTDC.GetChannel(l)); si->SetADCValueFront(ADC_import[i]); si->SetADCValueBack(ADC_import[j]); si->SetTDCValueFront(mTDC.GetValue(k)); si->SetTDCValueBack(-1); si->SetEnergyFront(energyi); si->SetEnergyBack(energyj); si->SetMult(mTDC.GetMult(k)); } } } } } } } } } } si->SetHits(si->SizeOfEvent()); if(!si->TestEvent())si->ClearEvent(); //If the event fails for some reason, we void it and clear it here. The number of these should be logged and, ideally, should be zero. A VOIDED EVENT IS ONE IN WHICH ALL SILICON DATA ARE THROWN AWAY BECAUSE THE RESULT IS **WRONG**. There are more energy hits than theta hits, for example. IT THEY ARE HAPPENING, THEN YOU'VE DONE IT WRONG. //printf("MMM.c L88"); //MMMGhostBuster(SiliconData *si); mTDC.ClearEvent(); return si; }