//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // Implementation of class TpcPSA_INT_ALICE // see TpcPSA_INT_ALICE.h for details // // Environment: // Software developed for the PANDA Detector at FAIR. // // Author List: // Sebastian Neubert TUM (original author) // Christian Hoeppner TUM (original author) // Sverre Doerheim TUM // Philipp Gadow TUM (added excessive debugmode) // //----------------------------------------------------------- // This Class' Header ------------------ #include "TpcPSA_INT_ALICE.h" #include "McIdCollection.h" // C/C++ Headers ---------------------- #include #include // Collaborating Class Headers -------- #include "TpcSample.h" #include "TpcDigi.h" #define DEBUG 0 #define debugmode 0 using std::cout; using std::endl; TpcPSA_INT_ALICE::TpcPSA_INT_ALICE() : TpcAbsPSAStrategy(), fTimeCalib(2.4), fsamplePersistence(kFALSE), fSatThreshold(-1) {} TpcDigi* TpcPSA_INT_ALICE::ProcessNext(const TpcSample* sample) { return NULL; } void TpcPSA_INT_ALICE::Process(const std::vector & samples, std::vector& digis, double padThreshold) { McIdCollection mcid; mcid.ClearData(); unsigned int nsamples = samples.size(); int amp=0; int prevamp=0; int time=0; int prevtime=0; bool inpulse=false; int deriv_0=0; int deriv_1=0; int deriv_2=0; bool fallingEdge = false; std::vector samplesInPulse; if (debugmode){ cout << "starting to loop over all samples, there are " << nsamples << " samples." << endl; cout << "the element at the position 0 of samples has the index " << samples.at(0)->index() << endl; cout << "the element at the beginning of samples has the index " << samples.front()->index() << endl; } for(unsigned int i=0;iamp(); time=samples.at(i)->t(); if (debugmode){ cout << "\n processing sample number " << i << endl; cout << "amp: "<< amp << " time: " << time << endl; } deriv_2=deriv_1; deriv_1=deriv_0; if (debugmode){ cout << "Calculating derivatives \n deriv_1: " << deriv_1 << " deriv_2: "<< deriv_2 << endl; } if(i==0){ // first sample if (debugmode){ cout << "first sample" << endl; cout << "sample index: " << samples.at(i)->index() << endl; } deriv_0=amp; //setting the derivative for the first sample fallingEdge=false; }else{ // i>0 if (debugmode){ cout << "not first sample" << endl; cout << "sample index: " << samples.at(i)->index() << endl; } prevamp=samples.at(i-1)->amp(); prevtime=samples.at(i-1)->t(); if(time-prevtime!=1){ //if there were empty samples between if (debugmode){ cout << "error, empty samples in between ++++++++++++++++++++++++++++++++++" << endl; } deriv_0=amp; fallingEdge=false; }else{ deriv_0=amp-prevamp; if(deriv_0<0) fallingEdge=true; } } if(DEBUG) cout<<"Processing sample: "<0 && deriv_1>=0)|| // _/ or // (deriv_0>=0 && deriv_1>0)|| // /_ or // (deriv_0<0 && deriv_1>0 && prevamp>0)) // /\ // && time-prevtime==1){ if(DEBUG) cout<<" starting new pulse"<0){ // add previous sample to pulse mcid.AddIDCollection(samples[i-1]->mcId(),1); samplesInPulse.push_back(samples[i-1]); if(debugmode){ cout << "adding previous sample to pulse: " << i-1 << " "; cout << "size of samplesinpulse is now " << samplesInPulse.size() << endl; } } // add sample to pulse mcid.AddIDCollection(samples[i]->mcId(),1); samplesInPulse.push_back(samples[i]); if (debugmode){ cout << "adding current sample to pulse: " << i << " "; cout << "size of samplesinpulse is now " << samplesInPulse.size() << endl; } } }else{ // sample is in pulse //checking for the end of a pulse if (debugmode){ cout << "sample is in pulse, checking for the end of a pulse: is deriv_0>0? " << deriv_0 << ", is deriv_1 <0? " << deriv_1 << endl; cout << "falling edge is " << fallingEdge << ", time is " << time << ", time - prevtime is " << (time - prevtime) << endl; cout << " is it the last sample? i = "<< i << ", last sample would be "<< nsamples-1 << endl; } if((deriv_0>0 && deriv_1<0) || //local minimum (fallingEdge && deriv_0==0) || //flat valley, on falling edge time-prevtime>1 || //gap in the samples i==nsamples-1){ //last sample if (debugmode){ cout << "there was a local minimum, a flat valley, a gap or it was the last sample" << endl; } if(i==nsamples-1 && time-prevtime==1){ // add last sample if there is no gap mcid.AddIDCollection(samples[i]->mcId(),1); samplesInPulse.push_back(samples[i]); if(debugmode){ cout << "there was no gap, adding last sample to pulse: " << i << " "; cout << samples[i] << endl; cout << "size of samplesinpulse is now " << samplesInPulse.size() << endl; } } inpulse=false; fallingEdge=false; double t0,A,length; if (debugmode){ cout << "finished collection of samples" << endl; cout << "size of samplesinpulse is now " << samplesInPulse.size() << endl; cout << "content of samplesinpulse is" << endl; for( Int_t isam = 0 ; isam < samplesInPulse.size(); isam++){ cout << "position: " << isam << ", amp: " << samplesInPulse.at(isam)->amp() << "index: " << samplesInPulse.at(isam)->index() << endl; } } processPulse(samplesInPulse,t0,A,length); if (debugmode){ cout << "finished ProcessPulse" << endl; cout << "size of samplesinpulse is now " << samplesInPulse.size() << endl; cout << "content of samplesinpulse is" << endl; for( Int_t isam = 0 ; isam < samplesInPulse.size(); isam++){ cout << "position: " << isam << ", amp: " << samplesInPulse.at(isam)->amp() << "index: " << samplesInPulse.at(isam)->index() << endl; } } mcid.Renormalize(); if(A>0){ // create Digi only when over threshold! TpcDigi* digi=new TpcDigi(A,t0,samples[i]->padId(),mcid); if (debugmode){ cout << "\n starting creation of digi --------------------------------------------" << endl; } for( Int_t isam = 0 ; isam < samplesInPulse.size(); isam++){ // std::cout<<"fSatThreshold:"<amp()<0&&samplesInPulse.at(isam)->amp()>fSatThreshold){ digi->setSaturation(true); } digi->addSample(samplesInPulse.at(isam)->index(),1); if (debugmode){ cout << "sample " << samplesInPulse.at(isam)->index() << " was added to digi." << endl; } } if (debugmode){ const std::map* tempmap = digi->getSampleMap(); std::map::const_iterator it; for (it = tempmap->begin(); it!=tempmap->end(); it++){ if(debugmode){ cout<<"sampleId "<first<<" weight: "<second<tlength(length); digis.push_back(digi); if(DEBUG) cout<<"Digi Amp over threshold ("<0){ if(DEBUG) cout<<"starting new pulse"<0){ // add previous sample to pulse; this sample will then be in two pulses mcid.AddIDCollection(samples[i-1]->mcId(),1); samplesInPulse.push_back(samples[i-1]); if (debugmode){ cout << "starting a new pulse, adding current sample to pulse: " << i-1 << " "; cout << samples[i-1] << endl; cout << "size of samplesinpulse is now " << samplesInPulse.size() << endl; } } // add sample to pulse mcid.AddIDCollection(samples[i]->mcId(),1); samplesInPulse.push_back(samples[i]); if (debugmode){ cout << "adding current sample to pulse: " << i << " "; cout << samples[i] << endl; cout << "size of samplesinpulse is now " << samplesInPulse.size() << endl; } } }else{ // not at the end of pulse // add sample to pulse mcid.AddIDCollection(samples[i]->mcId(),1); samplesInPulse.push_back(samples[i]); if (debugmode){ cout << "not at the end of pulse, adding current sample to pulse: " << i << " "; cout << samples[i] << endl; cout << "size of samplesinpulse is now " << samplesInPulse.size() << endl; } } } } // end loop over samples if(DEBUG) cout< samples, // double& t0,double& A, double& length){ // A=0.; // t0=0.; // double tA; // double Asum=0.; // double diffmax = 0.;double t0diff = -1;double ampt1 = 0.; // int tdiffi=-1; int tmaxi=-1; // // find maximum // if(DEBUG) cout<<"Pulse created from samples: "; // for(unsigned int i=0;iamp())//maximal research // { // A=samples[i]->amp(); // tA = samples[i]->t(); // tmaxi=i; // } // Asum+=samples[i]->amp();//integral calc // if(ampt1 && diffmaxamp()-ampt1) // maximal differential // { // diffmax = samples[i]->amp()-ampt1; // t0diff = samples[i]->t()-(samples[i]->amp()/diffmax); // tdiffi = i; // } // ampt1=samples[i]->amp(); // if(DEBUG) cout<t()<<", "; // } // length=samples.back()->t()-samples[0]->t(); // // scale factor // double c=fTimeCalib; // t0=tA-0.238; // if(tdiffi == tmaxi) //maximum amp in diff // t0diff = t0-0.5; // else // if(t0diff<0) //research of max. diff. failed // t0diff = t0; // else // t0diff-=1.154; // A=Asum;//Switch to integral // t0=t0diff; // if(DEBUG) cout<<"with t:"< samples, double& t0,double& A, double& length){ A=0.; t0=0.; double tA; double Asum=0.; // find maximum if(DEBUG) cout<<"Pulse created from samples: "; if(debugmode) cout<<"\n Started processPulse. Pulse created from samples: "; for(unsigned int i=0;iamp()){ A=samples[i]->amp(); tA = samples[i]->t(); } Asum+=samples[i]->amp();//integral calc if(DEBUG) cout<t()<<", "; } length=samples.back()->t()-samples[0]->t(); double t1=samples[0]->t();// + 0.3*length; double a1=samples[0]->amp(); // scale factor double c=fTimeCalib; t0=tA-c; A=Asum; if(DEBUG) cout<<"with t:"<