Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:47

0001 #include "phiedges_export.h"
0002 #include <vector>
0003 #include "TF1.h"
0004 #include "TMath.h"
0005 
0006 class  SawTeethFunctionObject {
0007 public:
0008   
0009   SawTeethFunctionObject(){};
0010   
0011   SawTeethFunctionObject(int idx): index(idx)
0012   {
0013     // copy corresponding wheel's phiedges
0014     for (int i=0;i<37;i++) ed[i] = phiedges[index][i];
0015     // determine n sectors
0016     n=0;
0017     while(ed[n]<999) {n++;}
0018     // set last sector's sorted phi properly:
0019     ed[n] = TMath::Pi() + fabs(ed[0] - TMath::Pi());
0020   }
0021    
0022   double operator() (double *xx, double *p) {
0023     double x = xx[0];
0024     if (x < ed[0]) x += TMath::TwoPi();
0025     for (int i=0; i<n; i++){
0026       if (x <= ed[i]) continue;
0027       if (x >  ed[i+1]) continue;
0028       // linear fit in the middle of sector
0029       return p[i*2] + p[i*2+1]*(x - 0.5*(ed[i]+ed[i+1]));
0030     }
0031     return 0;    
0032   }
0033   
0034   int getN() {return n;}
0035   
0036 private:
0037   int index;
0038   double ed[37];
0039   int n;
0040 };
0041 
0042 SawTeethFunctionObject *fobj0 = new SawTeethFunctionObject(0);
0043 SawTeethFunctionObject *fobj1 = new SawTeethFunctionObject(1);
0044 SawTeethFunctionObject *fobj2 = new SawTeethFunctionObject(2);
0045 SawTeethFunctionObject *fobj3 = new SawTeethFunctionObject(3);
0046 SawTeethFunctionObject *fobj4 = new SawTeethFunctionObject(4);
0047 SawTeethFunctionObject *fobj5 = new SawTeethFunctionObject(5);
0048 SawTeethFunctionObject *fobj6 = new SawTeethFunctionObject(6);
0049 SawTeethFunctionObject *fobj7 = new SawTeethFunctionObject(7);
0050 SawTeethFunctionObject *fobj8 = new SawTeethFunctionObject(8);
0051 SawTeethFunctionObject *fobj9 = new SawTeethFunctionObject(9);
0052 SawTeethFunctionObject *fobj10 = new SawTeethFunctionObject(10);
0053 SawTeethFunctionObject *fobj11 = new SawTeethFunctionObject(11);
0054 SawTeethFunctionObject *fobj12 = new SawTeethFunctionObject(12);
0055 SawTeethFunctionObject *fobj13 = new SawTeethFunctionObject(13);
0056 
0057 TF1 *fitf0 = new TF1("fitf0", fobj0, -TMath::Pi(), TMath::Pi(), 2*fobj0->getN(), "SawTeethFunctionObject");
0058 TF1 *fitf1 = new TF1("fitf1", fobj1, -TMath::Pi(), TMath::Pi(), 2*fobj1->getN(), "SawTeethFunctionObject");
0059 TF1 *fitf2 = new TF1("fitf2", fobj2, -TMath::Pi(), TMath::Pi(), 2*fobj2->getN(), "SawTeethFunctionObject");
0060 TF1 *fitf3 = new TF1("fitf3", fobj3, -TMath::Pi(), TMath::Pi(), 2*fobj3->getN(), "SawTeethFunctionObject");
0061 TF1 *fitf4 = new TF1("fitf4", fobj4, -TMath::Pi(), TMath::Pi(), 2*fobj4->getN(), "SawTeethFunctionObject");
0062 TF1 *fitf5 = new TF1("fitf5", fobj5, -TMath::Pi(), TMath::Pi(), 2*fobj5->getN(), "SawTeethFunctionObject");
0063 TF1 *fitf6 = new TF1("fitf6", fobj6, -TMath::Pi(), TMath::Pi(), 2*fobj6->getN(), "SawTeethFunctionObject");
0064 TF1 *fitf7 = new TF1("fitf7", fobj7, -TMath::Pi(), TMath::Pi(), 2*fobj7->getN(), "SawTeethFunctionObject");
0065 TF1 *fitf8 = new TF1("fitf8", fobj8, -TMath::Pi(), TMath::Pi(), 2*fobj8->getN(), "SawTeethFunctionObject");
0066 TF1 *fitf9 = new TF1("fitf9", fobj9, -TMath::Pi(), TMath::Pi(), 2*fobj9->getN(), "SawTeethFunctionObject");
0067 TF1 *fitf10 = new TF1("fitf10", fobj10, -TMath::Pi(), TMath::Pi(), 2*fobj10->getN(), "SawTeethFunctionObject");
0068 TF1 *fitf11 = new TF1("fitf11", fobj11, -TMath::Pi(), TMath::Pi(), 2*fobj11->getN(), "SawTeethFunctionObject");
0069 TF1 *fitf12 = new TF1("fitf12", fobj12, -TMath::Pi(), TMath::Pi(), 2*fobj12->getN(), "SawTeethFunctionObject");
0070 TF1 *fitf13 = new TF1("fitf13", fobj13, -TMath::Pi(), TMath::Pi(), 2*fobj13->getN(), "SawTeethFunctionObject");
0071 
0072 void cleanUpHeap(){
0073 delete fobj0 ;
0074 delete fobj1 ;
0075 delete fobj2 ;
0076 delete fobj3 ;
0077 delete fobj4 ;
0078 delete fobj5 ;
0079 delete fobj6 ;
0080 delete fobj7 ;
0081 delete fobj8 ;
0082 delete fobj9 ;
0083 delete fobj10;
0084 delete fobj11;
0085 delete fobj12;
0086 delete fobj13;
0087 delete fitf0 ;
0088 delete fitf1 ;
0089 delete fitf2 ;
0090 delete fitf3 ;
0091 delete fitf4 ;
0092 delete fitf5 ;
0093 delete fitf6 ;
0094 delete fitf7 ;
0095 delete fitf8 ;
0096 delete fitf9 ;
0097 delete fitf10;
0098 delete fitf11;
0099 delete fitf12;
0100 delete fitf13;
0101 }
0102 
0103 /*
0104 std::vector<SawTeethFunctionObject *> fobj;
0105 std::vector<TF1 *> fitf;
0106 TF1 *fitf0, *fitf1, *fitf2, *fitf3, *fitf4, *fitf5, *fitf6, *fitf7, *fitf8, *fitf9, *fitf10, *fitf11, *fitf12, *fitf13;
0107  
0108 void fitFunctionsInit()
0109 {
0110   for (int i=0; i<14; i++) {
0111     SawTeethFunctionObject *o = new SawTeethFunctionObject(i);
0112     fobj.push_back(o);
0113     char nm[20];
0114     sprintf(nm,"fitf%d",i);
0115     TF1 *f = new TF1(nm, fobj[i], -TMath::Pi(), TMath::Pi(), fobj[i]->getN(),"SawTeethFunctionObject");
0116     fitf.push_back(f);
0117   }
0118   fitf0 = fitf[0];
0119   fitf1 = fitf[1];
0120   fitf2 = fitf[2];
0121   fitf3 = fitf[3];
0122   fitf4 = fitf[4];
0123   fitf5 = fitf[5];
0124   fitf6 = fitf[6];
0125   fitf7 = fitf[7];
0126   fitf8 = fitf[8];
0127   fitf9 = fitf[9];
0128   fitf10 =fitf[10];
0129   fitf11 =fitf[11];
0130   fitf12 =fitf[12];
0131   fitf13 =fitf[13];
0132 }
0133 
0134 */