/[PAMELA software]/DarthVader/CalorimeterLevel2/src/CaloLevel1.cpp
ViewVC logotype

Diff of /DarthVader/CalorimeterLevel2/src/CaloLevel1.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by mocchiut, Fri Mar 30 11:22:07 2007 UTC revision 1.14 by mocchiut, Mon May 12 14:36:09 2008 UTC
# Line 8  Line 8 
8  ClassImp(CaloStrip);  ClassImp(CaloStrip);
9  ClassImp(CaloLevel1);  ClassImp(CaloLevel1);
10    
11    Float_t CaloStrip::UXal = CTX;
12    Float_t CaloStrip::UYal = CTY;
13    Float_t CaloStrip::UZal = CTZ;
14    Bool_t CaloStrip::paramload  = false;
15    
16  /**  /**
17   * CaloStrip default constructor   * CaloStrip default constructor
18  **/  **/
# Line 24  CaloStrip::CaloStrip(Bool_t mechalig) { Line 29  CaloStrip::CaloStrip(Bool_t mechalig) {
29    this->Clear();    this->Clear();
30    if ( mechalig ){    if ( mechalig ){
31      ismech = true;      ismech = true;
32        paramload = true;
33      UXal = MECHCTX;      UXal = MECHCTX;
34      UYal = MECHCTY;      UYal = MECHCTY;
35      UZal = MECHCTZ;      UZal = MECHCTZ;
# Line 51  CaloStrip::CaloStrip(CaloLevel1 *calo, B Line 57  CaloStrip::CaloStrip(CaloLevel1 *calo, B
57    this->Clear();    this->Clear();
58    if ( mechalig ){    if ( mechalig ){
59      ismech = true;      ismech = true;
60        paramload = true;
61      UXal = MECHCTX;      UXal = MECHCTX;
62      UYal = MECHCTY;      UYal = MECHCTY;
63      UZal = MECHCTZ;      UZal = MECHCTZ;
# Line 63  CaloStrip::CaloStrip(CaloLevel1 *calo, B Line 70  CaloStrip::CaloStrip(CaloLevel1 *calo, B
70  /**  /**
71   * Clear variables   * Clear variables
72  **/  **/
73  void CaloStrip::Clear() {    void CaloStrip::Clear(Option_t *t) {  
74    fE = 0.;    fE = 0.;
75    fX = 0.;    fX = 0.;
76    fY = 0.;    fY = 0.;
# Line 78  void CaloStrip::Clear() {   Line 85  void CaloStrip::Clear() {  
85   **/   **/
86  void CaloStrip::UseStandardAlig(){  void CaloStrip::UseStandardAlig(){
87    //    //
88    ismech = false;    if ( !paramload ){
   //  
   stringstream aligfile;  
   Int_t error = 0;  
   FILE *f = 0;  
   ifstream badfile;  
   GL_PARAM *glparam = new GL_PARAM();  
   //  
   TString host = "mysql://localhost/pamelaprod";  
   TString user = "anonymous";  
   TString psw = "";  
   const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");  
   const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");  
   const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");  
   if ( !pamdbhost ) pamdbhost = "";  
   if ( !pamdbuser ) pamdbuser = "";  
   if ( !pamdbpsw ) pamdbpsw = "";  
   if ( strcmp(pamdbhost,"") ) host = pamdbhost;  
   if ( strcmp(pamdbuser,"") ) user = pamdbuser;  
   if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;  
   TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());  
   //  
   UXal = 0.;  
   UYal = 0.;  
   UZal = 0.;  
   //  
   if ( dbc ){  
     //  
     // determine where I can find calorimeter ADC to MIP conversion file    
     //  
     printf(" Querying DB for calorimeter parameters files...\n");  
89      //      //
90        paramload = true;
91        ismech = false;
92      //      //
93        stringstream aligfile;
94        Int_t error = 0;
95        FILE *f = 0;
96        ifstream badfile;
97        GL_PARAM *glparam = new GL_PARAM();
98        //
99        TString host = "mysql://localhost/pamelaprod";
100        TString user = "anonymous";
101        TString psw = "";
102        const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
103        const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
104        const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
105        if ( !pamdbhost ) pamdbhost = "";
106        if ( !pamdbuser ) pamdbuser = "";
107        if ( !pamdbpsw ) pamdbpsw = "";
108        if ( strcmp(pamdbhost,"") ) host = pamdbhost;
109        if ( strcmp(pamdbuser,"") ) user = pamdbuser;
110        if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
111        TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
112        //
113        UXal = 0.;
114        UYal = 0.;
115        UZal = 0.;
116      //      //
117      error = 0;      if ( dbc ){
118      error = glparam->Query_GL_PARAM(1000,102,dbc);        //
119      if ( error >= 0 ){        // determine where I can find calorimeter ADC to MIP conversion file  
120          //
121          printf(" Querying DB for calorimeter parameters files...\n");
122          //
123        //        //
       aligfile.str("");  
       aligfile << glparam->PATH.Data() << "/";  
       aligfile << glparam->NAME.Data();  
124        //        //
125        printf("\n Using parameter file: \n %s \n",aligfile.str().c_str());        error = 0;
126        f = fopen(aligfile.str().c_str(),"rb");        error = glparam->Query_GL_PARAM(1000,102,dbc);
127        if ( f ){        if ( error >= 0 ){
128          //          //
129          fread(&UXal,sizeof(UXal),1,f);          aligfile.str("");
130          fread(&UYal,sizeof(UYal),1,f);          aligfile << glparam->PATH.Data() << "/";
131          fread(&UZal,sizeof(UZal),1,f);          aligfile << glparam->NAME.Data();
132            //
133            printf("\n Using parameter file: \n %s \n",aligfile.str().c_str());
134            f = fopen(aligfile.str().c_str(),"rb");
135            if ( f ){
136              //
137              fread(&UXal,sizeof(UXal),1,f);
138              fread(&UYal,sizeof(UYal),1,f);
139              fread(&UZal,sizeof(UZal),1,f);
140              //
141              fclose(f);
142            };
143          //          //
         fclose(f);  
144        };        };
145          dbc->Close();
146        };
147        if ( !UXal ){
148        //        //
149          printf(" No able to query DB for calorimeter parameters files\n Using hard-coded parameters \n");
150          UXal = CTX;
151          UYal = CTY;
152          UZal = CTZ;
153      };      };
154      dbc->Close();      //  
   };  
   if ( !UXal ){  
     //  
     printf(" No able to query DB for calorimeter parameters files\n Using hard-coded parameters \n");  
     UXal = CTX;  
     UYal = CTY;  
     UZal = CTZ;  
155    };    };
156    //    //
157  };  };
# Line 301  void CaloStrip::Set(Float_t X, Float_t Y Line 313  void CaloStrip::Set(Float_t X, Float_t Y
313  };  };
314    
315  /**  /**
316     * Given a point in the space or a strip it returns the Silicon sensor number. Numbering goes like this:
317     *
318     * y ^
319     *   |
320     *   |    6 7 8
321     *   |    3 4 5  
322     *   |    0 1 2
323     *   | -----------> x
324     *
325    **/
326    Int_t CaloStrip::GetSiSensor() {
327      //
328      // fX fY fZ // fView fPlane
329      //
330      Float_t deadsi = 0.096;
331      Float_t dead = 0.05;
332      Float_t sidim = 8.00;
333      //  Float_t stripdim = 0.244;
334      Float_t sensitarea = 7.808;
335      //
336      Float_t xoffset = 0.;
337      Float_t yoffset = 0.;
338      //
339      if ( (fView-1) == 0 && !((fPlane-1)%2) ){
340        xoffset = +0.05;
341        yoffset = 0.0;
342      };
343      if ( (fView-1) == 0 && ((fPlane-1)%2) ){
344        xoffset = -0.05;
345        yoffset = -0.20;
346      };
347      if ( (fView-1) == 1 && !((fPlane-1)%2) ){
348        xoffset = +0.10;
349        yoffset = -0.05;
350      };
351      if ( (fView-1) == 1 && ((fPlane-1)%2) ){
352        xoffset = -0.10;
353        yoffset = -0.15;
354      };
355      //
356      Int_t iind = -1;
357      Int_t jind = -1;
358      //
359      for (Int_t i = 0; i < 3; i++){
360        if ( (fX+xoffset+12.1) >= (deadsi+(sidim+dead)*i) && (fX+xoffset+12.1) <= (sensitarea+deadsi+(sidim+dead)*i) ){
361          iind = i;
362          break;
363        };
364      };
365      //
366      for (Int_t j = 0; j < 3; j++){
367        if ( (fY+yoffset+12.1) >= (deadsi+(sidim+dead)*j) && (fY+yoffset+12.1) <= (sensitarea+deadsi+(sidim+dead)*j) ){
368          jind = j;
369          break;
370        };
371      };
372      //
373      Int_t sensor = -1;
374      if ( iind != -1 &&  jind != -1 ){
375        sensor = iind + jind * 3;
376      };
377      //
378      //  printf(" View %i Plane %i x %f y %f z %f xoffset %f yoffset %f iind %i jind %i \n",fView,fPlane,fX,fY,fZ,xoffset,yoffset,iind,jind);
379      //
380      return(sensor);
381      //
382    };
383    
384    /**
385   * CaloLevel1 constructor   * CaloLevel1 constructor
386  **/  **/
387  CaloLevel1::CaloLevel1() {      CaloLevel1::CaloLevel1() {    
# Line 314  CaloLevel1::CaloLevel1() {     Line 395  CaloLevel1::CaloLevel1() {    
395  /**  /**
396   * Clear the CaloLevel1 object   * Clear the CaloLevel1 object
397   **/   **/
398  void CaloLevel1::Clear() {      void CaloLevel1::Clear(Option_t *t) {    
399    //    //
400    istrip = 0;    istrip = 0;
401    estrip.Reset();    estrip.Reset();
# Line 352  Float_t CaloLevel1::GetEstrip(Int_t svie Line 433  Float_t CaloLevel1::GetEstrip(Int_t svie
433   * Given estrip entry returns energy plus view, plane and strip numbers   * Given estrip entry returns energy plus view, plane and strip numbers
434  **/  **/
435  Float_t CaloLevel1::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip){  Float_t CaloLevel1::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip){
436      Bool_t sat = false;
437      Float_t mip=this->DecodeEstrip(entry,view,plane,strip,sat);
438      return(mip);
439    };
440    
441    /**
442     * Given estrip entry returns energy plus view, plane, strip numbers and saturation info
443    **/
444    Float_t CaloLevel1::DecodeEstrip(Int_t entry, Int_t &view, Int_t &plane, Int_t &strip, Bool_t &saturated){
445    //    //
446    if ( entry>istrip ) return(0.);    if ( entry>istrip ){
447        //
448        printf(" ERROR: problems decoding entry %i, it seems that number of entries is %i\n",entry,istrip);
449        //
450        return(0.);
451      };
452    //    //
453    //  printf(" num lim %f \n",std::numeric_limits<Float_t>::max());    //  printf(" num lim %f \n",std::numeric_limits<Float_t>::max());
454    //  printf(" estrip.At(%i) = %i \n",entry,estrip.At(entry));    //  printf(" estrip.At(%i) = %i \n",entry,estrip.At(entry));
# Line 395  Float_t CaloLevel1::DecodeEstrip(Int_t e Line 490  Float_t CaloLevel1::DecodeEstrip(Int_t e
490    //    //
491    strip = (Int_t)truncf((Float_t)((eval - fbi*1000000000 -plom*10000000)/100000));    strip = (Int_t)truncf((Float_t)((eval - fbi*1000000000 -plom*10000000)/100000));
492    //    //
493    Float_t mip = ((Float_t)(eval - fbi*1000000000 -plom*10000000 -strip*100000))/tim;    Double_t mip = (Double_t)(((Float_t)(eval - fbi*1000000000 -plom*10000000 -strip*100000))/tim);
494    //    //
495    if ( mip > 0. && mip < 99999. ) return(mip);    saturated = false;
496      if ( mip > 5000. ){
497        mip -= 5000.;
498        saturated = true;
499      };
500      if ( mip > 0. && mip < 99999. ) return((Float_t)mip);
501    //    //
502    printf(" WARNING: problems decoding value %i at entry %i \n",estrip.At(entry),entry);    printf(" ERROR: problems decoding value %i at entry %i \n",estrip.At(entry),entry);
503    //    //
504    view = -1;    view = -1;
505    plane = -1;    plane = -1;
# Line 411  Float_t CaloLevel1::DecodeEstrip(Int_t e Line 511  Float_t CaloLevel1::DecodeEstrip(Int_t e
511   * Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.).   * Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.).
512   */   */
513  Float_t CaloLevel1::qtotpl(Int_t nplane){  Float_t CaloLevel1::qtotpl(Int_t nplane){
514      Bool_t sat = false;
515      Float_t mip = this->qtotpl(nplane,sat);
516      return(mip);
517    };
518    
519    /*
520     * Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.).
521     */
522    Float_t CaloLevel1::qtotpl(Int_t nplane, Bool_t &sat){
523    //    //
524      sat = false;
525    Int_t sview = 1;    Int_t sview = 1;
526    if ( nplane%2 ) sview = 0;    if ( nplane%2 ) sview = 0;
527    //    //
528    Int_t splane = nplane-(sview+1)/2;  //  Int_t splane = nplane-(sview+1)/2;
529      Int_t splane = (nplane+sview-1)/2;
530    //    //
531    Float_t totmip = qtotpl(sview,splane);    Float_t totmip = qtotpl(sview,splane,sat);
532    //    //
533    return(totmip);    return(totmip);
534    //    //
# Line 427  Float_t CaloLevel1::qtotpl(Int_t nplane) Line 538  Float_t CaloLevel1::qtotpl(Int_t nplane)
538   * Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ).   * Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ).
539   */   */
540  Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane){  Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane){
541      Bool_t sat = false;
542      Float_t mip = this->qtotpl(sview,splane,sat);
543      return(mip);
544    };
545    
546    /*
547     * Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ).
548     */
549    Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane, Bool_t &sat){
550    //    //
551    Int_t view = -1;    Int_t view = -1;
552    Int_t plane = -1;    Int_t plane = -1;
553    Int_t strip = -1;    Int_t strip = -1;
554      Bool_t lsat = false;
555      sat = false;
556    //    //
557    Float_t mip = 0.;    Float_t mip = 0.;
558    Float_t totmip = 0.;    Float_t totmip = 0.;
# Line 439  Float_t CaloLevel1::qtotpl(Int_t sview, Line 561  Float_t CaloLevel1::qtotpl(Int_t sview,
561    //    //
562    for (Int_t i = 0; i<istrip; i++ ){    for (Int_t i = 0; i<istrip; i++ ){
563      //      //
564      mip = DecodeEstrip(i,view,plane,strip);      mip = DecodeEstrip(i,view,plane,strip,lsat);
565      //      //
566      if ( view == sview && splane == plane ) totmip += mip;      if ( view == sview && splane == plane ){
567          if ( lsat ) sat = true;
568          totmip += mip;
569          //printf(" totmip %f mip %f \n",totmip,mip);
570        };
571      //      //
572      // entry are ordered by strip, plane and view number. Go out if you pass the input strip      // entry are ordered by strip, plane and view number. Go out if you pass the input strip
573      //      //

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.14

  ViewVC Help
Powered by ViewVC 1.1.23